1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-06-26 06:29:28 +00:00

Add utils source and reorg

This commit is contained in:
David Schmenk 2019-12-21 08:30:04 -08:00
parent 48a33a4432
commit 4aa8c8da1f
16 changed files with 52 additions and 1046 deletions

View File

@ -1,993 +0,0 @@
//
// Wiznet 5100 based ethernet card
//
// TCP/IP is built into hardware, so no dependencies on the software
// layers, like the Uthernet
//
include "inc/cmdsys.plh"
//
// Net object
//
import inet
word iNet
end
struc t_inet
word initIP
word serviceIP
word openUDP
word sendUDP
word closeUDP
word listenTCP
word connectTCP
word sendTCP
word closeTCP
word setInterfaceIP
word getInterfaceHA
word setCallback
word setParam
end
//
// Module don't free memory
//
const modkeep = $2000
const modinitkeep = $4000
//
// Wiznet registers
//
const WIZ_MR = $00
const WIZ_GWR = $01
const WIZ_SUBR = $05
const WIZ_SHAR = $09
const WIZ_SIPR = $0F
const WIZ_IR = $15
const WIZ_IMR = $16
const WIZ_RTR = $17
const WIZ_RCR = $19
const WIZ_RMSR = $1A
const WIZ_TMSR = $1B
const WIZ_PATR = $1C
const WIZ_PTMR = $28
const WIZ_PMGC = $29
const WIZ_UIPR = $2A
const WIZ_UPRT = $2E
//
// Wiznet socket registers
//
const WIZ_SREGS = $0400
const WIZ_SSIZE = $0100
const WIZ_SOCK0 = $0400
const WIZ_SOCK1 = $0500
const WIZ_SOCK2 = $0600
const WIZ_SOCK3 = $0700
const WIZ_SnMR = $00
const WIZ_SnCR = $01
const WIZ_SnIR = $02
const WIZ_SnSR = $03
const WIZ_SnPORT = $04
const WIZ_SnDHAR = $06
const WIZ_SnDIPR = $0C
const WIZ_SnDPORT = $10
const WIZ_SnMSSR = $12
const WIZ_SnPROTO = $14
const WIZ_SnTOS = $15
const WIZ_SnTTL = $16
const WIZ_SnFSR = $20
const WIZ_SnTXRD = $22
const WIZ_SnTXWR = $24
const WIZ_SnRSR = $26
const WIZ_SnRXRD = $28
//
// Wiznet socket data
//
const WIZ_TXMEM = $4000
const WIZ_TXSIZE = $0800
const WIZ_TXMASK = WIZ_TXSIZE-1
const WIZ_TXMEM0 = $4000
const WIZ_TXMEM1 = $4800
const WIZ_TXMEM2 = $5000
const WIZ_TXMEM3 = $5800
const WIZ_RXMEM = $6000
const WIZ_RXSIZE = $0800
const WIZ_RXMASK = WIZ_RXSIZE-1
const WIZ_RXMEM0 = $6000
const WIZ_RXMEM1 = $6800
const WIZ_RXMEM2 = $7000
const WIZ_RXMEM3 = $7800
//
// Wiznet indirect registers
//
byte regidx, regdata
word slot, saveidx
//
// Wiznet MAC address
//
byte[6] wizMAC = $00,$0A,$99,$1E,$02,$B0
//
// Wiznet IP addresses
//
byte[4] localip
byte[4] subnet
byte[4] gateway
//
// Predefine service routine
//
predef wizServiceIP
//
// Segment list element
//
struc t_segment
word seg_buf
word seg_len
end
//
// Max Ethernet frame size
//
const MAX_FRAME_SIZE = 1518
const MAC_BROADCAST = $FFFF
const MAC_SIZE = 6
//
// Ethernet header
//
struc t_ethrhdr
byte[MAC_SIZE] ethr_dst
byte[MAC_SIZE] ethr_src
word ethr_payload
end
const PAYLOAD_IP = $0008 // BE format
const PAYLOAD_ARP = $0608 // BE format
//
// IP datagram header
//
const IP4ADR_SIZE = 4
struc t_iphdr
byte ip_vers_hlen
byte ip_service
word ip_length
word ip_id
word ip_flags_fragofst
byte ip_ttl
byte ip_proto
word ip_chksm
byte[IP4ADR_SIZE] ip_src
byte[IP4ADR_SIZE] ip_dst
byte[] ip_options
end
const IP_BROADCAST = $FFFF
const IP_PROTO_ICMP = $01
const IP_PROTO_UDP = $11
const IP_PROTO_TCP = $06
word bcast = IP_BROADCAST, IP_BROADCAST
//
// ICMP type/codes
//
const IP_PROTO_ICMP = 1
const ICMP_ECHO_REQST = 8
const ICMP_ECHO_REPLY = 0
//
// ICMP message format
//
struc t_icmp
byte icmp_type
byte icmp_code
word icmp_chksm
word[2] icmp_header
end
//
// UDP IPv4 psuedo header
//
struc t_piphdr
byte[IP4ADR_SIZE] pip_src
byte[IP4ADR_SIZE] pip_dst
byte pip_zero
byte pip_proto
word pip_len
end
//
// UDP header
//
struc t_udphdr
word udp_src
word udp_dst
word udp_len
word udp_chksm
end
//
// TCP header
//
struc t_tcphdr
word tcp_src
word tcp_dst
word tcp_len
word tcp_chksm
end
//
// Local network parameters
//
const MAX_WIZ_CHANNELS = 4
//
// Channel protocols
//
const WIZ_PROTO_CLOSED = 0
const WIZ_PROTO_TCP = 1
const WIZ_PROTO_UDP = 2
const WIZ_PROTO_IP = 3
const WIZ_PROTO_RAW = 4
//
// State transistions
//
const TCP_STATE_CLOSED = 0
const TCP_STATE_CLOSING = 1
const TCP_STATE_LISTEN = 2
const TCP_STATE_CONNECT = 3
const TCP_STATE_OPEN = 4
//
// HW channels
//
struc t_channel
byte channel_proto
byte channel_state
word channel_regs
word channel_txmem
word channel_rxmem
word channel_lclport
word channel_remport
byte[4] channel_remip
word channel_recv_func
word channel_recv_parm
end
byte[t_channel * MAX_WIZ_CHANNELS] wizChannel
//
// Service ICMP hook
//
export word hookICMP
//
// Defines for ASM routines
//
asm equates
!SOURCE "vmsrc/plvmzp.inc"
end
//
// Swap bytes in word
//
asm swab
LDA ESTKL,X
LDY ESTKH,X
STA ESTKH,X
STY ESTKL,X
RTS
end
//
// Wiznet I/O functions
//
// POKE WORD TO I/O SPACE
// Note: Big Endian format
//
asm _pokeiow
LDA ESTKH,X
end
asm _pokeiowl
STA $C000
LDA ESTKL,X
end
asm _pokeiowh
STA $C000
RTS
end
//
// POKE BYTE TO I/O SPACE
//
asm _pokeio
LDA ESTKL,X
end
asm _pokeiol
STA $C000
RTS
end
//
// PEEK BYTE FROM I/O SPACE
//
asm _peekio
DEX
end
asm _peekiol
LDA $C000
STA ESTKL,X
LDA #$00
STA ESTKH,X
RTS
end
//
// PEEK WORD FROM I/O SPACE
// Note: Big Endian format
//
asm _peekiow
DEX
end
asm _peekiowl
LDA $C000
STA ESTKH,X
end
asm _peekiowh
LDA $C000
STA ESTKL,X
RTS
end
//
// WRITE DATA INTO I/O SPACE
// pokedata(BUF, LEN)
//
asm pokedata
LDA ESTKL+1,X
STA SRCL
LDA ESTKH+1,X
STA SRCH
LDY ESTKL,X
BEQ POKELP
LDY #$00
INC ESTKH,X
POKELP LDA (SRC),Y
end
asm _pokedata
STA $C000
INY
BNE +
INC SRCH
+ DEC ESTKL,X
BNE POKELP
DEC ESTKH,X
BNE POKELP
INX
RTS
end
//
// READ DATA FROM I/O SPACE
// peekdata(BUF, LEN)
//
asm peekdata
LDA ESTKL+1,X
STA DSTL
LDA ESTKH+1,X
STA DSTH
LDY ESTKL,X
BEQ PEEKLP
LDY #$00
INC ESTKH,X
end
asm _peekdata
PEEKLP LDA $C000
STA (DST),Y
INY
BNE +
INC DSTH
+ DEC ESTKL,X
BNE PEEKLP
DEC ESTKH,X
BNE PEEKLP
INX
RTS
end
def pokeiow(io, data)
_pokeiowl.1 = io
_pokeiowh.1 = io+1
return _pokeiow(data)
end
def pokeio(io, data)
_pokeiol.1 = io
return _pokeio(data)
end
def peekio(io)
_peekiol.1 = io
return _peekio()
end
def peekiow(io)
_peekiowl.1 = io
_peekiowh.1 = io+1
return _peekiow()
end
def pokereg(reg, data)
_pokeiow(reg)
return _pokeio(data)
end
def peekreg(reg)
_pokeiow(reg)
return _peekio()
end
def pokeregs(reg, buf, len)
// _pokeiow(reg)
// return pokedata(buf, len)
word i
len = len - 1
for i = 0 to len
_pokeiow(reg + i)
_pokeio(buf->[i])
next
end
def peekregs(reg, buf, len)
// _pokeiow(reg)
// return peekdata(buf, len)
// There is an issue missing data on back-to-back reads
word i
len = len - 1
for i = 0 to len
_pokeiow(reg + i)
buf->[i] = _peekio()
next
end
def pokeregw(reg, dataw)
_pokeiow(reg)
_pokeio(dataw.1)
return _pokeio(dataw.0)
end
def peekregw(reg)
word dataw
_pokeiow(reg)
dataw.1 = _peekio()
_pokeiow(reg + 1)
dataw.0 = _peekio()
return dataw
end
//
// DEBUG
//
def putb(hexb)
return call($FDDA, hexb, 0, 0, 0)
end
def puth(hex)
return call($F941, hex >> 8, hex, 0, 0)
end
def putip(ipptr)
byte i
for i = 0 to 2
puti(ipptr->[i]); putc('.')
next
return puti(ipptr->[i])
end
//
// Send UDP datagram
//
def wizSendUDP(wiz, ipdst, portdst, data, len)
word wizregs, wizdata, txrr, txwr, splitlen
wizregs = wiz=>channel_regs
wizdata = wiz=>channel_txmem
if !ipdst
ipdst = @bcast
fin
//
// Wait for Tx room
//
repeat; until peekregw(wizregs + WIZ_SnFSR) >= len
//
// Calc new write ptr, check for split
//
txwr = peekregw(wizregs + WIZ_SnTXWR)
txrr = txwr & WIZ_TXMASK
if txrr + len > WIZ_TXSIZE
splitlen = WIZ_TXSIZE - txrr
pokeregs(wizdata + txrr, data, splitlen)
pokeregs(wizdata, data + splitlen, len - splitlen)
else
pokeregs(wizdata + txrr, data, len)
fin
//
// Set destination address/port
//
pokeregs(wizregs + WIZ_SnDIPR, ipdst, IP4ADR_SIZE)
pokeregw(wizregs + WIZ_SnDPORT, portdst)
//
// Update write pointer and send
//
pokeregw(wizregs + WIZ_SnTXWR, txwr + len)
pokereg(wizregs + WIZ_SnCR, $20) // SEND
end
//
// Open UDP channel and set datagram received callback
//
def wizOpenUDP(localport, callback, param)
word wiz
byte i
if !localport; return -1; fin // invalid port
//
// Look for an existing notification on localport
//
//putc('O')
wiz = @wizChannel
for i = 1 to MAX_WIZ_CHANNELS
if wiz->channel_proto == IP_PROTO_UDP and wiz=>channel_lclport == localport
break
fin
wiz = wiz + t_channel
next
if i > MAX_WIZ_CHANNELS
//
// Add notification on localport if room
//
wiz = @wizChannel
for i = 1 to MAX_WIZ_CHANNELS
if !wiz->channel_proto
break
fin
wiz = wiz + t_channel
next
if i > MAX_WIZ_CHANNELS
return 0
fin
fin
//putc('0' + i);putln
//
// Fill in this channel and open it
//
wiz->channel_proto = WIZ_PROTO_UDP
wiz=>channel_lclport = localport
wiz=>channel_recv_func = callback
wiz=>channel_recv_parm = param
pokeregw(wiz=>channel_regs + WIZ_SnPORT, localport)
pokereg(wiz=>channel_regs + WIZ_SnMR, $02) // UDP protocol
pokereg(wiz=>channel_regs + WIZ_SnCR, $01) // OPEN
return wiz
end
//
// Close UDP port
//
def wizCloseUDP(wiz)
//putc('S')
if isuge(wiz, @wizChannel) and isult(wiz, @wizChannel + MAX_WIZ_CHANNELS * t_channel)
//
// Clear notiications on this port
//
if wiz->channel_proto == WIZ_PROTO_UDP
//putc('1' + ((wiz=>channel_regs - WIZ_SREGS) >> 8));putln
wiz->channel_proto = WIZ_PROTO_CLOSED
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
return 0
fin
fin
//putc('!');putln
//
// Invalid port
//
return -1
end
//
// Open TCP socket in SERVER mode
//
def wizListenTCP(lclport, callback, param)
word wiz
byte i
//
// Look for an existing notification on localport
//
//putc('L')
wiz = @wizChannel
for i = 1 to MAX_WIZ_CHANNELS
if wiz->channel_proto == WIZ_PROTO_TCP and wiz->channel_state == TCP_STATE_LISTEN and wiz=>channel_lclport == lclport
break
fin
wiz = wiz + t_channel
next
if i > MAX_WIZ_CHANNELS
//
// Add notification on localport if room
//
wiz = @wizChannel
for i = 1 to MAX_WIZ_CHANNELS
if !wiz->channel_proto
break
fin
wiz = wiz + t_channel
next
if i > MAX_WIZ_CHANNELS
return 0
fin
fin
//putc('0' + i);putln
//
// Fill in this channel and open it
//
wiz->channel_proto = WIZ_PROTO_TCP
wiz->channel_state = TCP_STATE_LISTEN
wiz=>channel_remip:0 = 0
wiz=>channel_remip:2 = 0
wiz=>channel_remport = 0
wiz=>channel_lclport = lclport
wiz=>channel_recv_func = callback
wiz=>channel_recv_parm = param
pokereg(wiz=>channel_regs + WIZ_SnMR, $01) // TCP protocol
pokeregw(wiz=>channel_regs + WIZ_SnPORT, lclport)
pokereg(wiz=>channel_regs + WIZ_SnCR, $01) // OPEN
while peekreg(wiz=>channel_regs + WIZ_SnSR) <> $13; loop // Wait for init
pokereg(wiz=>channel_regs + WIZ_SnCR, $02) // LISTEN
return wiz
end
//
// Open TCP socket in CLIENT mode
//
def wizConnectTCP(remip, remport, lclport, callback, param)
word wiz
byte i
//
// Look for an existing notification on localport
//
wiz = @wizChannel
for i = 1 to MAX_WIZ_CHANNELS
if wiz->channel_proto == WIZ_PROTO_TCP and wiz->channel_state == TCP_STATE_CONNECT and wiz=>channel_lclport == lclport
break
fin
wiz = wiz + t_channel
next
if i > MAX_WIZ_CHANNELS
//
// Add notification on localport if room
//
wiz = @wizChannel
for i = 1 to MAX_WIZ_CHANNELS
if !wiz->channel_proto
break
fin
wiz = wiz + t_channel
next
if i > MAX_WIZ_CHANNELS
return 0
fin
fin
//
// Fill in this channel and open it
//
wiz->channel_proto = WIZ_PROTO_TCP
wiz->channel_state = TCP_STATE_CONNECT
wiz=>channel_remip:0 = remip=>0
wiz=>channel_remip:2 = remip=>2
wiz=>channel_remport = remport
wiz=>channel_lclport = lclport
wiz=>channel_recv_func = callback
wiz=>channel_recv_parm = param
pokereg(wiz=>channel_regs + WIZ_SnMR, $01) // TCP protocol
pokeregs(wiz=>channel_regs + WIZ_SnDIPR, remip, IP4ADR_SIZE)
pokeregw(wiz=>channel_regs + WIZ_SnDPORT, remport)
pokeregw(wiz=>channel_regs + WIZ_SnPORT, lclport)
pokereg(wiz=>channel_regs + WIZ_SnCR, $01) // OPEN
while peekreg(wiz=>channel_regs + WIZ_SnSR) <> $13; loop // Wait for init
pokereg(wiz=>channel_regs + WIZ_SnCR, $04) // CONNECT
return wiz
end
//
// Write to TCP socket
//
def wizSendTCP(wiz, data, len)
word wizregs, wizdata, txrr, txwr, splitlen
if wiz->channel_state <> TCP_STATE_OPEN; return -1; fin
//putc('W');puti(len);putc(':')
wizregs = wiz=>channel_regs
wizdata = wiz=>channel_txmem
//
// Wait for Tx room
//
repeat; until peekregw(wizregs + WIZ_SnFSR) >= len
//
// Calc new write ptr, check for split
//
txwr = peekregw(wizregs + WIZ_SnTXWR)
txrr = txwr & WIZ_TXMASK
if txrr + len > WIZ_TXSIZE
splitlen = WIZ_TXSIZE - txrr
pokeregs(wizdata + txrr, data, splitlen)
pokeregs(wizdata, data + splitlen, len - splitlen)
//putc('(');puti(splitlen);putc(',');puti(len-splitlen);putc(')')
else
pokeregs(wizdata + txrr, data, len)
fin
//puth(txrr);putc('-');putc('>');puth(txwr+len);putln
//
// Update write pointer and send
//
pokeregw(wizregs + WIZ_SnTXWR, txwr + len)
pokereg(wizregs + WIZ_SnCR, $20) // SEND
end
//
// Close TCP socket
//
def wizCloseTCP(wiz)
if isuge(wiz, @wizChannel) and isult(wiz, @wizChannel + MAX_WIZ_CHANNELS * t_channel)
//
// Clear notiications on this port
//
if wiz->channel_proto == WIZ_PROTO_TCP and (wiz->channel_state == TCP_STATE_OPEN or wiz->channel_state == TCP_STATE_CLOSING)
wiz->channel_state = TCP_STATE_CLOSING
pokereg(wiz=>channel_regs + WIZ_SnCR, $08) // DISCON
repeat
wizServiceIP()
until wiz->channel_state == TCP_STATE_CLOSED
wiz->channel_proto = WIZ_PROTO_CLOSED
return 0
fin
fin
//
// Invalid port
//
return -1
end
//
// Update notify callback
//
def wizSetCallback(wiz, callback)
if wiz->channel_proto == WIZ_PROTO_UDP or wiz->channel_proto == WIZ_PROTO_TCP
//
// Update callback on this port
//
wiz=>channel_recv_func = callback
return 0
fin
//
// Invalid port
//
return -1
end
//
// Update notify param
//
def wizSetParam(wiz, param)
if wiz->channel_proto == WIZ_PROTO_UDP or wiz->channel_proto == WIZ_PROTO_TCP
//
// Update param on this port
//
wiz=>channel_recv_parm = param
return 0
fin
//
// Invalid port
//
return -1
end
//
// Service incoming packets
//
def wizServiceIP
word wiz, wizregs, wizdata, rxlen, rxrr, rxwr, rxpkt, splitlen
byte ir, i, sir
ir = peekreg(WIZ_IR)
if ir and ir <> $FF // Ignore spurious read of IR
//putc('I');putb(ir)
wiz = @wizChannel
for i = 0 to 3
when ir & (1 << i)
is 1
is 2
is 4
is 8
wizregs = wiz=>channel_regs
wizdata = wiz=>channel_rxmem
sir = peekreg(wizregs + WIZ_SnIR)
when wiz->channel_proto
is WIZ_PROTO_TCP
if sir & $01
//putc('C')
//
// Connect TCP socket
//
when wiz->channel_state
is TCP_STATE_LISTEN
peekregs(wiz=>channel_regs + WIZ_SnDIPR, @wiz=>channel_remip, IP4ADR_SIZE)
wiz=>channel_remport = peekregw(wiz=>channel_regs + WIZ_SnDPORT)
is TCP_STATE_CONNECT
wiz->channel_state = TCP_STATE_OPEN
break
otherwise
//putc('?')
wend
fin
if sir & $04
//putc('R')
//
// Receive TCP packet
//
rxlen = peekregw(wizregs + WIZ_SnRSR)
rxrr = peekregw(wizregs + WIZ_SnRXRD)
rxwr = rxrr & WIZ_RXMASK
rxpkt = heapalloc(rxlen)
//puti(rxlen);putc(':')
if rxwr + rxlen > WIZ_RXSIZE
splitlen = WIZ_RXSIZE - rxwr
peekregs(wizdata + rxwr, rxpkt, splitlen)
peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen)
//putc('(');puti(splitlen);putc(',');puti(rxlen-splitlen);putc(')')
else
peekregs(wizdata + rxwr, rxpkt, rxlen)
fin
//puth(rxwr);putc('-');putc('>');puth(rxwr+rxlen);putln
pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen)
pokereg(wizregs + WIZ_SnCR, $40) // RECV
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,rxpkt,rxlen,wiz=>channel_recv_parm)
heaprelease(rxpkt)
fin
if sir & $02
//putc('S')
//
// Close TCP socket
//
when wiz->channel_state
is TCP_STATE_OPEN
wiz->channel_state = TCP_STATE_CLOSING
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,0,wiz=>channel_lclport,0,wiz=>channel_recv_parm)
break
is TCP_STATE_CLOSING
wiz->channel_state = TCP_STATE_CLOSED
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
break
otherwise
//putc('?')
wend
fin
if sir & $08
//putc('T')
//
// Timeout on TCP socket
//
when wiz->channel_state
is TCP_STATE_OPEN
wiz->channel_state = TCP_STATE_CLOSING
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,0,0,wiz=>channel_recv_parm)
break
is TCP_STATE_CONNECT
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,0,0,wiz=>channel_recv_parm)
is TCP_STATE_CLOSING
wiz->channel_state = TCP_STATE_CLOSED
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
break
otherwise
//putc('?')
wend
fin
//if sir & $10
//putc('W');putc('O');putc('K');puth(peekregw(wiz=>channel_regs+WIZ_SnTXWR));putln
//
// Write TCP socket OK
//
//fin
break
is WIZ_PROTO_UDP
//putc('U');putb(sir)
if sir & $04
//putc('R')
//
// Receive UDP packet
//
rxlen = peekregw(wizregs + WIZ_SnRSR)
rxrr = peekregw(wizregs + WIZ_SnRXRD)
rxwr = rxrr & WIZ_RXMASK
rxpkt = heapalloc(rxlen)
if rxwr + rxlen >= WIZ_RXSIZE
//putc('!')
splitlen = WIZ_RXSIZE - rxwr
peekregs(wizdata + rxwr, rxpkt, splitlen)
peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen)
else
peekregs(wizdata + rxwr, rxpkt, rxlen)
fin
//putc('=');putip(rxpkt);putc(' ');puti(rxlen)
//putc('/');puti(swab(rxpkt=>6))
//putc(' ');puth(rxrr);putc(' ');puth(rxwr);putln
pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen)
pokereg(wizregs + WIZ_SnCR, $40) // RECV
wiz=>channel_recv_func(rxpkt,swab(rxpkt=>4),rxpkt+8,rxlen-8,wiz=>channel_recv_parm)
heaprelease(rxpkt)
fin
break
otherwise
wend
pokereg(wiz=>channel_regs + WIZ_SnIR, sir) // Clear SnIR
ir = ir ^ (1 << i)
break
wend
wiz = wiz + t_channel
next
if ir
//
// Clear IR for now
//
pokereg(WIZ_IR, ir)
fin
fin
end
//
// Set the local IP addresses
//
def setWizIP(newIP, newSubnet, newGateway)
if newIP
localip:0 = newIP=>0; localip:2 = newIP=>2
pokeregs(WIZ_SIPR, newIP, IP4ADR_SIZE)
fin
if newSubnet
subnet:0 = newSubnet=>0; subnet:2 = newSubnet=>2
pokeregs(WIZ_SUBR, newSubnet, IP4ADR_SIZE)
fin
if newGateway
gateway:0 = newGateway=>0; gateway:2 = newGateway=>2
pokeregs(WIZ_GWR, newGateway, IP4ADR_SIZE)
fin
end
//
// Get the interface hardware address
//
def getWizHA(ha)
if ha
ha=>0 = wizMAC:0; ha=>2 = wizMAC:2; ha=>4 = wizMAC:4
fin
return MAC_SIZE
end
//
// Identify Wiznet card and initialize
//
for slot = $90 to $F0 step $10
regdata = peekio(slot)
if (regdata & $E4) == $00
pokeio(slot, $03) // Try setting auto-increment indirect I/F
if peekio(slot) == $03
saveidx = peekiow(slot + 1)
peekio(slot + 3) // Dummy read to data register should increment index
if peekiow(slot + 1) == saveidx + 1
//
// Good chance this is it
//
pokeio(slot, $80) // RESET
regidx = slot + 1
regdata = slot + 3
_pokedata.1 = regdata
_peekdata.1 = regdata
pokeio(slot, $03) // Auto-increment indirect I/F + enable ping
//
// The following looks redundant, but it sets up the peek/poke locations
// for peekreg(s)/pokereg(s)
//
pokeiow(regidx, WIZ_MR)
pokeio(regdata, $03) // Auto-increment indirect I/F + enable ping
peekio(regdata)
//
// Initialize common registers
//
pokeregs(WIZ_SHAR, @wizMAC, 6) // MAC addr
pokeregw(WIZ_RTR, 5000) // Timeout period to 500ms
pokereg(WIZ_RMSR, $55) // 2K Rx memory/channel
pokereg(WIZ_TMSR, $55) // 2K Tx memory/channel
//
// Fill channel structure
//
saveidx = @wizChannel
for slot = 0 to 3
saveidx=>channel_regs = WIZ_SREGS + (WIZ_SSIZE * slot)
saveidx=>channel_txmem = WIZ_TXMEM + (WIZ_TXSIZE * slot)
saveidx=>channel_rxmem = WIZ_RXMEM + (WIZ_RXSIZE * slot)
saveidx = saveidx + t_channel
next
//
// Fill in Net class
//
iNet:serviceIP = @wizServiceIP
iNet:openUDP = @wizOpenUDP
iNet:sendUDP = @wizSendUDP
iNet:closeUDP = @wizCloseUDP
iNet:listenTCP = @wizListenTCP
iNet:connectTCP = @wizConnectTCP
iNet:sendTCP = @wizSendTCP
iNet:closeTCP = @wizCloseTCP
iNet:setInterfaceIP = @setWizIP
iNet:getInterfaceHA = @getWizHA
iNet:setCallback = @wizSetCallback
iNet:setParam = @wizSetParam
return modkeep
fin
fin
pokeio(slot, regdata) // Restore register
fin
next
//
// Not found
//
return -1
done

View File

@ -18,12 +18,12 @@ JIT16 = rel/apple/JIT16\#FE1000
JITUNE = rel/apple/JITUNE\#FE1000
SOS = rel/apple/SOS\#FE1000
ROD = rel/apple/ROD\#FE1000
COPY = rel/COPY\#FE1000
DEL = rel/DEL\#FE1000
REN = rel/REN\#FE1000
CAT = rel/CAT\#FE1000
NEWDIR = rel/NEWDIR\#FE1000
TYPE = rel/TYPE\#FE1000
COPY = rel/apple/COPY\#FE1000
DEL = rel/apple/DEL\#FE1000
REN = rel/apple/REN\#FE1000
CAT = rel/apple/CAT\#FE1000
NEWDIR = rel/apple/NEWDIR\#FE1000
TYPE = rel/apple/TYPE\#FE1000
SIEVE = rel/SIEVE\#FE1000
PRIMEGAP = rel/PRIMEGAP\#FE1000
ARGS = rel/ARGS\#FE1000
@ -118,7 +118,9 @@ clean:
-rm libsrc/*.o libsrc/*~ libsrc/*.a
-rm libsrc/apple/*.o libsrc/apple/*~ libsrc/apple/*.a
-rm libsrc/c64/*.o libsrc/c64/*~ libsrc/c64/*.a
-rm libsrc/*.o libsrc/*~ libsrc/*.a
-rm utilsrc/*.o utilsrc/*~ utilsrc/*.a
-rm utilsrc/apple/*.o utilsrc/apple/*~ utilsrc/apple/*.a
-rm utilsrc/c64/*.o utilsrc/c64/*~ utilsrc/c64/*.a
#
# PLASMA compiler: plasm
@ -307,9 +309,9 @@ $(HTTPD): samplesrc/httpd.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < samplesrc/httpd.pla > samplesrc/httpd.a
acme --setpc 4094 -o $(HTTPD) samplesrc/httpd.a
$(TFTPD): samplesrc/tftpd.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < samplesrc/tftpd.pla > samplesrc/tftpd.a
acme --setpc 4094 -o $(TFTPD) samplesrc/tftpd.a
$(TFTPD): utilsrc/tftpd.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < utilsrc/tftpd.pla > utilsrc/tftpd.a
acme --setpc 4094 -o $(TFTPD) utilsrc/tftpd.a
$(MOUSE): libsrc/apple/mouse.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < libsrc/apple/mouse.pla > libsrc/apple/mouse.a
@ -411,37 +413,37 @@ $(HGRTEST): samplesrc/hgrtest.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < samplesrc/hgrtest.pla > samplesrc/hgrtest.a
acme --setpc 4094 -o $(HGRTEST) samplesrc/hgrtest.a
$(MON): samplesrc/mon.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < samplesrc/mon.pla > samplesrc/mon.a
acme --setpc 4094 -o $(MON) samplesrc/mon.a
$(MON): utilsrc/apple/mon.pla $(PLVM02) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/mon.pla > utilsrc/apple/mon.a
acme --setpc 4094 -o $(MON) utilsrc/apple/mon.a
$(COPY): libsrc/copy.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/copy.pla > libsrc/copy.a
acme --setpc 4094 -o $(COPY) libsrc/copy.a
$(COPY): utilsrc/apple/copy.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/copy.pla > utilsrc/apple/copy.a
acme --setpc 4094 -o $(COPY) utilsrc/apple/copy.a
$(DEL): libsrc/del.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/del.pla > libsrc/del.a
acme --setpc 4094 -o $(DEL) libsrc/del.a
$(DEL): utilsrc/apple/del.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/del.pla > utilsrc/apple/del.a
acme --setpc 4094 -o $(DEL) utilsrc/apple/del.a
$(REN): libsrc/ren.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/ren.pla > libsrc/ren.a
acme --setpc 4094 -o $(REN) libsrc/ren.a
$(REN): utilsrc/apple/ren.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/ren.pla > utilsrc/apple/ren.a
acme --setpc 4094 -o $(REN) utilsrc/apple/ren.a
$(CAT): libsrc/cat.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/cat.pla > libsrc/cat.a
acme --setpc 4094 -o $(CAT) libsrc/cat.a
$(CAT): utilsrc/apple/cat.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/cat.pla > utilsrc/apple/cat.a
acme --setpc 4094 -o $(CAT) utilsrc/apple/cat.a
$(NEWDIR): libsrc/newdir.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/newdir.pla > libsrc/newdir.a
acme --setpc 4094 -o $(NEWDIR) libsrc/newdir.a
$(NEWDIR): utilsrc/apple/newdir.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/newdir.pla > utilsrc/apple/newdir.a
acme --setpc 4094 -o $(NEWDIR) utilsrc/apple/newdir.a
$(TYPE): libsrc/type.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/type.pla > libsrc/type.a
acme --setpc 4094 -o $(TYPE) libsrc/type.a
$(TYPE): utilsrc/apple/type.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/type.pla > utilsrc/apple/type.a
acme --setpc 4094 -o $(TYPE) utilsrc/apple/type.a
$(SOS): libsrc/apple/sos.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < libsrc/apple/sos.pla > libsrc/apple/sos.a
acme --setpc 4094 -o $(SOS) libsrc/apple/sos.a
$(SOS): utilsrc/apple/sos.pla $(PLVM03) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/sos.pla > utilsrc/apple/sos.a
acme --setpc 4094 -o $(SOS) utilsrc/apple/sos.a
$(JIT): libsrc/apple/jit.pla libsrc/jitcore.pla $(PLVMJIT) $(PLASM)
./$(PLASM) -AMOW < libsrc/apple/jit.pla > libsrc/apple/jit.a
@ -451,8 +453,8 @@ $(JIT16): libsrc/apple/jit16.pla libsrc/jit16core.pla $(PLVMJIT) $(PLASM)
./$(PLASM) -AMOW < libsrc/apple/jit16.pla > libsrc/apple/jit16.a
acme --setpc 4094 -o $(JIT16) libsrc/apple/jit16.a
$(JITUNE): libsrc/apple/jitune.pla $(PLVMJIT) $(PLASM)
./$(PLASM) -AMOW < libsrc/apple/jitune.pla > libsrc/apple/jitune.a
acme --setpc 4094 -o $(JITUNE) libsrc/apple/jitune.a
$(JITUNE): utilsrc/apple/jitune.pla $(PLVMJIT) $(PLASM)
./$(PLASM) -AMOW < utilsrc/apple/jitune.pla > utilsrc/apple/jitune.a
acme --setpc 4094 -o $(JITUNE) utilsrc/apple/jitune.a

View File

@ -12,12 +12,12 @@ cp rel/apple/CONIO#FE1000 prodos/sys/CONIO.REL
cp rel/apple/LINESPANS#FE1000 prodos/sys/LINESPANS.REL
cp rel/apple/GRLIB#FE1000 prodos/sys/GRLIB.REL
cp rel/apple/DGRLIB#FE1000 prodos/sys/DGRLIB.REL
cp rel/COPY#FE1000 prodos/sys/COPY.REL
cp rel/DEL#FE1000 prodos/sys/DEL.REL
cp rel/REN#FE1000 prodos/sys/REN.REL
cp rel/CAT#FE1000 prodos/sys/CAT.REL
cp rel/NEWDIR#FE1000 prodos/sys/NEWDIR.REL
cp rel/TYPE#FE1000 prodos/sys/TYPE.REL
cp rel/apple/COPY#FE1000 prodos/sys/COPY.REL
cp rel/apple/DEL#FE1000 prodos/sys/DEL.REL
cp rel/apple/REN#FE1000 prodos/sys/REN.REL
cp rel/apple/CAT#FE1000 prodos/sys/CAT.REL
cp rel/apple/NEWDIR#FE1000 prodos/sys/NEWDIR.REL
cp rel/apple/TYPE#FE1000 prodos/sys/TYPE.REL
cp rel/ARGS#FE1000 prodos/sys/ARGS.REL
cp rel/ED#FE1000 prodos/sys/ED.REL
cp rel/FIBER#FE1000 prodos/sys/FIBER.REL
@ -90,7 +90,6 @@ cp rel/apple/GFXDEMO#FE1000 prodos/demos/apple3/GFXDEMO.REL
cp samplesrc/APPLE3.PIX#060000 prodos/demos/apple3/APPLE3.PIX.BIN
mkdir prodos/demos/net
cp rel/TFTPD#FE1000 prodos/demos/net/TFTPD.REL
cp rel/HTTPD#FE1000 prodos/demos/net/HTTPD.REL
cp samplesrc/index.html prodos/demos/net/INDEX.HTML.TXT
@ -111,7 +110,6 @@ cp samplesrc/dgrtest.pla prodos/bld/samples/DGRTEST.PLA.TXT
cp samplesrc/hgrtest.pla prodos/bld/samples/HGRTEST.PLA.TXT
cp samplesrc/fibertest.pla prodos/bld/samples/FIBERTEST.PLA.TXT
cp samplesrc/mousetest.pla prodos/bld/samples/MOUSETEST.PLA.TXT
cp samplesrc/mon.pla prodos/bld/samples/MON.PLA.TXT
cp samplesrc/memtest.pla prodos/bld/samples/MEMTEST.PLA.TXT
cp samplesrc/rod.pla prodos/bld/samples/ROD.PLA.TXT
cp samplesrc/sieve.pla prodos/bld/samples/SIEVE.PLA.TXT

View File

@ -29,6 +29,5 @@ echo "DEMOS/SDUTILS/FATREADDSK"; atftp $1 --put -l rel/apple/FATREADDSK#FE1000
echo "DEMOS/SDUTILS/FATWRITEDSK"; atftp $1 --put -l rel/apple/FATWRITEDSK#FE1000 -r $2/DEMOS/SDUTILS/FATWRITEDSK#FE1000
# Net demos
echo "DEMOS/NET/TFTPD"; atftp $1 --put -l rel/TFTPD#FE1000 -r $2/DEMOS/NET/TFTPD#FE1000
echo "DEMOS/NET/HTTPD"; atftp $1 --put -l rel/HTTPD#FE1000 -r $2/DEMOS/NET/HTTPD#FE1000
atftp $1 --put -l samplesrc/index.html -r $2/DEMOS/NET/INDEX.HTML#040000

View File

@ -19,6 +19,7 @@ echo "SYS/FIBER"; atftp $1 --put -l rel/FIBER#FE1000 -r $2/SYS/FIBER#FE1000
echo "SYS/INET"; atftp $1 --put -l rel/INET#FE1000 -r $2/SYS/INET#FE1000
echo "SYS/LONGJUMP"; atftp $1 --put -l rel/LONGJMP#FE1000 -r $2/SYS/LONGJMP#FE1000
echo "SYS/MEMMGR"; atftp $1 --put -l rel/MEMMGR#FE1000 -r $2/SYS/MEMMGR#FE1000
echo "SYS/LZ4"; atftp $1 --put -l rel/LZ4#FE1000 -r $2/SYS/LZ4#FE1000
echo "SYS/CONIO"; atftp $1 --put -l rel/apple/CONIO#FE1000 -r $2/SYS/CONIO#FE1000
echo "SYS/LINESPANS"; atftp $1 --put -l rel/apple/LINESPANS#FE1000 -r $2/SYS/LINESPANS#FE1000
echo "SYS/GRLIB"; atftp $1 --put -l rel/apple/GRLIB#FE1000 -r $2/SYS/GRLIB#FE1000

View File

@ -2,13 +2,12 @@
# Core utilities
echo "SYS/ED"; atftp $1 --put -l rel/ED#FE1000 -r $2/SYS/ED#FE1000
echo "SYS/COPY"; atftp $1 --put -l rel/COPY#FE1000 -r $2/SYS/COPY#FE1000
echo "SYS/DEL"; atftp $1 --put -l rel/DEL#FE1000 -r $2/SYS/DEL#FE1000
echo "SYS/REN"; atftp $1 --put -l rel/REN#FE1000 -r $2/SYS/REN#FE1000
echo "SYS/CAT"; atftp $1 --put -l rel/CAT#FE1000 -r $2/SYS/CAT#FE1000
echo "SYS/NEWDIR"; atftp $1 --put -l rel/NEWDIR#FE1000 -r $2/SYS/NEWDIR#FE1000
echo "SYS/TYPE"; atftp $1 --put -l rel/TYPE#FE1000 -r $2/SYS/TYPE#FE1000
echo "SYS/TFTPD"; atftp $1 --put -l rel/TFTPD#FE1000 -r $2/SYS/TFTPD#FE1000
echo "SYS/LZ4"; atftp $1 --put -l rel/LZ4#FE1000 -r $2/SYS/LZ4#FE1000
echo "SYS/COPY"; atftp $1 --put -l rel/apple/COPY#FE1000 -r $2/SYS/COPY#FE1000
echo "SYS/DEL"; atftp $1 --put -l rel/apple/DEL#FE1000 -r $2/SYS/DEL#FE1000
echo "SYS/REN"; atftp $1 --put -l rel/apple/REN#FE1000 -r $2/SYS/REN#FE1000
echo "SYS/CAT"; atftp $1 --put -l rel/apple/CAT#FE1000 -r $2/SYS/CAT#FE1000
echo "SYS/NEWDIR"; atftp $1 --put -l rel/apple/NEWDIR#FE1000 -r $2/SYS/NEWDIR#FE1000
echo "SYS/TYPE"; atftp $1 --put -l rel/apple/TYPE#FE1000 -r $2/SYS/TYPE#FE1000
echo "SYS/MON"; atftp $1 --put -l rel/apple/MON#FE1000 -r $2/SYS/MON#FE1000
echo "SYS/SOS"; atftp $1 --put -l rel/apple/SOS#FE1000 -r $2/SYS/SOS#FE1000