Remove extra new line in disk error messages

This commit is contained in:
Ry 2023-03-04 17:00:38 -08:00
parent 0b9d2f61a3
commit 7f482a809a

View File

@ -16,7 +16,7 @@ disk_controller_t disk_controller;
extern fox32_vm_t vm; extern fox32_vm_t vm;
void new_disk(const char *filename, size_t id) { void new_disk(const char *filename, size_t id) {
if (id > 3) { puts("attempting to access disk with ID > 3\n"); return; } if (id > 3) { puts("attempting to access disk with ID > 3"); return; }
printf("mounting %s as disk ID %d\n", filename, (int) id); printf("mounting %s as disk ID %d\n", filename, (int) id);
disk_controller.disks[id].file = fopen(filename, "r+b"); disk_controller.disks[id].file = fopen(filename, "r+b");
if (!disk_controller.disks[id].file) { if (!disk_controller.disks[id].file) {
@ -29,35 +29,35 @@ void new_disk(const char *filename, size_t id) {
} }
void insert_disk(disk_t disk, size_t id) { void insert_disk(disk_t disk, size_t id) {
if (id > 3) { puts("attempting to access disk with ID > 3\n"); return; } if (id > 3) { puts("attempting to access disk with ID > 3"); return; }
if (disk_controller.disks[id].size > 0) remove_disk(id); if (disk_controller.disks[id].size > 0) remove_disk(id);
printf("mounting disk ID %d\n", (int) id); printf("mounting disk ID %d\n", (int) id);
disk_controller.disks[id] = disk; disk_controller.disks[id] = disk;
} }
void remove_disk(size_t id) { void remove_disk(size_t id) {
if (id > 3) { puts("attempting to access disk with ID > 3\n"); return; } if (id > 3) { puts("attempting to access disk with ID > 3"); return; }
printf("unmounting disk ID %d\n", (int) id); printf("unmounting disk ID %d\n", (int) id);
fclose(disk_controller.disks[id].file); fclose(disk_controller.disks[id].file);
disk_controller.disks[id].size = 0; disk_controller.disks[id].size = 0;
} }
uint64_t get_disk_size(size_t id) { uint64_t get_disk_size(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"); return 0; }
return disk_controller.disks[id].size; return disk_controller.disks[id].size;
} }
void set_disk_sector(size_t id, uint64_t sector) { void set_disk_sector(size_t id, uint64_t sector) {
if (id > 3) { puts("attempting to access disk with ID > 3\n"); return; } if (id > 3) { puts("attempting to access disk with ID > 3"); return; }
fseek(disk_controller.disks[id].file, sector * 512, 0); fseek(disk_controller.disks[id].file, sector * 512, 0);
} }
size_t read_disk_into_memory(size_t id) { 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"); 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) { size_t write_disk_from_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"); return 0; }
return fwrite(&vm.memory_ram[disk_controller.buffer_pointer], 1, 512, disk_controller.disks[id].file); return fwrite(&vm.memory_ram[disk_controller.buffer_pointer], 1, 512, disk_controller.disks[id].file);
} }