wipes: seeing if I can get some 4am wipes going

This commit is contained in:
Vince Weaver 2024-10-30 16:30:41 -04:00
parent b7b311c19f
commit 903b01daa1
13 changed files with 1042 additions and 0 deletions

View File

@ -0,0 +1,37 @@
include ../../../Makefile.inc
DOS33 = ../../../utils/dos33fs-utils/dos33
TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
LINKER_SCRIPTS = ../../../linker_scripts
EMPTY_DISK = ../../../empty_disk
all: wipes.dsk
wipes.dsk: HELLO WIPE_TEST
cp $(EMPTY_DISK)/empty.dsk wipes.dsk
$(DOS33) -y wipes.dsk SAVE A HELLO
$(DOS33) -y wipes.dsk BSAVE -a 0x6000 WIPE_TEST
###
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
###
WIPE_TEST: wipe_test.o
ld65 -o WIPE_TEST wipe_test.o -C $(LINKER_SCRIPTS)/apple2_6000.inc
wipe_test.o: wipe_test.s \
zp.inc hardware.inc wait_keypress.s zx02_optim.s \
fx.hgr.bubbles.s \
fx.hgr.precomputed.1bit.s \
macros.s
ca65 -o wipe_test.o wipe_test.s -l wipe_test.lst
###
clean:
rm -f *~ *.o *.lst HELLO WIPE_TEST

View File

@ -0,0 +1,19 @@
;license:MIT
;(c) 2019-2020 by 4am/qkumba
;
;!cpu 6502
;!to "build/FX.INDEXED/BUBBLES",plain
;*=$6000
; !source "src/fx/fx.hgr.precomputed.1bit.a"
.include "fx.hgr.precomputed.1bit.s"
; +FX_INITONCE_1BIT FXCodeFile, CoordinatesFile, Start
Start:
; jmp FXCode
;FXCodeFile
; +PSTRING "HGR1"
;CoordinatesFile
; +PSTRING "BUBBLES.DATA"

View File

@ -0,0 +1,60 @@
;license:MIT
;(c) 2019-2024 by 4am
;
;------------------------------------------------------------------------------
; YE OLDE GRAND UNIFIED MEMORY MAP
;
; 0201..02C0 - hgrlo
; 02C1..02E8 - mirror_cols
; 02E9..0300
; 0301..03C0 - hgrhi
; 03C1..03EE
; 6000..61FF - module-specific code ($200 max)
; 6200.. - shared FX code (loaded once by module-specific code)
; 85FE..B880 - Coordinates1Bit (8600 but dither variants clobber Coordinates1Bit-2)
; B881..BB00
; BB01..BBC0 - hgrlomirror
; BBC1..BC00
; BC01..BCC0 - hgr1himirror
; BCC1..BDA7
; BDA8..BDFF - dithermasks
; BE00..BEFF - copymasks1bit
; BF00..BFFF - ProRWTS glue
;
; !source "src/fx/macros.a"
.include "macros.s"
;!macro FX_INITONCE_1BIT .CoordinatesFile, .Start {
;InitOnce
; bit .Start
; lda #$4C
; sta InitOnce
; +LDADDR .CoordinatesFile
; ldx #>Coordinates1Bit
; jsr iLoadFXDATA
; sec
; ror EndCoordinates1Bit
;}
; same but also loading an FXCode file
;!macro FX_INITONCE_1BIT .FXCodeFile, .CoordinatesFile, .Start {
;InitOnce
; bit .Start
; lda #$4C
; sta InitOnce
; +LDADDR .FXCodeFile
; ldx #>FXCode
; jsr iLoadFXCODE
; +LDADDR .CoordinatesFile
; ldx #>Coordinates1Bit
; jsr iLoadFXDATA
; sec
; ror EndCoordinates1Bit
;}

View File

@ -0,0 +1,21 @@
include ../../../../Makefile.inc
ZX02 = ~/research/6502_compression/zx02.git/build/zx02 -f
PNG_TO_HGR = ../../../../utils/hgr-utils/png2hgr
PNG2GR = ../../../../utils/gr-utils/png2gr
HGR_SPRITE = ../../../../utils/hgr-utils/hgr_make_sprite
all: a2_dating.hgr.zx02
####
a2_dating.hgr.zx02: a2_dating.hgr
$(ZX02) a2_dating.hgr a2_dating.hgr.zx02
a2_dating.hgr: a2_dating.png
$(PNG_TO_HGR) a2_dating.png > a2_dating.hgr
####
clean:
rm -f *~ *.zx02

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,102 @@
; HARDWARE LOCATIONS
KEYPRESS = $C000
KEYRESET = $C010
; SOFT SWITCHES
CLR80COL = $C000 ; PAGE1/PAGE1 normal
SET80COL = $C001 ; PAGE1/PAGE2 switches PAGE1 in Aux instead
EIGHTYCOLOFF = $C00C
EIGHTYCOLON = $C00D
TBCOLOR = $C022 ; IIgs text fg/bg colors
NEWVIDEO = $C029 ; IIgs graphics modes
SPEAKER = $C030
CLOCKCTL = $C034 ; bits 0-3 are IIgs border color
CYAREG = $C036 ; iigs motor detect and clock speed
SET_GR = $C050
SET_TEXT = $C051
FULLGR = $C052
TEXTGR = $C053
PAGE1 = $C054
PAGE2 = $C055
LORES = $C056 ; Enable LORES graphics
HIRES = $C057 ; Enable HIRES graphics
AN3 = $C05E ; Annunciator 3
PADDLE_BUTTON0 = $C061
PADDL0 = $C064
PTRIG = $C070
; APPLESOFT BASIC ROUTINES
NORMAL = $F273
HGR2 = $F3D8
HGR = $F3E2
BKGND0 = $F3F4 ; clear current page to A
HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y)
HPLOT0 = $F457 ; plot at (Y,X), (A)
COLOR_SHIFT = $F47E
HLINRL = $F530 ; (X,A),(Y)
HGLIN = $F53A ; line to (X,A),(Y)
COLORTBL = $F6F6
; 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
GBASCALC= $F847
SETCOL = $F864 ; COLOR=A
ROM_TEXT2COPY = $F962 ; iigs
TEXT = $FB36
TABV = $FB5B ; VTAB to A
ROM_MACHINEID = $FBB3 ; iigs
BASCALC = $FBC1 ;
BELL = $FBDD ; ring the bell
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,4 @@
5 HOME
10 PRINT "TESTING 4AM WIPE CODE FROM 4CADE"
60 PRINT:PRINT CHR$(4)"CATALOG"

View File

@ -0,0 +1,311 @@
;license:MIT
;(c) 2019-2022 by 4am
;
;!ifndef _FX_MACROS_HGR_ {
.ifndef _FX_MACROS_HGR_
;!macro HGR_CALC {
.macro HGR_CACLC
; in: A = HGR row (0x00..0xBF)
; out: A/X clobbered
; Y preserved
; ($26) points to first byte of given HGR row on hi-res page 1
; ($3C) points to same byte on hi-res page 2
; based on 'Woz Recodes Hi-Res Address Calculations'
; Apple Assembly Line vol. 7 issue 3 (December 1986)
; http://www.txbobsc.com/aal/1986/aal8612.html#a9
asl
tax
and #$F0
bpl @calc1
ora #$05
@calc1 bcc @calc2
ora #$0A
@calc2 asl
asl
sta $26
txa
and #$0E
adc #$10
asl $26
rol
sta $27
eor #$60
sta $3d
lda $26
sta $3c
;}
.endmacro
;!macro HGR_ROW_CALC {
.macro HGR_ROW_CALC
asl
asl
asl
; +HGR_CALC
HGR_CALC
;}
.endmacro
; /!\ C must be clear before using this macro
;!macro HGR_INC_WITHIN_BLOCK {
.macro HGR_INC_WITHIN_BLOCK
lda $27
adc #$04
sta $27
eor #$60
sta $3d
;}
.endmacro
;!macro RESET_HGR_CALC {
.macro RESET_HGR_CALC
lda $27
sec
sbc #$20
sta $27
eor #$60
sta $3d
;}
.endmacro
;!macro SWITCH_TO_MASKS .copy {
.macro SWITCH_TO_MASKS copy
lda #<copy
sta CopyMaskAddr
lda #>copy
sta CopyMaskAddr+1
;}
.endmacro
;!macro ROW_X_TO_BASE_ADDRESSES .src1, .src2, .dest1, .dest2 {
.macro ROW_X_TO_BAS_ADDRESSES src1, src2, dest1, dest2
lda hgrlo, x
sta <dest1
sta <src1
lda hgr1hi, x
sta <dest1+1
eor #$60
sta <src1+1
lda hgrlo+1, x
sta <dest2
sta <src2
lda hgr1hi+1, x
sta <dest2+1
eor #$60
sta <src2+1
;}
.endmacro
;!macro ROW_X_TO_MIRROR_ADDRESSES .mirror_src1, .mirror_src2, .mirror_dest1, .mirror_dest2 {
.macro ROW_X_TO_MIRROR_ADDRESSES mirror_src1, mirror_src2, mirror_dest1, mirror_dest2
lda hgrlomirror, x
sta <mirror_dest1
sta <mirror_src1
lda hgr1himirror, x
sta <mirror_dest1+1
eor #$60
sta <mirror_src1+1
lda hgrlomirror+1, x
sta <mirror_dest2
sta <mirror_src2
lda hgr1himirror+1, x
sta <mirror_dest2+1
eor #$60
sta <mirror_src2+1
;}
.endmacro
;!macro ROW_X_TO_2BIT_BASE_ADDRESSES .src1, .src2, .dest1, .dest2 {
.macro ROW_X_TO_2BIT_BASE_ADDRESSES src1, src2, dest1, dest2
; X = $01..$C0, mapping to row 0..191
lda hgrlo-1, x
sta <dest1
sta <src1
lda hgr1hi-1, x
sta <dest1+1
eor #$60
sta <src1+1
lda hgrlo, x
sta <dest2
sta <src2
lda hgr1hi, x
sta <dest2+1
eor #$60
sta <src2+1
;}
.endmacro
;!macro ROW_X_TO_3BIT_BASE_ADDRESSES .src1, .src2, .src3, .dest1, .dest2, .dest3 {
.macro ROW_X_TO_3BIT_BASE_ADDRESSES src1, src2, src3, dest1, dest2, dest3
; X = $00..$3F, mapping to row 0, 3, 6, 9, 12, ... 189
lda hgrlo3a, x
sta <dest1
sta <src1
lda hgrhi3a, x
sta <dest1+1
eor #$60
sta <src1+1
lda hgrlo3b, x
sta <dest2
sta <src2
lda hgrhi3b, x
sta <dest2+1
eor #$60
sta <src2+1
lda hgrlo3c, x
sta <dest3
sta <src3
lda hgrhi3c, x
sta <dest3+1
eor #$60
sta <src3+1
;}
.endmacro
;!macro HGR_CALC_ROUTINES {
.macro HGR_CALC_ROUTINES
HGRCalc:
; in: A = HGR row (0x00..0xBF)
; out: A/X clobbered
; Y preserved
; ($26) points to first byte of given HGR row on hi-res page 1
; ($3C) points to same byte on hi-res page 2
; based on 'Woz Recodes Hi-Res Address Calculations'
; Apple Assembly Line vol. 7 issue 3 (December 1986)
; http://www.txbobsc.com/aal/1986/aal8612.html#a9
HGR_CALC
rts
;}
.endmacro
;!macro HGR_BLOCK_COPY_ROUTINES {
.macro HGR_BLOCK_COPY_ROUTINES
HGRBlockCopy:
; in: A = HGR row / 8 (0x00..0x17)
; Y = HGR column (0x00..0x27)
; out: Y preserved
; X = #$00
; Z set
; C clear
; all other flags and registers clobbered
+HGR_ROW_CALC
HGRBlockCopyNoRecalc:
clc
ldx #$08
@loop:
lda ($3c),y
sta ($26),y
HGR_INC_WITHIN_BLOCK
dex
bne @loop
rts
;}
.endmacro
;!macro HGR_HALF_BLOCK_COPY_ROUTINES {
.macro HGR_HALF_BLOCK_COPY_ROUTINES
HGRHalfBlockCopy:
; in: A = HGR row / 4 (0x00..0x2F)
; Y = HGR column (0x00..0x27)
; out: Y preserved
; X = #$00
; Z set
; C clear
; all other flags and registers clobbered
asl
asl
HGR_CALC
HGRStaggerCopy:
clc
ldx #$04
@loop:
lda ($3c),y
sta ($26),y
HGR_INC_WITHIN_BLOCK
dex
bne @loop
rts
;}
.endmacro
;!macro HGR_WHITE_ROUTINES {
.macro HGR_WHITE_ROUTINES
HGRBlockToWhite:
; in: A = HGR row / 8 (0x00..0x17)
; Y = HGR column (0x00..0x27)
; out: Y preserved
; X = #$00
; Z set
; C clear
; all other flags and registers clobbered
HGR_ROW_CALC
clc
ldx #$08
@loop:
lda #$7F
sta ($26),y
HGR_INC_WITHIN_BLOCK
dex
bne @loop
rts
HGRHalfBlockToWhite:
; in: A = HGR row / 4 (0x00..0x2F)
; Y = HGR column (0x00..0x27)
; out: Y preserved
; X = #$00
; Z set
; C clear
; all other flags and registers clobbered
asl
asl
HGR_CALC
HGRStaggerToWhite:
clc
ldx #$04
@loop:
lda #$7F
sta ($26),y
HGR_INC_WITHIN_BLOCK
dex
bne @loop
rts
;}
.endmacro
;!macro HGR_COPY_MASK_ROUTINES {
.macro HGR_COPY_MASK_ROUTINES
SetCopyMask:
; in: A/Y points to 8-byte array of bit masks used by HGRBlockCopyWithMask
+ST16 CopyMaskAddr
rts
HGRBlockCopyWithMask:
; in: A = HGR row / 8 (0x00..0x17)
; Y = HGR column (0x00..0x27)
; must call SetCopyMask first
; out: Y preserved
; A/X clobbered
; $00 clobbered
+HGR_ROW_CALC
HGRBlockCopyWithMaskNoRecalc:
ldx #7
HGRBlockCopyWithMasksLoop:
lda ($26),y
eor ($3c),y
CopyMaskAddr=*+1
and $FDFD,x ; call SetCopyMask to set
eor ($26),y
sta ($26),y
clc
HGR_INC_WITHIN_BLOCK
dex
bpl HGRBlockCopyWithMasksLoop
rts
;}
.endmacro
_FX_MACROS_HGR_=*
.endif
;}

View File

@ -0,0 +1,19 @@
;license:MIT
;(c) 2019-2022 by 4am
;
;!ifndef _FX_MACROS_ {
.ifndef _FX_MACROS_
; !source "src/macros.a"
; .include "macros.s"
; !source "src/fx/macros.hgr.a"
.include "macros.hgr.s"
; !source "src/fx/macros.dhgr.a"
; !source "src/fx/macros.shr.a"
; !source "src/fx/macros.copybit.a"
; !source "src/fx/macros.misc.a"
.endif
_FX_MACROS_=*
;_FX_MACROS_=*
;}

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

View File

@ -0,0 +1,45 @@
; test some of the 4cade wipes
.include "zp.inc"
.include "hardware.inc"
wipe_test:
lda #0
bit SET_GR
bit HIRES
bit FULLGR
bit PAGE1
;=================================
; intro
;=================================
lda #<test_graphic
sta zx_src_l+1
lda #>test_graphic
sta zx_src_h+1
lda #$20
jsr zx02_full_decomp
jsr wait_until_keypress
;=================================
; test wipe...
;=================================
test_loop:
jsr Start
jsr wait_until_keypress
jmp test_loop
test_graphic:
.incbin "graphics/a2_dating.hgr.zx02"
.include "wait_keypress.s"
.include "zx02_optim.s"
.include "fx.hgr.bubbles.s"

260
graphics/hgr/wipes/zp.inc Normal file
View File

@ -0,0 +1,260 @@
;==================
;==================
; Zero Page Usage
;==================
;==================
; ZX0 decompression addresses
ZX0_src = $00
ZX0_dst = $02
offset = $04
bitr = $06
pntr = $07
WHICH_LOAD = $09
CURRENT_DISK = $0A
; Zero page monitor routines addresses
; We don't use the monitor but we use some of these anyway
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
WHICH_TRACK = $54
;==========================
; $60-$6F unused currently
;==========================
;==========================
; $70-$7F for PT3 Player
;==========================
AY_REGISTERS = $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
PT3_MIXER_VAL = $77
A_VOLUME = $78
B_VOLUME = $79
C_VOLUME = $7A
ENVELOPE_FINE = $7B
ENVELOPE_COARSE = $7C
ENVELOPE_SHAPE = $7D
PATTERN_L = $7E
PATTERN_H = $7F
;============================
; $80-$8D rest of pt3_player
;============================
PT3_TEMP = $80
ORNAMENT_L = $81
ORNAMENT_H = $82
SAMPLE_L = $83
SAMPLE_H = $84
LOOP = $85
MB_VALUE = $86
MB_ADDR_L = $87
MB_ADDR_H = $88
DONE_PLAYING = $89
DONE_SONG = $8A
APPLEII_MODEL = $8B
SOUND_STATUS = $8C
SOUND_DISABLED = $80
SOUND_IN_LC = $01 ; $01 sound effects in language card
SOUND_MOCKINGBOARD = $02 ; mockingboard detected
;=============================
; not sure why these are here
;=============================
DISP_PAGE = $8D
DRAW_PAGE = $8E
TOTAL_RAM = $8F
;=============================
; $90-$CF currently free
;=============================
; for plasma?
;Table1 = $A0 ; 40 bytes ($28) A0-C7
;Table2 = $C8 ; 40 bytes ($28) C8-EF
;=============================
; $D0-$D9 = hgr move
;=============================
HGR_X1 = $D0
HGR_X2 = $D1
HGR_Y1 = $D2
HGR_Y2 = $D3
HGR_DEST= $D4
BOARD_COUNT = $D5
WHICH_SLOT = $DA ; from boot sector
;==============================================
; $E0-$EF use for common things, don't re-use
;==============================================
IRQ_COUNTDOWN = $E0
SECOND_COUNTDOWN= $E1
COUNT = $E2
XSAVE = $E3
TEMPY = $E4
XPOS = $E5 ; gr_plot
YPOS = $E6 ; gr_plot
COLOR_MASK = $E7 ; gr_plot
FRAME = $E8
FRAMEL = $E8
FRAMEH = $E9
BTC_L = $EA ; audio
BTC_H = $EB ; audio
MASKL = $EC ; gr_putsprite_mask
MASKH = $ED
;==============================================
; $F0-$FB can re-use in each file
;==============================================
; D'NI
SPRITEY = $EE
SPRITEX = $EF
SPRITE_XSIZE = $F0
SIN_COUNT = $F1
NUMBER_HIGH = $F2
NUMBER_LOW = $F3
DRAW_NUMBER = $FA
;OUT1 = $F0
;OUT1H = $F1
;OUT2 = $F2
;OUT2H = $F3
;COMPT1 = $F4
;COMPT2 = $F5
;PARAM1 = $F6
;PARAM2 = $F7
;PARAM3 = $F8
;PARAM4 = $F9
;GRLINE = $FA
;GRLINEH = $FB
; Credits
BACKUP_OUTL = $F2
BACKUP_OUTH = $F3
; PLASMACUBE
;OUT1 = $F0
;OUT1H = $F1
;OUT2 = $F2
;OUT2H = $F3
COMPT1 = $F4
COMPT2 = $F5
PARAM1 = $F6
PARAM2 = $F7
PARAM3 = $F8
PARAM4 = $F9
;GRLINE = $FA
;GRLINEH = $FB
; PLASMA
; CUBE
SAVEX = $F3
SAVEY = $F4
SUM = $F5
; CIRCLES/DRAW_BOXES
COLOR2 = $F3
X1 = $F4
X2 = $F5
Y1 = $F6
Y2 = $F7
SCENE_COUNT = $F8
LAST_TYPE = $F9
; lens
LENS_X = $F0
LENS_Y = $F1
XADD = $F2
YADD = $F3
; rotozoom
NUM1L = $F0
NUM1H = $F1
NUM2L = $F2
NUM2H = $F3
RESULT = $F4 ; F5,F6,F7
SCALE_I = $F8
SCALE_F = $F9
ANGLE = $FA
; credits
SCROLL_X = $F0
; scroller
HGR_COPY_Y1 = $F1
HGR_COPY_Y2 = $F2
FIRE_COLOR = $F3
SCROLL_LENGTH = $F4
OFFSET = $F5
;==============================================
; $FC-$FF we use for in/out pointers
;==============================================
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,159 @@
; 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)
zx02_full_decomp:
; ; Get initialization block
; ldy #7
;
;copy_init: lda zx0_ini_block-1, y
; sta offset-1, y
; dey
; bne copy_init
sta ZX0_dst+1 ; page to output to in A
zx_src_l:
ldy #$dd
sty ZX0_src
zx_src_h:
ldy #$dd
sty ZX0_src+1
ldy #$80
sty bitr
ldy #0
sty offset
sty offset+1
sty ZX0_dst ; always on even page
; 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