# HG changeset patch # User Dylan Holmes # Date 1332144342 18000 # Node ID 2b69cbe8a5b96072f92c7013490ca80117e2f68c # Parent 1c58fa3cfc6809a82d6b7c2eb3428de23e05ddc4 saving progress on state machine; 240 ops -> 90 ops (provided it withstands debugging) diff -r 1c58fa3cfc68 -r 2b69cbe8a5b9 clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Sun Mar 18 20:49:40 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Mon Mar 19 03:05:42 2012 -0500 @@ -497,9 +497,10 @@ [] [ ;; --------- FRAME METRONOME - 0x00 ;; v-blank-prev D31D + 0x18 ;; jump ahead to cleanup. first time only. + 0x40 ;; v-blank-prev [D31E] - 0xFA ;; load modes into A + 0xFA ;; load modes into A [D31F] 0x41 0xFF @@ -512,7 +513,7 @@ 0x47 ;; now B_0 contains (VB==1) 0xFA ;; load v-blank-prev - 0x1D + 0x1E 0xD3 0x2F ;; complement v-blank-prev @@ -522,32 +523,30 @@ 0x78 ;; B->A - 0xEA ;; spit A --> vbprev - 0x1D + 0x1E 0xD3 0xCB ;test C_0 0x41 0x20 ; JUMP ahead to button input if nonzero - 0x03 - 0x18 ; JUMP back to frame metronome (D31E) - 0xE7 + 0x02 + 0x18 ; JUMP back to frame metronome (D31F) + 0xE6 ; todo: verify this jump length ;; -------- GET BUTTON INPUT ;; btw, C_0 is now 1 - 0x00 ;; var: which-input D337 ;; prepare to select bits 0x06 ;; load 0x00 into B - 0x00 + 0x00 ;; to initialize for "OR" loop 0x3E ;; load 0x20 into A, to measure dpad 0x20 - 0xE0 ;; load A into [FF00] ;; D33C + 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C] 0x00 0xF0 ;; load A from [FF00] @@ -571,21 +570,88 @@ 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] 0xED + + ;; ------ TAKE ACTION BASED ON USER INPUT + + ;; mode 0x00 : select mode + ;; mode 0x08 : select bytes-to-write + ;; mode 0x10 : select hi-bit + ;; mode 0x18 : select lo-bit + + ;; mode 0xF0 : write bytes + ;; mode 0xFF : jump PC + + + ;; registers + ;; D : mode select + ;; E : count of bytes to write + ;; H : address-high + ;; L : address-low + ;; now A contains the pressed keys + 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 4 of D (are we in o/p mode?) + 0x26 + 0x28 ; if test == 0, skip this o/p section + 0x13 ; JUMP + 0xCB ; else, test bit 0 of D (fragile; are we in pc mode?) + 0x42 + 0x28 ; if test == 0, skip the following command + 0x01 + ;; output mode I: moving the program counter + 0xE9 ; ** move PC to (HL) + ;; output mode II: writing bytes + 0xFE ; A compare 0. finished writing? + 0x00 + 0x28 ; 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 + + ;; continue writing bytes + 0x1D ;; decrement E, the number of bytes to write + 0x78 ;; B->A; now A contains the pressed keys + 0x77 ;; copy A to (HL) + 0x23 ;; increment HL + 0x18 ;; end frame. + 0xC2 ;; TODO: set skip length backwards - 0xC3 ;; todo replace with relative jump - 0x1E + ;; ---- end of o/p section + + ;; get data + 0x3E ;; load the constant 57 into A. [D369] + 0x57 + 0x82 ;; add the mode to A + 0xEA ;; store A into "thing to execute" + 0x74 0xD3 - ;;0x18 ;;JUMP back to "metronome" in one hop [D31E] - ;;0xCA ;; E1 + + 0x3E ;; load the constant 8 into A + 0x08 + 0x82 ;; add the mode to A + 0x57 ;; store the incremented mode into D + 0x78 ;; B->A; now A contains the pressed keys + 0x00 ;; var: thing to execute [D374] + + 0x18 ;; end frame + 0xA8 ;; JUMP ] ) @@ -595,6 +661,73 @@ (inject-item-assembly (write-memory-assembly*)))) +(defn dylan* [] + (-> + (write-mem-dyl) + + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + + ;;(view-memory 0xD374) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + (tick) + ;;(view-memory 0xD374) + (d-tick) + + (view-register "A" A) + (view-register "B" B) + (view-register "C" C)) + +) + + (defn dylan [] (-> (write-mem-dyl)