Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/rlm_assembly.clj @ 409:55a45f67e4a4
brought documentation up to date.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 14 Apr 2012 01:32:22 -0500 |
parents | bca0abd39db5 |
children | 0162dd315814 |
comparison
equal
deleted
inserted
replaced
408:7116b3f51ba8 | 409:55a45f67e4a4 |
---|---|
4 (:use (com.aurellem.gb gb-driver assembly util vbm constants)) | 4 (:use (com.aurellem.gb gb-driver assembly util vbm constants)) |
5 (:use (com.aurellem.run bootstrap-1)) | 5 (:use (com.aurellem.run bootstrap-1)) |
6 (:import [com.aurellem.gb.gb_driver SaveState])) | 6 (:import [com.aurellem.gb.gb_driver SaveState])) |
7 | 7 |
8 | 8 |
9 ;; MODE-SELECT | |
10 ;; SET-LENGTH | |
11 ;; SET-TARGET | |
12 ;; WRITE | |
13 ;; JUMP | |
14 | 9 |
15 ;; Specs for Main Bootstrap Program | 10 ;; Specs for Main Bootstrap Program |
16 | 11 |
17 ;; Number-Input | 12 ;; Number-Input |
18 ;; Number input works using all eight buttons to | 13 ;; Number input works using all eight buttons to |
19 ;; spell out an 8 bit number. The order of buttons is | 14 ;; spell out an 8 bit number. The order of buttons is |
20 ;; [:d :u :l :r :start :select :b :a] --> 11111111 | 15 ;; [:d :u :l :r :start :select :b :a] --> 11111111 |
21 ;; [ :l :start :a] --> 00101001 | 16 ;; [ :l :start :a] --> 00101001 |
22 | 17 |
18 ;;; MODES | |
19 ;; There are five modes in total: | |
20 ;; MODE-SELECT | |
21 ;; SET-H | |
22 ;; SET-L | |
23 ;; WRITE | |
24 ;; JUMP | |
25 | |
23 ;;; MODE-SELECT | 26 ;;; MODE-SELECT |
24 ;; The bootstrap program starts in MODE-SELECT mode. | 27 ;; The bootstrap program starts in MODE-SELECT mode. |
25 ;; MODE-SELECT transitions to one of three modes depending | 28 ;; MODE-SELECT transitions to one of three modes depending |
26 ;; on which buttons are pressed: | 29 ;; on which buttons are pressed: |
27 ;; 0 (no-buttons) : MODE-SELECT | 30 ;; 0 : MODE-SELECT |
28 ;; 8 [:start] : WRITE-BYTES | 31 ;; 0x67 : SET-H |
29 ;; 0xFF (all-buttons) : JUMP | 32 ;; 0x6F : SET-L |
33 ;; 0x47 : WRITE | |
34 ;; 0xE9 : JUMP | |
35 | |
36 ;;; SET-H | |
37 ;; SET-H sets the high 8 bits of the target address to which | |
38 ;; data will be written / the program will jump. It expects | |
39 ;; the following: | |
40 ;; | |
41 ;; Byte 0 : New Value of H | |
42 ;; Byte 1 : 0x00 | |
43 | |
44 ;;; SET-L | |
45 ;; This mode sets the low 8 bits of the target address and has | |
46 ;; the same semantics as SET-H. | |
30 | 47 |
31 ;;; WRITE-BYTES | 48 ;;; WRITE-BYTES |
32 | |
33 ;; WRITE-BYTES mode writes sequences of arbitray values to | 49 ;; WRITE-BYTES mode writes sequences of arbitray values to |
34 ;; arbitray memory locations. It expects you to enter a | 50 ;; arbitray memory locations. It expects you to enter a |
35 ;; header of three bytes describing what to write: | 51 ;; header of one byte describing how many bytes to write. |
36 | 52 |
37 ;; Byte 0 : Number of Bytes to Write | 53 ;; Byte 0 : Number of Bytes to Write |
38 ;; Byte 1 : Start Address High Byte | |
39 ;; Byte 1 : Start Address Low Byte | |
40 | 54 |
41 ;; Then, you enter the number of bytes specified in Byte 0 | 55 ;; Then, you enter the number of bytes specified in Byte 0 |
42 ;; they are written to the start address in | 56 ;; and they are written to the start address in sequence. |
43 ;; sequence. After the last byte is written control | 57 ;; After the last byte is written control returns to |
44 ;; returns to MODE-SELECT mode. | 58 ;; MODE-SELECT mode. The Target address will be incremented by |
59 ;; Number of Bytes to Write once you are done writing. | |
45 | 60 |
46 ;; Example: to write the sequence [1 2 3 4] starting at | 61 ;; Example: to write the sequence [1 2 3 4] starting at |
47 ;; address 0xC01F enter | 62 ;; the target address enter: |
48 ;; Byte 0 : 4 (will write four bytes) | 63 ;; Byte 0 : 4 (will write four bytes) |
49 ;; Byte 1 : 0xC0 (high byte of 0xC01F) | |
50 ;; Byte 2 : 0x1F (low byte of 0xC01F) | |
51 ;; Byte 3 : 1 (write 1 to 0xC01F) | 64 ;; Byte 3 : 1 (write 1 to 0xC01F) |
52 ;; Byte 4 : 2 (write 2 to 0xC020) | 65 ;; Byte 4 : 2 (write 2 to 0xC020) |
53 ;; Byte 5 : 3 (write 3 to 0xC021) | 66 ;; Byte 5 : 3 (write 3 to 0xC021) |
54 ;; Byte 6 : 4 (write 4 to 0xC022) | 67 ;; Byte 6 : 4 (write 4 to 0xC022) |
55 | 68 |
56 ;;; JUMP | 69 ;;; JUMP |
57 ;; JUMP mode jumps program control to any arbitray | 70 ;; JUMP mode jumps program control to the target address. |
58 ;; location. It expects you to enter two bytes which | 71 |
59 ;; correspond to the high and low bytes of the memory | 72 ;;; EXAMPLE |
60 ;; address to which you want to jump. | 73 ;; To write the infinite loop program [0x18 0xFE] to address |
61 ;; Byte 0 : Jump Address High Byte | 74 ;; 0xC00F and then jump to said program, enter the following |
62 ;; Byte 1 : Jump Address Low Byte | 75 ;; starting from MODE-SELECT mode. |
63 | 76 |
64 ;; Example: to jump to address 0x1234 enter | 77 ;; Byte 0 : 0x67 [:a :b :l :u :select] ;; SET-H mode |
65 ;; Byte 0 : 0x12 (high byte of 0x1234) | 78 ;; Byte 1 : 0xC0 [:d :u] ;; 0xC0 -> H |
66 ;; Byte 1 : 0x34 (low byte of 0x1234) | 79 ;; Byte 2 : 0x00 [] ;; trailer |
67 | 80 |
81 ;; Byte 3 : 0x6F [:a :start :b :l :u :select] ;; SET-L mode | |
82 ;; Byte 4 : 0x0F [:a :start :b :select] ;; 0x0F -> L | |
83 ;; Byte 5 : 0x00 [] ;; trailer | |
84 | |
85 ;; Byte 6 : 0x47 [:a :b :u :select] ;; WRITE-MODE | |
86 ;; Byte 7 : 0x02 [:b] ;; write 2 bytes | |
87 ;; Byte 8 : 0x18 [:r :start] ;; assembly | |
88 ;; Byte 9 : 0xFE [:r :start :b :d :l :u :select] ;; assembly | |
89 | |
90 ;; target address is now 0xC011 since we wrote 2 bytes. | |
91 ;; set it back to 0xC00F. | |
92 | |
93 ;; Byte 10 : 0x6F [:a :start :b :l :u :select] ;; SET-L mode | |
94 ;; Byte 12 : 0x0F [:a :start :b :select] ;; 0x0F -> L | |
95 ;; Byte 13 : 0x00 [] ;; trailer | |
96 | |
97 ;; Byte 14 : 0xE9 ;; JUMP-MODE | |
68 | 98 |
69 (defn ->signed-8-bit [n] | 99 (defn ->signed-8-bit [n] |
70 (if (< n 0) | 100 (if (< n 0) |
71 (+ 256 n) n)) | 101 (+ 256 n) n)) |
72 | 102 |
363 (step (buttons write-mode)) | 393 (step (buttons write-mode)) |
364 (step (buttons 4)) ; write 4 bytes | 394 (step (buttons 4)) ; write 4 bytes |
365 (step (buttons (nth assembly 0))) | 395 (step (buttons (nth assembly 0))) |
366 (step (buttons (nth assembly 1))) | 396 (step (buttons (nth assembly 1))) |
367 (step (buttons (nth assembly 2))) | 397 (step (buttons (nth assembly 2))) |
368 (step (buttons (nth assembly 3))) | 398 (step (buttons (nth assembly 3))))] |
369 (step []) | |
370 (step []) | |
371 (step []))] | |
372 ;;(println "before :" (get-mem-region before)) | 399 ;;(println "before :" (get-mem-region before)) |
373 ;;(println "after :" (get-mem-region after)) | 400 ;;(println "after :" (get-mem-region after)) |
374 ;;(assert (= assembly (take 4 (get-mem-region after)))) | 401 ;;(assert (= assembly (take 4 (get-mem-region after)))) |
375 (println "write-test-passed.") | 402 (println "write-test-passed.") |
376 after)) | 403 after)) |