simplify LoadGameInfo parser

This commit is contained in:
4am
2018-03-03 17:45:39 -05:00
parent c2a8f93111
commit 5361c5fe29

View File

@@ -157,35 +157,21 @@ GAMES ; length of this array must = kNumberOfGame
!byte 4 !byte 4
!raw "ZTUU" !raw "ZTUU"
.BEGIN_PARSER_DATA sectionPointers ; array of pointers to start of each section
bInSectionName addrVersions
!byte 0
bFoundCR
!byte 0
iSection
!byte 0
iSectionsFound
!byte 0
; array of pointers to start of each section (order must match code)
sectionPointers
addrInfo
!word 0 !word 0
addrDescription addrDescription
!word 0 !word 0
addrVersions addrInfo
!word 0 !word 0
.END_PARSER_DATA
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; LoadGameInfo ; LoadGameInfo
; load file with information about the current game ; load file with information about the current game
; ;
; in: gCurrentGame between 0 and (kNumberOfGames-1) ; in: gCurrentGame between 0 and (kNumberOfGames-1)
; out: if success, C clear and addrInfo, addrDescription, addrVersions ; out: addrInfo, addrDescription, addrVersions populated
; populated with pointers to parsed data ; all registers and flags clobbered
; if error, C set
; all other registers and flags clobbered
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
LoadGameInfo LoadGameInfo
jsr ResetPath jsr ResetPath
@@ -204,117 +190,61 @@ LoadGameInfo
!word $0800 !word $0800
!word $1400 !word $1400
!word kProDOSFileBuffer !word kProDOSFileBuffer
bcc .parseGameInfo
rts
.parseGameInfo
ldx #9 ; .END_PARSER_DATA-.BEGIN_PARSER_DATA-1
- stz .BEGIN_PARSER_DATA,x
dex
bpl -
stz $00
lda #$08
sta $01
lda mlilen
sta $02
lda mlilen+1
sta $03
ldy #$00
parseloop
lda ($00),y
cmp #$0A ; LF -> 0x00 (WeeGUI wants null-terminated strings)
bne .notCR
lda #$00
sta ($00),y
lda #$FF lda #$FF
sta bFoundCR sta $00
bra .next lda #$07
.notCR sta $01 ; ($00) points to start of data buffer
cmp #$5B ; '[' is section name start delimiter ldy #$00 ; index into ($00) pointing to current character
beq .startsectionname ldx #$04 ; index into sectionPointers array, stores pointer to start of each section
cmp #$5D ; ']' is section name end delimiter
beq .endsectionname .convertSectionLoop
bit bInSectionName jsr IncAndGetChar
bmi .parsesectionname .convertSectionNoInc
bvs .next cmp #$5B ; '['
tax beq .skipSectionName
beq .nostore cmp #$0A ; LF -> 0x00 (WeeGUI wants null-terminated strings)
beq .null
cmp #$5E ; '^' -> closed-apple mousetext cmp #$5E ; '^' -> closed-apple mousetext
bne + beq .ca
lda #$40 cmp #$26 ; '&' -> open-apple mousetext
bra .store beq .oa
+ cmp #$26 ; '&' -> open-apple mousetext
bne .highbit
lda #$41
bra .store
.highbit
ora #$80 ora #$80
.store !byte $2C
.null lda #$00
!byte $2C
.ca lda #$40
!byte $2C
.oa lda #$41
sta ($00),y sta ($00),y
.nostore bra .convertSectionLoop
bit bFoundCR
bpl .next ; We found the start of a new section, so skip to the first character on the next line
stz bFoundCR .skipSectionName
lda iSection jsr IncAndGetChar
beq .next cmp #$0A ; LF
; We found the start of the first line after the end of the section name. bne .skipSectionName
; Save this address in the sectionPointers array. jsr IncAndGetChar
asl
tax ; We are at the start of a section, so save this address in the sectionPointers array
pha
tya tya
clc clc
adc $00 adc $00
sta sectionPointers-2,x sta sectionPointers,x
lda $01 lda $01
bcc + bcc +
inc inc
+ sta sectionPointers-1,x + sta sectionPointers+1,x
stz iSection
bra .next
.startsectionname
lda #%11000000
sta bInSectionName
bra .next
.endsectionname
stz bInSectionName
bra .next
.parsesectionname
pha
lda #%01000000
sta bInSectionName
pla pla
cmp #$69 ; 'i'nfo dex
beq .info dex
cmp #$64 ; 'd'escription bpl .convertSectionNoInc
beq .description
cmp #$76 ; 'v'ersions IncAndGetChar
beq .versions iny
bne .next
.info
lda #1
!byte $2C ; hide next LDA
.description
lda #2
!byte $2C ; hide next LDA
.versions
lda #3
sta iSection
inc iSectionsFound
.next
inc $00
bne + bne +
inc $01 inc $01
+ dec $02 + lda ($00),y
bne +
dec $03
bmi .done
+ jmp parseloop
.done
lda iSectionsFound
cmp #$03
bne +
clc
rts
+ sec
rts rts
} }