Post by VDC 8x2 on Jul 5, 2014 5:28:59 GMT
I was looking at my old VDC decompress code and thought of a new way to make it.
It starts by taking destination and putting it into the address registers.
Next, we load a byte from the source. The lower 2 bits are for signalling if copy,fill,skip or quit. They are stripped off via the lsr opcode.
After the stripping is done we are left with a number from 0 to 63, 0 will have the special meaning of 256
Skip will just pass along 1-63 or 256 bytes to vdc.
Fill will fill the vdc with a byte, 2 - 63 or 256 times
Copy is what is differnt, it will copy the last 1 to 63 bytes or 256 byte in vdc mem forwords once.
00 bits will just have the code exit.
I haven't compiled it fully yet. do you see any way to improve it or bugs that I missed?
Source = $fe
destination = $fc
Temp = $fc
vdcadr = $d600
vdcdat = $d601
defm WAITVDC
bit $d600
bpl *-3
endm
*=$1300
Start ldx destination ;low byte
lda destination+1 ;high byte
ldy #$12
sty vdcadr
WAITVDC ;vdc ready?
sta vdcdat ;high byte dest
iny
sty vdcadr
stx vdcdat ;low byte set. destination is now set
MainLoop ldy #$00
lda (source),y
lsr ;get bit
bcs SkipCopy ;branch skip/copy test
lsr ;get next bit
bcs Fill ;branch to fill routine
rts ;end of file so bye bye
Fill tax ;bytes to fill always 2 to 63 or 0
dex ;never 1
lda #$18
sta vdcadr
lda vdcdat ;going to set to fill
and #$7f
sta vdcdat ;clear bit 7
jsr incsource
lda #$1f
sta vdcadr
WaitVdc ;wait for ready
lda (source),y ;byte to repeat
sta VDCDAT
lda #$1e
sta vdcadr
stx vdcdat ;start fill
jsr incsource
jmp MAINLOOP
SkipCopy lsr ;get bit
bcs Copy ;branch to Copy
tax ;transfer to x for counter. 0 will go 256 times.
lda #$1f
sta vdcadr
Waitvdc
@loop jsr IncSource ;get next byte
lda (source),y
WAITVDC ;vdc ready?
sta vdcdat ;store value
dex
beq @loop
jsr INCSOURCE ;we done so get get next byte
jmp MainLoop
Copy tax ;The copy routine copies -x bytes forwords +bytes
sta temp ;save for later
ldy #$13
sty vdcadr
lda vdcdat
sbc #$01 ;-1 to account for the autoinc of vdc
sbc temp ;low bite - value
sta temp ;we know carry is set
dey
sty vdcadr
waitvdc ;wait because reg 12
ldy vdcdat
bcs @next ;no borrow
dey
@next txa ;check value
bne @notzero ;0 is 256
dey
@notzero lda #$20
sta vdcadr
sty vdcdat ;store high byte
lda #$21
sta vdcadr
lda temp
sta vdcdat ;store low byte
lda #$18
sta vdcadr
lda vdcdat ;going set to copy
ora #$80
sta vdcdat ;clear bit 7
lda #$1e
sta vdcadr
stx vdcdat ;copy x bytes
jsr INCSOURCE ;update for next byte
jmp MainLoop
IncSource inc SOURCE
bne @end
inc source+1
@end rts
It starts by taking destination and putting it into the address registers.
Next, we load a byte from the source. The lower 2 bits are for signalling if copy,fill,skip or quit. They are stripped off via the lsr opcode.
After the stripping is done we are left with a number from 0 to 63, 0 will have the special meaning of 256
Skip will just pass along 1-63 or 256 bytes to vdc.
Fill will fill the vdc with a byte, 2 - 63 or 256 times
Copy is what is differnt, it will copy the last 1 to 63 bytes or 256 byte in vdc mem forwords once.
00 bits will just have the code exit.
I haven't compiled it fully yet. do you see any way to improve it or bugs that I missed?