GSCats/loader.s

208 lines
3.1 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
;
2017-10-02 00:36:09 +00:00
.include "equates.s"
.include "macros.s"
LOADBUFFER = $1000 ; Clear of this loader code
BUFFERSIZE = $8200 ; 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
main:
2017-10-02 00:36:09 +00:00
OP8 ; We launch in emulation. Stay there for now
; Open the main code file
jsr PRODOS
.byte $c8
.addr fileOpenCode
bne ioError
; Load the code into bank 0
jsr PRODOS
.byte $ca
2017-10-04 20:14:16 +00:00
.addr fileRead
2017-10-02 00:36:09 +00:00
bne ioError
; Close the file
jsr PRODOS
.byte $cc
2017-10-04 20:14:16 +00:00
.addr fileClose
2017-10-02 00:36:09 +00:00
NATIVE
2017-10-02 00:36:09 +00:00
; Copy code into bank 2
2017-10-04 20:14:16 +00:00
ldx fileReadLen
lda #2
2018-01-16 20:56:53 +00:00
ldy #0
2017-10-04 20:14:16 +00:00
jsr copyBytes
2017-10-04 20:14:16 +00:00
EMULATION
2018-01-16 20:56:53 +00:00
;;;;;;;;;;;;;;;;;;;;;
; Open the E1 code file
jsr PRODOS
.byte $c8
.addr fileOpenCodeE1
bne ioError
; Load the code into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
bne ioError
; Close the file
jsr PRODOS
.byte $cc
.addr fileClose
NATIVE
; Copy code into bank E1
ldx fileReadLen
lda #$E1
ldy #$800 ; Must match terrain_e1 .org
jsr copyBytes
EMULATION
;;;;;;;;;;;;;;;;;;;;;
2017-10-04 20:14:16 +00:00
; Open the sprite bank file
jsr PRODOS
.byte $c8
.addr fileOpenSprites
bne ioError
; Load the compiled sprites into bank 0
jsr PRODOS
.byte $ca
.addr fileRead
bne ioError
; Close the file
jsr PRODOS
.byte $cc
.addr fileClose
NATIVE
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
; 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
2017-10-02 00:36:09 +00:00
jml MAINENTRY
returnToProDOS:
SYNCDBR
EMULATION
rts
2017-10-02 00:36:09 +00:00
ioError:
brk
2017-10-04 20:14:16 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; copyBytes
; Copy data from read buffer in bank 0 to
; bottom of any other bank. Must be in native mode.
;
; 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
;
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
bpl copyBytesLoop
rts
copyBytesOdd:
dex
BITS8A
lda LOADBUFFER,x
copyBytesDest2:
sta $010000,x
BITS16
bra copyBytesEven
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
2018-01-16 20:56:53 +00:00
fileOpenCodeE1:
.byte 3
.addr codePathE1
.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
2017-10-02 00:36:09 +00:00
codePath:
pstring "/GSAPP/CODEBANK"
2018-01-16 20:56:53 +00:00
codePathE1:
pstring "/GSAPP/CODEBANKE1"
2017-10-04 20:14:16 +00:00
spritePath:
pstring "/GSAPP/SPRITEBANK00"