4cade/src/parse.games.a

114 lines
4.1 KiB
Plaintext
Raw Normal View History

;license:MIT
2020-03-14 00:11:59 +00:00
;(c) 2018-2020 by 4am
;
; GAMES.CONF parser
;
; Public functions:
; - ParseGamesList
;
;------------------------------------------------------------------------------
; ParseGamesList
2019-10-08 03:22:43 +00:00
; 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
2020-03-24 20:30:14 +00:00
+ST16 @store2
2019-09-24 00:01:42 +00:00
jsr SetKeyPtr
ldy #$00 ; index into ($FE) pointing to current character
2019-09-24 00:01:42 +00:00
beq @newkey ; always branches
@skipLine ; skip to CR
jsr IncAndGetChar
2020-03-23 01:58:26 +00:00
cmp #$0A ; CR
2019-09-24 00:01:42 +00:00
bne @skipLine
@newkey ldx #$00 ; X = index into current key
stx gValLen ; initialize value length (in case this line has no value)
2019-09-24 00:01:42 +00:00
@emptyline
jsr IncAndGetChar ; get first filter character ('1' if game requires joystick)
2020-03-23 01:58:26 +00:00
cmp #$0A ; ignore blank line
2019-09-24 00:01:42 +00:00
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)
2020-03-09 21:24:30 +00:00
and #CHEAT_CATEGORY
pha
@swallowComma
jsr IncAndGetChar
@gatherKey
jsr IncAndGetChar
2020-03-23 01:58:26 +00:00
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
2020-03-23 01:58:26 +00:00
cmp #$0A
beq @endValue
@gatherValue
jsr IncAndGetChar
2020-03-23 01:58:26 +00:00
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
2020-03-14 00:11:59 +00:00
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