Mercurial > vba-clojure
comparison clojure/com/aurellem/assembly.clj @ 110:f9dee79b2215
changed display for memory and registers to binary
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 15 Mar 2012 14:44:19 -0500 |
parents | c8b48102b17c |
children | 8be7ce890184 |
comparison
equal
deleted
inserted
replaced
109:c8b48102b17c | 110:f9dee79b2215 |
---|---|
62 (run-assembly info assembly n))) | 62 (run-assembly info assembly n))) |
63 | 63 |
64 | 64 |
65 (def buttons-port 0xFF00) | 65 (def buttons-port 0xFF00) |
66 | 66 |
67 (defn view-register [state name reg-fn] | |
68 (println (format "%s : 0x%02X" name (reg-fn state))) | |
69 state) | |
70 | 67 |
71 (defn A [state] | 68 (defn A [state] |
72 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) | 69 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) |
73 | 70 |
71 (defn binary-str [num] | |
72 (format "%08d" | |
73 (Integer/parseInt | |
74 (Integer/toBinaryString num) 10))) | |
75 | |
76 (defn view-register [state name reg-fn] | |
77 (println (format "%s: %s" name | |
78 (binary-str (reg-fn state)))) | |
79 state) | |
80 | |
81 | |
74 (defn view-memory [state mem] | 82 (defn view-memory [state mem] |
75 (println (format "mem 0x%04X = 0x%02X" mem (aget (memory state) mem))) | 83 (println (format "mem 0x%04X = %s" mem |
84 (binary-str (aget (memory state) mem)))) | |
76 state) | 85 state) |
77 | 86 |
78 (defn read-buttons [] | 87 (defn read-buttons [] |
79 (let [button-pressed (tick (step (mid-game) [:d]))] | 88 |
80 (-> button-pressed | 89 (-> (tick (mid-game)) |
81 (IE! 0) ; disable interrupts | 90 (IE! 0) ; disable interrupts |
82 (inject-item-assembly | 91 (inject-item-assembly |
83 (concat | 92 (concat |
84 ;; write 00010000 to 0xFF00 to select joypad | 93 ;; write 00010000 to 0xFF00 to select joypad |
85 [0x18 ;D31D ; jump over | 94 [0x18 ;D31D ; jump over |
86 0x01 ;D31E ; the next 8 bits | 95 0x01 ;D31E ; the next 8 bits |
87 (Integer/parseInt "00010000" 2) ;D31F data section | 96 (Integer/parseInt "00010000" 2) ;D31F data section |
88 0x00 ;D320 ; take a break | 97 0x00 ;D320 ; take a break |
89 0xFA ;D321 ; put DC15 into A | |
90 0x1F ;D322 --] | |
91 0xD3 ;D323 --] DC1F ; data section | |
92 0x01 ;D324 ; load 0xFF00 into BC | |
93 0x00 ;D325 | |
94 0xFF ;D326 | |
95 0x02 ;D327 (BC)->A ; load (00010000) into FF00 | |
96 ; to select directional | |
97 ; buttons | |
98 | 98 |
99 ] | 99 0xFA ;D321 ; put DC1F into A |
100 0x1F ;D322 --> | |
101 0xD3 ;D323 --> D31F | |
100 | 102 |
101 [])) | 103 0xEA ;D324 ; load (A), which is |
102 (info) | 104 0x00 ;D325 --> ; 00010000, into FF00 |
103 (tick) ;; skip over data section | 105 0xFF ;D326 --> FF00 |
104 (info) | 106 |
105 (tick) ;; no-op | 107 0x00 |
106 (info) | 108 ] |
107 (view-register "Register A" A) | 109 |
108 (tick) ;; load-data into A | 110 [])) |
109 (view-register "Register A" A) | 111 (info) |
110 (info) | 112 (tick) ;; skip over data section |
111 (view-register "Register BC" BC) | 113 (info) |
112 (tick) ;; store 0xFFOO into BC | 114 (tick) ;; no-op |
113 (view-register "Register BC" BC) | 115 (info) |
114 (info) | 116 (view-register "Register A" A) |
115 (view-memory 0xFF00) | 117 (tick) ;; load-data into A |
116 (tick) ;; load A into 0xFF00 | 118 (view-register "Register A" A) |
117 (view-memory 0xFF00) | 119 (info) |
118 ))) | 120 (view-memory 0xFF00) |
121 (tick) ;; load A into 0xFF00 | |
122 (view-memory 0xFF00) | |
123 )) | |
119 | 124 |
120 | 125 |
121 (defn trace [state] | 126 (defn trace [state] |
122 (loop [program-counters [] | 127 (loop [program-counters [] |
123 opcodes []] | 128 opcodes []] |