Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/dylan_assembly.clj @ 239:19fd38fe376e
revived a functional version of Dylan's assembly.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 25 Mar 2012 00:38:45 -0500 |
parents | |
children | 7c89fe478de4 |
comparison
equal
deleted
inserted
replaced
238:e23ab90fcc86 | 239:19fd38fe376e |
---|---|
1 (ns com.aurellem.gb.dylan-assembly | |
2 "A much more compact version of write-memory-assembly" | |
3 {:author "Dylan Holmes"} | |
4 (:use (com.aurellem.gb gb-driver assembly util)) | |
5 (:import [com.aurellem.gb.gb_driver SaveState])) | |
6 | |
7 (defn write-memory-assembly-compact | |
8 "Currently, grabs input from the user each frame." | |
9 [] | |
10 [ | |
11 ;; --------- FRAME METRONOME | |
12 0x18 ;; jump ahead to cleanup. first time only. | |
13 0x40 ;; v-blank-prev [D31E] | |
14 | |
15 0xFA ;; load modes into A [D31F] | |
16 0x41 | |
17 0xFF | |
18 | |
19 0x47 ;; A -> B | |
20 0xCB ;; rotate A | |
21 0x2F | |
22 0x2F ;; invert A | |
23 | |
24 0xA0 | |
25 0x47 ;; now B_0 contains (VB==1) | |
26 | |
27 0xFA ;; load v-blank-prev | |
28 0x1E | |
29 0xD3 | |
30 | |
31 0x2F ;; complement v-blank-prev | |
32 | |
33 0xA0 ;; A & B --> A | |
34 0x4F ;; now C_0 contains increment? | |
35 | |
36 | |
37 0x78 ;; B->A | |
38 0xEA ;; spit A --> vbprev | |
39 0x1E | |
40 0xD3 | |
41 | |
42 0xCB ;test C_0 | |
43 0x41 | |
44 0x20 ; JUMP ahead to button input if nonzero | |
45 0x02 | |
46 0x18 ; JUMP back to frame metronome (D31F) | |
47 0xE7 | |
48 | |
49 ;; -------- GET BUTTON INPUT | |
50 | |
51 ;; btw, C_0 is now 1 | |
52 ;; prepare to select bits | |
53 | |
54 0x06 ;; load 0x00 into B | |
55 0x00 ;; to initialize for "OR" loop | |
56 | |
57 0x3E ;; load 0x20 into A, to measure dpad | |
58 0x20 | |
59 | |
60 | |
61 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C] | |
62 0x00 | |
63 | |
64 0xF0 ;; load A from [FF00] | |
65 0x00 | |
66 | |
67 0xE6 ;; bitmask 00001111 | |
68 0x0F | |
69 | |
70 0xB0 ;; A or B --> A | |
71 0xCB | |
72 0x41 ;; test bit 0 of C | |
73 0x28 ;; JUMP forward if 0 | |
74 0x08 | |
75 | |
76 0x47 ;; A -> B | |
77 0xCB ;; swap B nybbles | |
78 0x30 | |
79 0x0C ;; increment C | |
80 0x3E ;; load 0x10 into A, to measure btns | |
81 0x10 | |
82 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] | |
83 0xED | |
84 | |
85 | |
86 ;; ------ TAKE ACTION BASED ON USER INPUT | |
87 | |
88 ;; "input mode" | |
89 ;; mode 0x00 : select mode | |
90 ;; mode 0x08 : select bytes-to-write | |
91 ;; mode 0x10 : select hi-bit | |
92 ;; mode 0x18 : select lo-bit | |
93 | |
94 ;; "output mode" | |
95 ;; mode 0x20 : write bytes | |
96 ;; mode 0xFF : jump PC | |
97 | |
98 | |
99 ;; registers | |
100 ;; D : mode select | |
101 ;; E : count of bytes to write | |
102 ;; H : address-high | |
103 ;; L : address-low | |
104 | |
105 ;; now A contains the pressed keys | |
106 0x2F ; complement A, by request. [D34F] | |
107 | |
108 0x47 ; A->B ;; now B contains the pressed keys | |
109 0x7B ; E->A ;; now A contains the count. | |
110 | |
111 0xCB ; test bit 5 of D (are we in o/p mode?) | |
112 0x6A | |
113 0x28 ; if test == 0, skip this o/p section | |
114 0x13 ; JUMP | |
115 | |
116 0xCB ; else, test bit 0 of D (fragile; are we in pc mode?) | |
117 0x42 | |
118 0x28 ; if test == 0, skip the following command | |
119 0x01 | |
120 | |
121 ;; output mode I: moving the program counter | |
122 0xE9 ; ** move PC to (HL) | |
123 | |
124 ;; output mode II: writing bytes | |
125 0xFE ; A compare 0. finished writing? | |
126 0x00 | |
127 0x20 ; if we are not finished, skip cleanup | |
128 0x04 ; JUMP | |
129 | |
130 ;; CLEANUP | |
131 ;; btw, A is already zero. | |
132 0xAF ; zero A [D35F] | |
133 0x57 ; A->D; makes D=0. | |
134 0x18 ; end of frame | |
135 0xBC | |
136 | |
137 ;; ---- end of cleanup | |
138 | |
139 | |
140 ;; continue writing bytes | |
141 0x1D ;; decrement E, the number of bytes to write [D363] | |
142 0x78 ;; B->A; now A contains the pressed keys | |
143 0x77 ;; copy A to (HL) | |
144 0x23 ;; increment HL | |
145 0x18 ;; end frame. [goto D31F] | |
146 0xB6 ;; TODO: set skip length backwards | |
147 | |
148 | |
149 ;; ---- end of o/p section | |
150 | |
151 ;; i/p mode | |
152 ;; adhere to the mode discipline: | |
153 ;; D must be one of 0x00 0x08 0x10 0x18. | |
154 | |
155 0x3E ;; load the constant 57 into A. [D369] | |
156 0x57 | |
157 0x82 ;; add the mode to A | |
158 0xEA ;; store A into "thing to execute" | |
159 0x74 | |
160 0xD3 | |
161 | |
162 0x3E ;; load the constant 8 into A | |
163 0x08 | |
164 0x82 ;; add the mode to A | |
165 | |
166 0x57 ;; store the incremented mode into D | |
167 0x78 ;; B->A; now A contains the pressed keys | |
168 | |
169 0x00 ;; var: thing to execute [D374] | |
170 | |
171 0x18 ;; end frame | |
172 0xA8]) | |
173 | |
174 (defn write-mem-compact [] | |
175 (-> (tick (mid-game)) | |
176 (IE! 0) | |
177 (inject-item-assembly (write-memory-assembly-compact)))) | |
178 | |
179 (defn drive-compact [] | |
180 (-> (write-mem-compact) | |
181 (#(do (println "memory from 0xC00F to 0xC01F:" | |
182 (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) | |
183 (step []) | |
184 (step []) | |
185 (step []) | |
186 (step [:start]) | |
187 (step [:select]) | |
188 (step [:u :d]) | |
189 (step [:a :b :start :select]) | |
190 (step [:a]) | |
191 (step [:b]) | |
192 (step [:a :b]) | |
193 (step [:select]) | |
194 (step []) | |
195 (step []) | |
196 (step []) | |
197 (#(do (println "memory from 0xC00F to 0xC01F:" | |
198 (subvec (vec (memory %)) 0xC00F 0xC01F)) %)))) | |
199 |