Terminal program for MailStation devices

wifi: Add WiFiStation source, make it the default

+193 -3
+4 -1
Makefile
··· 73 73 settings.rel: settings.s 74 74 $(ASZ80) -o ${.TARGET} ${ADDRS_INC} $> 75 75 76 + wifi.rel: wifi.s 77 + $(ASZ80) -o ${.TARGET} ${ADDRS_INC} $> 78 + 76 79 #csi.rel: csi.s 77 80 # $(ASZ80) -o ${.TARGET} $> 78 81 csi.rel: csi.c ··· 95 98 ruby $(SRCDIR)/tools/hexfont2inc.rb $> > $(SRCDIR)/${.TARGET} 96 99 97 100 msterm.ihx: crt0.rel isr.rel putchar.rel getchar.rel lpt.rel modem.rel \ 98 - msterm.rel mslib.rel csi.rel settings.rel 101 + msterm.rel mslib.rel csi.rel settings.rel wifi.rel 99 102 $(SDCC) --no-std-crt0 \ 100 103 --code-loc `ruby -e 'print ${BASE_ADDR} + ${CODE_OFF}'` \ 101 104 --data-loc `ruby -e 'print ${BASE_ADDR} + 0x4000 - ${DATA_SIZE}'` \
+6
mailstation.h
··· 185 185 extern void settings_read(void); 186 186 extern void settings_write(void); 187 187 188 + 189 + /* wifi.s */ 190 + void wifi_init(void); 191 + extern int wifi_write(char); 192 + extern int wifi_read(void); 193 + 188 194 #endif
+17 -2
msterm.c
··· 40 40 SOURCE_MODEM, 41 41 SOURCE_LPT, 42 42 SOURCE_ECHO, 43 + SOURCE_WIFI, 43 44 }; 44 45 unsigned char source; 45 46 ··· 70 71 restart: 71 72 lastkey = 0; 72 73 esc = 0; 73 - source = SOURCE_MODEM; 74 + source = SOURCE_WIFI; 74 75 putchar_sgr = 0; 75 76 in_csi = 0; 76 77 csibuflen = 0; ··· 99 100 100 101 printf(" v%u\n\n", msTERM_version); 101 102 102 - if (source == SOURCE_MODEM) { 103 + switch (source) { 104 + case SOURCE_MODEM: 103 105 modem_init(); 104 106 105 107 /* Restore factory configuration 0 */ ··· 117 119 obuf_queue("L0"); 118 120 /* Enable transparent XON/XOFF flow control */ 119 121 obuf_queue("&K5\r"); 122 + break; 123 + case SOURCE_WIFI: 124 + wifi_init(); 125 + obuf_queue("AT\r\n"); 126 + break; 120 127 } 121 128 122 129 for (;;) { ··· 133 140 if (b <= 0xff) 134 141 process_input(b & 0xff); 135 142 break; 143 + case SOURCE_WIFI: 144 + b = wifi_read(); 145 + if (b != -1) 146 + process_input(b & 0xff); 147 + break; 136 148 } 137 149 138 150 if (old_obuf_pos != obuf_pos) { ··· 147 159 break; 148 160 case SOURCE_ECHO: 149 161 putchar(obuf[old_obuf_pos++]); 162 + break; 163 + case SOURCE_WIFI: 164 + wifi_write(obuf[old_obuf_pos++]); 150 165 break; 151 166 } 152 167 }
+166
wifi.s
··· 1 + ; vim:syntax=z8a:ts=8 2 + ; 3 + ; msTERM 4 + ; WiFiStation parallel port routines 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 wifi 22 + 23 + .include "mailstation.inc" 24 + 25 + .area _CODE 26 + 27 + .equ CONTROL_DIR, #0x0a 28 + .equ CONTROL_DIR_OUT, #0xff 29 + .equ CONTROL_DIR_IN, #0 30 + 31 + .equ CONTROL_PORT, #0x9 32 + .equ CONTROL_STROBE_BIT, #0 33 + .equ CONTROL_STROBE, #(1 << CONTROL_STROBE_BIT) 34 + .equ CONTROL_LINEFEED_BIT, #1 35 + .equ CONTROL_LINEFEED, #(1 << CONTROL_LINEFEED_BIT) 36 + .equ CONTROL_INIT, #(1 << 2) 37 + .equ CONTROL_SELECT, #(1 << 3) 38 + 39 + .equ DATA_DIR, #0x2c 40 + .equ DATA_DIR_OUT, #0xff 41 + .equ DATA_DIR_IN, #0 42 + .equ DATA_PORT, #0x2d 43 + 44 + .equ STATUS_PORT, #0x21 45 + .equ STATUS_BUSY, #(1 << 7) 46 + .equ STATUS_ACK, #(1 << 6) 47 + .equ STATUS_PAPEROUT, #(1 << 5) 48 + 49 + ; void wifi_init(void); 50 + _wifi_init:: 51 + ; lower control lines 52 + ld a, #CONTROL_DIR_OUT 53 + out (#CONTROL_DIR), a 54 + xor a 55 + out (#CONTROL_PORT), a 56 + ret 57 + 58 + ; at idle, lower all control lines 59 + ; writer: reader: 60 + ; raise strobe 61 + ; see high strobe as high busy 62 + ; raise linefeed 63 + ; see high linefeed as high ack 64 + ; write all data pins 65 + ; lower strobe 66 + ; see low strobe as low busy 67 + ; read data 68 + ; lower linefeed 69 + ; see lower linefeed as high ack 70 + 71 + ; int wifi_write(char); -1 on error, 0 on success 72 + _wifi_write:: 73 + push ix 74 + ld ix, #0 75 + add ix, sp 76 + push bc 77 + push de 78 + ld c, 4(ix) ; char to send 79 + ld a, #DATA_DIR_OUT 80 + out (#DATA_DIR), a ; we're sending out 81 + ld a, #CONTROL_STROBE 82 + out (#CONTROL_PORT), a ; raise strobe 83 + ld de, #0xffff 84 + wait_for_ack: 85 + in a, (#STATUS_PORT) 86 + and #STATUS_ACK ; is ack high? 87 + jr nz, got_ack ; yes, break 88 + dec de ; no, de-- 89 + ld a, d 90 + cp #0 91 + jr nz, wait_for_ack 92 + ld a, e 93 + cp #0 94 + jr nz, wait_for_ack 95 + jr abort_send ; de == 0, fail 96 + got_ack: 97 + ld a, c 98 + out (#DATA_PORT), a ; write data 99 + xor a 100 + out (#CONTROL_PORT), a ; lower strobe 101 + ld de, #0xffff 102 + wait_for_final_ack: 103 + in a, (#STATUS_PORT) 104 + and #STATUS_ACK ; is ack low? 105 + jr z, got_final_ack ; yes, break 106 + dec de ; no, de-- 107 + ld a, d 108 + cp #0 109 + jr nz, wait_for_final_ack 110 + ld a, e 111 + cp #0 112 + jr nz, wait_for_final_ack 113 + got_final_ack: 114 + pop de 115 + pop bc 116 + pop ix 117 + ld hl, #0 ; return 0 118 + ret 119 + abort_send: 120 + xor a 121 + out (#CONTROL_PORT), a ; lower strobe 122 + pop de 123 + pop bc 124 + pop ix 125 + ld hl, #-1 ; return -1 126 + ret 127 + 128 + 129 + ; int wifi_read(void); -1 on nothing read, >= 0 on success returning char 130 + _wifi_read:: 131 + push ix 132 + ld ix, #0 133 + add ix, sp 134 + push de 135 + ld hl, #-1 ; return -1 unless we read something 136 + in a, (#STATUS_PORT) 137 + and #STATUS_BUSY ; is busy high? 138 + jr z, recv_done ; no, bail 139 + ld a, #DATA_DIR_IN 140 + out (#DATA_DIR), a ; we're reading in 141 + ld a, #CONTROL_LINEFEED ; raise linefeed 142 + out (#CONTROL_PORT), a 143 + ld de, #0xffff 144 + wait_for_busy_ack: 145 + in a, (#STATUS_PORT) 146 + and #STATUS_BUSY ; is busy high? 147 + jr z, read_data ; no, break 148 + dec de ; no, de-- 149 + ld a, d 150 + cp #0 151 + jr nz, wait_for_busy_ack 152 + ld a, e 153 + cp #0 154 + jr nz, wait_for_busy_ack 155 + jr recv_done ; de == 0, fail 156 + read_data: 157 + in a, (#DATA_PORT) 158 + ld h, #0 159 + ld l, a 160 + raise_lf: 161 + xor a 162 + out (#CONTROL_PORT), a ; lower linefeed 163 + recv_done: 164 + pop de 165 + pop ix 166 + ret