From 95550fcf704dbecc55560fa5f864475cee7147a4 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Wed, 11 Mar 2020 17:41:16 -0700 Subject: [PATCH] support compressed HGR/SHR --- src/4cade.a | 2 + src/exodecrunch.a | 427 +++++++++++++++++++++++++++++++++++++++++++ src/ui.attract.hgr.a | 32 +++- src/ui.attract.shr.a | 30 ++- winmake.bat | 8 +- 5 files changed, 488 insertions(+), 11 deletions(-) create mode 100644 src/exodecrunch.a diff --git a/src/4cade.a b/src/4cade.a index 9d478da98..7236f31ed 100644 --- a/src/4cade.a +++ b/src/4cade.a @@ -108,6 +108,8 @@ ResetVector ; 6 bytes, copied to $100 !source "src/glue.prorwts2.a" !source "src/ui.common.a" + !source "src/exodecrunch.a" + ; add new files above here so ui.wait stays last !source "src/ui.attract.dhgr.a" ; \-- execution falls through diff --git a/src/exodecrunch.a b/src/exodecrunch.a new file mode 100644 index 000000000..420b25563 --- /dev/null +++ b/src/exodecrunch.a @@ -0,0 +1,427 @@ +; This source code is altered and is not the original version found on +; the Exomizer homepage. +; It contains modifications made by qkumba to work with ACME assembler. + +; +; Copyright (c) 2002 - 2018 Magnus Lind. +; +; 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 distribution. +; +; 4. The names of this software and/or it's copyright holders may not be +; used to endorse or promote products derived from this software without +; specific prior written permission. +; +; ------------------------------------------------------------------- +; The decruncher jsr:s to the get_crunched_byte address when it wants to +; read a crunched byte into A. This subroutine has to preserve X and Y +; register and must not modify the state of the carry nor the overflow flag. +; ------------------------------------------------------------------- +;.import get_crunched_byte +; ------------------------------------------------------------------- +; this function is the heart of the decruncher. +; It initializes the decruncher zeropage locations and precalculates the +; decrunch tables and decrunches the data +; This function will not change the interrupt status bit and it will not +; modify the memory configuration. +; ------------------------------------------------------------------- +;.export decrunch + +; ------------------------------------------------------------------- +; Controls if the shared get_bits routines should be inlined or not. +;INLINE_GET_BITS=1 +; ------------------------------------------------------------------- +; if literal sequences is not used (the data was crunched with the -c +; flag) then the following line can be uncommented for shorter and. +; slightly faster code. +;LITERAL_SEQUENCES_NOT_USED = 1 +; ------------------------------------------------------------------- +; if the sequence length is limited to 256 (the data was crunched with +; the -M256 flag) then the following line can be uncommented for +; shorter and slightly faster code. +;MAX_SEQUENCE_LENGTH_256 = 1 +; ------------------------------------------------------------------- +; if the sequence length 3 has its own offset table then the following +; line can be uncommented for in some situations slightly better +; compression at the cost of a larger decrunch table. +EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE = 1 +; ------------------------------------------------------------------- +; zero page addresses used +; ------------------------------------------------------------------- +zp_len_lo = $a7 +zp_len_hi = $a8 + +zp_src_lo = $ae +zp_src_hi = zp_src_lo + 1 + +zp_bits_hi = $fc + +zp_bitbuf = $fd +zp_dest_lo = zp_bitbuf + 1 ; dest addr lo +zp_dest_hi = zp_bitbuf + 2 ; dest addr hi + +!IFDEF EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE { +encoded_entries = 68 +} ELSE { +encoded_entries = 52 +} + +tabl_bi = decrunch_table +tabl_lo = decrunch_table + encoded_entries +tabl_hi = decrunch_table + encoded_entries * 2 + + ;; refill bits is always inlined +!MACRO mac_refill_bits { + pha + jsr get_crunched_byte + rol + sta zp_bitbuf + pla +} + +!IFDEF INLINE_GET_BITS { +!MACRO mac_get_bits { + adc #$80 ; needs c=0, affects v + asl + bpl gb_skip +gb_next: + asl zp_bitbuf + bne gb_ok + mac_refill_bits +gb_ok: + rol + bmi gb_next +gb_skip: + bvc skip +gb_get_hi: + sec + sta zp_bits_hi + jsr get_crunched_byte +skip: +} +} ELSE { +!MACRO mac_get_bits { + jsr get_bits +} +get_bits: + adc #$80 ; needs c=0, affects v + asl + bpl gb_skip +gb_next: + asl zp_bitbuf + bne gb_ok + +mac_refill_bits +gb_ok: + rol + bmi gb_next +gb_skip: + bvs gb_get_hi + rts +gb_get_hi: + sec + sta zp_bits_hi + jmp get_crunched_byte +} +; ------------------------------------------------------------------- +; no code below this comment has to be modified in order to generate +; a working decruncher of this source file. +; However, you may want to relocate the tables last in the file to a +; more suitable address. +; ------------------------------------------------------------------- + +; ------------------------------------------------------------------- +; jsr this label to decrunch, it will in turn init the tables and +; call the decruncher +; no constraints on register content, however the +; decimal flag has to be #0 (it almost always is, otherwise do a cld) +decrunch: +; ------------------------------------------------------------------- +; init zeropage, x and y regs. (12 bytes) +; + ldy #0 + ldx #3 +init_zp: + jsr get_crunched_byte + sta zp_bitbuf - 1,x + dex + bne init_zp +; ------------------------------------------------------------------- +; calculate tables (62 bytes) + get_bits macro +; x and y must be #0 when entering +; + clc +table_gen: + tax + tya + and #$0f + sta tabl_lo,y + beq shortcut ; start a new sequence +; ------------------------------------------------------------------- + txa + adc tabl_lo - 1,y + sta tabl_lo,y + lda zp_len_hi + adc tabl_hi - 1,y +shortcut: + sta tabl_hi,y +; ------------------------------------------------------------------- + lda #$01 + sta game title stx gGameToLaunch - jsr LoadFile ; load HGR screenshot at $4000 + jsr LoadFile ; load compressed HGR screenshot at $3FF8 !word kHGRActionDirectory + !word $FDFD ; SMC - !word $4000 - + !word $3FF8 + jsr DecompressHGR jmp DrawGameTitleInActionSlideshowHGR + +;------------------------------------------------------------------------------ +; DecompressHGR [private] +; +; in: compressed HGR loaded to $3FF8+ +; file size in sizelo2/sizehi2 as set by ProRWTS2 +; out: decompressed HGR at $4000..$5FFF +; $00A7..$00A8 clobbered by decompressor +; $00AE..$00AF clobbered by decompressor +; $00FC..$00FF clobbered by decompressor +; $0200..$02CB clobbered by decompressor +;------------------------------------------------------------------------------ +DecompressHGR + clc + lda sizelo2 + adc #$F8 + sta _byte_lo + lda sizehi2 + adc #$3F + sta _byte_hi + jmp decrunch diff --git a/src/ui.attract.shr.a b/src/ui.attract.shr.a index 4f43e0e03..76e336291 100644 --- a/src/ui.attract.shr.a +++ b/src/ui.attract.shr.a @@ -50,7 +50,8 @@ SHRSingle jsr LoadFile !word kRootDirectory + !word $FDFD ; SMC - !word $2000 + !word $1FF8 + jsr DecompressSHR jsr LoadSHRTransition jsr ExecuteTransitionAtA000AndWait jmp BlankHGR @@ -96,12 +97,12 @@ SHRArtworkCallback jsr BlankSHR - ; load SHR artwork at $2000/main (not aux) + ; load compressed SHR artwork at $1FF8/main (not aux) jsr LoadFile !word kSHRArtworkDirectory @sfname !word $FDFD - !word $2000 - + !word $1FF8 + jsr DecompressSHR jmp ExecuteTransitionAtA000AndWait ;------------------------------------------------------------------------------ @@ -140,3 +141,24 @@ BlankSHR sta NEWVIDEO rts + +;------------------------------------------------------------------------------ +; DecompressSHR [private] +; +; in: compressed SHR loaded to $1FF8+ +; file size in sizelo2/sizehi2 as set by ProRWTS2 +; out: decompressed SHR at $2000..$9FFF +; $00A7..$00A8 clobbered by decompressor +; $00AE..$00AF clobbered by decompressor +; $00FC..$00FF clobbered by decompressor +; $0200..$02CB clobbered by decompressor +;------------------------------------------------------------------------------ +DecompressSHR + clc + lda sizelo2 + adc #$F8 + sta _byte_lo + lda sizehi2 + adc #$1F + sta _byte_hi + jmp decrunch diff --git a/winmake.bat b/winmake.bat index 0eded10b6..6a64c6bc1 100644 --- a/winmake.bat +++ b/winmake.bat @@ -13,6 +13,8 @@ set VOLUME=TOTAL.REPLAY rem third-party tools required to build (must be in path) rem https://sourceforge.net/projects/acme-crossass/ set ACME=acme +rem https://bitbucket.org/magli143/exomizer/wiki/Home +set EXOMIZER=exomizer mem -q -P23 -lnone rem https://www.brutaldeluxe.fr/products/crossdevtools/cadius/ rem https://github.com/mach-kernel/cadius set CADIUS=cadius @@ -54,10 +56,11 @@ for %%q in (build\*.CONF) do %CADIUS% ADDFILE "build\%DISK%" "/%VOLUME%/" "%%q" %CADIUS% ADDFILE "build\%DISK%" "/%VOLUME%/" "build\HELPTEXT" >>build\log cscript /nologo bin\rsync.js res\title.hgr\* build\TITLE.HGR >>build\log cscript /nologo bin\rsync.js res\title.dhgr\* build\TITLE.DHGR >>build\log -cscript /nologo bin\rsync.js res\action.hgr\* build\ACTION.HGR >>build\log +for %%q in (res\action.hgr\*) do if not exist build\%%~nxq %EXOMIZER% res\action.hgr\%%~nxq@0x4000 -o build\ACTION.HGR\%%~nxq +cscript /nologo bin\rsync.js res\title.dgr\* build\TITLE.DGR >>build\log cscript /nologo bin\rsync.js res\action.dhgr\* build\ACTION.DHGR >>build\log cscript /nologo bin\rsync.js res\action.gr\* build\ACTION.GR >>build\log -cscript /nologo bin\rsync.js res\artwork.shr\* build\ARTWORK.SHR >>build\log +for %%q in (res\artwork.shr\*) do if not exist build\%%~nxq %EXOMIZER% res\artwork.shr\%%~nxq@0x2000 -o build\ARTWORK.SHR\%%~nxq cscript /nologo bin\rsync.js res\attract\* build\ATTRACT >>build\log cscript /nologo bin\rsync.js res\ss\* build\SS >>build\log cscript /nologo bin\rsync.js res\demo\* build\DEMO >>build\log @@ -148,4 +151,5 @@ for %%q in (src\prelaunch\*.a) do ( set _to=!_to:~0,1! if !_to!==t %ACME% %%q for %%q in (res\title.hgr\*) do if not exist build\prelaunch\%%~nxq 1>nul copy build\prelaunch\standard build\prelaunch\%%~nxq +for %%q in (res\title.dhgr\*) do if not exist build\prelaunch\%%~nxq 1>nul copy build\prelaunch\standard build\prelaunch\%%~nxq )