Add disk write support

This commit is contained in:
Ry 2022-10-27 16:02:17 -07:00
parent 9396931592
commit a0fa0361ae
3 changed files with 9 additions and 1 deletions

View File

@ -206,7 +206,9 @@ int bus_io_write(void *user, uint32_t value, uint32_t port) {
break; break;
}; };
case 0x40: { case 0x40: {
// TODO: write specified disk sector from memory // write specified disk sector from memory
set_disk_sector(id, value);
write_disk_from_memory(id);
break; break;
}; };
case 0x50: { case 0x50: {

View File

@ -52,3 +52,8 @@ size_t read_disk_into_memory(size_t id) {
if (id > 3) { puts("attempting to access disk with ID > 3\n"); return 0; } if (id > 3) { puts("attempting to access disk with ID > 3\n"); return 0; }
return fread(&vm.memory_ram[disk_controller.buffer_pointer], 1, 512, disk_controller.disks[id].file); return fread(&vm.memory_ram[disk_controller.buffer_pointer], 1, 512, disk_controller.disks[id].file);
} }
size_t write_disk_from_memory(size_t id) {
if (id > 3) { puts("attempting to access disk with ID > 3\n"); return 0; }
return fwrite(&vm.memory_ram[disk_controller.buffer_pointer], 1, 512, disk_controller.disks[id].file);
}

View File

@ -16,3 +16,4 @@ void remove_disk(size_t id);
uint64_t get_disk_size(size_t id); uint64_t get_disk_size(size_t id);
void set_disk_sector(size_t id, uint64_t sector); void set_disk_sector(size_t id, uint64_t sector);
size_t read_disk_into_memory(size_t id); size_t read_disk_into_memory(size_t id);
size_t write_disk_from_memory(size_t id);