Initial Commit

This commit is contained in:
2026-08-26 23:09:04 +02:00
commit 1f4390a42b
25 changed files with 13462 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
#include "cpu.h"
#include "ram.h"
#include "rom.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
static struct termios orig_termios;
void restore_terminal(void) { tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios); }
void set_nonblocking_input(void) {
struct termios raw;
tcgetattr(STDIN_FILENO, &orig_termios);
atexit(restore_terminal);
raw = orig_termios;
raw.c_lflag &= ~(ICANON | ECHO); // disable line buffering and echo
raw.c_cc[VMIN] = 0; // don't block waiting for input
raw.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
// make stdin reads non-blocking too
int flags = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
}
int main(void) {
uint8_t *ram = NULL;
CPU cpu;
set_nonblocking_input();
initRom(rom);
if (createRAM(&ram) != 0) {
printf("Could not create RAM\n");
return 1;
}
/* DEBUG */
FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
if (!fp) {
perror("fopen");
return 1;
}
fread(ram, 1, 64 * 1024, fp);
if (ferror(fp)) {
perror("fread");
fclose(fp);
return 1;
}
fclose(fp);
/* DEBUG END*/
initCPU(&cpu);
resetCPU(&cpu, rom);
while (1) {
//printf("\tPC: 0x%x\tOP: 0x%x\n", cpu.ProgrammeCounter, ram[cpu.ProgrammeCounter]);
useconds_t sleep = runCycle(&cpu, ram, rom);
if (sleep == 1) {
printf("opcode missing: 0x%X\n", ram[cpu.ProgrammeCounter - 1]);
return 1;
}
fflush(stdout);
usleep(sleep);
}
/* CPU WORK */
destroyRAM(ram);
return 0;
}