view clojure/com/aurellem/gb/dylan_assembly.clj @ 312:2060219691fa

Added more to the rom map.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 01 Apr 2012 21:47:04 -0500
parents 19fd38fe376e
children 7c89fe478de4
line wrap: on
line source
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]))
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]
15 0xFA ;; load modes into A [D31F]
16 0x41
17 0xFF
19 0x47 ;; A -> B
20 0xCB ;; rotate A
21 0x2F
22 0x2F ;; invert A
24 0xA0
25 0x47 ;; now B_0 contains (VB==1)
27 0xFA ;; load v-blank-prev
28 0x1E
29 0xD3
31 0x2F ;; complement v-blank-prev
33 0xA0 ;; A & B --> A
34 0x4F ;; now C_0 contains increment?
37 0x78 ;; B->A
38 0xEA ;; spit A --> vbprev
39 0x1E
40 0xD3
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
49 ;; -------- GET BUTTON INPUT
51 ;; btw, C_0 is now 1
52 ;; prepare to select bits
54 0x06 ;; load 0x00 into B
55 0x00 ;; to initialize for "OR" loop
57 0x3E ;; load 0x20 into A, to measure dpad
58 0x20
61 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C]
62 0x00
64 0xF0 ;; load A from [FF00]
65 0x00
67 0xE6 ;; bitmask 00001111
68 0x0F
70 0xB0 ;; A or B --> A
71 0xCB
72 0x41 ;; test bit 0 of C
73 0x28 ;; JUMP forward if 0
74 0x08
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
86 ;; ------ TAKE ACTION BASED ON USER INPUT
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
94 ;; "output mode"
95 ;; mode 0x20 : write bytes
96 ;; mode 0xFF : jump PC
99 ;; registers
100 ;; D : mode select
101 ;; E : count of bytes to write
102 ;; H : address-high
103 ;; L : address-low
105 ;; now A contains the pressed keys
106 0x2F ; complement A, by request. [D34F]
108 0x47 ; A->B ;; now B contains the pressed keys
109 0x7B ; E->A ;; now A contains the count.
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
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
121 ;; output mode I: moving the program counter
122 0xE9 ; ** move PC to (HL)
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
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
137 ;; ---- end of cleanup
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
149 ;; ---- end of o/p section
151 ;; i/p mode
152 ;; adhere to the mode discipline:
153 ;; D must be one of 0x00 0x08 0x10 0x18.
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
162 0x3E ;; load the constant 8 into A
163 0x08
164 0x82 ;; add the mode to A
166 0x57 ;; store the incremented mode into D
167 0x78 ;; B->A; now A contains the pressed keys
169 0x00 ;; var: thing to execute [D374]
171 0x18 ;; end frame
172 0xA8])
174 (defn write-mem-compact []
175 (-> (tick (mid-game))
176 (IE! 0)
177 (inject-item-assembly (write-memory-assembly-compact))))
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)) %))))