LF only, more FS fixes

This commit is contained in:
Kilian committed 2026-09-28 17:30:47 +02:00
1 parent 566db4a550
commit a0cabac399
14 files changed
+130 -85

No files matched your search

+5 -5
View File
@@ -6,12 +6,12 @@
// Up to 256 files can be open
FILE *files[256];
int openFile(int fd, const char *path) {
int openFile(int fd, const char *path, const char *mode) {
if (files[fd] != NULL) {
return STATUS_READY | STATUS_ERROR;
}
files[fd] = fopen(path, "w+");
files[fd] = fopen(path, mode);
if (files[fd] == NULL) {
return STATUS_READY | STATUS_ERROR;
}
@@ -36,9 +36,9 @@ int closeFile(int fd) {
return STATUS_READY;
}
int readByte(const int fd, int *data) {
int readByte(const int fd, uint8_t *data) {
int status = 0;
int count = fread(&data, 1, 1, files[fd]);
int count = fread(data, 1, 1, files[fd]);
// Error or EOF
if (count != 1) {
int error = ferror(files[fd]);
@@ -53,7 +53,7 @@ int readByte(const int fd, int *data) {
return STATUS_READY | status;
}
int writeByte(const int fd, const int data) {
int writeByte(const int fd, const uint8_t data) {
int status = 0;
int count = fwrite(&data, 1, 1, files[fd]);
// Error or EOF
+28 -2
View File
@@ -65,12 +65,28 @@ void writeMemory(uint16_t address, uint8_t value, uint8_t *ram) {
case FILE_COMMAND: {
switch (value) {
case COMMAND_OPEN: {
case COMMAND_OPEN_R: {
ram[IO_BASE + FILE_STATUS] = 0;
uint16_t fileAddress = ram[IO_BASE + FILE_DATA] | ((uint16_t)ram[IO_BASE + FILE_DATA_HIGH] << 8);
ram[IO_BASE + FILE_STATUS] = openFile(ram[IO_BASE + FILE_DESCRIPTOR], (const char *)&ram[fileAddress]);
ram[IO_BASE + FILE_STATUS] = openFile(ram[IO_BASE + FILE_DESCRIPTOR], (const char *)&ram[fileAddress], "r");
break;
}
case COMMAND_OPEN_W: {
ram[IO_BASE + FILE_STATUS] = 0;
uint16_t fileAddress = ram[IO_BASE + FILE_DATA] | ((uint16_t)ram[IO_BASE + FILE_DATA_HIGH] << 8);
ram[IO_BASE + FILE_STATUS] = openFile(ram[IO_BASE + FILE_DESCRIPTOR], (const char *)&ram[fileAddress], "w+");
break;
}
case COMMAND_OPEN_A: {
ram[IO_BASE + FILE_STATUS] = 0;
uint16_t fileAddress = ram[IO_BASE + FILE_DATA] | ((uint16_t)ram[IO_BASE + FILE_DATA_HIGH] << 8);
ram[IO_BASE + FILE_STATUS] = openFile(ram[IO_BASE + FILE_DESCRIPTOR], (const char *)&ram[fileAddress], "a+");
break;
}
case COMMAND_CLOSE: {
@@ -78,6 +94,16 @@ void writeMemory(uint16_t address, uint8_t value, uint8_t *ram) {
ram[IO_BASE + FILE_STATUS] = closeFile(ram[IO_BASE + FILE_DESCRIPTOR]);
break;
}
case COMMAND_READ: {
ram[IO_BASE + FILE_STATUS] = 0;
ram[IO_BASE + FILE_STATUS] = readByte(ram[IO_BASE + FILE_DESCRIPTOR], &ram[IO_BASE + FILE_DATA]);
break;
}
case COMMAND_WRITE: {
ram[IO_BASE + FILE_STATUS] = 0;
ram[IO_BASE + FILE_STATUS] = writeByte(ram[IO_BASE + FILE_DESCRIPTOR], ram[IO_BASE + FILE_DATA]);
break;
}
default:
break;
-5
View File
@@ -20,11 +20,6 @@ int getChar(void) {
return 0xFF;
}
// BASIC expects CR always
if (c == '\n') {
return '\r';
}
// BASIC is uppercase only
if (c >= 'a' && c <= 'z') {
c = c - 'a' + 'A';