Add working emulator preview build method

This commit is contained in:
John Lorentzson 2025-07-28 12:38:56 +02:00
parent edde967aac
commit 0505b4cfef
4 changed files with 52 additions and 18 deletions

View file

@ -753,7 +753,7 @@ Additionally ensures correct line numbers on the way, as a bonus."
(clear-screen) (clear-screen)
(redisplay-view (current-view *editor*))) (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.") "If non-NIL, reload asm function addresses from listing before every compile.")
(defun com-compile-buffer () (defun com-compile-buffer ()

View file

@ -1,8 +1,12 @@
BINARY := host.prg HOST_BINARY := host.prg
PREVIEW_BINARY := preview.prg
BUILD_DIR := ./build BUILD_DIR := ./build
SRC_DIR := ./src 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') SRCS := $(shell find $(SRC_DIR) -name '*.s' -or -name '*.inc')
TOPLEVEL := source.s 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 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) mkdir -p $(BUILD_DIR)
$(CL) -o $@ $(CLFLAGS) $(SRC_DIR)/$(TOPLEVEL) $(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) all: $(HOST_PRG)
$(CL) -o $@ -D EMULATOR_PREVIEW $(CLFLAGS) $(SRC_DIR)/$(TOPLEVEL)
preview: $(PREVIEW_PRG)

View file

@ -1,15 +1,18 @@
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*- ;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
.scope mainsetup .scope mainsetup
;; USERPROG = $C000 .ifdef EMULATOR_PREVIEW
;; .repeat 4, I USERPROG = $C000
;; ldy #$00 .repeat 4, I
;; : ldy #$00
;; lda batch_userprog+(I*256),Y :
;; sta USERPROG+(I*256),Y lda batch_userprog+(I*256),Y
;; dey sta USERPROG+(I*256),Y
;; bne :- dey
;; .endrep bne :-
.endrep
.endif
.ifndef EMULATOR_PREVIEW
@waitstart: ;; Wait until joystick 2 has been pulled down to start the program @waitstart: ;; Wait until joystick 2 has been pulled down to start the program
dec $d020 dec $d020
lda $dc00 lda $dc00
@ -29,12 +32,19 @@
jsr maybe_download_userprog jsr maybe_download_userprog
beq @trying beq @trying
.endif
.endscope .endscope
lda #$0d lda #$0d
sta $d020 sta $d020
.scope mainloop .scope mainloop
ldx #$00
stx FRAMECOUNT
inx
sta FIRSTTIME
ml: ml:
USERPROG = $C000 USERPROG = $C000
RASTER = $D012 RASTER = $D012
@ -44,6 +54,7 @@ ml:
ora $01 ora $01
sta $01 sta $01
.ifndef EMULATOR_PREVIEW
jsr maybe_download_userprog jsr maybe_download_userprog
beq @nochange beq @nochange
ldx #$00 ldx #$00
@ -51,6 +62,7 @@ ml:
inx inx
sta FIRSTTIME sta FIRSTTIME
@nochange: @nochange:
.endif
jsr USERPROG jsr USERPROG
;; Bank out character ROM, I/O in ;; Bank out character ROM, I/O in

View file

@ -221,12 +221,15 @@
(format t "Finished, wrote compiled program to \"~A\".~%" (format t "Finished, wrote compiled program to \"~A\".~%"
output-filepath)))) output-filepath))))
(defun send-data-to-c64 (data) (defparameter *c64-tty* "/dev/ttyACM0")
(defun %send-data-to-c64 (data)
(declare (type vector data)) (declare (type vector data))
(with-open-file (stream "/dev/ttyACM0" (with-open-file (stream *c64-tty*
:direction :io :direction :io
:element-type '(unsigned-byte 8) :element-type '(unsigned-byte 8)
:if-exists :overwrite) :if-exists :overwrite
:if-does-not-exist :error)
(sleep 2.5) (sleep 2.5)
(let ((index 0) (let ((index 0)
(length (length data))) (length (length data)))
@ -245,6 +248,19 @@
(force-output stream) (force-output stream)
(format t "~D~%" index))))) (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) (defun compile-and-send-to-c64 (string)
(let ((bytes (compile-string-to-bytes string :print-ir-p t))) (let ((bytes (compile-string-to-bytes string :print-ir-p t)))
(send-data-to-c64 (coerce bytes 'vector)))) (send-data-to-c64 (coerce bytes 'vector))))