changeset 175:5d9a7a0ca09a

beginning test of latest assembly code. 240->70.
author Dylan Holmes <ocsenave@gmail.com>
date Wed, 21 Mar 2012 18:17:37 -0500
parents 5ce074824fac
children 95b2758dd517
files clojure/com/aurellem/gb/assembly.clj
diffstat 1 files changed, 39 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/assembly.clj	Wed Mar 21 03:38:46 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/assembly.clj	Wed Mar 21 18:17:37 2012 -0500
     1.3 @@ -407,87 +407,47 @@
     1.4    (dotimes [_ 90000] (step (view-memory @current-state 0xD352))))
     1.5  
     1.6  
     1.7 -    
     1.8 -
     1.9 -
    1.10 -
    1.11 -
    1.12 -
    1.13 -
    1.14 -
    1.15 -
    1.16 -
    1.17 -
    1.18 -
    1.19 -
    1.20 -
    1.21 -
    1.22 -
    1.23 -
    1.24 -
    1.25 -
    1.26 -
    1.27 -
    1.28 -
    1.29 -
    1.30 -
    1.31 -
    1.32 -
    1.33 -
    1.34  (defn write-memory-assembly*
    1.35 -  "Currently, grabs input from the user each frame."
    1.36 +  "A program for altering in-game memory by pressing buttons."
    1.37    []
    1.38    [
    1.39 +   0xF3 ; stop interrupts
    1.40 +   ;; --------- CLEANUP
    1.41 +   0xAF ; zero A  [D31E]
    1.42 +   0x57 ; A->D; makes D=0.
    1.43 +   
    1.44     ;; --------- FRAME METRONOME
    1.45 -   0x18 ;; jump ahead to cleanup. first time only.
    1.46 -   0x40 ;; v-blank-prev [D31E]
    1.47 +   0xF1 ;; pop AF (vblank prev) [D320]
    1.48  
    1.49 -   0xFA ;; load modes into A [D31F]
    1.50 +   0x2F ;; invert A
    1.51 +   0x47 ;; A -> B
    1.52 +   
    1.53 +   0xF0 ;; copy STAT into A
    1.54     0x41
    1.55 -   0xFF
    1.56  
    1.57 -   0x47 ;; A -> B
    1.58 -   0xCB ;; rotate A
    1.59 -   0x2F
    1.60 -   0x2F ;; invert A
    1.61 +   0xCB ;; swap A nybbles; now A_0 is (VB==1).
    1.62 +   0x37
    1.63  
    1.64 -   0xA0
    1.65 -   0x47 ;; now B_0 contains (VB==1)
    1.66 -
    1.67 -   0xFA ;; load v-blank-prev
    1.68 -   0x1E
    1.69 -   0xD3
    1.70 -
    1.71 -   0x2F ;; complement v-blank-prev
    1.72 +   0xF5 ;; push AF (vbprev)
    1.73     
    1.74 -   0xA0 ;; A & B --> A
    1.75 -   0x4F ;; now C_0 contains increment?
    1.76 -
    1.77 -
    1.78 -   0x78 ;; B->A
    1.79 -   0xEA ;; spit A --> vbprev
    1.80 -   0x1E
    1.81 -   0xD3
    1.82 -
    1.83 -   0xCB   ;test C_0
    1.84 -   0x41
    1.85 -   0x20   ; JUMP ahead to button input if nonzero
    1.86 -   0x02
    1.87 -   0x18   ; JUMP  back to frame metronome (D31F)
    1.88 -   0xE7
    1.89 +   0xA0 ;; A & B --> A. Now A_0 contains "increment?"
    1.90 +   
    1.91 +   0xCB ;; test A_0. this result will be used twice.
    1.92 +   0x47
    1.93 +   0x28 ;; end frame (JUMP) if A_0 = 0.  
    1.94 +   0x00 ;; TODO: set jump length
    1.95     
    1.96     ;; -------- GET BUTTON INPUT
    1.97 -
    1.98 -        ;; btw, C_0 is now 1
    1.99 +   
   1.100 +        ;; btw, Z bit is now 1
   1.101          ;; prepare to select bits
   1.102 -
   1.103 -   0x06 ;; load 0x00 into B
   1.104 -   0x00 ;; to initialize for "OR" loop
   1.105   
   1.106     0x3E ;; load 0x20 into A, to measure dpad
   1.107     0x20
   1.108 +   
   1.109 +   0x06 ;; load 0x00 into B
   1.110 +   0x00 ;; to initialize for "OR" loop
   1.111  
   1.112 -   
   1.113     0xE0 ;; load A into [FF00] ;; start of OR loop [D33C]
   1.114     0x00
   1.115     
   1.116 @@ -498,17 +458,19 @@
   1.117     0x0F
   1.118     
   1.119     0xB0 ;; A or B --> A
   1.120 -   0xCB
   1.121 -   0x41 ;; test bit 0 of C
   1.122 -   0x28 ;; JUMP forward if 0
   1.123 +
   1.124 +   0x28 ;; JUMP forward if Z=0
   1.125     0x08
   1.126  
   1.127     0x47 ;; A -> B
   1.128     0xCB ;; swap B nybbles
   1.129     0x30 
   1.130 -   0x0C ;; increment C
   1.131 +   
   1.132     0x3E ;; load 0x10 into A, to measure btns
   1.133     0x10
   1.134 +
   1.135 +   0xBF ;; compare(A,A) sets Z=0
   1.136 +   
   1.137     0x18 ;; JUMP back to "load A into [FF00]" [20 steps?]
   1.138     0xED
   1.139  
   1.140 @@ -536,7 +498,6 @@
   1.141     0x2F ; complement A, by request. [D34F]
   1.142     
   1.143     0x47 ; A->B ;; now B contains the pressed keys
   1.144 -   0x7B ; E->A ;; now A contains the count.
   1.145  
   1.146     0xCB ; test bit 5 of D (are we in o/p mode?)
   1.147     0x6A
   1.148 @@ -552,28 +513,16 @@
   1.149     0xE9 ; ** move PC to (HL)
   1.150  
   1.151     ;; output mode II: writing bytes
   1.152 -   0xFE ; A compare 0. finished writing?
   1.153 -   0x00
   1.154 -   0x20 ; if we are not finished, skip cleanup
   1.155 -   0x04 ; JUMP
   1.156 -
   1.157 -   ;; CLEANUP
   1.158 -   ;; btw, A is already zero.
   1.159 -   0xAF ; zero A  [D35F]
   1.160 -   0x57 ; A->D; makes D=0.
   1.161 -   0x18 ; end of frame
   1.162 -   0xBC
   1.163 -   
   1.164 -   ;; ---- end of cleanup
   1.165 -
   1.166 +   0xAF ; zero A
   1.167 +   0xBB ; compare count to zero. finished writing?
   1.168 +   0x28 ; if we are finished, jump back to cleanup
   1.169 +   0x00 ; TODO: set jump length backwards.
   1.170     
   1.171     ;; continue writing bytes
   1.172 -   0x1D ;; decrement E, the number of bytes to write [D363]
   1.173 -   0x78 ;; B->A; now A contains the pressed keys
   1.174 -   0x77 ;; copy A to (HL)
   1.175 -   0x23 ;; increment HL
   1.176 +   0x78 ;; B->A
   1.177 +   0x22 ;; copy A to (HL) and increment HL. 
   1.178     0x18 ;; end frame. [goto D31F]
   1.179 -   0xB6 ;; TODO: set skip length backwards
   1.180 +   0xB6 ;; JUMP
   1.181  
   1.182  
   1.183     ;; ---- end of o/p section
   1.184 @@ -599,7 +548,7 @@
   1.185     0x00 ;; var: thing to execute [D374]
   1.186  
   1.187     0x18 ;; end frame
   1.188 -   0xA8
   1.189 +   0xA8 ;; JUMP
   1.190     ]
   1.191    )
   1.192