Skip to content

Commit

Permalink
History refactoring. It fixes bug and adds multilevel history
Browse files Browse the repository at this point in the history
  • Loading branch information
nihirash committed Oct 24, 2020
1 parent 1a1f0b3 commit f0d6b8e
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 192 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ cspect/test.nex: pages main.asm engine/*.* drivers/*.* render/*.* utils/*.*
cp browser.nex cspect/

test: cspect/test.nex
cd cspect && mono CSpect.exe -w4 -nextrom -map=test.map -brk -tv -mmc=./../ -zxnext browser.nex
cd cspect && mono CSpect.exe -w5 -nextrom -map=test.map -brk -tv -mmc=./../ -zxnext browser.nex
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To compile project all you need is [sjasmplus](https://github.com/z00m128/sjasmp

You may use or not use GNU Make. But for just build enought only sjasmplus: `sjasmplus --zxnext=cspect main.asm`

If you want run it in emulator - use CSpect with configured REAL ESP-module! Buildin ESP-emulator doesn't support all necessary commands. But if you want run it in CSpect with buildin emulator there is some hack:
If you want run it in emulator - use CSpect with configured REAL ESP-module! Buildin ESP-emulator doesn't support all necessary commands. But if you want run it in CSpect with buildin emulator there is some hack(but it will work very bad):

* Found in `drivers` directory file `wifi.asm`.

Expand All @@ -35,6 +35,8 @@ And this

I've tried organize code for eaiser location all parts and wish you won't have issues with it. If there are some issues with it - feel free write me about it.

To bundle browser include `browser.nex` file and `docs/` directory in single package(should be placed in same directory).

## Usage

Before usage you should have already configured wifi chip(via wifi.bas/wifi2.bas located at demos/esp in Next distro).
Expand All @@ -60,7 +62,9 @@ Sometimes it's crashes. I didn't found reason - if you find it - please let me k
Still not possible download files. Sorry.

## Development plan

- [X] Publish first version and get first happy users
- [X] Fix history bugs
- [X] Make history multilevel
- [ ] Add file downloads using proxy server
- [ ] Add mouse support
- [ ] Automatic change song to next(if it goes as next link on page)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.gph
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ i Arrow Right or P - page down - - -
i Arrow Left or O - page up - - -
i Enter - visit link - - -
i N - enter new domain - - -
i B - history back(currently work only on one level) - - -
i B - history back(currently work only few levels) - - -
i H - return to this page - - -
i - - -
iIf you like my software - support it via PayPal donation: - - -
Expand Down
3 changes: 1 addition & 2 deletions drivers/esxdos.asm
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ loadBuffer:
ld b, Dos.FMODE_READ: call Dos.fopen
push af
ld hl, buffer, bc, #ffff - buffer : call Dos.fread
ld hl, buffer : add hl, bc : xor a : ld (hl), a
ld hl, buffer : add hl, bc : xor a : ld (hl), a : inc hl : ld (hl), a
pop af
call Dos.fclose
ei
xor a : ld (Render.cursor_position), a, (Render.page_offset), a
ret

; Returns:
Expand Down
8 changes: 4 additions & 4 deletions drivers/wifi.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
MODULE Wifi
inited db 0
bytes_avail dw 0
buffer_pointer dw 0
closed db 1
Expand All @@ -8,12 +7,13 @@ init:
call Uart.init
EspCmdOkErr "ATE0"
jr c, .initError
EspCmdOkErr "AT+CIPCLOSE" ; Close if there some connection was. Don't care about result
EspCmdOkErr "AT+CIPSERVER=0"
EspCmdOkErr "AT+CIPDINFO=0" ; Disable additional info
jr c, .initError
EspCmdOkErr "AT+CIPCLOSE" ; Close if there some connection was. Don't care about result
EspCmdOkErr "AT+CIPMUX=0" ; Single connection mode
jr c, .initError
EspCmdOkErr "AT+CIPDINFO=0" ; Disable additional info
jr c, .initError
or a
ret
.initError
Expand Down
4 changes: 2 additions & 2 deletions engine/engine.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include "history/index.asm"
include "urlencoder.asm"
include "fetcher.asm"
include "media-processor.asm"
include "history.asm"
include "media-processor.asm"
62 changes: 13 additions & 49 deletions engine/fetcher.asm
Original file line number Diff line number Diff line change
@@ -1,57 +1,25 @@
MODULE Fetcher
; HL - pointer to gopher page line
; C flag - is error happens
fetch:
call History.save
.skipHistory
push hl
ld hl, .msg : call DialogBox.msgNoWait
pop hl
push hl
ld a, (hl) : call Render.getIcon
ld (MediaProcessor.media_type), a
pop hl : push hl
call UrlEncoder.isFile
pop hl
jp c, fetchFromFS
push hl
call UrlEncoder.isValidGopherRow
pop hl
jr c, fetchFromNet
scf
ret
.msg db "Loading resource! Please wait! It will be here soon!", 0

; HL - pointer to gopher page line
fetchFromNet:
ld a, 9, bc, #ff : cpir
ld de, requestBuffer
ld hl, historyBlock.locator, de, requestBuffer
.copyRequest
ld a, (hl)
cp 9
jr z, .urlCopied
and a : jr z, .urlCopied
ld (de), a
inc hl, de
; TODO add search request support
jp .copyRequest
.urlCopied
xor a : ld (de), a
.getDomainAndHost
ld a, 9, bc, #ff : cpir
push hl ; domain
ld a, 9, bc, #ff : cpir
; hl - host
pop de ; de - port
ex hl, de
ld hl, historyBlock.host, de, historyBlock.port
call Wifi.openTCP
jr c, .error
ld hl, buffer, de, buffer + 1, bc, #ffff - buffer - 1, (hl), a
ldir
ld a, (Render.isInputRequest) : and a : jr z, .performRequest
ld a, (historyBlock.mediaType) : cp Font.INPUT : jr nz, .performRequest

ld a, 0, bc, #ff, hl, requestBuffer : cpir : dec hl
ld a, 9, (hl), a : inc hl
ld de, DialogBox.inputBuffer
ld de, historyBlock.search
.loadSearchRequest
ld a, (de) : ld (hl), a : and a : jr z, .performRequest
inc hl, de
Expand All @@ -64,25 +32,21 @@ fetchFromNet:
call Wifi.getPacket
ld a, (Wifi.closed) : and a : jr nz, .closedCallback
jr .loadPackets
.error
scf
.error
ld hl, .err : call DialogBox.msgBox
jp History.back
ret
.closedCallback
or a
ret
jp MediaProcessor.processResource
.err db "Document fetch error! Check your connection or hostname!", 0

; HL - pointer to gopher page line
fetchFromFS:
xor a : ld hl, buffer, de, buffer + 1, bc, #ffff - buffer - 1, (hl), a : ldir
call UrlEncoder.extractPath
loadFile
xor a : ld (de), a
ld hl, buffer, de, buffer + 1, bc, #ffff - buffer - 1, (hl), a
ldir
ld hl, nameBuffer : call Dos.loadBuffer
or a
ret
jp MediaProcessor.processResource

requestBuffer ds #ff
ENDMODULE
41 changes: 0 additions & 41 deletions engine/history.asm

This file was deleted.

72 changes: 72 additions & 0 deletions engine/history/controller.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
MODULE History

back:
ld a, (depth) : cp 1 : ret z
ld hl, historyBlock + HistoryRecord, de, historyBlock, bc, (total - 1) * HistoryRecord : ldir ; Move history up
ld hl, depth : dec (hl)
; Loads current resource
load:
ld hl, .msg : call DialogBox.msgNoWait
xor a : ld hl, buffer, de, buffer + 1, bc, #ffff - buffer - 1, (hl), a : ldir
ld a, (historyBlock.isFile) : and a : jp nz, Fetcher.fetchFromFS
jp Fetcher.fetchFromNet

.msg db "Loading resource! Please wait! It will be here soon!", 0

home:
ld hl, homePage
; HL - gopher row
navigate:
ld de, hl
call UrlEncoder.isValidGopherRow
jr nc, load ; Not valid - reload last
ld hl, de
push hl

push hl
ld hl, HistoryEnd - HistoryRecord, de, HistoryEnd, bc, HistoryRecord * total : lddr
pop hl

; Fill record
ld de, hl
call UrlEncoder.isFile
ex hl, de
ld de, historyBlock
ld (de), a : inc de
ld a, (hl) : push hl, de : call Render.getIcon : pop de, hl
ld (de), a : inc de
ld a, 9, bc, #ff : cpir
.locatorCopy
ld a, (hl) : cp 9 : jr z, 1f
ld (de), a : inc hl, de
jr .locatorCopy
1
inc hl : xor a : ld (de), a
ld de, historyBlock.host
.hostCopy
ld a, (hl) : cp 9 : jr z, 1f
ld (de), a : inc hl, de
jr .hostCopy
1
inc hl : xor a : ld (de), a
ld de, historyBlock.port
.portCopy
ld a, (hl)
cp 9 : jr z, 1f
cp 13 : jr z, 1f
cp 10 : jr z, 1f
cp 0 : jr z, 1f
ld (de), a : inc hl, de
jr .portCopy
1 xor a : ld (de), a
ld hl, DialogBox.inputBuffer, de, historyBlock.search, bc, #ff : ldir
ld de, (Render.position), (historyBlock.position + HistoryRecord), de
ld de, 0, (historyBlock.position), de
pop hl
ld a, (depth) : cp total : jr nc, 1f
inc a : ld (depth), a
1
jp load

ENDMODULE
1 change: 1 addition & 0 deletions engine/history/index.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include "controller.asm"
30 changes: 30 additions & 0 deletions engine/history/model.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; This shit brokes adressing!!!!
;
; STRUCT HistoryRecord
;isFile BYTE
;mediaType BYTE
;locator BLOCK #ff
;host BLOCK 64 ; If you'll use longer host name - you're "сам себе злобный буратино"(you're your only enemy)
;port BLOCK 6 ; can be up to 65535
;search BLOCK #FF
;position WORD #00
; ENDS


total equ 5
depth db 0

historyBlock:
.isFile db 0
.mediaType db 0
.locator ds #ff
.host ds 64
.port ds 6
.search ds #ff
.position dw #00

HistoryRecord EQU $ - historyBlock
dup total
ds HistoryRecord
edup
HistoryEnd equ $ - 1
10 changes: 3 additions & 7 deletions engine/media-processor.asm
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
MODULE MediaProcessor

media_type db 2 ; Same as icon

processResource:
call UrlEncoder.extractHostName

ld a, (media_type)
ld a, (historyBlock.mediaType)
cp Font.LINK : jr z, processPage
cp Font.INPUT : jr z, processPage
cp Font.MUSIC : jr z, processPT
Expand All @@ -17,14 +13,14 @@ processText:

processPT:
call VortexProcessor.play
jp History.refresh
jp History.back

processPage:
call Render.renderGopherScreen
jp Render.workLoop

processImage:
call ScreenViewer.display
jp History.refresh
jp History.back

ENDMODULE
14 changes: 2 additions & 12 deletions engine/resident-parts.asm
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
nameBuffer db "index.gph", 0
ds #7f - ($ - nameBuffer), 0
nameBuffer ds #ff, 0
db 0
hostName ds 48

MODULE History
row db "1Starting page", 09, "index.gph", 09, "file", 09, "70", 13, 10
ds #ff - ($ - row)
prev db "1Starting page", 09, "index.gph", 09, "file", 09, "70", 13, 10
ds #ff - ($ - prev)
position dw 0
input db 0
ENDMODULE
hostName ds 64
Loading

0 comments on commit f0d6b8e

Please sign in to comment.