# HG changeset patch # User Robert McIntyre # Date 1331973822 18000 # Node ID 901ee6b648da516259fee11ee9fd2c4ac3c21a54 # Parent 86f92deacd2ae3bd305949ef002be99ab786f04e preliminary memory bootstrapping program complete. diff -r 86f92deacd2a -r 901ee6b648da clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Sat Mar 17 02:25:48 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 03:43:42 2012 -0500 @@ -667,11 +667,14 @@ 0xCD ;D39D 0xD3 ;D39E ; goto Mode 3 if A == 3 - 0x00 ;D39F - 0x00 ;D3A0 - 0x00 ;D3A1 - 0x00 ;D3A2 - 0x00 ;D3A3 + ;; GOTO Mode 4 (write-memory) if current mode is 4 + 0xFE ;D39F + 0x04 ;D3A0 + + 0xCA ;D3A1 + 0xDB ;D3A2 + 0xD3 ;D3A3 + 0x00 ;D3A4 ;; End of Mode checking, goto beginning 0xC3 ;D3A5 @@ -795,12 +798,18 @@ 0xFA ;D3DB ; load bytes-to-write into A 0x83 ;D3DC 0xD3 ;D3DD + 0x47 ;D3DE ; load A into B + 0xFA ;D3DF ; load bytes-written into A 0x84 ;D3E0 0xD3 ;D3E1 + 0xB8 ;D3E2 ; compare A with B + 0xCA ;D3E3 ; if they are equal, go to cleanup + 0x07 ;D3E4 + 0xD4 ;D3E5 ;; Write Memory Section ;; Write the input-number, interpreted as an 8-bit number, @@ -808,58 +817,75 @@ ;; (+ start-point bytes-written). ;; Then, increment bytes-written by 1. - 0x00 ;D3D6 - 0x00 ;D3D6 - 0x00 ;D3D7 - 0x00 ;D3D8 - 0x00 ;D3D9 - 0x00 ;D3DA - 0x00 ;D3DB - 0x00 ;D3DC - 0x00 ;D3DD - 0x00 ;D3DE - 0x00 ;D3DF - 0x00 ;D3E0 - 0x00 ;D3E1 - 0x00 ;D3E2 - 0x00 ;D3E3 - 0x00 ;D3E4 - 0x00 ;D3E5 - 0x00 ;D3E6 - 0x00 ;D3E7 - 0x00 ;D3E8 - 0x00 ;D3E9 - 0x00 ;D3EA - 0x00 ;D3EB - 0x00 ;D3EC - 0x00 ;D3ED - 0x00 ;D3EE - 0x00 ;D3EF - 0x00 ;D3F0 - 0x00 ;D3F1 - 0x00 ;D3F2 + 0xFA ;D3E6 ; load start-point-high into A + 0x85 ;D3E7 + 0xD3 ;D3E8 + + 0x67 ;D3E9 ; load A into H + + 0xFA ;D3EA ; load start-point-low into A + 0x86 ;D3EB + 0xD3 ;D3EC + + 0x6F ;D3ED ; load A into L + + 0xFA ;D3EE ; load bytes-written into A + 0x84 ;D3EF + 0xD3 ;D3F0 + + 0x00 ;D3F1 ; These are here because + 0x00 ;D3F2 ; I screwed up again. 0x00 ;D3F3 - 0x00 ;D3F4 - 0x00 ;D3F5 - 0x00 ;D3F6 - 0x00 ;D3F7 - 0x00 ;D3F8 - 0x00 ;D3F9 - 0x00 ;D3FA - 0x00 ;D3FB - 0x00 ;D3FC - 0x00 ;D3FD - 0x00 ;D3FE + 0x85 ;D3F4 ; add L to A; store A in L. + 0x6F ;D3F5 + 0x30 ;D3F6 ; If the addition overflowed, + 0x01 ;D3F7 + 0x24 ;D3F8 ; increment H. + ;; Now, HL points to the correct place in memory + + 0xFA ;D3F9 ; load input-number into A + 0x52 ;D3FA + 0xD3 ;D3FB + 0x77 ;D3FC ; load A into (HL) - 0xC3 ; ; Complete Loop - 0x1D ; - 0xD3 ; + 0xFA ;D3FD ; load bytes-written into A + 0x84 ;D3FE + 0xD3 ;D3FF - + 0x3C ;D400 ; increment A + + 0xEA ;D401 ; load A into bytes-written + 0x84 ;D402 + 0xD3 ;D403 + + 0xC3 ;D404 ; go back to beginning. + 0x1D ;D405 + 0xD3 ;D406 + ;; End Write Memory Section + + ;; Mode 4 Cleanup Section + ;; reset bytes-written to 0 + ;; set mode to 0 + 0x3E ;D407 ; load 0 into A + 0x00 ;D408 + + 0xEA ;D409 ; load A into bytes-written + 0x84 ;D40A + 0xD3 ;D40B + + 0xEA ;D40C ; load A into current-mode + 0x82 ;D40D + 0xD3 ;D40E + + 0xC3 ;D40F ; go back to beginning + 0x1D ;D410 + 0xD3 ;D411 + + ;; End Mode 4 ]) @@ -867,12 +893,13 @@ (def frame-count 0xD31F) (def input 0xD352) -(def current-mode 0xD382) -(def bytes-to-write 0xD383) -(def start-point-high 0xD385) -(def start-point-low 0xD386) +(def current-mode 0xD382) +(def bytes-to-write 0xD383) +(def bytes-written 0xD384) +(def start-point-high 0xD385) +(def start-point-low 0xD386) -(def bytes-written 0xD385) + (defn write-memory [] (-> (tick (mid-game)) @@ -906,40 +933,82 @@ (step []) (view-memory frame-count))) -(defn test-mode-2 [] +(defn test-mode-4 [] (-> (write-memory) + (#(do (println "memory from 0xC00F to 0xC01F:" + (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) (view-memory current-mode) (step []) (step []) (step []) (#(do (println "after three steps") %)) (view-memory current-mode) + + ;; Activate memory writing mode + + (#(do (println "step with [:a]") %)) (step [:a]) - (#(do (println "step with [:a]") %)) (view-memory current-mode) (view-memory bytes-to-write) (view-memory start-point-high) (view-memory start-point-low) - (#(do (println "step with [:a :b :start]")%)) - (step [:a :b :start]) + + ;; Specify four bytes to be written + + (#(do (println "step with [:select]")%)) + (step [:select]) (view-memory current-mode) (view-memory bytes-to-write) (view-memory start-point-high) (view-memory start-point-low) + + ;; Specify target memory address as 0xC00F + (#(do (println "step with [:u :d]")%)) (step [:u :d]) (view-memory current-mode) (view-memory bytes-to-write) (view-memory start-point-high) (view-memory start-point-low) - (#(do (println "step with [:u :d :l :r]")%)) - (step [:u :d :l :r]) + + (#(do (println "step with [:a :b :start :select]")%)) + (step [:a :b :start :select]) (view-memory current-mode) (view-memory bytes-to-write) (view-memory start-point-high) (view-memory start-point-low) + + ;; Start reprogramming memory + + (#(do (println "step with [:a]")%)) + (step [:a]) + (view-memory current-mode) + (view-memory bytes-written) + + (#(do (println "step with [:b]")%)) + (step [:b]) + (view-memory current-mode) + (view-memory bytes-written) + + (#(do (println "step with [:a :b]")%)) + (step [:a :b]) + (view-memory current-mode) + (view-memory bytes-written) + + (#(do (println "step with [:select]")%)) + (step [:select]) + (view-memory current-mode) + (view-memory bytes-written) + + ;; Reprogramming done, program ready for more commands. + + (#(do (println "step with []")%)) + (step []) + (view-memory current-mode) + (view-memory bytes-written) - )) + (#(do (println "memory from 0xC00F to 0xC01F:" + (subvec (vec (memory %)) 0xC00F 0xC01F)) %))))