2013-12-27 13:57:56 +00:00
|
|
|
; text file parsing routines
|
2013-12-13 21:24:03 +00:00
|
|
|
; first call parser_init
|
|
|
|
; then call parser_skip_next
|
|
|
|
|
|
|
|
.export parser_init
|
|
|
|
.export parser_skip_next
|
|
|
|
|
2014-07-07 18:56:21 +00:00
|
|
|
.include "zeropage.inc"
|
2013-12-13 21:24:03 +00:00
|
|
|
.include "../inc/common.i"
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2014-07-07 18:56:21 +00:00
|
|
|
target_string = ptr1
|
|
|
|
search_string = ptr2
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
.bss
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
temp_ptr: .res 2
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2014-04-27 16:59:58 +00:00
|
|
|
.data
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
get_next_byte:
|
|
|
|
current_string_ptr=get_next_byte+1
|
|
|
|
lda $ffff
|
|
|
|
inc current_string_ptr
|
|
|
|
bne :+
|
|
|
|
inc current_string_ptr+1
|
2013-12-27 13:57:56 +00:00
|
|
|
: pha
|
2014-04-13 16:36:04 +00:00
|
|
|
pla ; reload A so flags are set correctly
|
2013-12-13 21:24:03 +00:00
|
|
|
rts
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
.code
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; set up a string for parsing
|
|
|
|
; inputs: AX = pointer to (null terminated) string to be parsed
|
|
|
|
; outputs: none
|
2013-12-13 21:24:03 +00:00
|
|
|
parser_init:
|
|
|
|
stax current_string_ptr
|
|
|
|
clc
|
|
|
|
rts
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; advance pointer along till just past the next occurance of specified string
|
|
|
|
; inputs: AX= pointer to (null terminated) string to search for
|
|
|
|
; outputs: sec if search string not found
|
|
|
|
; if clc, AX = pointer to first byte after string specified
|
2013-12-13 21:24:03 +00:00
|
|
|
; if sec (i.e. no match found), pointer stays in same place
|
|
|
|
parser_skip_next:
|
2013-12-27 13:57:56 +00:00
|
|
|
stax search_string
|
|
|
|
ldax current_string_ptr
|
2013-12-13 21:24:03 +00:00
|
|
|
stax temp_ptr
|
|
|
|
@check_string:
|
|
|
|
ldy #0
|
2013-12-27 13:57:56 +00:00
|
|
|
ldax current_string_ptr
|
2013-12-13 21:24:03 +00:00
|
|
|
stax target_string
|
|
|
|
@check_next_char:
|
|
|
|
lda (search_string),y
|
2013-12-27 13:57:56 +00:00
|
|
|
beq @matched
|
2013-12-13 21:24:03 +00:00
|
|
|
cmp (target_string),y
|
|
|
|
bne @not_matched
|
|
|
|
iny
|
|
|
|
bne @check_next_char
|
|
|
|
@matched:
|
2013-12-27 13:57:56 +00:00
|
|
|
; now skip 'y' bytes
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
@skip_byte:
|
|
|
|
jsr get_next_byte
|
2013-12-27 13:57:56 +00:00
|
|
|
dey
|
|
|
|
bne @skip_byte
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
ldax current_string_ptr
|
|
|
|
clc
|
|
|
|
rts
|
|
|
|
@not_matched:
|
|
|
|
jsr get_next_byte
|
|
|
|
bne @check_string
|
2013-12-27 13:57:56 +00:00
|
|
|
ldax temp_ptr
|
2013-12-13 21:24:03 +00:00
|
|
|
stax current_string_ptr
|
|
|
|
sec
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; -- LICENSE FOR parser.s --
|
2013-12-13 21:24:03 +00:00
|
|
|
; The contents of this file are subject to the Mozilla Public License
|
|
|
|
; Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
; compliance with the License. You may obtain a copy of the License at
|
|
|
|
; http://www.mozilla.org/MPL/
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; Software distributed under the License is distributed on an "AS IS"
|
|
|
|
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
; License for the specific language governing rights and limitations
|
|
|
|
; under the License.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Original Code is ip65.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Initial Developer of the Original Code is Jonno Downes,
|
|
|
|
; jonno@jamtronix.com.
|
|
|
|
; Portions created by the Initial Developer are Copyright (C) 2009
|
2013-12-27 13:57:56 +00:00
|
|
|
; Jonno Downes. All Rights Reserved.
|
2013-12-13 21:24:03 +00:00
|
|
|
; -- LICENSE END --
|