summaryrefslogtreecommitdiff
path: root/avr/cmd_boot.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/cmd_boot.c')
-rw-r--r--avr/cmd_boot.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c
new file mode 100644
index 0000000..4fb9c2a
--- /dev/null
+++ b/avr/cmd_boot.c
@@ -0,0 +1,106 @@
+
+/*
+ * Misc boot support
+ */
+#include "common.h"
+#include <stdlib.h>
+#include <avr/pgmspace.h>
+
+#include "command.h"
+#include "z80-if.h"
+
+/* ugly hack to get Z180 loadfile into flash memory */
+#define const const FLASH
+#include "../z180/hdrom.h"
+#undef const
+
+
+
+static void z80_load_mem(void)
+{
+ unsigned sec = 0;
+ uint32_t sec_base = hdrom_start;
+
+ printf_P(PSTR("Loading Z180 memory... \n"));
+
+ while (sec < hdrom_sections) {
+ printf_P(PSTR(" From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n"),
+ hdrom_address[sec],
+ hdrom_address[sec]+hdrom_length_of_sections[sec] - 1,
+ hdrom_length_of_sections[sec]);
+
+ z80_request_bus();
+ z80_write_block((const FLASH unsigned char *) &hdrom[sec_base], /* src */
+ hdrom_address[sec], /* dest */
+ hdrom_length_of_sections[sec]); /* len */
+ z80_release_bus();
+ sec_base+=hdrom_length_of_sections[sec];
+ sec++;
+ }
+}
+
+int do_loadf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ (void) cmdtp; (void) flag; (void) argc; (void) argv;
+
+ if (z80_runstate() != 0) {
+ printf_P(PSTR("## Can't load while CPU is running!\n"));
+ return 1;
+ }
+
+ z80_load_mem();
+
+ return 0;
+}
+
+
+int do_go(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ uint32_t addr;
+
+ (void) cmdtp; (void) flag; (void) argc;
+
+ if (z80_runstate() != 0) {
+ printf_P(PSTR("## CPU allready running!\n"));
+ return 1;
+ }
+
+ addr = strtoul(argv[1], NULL, 16);
+
+ if (addr > (1UL<<16) - 1) {
+ printf_P(PSTR("## Startaddress 0x%05lx too high.\n"
+ " (Out of logical address space (0x00000-0x0ffff))\n"),
+ addr);
+ return 1;
+ } else if (addr != 0) {
+ printf_P(PSTR("## Starting application at "
+ "address != 0x0000 not implemented yet.\n"));
+ return 1;
+ } else {
+ printf_P(PSTR("## Starting application at 0x%05lX ...\n"), addr);
+ z80_release_bus();
+ z80_reset(HIGH);
+ }
+
+ return 0;
+}
+
+int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ (void) cmdtp; (void) flag; (void) argc; (void) argv;
+
+ printf_P(PSTR("## CPU now in reset state.\n"));
+ z80_reset(LOW);
+
+ return 0;
+}
+
+int do_restart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ (void) cmdtp; (void) flag; (void) argc; (void) argv;
+
+ z80_reset_pulse();
+
+ return 0;
+}
+