diff --git a/sw/cc65 b/sw/cc65 index 84af5e6..9824f6e 160000 --- a/sw/cc65 +++ b/sw/cc65 @@ -1 +1 @@ -Subproject commit 84af5e6887c39dfd7d38b261e2410bf29dcdaa66 +Subproject commit 9824f6e3d40752e4bd8d0a4b40cb65d922e36fce diff --git a/sw/kernel/filesystems/fat32.s b/sw/kernel/filesystems/fat32.s index 029ce48..0c106ca 100644 --- a/sw/kernel/filesystems/fat32.s +++ b/sw/kernel/filesystems/fat32.s @@ -11,21 +11,16 @@ .data +root_cluster: .res 4 fat_start_sector: .res 2 data_start_sector: .res 4 fat_size: .res 4 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" +starting_cluster_str: .asciiz "Root cluster num: %lx\n"; +value_str: .asciiz "Value: 0x%x\n" .code @@ -34,6 +29,7 @@ sectors_per_cluster = sd_buf + $0D reserved_sectors = sd_buf + $0E fat_count = sd_buf + $10 sectors_per_fat = sd_buf + $24 +root_cluster_offs = sd_buf + $2C .proc _fat32_init ; load sector 0 into sd_buf @@ -49,68 +45,25 @@ sectors_per_fat = sd_buf + $24 ldx #>ptr1 jsr _SD_readSingleBlock - lda #bps_val_str - jsr pushax - lda bytes_per_sector - ldx bytes_per_sector+1 - jsr pushax - ldy #$4 - jsr _cprintf - - lda #sps_val_str - jsr pushax - lda sectors_per_cluster ldx #$00 - jsr pushax - ldy #$4 - jsr _cprintf - - lda #rsv_val_str - jsr pushax - lda reserved_sectors - ldx #$00 - jsr pushax - ldy #$4 - jsr _cprintf - - lda #fat_count_str - jsr pushax - lda fat_count - ldx #$00 - jsr pushax - ldy #$4 - jsr _cprintf - - - lda #rsv_sect_bytes_str - jsr pushax +L1: lda root_cluster_offs,x + sta root_cluster,x + inx + cpx #$4 + blt L1 + ; Multiply reserved sectors and bytes per sector, then divide by 512 to get sd sectors lda reserved_sectors jsr pusha0 lda bytes_per_sector ldx bytes_per_sector+1 jsr _imulii - jsr pushax - phx - ldy #$4 - jsr _cprintf - - pla + txa lsr sta fat_start_sector stz fat_start_sector + 1 - lda #fat_size_tot_str - jsr pushax - - ; multiply fat size and number of fats - + ; multiply fat size and number of fats to get total fat size lda fat_count jsr pusha0 lda sectors_per_fat @@ -122,13 +75,9 @@ sectors_per_fat = sd_buf + $24 sta fat_size+2 lda sreg+1 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 adc fat_start_sector sta data_start_sector diff --git a/sw/test_code/fs_test/harness.c b/sw/test_code/fs_test/harness.c index 93b9f9b..cd72522 100644 --- a/sw/test_code/fs_test/harness.c +++ b/sw/test_code/fs_test/harness.c @@ -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) { FILE* f = fopen(FILE_PATH, "rb"); + (void)error; fseek(f, addr * 512, SEEK_SET); fread(buf, 512, 1, f); + fclose(f); + return 0; } diff --git a/sw/test_code/fs_test/main.c b/sw/test_code/fs_test/main.c index 93d9085..410c999 100644 --- a/sw/test_code/fs_test/main.c +++ b/sw/test_code/fs_test/main.c @@ -3,7 +3,6 @@ void fat32_init(void); int main(void) { - printf("Hello, world!\n"); fat32_init(); return 0; } \ No newline at end of file