summaryrefslogtreecommitdiff
path: root/avr/cmd_cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/cmd_cpu.c')
-rw-r--r--avr/cmd_cpu.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c
new file mode 100644
index 0000000..de627c6
--- /dev/null
+++ b/avr/cmd_cpu.c
@@ -0,0 +1,90 @@
+/*
+ * (C) Copyright 2018 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include "cmd_cpu.h"
+//#include <ctype.h>
+//#include <util/atomic.h>
+
+#include "z80-if.h"
+#include "con-utils.h"
+//#include "env.h"
+//#include "eval_arg.h"
+//#include "getopt-min.h"
+//#include "debug.h"
+
+/* hack to get Z180 loadfile into flash memory */
+#define const const FLASH
+#include "../z180/cpuinfo.h"
+#undef const
+
+
+static const FLASH char * const FLASH cpu_strings[] = {
+ FSTR("Unknown CPU"),
+ FSTR("8080"),
+ FSTR("8085"),
+ FSTR("Z80"),
+ FSTR("x180"),
+ FSTR("HD64180"),
+ FSTR("Z80180"),
+ FSTR("Z80S180"),
+};
+
+command_ret_t do_cpuchk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+ uint8_t done = 0;
+ uint8_t cputype;
+ ERRNUM err = ESUCCESS;
+ uint8_t ram_save[cpuinfo_length];
+
+ if (z80_bus_state() & ZST_RUNNING) {
+ err = ERUNNING;
+ } else {
+ z80_bus_request_or_exit();
+ z80_read_block(ram_save, 0, cpuinfo_length);
+ z80_load_mem(0, cpuinfo,
+ &cpuinfo_sections,
+ cpuinfo_address,
+ cpuinfo_length_of_sections);
+ z80_bus_cmd(Release);
+
+ if (argv[1] && (argv[1][0] == 'n'))
+ goto donot;
+
+ z80_bus_cmd(Run);
+
+ clear_ctrlc(); /* forget any previous Control C */
+ while (done != 0xFF) {
+ _delay_ms(8);
+ /* check for ctrl-c to abort... */
+ if (had_ctrlc() || ctrlc()) {
+ err = EINTR;
+ break;
+ }
+ z80_bus_cmd(Request);
+ done = z80_read(3);
+ if (done == 0xFF)
+ cputype = z80_read(4);
+ z80_bus_cmd(Release);
+ }
+ z80_bus_cmd(Reset);
+ z80_bus_cmd(Request);
+// z80_write_block(ram_save, 0, cpuinfo_length);
+ z80_bus_cmd(Release);
+ }
+
+donot:
+
+ if (err)
+ cmd_error(CMD_RET_FAILURE, err, NULL);
+
+ if (done == 0xFF) {
+ if (cputype >= ARRAY_SIZE(cpu_strings))
+ cputype = 0;
+ printf_P(PSTR("Detected CPU: %S\n"), cpu_strings[cputype]);
+ }
+
+ return CMD_RET_SUCCESS;
+}