Index: .cproject
===================================================================
--- .cproject	(revision 33265158e047e6810048332a933f95a3ba419f1d)
+++ .cproject	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -29,4 +29,5 @@
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/buchla-emu/emu}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/buchla-emu/build}&quot;"/>
+									<listOptionValue builtIn="false" value="/opt/sdl2/include"/>
 								</option>
 								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1138147073" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
@@ -46,5 +47,5 @@
 					<sourceEntries>
 						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="build"/>
-						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="cpu"/>
+						<entry excluding="m68k_in.c" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="cpu"/>
 						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="emu"/>
 					</sourceEntries>
Index: Makefile
===================================================================
--- Makefile	(revision 33265158e047e6810048332a933f95a3ba419f1d)
+++ Makefile	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -1,3 +1,7 @@
-FLAGS :=		-std=c99 -O2 -gdwarf-4
+SDL2 :=			/opt/sdl2
+SDL2_INC :=		$(SDL2)/include
+SDL2_LIB :=		$(SDL2)/lib
+
+FLAGS :=		-std=c99 -pthread -O2 -gdwarf-4
 
 FLAGS_CPU :=	$(FLAGS) -I cpu -I build
@@ -8,5 +12,5 @@
 				-Wpedantic -Wconversion -Wsign-conversion -Wshadow \
 				-Wstrict-prototypes -Wmissing-declarations -Wredundant-decls \
-				-I cpu -I emu -I build
+				-I cpu -I emu -I build -I $(SDL2_INC)
 
 FLAGS_LNK :=	$(FLAGS) -Wall -Wextra
@@ -45,5 +49,5 @@
 				gcc $(FLAGS_CPU) -c -o $@ $<
 
-EMU_C :=		main.c
+EMU_C :=		main.c cpu.c sdl.c
 EMU_O :=		$(EMU_C:.c=.o)
 EMU_OP :=		$(EMU_O:%=build/%)
@@ -53,9 +57,14 @@
 
 buchla:			$(CPU_OP) $(GEN_OP)	$(EMU_OP)
-				gcc $(FLAGS_LNK) -o buchla $(CPU_OP) $(GEN_OP) $(EMU_OP)
+				gcc $(FLAGS_LNK) -o buchla \
+				$(CPU_OP) $(GEN_OP) $(EMU_OP) \
+				$(SDL2_LIB)/libSDL2.a -ldl -lm
+
+run:			buchla
+				./buchla
 
 val:			buchla
 				valgrind --leak-resolution=high --track-fds=yes --leak-check=full \
-				--show-reachable=yes ./buchla
+				--show-reachable=yes --suppressions=buchla.supp ./buchla
 
 clean:
Index: buchla.supp
===================================================================
--- buchla.supp	(revision ff8d800308997707a2040c22e309bbd0585ee959)
+++ buchla.supp	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -0,0 +1,28 @@
+{
+	_dl_open
+	Memcheck:Leak
+	...
+	fun:_dl_open
+}
+
+{
+	_dl_close
+	Memcheck:Leak
+	...
+	fun:_dl_close
+}
+
+{
+	_XOpenLC
+	Memcheck:Leak
+	...
+	fun:_XOpenLC
+}
+
+{
+	SDL_Init_REAL
+	Memcheck:Leak
+	...
+	fun:SDL_Init_REAL
+}
+
Index: emu/all.h
===================================================================
--- emu/all.h	(revision ff8d800308997707a2040c22e309bbd0585ee959)
+++ emu/all.h	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -0,0 +1,25 @@
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <m68k.h>
+
+#include <SDL2/SDL.h>
+
+#define inf(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__);
+#define err(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__);
+
+#define fail(...) { \
+	SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); \
+	exit(1); \
+}
+
+extern bool cpu_verbose;
+extern bool sdl_verbose;
+
+extern void sdl_init(void);
+extern void sdl_quit(void);
+
+extern void cpu_loop(void);
Index: emu/cpu.c
===================================================================
--- emu/cpu.c	(revision ff8d800308997707a2040c22e309bbd0585ee959)
+++ emu/cpu.c	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -0,0 +1,101 @@
+#include <all.h>
+
+#define ver(...) { \
+	if (cpu_verbose) { \
+		SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); \
+	} \
+}
+
+#define CYCLES 10
+
+#define RESET_PC 0x100000
+#define RESET_SP 0x100000
+
+bool cpu_verbose = false;
+static bool reset = true;
+
+uint32_t m68k_read_disassembler_8(uint32_t addr)
+{
+	ver("mem rd 0x%08x:8", addr);
+	return 0;
+}
+
+uint32_t m68k_read_disassembler_16(uint32_t addr)
+{
+	ver("mem rd 0x%08x:16", addr);
+	return 0;
+}
+
+uint32_t m68k_read_disassembler_32(uint32_t addr)
+{
+	ver("mem rd 0x%08x:32", addr);
+	return 0;
+}
+
+uint32_t m68k_read_memory_8(uint32_t addr)
+{
+	ver("mem rd 0x%08x:8", addr);
+	return 0;
+}
+
+uint32_t m68k_read_memory_16(uint32_t addr)
+{
+	ver("mem rd 0x%08x:16", addr);
+
+	if (addr < 0x100000) {
+	}
+
+	if (addr < 0x110000) {
+		return 0x60fe;
+	}
+
+	return 0;
+}
+
+uint32_t m68k_read_memory_32(uint32_t addr)
+{
+	ver("mem rd 0x%08x:32", addr);
+
+	if (reset) {
+		if (addr == 0) {
+			return RESET_SP;
+		}
+
+		if (addr == 4) {
+			reset = false;
+			return RESET_PC;
+		}
+
+		fail("invalid reset sequence");
+	}
+
+	return 0;
+}
+
+void m68k_write_memory_8(uint32_t addr, uint32_t val)
+{
+	ver("mem wr 0x%08x:8 0x%02x", addr, val);
+}
+
+void m68k_write_memory_16(uint32_t addr, uint32_t val)
+{
+	ver("mem wr 0x%08x:16 0x%04x", addr, val);
+}
+
+void m68k_write_memory_32(uint32_t addr, uint32_t val)
+{
+	ver("mem wr 0x%08x:32 0x%08x", addr, val);
+}
+
+void cpu_loop(void)
+{
+	ver("entering CPU loop");
+
+	m68k_init();
+	m68k_set_cpu_type(M68K_CPU_TYPE_68000);
+	m68k_pulse_reset();
+
+	for (int32_t i = 0; i < 5; ++i) {
+		m68k_execute(CYCLES);
+	}
+}
Index: emu/main.c
===================================================================
--- emu/main.c	(revision 33265158e047e6810048332a933f95a3ba419f1d)
+++ emu/main.c	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -1,61 +1,3 @@
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-
-#include <m68k.h>
-
-uint32_t m68k_read_disassembler_8(uint32_t addr)
-{
-	(void)addr;
-	return 0;
-}
-
-uint32_t m68k_read_disassembler_16(uint32_t addr)
-{
-	(void)addr;
-	return 0;
-}
-
-uint32_t m68k_read_disassembler_32(uint32_t addr)
-{
-	(void)addr;
-	return 0;
-}
-
-uint32_t m68k_read_memory_8(uint32_t addr)
-{
-	(void)addr;
-	return 0;
-}
-
-uint32_t m68k_read_memory_16(uint32_t addr)
-{
-	(void)addr;
-	return 0;
-}
-
-uint32_t m68k_read_memory_32(uint32_t addr)
-{
-	(void)addr;
-	return 0;
-}
-
-void m68k_write_memory_8(uint32_t addr, uint32_t val)
-{
-	(void)addr;
-	(void)val;
-}
-
-void m68k_write_memory_16(uint32_t addr, uint32_t val)
-{
-	(void)addr;
-	(void)val;
-}
-
-void m68k_write_memory_32(uint32_t addr, uint32_t val)
-{
-	(void)addr;
-	(void)val;
-}
+#include <all.h>
 
 int32_t main(int32_t argc, char *argv[])
@@ -63,5 +5,11 @@
 	(void)argc;
 	(void)argv;
+
+	sdl_init();
+
+	cpu_verbose = true;
+	cpu_loop();
+
+	sdl_quit();
 	return 0;
 }
-
Index: emu/sdl.c
===================================================================
--- emu/sdl.c	(revision ff8d800308997707a2040c22e309bbd0585ee959)
+++ emu/sdl.c	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -0,0 +1,24 @@
+#include <all.h>
+
+bool sdl_verbose = false;
+
+#define ver(...) { \
+	if (sdl_verbose) { \
+		SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__); \
+	} \
+}
+
+void sdl_init(void)
+{
+	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+		fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
+		exit(1);
+	}
+
+	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE);
+}
+
+void sdl_quit(void)
+{
+	SDL_Quit();
+}
Index: setup
===================================================================
--- setup	(revision ff8d800308997707a2040c22e309bbd0585ee959)
+++ setup	(revision ff8d800308997707a2040c22e309bbd0585ee959)
@@ -0,0 +1,1 @@
+export PATH="/opt/cross-m68k/bin:${PATH}"
