]> cloudbase.mooo.com Git - z180-stamp.git/blame - avr/cmd_cpu.c
move sys timer setup from main to timer.c
[z180-stamp.git] / avr / cmd_cpu.c
CommitLineData
226d3221
L
1/*
2 * (C) Copyright 2018 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#include "cmd_cpu.h"
8//#include <ctype.h>
9//#include <util/atomic.h>
10
11#include "z80-if.h"
12#include "con-utils.h"
13//#include "env.h"
14//#include "eval_arg.h"
15//#include "getopt-min.h"
16//#include "debug.h"
17
18/* hack to get Z180 loadfile into flash memory */
19#define const const FLASH
20#include "../z180/cpuinfo.h"
21#undef const
22
23
24static const FLASH char * const FLASH cpu_strings[] = {
25 FSTR("Unknown CPU"),
26 FSTR("8080"),
27 FSTR("8085"),
28 FSTR("Z80"),
29 FSTR("x180"),
30 FSTR("HD64180"),
31 FSTR("Z80180"),
32 FSTR("Z80S180"),
33};
34
35command_ret_t do_cpuchk(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
36{
37 uint8_t done = 0;
38 uint8_t cputype;
39 ERRNUM err = ESUCCESS;
40 uint8_t ram_save[cpuinfo_length];
41
42 if (z80_bus_state() & ZST_RUNNING) {
43 err = ERUNNING;
44 } else {
45 z80_bus_request_or_exit();
46 z80_read_block(ram_save, 0, cpuinfo_length);
47 z80_load_mem(0, cpuinfo,
48 &cpuinfo_sections,
49 cpuinfo_address,
50 cpuinfo_length_of_sections);
51 z80_bus_cmd(Release);
52
53 if (argv[1] && (argv[1][0] == 'n'))
54 goto donot;
55
56 z80_bus_cmd(Run);
57
58 clear_ctrlc(); /* forget any previous Control C */
59 while (done != 0xFF) {
60 _delay_ms(8);
61 /* check for ctrl-c to abort... */
62 if (had_ctrlc() || ctrlc()) {
63 err = EINTR;
64 break;
65 }
66 z80_bus_cmd(Request);
67 done = z80_read(3);
68 if (done == 0xFF)
69 cputype = z80_read(4);
70 z80_bus_cmd(Release);
71 }
72 z80_bus_cmd(Reset);
73 z80_bus_cmd(Request);
74// z80_write_block(ram_save, 0, cpuinfo_length);
75 z80_bus_cmd(Release);
76 }
77
78donot:
79
80 if (err)
81 cmd_error(CMD_RET_FAILURE, err, NULL);
82
83 if (done == 0xFF) {
84 if (cputype >= ARRAY_SIZE(cpu_strings))
85 cputype = 0;
86 printf_P(PSTR("Detected CPU: %S\n"), cpu_strings[cputype]);
87 }
88
89 return CMD_RET_SUCCESS;
90}