X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/4bc81323e51ac138e733c14eeb6f283ae706e904..4565be9a755c4de8ffdbc8b9a7b2d87c87f7a9e1:/z180/r3init.180 diff --git a/z180/r3init.180 b/z180/r3init.180 index 7ba9a0c..9edeaf2 100644 --- a/z180/r3init.180 +++ b/z180/r3init.180 @@ -3,7 +3,7 @@ extrn ddtz,bpent extrn $stack - extrn $coninit,$cists,$ci + extrn charini,?const,?conin extrn romend @@ -13,7 +13,7 @@ include config.inc include z180reg.inc include z180.lib - + ;CR equ 0dh @@ -22,7 +22,7 @@ cseg - jp start + jp start ; restart vectors @@ -32,8 +32,15 @@ rsti defl 1 jp bpent rsti defl rsti+1 endm + db 0, 0, 0, 0, 0 ;---------------------------------------------------------------------- + + ;org 40h + + dw 0 + db 0 + if ROMSYS $crom: defb c$rom ; @@ -44,7 +51,7 @@ $crom: defb c$rom ; dmclrt: ;clear ram per dma db dmct_e-dmclrt-2 ; db sar0l ;first port - dw nullbyte ;src (fixed) + dw nullbyte ;src (fixed) nullbyte: db 000h ;src dw romend ;dst (inc), start after "rom" code @@ -66,17 +73,20 @@ hwini0: ;---------------------------------------------------------------------- start: - push af ;003c - in0 a,(itc) ;003d Illegal opcode trap? - jp p,??st01 ;0040 - pop af ;0043 - jp bpent ;0044 yes, handle + ld (tmpstack),sp + ld sp,tmpstack + push af + in0 a,(itc) ;Illegal opcode trap? + jp m,??st01 + ld a,i ;I register == 0 ? + jr z,??st02 ; yes, harware reset ??st01: - ld a,i ;0047 I register == 0 ? - jr z,??st02 ;004b yes, harware reset - pop af ;004d - jp bpent ;004e no, allready set up + ld a,(syscbr) + out0 (cbr),a + pop af ;restore registers + ld sp,(tmpstack) ; + jp bpent ; ??st02: di ;0058 @@ -85,6 +95,11 @@ start: ld a,CWAITIO out0 (dcntl),a ; wait states + ld a,M_NCD ;No Clock Divide + out0 (ccr),a +; ld a,M_X2CM ;X2 Clock Multiplier +; out0 (cmr),a + ; search warm start mark ld ix,mark_55AA ;00b8 ; top of common area @@ -93,7 +108,7 @@ start: ld a,071h ;00bc ex af,af' ;00be ;for cbr = 0x70 downto 0x40 swsm_l: - ex af,af' ;00bf + ex af,af' ;00bf dec a ;00c0 cp 03fh ;00c1 jr z,kstart ;00c3 ; break (mark not found) @@ -125,9 +140,9 @@ kstart: ??f_0: out0 (cbr),a ;00f9 - ld (ix+0),a ;0103 + ld (ix+0),a ;0103 cpl - ld (ix+1),a ;0103 + ld (ix+1),a ;0103 cpl add a,8 ;010a next 'bank' cp 078h ;010c stop at 078000 @@ -153,7 +168,7 @@ kstart: add a,8 cp 078h ; stop at 078000 jr nz,??cp_0 - + ; ; ram test found 1 or more error free blocks (32k) ; @@ -177,8 +192,10 @@ ramok: alloc: out0 (cbr),c ;01de + ld a,c + ld (syscbr),a ld sp,$stack ;01e1 - + ; Clear RAM using DMA0 ld hl,dmclrt ;load DMA registers @@ -187,13 +204,13 @@ alloc: out0 (dmode),a ;01f1 ld b,512/64 - ld a,062h ;01f4 enable dma0, + ld a,062h ;01f4 enable dma0, ??cl_1: out0 (dstat),a ;01f9 clear (up to) 64k djnz ??cl_1 ; end of RAM? - + ; Init bank manager - + ld hl,banktabsys ;020f ld (hl),c ; Common area inc hl ;0213 @@ -211,7 +228,7 @@ l0218h: ld (hl),0e0h ; mark as sys ("rom"/monitor) inc hl djnz ??a_0 - + rr d ; shift out bit for block 0 rr e ; ld c,15 ;022c 15*32k remaining blocks @@ -220,14 +237,14 @@ l022eh: rr d ; rr e adc a,0 ; ==> 0xff : block ok - ld b,32/4 ; 32k == 8 * 4k + ld b,32/4 ; 32k == 8 * 4k l0236h: ld (hl),a ; inc hl ; djnz l0236h ; dec c ; jr nz,l022eh ;next 32k block - + ld hl,memalv+0ch ;memalv+0ch ld a,(banktabsys) ; call add_hl_a @@ -239,7 +256,7 @@ l024ah: ld (hl),0efh ;alloc common call gencrc_alv - ld hl,0000h ;bank # + ld hl,0000h ;bank # ld bc,0f0fh ; size (?) (4k blocks) xor a ; call sub_0420h ;alloc mem for bank 0 @@ -268,27 +285,29 @@ wstart: call prt0_init + call charini -;;; call bufferinit - - - call $coninit - + call bufferinit im 2 ;?030e ei ;0282 - call $cists ;0284 - call $cists ;0287 + call ?const ;0284 + call ?const ;0287 or a ;028a - call nz,$ci ;028d - - ld a,(banktab) ; - ld e,a ; + call nz,?conin ;028d + + ld a,(banktab) ; + ld e,a ; jp ddtz ;0290 - + + + ds 8 +tmpstack: + dw 2 +syscbr: db 1 ; ;---------------------------------------------------------------------- @@ -297,7 +316,7 @@ wstart: ;TODO: Make a ringbuffer module. global buf.init - + buf.init: ld (ix+o.in_idx),0 ld (ix+o.out_idx),0 @@ -305,50 +324,106 @@ buf.init: ret ;---------------------------------------------------------------------- +if 0 + extrn msginit,msg_tx_fifo,msg_rx_fifo + extrn msg.sout -.comment * +bufferinit: - extrn msginit,msg.sout,msg_fifo - extrn tx.buf,rx.buf + ld de,msg_tx_fifo + in0 a,cbr + call log2phys + ld (40h+0),hl + ld (40h+2),a + +; ld (bufdat+1),hl +; ld (bufdat+3),a +; ld a,1 +; ld (bufdat+0),a +; ld hl,inimsg +; call msg.sout + + ld de,msg_rx_fifo + in0 a,cbr + call log2phys + ld (bufdat+1),hl + ld (bufdat+3),a + ld a,2 + ld (bufdat+0),a + ld hl,inimsg + call msg.sout + + ret + +inimsg: + db inimsg_e - $ - 1 + db 0AEh + db inimsg_e - $ - 1 + db 0 +bufdat: + db 0 + dw 0 + db 0 +inimsg_e: + +endif +;---------------------------------------------------------------------- +; + + extrn msginit,msg.sout + extrn mtx.fifo,mrx.fifo + extrn co.fifo,ci.fifo bufferinit: call msginit - + ld hl,buffers - ld bc,0300h + ld b,buftablen bfi_1: + ld a,(hl) + inc hl + ld (bufdat+0),a ld e,(hl) inc hl ld d,(hl) inc hl push hl + + or a + jr nz,bfi_2 + in0 a,cbr + call log2phys + ld (40h+0),hl + ld (40h+2),a + out0 (AVRINT5),a + jr bfi_3 +bfi_2: in0 a,cbr call log2phys ld (bufdat+1),hl ld (bufdat+3),a - ld a,c - ld (bufdat+0),a ld hl,inimsg call msg.sout +bfi_3: pop hl - inc c djnz bfi_1 ret - rept 20 - db 0 - endm - buffers: - dw msg_fifo - dw tx.buf - dw rx.buf - -inimsg: - db inimsg_e - $ -2 - db PMSG - db 81h + db 0 + dw mtx.fifo + db 1 + dw mrx.fifo + db 2 + dw co.fifo + db 3 + dw ci.fifo +buftablen equ ($ - buffers)/3 + +inimsg: + db inimsg_e - $ -1 + db 0AEh db inimsg_e - $ -1 db 0 bufdat: @@ -357,7 +432,6 @@ bufdat: db 0 inimsg_e: - * ; ;---------------------------------------------------------------------- @@ -384,7 +458,7 @@ ivtab_init: ld d,high sp.int0 ld a,low sp.int0 ld b,9 -ivt_i1: +ivt_i1: ld (hl),a inc l ld (hl),d @@ -408,7 +482,7 @@ prt0_init: ld hl,prt0itab call io.ini.m ret - + prt0itab: db prt0it_e-prt0itab-2 db tmdr0l @@ -443,10 +517,10 @@ io.ini.m: inc hl ld c,(hl) inc hl - otimr - pop bc + otimr + pop bc ret - + io.ini.l: ; @@ -536,7 +610,7 @@ checkcrc_alv: ; ; ret: ; a: 0 == ok -; 1 == +; 1 == ; 2 == no bank # in requested range ; ff == crc error ; @@ -544,7 +618,7 @@ checkcrc_alv: sub_0420h: call checkcrc_alv ;0420 jr nz,l049ch ;0424 crc error, tables corrupt - + call sub_049dh ;0427 bank # in req. range available? jr c,l0499h ;042a push ix ;042c @@ -569,7 +643,7 @@ l0441h: djnz l043dh ;0442 jr l0464h ;0444 l0446h: - push hl ;0446 + push hl ;0446 pop ix ;0447 free blocks start here ld e,000h ;0449 jr l0451h ;044b @@ -583,12 +657,12 @@ l0451h: djnz l044dh ;0453 jr l0464h ;0455 -; end of free blocks run. +; end of free blocks run. l0457h: ld a,d ;0457 cp e ;0458 nr of blocks >= requested ? - jr nc,l0441h ;0459 + jr nc,l0441h ;0459 ld d,e ;045b push ix ;045c @@ -660,7 +734,7 @@ l04a1h: inc e ;04a1 test next # ld a,d ;04a2 cp e ;04a3 - jr c,l04b1h ;04a4 + jr c,l04b1h ;04a4 ld a,e ;04a6 ld hl,memalv ;04a7 ld bc,alv_len ;04aa @@ -721,7 +795,7 @@ log2phys: mlt bc ;bc = a<<4 ld l,d ; ld h,0 ; - add hl,bc ;bc + d == a<<4 + d + add hl,bc ;bc + d == a<<4 + d ld a,h ; ld h,l ; ld l,e ; @@ -737,11 +811,11 @@ log2phys: ; add_hl_a: - add a,l - ld l,a - ret nc - inc h - ret + add a,l + ld l,a + ret nc + inc h + ret ; --------------------------------------------------------- @@ -753,7 +827,7 @@ topcodsys: ; Trampoline for interrupt routines in banked ram. ; Switch stack pointer to "system" stack in top ram ; Save cbar - + isv_sw: ; ex (sp),hl ; save hl, return adr in hl push de ; @@ -848,7 +922,7 @@ sysrame: tim_ms: db 0 tim_s: dw 0 .dephase - + ;----------------------------------------------------- dseg @@ -864,7 +938,7 @@ memalv: alv_len equ $-memalv crc_len equ $-banktabsys -crc_memalv: +crc_memalv: ds 2 ; cseg