6 extrn charini,?const,?conin
21 ;----------------------------------------------------------------------
37 ;----------------------------------------------------------------------
51 dmclrt: ;clear ram per dma
54 dw nullbyte ;src (fixed)
57 dw romend ;dst (inc), start after "rom" code
59 dw 0-romend ;count (64k)
64 INIWAITS defl INIWAITS+CWAITROM
69 db rcr,CREFSH ;configure DRAM refresh
70 db dcntl,INIWAITS ;wait states
73 ;----------------------------------------------------------------------
79 in0 a,(itc) ;Illegal opcode trap?
81 ld a,i ;I register == 0 ?
82 jr z,??st02 ; yes, harware reset
87 pop af ;restore registers
94 out0 (rcr),a ; configure DRAM refresh
96 out0 (dcntl),a ; wait states
98 ld a,M_NCD ;No Clock Divide
100 ; ld a,M_X2CM ;X2 Clock Multiplier
103 ; search warm start mark
105 ld ix,mark_55AA ;00b8 ; top of common area
109 ex af,af' ;00be ;for cbr = 0x70 downto 0x40
114 jr z,kstart ;00c3 ; break (mark not found)
127 ld sp,$stack ;00e0 mark found, check
128 call checkcrc_alv ;00e3
129 jp z,wstart ;00e6 check ok,
132 ; ram not ok, initialize -- kstart --
136 ld a,088h ;00e9 0000-7fff: common 0
137 out0 (cbar),a ;00eb 8000-ffff: common 1
139 ld a,0 ;00f1 start at 008000 (2. phys. 32k block)
147 add a,8 ;010a next 'bank'
148 cp 078h ;010c stop at 078000
151 ld de,8000h ;0114 first block not tested, but mark as ok
152 ld a,0 ;00f1 start at 008000 (2. phys. 32k block)
169 cp 078h ; stop at 078000
173 ; ram test found 1 or more error free blocks (32k)
181 ld c,070h ;01ce highest block
185 jr c,alloc ;01d4 highest "error free" block
191 slp ;01dc should never be reached
199 ; Clear RAM using DMA0
201 ld hl,dmclrt ;load DMA registers
203 ld a,0cbh ;01ef dst +1, src fixed, burst
207 ld a,062h ;01f4 enable dma0,
209 out0 (dstat),a ;01f9 clear (up to) 64k
210 djnz ??cl_1 ; end of RAM?
214 ld hl,banktabsys ;020f
215 ld (hl),c ; Common area
217 ld (hl),c ; System work area
218 inc hl ;0215 Point to bank 0 entry
221 ld (hl),0ffh ;0218 Mark all banks as unassigned
226 ld b,8 ; 8*4k ie. first 32k
228 ld (hl),0e0h ; mark as sys ("rom"/monitor)
232 rr d ; shift out bit for block 0
234 ld c,15 ;022c 15*32k remaining blocks
236 ld a,0feh ; 0xfe == block with error(s)
239 adc a,0 ; ==> 0xff : block ok
240 ld b,32/4 ; 32k == 8 * 4k
246 jr nz,l022eh ;next 32k block
248 ld hl,memalv+0ch ;memalv+0ch
253 ld (hl),0ech ;alloc system ram
256 ld (hl),0efh ;alloc common
260 ld bc,0f0fh ; size (?) (4k blocks)
262 call sub_0420h ;alloc mem for bank 0
275 ld hl,055AAh ;set warm start mark
280 ; crc ok -- wstart --
283 call sysram_init ;027f
313 ;----------------------------------------------------------------------
316 ;TODO: Make a ringbuffer module.
326 ;----------------------------------------------------------------------
328 extrn msginit,msg_tx_fifo,msg_rx_fifo
370 ;----------------------------------------------------------------------
373 extrn msginit,msg.sout
374 extrn mtx.fifo,mrx.fifo
375 extrn co.fifo,ci.fifo
422 buftablen equ ($ - buffers)/3
437 ;----------------------------------------------------------------------
443 ld bc,sysrame-sysramw
448 ;----------------------------------------------------------------------
456 ; Let all vectors point to spurious int routines.
470 ;----------------------------------------------------------------------
487 db prt0it_e-prt0itab-2
491 db M_TIE0+M_TDE0 ;enable timer 0 interrupt and down count.
496 ;----------------------------------------------------------------------
501 ld b,0 ;high byte port adress
505 ld c,(hl) ;port address
508 inc b ;outi decrements b
527 ;----------------------------------------------------------------------
577 ld hl,banktabsys ;03f9
593 ld hl,banktabsys ;040d
594 ld bc,crc_len+2 ;0410
601 ;----------------------------------------------------------------------
614 ; 2 == no bank # in requested range
619 call checkcrc_alv ;0420
620 jr nz,l049ch ;0424 crc error, tables corrupt
622 call sub_049dh ;0427 bank # in req. range available?
639 inc a ;043e free blocks are marked 0ffh
647 pop ix ;0447 free blocks start here
650 l044dh: ; count free blocks
660 ; end of free blocks run.
664 cp e ;0458 nr of blocks >= requested ?
705 call gencrc_alv ;048e
720 ; search a free bank number in range
724 ; l: bank number available
725 ; nc, if found, bank nr. in l
734 inc e ;04a1 test next #
741 cpir ;04ad bank# allready allocated?
742 jr z,l04a1h ;04af if yes, search for next
759 call gencrc_alv ;04c4
761 or a ;04c8 clear carry
765 ;--------------------------------------------------------------
770 ;out ahl: Phys. (linear) Address
781 ;--------------------------------------------------------------
786 ; OP: ahl = (a<<12) + (d<<8) + e
788 ;out ahl: Phys. (linear) Address
798 add hl,bc ;bc + d == a<<4 + d
806 ;--------------------------------------------------------------
820 ; ---------------------------------------------------------
827 ; Trampoline for interrupt routines in banked ram.
828 ; Switch stack pointer to "system" stack in top ram
832 ex (sp),hl ; save hl, return adr in hl
869 ; ---------------------------------------------------------
893 ; ---------------------------------------------------------
898 sp.int.len equ $-sp.int0
926 ;-----------------------------------------------------
937 ds 512/4 ;Number of 4k blocks
939 crc_len equ $-banktabsys
947 ;ivtab equ 0ffc0h ; 0ffc0h ;int vector table