1
0
mirror of https://github.com/specht/champ.git synced 2024-11-26 16:49:35 +00:00
This commit is contained in:
Michael Specht 2018-02-05 21:50:24 +01:00
parent d2b2b63857
commit 3b5e038716
2 changed files with 57 additions and 45 deletions

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
champ: champ.c
gcc -o champ champ.c -lX11

100
champ.c
View File

@ -1,10 +1,4 @@
#define SHOW_SCREEN
#define SHOW_LOG
#ifdef SHOW_SCREEN
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -24,7 +18,6 @@
#define OVERFLOW 0x40 #define OVERFLOW 0x40
#define NEGATIVE 0x80 #define NEGATIVE 0x80
#ifdef SHOW_SCREEN
Display *dsp; Display *dsp;
Window win; Window win;
GC gc; GC gc;
@ -32,6 +25,8 @@ unsigned int white, black;
Atom wmDelete; Atom wmDelete;
XEvent evt; XEvent evt;
KeyCode keyQ; KeyCode keyQ;
uint8_t show_screen = 0;
uint8_t show_log = 1;
int init_display() int init_display()
{ {
@ -92,7 +87,6 @@ uint16_t yoffset[192] = {
0x0350, 0x0750, 0x0b50, 0x0f50, 0x1350, 0x1750, 0x1b50, 0x1f50, 0x0350, 0x0750, 0x0b50, 0x0f50, 0x1350, 0x1750, 0x1b50, 0x1f50,
0x03d0, 0x07d0, 0x0bd0, 0x0fd0, 0x13d0, 0x17d0, 0x1bd0, 0x1fd0 0x03d0, 0x07d0, 0x0bd0, 0x0fd0, 0x13d0, 0x17d0, 0x1bd0, 0x1fd0
}; };
#endif
typedef struct { typedef struct {
uint16_t ip; uint16_t ip;
@ -640,11 +634,12 @@ void handle_next_opcode()
break; break;
} }
#ifdef SHOW_LOG if (show_log)
printf("%04x | %d | %02x | %s %-18s | ", old_ip, cycles, read_opcode, OPCODE_STRINGS[opcode], {
ADDRESSING_MODE_STRINGS[addressing_mode] printf("%04x | %d | %02x | %s %-18s | ", old_ip, cycles, read_opcode, OPCODE_STRINGS[opcode],
); ADDRESSING_MODE_STRINGS[addressing_mode]
#endif );
}
int unhandled_opcode = 0; int unhandled_opcode = 0;
uint8_t t8 = 0; uint8_t t8 = 0;
@ -950,14 +945,14 @@ void handle_next_opcode()
exit(1); exit(1);
} }
cpu.total_cycles += cycles; cpu.total_cycles += cycles;
#ifdef SHOW_LOG if (show_log)
printf("A: %02x, X: %02x, Y: %02x, FLAGS: %02x, PC: %04x, SP: %02x | %10ld", {
cpu.a, cpu.x, cpu.y, cpu.flags, cpu.ip, cpu.sp, cpu.total_cycles); printf("A: %02x, X: %02x, Y: %02x, FLAGS: %02x, PC: %04x, SP: %02x | %10ld",
printf("\n"); cpu.a, cpu.x, cpu.y, cpu.flags, cpu.ip, cpu.sp, cpu.total_cycles);
#endif printf("\n");
}
} }
#ifdef SHOW_SCREEN
void set_pixel(int px, int py, unsigned int color) void set_pixel(int px, int py, unsigned int color)
{ {
int x, y; int x, y;
@ -982,16 +977,30 @@ void render_hires_screen()
} }
} }
} }
#endif
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (argc < 2)
{
printf("Usage: ./champ [options] <memory dump>\n");
printf("\n");
printf("Options:\n");
printf(" --show-screen\n");
printf(" --hide-log\n");
}
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], "--show-screen") == 0)
show_screen = 1;
if (strcmp(argv[i], "--hide-log") == 0)
show_log = 0;
}
memset(ram, 0, 0x10000); memset(ram, 0, 0x10000);
load("dump2", 0); load(argv[argc - 1], 0);
#ifdef SHOW_SCREEN if (show_screen)
init_display(); init_display();
#endif
init_cpu(&cpu); init_cpu(&cpu);
cpu.ip = 0x6000; cpu.ip = 0x6000;
@ -1015,34 +1024,35 @@ int main(int argc, char** argv)
// } // }
// else // else
// break; // break;
#ifdef SHOW_SCREEN if (show_screen)
if (XEventsQueued(dsp, QueuedAfterFlush) > 0)
{ {
int exit_program = 0; if (XEventsQueued(dsp, QueuedAfterFlush) > 0)
XNextEvent(dsp, &evt); {
int exit_program = 0;
XNextEvent(dsp, &evt);
switch (evt.type) { switch (evt.type) {
case (KeyRelease) : case (KeyRelease) :
if (evt.xkey.keycode == keyQ) if (evt.xkey.keycode == keyQ)
exit_program = 1; exit_program = 1;
case (ClientMessage) : case (ClientMessage) :
if (evt.xclient.data.l[0] == wmDelete) if (evt.xclient.data.l[0] == wmDelete)
exit_program = 1; exit_program = 1;
break; break;
}
if (exit_program)
break;
}
if (ram[0x30b] != old_screen_number)
{
old_screen_number = ram[0x30b];
render_hires_screen();
} }
if (exit_program)
break;
} }
if (ram[0x30b] != old_screen_number)
{
old_screen_number = ram[0x30b];
render_hires_screen();
}
#endif
} }
printf("Total cycles: %d\n", cpu.total_cycles); printf("Total cycles: %d\n", cpu.total_cycles);
return 0; return 0;