Save root cluster number
This commit is contained in:
2
sw/cc65
2
sw/cc65
Submodule sw/cc65 updated: 84af5e6887...9824f6e3d4
@@ -11,21 +11,16 @@
|
|||||||
|
|
||||||
|
|
||||||
.data
|
.data
|
||||||
|
root_cluster: .res 4
|
||||||
fat_start_sector: .res 2
|
fat_start_sector: .res 2
|
||||||
data_start_sector: .res 4
|
data_start_sector: .res 4
|
||||||
fat_size: .res 4
|
fat_size: .res 4
|
||||||
|
|
||||||
sd_buf: .res 512
|
sd_buf: .res 512
|
||||||
|
|
||||||
bps_val_str: .asciiz "Bytes Per Sector: 0x%x\n"
|
|
||||||
sps_val_str: .asciiz "Sectors Per Cluster: 0x%x\n"
|
|
||||||
rsv_val_str: .asciiz "Reserved Sectors: 0x%x\n"
|
|
||||||
fat_count_str: .asciiz "FAT count: 0x%x\n"
|
|
||||||
fat_sect_str: .asciiz "Sectors per FAT: 0x%x\n"
|
|
||||||
fat_size_tot_str: .asciiz "Total fat size: 0x%lx\n"
|
|
||||||
rsv_sect_bytes_str: .asciiz "Total reserved bytes: 0x%x\n"
|
|
||||||
rsv_sd_sectors: .asciiz "Reserved SD Sectors: 0x%x\n"
|
|
||||||
data_start_sect_str: .asciiz "Data sector start: 0x%lx\n"
|
data_start_sect_str: .asciiz "Data sector start: 0x%lx\n"
|
||||||
|
starting_cluster_str: .asciiz "Root cluster num: %lx\n";
|
||||||
|
value_str: .asciiz "Value: 0x%x\n"
|
||||||
|
|
||||||
.code
|
.code
|
||||||
|
|
||||||
@@ -34,6 +29,7 @@ sectors_per_cluster = sd_buf + $0D
|
|||||||
reserved_sectors = sd_buf + $0E
|
reserved_sectors = sd_buf + $0E
|
||||||
fat_count = sd_buf + $10
|
fat_count = sd_buf + $10
|
||||||
sectors_per_fat = sd_buf + $24
|
sectors_per_fat = sd_buf + $24
|
||||||
|
root_cluster_offs = sd_buf + $2C
|
||||||
|
|
||||||
.proc _fat32_init
|
.proc _fat32_init
|
||||||
; load sector 0 into sd_buf
|
; load sector 0 into sd_buf
|
||||||
@@ -49,68 +45,25 @@ sectors_per_fat = sd_buf + $24
|
|||||||
ldx #>ptr1
|
ldx #>ptr1
|
||||||
jsr _SD_readSingleBlock
|
jsr _SD_readSingleBlock
|
||||||
|
|
||||||
lda #<bps_val_str
|
|
||||||
ldx #>bps_val_str
|
|
||||||
jsr pushax
|
|
||||||
lda bytes_per_sector
|
|
||||||
ldx bytes_per_sector+1
|
|
||||||
jsr pushax
|
|
||||||
ldy #$4
|
|
||||||
jsr _cprintf
|
|
||||||
|
|
||||||
lda #<sps_val_str
|
|
||||||
ldx #>sps_val_str
|
|
||||||
jsr pushax
|
|
||||||
lda sectors_per_cluster
|
|
||||||
ldx #$00
|
ldx #$00
|
||||||
jsr pushax
|
L1: lda root_cluster_offs,x
|
||||||
ldy #$4
|
sta root_cluster,x
|
||||||
jsr _cprintf
|
inx
|
||||||
|
cpx #$4
|
||||||
lda #<rsv_val_str
|
blt L1
|
||||||
ldx #>rsv_val_str
|
|
||||||
jsr pushax
|
|
||||||
lda reserved_sectors
|
|
||||||
ldx #$00
|
|
||||||
jsr pushax
|
|
||||||
ldy #$4
|
|
||||||
jsr _cprintf
|
|
||||||
|
|
||||||
lda #<fat_count_str
|
|
||||||
ldx #>fat_count_str
|
|
||||||
jsr pushax
|
|
||||||
lda fat_count
|
|
||||||
ldx #$00
|
|
||||||
jsr pushax
|
|
||||||
ldy #$4
|
|
||||||
jsr _cprintf
|
|
||||||
|
|
||||||
|
|
||||||
lda #<rsv_sect_bytes_str
|
|
||||||
ldx #>rsv_sect_bytes_str
|
|
||||||
jsr pushax
|
|
||||||
|
|
||||||
|
; Multiply reserved sectors and bytes per sector, then divide by 512 to get sd sectors
|
||||||
lda reserved_sectors
|
lda reserved_sectors
|
||||||
jsr pusha0
|
jsr pusha0
|
||||||
lda bytes_per_sector
|
lda bytes_per_sector
|
||||||
ldx bytes_per_sector+1
|
ldx bytes_per_sector+1
|
||||||
jsr _imulii
|
jsr _imulii
|
||||||
jsr pushax
|
txa
|
||||||
phx
|
|
||||||
ldy #$4
|
|
||||||
jsr _cprintf
|
|
||||||
|
|
||||||
pla
|
|
||||||
lsr
|
lsr
|
||||||
sta fat_start_sector
|
sta fat_start_sector
|
||||||
stz fat_start_sector + 1
|
stz fat_start_sector + 1
|
||||||
|
|
||||||
lda #<fat_size_tot_str
|
; multiply fat size and number of fats to get total fat size
|
||||||
ldx #>fat_size_tot_str
|
|
||||||
jsr pushax
|
|
||||||
|
|
||||||
; multiply fat size and number of fats
|
|
||||||
|
|
||||||
lda fat_count
|
lda fat_count
|
||||||
jsr pusha0
|
jsr pusha0
|
||||||
lda sectors_per_fat
|
lda sectors_per_fat
|
||||||
@@ -122,13 +75,9 @@ sectors_per_fat = sd_buf + $24
|
|||||||
sta fat_size+2
|
sta fat_size+2
|
||||||
lda sreg+1
|
lda sreg+1
|
||||||
sta fat_size+3
|
sta fat_size+3
|
||||||
lda fat_size
|
|
||||||
ldx fat_size+1
|
|
||||||
jsr pusheax
|
|
||||||
ldy #$6
|
|
||||||
jsr _cprintf
|
|
||||||
|
|
||||||
|
|
||||||
|
; Add fat size to starting fat sector to get data start sector
|
||||||
lda fat_size
|
lda fat_size
|
||||||
adc fat_start_sector
|
adc fat_start_sector
|
||||||
sta data_start_sector
|
sta data_start_sector
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ uint16_t imulii(uint16_t a, uint16_t b) {
|
|||||||
|
|
||||||
uint8_t SD_readSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *error) {
|
uint8_t SD_readSingleBlock(uint32_t addr, uint8_t *buf, uint8_t *error) {
|
||||||
FILE* f = fopen(FILE_PATH, "rb");
|
FILE* f = fopen(FILE_PATH, "rb");
|
||||||
|
(void)error;
|
||||||
fseek(f, addr * 512, SEEK_SET);
|
fseek(f, addr * 512, SEEK_SET);
|
||||||
fread(buf, 512, 1, f);
|
fread(buf, 512, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
void fat32_init(void);
|
void fat32_init(void);
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
printf("Hello, world!\n");
|
|
||||||
fat32_init();
|
fat32_init();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user