Config, CTRL+C, exit
This commit is contained in:
1 parent
9e6a96f93a
commit
8101cc3f62
6 files changed
+53
-29
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "io.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int putChar(uint8_t c) {
|
||||
int _c = putchar(c);
|
||||
@@ -28,5 +29,9 @@ int getChar(void) {
|
||||
c = c - 'a' + 'A';
|
||||
}
|
||||
|
||||
if (c == 0x07) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
+18
-11
@@ -23,8 +23,10 @@ void set_nonblocking_input(void) {
|
||||
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_lflag &= ~(ICANON | ECHO); // disable line buffering, echo
|
||||
/* Ctrl+C becomes ordinary input byte 0x03 */
|
||||
raw.c_cc[VINTR] = _POSIX_VDISABLE;
|
||||
raw.c_cc[VMIN] = 0; // don't block waiting for input
|
||||
raw.c_cc[VTIME] = 0;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
|
||||
|
||||
@@ -34,6 +36,9 @@ void set_nonblocking_input(void) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
printf("6502PC Emulator with MS Basic\n");
|
||||
printf("CTRL + G to exit\n");
|
||||
|
||||
uint8_t *ram = NULL;
|
||||
CPU cpu;
|
||||
|
||||
@@ -43,26 +48,26 @@ int main(void) {
|
||||
|
||||
if (createRAM(&ram) != 0) {
|
||||
printf("Could not create RAM\n");
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* DEBUG */
|
||||
|
||||
//FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
||||
//FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
||||
//FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
||||
//FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
||||
// FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
||||
// FILE *fp = fopen("/Users/Kili2/Documents/Projekte/6502pc/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
||||
// FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_functional_test.bin", "rb");
|
||||
// FILE *fp = fopen("/mnt/c/Users/llego/source/repos/6502PC/6502_65C02_functional_tests/6502_decimal_test.bin", "rb");
|
||||
/*
|
||||
if (!fp) {
|
||||
perror("fopen");
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fread(ram, 1, RAM_SIZE, fp);
|
||||
if (ferror(fp)) {
|
||||
perror("fread");
|
||||
fclose(fp);
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
@@ -76,8 +81,10 @@ int main(void) {
|
||||
while (1) {
|
||||
uint8_t sleep = runCycle(&cpu, ram, rom);
|
||||
if (sleep == 1) {
|
||||
printf("opcode missing: 0x%X\n", ram[cpu.ProgrammeCounter - 1]);
|
||||
return 1;
|
||||
printf("Illegal opcode $%02X at $%04X "
|
||||
"A=$%02X X=$%02X Y=$%02X SP=$%02X\n",
|
||||
ram[cpu.ProgrammeCounter - 1], cpu.ProgrammeCounter - 1, cpu.Accumulator, cpu.X, cpu.Y, cpu.StackPointer);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sleepTime.tv_sec = 0;
|
||||
sleepTime.tv_nsec = sleep * (1000 / MACHINE_SPEED_HZ);
|
||||
|
||||
Reference in new issue
Block a user