From 0505b4cfef80e2bc3fad8644c668a56c5a973b63 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Mon, 28 Jul 2025 12:38:56 +0200 Subject: [PATCH] Add working emulator preview build method --- editor/editor.lisp | 2 +- host/Makefile | 16 +++++++++++----- host/src/mainloop.s | 30 +++++++++++++++++++++--------- user-side-compiler/interface.lisp | 22 +++++++++++++++++++--- 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/editor/editor.lisp b/editor/editor.lisp index 3d8a5b1..87a3430 100644 --- a/editor/editor.lisp +++ b/editor/editor.lisp @@ -753,7 +753,7 @@ Additionally ensures correct line numbers on the way, as a bonus." (clear-screen) (redisplay-view (current-view *editor*))) -(defparameter *refresh-asm-functions-p* nil +(defparameter *refresh-asm-functions-p* #+swank t #-swank nil "If non-NIL, reload asm function addresses from listing before every compile.") (defun com-compile-buffer () diff --git a/host/Makefile b/host/Makefile index 2a4e790..d36b5ec 100644 --- a/host/Makefile +++ b/host/Makefile @@ -1,8 +1,12 @@ -BINARY := host.prg +HOST_BINARY := host.prg +PREVIEW_BINARY := preview.prg BUILD_DIR := ./build SRC_DIR := ./src +HOST_PRG := $(BUILD_DIR)/$(HOST_BINARY) +PREVIEW_PRG := $(BUILD_DIR)/$(PREVIEW_BINARY) + SRCS := $(shell find $(SRC_DIR) -name '*.s' -or -name '*.inc') TOPLEVEL := source.s @@ -10,11 +14,13 @@ CL := cl65 CLFLAGS := -u __EXEHDR__ -t c64 -C c64-asm.cfg -l $(BUILD_DIR)/host.lst -Ln $(BUILD_DIR)/host.lbl -$(BUILD_DIR)/$(BINARY): $(SRCS) +$(HOST_PRG): $(SRCS) mkdir -p $(BUILD_DIR) $(CL) -o $@ $(CLFLAGS) $(SRC_DIR)/$(TOPLEVEL) -all: $(BUILD_DIR)/$(BINARY) +$(PREVIEW_PRG): $(SRCS) userprog.bin + $(CL) -o $@ --asm-define EMULATOR_PREVIEW $(CLFLAGS) $(SRC_DIR)/$(TOPLEVEL) -preview: userprog.bin $(SRCS) - $(CL) -o $@ -D EMULATOR_PREVIEW $(CLFLAGS) $(SRC_DIR)/$(TOPLEVEL) +all: $(HOST_PRG) + +preview: $(PREVIEW_PRG) diff --git a/host/src/mainloop.s b/host/src/mainloop.s index 6612125..3e5cc13 100644 --- a/host/src/mainloop.s +++ b/host/src/mainloop.s @@ -1,15 +1,18 @@ ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- .scope mainsetup -;; USERPROG = $C000 -;; .repeat 4, I -;; ldy #$00 -;; : -;; lda batch_userprog+(I*256),Y -;; sta USERPROG+(I*256),Y -;; dey -;; bne :- -;; .endrep +.ifdef EMULATOR_PREVIEW + USERPROG = $C000 +.repeat 4, I + ldy #$00 + : + lda batch_userprog+(I*256),Y + sta USERPROG+(I*256),Y + dey + bne :- +.endrep +.endif +.ifndef EMULATOR_PREVIEW @waitstart: ;; Wait until joystick 2 has been pulled down to start the program dec $d020 lda $dc00 @@ -29,12 +32,19 @@ jsr maybe_download_userprog beq @trying +.endif .endscope lda #$0d sta $d020 .scope mainloop + + ldx #$00 + stx FRAMECOUNT + inx + sta FIRSTTIME + ml: USERPROG = $C000 RASTER = $D012 @@ -44,6 +54,7 @@ ml: ora $01 sta $01 +.ifndef EMULATOR_PREVIEW jsr maybe_download_userprog beq @nochange ldx #$00 @@ -51,6 +62,7 @@ ml: inx sta FIRSTTIME @nochange: +.endif jsr USERPROG ;; Bank out character ROM, I/O in diff --git a/user-side-compiler/interface.lisp b/user-side-compiler/interface.lisp index 145ab1a..4938734 100644 --- a/user-side-compiler/interface.lisp +++ b/user-side-compiler/interface.lisp @@ -221,12 +221,15 @@ (format t "Finished, wrote compiled program to \"~A\".~%" output-filepath)))) -(defun send-data-to-c64 (data) +(defparameter *c64-tty* "/dev/ttyACM0") + +(defun %send-data-to-c64 (data) (declare (type vector data)) - (with-open-file (stream "/dev/ttyACM0" + (with-open-file (stream *c64-tty* :direction :io :element-type '(unsigned-byte 8) - :if-exists :overwrite) + :if-exists :overwrite + :if-does-not-exist :error) (sleep 2.5) (let ((index 0) (length (length data))) @@ -245,6 +248,19 @@ (force-output stream) (format t "~D~%" index))))) +(defun send-data-to-c64 (data) + (declare (type vector data)) + (handler-bind + ((file-error + (lambda (c) + (when (equalp (namestring (file-error-pathname c)) + (namestring *c64-tty*)) + (warn "Failed to open C64 transfer TTY.") + (abort c))))) + (restart-case + (%send-data-to-c64 data) + (abort ())))) + (defun compile-and-send-to-c64 (string) (let ((bytes (compile-string-to-bytes string :print-ir-p t))) (send-data-to-c64 (coerce bytes 'vector))))