Mercurial > vba-clojure
diff clojure/com/aurellem/items.clj @ 106:3a60bb14a64a
better functional assembly interface; removed frame numbers from SaveStates
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 14 Mar 2012 21:37:37 -0500 |
parents | 2f8089eacab9 |
children | ad96e9464d6a |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/items.clj Tue Mar 13 14:40:01 2012 -0500 1.2 +++ b/clojure/com/aurellem/items.clj Wed Mar 14 21:37:37 2012 -0500 1.3 @@ -214,7 +214,8 @@ 1.4 (aset mem index val)) 1.5 (range item-list-start 1.6 (+ item-list-start (count inv-codes))) inv-codes)) 1.7 - (write-memory! mem))) 1.8 + (write-memory! mem) 1.9 + (update-state))) 1.10 1.11 1.12 (defn set-inventory [^SaveState state new-inventory] 1.13 @@ -235,7 +236,11 @@ 1.14 (concat items (inventory state)))) 1.15 ([items] 1.16 (give @current-state items))) 1.17 - 1.18 + 1.19 +(defn clear-inventory 1.20 + ([^SaveState state] 1.21 + (set-inventory state [])) 1.22 + ([] (clear-inventory @current-state))) 1.23 1.24 (def gliched-tms 1.25 [[:TM51 1] 1.26 @@ -264,115 +269,3 @@ 1.27 [:soulbadge 1] 1.28 ]) 1.29 1.30 -(defn run-item-program 1.31 - "This is my first assembly/item program! 1.32 - it just increments BC by one. 1.33 - 1.34 - The code places a 3 'great balls' at the beginning of the 1.35 - inventory, then directly sets the program counter to start 1.36 - executing at the position of the 'great balls' in memory. 1.37 - 1.38 - Since a 'great ball' is represented in memory as 0x03, which 1.39 - corresponts to the opcode which increments BC by one, that is 1.40 - what happens. Then the program counter to the 0x03 quantity entry 1.41 - and BC is incremented again. 1.42 - 1.43 - Obviously, the game crashes more or less immediately after the 1.44 - program counter advances past the 'great balls' into the next items 1.45 - in the inventory, thus I call shutdown! before anything bad happens." 1.46 - [] 1.47 - (set-inventory (read-state 578544) [[:great-ball 3]]) 1.48 - (print-inventory) 1.49 - (println "3 ticks") (tick) (tick) (tick) 1.50 - (println "PC before:" (PC)) 1.51 - (println "BC before:" (BC)) 1.52 - (PC! (inc item-list-start)) 1.53 - (println "PC after setting:" (PC)) 1.54 - (println "data at PC:" (aget (memory) (PC))) 1.55 - (println "one tick") 1.56 - (tick) 1.57 - (println "PC after one tick:" (PC)) 1.58 - (println "BC after one tick:" (BC)) 1.59 - (tick) 1.60 - (println "PC after two ticks:" (PC)) 1.61 - (println "BC after two ticks:" (BC)) 1.62 - 1.63 - (shutdown!)) 1.64 - 1.65 - 1.66 -(defn test-opcodes-1 1.67 - [] 1.68 - (set-inv-mem (read-state 578544) 1.69 - [20 0x02 0x00 0x00 0x02 0x00 0x00 1.70 - 0x00 0x0 0xFF]) 1.71 - (print-inventory) 1.72 - (println "3 ticks") (tick) (tick) (tick) 1.73 - (println "PC before:" (PC)) 1.74 - (println "BC before:" (BC)) 1.75 - (println "AF:" (AF)) 1.76 - (PC! (inc item-list-start)) 1.77 - (BC! (+ 1 item-list-start)) 1.78 - (println "PC after setting:" (PC)) 1.79 - (println "data at PC:" (aget (memory) (PC))) 1.80 - (println "data at " (BC) "(BC):" (aget (memory) (BC))) 1.81 - 1.82 - (println "one tick") 1.83 - (tick) 1.84 - (println "PC after one tick:" (PC)) 1.85 - (println "BC after one tick:" (BC)) 1.86 - (println "data at PC:" (aget (memory) (PC))) 1.87 - (println "data at " (BC) "(BC):" (aget (memory) (BC))) 1.88 - (tick) 1.89 - (AF! 0xFFFF) 1.90 - (println "PC after two ticks:" (PC)) 1.91 - (println "BC after two ticks:" (BC)) 1.92 - (println "data at PC:" (aget (memory) (PC))) 1.93 - (println "data at " (BC) "(BC):" (aget (memory) (BC))) 1.94 - (tick) 1.95 - (println "PC after three ticks:" (PC)) 1.96 - (println "BC after three ticks:" (BC)) 1.97 - (println "data at PC:" (aget (memory) (PC))) 1.98 - (println "data at " (BC) "(BC):" (aget (memory) (BC))) 1.99 - (tick) 1.100 - (println "PC after four ticks:" (PC)) 1.101 - (println "BC after four ticks:" (BC)) 1.102 - (println "data at PC:" (aget (memory) (PC))) 1.103 - (println "data at " (BC) "(BC):" (aget (memory) (BC))) 1.104 - (tick) 1.105 - (println "PC after five ticks:" (PC)) 1.106 - (println "BC after five ticks:" (BC)) 1.107 - (println "data at PC:" (aget (memory) (PC))) 1.108 - (println "data at " (BC) "(BC):" (aget (memory) (BC))) 1.109 - (print-inventory) 1.110 - (shutdown!)) 1.111 - 1.112 - 1.113 - 1.114 -(defn test-opcodes-2 1.115 - [] 1.116 - (set-inv-mem (read-state 578544) 1.117 - [20 0x08 0x1D 0xD3 0x00 0x00 0x00 1.118 - 0x00 0x0 0xFF]) 1.119 - (print-inventory) 1.120 - (println "3 ticks") (tick) (tick) (tick) 1.121 - (println "PC before:" (PC)) 1.122 - (println "SP:" (SP)) 1.123 - (PC! (inc item-list-start)) 1.124 - (println "PC after setting:" (PC)) 1.125 - (println "SP:" (Integer/toBinaryString (SP))) 1.126 - (println "data at PC:" (aget (memory) (PC))) 1.127 - (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D))) 1.128 - (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E))) 1.129 - (println "one tick") 1.130 - (tick) 1.131 - (println "PC after one tick:" (PC)) 1.132 - (println "data at PC:" (aget (memory) (PC))) 1.133 - (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D))) 1.134 - (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E))) 1.135 - (tick) (tick) (tick) 1.136 - (println "PC aftter four tick:" (PC)) 1.137 - (println "data at PC:" (aget (memory) (PC))) 1.138 - (println "data at 0xD31D:" (aget (memory) 0xD31D)) 1.139 - 1.140 - (print-inventory) 1.141 - (shutdown!))