]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | /* | |
3 | * Misc boot support | |
4 | */ | |
5 | #include "common.h" | |
6 | #include <stdlib.h> | |
7 | #include <util/delay.h> | |
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 | ||
33 | z80_bus_cmd(Request); | |
34 | z80_write_block((const FLASH unsigned char *) &hdrom[sec_base], /* src */ | |
35 | hdrom_address[sec], /* dest */ | |
36 | hdrom_length_of_sections[sec]); /* len */ | |
37 | z80_bus_cmd(Release); | |
38 | sec_base+=hdrom_length_of_sections[sec]; | |
39 | sec++; | |
40 | } | |
41 | } | |
42 | ||
43 | command_ret_t do_loadf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
44 | { | |
45 | (void) cmdtp; (void) flag; (void) argc; (void) argv; | |
46 | ||
47 | if (z80_bus_state() & ZST_RUNNING) { | |
48 | printf_P(PSTR("## Can't load while CPU is running!\n")); | |
49 | return CMD_RET_FAILURE; | |
50 | } | |
51 | ||
52 | z80_load_mem(); | |
53 | ||
54 | return CMD_RET_SUCCESS; | |
55 | } | |
56 | ||
57 | ||
58 | command_ret_t do_busreq_pulse(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
59 | { | |
60 | uint16_t count=1; | |
61 | ||
62 | (void) cmdtp; (void) flag; | |
63 | ||
64 | if (!(z80_bus_state() & ZST_RUNNING)) { | |
65 | printf_P(PSTR("## CPU is not running!\n")); | |
66 | return CMD_RET_FAILURE; | |
67 | } | |
68 | ||
69 | if (argc > 1) | |
70 | count = (uint16_t) strtoul(argv[2], NULL, 16); | |
71 | ||
72 | z80_bus_cmd(Request); | |
73 | while (count--) | |
74 | z80_bus_cmd(M_Cycle); | |
75 | ||
76 | return CMD_RET_SUCCESS; | |
77 | } | |
78 | ||
79 | ||
80 | command_ret_t 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)) { | |
90 | printf_P(PSTR("## Startaddress 0x%05lx too high.\n" | |
91 | " (Out of logical address space (0x00000-0x0ffff))\n"), | |
92 | addr); | |
93 | return CMD_RET_FAILURE; | |
94 | } | |
95 | ||
96 | if (z80_bus_state() & ZST_RUNNING) { | |
97 | printf_P(PSTR("## CPU allready running!\n")); | |
98 | return CMD_RET_FAILURE; | |
99 | } | |
100 | ||
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_bus_cmd(Request); | |
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_bus_cmd(Run); | |
115 | z80_bus_cmd(M_Cycle); | |
116 | z80_bus_cmd(M_Cycle); | |
117 | for (i = 0; i < 3; i++) | |
118 | z80_write(i, tmp[i]); | |
119 | } else | |
120 | z80_bus_cmd(Run); | |
121 | ||
122 | z80_bus_cmd(Release); | |
123 | ||
124 | return CMD_RET_SUCCESS; | |
125 | } | |
126 | ||
127 | command_ret_t 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")); | |
132 | ||
133 | z80_bus_cmd(Reset); | |
134 | return CMD_RET_SUCCESS; | |
135 | } | |
136 | ||
137 | command_ret_t 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_bus_cmd(Restart); | |
142 | ||
143 | return CMD_RET_SUCCESS; | |
144 | } | |
145 | ||
146 | ||
147 | command_ret_t do_clock(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | |
148 | { | |
149 | uint32_t freq; | |
150 | ||
151 | (void) cmdtp; (void) flag; | |
152 | ||
153 | if (argc == 2) { | |
154 | freq = strtoul(argv[1], NULL, 10); | |
155 | if (freq == 0) { | |
156 | printf_P(PSTR("CPU clock cannot be 0\n")); | |
157 | return CMD_RET_USAGE; | |
158 | } | |
159 | ||
160 | if (freq > F_CPU / 2) { | |
161 | printf_P(PSTR("Max CPU clock freq. is: %luHz\n"), F_CPU/2); | |
162 | return CMD_RET_USAGE; | |
163 | } | |
164 | ||
165 | if (z80_clock_set(freq) < 0) { | |
166 | printf_P(PSTR("Setting CPU clock freq. to %luHz failed.\n"), | |
167 | freq); | |
168 | } | |
169 | } | |
170 | ||
171 | printf_P(PSTR("CPU clock: %luHz\n"), z80_clock_get()); | |
172 | ||
173 | ||
174 | return CMD_RET_SUCCESS; | |
175 | } | |
176 |