comparison clojure/com/aurellem/gb/dylan_assembly.clj @ 376:7c89fe478de4

modifying dylan's assembly bootstrap program so that my primitive item-writer program can write it to memory.
author Robert McIntyre <rlm@mit.edu>
date Wed, 11 Apr 2012 09:14:51 -0500
parents 19fd38fe376e
children 1f14c1b8af7e
comparison
equal deleted inserted replaced
375:ce74088cd953 376:7c89fe478de4
1 (ns com.aurellem.gb.dylan-assembly 1 (ns com.aurellem.gb.dylan-assembly
2 "A much more compact version of write-memory-assembly" 2 "A much more compact version of write-memory-assembly"
3 {:author "Dylan Holmes"} 3 {:author "Dylan Holmes"}
4 (:use (com.aurellem.gb gb-driver assembly util)) 4 (:use (com.aurellem.gb gb-driver assembly util))
5 (:import [com.aurellem.gb.gb_driver SaveState])) 5 (:import [com.aurellem.gb.gb_driver SaveState]))
6
7 ;; Specs for main bootstrap program
8
9 ;; Number-Input
10 ;; Number input works using all eight buttons to
11 ;; spell out an 8 bit number. The order of buttons is
12 ;; [:d :u :l :r :start :select :b :a] --> 11111111
13 ;; [ :l :start :a] --> 00101001
14
15 ;;; MODE-SELECT
16 ;; The bootstrap program starts in MODE-SELECT mode.
17 ;; MODE-SELECT transitions to one of three modes depending
18 ;; on which buttons are pressed:
19 ;; 0 (no-buttons) : MODE-SELECT
20 ;; 8 [:start] : WRITE-BYTES
21 ;; 0xFF (all-buttons) : JUMP
22
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
6 61
7 (defn write-memory-assembly-compact 62 (defn write-memory-assembly-compact
8 "Currently, grabs input from the user each frame." 63 "Currently, grabs input from the user each frame."
9 [] 64 []
10 [ 65 [
178 233
179 (defn drive-compact [] 234 (defn drive-compact []
180 (-> (write-mem-compact) 235 (-> (write-mem-compact)
181 (#(do (println "memory from 0xC00F to 0xC01F:" 236 (#(do (println "memory from 0xC00F to 0xC01F:"
182 (subvec (vec (memory %)) 0xC00F 0xC01F)) %)) 237 (subvec (vec (memory %)) 0xC00F 0xC01F)) %))
183 (step []) 238 (step []) ; make sure it can handle blanks
184 (step []) 239 (step []) ; at the beginning.
185 (step []) 240 (step [])
186 (step [:start]) 241 (step [:start]) ;
187 (step [:select]) 242 (step [:select])
188 (step [:u :d]) 243 (step [:u :d])
189 (step [:a :b :start :select]) 244 (step [:a :b :start :select])
190 (step [:a]) 245 (step [:a])
191 (step [:b]) 246 (step [:b])