Permalink
Browse files

Changed the SP to start at 0. Fixes #2

  • Loading branch information...
1 parent eb17b6c commit 5dc860033630f75e51444d5a63b6ddd3333c44ed @jjcomer jjcomer committed Apr 10, 2012
Showing with 6 additions and 4 deletions.
  1. +1 −1 src/clj_dcpu16/core.clj
  2. +5 −3 test/clj_dcpu16/core_test.clj
View
2 src/clj_dcpu16/core.clj
@@ -262,6 +262,6 @@
(change-memory :pc pc)
(run!))
([]
- (change-memory :sp 0xFFFF)
+ (change-memory :sp 0x0000)
(while true
(execute (follow-memory :pc)))))
View
8 test/clj_dcpu16/core_test.clj
@@ -3,7 +3,7 @@
clj-dcpu16.core))
(defn- clear-memory []
- (dosync (alter memory (fn [old] {:pc 0x0000 :sp 0xFFFF}))))
+ (dosync (alter memory (fn [old] {:pc 0x0000 :sp 0x0000}))))
(defn- force-memory [address value]
(dosync (alter memory #(assoc % address value))))
@@ -55,10 +55,10 @@
(testing "Push"
(clear-memory)
(change-memory :push 0x1234)
- (is (= 0xFFFE (get-memory :sp)))
+ (is (= 0xFFFF (get-memory :sp)))
(is (= 0x1234 (get-memory :peek)))
(change-memory :push 0x4321)
- (is (= 0xFFFD (get-memory :sp)))
+ (is (= 0xFFFE (get-memory :sp)))
(is (= 0x4321 (get-memory :peek)))))
(testing "Inc memory"
(clear-memory)
@@ -111,10 +111,12 @@
(testing "Peek"
(clear-memory)
(force-memory 0xFFFF 0x1234)
+ (force-memory :sp 0xFFFF)
(is (= [0x1234 0xFFFF] (get-address-and-value 0x19))))
(testing "Push"
(clear-memory)
(force-memory 0xFFFF 0x1234)
+ (force-memory :sp 0xFFFF)
(is (= [0x1234 :push] (get-address-and-value 0x1A))))
(testing "De-reference next word"
(clear-memory)

0 comments on commit 5dc8600

Please sign in to comment.