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
256 pop de ;get ptr to 'function address' in de
259 push hl ;put return address on stack
266 cp high (bs$stack-bs$stack$size) ;link80 can't process this
267 jr nc,$ + 5 ;skip if stack allready in common bios ram
271 ld hl,bs$stack-bs$stack$size
277 jr c,$ + 5 ;skip if stack allready in common bios ram
281 push hl ;save user stack pointer
290 ld e,(hl) ;get 'function address'
293 push de ;put on (switched) stack
295 ld hl,(b0_save_af) ;get back users registers
319 pop de ;get ptr to 'function address' in de
322 push hl ;put return address on stack
329 cp high (bs$stack-bs$stack$size) ;link80 can't process this
330 jr nc,$ + 5 ;skip if stack allready in common bios ram
334 ld hl,bs$stack-bs$stack$size
340 jr c,$ + 5 ;skip if stack allready in common bios ram
344 push hl ;save user stack pointer
353 ld e,(hl) ;get 'function address'
356 push de ;put on (switched) stack
358 ld hl,(b0_save_af) ;get back users registers
380 ;--------------------------------------------------------------------
381 ; Trampoline for interrupt routines in banked ram.
382 ; Switch stack pointer to "system" stack in top ram
390 ex (sp),hl ;save hl, 'return adr' in hl
393 ex de,hl ;'return address' in de
401 cp high (bs$stack-bs$stack$size) ;link80 can't process this
402 jr nc,$ + 5 ;skip if stack allready in common bios ram
406 ld hl,bs$stack-bs$stack$size
412 jr c,$ + 5 ;skip if stack allready in common bios ram
420 push hl ;save user stack pointer
447 ex (sp),hl ;save hl, 'return adr' in hl
449 ld (istack),sp ;save user stack pointer
481 ;--------------------------------------------------------------------
482 ; Load byte/word from user ram
484 ; de: src address in users bank
491 or a ; clear carry == byte store
494 scf ; set carry == word store
496 push hl ; make space on stack
499 ld b,a ; b = src bank
503 ld c,l ; c = dst bank (0)
516 ;--------------------------------------------------------------------
517 ; Store byte/word to user ram
519 ; de: dst address in users bank
526 or a ; clear carry == byte store
529 scf ; set carry == word store
531 push hl ; put value on stack
534 ld c,a ; c = dst bank
538 ld b,a ; b = src bank (0)
544 pop hl ; restore value
550 ;--------------------------------------------------------------------
559 out0 (bcr0l),a ; setup DMA count
566 out0 (sar0l),l ; setup DMA src address
574 out0 (dar0l),l ; setup DMA dst address
578 ld a,M_MMOD ; DMA burst mode
580 ld a,M_DE0+M_NDWE1 ; enable DMA0
581 out0 (dstat),a ; move ...
586 ;====================================================================
592 ;--------------------------------------------------------------------
593 ; Return the BBR value for the given bank number
609 ld ix,bnktbl ;4 / 12 | 14
610 ld ($+3+2),a ;3 / 15 | 19
611 ld a,(ix+0) ;3 / 14 | 19
613 ret ;1 / 9 | 10 15 / 76|91
616 ld hl,bnktbl ;3 / 9 | 10
624 ret ;1 / 9 | 10 12 / 66|71
627 add a,low bnktbl ;2 / 6 | 7
630 adc a,high bnktbl ;2 / 6 | 7
634 ret ;1 / 9 | 10 11 / 61|67