Improve/simplify Makefile. main.c also renamed.

This commit is contained in:
DavidBuchanan314 2017-01-03 20:01:18 +00:00
parent 378169d56b
commit 12f80f409c
3 changed files with 80 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.o *.o
6502-emu 6502-emu
memdump

71
6502-emu.c Normal file
View File

@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <time.h>
#include "6502.h"
#include "6850.h"
struct termios oldTermios;
void step_delay()
{
struct timespec req, rem;
req.tv_sec = 0;
req.tv_nsec = STEP_DURATION;
nanosleep(&req, &rem);
}
void run_cpu()
{
for (;;) {
// CPU timing is currently very far from being cycle-accurate
for (int i = 0; i < (CPU_FREQ / (ONE_SECOND / STEP_DURATION)); i++) {
step_cpu();
step_uart();
}
step_delay(); // remove this for more speed
}
}
void restore_stdin()
{
tcsetattr(0, TCSANOW, &oldTermios);
}
void raw_stdin()
{
struct termios newTermios;
tcgetattr(0, &oldTermios);
newTermios = oldTermios;
cfmakeraw(&newTermios);
tcsetattr(0, TCSANOW, &newTermios);
atexit(restore_stdin);
}
int main(int argc, char *argv[])
{
if (argc != 2) {
printf("Usage: %s file.rom\n", argv[0]);
printf("The first 16k of \"file.rom\" is loaded into the last 16k of memory.\n");
return EXIT_FAILURE;
}
if (load_rom(argv[1]) != 0) {
printf("Error loading \"%s\".\n", argv[1]);
return EXIT_FAILURE;
}
raw_stdin(); // allow individual keystrokes to be detected
init_tables();
init_uart();
reset_cpu();
run_cpu();
return EXIT_SUCCESS;
}

View File

@ -1,22 +1,17 @@
CC=gcc
CFLAGS = -Wall -Ofast -std=gnu99 CFLAGS = -Wall -Ofast -std=gnu99
LDFLAGS = -Ofast
OBJ := 6502-emu.o 6502.o 6850.o
all: 6502-emu all: 6502-emu
6502-emu: main.o 6502.o 6850.o debug: CFLAGS += -DDEBUG
$(CC) -o 6502-emu main.c 6502.o 6850.o debug: 6502-emu
main.o: main.c 6502-emu: $(OBJ)
$(CC) $(CFLAGS) -c main.c
6502.o: 6502.c
$(CC) $(CFLAGS) -c 6502.c
6850.o: 6850.c
$(CC) $(CFLAGS) -c 6850.c
clean: clean:
rm *.o 6502-emu $(RM) 6502-emu $(OBJ)
test: 6502-emu test: 6502-emu
./6502-emu examples/ehbasic.rom ./6502-emu examples/ehbasic.rom