Mercurial > vba-clojure
comparison clojure/com/aurellem/assembly.clj @ 105:2f8089eacab9
working on some actual assembly programs
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 13 Mar 2012 14:40:01 -0500 |
parents | |
children | 3a60bb14a64a |
comparison
equal
deleted
inserted
replaced
104:d2e00ea31508 | 105:2f8089eacab9 |
---|---|
1 (ns com.aurellem.assembly | |
2 (:use (com.aurellem gb-driver vbm title items)) | |
3 (:import [com.aurellem.gb_driver SaveState])) | |
4 | |
5 | |
6 | |
7 | |
8 (defn inject-assembly | |
9 [^SaveState state | |
10 program-counter registers | |
11 assembly-code] | |
12 (set-state! state) | |
13 (let [scratch-memory (memory state)] | |
14 ;; inject assembly code | |
15 (dorun (map (fn [index val] | |
16 (aset scratch-memory index val)) | |
17 (range program-counter | |
18 (+ program-counter (count assembly-code))) | |
19 assembly-code)) | |
20 (write-memory! scratch-memory) | |
21 (set-state! (update-state)) | |
22 (write-registers! registers) | |
23 (set-state! (update-state)) | |
24 (PC! program-counter) | |
25 (update-state))) | |
26 | |
27 (defn inject-item-assembly | |
28 ([^SaveState state assembly-code] | |
29 (inject-assembly state (inc item-list-start) | |
30 (registers state) | |
31 assembly-code)) | |
32 ([assembly-code] | |
33 (inject-item-assembly @current-state assembly-code))) | |
34 | |
35 (defn info | |
36 ([^SaveState state] | |
37 (set-state! state) | |
38 (println "PC: " (PC)) | |
39 (println "Instruction:" (format "0x%02X" (aget (memory state) (PC)))) | |
40 state)) | |
41 | |
42 (defn irony [] (read-state 578544)) | |
43 | |
44 (defn run-assembly | |
45 ([info-fn assembly n] | |
46 (let [final-state | |
47 (reduce (fn [state _] | |
48 (tick (info-fn state))) | |
49 (inject-item-assembly (tick (tick (tick (irony)))) assembly) | |
50 (range n))] | |
51 (shutdown!) | |
52 final-state)) | |
53 ([assembly n] | |
54 (run-assembly info assembly n))) | |
55 |