diff --git a/ethernet/ethernet/main.s b/ethernet/ethernet/main.s new file mode 100644 index 0000000..db5154a --- /dev/null +++ b/ethernet/ethernet/main.s @@ -0,0 +1,418 @@ +; +; main.s +; ethernet +; +; Created by Kris Kennaway on 03/01/2019. +; Copyright © 2019 Kris Kennaway. All rights reserved. +; + +.include "apple2.inc" + +.org $8000 +.proc main +; TCP SOCKET DEMO FOR W5100/UTHERNET II +; BY D. FINNIGAN +; OCTOBER 2015 +; +; UPDATED 09 JAN 2016 6* +; UPDATED 13 FEB 2017, C. TORRENCE +; -REMOVED SEPARATE PATH FOR WRAP, ADD DEBUG PRINT + +; SLOT 1 I/O ADDRESSES FOR THE W5100 +WMODE = $C094 +WADRH = $C095 +WADRL = $C096 +WDATA = $C097 + +; W5100 LOCATIONS +MACADDR = $0009 ; MAC ADDRESS +SRCIP = $000F ; SOURCE IP ADDRESS +RMSR = $001A ; RECEIVE BUFFER SIZE + +; SOCKET 0 LOCATIONS + +S0MR = $0400 ; SOCKET 0 MODE REGISTER +S0CR = $0401 ; COMMAND REGISTER +S0IR = $0402 ; INTERRUPT REGISTER +S0SR = $0403 ; STATUS REGISTER +S0LOCALPORT = $0404 ; LOCAL PORT +S0FORADDR = $040C ; FOREIGN ADDRESS +S0FORPORT = $0410 ; FOREIGN PORT +S0MSS = $0412 ; MAX SEGMENT SIZE +S0PROTO = $0414 ; IP PROTOCOL +S0TOS = $0415 ; DS/ECN (FORMER TOS) +S0TTL = $0416 ; IP TIME TO LIVE +S0TXFSR = $0420 ; TX FREE SIZE REGISTER +S0TXRR = $0422 ; TX READ POINTER REGISTER +S0TXWR = $0424 ; TX WRITE POINTER REGISTER +S0RXRSR = $0426 ; RX RECEIVED SIZE REGISTER +S0RXRD = $0428 ; RX READ POINTER REGISTER + +; SOCKET 0 PARAMETERS +RXBASE = $6000 ; SOCKET 0 RX BASE ADDR +RXMASK = $1FFF ; SOCKET 0 8KB ADDRESS MASK +TXBASE = $4000 ; SOCKET 0 TX BASE ADDR +TXMASK = RXMASK ; SOCKET 0 TX MASK + +; SOCKET COMMANDS +SCOPEN = $01 ; OPEN +SCLISTEN = $02 ; LISTEN +SCCONNECT = $04 ; CONNECT +SCDISCON = $08 ; DISCONNECT +SCCLOSE = $10 ; CLOSE +SCSEND = $20 ; SEND +SCSENDMAC = $21 ; SEND MAC +SCSENDKEEP = $22 ; SEND KEEP ALIVE +SCRECV = $40 ; RECV + +; SOCKET STATUS +STCLOSED = $00 +STINIT = $13 +STLISTEN = $14 +STESTABLISHED = $17 +STCLOSEWAIT = $1C +STUDP = $22 +STIPRAW = $32 +STMAXRAW = $42 +STPPOE = $5F + +; MONITOR SUBROUTINES +KBD = $C000 +KBDSTRB = $C010 +COUT = $FDED +PRBYTE = $FDDA +PRNTAX = $F941 + +; ZERO-PAGE STORAGE +PTR = $06 ; 2 BYTES FOR APPLE BUFFER +GETSIZE = $08 ; 2 BYTES FOR RX_RSR +GETOFFSET = $0A ; 2 BYTES FOR OFFSET ADDR +GETSTARTADR = $0C ; 2 BYTES FOR PHYSICAL ADDR + +; RESET AND CONFIGURE W5100 + LDA #6 ; 5 RETRIES TO GET CONNECTION + STA PTR ; NUMBER OF RETRIES + BPL RESET ; ALWAYS TAKEN + +SRCADDR: .byte $C0,$A8,$01,147 ; 192.168.2.5 W5100 IP +FADDR: .byte $C0,$A8,$01,15 ; 192.168.2.1 FOREIGN IP +FPORT: .byte $4E,$20 ; 20000 FOREIGN PORT +MAC: .byte $00,$08,$DC,$01,$02,$03 ; W5100 MAC ADDRESS + +RESET: + LDA #$80 ; reset + STA WMODE + LDA #3 ; CONFIGURE WITH AUTO-INCREMENT + STA WMODE + +; ASSIGN MAC ADDRESS + LDA #>MACADDR + STA WADRH + LDA #S0MR + STA WADRH + LDA #RXMASK + STA GETOFFSET+1 + LDA WDATA ; LOW BYTE + AND #=1 page + + LDA WDATA ; XXX: do I have to read it? DOn't think so + +; We know there is at least a page in the buffer, so read it + +; CALCULATE PHYSICAL ADDRESS WITHIN W5100 RX BUFFER + CLC + LDA GETOFFSET + ADC #RXBASE + STA GETSTARTADR+1 + +; SET BUFFER ADDRESS ON W5100 + JSR DEBUG ; UNCOMMENT FOR W5100 DEBUG INFO + LDA GETSTARTADR+1 ; HIGH BYTE FIRST + STA WADRH + LDA GETSTARTADR + STA WADRL + +; SET BUFFER ADDRESS ON APPLE +; XXX can hoist this out of the loop and let the low byte wrap + LDA #0 ; LOW BYTE OF BUFFER + STA PTR + LDA #$50 ; HIGH BYTE + STA PTR+1 + +; BEGIN COPY + LDY #$00 +@L: + LDA WDATA + STA (PTR),Y + JSR CLEANOUT ; DEBUG PRINT + INY + BNE @L + + LDA #$8D ; + JSR COUT ; DEBUG PRINT + +; UPDATE REXRD TO REFLECT DATA WE JUST READ + +UPDATERXRD: + CLC + LDA #>S0RXRD ; NEED HIGH BYTE HERE + STA WADRH ; XXX needed? I think this is already set + LDA #S0CR ; HIGH BYTE NEEDED + STA WADRH + LDA # +@OUT: + JMP COUT ; THIS WILL DO THE RTS + +; DEBUG - PRINT W5100 STARTADR AND SIZE +DEBUG: + LDA #$A0 ; " " + JSR COUT + LDA #$A4 ; "$" + JSR COUT + LDA GETSTARTADR+1 + LDX GETSTARTADR + JSR PRNTAX +; LDA #$A0 ; " " +; JSR COUT +; LDA #$A4 ; "$" +; JSR COUT +; LDA GETSIZE+1 +; LDX GETSIZE +; JSR PRNTAX + LDA #$8D + JMP COUT ; THIS WILL DO THE RTS + +.endproc