GSCats/loader.s

450 lines
6.6 KiB
ArmAsm
Raw Normal View History

;
; loader
; A very simplistic code loader designed to manage
; GS code under ProDOS 8 (if it's good enough for Will Harvey...)
;
; Created by Quinn Dunki on 7/29/17
;
.a16
.i16
2017-10-02 00:36:09 +00:00
.include "equates.s"
.include "macros.s"
2023-07-23 21:59:55 +00:00
LOADBUFFER = $1100 ; Clear of this loader code
BUFFERSIZE = $8000 ; About max size we can fit between buffer and this loader code
2017-10-04 20:14:16 +00:00
MAINENTRY = $020000
2017-10-02 00:36:09 +00:00
.org $800
2023-07-20 20:40:38 +00:00
LOADSTEP = 3
.macro addProgress amount
2023-07-25 03:29:11 +00:00
jsr nextVBL
2023-07-20 20:40:38 +00:00
lda #amount
jsr advanceLoadingBar
jsr renderLoadingBar
.endmacro
main:
BITS16
NATIVE
; Cache system colors
BITS8
lda BORDERCOLOR
sta BORDERCOLORCACHE
lda TEXTCOLOR
sta TEXTCOLORCACHE
BITS16
; Throw up a loading screen
2023-07-20 20:40:38 +00:00
jsr showLoadingScreen
EMULATION
2017-10-02 00:36:09 +00:00
; Open the main code file
jsr PRODOS
.byte $c8
.addr fileOpenCode
bne ioError
2023-07-20 20:40:38 +00:00
NATIVE
addProgress LOADSTEP
EMULATION
2023-06-19 01:14:41 +00:00
; Load first half of code into bank 0
2017-10-02 00:36:09 +00:00
jsr PRODOS
.byte $ca
2017-10-04 20:14:16 +00:00
.addr fileRead
2017-10-02 00:36:09 +00:00
bne ioError
2023-06-19 01:14:41 +00:00
NATIVE
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
2023-06-19 01:14:41 +00:00
; Copy code into bank 2
ldx fileReadLen
lda #2
ldy #0
jsr copyBytes
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
2023-06-19 01:14:41 +00:00
EMULATION
; Load rest of code into bank 0 (needed if code size exceeds BUFFERSIZE)
2023-06-22 03:07:30 +00:00
jsr PRODOS
.byte $ca
.addr fileRead
bne ioError
2017-10-02 00:36:09 +00:00
2023-07-20 20:40:38 +00:00
NATIVE
addProgress LOADSTEP
EMULATION
2017-10-02 00:36:09 +00:00
; Close the file
jsr PRODOS
.byte $cc
2017-10-04 20:14:16 +00:00
.addr fileClose
bra mainContinue
ioError:
brk
mainContinue:
2017-10-02 00:36:09 +00:00
NATIVE
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
2023-06-22 03:07:30 +00:00
; Copy rest of code into bank 2 (needed if code size exceeds BUFFERSIZE)
ldx fileReadLen
lda #2
ldy #BUFFERSIZE
jsr copyBytes
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
2017-10-04 20:14:16 +00:00
EMULATION
; Open the sprite bank file
jsr PRODOS
.byte $c8
.addr fileOpenSprites
bne ioError
2023-07-20 20:40:38 +00:00
NATIVE
addProgress LOADSTEP
EMULATION
2017-10-04 20:14:16 +00:00
; Load the compiled sprites into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
bne ioError
2023-07-20 20:40:38 +00:00
NATIVE
addProgress LOADSTEP
EMULATION
2017-10-04 20:14:16 +00:00
; Close the file
jsr PRODOS
.byte $cc
.addr fileClose
NATIVE
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
2017-10-04 20:14:16 +00:00
; Copy sprites into bank 3
ldx fileReadLen
lda #3
2018-01-16 20:56:53 +00:00
ldy #0
2017-10-04 20:14:16 +00:00
jsr copyBytes
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
EMULATION
; Open the sound file
jsr PRODOS
.byte $c8
.addr fileOpenSound
2023-07-20 20:40:38 +00:00
bne ioErrorJmp2
NATIVE
addProgress LOADSTEP
EMULATION
; Load the sound data into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
2023-07-20 20:40:38 +00:00
bne ioErrorJmp2
NATIVE
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
; Copy sound data into bank 4
ldx fileReadLen
txa
sta soundBankSize ; Note size of sound bank for later copying to Ensoniq RAM
lda #4
ldy #0
jsr copyBytes
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
EMULATION
; Load rest of sound data into bank 4 (needed if sound size exceeds BUFFERSIZE)
jsr PRODOS
.byte $ca
.addr fileRead
2023-07-20 20:40:38 +00:00
bne ioErrorJmp2
NATIVE
addProgress LOADSTEP
EMULATION
; Close the file
jsr PRODOS
.byte $cc
.addr fileClose
NATIVE
2023-07-20 20:40:38 +00:00
bra mainContinue2
ioErrorJmp2:
jmp ioError
mainContinue2:
addProgress LOADSTEP
; Copy rest of sound data into bank 4 (needed if sound size exceeds BUFFERSIZE)
ldx fileReadLen
txa
clc
adc soundBankSize ; Accumulate size of sound bank for later copying to Ensoniq RAM
sta soundBankSize
lda #4
ldy #BUFFERSIZE
jsr copyBytes
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
EMULATION
; Open the font file
jsr PRODOS
.byte $c8
.addr fileOpenFonts
bne ioErrorJmp
2023-07-20 20:40:38 +00:00
NATIVE
addProgress LOADSTEP
EMULATION
; Load the font data into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
bne ioErrorJmp
NATIVE
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
; Copy font data into bank 5
ldx fileReadLen
lda #5
ldy #0
jsr copyBytes
2023-07-20 20:40:38 +00:00
addProgress LOADSTEP
2023-07-23 21:59:55 +00:00
EMULATION
2023-07-13 19:08:21 +00:00
; Load rest of font data into bank 0 (needed if font size exceeds BUFFERSIZE)
2023-08-06 22:55:42 +00:00
jsr PRODOS
.byte $ca
.addr fileRead
bne ioErrorJmp
2023-07-13 19:08:21 +00:00
; Close the file
2023-07-23 21:59:55 +00:00
jsr PRODOS
.byte $cc
.addr fileClose
2023-07-13 19:08:21 +00:00
2023-08-06 22:55:42 +00:00
NATIVE
2023-07-13 19:08:21 +00:00
; Copy rest of font data into bank 5 (needed if font size exceeds BUFFERSIZE)
2023-08-06 22:55:42 +00:00
ldx fileReadLen
lda #5
ldy #BUFFERSIZE
jsr copyBytes
2023-07-13 19:08:21 +00:00
2023-07-23 21:59:55 +00:00
bra mainContinue3
ioErrorJmp:
jmp ioError
mainContinue3:
2023-08-06 22:55:42 +00:00
EMULATION
2023-07-23 21:59:55 +00:00
; Open the title screen file
jsr PRODOS
.byte $c8
.addr fileOpenTitle
bne ioErrorJmp
NATIVE
addProgress LOADSTEP
EMULATION
; Load the title screen data into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
bne ioErrorJmp
NATIVE
addProgress LOADSTEP
; Copy title screen data into bank 6
ldx fileReadLen
lda #6
ldy #0
jsr copyBytes
EMULATION
; Close the file
jsr PRODOS
.byte $cc
.addr fileClose
NATIVE
addProgress LOADSTEP
; Set up a long jump into bank 2, and
; a way for game code to get back here to exit
; properly to ProDOS 8
lda #returnToProDOS
2017-10-02 00:36:09 +00:00
sta PRODOSRETURN
2018-01-16 20:56:53 +00:00
2023-07-21 02:41:06 +00:00
lda #skyPalette
sta PARAML2
2023-07-20 21:42:22 +00:00
jsr paletteFade
2017-10-02 00:36:09 +00:00
jml MAINENTRY
returnToProDOS:
SYNCDBR
EMULATION
; Restore system colors
lda BORDERCOLOR
and #$f0
ora BORDERCOLORCACHE
2023-07-20 20:40:38 +00:00
sta BORDERCOLOR
lda TEXTCOLORCACHE
sta TEXTCOLOR
rts
2017-10-04 20:14:16 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; copyBytes
; Copy data from read buffer in bank 0 to
2023-06-19 01:14:41 +00:00
; offset any other bank. Must be in native mode.
2017-10-04 20:14:16 +00:00
;
; X = Length of data in bytes
2018-01-16 20:56:53 +00:00
; Y = Origin within bank
2017-10-04 20:14:16 +00:00
; A = Bank number of destination
2023-06-19 01:14:41 +00:00
; loadOffet : offset to start of copy destination
2017-10-04 20:14:16 +00:00
;
copyBytes:
2018-01-16 20:56:53 +00:00
sty copyBytesDest+1
sty copyBytesDest2+1
2017-10-04 20:14:16 +00:00
phx
BITS8
sta copyBytesDest+3
sta copyBytesDest2+3
2017-10-04 20:14:16 +00:00
BITS16
plx
txa
and #1
bne copyBytesOdd
copyBytesEven:
2017-10-04 20:14:16 +00:00
dex
dex
copyBytesLoop:
lda LOADBUFFER,x
copyBytesDest:
sta $010000,x
dex
dex
2023-06-19 01:14:41 +00:00
cpx #$fffe ; X will wrap when we're done
bne copyBytesLoop
2017-10-04 20:14:16 +00:00
rts
copyBytesOdd:
dex
BITS8A
lda LOADBUFFER,x
copyBytesDest2:
sta $010000,x
BITS16
bra copyBytesEven
2017-10-04 20:14:16 +00:00
2023-06-19 01:14:41 +00:00
loadOffet:
.word 0
2017-10-04 20:14:16 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2017-10-02 00:36:09 +00:00
fileOpenCode:
.byte 3
.addr codePath
.addr $9200 ; 1k below BASIC.SYSTEM
.byte 0 ; Result (file handle)
.byte 0 ; Padding
2017-10-04 20:14:16 +00:00
fileRead:
2017-10-02 00:36:09 +00:00
.byte 4
.byte 1 ; File handle (we know it's gonna be 1)
.addr LOADBUFFER
.word BUFFERSIZE
2017-10-04 20:14:16 +00:00
fileReadLen:
2017-10-02 00:36:09 +00:00
.word 0 ; Result (bytes read)
2017-10-04 20:14:16 +00:00
fileClose:
2017-10-02 00:36:09 +00:00
.byte 1
.byte 1 ; File handle (we know it's gonna be 1)
2017-10-04 20:14:16 +00:00
fileOpenSprites:
.byte 3
.addr spritePath
.addr $9200 ; 1k below BASIC.SYSTEM
.byte 0 ; Result (file handle)
.byte 0 ; Padding
fileOpenSound:
.byte 3
.addr soundPath
.addr $9200 ; 1k below BASIC.SYSTEM
.byte 0 ; Result (file handle)
.byte 0 ; Padding
fileOpenFonts:
.byte 3
.addr fontPath
.addr $9200 ; 1k below BASIC.SYSTEM
.byte 0 ; Result (file handle)
.byte 0 ; Padding
2023-07-23 21:59:55 +00:00
fileOpenTitle:
.byte 3
.addr titlePath
.addr $9200 ; 1k below BASIC.SYSTEM
.byte 0 ; Result (file handle)
.byte 0 ; Padding
2017-10-02 00:36:09 +00:00
codePath:
2024-02-01 17:17:14 +00:00
pstring "/CATFIGHT/CODEBANK"
2017-10-04 20:14:16 +00:00
spritePath:
2024-02-01 17:17:14 +00:00
pstring "/CATFIGHT/SPRITEBANK"
soundPath:
2024-02-01 17:17:14 +00:00
pstring "/CATFIGHT/SOUNDBANK"
fontPath:
2024-02-01 17:17:14 +00:00
pstring "/CATFIGHT/FONTBANK"
2023-07-23 21:59:55 +00:00
titlePath:
2024-02-01 17:17:14 +00:00
pstring "/CATFIGHT/TITLE"
2023-07-21 02:41:06 +00:00
.include "sharedGraphics.s"
.include "loaderGraphics.s"
2023-07-20 20:40:38 +00:00
.include "loadingBar.s"