From a0fa0361ae9fc25c67d8f02cefe414e8fd5d836b Mon Sep 17 00:00:00 2001 From: Ry Date: Thu, 27 Oct 2022 16:02:17 -0700 Subject: [PATCH] Add disk write support --- src/bus.c | 4 +++- src/disk.c | 5 +++++ src/disk.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bus.c b/src/bus.c index 8f1d655..06097fc 100644 --- a/src/bus.c +++ b/src/bus.c @@ -206,7 +206,9 @@ int bus_io_write(void *user, uint32_t value, uint32_t port) { break; }; 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; }; case 0x50: { diff --git a/src/disk.c b/src/disk.c index 7df5926..bac0503 100644 --- a/src/disk.c +++ b/src/disk.c @@ -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; } 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); +} diff --git a/src/disk.h b/src/disk.h index 3756150..19eae0a 100644 --- a/src/disk.h +++ b/src/disk.h @@ -16,3 +16,4 @@ void remove_disk(size_t id); uint64_t get_disk_size(size_t id); void set_disk_sector(size_t id, uint64_t sector); size_t read_disk_into_memory(size_t id); +size_t write_disk_from_memory(size_t id);