]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/init-80.180
Remove STM32 variant (and submodule libopencm3)
[z180-stamp.git] / z180 / init-80.180
1 page 255
2 .z80
3
4 extrn ddtz,bpent
5 extrn $stack
6 extrn charini,?const,?conin
7 extrn ?cono,?conos
8
9 extrn romend
10
11 global iobyte
12 global isv_sw
13
14 include config.inc
15
16
17
18
19 ;----------------------------------------------------------------------
20
21 cseg
22 romstart equ $
23
24 org romstart+0
25 jp start
26
27 iobyte: db 0
28
29 ; restart vectors
30
31 rsti defl 1
32 rept 7
33
34 org 8*rsti + romstart
35 jp bpent
36 rsti defl rsti+1
37 endm
38
39 ;----------------------------------------------------------------------
40
41 org romstart+40h
42
43 dw 0
44 db 0
45
46 cseg
47
48 if ROMSYS
49 $crom: defb c$rom ;
50 else
51 db 0 ;
52 endif
53
54
55 hwini0:
56 db 0 ;count
57 ; db rcr,CREFSH ;configure DRAM refresh
58 ; db dcntl,INIWAITS ;wait states
59 ; db cbar,SYS$CBAR
60
61
62 ;----------------------------------------------------------------------
63
64 org romstart+50h
65
66 start:
67 jp cstart
68 jp wstart
69 jp ?const
70 jp ?conin
71 jp ?cono
72 jp ?conos
73 jp charini
74
75 cstart:
76 di
77
78 xor a
79 ld (@cbnk),a
80
81 ; search warm start mark
82
83 ld ix,mark_55AA ; top of common area
84 ld a,0aah ;
85 cp (ix+000h) ;
86 jr nz,kstart ;
87 cp (ix+002h) ;
88 jr nz,kstart ;
89 cpl ;
90 cp (ix+001h) ;
91 jr nz,kstart ;
92 cp (ix+003h) ;
93 jr nz,kstart ;
94 ld sp,$stack ; mark found, check
95 ; call checkcrc_alv ;
96 jp z,wstart ; check ok,
97
98 ;
99 ; ram not ok, initialize -- kstart --
100
101 kstart:
102 ld sp,$stack ;01e1
103
104 ; Clear RAM
105
106 ; Init bank manager
107
108 ;----------------------------------------------------------------------
109 ;
110
111 ld hl,055AAh ;set warm start mark
112 ld (mark_55AA),hl ;
113 ld (mark_55AA+2),hl;
114
115 ;
116 ; -- wstart --
117 ;
118 wstart:
119 call sysram_init ;027f
120 call ivtab_init
121
122 call charini
123 call bufferinit
124
125 ld c,0
126 call selbnk
127
128
129 im 2 ;?030e
130 ei ;0282
131
132 call ?const ;0284
133 call ?const ;0287
134 or a ;028a
135 call nz,?conin ;028d
136
137 ;;; ld a,(banktab) ;
138 ;;; ld e,a ;
139 jp ddtz ;0290
140
141
142 ;----------------------------------------------------------------------
143 ;
144
145 ;TODO: Make a ringbuffer module.
146
147 global buf.init
148
149 buf.init:
150 ld (ix+o.in_idx),0
151 ld (ix+o.out_idx),0
152 ld (ix+o.mask),a
153 ret
154
155 ;----------------------------------------------------------------------
156
157
158 extrn msginit,msg.sout
159 extrn mtx.fifo,mrx.fifo
160 extrn co.fifo,ci.fifo
161
162
163 bufferinit:
164 call msginit
165
166 ld hl,buffers
167 ld b,buftablen
168 bfi_1:
169 ld a,(hl)
170 inc hl
171 ld (bufdat+0),a
172 ld e,(hl)
173 inc hl
174 ld d,(hl)
175 inc hl
176 ex de,hl
177
178 or a
179 jr nz,bfi_2
180
181 ld a,(@cbnk)
182 call bnk2phys
183
184 ld (40h+0),hl
185 ld (40h+2),a
186 out (AVRINT5),a
187 jr bfi_3
188 bfi_2:
189
190 ld a,(@cbnk)
191 call bnk2phys
192
193 ld (bufdat+1),hl
194 ld (bufdat+3),a
195 ld hl,inimsg
196 call msg.sout
197 bfi_3:
198 ex de,hl
199 djnz bfi_1
200 ret
201
202
203 buffers:
204 db 0
205 dw mtx.fifo
206 db 1
207 dw mrx.fifo
208 db 2
209 dw co.fifo
210 db 3
211 dw ci.fifo
212 buftablen equ ($ - buffers)/3
213
214 inimsg:
215 db inimsg_e - $ -1
216 db 0AEh
217 db inimsg_e - $ -1
218 db 0
219 bufdat:
220 db 0
221 dw 0
222 db 0
223 inimsg_e:
224
225
226 ;
227 ;----------------------------------------------------------------------
228 ;
229
230 bnk2phys:
231 sla h
232 jr nc,b2p_1 ;A15=1 --> common
233 ld a,3
234 b2p_1:
235 srl a
236 rr h
237 ret
238
239 ;
240 ;----------------------------------------------------------------------
241 ;
242
243 sysram_init:
244 ld hl,sysramw
245 ld de,topcodsys
246 ld bc,sysrame-sysramw
247 ldir
248
249 ret
250
251 ;----------------------------------------------------------------------
252
253 ivtab_init:
254 ld hl,ivtab ;
255 ld a,h ;
256 ld i,a ;
257 ; out0 (il),l ;
258
259 ; Let all vectors point to spurious int routines.
260
261 ld d,high sp.int0
262 ld a,low sp.int0
263 ld b,9
264 ivt_i1:
265 ld (hl),a
266 inc l
267 ld (hl),d
268 inc l
269 add a,sp.int.len
270 djnz ivt_i1
271 ret
272
273 ;----------------------------------------------------------------------
274 ;
275
276 global io.ini
277
278 io.ini:
279 push bc
280
281 if CPU_Z180
282
283 ld b,0 ;high byte port adress
284 ld a,(hl) ;count
285 inc hl
286 or a
287 jr z,ioi_e
288 ioi_1:
289 ld c,(hl) ;port address
290 inc hl
291 outi
292 inc b ;outi decrements b
293 dec a
294 jr nz,ioi_1
295
296 else
297 jr ioi_nxt
298 ioi_l:
299 ld c,(hl) ;port address
300 inc hl
301 otir
302 ioi_nxt:
303 ld b,(hl) ;count
304 inc hl
305 inc b
306 djnz ioi_l
307 endif
308 ioi_e:
309 pop bc
310 ret
311
312 if CPU_Z180
313 io.ini.m:
314 push bc
315 ld b,(hl)
316 inc hl
317 ld c,(hl)
318 inc hl
319 otimr
320 pop bc
321 ret
322 endif
323
324 io.ini.l:
325 ;
326
327
328 ;----------------------------------------------------------------------
329 ;
330 ;return:
331 ; hl = hl + a
332 ; Flags undefined
333 ;
334
335 add_hl_a:
336 add a,l
337 ld l,a
338 ret nc
339 inc h
340 ret
341
342 ; ---------------------------------------------------------
343
344 sysramw:
345
346 .phase isvsw_loc
347 topcodsys:
348
349 ; Trampoline for interrupt routines in banked ram.
350 ; Switch stack pointer to "system" stack in top ram
351
352 ; todo: z80 bank switch
353
354 isv_sw: ;
355 ex (sp),hl ; save hl, return adr in hl
356 push de ;
357 push af ;
358 ex de,hl ;
359 ld hl,0 ;
360 add hl,sp ;
361 ld a,h ;
362 cp 0f8h ;
363 jr nc,isw_1 ;
364 ld sp,$stack ;
365 isw_1:
366 push hl ;
367 ; save current bank
368 ; in0 h,(cbar) ;
369 push hl ;
370 ; switch to system bank
371 ; ld a,SYS$CBAR ;
372 ; out0 (cbar),a ;
373 ex de,hl ;
374 ld e,(hl) ;
375 inc hl ;
376 ld d,(hl) ;
377 ex de,hl ;
378 push bc ;
379 call jphl ;
380
381 pop bc ;
382 pop hl ; restore bank
383 ; out0 (cbar),h ;
384 pop hl ;
385 ld sp,hl ;
386 pop af ;
387 pop de ;
388 pop hl ;
389 ei ;
390 ret ;
391 jphl:
392 jp (hl) ;
393
394 ; ---------------------------------------------------------
395
396 sp.int0:
397 ld a,0d0h
398 jr sp.i.1
399 sp.int.len equ $-sp.int0
400 ld a,0d1h
401 jr sp.i.1
402 ld a,0d2h
403 jr sp.i.1
404 ld a,0d3h
405 jr sp.i.1
406 ld a,0d4h
407 jr sp.i.1
408 ld a,0d5h
409 jr sp.i.1
410 ld a,0d6h
411 jr sp.i.1
412 ld a,0d7h
413 jr sp.i.1
414 ld a,0d8h
415 sp.i.1:
416 ; out (80h),a
417 halt
418
419 ; ---------------------------------------------------------
420
421 ; Get IFF2
422 ; This routine may not be loaded in page zero
423 ;
424 ; return Carry clear, if INTs are enabled.
425 ;
426 global getiff
427 getiff:
428 xor a ;clear accu and carry
429 push af ;stack bottom := 00xxh
430 pop af
431 ld a,i ;P flag := IFF2
432 ret pe ;exit carry clear, if enabled
433 dec sp
434 dec sp ;has stack bottom been overwritten?
435 pop af
436 and a ;if not 00xxh, INTs were
437 ret nz ;actually enabled
438 scf ;Otherwise, they really are disabled
439 ret
440
441 ;----------------------------------------------------------------------
442
443 global selbnk
444
445 ; a: bank (0..2)
446
447 selbnk:
448 push bc
449 ld c,a
450 call getiff
451 push af
452
453 ld a,c
454 di
455 ld (@cbnk),a
456 ld a,5
457 out (SIOAC),a
458 ld a,(mm_sio0)
459 rla
460 srl c
461 rra
462 out (SIOAC),a
463 ld (mm_sio0),a
464
465 ld a,5
466 out (SIOBC),a
467 ld a,(mm_sio1)
468 rla
469 srl c
470 rra
471 out (SIOBC),a
472 ld (mm_sio1),a
473 pop af
474 pop bc
475 ret c ;INTs were disabled
476 ei
477 ret
478
479 ;----------------------------------------------------------------------
480
481 ; c: bank (0..2)
482
483 if 0
484
485 selbnk:
486 ld a,(@cbnk)
487 xor c
488 and 3
489 ret z ;no change
490
491 call getiff
492 push af
493 ld a,c
494 di
495 ld (@cbnk),a
496 ld a,5
497 out (SIOAC),a
498 ld a,(mm_sio0)
499 rla
500 srl c
501 rra
502 out (SIOAC),a
503 ld (mm_sio0),a
504
505 ld a,5
506 out (SIOBC),a
507 ld a,(mm_sio1)
508 rla
509 srl c
510 rra
511 out (SIOBC),a
512 ld (mm_sio1),a
513 pop af
514 ret nc ;INTs were disabled
515 ei
516 ret
517
518 endif
519
520 ;----------------------------------------------------------------------
521
522 if 0
523 ex af,af'
524 push af
525 ex af,af'
526
527 rra
528 jr nc,stbk1
529 ex af,af'
530 ld a,5
531 out (SIOAC),a
532 ld a,(mm_sio0)
533 rla
534 srl c
535 rra
536 out (SIOAC),a
537 ld (mm_sio1),a
538 ex af,af'
539
540 stbk1:
541 rra
542 jr nc,stbk2
543 ex af,af'
544 ld a,5
545 out (SIOBC),a
546 ld a,(mm_sio1)
547 rla
548 srl c
549 rra
550 out (SIOBC),a
551 ld (mm_sio1),a
552 ex af,af'
553
554 stbk2:
555 endif
556
557 global @cbnk
558 global mm_sio0, mm_sio1
559
560 @cbnk: db 0 ; current bank (0..2)
561 mm_sio0:
562 ds 1
563 mm_sio1:
564 ds 1
565
566 ;----------------------------------------------------------------------
567
568 curph defl $
569 .dephase
570 sysrame:
571 .phase curph
572 tim_ms: db 0
573 tim_s: dw 0
574 .dephase
575
576 ;-----------------------------------------------------
577
578 cseg
579
580 ;.phase 0ffc0h
581 ;ivtab equ 0ffc0h ; 0ffc0h ;int vector table
582 ;.dephase
583
584 ;.phase 0fffch
585 mark_55AA equ 0fffch
586 ;ds 4 ; 0fffch
587 ;.dephase
588
589
590 end
591