git-svn-id: http://svn.code.sf.net/p/netboot65/code@38 93682198-c243-4bdb-bd91-e943c89aac3b

This commit is contained in:
jonnosan 2009-02-08 05:41:42 +00:00
parent b2f30a8807
commit ba0a71ae6c
5 changed files with 240 additions and 8 deletions

View File

@ -25,6 +25,7 @@ ETHOBJS= \
debug.o \
dhcp.o \
dns.o \
dottedquad.o \
tftp.o \
all: ip65.lib

View File

@ -24,6 +24,10 @@
.import cfg_dns
.import parse_dotted_quad
.import dotted_quad_value
.import ip65_process
.import udp_add_listener
@ -91,6 +95,7 @@ hostname_copied: .res 1
questions_in_response: .res 1
hostname_was_dotted_quad: .res 1
.code
@ -98,9 +103,27 @@ dns_set_hostname:
stax dns_hostname
;copy the hostname into a buffer suitable to copy directly into the qname field
;we need to split on dots
jsr parse_dotted_quad ; if we are passed an IP address instead of a hostname, don't bother looking it up in dns
bcs @wasnt_dotted_quad
;if the string was a dotted quad, then copy the parsed 4 bytes in to dns_ip
lda #1
sta hostname_was_dotted_quad
ldx #3 ; set destination address
: lda dotted_quad_value,x
sta dns_ip,x
dex
bpl :-
rts ;done!
@wasnt_dotted_quad:
ldy #0 ;input pointer
ldx #1 ;output pointer (start at 1, to skip first length offset, which will be filled in later)
sty hostname_was_dotted_quad
sty dns_current_label_length
sty dns_current_label_offset
sty hostname_copied
@ -156,6 +179,12 @@ dns_set_hostname:
rts
dns_resolve:
lda hostname_was_dotted_quad
beq @hostname_not_dotted_quad
clc
rts ;we already set dns_ip when copying the hostname
@hostname_not_dotted_quad:
ldax #dns_in
stax udp_callback
lda #53

84
client/ip65/dottedquad.s Normal file
View File

@ -0,0 +1,84 @@
;########################
; helper routine to convert a string representing a dotted quad (IP address, netmask) into 4 octets
; written by jonno@jamtronix.com 2009
;
;########################
; to use -
; ldax with ptr of dotted quad string
; then call parse_dotted_quad
; on exit: carry flag is set if there was an error. if carry flag is clear, then dotted_quad_value will be set
;########################
.include "../inc/common.i"
.import print_a
.export parse_dotted_quad
.export dotted_quad_value
.bss
dotted_quad_value: .res 4
dotted_quad_ptr: .res 4
.code
parse_dotted_quad:
stax dotted_quad_ptr+1
lda #$AD ; $AD='LDA immediate'
sta dotted_quad_ptr
lda #$60 ; $60='RTS
sta dotted_quad_ptr+3
ldx #0
txa
sta dotted_quad_value
@each_byte:
jsr get_next_byte
cmp #0
beq @done
and #$7F ;turn off bit 7
cmp #'.'
beq @got_dot
sec
sbc #'0'
bcc @error
cmp #10
bcs @error
clc
ldy #10
@mul_by_y:
adc dotted_quad_value,x
bcs @error
dey
bne @mul_by_y
sta dotted_quad_value,x
jmp @each_byte
@got_dot:
inx
lda #0
sta dotted_quad_value,x
jmp @each_byte
@done:
cpx #3
bne @error
clc
rts
@error:
sec
rts
get_next_byte:
jsr dotted_quad_ptr
inc dotted_quad_ptr+1
bne :+
inc dotted_quad_ptr+2
:
rts

View File

@ -20,25 +20,29 @@ INCFILES=\
%.o: %.s
$(AS) $(AFLAGS) $<
%.bin: %.o $(IP65LIB) $(APPLE2NETLIB) $(INCFILES) ../cfg/a2bin.cfg
$(LD) -m $*.map -C ../cfg/a2bin.cfg -o $*.bin $(AFLAGS) $< $(IP65LIB) $(APPLE2NETLIB)
%.prg: %.o $(IP65LIB) $(C64NETLIB) $(INCFILES) ../cfg/c64prg.cfg
$(LD) -m $*.map -C ../cfg/c64prg.cfg -o $*.prg $(AFLAGS) $< $(IP65LIB) $(C64NETLIB)
ip65test.dsk: testdns.bin
dsktool.rb --init dos33 ip65test.dsk -a testdns.bin -t B
%.bin: %.o $(IP65LIB) $(APPLE2NETLIB) $(INCFILES) ../cfg/a2bin.cfg
$(LD) -m $*.map -C ../cfg/a2bin.cfg -o $*.bin $(AFLAGS) $< $(IP65LIB) $(APPLE2NETLIB)
ip65test.d64: testdns.prg testdottedquad.prg
ip65test.dsk: testdns.bin testdottedquad.bin
ripxplore.rb --init AppleDos ip65test.dsk -a testdns.bin -t AppleBinary
ripxplore.rb ip65test.dsk -a testdns.bin -t AppleBinary
all: \
ip65test.dsk \
testdns.prg \
testdns.bin \
testdns.prg \
testdottedquad.bin \
testdottedquad.prg \
ip65test.d64 \
clean:
rm -f *.o
rm -f testdns.prg testdns.map testdns.bin
rm -f testdns.prg testdns.map testdns.bin testdottedquad.prg testdottedquad.bin
rm -f ip65test.dsk
distclean: clean

View File

@ -0,0 +1,114 @@
.include "../inc/common.i"
.include "../inc/commonprint.i"
.include "../inc/net.i"
.import exit_to_basic
.import parse_dotted_quad
.import dotted_quad_value
.import __CODE_LOAD__
.import __CODE_SIZE__
.import __RODATA_SIZE__
.import __DATA_SIZE__
.segment "STARTUP" ;this is what gets put at the start of the file on the C64
.word basicstub ; load address
basicstub:
.word @nextline
.word 2003
.byte $9e
.byte <(((init / 1000) .mod 10) + $30)
.byte <(((init / 100 ) .mod 10) + $30)
.byte <(((init / 10 ) .mod 10) + $30)
.byte <(((init ) .mod 10) + $30)
.byte 0
@nextline:
.word 0
.segment "EXEHDR" ;this is what gets put an the start of the file on the Apple 2
.addr __CODE_LOAD__-$11 ; Start address
.word __CODE_SIZE__+__RODATA_SIZE__+__DATA_SIZE__+4 ; Size
jmp init
.code
init:
jsr print_cr
ldax #dotted_quad_1
jsr test_dotted_quad_string
ldax #dotted_quad_2
jsr test_dotted_quad_string
ldax #dotted_quad_3
jsr test_dotted_quad_string
ldax #dotted_quad_4
jsr test_dotted_quad_string
ldax #dotted_quad_5
jsr test_dotted_quad_string
ldax #dotted_quad_6
jsr test_dotted_quad_string
ldax #dotted_quad_7
jsr test_dotted_quad_string
jmp exit_to_basic
test_dotted_quad_string:
stax temp_ax
jsr print
lda #':'
jsr print_a
lda #' '
jsr print_a
ldax temp_ax
jsr parse_dotted_quad
bcs @error
ldax #dotted_quad_value
jsr print_dotted_quad
jsr print_cr
rts
@error:
ldax #failed_msg
jsr print
jsr print_cr
rts
.bss
temp_ax: .res 2
.rodata
dotted_quad_1:
.byte "1.1.1.1",0
dotted_quad_2:
.byte "GOOBER",0
dotted_quad_3:
.byte "255.255.255.0",0
dotted_quad_4:
.byte "111.222.333.444",0
dotted_quad_5:
.byte "111.22.3",0
dotted_quad_6:
.byte "111.22.3.4",0
dotted_quad_7:
.byte "3.4.5.6X",0