changeset 127:901ee6b648da

preliminary memory bootstrapping program complete.
author Robert McIntyre <rlm@mit.edu>
date Sat, 17 Mar 2012 03:43:42 -0500
parents 86f92deacd2a
children 203d64e16156
files clojure/com/aurellem/assembly.clj
diffstat 1 files changed, 131 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/assembly.clj	Sat Mar 17 02:25:48 2012 -0500
     1.2 +++ b/clojure/com/aurellem/assembly.clj	Sat Mar 17 03:43:42 2012 -0500
     1.3 @@ -667,11 +667,14 @@
     1.4     0xCD   ;D39D
     1.5     0xD3   ;D39E                    ; goto Mode 3 if A == 3
     1.6  
     1.7 -   0x00   ;D39F
     1.8 -   0x00   ;D3A0
     1.9 -   0x00   ;D3A1
    1.10 -   0x00   ;D3A2
    1.11 -   0x00   ;D3A3
    1.12 +   ;; GOTO Mode 4 (write-memory) if current mode is 4
    1.13 +   0xFE   ;D39F
    1.14 +   0x04   ;D3A0
    1.15 +
    1.16 +   0xCA   ;D3A1
    1.17 +   0xDB   ;D3A2
    1.18 +   0xD3   ;D3A3
    1.19 +
    1.20     0x00   ;D3A4
    1.21     ;; End of Mode checking, goto beginning
    1.22     0xC3   ;D3A5
    1.23 @@ -795,12 +798,18 @@
    1.24     0xFA   ;D3DB                   ; load bytes-to-write into A
    1.25     0x83   ;D3DC
    1.26     0xD3   ;D3DD
    1.27 +
    1.28     0x47   ;D3DE                   ; load A into B
    1.29 +
    1.30     0xFA   ;D3DF                   ; load bytes-written into A
    1.31     0x84   ;D3E0
    1.32     0xD3   ;D3E1
    1.33 +
    1.34     0xB8   ;D3E2                   ; compare A with B
    1.35 +
    1.36     0xCA   ;D3E3                   ; if they are equal, go to cleanup
    1.37 +   0x07   ;D3E4                   
    1.38 +   0xD4   ;D3E5                   
    1.39  
    1.40     ;;  Write Memory Section
    1.41     ;;    Write the input-number, interpreted as an 8-bit number,
    1.42 @@ -808,58 +817,75 @@
    1.43     ;;    (+ start-point bytes-written).
    1.44     ;;    Then, increment bytes-written by 1.
    1.45     
    1.46 -   0x00   ;D3D6
    1.47 -   0x00   ;D3D6                   
    1.48 -   0x00   ;D3D7                   
    1.49 -   0x00   ;D3D8                   
    1.50 -   0x00   ;D3D9                   
    1.51 -   0x00   ;D3DA                   
    1.52 -   0x00   ;D3DB                   
    1.53 -   0x00   ;D3DC                   
    1.54 -   0x00   ;D3DD                   
    1.55 -   0x00   ;D3DE                   
    1.56 -   0x00   ;D3DF                   
    1.57 -   0x00   ;D3E0                   
    1.58 -   0x00   ;D3E1                   
    1.59 -   0x00   ;D3E2                   
    1.60 -   0x00   ;D3E3                   
    1.61 -   0x00   ;D3E4                   
    1.62 -   0x00   ;D3E5                   
    1.63 -   0x00   ;D3E6                   
    1.64 -   0x00   ;D3E7                   
    1.65 -   0x00   ;D3E8                   
    1.66 -   0x00   ;D3E9                   
    1.67 -   0x00   ;D3EA                   
    1.68 -   0x00   ;D3EB                   
    1.69 -   0x00   ;D3EC                   
    1.70 -   0x00   ;D3ED                   
    1.71 -   0x00   ;D3EE                   
    1.72 -   0x00   ;D3EF                   
    1.73 -   0x00   ;D3F0                   
    1.74 -   0x00   ;D3F1                   
    1.75 -   0x00   ;D3F2                   
    1.76 +   0xFA   ;D3E6                   ; load start-point-high into A
    1.77 +   0x85   ;D3E7                   
    1.78 +   0xD3   ;D3E8                   
    1.79 +
    1.80 +   0x67   ;D3E9                   ; load A into H
    1.81 +
    1.82 +   0xFA   ;D3EA                   ; load start-point-low into A
    1.83 +   0x86   ;D3EB                   
    1.84 +   0xD3   ;D3EC
    1.85 +   
    1.86 +   0x6F   ;D3ED                   ; load A into L
    1.87 +   
    1.88 +   0xFA   ;D3EE                   ; load bytes-written into A
    1.89 +   0x84   ;D3EF                   
    1.90 +   0xD3   ;D3F0                   
    1.91 +   
    1.92 +   0x00   ;D3F1                   ; These are here because
    1.93 +   0x00   ;D3F2                   ; I screwed up again.
    1.94     0x00   ;D3F3                   
    1.95 -   0x00   ;D3F4                   
    1.96 -   0x00   ;D3F5                   
    1.97 -   0x00   ;D3F6                   
    1.98 -   0x00   ;D3F7                   
    1.99 -   0x00   ;D3F8                   
   1.100 -   0x00   ;D3F9                   
   1.101 -   0x00   ;D3FA                   
   1.102 -   0x00   ;D3FB                   
   1.103 -   0x00   ;D3FC                   
   1.104 -   0x00   ;D3FD                   
   1.105 -   0x00   ;D3FE                   
   1.106  
   1.107 +   0x85   ;D3F4                   ; add L to A; store A in L.
   1.108 +   0x6F   ;D3F5                   
   1.109  
   1.110 +   0x30   ;D3F6                   ; If the addition overflowed,
   1.111 +   0x01   ;D3F7                   
   1.112 +   0x24   ;D3F8                   ; increment H.
   1.113  
   1.114 +   ;;   Now, HL points to the correct place in memory
   1.115 +   
   1.116 +   0xFA   ;D3F9                   ; load input-number into A
   1.117 +   0x52   ;D3FA                   
   1.118 +   0xD3   ;D3FB                   
   1.119  
   1.120 +   0x77   ;D3FC                   ; load A into (HL)
   1.121  
   1.122 -   0xC3   ;                        ; Complete Loop
   1.123 -   0x1D   ;    
   1.124 -   0xD3   ;    
   1.125 +   0xFA   ;D3FD                   ; load bytes-written into A
   1.126 +   0x84   ;D3FE                   
   1.127 +   0xD3   ;D3FF                   
   1.128  
   1.129 -   
   1.130 +   0x3C   ;D400                   ; increment A
   1.131 +
   1.132 +   0xEA   ;D401                   ; load A into bytes-written
   1.133 +   0x84   ;D402                   
   1.134 +   0xD3   ;D403
   1.135 +
   1.136 +   0xC3   ;D404                   ; go back to beginning.
   1.137 +   0x1D   ;D405
   1.138 +   0xD3   ;D406
   1.139 +   ;;  End Write Memory Section
   1.140 +
   1.141 +   ;;  Mode 4 Cleanup Section
   1.142 +   ;;    reset bytes-written to 0
   1.143 +   ;;    set mode to 0
   1.144 +   0x3E   ;D407                   ; load 0 into A
   1.145 +   0x00   ;D408                  
   1.146 +
   1.147 +   0xEA   ;D409                   ; load A into bytes-written
   1.148 +   0x84   ;D40A                   
   1.149 +   0xD3   ;D40B                   
   1.150 +
   1.151 +   0xEA   ;D40C                   ; load A into current-mode
   1.152 +   0x82   ;D40D                   
   1.153 +   0xD3   ;D40E                   
   1.154 +
   1.155 +   0xC3   ;D40F                    ; go back to beginning
   1.156 +   0x1D   ;D410
   1.157 +   0xD3   ;D411
   1.158 +
   1.159 +   ;; End Mode 4
   1.160     
   1.161     ])
   1.162  
   1.163 @@ -867,12 +893,13 @@
   1.164  
   1.165  (def frame-count 0xD31F)
   1.166  (def input 0xD352)
   1.167 -(def current-mode 0xD382)
   1.168 -(def bytes-to-write 0xD383)
   1.169 -(def start-point-high 0xD385)
   1.170 -(def start-point-low 0xD386)
   1.171 +(def current-mode      0xD382)
   1.172 +(def bytes-to-write    0xD383)
   1.173 +(def bytes-written     0xD384)
   1.174 +(def start-point-high  0xD385)
   1.175 +(def start-point-low   0xD386)
   1.176  
   1.177 -(def bytes-written 0xD385)
   1.178 +
   1.179  
   1.180  (defn write-memory []
   1.181    (-> (tick (mid-game))
   1.182 @@ -906,40 +933,82 @@
   1.183     (step [])
   1.184     (view-memory frame-count)))
   1.185  
   1.186 -(defn test-mode-2 []
   1.187 +(defn test-mode-4 []
   1.188    (->
   1.189     (write-memory)
   1.190 +   (#(do (println "memory from 0xC00F to 0xC01F:"
   1.191 +                  (subvec (vec (memory %)) 0xC00F 0xC01F)) %))
   1.192     (view-memory current-mode)
   1.193     (step [])
   1.194     (step [])
   1.195     (step [])
   1.196     (#(do (println "after three steps") %))
   1.197     (view-memory current-mode)
   1.198 +
   1.199 +   ;; Activate memory writing mode
   1.200 +   
   1.201 +   (#(do (println "step with [:a]") %))
   1.202     (step [:a])
   1.203 -   (#(do (println "step with [:a]") %))
   1.204     (view-memory current-mode)
   1.205     (view-memory bytes-to-write)
   1.206     (view-memory start-point-high)
   1.207     (view-memory start-point-low)
   1.208 -   (#(do (println "step with [:a :b :start]")%))
   1.209 -   (step [:a :b :start])
   1.210 +
   1.211 +   ;; Specify four bytes to be written
   1.212 +   
   1.213 +   (#(do (println "step with [:select]")%))
   1.214 +   (step [:select])
   1.215     (view-memory current-mode)
   1.216     (view-memory bytes-to-write)
   1.217     (view-memory start-point-high)
   1.218     (view-memory start-point-low)
   1.219 +
   1.220 +   ;; Specify target memory address as 0xC00F
   1.221 +   
   1.222     (#(do (println "step with [:u :d]")%))
   1.223     (step [:u :d])
   1.224     (view-memory current-mode)
   1.225     (view-memory bytes-to-write)
   1.226     (view-memory start-point-high)
   1.227     (view-memory start-point-low)
   1.228 -   (#(do (println "step with [:u :d :l :r]")%))
   1.229 -   (step [:u :d :l :r])
   1.230 +
   1.231 +   (#(do (println "step with [:a :b :start :select]")%))
   1.232 +   (step [:a :b :start :select])
   1.233     (view-memory current-mode)
   1.234     (view-memory bytes-to-write)
   1.235     (view-memory start-point-high)
   1.236     (view-memory start-point-low)
   1.237 +
   1.238 +   ;; Start reprogramming memory
   1.239 +
   1.240 +   (#(do (println "step with [:a]")%))
   1.241 +   (step [:a])
   1.242 +   (view-memory current-mode)
   1.243 +   (view-memory bytes-written)
   1.244 +
   1.245 +   (#(do (println "step with [:b]")%))
   1.246 +   (step [:b])
   1.247 +   (view-memory current-mode)
   1.248 +   (view-memory bytes-written)
   1.249 +
   1.250 +   (#(do (println "step with [:a :b]")%))
   1.251 +   (step [:a :b])
   1.252 +   (view-memory current-mode)
   1.253 +   (view-memory bytes-written)
   1.254 +
   1.255 +   (#(do (println "step with [:select]")%))
   1.256 +   (step [:select])
   1.257 +   (view-memory current-mode)
   1.258 +   (view-memory bytes-written)
   1.259 +
   1.260 +   ;; Reprogramming done, program ready for more commands.
   1.261 +
   1.262 +   (#(do (println "step with []")%))
   1.263 +   (step [])
   1.264 +   (view-memory current-mode)
   1.265 +   (view-memory bytes-written)
   1.266     
   1.267 -   ))
   1.268 +   (#(do (println "memory from 0xC00F to 0xC01F:"
   1.269 +                  (subvec (vec (memory %)) 0xC00F 0xC01F)) %))))
   1.270  
   1.271