]> cloudbase.mooo.com Git - z180-stamp.git/blame - z180/cpuinfo.180
rewrite of cmd_cpu/do_cpu_freq
[z180-stamp.git] / z180 / cpuinfo.180
CommitLineData
226d3221
L
1 .z80 ; for M80, ignored by SLR assembler\r
2 include z180reg.inc\r
3\r
4RUN_TPA equ 0\r
5\r
6UUNKNOWN equ 0 ;Unknown CPU\r
7U8080 equ 1 ;8080\r
8U8085 equ 2 ;8085\r
9UZ80 equ 3 ;Z80\r
10UX180 equ 4 ;HD64180 or higher\r
11UHD64180 equ 5 ;HD64180\r
12UZ80180 equ 6 ;Z80180\r
13UZ8S180 equ 7 ;Z8S180, Z8L180\r
14\r
15\r
16;-------------------------------------------------------------------------------\r
17\r
18\r
19 if RUN_TPA\r
20base equ 0100h\r
21 else\r
22base equ 0\r
23 endif\r
24\r
25\r
26 aseg\r
27 org base\r
28 jp start\r
29\r
30done: db 0\r
31result: db 0\r
32\r
226d3221
L
33;-------------------------------------------------------------------------------\r
34; Check if register C exists. D holds mask of bit to test.\r
aea51b6c 35; return z, if register exists\r
226d3221
L
36\r
37chk_reg:\r
aea51b6c
L
38 in a,(c)\r
39 ld l,a\r
226d3221 40 ; check, if register is changeable\r
aea51b6c
L
41 xor d ;\r
42 out (c),a\r
43 in a,(c) ; get it back\r
44 xor d\r
45 out (c),l ; set register to original state\r
46 cp l\r
226d3221
L
47 ret\r
48\r
49;-------------------------------------------------------------------------------\r
50; Check CPU\r
51;\r
52;\r
53; return:\r
54; E = 0 Unknown\r
55; E = 1 8080\r
56; E = 2 8085\r
57; E = 3 Z80\r
58; E = 4 HD64180 or higher\r
59; E = 5 HD64180\r
60; E = 6 Z80180\r
61; E = 7 Z8S180, Z8L180\r
62;\r
63;-------------------------------------------------------------------------------\r
64; Registers only in Z180+, not in HD64180\r
65; 3E OMCR\r
66;\r
67; Registers only in Z8S180/Z8L180\r
68; 12 ASEXT0\r
69; 13 ASEXT1\r
70; 1A ASTC0L\r
71; 1B ASTC0H\r
72; 1C ASTC1L\r
73; 1D ASTC1H\r
74; 1E CMR\r
75; 1F CCR\r
76; 2D IAR1B\r
77;\r
78; Reserved registers\r
79; 11\r
80; 19\r
81; 35\r
82; 37\r
83; 3B - 3D\r
84\r
85check:\r
86 ld e,U8080 ; Init return val, assume 8080\r
87 xor a\r
88 dec a ; 00 --> 0FFH 8080/8085: even parity; Z80+: No overflow\r
89 jp po,chk_z80 ; Z80+ if P/V flag reset\r
90\r
91 ; The 8085 logical AND instructions always set the auxiliary flag ON.\r
92 ; The 8080 logical AND instructions set the flag to reflect the\r
93 ; logical OR of bit 3 of the values involved in the AND operation.\r
94 ; (8080/8085 ASSEMBLY LANGUAGE PROGRAMMING MANUAL, 1977, 1978)\r
95\r
96 xor a\r
97 and a ; 8085 sets, 8080 resets half carry.\r
98 daa ; A=06 (8085) or A=00 (8080)\r
99 ret z\r
100 inc e\r
101 ret\r
102\r
103chk_z80:\r
104 ld e,UZ80 ; Assume Z80\r
105 daa ; Z80: 099H, x180+: 0F9H\r
106 cp 99h ; Result on 180 type cpus is F9 here. Thanks Hitachi\r
107 ret z\r
108 inc e ; x180\r
109\r
110 ; At least Hitachi HD64180\r
111 ; Test differences in certain internal registers\r
112 ; to determine the 180 variant.\r
aea51b6c
L
113\r
114 ld b,0\r
115 ld c,icr\r
116 in a,(c)\r
226d3221 117 cp 01FH\r
aea51b6c 118 jr z,icr_ok\r
226d3221
L
119\r
120 ;TODO: additional plausibility checks\r
121\r
aea51b6c 122 ret ; I/O registers not found\r
226d3221
L
123\r
124 ; Register (base) found.\r
125\r
aea51b6c 126icr_ok:\r
226d3221 127 inc e ; HD64180\r
aea51b6c
L
128 out0 (RCR),b ;\r
129 ld c,omcr ; Check, if CPU has OMCR register\r
226d3221
L
130 ld d,M_IOC ;\r
131 call chk_reg ;\r
aea51b6c 132 ret nz ; Register does not exist. It's a HD64180\r
226d3221
L
133\r
134 inc e ; Z80180\r
aea51b6c 135 ld c,cmr ; Check, if CPU has CMR register\r
226d3221
L
136 ld d,M_LNC ;\r
137 call chk_reg ;\r
aea51b6c 138 ret nz ; register does not exist. It's a Z80180\r
226d3221
L
139\r
140 inc e ; S180/L180 (class) detected.\r
226d3221
L
141 ret\r
142\r
143;-------------------------------------------------------------------------------\r
144\r
145start:\r
146 ld sp,stack\r
aea51b6c
L
147 ld hl,done\r
148 ld (hl),0\r
149 inc hl\r
150 ld (hl),0\r
151 push hl\r
226d3221 152 call check\r
aea51b6c 153 pop hl\r
226d3221
L
154 ld (hl),e\r
155 dec hl\r
156 ld (hl),0ffH\r
1ffa84bd
L
157 out (040H),a\r
158\r
159; ld a,(wstates)\r
160; out0 (DCNTL),a\r
161 ;Z80 Z180(0W) Z180(MaxW)\r
162loop: ;--------------------------\r
163 in a,(050h) ;11 10 +3*3 19\r
164 jp loop ;10 9 +3*3 18\r
165 ;--------------------------\r
166 ;21 19 37\r
167\r
168; jr loop ;12 8 +2*3 14\r
226d3221
L
169\r
170 rept 8\r
171 dw 0\r
172 endm\r
173stack:\r
174 end\r
175\r
176; vim:set ts=8 noet nowrap\r