Implement first part of page2 (redirections to page0 for load/store operations)
authorNick Downing <nick@ndcode.org>
Mon, 17 Jun 2019 00:23:17 +0000 (10:23 +1000)
committerNick Downing <nick@ndcode.org>
Mon, 17 Jun 2019 00:23:17 +0000 (10:23 +1000)
sm2.asm

diff --git a/sm2.asm b/sm2.asm
index 1839c51..674c811 100644 (file)
--- a/sm2.asm
+++ b/sm2.asm
@@ -1,6 +1,6 @@
 page0  =       1
 page1  =       2
-page2  =       3
+page2  =       4
 
        .area   SM (abs,ovr)
 
@@ -35,18 +35,21 @@ page0_page1:
 ; 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
@@ -59,7 +62,7 @@ page0_imm_l:
 ;      exx
 ;      inc     h ; page 1
 ;      jr      page0_imm_w
-       call    imm_l
+       call    imm_l0
 dispatch2:
        ld      a,(bc)
        inc     bc
@@ -69,7 +72,8 @@ dispatch2:
 
 page0_ld_l:
        pop     hl
-       call    ld_l
+ld_l:
+       call    ld_l0
        jr      dispatch2
 
 page0_st_l:
@@ -77,31 +81,25 @@ 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
 
@@ -368,6 +366,13 @@ page1_call:
        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
@@ -424,28 +429,28 @@ page1_or_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
@@ -828,9 +833,83 @@ divnn:     ; negative dividend, negative divisor
        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
@@ -849,7 +928,7 @@ imm_l:
        ld      d,a
        ret
 
-ld_l:
+ld_l0:
        ld      a,(hl)
        inc     hl
        exx
@@ -865,7 +944,7 @@ ld_l:
        ld      d,(hl)
        ret
 
-st_l:
+st_l0:
        exx
        ld      a,l
        exx
@@ -881,21 +960,6 @@ st_l:
        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