summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-07-19 14:20:17 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-07-19 14:20:17 +0200
commit647ca0c2fad0d4749792698ca09adfa9c6d1b23b (patch)
treef21a5b26f52d0b37295c7d4525c08d1b0290b569
parent9c282b20f2c6fc3a31992d426f3f7f7d2c023716 (diff)
Fix instructions:
The program counter must be reset after each frame, and it's not supposed to be set after each instruction execution. We were setting the PC from the C value of the instructions but that's not what we need to do. The C value is only used for a jump and then, in the next frame the PC must be reloaded from its value in the memory. The only way to change the PC in the program is using it in the B argument of the instructions, which would overwrite it with an arbitrary value (stored in A).
-rw-r--r--bytepusher.scm11
1 files changed, 7 insertions, 4 deletions
diff --git a/bytepusher.scm b/bytepusher.scm
index e822073..54c7e28 100644
--- a/bytepusher.scm
+++ b/bytepusher.scm
@@ -173,7 +173,7 @@
(lambda () (load-instruction instruction-addr))
(lambda (a b c)
(set-byte! b (get-byte a))
- (set-pc! c))))
+ c)))
(define (load-instruction instruction-addr)
(let ((a (get-addr (+ 0 instruction-addr)))
@@ -185,9 +185,11 @@
(values a b c)))
(define (loop-frame!)
- (let loop ((count 65535))
- (execute! (get-pc))
- (unless (= count 0) (loop (- count 1)))))
+ (let loop ((count 65536)
+ (nextpc (get-pc)))
+ (unless (= count 0)
+ (loop (- count 1)
+ (execute! nextpc)))))
(define (handle-key! action! key)
(let ((index (hashq-ref key-ids key)))
@@ -240,6 +242,7 @@
(call-with-renderer (make-renderer w '(accelerated)) loop!)))
(sdl-quit))
+(main)
;; ---- main operation