changeset 138:2b69cbe8a5b9

saving progress on state machine; 240 ops -> 90 ops (provided it withstands debugging)
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 19 Mar 2012 03:05:42 -0500
parents 1c58fa3cfc68
children 74ec1ac044bb
files clojure/com/aurellem/assembly.clj
diffstat 1 files changed, 148 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Sun Mar 18 20:49:40 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Mon Mar 19 03:05:42 2012 -0500
     1.3 @@ -497,9 +497,10 @@
     1.4    []
     1.5    [
     1.6     ;; --------- FRAME METRONOME
     1.7 -   0x00 ;; v-blank-prev D31D
     1.8 +   0x18 ;; jump ahead to cleanup. first time only.
     1.9 +   0x40 ;; v-blank-prev [D31E]
    1.10  
    1.11 -   0xFA ;; load modes into A
    1.12 +   0xFA ;; load modes into A [D31F]
    1.13     0x41
    1.14     0xFF
    1.15  
    1.16 @@ -512,7 +513,7 @@
    1.17     0x47 ;; now B_0 contains (VB==1)
    1.18  
    1.19     0xFA ;; load v-blank-prev
    1.20 -   0x1D
    1.21 +   0x1E
    1.22     0xD3
    1.23  
    1.24     0x2F ;; complement v-blank-prev
    1.25 @@ -522,32 +523,30 @@
    1.26  
    1.27  
    1.28     0x78 ;; B->A
    1.29 -   
    1.30     0xEA ;; spit A --> vbprev
    1.31 -   0x1D
    1.32 +   0x1E
    1.33     0xD3
    1.34  
    1.35     0xCB   ;test C_0
    1.36     0x41
    1.37     0x20   ; JUMP ahead to button input if nonzero
    1.38 -   0x03
    1.39 -   0x18   ; JUMP  back to frame metronome (D31E)
    1.40 -   0xE7  
    1.41 +   0x02
    1.42 +   0x18   ; JUMP  back to frame metronome (D31F)
    1.43 +   0xE6   ; todo: verify this jump length  
    1.44     
    1.45     ;; -------- GET BUTTON INPUT
    1.46  
    1.47          ;; btw, C_0 is now 1
    1.48 -   0x00 ;; var: which-input D337
    1.49          ;; prepare to select bits
    1.50  
    1.51     0x06 ;; load 0x00 into B
    1.52 -   0x00
    1.53 +   0x00 ;; to initialize for "OR" loop
    1.54   
    1.55     0x3E ;; load 0x20 into A, to measure dpad
    1.56     0x20
    1.57  
    1.58     
    1.59 -   0xE0 ;; load A into [FF00] ;; D33C
    1.60 +   0xE0 ;; load A into [FF00] ;; start of OR loop [D33C]
    1.61     0x00
    1.62     
    1.63     0xF0 ;; load A from [FF00]
    1.64 @@ -571,21 +570,88 @@
    1.65     0x18 ;; JUMP back to "load A into [FF00]" [20 steps?]
    1.66     0xED
    1.67  
    1.68 +
    1.69 +   ;; ------ TAKE ACTION BASED ON USER INPUT
    1.70 +
    1.71 +   ;; mode 0x00 : select mode
    1.72 +   ;; mode 0x08 : select bytes-to-write
    1.73 +   ;; mode 0x10 : select hi-bit
    1.74 +   ;; mode 0x18 : select lo-bit
    1.75 +
    1.76 +   ;; mode 0xF0 : write bytes
    1.77 +   ;; mode 0xFF : jump PC
    1.78 +
    1.79 +
    1.80 +   ;; registers
    1.81 +   ;; D : mode select
    1.82 +   ;; E : count of bytes to write
    1.83 +   ;; H : address-high
    1.84 +   ;; L : address-low
    1.85 +   
    1.86     ;; now A contains the pressed keys
    1.87 +   0x2F ; complement A, by request. [D34F]
    1.88     
    1.89 +   0x47 ; A->B ;; now B contains the pressed keys
    1.90 +   0x7B ; E->A ;; now A contains the count.
    1.91 +
    1.92 +   0xCB ; test bit 4 of D (are we in o/p mode?)
    1.93 +   0x26
    1.94 +   0x28 ; if test == 0, skip this o/p section
    1.95 +   0x13 ; JUMP
    1.96     
    1.97 +   0xCB ; else, test bit 0 of D (fragile; are we in pc mode?)
    1.98 +   0x42
    1.99 +   0x28 ; if test == 0, skip the following command
   1.100 +   0x01
   1.101  
   1.102 +   ;; output mode I: moving the program counter
   1.103 +   0xE9 ; ** move PC to (HL)
   1.104  
   1.105 +   ;; output mode II: writing bytes
   1.106 +   0xFE ; A compare 0. finished writing?
   1.107 +   0x00
   1.108 +   0x28 ; if we are not finished, skip cleanup
   1.109 +   0x04 ; JUMP
   1.110  
   1.111 +   ;; CLEANUP
   1.112 +   ;; btw, A is already zero.
   1.113 +   0xAF ; zero A  [D35F]
   1.114 +   0x57 ; A->D; makes D=0.
   1.115 +   0x18 ; end of frame
   1.116 +   0xBC
   1.117 +   
   1.118 +   ;; ---- end of cleanup
   1.119  
   1.120 +   
   1.121 +   ;; continue writing bytes
   1.122 +   0x1D ;; decrement E, the number of bytes to write
   1.123 +   0x78 ;; B->A; now A contains the pressed keys
   1.124 +   0x77 ;; copy A to (HL)
   1.125 +   0x23 ;; increment HL
   1.126 +   0x18 ;; end frame.
   1.127 +   0xC2 ;; TODO: set skip length backwards
   1.128  
   1.129  
   1.130 -   0xC3 ;; todo replace with relative jump
   1.131 -   0x1E
   1.132 +   ;; ---- end of o/p section
   1.133 +   
   1.134 +   ;; get data
   1.135 +   0x3E ;; load the constant 57 into A. [D369]
   1.136 +   0x57
   1.137 +   0x82 ;; add the mode to A
   1.138 +   0xEA ;; store A into "thing to execute"
   1.139 +   0x74
   1.140     0xD3
   1.141 -   ;;0x18 ;;JUMP back to "metronome" in one hop [D31E]
   1.142 -   ;;0xCA ;; E1
   1.143 +
   1.144 +   0x3E ;; load the constant 8 into A
   1.145 +   0x08
   1.146 +   0x82 ;; add the mode to A
   1.147 +   0x57 ;; store the incremented mode into D
   1.148 +   0x78 ;; B->A; now A contains the pressed keys
   1.149     
   1.150 +   0x00 ;; var: thing to execute [D374]
   1.151 +
   1.152 +   0x18 ;; end frame
   1.153 +   0xA8 ;; JUMP
   1.154     ]
   1.155    )
   1.156  
   1.157 @@ -595,6 +661,73 @@
   1.158        (inject-item-assembly (write-memory-assembly*))))
   1.159  
   1.160  
   1.161 +(defn dylan* []
   1.162 +  (->
   1.163 +   (write-mem-dyl)
   1.164 +
   1.165 +   (tick)
   1.166 +   (tick)
   1.167 +   (tick)
   1.168 +   (tick)
   1.169 +   (tick)
   1.170 +   (tick)
   1.171 +   (tick)
   1.172 +   (tick)
   1.173 +   (tick)
   1.174 +   (tick)
   1.175 +   (tick)
   1.176 +   (tick)
   1.177 +   (tick)
   1.178 +   (tick)
   1.179 +   (tick)
   1.180 +   (tick)
   1.181 +   (tick)
   1.182 +   (tick)
   1.183 +   (tick)
   1.184 +   (tick)
   1.185 +   (tick)
   1.186 +   (tick)
   1.187 +   (tick)
   1.188 +   (tick)
   1.189 +   (tick)
   1.190 +   (tick)
   1.191 +   (tick)
   1.192 +   (tick)
   1.193 +   (tick)
   1.194 +   (tick)
   1.195 +   (tick)
   1.196 +   (tick)
   1.197 +   (tick)
   1.198 +   (tick)
   1.199 +   (tick)
   1.200 +   (tick)
   1.201 +
   1.202 +   ;;(view-memory 0xD374)
   1.203 +   (tick)
   1.204 +   (tick)
   1.205 +   (tick)
   1.206 +   (tick)
   1.207 +   (tick)
   1.208 +   (tick)
   1.209 +   (tick)
   1.210 +   (tick)
   1.211 +   (tick)
   1.212 +   (tick)
   1.213 +   (tick)
   1.214 +   (tick)
   1.215 +   (tick)
   1.216 +   (tick)
   1.217 +   (tick)
   1.218 +   ;;(view-memory 0xD374)
   1.219 +   (d-tick)
   1.220 +
   1.221 +   (view-register "A" A)
   1.222 +   (view-register "B" B)
   1.223 +   (view-register "C" C))
   1.224 +
   1.225 +)
   1.226 +
   1.227 +
   1.228  (defn dylan []
   1.229    (->
   1.230     (write-mem-dyl)