From c7ef8bf91582203b0548d964db2c45946df63d8f Mon Sep 17 00:00:00 2001
From: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 2 Jan 2020 16:59:38 -0500
Subject: [PATCH] recipes: add "make emul" targets where appropriate

---
 emul/hw/rc2014/Makefile  | 15 ++++++++++++---
 emul/hw/ti/Makefile      | 15 ++++++++++++---
 emul/hw/ti/ti84.c        |  4 ----
 recipes/rc2014/Makefile  |  9 +++++++++
 recipes/rc2014/README.md |  5 +++++
 recipes/ti84/Makefile    |  8 ++++++++
 recipes/ti84/README.md   | 20 +++++---------------
 7 files changed, 51 insertions(+), 25 deletions(-)

diff --git a/emul/hw/rc2014/Makefile b/emul/hw/rc2014/Makefile
index f5f613c..3ba5a7b 100644
--- a/emul/hw/rc2014/Makefile
+++ b/emul/hw/rc2014/Makefile
@@ -1,4 +1,13 @@
-OBJS = acia.o classic.o ../../emul.o ../../libz80/libz80.o
+EXTOBJS = ../../emul.o ../../libz80/libz80.o
+OBJS = acia.o classic.o 
+TARGET = classic
 
-classic: $(OBJS)
-	$(CC) $(OBJS) -o $@
+.PHONY: all
+all: $(TARGET)
+
+$(TARGET): $(OBJS) $(EXTOBJS)
+	$(CC) $(OBJS) $(EXTOBJS) -o $@
+
+.PHONY: clean
+clean:
+	rm -f $(TARGET) $(OBJS)
diff --git a/emul/hw/ti/Makefile b/emul/hw/ti/Makefile
index a5d3186..a909f24 100644
--- a/emul/hw/ti/Makefile
+++ b/emul/hw/ti/Makefile
@@ -1,6 +1,15 @@
-OBJS = ti84.o t6a04.o kbd.o ../../emul.o ../../libz80/libz80.o
+EXTOBJS = ../../emul.o ../../libz80/libz80.o
+OBJS = ti84.o t6a04.o kbd.o 
+TARGET = ti84
 CFLAGS += `pkg-config --cflags xcb`
 
-ti84: $(OBJS)
-	$(CC) `pkg-config --libs xcb` $(OBJS) -o $@
+.PHONY: all
+all: $(TARGET)
 
+$(TARGET): $(OBJS) $(EXTOBJS)
+	$(CC) `pkg-config --libs xcb` $(OBJS) $(EXTOBJS) -o $@
+
+.PHONY: clean
+clean:
+	rm -f $(TARGET) $(OBJS)
+	
diff --git a/emul/hw/ti/ti84.c b/emul/hw/ti/ti84.c
index 79c817f..8f18345 100644
--- a/emul/hw/ti/ti84.c
+++ b/emul/hw/ti/ti84.c
@@ -223,10 +223,6 @@ void draw_pixels()
 
 void event_loop()
 {
-    if (!emul_step()) {
-        // We're done
-        return;
-    }
     while (1) {
         emul_step();
         if (lcd_changed) {
diff --git a/recipes/rc2014/Makefile b/recipes/rc2014/Makefile
index 190d3aa..c5fe97b 100644
--- a/recipes/rc2014/Makefile
+++ b/recipes/rc2014/Makefile
@@ -3,8 +3,17 @@ BASEDIR = ../..
 ZASM = $(BASEDIR)/emul/zasm/zasm
 KERNEL = $(BASEDIR)/kernel
 APPS = $(BASEDIR)/apps
+EMUL = $(BASEDIR)/emul/hw/rc2014/classic
 
 .PHONY: all
 all: $(TARGET)
 $(TARGET): glue.asm
 	$(ZASM) $(KERNEL) $(APPS) < glue.asm > $@
+
+$(EMUL):
+	$(MAKE) -C ${@:%/classic=%}
+
+.PHONY: emul
+emul: $(EMUL) $(TARGET)
+	$(EMUL) $(TARGET)
+	
diff --git a/recipes/rc2014/README.md b/recipes/rc2014/README.md
index 7c88552..3c45e8a 100644
--- a/recipes/rc2014/README.md
+++ b/recipes/rc2014/README.md
@@ -81,6 +81,11 @@ We only have the shell to build, so it's rather straightforward:
 
 Running `make` will also work.
 
+### Emulate
+
+The Collapse OS project includes a RC2014 emulator suitable for this image.
+You can invoke it with `make emul`. See `emul/hw/rc2014/README.md` for details.
+
 ### Write to the ROM
 
 Plug your romwrite atmega328 to your computer and identify the tty bound to it.
diff --git a/recipes/ti84/Makefile b/recipes/ti84/Makefile
index 0bafac6..5808a62 100644
--- a/recipes/ti84/Makefile
+++ b/recipes/ti84/Makefile
@@ -3,6 +3,7 @@ BASEDIR = ../..
 ZASM = $(BASEDIR)/emul/zasm/zasm
 KERNEL = $(BASEDIR)/kernel
 APPS = $(BASEDIR)/apps
+EMUL = $(BASEDIR)/emul/hw/ti/ti84
 MKTIUPGRADE = mktiupgrade
 
 .PHONY: all
@@ -10,6 +11,13 @@ all: $(TARGET)
 $(TARGET): glue.asm
 	$(ZASM) $(KERNEL) $(APPS) < glue.asm > $@
 
+$(EMUL):
+	$(MAKE) -C ${@:%/ti84=%}
+
+.PHONY: emul
+emul: $(EMUL) $(TARGET)
+	$(EMUL) $(TARGET)
+	
 os.rom: $(TARGET)
 	cp $(TARGET) $@
 	truncate -s 1M $@
diff --git a/recipes/ti84/README.md b/recipes/ti84/README.md
index a445db7..1f7ddb0 100644
--- a/recipes/ti84/README.md
+++ b/recipes/ti84/README.md
@@ -22,27 +22,19 @@ screen as output and its builtin keyboard as input.
 * A USB cable
 * [tilp][tilp]
 * [mktiupgrade][mktiupgrade]
-* Optional: [z80e][z80e] to emulate
 
 ## Build the ROM
 
 Running `make` will result in `os.rom` being created.
 
-## Emulate through z80e
+## Emulate
 
-[KnightOS][knightos] has a handy emulator, [z80e][z80e] for TI calculators and
-it also emulates the screen. It is recommended to use this tool.
-
-Once z80e is installed (build it with SDL support) and `os.rom` is created,
-you can run the emulator with:
-
-    z80e-sdl -d TI84p --no-rom-check os.rom
+Collapse OS has a builtin TI-84+ emulator using XCB for display in `emul/hw/ti`.
+You can invoke it with `make emul`.
 
 You will start with a blank screen, it's normal, you haven't pressed the "ON"
-key yet. This key is mapped to F12 in the emulator. Once you press it, the
-Collapse OS prompt will appear.
-
-See z80e's `KEYBINDINGS.md` file for details.
+key yet. This key is mapped to tilde (~) in the emulator. Once you press it, the
+Collapse OS prompt will appear. See `emul/hw/ti/README.md` for details.
 
 ## Upload to the calculator
 
@@ -102,7 +94,5 @@ Keys that aren't a digit, a letter, a symbol that is part of 7-bit ASCII or one
 of the two mode key have no effect.
 
 [zasm]: ../../tools/emul
-[knightos]: https://knightos.org/
-[z80e]: https://github.com/KnightOS/z80e
 [mktiupgrade]: https://github.com/KnightOS/mktiupgrade
 [tilp]: http://lpg.ticalc.org/prj_tilp/