From 2bed77b2f814230bb0caff419f096cd670e7a96e Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 22 Aug 2024 14:39:24 -0400 Subject: [PATCH] peasant_mini: fix up so it compiles --- games/peasant/NOTES | 15 +-- games/peasant_mini/cliff/Makefile | 28 +++-- games/peasant_mini/cliff/cliff.s | 4 +- games/peasant_mini/cliff/hello.bas | 6 + games/peasant_mini/cliff/hgr_tables.s | 149 +++++++++++++++++++++++ games/peasant_mini/cliff/zx02_optim.s | 163 ++++++++++++++++++++++++++ 6 files changed, 348 insertions(+), 17 deletions(-) create mode 100644 games/peasant_mini/cliff/hello.bas create mode 100644 games/peasant_mini/cliff/hgr_tables.s create mode 100644 games/peasant_mini/cliff/zx02_optim.s diff --git a/games/peasant/NOTES b/games/peasant/NOTES index d6501701..0a8dfa9e 100644 --- a/games/peasant/NOTES +++ b/games/peasant/NOTES @@ -1,11 +1,12 @@ Dialog issues: - Uncompressed LZSA - DIALOG_PEASANT1 7394 4002 - DIALOG_PEASANT2 6857 3943 - DIALOG_PEASANT3 5809 3411 - DIALOG_PEASANT4 6900 3851 - DIALOG_CLIFF 4768 2825 - DIALOG_INSIDE 10832 5741 + Uncompressed LZSA ZX02 + DIALOG_PEASANT1 7394 4002 3804 + DIALOG_PEASANT2 6857 3943 3736 + DIALOG_PEASANT3 5809 3411 3201 + DIALOG_PEASANT4 6900 3851 3508 + DIALOG_CLIFF 4768 2825 2644 + DIALOG_INSIDE 10832 5741 3594 + DIALOG_INN 1840 Inventory: diff --git a/games/peasant_mini/cliff/Makefile b/games/peasant_mini/cliff/Makefile index 1df2cadb..ab8e0530 100644 --- a/games/peasant_mini/cliff/Makefile +++ b/games/peasant_mini/cliff/Makefile @@ -1,21 +1,33 @@ include ../../../Makefile.inc ZX02 = ~/research/6502_compression/zx02.git/build/zx02 -PNG_TO_HGR = ../../utils/hgr-utils/png2hgr +PNG_TO_HGR = ../../..utils/hgr-utils/png2hgr LINKER_SCRIPTS = ../../../linker_scripts -DOS33 = ../../utils/dos33fs-utils/dos33 -DOS33_RAW = ../../utils/dos33fs-utils/dos33_raw -EMPTY_DISK = ../../empty_disk/empty.dsk -TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft +DOS33 = ../../../utils/dos33fs-utils/dos33 +DOS33_RAW = ../../../utils/dos33fs-utils/dos33_raw +EMPTY_DISK = ../../../empty_disk/empty.dsk +TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft -all: CLIFF +all: cliff.dsk + +#### + +cliff.dsk: HELLO CLIFF + cp $(EMPTY_DISK) cliff.dsk + $(DOS33) -y cliff.dsk SAVE A HELLO + $(DOS33) -y cliff.dsk BSAVE -a 0x6000 CLIFF + +### + +HELLO: hello.bas + $(TOKENIZE) < hello.bas > HELLO #### CLIFF: cliff.o ld65 -o CLIFF cliff.o -C $(LINKER_SCRIPTS)/apple2_6000.inc -cliff.o: cliff.s ../zx02_optim.s \ +cliff.o: cliff.s zx02_optim.s \ hgr_copy.s hgr_partial_save.s \ cliff_graphics/cliff_base.hgr.zx02 \ zp.inc hardware.inc @@ -27,5 +39,5 @@ cliff_graphics/cliff_base.hgr.zx02: #### clean: - rm -f *.lst *.o CLIFF + rm -f *.lst *.o CLIFF HELLO cd cliff_graphics && make clean diff --git a/games/peasant_mini/cliff/cliff.s b/games/peasant_mini/cliff/cliff.s index 88011971..e0c3218d 100644 --- a/games/peasant_mini/cliff/cliff.s +++ b/games/peasant_mini/cliff/cliff.s @@ -137,9 +137,9 @@ done_cliff: rts - .include "../hgr_tables.s" + .include "hgr_tables.s" - .include "../zx02_optim.s" + .include "zx02_optim.s" .include "wait.s" diff --git a/games/peasant_mini/cliff/hello.bas b/games/peasant_mini/cliff/hello.bas new file mode 100644 index 00000000..617bb64a --- /dev/null +++ b/games/peasant_mini/cliff/hello.bas @@ -0,0 +1,6 @@ +5 HOME +10 PRINT "LOADING CLIFF V0.00" +96 PRINT +100 PRINT " ______" +110 PRINT " A \/\/\/ SOFTWARE PRODUCTION" +120 PRINT CHR$(4);"BRUN CLIFF" diff --git a/games/peasant_mini/cliff/hgr_tables.s b/games/peasant_mini/cliff/hgr_tables.s new file mode 100644 index 00000000..5dfdd6b3 --- /dev/null +++ b/games/peasant_mini/cliff/hgr_tables.s @@ -0,0 +1,149 @@ +;div7_table = $9C00 +;mod7_table = $9D00 +;hposn_high = $9E00 +;hposn_low = $9F00 + + + + ;===================== + ; make /7 %7 tables + ;===================== + + + ; HGR_PAGE should be $20/$40 to select if default for hposn + ; is page1 or page2 + +hgr_make_tables: + + ; for riven we aren't drawing lines so don't need mod/div tables +.if 0 + + ldy #0 + lda #0 + ldx #0 +div7_loop: + sta div7_table,Y + + inx + cpx #7 + bne div7_not7 + + clc + adc #1 + ldx #0 +div7_not7: + iny + bne div7_loop + + + ldy #0 + lda #0 +mod7_loop: + sta mod7_table,Y + clc + adc #1 + cmp #7 + bne mod7_not7 + lda #0 +mod7_not7: + iny + bne mod7_loop +.endif + + ; Hposn table + + lda #0 +hposn_loop: + ldy #0 + ldx #0 + pha + jsr hposn ; (Y,X),(A) + pla + tax + + lda GBASL + sta hposn_low,X + + lda GBASH + sta hposn_high,X + + inx + txa + + cmp #192 + bne hposn_loop + + rts + + ; left masks + ; in memory on screen + ; x111 1111 1111111 start at 0 + ; x111 1110 0111111 start at 1 + ; x111 1100 0011111 start at 2 + ; ... + ; x100 0000 0000001 start at 6 + +left_masks: + .byte $FF,$FE,$FC,$F8, $F0,$E0,$C0 + + ; right masks + ; in memory on screen + ; x000 0001 1000000 end at 0 + ; x000 0011 1100000 end at 1 + ; x000 0111 1110000 end at 2 + ; ... + ; x011 1111 1111110 end at 5 + ; x111 1111 1111111 end at 6 +right_masks: + .byte $81,$83,$87, $8F,$9F,$BF,$FF + + + + + ; from the Apple II firmware +hposn: +; sta HGR_Y ; save Y and X positions +; stx HGR_X +; sty HGR_X+1 + + pha ; Y pos on stack + + and #$C0 ; calc base addr for Y-pos + + sta GBASL + lsr + lsr + ora GBASL + sta GBASL + pla + + sta GBASH + asl + asl + asl + rol GBASH + asl + rol GBASH + asl + ror GBASL + lda GBASH + + and #$1F + + ora HGR_PAGE ; default is $40 in this game + + sta GBASH + +; txa +; cpy #0 +; beq xpos_lessthan_256 +; ldy #35 +; adc #4 +;label_1: +; iny +;xpos_lessthan_256: +; sbc #7 +; bcs label_1 + + rts + diff --git a/games/peasant_mini/cliff/zx02_optim.s b/games/peasant_mini/cliff/zx02_optim.s new file mode 100644 index 00000000..8b88caf8 --- /dev/null +++ b/games/peasant_mini/cliff/zx02_optim.s @@ -0,0 +1,163 @@ +; 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 ; offset +;comp_data: +; .byte $0, $0 ; zx0_src +;out_addr: +; .byte $0, $0 ; zx0_dst +; .byte $80 ; bitr + +;-------------------------------------------------- +; Decompress ZX0 data (6502 optimized format) + + ; destination page in A +full_decomp: + sta ZX0_dst+1 + + ldy #$80 + sty bitr + + ldy #0 ; always on page boundary + sty ZX0_dst + + sty offset + sty offset+1 + + ; Y needs to be 0 here + + ; 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