├── .gitignore ├── README.md ├── doc ├── any │ ├── readme.MD │ └── schematics.png └── harlequin │ ├── board.jpg │ ├── connection.jpg │ ├── esp12.jpg │ ├── pinboard.png │ ├── schematics.png │ └── wifi.md ├── irc ├── Makefile ├── README.md ├── irc.c ├── irc_BANK_7.bin ├── zcc_opt.def ├── zifi.c └── zifi.h ├── iwconfig ├── .gitignore ├── Makefile └── iwconfig.c ├── netman ├── .gitignore ├── Makefile ├── ay-uart.asm ├── esxdos.asm ├── font.bin ├── keyboard.asm ├── main.asm ├── netman.wav ├── p3dos.asm ├── ring.asm ├── screen64.asm ├── setspeed.asm ├── spectranet.asm ├── uno-uart.asm ├── utils.asm ├── wifi.asm └── zifi-uart.asm ├── tape ├── Makefile ├── README.md ├── esxdos.asm ├── font.bin ├── gopher.asm ├── keyboard.asm ├── main.asm ├── render.asm ├── ring.asm ├── screen64.asm ├── textrender.asm ├── tscreen.asm ├── uart.asm ├── ugoph.$c ├── ugoph.bin ├── ugoph.tap ├── utils.asm ├── vtpl.asm └── wifi.asm ├── uGophy ├── LICENSE ├── Makefile ├── ay-uart.asm ├── dos │ ├── decompressor.asm │ ├── fatfs.skv │ ├── ff.equ │ └── ochkodos.asm ├── esxdos.asm ├── font.bin ├── gopher.asm ├── keyboard.asm ├── main.asm ├── p3dos.asm ├── profiscreen.asm ├── render.asm ├── ring.asm ├── screen64.asm ├── spectranet.asm ├── spectranet │ ├── sockdefs.inc │ └── spectranet.inc ├── textrender.asm ├── tscreen.asm ├── ugoph3e.bas ├── uno-uart.asm ├── utils.asm ├── vtpl.asm ├── wifi.asm └── zifi-uart.asm └── wget ├── .gitignore ├── Makefile ├── README.md ├── ay-uart.asm ├── esxdos.asm ├── http.asm ├── main.asm ├── ring.asm ├── uno-uart.asm └── wifi.asm /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Network tools for ANY ZX Spectrum 128K with ESP-12 chip connected to AY and ZX-Uno 2 | 3 | How to connect WiFi chip to harlequin 128K you may read [here](https://github.com/nihirash/zx-net-tools/blob/master/doc/harlequin/wifi.md) 4 | 5 | A bit later will be published info about connecting ESP-chip to ANY speccy with AY-chip -------------------------------------------------------------------------------- /doc/any/readme.MD: -------------------------------------------------------------------------------- 1 | # Wifi for ANY zx with AY sound chip 2 | 3 | You should attach ESP chip to your AY following next diagram: 4 | 5 | ![schematic](schematics.png) 6 | 7 | You doesn't need to flash something or change modes via your PC - only attach ESP to good working 8 | -------------------------------------------------------------------------------- /doc/any/schematics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/doc/any/schematics.png -------------------------------------------------------------------------------- /doc/harlequin/board.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/doc/harlequin/board.jpg -------------------------------------------------------------------------------- /doc/harlequin/connection.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/doc/harlequin/connection.jpg -------------------------------------------------------------------------------- /doc/harlequin/esp12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/doc/harlequin/esp12.jpg -------------------------------------------------------------------------------- /doc/harlequin/pinboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/doc/harlequin/pinboard.png -------------------------------------------------------------------------------- /doc/harlequin/schematics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/doc/harlequin/schematics.png -------------------------------------------------------------------------------- /doc/harlequin/wifi.md: -------------------------------------------------------------------------------- 1 | # Wifi for any zx spectrum. Harlequin 128k Edition with divMMC/divIDE(esxDOS) 2 | 3 | Modern Harlequin 128K boards have buildin ESP-header for connecting wifi chips. 4 | 5 | There wasn't software to use it in full power. With simple mods you'll may use software ports from ZXUno(gopher browser, irc client, web file fetcher, platoTerm will be easly ported). 6 | 7 | ## Simplest board modification 8 | 9 | ZX Spectrum 128K have CTS signal that's say to device "I'm ready to receive data" - it's makes possible get stable data exchange without losing some data. ESP pin-header doesn't have this signal - first what we do - add this signal to it. 10 | 11 | To make this link - connect pin 12 of AY8912 to ESP-header(I'm using GPIO-0 pin of ESP-01). 12 | 13 | ![Board mod](board.jpg) 14 | 15 | If you'll try use ESP-01 chip better connect it with 1K resistor(I've added it to "modem's board" - you may put it on speccy's board and remove from modem). 16 | 17 | ## Wifi modem 18 | 19 | Ok. Your speccy are ready to connect simplest wifi modem. Schematic simple to make and cheap as cup of cofe. 20 | 21 | You'll need two 1 kilooms resistors and ESP-12 module. 22 | 23 | If you've installed resistor on prev. step(from AY to ESP header) - you need remove resistor from CTS pin. 24 | 25 | ![Schematics](schematics.png) 26 | 27 | You've soldered it? Ok. Make pin-connector to harlequin's board. 28 | 29 | I've made it like this: 30 | 31 | ![esp12](esp12.jpg) 32 | 33 | ![connection](connection.jpg) 34 | 35 | So you get this schematis: 36 | 37 | ![connected to pinboard](pinboard.png) 38 | 39 | Better isolate ESP-chip with isolation tape to prevent short circuits. 40 | 41 | So if you made all this steps - you're ready to begin your wifi on speccy experience. 42 | 43 | ## Software part. 44 | 45 | Extract this [archive from latest release](https://github.com/nihirash/zx-net-tools/releases/) to root of your memory card(or hard drive, if you using esxDOS with divIDE and hard drive). 46 | 47 | First that you must run is setspeed.tap file that placed in network folder - it change ESP-12 chip speed from 115200 without controll flow to 9600 with CTS flow control. 48 | 49 | After it you may configure your access point. Just enter in basic 50 | 51 | ``` 52 | .iwconfig YOUR-SSID PASSWORD 53 | ``` 54 | 55 | Replace YOUR-SSID and PASSWORD with your ssid and password. 56 | 57 | So, it's time to try it with gopher-browser - run it(`network/gopher/ugoph.bas` file). 58 | 59 | If all made right - it will download welcome page with key description and copyright notice. 60 | 61 | So - you may browse gopher sites, hear AY-music online, see speccy's screens and download games. 62 | 63 | My gopher server contains ton of this things. 64 | 65 | Feel free to contact me for any questions: 66 | 67 | * anihirash@gmail.com 68 | * @nihirash at telegram/github/twitter 69 | 70 | You also may support my work via [PayPal.Me page](https://paypal.me/pinport) -------------------------------------------------------------------------------- /irc/Makefile: -------------------------------------------------------------------------------- 1 | all: irc.tap 2 | 3 | irc.tap: *.c *.h 4 | zcc +zx -lndos -vn irc.c zifi.c -create-app -o irc 5 | 6 | clean: 7 | rm irc irc_BANK_7.bin *.tap zcc_opt.def -------------------------------------------------------------------------------- /irc/README.md: -------------------------------------------------------------------------------- 1 | # Simple IRC Client for ZX-Spectrum 2 | 3 | This is client works on any zx spectrum with AY-chip and compatible computers and simple WiFi shield. 4 | 5 | ## Requirements 6 | 7 | * AY-3-8912 8 | * WiFi shield attached to it 9 | * WiFi settings stored via [iwconfig](https://github.com/nihirash/iwconfig) 10 | 11 | ## Usage 12 | 13 | Just run tap-file and application starts and in dialog mode ask all necessary data. 14 | 15 | For sending IRC commands used symbol '!' but not '/'. Cause it simpler to type from rubber keyboard. 16 | 17 | There some shortcuts: 18 | 19 | * `!j #channel` - will joins specified channel 20 | * `!l` - will leave current channel(you must switch on channel what you want leave) 21 | * `!s #channel` or `!s user` - will sets current talk stream to channel or user. 22 | * `!m user and there goes your message` sends to `user` private message 23 | 24 | If you need send some other command just write it after bang, example: 25 | 26 | ``` 27 | !KICK user 28 | ``` 29 | 30 | ## Legals 31 | 32 | Some parts of code based of SIC(simple irc client/suckless irc client). 33 | 34 | My code is public domain. -------------------------------------------------------------------------------- /irc/irc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "zifi.h" 5 | 6 | char host[80]; 7 | char port[6]; 8 | 9 | char nick[40]; 10 | char pass[40]; 11 | char channel[256]; 12 | 13 | char recvBuff[4096]; 14 | char sendBuff[1024]; 15 | char iBuff[255]; 16 | unsigned char iPos = 0; 17 | 18 | char intBuff[80]; 19 | char msgOutBuff[1024]; 20 | 21 | static void myPutS(char *c); 22 | static void iRoutine(); 23 | 24 | static void setColour(char c) 25 | { 26 | printf("%c%c", 16, c); 27 | } 28 | 29 | 30 | static void cleanStatus() 31 | { 32 | 33 | gotoxy(0, 22); 34 | printf(" "); 35 | } 36 | 37 | static void cleanIRow() 38 | { 39 | gotoxy(0, 23); 40 | printf(" "); 41 | } 42 | 43 | static char* skip(char *s, char c) 44 | { 45 | while(*s != c && *s != '\0') 46 | s++; 47 | if(*s != '\0') 48 | *s++ = '\0'; 49 | return s; 50 | } 51 | 52 | static void trim(char *s) 53 | { 54 | char *e; 55 | 56 | e = s + strlen(s) - 1; 57 | while(isspace(*e) && e > s) 58 | e--; 59 | *(e + 1) = '\0'; 60 | } 61 | 62 | 63 | void readHostData() 64 | { 65 | printf("Enter host: "); 66 | cgets(host); 67 | 68 | printf("Enter port(or keep empty for 6667):"); 69 | cgets(port); 70 | if (!strcmp(port,"")) { 71 | strcpy(port, "6667"); 72 | } 73 | } 74 | 75 | void readUserData() 76 | { 77 | printf("Your nick:"); 78 | cgets(nick); 79 | if (!strcmp(nick, "")) { 80 | strcpy(nick, "anon-spectrum"); 81 | } 82 | 83 | printf("Your password(may keep empty): "); 84 | cgets(pass); 85 | } 86 | 87 | static void send() 88 | { 89 | int i; 90 | for (i=0; sendBuff[i] != 0; i++) 91 | sendByte(sendBuff[i]); 92 | 93 | sendByte('\r'); 94 | sendByte('\n'); 95 | } 96 | 97 | static void recv() 98 | { 99 | int i = 0; char j; 100 | while (i < 4095) { 101 | recvBuff[i] = getByte(); 102 | if (recvBuff[i] == 10 || recvBuff[i] == 13) break; 103 | if (recvBuff[i]>31) i++; else { 104 | __asm 105 | ei 106 | halt 107 | __endasm; 108 | 109 | iRoutine(); 110 | 111 | } 112 | } 113 | 114 | recvBuff[i] = 0; 115 | } 116 | 117 | void connect() 118 | { 119 | if (strlen(pass) > 0) { 120 | sprintf(&sendBuff, "PASS %s", pass); 121 | send(); 122 | } 123 | 124 | sprintf(&sendBuff, "NICK %s", nick); 125 | send(); 126 | 127 | sprintf(&sendBuff, "USER %s localhost %s :%s", nick, host, nick); 128 | send(); 129 | } 130 | 131 | static void privmsg(char *to, char *what) 132 | { 133 | if (to[0] == 0) { 134 | setColour( '5' ); 135 | myPutS("No target to send message!"); 136 | return; 137 | } 138 | 139 | if (what[0] == 0) return; 140 | 141 | sprintf(sendBuff, "PRIVMSG %s : %s", to, what); 142 | send(); 143 | 144 | sprintf(intBuff, "<%s> %s", nick, what); 145 | setColour( '3' ); 146 | myPutS(intBuff); 147 | } 148 | 149 | static void myPutS(char *c) 150 | { 151 | cleanStatus(); 152 | cleanIRow(); 153 | 154 | gotoxy(0, 20); 155 | printf("%s\n\n\n\n", c); 156 | 157 | } 158 | 159 | static void parseIn() 160 | { 161 | char *subStr, cnt; 162 | char argBuff[40]; 163 | if (iBuff[0] == 0) return; 164 | if (iBuff[0] != '!') { 165 | privmsg(channel, iBuff); 166 | return; 167 | } 168 | 169 | if (iBuff[1] != 0 && iBuff[2] == ' ') { 170 | subStr = &iBuff + 3; 171 | switch (iBuff[1]) 172 | { 173 | case 'j': 174 | sprintf(sendBuff, "JOIN %s", subStr); 175 | send(); 176 | strcpy(channel, subStr); 177 | sprintf(intBuff, "Current stream: %s", subStr); 178 | setColour( '7' ); 179 | myPutS(intBuff); 180 | break; 181 | case 's': 182 | strcpy(channel, subStr); 183 | sprintf(intBuff, "Current stream: %s", subStr); 184 | setColour( '7' ); 185 | myPutS(intBuff); 186 | break; 187 | case 'l': 188 | if (channel[0]) { 189 | sprintf(sendBuff, "PART %s :%s", channel, subStr); 190 | send(); 191 | channel[0] = 0; 192 | 193 | setColour( '7' ); 194 | myPutS("Select stream or join group to talk"); 195 | return; 196 | } 197 | case 'm': 198 | for (cnt=0;(subStr[cnt] != ' ') && (subStr[cnt] != 0) ; argBuff[cnt] = subStr[cnt ++]); 199 | 200 | argBuff[cnt] = 0; 201 | 202 | if (subStr[cnt] == ' ') { 203 | privmsg(argBuff, &subStr[++ cnt]); 204 | } 205 | else { 206 | setColour( '5' ); 207 | myPutS("No message specified!"); 208 | } 209 | default: 210 | break; 211 | } 212 | } else { 213 | if (iBuff[1] == 'l' && iBuff[2] == 0) { 214 | if (channel[0]) { 215 | sprintf(sendBuff, "PART %s", channel); 216 | send(); 217 | channel[0] = 0; 218 | 219 | return; 220 | } 221 | } else { 222 | strcpy(sendBuff, &iBuff[1]); 223 | send(); 224 | } 225 | } 226 | } 227 | 228 | static void parseSrv(char *cmd) 229 | { 230 | char *usr, *par, *txt; 231 | 232 | usr = host; 233 | if(!cmd || !*cmd) 234 | return; 235 | 236 | if(cmd[0] == ':') { 237 | usr = cmd + 1; 238 | cmd = skip(usr, ' '); 239 | if(cmd[0] == '\0') 240 | return; 241 | skip(usr, '!'); 242 | } 243 | skip(cmd, '\r'); 244 | par = skip(cmd, ' '); 245 | txt = skip(par, ':'); 246 | trim(par); 247 | if (!strcmp("PONG", cmd)) return; 248 | if(!strcmp("PRIVMSG", cmd)) { 249 | sprintf(msgOutBuff, "%s <%s> %s", par, usr, txt); 250 | setColour ( '2' ); 251 | myPutS(msgOutBuff); 252 | return; 253 | } 254 | 255 | if (!strcmp("PING", cmd)) { 256 | sprintf(sendBuff, "PONG %s", txt); 257 | send(); 258 | return; 259 | } 260 | 261 | if (!strcmp("NICK", cmd)) { 262 | strcpy(nick, txt); 263 | } 264 | sprintf(msgOutBuff, "%s!%s(%s): %s", usr, cmd, par, txt); 265 | 266 | setColour( '5' ); 267 | myPutS(msgOutBuff); 268 | } 269 | 270 | 271 | static void bar() 272 | { 273 | gotoxy(0, 22); 274 | setColour( '7' ); 275 | printf("Current stream: %s", channel); 276 | __asm 277 | ld hl, #0x5AC0 278 | ld a, #0x0F 279 | ld (hl), a 280 | ld de, #0x5AC1 281 | ld bc, #31 282 | ldir 283 | __endasm; 284 | } 285 | 286 | static void iRoutine() 287 | { 288 | char c; 289 | unsigned char i = 0; 290 | setColour( '7' ); 291 | 292 | gotoxy(0, 23); 293 | iBuff[iPos] = 0; 294 | 295 | if (iPos > 62) i = iPos - 62; 296 | 297 | c = getk(); 298 | printf(">%s_", &iBuff[i], c); 299 | 300 | if (c >= 32) iBuff[iPos ++] = c; 301 | if (c == 12) { 302 | if (i < 2) 303 | cleanIRow(); 304 | 305 | iPos --; 306 | } 307 | if (c == 13) { 308 | cleanIRow(); 309 | iPos = 0; 310 | parseIn(); 311 | bar(); 312 | 313 | } 314 | if (iPos < 0) iPos = 0; 315 | if (iPos > 254) iPos = 254; 316 | } 317 | 318 | 319 | void main() 320 | { 321 | char i; 322 | zx_border(INK_BLACK); 323 | zx_colour(PAPER_BLACK | INK_WHITE); 324 | clg(); 325 | __asm 326 | ld a, 7 327 | ld (23695), a 328 | ld (23693), a 329 | __endasm; 330 | 331 | setColour( '5' ); 332 | 333 | myPutS("Simple IRC Client for ZX-128 v. 0.3"); 334 | setColour( '3' ); 335 | 336 | myPutS("(c) 2020 Nihirash"); 337 | myPutS("Some parts based on Simple Irc Client(suckless software)"); 338 | myPutS("This software is Public Domain."); 339 | myPutS("Use it for the good of all beings"); 340 | myPutS(""); 341 | setColour ( '7' ); 342 | readHostData(); 343 | readUserData(); 344 | initWifi(); 345 | openTcp(host, port); 346 | myPutS("Connected!"); 347 | recv(); 348 | parseSrv(recvBuff); 349 | connect(); 350 | bar(); 351 | for(;;) { 352 | for (i = 0; i < 10; i++) { 353 | __asm 354 | ei 355 | halt 356 | __endasm; 357 | iRoutine(); 358 | } 359 | 360 | if (isAvail()) { 361 | recv(); 362 | parseSrv(recvBuff); 363 | bar(); 364 | } 365 | } 366 | } -------------------------------------------------------------------------------- /irc/irc_BANK_7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/irc/irc_BANK_7.bin -------------------------------------------------------------------------------- /irc/zcc_opt.def: -------------------------------------------------------------------------------- 1 | 2 | IF !DEFINED_CRT_printf_format 3 | defc DEFINED_CRT_printf_format = 1 4 | defc CRT_printf_format = 0x00000600 5 | ELSE 6 | UNDEFINE temp_printf_format 7 | defc temp_printf_format = CRT_printf_format 8 | UNDEFINE CRT_printf_format 9 | defc CRT_printf_format = temp_printf_format | 0x00000600 10 | ENDIF 11 | 12 | 13 | IF !NEED_printf 14 | DEFINE NEED_printf 15 | ENDIF 16 | 17 | -------------------------------------------------------------------------------- /irc/zifi.h: -------------------------------------------------------------------------------- 1 | #ifndef ZIFI_H 2 | #define ZIFI_H 1 3 | 4 | // ESX API 5 | #define ESX_GETSETDRV 0x89 6 | #define ESX_FOPEN 0x9A 7 | #define ESX_FCLOSE 0x9B 8 | #define ESX_FSYNC 0x9C 9 | #define ESX_FREAD 0x9D 10 | #define ESX_FWRITE 0x9E 11 | 12 | // File Modes 13 | #define FMODE_READ 0x01 14 | #define FMODE_WRITE 0x06 15 | #define FMODE_CREATE 0x0E 16 | 17 | extern char* ssid; 18 | extern char* wpass; 19 | extern char is_connected; 20 | 21 | void initWifi(); 22 | char openTcp(char *host, char *port); 23 | char isAvail(); 24 | char sendByte(char c); 25 | char getByte(); 26 | 27 | #endif -------------------------------------------------------------------------------- /iwconfig/.gitignore: -------------------------------------------------------------------------------- 1 | IWCONFIG 2 | *.bin 3 | *.def -------------------------------------------------------------------------------- /iwconfig/Makefile: -------------------------------------------------------------------------------- 1 | all: iwconfig 2 | 3 | iwconfig: iwconfig.c 4 | zcc +zx -vn -startup=30 -clib=new iwconfig.c -SO3 -o iwconfig -subtype=dot -create-app 5 | 6 | clean: 7 | rm *.bin *.def IWCONFIG -------------------------------------------------------------------------------- /iwconfig/iwconfig.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | char ssid[80]; 7 | char pass[80]; 8 | int i; 9 | int file; 10 | 11 | int main(int argc, char **argv) 12 | { 13 | printf("IWConfig by nihirash v.0.1\nWireless interface configurator\n"); 14 | if (argc < 3) { 15 | printf(".iwconfig SSID PASSWD\n"); 16 | return 0; 17 | } 18 | for (int i=0;i<80;i++) { 19 | ssid[i] = pass[i] = 0; 20 | } 21 | 22 | strcpy(ssid, argv[1]); 23 | strcpy(pass, argv[2]); 24 | file = esx_f_open("/sys/config/iw.cfg", ESX_MODE_WRITE | ESX_MODE_OPEN_CREAT_TRUNC); 25 | esx_f_write(file, ssid, 80); 26 | esx_f_write(file, pass, 80); 27 | esx_f_close(file); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /netman/.gitignore: -------------------------------------------------------------------------------- 1 | netman.tap 2 | netman.bin -------------------------------------------------------------------------------- /netman/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @echo "To make Network Manager please select target" 3 | @echo "" 4 | @echo "make zxuno - to make esxDOS ZX-Uno version" 5 | @echo "make zxuno3e - to make +3e ZX-Uno version" 6 | @echo "make plus3dos - to make +3/+3e version Spectrum 128 with ESP-12 on AY" 7 | @echo "make esxdos - to make esxDOS version Spectrum 128 with ESP-12 on AY" 8 | @echo "make karabaspro - to make karabas-pro version with ZX-Uno uart" 9 | @echo "make karabaspro-zifi - to make karabas-pro version with ZiFi uart" 10 | 11 | zxuno: *.asm font.bin 12 | sjasmplus -DESXDOS -DUNO main.asm 13 | 14 | zxuno3e: *.asm font.bin 15 | sjasmplus -DPLUS3DOS -DUNO main.asm 16 | specform -a 32768 netman.bin 17 | rm netman.bin 18 | mv netman.bin.zxb netman.bin 19 | 20 | esxdos: *.asm font.bin 21 | sjasmplus -DESXDOS -DAY main.asm 22 | 23 | plus3dos: 24 | sjasmplus -DPLUS3DOS -DAY main.asm 25 | specform -a 32768 netman.bin 26 | rm netman.bin 27 | mv netman.bin.zxb netman.bin 28 | 29 | karabaspro: 30 | sjasmplus -DTRDOS -DUNO main.asm 31 | 32 | karabaspro-zifi: 33 | sjasmplus -DTRDOS -DZIFI main.asm 34 | 35 | clean: 36 | rm netman.bin netman.tap netman.?c 37 | 38 | -------------------------------------------------------------------------------- /netman/ay-uart.asm: -------------------------------------------------------------------------------- 1 | DISPLAY "UART BEGINS AT ", $ 2 | ; Enable UART 3 | ; Cleaning all flags by reading UART regs 4 | ; Wastes AF and BC 5 | uartBegin: 6 | ld a, #07 7 | ld bc, #fffd 8 | out (c), a 9 | ld a, #fc 10 | ld b, #bf 11 | out (c), a ; Enable read mode 12 | 13 | ld a, #0e 14 | ld bc, #fffd 15 | out (c), a 16 | ld a, #fb 17 | ld b, #bf 18 | out (c), a 19 | ld b, #ff 20 | ei 21 | .flush 22 | halt 23 | djnz .flush 24 | ret 25 | 26 | ; Blocking read one byte 27 | uartReadBlocking: 28 | call uartRead 29 | push af : jr c, urb : pop af 30 | jp uartReadBlocking 31 | urb: 32 | pop af 33 | ret 34 | 35 | readSilient: 36 | call uartRead 37 | ret c 38 | jr readSilient 39 | 40 | 41 | uartWriteByte: 42 | push af 43 | call putC 44 | 45 | ld c, #fd ; prepare port addresses 46 | ld d, #ff 47 | ld e, #bf 48 | ld b, d 49 | 50 | ld a, #0e 51 | out (c), a ; Select AY's PORT A 52 | 53 | ld hl, (_baud) 54 | ld de, #0002 55 | or a 56 | sbc hl, de 57 | ex hl, de 58 | 59 | pop af 60 | cpl 61 | scf 62 | ld b, #0b ; Numbers of bits - 1 start, 8 data, 2 stop 63 | 64 | di ; Hard timing starts 65 | transmitBit: 66 | push bc 67 | push af 68 | 69 | ld a, #fe 70 | ld h, d 71 | ld l, e 72 | ld bc, #bffd 73 | jp nc, transmitOne 74 | ; Transmit Zero: 75 | and #f7 76 | out (c), a 77 | jr transmitNext 78 | transmitOne: 79 | or 8 80 | out (c), a 81 | jr transmitNext 82 | 83 | transmitNext: 84 | dec hl 85 | ld a, h 86 | or l 87 | jr nz, transmitNext 88 | 89 | nop 90 | nop 91 | nop 92 | 93 | pop af 94 | pop bc 95 | or a 96 | rra 97 | djnz transmitBit 98 | ei 99 | ret 100 | 101 | uartRead: 102 | call _uartRead 103 | ret nc 104 | push af 105 | call putC 106 | pop af 107 | scf 108 | ret 109 | 110 | _uartRead: 111 | ld hl, _testByte 112 | ld a, (hl) 113 | and a 114 | jr z, testSecond 115 | inc hl 116 | ld a, (hl) 117 | scf 118 | ret 119 | testSecond: 120 | ld hl, _isSecondByteAvail 121 | ld a, (hl) 122 | and a 123 | jr z, startReadByte 124 | ld (hl), 0 125 | inc hl 126 | ld a, (hl) 127 | scf 128 | ret 129 | startReadByte: 130 | di 131 | xor a 132 | exx 133 | ld de, (_baud) 134 | ld hl, (_baud) 135 | srl h 136 | rr l ; HL=_baud/2 137 | or a 138 | ld b, #FA ; Wait look length 139 | exx 140 | ld c, #fd 141 | ld d, #ff 142 | ld e, #bf 143 | ld b, d 144 | ld a, #0e 145 | out (c), a 146 | in a, (c) 147 | or #f0 ; Input lines is 1 148 | and #fb ; CTS force to 0 149 | ld b, e ; B = #BF 150 | out (c), a ; Make CTS high 151 | ld h, a 152 | 153 | waitStartBit: 154 | ld b, d 155 | in a, (c) 156 | and #80 157 | jr z, startBitFound 158 | readTimeOut: 159 | exx 160 | dec b 161 | exx 162 | jr nz, waitStartBit 163 | xor a 164 | push af 165 | jr readFinish 166 | startBitFound: 167 | in a, (c) 168 | and #80 169 | jr nz, readTimeOut 170 | 171 | in a, (c) 172 | and #80 173 | jr nz, readTimeOut 174 | ;; Start bit found! 175 | 176 | exx 177 | ld bc, #fffd 178 | ld a, #80 179 | ex af, af 180 | readTune: 181 | add hl, de ; HL = 1.5 * _baud 182 | nop 183 | nop 184 | nop 185 | nop ; Fine tuning delay 186 | 187 | bdDelay: 188 | dec hl 189 | ld a, h 190 | or l 191 | jr nz, bdDelay 192 | 193 | in a, (c) 194 | and #80 195 | jp z, zeroReceived 196 | ; One received: 197 | ex af, af 198 | scf 199 | rra 200 | jr c, receivedByte 201 | ex af, af 202 | jp readTune 203 | zeroReceived: 204 | ex af, af 205 | or a 206 | RRA 207 | jr c, receivedByte 208 | ex af, af 209 | jp readTune 210 | receivedByte: 211 | scf 212 | push af 213 | exx 214 | readFinish: 215 | ld a, h 216 | or #04 217 | ld b, e 218 | out (c), a 219 | 220 | exx 221 | ld h, d 222 | ld l, e 223 | 224 | ld bc, #0007 225 | or a 226 | sbc hl, bc 227 | 228 | delayForStopBit: 229 | dec hl 230 | ld a, h 231 | or l 232 | jr nz, delayForStopBit 233 | 234 | ld bc, #fffd 235 | add hl, de 236 | add hl, de 237 | add hl, de 238 | 239 | waitStartBitSecondByte: 240 | in a, (c) 241 | and #80 242 | jr z, secondStartBitFound 243 | dec hl 244 | ld a, h 245 | or l 246 | jr nz, waitStartBitSecondByte 247 | ; No second byte 248 | pop af 249 | ei 250 | ret 251 | 252 | secondStartBitFound: 253 | in a, (c) 254 | and #80 255 | jr nz, waitStartBitSecondByte 256 | ld h, d 257 | ld l, e 258 | ld bc, #0002 259 | srl h 260 | rr l 261 | or a 262 | sbc hl, bc 263 | ld bc, #fffd 264 | ld a, #80 265 | ex af, af 266 | secondByteTune: 267 | nop 268 | nop 269 | nop 270 | nop 271 | add hl, de 272 | 273 | secondDelay: 274 | dec hl 275 | ld a, h 276 | or l 277 | jr nz, secondDelay 278 | 279 | in a, (c) 280 | and #80 281 | jr z, secondZeroReceived 282 | ; Second 1 received 283 | ex af, af 284 | scf 285 | rra 286 | jr c, secondByteFinished 287 | ex af, af 288 | jp secondByteTune 289 | 290 | secondZeroReceived: 291 | ex af, af 292 | or a 293 | rra 294 | jr c, secondByteFinished 295 | ex af, af 296 | jp secondByteTune 297 | secondByteFinished: 298 | ld hl, _isSecondByteAvail 299 | ld (hl), 1 300 | inc hl 301 | ld (hl), a 302 | pop af 303 | ei 304 | ret 305 | dataSequence: 306 | 307 | db #f6, #fe, #f6, #fe, #fe, #f6, #f6, #f6, #f6, #fe 308 | db #f6, #f6, #fe, #f6, #fe, #f6, #f6, #f6, #f6, #fe 309 | db #f6, #fe, #f6, #f6, #f6, #f6, #f6, #fe, #f6, #fe 310 | db #f6, #f6, #f6, #fe, #f6, #fe, #f6, #fe, #f6, #fe 311 | db #f6, #fe, #fe, #f6, #fe, #f6, #fe, #f6, #f6, #fe 312 | db #f6, #fe, #f6, #fe, #f6, #fe, #f6, #fe, #f6, #fe 313 | db #f6, #fe, #f6, #f6, #f6, #f6, #f6, #fe, #f6, #fe 314 | db #f6, #f6, #fe, #f6, #f6, #fe, #f6, #fe, #f6, #fe 315 | db #f6, #f6, #f6, #fe, #f6, #fe, #f6, #fe, #f6, #fe 316 | db #f6, #fe, #fe, #fe, #fe, #fe, #f6, #fe, #f6, #fe 317 | db #f6, #f6, #f6, #fe, #f6, #f6, #f6, #fe, #f6, #fe 318 | db #f6, #fe, #f6, #fe, #f6, #f6, #f6, #fe, #f6, #fe 319 | db #f6, #f6, #fe, #fe, #f6, #f6, #f6, #fe, #f6, #fe 320 | db #f6, #fe, #f6, #fe, #fe, #fe, #fe, #f6, #f6, #fe 321 | db #f6, #fe, #f6, #f6, #fe, #fe, #fe, #f6, #f6, #fe 322 | db #f6, #f6, #fe, #fe, #f6, #fe, #fe, #f6, #f6, #fe 323 | db #f6, #f6, #f6, #f6, #f6, #fe, #fe, #f6, #f6, #fe 324 | db #f6, #f6, #f6, #f6, #f6, #fe, #fe, #f6, #f6, #fe 325 | db #f6, #f6, #f6, #fe, #fe, #f6, #fe, #f6, #f6, #fe 326 | db #f6, #f6, #f6, #f6, #fe, #fe, #fe, #f6, #f6, #fe 327 | db #f6, #f6, #f6, #fe, #fe, #f6, #fe, #f6, #f6, #fe 328 | db #f6, #fe, #f6, #f6, #f6, #fe, #fe, #f6, #f6, #fe 329 | db #f6, #f6, #f6, #fe, #fe, #f6, #fe, #f6, #f6, #fe 330 | db #f6, #f6, #f6, #f6, #f6, #fe, #fe, #f6, #f6, #fe 331 | db #f6, #f6, #f6, #fe, #fe, #f6, #fe, #f6, #f6, #fe 332 | db #f6, #f6, #fe, #f6, #f6, #fe, #fe, #f6, #f6, #fe 333 | db #f6, #fe, #f6, #fe, #fe, #f6, #f6, #f6, #f6, #fe 334 | db #f6, #f6, #fe, #f6, #fe, #f6, #f6, #f6, #f6, #fe 335 | dataSize = $ - dataSequence 336 | ; Total bytes 28 337 | 338 | setSpeed: 339 | ld hl, dataSequence : ld bc, #bffd 340 | 341 | dup dataSize 342 | outi : ld bc, #bffd : nop 343 | edup 344 | ret 345 | 346 | 347 | _baud dw 11 ; 54 - 2400 --- 25 - 4800 --- 11 - 9600 348 | _isSecondByteAvail dw #0 349 | _testByte dw #0 350 | -------------------------------------------------------------------------------- /netman/esxdos.asm: -------------------------------------------------------------------------------- 1 | ; API methods 2 | ESX_GETSETDRV = #89 3 | ESX_FOPEN = #9A 4 | ESX_FCLOSE = #9B 5 | ESX_FSYNC = #9C 6 | ESX_FREAD = #9D 7 | ESX_FWRITE = #9E 8 | 9 | ; File modes 10 | FMODE_READ = #01 11 | FMODE_WRITE = #06 12 | FMODE_CREATE = #0E 13 | 14 | ; Returns: 15 | ; A - current drive 16 | getDefaultDrive: 17 | ld a, 0 : rst #8 18 | defb ESX_GETSETDRV 19 | ret 20 | 21 | ; Opens file on default drive 22 | ; B - File mode 23 | ; HL - File name 24 | ; Returns: 25 | ; A - file stream id 26 | fopen: 27 | push bc : push hl 28 | call getDefaultDrive 29 | pop ix : pop bc 30 | rst #8 31 | defb ESX_FOPEN 32 | ret 33 | 34 | ; A - file stream id 35 | fclose: 36 | rst #8 37 | defb ESX_FCLOSE 38 | ret 39 | 40 | ; A - file stream id 41 | ; BC - length 42 | ; HL - buffer 43 | ; Returns 44 | ; BC - length(how much was actually read) 45 | fread: 46 | push hl : pop ix 47 | rst #8 48 | defb ESX_FREAD 49 | ret 50 | 51 | ; A - file stream id 52 | ; BC - length 53 | ; HL - buffer 54 | ; Returns: 55 | ; BC - actually written bytes 56 | fwrite: 57 | push hl : pop ix 58 | rst #8 59 | defb ESX_FWRITE 60 | ret 61 | 62 | ; A - file stream id 63 | fsync: 64 | rst #8 65 | defb ESX_FSYNC 66 | ret 67 | -------------------------------------------------------------------------------- /netman/font.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/netman/font.bin -------------------------------------------------------------------------------- /netman/keyboard.asm: -------------------------------------------------------------------------------- 1 | CURKEY = 23560 2 | 3 | ; Returns in A key code or zero if key wans't pressed 4 | inkey: 5 | ld hl, CURKEY : ld a, (hl) 6 | push af : xor a : ld (hl), a : pop af 7 | ret 8 | 9 | findZero: 10 | ld a, (hl) : or a : ret z 11 | inc hl 12 | jp findZero 13 | 14 | input: 15 | ld b, 20 : ld c, 0 : call gotoXY 16 | 17 | ld hl, cleanLine : call printZ64 18 | 19 | ld hl, iBuff : call findZero 20 | iLp: 21 | halt 22 | push hl 23 | 24 | ld b, 20 : ld c, 0: call gotoXY 25 | ld hl, iBuff : call printZ64 26 | 27 | ld a, '_' : call putC : ld a, ' ' : call putC 28 | 29 | call inkey 30 | 31 | cp 0 : jr z, iNth 32 | cp 12 : jr z, iBS 33 | cp 13 : jr z, iRet 34 | 35 | pop hl : ld (hl), A : push hl 36 | 37 | ld de, iBuff + 62 : sub hl, de : ld a, h : or l : jr z, iCr 38 | 39 | pop hl : inc hl 40 | jr iLp 41 | 42 | iBS: pop hl : push hl 43 | ld de, iBuff : sub hl, de : ld a, h : or l 44 | pop hl :jr z, iLp 45 | 46 | dec hl : ld (hl), 0 47 | jr iLp 48 | 49 | iCr pop hl : xor a : ld (hl), a : push hl 50 | iNth pop hl: jr iLp 51 | 52 | cleanIBuff: 53 | ld bc, 64 : ld hl, iBuff : ld de, iBuff + 1 : ld (hl), 0 : ldir 54 | ret 55 | 56 | iRet: 57 | pop hl 58 | 59 | ld b, 20 : ld c, 0 : call gotoXY 60 | ld hl, cleanLine :call printZ64 61 | ret 62 | 63 | iBuff defs 65 64 | cleanLine ds 64, 32 65 | db 0 -------------------------------------------------------------------------------- /netman/main.asm: -------------------------------------------------------------------------------- 1 | device zxspectrum48 2 | org #8000 3 | start: 4 | di 5 | ld sp, start - 1 6 | res 4, (iy+1) 7 | 8 | IFDEF TRDOS 9 | xor a : ld (#5c6a), a ; Thank you, Mario Prato, for feedback 10 | out (#fe), a : call changeBank 11 | ELSE 12 | xor a : out (#fe), a : call changeBank 13 | ENDIF 14 | 15 | call clearScreen 16 | ld hl, initing : call putStringZ 17 | call uartBegin 18 | ei 19 | halt 20 | call setSpeed 21 | IFDEF PLUS3DOS 22 | call initDos 23 | ld ix, DOS_MOTOR_OFF : call plus3dos 24 | ENDIF 25 | ld b, #ff ; flush uart shit 26 | .preRead 27 | push bc 28 | call uartRead 29 | pop bc 30 | djnz .preRead 31 | 32 | call clearScreen 33 | call initWifi 34 | 35 | ld a, 0, hl, buffer, bc, 2048, de, buffer + 1, (hl), a 36 | ldir 37 | ld hl, getNetwork : call uartWriteStringZ 38 | call clearScreen 39 | .skipShit 40 | call readSilient 41 | cp '+' 42 | jr nz, .skipShit 43 | 44 | call clearScreen 45 | call clearRing 46 | ld hl, buffer 47 | .rlp 48 | push hl 49 | call uartReadBlocking 50 | pop hl 51 | ld (hl), a 52 | inc hl 53 | push hl 54 | call pushRing 55 | ld hl, response_ok : call searchRing : cp 1 : jr z, .dp 56 | pop hl 57 | jp .rlp 58 | .dp: 59 | pop hl 60 | xor a 61 | .7 dec hl : ld (hl), a 62 | dbgEntry: 63 | call drawPage 64 | ei 65 | xor a : ld (CURKEY), a 66 | inputLoop: 67 | halt 68 | call inkey : or a : jr z, inputLoop 69 | push af 70 | call hideCursor 71 | pop af 72 | cp 'q' : jp z, moveUp 73 | cp 'a' : jp z, moveDown 74 | cp 13 : jp z, selectItem 75 | call showCursor 76 | jp inputLoop 77 | 78 | ssid ds 80 79 | pass ds 80 80 | 81 | IFDEF PLUS3DOS 82 | cfg db "iw.cfg", #ff 83 | ENDIF 84 | 85 | IFDEF ESXDOS 86 | cfg db "/sys/config/iw.cfg", 0 87 | fp db 0 88 | ENDIF 89 | 90 | selectItem: 91 | ld a, (cursor_pos) : dec a : ld b, a 92 | call findLine : call findName 93 | ld de, ssid 94 | .copyName 95 | ld a, (hl) 96 | cp '"' : jr z, .next 97 | ldi 98 | jp .copyName 99 | .next: 100 | ld a, (ssid) : and a : jp z, doNothing 101 | call prepHeader 102 | ld b, 19 : ld c, 0 : call gotoXY 103 | ld hl, enterpwd : call putStringZ 104 | 105 | call input 106 | ld hl, iBuff : ld de, pass : ld bc, 64 : ldir 107 | 108 | IFDEF PLUS3DOS 109 | ld hl, cfg 110 | ld c, ACCESS_MODE_EXCLUSIVE_WRITE, d, CREATE_ACTION_POINT_TO_DATA, e, OPEN_ACTION_MAKE_BACKUP 111 | call fopen 112 | 113 | ld c, 0, de, 160, hl, ssid 114 | call fwrite 115 | call fclose 116 | ENDIF 117 | 118 | IFDEF ESXDOS 119 | ld hl, cfg, b, FMODE_CREATE 120 | call fopen 121 | ld (fp), a 122 | ld hl, ssid, bc, 160 123 | call fwrite 124 | ld a, (fp) 125 | call fclose 126 | ENDIF 127 | 128 | IFDEF TRDOS 129 | ; trdos version stores wifi config into the esp flash 130 | ld hl, cmd_ap1 : call uartWriteStringZ 131 | ld hl, ssid : call uartWriteStringZ 132 | ld hl, cmd_ap2 : call uartWriteStringZ 133 | ld hl, pass : call uartWriteStringZ 134 | ld hl, cmd_ap3 : call okErrCmd 135 | ENDIF 136 | 137 | ld b, 2 : ld c, 0 : call gotoXY 138 | ld hl, allDone : call putStringZ 139 | 140 | jr $ 141 | ret 142 | 143 | moveUp: 144 | ld a, (cursor_pos) : dec a : or a : jp z, doNothing 145 | ld (cursor_pos), a 146 | call showCursor 147 | jp inputLoop 148 | 149 | moveDown: 150 | ld a, (cursor_pos) : inc a : cp 21 : jp z, doNothing 151 | ld (cursor_pos), a 152 | call showCursor 153 | jp inputLoop 154 | 155 | doNothing: 156 | call showCursor 157 | jp inputLoop 158 | 159 | prepHeader: 160 | call clearScreen 161 | ld hl, header : call putStringZ 162 | ld b, 23, c, 0 : call gotoXY 163 | ld hl, footer : call putStringZ 164 | ld b, 1, c, 0 : call gotoXY 165 | ld a, 22 : call drawLine 166 | xor a : jp drawLine 167 | 168 | drawPage: 169 | call prepHeader 170 | 171 | ld b, 21 172 | .l1 173 | push bc 174 | ld a, 21 : sub b 175 | call printName 176 | pop bc 177 | djnz .l1 178 | call showCursor 179 | ret 180 | 181 | ; b - line count 182 | findLine: 183 | ld hl, buffer 184 | ld a, b : and a : ret z 185 | .l1 186 | ld a, (hl) 187 | or a : jr z, .l2 188 | inc hl 189 | cp 10 : jr nz, .l1 190 | djnz .l1 191 | ret 192 | .l2 193 | ld hl, 0 194 | ret 195 | 196 | findName: 197 | ld a, (hl) 198 | inc hl 199 | cp '"' 200 | ret z 201 | jr findName 202 | 203 | ; a - Line number 204 | printName: 205 | ld b, a 206 | call findLine 207 | ld a, l : or h : ret z 208 | call findName 209 | push hl 210 | ld a, ' ' : call putC 211 | pop hl 212 | .l1 213 | ld a, (hl) 214 | cp '"' 215 | jp z, mvCR 216 | push hl 217 | call putC 218 | pop hl 219 | inc hl 220 | jr .l1 221 | 222 | 223 | allDone db "All done!", 13, "Reboot and load some WiFi software", 0 224 | enterpwd db "Enter WiFi password:", 0 225 | initing db "Initializing your WiFi modem!", 13, 10, 0 226 | header db " WiFi configuration utility v.0.1 (c) Alexander Sharikhin", 13, 0 227 | footer db " Q/A - move cursor Enter - select network for configuration", 0 228 | getNetwork db 13, 10, "AT+CWLAP", 13, 10, 0 229 | 230 | include "screen64.asm" 231 | 232 | IFDEF AY 233 | include "ay-uart.asm" 234 | ENDIF 235 | 236 | IFDEF UNO 237 | include "uno-uart.asm" 238 | ENDIF 239 | 240 | IFDEF ZIFI 241 | include "zifi-uart.asm" 242 | ENDIF 243 | 244 | include "utils.asm" 245 | include "ring.asm" 246 | include "wifi.asm" 247 | include "keyboard.asm" 248 | 249 | IFDEF PLUS3DOS 250 | include "p3dos.asm" 251 | ENDIF 252 | 253 | IFDEF ESXDOS 254 | include "esxdos.asm" 255 | ENDIF 256 | 257 | buffer db 0 258 | IFDEF PLUS3DOS 259 | savebin "netman.bin", start, $ - start 260 | ENDIF 261 | 262 | IFDEF ESXDOS 263 | savetap "netman.tap", start 264 | ENDIF 265 | 266 | IFDEF TRDOS 267 | savehob "netman.$c", "netman.C", start, $ - start 268 | ENDIF 269 | -------------------------------------------------------------------------------- /netman/netman.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/netman/netman.wav -------------------------------------------------------------------------------- /netman/p3dos.asm: -------------------------------------------------------------------------------- 1 | DOS_READ = #0112 2 | DOS_WRITE = #115 3 | DOS_OPEN = #0106 4 | DOS_CLOSE = #0109 5 | DOS_MOTOR_OFF = #019C 6 | DOS_SET_1346 = #013F 7 | 8 | CMR0 = #7FFD 9 | 10 | ; +3DOS constants 11 | OPEN_ACTION_ERROR_EXISTS = 0 12 | OPEN_ACTION_POSITION_TO_DATA = 1 13 | OPEN_ACTION_POSITION_TO_HEADER = 2 14 | OPEN_ACTION_MAKE_BACKUP = 3 15 | OPEN_ACTION_OVERWRITE = 4 16 | 17 | CREATE_ACTION_DONTCREATE = 0 18 | CREATE_ACTION_POINT_TO_DATA = 1 19 | CREATE_ACTION_POINT_TO_HEADER = 2 20 | 21 | FILE_TYPE_BASIC = 0 22 | FILE_TYPE_NUM_ARRAY = 1 23 | FILE_TYPE_CHR_ARRAY = 2 24 | FILE_TYPE_BYTES = 3 25 | 26 | ACCESS_MODE_EXCLUSIVE_READ = 1 27 | ACCESS_MODE_EXCLUSIVE_WRITE = 2 28 | ACCESS_MODE_EXCLUSIVE_READ_WRITE = 3 29 | ACCESS_MODE_SHARED = 5 30 | 31 | FMODE_CREATE = 0 32 | 33 | initDos: 34 | ld ix, DOS_SET_1346 : ld hl,0 : ld d,h : ld e,d : call plus3dos ; disable RAM DISK 35 | ret 36 | 37 | ; C - access mode 38 | ; D - Create action 39 | ; E - Open action 40 | ; HL - filename 41 | fopen: 42 | ld b, 1 43 | ld ix, DOS_OPEN : call plus3dos 44 | ret c 45 | jr error 46 | 47 | ; C - page 48 | ; DE - byte count 49 | ; HL - Address 50 | fread: 51 | ld b, 1 : ld ix, DOS_READ 52 | jp plus3dos 53 | 54 | ; C - page 55 | ; DE - Bytes 56 | ; HL - Buffer 57 | fwrite: 58 | ld b, 1 : ld ix, DOS_WRITE 59 | jp plus3dos 60 | 61 | fclose: 62 | ld b, ' ' : add b : call putC 63 | ld b, 1 : ld ix, DOS_CLOSE 64 | call plus3dos 65 | ld ix, DOS_MOTOR_OFF 66 | jp plus3dos 67 | 68 | error: 69 | ld a, 2 70 | out (254), a 71 | ld bc, #0200 : call gotoXY 72 | ld hl, dos_error 73 | call putStringZ 74 | jr $ 75 | 76 | setDOS: 77 | di 78 | push bc 79 | push af 80 | ld bc, CMR0 81 | ld a,(bankm) 82 | res 4,a 83 | or 7 84 | ld (bankm),a 85 | out (c),a 86 | pop af 87 | pop bc 88 | ret 89 | 90 | plus3dos: 91 | call setDOS 92 | ld (adds+1),ix 93 | adds: call 0 94 | setBASIC: 95 | di 96 | push af 97 | ld bc, CMR0 98 | ld a,(bankm) 99 | set 4,a 100 | and #0f8 101 | ld (bankm),a 102 | out (c),a 103 | pop af 104 | ret 105 | 106 | dos_error db 13, "DOS OPERATION ERROR!", 13, 0 -------------------------------------------------------------------------------- /netman/ring.asm: -------------------------------------------------------------------------------- 1 | ; Pushes A to ring buffer 2 | pushRing 3 | push af 4 | ld b, 32 : ld hl, ring_buffer + 1 : ld de, ring_buffer 5 | ringL 6 | ld a, (hl) : ld (de), a : inc hl : inc de : djnz ringL 7 | pop af 8 | ld hl, ring_buffer + 31 : ld (hl), a 9 | ret 10 | 11 | ; HL - Compare string(null terminated) 12 | ; A - 0 NOT Found 13 | ; 1 Found 14 | searchRing: 15 | ld b, 0 : push hl 16 | serlp: 17 | ld a, (hl) : inc hl : inc b : and a : jp nz, serlp 18 | dec b : pop hl : push bc : push hl 19 | SRWork: 20 | pop hl 21 | ld de, ring_buffer + 32 22 | srcLp 23 | dec de : djnz srcLp 24 | pop bc 25 | ringCmpLp 26 | push bc : push af 27 | ld a, (de) : ld b, a 28 | pop af : ld a, (hl) : cp b : pop bc : ld a, 0 : ret nz 29 | inc de : inc hl 30 | djnz ringCmpLp 31 | ld a, 1 32 | ret 33 | 34 | clearRing: 35 | xor a : ld hl, ring_buffer : ld de, ring_buffer + 1 : ld bc, 32 : ld (hl), a : ldir 36 | ret 37 | 38 | ring_buffer dup 33 39 | defb 0 40 | edup -------------------------------------------------------------------------------- /netman/screen64.asm: -------------------------------------------------------------------------------- 1 | clearScreen: 2 | ld a, 7 : call changeBank 3 | 4 | ld c, #fe 5 | ld a, 0 6 | out (c), a 7 | ld hl, #c000 8 | ld (hl), 0 9 | ld de, #c001 10 | ld bc, #17FF 11 | ldir 12 | ld hl, #d800 13 | ld a, (attr_screen) 14 | ld (hl), a 15 | ld de, #d801 16 | ld bc, #2FF 17 | ldir 18 | ld bc, 0 19 | call gotoXY 20 | ret 21 | 22 | showCursor: 23 | 24 | ld a, (cursor_pos) 25 | drawLine: 26 | ld c, 0 27 | ld b, a 28 | call bc_to_attr 29 | ld a, 7 : call changeBank 30 | 31 | ld (hl), #C 32 | ld de, hl 33 | inc de 34 | ld bc, 31 35 | ldir 36 | ret 37 | 38 | hideCursor: 39 | ld a, 7 : call changeBank 40 | 41 | ld a, (cursor_pos) 42 | ld b, a 43 | ld c, 0 44 | call bc_to_attr 45 | ld (hl), #07 46 | ld de, hl 47 | inc de 48 | ld bc, 31 49 | ldir 50 | ret 51 | 52 | ; Print just one symbol 53 | ; A - symbol 54 | putC 55 | cp 13 56 | jr z, mvCR 57 | or a 58 | cp ' ' 59 | ret c 60 | 61 | push af 62 | ld a, 7 63 | call changeBank 64 | pop af 65 | 66 | ld hl, single_symbol 67 | ld (hl), a 68 | ld hl, single_symbol_print 69 | jp print64 70 | 71 | mvCR 72 | ld bc, (col_screen) 73 | inc b 74 | ld c, 0 75 | ld a, 0 76 | ld (half_tile_screen), a 77 | call gotoXY 78 | ret 79 | 80 | ; Set console coordinates 81 | ; b = row(0..23), c = column (0..63) 82 | ; 83 | gotoXY: 84 | ld a, 0 85 | ld (half_tile_screen), a 86 | ld (col_screen), bc 87 | ld a, 22 88 | cp b 89 | jp s, scrl 90 | ret 91 | scrl 92 | ld b, 22 93 | ld (col_screen) ,bc 94 | jp scroll_up8 95 | 96 | 97 | ; Put string with coordinates 98 | ; b= row (0..23), c=col (0..63) 99 | ; hl - string pointer that's begins from symbol count 100 | printAt64: 101 | call gotoXY 102 | 103 | ; Put string 104 | ; hl - string pointer that's begins from symbol count 105 | print64 106 | ld a,(hl) 107 | and a 108 | ret z 109 | 110 | push hl 111 | call calc_addr_attr 112 | ld a,(attr_screen) 113 | ld (hl),a 114 | pop hl 115 | 116 | call calc_addr_scr 117 | 118 | ld a,(half_tile_screen) 119 | bit 0,a 120 | ld a,(hl) 121 | jp nz,print64_4 122 | print64_3 123 | push af 124 | push hl 125 | call calc_addr_attr 126 | ld a,(attr_screen) 127 | ld (hl),a 128 | pop hl 129 | 130 | inc hl 131 | push hl 132 | 133 | ld a,(hl) 134 | ld l,a 135 | ld h,0 136 | add hl,hl 137 | add hl,hl 138 | add hl,hl 139 | ld bc,font64 140 | add hl,bc 141 | 142 | push de 143 | 144 | ld b,6 145 | xor a 146 | ld (de),a 147 | print64_1 148 | inc d 149 | ld a,(hl) 150 | and #f0 151 | ld (de),a 152 | inc hl 153 | djnz print64_1 154 | 155 | inc d 156 | xor a 157 | ld (de),a 158 | 159 | ld a,1 160 | ld (half_tile_screen),a 161 | 162 | pop de 163 | pop hl 164 | pop af 165 | 166 | dec a 167 | ret z 168 | 169 | print64_4 170 | push af 171 | 172 | inc hl 173 | push hl 174 | 175 | ld a,(hl) 176 | ld l,a 177 | ld h,0 178 | add hl,hl 179 | add hl,hl 180 | add hl,hl 181 | ld bc,font64 182 | add hl,bc 183 | 184 | push de 185 | 186 | ld b,6 187 | xor a 188 | ld (de),a 189 | print64_2 190 | inc d 191 | ld a,(hl) 192 | and #0f 193 | ld c,a 194 | ld a,(de) 195 | or c 196 | ld (de),a 197 | inc hl 198 | djnz print64_2 199 | 200 | inc d 201 | xor a 202 | ld (de),a 203 | 204 | ld (half_tile_screen),a 205 | 206 | pop de 207 | 208 | call move_cr64 209 | 210 | pop hl 211 | pop af 212 | dec a 213 | 214 | jp nz,print64_3 215 | 216 | ret 217 | 218 | ; move cursor 219 | move_cr64 220 | inc de 221 | 222 | ld hl,col_screen 223 | inc (hl) 224 | ld a,(hl) 225 | 226 | cp 32 227 | ret c 228 | 229 | xor a 230 | ld (half_tile_screen),a 231 | ld (hl),a 232 | ld c,a 233 | 234 | inc hl 235 | inc (hl) 236 | ld a,(hl) 237 | ld b,a 238 | 239 | cp 24 240 | jp c,move_cr64_01 241 | 242 | ld a,23 243 | ld (hl),a 244 | ld b,a 245 | 246 | push bc 247 | call scroll_up8 248 | pop bc 249 | 250 | move_cr64_01 251 | call calc_addr_scr 252 | ret 253 | 254 | calc_addr_scr 255 | ld a,b 256 | ld d,a 257 | rrca 258 | rrca 259 | rrca 260 | and a,224 261 | add a,c 262 | ld e,a 263 | ld a,d 264 | and 24 265 | or #c0 266 | ld d,a 267 | ret 268 | 269 | calc_addr_attr 270 | ld bc,(col_screen) 271 | bc_to_attr: 272 | ld a,b 273 | rrca 274 | rrca 275 | rrca 276 | ld l,a 277 | and 31 278 | or #d8 279 | ld h,a 280 | ld a,l 281 | and 252 282 | or c 283 | ld l,a 284 | ret 285 | 286 | scroll_up8 287 | ld hl,table_addr_scr 288 | ld b,184 289 | 290 | scroll_up8_01 291 | push bc 292 | 293 | ld e,(hl) 294 | inc hl 295 | ld d,(hl) 296 | inc hl 297 | 298 | push hl 299 | 300 | ld bc,14 301 | add hl,bc 302 | ld c,(hl) 303 | inc hl 304 | ld b,(hl) 305 | 306 | ld h,b 307 | ld l,c 308 | 309 | ld bc,32 310 | ldir 311 | 312 | pop hl 313 | pop bc 314 | djnz scroll_up8_01 315 | 316 | ld b,8 317 | 318 | scroll_up8_02 319 | push bc 320 | 321 | ld e,(hl) 322 | inc hl 323 | ld d,(hl) 324 | inc hl 325 | 326 | push hl 327 | 328 | ld h,d 329 | ld l,e 330 | inc de 331 | ld (hl),0 332 | ld bc,31 333 | ldir 334 | 335 | pop hl 336 | pop bc 337 | djnz scroll_up8_02 338 | 339 | ld de,#5800 340 | ld hl,#5820 341 | ld bc,736 342 | ldir 343 | 344 | ld a,(de) 345 | 346 | ld hl,#5ae0 347 | ld de,#5ae1 348 | ld (hl),a 349 | ld bc,31 350 | ldir 351 | 352 | ret 353 | 354 | 355 | font64 incbin "font.bin" 356 | table_addr_scr 357 | defw #4000,#4100,#4200,#4300,#4400,#4500,#4600,#4700 358 | defw #4020,#4120,#4220,#4320,#4420,#4520,#4620,#4720 359 | defw #4040,#4140,#4240,#4340,#4440,#4540,#4640,#4740 360 | defw #4060,#4160,#4260,#4360,#4460,#4560,#4660,#4760 361 | defw #4080,#4180,#4280,#4380,#4480,#4580,#4680,#4780 362 | defw #40a0,#41a0,#42a0,#43a0,#44a0,#45a0,#46a0,#47a0 363 | defw #40c0,#41c0,#42c0,#43c0,#44c0,#45c0,#46c0,#47c0 364 | defw #40e0,#41e0,#42e0,#43e0,#44e0,#45e0,#46e0,#47e0 365 | 366 | defw #4800,#4900,#4a00,#4b00,#4c00,#4d00,#4e00,#4f00 367 | defw #4820,#4920,#4a20,#4b20,#4c20,#4d20,#4e20,#4f20 368 | defw #4840,#4940,#4a40,#4b40,#4c40,#4d40,#4e40,#4f40 369 | defw #4860,#4960,#4a60,#4b60,#4c60,#4d60,#4e60,#4f60 370 | defw #4880,#4980,#4a80,#4b80,#4c80,#4d80,#4e80,#4f80 371 | defw #48a0,#49a0,#4aa0,#4ba0,#4ca0,#4da0,#4ea0,#4fa0 372 | defw #48c0,#49c0,#4ac0,#4bc0,#4cc0,#4dc0,#4ec0,#4fc0 373 | defw #48e0,#49e0,#4ae0,#4be0,#4ce0,#4de0,#4ee0,#4fe0 374 | 375 | defw #5000,#5100,#5200,#5300,#5400,#5500,#5600,#5700 376 | defw #5020,#5120,#5220,#5320,#5420,#5520,#5620,#5720 377 | defw #5040,#5140,#5240,#5340,#5440,#5540,#5640,#5740 378 | defw #5060,#5160,#5260,#5360,#5460,#5560,#5660,#5760 379 | defw #5080,#5180,#5280,#5380,#5480,#5580,#5680,#5780 380 | defw #50a0,#51a0,#52a0,#53a0,#54a0,#55a0,#56a0,#57a0 381 | defw #50c0,#51c0,#52c0,#53c0,#54c0,#55c0,#56c0,#57c0 382 | defw #50e0,#51e0,#52e0,#53e0,#54e0,#55e0,#56e0,#57e0 383 | 384 | 385 | string_temp defb 0 386 | dup 255 387 | defb 32 388 | edup 389 | 390 | col_screen defb 0 391 | row_screen defb 0 392 | half_tile_screen defb 0 393 | attr_screen defb 07 394 | 395 | col_screen_temp defw 0 396 | half_tile_screen_temp defb 0 397 | 398 | single_symbol_print defb 1 399 | single_symbol defb 0 400 | cursor_pos db 1 -------------------------------------------------------------------------------- /netman/setspeed.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/netman/setspeed.asm -------------------------------------------------------------------------------- /netman/spectranet.asm: -------------------------------------------------------------------------------- 1 | include "inc/spectranet.inc" 2 | include "inc/sockdefs.inc" 3 | 4 | ; HL - domain 5 | ; BC - port 6 | openTcp: 7 | display $ 8 | display "HERE" 9 | push BC 10 | ld de, ip_buffer 11 | ld ix, GETHOSTBYNAME 12 | call IXCALL 13 | 14 | jp c, tcpError 15 | ld c, SOCK_STREAM 16 | ld hl, SOCKET 17 | call HLCALL 18 | 19 | jp c, tcpError 20 | ld (sock_fd), a 21 | pop bc 22 | ld de, ip_buffer 23 | ld hl, CONNECT 24 | call HLCALL 25 | 26 | jp c, tcpError 27 | 28 | ld a, 1 29 | ld (connectionOpen), a 30 | ret 31 | 32 | ; DE - pointer to string 33 | ; BC - count 34 | sendTcp: 35 | display $ 36 | display "SEND_TCP" 37 | ld a, (sock_fd) 38 | ld hl, SEND 39 | call HLCALL 40 | jp c, tcpError 41 | ret 42 | 43 | getPacket: 44 | ld hl, 0 45 | ld (bytes_avail), hl 46 | 47 | ld a, (sock_fd) 48 | ld hl, POLLFD 49 | call HLCALL 50 | ld a, c 51 | 52 | cp 2 53 | jp z, fin 54 | 55 | ld a, (sock_fd) 56 | ld de, output_buffer 57 | ld bc, 2048 58 | ld hl, RECV 59 | call HLCALL 60 | jp c, fin 61 | ld (bytes_avail), bc 62 | ret 63 | 64 | fin: 65 | xor a 66 | ld (connectionOpen), a 67 | 68 | ld a, (sock_fd) 69 | ld hl, CLOSE 70 | call HLCALL 71 | ret 72 | 73 | tcpError: 74 | di 75 | halt 76 | 77 | ip_buffer defs 4 78 | sock_fd db 0 79 | 80 | output_buffer defs 2050 81 | bytes_avail dw 0 -------------------------------------------------------------------------------- /netman/uno-uart.asm: -------------------------------------------------------------------------------- 1 | UART_DATA_REG = #c6 2 | UART_STAT_REG = #c7 3 | UART_BYTE_RECIVED = #80 4 | UART_BYTE_SENDING = #40 5 | SCANDBLCTRL_REG = #0B 6 | ZXUNO_ADDR = #FC3B 7 | ZXUNO_REG = #FD3B 8 | 9 | 10 | ; Enable UART 11 | ; Cleaning all flags by reading UART regs 12 | ; Wastes AF and BC 13 | uartBegin: 14 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 15 | ld bc, ZXUNO_REG : in A, (c) 16 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 17 | ld bc, ZXUNO_REG : in A, (c) 18 | ret 19 | 20 | ; Blocking read one byte 21 | uartReadBlocking: 22 | call uartRead 23 | push af : ld a, 1 : and b : jr nz, urb : pop af 24 | jp uartReadBlocking 25 | urb: 26 | pop af 27 | ret 28 | 29 | 30 | readSilient: 31 | call _uartRead 32 | push af : ld a, 1 : and b : jr nz, .exit : pop af 33 | jp readSilient 34 | .exit 35 | pop af 36 | ret 37 | 38 | ; Write single byte to UART 39 | ; A - byte to write 40 | ; BC will be wasted 41 | uartWriteByte: 42 | push af 43 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 44 | waitWriteReady: 45 | ld bc, ZXUNO_REG : in A, (c) : and UART_BYTE_RECIVED 46 | jr nz, is_recvF 47 | checkSent: 48 | ld bc, ZXUNO_REG : in A, (c) : and UART_BYTE_SENDING 49 | jr nz, checkSent 50 | 51 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 52 | 53 | ld bc, ZXUNO_REG : pop af : out (c), a 54 | ret 55 | is_recvF: 56 | push af : push hl 57 | 58 | ld hl, is_recv : ld a, 1 : ld (hl), a 59 | 60 | pop hl : pop af 61 | jr checkSent 62 | 63 | ; Is data avail in UART 64 | ; NZ - Data Presents 65 | ; Z - Data absent 66 | uartAvail: 67 | ld a, (is_recv) : and 1 : ret nz 68 | ld a, (poked_byte) : and 1 : ret nz 69 | 70 | call uartRead 71 | 72 | push af : ld a, b : and 1 : jr z, noneData : pop af 73 | 74 | push af 75 | ld hl, byte_buff : ld (hl), a : ld hl, poked_byte : ld a, 1 : ld (hl), a 76 | pop af 77 | 78 | ld b, a : ld a, 1 : or a : ld a, b 79 | ret 80 | noneData: 81 | pop bc : xor a 82 | ret 83 | 84 | 85 | uartRead: 86 | call _uartRead 87 | push af 88 | ld a, 1 : and b : jr z, .exit 89 | pop af 90 | push af 91 | call putC 92 | pop af 93 | ld b,1 94 | ret 95 | .exit 96 | pop af 97 | ld b, 0 98 | ret 99 | ; Read byte from UART 100 | ; A: byte 101 | ; B: 102 | ; 1 - Was read 103 | ; 0 - Nothing to read 104 | _uartRead: 105 | ld a, (poked_byte) : and 1 : jr nz, retBuff 106 | 107 | ld a, (is_recv) : and 1 : jr nz, recvRet 108 | 109 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 110 | ld bc, ZXUNO_REG : in a, (c) : and UART_BYTE_RECIVED 111 | jr nz, retReadByte 112 | 113 | ld b, 0 114 | ret 115 | 116 | retReadByte: 117 | xor a : ld (is_recv), a 118 | 119 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 120 | ld bc, ZXUNO_REG : in a, (c) 121 | 122 | ld b, 1 123 | ret 124 | 125 | recvRet: 126 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c),a 127 | 128 | ld bc, ZXUNO_REG : in a, (c) 129 | ld hl, is_recv : ld (hl), 0 130 | ld b, 1 131 | ret 132 | 133 | retBuff 134 | xor a : ld (poked_byte), a : ld a, (byte_buff) 135 | ld b, 1 136 | ret 137 | 138 | poked_byte defb 0 139 | byte_buff defb 0 140 | is_recv defb 0 141 | 142 | setSpeed: 143 | ld hl, set_speed_cmd 144 | jp uartWriteStringZ 145 | 146 | 147 | set_speed_cmd db "AT+UART_DEF=115200,8,1,0,2", 13, 10, 0 -------------------------------------------------------------------------------- /netman/utils.asm: -------------------------------------------------------------------------------- 1 | bankm equ 23388 2 | 3 | ; A - memory bank 4 | changeBank: 5 | ld bc, #7ffd : or #18 : out (c), a : ld (bankm), a 6 | ret 7 | 8 | ; Pushes to UART zero-terminated string 9 | ; HL - string poiner 10 | uartWriteStringZ: 11 | ld a, (hl) : and a : ret z 12 | 13 | push hl : call uartWriteByte : pop hl 14 | 15 | inc hl 16 | jp uartWriteStringZ 17 | 18 | ; Print zero-terminated string 19 | ; HL - string pointer 20 | putStringZ: 21 | printZ64: 22 | ld a,(hl) : and a : ret z 23 | 24 | push hl : call putC : pop hl 25 | 26 | inc hl 27 | jr printZ64 28 | 29 | 30 | printL64: 31 | ld a, (hl) 32 | 33 | and a : ret z 34 | cp #0A : ret z 35 | cp #0D : ret z 36 | 37 | push hl : call putC : pop hl 38 | 39 | inc hl 40 | jr printL64 41 | 42 | ; HL - string 43 | ; Return: bc - len 44 | getStringLength: 45 | ld bc, 0 46 | strLnLp 47 | ld a, (hl) : and a : ret z 48 | inc bc 49 | inc hl 50 | jr strLnLp 51 | 52 | SkipWhitespace: 53 | ld a, (hl) 54 | 55 | cp ' ' : ret nz 56 | 57 | inc hl 58 | jr SkipWhitespace 59 | 60 | findEnd: 61 | ld a,(hl) 62 | 63 | and a : ret z 64 | 65 | inc hl 66 | jr findEnd 67 | -------------------------------------------------------------------------------- /netman/wifi.asm: -------------------------------------------------------------------------------- 1 | ; Initialize WiFi chip and connect to WiFi 2 | initWifi: 3 | call uartBegin 4 | 5 | ld hl, cmd_plus : call uartWriteStringZ 6 | ei 7 | ld b,#ff 8 | wlp: 9 | halt : djnz wlp 10 | 11 | ld hl, cmd_rst : call uartWriteStringZ 12 | rstLp: 13 | call uartReadBlocking : call pushRing 14 | 15 | ld hl, response_rdy : call searchRing : cp 1 : jr nz, rstLp 16 | 17 | ; WiFi client mode 18 | ld hl, cmd_mode : call okErrCmd : and 1 : jr z, errInit 19 | ; Disable ECHO. BTW Basic UART test 20 | ld hl, cmd_at : call okErrCmd : and 1 : jr z, errInit 21 | ; Lets disconnect from last AP 22 | ld hl, cmd_cwqap : call okErrCmd 23 | ; Single connection mode 24 | ld hl, cmd_cmux : call okErrCmd : and 1 : jr z, errInit 25 | 26 | ; FTP enables this info? We doesn't need it :-) 27 | ld hl, cmd_inf_off : call okErrCmd : and 1 : jr z, errInit 28 | ret 29 | errInit 30 | ld hl, log_err : call putStringZ 31 | jr $ 32 | 33 | 34 | ; Send AT-command and wait for result. 35 | ; HL - Z-terminated AT-command(with CR/LF) 36 | ; A: 37 | ; 1 - Success 38 | ; 0 - Failed 39 | okErrCmd: 40 | call uartWriteStringZ 41 | okErrCmdLp: 42 | call uartReadBlocking : call pushRing 43 | 44 | ld hl, response_ok : call searchRing : cp 1 : jr z, okErrOk 45 | ld hl, response_err : call searchRing : cp 1 : jr z, okErrErr 46 | ld hl, response_fail : call searchRing : cp 1 : jr z, okErrErr 47 | 48 | jp okErrCmdLp 49 | okErrOk 50 | ld a, 1 51 | ret 52 | okErrErr 53 | ld a, 0 54 | ret 55 | 56 | 57 | cmd_plus defb "+++", 0 58 | cmd_rst defb "AT+RST",13, 10, 0 59 | cmd_at defb "ATE0", 13, 10, 0 ; Disable echo - less to parse 60 | cmd_mode defb "AT+CWMODE_DEF=1",13,10,0 ; Client mode 61 | cmd_cmux defb "AT+CIPMUX=0",13,10,0 ; Single connection mode 62 | cmd_cwqap defb "AT+CWQAP",13,10,0 ; Disconnect from AP 63 | cmd_inf_off defb "AT+CIPDINFO=0",13,10,0 ; doesn't send me info about remote port and ip 64 | 65 | crlf defb 13,10, 0 66 | 67 | cmd_ap1 defb "AT+CWJAP_DEF=", #22, 0 68 | cmd_ap2 defb #22, ",", #22, 0 69 | cmd_ap3 defb #22, 13, 10, 0 70 | 71 | response_rdy defb 'ready', 0 72 | response_ok defb 'OK', 13, 10, 0 ; Sucessful operation 73 | response_err defb 13,10,'ERROR',13,10,0 ; Failed operation 74 | response_fail defb 13,10,'FAIL',13,10,0 ; Failed connection to WiFi. For us same as ERROR 75 | 76 | log_err defb 'Failed initialize modem!',13, 0 77 | 78 | 79 | bytes_avail defw 0 80 | sbyte_buff defb 0, 0 81 | 82 | send_prompt defb ">",0 83 | 84 | ; WiFi configuration 85 | conf_file defb "iw.cfg",0 86 | -------------------------------------------------------------------------------- /netman/zifi-uart.asm: -------------------------------------------------------------------------------- 1 | ZIFI_CMD_REG = #C7EF 2 | ZIFI_ERR_REG = #C7EF 3 | ZIFI_DATA_REG = #BFEF 4 | ZIFI_FIFO_IN = #C0EF 5 | ZIFI_FIFO_OUT = #C1EF 6 | 7 | ZIFI_CMD_CLEAR_FIFO_IN = #01 8 | ZIFI_CMD_CLEAR_FIFO_OUT = #02 9 | ZIFI_CMD_CLEAR_FIFO_BOTH = #03 10 | ZIFI_CMD_API_DISABLE = #F0 11 | ZIFI_CMD_API_ENABLE = #F1 12 | ZIFI_CMD_API_VERSION = #FF 13 | 14 | ; Enable UART 15 | ; Cleaning all flags by sending api enable command and clear command to both fifo 16 | ; Wastes AF and BC 17 | uartBegin: 18 | ld bc, ZIFI_CMD_REG : ld a, ZIFI_CMD_API_ENABLE : out (c), a 19 | ld bc, ZIFI_CMD_REG : ld a, ZIFI_CMD_CLEAR_FIFO_BOTH : out (c), a 20 | ld bc, ZIFI_CMD_REG : ld a, ZIFI_CMD_API_VERSION : out (c), a 21 | ld bc, ZIFI_ERR_REG : in a, (c) 22 | cp 255 23 | jp nz, retUartBegin 24 | 25 | haltUartBegin: 26 | ld hl, nozifi_msg : call putStringZ 27 | jp uartBegin 28 | 29 | retUartBegin: 30 | ld hl, zifi_api_msg : call putStringZ 31 | ld b, #ff 32 | ret 33 | 34 | ; Blocking read one byte 35 | uartReadBlocking: 36 | call uartRead 37 | push af : ld a, 1 : and b : jr nz, urb : pop af 38 | jp uartReadBlocking 39 | urb: 40 | pop af 41 | ret 42 | 43 | readSilient: 44 | call _uartRead 45 | push af : ld a, 1 : and b : jr nz, .exit : pop af 46 | jp readSilient 47 | .exit 48 | pop af 49 | ret 50 | 51 | ; Write single byte to UART 52 | ; A - byte to write 53 | ; BC will be wasted 54 | uartWriteByte: 55 | push af 56 | ld bc, ZIFI_DATA_REG : out (c), a 57 | pop af 58 | ret 59 | 60 | uartRead: 61 | call _uartRead 62 | push af 63 | ld a,1 : and b : jr z, .exit 64 | pop af 65 | push af 66 | call putC 67 | pop af 68 | ld b,1 69 | ret 70 | .exit 71 | pop af 72 | ld b,0 73 | ret 74 | 75 | ; Read byte from UART 76 | ; A: byte 77 | ; B: 78 | ; 1 - Was read 79 | ; 0 - Nothing to read 80 | _uartRead: 81 | ld bc, ZIFI_FIFO_IN : in a, (c) 82 | cp 0 83 | jp nz, retReadByte 84 | 85 | noData: 86 | xor a 87 | ld b, 0 88 | ret 89 | 90 | retReadByte: 91 | ld bc, ZIFI_DATA_REG : in a, (c) 92 | ld b, 1 93 | ret 94 | 95 | setSpeed: 96 | ld hl, set_speed_cmd 97 | jp uartWriteStringZ 98 | 99 | set_speed_cmd db "AT+UART_DEF=115200,8,1,0,2", 13, 10, 0 100 | nozifi_msg db 'ZiFi hardware is not available...', 0 101 | zifi_api_msg db 'ZiFi API available...', 0 102 | -------------------------------------------------------------------------------- /tape/Makefile: -------------------------------------------------------------------------------- 1 | all: ugoph.bin 2 | 3 | ugoph.bin: *.asm 4 | sjasmplus main.asm 5 | 6 | clean: 7 | rm ugoph.bin ugoph.tap 8 | -------------------------------------------------------------------------------- /tape/README.md: -------------------------------------------------------------------------------- 1 | # uGoph - gopher client for ZX-Uno(and possible other zx-spectrums) 2 | 3 | ## Requirements 4 | 5 | For running this version you need: 6 | * Zx-spectrum 128k(or clone) with Wifi addon connected to AY-3-8912 7 | * Stored WiFi creds via [.iwconfig](https://github.com/antoniovillena/zxuno/tree/master/software/iwconfig) utility. 8 | 9 | For development you need only sjasmplus. 10 | 11 | ## Supported features 12 | 13 | Current version supports: 14 | 15 | * Rendering gopher-pages(catalogs) 16 | * Navigation between pages and servers 17 | * Rendering plain-text pages 18 | * Displaying zx-spectrum screens 19 | * Playing PT3 and PT2 music(including TruboSound tracks) 20 | * Downloading binary files to SD card 21 | * Opening specified server(only by root path) 22 | 23 | ## Legals 24 | 25 | (c) 2019 Alexander Sharikhin 26 | 27 | This program is free software: you can redistribute it and/or modify 28 | it under the terms of the GNU General Public License as published by 29 | the Free Software Foundation, either version 3 of the License, or 30 | (at your option) any later version. 31 | 32 | This program is distributed in the hope that it will be useful, 33 | but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | GNU General Public License for more details. 36 | 37 | You should have received a copy of the GNU General Public License 38 | along with this program. If not, see . 39 | -------------------------------------------------------------------------------- /tape/esxdos.asm: -------------------------------------------------------------------------------- 1 | ; API methods 2 | ESX_GETSETDRV = #89 3 | ESX_FOPEN = #9A 4 | ESX_FCLOSE = #9B 5 | ESX_FSYNC = #9C 6 | ESX_FREAD = #9D 7 | ESX_FWRITE = #9E 8 | 9 | ; File modes 10 | FMODE_READ = #01 11 | FMODE_WRITE = #06 12 | FMODE_CREATE = #0E 13 | 14 | ; Returns: 15 | ; A - current drive 16 | getDefaultDrive: 17 | ld a, 0 : rst #8 18 | defb ESX_GETSETDRV 19 | ret 20 | 21 | ; Opens file on default drive 22 | ; B - File mode 23 | ; HL - File name 24 | ; Returns: 25 | ; A - file stream id 26 | fopen: 27 | push bc : push hl 28 | call getDefaultDrive 29 | pop ix : pop bc 30 | rst #8 31 | defb ESX_FOPEN 32 | ret 33 | 34 | ; A - file stream id 35 | fclose: 36 | rst #8 37 | defb ESX_FCLOSE 38 | ret 39 | 40 | ; A - file stream id 41 | ; BC - length 42 | ; HL - buffer 43 | ; Returns 44 | ; BC - length(how much was actually read) 45 | fread: 46 | push hl : pop ix 47 | rst #8 48 | defb ESX_FREAD 49 | ret 50 | 51 | ; A - file stream id 52 | ; BC - length 53 | ; HL - buffer 54 | ; Returns: 55 | ; BC - actually written bytes 56 | fwrite: 57 | push hl : pop ix 58 | rst #8 59 | defb ESX_FWRITE 60 | ret 61 | 62 | ; A - file stream id 63 | fsync: 64 | rst #8 65 | defb ESX_FSYNC 66 | ret 67 | -------------------------------------------------------------------------------- /tape/font.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/tape/font.bin -------------------------------------------------------------------------------- /tape/gopher.asm: -------------------------------------------------------------------------------- 1 | ; hl - server 2 | ; de - path 3 | ; bc - port 4 | openPage: 5 | ld (srv_ptr), hl : ld (path_ptr), de : ld (port_ptr), bc 6 | xor a : call changeBank 7 | 8 | ex hl, de : ld de, hist : ld bc, 322 : ldir 9 | 10 | ld hl, (srv_ptr) : ld de, (path_ptr) : ld bc, (port_ptr) 11 | call makeRequest 12 | 13 | xor a : call changeBank 14 | ld hl, page_buffer : xor a : ld (hl), a : ld de, page_buffer + 1 : ld bc, #ffff - page_buffer - 1 : ldir 15 | 16 | ld hl, page_buffer : call loadData 17 | 18 | xor a : ld (show_offset), a 19 | inc a : ld (cursor_pos), a 20 | ret 21 | 22 | srv_ptr dw 0 23 | path_ptr dw 0 24 | port_ptr dw 0 25 | 26 | ; HL - domain stringZ 27 | ; DE - path stringZ 28 | ; BC - port stringZ 29 | makeRequest: 30 | ld (srv_ptr), hl : ld (path_ptr), de : ld (port_ptr), bc 31 | 32 | ld hl, downloading_msg : call showTypePrint 33 | 34 | xor a : call changeBank 35 | 36 | ; Open TCP connection 37 | ld hl, cmd_open1 : call uartWriteStringZ 38 | ld hl, (srv_ptr) : call uartWriteStringZ 39 | ld hl, cmd_open2 : call uartWriteStringZ 40 | ld hl, (port_ptr) : call uartWriteStringZ 41 | ld hl, cmd_open3 : call okErrCmd 42 | 43 | cp 1 : jp nz, reqErr 44 | 45 | ; Send request 46 | ld hl, cmd_send : call uartWriteStringZ 47 | ld hl, (path_ptr) 48 | call getStringLength 49 | push bc : pop hl : inc hl : inc hl : call B2D16 50 | 51 | ld hl, B2DBUF : call SkipWhitespace : call uartWriteStringZ 52 | ld hl, crlf : call okErrCmd 53 | 54 | cp 1 : jp nz, reqErr 55 | wPrmt: 56 | call uartReadBlocking : call pushRing 57 | ld hl, send_prompt : call searchRing : cp 1 : jr nz, wPrmt 58 | 59 | ld hl, (path_ptr) : call uartWriteStringZ 60 | 61 | ld hl, crlf : call uartWriteStringZ : ld a, 1 : ld (connectionOpen), a 62 | ret 63 | 64 | reqErr: 65 | ld sp, stack_pointer 66 | 67 | ld hl, connectionError : call showTypePrint : call wSec 68 | xor a : ld (connectionOpen), a 69 | 70 | call initWifi ; Trying reset ESP and continue work 71 | jp historyBack ; Let's try back home on one URL :) 72 | 73 | ; Load data to ram via gopher 74 | ; HL - data pointer 75 | ; In data_recv downloaded volume 76 | loadData: 77 | ld (data_pointer), hl 78 | ld hl, 0 : ld (data_recv), hl 79 | lpLoop: 80 | call getPacket 81 | 82 | ld a, (connectionOpen) : and a : jp z, ldEnd 83 | 84 | ld bc, (bytes_avail) : ld de, (data_pointer) : ld hl, output_buffer : ldir 85 | ld hl, (data_pointer) : ld de, (bytes_avail) : push de : add hl, de : ld (data_pointer), hl : pop de 86 | ld hl, (data_recv) : add hl, de : ld (data_recv), hl 87 | 88 | jp lpLoop 89 | 90 | ldEnd 91 | ld hl, 0 : ld (data_pointer), hl 92 | ret 93 | 94 | ; Download file via gopher 95 | ; HL - filename 96 | downloadData: 97 | ret 98 | 99 | openURI: 100 | call cleanIBuff 101 | 102 | ld b, 19: ld c, 0 :call gotoXY : ld hl, cleanLine : call printZ64 103 | ld b, 19: ld c, 0 : call gotoXY : ld hl, hostTxt : call printZ64 104 | 105 | call input 106 | 107 | ld a, (iBuff) : or a : jp z, backToPage 108 | 109 | ld b, 19 : ld c, 0 : call gotoXY : ld hl, cleanLine : call printZ64 110 | 111 | ld hl, iBuff : ld de, d_host : ld bc, 65 : ldir 112 | 113 | ld hl, d_host : ld de, d_path : ld bc, d_port : call openPage 114 | 115 | jp showPage 116 | 117 | 118 | data_pointer defw #4000 119 | data_recv defw 0 120 | fstream defb 0 121 | 122 | closed_callback 123 | xor a 124 | ld (connectionOpen), a 125 | ei 126 | ret 127 | 128 | hostTxt db 'Enter host: ', 0 129 | 130 | d_path db '/' 131 | defs 254 132 | d_host defs 70 133 | d_port db '70' 134 | defs 5 135 | 136 | hist ds 322 137 | connectionOpen db 0 138 | downloading_msg db 'Downloading...', 0 139 | 140 | connectionError db "Issue with making request - trying get back", 0 141 | -------------------------------------------------------------------------------- /tape/keyboard.asm: -------------------------------------------------------------------------------- 1 | CURKEY = 23560 2 | 3 | ; Returns in A key code or zero if key wans't pressed 4 | inkey: 5 | ld hl, CURKEY : ld a, (hl) 6 | push af : xor a : ld (hl), a : pop af 7 | ret 8 | 9 | findZero: 10 | ld a, (hl) : or a : ret z 11 | inc hl 12 | jp findZero 13 | 14 | input: 15 | ld b, 20 : ld c, 0 : call gotoXY 16 | 17 | ld hl, cleanLine : call printZ64 18 | 19 | ld hl, iBuff : call findZero 20 | iLp: 21 | halt 22 | push hl 23 | 24 | ld b, 20 : ld c, 0: call gotoXY 25 | ld hl, iBuff : call printZ64 26 | 27 | ld a, '_' : call putC : ld a, ' ' : call putC 28 | 29 | call inkey 30 | 31 | cp 0 : jr z, iNth 32 | cp 12 : jr z, iBS 33 | cp 13 : jr z, iRet 34 | 35 | pop hl : ld (hl), A : push hl 36 | 37 | ld de, iBuff + 62 : sub hl, de : ld a, h : or l : jr z, iCr 38 | 39 | pop hl : inc hl 40 | jr iLp 41 | 42 | iBS: pop hl : push hl 43 | ld de, iBuff : sub hl, de : ld a, h : or l 44 | pop hl :jr z, iLp 45 | 46 | dec hl : ld (hl), 0 47 | jr iLp 48 | 49 | iCr pop hl : xor a : ld (hl), a : push hl 50 | iNth pop hl: jr iLp 51 | 52 | cleanIBuff: 53 | ld bc, 64 : ld hl, iBuff : ld de, iBuff + 1 : ld (hl), 0 : ldir 54 | ret 55 | 56 | iRet: 57 | pop hl 58 | 59 | ld b, 20 : ld c, 0 : call gotoXY 60 | ld hl, cleanLine :call printZ64 61 | ret 62 | 63 | iBuff defs 65 -------------------------------------------------------------------------------- /tape/main.asm: -------------------------------------------------------------------------------- 1 | ;; (c) 2019 Alexander Sharikhin 2 | ;; This program is free software: you can redistribute it and/or modify 3 | ;; it under the terms of the GNU General Public License as published by 4 | ;; the Free Software Foundation, either version 3 of the License, or 5 | ;; (at your option) any later version. 6 | ;; 7 | ;; This program is distributed in the hope that it will be useful, 8 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | ;; GNU General Public License for more details. 11 | ;; 12 | ;; You should have received a copy of the GNU General Public License 13 | ;; along with this program. If not, see . 14 | 15 | DEVICE ZXSPECTRUM128 16 | org 24100 17 | stack_pointer EQU #5aff 18 | Start: 19 | di 20 | res 4, (iy+1) 21 | call checkHighMem : jp nz, noMem 22 | 23 | xor a : out (#fe), a : call changeBank 24 | 25 | ld sp, stack_pointer 26 | 27 | ld de, #4000 : ld bc, eop - player : ld hl, player : ldir 28 | 29 | ei 30 | 31 | call renderHeader 32 | ld hl, connecting_wifi : call printZ64 33 | call initWifi 34 | 35 | call wSec 36 | 37 | ld de, path : ld hl, server : ld bc, port : call openPage 38 | 39 | jp showPage 40 | 41 | noMem: 42 | ld hl, no128k 43 | nmLp: 44 | push hl 45 | ld a, (hl) 46 | and a : jr z, $ 47 | rst #10 48 | pop hl 49 | inc hl 50 | jp nmLp 51 | 52 | 53 | wSec: ld b, 50 54 | wsLp halt : djnz wsLp 55 | 56 | include "screen64.asm" 57 | include "keyboard.asm" 58 | include "utils.asm" 59 | include "wifi.asm" 60 | include "gopher.asm" 61 | include "render.asm" 62 | include "textrender.asm" 63 | include "uart.asm" 64 | include "ring.asm" 65 | 66 | 67 | connecting_wifi db 13, 'Connecting to WiFi', 13, 0 68 | open_lbl db 'Opening connection to ', 0 69 | 70 | path db '/ncmenu' 71 | defs 248 72 | server db 'nihirash.net' 73 | defs 58 74 | port db '70' 75 | defs 5 76 | db 0 77 | page_buffer equ $ 78 | display "PAGE buffer:", $ 79 | no128k db 13, "You're in 48k mode!", 13, 13 80 | db "Current version require full", 13 81 | db "128K memory access", 13, 13 82 | db "System halted!", 0 83 | player 84 | DISPLAY "Player starts:" , $ 85 | include "vtpl.asm" 86 | DISPLAY "Player ends: ", $ 87 | ENT 88 | eop equ $ 89 | SAVEBIN "ugoph.bin", Start, $ - Start 90 | SAVETAP "ugoph.tap", Start 91 | SAVEHOB "ugoph.$c", "ugoph.c", Start, $ - Start -------------------------------------------------------------------------------- /tape/render.asm: -------------------------------------------------------------------------------- 1 | showPage: 2 | xor a : ld (show_offset), a 3 | inc a :ld (cursor_pos), a 4 | backToPage: 5 | xor a : call changeBank 6 | call renderScreen : call showCursor 7 | showLp: 8 | xor a : call changeBank 9 | controls: 10 | xor a : ld (s_show_flag), a 11 | 12 | call inkey 13 | cp 0 : jr z, showLp 14 | cp 'q' : jp z, pageCursorUp 15 | cp 'a' : jp z, pageCursorDown 16 | cp 13 : jp z, selectItem 17 | cp 'b' : jp z, historyBack 18 | cp 'o' : jp z, pageScrollUp 19 | cp 'p' : jp z, pageScrollDn 20 | cp 'n' : jp z, openURI 21 | 22 | jp showLp 23 | 24 | historyBack: 25 | ld hl, server : ld de, path : ld bc, port : call openPage 26 | jp showPage 27 | 28 | pageCursorUp: 29 | ld a, (cursor_pos) 30 | dec a 31 | cp 0 : jp z, pageScrollUp 32 | 33 | push af : call hideCursor : pop af : ld (cursor_pos), a : call showCursor 34 | jp showLp 35 | 36 | pageCursorDown: 37 | ld a, (cursor_pos) 38 | inc a 39 | cp 21 : jp z, pageScrollDn 40 | 41 | push af : call hideCursor : pop af : ld (cursor_pos), a : call showCursor 42 | jp showLp 43 | 44 | pageScrollDn: 45 | ld hl, (show_offset) : ld de, 20 : add hl, de : ld (show_offset), hl 46 | ld a, 1 : ld (cursor_pos), a 47 | 48 | jp backToPage 49 | 50 | pageScrollUp: 51 | ld a, (show_offset) : and a : jp z, showLp 52 | ld hl, (show_offset) : ld de, 20 : sub hl, de : ld (show_offset), hl 53 | ld a, 20 : ld (cursor_pos), a 54 | 55 | jp backToPage 56 | 57 | selectItem: 58 | ld a, (cursor_pos) : dec a : ld b, a : ld a, (show_offset) : add b : ld b, a 59 | call findLine 60 | 61 | ld a, h : or l : jp z, showLp 62 | 63 | ld a, (hl) 64 | 65 | cp '1' : jr z, downPg 66 | cp '0' : jr z, downPg 67 | cp '9' : jp z, downFl 68 | cp '7' : jr z, userInput 69 | 70 | jp showLp 71 | 72 | userInput: 73 | call cleanIBuff : call input 74 | 75 | call extractInfo 76 | ld hl, file_buffer : call findEnd : ld a, 9 : ld (hl), a : inc hl 77 | ex hl, de : ld hl, iBuff : ld bc, 64 : ldir 78 | 79 | ld hl, hist : ld de, path : ld bc, 322 : ldir 80 | 81 | ld hl, server_buffer : ld de, file_buffer : ld bc, port_buffer : call openPage 82 | 83 | jp showPage 84 | 85 | downPg: 86 | push af 87 | call extractInfo 88 | 89 | ld hl, hist : ld de, path : ld bc, 322 : ldir 90 | 91 | ld hl, server_buffer : ld de, file_buffer : ld bc, port_buffer : call openPage 92 | 93 | pop af 94 | 95 | cp '1' : jp z,showPage 96 | cp '0' : jp z, showText 97 | 98 | jp showLp 99 | 100 | downFl: 101 | call extractInfo : call clearRing : call cleanIBuff 102 | 103 | ld hl, file_buffer : call findFnme : jp isOpenable 104 | dfl: 105 | ld hl, file_buffer : call findFnme 106 | ld de, iBuff : ld bc, 65 : ldir 107 | 108 | call input 109 | 110 | ld hl, iBuff : call showTypePrint 111 | 112 | ld hl, server_buffer : ld de, file_buffer : ld bc, port_buffer : call makeRequest 113 | 114 | xor a : call changeBank 115 | 116 | ld hl, iBuff : call downloadData 117 | 118 | call hideCursor : call showCursor 119 | 120 | jp backToPage 121 | 122 | isOpenable: 123 | ld a, (hl) : and a : jr z, checkFile 124 | push hl : call pushRing : pop hl 125 | inc hl 126 | jr isOpenable 127 | 128 | imgExt db ".scr", 0 129 | imgExt2 db ".SCR", 0 130 | pt3Ext db ".pt3", 0 131 | pt3Ext2 db ".PT3", 0 132 | pt2Ext db ".pt2", 0 133 | pt2Ext2 db ".PT2", 0 134 | 135 | checkFile: 136 | ;; Images 137 | ld hl, imgExt : call searchRing : cp 1 : jr z, loadImage 138 | ld hl, imgExt2 : call searchRing : cp 1 : jr z, loadImage 139 | ;; Music 140 | xor a: ld (#400A), a 141 | 142 | ld hl, pt3Ext : call searchRing : cp 1 : jr z, playMusic 143 | ld hl, pt3Ext2 : call searchRing : cp 1 : jr z, playMusic 144 | 145 | ld a, 2 : ld (#400A), a 146 | 147 | ld hl, pt2Ext2 : call searchRing : cp 1 : jr z, playMusic 148 | ld hl, pt2Ext : call searchRing : cp 1 : jr z, playMusic 149 | 150 | jp dfl 151 | loadImage: 152 | ld hl, server_buffer : ld de, file_buffer : ld bc, port_buffer : call makeRequest 153 | 154 | ld a, 7 : call changeBank 155 | ld hl, #c000 : call loadData 156 | 157 | out (#fe), a 158 | ld b, 255 159 | wKey: 160 | halt 161 | ld a, (s_show_flag) : and a : jr z, wK2 162 | dec b : jp z, startNext 163 | wK2: 164 | call inkey 165 | or a : jr z, wKey 166 | cp 's' : jr z, toggleSS 167 | xor a : call changeBank 168 | jp backToPage 169 | 170 | toggleSS: 171 | ld a, (s_show_flag) : xor #ff : ld (s_show_flag), a 172 | and a : jp nz, startNext 173 | jp backToPage 174 | 175 | playMusic: 176 | ld hl, hist : ld de, path : ld bc, 322 : ldir 177 | 178 | ld hl, (show_offset) : ld (offset_tmp), hl 179 | 180 | xor a : call changeBank 181 | ld hl, server_buffer : ld de, file_buffer : ld bc, port_buffer : call openPage 182 | 183 | ld hl, playing : call showTypePrint 184 | 185 | xor a : call changeBank 186 | 187 | ld a, (#400A) : or 1 : ld (#400A), a 188 | ld hl, page_buffer : call #4003 189 | playLp: 190 | halt : di : call #4005 : ei 191 | xor a : in a, (#fe) : cpl : and 31 : jp nz, stopPlay 192 | ld a, (#400A) : rla : jr nc, playLp 193 | songEnded: 194 | call #4008 : call uartBegin 195 | ld hl, server : ld de, path : ld bc, port : call openPage 196 | 197 | ld hl, (offset_tmp) : ld (show_offset), hl 198 | startNext: 199 | ld a, (cursor_pos) : inc a : cp 21 : jr z, playNxtPg : ld (cursor_pos), a 200 | 201 | jr playContinue 202 | playNxtPg: 203 | ld a, (show_offset) : add 20 : ld (show_offset), a : ld a, 1 : ld (cursor_pos), a 204 | playContinue: 205 | call renderScreen : call showCursor 206 | xor a : call changeBank 207 | jp selectItem 208 | 209 | stopPlay: 210 | call #4008 : call uartBegin 211 | 212 | ld hl, server : ld de, path : ld bc, port : call openPage 213 | ld hl, (offset_tmp) : ld (show_offset), hl 214 | 215 | jp backToPage 216 | 217 | findFnme: 218 | push hl : pop de 219 | ffnmlp: 220 | ld a, (hl) 221 | 222 | cp 0 : jr z, ffnmend 223 | cp '/' : jr z, fslsh 224 | inc hl 225 | jp ffnmlp 226 | fslsh: 227 | inc hl : push hl : pop de 228 | jp ffnmlp 229 | ffnmend: 230 | push de : pop hl 231 | ret 232 | 233 | showType: 234 | ld a, (cursor_pos) : dec a : ld b, a : ld a, (show_offset) : add b : ld b, a 235 | 236 | call findLine 237 | 238 | ld a, h : or l : jr z, showTypeUnknown 239 | 240 | ld a, (hl) 241 | 242 | cp 'i' : jr z, showTypeInfo 243 | cp '9' : jr z, showTypeDown 244 | cp '1' : jr z, showTypePage 245 | cp '0' : jr z, showTypeText 246 | cp '7' : jr z, showTypeInput 247 | 248 | jr showTypeUnknown 249 | 250 | showTypeInput: 251 | ld hl, type_inpt : call showTypePrint : call showURI 252 | ret 253 | 254 | showTypeText: 255 | ld hl, type_text : call showTypePrint : call showURI 256 | ret 257 | 258 | showTypeInfo: 259 | ld hl, type_info : jp showTypePrint 260 | 261 | showTypePage: 262 | ld hl, type_page : call showTypePrint : call showURI 263 | ret 264 | 265 | showTypeDown: 266 | ld hl, type_down : call showTypePrint : call showURI 267 | ret 268 | 269 | showURI: 270 | call extractInfo : ld hl, server_buffer : call printZ64 271 | ld hl, file_buffer : call printZ64 272 | ret 273 | 274 | showTypeUnknown: 275 | ld hl, type_unkn : jp showTypePrint 276 | 277 | showTypePrint: 278 | push hl 279 | 280 | ld b, 21 : ld c, 0 : call gotoXY : ld hl, cleanLine : call printZ64 281 | ld b, 21 : ld c, 0 : call gotoXY : pop hl : jp printZ64 282 | 283 | renderHeader: 284 | call clearScreen 285 | ld a, #0F 286 | ld (attr_screen), a 287 | ld bc, 0 288 | call gotoXY 289 | 290 | ld hl, head 291 | call printZ64 292 | 293 | ld a, #07 294 | ld (attr_screen), a 295 | ret 296 | 297 | renderScreen: 298 | call renderHeader 299 | ld b, 20 300 | renderLp: 301 | push bc 302 | ld a, 20 : sub b : ld b, a : ld a, (show_offset) : add b : ld b, a 303 | call renderLine 304 | pop bc 305 | djnz renderLp 306 | ret 307 | 308 | ; b - line number 309 | renderLine: 310 | call findLine 311 | ld a, h: or l: ret z 312 | ld a, (hl) : and a : ret z 313 | inc hl 314 | call printT64 : call mvCR 315 | ret 316 | 317 | ; B - line number 318 | ; HL - pointer to line(or zero if doesn't find it) 319 | findLine: 320 | ld hl, page_buffer 321 | fndLnLp: 322 | ld a, b : and a : ret z 323 | 324 | ld a, (hl) 325 | 326 | ; Buffer ends? 327 | and a : jr z, fndEnd 328 | 329 | ; New line? 330 | cp 10 : jr z, fndLnNL 331 | 332 | inc hl 333 | jp fndLnLp 334 | 335 | fndLnNL: 336 | dec b : inc hl : jp fndLnLp 337 | fndEnd: 338 | ld hl, 0 : ret 339 | 340 | extractInfo: 341 | ld a, (cursor_pos) : dec a : ld b, a : ld a, (show_offset) : add b : ld b, a 342 | 343 | call findLine 344 | 345 | ld a, h : or l : ret z 346 | 347 | call findNextBlock 348 | 349 | inc hl : ld de, file_buffer : call extractCol 350 | inc hl : ld de, server_buffer : call extractCol 351 | inc hl : ld de, port_buffer : call extractCol 352 | ret 353 | 354 | extractCol: 355 | ld a, (hl) 356 | 357 | cp 0 : jr z, endExtract 358 | cp 09 : jr z, endExtract 359 | cp 13 : jr z, endExtract 360 | 361 | ld (de), a : inc de : inc hl 362 | jr extractCol 363 | 364 | endExtract: 365 | xor a : ld (de), a 366 | ret 367 | 368 | findNextBlock: 369 | ld a, (hl) 370 | 371 | ; TAB 372 | cp 09 : ret z 373 | ; New line 374 | cp 13 : ret z 375 | ; End of buffer 376 | cp 0 : ret z 377 | 378 | inc hl 379 | jp findNextBlock 380 | 381 | s_show_flag db 0 382 | offset_tmp dw 0 383 | show_offset db 0 384 | cursor_pos db 1 385 | 386 | head db " UGophy - ZX-128 Gopher client v. 0.9h (c) Alexander Sharikhin ", 13,0 387 | 388 | cleanLine db " ",0 389 | playing db "Playing... Hold to stop!", 0 390 | type_inpt db "User input: ", 0 391 | type_text db "Text file: ", 0 392 | type_info db "Information ", 0 393 | type_page db "Page: ", 0 394 | type_down db "File to download: ", 0 395 | type_unkn db "Unknown type ", 0 396 | 397 | display $ 398 | 399 | file_buffer defs 255 ; URI path 400 | server_buffer defs 70 ; Host name 401 | port_buffer defs 7 ; Port 402 | 403 | end_inf_buff equ $ 404 | 405 | 406 | 407 | -------------------------------------------------------------------------------- /tape/ring.asm: -------------------------------------------------------------------------------- 1 | ; Pushes A to ring buffer 2 | pushRing 3 | push af 4 | ld b, 32 : ld hl, ring_buffer + 1 : ld de, ring_buffer 5 | ringL 6 | ld a, (hl) : ld (de), a : inc hl : inc de : djnz ringL 7 | pop af 8 | ld hl, ring_buffer + 31 : ld (hl), a 9 | ret 10 | 11 | ; HL - Compare string(null terminated) 12 | ; A - 0 NOT Found 13 | ; 1 Found 14 | searchRing: 15 | ld b, 0 : push hl 16 | serlp: 17 | ld a, (hl) : inc hl : inc b : and a : jp nz, serlp 18 | dec b : pop hl : push bc : push hl 19 | SRWork: 20 | pop hl 21 | ld de, ring_buffer + 32 22 | srcLp 23 | dec de : djnz srcLp 24 | pop bc 25 | ringCmpLp 26 | push bc : push af 27 | ld a, (de) : ld b, a 28 | pop af : ld a, (hl) : cp b : pop bc : ld a, 0 : ret nz 29 | inc de : inc hl 30 | djnz ringCmpLp 31 | ld a, 1 32 | ret 33 | 34 | clearRing: 35 | xor a : ld hl, ring_buffer : ld de, ring_buffer + 1 : ld bc, 32 : ld (hl), a : ldir 36 | ret 37 | 38 | ring_buffer dup 33 39 | defb 0 40 | edup -------------------------------------------------------------------------------- /tape/screen64.asm: -------------------------------------------------------------------------------- 1 | clearScreen: 2 | ld a, 7 : call changeBank 3 | 4 | ld c, #fe 5 | ld a, 0 6 | out (c), a 7 | ld hl, #c000 8 | ld (hl), 0 9 | ld de, #c001 10 | ld bc, #17FF 11 | ldir 12 | ld hl, #d800 13 | ld a, (attr_screen) 14 | ld (hl), a 15 | ld de, #d801 16 | ld bc, #2FF 17 | ldir 18 | ld bc, 0 19 | call gotoXY 20 | ret 21 | 22 | showCursor: 23 | ld a, 7 : call changeBank 24 | 25 | ld a, (cursor_pos) 26 | ld c, 0 27 | ld b, a 28 | call bc_to_attr 29 | ld (hl), #C 30 | ld de, hl 31 | inc de 32 | ld bc, 31 33 | ldir 34 | call showType 35 | ret 36 | 37 | hideCursor: 38 | ld a, 7 : call changeBank 39 | 40 | ld a, (cursor_pos) 41 | ld b, a 42 | ld c, 0 43 | call bc_to_attr 44 | ld (hl), #07 45 | ld de, hl 46 | inc de 47 | ld bc, 31 48 | ldir 49 | ret 50 | 51 | 52 | ; Print just one symbol 53 | ; A - symbol 54 | putC 55 | cp 13 56 | jr z, mvCR 57 | or a 58 | cp ' ' 59 | ret c 60 | 61 | push af 62 | ld a, 7 63 | call changeBank 64 | pop af 65 | 66 | ld hl, single_symbol 67 | ld (hl), a 68 | ld hl, single_symbol_print 69 | jp print64 70 | 71 | mvCR 72 | ld bc, (col_screen) 73 | inc b 74 | ld c, 0 75 | ld a, 0 76 | ld (half_tile_screen), a 77 | call gotoXY 78 | ret 79 | 80 | ; Set console coordinates 81 | ; b = row(0..23), c = column (0..63) 82 | ; 83 | gotoXY: 84 | ld a, 0 85 | ld (half_tile_screen), a 86 | ld (col_screen), bc 87 | ld a, 22 88 | cp b 89 | jp s, scrl 90 | ret 91 | scrl 92 | ld b, 22 93 | ld (col_screen) ,bc 94 | jp scroll_up8 95 | 96 | 97 | ; Put string with coordinates 98 | ; b= row (0..23), c=col (0..63) 99 | ; hl - string pointer that's begins from symbol count 100 | printAt64: 101 | call gotoXY 102 | 103 | ; Put string 104 | ; hl - string pointer that's begins from symbol count 105 | print64 106 | ld a,(hl) 107 | and a 108 | ret z 109 | 110 | push hl 111 | call calc_addr_attr 112 | ld a,(attr_screen) 113 | ld (hl),a 114 | pop hl 115 | 116 | call calc_addr_scr 117 | 118 | ld a,(half_tile_screen) 119 | bit 0,a 120 | ld a,(hl) 121 | jp nz,print64_4 122 | print64_3 123 | push af 124 | push hl 125 | call calc_addr_attr 126 | ld a,(attr_screen) 127 | ld (hl),a 128 | pop hl 129 | 130 | inc hl 131 | push hl 132 | 133 | ld a,(hl) 134 | sub 32 135 | ld l,a 136 | ld h,0 137 | add hl,hl 138 | ld c,l 139 | ld b,h 140 | add hl,hl 141 | add hl,bc 142 | ld bc,font64 143 | add hl,bc 144 | 145 | push de 146 | 147 | ld b,6 148 | xor a 149 | ld (de),a 150 | print64_1 151 | inc d 152 | ld a,(hl) 153 | and #f0 154 | ld (de),a 155 | inc hl 156 | djnz print64_1 157 | 158 | inc d 159 | xor a 160 | ld (de),a 161 | 162 | ld a,1 163 | ld (half_tile_screen),a 164 | 165 | pop de 166 | pop hl 167 | pop af 168 | 169 | dec a 170 | ret z 171 | 172 | print64_4 173 | push af 174 | 175 | inc hl 176 | push hl 177 | 178 | ld a,(hl) 179 | sub 32 180 | ld l,a 181 | ld h,0 182 | add hl,hl 183 | ld c,l 184 | ld b,h 185 | add hl,hl 186 | add hl,bc 187 | ld bc,font64 188 | add hl,bc 189 | 190 | push de 191 | 192 | ld b,6 193 | xor a 194 | ld (de),a 195 | print64_2 196 | inc d 197 | ld a,(hl) 198 | and #0f 199 | ld c,a 200 | ld a,(de) 201 | or c 202 | ld (de),a 203 | inc hl 204 | djnz print64_2 205 | 206 | inc d 207 | xor a 208 | ld (de),a 209 | 210 | ld (half_tile_screen),a 211 | 212 | pop de 213 | 214 | call move_cr64 215 | 216 | pop hl 217 | pop af 218 | dec a 219 | 220 | jp nz,print64_3 221 | 222 | ret 223 | 224 | ; move cursor 225 | move_cr64 226 | inc de 227 | 228 | ld hl,col_screen 229 | inc (hl) 230 | ld a,(hl) 231 | 232 | cp 32 233 | ret c 234 | 235 | xor a 236 | ld (half_tile_screen),a 237 | ld (hl),a 238 | ld c,a 239 | 240 | inc hl 241 | inc (hl) 242 | ld a,(hl) 243 | ld b,a 244 | 245 | cp 24 246 | jp c,move_cr64_01 247 | 248 | ld a,23 249 | ld (hl),a 250 | ld b,a 251 | 252 | push bc 253 | call scroll_up8 254 | pop bc 255 | 256 | move_cr64_01 257 | call calc_addr_scr 258 | ret 259 | 260 | calc_addr_scr 261 | ld a,b 262 | ld d,a 263 | rrca 264 | rrca 265 | rrca 266 | and a,224 267 | add a,c 268 | ld e,a 269 | ld a,d 270 | and 24 271 | or #c0 272 | ld d,a 273 | ret 274 | 275 | calc_addr_attr 276 | ld bc,(col_screen) 277 | bc_to_attr: 278 | ld a,b 279 | rrca 280 | rrca 281 | rrca 282 | ld l,a 283 | and 31 284 | or #d8 285 | ld h,a 286 | ld a,l 287 | and 252 288 | or c 289 | ld l,a 290 | ret 291 | 292 | scroll_up8 293 | ld hl,table_addr_scr 294 | ld b,184 295 | 296 | scroll_up8_01 297 | push bc 298 | 299 | ld e,(hl) 300 | inc hl 301 | ld d,(hl) 302 | inc hl 303 | 304 | push hl 305 | 306 | ld bc,14 307 | add hl,bc 308 | ld c,(hl) 309 | inc hl 310 | ld b,(hl) 311 | 312 | ld h,b 313 | ld l,c 314 | 315 | ld bc,32 316 | ldir 317 | 318 | pop hl 319 | pop bc 320 | djnz scroll_up8_01 321 | 322 | ld b,8 323 | 324 | scroll_up8_02 325 | push bc 326 | 327 | ld e,(hl) 328 | inc hl 329 | ld d,(hl) 330 | inc hl 331 | 332 | push hl 333 | 334 | ld h,d 335 | ld l,e 336 | inc de 337 | ld (hl),0 338 | ld bc,31 339 | ldir 340 | 341 | pop hl 342 | pop bc 343 | djnz scroll_up8_02 344 | 345 | ld de,#5800 346 | ld hl,#5820 347 | ld bc,736 348 | ldir 349 | 350 | ld a,(de) 351 | 352 | ld hl,#5ae0 353 | ld de,#5ae1 354 | ld (hl),a 355 | ld bc,31 356 | ldir 357 | 358 | ret 359 | 360 | 361 | font64 incbin "font.bin" 362 | table_addr_scr 363 | defw #4000,#4100,#4200,#4300,#4400,#4500,#4600,#4700 364 | defw #4020,#4120,#4220,#4320,#4420,#4520,#4620,#4720 365 | defw #4040,#4140,#4240,#4340,#4440,#4540,#4640,#4740 366 | defw #4060,#4160,#4260,#4360,#4460,#4560,#4660,#4760 367 | defw #4080,#4180,#4280,#4380,#4480,#4580,#4680,#4780 368 | defw #40a0,#41a0,#42a0,#43a0,#44a0,#45a0,#46a0,#47a0 369 | defw #40c0,#41c0,#42c0,#43c0,#44c0,#45c0,#46c0,#47c0 370 | defw #40e0,#41e0,#42e0,#43e0,#44e0,#45e0,#46e0,#47e0 371 | 372 | defw #4800,#4900,#4a00,#4b00,#4c00,#4d00,#4e00,#4f00 373 | defw #4820,#4920,#4a20,#4b20,#4c20,#4d20,#4e20,#4f20 374 | defw #4840,#4940,#4a40,#4b40,#4c40,#4d40,#4e40,#4f40 375 | defw #4860,#4960,#4a60,#4b60,#4c60,#4d60,#4e60,#4f60 376 | defw #4880,#4980,#4a80,#4b80,#4c80,#4d80,#4e80,#4f80 377 | defw #48a0,#49a0,#4aa0,#4ba0,#4ca0,#4da0,#4ea0,#4fa0 378 | defw #48c0,#49c0,#4ac0,#4bc0,#4cc0,#4dc0,#4ec0,#4fc0 379 | defw #48e0,#49e0,#4ae0,#4be0,#4ce0,#4de0,#4ee0,#4fe0 380 | 381 | defw #5000,#5100,#5200,#5300,#5400,#5500,#5600,#5700 382 | defw #5020,#5120,#5220,#5320,#5420,#5520,#5620,#5720 383 | defw #5040,#5140,#5240,#5340,#5440,#5540,#5640,#5740 384 | defw #5060,#5160,#5260,#5360,#5460,#5560,#5660,#5760 385 | defw #5080,#5180,#5280,#5380,#5480,#5580,#5680,#5780 386 | defw #50a0,#51a0,#52a0,#53a0,#54a0,#55a0,#56a0,#57a0 387 | defw #50c0,#51c0,#52c0,#53c0,#54c0,#55c0,#56c0,#57c0 388 | defw #50e0,#51e0,#52e0,#53e0,#54e0,#55e0,#56e0,#57e0 389 | 390 | 391 | string_temp defb 0 392 | dup 255 393 | defb 32 394 | edup 395 | 396 | col_screen defb 0 397 | row_screen defb 0 398 | half_tile_screen defb 0 399 | attr_screen defb 07 400 | 401 | col_screen_temp defw 0 402 | half_tile_screen_temp defb 0 403 | 404 | single_symbol_print defb 1 405 | single_symbol defb 0 406 | -------------------------------------------------------------------------------- /tape/textrender.asm: -------------------------------------------------------------------------------- 1 | showText: 2 | xor a : ld (show_offset), a 3 | call renderTextScreen 4 | showTxLp: 5 | call txControls 6 | 7 | xor a : call changeBank 8 | 9 | dup 5 10 | halt 11 | edup 12 | jp showTxLp 13 | 14 | txControls: 15 | call inkey 16 | 17 | and a : ret z 18 | 19 | cp 'q' : jp z, txUp 20 | cp 'o' : jp z, txUp 21 | cp 'a' : jp z, txDn 22 | cp 'p' : jp z, txDn 23 | cp 'b' : jp z, historyBack 24 | cp 'n' : jp z, openURI 25 | 26 | ret 27 | 28 | txUp: 29 | ld a, (show_offset) 30 | and a : ret z 31 | 32 | sub 20 : ld (show_offset), a 33 | call renderTextScreen 34 | ret 35 | 36 | txDn: 37 | ld a, (show_offset) 38 | add 20 : ld (show_offset), a 39 | 40 | call renderTextScreen 41 | ret 42 | 43 | renderTextScreen: 44 | call renderHeader 45 | ld b, 20 46 | txRenderLp: 47 | push bc 48 | 49 | ld a, 20 : sub b : ld b, a : ld a, (show_offset) : add b : ld b, a 50 | call renderTextLine 51 | 52 | pop bc 53 | djnz txRenderLp 54 | ret 55 | 56 | 57 | renderTextLine: 58 | call findLine 59 | 60 | ld a, h : or l : ret z 61 | ld a, (hl) : and a : ret z 62 | 63 | call printL64 64 | call mvCR 65 | ret 66 | -------------------------------------------------------------------------------- /tape/tscreen.asm: -------------------------------------------------------------------------------- 1 | ; Timex screen routines 2 | 3 | showCursor: 4 | hideCursor: 5 | call showType 6 | ld a, (cursor_pos) 7 | ld d, a 8 | inverseLine: 9 | ld e, 0 10 | ld b, 64 11 | ilp 12 | push bc 13 | push de 14 | call findAddr 15 | ld a, 7 16 | call changeBank 17 | 18 | ld b, 8 19 | iCLP: 20 | ld a, (de) 21 | xor #ff 22 | ld (de), a 23 | inc d 24 | djnz iCLP 25 | pop de 26 | inc e 27 | pop bc 28 | djnz ilp 29 | 30 | ;xor a 31 | ;call changeBank 32 | 33 | ret 34 | 35 | gotoXY: 36 | ld (coords), bc 37 | ret 38 | 39 | mvCR: 40 | ld hl, (coords) 41 | inc h 42 | ld l, 0 43 | ld (coords), hl 44 | cp 24 45 | ret c 46 | ld hl, 0 47 | ld (coords), hl 48 | ret 49 | 50 | ; A - char 51 | putC: 52 | cp 13 53 | jr z, mvCR 54 | 55 | sub 32 56 | ld b, a 57 | 58 | ld de, (coords) 59 | ld a, e 60 | cp 64 61 | ret nc 62 | 63 | push bc 64 | 65 | ld a, 7 66 | call changeBank 67 | 68 | call findAddr 69 | pop af 70 | ld l, a 71 | ld h, 0 72 | add hl, hl 73 | add hl, hl 74 | add hl, hl 75 | ld bc, font 76 | add hl, bc 77 | ld b, 8 78 | pLp: 79 | ld a, (HL) 80 | ld (DE), A 81 | inc hl 82 | inc d 83 | djnz pLp 84 | ld hl, (coords) 85 | inc l 86 | ld (coords), hl 87 | ret 88 | 89 | ; D - Y 90 | ; E - X 91 | ; OUT: de - coords 92 | findAddr: 93 | ld a, e 94 | srl a 95 | ld e, a 96 | ld hl, #A000 97 | jr c, fa1 98 | ld hl, #8000 99 | fa1: 100 | LD A,D 101 | AND 7 102 | RRCA 103 | RRCA 104 | RRCA 105 | OR E 106 | LD E,A 107 | LD A,D 108 | AND 24 109 | OR 64 110 | LD D,A 111 | ADD hl, de 112 | ex hl, de 113 | ret 114 | 115 | clearScreen: 116 | 117 | ld a, 7 118 | call changeBank 119 | 120 | ld c, #ff 121 | ld a, #3E 122 | out (c), a 123 | 124 | 125 | di 126 | ld hl,0 127 | ld d,h 128 | ld e,h 129 | ld b,h 130 | ld c,b 131 | add hl,sp 132 | ld sp,#c000 + 6144 133 | clgloop 134 | push de 135 | push de 136 | push de 137 | push de 138 | 139 | push de 140 | push de 141 | push de 142 | push de 143 | 144 | push de 145 | push de 146 | push de 147 | push de 148 | 149 | djnz clgloop 150 | 151 | ld b,c 152 | ld sp,#e000 + 6144 153 | clgloop2: 154 | push de 155 | push de 156 | push de 157 | push de 158 | 159 | push de 160 | push de 161 | push de 162 | push de 163 | 164 | push de 165 | push de 166 | push de 167 | push de 168 | 169 | djnz clgloop2 170 | 171 | ld sp,hl 172 | 173 | xor a 174 | call changeBank 175 | 176 | ei 177 | ret 178 | 179 | 180 | coords dw 0 181 | ; Using ZX-Spectrum font - 2K economy 182 | font equ #3D00 183 | -------------------------------------------------------------------------------- /tape/uart.asm: -------------------------------------------------------------------------------- 1 | DISPLAY "UART STARTS: ", $ 2 | ; Enable UART 3 | ; Cleaning all flags by reading UART regs 4 | ; Wastes AF and BC 5 | uartBegin: 6 | ld a, #07 7 | ld bc, #fffd 8 | out (c), a 9 | ld a, #fc 10 | ld b, #bf 11 | out (c), a ; Enable read mode 12 | 13 | ld a, #0e 14 | ld bc, #fffd 15 | out (c), a 16 | ld a, #fe 17 | ld b, #bf 18 | out (c), a ; Make CTS low 19 | ld b, #ff : djnz $ 20 | ret 21 | 22 | ; Blocking read one byte 23 | uartReadBlocking: 24 | call uartRead 25 | push af : jr c, urb : pop af 26 | jp uartReadBlocking 27 | urb: 28 | pop af 29 | ret 30 | 31 | 32 | uartWriteByte: 33 | push af 34 | 35 | ld c, #fd ; prepare port addresses 36 | ld d, #ff 37 | ld e, #bf 38 | ld b, d 39 | 40 | ld a, #0e 41 | out (c), a ; Select AY's PORT A 42 | 43 | ld hl, (_baud) 44 | ld de, #0002 45 | or a 46 | sbc hl, de 47 | ex hl, de 48 | 49 | pop af 50 | cpl 51 | scf 52 | ld b, #0b ; Numbers of bits - 1 start, 8 data, 2 stop 53 | 54 | di ; Hard timing starts 55 | transmitBit: 56 | push bc 57 | push af 58 | 59 | ld a, #fe 60 | ld h, d 61 | ld l, e 62 | ld bc, #bffd 63 | jp nc, transmitOne 64 | ; Transmit Zero: 65 | and #f7 66 | out (c), a 67 | jr transmitNext 68 | transmitOne: 69 | or 8 70 | out (c), a 71 | jr transmitNext 72 | 73 | transmitNext: 74 | dec hl 75 | ld a, h 76 | or l 77 | jr nz, transmitNext 78 | 79 | nop 80 | nop 81 | nop 82 | 83 | pop af 84 | pop bc 85 | or a 86 | rra 87 | djnz transmitBit 88 | ei 89 | ret 90 | 91 | 92 | uartRead: 93 | ld hl, _testByte 94 | ld a, (hl) 95 | and a 96 | jr z, testSecond 97 | inc hl 98 | ld a, (hl) 99 | scf 100 | ret 101 | testSecond: 102 | ld hl, _isSecondByteAvail 103 | ld a, (hl) 104 | and a 105 | jr z, startReadByte 106 | ld (hl), 0 107 | inc hl 108 | ld a, (hl) 109 | scf 110 | ret 111 | startReadByte: 112 | di 113 | xor a 114 | exx 115 | ld de, (_baud) 116 | ld hl, (_baud) 117 | srl h 118 | rr l ; HL=_baud/2 119 | or a 120 | ld b, #FA ; Wait look length 121 | exx 122 | ld c, #fd 123 | ld d, #ff 124 | ld e, #bf 125 | ld b, d 126 | ld a, #0e 127 | out (c), a 128 | in a, (c) 129 | or #f0 ; Input lines is 1 130 | and #fb ; CTS force to 0 131 | ld b, e ; B = #BF 132 | out (c), a ; Make CTS high 133 | ld h, a 134 | 135 | waitStartBit: 136 | ld b, d 137 | in a, (c) 138 | and #80 139 | jr z, startBitFound 140 | readTimeOut: 141 | exx 142 | dec b 143 | exx 144 | jr nz, waitStartBit 145 | xor a 146 | push af 147 | jr readFinish 148 | startBitFound: 149 | in a, (c) 150 | and #80 151 | jr nz, readTimeOut 152 | 153 | in a, (c) 154 | and #80 155 | jr nz, readTimeOut 156 | ;; Start bit found! 157 | 158 | exx 159 | ld bc, #fffd 160 | ld a, #80 161 | ex af, af 162 | readTune: 163 | add hl, de ; HL = 1.5 * _baud 164 | nop 165 | nop 166 | nop 167 | nop ; Fine tuning delay 168 | 169 | bdDelay: 170 | dec hl 171 | ld a, h 172 | or l 173 | jr nz, bdDelay 174 | 175 | in a, (c) 176 | and #80 177 | jp z, zeroReceived 178 | ; One received: 179 | ex af, af 180 | scf 181 | rra 182 | jr c, receivedByte 183 | ex af, af 184 | jp readTune 185 | zeroReceived: 186 | ex af, af 187 | or a 188 | RRA 189 | jr c, receivedByte 190 | ex af, af 191 | jp readTune 192 | receivedByte: 193 | scf 194 | push af 195 | exx 196 | readFinish: 197 | ld a, h 198 | or #04 199 | ld b, e 200 | out (c), a 201 | 202 | exx 203 | ld h, d 204 | ld l, e 205 | 206 | ld bc, #0007 207 | or a 208 | sbc hl, bc 209 | 210 | delayForStopBit: 211 | dec hl 212 | ld a, h 213 | or l 214 | jr nz, delayForStopBit 215 | 216 | ld bc, #fffd 217 | add hl, de 218 | add hl, de 219 | add hl, de 220 | 221 | waitStartBitSecondByte: 222 | in a, (c) 223 | and #80 224 | jr z, secondStartBitFound 225 | dec hl 226 | ld a, h 227 | or l 228 | jr nz, waitStartBitSecondByte 229 | ; No second byte 230 | pop af 231 | ei 232 | ret 233 | 234 | secondStartBitFound: 235 | in a, (c) 236 | and #80 237 | jr nz, waitStartBitSecondByte 238 | ld h, d 239 | ld l, e 240 | ld bc, #0002 241 | srl h 242 | rr l 243 | or a 244 | sbc hl, bc 245 | ld bc, #fffd 246 | ld a, #80 247 | ex af, af 248 | secondByteTune: 249 | nop 250 | nop 251 | nop 252 | nop 253 | add hl, de 254 | 255 | secondDelay: 256 | dec hl 257 | ld a, h 258 | or l 259 | jr nz, secondDelay 260 | 261 | in a, (c) 262 | and #80 263 | jr z, secondZeroReceived 264 | ; Second 1 received 265 | ex af, af 266 | scf 267 | rra 268 | jr c, secondByteFinished 269 | ex af, af 270 | jp secondByteTune 271 | 272 | secondZeroReceived: 273 | ex af, af 274 | or a 275 | rra 276 | jr c, secondByteFinished 277 | ex af, af 278 | jp secondByteTune 279 | secondByteFinished: 280 | ld hl, _isSecondByteAvail 281 | ld (hl), 1 282 | inc hl 283 | ld (hl), a 284 | pop af 285 | ei 286 | ret 287 | 288 | 289 | _baud dw 11 ; 54 - 2400 --- 25 - 4800 --- 11 - 9600 290 | _isSecondByteAvail dw #0 291 | _testByte dw #0 292 | -------------------------------------------------------------------------------- /tape/ugoph.$c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/tape/ugoph.$c -------------------------------------------------------------------------------- /tape/ugoph.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/tape/ugoph.bin -------------------------------------------------------------------------------- /tape/ugoph.tap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/tape/ugoph.tap -------------------------------------------------------------------------------- /tape/utils.asm: -------------------------------------------------------------------------------- 1 | ; This routine checks availability of extended(128K) memory. 2 | ; Output: 3 | ; Flag: Z - High memory available 4 | checkHighMem: 5 | xor a : call changeBank: ld hl, #c000 : xor a :ld (hl), a ; Let's write in zero page zero value 6 | inc a : call changeBank : ld a, 13 : ld (hl), a ; In other page - any other value. Let's write luck 13 7 | xor a : call changeBank : ld a, (hl) : and a ; When we back to zero page - still there zero?! 8 | ret 9 | 10 | ; A - memory bank 11 | changeBank: 12 | ld bc, #7ffd : or #18 : out (c), a 13 | ret 14 | 15 | ; Pushes to UART zero-terminated string 16 | ; HL - string poiner 17 | uartWriteStringZ: 18 | ld a, (hl) : and a : ret z 19 | 20 | push hl : call uartWriteByte : pop hl 21 | 22 | inc hl 23 | jp uartWriteStringZ 24 | 25 | ; Print zero-terminated string 26 | ; HL - string pointer 27 | putStringZ: 28 | printZ64: 29 | ld a,(hl) : and a : ret z 30 | 31 | push hl : call putC : pop hl 32 | 33 | inc hl 34 | jr printZ64 35 | 36 | printT64: 37 | ld b, 63 38 | ptlp: 39 | ld a, 0 : or b : ret z 40 | 41 | ld a, (hl) 42 | 43 | and a : ret z 44 | cp 09 : ret z 45 | 46 | push bc 47 | 48 | push hl : call putC : pop hl 49 | 50 | inc hl : pop bc : dec b 51 | jr ptlp 52 | 53 | printL64: 54 | ld a, (hl) 55 | 56 | and a : ret z 57 | cp #0A : ret z 58 | cp #0D : ret z 59 | 60 | push hl : call putC : pop hl 61 | 62 | inc hl 63 | jr printL64 64 | 65 | ; HL - string 66 | ; Return: bc - len 67 | getStringLength: 68 | ld bc, 0 69 | strLnLp 70 | ld a, (hl) : and a : ret z 71 | inc bc 72 | inc hl 73 | jr strLnLp 74 | 75 | SkipWhitespace: 76 | ld a, (hl) 77 | 78 | cp ' ' : ret nz 79 | 80 | inc hl 81 | jr SkipWhitespace 82 | 83 | findEnd: 84 | ld a,(hl) 85 | 86 | and a : ret z 87 | 88 | inc hl 89 | jr findEnd 90 | 91 | ;;;;;;;;;;;;;;;;;;;;;;;; 92 | 93 | ; Binary to decimal stuff 94 | ; From https://www.msx.org/forum/development/msx-development/32-bit-long-ascii 95 | 96 | ; Combined routine for conversion of different sized binary numbers into 97 | ; directly printable ASCII(Z)-string 98 | ; Input value in registers, number size and -related to that- registers to fill 99 | ; is selected by calling the correct entry: 100 | ; 101 | ; entry inputregister(s) decimal value 0 to: 102 | ; B2D8 A 255 (3 digits) 103 | ; B2D16 HL 65535 5 " 104 | ; B2D24 E:HL 16777215 8 " 105 | ; B2D32 DE:HL 4294967295 10 " 106 | ; B2D48 BC:DE:HL 281474976710655 15 " 107 | ; B2D64 IX:BC:DE:HL 18446744073709551615 20 " 108 | ; 109 | ; The resulting string is placed into a small buffer attached to this routine, 110 | ; this buffer needs no initialization and can be modified as desired. 111 | ; The number is aligned to the right, and leading 0's are replaced with spaces. 112 | ; On exit HL points to the first digit, (B)C = number of decimals 113 | ; This way any re-alignment / postprocessing is made easy. 114 | ; Changes: AF,BC,DE,HL,IX 115 | ; P.S. some examples below 116 | 117 | ; by Alwin Henseler 118 | 119 | B2D8: LD H,0 120 | LD L,A 121 | B2D16: LD E,0 122 | B2D24: LD D,0 123 | B2D32: LD BC,0 124 | B2D48: LD IX,0 ; zero all non-used bits 125 | B2D64: LD (B2DINV),HL 126 | LD (B2DINV+2),DE 127 | LD (B2DINV+4),BC 128 | LD (B2DINV+6),IX ; place full 64-bit input value in buffer 129 | LD HL,B2DBUF 130 | LD DE,B2DBUF+1 131 | LD (HL)," " 132 | B2DFILC: EQU $-1 ; address of fill-character 133 | LD BC,18 134 | LDIR ; fill 1st 19 bytes of buffer with spaces 135 | LD (B2DEND-1),BC ;set BCD value to "0" & place terminating 0 136 | LD E,1 ; no. of bytes in BCD value 137 | LD HL,B2DINV+8 ; (address MSB input)+1 138 | LD BC,0x0909 139 | XOR A 140 | B2DSKP0: DEC B 141 | JR Z,B2DSIZ ; all 0: continue with postprocessing 142 | DEC HL 143 | OR (HL) ; find first byte <>0 144 | JR Z,B2DSKP0 145 | B2DFND1: DEC C 146 | RLA 147 | JR NC,B2DFND1 ; determine no. of most significant 1-bit 148 | RRA 149 | LD D,A ; byte from binary input value 150 | B2DLUS2: PUSH HL 151 | PUSH BC 152 | B2DLUS1: LD HL,B2DEND-1 ; address LSB of BCD value 153 | LD B,E ; current length of BCD value in bytes 154 | RL D ; highest bit from input value -> carry 155 | B2DLUS0: LD A,(HL) 156 | ADC A,A 157 | DAA 158 | LD (HL),A ; double 1 BCD byte from intermediate result 159 | DEC HL 160 | DJNZ B2DLUS0 ; and go on to double entire BCD value (+carry!) 161 | JR NC,B2DNXT 162 | INC E ; carry at MSB -> BCD value grew 1 byte larger 163 | LD (HL),1 ; initialize new MSB of BCD value 164 | B2DNXT: DEC C 165 | JR NZ,B2DLUS1 ; repeat for remaining bits from 1 input byte 166 | POP BC ; no. of remaining bytes in input value 167 | LD C,8 ; reset bit-counter 168 | POP HL ; pointer to byte from input value 169 | DEC HL 170 | LD D,(HL) ; get next group of 8 bits 171 | DJNZ B2DLUS2 ; and repeat until last byte from input value 172 | B2DSIZ: LD HL,B2DEND ; address of terminating 0 173 | LD C,E ; size of BCD value in bytes 174 | OR A 175 | SBC HL,BC ; calculate address of MSB BCD 176 | LD D,H 177 | LD E,L 178 | SBC HL,BC 179 | EX DE,HL ; HL=address BCD value, DE=start of decimal value 180 | LD B,C ; no. of bytes BCD 181 | SLA C ; no. of bytes decimal (possibly 1 too high) 182 | LD A,"0" 183 | RLD ; shift bits 4-7 of (HL) into bit 0-3 of A 184 | CP "0" ; (HL) was > 9h? 185 | JR NZ,B2DEXPH ; if yes, start with recording high digit 186 | DEC C ; correct number of decimals 187 | INC DE ; correct start address 188 | JR B2DEXPL ; continue with converting low digit 189 | B2DEXP: RLD ; shift high digit (HL) into low digit of A 190 | B2DEXPH: LD (DE),A ; record resulting ASCII-code 191 | INC DE 192 | B2DEXPL: RLD 193 | LD (DE),A 194 | INC DE 195 | INC HL ; next BCD-byte 196 | DJNZ B2DEXP ; and go on to convert each BCD-byte into 2 ASCII 197 | SBC HL,BC ; return with HL pointing to 1st decimal 198 | RET 199 | 200 | AppendB2D: 201 | ; Append results of B2D to string at HL 202 | ex de, hl ; Get destination into DE 203 | ld hl, B2DBUF 204 | call SkipWhitespace 205 | ldir 206 | ex de, hl ; Get destination into DE 207 | ret 208 | 209 | B2DINV: DS 8 ; space for 64-bit input value (LSB first) 210 | B2DBUF: DS 20 ; space for 20 decimal digits 211 | B2DEND: DB 0 ; space for terminating 0 212 | -------------------------------------------------------------------------------- /tape/wifi.asm: -------------------------------------------------------------------------------- 1 | ; Initialize WiFi chip and connect to WiFi 2 | initWifi: 3 | call loadWiFiConfig : call uartBegin 4 | 5 | ld hl, cmd_plus : call uartWriteStringZ 6 | ld b,#ff 7 | wlp: 8 | push bc : ld b, #ff : djnz $ : pop bc : djnz wlp 9 | 10 | ld hl, cmd_rst : call uartWriteStringZ 11 | rstLp: 12 | call uartReadBlocking : call pushRing 13 | 14 | ld hl, response_rdy : call searchRing : cp 1 : jr nz, rstLp 15 | 16 | ; WiFi client mode 17 | ld hl, cmd_mode : call okErrCmd : and 1 : jr z, errInit 18 | ; Disable ECHO. BTW Basic UART test 19 | ld hl, cmd_at : call okErrCmd : and 1 : jr z, errInit 20 | ; Lets disconnect from last AP 21 | ld hl, cmd_cwqap : call okErrCmd : and 1 : jr z, errInit 22 | ; Single connection mode 23 | ld hl, cmd_cmux : call okErrCmd : and 1 : jr z, errInit 24 | 25 | ; FTP enables this info? We doesn't need it :-) 26 | ld hl, cmd_inf_off : call okErrCmd : and 1 : jr z, errInit 27 | 28 | ; Access Point connection 29 | ld hl, cmd_cwjap1 : call uartWriteStringZ : ld hl, ssid : call uartWriteStringZ : ld hl, cmd_cwjap2 : call uartWriteStringZ 30 | ld hl, pass :call uartWriteStringZ : ld hl, cmd_cwjap3 : call okErrCmd 31 | 32 | and 1 :jr z, errInit 33 | 34 | ld hl, log_ok : call putStringZ 35 | ret 36 | errInit 37 | ld hl, log_err : call putStringZ 38 | jr $ 39 | 40 | 41 | ; Send AT-command and wait for result. 42 | ; HL - Z-terminated AT-command(with CR/LF) 43 | ; A: 44 | ; 1 - Success 45 | ; 0 - Failed 46 | okErrCmd: 47 | call uartWriteStringZ 48 | okErrCmdLp: 49 | call uartReadBlocking : call pushRing 50 | 51 | ld hl, response_ok : call searchRing : cp 1 : jr z, okErrOk 52 | ld hl, response_err : call searchRing : cp 1 : jr z, okErrErr 53 | ld hl, response_fail : call searchRing : cp 1 : jr z, okErrErr 54 | 55 | jp okErrCmdLp 56 | okErrOk 57 | ld a, 1 58 | ret 59 | okErrErr 60 | ld a, 0 61 | ret 62 | 63 | ; Gets packet from network 64 | ; packet will be in var 'output_buffer' 65 | ; received packet size in var 'bytes_avail' 66 | ; 67 | ; If connection was closed it calls 'closed_callback' 68 | getPacket 69 | call uartReadBlocking : call pushRing 70 | 71 | ld hl, closed : call searchRing : cp 1 : jp z, closed_callback 72 | ld hl, ipd : call searchRing : cp 1 : jr nz, getPacket 73 | 74 | call count_ipd_lenght : ld (bytes_avail), hl 75 | push hl : pop bc 76 | 77 | ld hl, output_buffer 78 | readp: 79 | push bc : push hl 80 | call uartReadBlocking 81 | pop hl 82 | ld (hl), a 83 | pop bc 84 | 85 | dec bc : inc hl 86 | 87 | ld a, b : or c : jr nz, readp 88 | 89 | ld hl, (bytes_avail) 90 | ret 91 | 92 | count_ipd_lenght 93 | ld hl,0 ; count lenght 94 | cil1 push hl : call uartReadBlocking : push af : call pushRing : pop af : pop hl 95 | cp ':' : ret z 96 | sub 0x30 : ld c,l : ld b,h : add hl,hl : add hl,hl : add hl,bc : add hl,hl : ld c,a : ld b,0 : add hl,bc 97 | jr cil1 98 | 99 | ; HL - z-string to hostname or ip 100 | ; DE - z-string to port 101 | startTcp: 102 | push de 103 | push hl 104 | ld hl, cmd_open1 : call uartWriteStringZ 105 | pop hl : call uartWriteStringZ 106 | ld hl, cmd_open2 : call uartWriteStringZ 107 | pop de : call uartWriteStringZ 108 | ld hl, cmd_open3 : call okErrCmd 109 | ret 110 | 111 | ; Returns: 112 | ; A: 1 - Success 113 | ; 0 - Failed 114 | sendByte: 115 | push af 116 | ld hl, cmd_send_b : call okErrCmd 117 | cp 1 : jr nz, sbErr 118 | sbLp 119 | call uartReadBlocking 120 | ld hl, send_prompt : call searchRing : cp 1 : jr nz, sbLp 121 | pop af 122 | 123 | ld (sbyte_buff), a : call okErrCmd 124 | ret 125 | sbErr: 126 | pop af 127 | ld a, 0 128 | ret 129 | 130 | loadWiFiConfig: 131 | ei 132 | xor a : ld (CURKEY), a 133 | ld hl, lbl_ssid : call showTypePrint 134 | call cleanIBuff : call input 135 | ld hl, iBuff, de, ssid, bc, 64 : ldir 136 | 137 | ld hl, lbl_pass : call showTypePrint 138 | call cleanIBuff : call input 139 | ld hl, iBuff, de, pass, bc, 64 : ldir 140 | 141 | ret 142 | 143 | lbl_ssid db "SSID ^^^^", 0 144 | lbl_pass db "PASSWORD ^^^^", 0 145 | 146 | cmd_plus defb "+++", 0 147 | cmd_rst defb "AT+RST",13, 10, 0 148 | cmd_at defb "ATE0", 13, 10, 0 ; Disable echo - less to parse 149 | cmd_mode defb "AT+CWMODE_DEF=1",13,10,0 ; Client mode 150 | cmd_cmux defb "AT+CIPMUX=0",13,10,0 ; Single connection mode 151 | cmd_cwqap defb "AT+CWQAP",13,10,0 ; Disconnect from AP 152 | cmd_inf_off defb "AT+CIPDINFO=0",13,10,0 ; doesn't send me info about remote port and ip 153 | 154 | cmd_cwjap1 defb "AT+CWJAP_CUR=", #22,0 ;Connect to AP. Send this -> SSID 155 | cmd_cwjap2 defb #22,',',#22,0 ; -> This -> Password 156 | cmd_cwjap3 defb #22, 13, 10, 0 ; -> And this 157 | 158 | cmd_open1 defb "AT+CIPSTART=", #22, "TCP", #22, ",", #22, 0 159 | cmd_open2 defb #22, ",", 0 160 | cmd_open3 defb 13, 10, 0 161 | cmd_send defb "AT+CIPSEND=", 0 162 | cmd_close defb "AT+CIPCLOSE",13,10,0 163 | cmd_send_b defb "AT+CIPSEND=1", 13, 10,0 164 | closed defb "CLOSED", 13, 10, 0 165 | ipd defb 13, 10, "+IPD,", 0 166 | crlf defb 13,10, 0 167 | 168 | response_rdy defb 'ready', 0 169 | response_ok defb 'OK', 13, 10, 0 ; Sucessful operation 170 | response_err defb 13,10,'ERROR',13,10,0 ; Failed operation 171 | response_fail defb 13,10,'FAIL',13,10,0 ; Failed connection to WiFi. For us same as ERROR 172 | 173 | log_err defb 'Failed connect to WiFi!',13, 0 174 | log_ok defb 'WiFi connected!', 13, 0 175 | 176 | ssid defs 80 177 | pass defs 80 178 | 179 | bytes_avail defw 0 180 | sbyte_buff defb 0, 0 181 | 182 | send_prompt defb ">",0 183 | output_buffer defs 2048 ; buffer for downloading data 184 | 185 | ; WiFi configuration 186 | conf_file defb "/sys/config/iw.cfg",0 187 | -------------------------------------------------------------------------------- /uGophy/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @echo "To make ugophy please select target" 3 | @echo "" 4 | @echo "make zxuno - to make esxDOS ZX-Uno version" 5 | @echo "make zxuno3e - to make +3e ZX-Uno version" 6 | @echo "make plus3dos - to make +3/+3e version Spectrum 128 with ESP-12 on AY" 7 | @echo "make esxdos - to make esxDOS version Spectrum 128 with ESP-12 on AY" 8 | @echo "make spectranet - to make Spectranet version" 9 | @echo "make karabaspro - to make TR-DOS version for karabas-pro with UNO UART" 10 | @echo "make karabaspro-zifi - to make TR-DOS version for karabas-pro with ZIFI UART" 11 | 12 | player.bin: 13 | sjasmplus -DTRDOS vtpl.asm 14 | 15 | spectranet: *.asm font.bin 16 | sjasmplus -DSPECTRANET main.asm 17 | scp ugoph.bin root@nihirash.net:/var/tnfs/ugoph.bin 18 | 19 | spectranet48: *.asm font.bin 20 | sjasmplus -DSPECTRANET -DZX48 main.asm 21 | scp ugoph.bin root@nihirash.net:/var/tnfs/ugoph48.bin 22 | 23 | karabaspro: *.asm font.bin player.bin 24 | sjasmplus -DTRDOS -DUNO -DPROFISCR main.asm 25 | 26 | karabaspro-zifi: *.asm font.bin player.bin 27 | sjasmplus -DTRDOS -DZIFI -DPROFISCR main.asm 28 | 29 | karabaspro-debug: *.asm font.bin player.bin 30 | sjasmplus -DDEBUG -DTRDOS -DZIFI -DPROFISCR main.asm 31 | wine /home/andy/Downloads/unreal/unreal.exe ugoph.sna 32 | 33 | zxuno: *.asm font.bin 34 | sjasmplus -DESXDOS -DUNO -DTIMEXSCR main.asm 35 | 36 | zxuno3e: *.asm font.bin 37 | sjasmplus -DPLUS3DOS -DUNO main.asm 38 | specform -a 24100 ugoph.bin 39 | rm ugoph.bin 40 | mv ugoph.bin.zxb ugoph.bin 41 | 42 | plus3dos: *.asm font.bin 43 | sjasmplus -DPLUS3DOS -DAY main.asm 44 | specform -a 24100 ugoph.bin 45 | rm ugoph.bin 46 | mv ugoph.bin.zxb ugoph.bin 47 | 48 | esxdos: *.asm font.bin 49 | sjasmplus -DESXDOS -DAY main.asm 50 | 51 | tape: *.asm font.bin 52 | sjasmplus -DTAPE -DAY main.asm 53 | 54 | clean: 55 | rm ugoph.bin *.tap ugoph.?c player.bin ugoph.sna 56 | 57 | -------------------------------------------------------------------------------- /uGophy/ay-uart.asm: -------------------------------------------------------------------------------- 1 | DISPLAY "UART BEGINS AT ", $ 2 | ; Enable UART 3 | ; Cleaning all flags by reading UART regs 4 | ; Wastes AF and BC 5 | uartBegin: 6 | ld a, #07 7 | ld bc, #fffd 8 | out (c), a 9 | ld a, #fc 10 | ld b, #bf 11 | out (c), a ; Enable read mode 12 | 13 | ld a, #0e 14 | ld bc, #fffd 15 | out (c), a 16 | 17 | ld b, #bf 18 | in a, (c) 19 | and #fb 20 | out (c), a ; Make CTS low 21 | 22 | ei 23 | ld b, #ff 24 | .flush 25 | halt 26 | djnz .flush 27 | ret 28 | 29 | ; Blocking read one byte 30 | uartReadBlocking: 31 | call uartRead 32 | push af : jr c, urb : pop af 33 | jp uartReadBlocking 34 | urb: 35 | pop af 36 | ret 37 | 38 | 39 | uartWriteByte: 40 | push af 41 | 42 | ld c, #fd ; prepare port addresses 43 | ld d, #ff 44 | ld e, #bf 45 | ld b, d 46 | 47 | ld a, #0e 48 | out (c), a ; Select AY's PORT A 49 | 50 | ld hl, (_baud) 51 | ld de, #0002 52 | or a 53 | sbc hl, de 54 | ex hl, de 55 | 56 | pop af 57 | cpl 58 | scf 59 | ld b, #0b ; Numbers of bits - 1 start, 8 data, 2 stop 60 | 61 | di ; Hard timing starts 62 | transmitBit: 63 | push bc 64 | push af 65 | 66 | ld a, #fe 67 | ld h, d 68 | ld l, e 69 | ld bc, #bffd 70 | jp nc, transmitOne 71 | ; Transmit Zero: 72 | and #f7 73 | out (c), a 74 | jr transmitNext 75 | transmitOne: 76 | or 8 77 | out (c), a 78 | jr transmitNext 79 | 80 | transmitNext: 81 | dec hl 82 | ld a, h 83 | or l 84 | jr nz, transmitNext 85 | 86 | nop 87 | nop 88 | nop 89 | 90 | pop af 91 | pop bc 92 | or a 93 | rra 94 | djnz transmitBit 95 | ei 96 | ret 97 | 98 | 99 | uartRead: 100 | ld hl, _isSecondByteAvail 101 | ld a, (hl) 102 | and a 103 | jr z, startReadByte 104 | ld (hl), 0 105 | inc hl 106 | ld a, (hl) 107 | scf 108 | ret 109 | startReadByte: 110 | di 111 | xor a 112 | exx 113 | ld de, (_baud) 114 | ld hl, (_baud) 115 | srl h 116 | rr l ; HL=_baud/2 117 | or a 118 | ld b, #FA ; Wait look length 119 | exx 120 | ld c, #fd 121 | ld d, #ff 122 | ld e, #bf 123 | ld b, d 124 | ld a, #0e 125 | out (c), a 126 | in a, (c) 127 | or #f0 ; Input lines is 1 128 | and #fb ; CTS force to 0 129 | ld b, e ; B = #BF 130 | out (c), a ; Make CTS high 131 | ld h, a 132 | 133 | waitStartBit: 134 | ld b, d 135 | in a, (c) 136 | and #80 137 | jr z, startBitFound 138 | readTimeOut: 139 | exx 140 | dec b 141 | exx 142 | jr nz, waitStartBit 143 | xor a 144 | push af 145 | jr readFinish 146 | startBitFound: 147 | in a, (c) 148 | and #80 149 | jr nz, readTimeOut 150 | 151 | in a, (c) 152 | and #80 153 | jr nz, readTimeOut 154 | ;; Start bit found! 155 | 156 | exx 157 | ld bc, #fffd 158 | ld a, #80 159 | ex af, af 160 | readTune: 161 | add hl, de ; HL = 1.5 * _baud 162 | nop 163 | nop 164 | nop 165 | nop ; Fine tuning delay 166 | 167 | bdDelay: 168 | dec hl 169 | ld a, h 170 | or l 171 | jr nz, bdDelay 172 | 173 | in a, (c) 174 | and #80 175 | jp z, zeroReceived 176 | ; One received: 177 | ex af, af 178 | scf 179 | rra 180 | jr c, receivedByte 181 | ex af, af 182 | jp readTune 183 | zeroReceived: 184 | ex af, af 185 | or a 186 | RRA 187 | jr c, receivedByte 188 | ex af, af 189 | jp readTune 190 | receivedByte: 191 | scf 192 | push af 193 | exx 194 | readFinish: 195 | ld a, h 196 | or #04 197 | ld b, e 198 | out (c), a 199 | 200 | exx 201 | ld h, d 202 | ld l, e 203 | 204 | ld bc, #0007 205 | or a 206 | sbc hl, bc 207 | 208 | delayForStopBit: 209 | dec hl 210 | ld a, h 211 | or l 212 | jr nz, delayForStopBit 213 | 214 | ld bc, #fffd 215 | add hl, de 216 | add hl, de 217 | add hl, de 218 | 219 | waitStartBitSecondByte: 220 | in a, (c) 221 | and #80 222 | jr z, secondStartBitFound 223 | dec hl 224 | ld a, h 225 | or l 226 | jr nz, waitStartBitSecondByte 227 | ; No second byte 228 | pop af 229 | ei 230 | ret 231 | 232 | secondStartBitFound: 233 | in a, (c) 234 | and #80 235 | jr nz, waitStartBitSecondByte 236 | ld h, d 237 | ld l, e 238 | ld bc, #0002 239 | srl h 240 | rr l 241 | or a 242 | sbc hl, bc 243 | ld bc, #fffd 244 | ld a, #80 245 | ex af, af 246 | secondByteTune: 247 | nop 248 | nop 249 | nop 250 | nop 251 | add hl, de 252 | 253 | secondDelay: 254 | dec hl 255 | ld a, h 256 | or l 257 | jr nz, secondDelay 258 | 259 | in a, (c) 260 | and #80 261 | jr z, secondZeroReceived 262 | ; Second 1 received 263 | ex af, af 264 | scf 265 | rra 266 | jr c, secondByteFinished 267 | ex af, af 268 | jp secondByteTune 269 | 270 | secondZeroReceived: 271 | ex af, af 272 | or a 273 | rra 274 | jr c, secondByteFinished 275 | ex af, af 276 | jp secondByteTune 277 | secondByteFinished: 278 | ld hl, _isSecondByteAvail 279 | ld (hl), 1 280 | inc hl 281 | ld (hl), a 282 | pop af 283 | ei 284 | ret 285 | 286 | 287 | _baud dw 11 ; 54 - 2400 --- 25 - 4800 --- 11 - 9600 288 | _isSecondByteAvail dw #0 289 | _testByte dw #0 290 | -------------------------------------------------------------------------------- /uGophy/dos/decompressor.asm: -------------------------------------------------------------------------------- 1 | ;f0o6g0 2 | sauk: ld bc, 32768 3 | ld a, b 4 | copyby: inc c 5 | ldi 6 | mainlo: call getbit 7 | jr nc, copyby 8 | push de 9 | ld d, c 10 | lenval: call nc, getbit 11 | rl c 12 | rl b 13 | call getbit 14 | jr nc, lenval 15 | inc c 16 | jr z, exitdz 17 | ld e, (hl) 18 | inc hl 19 | defb 203, 51 20 | jr nc, offend 21 | ld d, 4 22 | nexbit: call getbit 23 | rl d 24 | jr nc, nexbit 25 | inc d 26 | srl d 27 | offend: rr e 28 | ex (sp), hl 29 | push hl 30 | sbc hl, de 31 | pop de 32 | ldir 33 | exitdz: pop hl 34 | jr nc, mainlo 35 | getbit: add a, a 36 | ret nz 37 | ld a, (hl) 38 | inc hl 39 | adc a, a 40 | ret 41 | -------------------------------------------------------------------------------- /uGophy/dos/fatfs.skv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/uGophy/dos/fatfs.skv -------------------------------------------------------------------------------- /uGophy/dos/ff.equ: -------------------------------------------------------------------------------- 1 | FF_JP_TABLE EQU 0xC000 2 | FF_MOUNT EQU FF_JP_TABLE ;FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ 3 | FF_OPEN EQU FF_JP_TABLE+3 ;FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ 4 | FF_UNLINK EQU FF_JP_TABLE+6 ;FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */ 5 | FF_READ EQU FF_JP_TABLE+9 ;FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */ 6 | FF_LSEEK EQU FF_JP_TABLE+12 ;FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */ 7 | FF_WRITE EQU FF_JP_TABLE+15 ;FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */ 8 | FF_SYNC EQU FF_JP_TABLE+18 ;FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */ 9 | FF_CHDIR EQU FF_JP_TABLE+21 ;FRESULT f_chdir (const TCHAR* path); /* Change current directory */ 10 | FF_READDIR EQU FF_JP_TABLE+24 ;FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */ 11 | FF_OPENDIR EQU FF_JP_TABLE+27 ;FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */ 12 | FF_CLOSE EQU FF_JP_TABLE+30 ;FRESULT f_close (FIL* fp); /* Close an open file object */ 13 | FF_MKDIR EQU FF_JP_TABLE+33 ;FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */ 14 | FF_RENAME EQU FF_JP_TABLE+36 ;FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ 15 | FF_GETCWD EQU FF_JP_TABLE+39 ;FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */ 16 | FF_FILSTATE EQU FF_JP_TABLE+42 ;DWORD f_filstate(FIL* fp, BYTE mode); /* Get a file status FP_EOF=1, FP_ERR=2, FP_TELL=3, FP_SIZE=4 */ 17 | DRV_INIT EQU FF_JP_TABLE+45 ;DSTATUS disk_initialize (unsigned char pdrv); 18 | DRV_READ EQU FF_JP_TABLE+48 ;DRESULT _disk_read (unsigned long sector, unsigned char count, unsigned char* buff, unsigned char pdrv); 19 | DRV_WRITE EQU FF_JP_TABLE+51 ;DRESULT _disk_write (unsigned long sector, unsigned char count, const unsigned char* buff, unsigned char pdrv); 20 | ;Библиотека юзает 16байт ОЗУ с адреса 0х7000, 21 | ;Этот адрес можно изменить, смотри строку: 22 | ;-Z(DATA)DATA0,IDATA0,UDATA0,ECSTR,TEMP=7000-700F 23 | ;в файле lnkz80.xcl 24 | ;сама либа скомпилена с адреся 0х0000 25 | ;-------------------------------------------------- 26 | ;Подробную информацию по функциям смотри на сайте Эльм Чана 27 | ;параметры в функции передаются в следующем виде(из доки ИАРа): 28 | ;первый параметр в DE(DWORD в BCDE), второй в ВС, остальные на стеке. На стек помещать параметры в обратном порядке. 29 | ;Незабываем, после вызова, снимать параметры со стека(если они там больше не понадобятся). 30 | ;Пример вызова функции f(p1,p2,p3,p4), при условии что параметры не длиннее word'а: 31 | ; ld hl,p4 32 | ; push hl 33 | ; ld hl,p3 34 | ; push hl 35 | ; ld bc,p2 36 | ; ld de,p1 37 | ; call f 38 | ; pop hl 39 | ; pop hl 40 | ;8битный параметр загружается в младший регистр. 41 | ;Результат возвращается из функции: 8битный в регистре А, 16битный в HL, 32битный в BCHL 42 | ;отдельно рассмотрим функцию FF_LSEEK(FIL* fp, DWORD ofs): 43 | ; ld hl,highword(ofs) 44 | ; push hl 45 | ; ld hl,lowword(ofs) 46 | ; push hl 47 | ; ld de,fp 48 | ; call FF_LSEEK 49 | ;---------------------------------------------------------------------- 50 | 51 | ;Флаги передаваемые при открытии файла: 52 | FA_READ equ 0x01 ;Specifies read access to the object. Data can be read from the file. 53 | ;Combine with FA_WRITE for read-write access. 54 | FA_WRITE equ 0x02 ;Specifies write access to the object. Data can be written to the file. 55 | ;Combine with FA_READ for read-write access. 56 | FA_OPEN_EXISTING equ 0x00 ;Opens the file. The function fails if the file is not existing. (Default) 57 | FA_OPEN_ALWAYS equ 0x10 ;Opens the file if it is existing. If not, a new file is created. 58 | ;To append data to the file, use f_lseek function after file open in this method. 59 | FA_CREATE_NEW equ 0x04 ;Creates a new file. The function fails with FR_EXIST if the file is existing. 60 | FA_CREATE_ALWAYS equ 0x08 ;Creates a new file. If the file is existing, it is truncated and overwritten. 61 | 62 | ; /* File function return code (FRESULT) */ 63 | ; FR_OK = 0, /* (0) Succeeded */ 64 | ; FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */ 65 | ; FR_INT_ERR, /* (2) Assertion failed */ 66 | ; FR_NOT_READY, /* (3) The physical drive cannot work */ 67 | ; FR_NO_FILE, /* (4) Could not find the file */ 68 | ; FR_NO_PATH, /* (5) Could not find the path */ 69 | ; FR_INVALID_NAME, /* (6) The path name format is invalid */ 70 | ; FR_DENIED, /* (7) Acces denied due to prohibited access or directory full */ 71 | ; FR_EXIST, /* (8) Acces denied due to prohibited access */ 72 | ; FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ 73 | ; FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ 74 | ; FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ 75 | ; FR_NOT_ENABLED, /* (12) The volume has no work area */ 76 | ; FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume on the physical drive */ 77 | ; FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */ 78 | ; FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ 79 | ; FR_LOCKED, /* (16) The operation is rejected according to the file shareing policy */ 80 | ; FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ 81 | ; FR_TOO_MANY_OPEN_FILES /* (18) Number of open files > _FS_SHARE */ 82 | 83 | FATFS_SIZE equ 562 84 | FIL_SIZE equ 32 85 | DIR_SIZE equ 26 86 | 87 | STRUCT FILINFO 88 | fsize dword ;/* file size */ 89 | fdate word ;/* last modified date */ 90 | ftime word ;/* last modified time */ 91 | fattrib byte ;/* attribute */ 92 | fname defs 26 ;/* short file name (8.3 format) */ 93 | ENDS 94 | 95 | ;/* File attribute bits for directory entry */ 96 | AM_RDO =0x01 ;/* Read only */ 97 | AM_HID =0x02 ;/* Hidden */ 98 | AM_SYS =0x04 ;/* System */ 99 | AM_VOL =0x08 ;/* Volume label */ 100 | AM_LFN =0x0F ;/* LFN entry */ 101 | AM_DIR =0x10 ;/* Directory */ 102 | AM_ARC =0x20 ;/* Archive */ 103 | AM_MASK =0x3F ;/* Mask of defined bits */ -------------------------------------------------------------------------------- /uGophy/dos/ochkodos.asm: -------------------------------------------------------------------------------- 1 | 2 | module Dos 3 | page = 1 4 | include "ff.equ" 5 | 6 | init: 7 | di 8 | ld a, page : call changeBank 9 | ld hl, bin, de, #c000 : call sauk 10 | mount: 11 | ld l,1 ; Check for valid 12 | push hl 13 | ld bc,drpath_zsd : ld de,ffs 14 | call FF_MOUNT 15 | pop hl 16 | or a 17 | jp nz, error 18 | ei 19 | sub a : call changeBank 20 | ret 21 | 22 | ; DE - ASCIZ path 23 | cwd: 24 | ld a, page : call changeBank 25 | call FF_CHDIR 26 | push af 27 | sub a : call changeBank 28 | pop af 29 | ret 30 | 31 | ; DE - ASCIZ path 32 | mkdir: 33 | ld a, page : call changeBank 34 | call FF_MKDIR 35 | push af 36 | sub a : call changeBank 37 | pop af 38 | ret 39 | 40 | ; L - file mode: 41 | ; BC - filename 42 | fopen: 43 | push bc : ld a, page : call changeBank : pop bc 44 | 45 | push hl 46 | ld de, file 47 | call FF_OPEN 48 | pop hl 49 | 50 | push af : sub a : call changeBank : pop af 51 | ret 52 | 53 | ; BC - buffer 54 | ; DE - buffer size 55 | fread: 56 | push bc : ld a, page : call changeBank : pop bc 57 | 58 | ld hl, rwres 59 | push hl 60 | push de 61 | ld de, file 62 | call FF_READ 63 | pop hl 64 | pop hl 65 | ret 66 | 67 | ; BC - buffer 68 | ; DE - buffer size 69 | fwrite: 70 | push bc : ld a, page : call changeBank : pop bc 71 | 72 | ld hl, rwres 73 | push hl 74 | push de 75 | ld de, file 76 | call FF_WRITE 77 | pop hl 78 | pop hl 79 | 80 | push af : sub a : call changeBank : pop af 81 | ret 82 | 83 | fclose: 84 | push bc : ld a, page : call changeBank : pop bc 85 | 86 | ld de, file 87 | call FF_CLOSE 88 | 89 | push af : sub a : call changeBank : pop af 90 | ret 91 | 92 | error: 93 | add '0' 94 | call putC 95 | ld hl, .msg : call putStringZ 96 | jr $ 97 | .msg db " - can't init SD Card or FAT!",13,"Computer halted!",0 98 | 99 | 100 | ffs defs FATFS_SIZE 101 | file defs FIL_SIZE 102 | rwres defw 0 103 | drpath_zsd defb '0:',0 ;путь девайса для монтирования. В данном случае Z-SD 104 | dir defs DIR_SIZE 105 | finfo FILINFO 106 | 107 | IFNDEF NOIMAGE 108 | bin: 109 | incbin "fatfs.skv" 110 | bin_size = $ - bin 111 | include "decompressor.asm" 112 | 113 | DISPLAY "fatfs size: ", $ - bin 114 | display "FAT FS ENDS: ", $ 115 | ENDIF 116 | 117 | endmodule 118 | -------------------------------------------------------------------------------- /uGophy/esxdos.asm: -------------------------------------------------------------------------------- 1 | ; API methods 2 | ESX_GETSETDRV = #89 3 | ESX_FOPEN = #9A 4 | ESX_FCLOSE = #9B 5 | ESX_FSYNC = #9C 6 | ESX_FREAD = #9D 7 | ESX_FWRITE = #9E 8 | 9 | ; File modes 10 | FMODE_READ = #01 11 | FMODE_WRITE = #06 12 | FMODE_CREATE = #0E 13 | 14 | ; Returns: 15 | ; A - current drive 16 | getDefaultDrive: 17 | ld a, 0 : rst #8 18 | defb ESX_GETSETDRV 19 | ret 20 | 21 | ; Opens file on default drive 22 | ; B - File mode 23 | ; HL - File name 24 | ; Returns: 25 | ; A - file stream id 26 | fopen: 27 | push bc : push hl 28 | call getDefaultDrive 29 | pop ix : pop bc 30 | rst #8 31 | defb ESX_FOPEN 32 | ret 33 | 34 | ; A - file stream id 35 | fclose: 36 | rst #8 37 | defb ESX_FCLOSE 38 | ret 39 | 40 | ; A - file stream id 41 | ; BC - length 42 | ; HL - buffer 43 | ; Returns 44 | ; BC - length(how much was actually read) 45 | fread: 46 | push hl : pop ix 47 | rst #8 48 | defb ESX_FREAD 49 | ret 50 | 51 | ; A - file stream id 52 | ; BC - length 53 | ; HL - buffer 54 | ; Returns: 55 | ; BC - actually written bytes 56 | fwrite: 57 | push hl : pop ix 58 | rst #8 59 | defb ESX_FWRITE 60 | ret 61 | 62 | ; A - file stream id 63 | fsync: 64 | rst #8 65 | defb ESX_FSYNC 66 | ret 67 | -------------------------------------------------------------------------------- /uGophy/font.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/uGophy/font.bin -------------------------------------------------------------------------------- /uGophy/gopher.asm: -------------------------------------------------------------------------------- 1 | ; hl - server 2 | ; de - path 3 | ; bc - port 4 | openPage: 5 | ld (srv_ptr), hl : ld (path_ptr), de : ld (port_ptr), bc 6 | IFNDEF ZX48 7 | xor a : call changeBank 8 | ENDIF 9 | 10 | ex hl, de : ld de, hist : ld bc, 322 : ldir 11 | 12 | ld hl, (srv_ptr) : ld de, (path_ptr) : ld bc, (port_ptr) 13 | call makeRequest 14 | IFNDEF ZX48 15 | xor a : call changeBank 16 | ENDIF 17 | ld hl, page_buffer : xor a : ld (hl), a : ld de, page_buffer + 1 : ld bc, #ffff - page_buffer - 1 : ldir 18 | 19 | ld hl, page_buffer : call loadData 20 | 21 | xor a : ld (show_offset), a 22 | inc a : ld (cursor_pos), a 23 | ret 24 | 25 | srv_ptr dw 0 26 | path_ptr dw 0 27 | port_ptr dw 0 28 | 29 | ; HL - domain stringZ 30 | ; DE - path stringZ 31 | ; BC - port stringZ 32 | makeRequest: 33 | ld (srv_ptr), hl : ld (path_ptr), de : ld (port_ptr), bc 34 | 35 | ld hl, downloading_msg : call showTypePrint 36 | IFNDEF ZX48 37 | xor a : call changeBank 38 | ENDIF 39 | 40 | IFDEF SPECTRANET 41 | ; SPECTRANET PART GOING HERE!!!!!!!!!!!!!!!!!!!!! 42 | ld de, (port_ptr) : call atoi : ld b, h, c, l, hl, (srv_ptr) 43 | call openTcp 44 | ld hl, (path_ptr), de, hl : call getStringLength : call sendTcp 45 | ld de, crlf, bc, 2 : call sendTcp 46 | ELSE 47 | ; WIFI PART GOING HERE!!!!!!!!!!!!!! 48 | ; Open TCP connection 49 | ld hl, cmd_open1 : call uartWriteStringZ 50 | ld hl, (srv_ptr) : call uartWriteStringZ 51 | ld hl, cmd_open2 : call uartWriteStringZ 52 | ld hl, (port_ptr) : call uartWriteStringZ 53 | ld hl, cmd_open3 : call okErrCmd 54 | 55 | cp 1 : jp nz, reqErr 56 | 57 | ; Send request 58 | ld hl, cmd_send : call uartWriteStringZ 59 | ld hl, (path_ptr) 60 | call getStringLength 61 | push bc : pop hl : inc hl : inc hl : call B2D16 62 | 63 | ld hl, B2DBUF : call SkipWhitespace : call uartWriteStringZ 64 | ld hl, crlf : call okErrCmd 65 | 66 | cp 1 : jp nz, reqErr 67 | wPrmt: 68 | call uartReadBlocking : call pushRing 69 | ld hl, send_prompt : call searchRing : cp 1 : jr nz, wPrmt 70 | 71 | ld hl, (path_ptr) : call uartWriteStringZ 72 | 73 | ld hl, crlf : call uartWriteStringZ : ld a, 1 : ld (connectionOpen), a 74 | ENDIF 75 | ret 76 | 77 | reqErr: 78 | ld sp, stack_pointer 79 | 80 | ld hl, connectionError : call showTypePrint : call wSec 81 | xor a : ld (connectionOpen), a 82 | 83 | IFNDEF SPECTRANET 84 | call initWifi ; Trying reset ESP and continue work 85 | ENDIF 86 | jp historyBack ; Let's try back home on one URL :) 87 | 88 | ; Load data to ram via gopher 89 | ; HL - data pointer 90 | ; In data_recv downloaded volume 91 | loadData: 92 | ld (data_pointer), hl, hl, 0, (data_recv), hl 93 | lpLoop: 94 | call getPacket 95 | 96 | ld a, (connectionOpen) : and a : jp z, ldEnd 97 | 98 | ld de, (data_pointer) 99 | ld hl, (bytes_avail) 100 | add hl, de 101 | ;DISPLAY "debug: ", $ 102 | 103 | ld a, h : cp #40 : jr c, lpLoop 104 | ; a bit buggy 105 | 106 | ld bc, (bytes_avail) : ld hl, output_buffer : ldir 107 | ld hl, (data_pointer) : ld de, (bytes_avail) : add hl, de : ld (data_pointer), hl 108 | ld hl, (data_recv) : add hl, de : ld (data_recv), hl 109 | 110 | jp lpLoop 111 | 112 | ldEnd 113 | ld hl, 0 : ld (data_pointer), hl 114 | ret 115 | 116 | ; Download file via gopher 117 | ; HL - filename 118 | downloadData: 119 | IFDEF SPECTRANET 120 | ret 121 | ENDIF 122 | 123 | IFDEF PLUS3DOS 124 | ld c, ACCESS_MODE_EXCLUSIVE_WRITE, d, CREATE_ACTION_POINT_TO_HEADER, e, OPEN_ACTION_MAKE_BACKUP 125 | call fopen 126 | ENDIF 127 | 128 | IFDEF ESXDOS 129 | ld b, FMODE_CREATE : call fopen : ld (fstream), a 130 | ENDIF 131 | 132 | IFDEF TRDOS 133 | ld l, Dos.FA_CREATE_ALWAYS | Dos.FA_WRITE | Dos.FA_READ 134 | call Dos.fopen 135 | ENDIF 136 | 137 | IFNDEF SPECTRANET 138 | dwnLp: 139 | call getPacket : ld a, (connectionOpen) : and a : jp z, dwnEnd 140 | 141 | IFDEF PLUS3DOS 142 | ld hl, (bytes_avail) : ex hl, de : ld hl, output_buffer : ld c, 0 : call fwrite 143 | ENDIF 144 | 145 | IFDEF ESXDOS 146 | ld bc, (bytes_avail), hl, output_buffer, a, (fstream) : call fwrite 147 | ENDIF 148 | 149 | IFDEF TRDOS 150 | ld hl, (bytes_avail) : ex hl, de : ld bc, output_buffer 151 | call Dos.fwrite 152 | ENDIF 153 | 154 | jp dwnLp 155 | dwnEnd: 156 | 157 | IFDEF PLUS3DOS 158 | call fclose 159 | ENDIF 160 | 161 | IFDEF ESXDOS 162 | ld a, (fstream) : call fclose 163 | ENDIF 164 | 165 | IFDEF TRDOS 166 | call Dos.fclose 167 | ENDIF 168 | 169 | ei 170 | ret 171 | ENDIF 172 | 173 | openURI: 174 | call cleanIBuff 175 | 176 | ld b, SCREEN_ROWS-1 : ld c, 0 :call gotoXY : ld hl, cleanLine : call printZ64 177 | ld b, SCREEN_ROWS-1 : ld c, 0 : call gotoXY : ld hl, hostTxt : call printZ64 178 | 179 | call input 180 | 181 | ld a, (iBuff) : or a : jp z, backToPage 182 | 183 | ld b, SCREEN_ROWS-1 : ld c, 0 : call gotoXY : ld hl, cleanLine : call printZ64 184 | 185 | ld hl, iBuff : ld de, d_host : ld bc, 65 : ldir 186 | 187 | ld hl, d_host : ld de, d_path : ld bc, d_port : call openPage 188 | 189 | jp showPage 190 | 191 | 192 | data_pointer defw #4000 193 | data_recv defw 0 194 | fstream defb 0 195 | 196 | closed_callback 197 | xor a 198 | ld (connectionOpen), a 199 | ei 200 | ret 201 | 202 | hostTxt db 'Enter host: ', 0 203 | 204 | crlf defb 13,10, 0 205 | 206 | d_path db '/' 207 | defs 254 208 | d_host defs 70 209 | d_port db '70' 210 | defs 5 211 | 212 | hist ds 322 213 | connectionOpen db 0 214 | downloading_msg db 'Downloading...', 0 215 | 216 | connectionError db "Issue with making request - trying get back", 0 217 | -------------------------------------------------------------------------------- /uGophy/keyboard.asm: -------------------------------------------------------------------------------- 1 | CURKEY = 23560 2 | 3 | ; Returns in A key code or zero if key wans't pressed 4 | inkey: 5 | ld hl, CURKEY : ld a, (hl) 6 | push af : xor a : ld (hl), a : pop af 7 | ret 8 | 9 | findZero: 10 | ld a, (hl) : or a : ret z 11 | inc hl 12 | jp findZero 13 | 14 | input: 15 | ld b, 20 : ld c, 0 : call gotoXY 16 | 17 | ld hl, cleanLine : call printZ64 18 | 19 | ld hl, iBuff : call findZero 20 | iLp: 21 | halt 22 | push hl 23 | 24 | ld b, 20 : ld c, 0: call gotoXY 25 | ld hl, iBuff : call printZ64 26 | 27 | ld a, '_' : call putC : ld a, ' ' : call putC 28 | 29 | call inkey 30 | 31 | cp 0 : jr z, iNth 32 | cp 12 : jr z, iBS 33 | cp 13 : jr z, iRet 34 | 35 | pop hl : ld (hl), A : push hl 36 | 37 | ld de, iBuff + 62 : sub hl, de : ld a, h : or l : jr z, iCr 38 | 39 | pop hl : inc hl 40 | jr iLp 41 | 42 | iBS: pop hl : push hl 43 | ld de, iBuff : sub hl, de : ld a, h : or l 44 | pop hl :jr z, iLp 45 | 46 | dec hl : ld (hl), 0 47 | jr iLp 48 | 49 | iCr pop hl : xor a : ld (hl), a : push hl 50 | iNth pop hl: jr iLp 51 | 52 | cleanIBuff: 53 | ld bc, 64 : ld hl, iBuff : ld de, iBuff + 1 : ld (hl), 0 : ldir 54 | ret 55 | 56 | iRet: 57 | pop hl 58 | 59 | ld b, 20 : ld c, 0 : call gotoXY 60 | ld hl, cleanLine :call printZ64 61 | ret 62 | 63 | iBuff defs 65 -------------------------------------------------------------------------------- /uGophy/main.asm: -------------------------------------------------------------------------------- 1 | ;; (c) 2019 Alexander Sharikhin 2 | ;; This program is free software: you can redistribute it and/or modify 3 | ;; it under the terms of the GNU General Public License as published by 4 | ;; the Free Software Foundation, either version 3 of the License, or 5 | ;; (at your option) any later version. 6 | ;; 7 | ;; This program is distributed in the hope that it will be useful, 8 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | ;; GNU General Public License for more details. 11 | ;; 12 | ;; You should have received a copy of the GNU General Public License 13 | ;; along with this program. If not, see . 14 | 15 | DEVICE ZXSPECTRUM128 16 | org #6000 17 | Start: 18 | di 19 | res 4, (iy+1) 20 | IFNDEF ZX48 21 | stack_pointer = #5aff 22 | call checkHighMem : jp nz, noMem 23 | 24 | xor a : out (#fe), a : call changeBank 25 | IFDEF TRDOS 26 | ld sp, $ ; We don't care about anything before 27 | ELSE 28 | ld de, #4000 : ld bc, eop - player : ld hl, player : ldir 29 | ENDIF 30 | ELSE 31 | jp zx48start 32 | ds 128 33 | stack_pointer = $ - 1 34 | ENDIF 35 | zx48start: 36 | ld sp, stack_pointer 37 | xor a : ld (#5c6a), a ; Thank you, Mario Prato, for feedback 38 | ei 39 | 40 | call renderHeader 41 | 42 | IFDEF PLUS3DOS 43 | call initDos 44 | ENDIF 45 | 46 | IFDEF TRDOS 47 | ld hl, init1 : call putStringZ 48 | 49 | call Dos.init 50 | ld de, work_dir : call Dos.cwd 51 | or a : jp nz, .dirError 52 | 53 | ld hl, init2 : call putStringZ 54 | ; Read player from disk 55 | ld l, Dos.FA_READ, bc, player_name : call Dos.fopen 56 | ld bc, #4000, de, 3061 : call Dos.fread 57 | call Dos.fclose 58 | 59 | xor a : ld (#5c6a), a ; Thank you, Mario Prato, for feedback 60 | ei 61 | 62 | ld hl, init3 : call putStringZ 63 | ENDIF 64 | 65 | IFNDEF SPECTRANET 66 | call initWifi 67 | ENDIF 68 | 69 | call wSec 70 | 71 | ld de, path : ld hl, server : ld bc, port : call openPage 72 | 73 | jp showPage 74 | .dirError 75 | ld hl, .err : call putStringZ 76 | jr $ 77 | 78 | .err db "Can't enter 'wifi' directory",13,"Computer halted",0 79 | 80 | IFNDEF ZX48 81 | noMem: 82 | ld hl, no128k 83 | nmLp: 84 | push hl 85 | ld a, (hl) 86 | and a : jr z, $ 87 | rst #10 88 | pop hl 89 | inc hl 90 | jp nmLp 91 | ENDIF 92 | 93 | init1 db "Initing sd card", 13, 0 94 | init2 db "Loading PT3 player", 13, 0 95 | init3 db "Initing Wifi module", 13, 0 96 | 97 | wSec: ei : ld b, 50 98 | wsLp halt : djnz wsLp 99 | IFDEF TIMEXSCR 100 | include "tscreen.asm" 101 | ELSE 102 | IFDEF PROFISCR 103 | include "profiscreen.asm" 104 | ELSE 105 | include "screen64.asm" 106 | ENDIF 107 | ENDIF 108 | include "keyboard.asm" 109 | include "utils.asm" 110 | include "gopher.asm" 111 | include "render.asm" 112 | include "textrender.asm" 113 | include "ring.asm" 114 | 115 | IFDEF PLUS3DOS 116 | include "p3dos.asm" 117 | ENDIF 118 | 119 | IFDEF ESXDOS 120 | include "esxdos.asm" 121 | ENDIF 122 | 123 | IFDEF AY 124 | include "wifi.asm" 125 | include "ay-uart.asm" 126 | ENDIF 127 | 128 | IFDEF UNO 129 | include "uno-uart.asm" 130 | include "wifi.asm" 131 | ENDIF 132 | 133 | IFDEF ZIFI 134 | include "zifi-uart.asm" 135 | include "wifi.asm" 136 | ENDIF 137 | 138 | IFDEF SPECTRANET 139 | include "spectranet.asm" 140 | ENDIF 141 | 142 | work_dir db "wifi",0 143 | 144 | player_name db "player.bin", 0 145 | 146 | open_lbl db 'Opening connection to ', 0 147 | 148 | path db '/uhello' 149 | defs 248 150 | server db 'nihirash.net' 151 | defs 58 152 | port db '70' 153 | defs 5 154 | db 0 155 | 156 | IFDEF TRDOS 157 | include "dos/ochkodos.asm" 158 | page_buffer equ Dos.bin 159 | ELSE 160 | page_buffer equ $ 161 | ENDIF 162 | 163 | display "PAGE buffer:", $ 164 | IFNDEF ZX48 165 | no128k db 13, "You're in 48k mode!", 13, 13 166 | db "Current version require full", 13 167 | db "128K memory access", 13, 13 168 | db "System halted!", 0 169 | ENDIF 170 | IFNDEF ZX48 171 | 172 | player 173 | IFNDEF TRDOS 174 | DISPLAY "Player starts:" , $ 175 | include "vtpl.asm" 176 | DISPLAY "Player ends: ", $ 177 | ENT 178 | ENDIF 179 | ENDIF 180 | eop equ $ 181 | SAVEBIN "ugoph.bin", Start, $ - Start 182 | 183 | SAVETAP "ugoph.tap", Start 184 | 185 | SAVEHOB "ugoph.$c", "ugoph.C", Start, $ - Start 186 | 187 | IFDEF DEBUG 188 | SAVESNA "ugoph.sna", Start 189 | ENDIF 190 | -------------------------------------------------------------------------------- /uGophy/p3dos.asm: -------------------------------------------------------------------------------- 1 | DOS_READ = #0112 2 | DOS_WRITE = #115 3 | DOS_OPEN = #0106 4 | DOS_CLOSE = #0109 5 | DOS_MOTOR_OFF = #019C 6 | DOS_SET_1346 = #013F 7 | 8 | CMR0 = #7FFD 9 | 10 | ; +3DOS constants 11 | OPEN_ACTION_ERROR_EXISTS = 0 12 | OPEN_ACTION_POSITION_TO_DATA = 1 13 | OPEN_ACTION_POSITION_TO_HEADER = 2 14 | OPEN_ACTION_MAKE_BACKUP = 3 15 | OPEN_ACTION_OVERWRITE = 4 16 | 17 | CREATE_ACTION_DONTCREATE = 0 18 | CREATE_ACTION_POINT_TO_DATA = 1 19 | CREATE_ACTION_POINT_TO_HEADER = 2 20 | 21 | FILE_TYPE_BASIC = 0 22 | FILE_TYPE_NUM_ARRAY = 1 23 | FILE_TYPE_CHR_ARRAY = 2 24 | FILE_TYPE_BYTES = 3 25 | 26 | ACCESS_MODE_EXCLUSIVE_READ = 1 27 | ACCESS_MODE_EXCLUSIVE_WRITE = 2 28 | ACCESS_MODE_EXCLUSIVE_READ_WRITE = 3 29 | ACCESS_MODE_SHARED = 5 30 | 31 | FMODE_CREATE = 0 32 | 33 | initDos: 34 | ld ix, DOS_SET_1346 : ld hl,0 : ld d,h : ld e,d : call plus3dos ; disable RAM DISK 35 | ret 36 | 37 | ; C - access mode 38 | ; D - Create action 39 | ; E - Open action 40 | ; HL - filename 41 | fopen: 42 | ld b, 1 43 | push hl 44 | .l1 45 | inc hl ; Anyway filename more than one symbol 46 | ld a, (hl) 47 | and a 48 | jr nz, .l1 49 | ld a, #ff : ld (hl), a 50 | pop hl 51 | ld ix, DOS_OPEN : call plus3dos 52 | ret c 53 | jp error 54 | 55 | ; C - page 56 | ; DE - byte count 57 | ; HL - Address 58 | fread: 59 | ld b, 1 : ld ix, DOS_READ 60 | jp plus3dos 61 | 62 | ; C - page 63 | ; DE - Bytes 64 | ; HL - Buffer 65 | fwrite: 66 | ld b, 1 : ld ix, DOS_WRITE 67 | jp plus3dos 68 | 69 | fclose: 70 | ld b, 1 : ld ix, DOS_CLOSE 71 | call plus3dos 72 | ld ix, DOS_MOTOR_OFF 73 | jp plus3dos 74 | 75 | error: 76 | ld a, 2 77 | out (254), a 78 | ld hl, dos_error 79 | jp putStringZ 80 | 81 | 82 | setDOS: 83 | di 84 | push bc 85 | push af 86 | ld bc, CMR0 87 | ld a,(bankm) 88 | res 4,a 89 | or 7 90 | ld (bankm),a 91 | out (c),a 92 | pop af 93 | pop bc 94 | ret 95 | 96 | plus3dos: 97 | call setDOS 98 | ld (adds+1),ix 99 | adds: call 0 100 | setBASIC: 101 | di 102 | push af 103 | ld bc, CMR0 104 | ld a,(bankm) 105 | set 4,a 106 | and #0f8 107 | ld (bankm),a 108 | out (c),a 109 | pop af 110 | ret 111 | 112 | dos_error db 13, "DOS OPERATION ERROR!", 13, 0 -------------------------------------------------------------------------------- /uGophy/profiscreen.asm: -------------------------------------------------------------------------------- 1 | ; Profi (512x240) screen routines 2 | ; 3 | ; Public definitions: 4 | ; clearScreen 5 | ; showCursor 6 | ; hideCursor 7 | ; putC 8 | ; gotoXY 9 | 10 | SCREEN_ROWS = 28 11 | 12 | showCursor: 13 | hideCursor: 14 | call showType 15 | ld a, (cursor_pos) 16 | ld d, a 17 | inverseLine: 18 | ld e, 0 19 | ld b, 64 20 | ilp 21 | push bc 22 | push de 23 | call findAddr 24 | ld a, 6 25 | ld b, #80 26 | call changeBank 27 | 28 | ld b, 8 29 | iCLP: 30 | ld a, (de) 31 | xor #ff 32 | ld (de), a 33 | inc d 34 | djnz iCLP 35 | pop de 36 | inc e 37 | pop bc 38 | djnz ilp 39 | 40 | ;xor a 41 | ;call changeBank 42 | 43 | ret 44 | 45 | gotoXY: 46 | ld (coords), bc 47 | ret 48 | 49 | mvCR: 50 | ld hl, (coords) 51 | inc h 52 | ld l, 0 53 | ld (coords), hl 54 | cp 24 55 | ret c 56 | ld hl, 0 57 | ld (coords), hl 58 | ret 59 | 60 | ; A - char 61 | putC: 62 | cp 13 63 | jr z, mvCR 64 | 65 | sub 32 66 | ld b, a 67 | 68 | ld de, (coords) 69 | ld a, e 70 | cp 64 71 | ret nc 72 | 73 | push bc 74 | 75 | ld a, 6 76 | call changeBank 77 | 78 | call findAddr 79 | pop af 80 | ld l, a 81 | ld h, 0 82 | add hl, hl 83 | add hl, hl 84 | add hl, hl 85 | ld bc, font 86 | add hl, bc 87 | ld b, 8 88 | pLp: 89 | ld a, (HL) 90 | ld (DE), A 91 | inc hl 92 | inc d 93 | djnz pLp 94 | ld hl, (coords) 95 | inc l 96 | ld (coords), hl 97 | ret 98 | 99 | ; D - Y 100 | ; E - X 101 | ; OUT: de - coords 102 | findAddr: 103 | ld a, e 104 | srl a 105 | ld e, a 106 | ld hl, #8000 107 | jr c, fa1 108 | ld hl, #A000 109 | fa1: 110 | LD A,D 111 | AND 7 112 | RRCA 113 | RRCA 114 | RRCA 115 | OR E 116 | LD E,A 117 | LD A,D 118 | AND 24 119 | OR 64 120 | LD D,A 121 | ADD hl, de 122 | ex hl, de 123 | ret 124 | 125 | clearScreen: 126 | 127 | ld a, 6 : call changeBank ; RAM06 128 | xor a : call changeBankHiProfi 129 | ld a, #ff : out (#fe), a ; black border (inversed on profi screen) 130 | 131 | di 132 | ld hl,0 : ld d,h : ld e,h : ld b,h :ld c,b 133 | add hl,sp 134 | ld sp, 0 ; #c000 + 16384 ; profi pixels (both banks) 135 | clgloop 136 | DUP 32 137 | push de 138 | EDUP 139 | djnz clgloop ; 256 times 140 | ld sp,hl 141 | 142 | ; RAM 3A = 111 dffd, 010 7ffd 143 | ld a, 2 : call changeBank 144 | ld a, 7 :call changeBankHiProfi 145 | 146 | ld hl,0 : ld d,#47 : ld e,#47 : ld b,h :ld c,b ; #47 = white on black 147 | add hl,sp 148 | ld sp, 0 ; #c000 + 16384 ; profi attrs (both banks) 149 | claloop 150 | DUP 32 151 | push de 152 | EDUP 153 | djnz claloop ; 256 times 154 | ld sp,hl 155 | 156 | xor a : call changeBank 157 | xor a : call changeBankHiProfi 158 | 159 | ei 160 | ret 161 | 162 | coords dw 0 163 | attr_screen db 0 ; just for compatibility 164 | ; Using ZX-Spectrum font - 2K economy 165 | font equ #3D00 -------------------------------------------------------------------------------- /uGophy/ring.asm: -------------------------------------------------------------------------------- 1 | ; Pushes A to ring buffer 2 | pushRing 3 | push af 4 | ld b, 32 : ld hl, ring_buffer + 1 : ld de, ring_buffer 5 | ringL 6 | ld a, (hl) : ld (de), a : inc hl : inc de : djnz ringL 7 | pop af 8 | ld hl, ring_buffer + 31 : ld (hl), a 9 | ret 10 | 11 | ; HL - Compare string(null terminated) 12 | ; A - 0 NOT Found 13 | ; 1 Found 14 | searchRing: 15 | ld b, 0 : push hl 16 | serlp: 17 | ld a, (hl) : inc hl : inc b : and a : jp nz, serlp 18 | dec b : pop hl : push bc : push hl 19 | SRWork: 20 | pop hl 21 | ld de, ring_buffer + 32 22 | srcLp 23 | dec de : djnz srcLp 24 | pop bc 25 | ringCmpLp 26 | push bc : push af 27 | ld a, (de) : ld b, a 28 | pop af : ld a, (hl) : cp b : pop bc : ld a, 0 : ret nz 29 | inc de : inc hl 30 | djnz ringCmpLp 31 | ld a, 1 32 | ret 33 | 34 | clearRing: 35 | xor a : ld hl, ring_buffer : ld de, ring_buffer + 1 : ld bc, 32 : ld (hl), a : ldir 36 | ret 37 | 38 | ring_buffer dup 33 39 | defb 0 40 | edup -------------------------------------------------------------------------------- /uGophy/screen64.asm: -------------------------------------------------------------------------------- 1 | ; Public definitions: 2 | ; clearScreen 3 | ; showCursor 4 | ; hideCursor 5 | ; putC 6 | ; gotoXY 7 | 8 | SCREEN_ROWS = 20 9 | 10 | clearScreen: 11 | IFNDEF ZX48 12 | ld a, 7 : call changeBank 13 | ENDIF 14 | 15 | xor a 16 | out (#fe), a 17 | IFNDEF ZX48 18 | ld hl, #c000 19 | ld de, #c001 20 | ELSE 21 | ld hl, #4000 22 | ld de, #4001 23 | ENDIF 24 | ld (hl), 0 25 | ld bc, #17FF 26 | ldir 27 | IFNDEF ZX48 28 | ld hl, #d800 29 | ld de, #d801 30 | ELSE 31 | ld hl, #5800 32 | ld de, #5801 33 | ENDIF 34 | 35 | ld a, (attr_screen) 36 | ld (hl), a 37 | ld bc, #2FF 38 | ldir 39 | 40 | ld bc, 0 41 | call gotoXY 42 | ret 43 | 44 | showCursor: 45 | IFNDEF ZX48 46 | ld a, 7 : call changeBank 47 | ENDIF 48 | 49 | ld a, (cursor_pos) 50 | ld c, 0 51 | ld b, a 52 | call bc_to_attr 53 | ld (hl), #C 54 | ld de, hl 55 | inc de 56 | ld bc, 31 57 | ldir 58 | call showType 59 | ret 60 | 61 | hideCursor: 62 | IFNDEF ZX48 63 | ld a, 7 : call changeBank 64 | ENDIF 65 | 66 | ld a, (cursor_pos) 67 | ld b, a 68 | ld c, 0 69 | call bc_to_attr 70 | ld (hl), #07 71 | ld de, hl 72 | inc de 73 | ld bc, 31 74 | ldir 75 | ret 76 | 77 | 78 | ; Print just one symbol 79 | ; A - symbol 80 | putC 81 | cp 13 82 | jr z, mvCR 83 | or a 84 | cp ' ' 85 | ret c 86 | 87 | IFNDEF ZX48 88 | push af 89 | ld a, 7 90 | call changeBank 91 | pop af 92 | ENDIF 93 | 94 | ld hl, single_symbol 95 | ld (hl), a 96 | ld hl, single_symbol_print 97 | jp print64 98 | 99 | mvCR 100 | ld bc, (col_screen) 101 | inc b 102 | ld c, 0 103 | ld a, 0 104 | ld (half_tile_screen), a 105 | call gotoXY 106 | ret 107 | 108 | ; Set console coordinates 109 | ; b = row(0..23), c = column (0..63) 110 | ; 111 | gotoXY: 112 | ld a, 0 113 | ld (half_tile_screen), a 114 | ld (col_screen), bc 115 | ld a, 22 116 | cp b 117 | jp s, scrl 118 | ret 119 | scrl 120 | ld b, 22 121 | ld (col_screen) ,bc 122 | jp scroll_up8 123 | 124 | 125 | ; Put string with coordinates 126 | ; b= row (0..23), c=col (0..63) 127 | ; hl - string pointer that's begins from symbol count 128 | printAt64: 129 | call gotoXY 130 | 131 | ; Put string 132 | ; hl - string pointer that's begins from symbol count 133 | print64 134 | ld a,(hl) 135 | and a 136 | ret z 137 | 138 | push hl 139 | call calc_addr_attr 140 | ld a,(attr_screen) 141 | ld (hl),a 142 | pop hl 143 | 144 | call calc_addr_scr 145 | 146 | ld a,(half_tile_screen) 147 | bit 0,a 148 | ld a,(hl) 149 | jp nz,print64_4 150 | print64_3 151 | push af 152 | push hl 153 | call calc_addr_attr 154 | ld a,(attr_screen) 155 | ld (hl),a 156 | pop hl 157 | 158 | inc hl 159 | push hl 160 | 161 | ld a,(hl) 162 | ld l,a 163 | ld h,0 164 | add hl,hl 165 | add hl,hl 166 | add hl,hl 167 | ld bc,font64 168 | add hl,bc 169 | 170 | push de 171 | 172 | ld b,6 173 | xor a 174 | ld (de),a 175 | print64_1 176 | inc d 177 | ld a,(hl) 178 | and #f0 179 | ld (de),a 180 | inc hl 181 | djnz print64_1 182 | 183 | inc d 184 | xor a 185 | ld (de),a 186 | 187 | ld a,1 188 | ld (half_tile_screen),a 189 | 190 | pop de 191 | pop hl 192 | pop af 193 | 194 | dec a 195 | ret z 196 | 197 | print64_4 198 | push af 199 | 200 | inc hl 201 | push hl 202 | 203 | ld a,(hl) 204 | ld l,a 205 | ld h,0 206 | add hl,hl 207 | add hl,hl 208 | add hl,hl 209 | ld bc,font64 210 | add hl,bc 211 | 212 | push de 213 | 214 | ld b,6 215 | xor a 216 | ld (de),a 217 | print64_2 218 | inc d 219 | ld a,(hl) 220 | and #0f 221 | ld c,a 222 | ld a,(de) 223 | or c 224 | ld (de),a 225 | inc hl 226 | djnz print64_2 227 | 228 | inc d 229 | xor a 230 | ld (de),a 231 | 232 | ld (half_tile_screen),a 233 | 234 | pop de 235 | 236 | call move_cr64 237 | 238 | pop hl 239 | pop af 240 | dec a 241 | 242 | jp nz,print64_3 243 | 244 | ret 245 | 246 | ; move cursor 247 | move_cr64 248 | inc de 249 | 250 | ld hl,col_screen 251 | inc (hl) 252 | ld a,(hl) 253 | 254 | cp 32 255 | ret c 256 | 257 | xor a 258 | ld (half_tile_screen),a 259 | ld (hl),a 260 | ld c,a 261 | 262 | inc hl 263 | inc (hl) 264 | ld a,(hl) 265 | ld b,a 266 | 267 | cp 24 268 | jp c,move_cr64_01 269 | 270 | ld a,23 271 | ld (hl),a 272 | ld b,a 273 | 274 | push bc 275 | call scroll_up8 276 | pop bc 277 | 278 | move_cr64_01 279 | call calc_addr_scr 280 | ret 281 | 282 | calc_addr_scr 283 | ld a,b 284 | ld d,a 285 | rrca 286 | rrca 287 | rrca 288 | and a,224 289 | add a,c 290 | ld e,a 291 | ld a,d 292 | and 24 293 | IFNDEF ZX48 294 | or #c0 295 | ELSE 296 | or #40 297 | ENDIF 298 | ld d,a 299 | ret 300 | 301 | calc_addr_attr 302 | ld bc,(col_screen) 303 | bc_to_attr: 304 | ld a,b 305 | rrca 306 | rrca 307 | rrca 308 | ld l,a 309 | and 31 310 | IFNDEF ZX48 311 | or #d8 312 | ELSE 313 | or #58 314 | ENDIF 315 | ld h,a 316 | ld a,l 317 | and 252 318 | or c 319 | ld l,a 320 | ret 321 | 322 | scroll_up8 323 | ld hl,table_addr_scr 324 | ld b,184 325 | 326 | scroll_up8_01 327 | push bc 328 | 329 | ld e,(hl) 330 | inc hl 331 | ld d,(hl) 332 | inc hl 333 | 334 | push hl 335 | 336 | ld bc,14 337 | add hl,bc 338 | ld c,(hl) 339 | inc hl 340 | ld b,(hl) 341 | 342 | ld h,b 343 | ld l,c 344 | 345 | ld bc,32 346 | ldir 347 | 348 | pop hl 349 | pop bc 350 | djnz scroll_up8_01 351 | 352 | ld b,8 353 | 354 | scroll_up8_02 355 | push bc 356 | 357 | ld e,(hl) 358 | inc hl 359 | ld d,(hl) 360 | inc hl 361 | 362 | push hl 363 | 364 | ld h,d 365 | ld l,e 366 | inc de 367 | ld (hl),0 368 | ld bc,31 369 | ldir 370 | 371 | pop hl 372 | pop bc 373 | djnz scroll_up8_02 374 | IFNDEF ZX48 375 | ld de,#D800 376 | ld hl,#D820 377 | ELSE 378 | ld de,#5800 379 | ld hl,#5820 380 | ENDIF 381 | ld bc,736 382 | ldir 383 | 384 | ld a,(de) 385 | 386 | IFNDEF ZX48 387 | ld hl,#dae0 388 | ld de,#dae1 389 | ELSE 390 | ld hl,#5ae0 391 | ld de,#5ae1 392 | ENDIF 393 | ld (hl),a 394 | ld bc,31 395 | ldir 396 | 397 | ret 398 | 399 | 400 | font64 incbin "font.bin" 401 | table_addr_scr 402 | defw #4000,#4100,#4200,#4300,#4400,#4500,#4600,#4700 403 | defw #4020,#4120,#4220,#4320,#4420,#4520,#4620,#4720 404 | defw #4040,#4140,#4240,#4340,#4440,#4540,#4640,#4740 405 | defw #4060,#4160,#4260,#4360,#4460,#4560,#4660,#4760 406 | defw #4080,#4180,#4280,#4380,#4480,#4580,#4680,#4780 407 | defw #40a0,#41a0,#42a0,#43a0,#44a0,#45a0,#46a0,#47a0 408 | defw #40c0,#41c0,#42c0,#43c0,#44c0,#45c0,#46c0,#47c0 409 | defw #40e0,#41e0,#42e0,#43e0,#44e0,#45e0,#46e0,#47e0 410 | 411 | defw #4800,#4900,#4a00,#4b00,#4c00,#4d00,#4e00,#4f00 412 | defw #4820,#4920,#4a20,#4b20,#4c20,#4d20,#4e20,#4f20 413 | defw #4840,#4940,#4a40,#4b40,#4c40,#4d40,#4e40,#4f40 414 | defw #4860,#4960,#4a60,#4b60,#4c60,#4d60,#4e60,#4f60 415 | defw #4880,#4980,#4a80,#4b80,#4c80,#4d80,#4e80,#4f80 416 | defw #48a0,#49a0,#4aa0,#4ba0,#4ca0,#4da0,#4ea0,#4fa0 417 | defw #48c0,#49c0,#4ac0,#4bc0,#4cc0,#4dc0,#4ec0,#4fc0 418 | defw #48e0,#49e0,#4ae0,#4be0,#4ce0,#4de0,#4ee0,#4fe0 419 | 420 | defw #5000,#5100,#5200,#5300,#5400,#5500,#5600,#5700 421 | defw #5020,#5120,#5220,#5320,#5420,#5520,#5620,#5720 422 | defw #5040,#5140,#5240,#5340,#5440,#5540,#5640,#5740 423 | defw #5060,#5160,#5260,#5360,#5460,#5560,#5660,#5760 424 | defw #5080,#5180,#5280,#5380,#5480,#5580,#5680,#5780 425 | defw #50a0,#51a0,#52a0,#53a0,#54a0,#55a0,#56a0,#57a0 426 | defw #50c0,#51c0,#52c0,#53c0,#54c0,#55c0,#56c0,#57c0 427 | defw #50e0,#51e0,#52e0,#53e0,#54e0,#55e0,#56e0,#57e0 428 | 429 | 430 | string_temp defb 0 431 | dup 255 432 | defb 32 433 | edup 434 | 435 | col_screen defb 0 436 | row_screen defb 0 437 | half_tile_screen defb 0 438 | attr_screen defb 07 439 | 440 | col_screen_temp defw 0 441 | half_tile_screen_temp defb 0 442 | 443 | single_symbol_print defb 1 444 | single_symbol defb 0 445 | -------------------------------------------------------------------------------- /uGophy/spectranet.asm: -------------------------------------------------------------------------------- 1 | include "spectranet/spectranet.inc" 2 | include "spectranet/sockdefs.inc" 3 | 4 | ; HL - domain 5 | ; BC - port 6 | openTcp: 7 | display "Open tcp: ", $ 8 | push BC 9 | ld de, ip_buffer 10 | ld ix, GETHOSTBYNAME 11 | call IXCALL 12 | 13 | jp c, tcpError 14 | ld c, SOCK_STREAM 15 | ld hl, SOCKET 16 | call HLCALL 17 | 18 | jp c, tcpError 19 | ld (sock_fd), a 20 | pop bc 21 | ld de, ip_buffer 22 | ld hl, CONNECT 23 | call HLCALL 24 | 25 | jp c, tcpError 26 | 27 | ld a, 1 28 | ld (connectionOpen), a 29 | ret 30 | 31 | ; DE - pointer to string 32 | ; BC - count 33 | sendTcp: 34 | display "Send Tcp: ", $ 35 | ld a, (sock_fd) 36 | ld hl, SEND 37 | call HLCALL 38 | jp c, tcpError 39 | ret 40 | 41 | getPacket: 42 | ld hl, 0 43 | ld (bytes_avail), hl 44 | 45 | ld a, (sock_fd) 46 | ld hl, POLLFD 47 | call HLCALL 48 | ld a, c 49 | 50 | cp 2 51 | jp z, fin 52 | 53 | ld a, (sock_fd) 54 | ld de, output_buffer 55 | ld bc, 2048 56 | ld hl, RECV 57 | call HLCALL 58 | jp c, fin 59 | ld (bytes_avail), bc 60 | ret 61 | 62 | fin: 63 | xor a 64 | ld (connectionOpen), a 65 | 66 | ld a, (sock_fd) 67 | ld hl, CLOSE 68 | call HLCALL 69 | ret 70 | 71 | tcpError: 72 | di 73 | halt 74 | 75 | ip_buffer defs 4 76 | sock_fd db 0 77 | 78 | output_buffer defs 2050 79 | bytes_avail dw 0 -------------------------------------------------------------------------------- /uGophy/spectranet/sockdefs.inc: -------------------------------------------------------------------------------- 1 | ;The MIT License 2 | ; 3 | ;Copyright (c) 2008 Dylan Smith 4 | ; 5 | ;Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ;of this software and associated documentation files (the "Software"), to deal 7 | ;in the Software without restriction, including without limitation the rights 8 | ;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ;copies of the Software, and to permit persons to whom the Software is 10 | ;furnished to do so, subject to the following conditions: 11 | ; 12 | ;The above copyright notice and this permission notice shall be included in 13 | ;all copies or substantial portions of the Software. 14 | ; 15 | ;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ;THE SOFTWARE. 22 | 23 | ; General definitions. These are not hardware specific (generally). 24 | 25 | ; File descriptor flags. 26 | FD_CLOSED equ 0x80 27 | CLOSEDBIT equ 7 28 | FD_VIRTUAL equ 0x40 29 | VIRTBIT equ 6 30 | FD_VFS equ 0x20 ; for file descriptors that are valid 31 | VFSBIT equ 5 ; but are not sockets 32 | NOTSOCKMASK equ 0xE0 ; all hw sockets must be < 0x1F 33 | SOCKMASK equ 0x1F 34 | 35 | ; Error return codes - base socket library 36 | EBUGGERED equ 0xFF 37 | ESNFILE equ 0xFE ; TODO: Rationalize these and make 38 | ESBADF equ 0xFD ; compatible with filesystem 39 | ECONNRESET equ 0xFC 40 | ETIMEDOUT equ 0xFB 41 | ECONNREFUSED equ 0xFA 42 | 43 | ; Error return codes - DNS 44 | HOST_NOT_FOUND equ 0xEF 45 | NO_RECOVERY equ 0xEE 46 | NO_ADDRESS equ 0xED 47 | DNS_TIMEOUT equ 0xEC 48 | 49 | ; Socket types 50 | SOCK_STREAM equ 0x01 51 | SOCK_DGRAM equ 0x02 52 | SOCK_RAW equ 0x03 53 | 54 | -------------------------------------------------------------------------------- /uGophy/spectranet/spectranet.inc: -------------------------------------------------------------------------------- 1 | ;The MIT License 2 | ; 3 | ;Copyright (c) 2008 Dylan Smith 4 | ; 5 | ;Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ;of this software and associated documentation files (the "Software"), to deal 7 | ;in the Software without restriction, including without limitation the rights 8 | ;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ;copies of the Software, and to permit persons to whom the Software is 10 | ;furnished to do so, subject to the following conditions: 11 | ; 12 | ;The above copyright notice and this permission notice shall be included in 13 | ;all copies or substantial portions of the Software. 14 | ; 15 | ;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ;THE SOFTWARE. 22 | 23 | ; This file can be included in assembly language programs to give 24 | ; symbolic access to the public jump table entry points. 25 | 26 | ; Hardware page-in entry points 27 | MODULECALL equ 0x3FF8 28 | MODULECALL_NOPAGE equ 0x28 29 | PAGEIN equ 0x3FF9 30 | PAGEOUT equ 0x007C 31 | HLCALL equ 0x3FFA 32 | IXCALL equ 0x3FFD 33 | 34 | ; Port defines 35 | CTRLREG equ 0x033B 36 | CPLDINFO equ 0x023B 37 | 38 | ; Jump table entry points 39 | SOCKET equ 0x3E00 ; Allocate a socket 40 | CLOSE equ 0x3E03 ; Close a socket 41 | LISTEN equ 0x3E06 ; Listen for incoming connections 42 | ACCEPT equ 0x3E09 ; Accept an incoming connection 43 | BIND equ 0x3E0C ; Bind a local address to a socket 44 | CONNECT equ 0x3E0F ; Connect to a remote host 45 | SEND equ 0x3E12 ; Send data 46 | RECV equ 0x3E15 ; Receive data 47 | SENDTO equ 0x3E18 ; Send data to an address 48 | RECVFROM equ 0x3E1B ; Receive data from an address 49 | POLL equ 0x3E1E ; Poll a list of sockets 50 | POLLALL equ 0x3E21 ; Poll all open sockets 51 | POLLFD equ 0x3E24 ; Poll a single socket 52 | GETHOSTBYNAME equ 0x3E27 ; Look up a hostname 53 | PUTCHAR42 equ 0x3E2A ; 42 column print write a character 54 | PRINT42 equ 0x3E2D ; 42 column print a null terminated string 55 | CLEAR42 equ 0x3E30 ; Clear the screen and reset 42-col print 56 | SETPAGEA equ 0x3E33 ; Sets page area A 57 | SETPAGEB equ 0x3E36 ; Sets page area B 58 | LONG2IPSTRING equ 0x3E39 ; Convert a 4 byte big endian long to an IP 59 | IPSTRING2LONG equ 0x3E3C ; Convert an IP to a 4 byte big endian long 60 | ITOA8 equ 0x3E3F ; Convert a byte to ascii 61 | RAND16 equ 0x3E42 ; 16 bit PRNG 62 | REMOTEADDRESS equ 0x3E45 ; Fill struct sockaddr_in 63 | IFCONFIG_INET equ 0x3E48 ; Set IPv4 address 64 | IFCONFIG_NETMASK equ 0x3E4B ; Set netmask 65 | IFCONFIG_GW equ 0x3E4E ; Set gateway 66 | INITHW equ 0x3E51 ; Set the MAC address and initial hw registers 67 | GETHWADDR equ 0x3E54 ; Read the MAC address 68 | DECONFIG equ 0x3E57 ; Deconfigure inet, netmask and gateway 69 | MAC2STRING equ 0x3E5A ; Convert 6 byte MAC address to a string 70 | STRING2MAC equ 0x3E5D ; Convert a hex string to a 6 byte MAC address 71 | ITOH8 equ 0x3E60 ; Convert accumulator to hex string 72 | HTOI8 equ 0x3E63 ; Convert hex string to byte in A 73 | GETKEY equ 0x3E66 ; Get a key from the keyboard, and put it in A 74 | KEYUP equ 0x3E69 ; Wait for key release 75 | INPUTSTRING equ 0x3E6C ; Read a string into buffer at DE 76 | GET_IFCONFIG_INET equ 0x3E6F ; Gets the current IPv4 address 77 | GET_IFCONFIG_NETMASK equ 0x3E72 ; Gets the current netmask 78 | GET_IFCONFIG_GW equ 0x3E75 ; Gets the current gateway address 79 | SETTRAP equ 0x3E78 ; Sets the programmable trap 80 | DISABLETRAP equ 0x3E7B ; Disables the programmable trap 81 | ENABLETRAP equ 0x3E7E ; Enables the programmable trap 82 | PUSHPAGEA equ 0x3E81 ; Pages a page into area A, pushing the old one 83 | POPPAGEA equ 0x3E84 ; Restores the previous page in area A 84 | PUSHPAGEB equ 0x3E87 ; Pages into area B pushing the old one 85 | POPPAGEB equ 0x3E8A ; Restores the previous page in area B 86 | PAGETRAPRETURN equ 0x3E8D ; Returns from a trap to page area B 87 | TRAPRETURN equ 0x3E90 ; Returns from a trap that didn't page area B 88 | ADDBASICEXT equ 0x3E93 ; Adds a BASIC command 89 | STATEMENT_END equ 0x3E96 ; Check for statement end, exit at syntax time 90 | EXIT_SUCCESS equ 0x3E99 ; Use this to exit successfully after cmd 91 | PARSE_ERROR equ 0x3E9C ; Use this to exit to BASIC with a parse error 92 | RESERVEPAGE equ 0x3E9F ; Reserve a page of static RAM 93 | FREEPAGE equ 0x3EA2 ; Free a page of static RAM 94 | REPORTERR equ 0x3EA5 ; report an error via BASIC 95 | 96 | ; Filesystem functions 97 | MOUNT equ 0x3EA8 98 | UMOUNT equ 0x3EAB 99 | OPENDIR equ 0x3EAE 100 | OPEN equ 0x3EB1 101 | UNLINK equ 0x3EB4 102 | MKDIR equ 0x3EB7 103 | RMDIR equ 0x3EBA 104 | SIZE equ 0x3EBD 105 | FREE equ 0x3EC0 106 | STAT equ 0x3EC3 107 | CHMOD equ 0x3EC6 108 | READ equ 0x3EC9 109 | WRITE equ 0x3ECC 110 | LSEEK equ 0x3ECF 111 | VCLOSE equ 0x3ED2 112 | VPOLL equ 0x3ED5 113 | READDIR equ 0x3ED8 114 | CLOSEDIR equ 0x3EDB 115 | CHDIR equ 0x3EDE 116 | GETCWD equ 0x3EE1 117 | RENAME equ 0x3EE4 118 | SETMOUNTPOINT equ 0x3EE7 119 | FREEMOUNTPOINT equ 0x3EEA 120 | RESALLOC equ 0x3EED 121 | 122 | 123 | ; Definitions 124 | ALLOCFD equ 1 125 | FREEFD equ 0 126 | ALLOCDIRHND equ 3 127 | FREEDIRHND equ 2 128 | 129 | ; POLL status bits 130 | BIT_RECV equ 2 131 | BIT_DISCON equ 1 132 | BIT_CONN equ 0 133 | 134 | -------------------------------------------------------------------------------- /uGophy/textrender.asm: -------------------------------------------------------------------------------- 1 | showText: 2 | DISPLAY "show text: ", $ 3 | xor a : ld (show_offset), a, (s_half), a 4 | reRenderText: 5 | call renderTextScreen 6 | showTxLp: 7 | call txControls 8 | IFNDEF ZX48 9 | xor a : call changeBank 10 | ENDIF 11 | dup 5 12 | halt 13 | edup 14 | jp showTxLp 15 | 16 | txControls: 17 | call inkey 18 | 19 | and a : ret z 20 | 21 | cp 'q' : jp z, txUp 22 | cp 'o' : jp z, txUp 23 | cp 'a' : jp z, txDn 24 | cp 'p' : jp z, txDn 25 | cp 'b' : jp z, .justBack 26 | cp 'n' : jp z, openURI 27 | cp 32 : jp z, .toggleHalf 28 | ret 29 | .justBack 30 | pop af 31 | jp historyBack 32 | .toggleHalf 33 | pop af 34 | ld a, (s_half) : xor #ff : ld (s_half), a 35 | jp reRenderText 36 | 37 | txUp: 38 | ld a, (show_offset) 39 | and a : ret z 40 | 41 | sub SCREEN_ROWS : ld (show_offset), a 42 | call renderTextScreen 43 | ret 44 | 45 | txDn: 46 | ld a, (show_offset) 47 | add SCREEN_ROWS : ld (show_offset), a 48 | 49 | call renderTextScreen 50 | ret 51 | 52 | renderTextScreen: 53 | DISPLAY "renderTextScreen: ", $ 54 | call renderHeader 55 | ld b, SCREEN_ROWS 56 | .loop 57 | push bc 58 | 59 | ld a, SCREEN_ROWS : sub b : ld b, a : ld a, (show_offset) : add b : ld b, a 60 | call renderTextLine 61 | 62 | pop bc 63 | djnz .loop 64 | DISPLAY "CRASH HERE?", $ 65 | ret 66 | 67 | 68 | renderTextLine: 69 | call findLine 70 | 71 | ld a, h : or l : ret z 72 | 73 | ld a, (hl) : and a : ret z 74 | ld a, (s_half) : and a : call nz, skipHalf64T 75 | call printL64 76 | call mvCR 77 | ret 78 | -------------------------------------------------------------------------------- /uGophy/tscreen.asm: -------------------------------------------------------------------------------- 1 | ; Timex screen routines 2 | 3 | SCREEN_ROWS = 20 4 | 5 | showCursor: 6 | hideCursor: 7 | call showType 8 | ld a, (cursor_pos) 9 | ld d, a 10 | inverseLine: 11 | ld e, 0 12 | ld b, 64 13 | ilp 14 | push bc 15 | push de 16 | call findAddr 17 | ld a, 7 18 | call changeBank 19 | 20 | ld b, 8 21 | iCLP: 22 | ld a, (de) 23 | xor #ff 24 | ld (de), a 25 | inc d 26 | djnz iCLP 27 | pop de 28 | inc e 29 | pop bc 30 | djnz ilp 31 | 32 | ;xor a 33 | ;call changeBank 34 | 35 | ret 36 | 37 | gotoXY: 38 | ld (coords), bc 39 | ret 40 | 41 | mvCR: 42 | ld hl, (coords) 43 | inc h 44 | ld l, 0 45 | ld (coords), hl 46 | cp 24 47 | ret c 48 | ld hl, 0 49 | ld (coords), hl 50 | ret 51 | 52 | ; A - char 53 | putC: 54 | cp 13 55 | jr z, mvCR 56 | 57 | sub 32 58 | ld b, a 59 | 60 | ld de, (coords) 61 | ld a, e 62 | cp 64 63 | ret nc 64 | 65 | push bc 66 | 67 | ld a, 7 68 | call changeBank 69 | 70 | call findAddr 71 | pop af 72 | ld l, a 73 | ld h, 0 74 | add hl, hl 75 | add hl, hl 76 | add hl, hl 77 | ld bc, font 78 | add hl, bc 79 | ld b, 8 80 | pLp: 81 | ld a, (HL) 82 | ld (DE), A 83 | inc hl 84 | inc d 85 | djnz pLp 86 | ld hl, (coords) 87 | inc l 88 | ld (coords), hl 89 | ret 90 | 91 | ; D - Y 92 | ; E - X 93 | ; OUT: de - coords 94 | findAddr: 95 | ld a, e 96 | srl a 97 | ld e, a 98 | ld hl, #A000 99 | jr c, fa1 100 | ld hl, #8000 101 | fa1: 102 | LD A,D 103 | AND 7 104 | RRCA 105 | RRCA 106 | RRCA 107 | OR E 108 | LD E,A 109 | LD A,D 110 | AND 24 111 | OR 64 112 | LD D,A 113 | ADD hl, de 114 | ex hl, de 115 | ret 116 | 117 | clearScreen: 118 | 119 | ld a, 7 120 | call changeBank 121 | 122 | ld c, #ff 123 | ld a, #3E 124 | out (c), a 125 | 126 | 127 | di 128 | ld hl,0 129 | ld d,h 130 | ld e,h 131 | ld b,h 132 | ld c,b 133 | add hl,sp 134 | ld sp,#c000 + 6144 135 | clgloop 136 | push de 137 | push de 138 | push de 139 | push de 140 | 141 | push de 142 | push de 143 | push de 144 | push de 145 | 146 | push de 147 | push de 148 | push de 149 | push de 150 | 151 | djnz clgloop 152 | 153 | ld b,c 154 | ld sp,#e000 + 6144 155 | clgloop2: 156 | push de 157 | push de 158 | push de 159 | push de 160 | 161 | push de 162 | push de 163 | push de 164 | push de 165 | 166 | push de 167 | push de 168 | push de 169 | push de 170 | 171 | djnz clgloop2 172 | 173 | ld sp,hl 174 | 175 | xor a 176 | call changeBank 177 | 178 | ei 179 | ret 180 | 181 | 182 | coords dw 0 183 | attr_screen db 0 ; just for compatibility 184 | ; Using ZX-Spectrum font - 2K economy 185 | font equ #3D00 186 | -------------------------------------------------------------------------------- /uGophy/ugoph3e.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nihirash/zx-net-tools/1601a9f454cd0e59f785be461e72d588da561846/uGophy/ugoph3e.bas -------------------------------------------------------------------------------- /uGophy/uno-uart.asm: -------------------------------------------------------------------------------- 1 | UART_DATA_REG = #c6 2 | UART_STAT_REG = #c7 3 | UART_BYTE_RECIVED = #80 4 | UART_BYTE_SENDING = #40 5 | SCANDBLCTRL_REG = #0B 6 | ZXUNO_ADDR = #FC3B 7 | ZXUNO_REG = #FD3B 8 | 9 | 10 | ; Enable UART 11 | ; Cleaning all flags by reading UART regs 12 | ; Wastes AF and BC 13 | uartBegin: 14 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 15 | ld bc, ZXUNO_REG : in A, (c) 16 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 17 | ld bc, ZXUNO_REG : in A, (c) 18 | ld b, #ff 19 | .loop 20 | push bc 21 | call uartRead 22 | pop bc 23 | djnz .loop 24 | 25 | ld a, SCANDBLCTRL_REG : ld bc, ZXUNO_ADDR : out (c), a 26 | ld bc, ZXUNO_REG : in a, (c) : and #3f : or #80 : out (c), a 27 | ret 28 | 29 | ; Blocking read one byte 30 | uartReadBlocking: 31 | call uartRead 32 | push af : ld a, 1 : and b : jr nz, urb : pop af 33 | jp uartReadBlocking 34 | urb: 35 | pop af 36 | ret 37 | 38 | ; Write single byte to UART 39 | ; A - byte to write 40 | ; BC will be wasted 41 | uartWriteByte: 42 | push af 43 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 44 | waitWriteReady: 45 | ld bc, ZXUNO_REG : in A, (c) : and UART_BYTE_RECIVED 46 | jr nz, is_recvF 47 | checkSent: 48 | ld bc, ZXUNO_REG : in A, (c) : and UART_BYTE_SENDING 49 | jr nz, checkSent 50 | 51 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 52 | 53 | ld bc, ZXUNO_REG : pop af : out (c), a 54 | ret 55 | is_recvF: 56 | push af : push hl 57 | 58 | ld hl, is_recv : ld a, 1 : ld (hl), a 59 | 60 | pop hl : pop af 61 | jr checkSent 62 | 63 | ; Is data avail in UART 64 | ; NZ - Data Presents 65 | ; Z - Data absent 66 | uartAvail: 67 | ld a, (is_recv) : and 1 : ret nz 68 | ld a, (poked_byte) : and 1 : ret nz 69 | 70 | call uartRead 71 | 72 | push af : ld a, b : and 1 : jr z, noneData : pop af 73 | 74 | push af 75 | ld hl, byte_buff : ld (hl), a : ld hl, poked_byte : ld a, 1 : ld (hl), a 76 | pop af 77 | 78 | ld b, a : ld a, 1 : or a : ld a, b 79 | ret 80 | noneData: 81 | pop bc : xor a 82 | ret 83 | 84 | ; Read byte from UART 85 | ; A: byte 86 | ; B: 87 | ; 1 - Was read 88 | ; 0 - Nothing to read 89 | uartRead: 90 | ld a, (poked_byte) : and 1 : jr nz, retBuff 91 | 92 | ld a, (is_recv) : and 1 : jr nz, recvRet 93 | 94 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 95 | ld bc, ZXUNO_REG : in a, (c) : and UART_BYTE_RECIVED 96 | jr nz, retReadByte 97 | 98 | ld b, 0 99 | ret 100 | 101 | retReadByte: 102 | xor a : ld (poked_byte), a : ld (is_recv), a 103 | 104 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 105 | ld bc, ZXUNO_REG : in a, (c) 106 | 107 | ld b, 1 108 | ret 109 | 110 | recvRet: 111 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c),a 112 | 113 | ld bc, ZXUNO_REG : in a, (c) 114 | ld hl, is_recv : ld (hl), 0 115 | ld hl, poked_byte : ld (hl), 0 116 | 117 | ld b, 1 118 | ret 119 | 120 | retBuff 121 | ld a, 0 : ld (poked_byte), a : ld a, (byte_buff) 122 | ld b, 1 123 | ret 124 | 125 | poked_byte defb 0 126 | byte_buff defb 0 127 | is_recv defb 0 -------------------------------------------------------------------------------- /uGophy/utils.asm: -------------------------------------------------------------------------------- 1 | bankm equ 23388 2 | IFNDEF ZX48 3 | ; This routine checks availability of extended(128K) memory. 4 | ; Output: 5 | ; Flag: Z - High memory available 6 | checkHighMem: 7 | xor a : call changeBank: ld hl, #c000 : xor a :ld (hl), a ; Let's write in zero page zero value 8 | inc a : call changeBank : ld a, 13 : ld (hl), a ; In other page - any other value. Let's write luck 13 9 | xor a : call changeBank : ld a, (hl) : and a ; When we back to zero page - still there zero?! 10 | ret 11 | 12 | ; A - memory bank 13 | changeBank: 14 | push af : ld bc, #7ffd : and #7 : or #18 : out (c), a: ld (bankm), a : pop af 15 | ret 16 | 17 | IFDEF PROFISCR 18 | changeBankHiProfi: 19 | push af : ld bc, #dffd : and #7 : or #80 : out (c), a : pop af 20 | ret 21 | 22 | changeBankHiSpectrum: 23 | push af : ld bc, #dffd : and #7 : out (c), a : pop af 24 | ret 25 | ENDIF 26 | 27 | ENDIF 28 | 29 | IFNDEF SPECTRANET 30 | ; Pushes to UART zero-terminated string 31 | ; HL - string poiner 32 | uartWriteStringZ: 33 | ld a, (hl) : and a : ret z 34 | 35 | push hl : call uartWriteByte : pop hl 36 | 37 | inc hl 38 | jp uartWriteStringZ 39 | ENDIF 40 | 41 | ; Print zero-terminated string 42 | ; HL - string pointer 43 | putStringZ: 44 | printZ64: 45 | ld a,(hl) : and a : ret z 46 | 47 | push hl : call putC : pop hl 48 | 49 | inc hl 50 | jr printZ64 51 | 52 | skipHalf64: 53 | ld b, 63 54 | .loop 55 | xor a : or b : ret z 56 | ld a, (hl) 57 | and a : ret z 58 | cp 09 : ret z 59 | inc hl 60 | dec b 61 | jr .loop 62 | 63 | skipHalf64T: 64 | ld b, 63 65 | .loop 66 | xor a : or b : ret z 67 | ld a, (hl) 68 | and a : ret z 69 | cp 13 : ret z 70 | cp 10 : ret z 71 | inc hl 72 | dec b 73 | jr .loop 74 | 75 | 76 | printT64: 77 | ld b, 63 78 | ptlp: 79 | xor a : or b : ret z 80 | 81 | ld a, (hl) 82 | 83 | and a : ret z 84 | cp 09 : ret z 85 | 86 | push bc 87 | 88 | push hl : call putC : pop hl 89 | 90 | inc hl : pop bc : dec b 91 | jr ptlp 92 | 93 | printL64: 94 | ld b, 63 95 | .loop 96 | xor a : or b : ret z 97 | ld a, (hl) 98 | 99 | and a : ret z 100 | cp #0A : ret z 101 | cp #0D : ret z 102 | 103 | push hl, bc : call putC : pop bc, hl 104 | dec b 105 | inc hl 106 | jr .loop 107 | 108 | ; HL - string 109 | ; Return: bc - len 110 | getStringLength: 111 | ld bc, 0 112 | strLnLp 113 | ld a, (hl) : and a : ret z 114 | inc bc 115 | inc hl 116 | jr strLnLp 117 | 118 | SkipWhitespace: 119 | ld a, (hl) 120 | 121 | cp ' ' : ret nz 122 | 123 | inc hl 124 | jr SkipWhitespace 125 | 126 | ; DE <= StringZ 127 | ; HL => output 128 | atoi: 129 | ld hl, 0 130 | .loop 131 | ld a, (de) 132 | 133 | and a : ret z 134 | cp 13 : ret z 135 | cp 9 : ret z 136 | 137 | sub 0x30 138 | ld c,l 139 | ld b,h 140 | add hl,hl 141 | add hl,hl 142 | add hl,bc 143 | add hl,hl 144 | ld c,a 145 | ld b,0 146 | add hl,bc 147 | 148 | inc de 149 | 150 | jr .loop 151 | 152 | findEnd: 153 | ld a,(hl) 154 | 155 | and a : ret z 156 | 157 | inc hl 158 | jr findEnd 159 | 160 | ;;;;;;;;;;;;;;;;;;;;;;;; 161 | 162 | ; Binary to decimal stuff 163 | ; From https://www.msx.org/forum/development/msx-development/32-bit-long-ascii 164 | 165 | ; Combined routine for conversion of different sized binary numbers into 166 | ; directly printable ASCII(Z)-string 167 | ; Input value in registers, number size and -related to that- registers to fill 168 | ; is selected by calling the correct entry: 169 | ; 170 | ; entry inputregister(s) decimal value 0 to: 171 | ; B2D8 A 255 (3 digits) 172 | ; B2D16 HL 65535 5 " 173 | ; B2D24 E:HL 16777215 8 " 174 | ; B2D32 DE:HL 4294967295 10 " 175 | ; B2D48 BC:DE:HL 281474976710655 15 " 176 | ; B2D64 IX:BC:DE:HL 18446744073709551615 20 " 177 | ; 178 | ; The resulting string is placed into a small buffer attached to this routine, 179 | ; this buffer needs no initialization and can be modified as desired. 180 | ; The number is aligned to the right, and leading 0's are replaced with spaces. 181 | ; On exit HL points to the first digit, (B)C = number of decimals 182 | ; This way any re-alignment / postprocessing is made easy. 183 | ; Changes: AF,BC,DE,HL,IX 184 | ; P.S. some examples below 185 | 186 | ; by Alwin Henseler 187 | 188 | B2D8: LD H,0 189 | LD L,A 190 | B2D16: LD E,0 191 | B2D24: LD D,0 192 | B2D32: LD BC,0 193 | B2D48: LD IX,0 ; zero all non-used bits 194 | B2D64: LD (B2DINV),HL 195 | LD (B2DINV+2),DE 196 | LD (B2DINV+4),BC 197 | LD (B2DINV+6),IX ; place full 64-bit input value in buffer 198 | LD HL,B2DBUF 199 | LD DE,B2DBUF+1 200 | LD (HL)," " 201 | B2DFILC: EQU $-1 ; address of fill-character 202 | LD BC,18 203 | LDIR ; fill 1st 19 bytes of buffer with spaces 204 | LD (B2DEND-1),BC ;set BCD value to "0" & place terminating 0 205 | LD E,1 ; no. of bytes in BCD value 206 | LD HL,B2DINV+8 ; (address MSB input)+1 207 | LD BC,0x0909 208 | XOR A 209 | B2DSKP0: DEC B 210 | JR Z,B2DSIZ ; all 0: continue with postprocessing 211 | DEC HL 212 | OR (HL) ; find first byte <>0 213 | JR Z,B2DSKP0 214 | B2DFND1: DEC C 215 | RLA 216 | JR NC,B2DFND1 ; determine no. of most significant 1-bit 217 | RRA 218 | LD D,A ; byte from binary input value 219 | B2DLUS2: PUSH HL 220 | PUSH BC 221 | B2DLUS1: LD HL,B2DEND-1 ; address LSB of BCD value 222 | LD B,E ; current length of BCD value in bytes 223 | RL D ; highest bit from input value -> carry 224 | B2DLUS0: LD A,(HL) 225 | ADC A,A 226 | DAA 227 | LD (HL),A ; double 1 BCD byte from intermediate result 228 | DEC HL 229 | DJNZ B2DLUS0 ; and go on to double entire BCD value (+carry!) 230 | JR NC,B2DNXT 231 | INC E ; carry at MSB -> BCD value grew 1 byte larger 232 | LD (HL),1 ; initialize new MSB of BCD value 233 | B2DNXT: DEC C 234 | JR NZ,B2DLUS1 ; repeat for remaining bits from 1 input byte 235 | POP BC ; no. of remaining bytes in input value 236 | LD C,8 ; reset bit-counter 237 | POP HL ; pointer to byte from input value 238 | DEC HL 239 | LD D,(HL) ; get next group of 8 bits 240 | DJNZ B2DLUS2 ; and repeat until last byte from input value 241 | B2DSIZ: LD HL,B2DEND ; address of terminating 0 242 | LD C,E ; size of BCD value in bytes 243 | OR A 244 | SBC HL,BC ; calculate address of MSB BCD 245 | LD D,H 246 | LD E,L 247 | SBC HL,BC 248 | EX DE,HL ; HL=address BCD value, DE=start of decimal value 249 | LD B,C ; no. of bytes BCD 250 | SLA C ; no. of bytes decimal (possibly 1 too high) 251 | LD A,"0" 252 | RLD ; shift bits 4-7 of (HL) into bit 0-3 of A 253 | CP "0" ; (HL) was > 9h? 254 | JR NZ,B2DEXPH ; if yes, start with recording high digit 255 | DEC C ; correct number of decimals 256 | INC DE ; correct start address 257 | JR B2DEXPL ; continue with converting low digit 258 | B2DEXP: RLD ; shift high digit (HL) into low digit of A 259 | B2DEXPH: LD (DE),A ; record resulting ASCII-code 260 | INC DE 261 | B2DEXPL: RLD 262 | LD (DE),A 263 | INC DE 264 | INC HL ; next BCD-byte 265 | DJNZ B2DEXP ; and go on to convert each BCD-byte into 2 ASCII 266 | SBC HL,BC ; return with HL pointing to 1st decimal 267 | RET 268 | 269 | AppendB2D: 270 | ; Append results of B2D to string at HL 271 | ex de, hl ; Get destination into DE 272 | ld hl, B2DBUF 273 | call SkipWhitespace 274 | ldir 275 | ex de, hl ; Get destination into DE 276 | ret 277 | 278 | B2DINV: DS 8 ; space for 64-bit input value (LSB first) 279 | B2DBUF: DS 20 ; space for 20 decimal digits 280 | B2DEND: DB 0 ; space for terminating 0 281 | -------------------------------------------------------------------------------- /uGophy/wifi.asm: -------------------------------------------------------------------------------- 1 | ; Initialize WiFi chip and connect to WiFi 2 | initWifi: 3 | IFDEF TRDOS 4 | 5 | call uartBegin 6 | 7 | ; Disable ECHO. BTW Basic UART test 8 | ld hl, cmd_at : call okErrCmd : and 1 : jr z, errInit 9 | ; Single connection mode 10 | ld hl, cmd_cmux : call okErrCmd : and 1 : jr z, errInit 11 | 12 | ; FTP enables this info? We doesn't need it :-) 13 | ld hl, cmd_inf_off : call okErrCmd : and 1 : jr z, errInit 14 | 15 | ret 16 | ELSE 17 | 18 | call loadWiFiConfig 19 | ld hl, connectTo : call putStringZ 20 | call uartBegin 21 | 22 | ld hl, cmd_plus : call uartWriteStringZ 23 | ei 24 | ld b,#ff 25 | wlp: 26 | halt : djnz wlp 27 | 28 | ld hl, cmd_rst : call uartWriteStringZ 29 | rstLp: 30 | call uartReadBlocking : call pushRing 31 | 32 | ld hl, response_rdy : call searchRing : cp 1 : jr nz, rstLp 33 | 34 | ; WiFi client mode 35 | ld hl, cmd_mode : call okErrCmd : and 1 : jr z, errInit 36 | ; Disable ECHO. BTW Basic UART test 37 | ld hl, cmd_at : call okErrCmd : and 1 : jr z, errInit 38 | ; Lets disconnect from last AP 39 | ld hl, cmd_cwqap : call okErrCmd : and 1 : jr z, errInit 40 | ; Single connection mode 41 | ld hl, cmd_cmux : call okErrCmd : and 1 : jr z, errInit 42 | 43 | ; FTP enables this info? We doesn't need it :-) 44 | ld hl, cmd_inf_off : call okErrCmd : and 1 : jr z, errInit 45 | 46 | ; Access Point connection 47 | ld hl, cmd_cwjap1 : call uartWriteStringZ : ld hl, ssid : call uartWriteStringZ : ld hl, cmd_cwjap2 : call uartWriteStringZ 48 | ld hl, pass :call uartWriteStringZ : ld hl, cmd_cwjap3 : call okErrCmd 49 | 50 | and 1 :jr z, errInit 51 | 52 | ld hl, log_ok : call putStringZ 53 | ret 54 | ENDIF 55 | errInit 56 | ld hl, log_err : call putStringZ 57 | jr $ 58 | 59 | 60 | ; Send AT-command and wait for result. 61 | ; HL - Z-terminated AT-command(with CR/LF) 62 | ; A: 63 | ; 1 - Success 64 | ; 0 - Failed 65 | okErrCmd: 66 | call uartWriteStringZ 67 | okErrCmdLp: 68 | call uartReadBlocking : call pushRing 69 | 70 | ld hl, response_ok : call searchRing : cp 1 : jr z, okErrOk 71 | ld hl, response_err : call searchRing : cp 1 : jr z, okErrErr 72 | ld hl, response_fail : call searchRing : cp 1 : jr z, okErrErr 73 | 74 | jp okErrCmdLp 75 | okErrOk 76 | ld a, 1 77 | ret 78 | okErrErr 79 | ld a, 0 80 | ret 81 | 82 | ; Gets packet from network 83 | ; packet will be in var 'output_buffer' 84 | ; received packet size in var 'bytes_avail' 85 | ; 86 | ; If connection was closed it calls 'closed_callback' 87 | getPacket 88 | call uartReadBlocking : call pushRing 89 | 90 | ld hl, closed : call searchRing : cp 1 : jp z, closed_callback 91 | ld hl, ipd : call searchRing : cp 1 : jr nz, getPacket 92 | 93 | call count_ipd_lenght : ld (bytes_avail), hl 94 | push hl : pop bc 95 | 96 | ld hl, output_buffer 97 | readp: 98 | push bc : push hl 99 | call uartReadBlocking 100 | pop hl 101 | ld (hl), a 102 | pop bc 103 | 104 | dec bc : inc hl 105 | 106 | ld a, b : or c : jr nz, readp 107 | 108 | ld hl, (bytes_avail) 109 | ret 110 | 111 | count_ipd_lenght 112 | ld hl,0 ; count lenght 113 | cil1 push hl : call uartReadBlocking : push af : call pushRing : pop af : pop hl 114 | cp ':' : ret z 115 | sub 0x30 : ld c,l : ld b,h : add hl,hl : add hl,hl : add hl,bc : add hl,hl : ld c,a : ld b,0 : add hl,bc 116 | jr cil1 117 | 118 | ; HL - z-string to hostname or ip 119 | ; DE - z-string to port 120 | startTcp: 121 | push de 122 | push hl 123 | ld hl, cmd_open1 : call uartWriteStringZ 124 | pop hl : call uartWriteStringZ 125 | ld hl, cmd_open2 : call uartWriteStringZ 126 | pop de : call uartWriteStringZ 127 | ld hl, cmd_open3 : call okErrCmd 128 | ret 129 | 130 | ; Returns: 131 | ; A: 1 - Success 132 | ; 0 - Failed 133 | sendByte: 134 | push af 135 | ld hl, cmd_send_b : call okErrCmd 136 | cp 1 : jr nz, sbErr 137 | sbLp 138 | call uartReadBlocking 139 | ld hl, send_prompt : call searchRing : cp 1 : jr nz, sbLp 140 | pop af 141 | 142 | ld (sbyte_buff), a : call okErrCmd 143 | ret 144 | sbErr: 145 | pop af 146 | ld a, 0 147 | ret 148 | 149 | loadWiFiConfig: 150 | IFDEF PLUS3DOS 151 | ld hl, conf_file, c, ACCESS_MODE_EXCLUSIVE_READ, d, CREATE_ACTION_DONTCREATE, e, OPEN_ACTION_POSITION_TO_DATA 152 | call fopen 153 | ld c, 0, de, 160, hl, ssid : call fread 154 | call fclose 155 | ENDIF 156 | 157 | IFDEF ESXDOS 158 | ld b, FMODE_READ : ld hl, conf_file : call fopen 159 | push af : ld hl, ssid : ld bc, 160 : call fread : pop af 160 | call fclose 161 | ENDIF 162 | ret 163 | 164 | cmd_plus defb "+++", 0 165 | cmd_rst defb "AT+RST",13, 10, 0 166 | cmd_at defb "ATE0", 13, 10, 0 ; Disable echo - less to parse 167 | cmd_mode defb "AT+CWMODE_DEF=1",13,10,0 ; Client mode 168 | cmd_cmux defb "AT+CIPMUX=0",13,10,0 ; Single connection mode 169 | cmd_cwqap defb "AT+CWQAP",13,10,0 ; Disconnect from AP 170 | cmd_inf_off defb "AT+CIPDINFO=0",13,10,0 ; doesn't send me info about remote port and ip 171 | 172 | cmd_cwjap1 defb "AT+CWJAP_CUR=", #22,0 ;Connect to AP. Send this -> SSID 173 | cmd_cwjap2 defb #22,',',#22,0 ; -> This -> Password 174 | cmd_cwjap3 defb #22, 13, 10, 0 ; -> And this 175 | 176 | cmd_open1 defb "AT+CIPSTART=", #22, "TCP", #22, ",", #22, 0 177 | cmd_open2 defb #22, ",", 0 178 | cmd_open3 defb 13, 10, 0 179 | cmd_send defb "AT+CIPSEND=", 0 180 | cmd_close defb "AT+CIPCLOSE",13,10,0 181 | cmd_send_b defb "AT+CIPSEND=1", 13, 10,0 182 | closed defb "CLOSED", 13, 10, 0 183 | ipd defb 13, 10, "+IPD,", 0 184 | 185 | response_rdy defb 'ready', 0 186 | response_ok defb 'OK', 13, 10, 0 ; Sucessful operation 187 | response_err defb 13,10,'ERROR',13,10,0 ; Failed operation 188 | response_fail defb 13,10,'FAIL',13,10,0 ; Failed connection to WiFi. For us same as ERROR 189 | 190 | log_err defb 13,'Failed connect to WiFi!',13, 0 191 | log_ok defb 13, 'WiFi connected!', 13, 0 192 | 193 | connectTo db 13, 'Connecting to ' 194 | 195 | ssid defs 80 196 | pass defs 80 197 | 198 | bytes_avail defw 0 199 | sbyte_buff defb 0, 0 200 | 201 | send_prompt defb ">",0 202 | output_buffer defs 4096 ; buffer for downloading data 203 | 204 | ; WiFi configuration 205 | IFDEF PLUS3DOS 206 | conf_file defb "iw.cfg",0 207 | ENDIF 208 | 209 | IFDEF ESXDOS 210 | conf_file defb "/sys/config/iw.cfg",0 211 | ENDIF 212 | -------------------------------------------------------------------------------- /uGophy/zifi-uart.asm: -------------------------------------------------------------------------------- 1 | ZIFI_CMD_REG = #C7EF 2 | ZIFI_ERR_REG = #C7EF 3 | ZIFI_DATA_REG = #BFEF 4 | ZIFI_FIFO_IN = #C0EF 5 | ZIFI_FIFO_OUT = #C1EF 6 | 7 | ZIFI_CMD_CLEAR_FIFO_IN = #01 8 | ZIFI_CMD_CLEAR_FIFO_OUT = #02 9 | ZIFI_CMD_CLEAR_FIFO_BOTH = #03 10 | ZIFI_CMD_API_DISABLE = #F0 11 | ZIFI_CMD_API_ENABLE = #F1 12 | ZIFI_CMD_API_VERSION = #FF 13 | 14 | ; Enable UART 15 | ; Cleaning all flags by sending api enable command and clear command to both fifo 16 | ; Wastes AF and BC 17 | uartBegin: 18 | ld bc, ZIFI_CMD_REG : ld a, ZIFI_CMD_API_ENABLE : out (c), a 19 | ld bc, ZIFI_CMD_REG : ld a, ZIFI_CMD_CLEAR_FIFO_BOTH : out (c), a 20 | ld bc, ZIFI_CMD_REG : ld a, ZIFI_CMD_API_VERSION : out (c), a 21 | ld bc, ZIFI_ERR_REG : in a, (c) 22 | cp 255 23 | jp nz, retUartBegin 24 | 25 | haltUartBegin: 26 | ld hl, nozifi_msg : call showTypePrint 27 | jp uartBegin 28 | 29 | retUartBegin: 30 | ld hl, zifi_api_msg : call showTypePrint 31 | ld b, #ff 32 | ret 33 | 34 | ; Blocking read one byte 35 | uartReadBlocking: 36 | call uartRead 37 | push af : ld a, 1 : and b : jr nz, urb : pop af 38 | jp uartReadBlocking 39 | urb: 40 | pop af 41 | ret 42 | 43 | ; Write single byte to UART 44 | ; A - byte to write 45 | ; BC will be wasted 46 | uartWriteByte: 47 | push af 48 | ld bc, ZIFI_DATA_REG : out (c), a 49 | pop af 50 | ret 51 | 52 | ; Read byte from UART 53 | ; A: byte 54 | ; B: 55 | ; 1 - Was read 56 | ; 0 - Nothing to read 57 | uartRead: 58 | ld bc, ZIFI_FIFO_IN : in a, (c) 59 | cp 0 60 | jp nz, retReadByte 61 | 62 | noData: 63 | xor a 64 | ld b, 0 65 | ret 66 | 67 | retReadByte: 68 | ld bc, ZIFI_DATA_REG : in a, (c) 69 | ld b, 1 70 | ret 71 | 72 | nozifi_msg db 'ZiFi hardware is not available...', 0 73 | zifi_api_msg db 'ZiFi API available...', 0 74 | -------------------------------------------------------------------------------- /wget/.gitignore: -------------------------------------------------------------------------------- 1 | WGET -------------------------------------------------------------------------------- /wget/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @echo "This application works only with esxDOS" 3 | @echo "" 4 | @echo "make zxuno - for build it for zxuno" 5 | @echo "make esxdos - for build it for any zxspectrum with esxDos and ESP on AY-chip" 6 | 7 | zxuno: *.asm 8 | sjasmplus -DUNO main.asm 9 | 10 | esxdos: *.asm 11 | sjasmplus -DAY main.asm 12 | 13 | clean: 14 | rm WGET 15 | -------------------------------------------------------------------------------- /wget/README.md: -------------------------------------------------------------------------------- 1 | # WGet for ZX-Spectrum 128K with esxDOS and ESP-12 on AY chip 2 | 3 | This tool made for downloading something from HTTP(https doesn't supported) and storing to SD card via esxDOS. 4 | 5 | ## Usage 6 | 7 | Download from releases WGET and put it to `/BIN` directory of speccy's SD Card(or divIDE's drive). 8 | 9 | By restriction Sinclair Basic you can't use `:` symbol in url(you may skip it in protocol part), but you must keep double slashes at url start. 10 | 11 | To download `http://artisia.net/out.scr` to `test.scr` you must enter this thing: 12 | 13 | ``` 14 | .wget //artisia.net/out.scr test.scr 15 | ``` 16 | 17 | or 18 | 19 | ``` 20 | .wget http//artisia.net/out.scr test.scr 21 | ``` 22 | 23 | ## Legals 24 | 25 | Made by Alexander Sharikhin 26 | 27 | Originally made for ZX-Uno. 28 | 29 | Some part of code(preparing HTTP-request) based on [ZiFi project](https://github.com/HackerVBI/ZiFi/). 30 | 31 | This code is public domain. -------------------------------------------------------------------------------- /wget/ay-uart.asm: -------------------------------------------------------------------------------- 1 | ; Enable UART 2 | ; Cleaning all flags by reading UART regs 3 | ; Wastes AF and BC 4 | uartBegin: 5 | ld a, #07 6 | ld bc, #fffd 7 | out (c), a 8 | ld a, #fc 9 | ld b, #bf 10 | out (c), a ; Enable read mode 11 | 12 | ld a, #0e 13 | ld bc, #fffd 14 | out (c), a 15 | ld a, #fe 16 | ld b, #bf 17 | out (c), a ; Make CTS low 18 | ret 19 | 20 | ; Blocking read one byte 21 | uartReadBlocking: 22 | call uartRead 23 | push af : jr c, urb : pop af 24 | jp uartReadBlocking 25 | urb: 26 | pop af 27 | ret 28 | 29 | 30 | uartWriteByte: 31 | push af 32 | 33 | ld c, #fd ; prepare port addresses 34 | ld d, #ff 35 | ld e, #bf 36 | ld b, d 37 | 38 | ld a, #0e 39 | out (c), a ; Select AY's PORT A 40 | 41 | ld hl, (_baud) 42 | ld de, #0002 43 | or a 44 | sbc hl, de 45 | ex hl, de 46 | 47 | pop af 48 | cpl 49 | scf 50 | ld b, #0b ; Numbers of bits - 1 start, 8 data, 2 stop 51 | 52 | ;di ; Hard timing starts 53 | transmitBit: 54 | push bc 55 | push af 56 | 57 | ld a, #fe 58 | ld h, d 59 | ld l, e 60 | ld bc, #bffd 61 | jp nc, transmitOne 62 | ; Transmit Zero: 63 | and #f7 64 | out (c), a 65 | jr transmitNext 66 | transmitOne: 67 | or 8 68 | out (c), a 69 | jr transmitNext 70 | 71 | transmitNext: 72 | dec hl 73 | ld a, h 74 | or l 75 | jr nz, transmitNext 76 | 77 | nop 78 | nop 79 | nop 80 | 81 | pop af 82 | pop bc 83 | or a 84 | rra 85 | djnz transmitBit 86 | 87 | ret 88 | 89 | 90 | uartRead: 91 | ld hl, _testByte 92 | ld a, (hl) 93 | and a 94 | jr z, testSecond 95 | inc hl 96 | ld a, (hl) 97 | scf 98 | ret 99 | testSecond: 100 | ld hl, _isSecondByteAvail 101 | ld a, (hl) 102 | and a 103 | jr z, startReadByte 104 | ld (hl), 0 105 | inc hl 106 | ld a, (hl) 107 | scf 108 | ret 109 | startReadByte: 110 | ;di 111 | xor a 112 | exx 113 | ld de, (_baud) 114 | ld hl, (_baud) 115 | srl h 116 | rr l ; HL=_baud/2 117 | or a 118 | ld b, #FA ; Wait look length 119 | exx 120 | ld c, #fd 121 | ld d, #ff 122 | ld e, #bf 123 | ld b, d 124 | ld a, #0e 125 | out (c), a 126 | in a, (c) 127 | or #f0 ; Input lines is 1 128 | and #fb ; CTS force to 0 129 | ld b, e ; B = #BF 130 | out (c), a ; Make CTS high 131 | ld h, a 132 | 133 | waitStartBit: 134 | ld b, d 135 | in a, (c) 136 | and #80 137 | jr z, startBitFound 138 | readTimeOut: 139 | exx 140 | dec b 141 | exx 142 | jr nz, waitStartBit 143 | xor a 144 | push af 145 | jr readFinish 146 | startBitFound: 147 | in a, (c) 148 | and #80 149 | jr nz, readTimeOut 150 | 151 | in a, (c) 152 | and #80 153 | jr nz, readTimeOut 154 | ;; Start bit found! 155 | 156 | exx 157 | ld bc, #fffd 158 | ld a, #80 159 | ex af, af 160 | readTune: 161 | add hl, de ; HL = 1.5 * _baud 162 | nop 163 | nop 164 | nop 165 | nop ; Fine tuning delay 166 | 167 | bdDelay: 168 | dec hl 169 | ld a, h 170 | or l 171 | jr nz, bdDelay 172 | 173 | in a, (c) 174 | and #80 175 | jp z, zeroReceived 176 | ; One received: 177 | ex af, af 178 | scf 179 | rra 180 | jr c, receivedByte 181 | ex af, af 182 | jp readTune 183 | zeroReceived: 184 | ex af, af 185 | or a 186 | RRA 187 | jr c, receivedByte 188 | ex af, af 189 | jp readTune 190 | receivedByte: 191 | scf 192 | push af 193 | exx 194 | readFinish: 195 | ld a, h 196 | or #04 197 | ld b, e 198 | out (c), a 199 | 200 | exx 201 | ld h, d 202 | ld l, e 203 | 204 | ld bc, #0007 205 | or a 206 | sbc hl, bc 207 | 208 | delayForStopBit: 209 | dec hl 210 | ld a, h 211 | or l 212 | jr nz, delayForStopBit 213 | 214 | ld bc, #fffd 215 | add hl, de 216 | add hl, de 217 | add hl, de 218 | 219 | waitStartBitSecondByte: 220 | in a, (c) 221 | and #80 222 | jr z, secondStartBitFound 223 | dec hl 224 | ld a, h 225 | or l 226 | jr nz, waitStartBitSecondByte 227 | ; No second byte 228 | pop af 229 | 230 | ret 231 | 232 | secondStartBitFound: 233 | in a, (c) 234 | and #80 235 | jr nz, waitStartBitSecondByte 236 | ld h, d 237 | ld l, e 238 | ld bc, #0002 239 | srl h 240 | rr l 241 | or a 242 | sbc hl, bc 243 | ld bc, #fffd 244 | ld a, #80 245 | ex af, af 246 | secondByteTune: 247 | nop 248 | nop 249 | nop 250 | nop 251 | add hl, de 252 | 253 | secondDelay: 254 | dec hl 255 | ld a, h 256 | or l 257 | jr nz, secondDelay 258 | 259 | in a, (c) 260 | and #80 261 | jr z, secondZeroReceived 262 | ; Second 1 received 263 | ex af, af 264 | scf 265 | rra 266 | jr c, secondByteFinished 267 | ex af, af 268 | jp secondByteTune 269 | 270 | secondZeroReceived: 271 | ex af, af 272 | or a 273 | rra 274 | jr c, secondByteFinished 275 | ex af, af 276 | jp secondByteTune 277 | secondByteFinished: 278 | ld hl, _isSecondByteAvail 279 | ld (hl), 1 280 | inc hl 281 | ld (hl), a 282 | pop af 283 | 284 | ret 285 | 286 | 287 | _baud dw 11 ; 54 - 2400 -- 25 - 4800 -- 11 - 9600 288 | _isSecondByteAvail dw #0 289 | _testByte dw #0 290 | -------------------------------------------------------------------------------- /wget/esxdos.asm: -------------------------------------------------------------------------------- 1 | ; API methods 2 | ESX_GETSETDRV = #89 3 | ESX_FOPEN = #9A 4 | ESX_FCLOSE = #9B 5 | ESX_FSYNC = #9C 6 | ESX_FREAD = #9D 7 | ESX_FWRITE = #9E 8 | 9 | ; File modes 10 | FMODE_READ = #01 11 | FMODE_WRITE = #06 12 | FMODE_CREATE = #0E 13 | 14 | ; Returns: 15 | ; A - current drive 16 | getDefaultDrive: 17 | ld a, 0 18 | rst #8 19 | defb ESX_GETSETDRV 20 | ret 21 | 22 | ; Opens file on default drive 23 | ; B - File mode 24 | ; HL - File name 25 | ; Returns: 26 | ; A - file stream id 27 | fopen: 28 | push bc 29 | push hl 30 | call getDefaultDrive 31 | pop ix 32 | pop bc 33 | rst #8 34 | defb ESX_FOPEN 35 | ret 36 | 37 | ; A - file stream id 38 | fclose: 39 | rst #8 40 | defb ESX_FCLOSE 41 | ret 42 | 43 | ; A - file stream id 44 | ; BC - length 45 | ; HL - buffer 46 | ; Returns 47 | ; BC - length(how much was actually read) 48 | fread: 49 | push hl 50 | pop ix 51 | rst #8 52 | defb ESX_FREAD 53 | ret 54 | 55 | ; A - file stream id 56 | ; BC - length 57 | ; HL - buffer 58 | ; Returns: 59 | ; BC - actually written bytes 60 | fwrite: 61 | push hl 62 | pop ix 63 | rst #8 64 | defb ESX_FWRITE 65 | ret 66 | 67 | ; A - file stream id 68 | fsync: 69 | rst #8 70 | defb ESX_FSYNC 71 | ret 72 | -------------------------------------------------------------------------------- /wget/http.asm: -------------------------------------------------------------------------------- 1 | ; Some parts taken from ZiFi sources 2 | 3 | ; Performs HTTP-get request 4 | ; First packet will be in var 'output_buffer' 5 | ; received packet size in var 'bytes_avail' 6 | ; 7 | ; HL - url includes http:// header 8 | httpGet ld de,cmd_conn2site_adr 9 | pu1 ld a,(hl) ; http:// 10 | inc hl 11 | cp "/" 12 | jr nz,pu1 13 | inc hl ; / 14 | ld bc,"//" 15 | ld (host_url+1),hl 16 | call find_copy_char 17 | inc hl 18 | ld (file_url+1),hl 19 | 20 | create_link1 ld hl,create_link_suffix 21 | ld bc,7 22 | ldir 23 | ld hl,modem_command 24 | 25 | ld (hl),"G" 26 | inc hl 27 | ld (hl),"E" 28 | inc hl 29 | ld (hl),"T" 30 | inc hl 31 | ld (hl)," " 32 | inc hl 33 | ld (hl),"/" 34 | inc hl 35 | 36 | ex hl,de 37 | file_url ld hl,0 38 | ld bc,#0d0a 39 | call find_copy_char 40 | ld hl,http_part1 41 | ld bc,http_part2-http_part1 42 | ldir 43 | host_url ld hl,0 44 | ld bc,"//" 45 | call find_copy_char 46 | ld a,13 47 | ld (de),a 48 | inc de 49 | ld a,10 50 | ld (de),a 51 | inc de 52 | ld hl,http_part2 53 | ld bc,http_part3-http_part2 54 | ldir 55 | ex de,hl 56 | ld de,modem_command 57 | or a 58 | sbc hl,de 59 | ld de,url_len 60 | ld bc,-1000 61 | call Num1 62 | cp "0" 63 | jr z,1f 64 | ld (de),a 65 | inc de 66 | 1 ld bc,-100 67 | call Num1 68 | ld (de),a 69 | inc de 70 | 1 ld c,-10 71 | call Num1 72 | ld (de),a 73 | inc de 74 | 1 ld c,-1 75 | call Num1 76 | ld (de),a 77 | inc de 78 | ld a,#0d 79 | ld (de),a 80 | inc de 81 | ld a,#0a 82 | ld (de),a 83 | inc de 84 | xor a 85 | ld (de),a 86 | jr firstPacket 87 | 88 | Num1: ld a,'0'-1 89 | Num2: inc a 90 | add hl,bc 91 | jr c,Num2 92 | sbc hl,bc 93 | ret 94 | 95 | find_copy_char ld a,(hl) 96 | cp c 97 | ret z 98 | cp b 99 | ret z 100 | ld (de),a 101 | inc hl 102 | inc de 103 | jr find_copy_char 104 | 105 | firstPacket: 106 | call performRequest 107 | 108 | skipHeaders: 109 | ld de, output_buffer, bc, 0 110 | .loop 111 | ld a, (de) 112 | inc bc 113 | inc de 114 | cp ' ' 115 | jr nz, .loop 116 | 117 | ld a,(de) 118 | cp '2' 119 | jp nz, httpError 120 | inc de : inc bc 121 | shLp: 122 | ld a, (de) 123 | push de 124 | push bc 125 | call pushRing 126 | ld hl, headers_end 127 | call searchRing 128 | pop bc 129 | pop de 130 | inc de 131 | inc bc 132 | cp 1 133 | jr nz, shLp 134 | ld hl, (bytes_avail) 135 | sbc hl, bc 136 | ld (bytes_avail), hl 137 | push hl 138 | pop bc 139 | push de 140 | ld de, output_buffer 141 | pop hl 142 | ldir 143 | ret 144 | 145 | httpError: 146 | ld hl, wrong_response_status : call putStringZ 147 | ld hl, output_buffer 148 | .loop 149 | ld a, (hl) 150 | cp 13 : jr z, .exit 151 | push hl 152 | call putC 153 | pop hl 154 | inc hl 155 | jr .loop 156 | .exit 157 | ld hl, cmd_close 158 | call uartWriteStringZ 159 | 160 | ld hl, cmd_rst 161 | call uartWriteStringZ 162 | .rstLp 163 | call uartReadBlocking 164 | call pushRing 165 | ld hl, response_rdy 166 | call searchRing 167 | cp 1 168 | jr nz, .rstLp 169 | 170 | pop af : xor a : ei : ret 171 | 172 | performRequest: 173 | ld hl, cmd_conn2site 174 | call okErrCmd 175 | cp 1 176 | jr z, zg_ok 177 | ; Failed connect 178 | ld hl, failed_connect 179 | call putStringZ 180 | ld de, (retAddr) 181 | push de 182 | xor a 183 | ret 184 | 185 | zg_ok: 186 | ld hl, cmd_cipsend 187 | call okErrCmd 188 | guLp: 189 | call uartReadBlocking 190 | call pushRing 191 | ld hl, send_prompt 192 | call searchRing 193 | cp 1 194 | jr nz, guLp 195 | ld hl, modem_command 196 | call okErrCmd 197 | jp getPacket 198 | 199 | failed_connect db 13, "Failed connect to host",0 200 | wrong_response_status db 13, "Response: ", 0 201 | 202 | 203 | create_link_suffix 204 | db #22,",80",13,10,0 205 | display $ 206 | modem_command ds 256+128 207 | display $ 208 | http_part1 db " HTTP/1.0",13,10 ;size=123 209 | db "Host: " 210 | http_part2 db "User-Agent: ZX Spectrum(Z80 CPU)",13,10 ; show off ;) 211 | db "Accept: */*",13,10 212 | db "Connection: close",13,10,13,10 213 | http_part3 214 | 215 | cmd_conn2site defb "AT+CIPSTART=", 0x22,"TCP",0x22,",",0x22 216 | cmd_conn2site_adr ds #40 217 | 218 | headers_end defb 13,10,13,10,0 219 | cmd_cipsend defb "AT+CIPSEND=" 220 | url_len defs 6 221 | defb 0 222 | -------------------------------------------------------------------------------- /wget/main.asm: -------------------------------------------------------------------------------- 1 | DEVICE ZXSPECTRUM48 2 | org #2000 3 | Start: 4 | pop de 5 | ld (retAddr), de 6 | push de 7 | 8 | push hl 9 | ld hl, about 10 | call putStringZ 11 | 12 | pop hl 13 | 14 | ld a, l 15 | or h 16 | jr z, noArgs 17 | call loadArgs 18 | 19 | ld hl, initUart : call putStringZ : call uartBegin 20 | ld hl, connecting : call putStringZ : call initWifi 21 | ld hl, makingRequest : call putStringZ : ld hl, proto : call putStringZ 22 | 23 | ld hl, proto : call httpGet 24 | 25 | ld hl, fout, b, FMODE_CREATE : call fopen 26 | ld (fpointer), a 27 | ld hl, downloading : call putStringZ 28 | downloop: 29 | ld a, (fpointer) 30 | ld bc, (bytes_avail) 31 | ld hl, output_buffer 32 | call fwrite 33 | 34 | ld a, '.' : rst #10 35 | 36 | ld a, (fpointer) 37 | call fsync 38 | call getPacket 39 | jp downloop 40 | 41 | loadArgs: 42 | ld de, url 43 | aLp: 44 | ld a,(hl) 45 | 46 | cp 13 47 | jr z, aE 48 | 49 | cp ':' 50 | jr z, aE 51 | 52 | cp ' ' 53 | jr z, narg 54 | 55 | ld (de), a 56 | 57 | inc de 58 | inc hl 59 | jr aLp 60 | aE: 61 | ld a, 0 62 | ld (de), a 63 | ret 64 | narg: 65 | ld a, #d 66 | ld (de), a 67 | 68 | inc de 69 | ld a, 0 70 | ld (de), a 71 | 72 | inc hl 73 | ld de, fout 74 | jr aLp 75 | 76 | noArgs: 77 | ld hl, usage 78 | call putStringZ 79 | ret 80 | 81 | closed_callback 82 | ld a, (fpointer) 83 | call fclose 84 | 85 | ld hl,done 86 | call putStringZ 87 | 88 | ld de, (retAddr) 89 | push de 90 | ret 91 | 92 | ; A - char 93 | putC: 94 | rst #10 95 | ret 96 | 97 | ; HL - string 98 | putStringZ: 99 | ld a, (hl) 100 | and a 101 | ret z 102 | push hl 103 | call putC 104 | pop hl 105 | inc hl 106 | jr putStringZ 107 | 108 | uartWriteStringZ: 109 | ld a, (hl) 110 | and a : ret z 111 | push hl 112 | call uartWriteByte 113 | pop hl 114 | inc hl 115 | jr uartWriteStringZ 116 | 117 | about: defb 'wGet v.0.3 (c) 2020 Nihirash', 13, 0 118 | usage: defb 'Usage: .wget ', 13, 0 119 | initUart defb "Initializing UART", 13, 0 120 | connecting defb "Connecting to WiFi", 13, 0 121 | makingRequest defb "Making request: ", 13, 0 122 | downloading defb 'Downloading', 0 123 | done: defb 13, 'File saved', 13, 0 124 | proto db "http://" 125 | url defs 255 ; 0xd ending is important! Be carefull! 126 | fout defs 80 127 | test_params defb '1 2 3',0 128 | fpointer defb 0 129 | retAddr defw 0 130 | 131 | conclosed db 13, 13, "Connection closed", 0 132 | IFDEF UNO 133 | include "uno-uart.asm" 134 | ENDIF 135 | 136 | IFDEF AY 137 | include "ay-uart.asm" 138 | ENDIF 139 | 140 | include "wifi.asm" 141 | include "ring.asm" 142 | include "http.asm" 143 | include "esxdos.asm" 144 | output_buffer EQU $ 145 | SAVEBIN "WGET", Start, $ - Start 146 | -------------------------------------------------------------------------------- /wget/ring.asm: -------------------------------------------------------------------------------- 1 | ; Pushes A to ring buffer 2 | pushRing 3 | push af 4 | ld b, 32 5 | ld hl, ring_buffer + 1 6 | ld de, ring_buffer 7 | ringL 8 | ld a, (hl) 9 | ld (de), a 10 | inc hl 11 | inc de 12 | djnz ringL 13 | pop af 14 | ld hl, ring_buffer + 31 15 | ld (hl), a 16 | ret 17 | 18 | ; HL - Compare string(null terminated) 19 | ; A - 0 NOT Found 20 | ; 1 Found 21 | searchRing: 22 | ld b, 0 23 | push hl 24 | serlp: 25 | ld a, (hl) 26 | inc hl 27 | inc b 28 | and a 29 | jp nz, serlp 30 | dec b 31 | pop hl 32 | push bc 33 | push hl 34 | SRWork: 35 | pop hl 36 | ld de, ring_buffer + 32 37 | srcLp 38 | dec de 39 | djnz srcLp 40 | pop bc 41 | ringCmpLp 42 | push bc 43 | push af 44 | ld a, (de) 45 | ld b, a 46 | pop af 47 | ld a, (hl) 48 | cp b 49 | pop bc 50 | ld a, 0 51 | ret nz 52 | inc de 53 | inc hl 54 | djnz ringCmpLp 55 | ld a, 1 56 | ret 57 | 58 | ring_buffer dup 33 59 | defb 0 60 | edup -------------------------------------------------------------------------------- /wget/uno-uart.asm: -------------------------------------------------------------------------------- 1 | UART_DATA_REG = #c6 2 | UART_STAT_REG = #c7 3 | UART_BYTE_RECIVED = #80 4 | UART_BYTE_SENDING = #40 5 | SCANDBLCTRL_REG = #0B 6 | ZXUNO_ADDR = #FC3B 7 | ZXUNO_REG = #FD3B 8 | 9 | 10 | ; Enable UART 11 | ; Cleaning all flags by reading UART regs 12 | ; Wastes AF and BC 13 | uartBegin: 14 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 15 | ld bc, ZXUNO_REG : in A, (c) 16 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 17 | ld bc, ZXUNO_REG : in A, (c) 18 | ld b, #ff 19 | .loop 20 | push bc 21 | call uartRead 22 | pop bc 23 | djnz .loop 24 | 25 | ret 26 | 27 | ; Blocking read one byte 28 | uartReadBlocking: 29 | call uartRead 30 | push af : ld a, 1 : and b : jr nz, urb : pop af 31 | jp uartReadBlocking 32 | urb: 33 | pop af 34 | ret 35 | 36 | ; Write single byte to UART 37 | ; A - byte to write 38 | ; BC will be wasted 39 | uartWriteByte: 40 | push af 41 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 42 | waitWriteReady: 43 | ld bc, ZXUNO_REG : in A, (c) : and UART_BYTE_RECIVED 44 | jr nz, is_recvF 45 | checkSent: 46 | ld bc, ZXUNO_REG : in A, (c) : and UART_BYTE_SENDING 47 | jr nz, checkSent 48 | 49 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 50 | 51 | ld bc, ZXUNO_REG : pop af : out (c), a 52 | ret 53 | is_recvF: 54 | push af : push hl 55 | 56 | ld hl, is_recv : ld a, 1 : ld (hl), a 57 | 58 | pop hl : pop af 59 | jr checkSent 60 | 61 | ; Is data avail in UART 62 | ; NZ - Data Presents 63 | ; Z - Data absent 64 | uartAvail: 65 | ld a, (is_recv) : and 1 : ret nz 66 | ld a, (poked_byte) : and 1 : ret nz 67 | 68 | call uartRead 69 | 70 | push af : ld a, b : and 1 : jr z, noneData : pop af 71 | 72 | push af 73 | ld hl, byte_buff : ld (hl), a : ld hl, poked_byte : ld a, 1 : ld (hl), a 74 | pop af 75 | 76 | ld b, a : ld a, 1 : or a : ld a, b 77 | ret 78 | noneData: 79 | pop bc : xor a 80 | ret 81 | 82 | ; Read byte from UART 83 | ; A: byte 84 | ; B: 85 | ; 1 - Was read 86 | ; 0 - Nothing to read 87 | uartRead: 88 | ld a, (poked_byte) : and 1 : jr nz, retBuff 89 | 90 | ld a, (is_recv) : and 1 : jr nz, recvRet 91 | 92 | ld bc, ZXUNO_ADDR : ld a, UART_STAT_REG : out (c), a 93 | ld bc, ZXUNO_REG : in a, (c) : and UART_BYTE_RECIVED 94 | jr nz, retReadByte 95 | 96 | ld b, 0 97 | ret 98 | 99 | retReadByte: 100 | xor a : ld (poked_byte), a : ld (is_recv), a 101 | 102 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c), a 103 | ld bc, ZXUNO_REG : in a, (c) 104 | 105 | ld b, 1 106 | ret 107 | 108 | recvRet: 109 | ld bc, ZXUNO_ADDR : ld a, UART_DATA_REG : out (c),a 110 | 111 | ld bc, ZXUNO_REG : in a, (c) 112 | ld hl, is_recv : ld (hl), 0 113 | ld hl, poked_byte : ld (hl), 0 114 | 115 | ld b, 1 116 | ret 117 | 118 | retBuff 119 | ld a, 0 : ld (poked_byte), a : ld a, (byte_buff) 120 | ld b, 1 121 | ret 122 | 123 | poked_byte defb 0 124 | byte_buff defb 0 125 | is_recv defb 0 -------------------------------------------------------------------------------- /wget/wifi.asm: -------------------------------------------------------------------------------- 1 | ; Initialize WiFi chip and connect to WiFi 2 | initWifi: 3 | call loadWiFiConfig 4 | 5 | ld hl, cmd_plus 6 | call uartWriteStringZ 7 | ld b,#ff 8 | .loop: 9 | push bc 10 | ld b, #ff 11 | djnz $ 12 | pop bc 13 | djnz .loop 14 | 15 | ld hl, cmd_rst 16 | call uartWriteStringZ 17 | rstLp: 18 | call uartReadBlocking 19 | call pushRing 20 | ld hl, response_rdy 21 | call searchRing 22 | cp 1 23 | jr nz, rstLp 24 | 25 | ld hl, cmd_mode : call okErrCmd : and 1 : jr z, errInit 26 | 27 | ld hl, cmd_at ; Disable ECHO. BTW Basic UART test 28 | call okErrCmd 29 | and 1 30 | jr z, errInit 31 | 32 | ld hl, cmd_cwqap ; Lets disconnect from last AP 33 | call okErrCmd 34 | and 1 35 | jr z, errInit 36 | 37 | ld hl, cmd_cmux ; Single connection mode 38 | call okErrCmd 39 | and 1 40 | jr z, errInit 41 | 42 | ld hl, cmd_inf_off ; FTP enables this info? We doesn't need it :-) 43 | call okErrCmd 44 | and 1 45 | jr z, errInit 46 | 47 | ld hl, cmd_cwjap1 ; Access Point connection 48 | call uartWriteStringZ 49 | ld hl, ssid 50 | call uartWriteStringZ 51 | ld hl, cmd_cwjap2 52 | call uartWriteStringZ 53 | ld hl, pass 54 | call uartWriteStringZ 55 | ld hl, cmd_cwjap3 56 | call okErrCmd 57 | and 1 58 | jr z, errInit 59 | 60 | ld hl, log_ok 61 | call putStringZ 62 | 63 | ret 64 | errInit 65 | ld hl, log_err 66 | call putStringZ 67 | jr $ 68 | 69 | 70 | ; Send AT-command and wait for result. 71 | ; HL - Z-terminated AT-command(with CR/LF) 72 | ; A: 73 | ; 1 - Success 74 | ; 0 - Failed 75 | okErrCmd: 76 | call uartWriteStringZ 77 | okErrCmdLp: 78 | call uartReadBlocking 79 | call pushRing 80 | 81 | ld hl, response_ok 82 | call searchRing 83 | cp 1 84 | jr z, okErrOk 85 | 86 | ld hl, response_err 87 | call searchRing 88 | cp 1 89 | jr z, okErrErr 90 | 91 | ld hl, response_fail 92 | call searchRing 93 | cp 1 94 | jr z, okErrErr 95 | 96 | 97 | jp okErrCmdLp 98 | okErrOk 99 | ld a, 1 100 | ret 101 | okErrErr 102 | ld a, 0 103 | ret 104 | 105 | ; Gets packet from network 106 | ; packet will be in var 'output_buffer' 107 | ; received packet size in var 'bytes_avail' 108 | ; 109 | ; If connection was closed it calls 'closed_callback' 110 | getPacket 111 | call uartReadBlocking 112 | call pushRing 113 | 114 | ld hl, closed 115 | call searchRing 116 | cp 1 117 | jp z, closed_callback 118 | 119 | ld hl, ipd 120 | call searchRing 121 | cp 1 122 | jr nz, getPacket 123 | 124 | call count_ipd_lenght 125 | ld (bytes_avail), hl 126 | push hl 127 | pop bc 128 | ld hl, output_buffer 129 | readp: 130 | push bc 131 | push hl 132 | call uartReadBlocking 133 | pop hl 134 | ld (hl), a 135 | pop bc 136 | dec bc 137 | inc hl 138 | ld a, b 139 | or c 140 | jr nz, readp 141 | ld hl, (bytes_avail) 142 | ret 143 | 144 | count_ipd_lenght 145 | ld hl,0 ; count lenght 146 | cil1 push hl 147 | call uartReadBlocking 148 | push af 149 | call pushRing 150 | pop af 151 | pop hl 152 | cp ':' 153 | ret z 154 | sub 0x30 155 | ld c,l 156 | ld b,h 157 | add hl,hl 158 | add hl,hl 159 | add hl,bc 160 | add hl,hl 161 | ld c,a 162 | ld b,0 163 | add hl,bc 164 | jr cil1 165 | 166 | ; HL - z-string to hostname or ip 167 | ; DE - z-string to port 168 | startTcp: 169 | push de 170 | push hl 171 | ld hl, cmd_open1 172 | call uartWriteStringZ 173 | pop hl 174 | call uartWriteStringZ 175 | ld hl, cmd_open2 176 | call uartWriteStringZ 177 | pop de 178 | call uartWriteStringZ 179 | ld hl, cmd_open3 180 | call okErrCmd 181 | ret 182 | 183 | ; Returns: 184 | ; A: 1 - Success 185 | ; 0 - Failed 186 | sendByte: 187 | push af 188 | ld hl, cmd_send_b 189 | call okErrCmd 190 | cp 1 191 | jr nz, sbErr 192 | sbLp 193 | call uartReadBlocking 194 | ld hl, send_prompt 195 | call searchRing 196 | cp 1 197 | jr nz, sbLp 198 | pop af 199 | ld (sbyte_buff), a 200 | call okErrCmd 201 | ret 202 | sbErr: 203 | pop af 204 | ld a, 0 205 | ret 206 | 207 | loadWiFiConfig: 208 | ld b, FMODE_READ 209 | ld hl, conf_file 210 | call fopen 211 | 212 | push af 213 | ld hl, ssid 214 | ld bc, 160 215 | call fread 216 | pop af 217 | 218 | call fclose 219 | ret 220 | cmd_plus defb "+++", 0 221 | cmd_rst defb "AT+RST",13, 10, 0 222 | cmd_at defb "ATE0", 13, 10, 0 ; Disable echo - less to parse 223 | cmd_mode defb "AT+CWMODE_DEF=1",13,10,0 ; Client mode 224 | cmd_cmux defb "AT+CIPMUX=0",13,10,0 ; Single connection mode 225 | cmd_cwqap defb "AT+CWQAP",13,10,0 ; Disconnect from AP 226 | cmd_inf_off defb "AT+CIPDINFO=0",13,10,0 ; doesn't send me info about remote port and ip 227 | 228 | cmd_cwjap1 defb "AT+CWJAP_CUR=", #22,0 ;Connect to AP. Send this -> SSID 229 | cmd_cwjap2 defb #22,',',#22,0 ; -> This -> Password 230 | cmd_cwjap3 defb #22, 13, 10, 0 ; -> And this 231 | 232 | cmd_open1 defb "AT+CIPSTART=", #22, "TCP", #22, ",", #22, 0 233 | cmd_open2 defb #22, ",", 0 234 | cmd_open3 defb 13, 10, 0 235 | 236 | cmd_close defb "AT+CIPCLOSE",13,10,0 237 | cmd_send_b defb "AT+CIPSEND=1", 13, 10,0 238 | closed defb "CLOSED", 13, 10, 0 239 | ipd defb 13, 10, "+IPD,", 0 240 | 241 | response_rdy defb 'ready', 0 242 | response_ok defb 'OK', 13, 10, 0 ; Sucessful operation 243 | response_err defb 13,10,'ERROR',13,10,0 ; Failed operation 244 | response_fail defb 13,10,'FAIL',13,10,0 ; Failed connection to WiFi. For us same as ERROR 245 | 246 | log_err defb 'Failed connect to WiFi!',13, 0 247 | log_ok defb 'WiFi connected!', 13, 0 248 | 249 | ssid defs 80 250 | pass defs 80 251 | 252 | bytes_avail defw 0 253 | sbyte_buff defb 0, 0 254 | 255 | send_prompt defb ">",0 256 | 257 | ; WiFi configuration 258 | conf_file defb "/sys/config/iw.cfg",0 --------------------------------------------------------------------------------