# HG changeset patch # User Robert McIntyre # Date 1331876608 18000 # Node ID 0831da75d2c5fe1bfad293fdec5d2a8db975e8a0 # Parent 6fe33bb5ea221df8f8a485ac32373206a0dd3e96 completed frame-counting machine language program with dylan's help diff -r 6fe33bb5ea22 -r 0831da75d2c5 clojure/com/aurellem/assembly.clj --- a/clojure/com/aurellem/assembly.clj Thu Mar 15 17:29:49 2012 -0500 +++ b/clojure/com/aurellem/assembly.clj Fri Mar 16 00:43:28 2012 -0500 @@ -74,7 +74,7 @@ (binary-str (aget (memory state) mem)))) state) -(defn read-buttons [] +(defn read-down-button [] (-> (tick (mid-game)) (IE! 0) ; disable interrupts (inject-item-assembly @@ -82,7 +82,8 @@ ;; write 00010000 to 0xFF00 to select joypad [0x18 ;D31D ; jump over 0x01 ;D31E ; the next 8 bits - (Integer/parseInt "00100000" 2) ;D31F data section + ;D31F + (Integer/parseInt "00100000" 2) ; data section 0xFA ;D320 ; load (D31F) into A 0x1F ;D321 --> @@ -123,8 +124,120 @@ [])))) + +;; specs for main bootstrap program +;; starts in "mode-select" mode +;; Each button press takes place in a single frame. +;; mode-select-mode takes one of the main buttons +;; which selects one of up to eight modes +;; mode 1 activated by the "A" button +;; the next two button presses indicates the start +;; memory location which to which the bootstrap +;; program will write. +;; This is done by using each of the eight buttons to +;; spell out an 8 bit number. The order of buttons is +;; ["A" "B" "start" "select" "up" "right" "down" "left"], +;; [:a :start :l] --> 10100001 + +;; the next button press determines how many bytes are to be +;; written, starting at the start position. + +;; then, the actual bytes are entered and are written to the +;; start address in sequence. + + +(defn count-frames [] + (-> (tick (mid-game)) + (IE! 0) ; disable interrupts + (inject-item-assembly + ;; write 00010000 to 0xFF00 to select joypad + [0x18 ;D31D ; jump over + 0x02 ;D31E ; the next 2 bytes + 0x00 ;D31F ; frame-count + 0x00 ;D320 ; v-blank-prev + + 0xFA ;D321 + 0x41 ;D322 ; load (FF41) into A + 0xFF ;D323 ; this contains mode flags + + + + ;; 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 + + 0xC2 ;D326 ; if bit-1 is not 0 + 0x43 ;D327 ; GOTO not-v-blank + 0xD3 ;D328 + + 0xCB ;D329 ; test bit-0 of A + 0x47 ;D32A + + 0xCA ;D32B ; if bit-0 is not 1 + 0x43 ;D32C ; GOTO not-v-blank + 0xD3 ;D32D + + ;; in v-blank mode + + ;; if v-blank-prev was 0, + ;; increment frame-count + + 0xFA ;D32E ; load v-blank-prev to A + 0x20 ;D32F + 0xD3 ;D330 + + 0xCB ;D331 + 0x47 ;D332 ; test bit-0 of A + + 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? to 1 + 0x3E ;D33C ; load 1 into A + 0x01 ;D33D + + 0xEA ;D33E ; load A into v-blank-prev + 0x20 ;D33F + 0xD3 ;D340 + + 0x18 ;D341 ; skip not-in-v-blank section + 0x05 ;D342 + + ;; not in v-blank mode + ;; set b-blank? to 0 + 0x3E ;D343 ; load 0 into A + 0x00 ;D344 + + 0xEA ;D345 ; load A into v-blank-prev + 0x20 ;D346 + 0xD3 ;D347 + + + 0xC3 ;D348 ; return to beginning + 0x1D ;D349 + 0xD3 ;D34A + + + + ]))) + + + + (defn run-a-bit [] - (-> (read-buttons) + (-> (read-down-button) (info) (tick) ;; skip over data section (info)