Skip to content

Instantly share code, notes, and snippets.

@S0urceror
Created August 14, 2021 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save S0urceror/63ffbd58b9e58c083c12fb9b071a24d7 to your computer and use it in GitHub Desktop.
Save S0urceror/63ffbd58b9e58c083c12fb9b071a24d7 to your computer and use it in GitHub Desktop.
org 08000h
ld hl, 08000h ; this memory area
call Memory_GetSlot
call GET_SLTWRK_FOR_SLOT
; retrieve pointer from SLTWRK area
ld e,(hl)
inc hl
ld d,(hl)
; do something with it
;
;
ret
GET_SLTWRK_FOR_SLOT:
; formula: SLTWRK address = FD09H + 32*primary slot + 8*expansion slot + 2*page
ld b, a
and 00000011b; select primary slot
ld hl,0
ld l,a
add hl, hl
add hl, hl
add hl, hl
add hl, hl
add hl, hl; multiply by 32
ld a, b
and 00001100b; select extended slot
sla a; times 2
ld de, 0
ld e, a
add hl, de
ld de, SLTWRK
add hl, de
ld a, (hl)
ld e, a
inc hl
ld a, (hl)
ld d, a
ld hl, de
or a ; clear Cy
ret
; h = memory address high byte (bits 6-7: page)
; a <- slot ID formatted FxxxSSPP
; Modifies: f, bc, de
Memory_GetSlot:
call BIOS_RSLREG
bit 7,h
jr z,PrimaryShiftContinue
rrca
rrca
rrca
rrca
PrimaryShiftContinue:
bit 6,h
jr z,PrimaryShiftDone
rrca
rrca
PrimaryShiftDone:
and #0b00000011
ld c,a
ld b,#0
ex de,hl
ld hl,#BIOS_EXPTBL
add hl,bc
ld a,(hl)
and #0x80
or c
ld c,a
inc hl ; move to SLTTBL
inc hl
inc hl
inc hl
ld a,(hl)
ex de,hl
bit 7,h
jr z,SecondaryShiftContinue
rrca
rrca
rrca
rrca
SecondaryShiftContinue:
bit 6,h
jr nz,SecondaryShiftDone
rlca
rlca
SecondaryShiftDone:
and #0b00001100
or c
ld l, a
ret
@D15C0DE
Copy link

D15C0DE commented Aug 15, 2021

Allocating more memory in page 3 leads to all kinds of compatibility problems. It's too short-sighted.

@S0urceror
Copy link
Author

S0urceror commented Aug 15, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment