Mercurial > vba-clojure
view clojure/com/aurellem/assembly.clj @ 125:d2e00c923bad
need to add another mode to handle 16 bit start point
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 17 Mar 2012 02:00:02 -0500 |
parents | f8dadd9478a5 |
children | 86f92deacd2a |
line wrap: on
line source
1 (ns com.aurellem.assembly2 (:use (com.aurellem gb-driver vbm title items))3 (:import [com.aurellem.gb_driver SaveState]))5 (defn mid-game []6 (read-state "mid-game"))8 (defn inject-assembly9 ([^SaveState state10 program-counter registers11 assembly-code]12 (let [scratch-memory (memory state)]13 ;; inject assembly code14 (dorun (map (fn [index val]15 (aset scratch-memory index val))16 (range program-counter17 (+ program-counter (count assembly-code)))18 assembly-code))19 (-> state20 (write-memory! scratch-memory)21 (write-registers! registers)22 (PC! program-counter)))))24 (defn inject-item-assembly25 ([^SaveState state assembly-code]26 (inject-assembly state (inc item-list-start)27 (registers state)28 assembly-code))29 ([assembly-code]30 (inject-item-assembly @current-state assembly-code)))32 (defn info33 ([^SaveState state]34 (println (format "PC: 0x%04X" (PC state)))35 (println "Instruction:"36 (format "0x%02X" (aget (memory state) (PC state))))37 state))39 (defn print-interrupt40 [^SaveState state]41 (println (format "IE: %d" (IE state)))42 state)44 (defn print-listing [state begin end]45 (dorun (map46 (fn [opcode line]47 (println (format "0x%04X: 0x%02X" line opcode)))48 (subvec (vec (memory state)) begin end)49 (range begin end)))50 state)52 (defn run-assembly53 ([info-fn assembly n]54 (let [final-state55 (reduce (fn [state _]56 (tick (info-fn state)))57 (inject-item-assembly58 (mid-game) assembly)59 (range n))]60 final-state))61 ([assembly n]62 (run-assembly info assembly n)))64 (def buttons-port 0xFF00)66 (defn A [state]67 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8))69 (defn binary-str [num]70 (format "%08d"71 (Integer/parseInt72 (Integer/toBinaryString num) 10)))74 (defn view-register [state name reg-fn]75 (println (format "%s: %s" name76 (binary-str (reg-fn state))))77 state)79 (defn view-memory [state mem]80 (println (format "mem 0x%04X = %s" mem81 (binary-str (aget (memory state) mem))))82 state)84 (defn trace [state]85 (loop [program-counters [(first (registers @current-state)) ]86 opcodes [(aget (memory @current-state) (PC @current-state))]]87 (let [frame-boundary?88 (com.aurellem.gb.Gb/tick)]89 (if frame-boundary?90 [program-counters opcodes]91 (recur92 (conj program-counters93 (first (registers @current-state)))94 (conj opcodes95 (aget (memory @current-state)96 (PC @current-state))))))))98 (defn print-trace [state n]99 (let [[program-counters opcodes] (trace state)]100 (dorun (map (fn [pc op] (println (format "%04X: 0x%02X" pc op)))101 (take n program-counters)102 (take n opcodes)))))104 (defn good-trace []105 (-> (mid-game) (tick) (IE! 0)106 (set-inv-mem [0x00 0x00 0X00 0x00])107 (PC! item-list-start)(print-interrupt)108 (info) (tick) (info) (tick) (info)))110 (defn read-down-button []111 (-> (tick (mid-game))112 (IE! 0) ; disable interrupts113 (inject-item-assembly114 ;; write 00010000 to 0xFF00 to select joypad115 [0x18 ;D31D ; jump over116 0x01 ;D31E ; the next 8 bits117 ;D31F118 (Integer/parseInt "00100000" 2) ; data section120 0xFA ;D320 ; load (D31F) into A121 0x1F ;D321 -->122 0xD3 ;D322 --> D31F124 0xEA ;D323 ; load (A), which is125 0x00 ;D324 --> ; 00010000, into FF00126 0xFF ;D325 --> FF00128 0x18 ;D326 ; this is the place where129 0x01 ;D327 ; we will store whether130 0x00 ;D328 ; "down" is pressed.132 0xFA ;D329 ; (FF00) -> A133 0x00 ;D32A134 0xFF ;D32B136 0xCB ;D32C ; Test whether "down"137 0x5F ;D32D ; is pressed.139 0x28 ;D32E ; if down is pressed,140 0x03 ;D32F ; skip the next section141 ; of code.142 ;; down-is-not-pressed143 0xC3 ;D330144 0x1D ;D331 ; return to beginning145 0xD3 ;D332147 ;; down-is-pressed148 0xEA ;D334 ; write A to D328 if149 0x28 ;D335 ; "down" was pressed150 0xD3 ;D336152 0xC3 ;D330153 0x1D ;D331 ; return to beginning154 0xD3 ;D332155 ])))157 (defn test-read-down []158 (= (view-memory (step (step (read-down-button) [:d])) 0xD328)159 (view-memory (step (step (read-down-button))) 0xD328)))161 (defn count-frames []162 (-> (tick (mid-game))163 (IE! 0) ; disable interrupts164 (inject-item-assembly165 [0x18 ;D31D ; jump over166 0x02 ;D31E ; the next 2 bytes167 0x00 ;D31F ; frame-count168 0x00 ;D320 ; v-blank-prev170 0xFA ;D321171 0x41 ;D322 ; load (FF41) into A172 0xFF ;D323 ; this contains mode flags174 ;; if we're in v-blank, the bit-1 is 0175 ;; and bit-2 is 1 Otherwise, it is not v-blank.176 0xCB ;D324 ; test bit-1 of A177 0x4F ;D325179 0xC2 ;D326 ; if bit-1 is not 0180 0x44 ;D327 ; GOTO not-v-blank181 0xD3 ;D328183 0xCB ;D329 ; test bit-0 of A184 0x47 ;D32A186 0xCA ;D32B ; if bit-0 is not 1187 0x44 ;D32C ; GOTO not-v-blank188 0xD3 ;D32D189 ;;; in v-blank mode190 ;; if v-blank-prev was 0,191 ;; increment frame-count193 0xFA ;D32E ; load v-blank-prev to A194 0x20 ;D32F195 0xD3 ;D330197 0xCB ;D331198 0x47 ;D332 ; test bit-0 of A200 0x20 ;D333 ; skip next section201 0x07 ;D334 ; if v-blank-prev was not zero203 ;; v-blank was 0, increment frame-count204 0xFA ;D335 ; load frame-count into A205 0x1F ;D336206 0xD3 ;D337208 0x3C ;D338 ; inc A210 0xEA ;D339 ; load A into frame-count211 0x1F ;D33A212 0xD3 ;D33B214 ;; set v-blank-prev to 1215 0x3E ;D33C ; load 1 into A216 0x01 ;D33D218 0xEA ;D33E ; load A into v-blank-prev219 0x20 ;D33F220 0xD3 ;D340222 0xC3 ;D341 ; return to beginning223 0x1D ;D342224 0xD3 ;D343226 ;;; not in v-blank mode227 ;; set v-blank-prev to 0228 0x3E ;D344 ; load 0 into A229 0x00 ;D345231 0xEA ;D346 ; load A into v-blank-prev232 0x20 ;D347233 0xD3 ;D348235 0xC3 ;D349 ; return to beginning236 0x1D ;D34A237 0xD3 ;D34B238 ])))240 (defn step-count-frames []241 (-> (read-down-button)242 (info)243 (tick) ;; skip over data section244 (info)245 (view-register "Register A" A)246 (tick) ;; load-data into A247 (view-register "Register A" A)248 (info)249 (view-memory 0xFF00)250 (tick) ;; load A into 0xFF00251 (view-memory 0xFF00)252 (info)253 (tick)254 (info)255 (tick)256 (info)257 (tick)258 (info)259 (tick)260 (info)261 (tick)262 (info)263 (tick)264 (print-inventory)))266 (defn test-count-frames []267 (= 255 (aget (memory ((apply comp (repeat 255 step))268 (count-frames)))269 0xD31F)))271 ;; specs for main bootstrap program272 ;; starts in "mode-select" mode273 ;; Each button press takes place in a single frame.274 ;; mode-select-mode takes one of the main buttons275 ;; which selects one of up to eight modes276 ;; mode 1 activated by the "A" button277 ;; the next two button presses indicates the start278 ;; memory location which to which the bootstrap279 ;; program will write.280 ;; This is done by using each of the eight buttons to281 ;; spell out an 8 bit number. The order of buttons is282 ;; [:d :u :l :r :start :select :b :a]283 ;; [:a :start :l] --> 00101001285 ;; the next button press determines how many bytes are to be286 ;; written, starting at the start position.288 ;; then, the actual bytes are entered and are written to the289 ;; start address in sequence.291 (defn input-number-assembly []292 [0x18 ;D31D ; jump over293 0x02 ;D31E ; the next 2 bytes294 0x00 ;D31F ; frame-count295 0x00 ;D320 ; v-blank-prev297 0xFA ;D321298 0x41 ;D322 ; load (FF41) into A299 0xFF ;D323 ; this contains mode flags301 ;; if we're in v-blank, the bit-1 is 0302 ;; and bit-2 is 1 Otherwise, it is not v-blank.303 0xCB ;D324 ; test bit-1 of A304 0x4F ;D325306 0xC2 ;D326 ; if bit-1 is not 0307 0x44 ;D327 ; GOTO not-v-blank308 0xD3 ;D328310 0xCB ;D329 ; test bit-0 of A311 0x47 ;D32A313 0xCA ;D32B ; if bit-0 is not 1314 0x44 ;D32C ; GOTO not-v-blank315 0xD3 ;D32D317 ;;; in v-blank mode319 ;; if v-blank-prev was 0,320 ;; increment frame-count322 0xFA ;D32E ; load v-blank-prev to A323 0x20 ;D32F324 0xD3 ;D330326 0xCB ;D331327 0x47 ;D332 ; test bit-0 of A329 0x20 ;D333 ; skip next section330 0x07 ;D334 ; if v-blank-prev was not zero332 ;; v-blank was 0, increment frame-count333 0xFA ;D335 ; load frame-count into A334 0x1F ;D336335 0xD3 ;D337337 0x3C ;D338 ; inc A339 0xEA ;D339 ; load A into frame-count340 0x1F ;D33A341 0xD3 ;D33B343 ;; set v-blank-prev to 1344 0x3E ;D33C ; load 1 into A345 0x01 ;D33D347 0xEA ;D33E ; load A into v-blank-prev348 0x20 ;D33F349 0xD3 ;D340351 0xC3 ;D341 ; GOTO input handling code352 0x4E ;D342353 0xD3 ;D343355 ;;; not in v-blank mode356 ;; set v-blank-prev to 0357 0x3E ;D344 ; load 0 into A358 0x00 ;D345360 0xEA ;D346 ; load A into v-blank-prev361 0x20 ;D347362 0xD3 ;D348364 0xC3 ;D349 ; return to beginning365 0x1D ;D34A366 0xD3 ;D34B368 0x00 ;D34C ; these are here369 0x00 ;D34D ; for glue372 ;;; calculate input number based on button presses373 0x18 ;D34E ; skip next 3 bytes374 0x03 ;D34F375 ;D350376 (Integer/parseInt "00100000" 2) ; select directional pad377 ;D351378 (Integer/parseInt "00010000" 2) ; select buttons379 0x00 ;D352 ; input-number381 ;; select directional pad, store low bits in B383 0xFA ;D353 ; load (D350) into A384 0x50 ;D354 -->385 0xD3 ;D355 --> D31F387 0xEA ;D356 ; load (A), which is388 0x00 ;D357 --> ; 00010000, into FF00389 0xFF ;D358 --> FF00391 0x06 ;D359392 ;D35A393 (Integer/parseInt "11110000" 2) ; "11110000" -> B394 0xFA ;D35B ; (FF00) -> A395 0x00 ;D35C396 0xFF ;D35D398 0xCB ;D35E ; swap nybbles on A399 0x37 ;D35F400 0xA0 ;D360 ; (AND A B) -> A401 0x47 ;D361 ; A -> B403 ;; select buttons store bottom bits in C405 0xFA ; ; load (D351) into A406 0x51 ; -->407 0xD3 ; --> D31F409 0xEA ; ; load (A), which is410 0x00 ; --> ; 00001000, into FF00411 0xFF ; --> FF00413 0x0E ;414 (Integer/parseInt "00001111" 2) ; "00001111" -> C416 0xFA ; ; (FF00) -> A417 0x00 ;418 0xFF ;420 0xA1 ; ; (AND A C) -> A421 0x4F ; ; A -> C423 ;; combine the B and C registers into the input number424 0x79 ; ; C -> A425 0xB0 ; ; (OR A B) -> A426 0x2F ; ; negate A428 0xEA ; ; store A into input-number429 0x52 ;430 0xD3 ;432 0xC3 ; ; return to beginning433 0x1D ;434 0xD3 ;435 ])437 (defn input-number []438 (-> (tick (mid-game))439 (IE! 0) ; disable interrupts440 (inject-item-assembly (input-number-assembly))))442 (defn test-input-number443 "Input freestyle buttons and observe the effects at the repl."444 []445 (set-state! (input-number))446 (dotimes [_ 90000] (step (view-memory @current-state 0xD352))))448 (defn write-memory-assembly []450 [451 ;; Main Timing Loop452 ;; Constantly check for v-blank and Trigger main state machine on453 ;; every transtion from v-blank to non-v-blank.455 0x18 ; D31D ; Variable declaration456 0x02 ; D31E457 0x00 ; D31F ; frame-count458 0x00 ; D320 ; v-blank-prev460 0xFA ; D321 ; load v-blank mode flags into A461 0x41 ; D322462 0xFF ; D323464 ;; Branch dependent on v-blank. v-blank happens when the last two465 ;; bits in A are "01"466 0xCB ; D324467 0x4F ; D325469 0xC2 ; D326 ; if bit-1 is not 0, then470 0x3E ; D327 ; GOTO non-v-blank.471 0xD3 ; D328473 0xCB ; D329474 0x47 ; D32A476 0xCA ; D32B ; if bit-0 is not 1, then477 0x3E ; D32C ; GOTO non-v-blank.478 0xD3 ; D32D480 ;; V-Blank481 ;; Activate state-machine if this is a transition event.483 0xFA ; D32E ; load v-bank-prev into A484 0x20 ; D32F485 0xD3 ; D330487 0xFE ; D331 ; compare A to 0. >--------\488 0x00 ; D332 \489 ; |490 ;; set v-blank-prev to 1. |491 0x3E ; D333 ; load 1 into A. |492 0x01 ; D334 |493 ; |494 0xEA ; D335 ; load A into v-blank-prev |495 0x20 ; D336 |496 0xD3 ; D337 |497 ; /498 ;; if v-blank-prev was 0, activate state-machine <------/499 0xCA ; D338 ; if v-blank-prev500 0x46 ; D339 ; was 0,501 0xD3 ; D33A ; GOTO state-machine503 0xC3 ; D33B504 0x1D ; D33C505 0xD3 ; D33D ; GOTO beginning506 ;; END V-blank508 ;; Non-V-Blank509 ;; Set v-blank-prev to 0510 0x3E ; D33E ; load 0 into A511 0x00 ; D33F513 0xEA ; D340 ; load A into v-blank-prev514 0x20 ; D341515 0xD3 ; D342517 0xC3 ; D343518 0x1D ; D344519 0xD3 ; D345 ; GOTO beginning520 ;; END Not-V-Blank523 ;; Main State Machine -- Input Section524 ;; This is called once every frame.525 ;; It collects input and uses it to drive the526 ;; state transitions.528 ;; Increment frame-count529 0xFA ; D346 ; load frame-count into A530 0x1F ; D347531 0xD3 ; D348533 0x3C ; D349 ; inc A535 0xEA ; D34A536 0x1F ; D34B ; load A into frame-count537 0xD3 ; D34C539 0x00 ; D34D ; glue :)542 ;;;;;;;;; BEGIN RLM DEBUG543 ;;0xC3 ;; jump to beginning544 ;;0x1D545 ;;0xD3546 ;;;;;;;;; END RLM DEBUG549 0x18 ;D34E ; skip next 3 bytes550 0x03 ;D34F551 ;D350552 (Integer/parseInt "00100000" 2) ; select directional pad553 ;D351554 (Integer/parseInt "00010000" 2) ; select buttons555 0x00 ;D352 ; input-number557 ;; select directional pad; store low bits in B559 0xFA ;D353 ; load (D350) into A560 0x50 ;D354 -->561 0xD3 ;D355 --> D350563 0xEA ;D356 ; load (A), which is564 0x00 ;D357 --> ; 00010000, into FF00565 0xFF ;D358 --> FF00567 0x06 ;D359568 ;D35A569 (Integer/parseInt "11110000" 2) ; "11110000" -> B570 0xFA ;D35B ; (FF00) -> A571 0x00 ;D35C572 0xFF ;D35D574 0xCB ;D35E ; swap nybbles on A575 0x37 ;D35F576 0xA0 ;D360 ; (AND A B) -> A577 0x47 ;D361 ; A -> B579 ;; select buttons; store bottom bits in C581 0xFA ;D362 ; load (D351) into A582 0x51 ;D363 -->583 0xD3 ;D364 --> D351585 0xEA ;D365 ; load (A), which is586 0x00 ;D366 --> ; 00001000, into FF00587 0xFF ;D367 --> FF00589 0x0E ;D368590 ;D369591 (Integer/parseInt "00001111" 2) ; "00001111" -> C593 0xFA ;D36A ; (FF00) -> A594 0x00 ;D36B595 0xFF ;D36C597 0xA1 ;D36D ; (AND A C) -> A598 0x4F ;D36E ; A -> C600 ;; combine the B and C registers into the input number601 0x79 ;D36F ; C -> A602 0xB0 ;D370 ; (OR A B) -> A603 0x2F ;D371 ; negate A605 0xEA ;D372 ; store A into input-number606 0x52 ;D373607 0xD3 ;D374609 0x00 ;D375610 0x00 ;D376611 0x00 ;D377612 0x00 ;D378613 0x00 ;D379614 0x00 ;D37A615 0x00 ;D37B ; these are here because616 0x00 ;D37C ; I messed up :(617 0x00 ;D37D618 0x00 ;D37E619 0x00 ;D37F621 ;; beginning of main state machine622 0x18 ;D380 ; Declaration of variables623 0x05 ;D381 ; 5 variables:624 0x00 ;D382 ; current-mode625 0x00 ;D383 ; bytes-to-write626 0x00 ;D384 ; start-point627 0x00 ;D385 ; bytes-written628 0x00 ;D386 ; unused631 ;; banch on current mode632 0xFA ;D387 ; load current-mode (0xD382)633 0x82 ;D388 ; into A634 0xD3 ;D389635 0x00 ;D38A638 ;; GOTO Mode 0 (input-mode) if current-mode is 0639 0xFE ;D38B640 0x00 ;D38C ; compare A with 0x00642 0xCA ;D38D ; goto Mode 0 if A == 0643 0xA8 ;D38E644 0xD3 ;D38F646 ;; GOTO Mode 1 (set-length) if current-mode is 1647 0xFE ;D390648 0x01 ;D391 ; compare A with 0x01650 0xCA ;D392651 0xB1 ;D393652 0xD3 ;D394 ; goto Mode 1 if A == 1654 ;; GOTO Mode 2 (set-start-point) if current mode is 2655 0xFE ;D395656 0x02 ;D396 ; compare A with 0x02658 0xCA ;D397659 0xBF ;D398660 0xD3 ;D399 ; goto Mode 2 if A == 2662 ;; GOTO Mode 3 (write-memory) if current mode is 3663 0xFE ;D39A664 0x03 ;D39B666 0x00 ;D39C667 0xCA ;D39D668 0xXX ;D39E669 0xXX ;D39F670 0x00 ;D3A0671 0x00 ;D3A1672 0x00 ;D3A2673 0x00 ;D3A3674 0x00 ;D3A4675 ;; End of Mode checking, goto beginning676 0xC3 ;D3A5677 0x1D ;D3A6678 0xD3 ;D3A7681 ;; Mode 0 -- input-mode mode682 ;; means that we are waiting for a mode, so set the mode to683 ;; whatever is currently in input-number. If nothing is684 ;; entered, then the program stays in input-mode mode686 ;; set current-mode to input-number687 0xFA ;D3A8 ; load input-number (0xD352)688 0x52 ;D3A9 ; into A689 0xD3 ;D3AA691 0xEA ;D3AB ; load A into current-mode692 0x82 ;D3AC ; (0xD382)693 0xD3 ;D3AD695 0xC3 ;D3AE ; go back to beginning696 0x1D ;D3AF697 0xD3 ;D3B0698 ;; End Mode 0701 ;; Mode 1 -- set-length mode702 ;; This is the header for writing things to memory.703 ;; User specifies the number of bytes to write.704 ;; Mode is auto advanced to Mode 2 after this mode705 ;; completes.707 ;; Set bytes left to write to input-number;708 ;; set current-mode to 0x02.709 0xFA ;D3B1 ; load input-number (0xD352)710 0x52 ;D3B2 ; into A711 0xD3 ;D3B3713 0xEA ;D3B4 ; load A into bytes-left-to-write714 0x83 ;D3B5 ; (0xD383)715 0xD3 ;D3B6717 0x3E ;D3B7 ; load 0x02 into A.718 0x02 ;D3B8720 0xEA ;D3B9 ; load A to current-mode721 0x82 ;D3BA ; advancing from Mode 1 to722 0xD3 ;D3BB ; Mode 2724 0xC3 ;D3BC ; go back to beginning725 0x1D ;D3BD726 0xD3 ;D3BE727 ;; End Mode 1730 ;; Mode 2 -- set start-point mode731 ;; Final part of the header for writing things to memory.732 ;; User specifies the start location in RAM to which733 ;; data will be written.734 ;; Mode is auto advanced to Mode 3 after this mode completes.736 ;; Set start-point to input-number;737 ;; set current mode to 0x03.738 0xFA ;D3BF ; load input-number (0xD352)739 0x52 ;D3C0 ; into A740 0xD3 ;D3C1742 0xEA ;D3C2 ; load A into start-point743 0x84 ;D3C3 ; (0xD384)744 0xD3 ;D3C4746 0x3E ;D3C5 ; load 0x03 into A.747 0x03 ;D3C6749 0xEA ;D3C7 ; load A to current-mode,750 0x82 ;D3C8 ; advancing from Mode 2 to751 0xD3 ;D3C9 ; Mode 3.753 0xC3 ;D3CA ; go back to beginning754 0x1D ;D3CB755 0xD3 ;D3CC756 ;;End Mode 2759 ;; Mode 3 -- write bytes mode761 ;; This is where RAM manipulation happens. User supplies762 ;; bytes every frame, which are written sequentially to763 ;; start-point until bytes-to-write have been written. Once764 ;; bytes-to-write have been written, the mode is reset to 0.766 ;; compare bytes-written with bytes-to-write.767 ;; if they are the same, then reset mode to 0769 0xFA ;D3CD ; load bytes-to-write into A770 0x83 ;D3CE771 0xD3 ;D3CF773 0x47 ;D3D0 ; load A into B775 0xFA ;D3D1 ; load bytes-written into A776 0x82 ;D3D2777 0xD3 ;D3D3779 0xB8 ;D3D4 ; compare A with B781 0xCA ;D3D5 ; if they are equal, go to cleanup783 ;; Write Memory Section784 ;; Write the input-number, interpreted as an 8-bit number,785 ;; into the current target register, determined by786 ;; (+ start-point bytes-written).787 ;; Then, increment bytes-written by 1.789 0x00 ;D3D6790 0x00 ;D3D6791 0x00 ;D3D7792 0x00 ;D3D8793 0x00 ;D3D9794 0x00 ;D3DA795 0x00 ;D3DB796 0x00 ;D3DC797 0x00 ;D3DD798 0x00 ;D3DE799 0x00 ;D3DF800 0x00 ;D3E0801 0x00 ;D3E1802 0x00 ;D3E2803 0x00 ;D3E3804 0x00 ;D3E4805 0x00 ;D3E5806 0x00 ;D3E6807 0x00 ;D3E7808 0x00 ;D3E8809 0x00 ;D3E9810 0x00 ;D3EA811 0x00 ;D3EB812 0x00 ;D3EC813 0x00 ;D3ED814 0x00 ;D3EE815 0x00 ;D3EF816 0x00 ;D3F0817 0x00 ;D3F1818 0x00 ;D3F2819 0x00 ;D3F3820 0x00 ;D3F4821 0x00 ;D3F5822 0x00 ;D3F6823 0x00 ;D3F7824 0x00 ;D3F8825 0x00 ;D3F9826 0x00 ;D3FA827 0x00 ;D3FB828 0x00 ;D3FC829 0x00 ;D3FD830 0x00 ;D3FE836 0xC3 ; ; Complete Loop837 0x1D ;838 0xD3 ;842 ])846 (def frame-count 0xD31F)847 (def input 0xD352)848 (def current-mode 0xD382)849 (def bytes-to-write 0xD383)850 (def start-point 0xD384)851 (def bytes-written 0xD385)853 (defn write-memory []854 (-> (tick (mid-game))855 (IE! 0) ; disable interrupts856 (inject-item-assembly (write-memory-assembly))))858 (defn test-write-memory []859 (set-state! (write-memory))860 (dorun861 (dotimes [_ 5000]862 (view-memory (step @current-state) current-mode))))864 (def bytes-to-write 0xD383)865 (def start-point 0xD384)867 (defn print-blank-assembly868 [start end]869 (dorun870 (map871 #(println (format "0x00 ;%04X " %))872 (range start end))))874 (defn test-mode-2 []875 (->876 (write-memory)877 (view-memory frame-count)878 (step)879 (step [:a])880 (step [:b])881 (step [:start])882 (step [])883 (view-memory frame-count)))885 (defn test-mode-2 []886 (->887 (write-memory)888 (view-memory current-mode)889 (step [])890 (step [])891 (step [])892 (#(do (println "after three steps") %))893 (view-memory current-mode)894 (step [:a])895 (#(do (println "step with [:a]") %))896 (view-memory current-mode)897 (view-memory bytes-to-write)898 (view-memory start-point)899 (#(do (println "step with [:u :d :l :r]")%))900 (step [:u :d :l :r])901 (view-memory current-mode)902 (view-memory bytes-to-write)903 (view-memory start-point)904 (#(do (println "step with [:u :d]")%))905 (step [:u :d])906 (view-memory current-mode)907 (view-memory bytes-to-write)908 (view-memory start-point)910 ))