From 32ec1e9df4ddfe3b19f1307874e81e7d1d87c0df Mon Sep 17 00:00:00 2001 From: mgcaret Date: Sat, 4 Jan 2020 16:25:41 -0800 Subject: [PATCH] resolve #6; general clean-up --- asm/forth-dictionary.s | 16 ++++++---- asm/interpreter.s | 66 ------------------------------------------ asm/mathlib.s | 1 + asm/memmgr.s | 48 ++++++++++++++++++------------ 4 files changed, 41 insertions(+), 90 deletions(-) diff --git a/asm/forth-dictionary.s b/asm/forth-dictionary.s index 351f8e8..89a0464 100644 --- a/asm/forth-dictionary.s +++ b/asm/forth-dictionary.s @@ -3102,7 +3102,7 @@ getbuf: lda [SYSVARS],y ; get buffer pointer setbuf1: ldy #SV_SBUF1 ; select buf 1 setbuf: pla ; update pointers sta YR ; in YR - sta [SYSVARS],y ; in the appropriate system var + sta [SYSVARS],y ; in the appropriate system var sta STACKBASE+4,x ; in the parameter stack iny iny @@ -3110,7 +3110,8 @@ setbuf: pla ; update pointers sta YR+2 sta [SYSVARS],y sta STACKBASE+6,x - jsr _move + sec ; move down is faster + jsr _memmove NEXT nomem: ldy #.loword(-18) lda #.hiword(-18) @@ -3779,7 +3780,7 @@ dword MOVE,"MOVE" jsr _popxr jsr _popyr jsr _popwr - jsr _move + jsr _memmove NEXT eword @@ -3793,7 +3794,8 @@ dword CMOVEUP,"CMOVE>" jsr _popxr jsr _popyr jsr _popwr - jsr _moveup + clc + jsr _memmove_c NEXT eword @@ -4483,7 +4485,8 @@ dword PACK,"PACK" inc YR bne :+ inc YR+2 -: jsr _move +: sec ; move down is faster + jsr _memmove_c NEXT bad: ldy #.loword(-18) lda #.hiword(-18) @@ -5396,7 +5399,8 @@ hword SCONCAT,"SCONCAT" lda XR+2 adc STACKBASE+2,x sta STACKBASE+2,x - jsr _move ; move the string + sec ; move down is faster + jsr _memmove_c ; move the string NEXT eword diff --git a/asm/interpreter.s b/asm/interpreter.s index 8b64372..d3b4230 100644 --- a/asm/interpreter.s +++ b/asm/interpreter.s @@ -899,72 +899,6 @@ good: sec .endproc .a16 -; Move XR bytes from [WR] to [YR], starting at the bottom -; trashes WR, YR, and XR -; could be optimized to move words, excepting the last one if odd number of bytes -; use for moving data downward, but that adds two comparison instructions which -; are slower than the SEP/REP, maybe -.proc _move -.if 1 ; fast move in memmgr.s - sec - jmp _memmove_c -.else ; slower but smaller move -lp: lda XR+2 ; see if zero bytes - ora XR - bne :+ - rts -: jsr _decxr ; pre-decrement XR - sep #SHORT_A - lda [WR] - sta [YR] - rep #SHORT_A - jsr _incwr ; post increment WR - inc YR ; and YR - bne lp - inc YR+2 - bra lp -.endif -.endproc - -; Move XR bytes from [WR] to [YR], starting at the top -; trashes YR and XR -; could be optimized to move words, excepting the last one if odd number of bytes -; use for moving data upward -.proc _moveup -.if 1 ; fast move in memmgr.s - clc - jmp _memmove_c -.else ; slower but smaller move -lp: jsr _wrplusxr - lda WR ; move WR to 1 past the end of the block - clc - adc XR - sta WR - lda WR+2 - adc XR+2 - sta WR+2 - lda YR ; move YR to 1 past the end of the block - clc - adc XR - sta YR - lda YR+2 - adc XR+2 - sta YR+2 - lda XR+2 - ora XR - bne :+ - rts -: jsr _decxr ; decrement XR - jsr _decwr ; and WR - jsr _decyr ; and YR - sep #SHORT_A - lda [WR] - sta [YR] - rep #SHORT_A - bra lp -.endif -.endproc - ; With word header address in YR, set YR to previous dictionary entry header ; return with Z flag set if the new address is zero .proc _prevword diff --git a/asm/mathlib.s b/asm/mathlib.s index 342862b..0c06f2c 100644 --- a/asm/mathlib.s +++ b/asm/mathlib.s @@ -20,6 +20,7 @@ samesign: lda STACKBASE+6,x cmp STACKBASE+0,x : rts .endproc +_test32 = _stest32::samesign .proc _invertay pha diff --git a/asm/memmgr.s b/asm/memmgr.s index c6bcbf0..f4316a5 100644 --- a/asm/memmgr.s +++ b/asm/memmgr.s @@ -419,17 +419,16 @@ loop: jsr _chk_himem done: rts .endproc -.if 1 ; include fast memory move routines ; Memory move routines ; move XR bytes of memory from [WR] to [YR] -; Move appropriately based +; Move appropriately based on source and destination .proc _memmove lda WR cmp YR lda WR+2 sbc YR+2 - ; now carry is set if WR >= XR, move down in that case, otherwise move up + ; now carry is set if WR >= YR, move down in that case, otherwise move up ; fall-through .endproc @@ -509,7 +508,7 @@ md6: pha jsl f:_callzr plb pla - eor #$ffff ; a xor $ffff = $ffff - a = -1 - a + eor #$FFFF ; a xor $FFFF = $FFFF - a = -1 - a adc sizel sta sizel ; sizel = sizel - 1 - a sep #$20 @@ -517,10 +516,9 @@ md6: pha lda sizeh ; update high byte of size sbc #$00 bcs md1 - rep #$30 + plp .a16 .i16 - plp plx rts .endproc @@ -533,11 +531,27 @@ tol = YR sizeh = XR+2 sizel = XR mu7 = ZR + ; first convert start addresses to end addresses + lda WR + clc + adc XR + sta WR + lda WR+2 + adc XR+2 + sta WR+2 + lda YR + clc + adc XR + sta YR + lda YR+2 + adc XR+2 + sta YR+2 + ; now start the move phx php lda #$6B00 ; RTL sta mu7+2 - lda #$0054 ; MVN + lda #$0044 ; MVP sta mu7 sep #$21 ; 8-bit accumulator, set carry .a8 @@ -557,25 +571,25 @@ mu7 = ZR cmp froml bcs mu3 bra mu4 - .a8 + .a8 ; a is 8 bits when we branch to mu1! mu1: sta sizeh - eor #$80 ; set v if size is zero, clear v otherwise + eor #$80 ; set v if size is zero, clear v otherwise sbc #$01 cpx #$FFFF - bne mu2 ; if x is not $FFFF, then y must be + bne mu2 ; if x is not $FFFF, then y must be dec mu7+2 rep #$20 .a16 tya cpy #$FFFF bne mu4 - .a8 sep #$20 + .a8 mu2: dec mu7+1 rep #$20 .a16 mu3: txa -mu4: bvc mu5 ; branch if sizeh is nonzero +mu4: bvc mu5 ; branch if sizeh is nonzero cmp sizel bcc mu6 lda sizel @@ -585,18 +599,17 @@ mu6: pha jsl f:_callzr plb pla - eor #$FFFF ; a xor $FFFF = $FFFF - a = -1 - a + eor #$FFFF ; a xor $FFFF = $FFFF - a = -1 - a adc sizel - sta sizel ; sizel = sizel - 1 - a + sta sizel ; sizel = sizel - 1 - a sep #$20 .a8 - lda sizeh ; update high byte of size + lda sizeh ; update high byte of size sbc #$00 bcs mu1 - rep #$30 + plp .a16 .i16 - plp plx rts .endproc @@ -623,4 +636,3 @@ mu6: pha pla ; ( 0 zrh zrl ah al -- 0 zrh zrl ) rtl ; ( 0 zrh zrl -- ) .endproc -.endif