emailler/ip65/string_utils.s

112 lines
2.1 KiB
ArmAsm
Raw Normal View History

; text file parsing routines
2013-12-13 21:24:03 +00:00
.export parse_integer
.export parse_hex_digits
.import mul_8_16
.importzp acc16
.include "zeropage.inc"
2013-12-13 21:24:03 +00:00
.include "../inc/common.i"
target_string = ptr2
2013-12-13 21:24:03 +00:00
.bss
2013-12-13 21:24:03 +00:00
temp_value: .res 2
.code
; parses a string, returns integer (up to 16 bits)
; inputs: AX points to a string containing an integer
; outputs: AX contains integer
2013-12-13 21:24:03 +00:00
parse_integer:
stax target_string
2013-12-13 21:24:03 +00:00
lda #0
sta temp_value
sta temp_value+1
tay
@parse_int:
lda (target_string),y
cmp #$30
bcc @end_of_int ; any non-decimal char should be treated as end of integer
2013-12-13 21:24:03 +00:00
cmp #$3A
bcs @end_of_int ; any non-decimal char should be treated as end of integer
ldax temp_value
stax acc16
2013-12-13 21:24:03 +00:00
lda #10
jsr mul_8_16
ldax acc16
stax temp_value
2013-12-13 21:24:03 +00:00
lda (target_string),y
sec
sbc #'0'
clc
adc temp_value
sta temp_value
bcc @no_rollover
2013-12-13 21:24:03 +00:00
inc temp_value+1
@no_rollover:
iny
bne @parse_int
@end_of_int:
ldax temp_value
clc
rts
; parses 2 hex digits, returns a byte
; inputs: X contains high nibble char, A contains low nibble char
; outputs: A contains byte
2013-12-13 21:24:03 +00:00
parse_hex_digits:
pha
txa
jsr parse_1_digit
asl
asl
asl
asl
sta temp_value
2013-12-13 21:24:03 +00:00
pla
jsr parse_1_digit
clc
adc temp_value
rts
2013-12-13 21:24:03 +00:00
parse_1_digit:
cmp #$3A
2013-12-13 21:24:03 +00:00
bcs @not_digit
sec
sbc #$30
rts
@not_digit:
ora #$20 ; make lower case
2013-12-13 21:24:03 +00:00
sec
sbc #'a'-10
rts
; -- LICENSE FOR string_utils.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-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-13 21:24:03 +00:00
; The Original Code is ip65.
;
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
; Jonno Downes. All Rights Reserved.
2013-12-13 21:24:03 +00:00
; -- LICENSE END --