4cade/src/4cade.init.a

488 lines
12 KiB
Plaintext
Raw Normal View History

2018-12-29 18:38:18 +00:00
;license:MIT
2020-03-17 01:58:05 +00:00
;(c) 2018-2020 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
2018-12-29 18:38:18 +00:00
;
2019-06-27 14:55:07 +00:00
+READ_ROM_NO_WRITE
sta PRIMARYCHARSET
sta CLR80VID
sta STOREOFF
sta READMAINMEM
sta WRITEMAINMEM
jsr ROM_TEXT
jsr ROM_HOME
jsr ROM_NORMAL
2019-11-27 23:24:59 +00:00
jsr ROM_IN0
jsr ROM_PR0
2021-05-13 04:18:47 +00:00
; print text title in same place as graphical title will appear
ldy #9
- lda TOTAL-1,y
ora #$80
sta $04B7-1,y
dey
bne -
ldy #11
- lda REPLAY-1,y
ora #$80
sta $0536-1,y
dey
bne -
; proboothd duplicates the above code and jumps here,
; so if you make any changes before this comment, you
; MUST adjust the final JMP in src/proboothd/proboothd.a
2019-09-29 15:08:57 +00:00
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
+
lda #0
sta zpMachineStatus
2019-11-21 04:05:35 +00:00
sta SETC3ROM
jsr HasVidHDCard ; check for VidHD card (allows super hi-res artwork even on non-IIgs machines)
sta CLRC3ROM
ror zpMachineStatus
2019-09-23 03:31:41 +00:00
lda ROM_MACHINEID
cmp #$06
2019-11-21 04:05:35 +00:00
bne @NotGS
sec
jsr $FE1F ; check for IIgs (allows super hi-res artwork)
2019-11-21 04:05:35 +00:00
bcs @NotGS
2020-03-05 17:45:35 +00:00
sec
2020-03-05 17:38:53 +00:00
+HIDE_NEXT_BYTE
@NotGS clc
ror zpMachineStatus
jsr Has128K ; check for 128K (allows DHGR slideshows and 128K games)
ror zpMachineStatus
2019-01-13 23:55:40 +00:00
jsr HasJoystick ; check for joystick (absence is OK but we filter out some games that require a joystick)
2020-03-05 17:38:53 +00:00
ror zpMachineStatus
; now bit 4 = 1 if VidHD
; bit 5 = 1 if IIgs
2019-01-13 23:55:40 +00:00
; bit 6 = 1 if 128K
; bit 7 = 1 if joystick
2020-03-05 17:38:53 +00:00
; and all other bits are 0 (we'll set bit 3 after copying it to LC RAM)
2020-03-13 14:46:22 +00:00
; accommodate uppercase-only machines (64K ][+ is supported)
lda ROM_MACHINEID
2020-08-05 23:01:22 +00:00
cmp #$A0
beq + ; Spectrum ED
cmp #$06
beq +
lda #$DF
+HIDE_NEXT_2_BYTES
+ lda #$FF
sta zpCharMask
2020-03-05 17:38:53 +00:00
; increase text window width so we can print to the edge of the screen without scrolling
inc $21
; print version or build number in lower right corner
ldx #30
ldy #23
jsr SetCursorPosition
+LDADDR LoadingVersion
jsr LoadingPrint
2019-10-14 01:38:54 +00:00
!ifndef RELEASE {
2020-03-05 17:38:53 +00:00
lda LoadingBuild
ldx LoadingBuild+1
2019-10-14 01:38:54 +00:00
ldy #0
jsr PrintAsDecimal
}
2020-03-05 17:38:53 +00:00
; set up text window so it only covers lower left corner
lda #30
sta $21
lda #19
sta $22
; print machine configuration in lower left corner
ldx #0
ldy #23
jsr SetCursorPosition
; if zpMachineStatus AND IS_IIGS then print 'IIgs'
; else if zpMachineStatus AND HAS_128K then print '128K'
; else print '64K'
lda zpMachineStatus
and #IS_IIGS
beq +
+LDADDR LoadingIIgs
bne @printMem
+ lda zpMachineStatus
and #HAS_128K
beq +
+LDADDR Loading128K
bne @printMem
+
2020-03-05 17:38:53 +00:00
+LDADDR Loading64K
@printMem
jsr LoadingPrint
; if zpMachineStatus AND HAS_JOYSTICK then CR & print 'joystick'
lda zpMachineStatus
and #HAS_JOYSTICK
beq +
jsr LoadingCR
+LDADDR LoadingJoystick
jsr LoadingPrint
+
; if zpMachineStatus AND HAS_VIDHD then CR & print 'VidHD'
lda zpMachineStatus
and #HAS_VIDHD
beq +
jsr LoadingCR
+LDADDR LoadingVidHD
jsr LoadingPrint
+
@Relocate
2020-08-12 15:35:21 +00:00
; if zpMachineStatus AND IS_IIGS then check for CFFA
; before performing any further disk access
lda zpMachineStatus
and #IS_IIGS
beq +
jsr HackThaCFFA
+
2019-06-20 01:36:49 +00:00
+READ_ROM_WRITE_RAM2
jsr init ; initialize and relocate ProRWTS2 to $D400 in RAM bank 2
2019-06-21 16:43:43 +00:00
; ProRWTS2 disk-data live at $D000-D3FF
ldx #$00 ; relocate program code to top of language card
2019-06-21 16:43:43 +00:00
; 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 COPYSRC,x ; relocate pseudo-ProDOS to RAM bank 2
sta COPYDST,x
inx
bne @LM
inc @LM+2
inc @LM+5
dey
bne @LM
2019-09-30 18:18:57 +00:00
ldy #4
@ELM lda FONTSRC,x
; relocate font data to RAM bank 2
sta FONTDST,x
inx
bne @ELM
inc @ELM+2
inc @ELM+5
dey
bne @ELM
+READ_ROM_NO_WRITE
jsr BuildAcceleratorFunction
+READ_RAM2_WRITE_RAM2
2020-03-24 20:30:14 +00:00
+ST16 @accelSrc
dex
-
@accelSrc=*+1
lda $FDFD,x ; copy (de)acceleration functions to RAM bank 2
sta DisableAccelerator,x
dex
bpl -
+READ_ROM_WRITE_RAM2
jsr BuildVBLFunction
2020-07-27 03:35:42 +00:00
+DISABLE_ACCEL ; cycle counting in Mockingboard detection requires 1MHz
2020-03-05 17:38:53 +00:00
+LDADDR FoundMockingboardCallback
2020-02-28 23:33:10 +00:00
jsr GetMockingboardStuff
2020-08-09 05:41:07 +00:00
+READ_RAM2_WRITE_RAM2
2020-02-28 23:33:10 +00:00
stx MockingboardStuff ; save mockingboard slot and type in LC RAM
2020-08-09 05:41:07 +00:00
+READ_ROM_NO_WRITE
2020-03-05 17:38:53 +00:00
; if Mockingboard AND HAS_SPEECH then print CR & '...and it talks!'
txa
and #HAS_SPEECH
beq +
jsr LoadingCR
+LDADDR LoadingMockingboardSpeech
jsr LoadingPrint
+
+READ_RAM2_WRITE_RAM2
jsr EnableAccelerator
jmp OneTimeSetup
; ProRWTS2 has its own function to relocate itself
!source "src/prorwts2.a"
ProRWTSBuffer
2018-11-10 13:36:36 +00:00
; these routines will only be called once, from main memory, before relocating to language card
2019-01-13 23:55:40 +00:00
!source "src/hw.vidhd.a"
!source "src/hw.memcheck.a"
!source "src/hw.joystick.a"
!source "src/hw.mockingboard.a"
2020-03-05 17:38:53 +00:00
SetCursorPosition
stx HTAB
sty VTAB
jmp $FC22
LoadingPrint
2020-03-24 20:30:14 +00:00
+ST16 PTR
2020-03-05 17:38:53 +00:00
ldy #0
lda (PTR),y
sta @max
sty i
- inc i
ldy i
lda (PTR),y
ora #$80
+FORCE_UPPERCASE_IF_REQUIRED
jsr ROM_COUT
ldy i
@max=*+1
cpy #$FD ; SMC
bne -
rts
LoadingCR
lda #$8D
jmp ROM_COUT
FoundMockingboardCallback
; in: zp$81 contains slot number in form $Cx
jsr LoadingCR
+LDADDR LoadingMockingboard
jsr LoadingPrint
lda $81
and #$0F
ora #$B0
jmp ROM_COUT
TOTAL
2020-03-05 17:38:53 +00:00
!text "T O T A L"
REPLAY
2020-03-05 17:38:53 +00:00
!text "R E P L A Y"
2019-10-14 01:38:54 +00:00
!ifndef RELEASE {
2020-03-05 17:38:53 +00:00
LoadingVersion
!byte 6
!text "build "
LoadingBuild
!word BUILDNUMBER
2019-10-14 01:38:54 +00:00
} else {
2020-03-05 17:38:53 +00:00
LoadingVersion
2021-02-12 22:54:26 +00:00
!byte 10
!text " v4.0"
2019-10-14 01:38:54 +00:00
}
2020-03-05 17:38:53 +00:00
Loading64K
!byte 3
!text "64K"
Loading128K
!byte 4
!text "128K"
LoadingIIgs
!byte 4
!text "IIgs"
LoadingJoystick
!byte 8
!text "joystick"
LoadingVidHD
!byte 5
!text "VidHD"
LoadingMockingboard
!byte 21
!text "Mockingboard in slot "
LoadingMockingboardSpeech
!byte 16
!text "...and it talks!"
2019-10-14 02:29:25 +00:00
!ifndef RELEASE {
2019-10-14 01:38:54 +00:00
PrintAsDecimal
jsr $FF4A
2020-03-05 17:38:53 +00:00
lda $FDE2
cmp #$EA
2020-03-05 17:38:53 +00:00
bne +
dec @addr+1 ; fix for Laser
+
2019-10-14 01:38:54 +00:00
-- lda #$00
clv
ldx #$18
- cmp #$05
bcc +
sbc #$85
sec
+ rol $45
rol $46
rol $47
rol
dex
bne -
pha
lda #$FD
pha
@addr lda #$E1
2019-10-14 01:38:54 +00:00
pha
bvs --
rts
2019-10-14 02:29:25 +00:00
}
2019-10-14 01:38:54 +00:00
!source "src/hw.accel.a"
!source "src/hw.vbl.init.a"
!source "src/parse.common.a"
2019-09-19 03:49:24 +00:00
!source "src/parse.games.a"
OneTimeSetup
lda zpMachineStatus
sta MachineStatus ; save machine status in LC RAM
2020-07-30 04:37:32 +00:00
and #IS_IIGS
beq @NotGSOS
!cpu 65816
lda $E100BD ; Make sure GS/OS was the boot OS
!cpu 6502
beq @NotGSOS
2020-08-13 23:12:57 +00:00
jsr PrepareGSOS
2020-07-30 04:37:32 +00:00
@NotGSOS
2019-10-01 20:08:50 +00:00
ldy #$0b
CopyDevs
lda $BF13,y
sta promote + $13,y
dey
bpl CopyDevs
lda $BF30
2019-09-09 21:28:13 +00:00
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
2021-10-14 05:43:50 +00:00
sta gRootDirectory+1
sty gRootDirectory+3
2021-10-14 13:05:18 +00:00
jsr SwitchToBank1
2019-09-10 02:58:16 +00:00
jsr LoadFile ; load preferences file into $8000
2019-09-10 02:38:17 +00:00
!word kRootDirectory
!word kGlobalPrefsFilename
2019-09-10 02:58:16 +00:00
- !word $8000
2018-12-29 18:38:18 +00:00
jsr ParseKeyValueList ; parse contents into OKVS data structure into LC RAM bank
2018-11-10 15:08:14 +00:00
!word gGlobalPrefsStore
2019-09-10 02:58:16 +00:00
!word -
2018-11-10 15:08:14 +00:00
!byte 16
+LD16 SAVE
+ST16 PTR
jsr stepptr
+LD16 PTR ; (PTR) points to free space after the OKVS data structure we just created
2020-03-24 20:30:14 +00:00
+ST16 gGamesListStore ; save pointer to free space for next store
2018-11-10 15:08:14 +00:00
jsr LoadFile ; load games list file into $8200
2019-09-10 02:38:17 +00:00
!word kRootDirectory
!word @kGameListConfFile
- !word $8200
2018-12-29 18:38:18 +00:00
jsr ParseGamesList ; parse games list into OKVS data structure in LC RAM bank
!word gGamesListStore
2019-09-10 02:58:16 +00:00
!word -
2018-12-29 18:38:18 +00:00
2020-03-13 00:21:35 +00:00
!ifndef RELEASE {
+LD16 SAVE
+ST16 PTR
jsr stepptr
2020-03-13 00:21:35 +00:00
+READ_ROM_NO_WRITE
lda #40
sta $21
lda #36
sta $24
dec $25
jsr $FC22
lda PTR+1
2020-03-13 00:21:35 +00:00
jsr $FDDA
lda PTR
2020-03-13 00:21:35 +00:00
jsr $FDDA
2020-03-13 01:05:43 +00:00
+READ_RAM1_WRITE_RAM1
2020-03-13 00:21:35 +00:00
}
2021-10-23 04:53:23 +00:00
ldx #$30
lda MachineStatus
and #HAS_JOYSTICK
beq +
inx
+ stx gSearchHasJoystick
ldx #$30
lda MachineStatus
and #HAS_128K
beq +
inx
+ stx gSearchHas128K
2019-09-20 23:42:26 +00:00
+LDADDR gGamesListStore
jsr okvs_len
2020-03-24 20:30:14 +00:00
+LD16 WCOUNT
+ST16 GameCount
+ST16 SAVE
jsr pref_get ; see if cheats are enabled by default
2021-10-12 23:37:45 +00:00
; sets PTR -> cheat pref value as length-prefixed string '1' or '0'
!word kCheat
!word 0
ldy #1
lda (PTR),y ; A = #$B1 or #$B0
and #1 ; A = #$01 or #$00
asl
asl
2020-03-05 17:38:53 +00:00
asl ; A = #$08 or #$00
ora MachineStatus
2020-03-05 17:38:53 +00:00
sta MachineStatus ; set bit 3 of MachineStatus
; calculate and update visible game count (3-digit decimal number as ASCII string)
dey ; Y = 0
@outer
lda #0
pha
@inner
lda SAVE
2020-03-24 20:30:14 +00:00
sec
2019-06-30 19:10:09 +00:00
sbc @kPowersOfTen,y
sta SAVE
lda SAVE+1
sbc #0
2020-03-24 20:30:14 +00:00
bcc @digitDone
sta SAVE+1
pla
adc #0
pha
jmp @inner
@digitDone
2020-03-24 20:30:14 +00:00
lda SAVE
adc @kPowersOfTen,y
sta SAVE
pla
ora #$30
2019-06-27 15:37:23 +00:00
sta VisibleGameCount,y
iny
cpy #$03
bcc @outer
2019-06-27 14:55:07 +00:00
bit CLEARKBD
2019-09-15 02:57:52 +00:00
jmp Reenter
2019-06-30 19:10:09 +00:00
@kGameListConfFile
2018-12-29 18:38:18 +00:00
!byte 10
!text "GAMES.CONF"
2019-06-30 19:10:09 +00:00
@kPowersOfTen
!byte 100
!byte 10
!byte 1