Mercurial > vba-clojure
view 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 |
line wrap: on
line source
1 (ns com.aurellem.assembly2 (:use (com.aurellem gb-driver vbm title items))3 (:import [com.aurellem.gb_driver SaveState]))8 (defn inject-assembly9 [^SaveState state10 program-counter registers11 assembly-code]12 (set-state! state)13 (let [scratch-memory (memory state)]14 ;; inject assembly code15 (dorun (map (fn [index val]16 (aset scratch-memory index val))17 (range program-counter18 (+ 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)))27 (defn inject-item-assembly28 ([^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)))35 (defn info36 ([^SaveState state]37 (set-state! state)38 (println "PC: " (PC))39 (println "Instruction:" (format "0x%02X" (aget (memory state) (PC))))40 state))42 (defn irony [] (read-state 578544))44 (defn run-assembly45 ([info-fn assembly n]46 (let [final-state47 (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)))