hgr_viewer: update and put things together

This commit is contained in:
Vince Weaver 2022-07-19 21:59:43 -04:00
parent d0c491b6b7
commit 77bd42616f
26 changed files with 1519 additions and 521 deletions

View File

@ -1,32 +0,0 @@
include ../../../Makefile.inc
DOS33 = ../../../utils/dos33fs-utils/dos33
DOS33_RAW = ../../../utils/dos33fs-utils/dos33_raw
TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
LINKER_SCRIPTS = ../../../linker_scripts
EMPTY_DISK = ../../../empty_disk
all: mona.dsk
mona.dsk: HELLO MONA
cp $(EMPTY_DISK)/empty.dsk mona.dsk
$(DOS33) -y mona.dsk SAVE A HELLO
$(DOS33) -y mona.dsk BSAVE -a 0x6000 MONA
###
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
###
MONA: mona.o
ld65 -o MONA mona.o -C $(LINKER_SCRIPTS)/apple2_6000.inc
mona.o: mona.s graphics/graphics.inc
ca65 -o mona.o mona.s -l mona.lst
###
clean:
rm -f *~ *.o *.lst HELLO MONA

View File

@ -1,370 +0,0 @@
; note -- modified by Vince Weaver to assemble with ca65
; in this case, A = page to decompress to
; getsrc_smc+1, getsrc_smc+2 is src location
; -----------------------------------------------------------------------------
; Decompress raw LZSA2 block.
; Create one with lzsa -r -f2 <original_file> <compressed_file>
;
; in:
; * LZSA_SRC_LO and LZSA_SRC_HI contain the compressed raw block address
; * LZSA_DST_LO and LZSA_DST_HI contain the destination buffer address
;
; out:
; * LZSA_DST_LO and LZSA_DST_HI contain the last decompressed byte address, +1
;
; -----------------------------------------------------------------------------
; Backward decompression is also supported, use lzsa -r -b -f2 <original_file> <compressed_file>
; To use it, also define BACKWARD_DECOMPRESS=1 before including this code!
;
; in:
; * LZSA_SRC_LO/LZSA_SRC_HI must contain the address of the last byte of compressed data
; * LZSA_DST_LO/LZSA_DST_HI must contain the address of the last byte of the destination buffer
;
; out:
; * LZSA_DST_LO/LZSA_DST_HI contain the last decompressed byte address, -1
;
; -----------------------------------------------------------------------------
;
; Copyright (C) 2019 Emmanuel Marty, Peter Ferrie
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source distribution.
; -----------------------------------------------------------------------------
;NIBCOUNT = $FC ; zero-page location for temp offset
decompress_lzsa2_fast:
sta LZSA_DST_HI
ldy #$00
sty LZSA_DST_LO
sty NIBCOUNT
decode_token:
jsr getsrc ; read token byte: XYZ|LL|MMM
pha ; preserve token on stack
and #$18 ; isolate literals count (LL)
beq no_literals ; skip if no literals to copy
cmp #$18 ; LITERALS_RUN_LEN_V2?
bcc prepare_copy_literals ; if less, count is directly embedded in token
jsr getnibble ; get extra literals length nibble
; add nibble to len from token
adc #$02 ; (LITERALS_RUN_LEN_V2) minus carry
cmp #$12 ; LITERALS_RUN_LEN_V2 + 15 ?
bcc prepare_copy_literals_direct ; if less, literals count is complete
jsr getsrc ; get extra byte of variable literals count
; the carry is always set by the CMP above
; GETSRC doesn't change it
sbc #$EE ; overflow?
jmp prepare_copy_literals_direct
prepare_copy_literals_large:
; handle 16 bits literals count
; literals count = directly these 16 bits
jsr getlargesrc ; grab low 8 bits in X, high 8 bits in A
tay ; put high 8 bits in Y
bcs prepare_copy_literals_high ; (*same as JMP PREPARE_COPY_LITERALS_HIGH but shorter)
prepare_copy_literals:
lsr ; shift literals count into place
lsr
lsr
prepare_copy_literals_direct:
tax
bcs prepare_copy_literals_large ; if so, literals count is large
prepare_copy_literals_high:
txa
beq copy_literals
iny
copy_literals:
jsr getput ; copy one byte of literals
dex
bne copy_literals
dey
bne copy_literals
no_literals:
pla ; retrieve token from stack
pha ; preserve token again
asl
bcs repmatch_or_large_offset ; 1YZ: rep-match or 13/16 bit offset
asl ; 0YZ: 5 or 9 bit offset
bcs offset_9_bit
; 00Z: 5 bit offset
ldx #$FF ; set offset bits 15-8 to 1
jsr getcombinedbits ; rotate Z bit into bit 0, read nibble for bits 4-1
ora #$E0 ; set bits 7-5 to 1
bne got_offset_lo ; go store low byte of match offset and prepare match
offset_9_bit: ; 01Z: 9 bit offset
;;asl ; shift Z (offset bit 8) in place
rol
rol
and #$01
eor #$FF ; set offset bits 15-9 to 1
bne got_offset_hi ; go store high byte, read low byte of match offset and prepare match
; (*same as JMP GOT_OFFSET_HI but shorter)
repmatch_or_large_offset:
asl ; 13 bit offset?
bcs repmatch_or_16bit ; handle rep-match or 16-bit offset if not
; 10Z: 13 bit offset
jsr getcombinedbits ; rotate Z bit into bit 8, read nibble for bits 12-9
adc #$DE ; set bits 15-13 to 1 and substract 2 (to substract 512)
bne got_offset_hi ; go store high byte, read low byte of match offset and prepare match
; (*same as JMP GOT_OFFSET_HI but shorter)
repmatch_or_16bit: ; rep-match or 16 bit offset
;;ASL ; XYZ=111?
bmi rep_match ; reuse previous offset if so (rep-match)
; 110: handle 16 bit offset
jsr getsrc ; grab high 8 bits
got_offset_hi:
tax
jsr getsrc ; grab low 8 bits
got_offset_lo:
sta OFFSLO ; store low byte of match offset
stx OFFSHI ; store high byte of match offset
rep_match:
.ifdef BACKWARD_DECOMPRESS
; Backward decompression - substract match offset
sec ; add dest + match offset
lda putdst+1 ; low 8 bits
OFFSLO = *+1
sbc #$AA
sta copy_match_loop+1 ; store back reference address
lda putdst+2
OFFSHI = *+1
sbc #$AA ; high 8 bits
sta copy_match_loop+2 ; store high 8 bits of address
sec
.else
; Forward decompression - add match offset
clc ; add dest + match offset
lda putdst+1 ; low 8 bits
OFFSLO = *+1
adc #$AA
sta copy_match_loop+1 ; store back reference address
OFFSHI = *+1
lda #$AA ; high 8 bits
adc putdst+2
sta copy_match_loop+2 ; store high 8 bits of address
.endif
pla ; retrieve token from stack again
and #$07 ; isolate match len (MMM)
adc #$01 ; add MIN_MATCH_SIZE_V2 and carry
cmp #$09 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2?
bcc prepare_copy_match ; if less, length is directly embedded in token
jsr getnibble ; get extra match length nibble
; add nibble to len from token
adc #$08 ; (MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2) minus carry
cmp #$18 ; MIN_MATCH_SIZE_V2 + MATCH_RUN_LEN_V2 + 15?
bcc prepare_copy_match ; if less, match length is complete
jsr getsrc ; get extra byte of variable match length
; the carry is always set by the CMP above
; GETSRC doesn't change it
sbc #$E8 ; overflow?
prepare_copy_match:
tax
bcc prepare_copy_match_y ; if not, the match length is complete
beq decompression_done ; if EOD code, bail
; Handle 16 bits match length
jsr getlargesrc ; grab low 8 bits in X, high 8 bits in A
tay ; put high 8 bits in Y
prepare_copy_match_y:
txa
beq copy_match_loop
iny
copy_match_loop:
lda $AAAA ; get one byte of backreference
jsr putdst ; copy to destination
.ifdef BACKWARD_DECOMPRESS
; Backward decompression -- put backreference bytes backward
lda copy_match_loop+1
beq getmatch_adj_hi
getmatch_done:
dec copy_match_loop+1
.else
; Forward decompression -- put backreference bytes forward
inc copy_match_loop+1
beq getmatch_adj_hi
getmatch_done:
.endif
dex
bne copy_match_loop
dey
bne copy_match_loop
jmp decode_token
.ifdef BACKWARD_DECOMPRESS
getmatch_adj_hi:
dec copy_match_loop+2
jmp getmatch_done
.else
getmatch_adj_hi:
inc copy_match_loop+2
jmp getmatch_done
.endif
getcombinedbits:
eor #$80
asl
php
jsr getnibble ; get nibble into bits 0-3 (for offset bits 1-4)
plp ; merge Z bit as the carry bit (for offset bit 0)
combinedbitz:
rol ; nibble -> bits 1-4; carry(!Z bit) -> bit 0 ; carry cleared
decompression_done:
rts
getnibble:
NIBBLES = *+1
lda #$AA
lsr NIBCOUNT
bcc need_nibbles
and #$0F ; isolate low 4 bits of nibble
rts
need_nibbles:
inc NIBCOUNT
jsr getsrc ; get 2 nibbles
sta NIBBLES
lsr
lsr
lsr
lsr
sec
rts
.ifdef BACKWARD_DECOMPRESS
; Backward decompression -- get and put bytes backward
getput:
jsr getsrc
putdst:
LZSA_DST_LO = *+1
LZSA_DST_HI = *+2
sta $AAAA
lda putdst+1
beq putdst_adj_hi
dec putdst+1
rts
putdst_adj_hi:
dec putdst+2
dec putdst+1
rts
getlargesrc:
jsr getsrc ; grab low 8 bits
tax ; move to X
; fall through grab high 8 bits
getsrc:
LZSA_SRC_LO = *+1
LZSA_SRC_HI = *+2
lda $AAAA
pha
lda getsrc+1
beq getsrc_adj_hi
dec getsrc+1
pla
rts
getsrc_adj_hi:
dec getsrc+2
dec getsrc+1
pla
rts
.else
; Forward decompression -- get and put bytes forward
getput:
jsr getsrc
putdst:
LZSA_DST_LO = *+1
LZSA_DST_HI = *+2
sta $AAAA
inc putdst+1
beq putdst_adj_hi
rts
putdst_adj_hi:
inc putdst+2
rts
getlargesrc:
jsr getsrc ; grab low 8 bits
tax ; move to X
; fall through grab high 8 bits
getsrc:
getsrc_smc:
LZSA_SRC_LO = *+1
LZSA_SRC_HI = *+2
lda $AAAA
inc getsrc+1
beq getsrc_adj_hi
rts
getsrc_adj_hi:
inc getsrc+2
rts
.endif

View File

@ -1 +0,0 @@
mona.png: by JiskeyJasket on twitter

View File

@ -1,3 +0,0 @@
5 HOME
20 PRINT CHR$(4)"CATALOG"

View File

@ -1,27 +0,0 @@
NIBCOUNT = $09
HGR2 = $F3D8
hgr_display:
jsr HGR2 ; Hi-res graphics, no text at bottom
; Y=0, A=0 after this called
lda #<(mona_lzsa)
sta getsrc_smc+1
lda #>(mona_lzsa)
sta getsrc_smc+2
lda #$40
jsr decompress_lzsa2_fast
forever:
jmp forever
.include "decompress_fast_v2.s"
.include "graphics/graphics.inc"

View File

@ -4,109 +4,85 @@ DOS33 = ../../utils/dos33fs-utils/dos33
B2D = ../../utils/bmp2dhr/b2d
PNG_TO_40x96 = ../../utils/gr-utils/png_to_40x96
PNG_TO_RLE = ../../utils/gr-utils/png2rle
EMPTY_DISK = ../../empty_disk/empty.dsk
TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft
all: hires.dsk
all: hires_plain.dsk hires_special.dsk hires_jiskey.dsk
hires.dsk: HELLO HIRES bbl.img.lz4t bbl2.img.lz4t \
girl.hgr.lz4t 1bg.hgr.lz4t fup.hgr.lz4t witch.hgr.lz4t
$(DOS33) -y hires.dsk SAVE A HELLO
$(DOS33) -y hires.dsk BSAVE -a 0x0c00 HIRES
$(DOS33) -y hires.dsk BSAVE -a 0xa000 bbl.img.lz4t BBL.LZ4
$(DOS33) -y hires.dsk BSAVE -a 0xa000 bbl2.img.lz4t BBL2.LZ4
$(DOS33) -y hires.dsk BSAVE -a 0xa000 girl.hgr.lz4t GIRL.LZ4
$(DOS33) -y hires.dsk BSAVE -a 0xa000 1bg.hgr.lz4t OBG.LZ4
$(DOS33) -y hires.dsk BSAVE -a 0xa000 fup.hgr.lz4t FUP.LZ4
$(DOS33) -y hires.dsk BSAVE -a 0xa000 witch.hgr.lz4t WITCH.LZ4
hires_special.dsk: HELLO HIRES_SPECIAL \
special/bbl.hgr.zx02 special/bbl2.hgr.zx02 \
special/grl.hgr.zx02 special/1bg.hgr.zx02 \
special/fup.hgr.zx02 special/witch.hgr.zx02
cp $(EMPTY_DISK) hires_special.dsk
$(DOS33) -y hires_special.dsk SAVE A HELLO
$(DOS33) -y hires_special.dsk BSAVE -a 0x0c00 HIRES_SPECIAL HIRES
$(DOS33) -y hires_special.dsk BSAVE -a 0xa000 ./special/bbl.hgr.zx02 BBL.ZX02
$(DOS33) -y hires_special.dsk BSAVE -a 0xa000 ./special/bbl2.hgr.zx02 BBL2.ZX02
$(DOS33) -y hires_special.dsk BSAVE -a 0xa000 ./special/grl.hgr.zx02 GRL.ZX02
$(DOS33) -y hires_special.dsk BSAVE -a 0xa000 ./special/1bg.hgr.zx02 OBG.ZX02
$(DOS33) -y hires_special.dsk BSAVE -a 0xa000 ./special/fup.hgr.zx02 FUP.ZX02
$(DOS33) -y hires_special.dsk BSAVE -a 0xa000 ./special/witch.hgr.zx02 WITCH.ZX02
####
HIRES: hires.o
ld65 -o HIRES hires.o -C ../../linker_scripts/apple2_c00.inc
hires_plain.dsk: HELLO HIRES_PLAIN \
./plain/gp.hgr.zx02 ./plain/peddle.hgr.zx02
cp $(EMPTY_DISK) hires_plain.dsk
$(DOS33) -y hires_plain.dsk SAVE A HELLO
$(DOS33) -y hires_plain.dsk BSAVE -a 0x0c00 HIRES_PLAIN HIRES
$(DOS33) -y hires_plain.dsk BSAVE -a 0xa000 ./plain/gp.hgr.zx02 GP.ZX02
$(DOS33) -y hires_plain.dsk BSAVE -a 0xa000 ./plain/peddle.hgr.zx02 PEDDLE.ZX02
hires.o: hires.s \
####
hires_jiskey.dsk: HELLO HIRES_JISKEY \
jiskey/grl.hgr.zx02 jiskey/witch.hgr.zx02 \
jiskey/mona.hgr.zx02 jiskey/gw.hgr.zx02
cp $(EMPTY_DISK) hires_jiskey.dsk
$(DOS33) -y hires_jiskey.dsk SAVE A HELLO
$(DOS33) -y hires_jiskey.dsk BSAVE -a 0x0c00 HIRES_JISKEY HIRES
$(DOS33) -y hires_jiskey.dsk BSAVE -a 0xa000 ./jiskey/grl.hgr.zx02 GRL.ZX02
$(DOS33) -y hires_jiskey.dsk BSAVE -a 0xa000 ./jiskey/witch.hgr.zx02 WITCH.ZX02
$(DOS33) -y hires_jiskey.dsk BSAVE -a 0xa000 ./jiskey/mona.hgr.zx02 MONA.ZX02
$(DOS33) -y hires_jiskey.dsk BSAVE -a 0xa000 ./jiskey/gw.hgr.zx02 GW.ZX02
####
HIRES_SPECIAL: hires_special.o
ld65 -o HIRES_SPECIAL hires_special.o -C ../../linker_scripts/apple2_c00.inc
hires_special.o: hires_special.s zx02_optim.s \
zp.inc hardware.inc
ca65 -o hires.o hires.s -l hires.lst
ca65 -o hires_special.o hires_special.s -l hires_special.lst
####
HIRES_PLAIN: hires_plain.o
ld65 -o HIRES_PLAIN hires_plain.o -C ../../linker_scripts/apple2_c00.inc
hires_plain.o: hires_plain.s \
zp.inc hardware.inc
ca65 -o hires_plain.o hires_plain.s -l hires_plain.lst
####
HIRES_JISKEY: hires_jiskey.o
ld65 -o HIRES_JISKEY hires_jiskey.o -C ../../linker_scripts/apple2_c00.inc
hires_jiskey.o: hires_jiskey.s \
zp.inc hardware.inc
ca65 -o hires_jiskey.o hires_jiskey.s -l hires_jiskey.lst
####
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
####
bbl.img.lz4t: bbl.img.lz4
dd if=bbl.img.lz4 of=bbl.img.lz4t bs=1 skip=11
truncate bbl.img.lz4t -s -8
bbl.img.lz4: bbl.img
lz4 -f -16 bbl.img
bbl.img: bbl.png
../hgr-utils/png2hgr bbl.png > bbl.img
####
bbl2.img.lz4t: bbl2.img.lz4
dd if=bbl2.img.lz4 of=bbl2.img.lz4t bs=1 skip=11
truncate bbl2.img.lz4t -s -8
bbl2.img.lz4: bbl2.img
lz4 -f -16 bbl2.img
bbl2.img: bbl2.png
../hgr-utils/png2hgr bbl2.png > bbl2.img
####
1bg.hgr.lz4t: 1bg.hgr.lz4
dd if=1bg.hgr.lz4 of=1bg.hgr.lz4t bs=1 skip=11
truncate 1bg.hgr.lz4t -s -8
1bg.hgr.lz4: 1bg.hgr
lz4 -f -16 1bg.hgr
1bg.hgr: 1bg.png
../hgr-utils/png2hgr 1bg.png > 1bg.hgr
####
fup.hgr.lz4t: fup.hgr.lz4
dd if=fup.hgr.lz4 of=fup.hgr.lz4t bs=1 skip=11
truncate fup.hgr.lz4t -s -8
fup.hgr.lz4: fup.hgr
lz4 -f -16 fup.hgr
fup.hgr: fup.png
../hgr-utils/png2hgr fup.png > fup.hgr
####
witch.hgr.lz4t: witch.hgr.lz4
dd if=witch.hgr.lz4 of=witch.hgr.lz4t bs=1 skip=11
truncate witch.hgr.lz4t -s -8
witch.hgr.lz4: witch.hgr
lz4 -f -16 witch.hgr
witch.hgr: witch.png
../hgr-utils/png2hgr witch.png > witch.hgr
###
girl.hgr.lz4t: girl.hgr.lz4
dd if=girl.hgr.lz4 of=girl.hgr.lz4t bs=1 skip=11
truncate girl.hgr.lz4t -s -8
girl.hgr.lz4: girl.hgr
lz4 -f -16 girl.hgr
###
clean:
rm -f *~ *.o *.lst HIRES
rm -f *~ *.o *.lst HIRES_PLAIN HIRES_SPECIAL HIRES_JISKEY HELLO

View File

@ -0,0 +1,84 @@
;; HARDWARE LOCATIONS
KEYPRESS = $C000
KEYRESET = $C010
;; SOFT SWITCHES
CLR80COL = $C000 ; PAGE0/PAGE1 normal
SET80COL = $C001 ; PAGE0/PAGE1 switches PAGE0 in Aux instead
EIGHTYCOLOFF = $C00C
EIGHTYCOLON = $C00D
SPEAKER = $C030
SET_GR = $C050
SET_TEXT = $C051
FULLGR = $C052
TEXTGR = $C053
PAGE0 = $C054
PAGE1 = $C055
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
AN3 = $C05E ; Annunciator 3
PADDLE_BUTTON0 = $C061
PADDL0 = $C064
PTRIG = $C070
;; BASIC ROUTINES
NORMAL = $F273
;; MONITOR ROUTINES
HLINE = $F819 ;; HLINE Y,$2C at A
VLINE = $F828 ;; VLINE A,$2D at Y
CLRSCR = $F832 ;; Clear low-res screen
CLRTOP = $F836 ;; clear only top of low-res screen
SETCOL = $F864 ;; COLOR=A
TEXT = $FB36
TABV = $FB5B ;; VTAB to A
BASCALC = $FBC1 ;;
VTAB = $FC22 ;; VTAB to CV
HOME = $FC58 ;; Clear the text screen
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
SETINV = $FE80 ;; INVERSE
SETNORM = $FE84 ;; NORMAL
COUT = $FDED ;; output A to screen
COUT1 = $FDF0 ;; output A to screen
COLOR_BLACK = 0
COLOR_RED = 1
COLOR_DARKBLUE = 2
COLOR_PURPLE = 3
COLOR_DARKGREEN = 4
COLOR_GREY = 5
COLOR_MEDIUMBLUE = 6
COLOR_LIGHTBLUE = 7
COLOR_BROWN = 8
COLOR_ORANGE = 9
COLOR_GREY2 = 10
COLOR_PINK = 11
COLOR_LIGHTGREEN = 12
COLOR_YELLOW = 13
COLOR_AQUA = 14
COLOR_WHITE = 15
COLOR_BOTH_BLACK = $00
COLOR_BOTH_RED = $11
COLOR_BOTH_DARKBLUE = $22
COLOR_BOTH_DARKGREEN = $44
COLOR_BOTH_GREY = $55
COLOR_BOTH_MEDIUMBLUE = $66
COLOR_BOTH_LIGHTBLUE = $77
COLOR_BOTH_BROWN = $88
COLOR_BOTH_ORANGE = $99
COLOR_BOTH_PINK = $BB
COLOR_BOTH_LIGHTGREEN = $CC
COLOR_BOTH_YELLOW = $DD
COLOR_BOTH_AQUA = $EE
COLOR_BOTH_WHITE = $FF

View File

@ -0,0 +1,2 @@
5 HOME
105 PRINT CHR$ (4)"BRUN HIRES"

View File

@ -0,0 +1,128 @@
; VMW Productions HIRES viewer
;
; by deater (Vince Weaver) <vince@deater.net>
.include "zp.inc"
.include "hardware.inc"
hires_start:
;===================
; Init RTS disk code
;===================
jsr rts_init
;===================
; set graphics mode
;===================
jsr HOME
bit HIRES
bit FULLGR
bit SET_GR
bit PAGE0
;===================
; Load graphics
;===================
load_loop:
;=============================
lda #<grl_filename
sta OUTL
lda #>grl_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
lda #<witch_filename
sta OUTL
lda #>witch_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
;=============================
lda #<mona_filename
sta OUTL
lda #>mona_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
;=============================
lda #<gw_filename
sta OUTL
lda #>gw_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
jmp load_loop
;==========================
; Load Image
;===========================
load_image:
jsr opendir_filename ; open and read entire file into memory
; size in ldsizeh:ldsizel (f1/f0)
comp_data = $a000
out_addr = $2000
jsr full_decomp
rts
.align $100
.include "wait_keypress.s"
.include "zx02_optim.s"
.include "rts.s"
; filename to open is 30-character Apple text:
grl_filename: ; .byte "GRL.ZX02",0
.byte 'G'|$80,'R'|$80,'L'|$80,'.'|$80,'Z'|$80,'X'|$80
.byte '0'|$80,'2'|$80,$00
witch_filename: ; .byte "WITCH.ZX02",0
.byte 'W'|$80,'I'|$80,'T'|$80,'C'|$80,'H'|$80
.byte '.'|$80,'Z'|$80,'X'|$80,'0'|$80,'2'|$80,$00
mona_filename: ; .byte "MONA.ZX02",0
.byte 'M'|$80,'O'|$80,'N'|$80,'A'|$80
.byte '.'|$80,'Z'|$80,'X'|$80,'0'|$80,'2'|$80,$00
gw_filename: ; .byte "GW.ZX02",0
.byte 'G'|$80,'W'|$80
.byte '.'|$80,'Z'|$80,'X'|$80,'0'|$80,'2'|$80,$00

View File

@ -0,0 +1,89 @@
; VMW Productions HIRES viewer
;
; by deater (Vince Weaver) <vince@deater.net>
.include "zp.inc"
.include "hardware.inc"
hires_start:
;===================
; Init RTS disk code
;===================
jsr rts_init
;===================
; set graphics mode
;===================
jsr HOME
bit HIRES
bit FULLGR
bit SET_GR
bit PAGE0
;===================
; Load graphics
;===================
load_loop:
;=============================
lda #<gp_filename
sta OUTL
lda #>gp_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
lda #<peddle_filename
sta OUTL
lda #>peddle_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
jmp load_loop
;==========================
; Load Image
;===========================
load_image:
jsr opendir_filename ; open and read entire file into memory
; size in ldsizeh:ldsizel (f1/f0)
comp_data = $a000
out_addr = $2000
jsr full_decomp
rts
.align $100
.include "wait_keypress.s"
.include "zx02_optim.s"
.include "rts.s"
; filename to open is 30-character Apple text:
gp_filename: ; .byte "GP.ZX02",0
.byte 'G'|$80,'P'|$80
.byte '.'|$80,'Z'|$80,'X'|$80,'0'|$80,'2'|$80,$00
peddle_filename: ; .byte "PEDDLE.ZX02",0
.byte 'P'|$80,'E'|$80,'D'|$80,'D'|$80,'L'|$80,'E'|$80
.byte '.'|$80,'Z'|$80,'X'|$80,'0'|$80,'2'|$80,$00

View File

@ -0,0 +1,156 @@
; VMW Productions HIRES viewer
;
; by deater (Vince Weaver) <vince@deater.net>
.include "zp.inc"
.include "hardware.inc"
hires_start:
;===================
; Init RTS disk code
;===================
jsr rts_init
;===================
; set graphics mode
;===================
jsr HOME
bit HIRES
bit FULLGR
bit SET_GR
bit PAGE0
;===================
; Load graphics
;===================
load_loop:
;=============================
lda #<bbl_filename
sta OUTL
lda #>bbl_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
lda #<bbl2_filename
sta OUTL
lda #>bbl2_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
lda #<grl_filename
sta OUTL
lda #>grl_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
;=============================
lda #<obg_filename
sta OUTL
lda #>obg_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
lda #<fup_filename
sta OUTL
lda #>fup_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
;=============================
lda #<witch_filename
sta OUTL
lda #>witch_filename
sta OUTH
jsr load_image
jsr wait_until_keypress
;=============================
jmp load_loop
;==========================
; Load Image
;===========================
load_image:
jsr opendir_filename ; open and read entire file into memory
; size in ldsizeh:ldsizel (f1/f0)
comp_data = $a000
out_addr = $2000
jsr full_decomp
rts
.align $100
.include "wait_keypress.s"
.include "zx02_optim.s"
.include "rts.s"
; filename to open is 30-character Apple text:
bbl_filename: ; .byte "BBL.ZX02",0
.byte 'B'|$80,'B'|$80,'L'|$80,'.'|$80,'Z'|$80,'X'|$80,'0'|$80
.byte '2'|$80,$00
bbl2_filename: ; .byte "BBL2.ZX02",0
.byte 'B'|$80,'B'|$80,'L'|$80,'2'|$80,'.'|$80,'Z'|$80,'X'|$80
.byte '0'|$80,'2'|$80,$00
grl_filename: ; .byte "GRL.ZX02",0
.byte 'G'|$80,'R'|$80,'L'|$80,'.'|$80,'Z'|$80,'X'|$80
.byte '0'|$80,'2'|$80,$00
obg_filename: ; .byte "OBG.ZX02",0
.byte 'O'|$80,'B'|$80,'G'|$80,'.'|$80,'Z'|$80,'X'|$80
.byte '0'|$80,'2'|$80,$00
fup_filename: ; .byte "FUP.ZX02",0
.byte 'F'|$80,'U'|$80,'P'|$80,'.'|$80,'Z'|$80,'X'|$80
.byte '0'|$80,'2'|$80,$00
witch_filename: ; .byte "WITCH.ZX02",0
.byte 'W'|$80,'I'|$80,'T'|$80,'C'|$80,'H'|$80
.byte '.'|$80,'Z'|$80,'X'|$80,'0'|$80,'2'|$80,$00

View File

@ -0,0 +1,2 @@
All images by JiskeyJasket on twitter

Binary file not shown.

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

View File

@ -0,0 +1,25 @@
include ../../../Makefile.inc
ZX02 = ~/research/6502_compression/zx02.git/build/zx02
PNG_TO_HGR = ../../../utils/hgr-utils/png2hgr
all: gp.hgr.zx02 peddle.hgr.zx02
####
gp.hgr.zx02: gp.hgr
$(ZX02) gp.hgr gp.hgr.zx02
gp.hgr: gp.png
$(PNG_TO_HGR) gp.png > gp.hgr
####
peddle.hgr.zx02: peddle.hgr
$(ZX02) peddle.hgr peddle.hgr.zx02
####
clean:
rm -f *~ *.o *.lst

View File

@ -0,0 +1,3 @@
gp.png: Морская свинка by ax34 https://zxart.ee/eng/authors/a/ax34/morskaja-svinka/
peddle.hgr: based on https://www.flickr.com/photos/textfiles/10333719586
by Jason Scott, via Wikipedia

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

557
graphics/hgr_viewer/rts.s Normal file
View File

@ -0,0 +1,557 @@
; read any file slot 6 version
; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018
; modified to assembled with ca65 -- vmw
; added code to patch it to run from current disk slot -- vmw
; USAGE:
; file to load in namlo:namhi
; Loads file contents to addr from filesystem
; also stores filesize in ldsizel:ldsizeh
dirbuf = $900
; note, don't put this immediately below
; the value being read as destaddr-4
; is temporarily overwritten during read
; process
;======================
; filename to open is 30-character Apple text:
filename:
.byte $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0
.byte $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0
.byte $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0
.byte $A0,$A0,$A0,$A0,$A0,$A0
;=======================================================
;=======================================================
;=======================================================
;unhook DOS and build nibble table
rts_init:
; patch to use current drive
; locate input paramater list
jsr $3E3
; result is in A:Y
sta $FF
sty $FE
ldy #1
lda ($FE),y
; list+1 should have slot<<8
ora #$80 ; add in $80
; c0e0
sta mlsmc06+1
; c0e8
clc
adc #8
sta mlsmc02+1
; c0e9
clc
adc #1
sta mlsmc01+1
; c0ec
clc
adc #3
sta mlsmc03+1
sta mlsmc04+1
sta mlsmc05+1
jsr $fe93 ; clear COUT
jsr $fe89 ; clear KEYIN
;========================
; Create nibble table
; Note: the table starts 16 bytes in, and is sparse
; so it doesn't entirely look like the DOS33 table at
ldy #0
ldx #3
L1: stx $3c ; store tempx (3?)
txa ; a=x (a=3)
asl ; a*=2 (a=6)
bit $3c ; a&tempx, set N/V (a=6)
beq L3 ; if 0, skip to L3
ora $3c ; a|=tempx (a=7)
eor #$ff ; a=~a (a=f8)
and #$7e ; a&=0x7e 0111 1110 (a=78)
L2: bcs L3 ; this set way back at asl??
lsr ; a>>1 a=3c c=0
; a=1e c=0
; a=0f c=0
; a=07 c=1
bne L2 ; if a!=0 goto l2
tya ; if a==0, a=y
sta nibtbl, x ; write out to table
iny ; increment y
L3: inx ; increment x x=4, a=0f
bpl L1 ; loop while high bit not set
rts
;=======================================================
;=======================================================
;=======================================================
; filename in OUTL:OUTH
opendir_filename:
; clear out the filename with $A0 (space)
lda #<filename
sta namlo
lda #>filename
sta namhi
ldy #29
wipe_filename_loop:
lda #$A0
sta (namlo),Y
dey
bpl wipe_filename_loop
ldy #0
copy_filename_loop:
lda (OUTL),Y
beq copy_filename_done
sta (namlo),Y
iny
bne copy_filename_loop
copy_filename_done:
; fallthrough
;=======================================================
;=======================================================
;=======================================================
;===========================
; opendir
;===========================
; turn on drive and read volume table of contents
opendir:
mlsmc01:lda $c0e9 ; turn slot#6 drive on
ldx #0
stx adrlo ; zero out adrlo
stx secsize ; zero out secsize
lda #$11 ; a=$11 (VTOC)
jsr readdirsec
firstent:
lda dirbuf+1
; lock if entry not found
entry_not_found:
beq entry_not_found
; read directory sector
ldx dirbuf+2
jsr seekread1
ldy #7 ;number of directory entries in a sector
ldx #$2b ;offset of filename in directory entry
nextent:
tya
pha ; was **phy**
txa
pha ; was **phx**
ldy #$1d
; match name backwards (slower but smaller)
L4:
lda (namlo), y
cmp dirbuf, x
beq foundname
pla
; move to next directory in this block, if possible
clc
adc #$23
tax
pla
tay ; was **ply**
dey
bne nextent
beq firstent ; was **bra**
foundname:
dex
dey
bpl L4
pla
tay ; was **ply**
pla
; read track/sector list
lda dirbuf-32, y
ldx dirbuf-31, y
jsr seekread1
; read load offset and length info only, initially
lda #<filbuf
sta adrlo
lda #4
sta secsize
lda dirbuf+12
ldx dirbuf+13
ldy #>filbuf
jsr seekread
; reduce load offset by 4, to account for offset and length
sec
lda filbuf
sbc #4
sta adrlo
lda filbuf+1
sbc #0
sta adrhi
; save on stack bytes that will be overwritten by extra read
ldy #3
L5:
lda (adrlo), y
pha
dey
bpl L5
lda adrhi
pha
lda adrlo
pha
; increase load size by 4, to account for offst and length
lda filbuf+2
sta ldsizel ; store out raw size
adc #3
sta sizelo
sta secsize
lda filbuf+3
sta ldsizeh ; store out raw size
adc #0
sta sizehi
sta ldsizeh
beq readfirst
lda #0 ; was **stz secsize**
sta secsize
readfirst:
ldy #$0c
; read a file sector
readnext:
tya
pha
lda dirbuf, y ; A = track
ldx dirbuf+1, y ; x = sector
jsr seekread1
pla
tay
; if low count is non-zero then we are done
; (can happen only for partial last block)
lda secsize
bne readdone
; continue if more than $100 bytes left
dec sizehi
bne L6
; set read size to min(length, $100)
lda sizelo
beq readdone
sta secsize
L6:
inc adrhi
iny
iny
bne readnext
; save current address for after t/s read
lda adrhi
pha
lda adrlo
pha
lda #0
sta adrlo ; was **stz adrlo**
; read next track/sector sector
lda dirbuf+1
ldx dirbuf+2
jsr readdirsec
clc
; restore current address
readdone:
pla
; sta adrhi
; pla
sta adrlo ; code originally had this backwards
pla
sta adrhi
bcc readfirst
mlsmc02:lda $c0e8
; restore from stack bytes that were overwritten by extra read
ldx #3
ldy #0
L7:
pla
sta (adrlo), y
iny
dex
bpl L7
rts
;======================
; readdirsec
;======================
; a = track?
; x = sector?
readdirsec:
ldy #>dirbuf
seekread:
sty adrhi
seekread1:
sta phase
lda sectbl, x
sta reqsec
jsr readadr
; if track does not match, then seek
cpx phase
beq checksec
jsr seek
;=========================================
; re merge in with qkumba's recent changes
; to fix seek problem?
;=========================================
; [re-]read sector
re_read_addr:
jsr readadr
checksec:
cmp reqsec
bne re_read_addr
;=========================
; read sector data
;=========================
readdata:
jsr readd5aa
eor #$ad ; zero A if match
bne re_read_addr
L12:
mlsmc03:ldx $c0ec ; read until valid data (high bit set)
bpl L12
eor nibtbl-$80, x
sta bit2tbl-$aa, y
iny
bne L12
L13:
mlsmc04:ldx $c0ec ; read until valid data (high bit set)
bpl L13
eor nibtbl-$80, x
sta (adrlo), y ; the real address
iny
cpy secsize
bne L13
ldy #0
L14:
ldx #$a9
L15:
inx
beq L14
lda (adrlo), y
lsr bit2tbl-$aa, x
rol
lsr bit2tbl-$aa, x
rol
sta (adrlo), y
iny
cpy secsize
bne L15
rts
; no tricks here, just the regular stuff
;=======================
; readaddr -- read the address field
;=======================
; Find address field, put track in cutrk, sector in tmpsec
readadr:
jsr readd5aa
cmp #$96
bne readadr
ldy #3 ; three?
; first read volume/volume
; then track/track
; then sector/sector?
adr_read_two_bytes:
tax
jsr readnib
rol
sta tmpsec
jsr readnib
and tmpsec
dey
bne adr_read_two_bytes
rts
;========================
; make sure we see the $D5 $AA pattern
readd5aa:
L16:
jsr readnib
L17:
cmp #$d5
bne L16
jsr readnib
cmp #$aa
bne L17
tay ; we need Y=#$AA later
readnib:
mlsmc05:lda $c0ec ; read until valid (high bit set)
bpl readnib
seekret:
rts
;=====================
; SEEK
;=====================
; current track in X?
; desired track in phase
seek:
ldy #0
sty step
asl phase ; multiply by two
txa ; current track?
asl ; mul by two
copy_cur:
tax
sta tmptrk
sec
sbc phase
beq L22
bcs L18
eor #$ff
inx
bcc L19
L18:
sbc #1
dex
L19:
cmp step
bcc L20
lda step
L20:
cmp #8
bcs L21
tay
sec
L21:
txa
pha
ldx step1, y
L22:
php
bne L24
L23:
clc
lda tmptrk
ldx step2, y
L24:
stx tmpsec
and #3
rol
tax
lsr
mlsmc06:lda $c0e0, x
L25:
ldx #$12
L26:
dex
bpl L26
dec tmpsec
bne L25
bcs L23
plp
beq seekret
pla
inc step
bne copy_cur
step1: .byte $01, $30, $28, $24, $20, $1e, $1d, $1c
step2: .byte $70, $2c, $26, $22, $1f, $1e, $1d, $1c
sectbl: .byte $00,$0d,$0b,$09,$07,$05,$03,$01,$0e,$0c,$0a,$08,$06,$04,$02,$0f
; From $BA96 of DOS33
nibtbl: .res 128 ; = *
; .byte $00,$01,$98,$99,$02,$03,$9C,$04 ; $BA96 ; 00
; .byte $05,$06,$A0,$A1,$A2,$A4,$A4,$A5 ; $BA9E ; 08
; .byte $07,$08,$A8,$A9,$AA,$09,$0A,$0B ; $BAA6 ; 10
; .byte $0C,$0D,$B0,$B1,$0E,$0F,$10,$11 ; $BAAE ; 18
; .byte $12,$13,$B8,$14,$15,$16,$17,$18 ; $BAB6 ; 20
; .byte $19,$1A,$C0,$C1,$C2,$C3,$C4,$C5 ; $BABE ; 28
; .byte $C6,$C7,$C8,$C9,$CA,$1B,$CC,$1C ; $BAC6 ; 30
; .byte $1D,$1E,$D0,$D1,$D2,$1E,$D4,$D5 ; $BACE ; 38
; .byte $20,$21,$D8,$22,$23,$24,$25,$26 ; $BAD6 ; 40
; .byte $27,$28,$E0,$E1,$E2,$E3,$E4,$29 ; $BADE ; 48
; .byte $2A,$2B,$E8,$2C,$2D,$2E,$2F,$30 ; $BAE6 ; 50
; .byte $31,$32,$F0,$F1,$33,$34,$35,$36 ; $BAEE ; 58
; .byte $37,$38,$F8,$39,$3A,$3B,$3C,$3D ; $BAF6 ; 60
; .byte $3E,$3F,$13,$00,$01,$02,$01,$00 ; $BAFE ; 68
; .byte $00,$00,$00,$00,$00,$00,$00,$00
; .byte $00,$00,$00,$00,$00,$00,$00,$00
bit2tbl: .res 86 ; = nibtbl+128
filbuf: .res 4 ; = bit2tbl+86
;dataend = filbuf+4

View File

@ -0,0 +1,60 @@
include ../../../Makefile.inc
ZX02 = ~/research/6502_compression/zx02.git/build/zx02
PNG_TO_HGR = ../../../utils/hgr-utils/png2hgr
all: bbl.hgr.zx02 bbl2.hgr.zx02 \
grl.hgr.zx02 1bg.hgr.zx02 fup.hgr.zx02 witch.hgr.zx02
####
bbl.hgr.zx02: bbl.hgr
$(ZX02) bbl.hgr bbl.hgr.zx02
bbl.hgr: bbl.png
$(PNG_TO_HGR) bbl.png > bbl.hgr
####
bbl2.hgr.zx02: bbl2.hgr
$(ZX02) bbl2.hgr bbl2.hgr.zx02
bbl2.hgr: bbl2.png
$(PNG_TO_HGR) bbl2.png > bbl2.hgr
####
1bg.hgr.zx02: 1bg.hgr
$(ZX02) 1bg.hgr 1bg.hgr.zx02
1bg.hgr: 1bg.png
$(PNG_TO_HGR) 1bg.png > 1bg.hgr
####
fup.hgr.zx02: fup.hgr
$(ZX02) fup.hgr fup.hgr.zx02
fup.hgr: fup.png
$(PNG_TO_HGR) fup.png > fup.hgr
####
witch.hgr.zx02: witch.hgr
$(ZX02) witch.hgr witch.hgr.zx02
witch.hgr: witch.png
$(PNG_TO_HGR) witch.png > witch.hgr
###
grl.hgr.zx02: grl.hgr
$(ZX02) grl.hgr grl.hgr.zx02
###
clean:
rm -f *~ *.o *.lst

View File

@ -0,0 +1,5 @@
wait_until_keypress:
lda KEYPRESS ; 4
bpl wait_until_keypress ; 3
bit KEYRESET ; clear the keyboard buffer
rts ; 6

200
graphics/hgr_viewer/zp.inc Normal file
View File

@ -0,0 +1,200 @@
;; Zero Page
FRAMEBUFFER = $00 ; $00 - $0F
;; LZ4 addresses
FLAME_STATE = $00
FLAME1 = $01
FLAME2 = $02
FLAME3 = $03
FLAME4 = $04
FLAME5 = $05
LZ4_SRC = $00
LZ4_DST = $02
LZ4_END = $04
COUNT = $06
DELTA = $08
;; Zero page monitor routines addresses
WNDLFT = $20
WNDWDTH = $21
WNDTOP = $22
WNDBTM = $23
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
H2 = $2C
V2 = $2D
MASK = $2E
COLOR = $30
;INVFLG = $32
; dos33 zero page = 26-2f, 35-38, 3e 3f 40-4d
; overlap applesoft 67-6a,6f,70,af,b0,ca-cd,d8
; DOS33: Confirmed kills $68
RWTSL = $60
RWTSH = $61
DOSBUFL = $62
DOSBUFH = $63
FILEML = $64
FILEMH = $65
FRAME = $60
FRAMEH = $61
WAITING = $62
LETTERL = $63
LETTERH = $64
LETTERX = $65
LETTERY = $66
LETTERD = $67
LETTER = $68
BLARGH = $69
;FACTOR_I = $66
;FACTOR_F = $67
;DX_I = $68
;DX_F = $69
;SPACEX_I = $6A
;SPACEX_F = $6B
;CX_I = $6C
;CX_F = $6D
;DY_I = $6E
;DY_F = $6F
ZPOS = $78
REGISTER_DUMP = $70
A_FINE_TONE = $70
A_COARSE_TONE = $71
B_FINE_TONE = $72
B_COARSE_TONE = $73
C_FINE_TONE = $74
C_COARSE_TONE = $75
NOISE = $76
ENABLE = $77
A_VOLUME = $78
B_VOLUME = $79
C_VOLUME = $7A
ENVELOPE_FINE = $7B
ENVELOPE_COARSE = $7C
ENVELOPE_SHAPE = $7D
COPY_OFFSET = $7E
DECODER_STATE = $7F
REGISTER_DUMP2 = $80
A_FINE_TONE2 = $80
A_COARSE_TONE2 = $81
B_FINE_TONE2 = $82
B_COARSE_TONE2 = $83
C_FINE_TONE2 = $84
C_COARSE_TONE2 = $85
NOISE2 = $86
ENABLE2 = $87
A_VOLUME2 = $88
B_VOLUME2 = $89
C_VOLUME2 = $8A
ENVELOPE_FINE2 = $8B
ENVELOPE_COARS2 = $8C
ENVELOPE_SHAPE2 = $8D
LYRICSL = $8E
LYRICSH = $8F
FRAME_COUNT = $90
MB_VALUE = $91
MB_ADDRL = $91
MB_ADDRH = $92
DONE_PLAYING = $93
MB_CHUNK_OFFSET = $94
MB_FRAME = $94
MB_PATTERN = $95
CHUNKSIZE = $95
LZ4_DONE = $96
DECODE_ERROR = $97
COPY_TIME = $98
DECOMPRESS_TIME = $99
TIME_TAKEN = $9A
LYRICS_ACTIVE = $9B
;FORTYCOL = $9C
CURSOR = $9D
; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related
;COLOR1 = $E0
;COLOR2 = $E1
;MATCH = $E2
XX = $E3
YY = $E4
HGR_COLOR = $E4
;SHIPY = $E4
;YADD = $E5
;LOOP = $E6
;MEMPTRL = $E7
;MEMPTRH = $E8
;NAMEL = $E9
;NAMEH = $EA
;NAMEX = $EB
;CHAR = $EC
STATE = $ED
DISP_PAGE = $ED
DRAW_PAGE = $EE
OFFSET = $EF
;FIRST = $F0
LASTKEY = $F1
PADDLE_STATUS = $F2
SPRITETEMP = $F2
XPOS = $F3
YPOS = $F4
TEMP = $FA
TEMPY = $FB
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF
; read any file slot 6 version
; based on FASTLD6 and RTS copyright (c) Peter Ferrie 2011-2013,2018
; modified to assembled with ca64 -- vmw
; added code to patch it to run from current disk slot -- vmw
adrlo = $26 ; constant from boot prom
adrhi = $27 ; constant from boot prom
tmpsec = $3c ; constant from boot prom
reqsec = $3d ; constant from boot prom
sizelo = $44
sizehi = $45
secsize = $46
ldsizel = $f0
ldsizeh = $f1
namlo = $fb
namhi = $fc
step = $fd ; state for stepper motor
tmptrk = $fe ; temporary copy of current track
phase = $ff ; current phase for /seek

View File

@ -0,0 +1,144 @@
; De-compressor for ZX02 files
; ----------------------------
;
; Decompress ZX02 data (6502 optimized format), optimized for speed and size
; 138 bytes code, 58.0 cycles/byte in test file.
;
; Compress with:
; zx02 input.bin output.zx0
;
; (c) 2022 DMSC
; Code under MIT license, see LICENSE file.
ZP=$80
offset = ZP+0
ZX0_src = ZP+2
ZX0_dst = ZP+4
bitr = ZP+6
pntr = ZP+7
; Initial values for offset, source, destination and bitr
zx0_ini_block:
.byte $00, $00, <comp_data, >comp_data, <out_addr, >out_addr, $80
;--------------------------------------------------
; Decompress ZX0 data (6502 optimized format)
full_decomp:
; Get initialization block
ldy #7
copy_init: lda zx0_ini_block-1, y
sta offset-1, y
dey
bne copy_init
; Decode literal: Ccopy next N bytes from compressed file
; Elias(length) byte[1] byte[2] ... byte[N]
decode_literal:
jsr get_elias
cop0: lda (ZX0_src), y
inc ZX0_src
bne plus1
inc ZX0_src+1
plus1: sta (ZX0_dst),y
inc ZX0_dst
bne plus2
inc ZX0_dst+1
plus2: dex
bne cop0
asl bitr
bcs dzx0s_new_offset
; Copy from last offset (repeat N bytes from last offset)
; Elias(length)
jsr get_elias
dzx0s_copy:
lda ZX0_dst
sbc offset ; C=0 from get_elias
sta pntr
lda ZX0_dst+1
sbc offset+1
sta pntr+1
cop1:
lda (pntr), y
inc pntr
bne plus3
inc pntr+1
plus3: sta (ZX0_dst),y
inc ZX0_dst
bne plus4
inc ZX0_dst+1
plus4: dex
bne cop1
asl bitr
bcc decode_literal
; Copy from new offset (repeat N bytes from new offset)
; Elias(MSB(offset)) LSB(offset) Elias(length-1)
dzx0s_new_offset:
; Read elias code for high part of offset
jsr get_elias
beq exit ; Read a 0, signals the end
; Decrease and divide by 2
dex
txa
lsr ; @
sta offset+1
; Get low part of offset, a literal 7 bits
lda (ZX0_src), y
inc ZX0_src
bne plus5
inc ZX0_src+1
plus5:
; Divide by 2
ror ; @
sta offset
; And get the copy length.
; Start elias reading with the bit already in carry:
ldx #1
jsr elias_skip1
inx
bcc dzx0s_copy
; Read an elias-gamma interlaced code.
; ------------------------------------
get_elias:
; Initialize return value to #1
ldx #1
bne elias_start
elias_get: ; Read next data bit to result
asl bitr
rol ; @
tax
elias_start:
; Get one bit
asl bitr
bne elias_skip1
; Read new bit from stream
lda (ZX0_src), y
inc ZX0_src
bne plus6
inc ZX0_src+1
plus6: ;sec ; not needed, C=1 guaranteed from last bit
rol ;@
sta bitr
elias_skip1:
txa
bcs elias_get
; Got ending bit, stop reading
exit:
rts