written code for reading file from SD card, not tested yet
This commit is contained in:
1 parent
1de5af7cb4
commit
b7f579525b
5 files changed
+91
-4
No files matched your search
@@ -48,6 +48,7 @@
|
||||
|
||||
!addr SD_CTL = $D680
|
||||
!addr SD_ADDR = $D681 ; 4 bytes
|
||||
!addr SD_BUFCTL = $D689
|
||||
!addr SD_ERRCODE = $D6DA
|
||||
|
||||
; SD card sector buffer, $FFFD6E00
|
||||
|
||||
@@ -128,4 +128,7 @@
|
||||
!addr RD_DIR_ENTRY = $82E0 ; - ram disk
|
||||
|
||||
!addr SD_MEMSHADOW = $8310 ; 256 byte buffer for preserving original memory content
|
||||
!addr SD_DESC = $8410 ; current file descriptor
|
||||
!addr SD_FILEBUF = $8410 ; 512 byte buffer for file reading
|
||||
|
||||
!addr SD_DESC = $8610 ; current file descriptor
|
||||
|
||||
@@ -53,6 +53,9 @@ dev_sd_cmd_OPEN_file:
|
||||
|
||||
dev_sd_cmd_OPEN_dir:
|
||||
|
||||
lda #$02 ; mode: read directory
|
||||
sta SD_MODE
|
||||
|
||||
; Copy the filter from command XXX this should be moved to common part and deduplicated with file opening
|
||||
|
||||
ldy #$00
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
dev_sd_cmd_READ:
|
||||
|
||||
; XXX provide implementation for regular files
|
||||
lda SD_MODE
|
||||
cmp #$03
|
||||
+beq fs_hvsr_read_file
|
||||
|
||||
lda SD_DIR_PHASE
|
||||
cmp #$01
|
||||
|
||||
@@ -49,12 +49,90 @@ fs_hvsr_read_file_open:
|
||||
|
||||
; Found the file - load it
|
||||
|
||||
; XXX provide implementation
|
||||
jsr fs_hvsr_direntmem_restore ; restore $1000 memory content
|
||||
|
||||
lda #$18 ; dos_openfile
|
||||
sta HTRAP00
|
||||
+nop
|
||||
|
||||
; XXX check error code
|
||||
|
||||
jmp dos_EXIT_CLC
|
||||
; XXX check for errors
|
||||
|
||||
; Read the first 512-byte chunk
|
||||
|
||||
lda #$03 ; mode: read file
|
||||
sta SD_MODE
|
||||
|
||||
jsr fs_hvsr_read_file
|
||||
jmp dos_EXIT
|
||||
|
||||
fs_hvsr_read_file:
|
||||
|
||||
; Read chunk of data to SD card buffer
|
||||
|
||||
lda #$1A ; dos_readfile
|
||||
sta HTRAP00
|
||||
+nop
|
||||
|
||||
; XXX check error code
|
||||
|
||||
; Store number of bytes read
|
||||
|
||||
stx SD_ACPTR_LEN+0
|
||||
sty SD_ACPTR_LEN+1
|
||||
|
||||
; Check if any data was read
|
||||
|
||||
lda SD_ACPTR_LEN+0
|
||||
ora SD_ACPTR_LEN+0
|
||||
bne @copy
|
||||
|
||||
lda #$20 ; dos_closefile
|
||||
sta HTRAP00
|
||||
+nop
|
||||
|
||||
lda #$00
|
||||
sec
|
||||
rts
|
||||
|
||||
@copy:
|
||||
|
||||
; Set pointer to new data
|
||||
|
||||
lda #<SD_FILEBUF
|
||||
sta SD_ACPTR_PTR+0
|
||||
lda #>SD_FILEBUF
|
||||
sta SD_ACPTR_PTR+1
|
||||
|
||||
; Copy data to SD_FILEBUF
|
||||
|
||||
lda #%10000000 ; select SD card buffer
|
||||
tsb SD_BUFCTL
|
||||
|
||||
lda #$02
|
||||
sta DMA_ADDRBANK ; $D702
|
||||
lda #$00
|
||||
sta DMA_ADDRMB ; $D704
|
||||
|
||||
lda #>(@dmalist-$4000)
|
||||
sta DMA_ADDRMSB ; $D701
|
||||
lda #<(@dmalist-$4000)
|
||||
sta DMA_ETRIG ; $D705
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
@dmalist:
|
||||
|
||||
!byte $0A ; use F018A list format (it is shorter by 1 byte)
|
||||
!byte $80, $FF ; src. address is $FFxxxxx
|
||||
!byte $81, $00 ; dst. address is $00xxxxx
|
||||
!byte $00 ; end of options
|
||||
!byte $00 ; operation: COPY
|
||||
!word $0200 ; data size if 512 bytes
|
||||
!byte $00, $6E, $0D ; src. addr is $xxD6E00
|
||||
!byte <SD_FILEBUF, >SD_FILEBUF - $80, $01 ; dst. addr is $xx1xxxx (internal buffer)
|
||||
|
||||
fs_hvsr_file_not_found:
|
||||
|
||||
|
||||
Reference in new issue
Block a user