From 5f30e6190708905cab3cb25bde3f8fbfbf06644d Mon Sep 17 00:00:00 2001 From: d_m Date: Mon, 20 Jan 2025 01:33:58 -0500 Subject: [PATCH] use uxncli debug format --- vm.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/vm.scm b/vm.scm index 2bd5ec9..cb7e4ea 100644 --- a/vm.scm +++ b/vm.scm @@ -196,11 +196,29 @@ (define (_deo byte port) (vector-set! dev port (u8 byte)) (cond - ((= 14 port) (display wst) (display "\n") (display rst) (display "\n")) + ((= 14 port) (debug)) ((= 24 port) (write-char (integer->char byte) (current-output-port))) ((= 25 port) (write-char (integer->char byte) (current-error-port))) (* '()))) +(define (debug) + (debug-stack "WST" wst) (debug-stack "RST" rst)) + +(define (debug-stack label st) + (display label) + (debug-cells (cdr st) (u8 (- (car st) 8)) (car st) (current-output-port))) + +(define (debug-cells cells i limit port) + (display (if (= i 0) "|" " ") port) + (if (= i limit) (display "<\n") + (begin + (emit-u8 (vector-ref cells i) port) + (debug-cells cells (u8 (+ i 1)) limit port)))) + +(define (emit-u8 n port) + (display (number->string (quotient n 16) 16) port) + (display (number->string (modulo n 16) 16) port)) + ; SFT base instruction implementation (define (sft-impl k) (let* ((n (_pop1))