From 60e5dbf7b1aa1a8bf7efaeec7e8f8998ea250688 Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Sat, 14 Oct 2017 22:40:50 -0400 Subject: [PATCH 1/2] Debugger support --- src/CMakeLists.txt | 4 +- src/Makefile | 1022 +++++++++++++++++++++++++++++++++++++++----- src/dbg.c | 24 ++ src/dbg.h | 26 ++ src/one.c | 13 + 5 files changed, 989 insertions(+), 100 deletions(-) create mode 100644 src/dbg.c create mode 100644 src/dbg.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2b9525d..59d6ffb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,8 +14,8 @@ set(CPU_SOURCES cpu.c mem.c fmt.c ins.c utl.c) set(SDL_SOURCES sdl.c) set(BOO_SOURCES boo.c tty.c chr.c) -set(ONE_SOURCES one.c tty.c chr.c pia.c) -set(TWO_SOURCES two.c scr.c dsk.c chr.c alc.c) +set(ONE_SOURCES one.c tty.c chr.c pia.c dbg.c) +set(TWO_SOURCES two.c scr.c dsk.c chr.c alc.c dbg.c) add_executable(cpu_test ${CPU_SOURCES} cpu_test.c) diff --git a/src/Makefile b/src/Makefile index 39f2818..de80846 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,107 +1,933 @@ -# The MIT License (MIT) -# -# Copyright (c) 2015 Stefan Arentz - https://github.com/st3fan/ewm -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -UNAME := $(shell uname) - -CC?=cc -CFLAGS=-std=gnu11 -Wall -Wextra -Werror -Wno-unused-parameter -I/usr/include -LDFLAGS=-L/usr/local/lib - -ifndef DEBUG - CFLAGS += -O3 -flto - LDFLAGS += -flto -else - CFLAGS += -Og -g - LDFLAGS += -g -endif - -ifdef LUA - CFLAGS += -DEWM_LUA - ifeq ($(UNAME), Linux) - LUA_LIBS = -llua5.1 - CFLAGS += -I/usr/include/lua5.1 - LDFLAGS += -L/usr/lib/arm-linux-gnueabihf - else - LUA_LIBS=-llua - endif -endif - -CPU_SOURCES=cpu.c mem.c fmt.c ins.c utl.c -ifdef LUA - CPU_SOURCES += lua.c -endif - -EWM_EXECUTABLE=ewm -EWM_SOURCES=$(CPU_SOURCES) pia.c ewm.c two.c scr.c dsk.c chr.c alc.c one.c tty.c boo.c sdl.c -EWM_OBJECTS=$(EWM_SOURCES:.c=.o) -EWM_LIBS=-lSDL2 $(LUA_LIBS) - -CPU_TEST_EXECUTABLE=cpu_test -CPU_TEST_SOURCES=$(CPU_SOURCES) cpu_test.c -CPU_TEST_OBJECTS=$(CPU_TEST_SOURCES:.c=.o) -CPU_TEST_LIBS=$(LUA_LIBS) - -SCR_TEST_EXECUTABLE=scr_test -SCR_TEST_SOURCES=$(CPU_SOURCES) two.c scr.c dsk.c chr.c alc.c scr_test.c sdl.c -SCR_TEST_OBJECTS=$(SCR_TEST_SOURCES:.c=.o) -SCR_TEST_LIBS=-lSDL2 $(LUA_LIBS) - -TTY_TEST_EXECUTABLE=tty_test -TTY_TEST_SOURCES=$(CPU_SOURCES) one.c tty.c pia.c chr.c tty_test.c sdl.c -TTY_TEST_OBJECTS=$(TTY_TEST_SOURCES:.c=.o) -TTY_TEST_LIBS=-lSDL2 $(LUA_LIBS) - -CPU_BENCH=cpu_bench -CPU_BENCH_SOURCES=$(CPU_SOURCES) cpu_bench.c -CPU_BENCH_OBJECTS=$(CPU_BENCH_SOURCES:.c=.o) -CPU_BENCH_LIBS=$(LUA_LIBS) - -MEM_BENCH=mem_bench -MEM_BENCH_SOURCES=$(CPU_SOURCES) mem_bench.c -MEM_BENCH_OBJECTS=$(MEM_BENCH_SOURCES:.c=.o) -MEM_BENCH_LIBS=$(LUA_LIBS) - -all: $(EWM_SOURCES) $(EWM_EXECUTABLE) $(CPU_TEST_SOURCES) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_EXECUTABLE) $(TTY_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH) +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.9 +# Default target executed when no arguments are given to make. +default_target: all + +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/local/Cellar/cmake/3.9.4/bin/cmake + +# The command to remove a file. +RM = /usr/local/Cellar/cmake/3.9.4/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /Users/stefan/Projects/ewm/src + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /Users/stefan/Projects/ewm/src + +#============================================================================= +# Targets provided globally by CMake. + +# 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) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache + +.PHONY : rebuild_cache/fast + +# 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) +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache + +.PHONY : edit_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /Users/stefan/Projects/ewm/src/CMakeFiles /Users/stefan/Projects/ewm/src/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /Users/stefan/Projects/ewm/src/CMakeFiles 0 +.PHONY : all + +# The main clean target clean: - rm -f $(EWM_OBJECTS) $(EWM_EXECUTABLE) $(CPU_TEST_OBJECTS) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_OBJECTS) $(SCR_TEST_EXECUTABLE) $(TTY_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH) + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean + +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named ewm + +# Build rule for target. +ewm: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 ewm +.PHONY : ewm + +# fast build rule for target. +ewm/fast: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/build +.PHONY : ewm/fast + +#============================================================================= +# Target rules for targets named scr_test + +# Build rule for target. +scr_test: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 scr_test +.PHONY : scr_test + +# fast build rule for target. +scr_test/fast: + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/build +.PHONY : scr_test/fast + +#============================================================================= +# Target rules for targets named cpu_bench + +# Build rule for target. +cpu_bench: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 cpu_bench +.PHONY : cpu_bench + +# fast build rule for target. +cpu_bench/fast: + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/build +.PHONY : cpu_bench/fast + +#============================================================================= +# Target rules for targets named tty_test + +# Build rule for target. +tty_test: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 tty_test +.PHONY : tty_test + +# fast build rule for target. +tty_test/fast: + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/build +.PHONY : tty_test/fast + +#============================================================================= +# Target rules for targets named cpu_test + +# Build rule for target. +cpu_test: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 cpu_test +.PHONY : cpu_test + +# fast build rule for target. +cpu_test/fast: + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/build +.PHONY : cpu_test/fast + +alc.o: alc.c.o + +.PHONY : alc.o + +# target to build an object file +alc.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/alc.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/alc.c.o +.PHONY : alc.c.o + +alc.i: alc.c.i + +.PHONY : alc.i + +# target to preprocess a source file +alc.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/alc.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/alc.c.i +.PHONY : alc.c.i + +alc.s: alc.c.s + +.PHONY : alc.s + +# target to generate assembly for a file +alc.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/alc.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/alc.c.s +.PHONY : alc.c.s + +boo.o: boo.c.o + +.PHONY : boo.o + +# target to build an object file +boo.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/boo.c.o +.PHONY : boo.c.o + +boo.i: boo.c.i + +.PHONY : boo.i + +# target to preprocess a source file +boo.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/boo.c.i +.PHONY : boo.c.i + +boo.s: boo.c.s + +.PHONY : boo.s + +# target to generate assembly for a file +boo.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/boo.c.s +.PHONY : boo.c.s + +chr.o: chr.c.o + +.PHONY : chr.o + +# target to build an object file +chr.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/chr.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/chr.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/chr.c.o +.PHONY : chr.c.o + +chr.i: chr.c.i + +.PHONY : chr.i + +# target to preprocess a source file +chr.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/chr.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/chr.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/chr.c.i +.PHONY : chr.c.i + +chr.s: chr.c.s + +.PHONY : chr.s + +# target to generate assembly for a file +chr.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/chr.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/chr.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/chr.c.s +.PHONY : chr.c.s + +cpu.o: cpu.c.o + +.PHONY : cpu.o + +# target to build an object file +cpu.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/cpu.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/cpu.c.o + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/cpu.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/cpu.c.o + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/cpu.c.o +.PHONY : cpu.c.o + +cpu.i: cpu.c.i + +.PHONY : cpu.i + +# target to preprocess a source file +cpu.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/cpu.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/cpu.c.i + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/cpu.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/cpu.c.i + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/cpu.c.i +.PHONY : cpu.c.i + +cpu.s: cpu.c.s + +.PHONY : cpu.s + +# target to generate assembly for a file +cpu.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/cpu.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/cpu.c.s + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/cpu.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/cpu.c.s + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/cpu.c.s +.PHONY : cpu.c.s + +cpu_bench.o: cpu_bench.c.o + +.PHONY : cpu_bench.o + +# target to build an object file +cpu_bench.c.o: + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/cpu_bench.c.o +.PHONY : cpu_bench.c.o + +cpu_bench.i: cpu_bench.c.i + +.PHONY : cpu_bench.i + +# target to preprocess a source file +cpu_bench.c.i: + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/cpu_bench.c.i +.PHONY : cpu_bench.c.i + +cpu_bench.s: cpu_bench.c.s + +.PHONY : cpu_bench.s + +# target to generate assembly for a file +cpu_bench.c.s: + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/cpu_bench.c.s +.PHONY : cpu_bench.c.s + +cpu_test.o: cpu_test.c.o + +.PHONY : cpu_test.o + +# target to build an object file +cpu_test.c.o: + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/cpu_test.c.o +.PHONY : cpu_test.c.o + +cpu_test.i: cpu_test.c.i + +.PHONY : cpu_test.i + +# target to preprocess a source file +cpu_test.c.i: + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/cpu_test.c.i +.PHONY : cpu_test.c.i + +cpu_test.s: cpu_test.c.s + +.PHONY : cpu_test.s + +# target to generate assembly for a file +cpu_test.c.s: + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/cpu_test.c.s +.PHONY : cpu_test.c.s + +dbg.o: dbg.c.o + +.PHONY : dbg.o + +# target to build an object file +dbg.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/dbg.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/dbg.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/dbg.c.o +.PHONY : dbg.c.o + +dbg.i: dbg.c.i + +.PHONY : dbg.i + +# target to preprocess a source file +dbg.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/dbg.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/dbg.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/dbg.c.i +.PHONY : dbg.c.i + +dbg.s: dbg.c.s + +.PHONY : dbg.s + +# target to generate assembly for a file +dbg.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/dbg.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/dbg.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/dbg.c.s +.PHONY : dbg.c.s + +dsk.o: dsk.c.o + +.PHONY : dsk.o + +# target to build an object file +dsk.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/dsk.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/dsk.c.o +.PHONY : dsk.c.o + +dsk.i: dsk.c.i + +.PHONY : dsk.i + +# target to preprocess a source file +dsk.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/dsk.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/dsk.c.i +.PHONY : dsk.c.i + +dsk.s: dsk.c.s + +.PHONY : dsk.s + +# target to generate assembly for a file +dsk.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/dsk.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/dsk.c.s +.PHONY : dsk.c.s + +ewm.o: ewm.c.o + +.PHONY : ewm.o + +# target to build an object file +ewm.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/ewm.c.o +.PHONY : ewm.c.o + +ewm.i: ewm.c.i + +.PHONY : ewm.i + +# target to preprocess a source file +ewm.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/ewm.c.i +.PHONY : ewm.c.i + +ewm.s: ewm.c.s + +.PHONY : ewm.s + +# target to generate assembly for a file +ewm.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/ewm.c.s +.PHONY : ewm.c.s + +fmt.o: fmt.c.o + +.PHONY : fmt.o + +# target to build an object file +fmt.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/fmt.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/fmt.c.o + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/fmt.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/fmt.c.o + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/fmt.c.o +.PHONY : fmt.c.o + +fmt.i: fmt.c.i + +.PHONY : fmt.i + +# target to preprocess a source file +fmt.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/fmt.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/fmt.c.i + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/fmt.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/fmt.c.i + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/fmt.c.i +.PHONY : fmt.c.i + +fmt.s: fmt.c.s + +.PHONY : fmt.s + +# target to generate assembly for a file +fmt.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/fmt.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/fmt.c.s + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/fmt.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/fmt.c.s + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/fmt.c.s +.PHONY : fmt.c.s + +ins.o: ins.c.o + +.PHONY : ins.o + +# target to build an object file +ins.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/ins.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/ins.c.o + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/ins.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/ins.c.o + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/ins.c.o +.PHONY : ins.c.o + +ins.i: ins.c.i + +.PHONY : ins.i + +# target to preprocess a source file +ins.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/ins.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/ins.c.i + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/ins.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/ins.c.i + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/ins.c.i +.PHONY : ins.c.i + +ins.s: ins.c.s + +.PHONY : ins.s + +# target to generate assembly for a file +ins.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/ins.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/ins.c.s + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/ins.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/ins.c.s + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/ins.c.s +.PHONY : ins.c.s + +mem.o: mem.c.o + +.PHONY : mem.o + +# target to build an object file +mem.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/mem.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/mem.c.o + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/mem.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/mem.c.o + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/mem.c.o +.PHONY : mem.c.o + +mem.i: mem.c.i + +.PHONY : mem.i + +# target to preprocess a source file +mem.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/mem.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/mem.c.i + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/mem.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/mem.c.i + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/mem.c.i +.PHONY : mem.c.i + +mem.s: mem.c.s + +.PHONY : mem.s + +# target to generate assembly for a file +mem.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/mem.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/mem.c.s + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/mem.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/mem.c.s + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/mem.c.s +.PHONY : mem.c.s + +one.o: one.c.o + +.PHONY : one.o + +# target to build an object file +one.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/one.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/one.c.o +.PHONY : one.c.o + +one.i: one.c.i + +.PHONY : one.i + +# target to preprocess a source file +one.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/one.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/one.c.i +.PHONY : one.c.i + +one.s: one.c.s + +.PHONY : one.s + +# target to generate assembly for a file +one.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/one.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/one.c.s +.PHONY : one.c.s + +pia.o: pia.c.o + +.PHONY : pia.o + +# target to build an object file +pia.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/pia.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/pia.c.o +.PHONY : pia.c.o + +pia.i: pia.c.i + +.PHONY : pia.i + +# target to preprocess a source file +pia.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/pia.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/pia.c.i +.PHONY : pia.c.i + +pia.s: pia.c.s + +.PHONY : pia.s + +# target to generate assembly for a file +pia.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/pia.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/pia.c.s +.PHONY : pia.c.s + +scr.o: scr.c.o + +.PHONY : scr.o + +# target to build an object file +scr.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/scr.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/scr.c.o +.PHONY : scr.c.o + +scr.i: scr.c.i + +.PHONY : scr.i + +# target to preprocess a source file +scr.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/scr.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/scr.c.i +.PHONY : scr.c.i + +scr.s: scr.c.s + +.PHONY : scr.s + +# target to generate assembly for a file +scr.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/scr.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/scr.c.s +.PHONY : scr.c.s + +scr_test.o: scr_test.c.o + +.PHONY : scr_test.o + +# target to build an object file +scr_test.c.o: + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/scr_test.c.o +.PHONY : scr_test.c.o + +scr_test.i: scr_test.c.i + +.PHONY : scr_test.i + +# target to preprocess a source file +scr_test.c.i: + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/scr_test.c.i +.PHONY : scr_test.c.i + +scr_test.s: scr_test.c.s + +.PHONY : scr_test.s + +# target to generate assembly for a file +scr_test.c.s: + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/scr_test.c.s +.PHONY : scr_test.c.s + +sdl.o: sdl.c.o + +.PHONY : sdl.o + +# target to build an object file +sdl.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/sdl.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/sdl.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/sdl.c.o +.PHONY : sdl.c.o + +sdl.i: sdl.c.i + +.PHONY : sdl.i + +# target to preprocess a source file +sdl.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/sdl.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/sdl.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/sdl.c.i +.PHONY : sdl.c.i + +sdl.s: sdl.c.s + +.PHONY : sdl.s + +# target to generate assembly for a file +sdl.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/sdl.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/sdl.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/sdl.c.s +.PHONY : sdl.c.s + +tty.o: tty.c.o + +.PHONY : tty.o + +# target to build an object file +tty.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/tty.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/tty.c.o +.PHONY : tty.c.o + +tty.i: tty.c.i + +.PHONY : tty.i + +# target to preprocess a source file +tty.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/tty.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/tty.c.i +.PHONY : tty.c.i + +tty.s: tty.c.s + +.PHONY : tty.s + +# target to generate assembly for a file +tty.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/tty.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/tty.c.s +.PHONY : tty.c.s + +tty_test.o: tty_test.c.o + +.PHONY : tty_test.o + +# target to build an object file +tty_test.c.o: + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/tty_test.c.o +.PHONY : tty_test.c.o + +tty_test.i: tty_test.c.i + +.PHONY : tty_test.i + +# target to preprocess a source file +tty_test.c.i: + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/tty_test.c.i +.PHONY : tty_test.c.i + +tty_test.s: tty_test.c.s + +.PHONY : tty_test.s + +# target to generate assembly for a file +tty_test.c.s: + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/tty_test.c.s +.PHONY : tty_test.c.s + +two.o: two.c.o + +.PHONY : two.o + +# target to build an object file +two.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/two.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/two.c.o +.PHONY : two.c.o + +two.i: two.c.i + +.PHONY : two.i + +# target to preprocess a source file +two.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/two.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/two.c.i +.PHONY : two.c.i + +two.s: two.c.s + +.PHONY : two.s + +# target to generate assembly for a file +two.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/two.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/two.c.s +.PHONY : two.c.s + +utl.o: utl.c.o + +.PHONY : utl.o + +# target to build an object file +utl.c.o: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/utl.c.o + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/utl.c.o + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/utl.c.o + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/utl.c.o + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/utl.c.o +.PHONY : utl.c.o + +utl.i: utl.c.i + +.PHONY : utl.i + +# target to preprocess a source file +utl.c.i: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/utl.c.i + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/utl.c.i + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/utl.c.i + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/utl.c.i + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/utl.c.i +.PHONY : utl.c.i + +utl.s: utl.c.s + +.PHONY : utl.s -$(EWM_EXECUTABLE): $(EWM_OBJECTS) - $(CC) $(LDFLAGS) $(EWM_OBJECTS) $(EWM_LIBS) -o $@ +# target to generate assembly for a file +utl.c.s: + $(MAKE) -f CMakeFiles/ewm.dir/build.make CMakeFiles/ewm.dir/utl.c.s + $(MAKE) -f CMakeFiles/scr_test.dir/build.make CMakeFiles/scr_test.dir/utl.c.s + $(MAKE) -f CMakeFiles/cpu_bench.dir/build.make CMakeFiles/cpu_bench.dir/utl.c.s + $(MAKE) -f CMakeFiles/tty_test.dir/build.make CMakeFiles/tty_test.dir/utl.c.s + $(MAKE) -f CMakeFiles/cpu_test.dir/build.make CMakeFiles/cpu_test.dir/utl.c.s +.PHONY : utl.c.s -$(CPU_TEST_EXECUTABLE): $(CPU_TEST_OBJECTS) - $(CC) $(LDFLAGS) $(CPU_TEST_OBJECTS) $(CPU_TEST_LIBS) -o $@ +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... rebuild_cache" + @echo "... edit_cache" + @echo "... ewm" + @echo "... scr_test" + @echo "... cpu_bench" + @echo "... tty_test" + @echo "... cpu_test" + @echo "... alc.o" + @echo "... alc.i" + @echo "... alc.s" + @echo "... boo.o" + @echo "... boo.i" + @echo "... boo.s" + @echo "... chr.o" + @echo "... chr.i" + @echo "... chr.s" + @echo "... cpu.o" + @echo "... cpu.i" + @echo "... cpu.s" + @echo "... cpu_bench.o" + @echo "... cpu_bench.i" + @echo "... cpu_bench.s" + @echo "... cpu_test.o" + @echo "... cpu_test.i" + @echo "... cpu_test.s" + @echo "... dbg.o" + @echo "... dbg.i" + @echo "... dbg.s" + @echo "... dsk.o" + @echo "... dsk.i" + @echo "... dsk.s" + @echo "... ewm.o" + @echo "... ewm.i" + @echo "... ewm.s" + @echo "... fmt.o" + @echo "... fmt.i" + @echo "... fmt.s" + @echo "... ins.o" + @echo "... ins.i" + @echo "... ins.s" + @echo "... mem.o" + @echo "... mem.i" + @echo "... mem.s" + @echo "... one.o" + @echo "... one.i" + @echo "... one.s" + @echo "... pia.o" + @echo "... pia.i" + @echo "... pia.s" + @echo "... scr.o" + @echo "... scr.i" + @echo "... scr.s" + @echo "... scr_test.o" + @echo "... scr_test.i" + @echo "... scr_test.s" + @echo "... sdl.o" + @echo "... sdl.i" + @echo "... sdl.s" + @echo "... tty.o" + @echo "... tty.i" + @echo "... tty.s" + @echo "... tty_test.o" + @echo "... tty_test.i" + @echo "... tty_test.s" + @echo "... two.o" + @echo "... two.i" + @echo "... two.s" + @echo "... utl.o" + @echo "... utl.i" + @echo "... utl.s" +.PHONY : help -$(SCR_TEST_EXECUTABLE): $(SCR_TEST_OBJECTS) - $(CC) $(LDFLAGS) $(SCR_TEST_OBJECTS) $(SCR_TEST_LIBS) -o $@ -$(TTY_TEST_EXECUTABLE): $(TTY_TEST_OBJECTS) - $(CC) $(LDFLAGS) $(TTY_TEST_OBJECTS) $(TTY_TEST_LIBS) -o $@ -$(CPU_BENCH): $(CPU_BENCH_OBJECTS) - $(CC) $(LDFLAGS) $(CPU_BENCH_OBJECTS) $(CPU_BENCH_LIBS) -o $@ +#============================================================================= +# Special targets to cleanup operation of make. -$(MEM_BENCH): $(MEM_BENCH_OBJECTS) - $(CC) $(LDFLAGS) $(MEM_BENCH_OBJECTS) $(MEM_BENCH_LIBS) -o $@ +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system -.c.o: - $(CC) $(CFLAGS) $< -c -o $@ diff --git a/src/dbg.c b/src/dbg.c new file mode 100644 index 0000000..29899f5 --- /dev/null +++ b/src/dbg.c @@ -0,0 +1,24 @@ +// The MIT License (MIT) +// +// Copyright (c) 2015 Stefan Arentz - http://github.com/st3fan/ewm +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include "dbg.h" + diff --git a/src/dbg.h b/src/dbg.h new file mode 100644 index 0000000..4483300 --- /dev/null +++ b/src/dbg.h @@ -0,0 +1,26 @@ +// The MIT License (MIT) +// +// Copyright (c) 2015 Stefan Arentz - http://github.com/st3fan/ewm +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef EWM_DBG_H +#define EWM_DBG_H + +#endif // EWM_DBG_H diff --git a/src/one.c b/src/one.c index 73a7638..d710bfa 100644 --- a/src/one.c +++ b/src/one.c @@ -31,6 +31,7 @@ #include "mem.h" #include "pia.h" #include "tty.h" +#include "dbg.h" #include "one.h" static void ewm_one_pia_callback(struct ewm_pia_t *pia, void *obj, uint8_t ddr, uint8_t v) { @@ -176,6 +177,7 @@ static bool ewm_one_step_cpu(struct ewm_one_t *one, int cycles) { #define EWM_ONE_OPT_MEMORY (2) #define EWM_ONE_OPT_TRACE (3) #define EWM_ONE_OPT_STRICT (4) +#define EWM_ONE_OPT_DEBUG (5) static struct option one_options[] = { { "help", no_argument, NULL, EWM_ONE_OPT_HELP }, @@ -183,6 +185,7 @@ static struct option one_options[] = { { "memory", required_argument, NULL, EWM_ONE_OPT_MEMORY }, { "trace", optional_argument, NULL, EWM_ONE_OPT_TRACE }, { "strict", no_argument, NULL, EWM_ONE_OPT_STRICT }, + { "debug", no_argument, NULL, EWM_ONE_OPT_DEBUG }, { NULL, 0, NULL, 0 } }; @@ -192,6 +195,7 @@ static void usage() { fprintf(stderr, " --memory add memory region (ram|rom:address:path)\n"); fprintf(stderr, " --trace trace cpu to file\n"); fprintf(stderr, " --strict run emulator in strict mode\n"); + fprintf(stderr, " --debug run debugger on port (default: 6502)\n"); fprintf(stderr, "\n"); fprintf(stderr, "Supported models:\n"); fprintf(stderr, " apple1 Classic Apple 1, 6502, 8KB RAM, Woz Monitor\n"); @@ -204,6 +208,7 @@ int ewm_one_main(int argc, char **argv) { struct ewm_memory_option_t *extra_memory = NULL; char *trace_path = NULL; bool strict = false; + int debug_port = 0; int ch; while ((ch = getopt_long_only(argc, argv, "", one_options, NULL)) != -1) { @@ -240,6 +245,14 @@ int ewm_one_main(int argc, char **argv) { strict = true; break; } + case EWM_ONE_OPT_DEBUG: { + debug_port = optarg ? atoi(optarg) : 6502; + if (debug_port == 0) { + fprintf(stderr, "Invalid debugger port\n"); + exit(1); + } + break; + } default: { usage(); exit(1); From d8bcf49e80fb4c20ca321e5a1e68143c10c8ae74 Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Fri, 1 Jun 2018 19:03:11 -0400 Subject: [PATCH 2/2] Work in progress --- src/CMakeLists.txt | 6 ++-- src/Makefile | 12 ++++---- src/cpu.h | 5 ++++ src/dbg.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/dbg.h | 14 ++++++++++ src/one.c | 14 +++++++++- 6 files changed, 109 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 59d6ffb..4bdd69a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/Makefile b/src/Makefile index de80846..41fce78 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 diff --git a/src/cpu.h b/src/cpu.h index 46cb1a1..78d5c3f 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -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); diff --git a/src/dbg.c b/src/dbg.c index 29899f5..b215217 100644 --- a/src/dbg.c +++ b/src/dbg.c @@ -20,5 +20,73 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include +#include + +#include +#include + +#include + +#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; +} diff --git a/src/dbg.h b/src/dbg.h index 4483300..e0c861f 100644 --- a/src/dbg.h +++ b/src/dbg.h @@ -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 diff --git a/src/one.c b/src/one.c index d710bfa..b2dd09b 100644 --- a/src/one.c +++ b/src/one.c @@ -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();