In native_words.asm:
Save 4 bytes with:
Code:
_stack_ok:
; Display system prompt if all went well. If we're interpreting,
; this is " ok", if we're compiling, it's " compiled"
lda state
beq _print ; zero is "ok" string
lda #1 ; one is "compiled" string
_print:
jsr print_string
; Awesome line, everybody! Now get the next one
bra _get_line
z_cold:
z_abort:
z_quit: ; no RTS required
Save 6 bytes with:
Code:
; ## BOUNDS ( addr u -- addr+u addr ) "Prepare address for looping"
; ## "bounds" src: Gforth b: 36 c: TBA status: tested
; """Given a string, return the correct Data Stack parameters for
; a DO/LOOP loop; over its characters. This is realized as
; OVER + SWAP in Forth, but we do it a lot faster in assembler
; """
xt_bounds:
cpx #dsp0-3
bmi +
lda #11 ; underflow
jmp error
*
clc
lda 0,x ; <u
ldy 2,x ; <addr
adc 2,x
sta 2,x ; <(addr+u)
sty 0,x ; <addr
lda 1,x ; >u
ldy 3,x ; >addr
adc 3,x
sta 3,x ; >(addr+u)
sty 1,x ; >addr
z_bounds: rts
Save 1 byte with:
Code:
; ## CELL_PLUS ( u -- u ) "Add cell size in bytes"
; ## "cell+" src: ANSI core b: 22 c: TBA status: tested
; """Add the number of bytes ("address units") that one cell needs.
; Since this is an 8 bit machine with 16 bit cells, we add two bytes.
; """
.scope
xt_cell_plus:
cpx #dsp0-1
bmi +
lda #11
jmp error
*
inc 0,x
bne +
inc 1,x
*
inc 0,x
bne z_cell_plus
inc 1,x
z_cell_plus: rts
.scend
Save 13 bytes with:
Code:
; ## CMOVE ( addr1 addr2 u -- ) "Copy bytes going from low to high"
; ## "cmove" src: ANSI string b: 78 c: TBA status: coded
; """Copy u bytes from addr1 to addr2, going low to high (addr2 is
; larger than addr1). Based on code in Leventhal, Lance A.
; "6502 Assembly Language Routines", p. 201
; """
.scope
xt_cmove:
cpx #dsp0-5
bmi +
lda #11 ; underflow
jmp error
*
; move dst address to where we can work with it
lda 2,x
sta tmp2 ; use tmp2 because easier to remember
lda 3,x
sta tmp2+1
; move src address to where we can work with it
lda 4,x
sta tmp1 ; use tmp1 because easier to remember
lda 5,x
sta tmp1+1
ldy #0
lda 1,x ; number of whole pages to move
beq _dopartial
_page:
lda (tmp1),y
sta (tmp2),y
iny
bne _page
inc tmp1+1
inc tmp2+1
dec 1,x
bne _page
_dopartial:
lda 0,x ; length of last page
beq _done
_partial:
lda (tmp1),y
sta (tmp2),y
iny
dec 0,x
bne _partial
_done: ; clear the stack
txa
clc
adc #6
tax
z_cmove: rts
.scend
Save 28 bytes with:
Code:
; ## CMOVE_UP ( add1 add2 u -- ) "Copy bytes from high to low"
; ## "cmove>" src: ANSI string b: 93 c: TBA status: coded
; """Note addr1 is larger than ; ; addr2). Based on code in
; Leventhal, Lance A. "6502 Assembly Language Routines", p. 201.
; """
.scope
xt_cmove_up:
cpx #dsp0-5
bmi +
lda #11 ; underflow
jmp error
*
; move dst address to where we can work with it
lda 2,x
sta tmp2 ; use tmp2 because easier to remember
lda 3,x
clc
adc 1,x
sta tmp2+1 ; point to last page of destination
; move src address to where we can work with it
lda 4,x
sta tmp1 ; use tmp1 because easier to remember
lda 5,x
clc
adc 1,x
sta tmp1+1 ; point to last page of source
inc 1,x ; allows us to use bne with dec 1,x below
; move the last partial page first
ldy 0,x ; length of last page
beq _nopartial
_outerloop:
dey
beq _finishpage
_innerloop:
lda (tmp1),y
sta (tmp2),y
dey
bne _innerloop
_finishpage:
lda (tmp1) ; handle y = 0 separately
sta (tmp2)
_nopartial:
dec tmp1+1 ; back up to previous pages
dec tmp2+1
dec 1,x
bne _outerloop
_done:
; clear up the stack and leave
txa
clc
adc #6
tax
z_cmove_up: rts
.scend
These are all untested, and cmove_up is highly experimental.
Mike B.