Skip to content

Commit

Permalink
[DOS/FAT32] add T tell command, include position and size of open fil…
Browse files Browse the repository at this point in the history
…e channel
  • Loading branch information
mooinglemur committed May 12, 2024
1 parent be884c7 commit aa78fe3
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dos/cmdch.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
.include "banks.inc"

.export set_status, cmdch_read
.export cmdch_exec
.export cmdch_exec, add_decimal
.export status_r, status_w, statusbuffer

; parser.s
.import parse_command
Expand Down
2 changes: 1 addition & 1 deletion dos/declare.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ shared_vars:
; API arguments and return data, shared from DOS into FAT32
; but used primarily by FAT32
fat32_dirent: .tag dirent ; Buffer containing decoded directory entry
fat32_size: .res 4 ; Used for fat32_read, fat32_write, fat32_get_offset, fat32_get_free_space
fat32_size: .res 4 ; Used for fat32_read, fat32_write, fat32_get_offset, fat32_get_free_space, fat32_tell, fat32_get_size
fat32_errno: .byte 0 ; Last error
fat32_readonly: .byte 0 ; User-accessible read-only flag

Expand Down
79 changes: 77 additions & 2 deletions dos/file.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.include "file.inc"

; cmdch.s
.import set_status
.import set_status, add_decimal

; parser.s
.import find_wildcards
Expand All @@ -27,11 +27,12 @@

; functions.s
.import alloc_context, free_context
.export file_set_position
.export file_set_position, file_get_position_and_size

; other BSS
.import fat32_size
.import fat32_errno
.import statusbuffer, status_w, status_r

.bss

Expand Down Expand Up @@ -464,6 +465,80 @@ file_set_position:
@error: sec
rts

;---------------------------------------------------------------
; file_get_position_and_size
;
; In: a context
;---------------------------------------------------------------
file_get_position_and_size:
tax
bmi @error ; not a file context
fat32_call fat32_set_context

lda #'0'
sta statusbuffer + 0
lda #'7'
sta statusbuffer + 1
lda #','
sta statusbuffer + 2

fat32_call fat32_get_offset
bcc @error

ldx #3
jsr @hexdword

lda #' '
sta statusbuffer,x
inx

; .X should be preserved by this
fat32_call fat32_get_size
bcc @error

jsr @hexdword

lda #0
jsr add_decimal
lda #0
jsr add_decimal

stz status_r
stx status_w

clc
rts

@error: sec
rts

@hexdword:
ldy #3
@hdloop:
lda fat32_size,y
jsr @storehex8
dey
bpl @hdloop
rts

@storehex8:
pha
lsr
lsr
lsr
lsr
jsr @storehex4
pla
@storehex4:
and #$0f
cmp #$0a
bcc :+
adc #$66
: eor #$30
sta statusbuffer,x
inx
rts

;---------------------------------------------------------------
convert_errno_status:
ldx fat32_errno
Expand Down
1 change: 1 addition & 0 deletions dos/functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
.global block_write_u2
.global block_execute
.global set_position
.global get_position_and_size
22 changes: 21 additions & 1 deletion dos/functions.s
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
.import buffer
.importzp krn_ptr1, bank_save

.import context_for_channel

.import file_get_position_and_size

; other BSS
.import fat32_readonly
.import fat32_dirent
Expand Down Expand Up @@ -1233,7 +1237,6 @@ block_execute:
; offset 4 offset[24:31]
;---------------------------------------------------------------
set_position:
.import context_for_channel
stx fat32_ptr
sty fat32_ptr + 1
lda (fat32_ptr) ; channel
Expand All @@ -1251,3 +1254,20 @@ set_position:

@error: lda #$70 ; no channel
rts

;---------------------------------------------------------------
; get_position_and_size
;
; In: .A channel
;---------------------------------------------------------------

get_position_and_size:
tax
lda context_for_channel,x
jsr file_get_position_and_size
bcs @error
lda #$ff ; status already filled
rts

@error: lda #$70 ; no channel
rts
11 changes: 11 additions & 0 deletions dos/parser.s
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ cmds:
; 'F-R' file restore
.byte 'W' ; 'W-n' write protect
.byte 'P' ; 'P' position
.byte 'T' ; 'T' tell
.byte 255 ; echo (internal)
cmds_end:
cmd_ptrs:
Expand All @@ -1074,6 +1075,7 @@ cmd_ptrs:
.word cmd_f
.word cmd_w
.word cmd_p
.word cmd_t
.word cmd_255 ; echo (internal)

;---------------------------------------------------------------
Expand Down Expand Up @@ -1793,6 +1795,15 @@ cmd_p:
clc
rts

;---------------------------------------------------------------
; T - tell (X16)
;---------------------------------------------------------------
cmd_t:
lda buffer+1
jsr get_position_and_size
clc
rts

;---------------------------------------------------------------
; CHR$(255) - echo message (internal)
;---------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions fat32/fat32.s
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ _fat32_bss_end:
.export fat32_write_byte
.export sync_sector_buffer
.export fat32_set_time
.export fat32_get_size

.code

Expand Down Expand Up @@ -3737,6 +3738,22 @@ fat32_get_ptable_entry:
sec
rts


;-----------------------------------------------------------------------------
; fat32_get_size
;
; Out: fat32_size: file size of context
;
; * c=0: failure; sets errno
;-----------------------------------------------------------------------------
fat32_get_size:
stz fat32_errno

set32 fat32_size, cur_context + context::file_size

sec
rts

;-----------------------------------------------------------------------------
; fat32_seek
;
Expand Down
2 changes: 2 additions & 0 deletions fat32/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

.import fat32_set_time

.import fat32_get_size

.segment "API"
jmp fat32_init ; $C000
Expand Down Expand Up @@ -106,3 +107,4 @@
jmp sdcard_check_alive ; $C06C

jmp sdcard_set_fast_mode ; $C06F
jmp fat32_get_size ; $C072
2 changes: 2 additions & 0 deletions inc/fat32.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ sdcard_init = $C069
sdcard_check_alive = $C06C

sdcard_set_fast_mode = $C06F

fat32_get_size = $C072

0 comments on commit aa78fe3

Please sign in to comment.