moved read16 & write16 to helper funcs in fat16.c, removed from iface

master
Ondřej Hruška 10 years ago
parent 228099e1d4
commit 3972499b36
  1. 24
      fat16.c
  2. 4
      fat16.h
  3. 15
      main.c
  4. BIN
      test

@ -57,6 +57,20 @@ bool find_empty_file_slot(FAT16_FILE* file);
// =========== INTERNAL FUNCTION IMPLEMENTATIONS =========
uint16_t read16(const BLOCKDEV* dev)
{
uint16_t a;
dev->load(&a, 2);
return a;
}
void write16(const BLOCKDEV* dev, const uint16_t val)
{
dev->store(&val, 2);
}
/** Find absolute address of first boot sector. Returns 0 on failure. */
uint32_t find_bs(const BLOCKDEV* dev)
{
@ -139,14 +153,14 @@ void read_bs(const BLOCKDEV* dev, Fat16BootSector* info, const uint32_t addr)
void write_fat(const FAT16* fat, const uint16_t cluster, const uint16_t value)
{
fat->dev->seek(fat->fat_addr + (cluster * 2));
fat->dev->write16(value);
write16(fat->dev, value);
}
uint16_t read_fat(const FAT16* fat, const uint16_t cluster)
{
fat->dev->seek(fat->fat_addr + (cluster * 2));
return fat->dev->read16();
return read16(fat->dev);
}
@ -418,11 +432,11 @@ void write_file_header(FAT16_FILE* file, const char* fname_raw, const uint8_t at
}
// addr of the first file cluster
dev->write16(clu_start);
write16(dev, clu_start);
// file size (uint32_t)
dev->write16(0);
dev->write16(0);
write16(dev, 0);
write16(dev, 0);
// reopen file - load & parse the information just written
open_file(file->fat, file, file->clu, file->num);

@ -9,12 +9,8 @@ typedef struct
void (*store)(const void* src, const uint16_t len);
// Sequential byte write
void (*write)(const uint8_t b);
// Sequential 2-byte write
void (*write16)(const uint16_t b);
// Sequential byte read
uint8_t (*read)(void);
// Sequential 2-byte read
uint16_t (*read16)(void);
// Absolute seek
void (*seek)(const uint32_t);
// Relative seek

@ -45,11 +45,6 @@ void test_write(const uint8_t b)
fwrite(&b, 1, 1, testf);
}
void test_write16(const uint16_t b)
{
fwrite(&b, 2, 1, testf);
}
uint8_t test_read()
{
uint8_t a;
@ -57,21 +52,11 @@ uint8_t test_read()
return a;
}
uint16_t test_read16()
{
uint16_t a;
fread(&a, 2, 1, testf);
return a;
}
void test_open()
{
test.read = &test_read;
test.write = &test_write;
test.read16 = &test_read16;
test.write16 = &test_write16;
test.load = &test_load;
test.store = &test_store;

BIN
test

Binary file not shown.
Loading…
Cancel
Save