summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bytepusher.scm27
1 files changed, 19 insertions, 8 deletions
diff --git a/bytepusher.scm b/bytepusher.scm
index f28b961..9c8b96b 100644
--- a/bytepusher.scm
+++ b/bytepusher.scm
@@ -1,6 +1,7 @@
(define-module (bytepusher)
#:use-module (rnrs bytevectors)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-60)
#:use-module (ice-9 binary-ports)
#:use-module (sdl2)
#:use-module (sdl2 render)
@@ -39,13 +40,14 @@
;; memory ----
(define (get-pc)
- (+ (bytevector-u16-ref memory 3 (endianness big))
- (ash (bytevector-u8-ref memory 2) 16)))
+ (+ (ash (get-byte 4) 0)
+ (ash (get-byte 3) 8)
+ (ash (get-byte 2) 16)))
(define (set-pc! value)
- (let ((pc value))
- (bytevector-u16-set! memory 2 (ash pc -8) (endianness big))
- (bytevector-u8-set! memory 4 (ash pc -16))))
+ (set-byte! 4 (ash value 0))
+ (set-byte! 3 (ash value -8))
+ (set-byte! 2 (ash value -16)))
(define (get-addr pos)
(+ (bytevector-u16-ref memory (+ 1 pos) (endianness big))
@@ -61,7 +63,7 @@
(bytevector-u8-ref memory n))
(define (set-byte! n v)
- (bytevector-u8-set! memory n v))
+ (bytevector-u8-set! memory n (logand v #xFF)))
;; ---- memory
@@ -152,11 +154,20 @@
(bytevector-copy! program 0 memory 0 (bytevector-length program))))))
(define (execute! instruction-addr)
+ (call-with-values
+ (lambda () (load-instruction instruction-addr))
+ (lambda (a b c)
+ (set-byte! b (get-byte a))
+ (set-pc! c))))
+
+(define (load-instruction instruction-addr)
(let ((a (get-addr (+ 0 instruction-addr)))
(b (get-addr (+ 3 instruction-addr)))
(c (get-addr (+ 6 instruction-addr))))
- (set-byte! b (get-byte a))
- (set-pc! c)))
+ #;(display (string-append "a: " (number->string a 16) " "))
+ #;(display (string-append "b: " (number->string b 16) " "))
+ #;(display (string-append "c: " (number->string c 16) "\n"))
+ (values a b c)))
(define (loop-frame!)
(let loop ((count 65536))