page 255 .z80 global mmuinit global bnk2log,bnk2phy,hwl2phy include config.inc include z180reg.inc ;---------------------------------------------------------------------- ; Memory Map: ; ; Common CAStart ... 0FFFF ; Bank 0 00000 ... CAStart-1 ; Bank 1 10000 ... ; Bank 2 ; ;---------------------------------------------------------------------- cseg mmuinit: ld a,USR$CBAR out0 (cbar),a ret ;-------------------------------------------------------------------- ; Return the BBR value for the given bank number ; ; in a: Bank number ; out a: bbr value bnk2log: or a ; ret z ; Bank 0 is at physical address 0 dec a push bc ; ld b,a ; ld c,CA ; mlt bc ; bank size * bank number ld a,c ; add a,10h ; add bank0 + common pop bc ; ret ; ;-------------------------------------------------------------- ;in hl: Log. Address ; a: Bank number ; ;out ahl: Phys. (linear) Address bnk2phy: call bnk2log ; fall thru ;-------------------------------------------------------------- ; ; hl: Log. Address ; a: Bank base (bbr) ; ; 2 0 0 ; 0 6 8 0 ; hl hhhhhhhhllllllll ; a + bbbbbbbb ; ; OP: ahl = (a<<12) + (h<<8) + l ; ;out ahl: Phys. (linear) Address log2phy: push bc ; l2p_i: ld c,a ; ld b,16 ; mlt bc ; bc = a<<4 ld a,c ; add a,h ; ld h,a ; ld a,b ; adc a,0 ; pop bc ; ret ; ;-------------------------------------------------------------- ; ; de: Log. Address ; ; ; OP: ahl = (bankbase<<12) + (d<<8) + e ; ;out ahl: Phys. (linear) Address hwl2phy: push bc ; in0 c,(cbar) ; ld a,h ; or 00fh ; log. addr in common1? cp c jr c,hlp_1 in0 a,(cbr) ; yes, cbr is address base jr hl2p_x hlp_1: ld b,16 ; log. address in baked area? mlt bc ld a,h cp c jr c,hlp_2 in0 a,(bbr) ; yes, bbr is address base jr hl2p_x hlp_2: xor a ; common1 hl2p_x: jr nz,l2p_i pop bc ; bank part is 0, no translation ret ; ;==================================================================== if 0 ;-------------------------------------------------------------------- ; Return the BBR value for the given bank number bnk2bbr: or a ; 4 ret z ; 5/10 | 11 14 push bc ;11 | 11 ld b,a ; 4 ld c,CA ; 6 mlt bc ;17 >45 ld a,c ; 4 add a,10h ; 6 pop bc ; 9 | 10 ret ; 9 | 10 76 push ix ;2 / 14 | 15 ld ix,bnktbl ;4 / 12 | 14 ld ($+3+2),a ;3 / 15 | 19 ld a,(ix+0) ;3 / 14 | 19 pop ix ;2 / 12 | 14 ret ;1 / 9 | 10 15 / 76|91 push hl ;1 / 11 | 11 ld hl,bnktbl ;3 / 9 | 10 add a,l ;1 / 4 | 4 ld l,a ;1 / 4 | 4 ld a,0 ;1 / 6 | 7 adc a,h ;1 / 4 | 4 ld h,a ;1 / 4 | 4 ld a,(hl) ;1 / 6 | 7 pop hl ;1 / 9 | 10 ret ;1 / 9 | 10 12 / 66|71 push hl ;1 / 11 | 11 add a,low bnktbl ;2 / 6 | 7 ld l,a ;1 / 4 | 4 ld a,0 ;1 / 6 | 7 adc a,high bnktbl ;2 / 6 | 7 ld h,a ;1 / 4 | 4 ld a,(hl) ;1 / 6 | 7 pop hl ;1 / 9 | 10 ret ;1 / 9 | 10 11 / 61|67 endif end