From 57a47e6ba36d50e6bb0342829d9e42f57ee97298 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Thu, 10 Jul 2025 18:10:35 +0200 Subject: [PATCH] Add basic unfinished C64 upload function to USC --- wip-duuqnd/user-side-compiler/interface.lisp | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wip-duuqnd/user-side-compiler/interface.lisp b/wip-duuqnd/user-side-compiler/interface.lisp index 6e42aab..90d0553 100644 --- a/wip-duuqnd/user-side-compiler/interface.lisp +++ b/wip-duuqnd/user-side-compiler/interface.lisp @@ -220,3 +220,32 @@ :do (write-byte byte stream))) (format t "Finished, wrote compiled program to \"~A\".~%" output-filepath)))) + +(defun send-data-to-c64 (data) + (with-open-file (stream "/dev/ttyACM0" + :direction :io + :element-type '(unsigned-byte 8) + :if-exists :overwrite) + (sleep 2.5) + (let ((index 0) + (length (length data))) + (write-byte (ldb (byte 8 0) length) stream) + (write-byte (ldb (byte 8 8) length) stream) + (force-output stream) + (loop :while (< index length) + :for amount := (min 16 (- (length data) index)) + :do (format t "~D " amount) + (read-byte stream) + (write-byte amount stream) + (format t "~D " index) + (loop :for byte + :across (subseq data index (incf index amount)) + :do (write-byte byte stream)) + (force-output stream) + (format t "~D~%" index))))) + +(defun compile-and-send-to-c64 (string) + (let ((bytes (compile-string-to-bytes string :print-ir-p t))) + (handler-case + (send-data-to-c64 (coerce bytes 'vector)) + (error (c) (abort c)))))