Use parameters for TCP C callback.

In contrast to the multiple UDP callbacks there's only one TCP callback so it easy to provide a wrapper for the C callback that pushes C parameters on the stack.
This commit is contained in:
Oliver Schmidt 2017-11-07 23:05:05 +01:00
parent 7af0dcd1fa
commit e1bf89d1a8
3 changed files with 28 additions and 20 deletions

View File

@ -179,19 +179,24 @@ unsigned char __fastcall__ udp_send(const unsigned char* buf, unsigned int len,
//
// Inputs: port: TCP port to listen on
// callback: Vector to call when data arrives on this connection
// buf: Pointer to buffer with data received
// len: -1 on close, otherwise length of data received
// Output: 1 if an error occured, 0 otherwise
//
unsigned char __fastcall__ tcp_listen(unsigned int port, void (*callback)(void));
unsigned char __fastcall__ tcp_listen(unsigned int port,
void (*callback)(const unsigned char* buf, int len));
// Make outbound TCP connection
//
// Inputs: dest: Destination IP address
// dest_port: Destination port
// callback: Vector to call when data arrives on this connection
// buf: Pointer to buffer with data received
// len: -1 on close, otherwise length of data received
// Output: 1 if an error occured, 0 otherwise
//
unsigned char __fastcall__ tcp_connect(unsigned long dest, unsigned int dest_port,
void (*callback)(void));
void (*callback)(const unsigned char* buf, int len));
// Close the current TCP connection
//
@ -200,14 +205,6 @@ unsigned char __fastcall__ tcp_connect(unsigned long dest, unsigned int dest_por
//
unsigned char tcp_close(void);
// Access to received TCP data
//
// Access to the two items below is only valid in the context of a callback
// set with tcp_listen or tcp_connect.
//
extern unsigned char* tcp_recv_buf; // Pointer to buffer with data received
extern int tcp_recv_len; // -1 on close, otherwise length of data received
// Send data on the current TCP connection
//
// Inputs: buf: Pointer to buffer containing data to be sent

View File

@ -3,8 +3,6 @@
.export _tcp_listen
.export _tcp_connect
.export _tcp_close
.export _tcp_recv_buf
.export _tcp_recv_len
.export _tcp_send
.export _tcp_send_keep_alive
@ -20,10 +18,25 @@
.import tcp_connect_ip
.import tcp_send_data_len
.import popax, popeax
.import pushax, popax, popeax
.importzp ptr1, sreg
.data
callback:
ldax tcp_inbound_data_ptr
jsr pushax
ldax tcp_inbound_data_length
jmpvector:
jmp $FFFF
.code
_tcp_listen:
stax jmpvector+1
ldax #callback
stax tcp_callback
jsr popax
jsr tcp_listen
@ -33,6 +46,8 @@ _tcp_listen:
rts
_tcp_connect:
stax jmpvector+1
ldax #callback
stax tcp_callback
jsr popax
stax ptr1
@ -54,10 +69,6 @@ _tcp_close:
rol
rts
_tcp_recv_buf := tcp_inbound_data_ptr
_tcp_recv_len := tcp_inbound_data_length
_tcp_send:
stax tcp_send_data_len
jsr popax

View File

@ -23,16 +23,16 @@ void error_exit(void)
exit(1);
}
void tcp_recv(void)
void tcp_recv(const unsigned char* tcp_buf, int tcp_len)
{
if (len)
{
return;
}
len = tcp_recv_len;
len = tcp_len;
if (len != -1)
{
memcpy(buf, tcp_recv_buf, len);
memcpy(buf, tcp_buf, len);
}
}