view clojure/com/aurellem/exp/assembly.clj @ 146:c5914665012d

made function to get the sixth pokemon's full name
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 21:35:43 -0500
parents 412ca096a9ba
children
line wrap: on
line source
1 (ns com.aurellem.exp.assembly
2 (:use (com.aurellem.gb gb-driver vbm title items))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
6 (defn run-item-program
7 "This is my first assembly/item program!
8 it just increments BC by one.
10 The code places a 3 'great balls' at the beginning of the
11 inventory, then directly sets the program counter to start
12 executing at the position of the 'great balls' in memory.
14 Since a 'great ball' is represented in memory as 0x03, which
15 corresponts to the opcode which increments BC by one, that is
16 what happens. Then the program counter to the 0x03 quantity entry
17 and BC is incremented again.
19 Obviously, the game crashes more or less immediately after the
20 program counter advances past the 'great balls' into the next items
21 in the inventory, thus I call shutdown! before anything bad happens."
22 []
23 (set-inventory (read-state "mid-game") [[:great-ball 3]])
24 (print-inventory)
25 (println "3 ticks") (tick) (tick) (tick)
26 (println "PC before:" (PC))
27 (println "BC before:" (BC))
28 (PC! (inc item-list-start))
29 (println "PC after setting:" (PC))
30 (println "data at PC:" (aget (memory) (PC)))
31 (println "one tick")
32 (tick)
33 (println "PC after one tick:" (PC))
34 (println "BC after one tick:" (BC))
35 (tick)
36 (println "PC after two ticks:" (PC))
37 (println "BC after two ticks:" (BC))
39 (shutdown!))
44 (defn test-opcodes-1
45 []
46 (let [final-state
47 (->
48 (read-state "mid-game")
49 (set-inv-mem
50 [20 0x02 0x00 0x00 0x02 0x00 0x00
51 0x00 0x0 0xFF])
52 (print-inventory)
53 ;;((fn [_] (println "3 ticks") _))
54 (tick) (tick) (tick)
56 ;;(println "PC before:" (PC))
57 ;;(println "BC before:" (BC))
58 ;;(println "AF:" (AF))
59 (PC! (inc item-list-start))
60 (BC! (+ 1 item-list-start))
61 ;;(println "PC after setting:" (PC))
62 ;;(println "data at PC:" (aget (memory) (PC)))
63 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
65 ;;(println "one tick")
66 (tick)
67 ;;(println "PC after one tick:" (PC))
68 ;;(println "BC after one tick:" (BC))
69 ;;(println "data at PC:" (aget (memory) (PC)))
70 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
71 (tick)
72 (AF! 0xFFFF)
73 ;;(println "PC after two ticks:" (PC))
74 ;;(println "BC after two ticks:" (BC))
75 ;;(println "data at PC:" (aget (memory) (PC)))
76 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
77 (tick)
78 ;;(println "PC after three ticks:" (PC))
79 ;;(println "BC after three ticks:" (BC))
80 ;;(println "data at PC:" (aget (memory) (PC)))
81 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
82 (tick)
83 ;;(println "PC after four ticks:" (PC))
84 ;;(println "BC after four ticks:" (BC))
85 ;;(println "data at PC:" (aget (memory) (PC)))
86 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
87 (tick)
88 ;;(println "PC after five ticks:" (PC))
89 ;;(println "BC after five ticks:" (BC))
90 ;;(println "data at PC:" (aget (memory) (PC)))
91 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
92 (print-inventory)
93 )]
95 (shutdown!)
96 final-state))
100 (defn test-opcodes-2
101 []
102 (set-inv-mem (read-state "mid-game")
103 [20 0x08 0x1D 0xD3 0x00 0x00 0x00
104 0x00 0x0 0xFF])
105 (print-inventory)
106 (println "3 ticks") (tick) (tick) (tick)
107 (println "PC before:" (PC))
108 (println "SP:" (SP))
109 (PC! (inc item-list-start))
110 (println "PC after setting:" (PC))
111 (println "SP:" (Integer/toBinaryString (SP)))
112 (println "data at PC:" (aget (memory) (PC)))
113 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
114 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
115 (println "one tick")
116 (tick)
117 (println "PC after one tick:" (PC))
118 (println "data at PC:" (aget (memory) (PC)))
119 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
120 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
121 (tick) (tick) (tick)
122 (println "PC aftter four tick:" (PC))
123 (println "data at PC:" (aget (memory) (PC)))
124 (println "data at 0xD31D:" (aget (memory) 0xD31D))
126 (print-inventory)
127 (shutdown!))