I'm trying to build the UDP Listener example code from the IP65 website,
http://ip65.sourceforge.net/ I did build a test code for the UDP client, using one I found in this forum. I left out the pre-processor section from the test code below to keep it short. I hope that someone can help clarify a few things about this code.
Basically , I get an error about the "zp_data" variable that's not defined in the example code. I'm not sure yet on how it's used. I could use some help to clarify on what's being done with this. I thought it might have been a variable used in the IP65 code, but a search in that code comes up empty.
I understand that while it calls 'ip65_process' and a packet arrives, it will call 'gotpacket'. I'm just not entirely sure of the purpose for the steps being used in this section of the code.
I see that 'udp_inp' points to the UDP packet. It seems that 'zp_data' is the message which I can print to the screen. But the offsets being
used in here for 'udp_inp' doesn't seem right.
From looking at the upd.s in the IP65 source, the UDP Length is offset +4, and 2bytes long. And the payload data is offset +8.
But the line ' lda udp_inp + 1' tells me its pointing to the LoByte of the Source Port addr in the UDP Header. And the line 'ldx udp_inp + 2' tells me that's pointing to the HiByte of the Dest.Port addr in the UDP Header. So i'm not sure what is supposed to be stored at 'zp_data' in memory.
I see in the 'copy:' section is where it should extract the data from the UDP packet. But line 'ldy udp_inp + 3' tells me it's pointing to the LoByte of the Dest Port Addr. Shouldn't this point to the UDP Length at offset +4, but since only one byte is used here (I guess for short messages), maybe use the LoByte at offset +5, so then 'ldy udp_inp + 5'
And on line 'lda udp_inp + 3,y' should this point the the beginning of the payload data at offset+8, 'lda udp_inp + 8,y'. And then the loop should decrement the length byte until it reads the entire message. And I can then use the print call in the kernal rom to display it on the screen.
I'm not sure of the significance of using the zero page addr $01 in the 'gotpacket' section, after the sei, since this normally affects the memory configuration for the Ram.
Dan
Code:
;==============================================================================
gangedport = 60064
;----------------------------------------------------------------------------------------------------
init:
jsr ip65_init ;IP65 call
lda #<gotpacket
ldx #>gotpacket
sta udp_callback ;IP65 variable
stx udp_callback + 1
lda #<gangedport
ldx #>gangedport
jsr udp_add_listener ;IP65 call
;----------------------------------------------------------------------------------------------------
main:
jsr ip65_process ;IP65 call
jmp main
;----------------------------------------------------------------------------------------------------
gotpacket:
sei
lda $01
pha
lda udp_inp
sta $01
lda udp_inp + 1
ldx udp_inp + 2
sta zp_data
stx zp_data + 2
ldy udp_inp + 3
copy:
lda udp_inp + 3,y
sta (zp_data),y
dey
bne copy
pla
sta $01
cli
rts
;==============================================================================