major refactor for more speed and smaller size

This commit is contained in:
Peter Ferrie 2015-08-14 14:05:48 -07:00
parent 7720b2c161
commit d79ef369fd

View File

@ -18,6 +18,7 @@ tok_empty equ 253
tok_eod equ 254 tok_eod equ 254
overrun_check equ 0 overrun_check equ 0
smaller equ 0
* *
* Variable storage * Variable storage
@ -59,13 +60,60 @@ entry
lda (srcptr),y lda (srcptr),y
cmp #lz4fh_magic ;does magic match? cmp #lz4fh_magic ;does magic match?
beq goodmagic beq goodmagic
jmp fail
fail
jsr bell
jmp monitor
hi2
inc srcptr+1
bne nohi2
hi3
inc srcptr+1
clc
bcc nohi3
hi4
inc dstptr+1
bne nohi4
notempty
cmp #tok_eod
bne fail
rts ;success!
;* handle "special" match values (value in A)
specialmatch
cmp #tok_empty
bne notempty
DO smaller
advsrc1
sec
advsrc2
FIN
tya ;empty match, advance srcptr
adc srcptr ; past and jump to main loop
sta srcptr
bcc mainloop
inc srcptr+1
bne mainloop
DO smaller
ELSE
hi5
inc srcptr+1
clc
bcc nohi5
FIN
goodmagic goodmagic
inc srcptr inc srcptr
bne :nohi bne mainloop
inc srcptr+1 inc srcptr+1
:nohi
mainloop mainloop
* Get the mixed-length byte and handle the literal. * Get the mixed-length byte and handle the literal.
@ -81,12 +129,10 @@ mainloop
bne shortlit bne shortlit
inc srcptr inc srcptr
bne :nohi beq hi2
inc srcptr+1 nohi2
:nohi
lda (srcptr),y ;get length extension lda (srcptr),y ;get length extension
clc adc #14 ;(carry set) add 15 - will not exceed 255
adc #15 ;add 15 - will not exceed 255
* At this point, srcptr holds the address of the "mix" * At this point, srcptr holds the address of the "mix"
* word or the length extension, and dstptr holds the * word or the length extension, and dstptr holds the
@ -107,21 +153,18 @@ shortlit sta savlen
bne :litloop ;3 -> 16 cycles/byte bne :litloop ;3 -> 16 cycles/byte
* Advance srcptr by savlen+1, and dstptr by savlen * Advance srcptr by savlen+1, and dstptr by savlen
lda srcptr txa
sec ;this gets us the +1 sec ;this gets us the +1
adc savlen adc srcptr
sta srcptr sta srcptr
bcc :nohi bcs hi3
inc srcptr+1 nohi3
clc txa
:nohi adc dstptr
lda dstptr
adc savlen
sta dstptr sta dstptr
bcc :nohi1 bcs hi4
inc dstptr+1 nohi4
:nohi1 dey ;next INY rolls back to zero
ldy #$ff ;next INY rolls back to zero
* Handle match. Y holds an offset into srcptr such * Handle match. Y holds an offset into srcptr such
* that we need to increment it once to get the next * that we need to increment it once to get the next
@ -155,13 +198,19 @@ _desthi ora #$00 ;OR in hi-res page
* remember how many bytes it took to encode. Y is * remember how many bytes it took to encode. Y is
* indexing the last value used, so we want to go * indexing the last value used, so we want to go
* advance srcptr by Y+1. * advance srcptr by Y+1.
DO smaller
sty savsrc
ELSE
tya tya
sec sec
adc srcptr adc srcptr
sta srcptr sta srcptr
bcc :nohi bcs hi5
inc srcptr+1 nohi5
:nohi FIN
* Copy the match. The length is in X. Note this * Copy the match. The length is in X. Note this
* must be a forward copy so overlapped data works. * must be a forward copy so overlapped data works.
@ -180,21 +229,41 @@ _desthi ora #$00 ;OR in hi-res page
* advance dstptr past copied data * advance dstptr past copied data
lda dstptr lda dstptr
clc
adc savlen adc savlen
sta dstptr sta dstptr
bcc :nohi1
inc dstptr+1
:nohi1
DO smaller
ldy savsrc
linkadv
bcc advsrc
ELSE
bcc mainloop
FIN
inc dstptr+1
DO overrun_check DO overrun_check
LDA dstptr+1 LDA dstptr+1
CMP #$60 CMP #$60
BLT :OKAY
DO smaller
bcc linkadv
ELSE
bcc mainloop
FIN
BRK BRK
BRK BRK
:OKAY
jmp mainloop ELSE
DO smaller
bne advsrc2
ELSE ELSE
@ -202,24 +271,4 @@ _desthi ora #$00 ;OR in hi-res page
FIN FIN
* handle "special" match values (value in A) FIN
specialmatch
cmp #tok_empty
bne :notempty
tya ;empty match, advance srcptr
adc srcptr ; past and jump to main loop
sta srcptr
bcc :nohi
inc srcptr+1
clc
:nohi
jmp mainloop
:notempty
cmp #tok_eod
bne fail
rts ;success!
fail
jsr bell
jmp monitor