diff 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
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj	Fri Apr 13 11:33:56 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj	Sat Apr 14 01:32:22 2012 -0500
     1.3 @@ -6,11 +6,6 @@
     1.4    (:import [com.aurellem.gb.gb_driver SaveState]))
     1.5  
     1.6  
     1.7 -;; MODE-SELECT
     1.8 -;; SET-LENGTH
     1.9 -;; SET-TARGET
    1.10 -;; WRITE
    1.11 -;; JUMP
    1.12  
    1.13  ;; Specs for Main Bootstrap Program
    1.14  
    1.15 @@ -20,51 +15,86 @@
    1.16  ;;   [:d :u :l :r :start :select :b :a]  -->  11111111
    1.17  ;;   [      :l    :start            :a]  -->  00101001
    1.18  
    1.19 +;;; MODES
    1.20 +;; There are five modes in total:
    1.21 +;;   MODE-SELECT
    1.22 +;;   SET-H
    1.23 +;;   SET-L
    1.24 +;;   WRITE
    1.25 +;;   JUMP
    1.26 +
    1.27  ;;; MODE-SELECT
    1.28  ;;   The bootstrap program starts in MODE-SELECT mode.
    1.29  ;;   MODE-SELECT transitions to one of three modes depending
    1.30  ;;   on which buttons are pressed:
    1.31 -;;       0   (no-buttons)  :  MODE-SELECT
    1.32 -;;       8   [:start]      :  WRITE-BYTES
    1.33 -;;    0xFF   (all-buttons) :  JUMP
    1.34 +;;       0   :  MODE-SELECT
    1.35 +;;    0x67   :  SET-H
    1.36 +;;    0x6F   :  SET-L
    1.37 +;;    0x47   :  WRITE
    1.38 +;;    0xE9   :  JUMP
    1.39 +
    1.40 +;;; SET-H
    1.41 +;;   SET-H sets the high 8 bits of the target address to which
    1.42 +;;   data will be written / the program will jump.  It expects
    1.43 +;;   the following:
    1.44 +;;
    1.45 +;;    Byte 0 : New Value of H
    1.46 +;;    Byte 1 : 0x00
    1.47 +
    1.48 +;;; SET-L
    1.49 +;;   This mode sets the low 8 bits of the target address and has
    1.50 +;;   the same semantics as SET-H.
    1.51  
    1.52  ;;; WRITE-BYTES
    1.53 -
    1.54  ;;   WRITE-BYTES mode writes sequences of arbitray values to
    1.55  ;;   arbitray memory locations. It expects you to enter a
    1.56 -;;   header of three bytes describing what to write:
    1.57 +;;   header of one byte describing how many bytes to write.
    1.58  
    1.59  ;;    Byte 0  : Number of Bytes to Write
    1.60 -;;    Byte 1  : Start Address High Byte
    1.61 -;;    Byte 1  : Start Address Low  Byte
    1.62  
    1.63  ;;   Then, you enter the number of bytes specified in Byte 0
    1.64 -;;   they are written to the start address in
    1.65 -;;   sequence. After the last byte is written control
    1.66 -;;   returns to MODE-SELECT mode.
    1.67 +;;   and they are written to the start address in sequence.
    1.68 +;;   After the last byte is written control returns to
    1.69 +;;   MODE-SELECT mode. The Target address will be incremented by
    1.70 +;;   Number of Bytes to Write once you are done writing.
    1.71  
    1.72  ;;   Example: to write the sequence [1 2 3 4] starting at
    1.73 -;;   address 0xC01F enter
    1.74 +;;   the target address enter:
    1.75  ;;    Byte 0  : 4 (will write four bytes)
    1.76 -;;    Byte 1  : 0xC0  (high byte of 0xC01F)
    1.77 -;;    Byte 2  : 0x1F  (low  byte of 0xC01F)
    1.78  ;;    Byte 3  : 1 (write 1 to 0xC01F)
    1.79  ;;    Byte 4  : 2 (write 2 to 0xC020)
    1.80  ;;    Byte 5  : 3 (write 3 to 0xC021)
    1.81  ;;    Byte 6  : 4 (write 4 to 0xC022)
    1.82  
    1.83  ;;; JUMP 
    1.84 -;;   JUMP mode jumps program control to any arbitray
    1.85 -;;   location. It expects you to enter two bytes which
    1.86 -;;   correspond to the high and low bytes of the memory
    1.87 -;;   address to which you want to jump.
    1.88 -;;    Byte 0  : Jump Address High Byte
    1.89 -;;    Byte 1  : Jump Address Low  Byte
    1.90 +;;   JUMP mode jumps program control to the target address.
    1.91  
    1.92 -;;   Example: to jump to address 0x1234 enter
    1.93 -;;    Byte 0  : 0x12 (high byte of 0x1234)
    1.94 -;;    Byte 1  : 0x34 (low  byte of 0x1234)
    1.95 +;;; EXAMPLE
    1.96 +;;   To write the infinite loop program [0x18 0xFE] to address
    1.97 +;;   0xC00F and then jump to said program, enter the following
    1.98 +;;   starting from MODE-SELECT mode.
    1.99  
   1.100 +;;    Byte 0  : 0x67 [:a :b :l :u :select]        ;; SET-H mode
   1.101 +;;    Byte 1  : 0xC0 [:d :u]                      ;; 0xC0 -> H
   1.102 +;;    Byte 2  : 0x00 []                           ;; trailer
   1.103 +
   1.104 +;;    Byte 3  : 0x6F [:a :start :b :l :u :select] ;; SET-L mode
   1.105 +;;    Byte 4  : 0x0F [:a :start :b :select]       ;; 0x0F -> L
   1.106 +;;    Byte 5  : 0x00 []                           ;; trailer
   1.107 +
   1.108 +;;    Byte 6  : 0x47 [:a :b :u :select]           ;; WRITE-MODE
   1.109 +;;    Byte 7  : 0x02 [:b]                         ;; write 2 bytes
   1.110 +;;    Byte 8  : 0x18 [:r :start]                  ;; assembly
   1.111 +;;    Byte 9  : 0xFE [:r :start :b :d :l :u :select] ;; assembly
   1.112 +
   1.113 +;;    target address is now 0xC011 since we wrote 2 bytes.
   1.114 +;;    set it back to 0xC00F.
   1.115 +
   1.116 +;;    Byte 10 : 0x6F [:a :start :b :l :u :select] ;; SET-L mode
   1.117 +;;    Byte 12 : 0x0F [:a :start :b :select]       ;; 0x0F -> L
   1.118 +;;    Byte 13 : 0x00 []                           ;; trailer
   1.119 +
   1.120 +;;    Byte 14 : 0xE9                              ;; JUMP-MODE
   1.121  
   1.122  (defn ->signed-8-bit [n]
   1.123    (if (< n 0)
   1.124 @@ -365,10 +395,7 @@
   1.125              (step (buttons (nth assembly 0)))
   1.126              (step (buttons (nth assembly 1)))
   1.127              (step (buttons (nth assembly 2)))
   1.128 -            (step (buttons (nth assembly 3)))
   1.129 -            (step [])
   1.130 -            (step [])
   1.131 -            (step []))]
   1.132 +            (step (buttons (nth assembly 3))))]
   1.133      ;;(println "before :" (get-mem-region before))
   1.134      ;;(println "after  :" (get-mem-region after))
   1.135      ;;(assert (= assembly (take 4 (get-mem-region after))))