summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-07-08 22:22:42 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-07-08 22:22:42 +0200
commitfa0fa9271012ae487288ecee206c68cf4d3df9bf (patch)
tree364a8a29aeb96066d2c0cd6d9266ce88a76527ec
parente4182192683e5101723ff63b6f32cea6cfe5122e (diff)
Rewrite access in terms of get-byte
- This changes happens to slow down the whole system a lot. Also add a test for the PC.
-rw-r--r--bytepusher.scm22
1 files changed, 16 insertions, 6 deletions
diff --git a/bytepusher.scm b/bytepusher.scm
index 9c8b96b..7e08e2b 100644
--- a/bytepusher.scm
+++ b/bytepusher.scm
@@ -40,9 +40,7 @@
;; memory ----
(define (get-pc)
- (+ (ash (get-byte 4) 0)
- (ash (get-byte 3) 8)
- (ash (get-byte 2) 16)))
+ (get-addr 2))
(define (set-pc! value)
(set-byte! 4 (ash value 0))
@@ -50,11 +48,12 @@
(set-byte! 2 (ash value -16)))
(define (get-addr pos)
- (+ (bytevector-u16-ref memory (+ 1 pos) (endianness big))
- (ash (bytevector-u8-ref memory pos) 16)))
+ (+ (ash (get-byte (+ 2 pos)) 0)
+ (ash (get-byte (+ 1 pos)) 8)
+ (ash (get-byte pos) 16)))
(define (get-initial-pixel)
- (ash (bytevector-u8-ref memory 5) 16))
+ (ash (get-byte 5) 16))
(define (get-sample)
(bytevector-u16-ref memory 6 (endianness big)))
@@ -204,3 +203,14 @@
(sdl-quit))
;; ---- main operation
+
+
+;; tests ----
+(define (test-pc)
+ (for-each
+ (lambda (addr)
+ (set-pc! addr)
+ (when (not (= (get-pc) addr))
+ (error "Error in set pc")))
+ (iota #x1000000)))
+;; ---- tests