6 extrn charini,?const,?conin
23 ;----------------------------------------------------------------------
41 ;----------------------------------------------------------------------
57 INIWAITS defl INIWAITS+CWAITROM
64 db rcr,CREFSH ;configure DRAM refresh
65 db dcntl,INIWAITS ;wait states
71 ;----------------------------------------------------------------------
83 ;----------------------------------------------------------------------
85 dmclrt: ;clear ram per dma
88 dw nullbyte ;src (fixed)
91 dw romend ;dst (inc), start after "rom" code
93 dw 0-romend ;count (64k)
100 in0 a,(itc) ;Illegal opcode trap?
102 ld a,i ;I register == 0 ?
103 jr z,??st02 ; yes, harware reset
109 pop af ;restore registers
115 out0 (rcr),a ; configure DRAM refresh
117 out0 (dcntl),a ; wait states
119 ld a,M_NCD ;No Clock Divide
121 ; ld a,M_X2CM ;X2 Clock Multiplier
129 ; search warm start mark
133 ld ix,mark_55AA ;00b8 ; top of common area
137 ex af,af' ;00be ;for cbr = 0x70 downto 0x40
142 jr z,kstart ;00c3 ; break (mark not found)
155 ld sp,$stack ;00e0 mark found, check
156 call checkcrc_alv ;00e3
157 jp z,wstart ;00e6 check ok,
159 ld ix,mark_55AA ; top of common area
170 ld sp,$stack ; mark found, check
171 jp z,wstart ; check ok,
174 ; ram not ok, initialize -- kstart --
181 ld a,088h ;00e9 0000-7fff: common 0
182 out0 (cbar),a ;00eb 8000-ffff: common 1
184 ld a,0 ;00f1 start at 008000 (2. phys. 32k block)
192 add a,8 ;010a next 'bank'
193 cp 078h ;010c stop at 078000
196 ld de,8000h ;0114 first block not tested, but mark as ok
197 ld a,0 ;00f1 start at 008000 (2. phys. 32k block)
214 cp 078h ; stop at 078000
226 ; ram test found 1 or more error free blocks (32k)
234 ld c,070h ;01ce highest block
238 jr c,alloc ;01d4 highest "error free" block
244 slp ;01dc should never be reached
253 ; Clear RAM using DMA0
259 ld hl,dmclrt ;load DMA registers
261 ld a,0cbh ;01ef dst +1, src fixed, burst
265 ld a,062h ;01f4 enable dma0,
267 out0 (dstat),a ;01f9 clear (up to) 64k
268 djnz ??cl_1 ; end of RAM?
274 ld hl,banktabsys ;020f
275 ld (hl),c ; Common area
277 ld (hl),c ; System work area
278 inc hl ;0215 Point to bank 0 entry
281 ld (hl),0ffh ;0218 Mark all banks as unassigned
286 ld b,8 ; 8*4k ie. first 32k
288 ld (hl),0e0h ; mark as sys ("rom"/monitor)
292 rr d ; shift out bit for block 0
294 ld c,15 ;022c 15*32k remaining blocks
296 ld a,0feh ; 0xfe == block with error(s)
299 adc a,0 ; ==> 0xff : block ok
300 ld b,32/4 ; 32k == 8 * 4k
306 jr nz,l022eh ;next 32k block
308 ld hl,memalv+0ch ;memalv+0ch
313 ld (hl),0ech ;alloc system ram
316 ld (hl),0efh ;alloc common
320 ld bc,0f0fh ; size (?) (4k blocks)
322 call sub_0420h ;alloc mem for bank 0
336 ld hl,055AAh ;set warm start mark
341 ; (crc ok) -- wstart --
344 call sysram_init ;027f
382 ;----------------------------------------------------------------------
385 ;TODO: Make a ringbuffer module.
395 ;----------------------------------------------------------------------
397 extrn msginit,msg_tx_fifo,msg_rx_fifo
439 ;----------------------------------------------------------------------
442 extrn msginit,msg.sout
443 extrn mtx.fifo,mrx.fifo
444 extrn co.fifo,ci.fifo
531 buftablen equ ($ - buffers)/3
546 ;----------------------------------------------------------------------
552 ld bc,sysrame-sysramw
557 ;----------------------------------------------------------------------
567 ; Let all vectors point to spurious int routines.
581 ;----------------------------------------------------------------------
599 db prt0it_e-prt0itab-2
603 db M_TIE0+M_TDE0 ;enable timer 0 interrupt and down count.
609 ;----------------------------------------------------------------------
616 ld b,0 ;high byte port adress
622 ld c,(hl) ;port address
625 inc b ;outi decrements b
632 ld c,(hl) ;port address
661 ;----------------------------------------------------------------------
713 ld hl,banktabsys ;03f9
729 ld hl,banktabsys ;040d
730 ld bc,crc_len+2 ;0410
737 ;----------------------------------------------------------------------
750 ; 2 == no bank # in requested range
755 call checkcrc_alv ;0420
756 jr nz,l049ch ;0424 crc error, tables corrupt
758 call sub_049dh ;0427 bank # in req. range available?
775 inc a ;043e free blocks are marked 0ffh
783 pop ix ;0447 free blocks start here
786 l044dh: ; count free blocks
796 ; end of free blocks run.
800 cp e ;0458 nr of blocks >= requested ?
841 call gencrc_alv ;048e
856 ; search a free bank number in range
860 ; l: bank number available
861 ; nc, if found, bank nr. in l
870 inc e ;04a1 test next #
877 cpir ;04ad bank# allready allocated?
878 jr z,l04a1h ;04af if yes, search for next
895 call gencrc_alv ;04c4
897 or a ;04c8 clear carry
901 ;--------------------------------------------------------------
906 ;out ahl: Phys. (linear) Address
917 ;--------------------------------------------------------------
922 ; OP: ahl = (a<<12) + (d<<8) + e
924 ;out ahl: Phys. (linear) Address
934 add hl,bc ;bc + d == a<<4 + d
941 ;--------------------------------------------------------------
946 ; OP: ahl = (bankbase<<12) + (d<<8) + e
948 ;out ahl: Phys. (linear) Address
973 add hl,bc ;bc + d == a<<4 + d
983 ;----------------------------------------------------------------------
988 jr nc,b2p_1 ;A15=1 --> common
997 ;--------------------------------------------------------------
1011 ; ---------------------------------------------------------
1018 ; Trampoline for interrupt routines in banked ram.
1019 ; Switch stack pointer to "system" stack in top ram
1023 ex (sp),hl ; save hl, return adr in hl
1060 ; ---------------------------------------------------------
1087 ; ---------------------------------------------------------
1092 sp.int.len equ $-sp.int0
1112 ; ---------------------------------------------------------
1117 ; This routine may not be loaded in page zero
1119 ; return Carry clear, if INTs are enabled.
1123 xor a ;clear accu and carry
1124 push af ;stack bottom := 00xxh
1126 ld a,i ;P flag := IFF2
1127 ret pe ;exit carry clear, if enabled
1129 dec sp ;has stack bottom been overwritten?
1131 and a ;if not 00xxh, INTs were
1132 ret nz ;actually enabled
1133 scf ;Otherwise, they really are disabled
1136 ;----------------------------------------------------------------------
1170 ret c ;INTs were disabled
1174 ;----------------------------------------------------------------------
1209 ret nc ;INTs were disabled
1215 ;----------------------------------------------------------------------
1253 global mm_sio0, mm_sio1
1255 @cbnk: db 0 ; current bank (0..2)
1264 ;----------------------------------------------------------------------
1274 ;-----------------------------------------------------
1287 ds 512/4 ;Number of 4k blocks
1288 alv_len equ $-memalv
1289 crc_len equ $-banktabsys
1299 ;ivtab equ 0ffc0h ; 0ffc0h ;int vector table
1303 mark_55AA equ 0fffch