Mercurial > vba-clojure
comparison clojure/com/aurellem/assembly.clj @ 111:8be7ce890184
now I have an assembly program that can read button presses!
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 15 Mar 2012 17:20:55 -0500 |
parents | f9dee79b2215 |
children | 6fe33bb5ea22 |
comparison
equal
deleted
inserted
replaced
110:f9dee79b2215 | 111:8be7ce890184 |
---|---|
83 (println (format "mem 0x%04X = %s" mem | 83 (println (format "mem 0x%04X = %s" mem |
84 (binary-str (aget (memory state) mem)))) | 84 (binary-str (aget (memory state) mem)))) |
85 state) | 85 state) |
86 | 86 |
87 (defn read-buttons [] | 87 (defn read-buttons [] |
88 | |
89 (-> (tick (mid-game)) | 88 (-> (tick (mid-game)) |
90 (IE! 0) ; disable interrupts | 89 (IE! 0) ; disable interrupts |
91 (inject-item-assembly | 90 (inject-item-assembly |
92 (concat | 91 (concat |
93 ;; write 00010000 to 0xFF00 to select joypad | 92 ;; write 00010000 to 0xFF00 to select joypad |
94 [0x18 ;D31D ; jump over | 93 [0x18 ;D31D ; jump over |
95 0x01 ;D31E ; the next 8 bits | 94 0x01 ;D31E ; the next 8 bits |
96 (Integer/parseInt "00010000" 2) ;D31F data section | 95 (Integer/parseInt "00100000" 2) ;D31F data section |
97 0x00 ;D320 ; take a break | 96 |
97 0xFA ;D320 ; load (D31F) into A | |
98 0x1F ;D321 --> | |
99 0xD3 ;D322 --> D31F | |
98 | 100 |
99 0xFA ;D321 ; put DC1F into A | 101 0xEA ;D323 ; load (A), which is |
100 0x1F ;D322 --> | 102 0x00 ;D324 --> ; 00010000, into FF00 |
101 0xD3 ;D323 --> D31F | 103 0xFF ;D325 --> FF00 |
104 | |
105 0x18 ;D326 ; this is the place where | |
106 0x01 ;D327 ; we will store whether | |
107 0x00 ;D328 ; "down" is pressed. | |
102 | 108 |
103 0xEA ;D324 ; load (A), which is | 109 0xFA ;D329 ; (FF00) -> A |
104 0x00 ;D325 --> ; 00010000, into FF00 | 110 0x00 ;D32A |
105 0xFF ;D326 --> FF00 | 111 0xFF ;D32B |
106 | 112 |
107 0x00 | 113 0xCB ;D32C ; Test whether "down" |
114 0x5F ;D32D ; is pressed. | |
115 | |
116 0x28 ;D32E ; if down is pressed, | |
117 0x03 ;D32F ; skip the next section | |
118 ; of code. | |
119 ;; down-is-not-pressed | |
120 0xC3 ;D330 | |
121 0x1D ;D331 ; return to beginning | |
122 0xD3 ;D332 | |
123 | |
124 ;; down-is-pressed | |
125 0xEA ;D334 ; write A to D328 if | |
126 0x28 ;D335 ; "down" was pressed | |
127 0xD3 ;D336 | |
128 | |
129 0xC3 ;D330 | |
130 0x1D ;D331 ; return to beginning | |
131 0xD3 ;D332 | |
108 ] | 132 ] |
109 | 133 |
110 [])) | 134 [])))) |
135 | |
136 | |
137 (defn run-a-bit [] | |
138 (-> (read-buttons) | |
111 (info) | 139 (info) |
112 (tick) ;; skip over data section | 140 (tick) ;; skip over data section |
113 (info) | 141 (info) |
114 (tick) ;; no-op | |
115 (info) | |
116 (view-register "Register A" A) | 142 (view-register "Register A" A) |
117 (tick) ;; load-data into A | 143 (tick) ;; load-data into A |
118 (view-register "Register A" A) | 144 (view-register "Register A" A) |
119 (info) | 145 (info) |
120 (view-memory 0xFF00) | 146 (view-memory 0xFF00) |
121 (tick) ;; load A into 0xFF00 | 147 (tick) ;; load A into 0xFF00 |
122 (view-memory 0xFF00) | 148 (view-memory 0xFF00) |
123 )) | 149 (info) |
124 | 150 (tick) |
125 | 151 (info) |
152 (tick) | |
153 (info) | |
154 (tick) | |
155 (info) | |
156 (tick) | |
157 (info) | |
158 (tick) | |
159 (info) | |
160 (tick) | |
161 (print-inventory))) | |
162 | |
163 | |
164 (comment | |
165 (view-memory (step (step (read-buttons) [:d])) 0xD328) | |
166 ;;mem 0xD328 = 11100111 | |
167 (view-memory (step (step (read-buttons))) 0xD328) | |
168 ;;mem 0xD328 = 00000000 | |
169 ) | |
170 | |
126 (defn trace [state] | 171 (defn trace [state] |
127 (loop [program-counters [] | 172 (loop [program-counters [] |
128 opcodes []] | 173 opcodes []] |
129 (let [frame-boundary? | 174 (let [frame-boundary? |
130 (com.aurellem.gb.Gb/tick)] | 175 (com.aurellem.gb.Gb/tick)] |