mirror of
https://github.com/a2-4am/4cade.git
synced 2024-12-21 17:31:08 +00:00
114 lines
4.1 KiB
Plaintext
114 lines
4.1 KiB
Plaintext
;license:MIT
|
|
;(c) 2018-2020 by 4am
|
|
;
|
|
; GAMES.CONF parser
|
|
;
|
|
; Public functions:
|
|
; - ParseGamesList
|
|
;
|
|
|
|
;------------------------------------------------------------------------------
|
|
; ParseGamesList
|
|
; parse buffer with ABC,KEY=VALUE lines of text into an okvs
|
|
; keys and values limited to 127 characters, which should be enough for anyone
|
|
; '[' character at beginning of line ends the parsing
|
|
; (see games.conf file for more format information)
|
|
;
|
|
; in: stack contains 4 bytes of parameters:
|
|
; +1 [word] handle to storage space for okvs
|
|
; +3 [word] handle to buffer containing contents of GAMES.CONF
|
|
; out: all registers and flags clobbered
|
|
; $1F00..$1FFF clobbered
|
|
; $00/$01 clobbered
|
|
; $02/$03 clobbered
|
|
; $04/$05 has the address of the next available byte after the okvs
|
|
; $FE/$FF clobbered
|
|
;------------------------------------------------------------------------------
|
|
ParseGamesList
|
|
+PARAMS_ON_STACK 4
|
|
|
|
+LDPARAM 1
|
|
+ST16 @store2
|
|
jsr SetKeyPtr
|
|
|
|
ldy #$00 ; index into ($FE) pointing to current character
|
|
beq @newkey ; always branches
|
|
@skipLine ; skip to CR
|
|
jsr IncAndGetChar
|
|
cmp #$0A ; CR
|
|
bne @skipLine
|
|
@newkey ldx #$00 ; X = index into current key
|
|
stx gValLen ; initialize value length (in case this line has no value)
|
|
@emptyline
|
|
jsr IncAndGetChar ; get first filter character ('1' if game requires joystick)
|
|
cmp #$0A ; ignore blank line
|
|
beq @emptyline
|
|
cmp #$5B ; '[' ends the parsing
|
|
beq @exit
|
|
cmp #$30 ; '0' -> no filtering on joystick
|
|
beq @filterOnMemory
|
|
cmp #$31 ; not '0' or '1' or '[' or CR -> ignore entire line (e.g. comment)
|
|
bne @skipLine
|
|
bit zpMachineStatus
|
|
bpl @skipLine ; game requires joystick but we don't have one, so ignore entire line
|
|
@filterOnMemory
|
|
jsr IncAndGetChar ; get second filter character ('1' if game requires 128K)
|
|
cmp #$30 ; '0' -> no filtering on memory
|
|
beq @parseDHGRTitle
|
|
cmp #$31 ; not '0' or '1' -> ignore entire line
|
|
bne @skipLine
|
|
bit zpMachineStatus
|
|
bvc @skipLine ; game requires 128K but we only have 64K, so ignore entire line
|
|
@parseDHGRTitle
|
|
jsr IncAndGetChar ; get third character ('1' if game has DHGR title)
|
|
and #$01
|
|
pha
|
|
@parseCheatsAvailable
|
|
jsr IncAndGetChar ; get fourth character (cheat category, int)
|
|
and #CHEAT_CATEGORY
|
|
pha
|
|
@swallowComma
|
|
jsr IncAndGetChar
|
|
@gatherKey
|
|
jsr IncAndGetChar
|
|
cmp #$0A ; CR -> finalize key, no value
|
|
beq @endKey
|
|
cmp #$3D ; '=' ends the key
|
|
beq @endKey
|
|
sta gKey,x
|
|
inx
|
|
bpl @gatherKey
|
|
@endKey stx gKeyLen
|
|
ldx #$00 ; now X = index into the current value
|
|
cmp #$0A
|
|
beq @endValue
|
|
@gatherValue
|
|
jsr IncAndGetChar
|
|
cmp #$0A ; CR ends the value
|
|
beq @endValue
|
|
sta gVal,x
|
|
inx
|
|
bpl @gatherValue
|
|
@endValue
|
|
pla ; pop cheat category
|
|
sta gVal,x ; store after game display name
|
|
pla ; pop has-DHGR-title flag
|
|
lsr
|
|
ror
|
|
ora gVal,x
|
|
sta gVal,x ; store in bit 7 of same byte as cheat category
|
|
inx
|
|
stx gValLen
|
|
tya
|
|
pha ; okvs functions clobber everything but we need Y
|
|
jsr okvs_append
|
|
@store2 !word $FDFD ; SMC
|
|
!word gKeyLen
|
|
!word gValLen
|
|
!byte 0
|
|
pla ; pop saved Y
|
|
tay
|
|
jmp @newkey
|
|
|
|
@exit rts
|