Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 377:1f14c1b8af7e
working on main bootstrap program
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 11 Apr 2012 10:47:27 -0500 |
parents | |
children | 5c4a30521d09 |
comparison
equal
deleted
inserted
replaced
376:7c89fe478de4 | 377:1f14c1b8af7e |
---|---|
1 (ns com.aurellem.gb.rlm-assembly | |
2 "Version of main bootstrap program that is valid output for the | |
3 item-writer program." | |
4 (:use (com.aurellem.gb gb-driver assembly util vbm constants)) | |
5 (:use (com.aurellem.run bootstrap-1)) | |
6 (:import [com.aurellem.gb.gb_driver SaveState])) | |
7 | |
8 ;; Specs for Main Bootstrap Program | |
9 | |
10 ;; Number-Input | |
11 ;; Number input works using all eight buttons to | |
12 ;; spell out an 8 bit number. The order of buttons is | |
13 ;; [:d :u :l :r :start :select :b :a] --> 11111111 | |
14 ;; [ :l :start :a] --> 00101001 | |
15 | |
16 ;;; MODE-SELECT | |
17 ;; The bootstrap program starts in MODE-SELECT mode. | |
18 ;; MODE-SELECT transitions to one of three modes depending | |
19 ;; on which buttons are pressed: | |
20 ;; 0 (no-buttons) : MODE-SELECT | |
21 ;; 8 [:start] : WRITE-BYTES | |
22 ;; 0xFF (all-buttons) : JUMP | |
23 | |
24 ;;; WRITE-BYTES | |
25 | |
26 ;; WRITE-BYTES mode writes sequences of arbitray values to | |
27 ;; arbitray memory locations. It expects you to enter a | |
28 ;; header of three bytes describing what to write: | |
29 | |
30 ;; Byte 0 : Number of Bytes to Write | |
31 ;; Byte 1 : Start Address High Byte | |
32 ;; Byte 1 : Start Address Low Byte | |
33 | |
34 ;; Then, you enter the number of bytes specified in Byte 0 | |
35 ;; they are written to the start address in | |
36 ;; sequence. After the last byte is written control | |
37 ;; returns to MODE-SELECT mode. | |
38 | |
39 ;; Example: to write the sequence [1 2 3 4] starting at | |
40 ;; address 0xC01F enter | |
41 ;; Byte 0 : 4 (will write four bytes) | |
42 ;; Byte 1 : 0xC0 (high byte of 0xC01F) | |
43 ;; Byte 2 : 0x1F (low byte of 0xC01F) | |
44 ;; Byte 3 : 1 (write 1 to 0xC01F) | |
45 ;; Byte 4 : 2 (write 2 to 0xC020) | |
46 ;; Byte 5 : 3 (write 3 to 0xC021) | |
47 ;; Byte 6 : 4 (write 4 to 0xC022) | |
48 | |
49 ;;; JUMP | |
50 ;; JUMP mode jumps program control to any arbitray | |
51 ;; location. It expects you to enter two bytes which | |
52 ;; correspond to the high and low bytes of the memory | |
53 ;; address to which you want to jump. | |
54 ;; Byte 0 : Jump Address High Byte | |
55 ;; Byte 1 : Jump Address Low Byte | |
56 | |
57 ;; Example: to jump to address 0x1234 enter | |
58 ;; Byte 0 : 0x12 (high byte of 0x1234) | |
59 ;; Byte 1 : 0x34 (low byte of 0x1234) | |
60 | |
61 | |
62 | |
63 (defn main-bootstrap-program [start-address] | |
64 (let [[start-high start-low] (disect-bytes-2 start-address)] | |
65 [0xF3 0x18 0xFE])) | |
66 | |
67 ;;;;;; TESTS ;;;;;; | |
68 | |
69 (defn bootstrap-base [] | |
70 (let [program (main-bootstrap-program pokemon-list-start)] | |
71 ;; make sure program is valid output for item-writer | |
72 (bootstrap-pattern program) | |
73 (-> (tick (mid-game)) | |
74 (set-memory-range pokemon-list-start program) | |
75 (PC! pokemon-list-start)))) | |
76 | |
77 (defn test-write-bytes-mode [] | |
78 (let [target-address 0xC00F | |
79 [target-high target-low] (disect-bytes-2 target-address) | |
80 assembly [0xF3 0x18 0xFE 0x12] | |
81 get-mem-region #(subvec (vec (memory %)) | |
82 target-address (+ target-address 20)) | |
83 before (bootstrap-base) | |
84 after | |
85 (-> before | |
86 (step []) ; make sure it can handle blanks | |
87 (step []) ; at the beginning. | |
88 (step []) | |
89 (step [:start]) ; select WRITE-BYTES mode | |
90 (step (buttons 4)) ; write 4 bytes | |
91 (step (buttons target-high)) | |
92 (step (buttons target-low)) | |
93 (step (buttons (nth assembly 0))) | |
94 (step (buttons (nth assembly 1))) | |
95 (step (buttons (nth assembly 2))) | |
96 (step (buttons (nth assembly 3))) | |
97 (step []) | |
98 (step []) | |
99 (step []))] | |
100 (println "before :" (get-mem-region before)) | |
101 (println "after :" (get-mem-region after)) | |
102 (assert (= assembly (take 4 (get-mem-region after)))) | |
103 after)) | |
104 | |
105 (defn test-jump-mode [] | |
106 (let [target-address 0xC00F | |
107 [target-high target-low] (disect-bytes-2 target-address) | |
108 post-jump | |
109 (-> (test-write-bytes-mode) | |
110 (step []) | |
111 (step []) | |
112 (step []) | |
113 (step (buttons 0xFF)) ; Select JUMP mode. | |
114 (step (buttons target-high)) | |
115 (step (buttons target-low))) | |
116 program-counters | |
117 (capture-program-counter | |
118 post-jump | |
119 10000)] | |
120 (println program-counters) | |
121 (assert (contains? (set program-counters) target-address)) | |
122 post-jump)) |