# HG changeset patch # User Robert McIntyre # Date 1331962174 18000 # Node ID c9a280b8bd1cfc7c21e4c29d617666ee7fd172d3 # Parent e85b53994fac0c93f94724bf1da89244a744c6b0 saving progress. diff -r e85b53994fac -r c9a280b8bd1c clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Fri Mar 16 20:55:28 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 00:29:34 2012 -0500 @@ -181,9 +181,7 @@ 0xCA ;D32B ; if bit-0 is not 1 0x44 ;D32C ; GOTO not-v-blank 0xD3 ;D32D - ;;; in v-blank mode - ;; if v-blank-prev was 0, ;; increment frame-count @@ -443,107 +441,125 @@ (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) (defn write-memory-assembly [] - [0x18 ;D31D ; jump over - 0x02 ;D31E ; the next 2 bytes - 0x00 ;D31F ; frame-count - 0x00 ;D320 ; v-blank-prev + [ + ;; Main Timing Loop + ;; Constantly check for v-blank and Trigger main state machine on + ;; every transtion from v-blank to non-v-blank. - 0xFA ;D321 - 0x41 ;D322 ; load (FF41) into A - 0xFF ;D323 ; this contains mode flags + 0x18 ; D31D ; Variable declaration + 0x02 ; D31E + 0x00 ; D31F ; frame-count + 0x00 ; D320 ; v-blank-prev + + 0xFA ; D321 ; load v-blank mode flags into A + 0x41 ; D322 + 0xFF ; D323 + + ;; Branch dependent on v-blank. v-blank happens when the last two + ;; bits in A are "01" + 0xCB ; D324 + 0x4F ; D325 + + 0xC2 ; D326 ; if bit-1 is not 0, then + 0x44 ; D327 ; GOTO non-v-blank. + 0xD3 ; D328 + + 0xCB ; D329 + 0x47 ; D32A + + 0xCA ; D32B ; if bit-0 is not 1, then + 0x44 ; D32C ; GOTO non-v-blank. + 0xD3 ; D32D + + ;; V-Blank + ;; Activate state-machine if this is a transition event. + + 0xFA ; D32E ; load v-bank-prev into A + 0x20 ; D32F + 0xD3 ; D330 + + 0xFE ; D331 ; compare A to 0. + 0x00 ; D332 + + ;; set v-blank-prev to 1. + 0x3E ; D333 ; load 1 into A. + 0x01 ; D334 - ;; if we're in v-blank, the bit-1 is 0 - ;; and bit-2 is 1 Otherwise, it is not v-blank. - 0xCB ;D324 ; test bit-1 of A - 0x4F ;D325 + 0xEA ; D335 ; load A into v-blank-prev + 0x20 ; D336 + 0xD3 ; D337 - 0xC2 ;D326 ; if bit-1 is not 0 - 0x44 ;D327 ; GOTO not-v-blank - 0xD3 ;D328 + ;; if v-blank-prev was 0, activate state-machine + 0xC2 ; D338 ; if v-blank-prev + 0x46 ; D339 ; was 0, + 0xD3 ; D33A ; GOTO state-machine + + 0xC3 ; D33B + 0x1D ; D33C + 0xD3 ; D33D ; GOTO beginning + ;; END V-blank + + ;; Non-V-Blank + ;; Set v-blank-prev to 0 + 0x3E ; D33E ; load 0 into A + 0x00 ; D33F + + 0xEA ; D340 ; load A into v-blank-prev + 0x20 ; D341 + 0xD3 ; D342 - 0xCB ;D329 ; test bit-0 of A - 0x47 ;D32A + 0xC3 ; D343 + 0x1D ; D344 + 0xD3 ; D345 ; GOTO beginning + ;; END Not-V-Blank - 0xCA ;D32B ; if bit-0 is not 1 - 0x44 ;D32C ; GOTO not-v-blank - 0xD3 ;D32D + ;; Main State Machine -- Input Section + ;; This is called once every frame. + ;; It collects input and uses it to drive the + ;; state transitions. + + ;; Increment frame-count + 0xFA ; D346 ; load frame-count into A + 0x1F ; D347 + 0xD3 ; D348 - ;;; in v-blank mode + 0x3C ; D349 ; inc A - ;; if v-blank-prev was 0, - ;; increment frame-count + 0xEA ; D34A + 0x1F ; D34B ; load A into frame-count + 0xD3 ; D34C - 0xFA ;D32E ; load v-blank-prev to A - 0x20 ;D32F - 0xD3 ;D330 + 0x00 ; D34D ; glue :) + + + ;;;;;;;;; BEGIN RLM DEBUG + 0xC3 ;; jump to beginning + 0x1D + 0xD3 - 0xCB ;D331 - 0x47 ;D332 ; test bit-0 of A + ;;;;;;;;; END RLM DEBUG - 0x20 ;D333 ; skip next section - 0x07 ;D334 ; if v-blank-prev was not zero - ;; v-blank was 0, increment frame-count - 0xFA ;D335 ; load frame-count into A - 0x1F ;D336 - 0xD3 ;D337 - - 0x3C ;D338 ; inc A - - 0xEA ;D339 ; load A into frame-count - 0x1F ;D33A - 0xD3 ;D33B - - ;; set v-blank-prev to 1 - 0x3E ;D33C ; load 1 into A - 0x01 ;D33D - - 0xEA ;D33E ; load A into v-blank-prev - 0x20 ;D33F - 0xD3 ;D340 - - 0xC3 ;D341 ; GOTO input handling code - 0x4E ;D342 - 0xD3 ;D343 - - ;;; not in v-blank mode - ;; set v-blank-prev to 0 - 0x3E ;D344 ; load 0 into A - 0x00 ;D345 - - 0xEA ;D346 ; load A into v-blank-prev - 0x20 ;D347 - 0xD3 ;D348 - - 0xC3 ;D349 ; return to beginning - 0x1D ;D34A - 0xD3 ;D34B - - 0x00 ;D34C ; these are here - 0x00 ;D34D ; for glue - - - ;;; calculate input number based on button presses 0x18 ;D34E ; skip next 3 bytes 0x03 ;D34F - ;D350 + ;D350 (Integer/parseInt "00100000" 2) ; select directional pad - ;D351 + ;D351 (Integer/parseInt "00010000" 2) ; select buttons 0x00 ;D352 ; input-number - ;; select directional pad, store low bits in B + ;; select directional pad; store low bits in B 0xFA ;D353 ; load (D350) into A 0x50 ;D354 --> - 0xD3 ;D355 --> D31F + 0xD3 ;D355 --> D350 0xEA ;D356 ; load (A), which is 0x00 ;D357 --> ; 00010000, into FF00 0xFF ;D358 --> FF00 0x06 ;D359 - ;D35A + ;D35A (Integer/parseInt "11110000" 2) ; "11110000" -> B 0xFA ;D35B ; (FF00) -> A 0x00 ;D35C @@ -554,11 +570,11 @@ 0xA0 ;D360 ; (AND A B) -> A 0x47 ;D361 ; A -> B - ;; select buttons store bottom bits in C + ;; select buttons; store bottom bits in C 0xFA ;D362 ; load (D351) into A 0x51 ;D363 --> - 0xD3 ;D364 --> D31F + 0xD3 ;D364 --> D351 0xEA ;D365 ; load (A), which is 0x00 ;D366 --> ; 00001000, into FF00 @@ -584,11 +600,9 @@ 0x52 ;D373 0xD3 ;D374 - 0xC3 ;D375 ; GOTO state machine - ;;0x1D - 0x80 ;D376 + 0xC3 ;D375 ; secret jump :) + 0x1D ;D376 0xD3 ;D377 - 0x00 ;D378 0x00 ;D379 0x00 ;D37A @@ -761,6 +775,7 @@ ]) + (def frame-count 0xD31F) (def input 0xD352) (def current-mode 0xD382) @@ -782,12 +797,14 @@ (defn test-mode-2 [] (-> (write-memory) - (view-memory bytes-to-write) - (view-memory start-point) + (view-memory frame-count) (step) (step [:a]) (step [:b]) (step [:start]) (step []) - (view-memory bytes-to-write) - (view-memory start-point))) \ No newline at end of file + (view-memory frame-count))) + + + +