page0 = 1
page1 = 2
+page2 = 3
.area SM (abs,ovr)
.org page0 * 0x100
- jp start
+; administrative
page0_trace:
- jp print_trace
+ jp start ; will be overwritten with print_trace
page0_esc:
ld l,c
ld h,b
jp (hl)
+page0_page2:
+ exx
+ pop hl
+ exx
+ inc h ; page 1
page0_page1:
pop de
ld a,(bc)
inc bc
ld l,a
- inc h ; page 1
+ inc h ; page 1 (or 2 if came from page0_page2)
+ jp (hl)
+
+; long ops
+
+page0_stkld_l:
+ rst 8 ; ld hl,(bc)+
+ add hl,sp
+ call ld_l
+ jr dispatch2
+
+page0_stkst_l:
+ rst 8 ; ld hl,(bc)+
+ add hl,sp
+ call st_l
+ jr dispatch0
+
+page0_imm_l:
+; ld a,(bc)
+; inc bc
+; exx
+; ld l,a
+; exx
+; ld a,(bc)
+; inc bc
+; exx
+; ld h,a
+; exx
+; inc h ; page 1
+; jr page0_imm_w
+ call imm_l
+dispatch2:
+ ld a,(bc)
+ inc bc
+ ld l,a
+ ld h,page2
jp (hl)
+page0_ld_l:
+ pop hl
+ call ld_l
+ jr dispatch2
+
+page0_st_l:
+ exx
+ pop hl
+ exx
+ pop de
+ pop hl
+ call st_l
+ jr dispatch0
+
+page0_imm_st_l:
+ call imm_l
+ pop hl
+ call st_l
+ jr dispatch0
+
+; less used long ops
+
+page0_imm_xchg_l:
+ call imm_l
+ ;call xchg_l
+ ;jr dispatch0
+ jr xchg_entry
+page0_xchg_l:
+ exx
+ pop hl
+ exx
+ pop de
+xchg_entry:
+ call xchg_l
+ jr dispatch0
+
+; less used word ops
+
page0_imm_xchg_w:
ld a,(bc)
inc bc
pop hl
ex (sp),hl
push hl
- ld a,(bc)
- inc bc
- ld l,a
- ld h,page0
- jp (hl)
+ jr dispatch0
+
+; control transfer ops
page0_call:
pop de
ld l,a
jp (hl)
- .org page0 * 0x100 + 0x84
+ .org page0 * 0x100 + 0x86
+
+; stack ops (reachable from start of page 1)
imm_call:
push de
ld l,a
jp (hl)
-stkptr:
- push de
-page0_stkptr:
+page0_ret:
+ pop bc
+page0_stkadj:
+stkadj:
ld a,(bc)
inc bc
ld l,a
inc bc
ld h,a
add hl,sp
- ex de,hl
+ ld sp,hl
+dispatch0:
ld a,(bc)
inc bc
ld l,a
- ld h,page1
+ ld h,page0
jp (hl)
-page0_ret:
- pop bc
-page0_stkadj:
-stkadj:
+page0_stkptr:
+stkptr:
ld a,(bc)
inc bc
ld l,a
inc bc
ld h,a
add hl,sp
- ld sp,hl
+ ex de,hl
ld a,(bc)
inc bc
ld l,a
- ld h,page0
+ ld h,page1
jp (hl)
-stkld_w:
- push de
+; word ops
+
page0_stkld_w:
+stkld_w:
ld a,(bc)
inc bc
ld l,a
jp (hl)
page0_imm_w:
- inc h ; page1
+ inc h ; page1 (or page2 if came from page0_imm_l)
imm_w:
ld a,(bc)
inc bc
page1_imm_call:
jr imm_call
-page1_stkptr:
- jr stkptr
page1_stkadj:
push de
jr stkadj
+page1_stkptr:
+ push de
+ jr stkptr
page1_stkld_w:
+ push de
jr stkld_w
page1_stkst_w:
jr stkst_w
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
ld h,page0
jp (hl)
-; math package
+; word math package
imm_sl_w:
ex de,hl
pop bc
ret
+; long math package
+
+imm_l:
+ ld a,(bc)
+ inc bc
+ exx
+ ld l,a
+ exx
+ ld a,(bc)
+ inc bc
+ exx
+ ld h,a
+ exx
+ ld a,(bc)
+ inc bc
+ ld e,a
+ ld a,(bc)
+ inc bc
+ ld d,a
+ ret
+
+ld_l:
+ ld a,(hl)
+ inc hl
+ exx
+ ld l,a
+ exx
+ ld a,(hl)
+ inc hl
+ exx
+ ld h,a
+ exx
+ ld e,(hl)
+ inc hl
+ ld d,(hl)
+ ret
+
+st_l:
+ exx
+ ld a,l
+ exx
+ ld (hl),a
+ inc hl
+ exx
+ ld a,h
+ exx
+ ld (hl),a
+ inc hl
+ ld (hl),e
+ inc hl
+ 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
; sm code
start:
+ ld hl,print_trace
+ ld (page0_trace + 1),hl
+
+ ld hl,rst8
+ ld de,8
+ ld bc,7
+ ldir
+
ld h,page0
call page0_jmp
.db <page0_imm_call
.db <page0_esc
jp 0
+rst8: ; ld hl,(bc)+
+ ld a,(bc)
+ inc bc
+ ld l,a
+ ld a,(bc)
+ inc bc
+ ld h,a
+ ret
+
sm_main:
; create stack frame
.db <page0_stkadj