]>
Commit | Line | Data |
---|---|---|
534e1dfc L |
1 | |
2 | /* | |
3 | * Misc boot support | |
4 | */ | |
5 | #include "common.h" | |
6 | #include <stdlib.h> | |
f338df2a | 7 | #include <util/delay.h> |
534e1dfc L |
8 | #include <avr/pgmspace.h> |
9 | ||
10 | #include "command.h" | |
11 | #include "z80-if.h" | |
12 | ||
13 | /* ugly hack to get Z180 loadfile into flash memory */ | |
14 | #define const const FLASH | |
15 | #include "../z180/hdrom.h" | |
16 | #undef const | |
17 | ||
18 | ||
19 | ||
20 | static void z80_load_mem(void) | |
21 | { | |
22 | unsigned sec = 0; | |
23 | uint32_t sec_base = hdrom_start; | |
24 | ||
25 | printf_P(PSTR("Loading Z180 memory... \n")); | |
26 | ||
27 | while (sec < hdrom_sections) { | |
28 | printf_P(PSTR(" From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n"), | |
29 | hdrom_address[sec], | |
30 | hdrom_address[sec]+hdrom_length_of_sections[sec] - 1, | |
31 | hdrom_length_of_sections[sec]); | |
32 | ||
f338df2a | 33 | zstate_t state = z80_request_bus_save(); |
534e1dfc L |
34 | z80_write_block((const FLASH unsigned char *) &hdrom[sec_base], /* src */ |
35 | hdrom_address[sec], /* dest */ | |
36 | hdrom_length_of_sections[sec]); /* len */ | |
f338df2a | 37 | z80_release_bus_save(state); |
534e1dfc L |
38 | sec_base+=hdrom_length_of_sections[sec]; |
39 | sec++; | |
40 | } | |
41 | } | |
42 | ||
43 | int do_loadf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
44 | { | |
45 | (void) cmdtp; (void) flag; (void) argc; (void) argv; | |
46 | ||
f338df2a | 47 | if (z80_runstate() & ZST_RUNNING) { |
534e1dfc L |
48 | printf_P(PSTR("## Can't load while CPU is running!\n")); |
49 | return 1; | |
50 | } | |
51 | ||
52 | z80_load_mem(); | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | ||
f338df2a | 58 | int do_busreq_pulse(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
534e1dfc | 59 | { |
f338df2a | 60 | uint16_t count=1; |
534e1dfc | 61 | |
f338df2a | 62 | (void) cmdtp; (void) flag; |
534e1dfc | 63 | |
f338df2a L |
64 | if (!(z80_runstate() & ZST_RUNNING)) { |
65 | printf_P(PSTR("## CPU is not running!\n")); | |
534e1dfc L |
66 | return 1; |
67 | } | |
68 | ||
f338df2a L |
69 | if (argc > 1) |
70 | count = (uint16_t) strtoul(argv[2], NULL, 16); | |
71 | ||
72 | z80_request_bus(); | |
73 | while (count--) | |
74 | z80_busreq_hpulse(); | |
534e1dfc | 75 | |
f338df2a L |
76 | return 0; |
77 | } | |
78 | ||
79 | ||
80 | int do_go(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
81 | { | |
82 | uint32_t addr; | |
83 | ||
84 | (void) cmdtp; (void) flag; | |
85 | ||
86 | if (argc < 2) | |
87 | return CMD_RET_USAGE; | |
88 | addr = strtoul(argv[1], NULL, 16); | |
89 | if (addr >= (1UL<<16)) { | |
534e1dfc L |
90 | printf_P(PSTR("## Startaddress 0x%05lx too high.\n" |
91 | " (Out of logical address space (0x00000-0x0ffff))\n"), | |
92 | addr); | |
93 | return 1; | |
f338df2a L |
94 | } |
95 | ||
96 | if (z80_runstate() & ZST_RUNNING) { | |
97 | printf_P(PSTR("## CPU allready running!\n")); | |
534e1dfc | 98 | return 1; |
534e1dfc L |
99 | } |
100 | ||
f338df2a L |
101 | printf_P(PSTR("## Starting application at 0x%04lx ...\n"), addr); |
102 | ||
103 | if (addr != 0) { | |
104 | uint8_t tmp[3]; | |
105 | uint_fast8_t i; | |
106 | ||
107 | z80_request_bus(); | |
108 | for (i = 0; i < 3; i++) | |
109 | tmp[i] = z80_read(i); | |
110 | z80_write(0, 0xc3); | |
111 | z80_write(1, addr); | |
112 | z80_write(2, (addr >> 8)); | |
113 | ||
114 | z80_run(); | |
115 | z80_busreq_hpulse(); | |
116 | z80_busreq_hpulse(); | |
117 | for (i = 0; i < 3; i++) | |
118 | z80_write(i, tmp[i]); | |
119 | } else | |
120 | z80_run(); | |
121 | ||
122 | z80_release_bus(); | |
123 | ||
534e1dfc L |
124 | return 0; |
125 | } | |
126 | ||
127 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
128 | { | |
129 | (void) cmdtp; (void) flag; (void) argc; (void) argv; | |
130 | ||
131 | printf_P(PSTR("## CPU now in reset state.\n")); | |
f338df2a | 132 | z80_reset(); |
534e1dfc L |
133 | |
134 | return 0; | |
135 | } | |
136 | ||
137 | int do_restart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
138 | { | |
139 | (void) cmdtp; (void) flag; (void) argc; (void) argv; | |
140 | ||
141 | z80_reset_pulse(); | |
142 | ||
143 | return 0; | |
144 | } | |
145 |