Made W5100 UDP driver directly callable from C.

This commit is contained in:
Oliver Schmidt 2015-08-02 17:03:14 +02:00
parent c9af38790a
commit 24a5bcea85
4 changed files with 57 additions and 91 deletions

View File

@ -29,9 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/ ******************************************************************************/
.export init .export _w5100_init
.export recv_init, recv_byte, recv_done .export _w5100_recv_init, _w5100_recv_byte, _w5100_recv_done
.export send_init, send_byte, send_done .export _w5100_send_init, _w5100_send_byte, _w5100_send_done
ptr := $06 ; 2 byte pointer value ptr := $06 ; 2 byte pointer value
sha := $08 ; 2 byte physical addr shadow ($F000-$FFFF) sha := $08 ; 2 byte physical addr shadow ($F000-$FFFF)
@ -46,7 +46,7 @@ data := $C0B7
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
init: _w5100_init:
; Input ; Input
; AX: Address of ip_parms (serverip, cfg_ip, cfg_netmask, cfg_gateway) ; AX: Address of ip_parms (serverip, cfg_ip, cfg_netmask, cfg_gateway)
; Output ; Output
@ -159,19 +159,18 @@ set_data6502:
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
recv_init: _w5100_recv_init:
; Input ; Input
; None ; None
; Output ; Output
; C: Clear if ready to receive ; AX: Number of bytes to receive
; AX: If C is clear then number of bytes to receive
; Remark ; Remark
; To be called before recv_byte. ; To be called before recv_byte.
; Socket 1 RX Received Size Register: 0 or volatile ? ; Socket 1 RX Received Size Register: 0 or volatile ?
lda #$26 ; Socket RX Received Size Register lda #$26 ; Socket RX Received Size Register
jsr prolog jsr prolog
bcs :+++ bne error
; Socket 1 RX Read Pointer Register ; Socket 1 RX Read Pointer Register
; -> addr already set ; -> addr already set
@ -185,7 +184,7 @@ recv_init:
clc clc
ldx #$05 ldx #$05
stx tmp stx tmp
: jsr recv_byte ; Doesn't trash C : jsr _w5100_recv_byte ; Doesn't trash C
ldx tmp ldx tmp
eor hdr,x ; Doesn't trash C eor hdr,x ; Doesn't trash C
beq :+ beq :+
@ -195,9 +194,9 @@ recv_init:
php ; Save C php ; Save C
; Read data length ; Read data length
jsr recv_byte ; Hibyte jsr _w5100_recv_byte ; Hibyte
sta len+1 sta len+1
jsr recv_byte ; Lobyte jsr _w5100_recv_byte ; Lobyte
sta len sta len
; Add 8 byte header to set pointer advancement ; Add 8 byte header to set pointer advancement
@ -211,21 +210,20 @@ recv_init:
; Skip frame if it doesn't originate from our ; Skip frame if it doesn't originate from our
; expected communicaion peer ; expected communicaion peer
plp ; Restore C plp ; Restore C
bcs recv_done bcs _w5100_recv_done
; Return success with data length ; Return data length
lda len lda len
ldx len+1 ldx len+1
clc rts
: rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
send_init: _w5100_send_init:
; Input ; Input
; AX: Number of bytes to send ; AX: Number of bytes to send
; Output ; Output
; C: Clear if ready to send ; A: Nonzero if ready to send
; Remark ; Remark
; To be called before send_byte. ; To be called before send_byte.
@ -236,12 +234,12 @@ send_init:
; Socket 1 TX Free Size Register: 0 or volatile ? ; Socket 1 TX Free Size Register: 0 or volatile ?
lda #$20 ; Socket TX Free Size Register lda #$20 ; Socket TX Free Size Register
jsr prolog jsr prolog
bcs :+ bne error
; Socket 1 TX Free Size Register: < advancement ? ; Socket 1 TX Free Size Register: < advancement ?
cpx adv ; Lobyte cpx adv ; Lobyte
sbc adv+1 ; Hibyte sbc adv+1 ; Hibyte
bcc sec_rts ; Not enough free size -> error bcc error ; Not enough free size
; Socket 1 TX Write Pointer Register ; Socket 1 TX Write Pointer Register
ldy #$24 ldy #$24
@ -252,8 +250,16 @@ send_init:
jsr set_addrphysical jsr set_addrphysical
; Return success ; Return success
clc lda #$01
: rts ldx #>$0000 ; Required by cc65 C callers
rts
;------------------------------------------------------------------------------
error:
lda #<$0000
tax
rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -262,7 +268,7 @@ prolog:
; Socket 1 Command Register: 0 ? ; Socket 1 Command Register: 0 ?
jsr set_addrcmdreg1 jsr set_addrcmdreg1
ldx data ldx data
bne sec_rts ; Not completed -> error bne :++ ; Not completed -> Z = 0
; Socket Size Register: not 0 ? ; Socket Size Register: not 0 ?
tay ; Select Size Register tay ; Select Size Register
@ -271,23 +277,20 @@ prolog:
sta ptr+1 ; Hibyte sta ptr+1 ; Hibyte
ora ptr ora ptr
bne :+ bne :+
inx ; -> Z = 0
sec_rts:
sec ; Error (size == 0)
rts rts
; Socket Size Register: volatile ? ; Socket Size Register: volatile ?
: jsr get_wordsocket1 : jsr get_wordsocket1
cpx ptr ; Lobyte cpx ptr ; Lobyte
bne sec_rts ; Volatile size -> error bne :+ ; Volatile size -> Z = 0
cmp ptr+1 ; Hibyte cmp ptr+1 ; Hibyte
bne sec_rts ; Volatile size -> error ; bne :+ ; Volatile size -> Z = 0
clc ; Success (size != 0) : rts
rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
recv_byte: _w5100_recv_byte:
; Input ; Input
; None ; None
; Output ; Output
@ -301,11 +304,12 @@ recv_byte:
; Increment physical addr shadow lobyte ; Increment physical addr shadow lobyte
inc sha inc sha
beq incsha beq incsha
ldx #>$0000 ; Required by cc65 C callers
rts rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
send_byte: _w5100_send_byte:
; Input ; Input
; A: Byte to send ; A: Byte to send
; Output ; Output
@ -325,11 +329,12 @@ incsha:
; Increment physical addr shadow hibyte ; Increment physical addr shadow hibyte
inc sha+1 inc sha+1
beq set_addrbase beq set_addrbase
ldx #>$0000 ; Required by cc65 C callers (_w5100_recv_byte)
rts rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
recv_done: _w5100_recv_done:
; Input ; Input
; None ; None
; Output ; Output
@ -346,7 +351,7 @@ recv_done:
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
send_done: _w5100_send_done:
; Input ; Input
; None ; None
; Output ; Output
@ -377,8 +382,9 @@ epilog:
tya ; Restore command tya ; Restore command
jsr set_addrcmdreg1 jsr set_addrcmdreg1
sta data sta data
sec ; When coming from recv_init -> error
rts ; Return error (_w5100_recv_init)
bne error ; Always
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -398,6 +404,7 @@ set_addrphysical:
set_addr: set_addr:
stx addr ; Hibyte stx addr ; Hibyte
sty addr+1 ; Lobyte sty addr+1 ; Lobyte
ldx #>$0000 ; Required by cc65 C callers (_w5100_recv_byte)
rts rts
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------

View File

@ -118,7 +118,7 @@ ip65demo.dsk: httpd.bin httpd-slotscan.bin
java -jar $(AC) -cc65 $@ webserver-slot3 B < httpd.bin java -jar $(AC) -cc65 $@ webserver-slot3 B < httpd.bin
java -jar $(AC) -cc65 $@ webserver-slotscan B < httpd-slotscan.bin java -jar $(AC) -cc65 $@ webserver-slotscan B < httpd-slotscan.bin
w5100_%.bin: ../supplement/w5100_%.s w5100_%_s.s w5100_%_c.c w5100_%.bin: ../supplement/w5100_%.s w5100_%_main.c
cl65 -o $@ -t apple2enh -m $(basename $@).map $^ cl65 -o $@ -t apple2enh -m $(basename $@).map $^
w5100.dsk: w5100_udp.bin w5100.dsk: w5100_udp.bin

View File

@ -1,15 +1,15 @@
#include <stdio.h> #include <stdio.h>
#include <conio.h> #include <conio.h>
void __fastcall__ init(void *parms); void __fastcall__ w5100_init(void *parms);
unsigned recv_init(void); unsigned int w5100_recv_init(void);
unsigned char recv_byte(void); unsigned char w5100_recv_byte(void);
void recv_done(void); void w5100_recv_done(void);
unsigned __fastcall__ send_init(unsigned len); unsigned char __fastcall__ w5100_send_init(unsigned int len);
void __fastcall__ send_byte(unsigned char val); void __fastcall__ w5100_send_byte(unsigned char val);
void send_done(void); void w5100_send_done(void);
struct struct
{ {
@ -32,7 +32,7 @@ void main(void)
videomode(VIDEOMODE_80COL); videomode(VIDEOMODE_80COL);
printf("Init\n"); printf("Init\n");
init(&parms); w5100_init(&parms);
printf("(S)end or e(X)it\n"); printf("(S)end or e(X)it\n");
do do
@ -57,19 +57,19 @@ void main(void)
parms.serverip[1], parms.serverip[1],
parms.serverip[2], parms.serverip[2],
parms.serverip[3]); parms.serverip[3]);
while (!send_init(len)) while (!w5100_send_init(len))
{ {
printf("!"); printf("!");
} }
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
{ {
send_byte(i); w5100_send_byte(i);
} }
send_done(); w5100_send_done();
printf(".\n"); printf(".\n");
} }
len = recv_init(); len = w5100_recv_init();
if (len) if (len)
{ {
unsigned i; unsigned i;
@ -84,9 +84,9 @@ void main(void)
{ {
printf("\n$%04X:", i); printf("\n$%04X:", i);
} }
printf(" %02X", recv_byte()); printf(" %02X", w5100_recv_byte());
} }
recv_done(); w5100_recv_done();
printf(".\n"); printf(".\n");
} }
} }

View File

@ -1,41 +0,0 @@
.export _init
.export _recv_init, _recv_byte, _recv_done
.export _send_init, _send_byte, _send_done
.import init
.import recv_init, recv_byte, recv_done
.import send_init, send_byte, send_done
_init:
jmp init
_recv_init:
jsr recv_init
bcc :+
lda #<$0000
ldx #>$0000
: rts
_recv_byte:
jsr recv_byte
ldx #>$0000
rts
_recv_done:
jmp recv_done
_send_init:
jsr send_init
bcc :+
lda #<$0000
ldx #>$0000
rts
: lda #<$0001
ldx #>$0001
rts
_send_byte:
jmp send_byte
_send_done:
jmp send_done