4cade/src/glue.launch.lc2.a
2024-06-10 12:30:14 -04:00

69 lines
2.2 KiB
Plaintext

;license:MIT
;(c) 2018-2021 by 4am & qkumba
;
; Functions to launch games and self-running demos
;
; /!\ These live in LC RAM 2 and rely on the ProRWTS code which is also in LC RAM 2. /!\
; Code in LC RAM 1 (which is most program code) should call the functions in glue.launch
; which handle bank switching for you.
LaunchInternal
tsx ; back up stack pointer
stx STACKPTR + 1
inx
- pla
sta STACKBASE - $100 + gStackSize,x
; back up stack
inx
bne -
stx RestoreStackNextTime + 1
; tell |Reenter| to restore the stack and stack pointer
ldx #(PrelaunchInitInternal_e-PrelaunchInitInternal+1)
- lda PrelaunchInitInternal-1, x
sta PrelaunchInit-1, x
dex
bne -
;X=0
txa
ldy #$18
- sta $bf57,y
dey
bne -
ldx #RNDSEED-1 ; wipe lower part of zero page
txa
- sta $00,x
dex
bpl -
lda #$65 ; Initialize 'random' seed. These are
sta RNDSEED ; arbitrary values. Some games like Pooyan
lda #$02 ; require these to be non-zero. Ask me
sta RNDSEED+1 ; how long that one took to debug.
sta STOREOFF
sta READMAINMEM
sta WRITEMAINMEM
sta CLR80VID
sta PRIMARYCHARSET
bit CLEARKBD
jmp iPrelaunchInit
PrelaunchInitInternal
!pseudopc PrelaunchInit {
+READ_ROM_NO_WRITE
jsr ROM_IN0 ; Initialize machine like a cold boot.
jsr ROM_PR0 ; Many games assume a 'clean slate' and
jsr ROM_NORMAL ; rely on zero page values set by these
jsr ROM_TEXT ; ROM routines, e.g. Wavy Navy prints text
jsr ROM_HOME ; via $FDED and expects it to work.
AnimationPrelaunchInit
sei
jmp $106
!if * != $100 {
!serious "adjust PrelaunchInit to ",PrelaunchInit+$100-*
}
}
PrelaunchInitInternal_e