Block 0

admtek comet an983b macro
align here 7 and 3 or drop if nop align ; then ; forth
array pop 2/ 2/ ;
us n 550 3 / * for next ;
r n-a db000000 + 2/ 2/ ;
rom a-n a4 + r @ ;
3rom nnn 4 rom 0 rom dup 16 for 2/ next swap ;
reset 1 0 r ! 1000 us ;
frag 0 , 2000000 , 0 , here 4 + , ;
tx align array frag frag frag frag
n tx 1 + ;
a tx 2 + ; f 8
fr! f @ + ! ;
first an 0 f ! 20000000 or
send an 1000000 or n fr! a fr! 80000000 tx fr! 4 f +! ;
last an 42000000 or send 1 us -1 8 r ! ;

Block 1

move sdn move n bytes from source to destination. register 1 is used, 6 and 7 are saved
array -a returns word-aligned address in dictionary
us n delay n microseconds. edit cpu clock rate
r n-a word address of register. edit base address from north pci device configuration
rom a-n fetch 2 bytes of ethernet id
3rom nnn 3 byte-pairs of id. 54, 32 and 10
reset controller
tx -a transmit buffer. 1536 bytes. fragments must be assembled for transmission
rx -b receive buffer. 8k+16 bytes
n -a tx status/length. writing starts transmission
send an fragment into transmit buffer
first an fragment. wait till buffer empty
last an fragment. start transmission
init ialize controller. set tx/rx address/on and perfect match

Block 2

receive rxp 273222
rx align array 80000000 , 1000600 , 2000 block 4 * dup , here 4 + , 80000000 , 1000600 , 600 + , rx 4 * , rx rxp !
wait -a dup @ 0 or drop -if wait ; then 2 + @ ;
init reset rx 2 * 2* 18 r receive ! 1 us tx 2 * 2* 20 r transmit ! 1 us 2002 start 30 r ! 1 us 10040 38 r ! sti -1 28 r ! ;
/int rxp @ 80000000 over ! 3 + @ 2/ 2/ rxp ! -1 28 r ! ;
rcvd rxp @ wait ;
reg dup r @ h. space 2 h.n cr ;
regs b8 reg a0 reg 98 reg 90 reg 78 reg 60 reg 48 10 for dup reg -8 + next drop ;
ok show red screen text regs keyboard ;
rx1 2000 block dump ;
rx2 2000 block 180 + dump ; ok

Block 3

wait -b till packet received
reg a display register and address
regs display interesting registers
ok diagnostic display

Block 4

ethernet empty 124 load
empty empt logo cli ; macro
w 66 1, ;
w@ 8b 2, ;
w! 289 2, drop ;
*byte c486 2, ; forth 126 load 128 load
n@ w w@ ffff and *byte ;
2! a! w w! ;
n! a! *byte w w! ;
n, *byte 2, ;
string pop ;
packet string -1 dup , 2, 3rom 2, 2, 2, 0 n,
length n packet 12 + n! ;
broadcast -1 dup dup packet nop
3! swap over 2! 2 + swap over 2! 2 + 2! ;
ethernet n length packet 14 first ;
+ethernet -a rcvd 14 + ; 132 load 134 load 136 load 138 load 144 load 2a interrupt
serve forth receive /int 8clear /forth i; init ok

Block 5

empty redefined to disable interrupts
w 16-bit prefix
w@ b-n fetch 16-bits from byte address
w! nb store 16-bits
*byte n-n swap bytes 0 and 1
n@ b-n fetch 16-bit network-ordered number
2! nb store 16-bit number
n! nb store 16-bit number in network order
n, n compile 16-bit number in network order
string -b returns byte address
packet -b ethernet packet header
dest -b destination field in packet
src -b source field
length n store length into packet
3! nnnb store 3-word mac
ethernet n send header with type/length
@ethernet -b return payload address of received packet

Block 6

arp for a single correspondent macro
move sdn c189 2, drop c78957 3, drop c68956 3, a4f3 2, 5f5e 2, drop ; forth
. n 1, ;
message string 1 n, 800 n, 6 . 4 . 1 n,
me 3rom 2, 2, 2, ip 0 . 0 . 0 . 0 .
to 0 0 0 2, 2, 2, ip 0 . 0 . 0 . 0 .
sender 8 + ;
target 18 + ;
dir 6 + ;
ip 6 + w@ ;
ar n message dir n! 806 arp ethernet message 28 last ;
arp cli broadcast 1 ar sti ;
-arp b-b dup -2 + n@ 806 or drop if ; then pop drop
me? dup target ip message sender ip or drop if ; then dup sender packet 6 move
query? dup dir n@ 1 or drop if ; then sender message target 10 move 2 ar ;

Block 7

set ip addresses with edit. normal order, net bytes first
. n compile byte. resembles url punctuation
message -b 28-byte string
me comment marking my mac/ip address
to comment marking correspondent
sender
target
dir -b fields in either message or received message
ip b-n fetch ip address
ar n send query 1, or reply 4
arp broadcast query
-arp b-b return if not arp. otherwise process and skip out.
me? b return if broadcast not for me. save sender only in packet
query? b if a request, reply

Block 8

ipv4
header align string 4500 n, 0 n, 1 n, 0 n, ff11 n, 0 n, 0 , 0 ,
length n header 2 + n! ;
+id header 4 + dup n@ 1 + swap n! ;
-sum for dup n@ u+ 2 + next drop dup 10000 / + - ;
sum header 10 + n! ;
checksum 0 sum 0 header 10 -sum sum ;
source header 12 + ;
destination header 16 + ;
ip n-n dup 20 + 800 ethernet length +id checksum header 20 send ;
+ip dup -2 + n@ 800 or drop if pop ; then 20 + ;

Block 9

set ip addresses with edit. normal order, net bytes first
header -a 40-byte ipv6 header
length n store 2-byte length in header
dest -a 4-byte destination ip address
src -a source ip
ip n send ip header embedded in ethernet packet
+ip b-b skip out if not ip. otherwise return payload address

Block 10

udp
b@ b-n w@ ff and ;
header string 0 n, 0 n, 8 n, 0 n, 0 n,
length n 8 + header 4 + n! ;
port header 2 + n! ;
udp n dup 8 + ip length ;
+udp b-b dup -11 + b@ 17 or drop if pop ; then 8 + ;

Block 11

b@ b-n fetch byte
header -a 8-byte udp header
length n store length in header
udp n send ip header for n-byte packet
+udp b-b skip out if not udp. otherwise return payload address

Block 12

dhcp
fill for 0 , next ;
xid 3rom + + ;
msg align string 60101 , xid , 5 fill 3rom 2, 2, 2, 0 2, 50 fill 6382 n, 5363 n, 53 . 1 . 1 . 55 . 1 . 3 . ff 2, 0 , 50 . 4 . 0 , ff .
eq over over or drop ;
skip over 1 + b@ 2 + u+ ;
find over b@ if eq if ff or if drop skip find ; then then drop drop 2 + ; then drop 1 u+ find ;
nul drop ;
4! a! w! ;
yiaddr 16 + w@ ;
offer 54 find w@ msg 248 + 4! yiaddr msg 254 + 4!
request 259 3604 103 msg 241 + n!
bootr msg 246 + n! broadcast -1 destination 4! 67 port udp header 8 send msg swap last ;
discover 247 ff00 bootr ; 140 load

Block 13


Block 14

dhcp
ack 3 find w@ message target 6 + 4! yiaddr dup message sender 6 + 4! source 4! 1 ar ;
-dhcp dup -8 + n@ 67 or drop if ; then dup 4 + w@ xid or drop if ; then dup 240 +
type dup 53 find w@ 7 and jump nul nul offer nul nul ack nul nul

Block 15


Block 16

icmp
header string 800 n, 0 n, 0 ,
icmp dup -34 + b@ 1 or drop if ; then ;
ping 8 ip header 8 last ;

Block 17


Block 18

blocks to/from server
payload n-bn header 8 + n! header 10 ;
+put nn 1026 udp over payload send + block 2* 2* 1024 last ;
it b dup 2 + swap n@ 300 + block 2* 2* 1024 move ;
-got b-b dup -4 + n@ 2 8 + or drop if it pop ; then ;
receive +ethernet -arp +ip +udp -dhcp -got
+get b n@ 300 +put ;
... interrupt-protect words that transmit
get n cli 2 udp payload last sti ;
put n cli 0 +put sti ;
archive 161 for i put 1000 us -next ;

Block 19

client can get or put blocks to server
payload n-bn 2 bytes were appended to udp header for block number
+put nn send block number. append block as last fragment. packet length distinguishes two messages
it b move 1024 bytes from packet to offset block
-got b-b if a 2-byte message, return. otherwise move block to archive - 300+ - and skip out
receive check and decode received packet. +test returns if true, -test returns if false. otherwise they pop - skip-out - return from receive. resulting stack need not be empty, since /forth will restore pre-interrupt stack. pop must be in a word called by receive, it cant be nested
+get b send requested block from archive
get n send block number to request. interrupt disabled lest reply interfer
put n send block
archive send blocks 0-161 - 9 cylinders icmp dhcp
Hosted by www.Geocities.ws

1