From 5cfabce59ced4fcabd1210e3aefd42f59a09a544 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Sun, 5 Mar 2023 20:54:41 -0500 Subject: [PATCH] sb: ill advised new project --- games/sb/Makefile | 36 +++++ games/sb/graphics/Makefile | 24 +++ games/sb/graphics/strongbad_sample.png | Bin 0 -> 1125 bytes games/sb/hardware.inc | 84 +++++++++++ games/sb/hello.bas | 2 + games/sb/sb.s | 64 ++++++++ games/sb/zp.inc | 200 +++++++++++++++++++++++++ games/sb/zx02_optim.s | 144 ++++++++++++++++++ 8 files changed, 554 insertions(+) create mode 100644 games/sb/Makefile create mode 100644 games/sb/graphics/Makefile create mode 100644 games/sb/graphics/strongbad_sample.png create mode 100644 games/sb/hardware.inc create mode 100644 games/sb/hello.bas create mode 100644 games/sb/sb.s create mode 100644 games/sb/zp.inc create mode 100644 games/sb/zx02_optim.s diff --git a/games/sb/Makefile b/games/sb/Makefile new file mode 100644 index 00000000..5cf7b1bd --- /dev/null +++ b/games/sb/Makefile @@ -0,0 +1,36 @@ +include ../../Makefile.inc + +ZX02 = ~/research/6502_compression/zx02.git/build/zx02 +PNG_TO_HGR = ../../utils/hgr-utils/png2hgr +LINKER_SCRIPTS = ../../linker_scripts +DOS33 = ../../utils/dos33fs-utils/dos33 +EMPTY_DISK = ../../empty_disk/empty.dsk +TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft + +all: sb.dsk + +#### + +sb.dsk: HELLO SB + cp $(EMPTY_DISK) sb.dsk + $(DOS33) -y sb.dsk SAVE A HELLO + $(DOS33) -y sb.dsk BSAVE -a 0x0c00 SB + +#### + +SB: sb.o + ld65 -o SB sb.o -C $(LINKER_SCRIPTS)/apple2_c00.inc + +sb.o: sb.s zx02_optim.s \ + zp.inc hardware.inc + ca65 -o sb.o sb.s -l sb.lst + +#### + +HELLO: hello.bas + $(TOKENIZE) < hello.bas > HELLO + +#### + +clean: + rm -f *.lst *.o SB *~ diff --git a/games/sb/graphics/Makefile b/games/sb/graphics/Makefile new file mode 100644 index 00000000..972ad3ea --- /dev/null +++ b/games/sb/graphics/Makefile @@ -0,0 +1,24 @@ +include ../../../Makefile.inc + +ZX02 = ~/research/6502_compression/zx02.git/build/zx02 +PNG_TO_HGR = ../../../utils/hgr-utils/png2hgr +LINKER_SCRIPTS = ../../../linker_scripts +DOS33 = ../../../utils/dos33fs-utils/dos33 +EMPTY_DISK = ../../../empty_disk/empty.dsk +TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft + +all: strongbad_sample.hgr.zx02 + +#### + +strongbad_sample.hgr.zx02: strongbad_sample.hgr + $(ZX02) strongbad_sample.hgr strongbad_sample.hgr.zx02 + +strongbad_sample.hgr: strongbad_sample.png + $(PNG_TO_HGR) strongbad_sample.png > strongbad_sample.hgr + +#### + +clean: + rm -f *~ *.o *.lst + diff --git a/games/sb/graphics/strongbad_sample.png b/games/sb/graphics/strongbad_sample.png new file mode 100644 index 0000000000000000000000000000000000000000..16cb6b5959a1a875a58429e0df6795cd2b9ebae4 GIT binary patch literal 1125 zcmV-r1e*JaP)EX>4Tx04R}tkv&MmKpe$i(@I4u4t5X`$xt1{E-K=vRVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRAQI0q!?cMvh^IGg zgY!Odl$B(a_?&p$qze*1a$WKGjdRgufoDd|OnRO;N-P#TSm|I^GBx5U;+U%GlrLmG zRyl8R)+#mDx+i~OB(JY5bDic8l32tNB#2N@Lm3s=h|{W*Vj)fY2_OHU>zBx-kgE(v zjs;YqL3aJ%fAG6ot1vm?B}EcI*NfwPi~!+XpjmgE?_;0000IP)t-s0000R%K_vx{{R2~&07H*n*NcW zLm2=7010qNS#tmY7)$^F7<2)js6Ze9000McNliru=K}-eSad^g zZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00J>dL_t(|+U?g1PQx$|gyB&+L2rQO z1W0=p?tc}c7TTor;ds~Hl{#x70TSWU53v&vbrwJ^l~Ea$*)Dss=9aM?Ykmv22y+~f zg)DG+%GiLFU!*~U`I7y0Z1`#|W0O{mDi1Wsle}(YnHpqDp0%-T4YDm(rpk>5`4%hG zWu-v{ixui}(ZFZ9H@-G;4v(q7Ow07N86)ZO0OKTkJ$uXa&4@CdX>BvZ(&lL|!x@@M zk|qu2SzdcE)k0^P=<$>pF}-CtRf7ZzyUK8~1__df8su2GtIUjPEyENI5-n^h!z2w- zEqqyqX&NM3__PcYHAuJcVHp-G!$M`4tf^3jrONP58D?ux!@`>~%-5ibg{v|>gVV&9 z>9?Rp8H8)#w!~q6%eXLc8g$=DBQV`}^%ZldQRaA_8f9pqyCqzIrK6c0EwGFSvsfaJ z5qAD^h0JXqJzB4C6Q82n>Z8{A}gHupoxQ+{gSrN|eA{O=*}- zl4J}v&*GIZ$i|Pz%m%VBL;is5O5V?gc0WLFw1<-yoxZw2qTOz zH + + +.include "zp.inc" +.include "hardware.inc" + + +hires_start: + + ;=================== + ; set graphics mode + ;=================== + jsr HOME + + bit HIRES + bit FULLGR + bit SET_GR + bit PAGE0 + + + ;=================== + ; Load graphics + ;=================== +load_loop: + + ;============================= + + + ;========================== + ; Load Image + ;=========================== + +load_image: + + ; size in ldsizeh:ldsizel (f1/f0) + +; comp_data = $a000 + out_addr = $2000 + + + jsr full_decomp + + rts + + + +wait_until_keypress: + lda KEYPRESS ; 4 + bpl wait_until_keypress ; 3 + bit KEYRESET ; clear the keyboard buffer + +which_ok: + jmp load_loop + + + + + .include "zx02_optim.s" + + +comp_data: + .incbin "graphics/strongbad_sample.hgr.zx02" diff --git a/games/sb/zp.inc b/games/sb/zp.inc new file mode 100644 index 00000000..311a38ff --- /dev/null +++ b/games/sb/zp.inc @@ -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 + diff --git a/games/sb/zx02_optim.s b/games/sb/zx02_optim.s new file mode 100644 index 00000000..5f6121f2 --- /dev/null +++ b/games/sb/zx02_optim.s @@ -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, 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