6 public bnk2log,bnk2phy,hwl2phy,phy2log
8 public b_ld_a,b_ld_hl,b_st_a,b_st_hl
19 ;----------------------------------------------------------------------
22 ; Common CAStart .. 0FFFF
23 ; Bank 0 00000 .. CAStart-1
29 ; Common 18000 .. 1BFFF BANK1
31 ; Bank 0 00000 .. 0BFFF 0
32 ; Bank 1 0C000 .. 17FFF 1*BNK_SIZE
33 ; Bank 2 1C000 .. 27FFF 2*BNK_SIZE + CMN_SIZE
34 ; Bank 3 28000 .. 33FFF 3*BNK_SIZE + CMN_SIZE
35 ; Bank n n*BNK_SIZE + (n < 2) ? 0 : CMN_SIZE
37 ;----------------------------------------------------------------------
46 ;--------------------------------------------------------------------
47 ; Return the BBR value for the given bank number
56 ret z ; Bank 0 is at physical address 0
62 mlt bc ; bank size * bank number
64 add a,10h ; add bank0 + common
72 ret z ; Bank 0 is at physical address 0
77 mlt bc ; bank size * bank number
101 ;--------------------------------------------------------------
106 ;out ahl: Phys. (linear) Address
118 ; address is in common
122 ld a,1 ; same as bank1
126 call bnk2log ; get address base
130 ;--------------------------------------------------------------
137 ; hl hhhhhhhhllllllll
140 ; OP: ahl = (a<<12) + (h<<8) + l
142 ;out ahl: Phys. (linear) Address
158 ;--------------------------------------------------------------
163 ; OP: ahl = (bankbase<<12) + (h<<8) + l
165 ;out ahl: Phys. (linear) Address
172 or 00fh ; log. addr in common1?
176 in0 a,(cbr) ; yes, cbr is address base
179 ld b,16 ; log. address in baked area?
184 in0 a,(bbr) ; yes, bbr is address base
191 pop bc ; bank part is 0, no translation
195 ;--------------------------------------------------------------
196 ; return logical bank 0 address for given physical address.
198 ; in: ahl: pyhsical addres (20 bit)
199 ; out hl: logical address.
200 ; logical address is in bank 0 or common, no bank number returned
219 ;--------------------------------------------------------------
220 ; Trampoline for routines in banked ram.
221 ; Switch stack pointer to "system" stack in top ram
224 ; HL: function pointer
232 ld hl,bs$stack-bs$stack$size
238 jr c,$ + 5 ;skip if stack allready in common bios ram
241 push hl ;save user stack pointer
264 ;--------------------------------------------------------------------
265 ; Trampoline for interrupt routines in banked ram.
266 ; Switch stack pointer to "system" stack in top ram
274 ex (sp),hl ;save hl, 'return adr' in hl
277 ex de,hl ;'return address' in de
285 cp high (bs$stack-bs$stack$size) ;link80 can't process this
286 jr nc,$ + 5 ;skip if stack allready in common bios ram
290 ld hl,bs$stack-bs$stack$size
296 jr c,$ + 5 ;skip if stack allready in common bios ram
304 push hl ;save user stack pointer
331 ex (sp),hl ;save hl, 'return adr' in hl
333 ld (i$stack),sp ;save user stack pointer
369 ;--------------------------------------------------------------------
370 ; Load byte/word from user ram
372 ; de: src address in users bank
379 or a ; clear carry == byte store
382 scf ; set carry == word store
384 push hl ; make space on stack
387 ld b,a ; b = src bank
391 ld c,l ; c = dst bank (0)
404 ;--------------------------------------------------------------------
405 ; Store byte/word to user ram
407 ; de: dst address in users bank
414 or a ; clear carry == byte store
417 scf ; set carry == word store
419 push hl ; put value on stack
422 ld c,a ; c = dst bank
426 ld b,a ; b = src bank (0)
432 pop hl ; restore value
438 ;--------------------------------------------------------------------
447 out0 (bcr0l),a ; setup DMA count
454 out0 (sar0l),l ; setup DMA src address
462 out0 (dar0l),l ; setup DMA dst address
466 ld a,M_MMOD ; DMA burst mode
468 ld a,M_DE0+M_NDWE1 ; enable DMA0
469 out0 (dstat),a ; move ...
474 ;====================================================================
480 ;--------------------------------------------------------------------
481 ; Return the BBR value for the given bank number
497 ld ix,bnktbl ;4 / 12 | 14
498 ld ($+3+2),a ;3 / 15 | 19
499 ld a,(ix+0) ;3 / 14 | 19
501 ret ;1 / 9 | 10 15 / 76|91
504 ld hl,bnktbl ;3 / 9 | 10
512 ret ;1 / 9 | 10 12 / 66|71
515 add a,low bnktbl ;2 / 6 | 7
518 adc a,high bnktbl ;2 / 6 | 7
522 ret ;1 / 9 | 10 11 / 61|67