2018-08-31 04:31:54 +00:00
|
|
|
;license:MIT
|
2020-03-14 00:11:59 +00:00
|
|
|
;(c) 2018-2020 by 4am
|
2018-08-31 04:31:54 +00:00
|
|
|
;
|
|
|
|
; 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
|
2018-08-31 04:31:54 +00:00
|
|
|
; 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
|
2018-08-31 04:31:54 +00:00
|
|
|
|
|
|
|
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
|
2018-08-31 04:31:54 +00:00
|
|
|
@newkey ldx #$00 ; X = index into current key
|
2020-03-18 16:08:39 +00:00
|
|
|
stx gValLen ; initialize value length (in case this line has no value)
|
2019-09-24 00:01:42 +00:00
|
|
|
@emptyline
|
2018-08-31 04:31:54 +00:00
|
|
|
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
|
2018-08-31 04:31:54 +00:00
|
|
|
cmp #$5B ; '[' ends the parsing
|
2018-11-11 13:42:53 +00:00
|
|
|
beq @exit
|
2018-08-31 04:31:54 +00:00
|
|
|
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
|
2019-06-27 13:51:17 +00:00
|
|
|
bit zpMachineStatus
|
2018-08-31 04:31:54 +00:00
|
|
|
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
|
2020-03-08 20:12:36 +00:00
|
|
|
beq @parseDHGRTitle
|
2018-08-31 04:31:54 +00:00
|
|
|
cmp #$31 ; not '0' or '1' -> ignore entire line
|
|
|
|
bne @skipLine
|
2019-06-27 13:51:17 +00:00
|
|
|
bit zpMachineStatus
|
2018-08-31 04:31:54 +00:00
|
|
|
bvc @skipLine ; game requires 128K but we only have 64K, so ignore entire line
|
2020-03-08 20:12:36 +00:00
|
|
|
@parseDHGRTitle
|
|
|
|
jsr IncAndGetChar ; get third character ('1' if game has DHGR title)
|
|
|
|
and #$01
|
|
|
|
pha
|
2019-09-15 21:55:16 +00:00
|
|
|
@parseCheatsAvailable
|
2020-03-08 20:12:36 +00:00
|
|
|
jsr IncAndGetChar ; get fourth character (cheat category, int)
|
2020-03-09 21:24:30 +00:00
|
|
|
and #CHEAT_CATEGORY
|
2019-09-15 21:55:16 +00:00
|
|
|
pha
|
2018-08-31 04:31:54 +00:00
|
|
|
@swallowComma
|
|
|
|
jsr IncAndGetChar
|
|
|
|
@gatherKey
|
|
|
|
jsr IncAndGetChar
|
2020-03-23 01:58:26 +00:00
|
|
|
cmp #$0A ; CR -> finalize key, no value
|
2020-03-18 16:08:39 +00:00
|
|
|
beq @endKey
|
2018-08-31 04:31:54 +00:00
|
|
|
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
|
2020-03-18 16:08:39 +00:00
|
|
|
beq @endValue
|
2018-08-31 04:31:54 +00:00
|
|
|
@gatherValue
|
|
|
|
jsr IncAndGetChar
|
2020-03-23 01:58:26 +00:00
|
|
|
cmp #$0A ; CR ends the value
|
2018-08-31 04:31:54 +00:00
|
|
|
beq @endValue
|
|
|
|
sta gVal,x
|
|
|
|
inx
|
|
|
|
bpl @gatherValue
|
|
|
|
@endValue
|
2020-03-09 01:32:14 +00:00
|
|
|
pla ; pop cheat category
|
2020-03-18 16:08:39 +00:00
|
|
|
sta gVal,x ; store after game display name
|
|
|
|
pla ; pop has-DHGR-title flag
|
2020-03-14 00:11:59 +00:00
|
|
|
lsr
|
2020-03-09 01:32:14 +00:00
|
|
|
ror
|
|
|
|
ora gVal,x
|
|
|
|
sta gVal,x ; store in bit 7 of same byte as cheat category
|
|
|
|
inx
|
2018-08-31 04:31:54 +00:00
|
|
|
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
|
2019-09-15 21:55:16 +00:00
|
|
|
pla ; pop saved Y
|
2018-08-31 04:31:54 +00:00
|
|
|
tay
|
2020-03-18 16:08:39 +00:00
|
|
|
jmp @newkey
|
2018-08-31 04:31:54 +00:00
|
|
|
|
2018-11-11 13:42:53 +00:00
|
|
|
@exit rts
|