Mercurial > vba-clojure
view clojure/com/aurellem/gb/dylan_assembly.clj @ 336:25b7bb7da3b1
Fixed two major bugs related to restart events which were causing desync. The entire video now syncs properly.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 07 Apr 2012 07:31:59 -0500 |
parents | 19fd38fe376e |
children | 7c89fe478de4 |
line wrap: on
line source
1 (ns com.aurellem.gb.dylan-assembly2 "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-compact8 "Currently, grabs input from the user each frame."9 []10 [11 ;; --------- FRAME METRONOME12 0x18 ;; jump ahead to cleanup. first time only.13 0x40 ;; v-blank-prev [D31E]15 0xFA ;; load modes into A [D31F]16 0x4117 0xFF19 0x47 ;; A -> B20 0xCB ;; rotate A21 0x2F22 0x2F ;; invert A24 0xA025 0x47 ;; now B_0 contains (VB==1)27 0xFA ;; load v-blank-prev28 0x1E29 0xD331 0x2F ;; complement v-blank-prev33 0xA0 ;; A & B --> A34 0x4F ;; now C_0 contains increment?37 0x78 ;; B->A38 0xEA ;; spit A --> vbprev39 0x1E40 0xD342 0xCB ;test C_043 0x4144 0x20 ; JUMP ahead to button input if nonzero45 0x0246 0x18 ; JUMP back to frame metronome (D31F)47 0xE749 ;; -------- GET BUTTON INPUT51 ;; btw, C_0 is now 152 ;; prepare to select bits54 0x06 ;; load 0x00 into B55 0x00 ;; to initialize for "OR" loop57 0x3E ;; load 0x20 into A, to measure dpad58 0x2061 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C]62 0x0064 0xF0 ;; load A from [FF00]65 0x0067 0xE6 ;; bitmask 0000111168 0x0F70 0xB0 ;; A or B --> A71 0xCB72 0x41 ;; test bit 0 of C73 0x28 ;; JUMP forward if 074 0x0876 0x47 ;; A -> B77 0xCB ;; swap B nybbles78 0x3079 0x0C ;; increment C80 0x3E ;; load 0x10 into A, to measure btns81 0x1082 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?]83 0xED86 ;; ------ TAKE ACTION BASED ON USER INPUT88 ;; "input mode"89 ;; mode 0x00 : select mode90 ;; mode 0x08 : select bytes-to-write91 ;; mode 0x10 : select hi-bit92 ;; mode 0x18 : select lo-bit94 ;; "output mode"95 ;; mode 0x20 : write bytes96 ;; mode 0xFF : jump PC99 ;; registers100 ;; D : mode select101 ;; E : count of bytes to write102 ;; H : address-high103 ;; L : address-low105 ;; now A contains the pressed keys106 0x2F ; complement A, by request. [D34F]108 0x47 ; A->B ;; now B contains the pressed keys109 0x7B ; E->A ;; now A contains the count.111 0xCB ; test bit 5 of D (are we in o/p mode?)112 0x6A113 0x28 ; if test == 0, skip this o/p section114 0x13 ; JUMP116 0xCB ; else, test bit 0 of D (fragile; are we in pc mode?)117 0x42118 0x28 ; if test == 0, skip the following command119 0x01121 ;; output mode I: moving the program counter122 0xE9 ; ** move PC to (HL)124 ;; output mode II: writing bytes125 0xFE ; A compare 0. finished writing?126 0x00127 0x20 ; if we are not finished, skip cleanup128 0x04 ; JUMP130 ;; CLEANUP131 ;; btw, A is already zero.132 0xAF ; zero A [D35F]133 0x57 ; A->D; makes D=0.134 0x18 ; end of frame135 0xBC137 ;; ---- end of cleanup140 ;; continue writing bytes141 0x1D ;; decrement E, the number of bytes to write [D363]142 0x78 ;; B->A; now A contains the pressed keys143 0x77 ;; copy A to (HL)144 0x23 ;; increment HL145 0x18 ;; end frame. [goto D31F]146 0xB6 ;; TODO: set skip length backwards149 ;; ---- end of o/p section151 ;; i/p mode152 ;; 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 0x57157 0x82 ;; add the mode to A158 0xEA ;; store A into "thing to execute"159 0x74160 0xD3162 0x3E ;; load the constant 8 into A163 0x08164 0x82 ;; add the mode to A166 0x57 ;; store the incremented mode into D167 0x78 ;; B->A; now A contains the pressed keys169 0x00 ;; var: thing to execute [D374]171 0x18 ;; end frame172 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)) %))))