mirror of
https://github.com/RyuKojiro/apple1.git
synced 2024-07-06 17:29:01 +00:00
Use new interactive debugger module from v6502
git-svn-id: svn+ssh://svn.phoenixbox.net/svn/apple1/trunk@33 64f78de7-aa59-e511-a0e8-0002a5492df0
This commit is contained in:
parent
a75d31065c
commit
0d7a3c032a
@ -13,6 +13,7 @@
|
|||||||
E668391B1BA64C5B008F0F06 /* liblibdis6502.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E66838FC1BA4F705008F0F06 /* liblibdis6502.a */; };
|
E668391B1BA64C5B008F0F06 /* liblibdis6502.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E66838FC1BA4F705008F0F06 /* liblibdis6502.a */; };
|
||||||
E668391E1BA64C61008F0F06 /* liblibas6502.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E66838F81BA4F705008F0F06 /* liblibas6502.a */; };
|
E668391E1BA64C61008F0F06 /* liblibas6502.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E66838F81BA4F705008F0F06 /* liblibas6502.a */; };
|
||||||
E66839201BA659A6008F0F06 /* libcurses.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E668391F1BA659A6008F0F06 /* libcurses.dylib */; };
|
E66839201BA659A6008F0F06 /* libcurses.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E668391F1BA659A6008F0F06 /* libcurses.dylib */; };
|
||||||
|
E6ECE7B91BABED0100D1812C /* libedit.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E6ECE7B81BABED0100D1812C /* libedit.dylib */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@ -136,6 +137,7 @@
|
|||||||
E66839041BA53A82008F0F06 /* pia.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pia.c; sourceTree = "<group>"; };
|
E66839041BA53A82008F0F06 /* pia.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pia.c; sourceTree = "<group>"; };
|
||||||
E66839051BA53A82008F0F06 /* pia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pia.h; sourceTree = "<group>"; };
|
E66839051BA53A82008F0F06 /* pia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pia.h; sourceTree = "<group>"; };
|
||||||
E668391F1BA659A6008F0F06 /* libcurses.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurses.dylib; path = usr/lib/libcurses.dylib; sourceTree = SDKROOT; };
|
E668391F1BA659A6008F0F06 /* libcurses.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurses.dylib; path = usr/lib/libcurses.dylib; sourceTree = SDKROOT; };
|
||||||
|
E6ECE7B81BABED0100D1812C /* libedit.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libedit.dylib; path = usr/lib/libedit.dylib; sourceTree = SDKROOT; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -143,6 +145,7 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
E6ECE7B91BABED0100D1812C /* libedit.dylib in Frameworks */,
|
||||||
E66839201BA659A6008F0F06 /* libcurses.dylib in Frameworks */,
|
E66839201BA659A6008F0F06 /* libcurses.dylib in Frameworks */,
|
||||||
E668391E1BA64C61008F0F06 /* liblibas6502.a in Frameworks */,
|
E668391E1BA64C61008F0F06 /* liblibas6502.a in Frameworks */,
|
||||||
E668391B1BA64C5B008F0F06 /* liblibdis6502.a in Frameworks */,
|
E668391B1BA64C5B008F0F06 /* liblibdis6502.a in Frameworks */,
|
||||||
@ -184,6 +187,7 @@
|
|||||||
E66838D21BA4F6F8008F0F06 /* Frameworks */ = {
|
E66838D21BA4F6F8008F0F06 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E6ECE7B81BABED0100D1812C /* libedit.dylib */,
|
||||||
E668391F1BA659A6008F0F06 /* libcurses.dylib */,
|
E668391F1BA659A6008F0F06 /* libcurses.dylib */,
|
||||||
E66838D31BA4F705008F0F06 /* v6502.xcodeproj */,
|
E66838D31BA4F705008F0F06 /* v6502.xcodeproj */,
|
||||||
);
|
);
|
||||||
|
144
apple1/main.c
144
apple1/main.c
@ -6,77 +6,123 @@
|
|||||||
// Copyright (c) 2015 Daniel Loffgren. All rights reserved.
|
// Copyright (c) 2015 Daniel Loffgren. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <v6502/cpu.h>
|
|
||||||
#include <v6502/mem.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "pia.h"
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <histedit.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <dis6502/reverse.h>
|
#include <dis6502/reverse.h>
|
||||||
#include <v6502/log.h>
|
#include <v6502/log.h>
|
||||||
|
#include <v6502/debugger.h>
|
||||||
|
#include <v6502/cpu.h>
|
||||||
|
#include <v6502/mem.h>
|
||||||
|
#include <as6502/error.h>
|
||||||
|
|
||||||
|
#include "pia.h"
|
||||||
|
|
||||||
#define ROM_START 0xF000
|
#define ROM_START 0xF000
|
||||||
#define ROM_SIZE 0x00FF
|
#define ROM_SIZE 0x00FF
|
||||||
#define RESET_VECTOR 0xFF00
|
#define RESET_VECTOR 0xFF00
|
||||||
|
|
||||||
void fault(void *ctx, const char *e) {
|
static int faulted = 0;
|
||||||
|
static v6502_cpu *cpu;
|
||||||
|
static a1pia *pia;
|
||||||
|
|
||||||
|
static void fault(void *ctx, const char *e) {
|
||||||
(*(int *)ctx)++;
|
(*(int *)ctx)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadRomFile(v6502_memory *mem, const char *fname, uint16_t address) {
|
//static uint8_t romMirrorCallback(struct _v6502_memory *memory, uint16_t offset, int trap, void *context) {
|
||||||
FILE *f = fopen(fname, "r");
|
// return memory->bytes[offset % ROM_SIZE];
|
||||||
|
//}
|
||||||
if (!f) {
|
|
||||||
fprintf(stderr, "Could not read from \"%s\"!\n", fname);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t byte;
|
|
||||||
uint16_t offset = 0;
|
|
||||||
|
|
||||||
while (fread(&byte, 1, 1, f)) {
|
|
||||||
mem->bytes[address + (offset++)] = byte;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "loaded \"%s\" at 0x%04x\n", fname, address);
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t romMirrorCallback(struct _v6502_memory *memory, uint16_t offset, int trap, void *context) {
|
|
||||||
return memory->bytes[offset % ROM_SIZE];
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, const char * argv[])
|
|
||||||
{
|
|
||||||
int faulted = 0;
|
|
||||||
|
|
||||||
v6502_cpu *cpu = v6502_createCPU();
|
|
||||||
cpu->memory = v6502_createMemory(v6502_memoryStartCeiling + 1);
|
|
||||||
cpu->fault_callback = fault;
|
|
||||||
cpu->fault_context = &faulted;
|
|
||||||
|
|
||||||
// Load Woz Monitor
|
|
||||||
for (uint16_t start = ROM_START;
|
|
||||||
start < v6502_memoryStartCeiling && start >= ROM_START;
|
|
||||||
start += ROM_SIZE + 1) {
|
|
||||||
loadRomFile(cpu->memory, "apple1.rom", start);
|
|
||||||
//v6502_map(cpu->memory, start, ROM_SIZE, romMirrorCallback, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attach PIA
|
|
||||||
a1pia *pia = pia_create(cpu->memory);
|
|
||||||
|
|
||||||
v6502_reset(cpu);
|
|
||||||
|
|
||||||
|
static void run(v6502_cpu *cpu) {
|
||||||
FILE *asmfile = fopen("runtime.s", "w");
|
FILE *asmfile = fopen("runtime.s", "w");
|
||||||
|
pia_start(pia);
|
||||||
while (!faulted) {
|
while (!faulted) {
|
||||||
dis6502_printAnnotatedInstruction(asmfile, cpu, cpu->pc);
|
dis6502_printAnnotatedInstruction(asmfile, cpu, cpu->pc);
|
||||||
v6502_step(cpu);
|
v6502_step(cpu);
|
||||||
v6502_printCpuState(asmfile, cpu);
|
v6502_printCpuState(asmfile, cpu);
|
||||||
}
|
}
|
||||||
|
pia_stop(pia);
|
||||||
fclose(asmfile);
|
fclose(asmfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *prompt() {
|
||||||
|
static char prompt[10];
|
||||||
|
snprintf(prompt, 10, "(0x%04x) ", cpu->pc);
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char * argv[])
|
||||||
|
{
|
||||||
|
cpu = v6502_createCPU();
|
||||||
|
cpu->memory = v6502_createMemory(v6502_memoryStartCeiling + 1);
|
||||||
|
cpu->fault_callback = fault;
|
||||||
|
cpu->fault_context = &faulted;
|
||||||
|
|
||||||
|
v6502_breakpoint_list *breakpoint_list = v6502_createBreakpointList();
|
||||||
|
|
||||||
|
// Load Woz Monitor
|
||||||
|
for (uint16_t start = ROM_START;
|
||||||
|
start < v6502_memoryStartCeiling && start >= ROM_START;
|
||||||
|
start += ROM_SIZE + 1) {
|
||||||
|
v6502_loadFileAtAddress(cpu->memory, "apple1.rom", start);
|
||||||
|
//v6502_map(cpu->memory, start, ROM_SIZE, romMirrorCallback, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attach PIA
|
||||||
|
pia = pia_create(cpu->memory);
|
||||||
|
|
||||||
|
v6502_reset(cpu);
|
||||||
|
|
||||||
|
int verbose = 0;
|
||||||
|
int commandLen;
|
||||||
|
HistEvent ev;
|
||||||
|
History *hist = history_init();
|
||||||
|
history(hist, &ev, H_SETSIZE, 100);
|
||||||
|
|
||||||
|
EditLine *el = el_init("apple1", stdin, stdout, stderr);
|
||||||
|
el_set(el, EL_PROMPT, &prompt);
|
||||||
|
el_set(el, EL_SIGNAL, SIGWINCH);
|
||||||
|
el_set(el, EL_EDITOR, "emacs");
|
||||||
|
el_set(el, EL_HIST, history, hist);
|
||||||
|
|
||||||
|
char *command = NULL;
|
||||||
|
while (!feof(stdin)) {
|
||||||
|
currentLineNum++;
|
||||||
|
|
||||||
|
const char *in = el_gets(el, &commandLen);
|
||||||
|
if (!in) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
history(hist, &ev, H_ENTER, in);
|
||||||
|
command = realloc(command, commandLen + 1);
|
||||||
|
memcpy(command, in, commandLen);
|
||||||
|
|
||||||
|
// Trim newline, always the last char
|
||||||
|
command[commandLen - 1] = '\0';
|
||||||
|
|
||||||
|
if (command[0] == '\0') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v6502_handleDebuggerCommand(cpu, command, commandLen, breakpoint_list, run, &verbose)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (command[0] != ';') {
|
||||||
|
as6502_executeAsmLineOnCPU(cpu, command, strlen(command));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
v6502_destroyBreakpointList(breakpoint_list);
|
||||||
|
history_end(hist);
|
||||||
|
el_end(el);
|
||||||
|
free(command);
|
||||||
pia_destroy(pia);
|
pia_destroy(pia);
|
||||||
v6502_destroyMemory(cpu->memory);
|
v6502_destroyMemory(cpu->memory);
|
||||||
v6502_destroyCPU(cpu);
|
v6502_destroyCPU(cpu);
|
||||||
|
printf("\n");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
22
apple1/pia.c
22
apple1/pia.c
@ -121,18 +121,14 @@ static void _doCoolVideoStart(a1pia *pia) {
|
|||||||
a1pia *pia_create(v6502_memory *mem) {
|
a1pia *pia_create(v6502_memory *mem) {
|
||||||
a1pia *pia = malloc(sizeof(a1pia));
|
a1pia *pia = malloc(sizeof(a1pia));
|
||||||
pia->memory = mem;
|
pia->memory = mem;
|
||||||
pia->screen = initscr();
|
pia->screen = NULL;
|
||||||
//nodelay(stdscr, true);
|
|
||||||
crmode();
|
|
||||||
noecho();
|
|
||||||
nonl();
|
|
||||||
|
|
||||||
v6502_map(mem, A1PIA_KEYBOARD_INPUT, 1, (v6502_readFunction *)keyboardReadCharacterCallback, NULL, pia);
|
v6502_map(mem, A1PIA_KEYBOARD_INPUT, 1, (v6502_readFunction *)keyboardReadCharacterCallback, NULL, pia);
|
||||||
v6502_map(mem, A1PIA_KEYBOARD_CRLF_REG, 1, (v6502_readFunction *)keyboardReadReadyCallback, NULL, pia);
|
v6502_map(mem, A1PIA_KEYBOARD_CRLF_REG, 1, (v6502_readFunction *)keyboardReadReadyCallback, NULL, pia);
|
||||||
v6502_map(mem, A1PIA_VIDEO_OUTPUT, 1, FIXME_I_SHOULDNT_BE_NULL, (v6502_writeFunction *)videoWriteCharCallback, pia);
|
v6502_map(mem, A1PIA_VIDEO_OUTPUT, 1, FIXME_I_SHOULDNT_BE_NULL, (v6502_writeFunction *)videoWriteCharCallback, pia);
|
||||||
v6502_map(mem, A1PIA_VIDEO_CRLF_REG, 1, FIXME_I_SHOULDNT_BE_NULL, (v6502_writeFunction *)videoWriteNewlineCallback, pia);
|
v6502_map(mem, A1PIA_VIDEO_CRLF_REG, 1, FIXME_I_SHOULDNT_BE_NULL, (v6502_writeFunction *)videoWriteNewlineCallback, pia);
|
||||||
|
|
||||||
_doCoolVideoStart(pia);
|
// _doCoolVideoStart(pia);
|
||||||
return pia;
|
return pia;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,3 +136,17 @@ void pia_destroy(a1pia *pia) {
|
|||||||
endwin();
|
endwin();
|
||||||
free(pia);
|
free(pia);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pia_start(a1pia *pia) {
|
||||||
|
if (!pia->screen) {
|
||||||
|
pia->screen = initscr();
|
||||||
|
}
|
||||||
|
//nodelay(stdscr, true);
|
||||||
|
crmode();
|
||||||
|
noecho();
|
||||||
|
nonl();
|
||||||
|
}
|
||||||
|
|
||||||
|
void pia_stop(a1pia *pia) {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -28,4 +28,7 @@ typedef struct {
|
|||||||
a1pia *pia_create(v6502_memory *mem);
|
a1pia *pia_create(v6502_memory *mem);
|
||||||
void pia_destroy(a1pia *pia);
|
void pia_destroy(a1pia *pia);
|
||||||
|
|
||||||
|
void pia_start(a1pia *pia);
|
||||||
|
void pia_stop(a1pia *pia);
|
||||||
|
|
||||||
#endif /* defined(__apple1__pia__) */
|
#endif /* defined(__apple1__pia__) */
|
||||||
|
Loading…
Reference in New Issue
Block a user