-
Notifications
You must be signed in to change notification settings - Fork 1
/
gotoHost.b09
86 lines (79 loc) · 2.49 KB
/
gotoHost.b09
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
PROCEDURE gotoHost
(* 06/23/22
TYPE bookmarks=server,page,title:STRING[144]
DIM hostname,lineout(4):STRING[144]
DIM crlf:STRING[2]
DIM hostaddr(4):INTEGER
DIM int1,fn1,fn2,waddr,wbase,wend,wmask,wsize,wptr:INTEGER
DIM debug:BOOLEAN
PARAM bookmark:bookmarks
(* FIXME replace fixed 2K buffer size
wbase:=$4000 \wmask:=$07FF \wend:=wbase+wmask
debug:=FALSE
crlf=CHR$(13)+CHR$(10)
(* _____ set addr in WizNet
hostname:=bookmark.server
RUN getdns(hostname,hostaddr)
IF debug=TRUE THEN
PRINT "DB hostname "; hostname; "addr ";
ENDIF
POKE $FF69,$04 \ POKE $FF6A,$0C
FOR fn1=1 TO 4
IF debug=TRUE THEN PRINT hostaddr(fn1); "."; \ ENDIF
POKE $FF6B,hostaddr(fn1)
NEXT fn1
POKE $FF6B,0 \ POKE $FF6B,80
(* random local port * DB 8/26/21
POKE $FF69,$04 \ POKE $FF6A,$04
POKE $FF6B,$80 \ POKE $FF6B,RND($FF)
(* _____open socket, fn until status OK or fatal error
POKE $FF69,$04 \ POKE $FF6A,$01 \ POKE $FF6B,$01
POKE $FF69,$04 \ POKE $FF6A,$03 \int1:=PEEK($FF6B)
IF int1<>$13 THEN \(* socket not open tcp mode
PRINT "FATAL: local socket didn't initialize. BREAK to exit"
INPUT int1
GOTO 5000
ENDIF
REPEAT
POKE $FF69,$04 \ POKE $FF6A,$01 \ POKE $FF6B,$04
POKE $FF69,$04 \ POKE $FF6A,$03 \int1:=PEEK($FF6B)
IF int1=0 THEN \(* socket was closed
PRINT "ERROR: remote server closed connection. Reload page."
INPUT int1
GOTO 5000
ENDIF
UNTIL int1=$17 \(* connected
IF debug=TRUE THEN PRINT \ PRINT "Socket open" \ ENDIF
lineout(1):="GET "+bookmark.page+" HTTP/1.1"
lineout(2):="Host: "+bookmark.server
lineout(3):="Accept-Language: en"
lineout(4):=""
wsize:=LEN(lineout(1))+LEN(lineout(2))+LEN(lineout(3))+8
100
(* _____ wait until SN_CR has enough room for send
(* FIXME using this loop as IRQ dodge FIXME
REPEAT
POKE $FF69,$04 \ POKE $FF6A,$20
int1:=PEEK($FF6B)*256+PEEK($FF6B)
UNTIL int1>wsize
POKE $FF69,$04 \ POKE $FF6A,$22
wptr:=PEEK($FF6B)*256+PEEK($FF6B)
int1:=INT(wptr/256) \int2:=wptr-256*int1
int3:=INT(wmask/256) \int4:=wmask-256*int3
int1:=LAND(int1,int3) \int2:=LAND(int2,int4)
waddr:=int1*256+int2+wbase
(* _____ blast the request
segment:=wsize
int1:=INT(waddr/256) \int2:=waddr-256*int1
POKE $FF69,int1 \ POKE $FF6A,int2
FOR fn1=1 TO 4
FOR fn2=1 TO LEN(lineout(fn1))
int1:=ASC(MID$(lineout(fn1),fn2,1))
POKE $FF6B,int1
IF debug=TRUE THEN \ PRINT CHR$(int1); \ ENDIF
NEXT fn2
POKE $FF6B,$0D \ POKE $FF6B,$0A
IF debug=TRUE THEN \ PRINT \ ENDIF
NEXT fn1
POKE $FF69,$04 \ POKE $FF6A,$01 \ POKE $FF6B,$20
5000 END