2018-02-23 15:36:05 +00:00
|
|
|
.include "../inc/common.inc"
|
2017-11-05 13:28:49 +00:00
|
|
|
|
|
|
|
.export _dotted_quad
|
|
|
|
.export _parse_dotted_quad
|
|
|
|
|
|
|
|
.import parse_dotted_quad
|
|
|
|
.import dotted_quad_value
|
|
|
|
|
|
|
|
.importzp sreg, tmp1, tmp2, tmp3
|
|
|
|
|
|
|
|
|
|
|
|
.bss
|
|
|
|
|
|
|
|
dotted_quad: .res 4*4 ; "xxx.xxx.xxx.xxx\0"
|
|
|
|
|
2018-07-20 11:59:06 +00:00
|
|
|
|
2017-11-05 13:28:49 +00:00
|
|
|
.code
|
|
|
|
|
|
|
|
_dotted_quad:
|
|
|
|
stax dotted_quad_value
|
|
|
|
ldax sreg
|
|
|
|
stax dotted_quad_value+2
|
|
|
|
|
|
|
|
ldx #$00
|
|
|
|
ldy #$00
|
|
|
|
: jsr convert_byte
|
|
|
|
inx
|
|
|
|
cpx #4
|
|
|
|
bcc :-
|
|
|
|
|
|
|
|
dey
|
|
|
|
lda #$00
|
|
|
|
sta dotted_quad,y ; replace last dot with '\0'
|
|
|
|
ldax #dotted_quad
|
|
|
|
rts
|
|
|
|
|
|
|
|
convert_byte:
|
2019-05-10 09:55:32 +00:00
|
|
|
; hex to bcd routine taken from Andrew Jacob's code at
|
|
|
|
; http://www.6502.org/source/integers/hex2dec-more.htm
|
2017-11-05 13:28:49 +00:00
|
|
|
sed ; switch to decimal mode
|
|
|
|
lda #$00 ; ensure the result is clear
|
|
|
|
sta tmp1 ; BCD low
|
|
|
|
sta tmp2 ; BCD high
|
|
|
|
lda #8 ; the number of source bits
|
|
|
|
sta tmp3
|
|
|
|
: asl dotted_quad_value,x ; shift out one bit
|
|
|
|
lda tmp1 ; and add into result
|
|
|
|
adc tmp1
|
|
|
|
sta tmp1
|
|
|
|
lda tmp2 ; propagating any carry
|
|
|
|
adc tmp2
|
|
|
|
sta tmp2
|
|
|
|
dec tmp3 ; and repeat for next bit
|
|
|
|
bne :-
|
|
|
|
cld ; back to binary
|
|
|
|
|
2019-05-10 09:55:32 +00:00
|
|
|
lda tmp1
|
2017-11-05 13:28:49 +00:00
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
2019-05-10 09:55:32 +00:00
|
|
|
pha
|
|
|
|
lda tmp2
|
2017-11-05 13:28:49 +00:00
|
|
|
beq :+
|
|
|
|
ora #'0'
|
2019-05-10 09:55:32 +00:00
|
|
|
sta dotted_quad,y ; write x00
|
|
|
|
pla
|
|
|
|
iny
|
|
|
|
bne :++ ; always
|
|
|
|
: pla
|
|
|
|
beq :++
|
|
|
|
: ora #'0'
|
|
|
|
sta dotted_quad,y ; write 0x0
|
2017-11-05 13:28:49 +00:00
|
|
|
iny
|
|
|
|
: lda tmp1
|
|
|
|
and #$0F
|
|
|
|
ora #'0'
|
|
|
|
sta dotted_quad,y ; write 00x
|
|
|
|
iny
|
|
|
|
|
|
|
|
lda #'.'
|
|
|
|
sta dotted_quad,y ; write dot
|
|
|
|
iny
|
|
|
|
rts
|
|
|
|
|
|
|
|
_parse_dotted_quad:
|
|
|
|
jsr parse_dotted_quad
|
|
|
|
bcs error
|
|
|
|
ldax dotted_quad_value+2
|
|
|
|
stax sreg
|
|
|
|
ldax dotted_quad_value
|
|
|
|
rts
|
|
|
|
|
|
|
|
error:
|
|
|
|
ldx #$00
|
|
|
|
txa
|
|
|
|
stax sreg
|
|
|
|
rts
|