]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/cmd_boot.c
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * SPDX-License-Identifier: GPL-2.0+
16 #include <util/atomic.h>
19 #include "con-utils.h"
21 #include "z180-serv.h"
24 /* ugly hack to get Z180 loadfile into flash memory */
25 #define const const FLASH
26 #include "../z180/hdrom.h"
31 static void z80_load_mem(void)
34 uint32_t sec_base
= hdrom_start
;
36 printf_P(PSTR("Loading Z180 memory... \n"));
38 while (sec
< hdrom_sections
) {
39 printf_P(PSTR(" From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n"),
41 hdrom_address
[sec
]+hdrom_length_of_sections
[sec
] - 1,
42 hdrom_length_of_sections
[sec
]);
45 z80_write_block_P((const FLASH
unsigned char *) &hdrom
[sec_base
], /* src */
46 hdrom_address
[sec
], /* dest */
47 hdrom_length_of_sections
[sec
]); /* len */
49 sec_base
+=hdrom_length_of_sections
[sec
];
54 command_ret_t
do_loadf(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
56 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
58 if (z80_bus_state() & ZST_RUNNING
) {
59 printf_P(PSTR("## Can't load while CPU is running!\n"));
60 return CMD_RET_FAILURE
;
65 return CMD_RET_SUCCESS
;
69 command_ret_t
do_busreq_pulse(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
73 (void) cmdtp
; (void) flag
;
75 if (!(z80_bus_state() & ZST_RUNNING
)) {
76 printf_P(PSTR("## CPU is not running!\n"));
77 return CMD_RET_FAILURE
;
81 count
= (uint16_t) strtoul(argv
[2], NULL
, 16);
87 return CMD_RET_SUCCESS
;
91 command_ret_t
do_go(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
95 (void) cmdtp
; (void) flag
;
99 addr
= strtoul(argv
[1], NULL
, 16);
100 if (addr
>= (1UL<<16)) {
101 printf_P(PSTR("## Startaddress 0x%05lx too high.\n"
102 " (Out of logical address space (0x00000-0x0ffff))\n"),
104 return CMD_RET_FAILURE
;
107 if (z80_bus_state() & ZST_RUNNING
) {
108 printf_P(PSTR("## CPU allready running!\n"));
109 return CMD_RET_FAILURE
;
112 printf_P(PSTR("## Starting application at 0x%04lx ...\n"), addr
);
118 z80_bus_cmd(Request
);
119 for (i
= 0; i
< 3; i
++)
120 tmp
[i
] = z80_read(i
);
123 z80_write(2, (addr
>> 8));
126 z80_bus_cmd(M_Cycle
);
127 z80_bus_cmd(M_Cycle
);
128 for (i
= 0; i
< 3; i
++)
129 z80_write(i
, tmp
[i
]);
133 z80_bus_cmd(Release
);
135 return CMD_RET_SUCCESS
;
139 void reset_cpu(bus_cmd_t mode
)
146 command_ret_t
do_reset(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
148 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
150 printf_P(PSTR("## CPU now in reset state.\n"));
153 return CMD_RET_SUCCESS
;
156 command_ret_t
do_restart(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
158 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
162 return CMD_RET_SUCCESS
;
166 void print_con_usage(char esc
)
168 "------------------------------------------------\n"
170 " R - Reset (Restart) CPU\n"
171 " Q,X - Return to command line\n"
172 " \\ - code input:\n"
173 " \\nnn 3 decimal digits character code\n"
174 " \\Xhh 2 hexadecimal digits character code\n"
175 " ^%c - (Escape char) Type again to send itself\n"
180 command_ret_t
do_console(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
184 // uint8_t help_prompt = 0;
188 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
193 ATOMIC_BLOCK(ATOMIC_FORCEON
) {
194 pending
= (Stat
& S_CON_PENDING
) != 0;
195 Stat
&= ~S_CON_PENDING
;
198 while ((ch
= z80_memfifo_getc(fifo_conout
)) >= 0)
201 if ((ch
= my_getchar(0)) >= 0) {
204 if (ch
== CONFIG_ESC_CHAR
) {
206 /* TODO: Timer starten */
208 z80_memfifo_putc(fifo_conin
, ch
);
213 "------------------------------------------------\n"));
216 switch (toupper(ch
)) {
220 print_con_usage(CONFIG_ESC_CHAR
);
230 printf_P(PSTR("\n"));
239 case CONFIG_ESC_CHAR
:
240 z80_memfifo_putc(fifo_conin
, ch
);
247 if (toupper(ch
) == 'X') {
255 code
= code
* 10 + ch
- '0';
259 z80_memfifo_putc(fifo_conin
, code
);
269 code
= code
* 16 + ch
- '0';
273 z80_memfifo_putc(fifo_conin
, code
);
281 return CMD_RET_SUCCESS
;