Bringing WiFi to the Cidco Mailstation
1; vim:syntax=z8a:ts=8
2;
3; WiFiStation
4; Parallel port loader
5;
6; Copyright (c) 2019-2021 joshua stein <jcs@jcs.org>
7;
8; Permission to use, copy, modify, and distribute this software for any
9; purpose with or without fee is hereby granted, provided that the above
10; copyright notice and this permission notice appear in all copies.
11;
12; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19;
20
21 .module loader
22
23 .area _DATA
24 .area _HEADER (ABS)
25 .org 0x4000 ; we're running from dataflash
26
27 jp main
28
29 .dw (icons)
30 .dw (caption)
31 .dw (dunno)
32dunno:
33 .db #0
34 .dw #0
35 .dw #0
36caption:
37 .dw #0x0001
38 .dw (endcap - caption - 6)
39 .dw #0x0006
40 .ascii "WSLoader" ; the icon caption
41endcap:
42
43icons:
44 .dw #0 ; size icon0
45 .dw (icon0 - icons) ; offset to icon0
46 .dw #0 ; size icon1
47 .dw (icon1 - icons) ; offset to icon1 (0x00b5)
48icon0:
49 .dw #0 ; icon width
50 .db #0 ; icon height
51icon1:
52 .dw #0 ; icon width
53 .db #0 ; icon height
54
55 ; actual loader code
56
57 .equ CONTROL_DIR, #0x0a
58 .equ CONTROL_DIR_OUT, #0xff
59 .equ CONTROL_DIR_IN, #0
60
61 .equ CONTROL_PORT, #0x9
62 .equ CONTROL_STROBE, #(1 << 0)
63 .equ CONTROL_LINEFEED, #(1 << 1)
64 .equ CONTROL_INIT, #(1 << 2)
65 .equ CONTROL_SELECT, #(1 << 3)
66
67 .equ DATA_DIR, #0x2c
68 .equ DATA_DIR_OUT, #0xff
69 .equ DATA_DIR_IN, #0
70 .equ DATA_PORT, #0x2d
71
72 .equ STATUS_PORT, #0x21
73 .equ STATUS_BUSY, #(1 << 7)
74 .equ STATUS_ACK, #(1 << 6)
75
76main:
77 ; lower control lines
78 ld a, #CONTROL_DIR_OUT
79 out (#CONTROL_DIR), a
80 xor a
81 out (#CONTROL_PORT), a
82 ld a, #DATA_DIR_IN
83 out (#DATA_DIR), a ; we're going to be receiving
84
85 ; first read the low and high bytes of the length we're going to read
86 call lptrecv_blocking
87 ld l, a
88 call lptrecv_blocking
89 ld h, a ; hl = bytes to download
90
91 ld a, #1 ; put ram page 1 into slot8000
92 out (#0x08), a
93 out (#0x07), a
94
95 ld bc, #0x8000 ; bc = ram addr
96getbyte:
97 call lptrecv_blocking
98 ld (bc), a
99 inc bc ; addr++
100 dec hl ; bytes--
101 xor a
102 or h
103 jr nz, getbyte ; if h != 0, keep reading
104 xor a
105 or l
106 jr nz, getbyte ; if l != 0, keep going
107 jp 0x8000 ; else, jump to new code in ram
108
109
110; at idle, lower all control lines
111;
112; writer: reader:
113; raise strobe
114; see high strobe as high busy
115; raise linefeed
116; see high linefeed as high ack
117; write all data pins
118; lower strobe
119; see low strobe as low busy
120; read data
121; lower linefeed
122; see lower linefeed as high ack
123
124; return byte in a
125lptrecv_blocking:
126 push hl
127wait_for_busy:
128 in a, (#STATUS_PORT)
129 and #STATUS_BUSY ; is busy high? (strobe on writer)
130 jr z, wait_for_busy ; no, wait until it is
131 and #STATUS_ACK ; but is ack high too? that's bogus
132 jr nz, wait_for_busy
133 ld a, #CONTROL_LINEFEED ; raise linefeed
134 out (#CONTROL_PORT), a
135wait_for_busy_ack:
136 in a, (#STATUS_PORT)
137 and #STATUS_BUSY ; is busy high?
138 jr nz, wait_for_busy_ack ; no, wait
139read_data:
140 in a, (#DATA_PORT)
141 ld l, a
142lower_lf:
143 xor a
144 out (#CONTROL_PORT), a ; lower linefeed
145 ld a, l ; return read byte in a
146 pop hl
147 ret