page0 = 1
page1 = 2
-page2 = 3
+page2 = 4
.area SM (abs,ovr)
; long ops
page0_stkld_l:
+stkld_l:
rst 8 ; ld hl,(bc)+
add hl,sp
- call ld_l
+ call ld_l0
jr dispatch2
page0_stkst_l:
+stkst_l:
rst 8 ; ld hl,(bc)+
add hl,sp
- call st_l
+ call st_l0
jr dispatch0
page0_imm_l:
+imm_l:
; ld a,(bc)
; inc bc
; exx
; exx
; inc h ; page 1
; jr page0_imm_w
- call imm_l
+ call imm_l0
dispatch2:
ld a,(bc)
inc bc
page0_ld_l:
pop hl
- call ld_l
+ld_l:
+ call ld_l0
jr dispatch2
page0_st_l:
pop hl
exx
pop de
+st_l:
pop hl
- call st_l
+ call st_l0
jr dispatch0
page0_imm_st_l:
- call imm_l
pop hl
- call st_l
+imm_st_l:
+ call imm_l0
+ call st_l0
jr dispatch0
; less used long ops
page0_imm_xchg_l:
- call imm_l
- ;call xchg_l
- ;jr dispatch0
- jr xchg_entry
+ call imm_l0
+ jp xchg_l0
page0_xchg_l:
- exx
- pop hl
- exx
- pop de
-xchg_entry:
- call xchg_l
- jr dispatch0
+ jp xchg_l
; less used word ops
dec h ; page 0
jp _call
+page1_ld_l:
+ ex de,hl
+ jp ld_l
+page1_imm_st_l:
+ ex de,hl
+ jp st_l
+
page1_imm_and_w:
ld a,(bc)
inc bc
ld h,page1
jp (hl)
-page1_imm_xor_w:
- ld a,(bc)
- inc bc
- xor e
- ld e,a
- ld a,(bc)
- inc bc
- xor d
- ld d,a
- ld a,(bc)
- inc bc
- ld l,a
- jp (hl)
-
-;page1_imm_xor_w: ; xor is less common than and/or, so save space for immediate
+;page1_imm_xor_w:
; ld a,(bc)
-; ld l,a
; inc bc
+; xor e
+; ld e,a
; ld a,(bc)
-; ld h,a
; inc bc
-; .db 0x3e ; ld a,
+; xor d
+; ld d,a
+; ld a,(bc)
+; inc bc
+; ld l,a
+; jp (hl)
+
+page1_imm_xor_w: ; xor is less common than and/or, so save space for immediate
+ ld a,(bc)
+ ld l,a
+ inc bc
+ ld a,(bc)
+ ld h,a
+ inc bc
+ .db 0x3e ; ld a,
page1_xor_w:
pop hl
ld a,e
pop bc
ret
+; long math package (reachable from page 2)
+
+xchg_l:
+ exx
+ pop hl
+ exx
+ pop de
+xchg_l0:
+ exx
+ pop de
+ exx
+ pop hl
+ push de
+ exx
+ push hl
+ exx
+ push hl
+ exx
+ push de
+ exx
+ ld a,(bc)
+ inc bc
+ ld l,a
+ ld h,page2
+ jp (hl)
+
+; page 2 interpreter
+; long arithmetic operations
+; top stack long cached in de:hl'
+
+ .org page2 * 0x100
+
+page2_imm_call:
+ jp imm_call
+page2_stkadj:
+ exx
+ push hl
+ exx
+ push de
+ jp stkadj
+page2_stkptr:
+ exx
+ push hl
+ exx
+ push de
+ jp stkptr
+page2_stkld_l:
+ exx
+ push hl
+ exx
+ push de
+ jp stkld_l
+page2_stkst_l:
+ jp stkst_l
+page2_imm_l:
+ exx
+ push hl
+ exx
+ push de
+ jp imm_l
+page2_st_l:
+ jp st_l
+
+page2_page0:
+ exx
+ push hl
+ exx
+ push de
+ ld a,(bc)
+ inc bc
+ ld l,a
+ ld h,page0
+ jp (hl)
+
; long math package
-imm_l:
+imm_l0:
ld a,(bc)
inc bc
exx
ld d,a
ret
-ld_l:
+ld_l0:
ld a,(hl)
inc hl
exx
ld d,(hl)
ret
-st_l:
+st_l0:
exx
ld a,l
exx
ld (hl),d
ret
-xchg_l:
- exx
- pop de
- exx
- pop hl
- push de
- exx
- push hl
- exx
- push hl
- exx
- push de
- exx
- ret
-
; non-restoring division routine
; de = divisor, hl:a = dividend with hl = previous remainder, a = next byte