Work in progress

This commit is contained in:
Stefan Arentz 2018-06-01 19:03:11 -04:00
parent 60e5dbf7b1
commit d8bcf49e80
6 changed files with 109 additions and 10 deletions

View File

@ -22,11 +22,11 @@ add_executable(cpu_test ${CPU_SOURCES} cpu_test.c)
add_executable(cpu_bench ${CPU_SOURCES} cpu_bench.c)
add_executable(ewm ${CPU_SOURCES} ${BOO_SOURCES} ${ONE_SOURCES} ${TWO_SOURCES} ${SDL_SOURCES} ewm.c)
target_link_libraries(ewm SDL2)
target_link_libraries(ewm SDL2 readline)
add_executable(tty_test ${CPU_SOURCES} ${ONE_SOURCES} ${SDL_SOURCES} tty_test.c)
target_link_libraries(tty_test SDL2)
target_link_libraries(tty_test SDL2 readline)
add_executable(scr_test ${CPU_SOURCES} ${TWO_SOURCES} ${SDL_SOURCES} scr_test.c)
target_link_libraries(scr_test SDL2)
target_link_libraries(scr_test SDL2 readline)

View File

@ -1,5 +1,5 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.9
# Generated by "Unix Makefiles" Generator, CMake Version 3.8
# Default target executed when no arguments are given to make.
default_target: all
@ -39,10 +39,10 @@ cmake_force:
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/local/Cellar/cmake/3.9.4/bin/cmake
CMAKE_COMMAND = /Applications/CLion.app/Contents/bin/cmake/bin/cmake
# The command to remove a file.
RM = /usr/local/Cellar/cmake/3.9.4/bin/cmake -E remove -f
RM = /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
@ -59,7 +59,7 @@ CMAKE_BINARY_DIR = /Users/stefan/Projects/ewm/src
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/local/Cellar/cmake/3.9.4/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
@ -69,8 +69,8 @@ rebuild_cache/fast: rebuild_cache
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/local/Cellar/cmake/3.9.3_1/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache
# Special rule for the target edit_cache

View File

@ -38,6 +38,9 @@
#define EWM_VECTOR_RES 0xfffc
#define EWM_VECTOR_IRQ 0xfffe
#define EWM_CPU_STATUS_RUNNING (0)
#define EWM_CPU_STATUS_PAUSED (1)
struct cpu_instruction_t;
struct ewm_lua_t;
@ -62,6 +65,8 @@ struct cpu_t {
#if defined(EWM_LUA)
struct ewm_lua_t *lua;
#endif
int status;
};
typedef void (*cpu_instruction_handler_t)(struct cpu_t *cpu);

View File

@ -20,5 +20,73 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <SDL2/SDL.h>
#include "cpu.h"
#include "dbg.h"
static int ewm_dbg_thread(void *object) {
struct ewm_dbg_t *dbg = (struct ewm_dbg_t*) object;
printf("Welcome to the EWM debugger\n");
while (1) {
// Wait for the CPU to pause
while (dbg->cpu->status == EWM_CPU_STATUS_RUNNING) {
// TODO Replace this with a condition variable
}
printf("%.4x: A=%.2x X=%.2x Y=%.2x SP=%.2x\n", dbg->cpu->state.pc, dbg->cpu->state.a,
dbg->cpu->state.x, dbg->cpu->state.y, dbg->cpu->state.sp);
char *line = readline("(ewm) ");
if (strcmp(line, "quit") == 0) {
exit(0);
}
if (strcmp(line, "run") == 0) {
ewm_dbg_continue(dbg);
continue;
}
if (strcmp(line, "br $ffef") == 0) {
dbg_breakpoint_set(dbg, 0xffef);
}
printf("Sorry I don't understand that\n");
}
return 0;
}
int ewm_dbg_start(struct ewm_dbg_t *dbg) {
SDL_Thread *thread = SDL_CreateThread(ewm_dbg_thread, "ewm: debugger", dbg);
if (thread == NULL) {
return -1;
}
return 0;
}
void ewm_dbg_pause(struct ewm_dbg_t *dbg) {
dbg->cpu->status = EWM_CPU_STATUS_PAUSED;
}
void ewm_dbg_continue(struct ewm_dbg_t *dbg) {
dbg->cpu->status = EWM_CPU_STATUS_RUNNING;
}
void ewm_dbg_breakpoint_set(struct ewm_dbg_t *dbg, uint16_t addr) {
printf("Setting breakpoint at %.4x\n", addr);
}
struct ewm_dbg_t *ewm_dbg_create(struct cpu_t *cpu) {
struct ewm_dbg_t *dbg = (struct ewm_dbg_t*) malloc(sizeof(struct ewm_dbg_t));
if (dbg != NULL) {
dbg->cpu = cpu;
}
return dbg;
}

View File

@ -23,4 +23,18 @@
#ifndef EWM_DBG_H
#define EWM_DBG_H
struct cpu_t;
struct ewm_dbg_t {
struct cpu_t *cpu;
};
struct ewm_dbg_t *ewm_dbg_create(struct cpu_t *cpu);
int ewm_dbg_start(struct ewm_dbg_t *dbg);
void ewm_dbg_pause(struct ewm_dbg_t *dbg);
void ewm_dbg_continue(struct ewm_dbg_t *dbg);
void ewm_dbg_breakpoint_set(struct ewm_dbg_t *dbg, uint16_t addr);
#endif // EWM_DBG_H

View File

@ -145,6 +145,10 @@ static bool ewm_one_poll_event(struct ewm_one_t *one, SDL_Window *window) {
}
static bool ewm_one_step_cpu(struct ewm_one_t *one, int cycles) {
if (one->cpu->status == EWM_CPU_STATUS_PAUSED) {
return true;
}
while (true) {
int ret = cpu_step(one->cpu);
if (ret < 0) {
@ -305,9 +309,17 @@ int ewm_one_main(int argc, char **argv) {
cpu_strict(one->cpu, strict);
cpu_trace(one->cpu, trace_path);
cpu_reset(one->cpu);
if (debug_port != 0) {
struct ewm_dbg_t *dbg = ewm_dbg_create(one->cpu);
ewm_dbg_pause(dbg);
if (ewm_dbg_start(dbg) != 0) {
printf("ewm: one: failed to start debugger\n");
exit(1);
}
}
// Main loop
SDL_StartTextInput();