From 264764a0ca6e85995ae909a1b0c7471d3461cf66 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 2 Feb 2024 15:43:41 -0500 Subject: [PATCH] lovebyte: work on dont --- demos/lovebyte2024/d2v/Makefile | 59 +++++++ demos/lovebyte2024/d2v/dont.s | 49 ++++++ demos/lovebyte2024/d2v/dont2.s | 202 ++++++++++++++++++++++ demos/lovebyte2024/d2v/graphics/Makefile | 21 +++ demos/lovebyte2024/d2v/graphics/scene.png | Bin 0 -> 4544 bytes demos/lovebyte2024/d2v/hello.bas | 7 + demos/lovebyte2024/d2v/zx02_optim.s | 159 +++++++++++++++++ 7 files changed, 497 insertions(+) create mode 100644 demos/lovebyte2024/d2v/Makefile create mode 100644 demos/lovebyte2024/d2v/dont.s create mode 100644 demos/lovebyte2024/d2v/dont2.s create mode 100644 demos/lovebyte2024/d2v/graphics/Makefile create mode 100644 demos/lovebyte2024/d2v/graphics/scene.png create mode 100644 demos/lovebyte2024/d2v/hello.bas create mode 100644 demos/lovebyte2024/d2v/zx02_optim.s diff --git a/demos/lovebyte2024/d2v/Makefile b/demos/lovebyte2024/d2v/Makefile new file mode 100644 index 00000000..736dba78 --- /dev/null +++ b/demos/lovebyte2024/d2v/Makefile @@ -0,0 +1,59 @@ +include ../../../Makefile.inc + +DOS33 = ../../../utils/dos33fs-utils/dos33 +TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft +EMPTYDISK = ../../../empty_disk/empty.dsk +LINKERSCRIPTS = ../../../linker_scripts/ + +all: dont.dsk + +dont.dsk: HELLO DONT DONT2 + cp $(EMPTYDISK) dont.dsk + $(DOS33) -y dont.dsk SAVE A HELLO + $(DOS33) -y dont.dsk BSAVE -a 0xc00 DONT + $(DOS33) -y dont.dsk BSAVE -a 0xc00 DONT2 + +### + +submit: dont.zip + +dont.zip: DONT dont.s file_id.diz dont.dsk + mkdir -p lovebyte2023_dont + cp DONT ./lovebyte2023_dont + cp dont.s ./lovebyte2023_dont + cp file_id.diz ./lovebyte2023_dont + cp dont.dsk ./lovebyte2023_dont + cp monitor.txt ./lovebyte2023_dont + cp dont_screen.png ./lovebyte2023_dont + cp dont_720p.mp4 ./lovebyte2023_dont + zip -r dont.zip lovebyte2023_dont + +#### + + +#### + +HELLO: hello.bas + $(TOKENIZE) < hello.bas > HELLO + +### + +DONT: dont.o + ld65 -o DONT dont.o -C $(LINKERSCRIPTS)/apple2_c00.inc + +dont.o: dont.s + ca65 -o dont.o dont.s -l dont.lst + +### + +DONT2: dont2.o + ld65 -o DONT2 dont2.o -C $(LINKERSCRIPTS)/apple2_c00.inc + +dont2.o: dont2.s + ca65 -o dont2.o dont2.s -l dont2.lst + + +#### + +clean: + rm -f *~ *.o *.lst HELLO DONT DONT2 *.zip diff --git a/demos/lovebyte2024/d2v/dont.s b/demos/lovebyte2024/d2v/dont.s new file mode 100644 index 00000000..38f798c4 --- /dev/null +++ b/demos/lovebyte2024/d2v/dont.s @@ -0,0 +1,49 @@ +; Don't Tell Valve + +; by Vince `deater` Weaver / DsR + +; zero page locations +GBASL = $26 +GBASH = $27 +HGR_SCALE = $E7 +HGR_ROTATION = $F9 + +ZP=$80 +offset = ZP+0 +ZX0_src = ZP+2 +ZX0_dst = ZP+4 +bitr = ZP+6 +pntr = ZP+7 + + +; ROM locations +HGR2 = $F3D8 +HGR = $F3E2 +HPOSN = $F411 +XDRAW0 = $F65D +XDRAW1 = $F661 +HPLOT0 = $F457 + +dont: + + jsr HGR ; Hi-res, full screen ; 3 + ; Y=0, A=0 after this call + + + lda #scene + sta zx_src_h+1 + + lda #$20 + + jsr zx02_full_decomp + + +ending: + jmp ending + +.include "zx02_optim.s" + +scene: +.incbin "graphics/scene.hgr.zx02" diff --git a/demos/lovebyte2024/d2v/dont2.s b/demos/lovebyte2024/d2v/dont2.s new file mode 100644 index 00000000..c574d7bd --- /dev/null +++ b/demos/lovebyte2024/d2v/dont2.s @@ -0,0 +1,202 @@ +; Don't Tell Valve + +; by Vince `deater` Weaver / DsR + + +; 147 bytes = initial block code +; 144 bytes = optimize color pick +; 137 bytes = optimize table generation +; 135 bytes = more optimization + +; zero page locations +GBASL = $26 +GBASH = $27 + +HGR_X = $E0 +HGR_Y = $E2 +HGR_SCALE = $E7 + +TEMPY = $F0 +HGR_ROTATION = $F9 + +INL = $FE +INH = $FF + +; ROM locations +HGR2 = $F3D8 +HGR = $F3E2 +HPOSN = $F411 +XDRAW0 = $F65D +XDRAW1 = $F661 +HPLOT0 = $F457 + +hposn_low = $6000 +hposn_high = $6100 + +dont: + + jsr HGR ; Hi-res, full screen ; 3 + ; Y=0, A=0 after this call + + ;========================== + ; make table + +; ldy #0 +table_loop: +; sty TEMPY +; lda #0 ; we are out of bounds, does it matter? +; tax + tya + jsr HPOSN + ldy HGR_Y ; HPOSN saves this + lda GBASL + sta hposn_low,Y + lda GBASH + sta hposn_high,Y + iny +; cpy #192 ; what happens if we run 192..255? + bne table_loop + + ldx #8 +draw_loop: + jsr draw_box + dex + bpl draw_loop + + ldx #37 + lda #companion_cube + sta INH + jsr draw_sprite + + ldx #34 + lda #companion_cube + sta INH + jsr draw_sprite + + lda #101 + sta draw_sprite_y_smc+1 + + ldx #38 + lda #companion_cube + sta INH + jsr draw_sprite + + +ending: + jmp ending + + +box_color_odd: + .byte $2A,$55,$AA,$7F,$7F,$7F,$60,$03,$E0 +box_color_even: + .byte $55,$2A,$D5,$7F,$7F,$7F,$60,$03,$E0 +box_x1: + .byte 16, 33, 0, 0, 24, 16, 15, 24, 39 +box_x2: + .byte 24, 40, 34, 16, 40, 24, 16, 25, 40 +box_y1: + .byte 130, 50, 42,120,120,159,121,121,101 +box_y2: + .byte 159, 57, 43,121,121,160,160,160,120 + + + ;========================== + ; draw box + ;========================== + ; which to draw in X + ; X preserved? + +draw_box: + lda box_y1,X ; 3 +draw_box_outer: + sta TEMPY ; 2 + tay ; 1 + lda hposn_low,Y ; 3 + sta GBASL ; 2 + lda hposn_high,Y ; 3 + sta GBASH ; 2 + ldy box_x1,X ; 3 +draw_box_inner: + tya ; 1 + lsr ; 1 + lda box_color_odd,X ; 3 + bcc draw_color_odd ; 2 ; we might have these flipped +draw_color_even: + lda box_color_even,X ; 3 +draw_color_odd: + sta (GBASL),Y ; 2 + iny ; 1 + tya ; 1 + cmp box_x2,X ; 3 + bne draw_box_inner ; 2 + + inc TEMPY ; 2 + lda TEMPY ; 2 + cmp box_y2,X ; 3 + bne draw_box_outer ; 2 + + rts ; 1 + + +companion_cube: + .byte $6F,$3D ; .@@@@.@@ @.@@@@.. + .byte $07,$38 ; .@@@.... ...@@@.. + .byte $03,$38 ; .@@..... ....@@.. + .byte $30,$03 ; .....@@. @@...... + .byte $73,$33 ; .@@..@@@ @@..@@.. + .byte $73,$33 ; .@@..@@@ @@..@@.. + .byte $60,$01 ; ......@@ @....... + .byte $43,$30 ; .@@....@ ....@@.. + .byte $07,$38 ; .@@@.... ...@@@.. + .byte $6F,$3D ; .@@@@.@@ @.@@@@.. + .byte $00,$00 + + + ;========================== + ; draw sprite + ;========================== + ; INL/INH is sprite + ; X is X location + +draw_sprite: + stx draw_sprite_xpos+1 +draw_sprite_y_smc: + lda #50 ; 2 ; Y position + sta draw_sprite_y_end_smc+1 + sec + sbc #11 +draw_sprite_outer: + sta TEMPY ; 2 + tay ; 1 + lda hposn_low,Y ; 3 + clc +draw_sprite_xpos: + adc #37 ; Xpos=37 + sta GBASL ; 2 + lda hposn_high,Y ; 3 + sta GBASH ; 2 + + ldy #0 ; 2 + + lda (INL),Y + sta (GBASL),Y + iny + lda (INL),Y + sta (GBASL),Y + + inc INL + inc INL + + inc TEMPY ; 2 + lda TEMPY ; 2 +draw_sprite_y_end_smc: + cmp #50 ; 3 + bne draw_sprite_outer ; 2 + + rts ; 1 diff --git a/demos/lovebyte2024/d2v/graphics/Makefile b/demos/lovebyte2024/d2v/graphics/Makefile new file mode 100644 index 00000000..d6a0b224 --- /dev/null +++ b/demos/lovebyte2024/d2v/graphics/Makefile @@ -0,0 +1,21 @@ +include ../../../../Makefile.inc + +ZX02 = ~/research/6502_compression/zx02.git/build/zx02 +PNG_TO_HGR = ../../../../utils/hgr-utils/png2hgr +PNG2GR = ../../../../utils/gr-utils/png2gr + +all: scene.hgr.zx02 + + +#### + +scene.hgr: scene.png + $(PNG_TO_HGR) scene.png > scene.hgr + +scene.hgr.zx02: scene.hgr + $(ZX02) scene.hgr scene.hgr.zx02 + +#### + +clean: + rm -f *~ diff --git a/demos/lovebyte2024/d2v/graphics/scene.png b/demos/lovebyte2024/d2v/graphics/scene.png new file mode 100644 index 0000000000000000000000000000000000000000..2ff6c698b3e64429de5d82bfdf60121cc3456a77 GIT binary patch literal 4544 zcmeHLeNa03dQK9P4m-k-6(4+!ky zim>66#7>$G-C--o2)ivESA1s|t#! z?)G=QrsvgGtymj<_wR>y?U~rPFkFAAX!bD^(tT^MtYvTT&DR&jqCB85tWc&)FmXmhy_GY zUa(!0)VMHg)6L4I+WEYkZMV1WN3UtM5$mRHF-BhHeTJ5(eLsHrPo^3S;c7!vTLq1SJ~D!wKa*Cw?${P-tu;_1^rg((d}x*7o8+P;wp$lvbKSkK(jlh!M1z6ngAV zP;(rP`VEg0!`G1v-%MI5heq(P(`N*HiqHsF$_%it0D6c#m{TMc!Xmp}G}6M&XmbF` zphGXUaGSsm6{V1FI@^Vl+8ols%pOTW;6wJ#Y?sX&4uOkE8)*knH&|6XYRM%!gK@}$ zmB32bon9*-_9!GnS%$?LYVLVI_``@)1-zhnvA1ILT50av=qH%rd!! zfaMm*4B!v~o0X7ROsXKcM4?bhF+_!kr6VZbbWxxxG22M5SSkWgNpXTu;-nlBTa+pY zQL2Dn2yTWDjF2NT86lQQU@sMcql;;m9Rum4?3k4lIUQE-1S>ciZ`5f75}^<39WmN4 z#sUm90zKu(_6$Q!l$}gvFjh^m0+uUPQi)QcfR%_uHVj%py4;`=Sxzx5lp@|4HZ3R! z1_+C>bqWZ);~*9^!9`*W?K07{O(S3(;Io!P(+04e2#moJF@^-BumnM233!>r;8To( zeF4i*cm$p%C`;b|LbIEPulA)piE@MW^Snd89hFLE`Fg&tjq+|KKHs}3Pz?8l;Kp)D z!s{pC@=f8Hn8Qkf(_^q)UyM^PDFsqyL8L0g0?A=a0kS4nK$ui1gXB^YK?t)1$4GoM zyPLK!xtNQLw*no3R-in+TJh(36BRugotsIrSpb4TFc9e%f{6wL7O`i>i-^^tUudHC z0!AD%z|J=Y4li&PiiQruLCx4>=T~flx%d@V0Mz4)j7i^dxyI!hlLBJ`k5|{YTw_vT zOyKeA`oGD=8@^7F4)7}|7hINpGx4iFaM21g>P=ek9e$B}2k9Re7~pcbmsWAZclU#K zXSJdQ%uR46rMo$ti6QKp%h_Gd{z(wX=nUGxyMBICxS^qu-#-G^>(#o%c$4RP&$R}7 z5j-`Z^Wa&(HTy&OPq)RSq(#Osg)`I6BYyUOs=r5}8If}1g4 zx-&Tax_++S(6e$)Mr!lU>c2Hj{&P&~H*4lCX`lJ_yE7|$i#pWn8-IEpVQRd1V^@8B zy&9^tv?4wFKh~fd3Jb4^&kkIwm=ZAD=7v<-F4VjibD-x@MZ?aPVijFTHXOe)r=jU& zcZKBI4SksPsHyAN(OG5dKmEG9u{G;LkiV}zDlSEK9Qjq7aBNh2-Wv6&n(87Z>y`rPIXZ1};?YI#Z2T|T Cevotk literal 0 HcmV?d00001 diff --git a/demos/lovebyte2024/d2v/hello.bas b/demos/lovebyte2024/d2v/hello.bas new file mode 100644 index 00000000..ac44345e --- /dev/null +++ b/demos/lovebyte2024/d2v/hello.bas @@ -0,0 +1,7 @@ +5 HOME +10 PRINT " DONT" +20 PRINT CHR$(4)"CATALOG" +25 PRINT:PRINT "PRESS ANY KEY TO 'BRUN DONT'" +30 GET A$ +35 PRINT +'40 PRINT CHR$(4)"BRUN DONT" diff --git a/demos/lovebyte2024/d2v/zx02_optim.s b/demos/lovebyte2024/d2v/zx02_optim.s new file mode 100644 index 00000000..5eebc2e0 --- /dev/null +++ b/demos/lovebyte2024/d2v/zx02_optim.s @@ -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, 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