From b46d5f45ecca1b15f901dd216581dd13ec7d460b Mon Sep 17 00:00:00 2001 From: nihirash Date: Tue, 23 Jul 2019 20:05:55 +0300 Subject: [PATCH] uGophy is a part of ZX-Uno project --- readme.txt | 2 +- software/esprst/.gitignore | 1 + software/esprst/Makefile | 7 ++ software/esprst/main.asm | 66 ++++++++++++ software/esprst/ring.asm | 60 +++++++++++ software/esprst/uart.asm | 194 +++++++++++++++++++++++++++++++++++ software/iwconfig/.gitignore | 3 + software/iwconfig/Makefile | 7 ++ software/iwconfig/iwconfig.c | 29 ++++++ 9 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 software/esprst/.gitignore create mode 100644 software/esprst/Makefile create mode 100644 software/esprst/main.asm create mode 100644 software/esprst/ring.asm create mode 100644 software/esprst/uart.asm create mode 100644 software/iwconfig/.gitignore create mode 100644 software/iwconfig/Makefile create mode 100644 software/iwconfig/iwconfig.c diff --git a/readme.txt b/readme.txt index 30c3971..6fa5376 100644 --- a/readme.txt +++ b/readme.txt @@ -3,4 +3,4 @@ All the files for ZX-Uno project repository: http://zxuno.com http://www.atc.us.es/svn/zxuno/ -License is Creative Commons by SA, except the cores that has its own license +License is Creative Commons by SA, except the cores and ugophy(gopher browser) that has its own license diff --git a/software/esprst/.gitignore b/software/esprst/.gitignore new file mode 100644 index 0000000..dd05a34 --- /dev/null +++ b/software/esprst/.gitignore @@ -0,0 +1 @@ +esprst \ No newline at end of file diff --git a/software/esprst/Makefile b/software/esprst/Makefile new file mode 100644 index 0000000..0d3cc0c --- /dev/null +++ b/software/esprst/Makefile @@ -0,0 +1,7 @@ +all: esprst + +esprst: + sjasmplus main.asm + +clean: + rm esprst diff --git a/software/esprst/main.asm b/software/esprst/main.asm new file mode 100644 index 0000000..f3985f3 --- /dev/null +++ b/software/esprst/main.asm @@ -0,0 +1,66 @@ + DEVICE ZXSPECTRUM48 + org #2000 +Start: + ld hl, init_txt + call putS + + call uartBegin + + ld hl, cmd_mode + call uartWriteStringZ + + call wait + + ld hl, cmd_rst + call uartWriteStringZ + + call wait + call wait + + ld hl, cmd_at + call uartWriteStringZ +wtlp: + call uartReadBlocking + call pushRing + + ld hl,response_ok + call searchRing + cp 1 + jr nz, wtlp + + ld hl, fin + call putS + + ret + +wait: + ld b, 50 +wlp: + halt + djnz wlp + ret + + include "uart.asm" + include "ring.asm" + +putS: + ld a, (hl) + or 0 + ret z + push hl + rst #10 + pop hl + inc hl + jr putS + +init_txt defb ".EspRst v.0.1 (c) Nihirash",13,"This tool resets esp-chip",13,0 + +fin defb "WiFi module ready to work", 13, 0 + +cmd_mode defb "+++", 0 +cmd_rst defb "AT+RST", 13, 10, 0 +cmd_at defb "AT", 13, 10, 0 + +response_ok defb "OK", 13, 10, 0 + + SAVEBIN "esprst", Start, $ - Start \ No newline at end of file diff --git a/software/esprst/ring.asm b/software/esprst/ring.asm new file mode 100644 index 0000000..2b13381 --- /dev/null +++ b/software/esprst/ring.asm @@ -0,0 +1,60 @@ +; Pushes A to ring buffer +pushRing + push af + ld b, 32 + ld hl, ring_buffer + 1 + ld de, ring_buffer +ringL + ld a, (hl) + ld (de), a + inc hl + inc de + djnz ringL + pop af + ld hl, ring_buffer + 31 + ld (hl), a + ret + +; HL - Compare string(null terminated) +; A - 0 NOT Found +; 1 Found +searchRing: + ld b, 0 + push hl +serlp: + ld a, (hl) + inc hl + inc b + and a + jp nz, serlp + dec b + pop hl + push bc + push hl +SRWork: + pop hl + ld de, ring_buffer + 32 +srcLp + dec de + djnz srcLp + pop bc +ringCmpLp + push bc + push af + ld a, (de) + ld b, a + pop af + ld a, (hl) + cp b + pop bc + ld a, 0 + ret nz + inc de + inc hl + djnz ringCmpLp + ld a, 1 + ret + +ring_buffer dup 33 + defb 0 + edup \ No newline at end of file diff --git a/software/esprst/uart.asm b/software/esprst/uart.asm new file mode 100644 index 0000000..c0820ed --- /dev/null +++ b/software/esprst/uart.asm @@ -0,0 +1,194 @@ +UART_DATA_REG = #c6 +UART_STAT_REG = #c7 +UART_BYTE_RECIVED = #80 +UART_BYTE_SENT = #40 +ZXUNO_ADDR = #FC3B +ZXUNO_REG = #FD3B + +; Enable UART +; Cleaning all flags by reading UART regs +; Wastes AF and BC +uartBegin: + ld bc, ZXUNO_ADDR + ld a, UART_STAT_REG + out (c), a + + ld bc, ZXUNO_REG + in A, (c) + + ld bc, ZXUNO_ADDR + ld a, UART_DATA_REG + out (c), a + + ld bc, ZXUNO_REG + in A, (c) + ret + +; Pushes to UART zero-terminated string +; HL - string poiner +uartWriteStringZ: + ld a, (hl) + and a + ret z + push hl + call uartWriteByte + pop hl + inc hl + jp uartWriteStringZ + +; Blocking read one byte +uartReadBlocking: + call uartRead + push af + ld a, 1 + cp b + jr z, urb + pop af + ret nz + jp uartReadBlocking +urb: + pop af + ret + +; Write single byte to UART +; A - byte to write +; BC will be wasted +uartWriteByte: + push af + ld bc, ZXUNO_ADDR + ld a, UART_STAT_REG + out (c), a + +waitWriteReady: + ld bc, ZXUNO_REG + in A, (c) + and UART_BYTE_RECIVED + jr nz, is_recvF +checkSent: + ld bc, ZXUNO_REG + in A, (c) + and UART_BYTE_SENT + jr nz, checkSent + + ld bc, ZXUNO_ADDR + ld a, UART_DATA_REG + out (c), a + ld bc, ZXUNO_REG + pop af + out (c), a + ret +is_recvF: + push af + push hl + ld hl, is_recv + ld a, 1 + ld (hl), a + pop hl + pop af + jr checkSent + +; Is data avail in UART +; NZ - Data Presents +; Z - Data absent +uartAvail: + ld a, (is_recv) + and 1 + ret nz + + ld a, (poked_byte) + and 1 + ret nz + + call uartRead + + push af + ld a, b + and 1 + jr z, noneData + pop af + push af + ld hl, byte_buff + ld (hl), a + ld hl, poked_byte + ld a, 1 + ld (hl), a + pop af + ld b, a + ld a, 1 + or a + ld a, b + ret +noneData: + pop bc + xor a + ret + +; Read byte from UART +; A: byte +; B: +; 1 - Was read +; 0 - Nothing to read +uartRead: + ld a, (poked_byte) + and 1 + jr nz, retBuff + + ld a, (is_recv) + and 1 + jr nz, recvRet + + ld bc, ZXUNO_ADDR + ld a, UART_STAT_REG + out (c), a + + ld bc, ZXUNO_REG + in a, (c) + and UART_BYTE_RECIVED + jr nz, retReadByte + + ld b, 0 + ret + +retReadByte: + ld a, 0 + ld (poked_byte), a + ld (is_recv), a + + ld bc, ZXUNO_ADDR + ld a, UART_DATA_REG + out (c), a + + ld bc, ZXUNO_REG + in a, (c) + + ld b, 1 + ret + +recvRet: + ld bc, ZXUNO_ADDR + ld a, UART_DATA_REG + out (c),a + + ld bc, ZXUNO_REG + in a, (c) + + ld hl, is_recv + ld (hl), 0 + + ld hl, poked_byte + ld (hl), 0 + + ld b, 1 + ret + +retBuff + ld a, 0 + ld (poked_byte), a + + ld a, (byte_buff) + ld b, 1 + ret + +poked_byte defb 0 +byte_buff defb 0 +is_recv defb 0 \ No newline at end of file diff --git a/software/iwconfig/.gitignore b/software/iwconfig/.gitignore new file mode 100644 index 0000000..65de6e4 --- /dev/null +++ b/software/iwconfig/.gitignore @@ -0,0 +1,3 @@ +*.bin +*.def +IWCONFIG \ No newline at end of file diff --git a/software/iwconfig/Makefile b/software/iwconfig/Makefile new file mode 100644 index 0000000..82ceaad --- /dev/null +++ b/software/iwconfig/Makefile @@ -0,0 +1,7 @@ +all: iwconfig + +iwconfig: iwconfig.c + zcc +zx -vn -startup=30 -clib=new iwconfig.c -SO3 -o iwconfig -subtype=dot -create-app + +clean: + rm *.bin *.def IWCONFIG \ No newline at end of file diff --git a/software/iwconfig/iwconfig.c b/software/iwconfig/iwconfig.c new file mode 100644 index 0000000..eab7225 --- /dev/null +++ b/software/iwconfig/iwconfig.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +char ssid[80]; +char pass[80]; +int i; +int file; + +int main(int argc, char **argv) +{ + printf("IWConfig by nihirash v.0.1\nWireless interface configurator\n"); + if (argc < 3) { + printf(".iwconfig SSID PASSWD\n"); + return 0; + } + for (int i=0;i<80;i++) { + ssid[i] = pass[i] = 0; + } + + strcpy(ssid, argv[1]); + strcpy(pass, argv[2]); + file = esx_f_open("/sys/config/iw.cfg", ESX_MODE_WRITE | ESX_MODE_OPEN_CREAT_TRUNC); + esx_f_write(file, ssid, 80); + esx_f_write(file, pass, 80); + esx_f_close(file); + return 0; +} \ No newline at end of file