Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Make retry mechanism actually work for file reads
Browse files Browse the repository at this point in the history
  • Loading branch information
spectrumero committed Oct 31, 2010
1 parent e9c240b commit 4cfad75
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
3 changes: 3 additions & 0 deletions rom/sysvars.asm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;THE SOFTWARE.

; Buffer for filesystems, 512 bytes
fs_scratchpad equ 0x3500

NMISTACK equ 0x38FE

; General purpose small workspace for ROM modules. Each ROM page gets 8 bytes
Expand Down
26 changes: 13 additions & 13 deletions rom/tnfs_core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -307,23 +307,25 @@ F_tnfs_message_w_hl ; entry point for when HL is already set
F_tnfs_message
ld a, tnfs_max_retries ; number of retries
ld (v_tnfs_retriesleft), a ; into memory
ld (v_tnfs_tx_de), de ; save pointer
ld (v_tnfs_tx_bc), bc ; save size

.retryloop
ld a, (v_curmountpt) ; current mount point
rlca ; multiply by 8 to find the sockinfo
rlca
rlca
add v_tnfs_sockinfo0 % 256 ; LSB
ld h, v_tnfs_sockinfo0 / 256 ; MSB
ld l, a
push de ; stack the parameters
push bc
ld (v_tnfs_tx_hl), hl ; save sockinfo pointer
.retryloop
ld hl, (v_tnfs_tx_hl) ; Fetch parameters
ld de, (v_tnfs_tx_de)
ld bc, (v_tnfs_tx_bc)
ld a, (v_tnfs_sock) ; socket descriptor
call SENDTO ; send the data
jr nc, .pollstart
pop bc ; error, leave now after restoring stack
pop de
ret
ret ; error, leave now
; wait for the response by polling
.pollstart
Expand All @@ -333,23 +335,21 @@ F_tnfs_message
dec a ; decrement it
ld (v_tnfs_retriesleft), a ; and store it
and a ; is it at zero?
pop bc ; fetch parameters to either restore stack
pop de ; or get ready for the next try
jr nz, .retryloop
ld a, TTIMEOUT ; error code - we tried...but gave up
scf ; timed out
ret

.continue
pop bc ; restore stack
pop ix ; start of the block we sent
ld ix, (v_tnfs_tx_de) ; start of the block we sent
ld a, (ix+tnfs_cmd_offset) ; check the command
cp TNFS_OP_READ ; and see if it's a read operation
ld hl, v_vfs_sockinfo ; Address to receive remote datagram IP/port
ld de, tnfs_recv_buffer ; Address to receive data
ld a, (v_tnfs_sock) ; The tnfs socket
jr z, .read ; ...if the command was READ, handle it

ld bc, 1024 ; max message size
call RECVFROM
ld a, (tnfs_recv_buffer + tnfs_seqno_offset)
Expand Down Expand Up @@ -379,7 +379,7 @@ F_tnfs_message
add v_tnfs_seqno0 % 256
ld l, a
ld h, v_tnfs_seqno0 / 256
ld a, (hl) ; (TODO) Consume rest of packet when no match
ld a, (hl) ; Consume rest of packet when no match
cp b ; sequence number match? if not
jr nz, .consume ; consume and discard the non-match data

Expand Down Expand Up @@ -410,9 +410,9 @@ F_tnfs_message
.consume ; consume and discard data we don't want
ld a, (v_tnfs_sock) ; if there is any data to be consumed
call POLLFD ; (a non data datagram or an error datagram
jp z, .pollstart ; may not have any more data)
jp z, .retryloop ; may not have any more data)
ld de, buf_tnfs_wkspc
ld de, tnfs_recv_buffer
ld bc, 256
ld a, (v_tnfs_sock)
call RECV ; unload any remaining data from the socket
Expand Down
7 changes: 5 additions & 2 deletions rom/tnfs_sysvars.asm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ v_tnfs_sockinfo3 equ 0x1038

v_tnfs_polltime equ 0x1040 ; current poll time in 50ths/sec
v_tnfs_backoff equ 0x1041 ; have we backed off yet?
v_tnfs_tx_de equ 0x1042 ; DE for transmit
v_tnfs_tx_bc equ 0x1044 ; BC for transmit
v_tnfs_tx_hl equ 0x1046 ; HL for transmit

HANDLESPACE equ 0x1100 ; Handle information storage space
HMETASPACE equ 0x1200 ; Handle metadata storage space
Expand All @@ -59,5 +62,5 @@ v_cwd1 equ 0x1900 ; for mount points 0 to 4
v_cwd2 equ 0x1A00
v_cwd3 equ 0x1B00

tnfs_recv_buffer equ 0x3B00 ; up to 768 bytes
buf_tnfs_wkspc equ 0x3B00 ; General network workspace
tnfs_recv_buffer equ 0x3500 ; up to 512 bytes + header
buf_tnfs_wkspc equ 0x3B00 ; up to 512 bytes + header

0 comments on commit 4cfad75

Please sign in to comment.