From 567bdf7edd88f698ca57a8369c8bccc6d33735ff Mon Sep 17 00:00:00 2001 From: 4am Date: Wed, 18 Apr 2018 16:39:59 -0400 Subject: [PATCH] move more one-time initialization code before WeeGUI, centralize entry point address --- Makefile | 1 + bin/fixFileInformation.sh | 4 ++ res/_FileInformation.txt | 2 +- src/constants.a | 6 +++ src/glue.onbeyond.a | 18 -------- src/loader/grue.system.s | 6 ++- src/parse.gamelist.a | 37 --------------- src/parse.prefs.a | 34 +++----------- src/pitchdark.a | 24 ++++------ src/pitchdark.init.a | 97 +++++++++++++++++++++++++++++++++++++++ src/prodos.ramdisk.a | 71 ---------------------------- 11 files changed, 129 insertions(+), 171 deletions(-) create mode 100755 bin/fixFileInformation.sh delete mode 100644 src/parse.gamelist.a create mode 100644 src/pitchdark.init.a diff --git a/Makefile b/Makefile index 7f29f8e..9bb59fa 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ asm: md dsk: md asm cp res/"Pitch Dark.master games collection.do.not.edit.2mg" build/"$(DISK)" cp res/_FileInformation.txt build/ + bin/fixFileInformation.sh build/_FileInformation.txt $(CADIUS) ADDFILE build/"$(DISK)" "/PITCH.DARK/" "build/GRUE.SYSTEM" $(CADIUS) ADDFILE build/"$(DISK)" "/PITCH.DARK/" "build/ONBEYOND.SYSTEM" $(CADIUS) ADDFILE build/"$(DISK)" "/PITCH.DARK/" "build/ZINFO.SYSTEM" diff --git a/bin/fixFileInformation.sh b/bin/fixFileInformation.sh new file mode 100755 index 0000000..fca31d9 --- /dev/null +++ b/bin/fixFileInformation.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +addr=`grep kPitchDarkBinaryAddress src/constants.a | cut -d"$" -f2` +sed -i -e "s/kPitchDarkBinaryAddress/$addr/g" "$1" diff --git a/res/_FileInformation.txt b/res/_FileInformation.txt index 40fb1d0..1f2b181 100644 --- a/res/_FileInformation.txt +++ b/res/_FileInformation.txt @@ -1,5 +1,5 @@ GRUE.SYSTEM=Type(FF),AuxType(2000),Access(C3) -PITCH.DARK=Type(06),AuxType(3FE3),Access(C3) +PITCH.DARK=Type(06),AuxType(kPitchDarkBinaryAddress),Access(C3) PITCH.DARK.CONF=Type(04),AuxType(0000),Access(C3) GAMES.CONF=Type(04),AuxType(0000),Access(C3) ONBEYOND.SYSTEM=Type(FF),AuxType(2000),Access(C3) diff --git a/src/constants.a b/src/constants.a index eb437cc..6301ae6 100644 --- a/src/constants.a +++ b/src/constants.a @@ -17,6 +17,8 @@ ;~7400...... - program data (approximate) ; +kPitchDarkBinaryAddress = $3F4D + kGameInfoBuffer = $0800 ; used by LoadGameInfo kProDOSFileBuffer = $1C00 ; 1K buffer for ProDOS MLI calls kSystemAddress = $2000 ; used by LaunchInterpreter @@ -28,6 +30,10 @@ gKey = $3F01 gValLen = $3F80 gVal = $3F81 WGInit = $4000 ; WeeGUI file load address and initialization function +NODEV = $BF10 ; means 'no device connected' +RAM32 = $BF26 ; S3,D2 /RAM device +DEVCNT = $BF31 ; ProDOS device count +DEVLST = $BF32 ; ProDOS device list MAGICRTS = $FF58 ; used to set overflow bit ; zero page diff --git a/src/glue.onbeyond.a b/src/glue.onbeyond.a index 82a147c..e92513d 100644 --- a/src/glue.onbeyond.a +++ b/src/glue.onbeyond.a @@ -4,7 +4,6 @@ ; glue code to load, set up, and launch the On Beyond Z-Machine! interpreter ; ; Public functions -; - ClearInterpreterOptions ; - LaunchInterpreterWithNewGame ; - LaunchInterpreterWithGame ; - LaunchInterpreterWithHints @@ -27,23 +26,6 @@ kOnBeyondAutoScript = $0304 kOnBeyondWarnMissing = $0305 kOnBeyondChecksum = $0306 -;------------------------------------------------------------------------------ -; ClearInterpreterOptions -; clear options script and make checksum invalid -; -; in: none -; out: A/Y clobbered -; X preserved -; all flags clobbered -;------------------------------------------------------------------------------ -ClearInterpreterOptions - ldy #(kOnBeyondChecksum-kOnBeyondOptionsStruct) - lda #0 -- sta kOnBeyondOptionsStruct,y - dey - bpl - - rts - ;------------------------------------------------------------------------------ ; LaunchInterpreterWithGame ; load interpreter and launch it with a game based on global preferences store, diff --git a/src/loader/grue.system.s b/src/loader/grue.system.s index 593f092..1b3e029 100644 --- a/src/loader/grue.system.s +++ b/src/loader/grue.system.s @@ -5,6 +5,8 @@ *=$2000 !to "build/GRUE.SYSTEM",plain + !source "src/constants.a" + lda $BF98 ; machine identification byte and #$30 cmp #$30 ; 128K? @@ -90,7 +92,7 @@ reloc cld jsr $bf00 !byte $cc !word cc_parms - jmp $3FE3 + jmp kPitchDarkBinaryAddress c7_parms c6_parms @@ -106,7 +108,7 @@ c8_parms ca_parms !byte 4 !byte $d1 - !word $3FE3 + !word kPitchDarkBinaryAddress !word $ffff !word $34d1 diff --git a/src/parse.gamelist.a b/src/parse.gamelist.a deleted file mode 100644 index c42778f..0000000 --- a/src/parse.gamelist.a +++ /dev/null @@ -1,37 +0,0 @@ -;license:MIT -;(c) 2018 by 4am -; -; Parser for game list file -; -; Public functions -; - LoadGameList -; - -;------------------------------------------------------------------------------ -; LoadGameList -; load file with master game list -; -; in: current ProDOS prefix is the same as the GAMES.CONF file -; out: gGamesListStore populated -; all registers and flags clobbered -;------------------------------------------------------------------------------ -!zone { -LoadGameList - jsr LoadFile ; load prefs file at $2000 - !word .gamesListFilename -.handle !word $2000 - !word kProDOSFileBuffer - - jsr ParseKeyValueText ; parse contents into games list store - !word gGamesListStore - !word .handle - !byte 0 - - +LDAY SRC - +STAY gGlobalPrefsStore ; save pointer to free space for next store - rts - -.gamesListFilename - !byte 10 - !raw "GAMES.CONF" -} diff --git a/src/parse.prefs.a b/src/parse.prefs.a index 324d229..5f4718f 100644 --- a/src/parse.prefs.a +++ b/src/parse.prefs.a @@ -13,6 +13,7 @@ ; set to 1 if prefs have changed. SaveGlobalPreferences won't write to disk if this is 0. ; ; Public constants (all length-prefixed strings) +; - kGlobalPrefsFilename ; - kForce40 ; - kForceUpper ; - kScriptToFile @@ -27,6 +28,10 @@ gGlobalPrefsStore gGlobalPrefsDirty !byte 0 +kGlobalPrefsFilename + !byte 15 + !raw "PITCH.DARK.CONF" + kForce40 !byte 14 !raw "FORCE40COLUMNS" @@ -43,29 +48,6 @@ kLastPlayed !byte 10 !raw "LASTPLAYED" -;------------------------------------------------------------------------------ -; LoadGlobalPreferences -; load global options and state (including current game) from file and populate -; global prefs store -; -; in: current ProDOS prefix is the same as the PITCH.DARK.CONF file -; out: all registers and flags clobbered -;------------------------------------------------------------------------------ -LoadGlobalPreferences - stz gGlobalPrefsDirty - - jsr LoadFile ; load prefs file at $2000 - !word .globalPrefsFilename -.handle !word kGlobalPrefsBuffer - !word kProDOSFileBuffer - - jsr ParseKeyValueText ; parse contents into global prefs store - !word gGlobalPrefsStore - !word .handle - !byte 16 - - +LDAY SRC - +STAY gVersionsStore ; save pointer to free space for next store .exit rts ;------------------------------------------------------------------------------ @@ -122,7 +104,7 @@ SaveGlobalPreferences sta .filelen+1 jsr SaveFile - !word .globalPrefsFilename + !word kGlobalPrefsFilename !byte 4 ; filetype=TXT !word 0 ; auxtype=0000 !word kGlobalPrefsBuffer @@ -182,10 +164,6 @@ addString bne - rts -.globalPrefsFilename - !byte 15 - !raw "PITCH.DARK.CONF" - .equals !byte 1 !raw "=" .lf !byte 1 diff --git a/src/pitchdark.a b/src/pitchdark.a index fc246f4..f03bcfc 100644 --- a/src/pitchdark.a +++ b/src/pitchdark.a @@ -13,34 +13,30 @@ !cpu 65c02 !ct "src/lcase.ct" !to "build/PITCH.DARK",plain -*=$3FE3 + + !source "src/constants.a" + !source "src/macros.a" + !source "src/WeeGUI_MLI.s" + +*=kPitchDarkBinaryAddress jsr QuitUnless128KAnd65C02; check minimum hardware requirements - jsr DisconnectRAM32 ; disconnect /RAM in S3,D2 - jsr ClearInterpreterOptions ; clear options struct at $300 - jsr WGInit ; initialize WeeGUI - jsr LoadGameList ; get master list of games - jsr LoadGlobalPreferences ; get global options, including current game + !source "src/pitchdark.init.a" jsr LoadGameInfo ; get current game description and game-specific options + jsr WGInit ; initialize WeeGUI ldx #WGEnableMouse ; enable mouse support jsr WeeGUI jmp MainScreen -!if * != $4000 { - !serious "WeeGUI library must start at $4000" +!if *!=$4000 { + !serious "WeeGUI library must start at $4000, set kPitchDarkBinaryAddress to ",kPitchDarkBinaryAddress+$4000-* } !bin "res/WEEGUI" - !source "src/macros.a" - !source "src/constants.a" - !source "src/WeeGUI_MLI.s" - !source "src/okvs.a" !source "src/prodos.mli.a" - !source "src/prodos.ramdisk.a" !source "src/prodos.path.a" !source "src/parse.common.a" - !source "src/parse.gamelist.a" !source "src/parse.gameinfo.a" !source "src/parse.prefs.a" !source "src/glue.common.a" diff --git a/src/pitchdark.init.a b/src/pitchdark.init.a new file mode 100644 index 0000000..df55bfa --- /dev/null +++ b/src/pitchdark.init.a @@ -0,0 +1,97 @@ +;------------------------------------------------------------------------------ +; disconnect ProDOS /RAM disk in S3,D2 +; (does not affect other RAM disks like RAMWorks or RAMFactor) +; see ProDOS TechNote #26 Polite Use of Auxiliary Memory +; and ProDOS 8 Technical Reference Manual 5.2.2.2 Disconnecting /RAM +;------------------------------------------------------------------------------ + lda RAM32 + cmp NODEV + bne + + lda RAM32+1 + cmp NODEV+1 + beq .noRAMdisk ++ ldy DEVCNT +- lda DEVLST, y + and #$F3 + cmp #$B3 + beq .foundRAMdisk + dey + bpl - + bmi .noRAMdisk +.foundRAMdisk + lda DEVLST, y + sta saveRAMDiskUnit ; save RAM disk unit number +- lda DEVLST+1, y ; move other devices up in list + sta DEVLST, y + beq + ; device list is zero-terminated + iny + bne - ; always branches ++ + lda RAM32 + sta saveRAMDiskDriver ; save RAM disk device address + lda RAM32+1 + sta saveRAMDiskDriver+1 + lda NODEV ; tell ProDOS there's no RAM disk anymore + sta RAM32 + lda NODEV+1 + sta RAM32+1 + dec DEVCNT ; reduce ProDOS device count +.noRAMdisk + bra + +saveRAMDiskUnit + !byte 0 +saveRAMDiskDriver + !word 0 ++ + +;------------------------------------------------------------------------------ +; clear options script and make checksum invalid +;------------------------------------------------------------------------------ +ClearInterpreterOptions + ldy #(kOnBeyondChecksum-kOnBeyondOptionsStruct) + lda #0 +- sta kOnBeyondOptionsStruct,y + dey + bpl - + +;------------------------------------------------------------------------------ +; load file with master game list +;------------------------------------------------------------------------------ + jsr LoadFile ; load prefs file at $2000 + !word .gamesListFilename +.gamesListHandle + !word $2000 + !word kProDOSFileBuffer + + jsr ParseKeyValueText ; parse contents into games list store + !word gGamesListStore + !word .gamesListHandle + !byte 0 + + +LDAY SRC + +STAY gGlobalPrefsStore ; save pointer to free space for next store + bra + + +.gamesListFilename + !byte 10 + !raw "GAMES.CONF" ++ + +;------------------------------------------------------------------------------ +; load global options and state (including current game) from file and populate +; global prefs store +;------------------------------------------------------------------------------ + stz gGlobalPrefsDirty + jsr LoadFile ; load prefs file at $2000 + !word kGlobalPrefsFilename +.globalPrefsHandle + !word kGlobalPrefsBuffer + !word kProDOSFileBuffer + + jsr ParseKeyValueText ; parse contents into global prefs store + !word gGlobalPrefsStore + !word .globalPrefsHandle + !byte 16 + + +LDAY SRC + +STAY gVersionsStore ; save pointer to free space for next store diff --git a/src/prodos.ramdisk.a b/src/prodos.ramdisk.a index ffd34d9..e69de29 100644 --- a/src/prodos.ramdisk.a +++ b/src/prodos.ramdisk.a @@ -1,71 +0,0 @@ -;license:MIT -;(c) 2018 by 4am -; -; /RAM routines -; see ProDOS TechNote #26 Polite Use of Auxiliary Memory -; and ProDOS 8 Technical Reference Manual 5.2.2.2 Disconnecting /RAM -; -; Public functions -; - DisconnectRAM32 -; -; does not reconnect /RAM on exit, which is rude -; -NODEV = $BF10 ; means 'no device connected' -RAM32 = $BF26 ; S3,D2 /RAM device -DEVCNT = $BF31 ; ProDOS device count -DEVLST = $BF32 ; ProDOS device list - -;------------------------------------------------------------------------------ -; DisconnectRAM32 -; disconnect ProDOS /RAM disk in S3,D2 -; (does not affect other RAM disks like RAMWorks or RAMFactor) -; -; in: ProDOS in memory -; out: C clear if /RAM was found and disconnected -; C set if /RAM was not found or could not be disconnected -; all other registers and flags clobbered -;------------------------------------------------------------------------------ -!zone { -DisconnectRAM32 - lda RAM32 ; search for /RAM and disconnect if found - cmp NODEV - bne + - lda RAM32+1 - cmp NODEV+1 - beq .noRAMdisk -+ ldy DEVCNT -- lda DEVLST, y - and #$F3 - cmp #$B3 - beq .foundRAMdisk - dey - bpl - - bmi .noRAMdisk -.foundRAMdisk - lda DEVLST, y - sta saveRAMDiskUnit ; save RAM disk unit number -- lda DEVLST+1, y ; move other devices up in list - sta DEVLST, y - beq + ; device list is zero-terminated - iny - bne - ; always branches -+ - lda RAM32 - sta saveRAMDiskDriver ; save RAM disk device address - lda RAM32+1 - sta saveRAMDiskDriver+1 - lda NODEV ; tell ProDOS there's no RAM disk anymore - sta RAM32 - lda NODEV+1 - sta RAM32+1 - dec DEVCNT ; reduce ProDOS device count - clc - rts -.noRAMdisk - sec - rts -saveRAMDiskUnit - !byte 0 -saveRAMDiskDriver - !word 0 -}