Merged cpm22 and bios, and layed foundation for different disk types
This commit is contained in:
84
Src/disk.c
84
Src/disk.c
@@ -2,12 +2,16 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "fatfs.h"
|
||||
#include "ff.h"
|
||||
#include "toml.h"
|
||||
#include "disk.h"
|
||||
|
||||
#define CPM_RECORD_SIZE 128
|
||||
#define CPM_RECORDS_PER_BLOCK 128
|
||||
#define CPM_BLOCK_SIZE CPM_RECORD_SIZE*CPM_RECORDS_PER_BLOCK
|
||||
|
||||
// @todo Properly deal with errors
|
||||
|
||||
struct DirtyBlock {
|
||||
uint32_t block;
|
||||
struct DirtyBlock* next;
|
||||
@@ -27,6 +31,12 @@ typedef struct {
|
||||
struct DirtyBlock* dirty_block;
|
||||
} Storage;
|
||||
|
||||
enum DiskType {
|
||||
DISK_UNKNOWN,
|
||||
DISK_RAW,
|
||||
DISK_CPM,
|
||||
} disk_type = DISK_RAW;
|
||||
|
||||
Storage storage;
|
||||
|
||||
uint8_t disk_read_byte() {
|
||||
@@ -58,12 +68,9 @@ void disk_write_byte(uint8_t value) {
|
||||
if (storage.lba == 0) {
|
||||
snprintf(filename, 128, "0:loader.bin");
|
||||
offset = storage.lba - 0;
|
||||
} else if (storage.lba >= 1 && storage.lba < 45) {
|
||||
snprintf(filename, 128, "0:cpm22.bin");
|
||||
} else if (storage.lba >= 1 && storage.lba < 256) {
|
||||
snprintf(filename, 128, "0:system.bin");
|
||||
offset = storage.lba - 1;
|
||||
} else if (storage.lba >= 45 && storage.lba < 51) {
|
||||
snprintf(filename, 128, "0:bios.bin");
|
||||
offset = storage.lba - 45;
|
||||
} else if (storage.lba >= 256 && storage.lba < 384) {
|
||||
offset = storage.lba - 256;
|
||||
|
||||
@@ -301,12 +308,9 @@ void disk_receive_command(uint8_t command) {
|
||||
if (storage.lba == 0) {
|
||||
snprintf(filename, 128, "0:loader.bin");
|
||||
offset = storage.lba - 0;
|
||||
} else if (storage.lba >= 1 && storage.lba < 45) {
|
||||
snprintf(filename, 128, "0:cpm22.bin");
|
||||
} else if (storage.lba >= 1 && storage.lba < 256) {
|
||||
snprintf(filename, 128, "0:system.bin");
|
||||
offset = storage.lba - 1;
|
||||
} else if (storage.lba >= 45 && storage.lba < 51) {
|
||||
snprintf(filename, 128, "0:bios.bin");
|
||||
offset = storage.lba - 45;
|
||||
} else if (storage.lba >= 256 && storage.lba < 384) {
|
||||
offset = storage.lba - 256;
|
||||
storage.size = 128;
|
||||
@@ -517,6 +521,66 @@ void disk_init() {
|
||||
printf("File error: %i\n\r", fr);
|
||||
}
|
||||
|
||||
disk_type = DISK_RAW;
|
||||
|
||||
// @todo Get rid of all the nesting
|
||||
FIL file;
|
||||
fr = f_open(&file, "0:disk.tml", FA_READ);
|
||||
if (fr == FR_OK) {
|
||||
// @todo Do not hardcode size
|
||||
char buffer[4096];
|
||||
unsigned int bytes_read;
|
||||
fr = f_read(&file, buffer, 4096-1, &bytes_read);
|
||||
if (fr) {
|
||||
printf("File error: %i\n\r", fr);
|
||||
}
|
||||
// Null terminate the string
|
||||
buffer[bytes_read] = 0x00;
|
||||
|
||||
char errbuf[200];
|
||||
toml_table_t* conf = toml_parse(buffer, errbuf, sizeof(errbuf));
|
||||
|
||||
fr = f_close(&file);
|
||||
if (fr) {
|
||||
printf("File error: %i\n\r", fr);
|
||||
}
|
||||
|
||||
if (conf) {
|
||||
toml_datum_t type = toml_string_in(conf, "type");
|
||||
if (type.ok) {
|
||||
if (!strcmp(type.u.s, "raw")) {
|
||||
disk_type = DISK_RAW;
|
||||
} else if (!strcmp(type.u.s, "cpm")) {
|
||||
disk_type = DISK_CPM;
|
||||
} else {
|
||||
disk_type = DISK_UNKNOWN;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("TOML Error: %s\n\r", errbuf);
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("File error: %i\n\r", fr);
|
||||
}
|
||||
|
||||
// @todo This is just for show
|
||||
// Instead we need to make a jump table for every function
|
||||
// Based on the disk_type the main function jumps to the correct sub function
|
||||
switch (disk_type) {
|
||||
case DISK_RAW:
|
||||
printf("Raw disk, unimplemented!\n\r");
|
||||
break;
|
||||
|
||||
case DISK_CPM:
|
||||
printf("CPM disk, implemtened\n\r");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unknown disk type\n\r");
|
||||
break;
|
||||
}
|
||||
|
||||
disk_get_entries();
|
||||
}
|
||||
|
||||
|
||||
2305
Src/toml.c
Normal file
2305
Src/toml.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user