From e5b6f1e91e4800c2e8ae56543fc7b9787dd7f88a Mon Sep 17 00:00:00 2001 From: nihirash Date: Tue, 25 Jun 2019 22:27:29 +0300 Subject: [PATCH] Version 0.1 --- .gitignore | 3 + Makefile | 7 + esxdos.asm | 71 ++++++++ font.bin | Bin 0 -> 1248 bytes gopher.asm | 217 ++++++++++++++++++++++++ http.asm | 176 +++++++++++++++++++ index.pg | 13 ++ keyboard.asm | 99 +++++++++++ main.asm | 36 ++++ render.asm | 451 +++++++++++++++++++++++++++++++++++++++++++++++++ ring.asm | 60 +++++++ screen64.asm | 414 +++++++++++++++++++++++++++++++++++++++++++++ textrender.asm | 78 +++++++++ uart.asm | 194 +++++++++++++++++++++ utils.asm | 140 +++++++++++++++ wifi.asm | 258 ++++++++++++++++++++++++++++ 16 files changed, 2217 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 esxdos.asm create mode 100644 font.bin create mode 100644 gopher.asm create mode 100644 http.asm create mode 100644 index.pg create mode 100644 keyboard.asm create mode 100644 main.asm create mode 100644 render.asm create mode 100644 ring.asm create mode 100644 screen64.asm create mode 100644 textrender.asm create mode 100644 uart.asm create mode 100644 utils.asm create mode 100644 wifi.asm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a31e2af --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.tap +ugoph.bin +.vscode diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c4a4ffd --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: ugoph.tap + +ugoph.tap: *.asm *.pg + sjasmplus main.asm + +clean: + rm *.tap diff --git a/esxdos.asm b/esxdos.asm new file mode 100644 index 0000000..b74d230 --- /dev/null +++ b/esxdos.asm @@ -0,0 +1,71 @@ +; API methods +ESX_GETSETDRV = #89 +ESX_FOPEN = #9A +ESX_FCLOSE = #9B +ESX_FSYNC = #9C +ESX_FREAD = #9D +ESX_FWRITE = #9E + +; File modes +FMODE_READ = #01 +FMODE_WRITE = #06 +FMODE_CREATE = #0E + +; Returns: +; A - current drive +getDefaultDrive: + ld a, 0 + rst #8 + defb ESX_GETSETDRV + ret + +; Opens file on default drive +; B - File mode +; HL - File name +; Returns: +; A - file stream id +fopen: + push bc + push hl + call getDefaultDrive + pop ix + pop bc + rst #8 + defb ESX_FOPEN + ret + +; A - file stream id +fclose: + rst #8 + defb ESX_FCLOSE + ret + +; A - file stream id +; BC - length +; HL - buffer +; Returns +; BC - length(how much was actually read) +fread: + push hl + pop ix + rst #8 + defb ESX_FREAD + ret + +; A - file stream id +; BC - length +; HL - buffer +; Returns: +; BC - actually written bytes +fwrite: + push hl + pop ix + rst #8 + defb ESX_FWRITE + ret + +; A - file stream id +fsync: + rst #8 + defb ESX_FSYNC + ret diff --git a/font.bin b/font.bin new file mode 100644 index 0000000000000000000000000000000000000000..127dfe147836f3c7176a0120125f10b2c1c01799 GIT binary patch literal 1248 zcmeH_OL4?N3`7Tuu!w>wh(ag~g{2@0OF;kWQxO_Dizmx-Gcp=F^*0@L@4%cVFk4%6u!Pzv zmH;BNn>rNZhfrLqc(&*->6F;TY*S&DJAtZ07WXl-gEsQrp0 + JR Z,B2DSKP0 +B2DFND1: DEC C + RLA + JR NC,B2DFND1 ; determine no. of most significant 1-bit + RRA + LD D,A ; byte from binary input value +B2DLUS2: PUSH HL + PUSH BC +B2DLUS1: LD HL,B2DEND-1 ; address LSB of BCD value + LD B,E ; current length of BCD value in bytes + RL D ; highest bit from input value -> carry +B2DLUS0: LD A,(HL) + ADC A,A + DAA + LD (HL),A ; double 1 BCD byte from intermediate result + DEC HL + DJNZ B2DLUS0 ; and go on to double entire BCD value (+carry!) + JR NC,B2DNXT + INC E ; carry at MSB -> BCD value grew 1 byte larger + LD (HL),1 ; initialize new MSB of BCD value +B2DNXT: DEC C + JR NZ,B2DLUS1 ; repeat for remaining bits from 1 input byte + POP BC ; no. of remaining bytes in input value + LD C,8 ; reset bit-counter + POP HL ; pointer to byte from input value + DEC HL + LD D,(HL) ; get next group of 8 bits + DJNZ B2DLUS2 ; and repeat until last byte from input value +B2DSIZ: LD HL,B2DEND ; address of terminating 0 + LD C,E ; size of BCD value in bytes + OR A + SBC HL,BC ; calculate address of MSB BCD + LD D,H + LD E,L + SBC HL,BC + EX DE,HL ; HL=address BCD value, DE=start of decimal value + LD B,C ; no. of bytes BCD + SLA C ; no. of bytes decimal (possibly 1 too high) + LD A,"0" + RLD ; shift bits 4-7 of (HL) into bit 0-3 of A + CP "0" ; (HL) was > 9h? + JR NZ,B2DEXPH ; if yes, start with recording high digit + DEC C ; correct number of decimals + INC DE ; correct start address + JR B2DEXPL ; continue with converting low digit +B2DEXP: RLD ; shift high digit (HL) into low digit of A +B2DEXPH: LD (DE),A ; record resulting ASCII-code + INC DE +B2DEXPL: RLD + LD (DE),A + INC DE + INC HL ; next BCD-byte + DJNZ B2DEXP ; and go on to convert each BCD-byte into 2 ASCII + SBC HL,BC ; return with HL pointing to 1st decimal + RET + +AppendB2D: +; Append results of B2D to string at HL + ex de, hl ; Get destination into DE + ld hl, B2DBUF + call SkipWhitespace + ldir + ex de, hl ; Get destination into DE + ret + +B2DINV: DS 8 ; space for 64-bit input value (LSB first) +B2DBUF: DS 20 ; space for 20 decimal digits +B2DEND: DB 0 ; space for terminating 0 \ No newline at end of file diff --git a/wifi.asm b/wifi.asm new file mode 100644 index 0000000..92cc7d1 --- /dev/null +++ b/wifi.asm @@ -0,0 +1,258 @@ +; Initialize WiFi chip and connect to WiFi +initWifi: + call loadWiFiConfig + + ld hl, cmd_plus + call uartWriteStringZ + ld b,#ff +wlp: + push bc + ld b, #ff + djnz $ + pop bc + djnz wlp + + ld hl, cmd_rst + call uartWriteStringZ +rstLp: + call uartReadBlocking + call pushRing + ld hl, response_rdy + call searchRing + cp 1 + jr nz, rstLp + + ld hl, cmd_at ; Disable ECHO. BTW Basic UART test + call okErrCmd + and 1 + jr z, errInit + + ld hl, cmd_cwqap ; Lets disconnect from last AP + call okErrCmd + and 1 + jr z, errInit + + ld hl, cmd_cmux ; Single connection mode + call okErrCmd + and 1 + jr z, errInit + + ld hl, cmd_inf_off ; FTP enables this info? We doesn't need it :-) + call okErrCmd + and 1 + jr z, errInit + + ld hl, cmd_cwjap1 ; Access Point connection + call uartWriteStringZ + ld hl, ssid + call uartWriteStringZ + ld hl, cmd_cwjap2 + call uartWriteStringZ + ld hl, pass + call uartWriteStringZ + ld hl, cmd_cwjap3 + call okErrCmd + and 1 + jr z, errInit + + ld hl, log_ok + call putStringZ + + ret +errInit + ld hl, log_err + call putStringZ + jr $ + + +; Send AT-command and wait for result. +; HL - Z-terminated AT-command(with CR/LF) +; A: +; 1 - Success +; 0 - Failed +okErrCmd: + call uartWriteStringZ +okErrCmdLp: + call uartReadBlocking + call pushRing + + ld hl, response_ok + call searchRing + cp 1 + jr z, okErrOk + + ld hl, response_err + call searchRing + cp 1 + jr z, okErrErr + + ld hl, response_fail + call searchRing + cp 1 + jr z, okErrErr + + + jp okErrCmdLp +okErrOk + ld a, 1 + ret +okErrErr + ld a, 0 + ret + +; Gets packet from network +; packet will be in var 'output_buffer' +; received packet size in var 'bytes_avail' +; +; If connection was closed it calls 'closed_callback' +getPacket + call uartReadBlocking + call pushRing + + ld hl, closed + call searchRing + cp 1 + jp z, closed_callback + + ld hl, ipd + call searchRing + cp 1 + jr nz, getPacket + + call count_ipd_lenght + ld (bytes_avail), hl + push hl + pop bc + ld hl, output_buffer +readp: + push bc + push hl + call uartReadBlocking + pop hl + ld (hl), a + pop bc + dec bc + inc hl + ld a, b + or c + jr nz, readp + ld hl, (bytes_avail) + ret + +count_ipd_lenght + ld hl,0 ; count lenght +cil1 push hl + call uartReadBlocking + push af + call pushRing + pop af + pop hl + cp ':' + ret z + 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 + jr cil1 + +; HL - z-string to hostname or ip +; DE - z-string to port +startTcp: + push de + push hl + ld hl, cmd_open1 + call uartWriteStringZ + pop hl + call uartWriteStringZ + ld hl, cmd_open2 + call uartWriteStringZ + pop de + call uartWriteStringZ + ld hl, cmd_open3 + call okErrCmd + ret + +; Returns: +; A: 1 - Success +; 0 - Failed +sendByte: + push af + ld hl, cmd_send_b + call okErrCmd + cp 1 + jr nz, sbErr +sbLp + call uartReadBlocking + ld hl, send_prompt + call searchRing + cp 1 + jr nz, sbLp + pop af + ld (sbyte_buff), a + call okErrCmd + ret +sbErr: + pop af + ld a, 0 + ret + +loadWiFiConfig: + ld b, FMODE_READ + ld hl, conf_file + call fopen + + push af + ld hl, ssid + ld bc, 160 + call fread + pop af + + call fclose + ret +cmd_plus defb "+++", 0 +cmd_rst defb "AT+RST",13, 10, 0 +cmd_at defb "ATE0", 13, 10, 0 ; Disable echo - less to parse +cmd_mode defb "AT+CWMODE_DEF=1",13,10,0 ; Client mode +cmd_cmux defb "AT+CIPMUX=0",13,10,0 ; Single connection mode +cmd_cwqap defb "AT+CWQAP",13,10,0 ; Disconnect from AP +cmd_inf_off defb "AT+CIPDINFO=0",13,10,0 ; doesn't send me info about remote port and ip + +cmd_cwjap1 defb "AT+CWJAP_CUR=", #22,0 ;Connect to AP. Send this -> SSID +cmd_cwjap2 defb #22,',',#22,0 ; -> This -> Password +cmd_cwjap3 defb #22, 13, 10, 0 ; -> And this + +cmd_open1 defb "AT+CIPSTART=", #22, "TCP", #22, ",", #22, 0 +cmd_open2 defb #22, ",", 0 +cmd_open3 defb 13, 10, 0 +cmd_send defb "AT+CIPSEND=", 0 +cmd_close defb "AT+CIPCLOSE",13,10,0 +cmd_send_b defb "AT+CIPSEND=1", 13, 10,0 +closed defb "CLOSED", 13, 10, 0 +ipd defb 13, 10, "+IPD,", 0 +crlf defb 13,10, 0 + +response_rdy defb 'ready', 0 +response_ok defb 'OK', 13, 10, 0 ; Sucessful operation +response_err defb 13,10,'ERROR',13,10,0 ; Failed operation +response_fail defb 13,10,'FAIL',13,10,0 ; Failed connection to WiFi. For us same as ERROR + +log_err defb 'Failed connect to WiFi!',13, 0 +log_ok defb 'WiFi connected!', 13, 0 + +ssid defs 80 +pass defs 80 + +bytes_avail defw 0 +sbyte_buff defb 0, 0 + +send_prompt defb ">",0 +output_buffer defs 2048 ; buffer for downloading data + +; WiFi configuration +conf_file defb "/sys/config/iw.cfg",0 \ No newline at end of file