4cade/src/4cade.init.a

268 lines
7.9 KiB
Plaintext

;license:MIT
;(c) 2018-9 by 4am
;
; first-run initialization code
;
; This file is included directly and is run from $2000/main as soon as the
; .SYSTEM file is loaded
;
+READ_ROM_NO_WRITE
sta PRIMARYCHARSET
sta CLR80VID
sta STOREOFF
sta READMAINMEM
sta WRITEMAINMEM
jsr ROM_TEXT
jsr ROM_HOME
jsr IsLowPartition ; check if running from partition 1-4 (required)
bcc +
ldy #@noHighPartlen
- lda @s_noHighPart,y
sta $6B1,y
dey
bpl -
bmi @hang
@s_noHighPart !scrxor $80,"RUN FROM PARTITION 1-4"
@noHighPartlen=(*-@s_noHighPart)-1
+ jsr Has64K ; check for 64K (required)
bcc +
ldy #@no64Klen
- lda @s_no64K,y
sta $6B6,y
dey
bpl -
@hang bmi @hang
@s_no64K !scrxor $80,"REQUIRES 64K"
@no64Klen=(*-@s_no64K)-1
+ jsr DisableAccelerator ; set to 1 MHz (supports IIgs and many common accelerator cards)
jsr IsGS ; check for IIgs (allows super hi-res artwork)
php
bcc +
jsr ROM_TEXT2COPY ; set alternate display mode on IIgs (required for some games)
+ plp
ror zpMachineStatus
sta SETC3ROM
jsr HasVidHDCard ; check for VidHD card (allows super hi-res artwork even on non-IIgs machines)
ror zpMachineStatus
sta CLRC3ROM
jsr Has128K ; check for 128K (allows DHGR slideshows and 128K games)
ror zpMachineStatus
jsr HasJoystick ; check for joystick (absence is OK but we filter out some games that require a joystick)
ror zpMachineStatus ; now bit 4 = 1 if IIgs
; bit 5 = 1 if VidHD
; bit 6 = 1 if 128K
; bit 7 = 1 if joystick
lda ROM_MACHINEID
cmp #$06
beq +
lda #$DF
+HIDE_NEXT_2_BYTES
+ lda #$FF
sta zpCharMask
ldy #8
- lda TOTAL,y
ora #$80
sta $04B7,y
dey
bpl -
ldy #10
- lda REPLAY,y
ora #$80
sta $0536,y
dey
bpl -
ldy LoaderVersion
- lda LoaderVersion,y
ora #$80
+FORCE_UPPERCASE_IF_REQUIRED
sta $07CF,y
dey
bne -
bit zpMachineStatus
bvc ++
bpl +
+LDADDR Loader128KAndJoystick
bne @ShowLoadScreen
+
+LDADDR Loader128K
bne @ShowLoadScreen
++
bpl +
+LDADDR Loader64KAndJoystick
bne @ShowLoadScreen
+
+LDADDR Loader64K
@ShowLoadScreen
+STAY PTR
ldy #0
lda (PTR),y
tay
- lda (PTR),y
ora #$80
+FORCE_UPPERCASE_IF_REQUIRED
@load sta $07F7
dec @load+1
dey
bne -
@Relocate
+READ_ROM_WRITE_RAM2
jsr init ; initialize and relocate ProRWTS2 to $D400 in RAM bank 2
; ProRWTS2 disk-data live at $D000-D3FF
ldx #$00 ; relocate program code to top of language card
; since we end at $0000 now, adjust low offset to avoid destroying zpage
@FM lda FirstMover - (RELBASE & $FF),x
sta RELBASE & $FF00,x
inx
bne @FM
inc @FM+2
inc @FM+5
bne @FM
+ ldy #>(255 + EvenLasterMover - LastMover)
@LM lda LastMover,x ; relocate font data to $D600 in RAM bank 2
sta $D600,x ; and pseudo-ProDOS to $DA00 in RAM bank 2
inx
bne @LM
inc @LM+2
inc @LM+5
dey
bne @LM
jmp OneTimeSetup
; ProRWTS2 has its own function to relocate itself
!source "src/prorwts2.a"
ProRWTSBuffer
; these routines will only be called once, from main memory, before relocating to language card
!source "src/hw.diskcheck.a"
!source "src/hw.iigs.a"
!source "src/hw.vidhd.a"
!source "src/hw.memcheck.a"
!source "src/hw.joystick.a"
!source "src/hw.normfast.a"
TOTAL
!text "T O T A L"
REPLAY
!text "R E P L A Y"
LoaderVersion
!byte 10
!text "v3.0-alpha"
Loader64K
!byte 3
!text "64K"
Loader64KAndJoystick
!byte 14
!text "joystick + 64K"
Loader128K
!byte 4
!text "128K"
Loader128KAndJoystick
!byte 15
!text "joystick + 128K"
*=ProRWTSBuffer+512 ; ProRWTS needs a 512-byte buffer for its init function
; so we reuse as much of the 1-time code as possible
; and fill the rest with zeros
!source "src/parse.games.a" ; this needs to be outside the buffer because it's not used
; until after ProRWTS initialization
OneTimeSetup
lda zpMachineStatus
sta MachineStatus ; save machine status
jsr SaveOrRestoreScreenHoles ; save initial copy of screen hole content
lda #$91
sta holepatch ; enable restoring of copy from now on
lda $43
sta promote + ProDOS_unit - $bf00
; save unit in LC bank 2 while overriding !pseudopc
lda hddopendir+1 ; save current directory as 'root'
ldy hddopendir+3
+READ_RAM1_WRITE_RAM1
+STAY gRootDirectory
jsr LoadFile ; load preferences file into $8000
!word kRootDirectory
!word kGlobalPrefsFilename
- !word $8000
jsr ParseKeyValueList ; parse contents into OKVS data structure into LC RAM bank
!word gGlobalPrefsStore
!word -
!byte 16
+LDAY SRC ; (SRC) points to free space after the OKVS data structure we just created
+STAY gGamesListStore ; save pointer to free space for next store
jsr LoadFile ; load games list file into $8000
!word kRootDirectory
!word @kGameListConfFile
- !word $8000
jsr ParseGamesList ; parse games list into OKVS data structure in LC RAM bank
!word gGamesListStore
!word -
jsr okvs_len
!word gGamesListStore
sta GameCount
sta SAVE
jsr pref_get ; see if cheats are enabled by default
!word kCheat
!word 0
+STAY PTR ; (PTR) -> cheat pref value as length-prefixed string '1' or '0'
ldy #1
lda (PTR),y ; A = #$B1 or #$B0
and #1 ; A = #$01 or #$00
clc
ror
ror ; A = #$80 or #$00
sta gCheatsEnabled
; calculate and update visible game count (3-digit decimal number as ASCII string)
dey ; Y = 0
@outer
lda #0
pha
@inner
lda SAVE
cmp @kPowersOfTen,y
bcc @digitDone
sbc @kPowersOfTen,y
sta SAVE
lda SAVE+1
sbc #0
sta SAVE+1
pla
adc #0
pha
jmp @inner
@digitDone
pla
ora #$30
sta VisibleGameCount,y
iny
cpy #$03
bcc @outer
bit CLEARKBD
jmp Reenter
@kGameListConfFile
!byte 10
!text "GAMES.CONF"
@kPowersOfTen
!byte 100
!byte 10
!byte 1