# HG changeset patch # User Dylan Holmes # Date 1332371857 18000 # Node ID 5d9a7a0ca09ac1d49b38dd4e8f0947959436d6c6 # Parent 5ce074824faced76f024b2785f3dbe0a0522de22 beginning test of latest assembly code. 240->70. diff -r 5ce074824fac -r 5d9a7a0ca09a clojure/com/aurellem/gb/assembly.clj --- a/clojure/com/aurellem/gb/assembly.clj Wed Mar 21 03:38:46 2012 -0500 +++ b/clojure/com/aurellem/gb/assembly.clj Wed Mar 21 18:17:37 2012 -0500 @@ -407,87 +407,47 @@ (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) - - - - - - - - - - - - - - - - - - - - - - - - - - - (defn write-memory-assembly* - "Currently, grabs input from the user each frame." + "A program for altering in-game memory by pressing buttons." [] [ + 0xF3 ; stop interrupts + ;; --------- CLEANUP + 0xAF ; zero A [D31E] + 0x57 ; A->D; makes D=0. + ;; --------- FRAME METRONOME - 0x18 ;; jump ahead to cleanup. first time only. - 0x40 ;; v-blank-prev [D31E] + 0xF1 ;; pop AF (vblank prev) [D320] - 0xFA ;; load modes into A [D31F] + 0x2F ;; invert A + 0x47 ;; A -> B + + 0xF0 ;; copy STAT into A 0x41 - 0xFF - 0x47 ;; A -> B - 0xCB ;; rotate A - 0x2F - 0x2F ;; invert A + 0xCB ;; swap A nybbles; now A_0 is (VB==1). + 0x37 - 0xA0 - 0x47 ;; now B_0 contains (VB==1) - - 0xFA ;; load v-blank-prev - 0x1E - 0xD3 - - 0x2F ;; complement v-blank-prev + 0xF5 ;; push AF (vbprev) - 0xA0 ;; A & B --> A - 0x4F ;; now C_0 contains increment? - - - 0x78 ;; B->A - 0xEA ;; spit A --> vbprev - 0x1E - 0xD3 - - 0xCB ;test C_0 - 0x41 - 0x20 ; JUMP ahead to button input if nonzero - 0x02 - 0x18 ; JUMP back to frame metronome (D31F) - 0xE7 + 0xA0 ;; A & B --> A. Now A_0 contains "increment?" + + 0xCB ;; test A_0. this result will be used twice. + 0x47 + 0x28 ;; end frame (JUMP) if A_0 = 0. + 0x00 ;; TODO: set jump length ;; -------- GET BUTTON INPUT - - ;; btw, C_0 is now 1 + + ;; btw, Z bit is now 1 ;; prepare to select bits - - 0x06 ;; load 0x00 into B - 0x00 ;; to initialize for "OR" loop 0x3E ;; load 0x20 into A, to measure dpad 0x20 + + 0x06 ;; load 0x00 into B + 0x00 ;; to initialize for "OR" loop - 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C] 0x00 @@ -498,17 +458,19 @@ 0x0F 0xB0 ;; A or B --> A - 0xCB - 0x41 ;; test bit 0 of C - 0x28 ;; JUMP forward if 0 + + 0x28 ;; JUMP forward if Z=0 0x08 0x47 ;; A -> B 0xCB ;; swap B nybbles 0x30 - 0x0C ;; increment C + 0x3E ;; load 0x10 into A, to measure btns 0x10 + + 0xBF ;; compare(A,A) sets Z=0 + 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] 0xED @@ -536,7 +498,6 @@ 0x2F ; complement A, by request. [D34F] 0x47 ; A->B ;; now B contains the pressed keys - 0x7B ; E->A ;; now A contains the count. 0xCB ; test bit 5 of D (are we in o/p mode?) 0x6A @@ -552,28 +513,16 @@ 0xE9 ; ** move PC to (HL) ;; output mode II: writing bytes - 0xFE ; A compare 0. finished writing? - 0x00 - 0x20 ; if we are not finished, skip cleanup - 0x04 ; JUMP - - ;; CLEANUP - ;; btw, A is already zero. - 0xAF ; zero A [D35F] - 0x57 ; A->D; makes D=0. - 0x18 ; end of frame - 0xBC - - ;; ---- end of cleanup - + 0xAF ; zero A + 0xBB ; compare count to zero. finished writing? + 0x28 ; if we are finished, jump back to cleanup + 0x00 ; TODO: set jump length backwards. ;; continue writing bytes - 0x1D ;; decrement E, the number of bytes to write [D363] - 0x78 ;; B->A; now A contains the pressed keys - 0x77 ;; copy A to (HL) - 0x23 ;; increment HL + 0x78 ;; B->A + 0x22 ;; copy A to (HL) and increment HL. 0x18 ;; end frame. [goto D31F] - 0xB6 ;; TODO: set skip length backwards + 0xB6 ;; JUMP ;; ---- end of o/p section @@ -599,7 +548,7 @@ 0x00 ;; var: thing to execute [D374] 0x18 ;; end frame - 0xA8 + 0xA8 ;; JUMP ] )