Mercurial > vba-clojure
changeset 392:309614263aa9
saving progress....
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 12 Apr 2012 00:52:19 -0500 |
parents | 2e9b2d27f32f |
children | b21d28e6c966 |
files | clojure/com/aurellem/gb/rlm_assembly.clj |
diffstat | 1 files changed, 59 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 00:20:16 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj Thu Apr 12 00:52:19 2012 -0500 1.3 @@ -211,7 +211,7 @@ 1.4 1.5 (let [[start-high start-low] (disect-bytes-2 start-address) 1.6 jump-distance (+ (count (frame-metronome)) 1.7 - (read-user-input)) 1.8 + (count (read-user-input))) 1.9 1.10 init 1.11 [0xAF 0x5F 0x57 0x47] ;; 0->A; 0->E; 0->D; 0->B 1.12 @@ -226,20 +226,17 @@ 1.13 1.14 0x20 ;; skip input section if 1.15 :to-output ;; we're not in input mode 1.16 - 1.17 - 1.18 + 1.19 :to-be-executed 1.20 - 1.21 1.22 - ;; write mode to instruction to be executed (pun) 1.23 + ;; write mode to instruction-to-be-executed (pun) 1.24 0xEA 1.25 :to-be-executed-address 1.26 0x18 ;; return 1.27 - :to-beginning] 1.28 - 1.29 + :to-beginning-1] 1.30 + 1.31 output 1.32 - [0x05 ;; DEC bytes-to-write (B) 1.33 - 1.34 + [:output-start ;; just a label 1.35 0x54 ;; 1.36 0x5D ;; HL->DE \ 1.37 ;; | 1.38 @@ -248,40 +245,66 @@ 1.39 ;; | any repeating nybbles 1.40 0x23 ;; inc HL / 1.41 1.42 - ] 1.43 + 1.44 + 0x05 ;; DEC bytes-to-write (B) 1.45 + 0x20 ;; if there are no more bytes to write, 1.46 + 0x04 1.47 + 0xAF ;; put a no op (0x00) in to-be-executed 1.48 + 0xEA 1.49 + :to-be-executed-address 1.50 + 1.51 + 0x18 1.52 + :to-beginning-2] 1.53 + 1.54 + symbol-index 1.55 + (fn [symbol sequence] 1.56 + (count (take-while 1.57 + (partial not= symbol) 1.58 + sequence))) 1.59 1.60 - 1.61 - 1.62 + symbols 1.63 + {:to-be-executed-address 1.64 + (disect-bytes-2 1.65 + (+ start-address jump-distance 1.66 + (count init) 1.67 + (symbol-index :to-be-executed input))) 1.68 + :to-be-executed 0x3F} ;; clear carry flag no-op 1.69 1.70 - 1.71 + program** (flatten 1.72 + (replace 1.73 + symbols 1.74 + (concat init (frame-metronome) 1.75 + (read-user-input) 1.76 + input output))) 1.77 + resolve-internal-jumps 1.78 + {:output-start [] 1.79 + :to-output 1.80 + (->signed-8-bit 1.81 + (- (symbol-index :output-start program**) 1.82 + (symbol-index :to-output program**)))} 1.83 1.84 - 0x22 ;; A->(HL) ; inc HL 1.85 + program* 1.86 + (flatten (replace resolve-internal-jumps program**)) 1.87 + 1.88 + resolve-external-jumps 1.89 + {:to-beginning-1 1.90 + (->signed-8-bit 1.91 + (+ -2 (- (symbol-index :to-beginning-1 program*)))) 1.92 + :to-beginning-2 1.93 + (->signed-8-bit 1.94 + (+ -2 (- (symbol-index :to-beginning-2 program*))))} 1.95 1.96 - 1.97 - 1.98 - 1.99 - 1.100 - 1.101 - ;; HL = here 1.102 - ;; add C to HL 1.103 - ;; jp HL 1.104 - 1.105 -]])) 1.106 - 1.107 - 1.108 - 1.109 - 1.110 - 1.111 + program 1.112 + (replace resolve-external-jumps program*)] 1.113 + program)) 1.114 1.115 1.116 -(comment 1.117 - 1.118 ;;;;;; TESTS ;;;;;; 1.119 1.120 (defn bootstrap-base [] 1.121 (let [program (main-bootstrap-program pokemon-list-start)] 1.122 ;; make sure program is valid output for item-writer 1.123 - (bootstrap-pattern program) 1.124 + ;;(bootstrap-pattern program) 1.125 (-> (tick (mid-game)) 1.126 (set-memory-range pokemon-list-start program) 1.127 (PC! pokemon-list-start)))) 1.128 @@ -295,11 +318,11 @@ 1.129 before (bootstrap-base) 1.130 after 1.131 (-> before 1.132 - (step []) ; make sure it can handle blanks 1.133 - (step []) ; at the beginning. 1.134 + (step []) ; make sure it can handle blanks 1.135 + (step []) ; at the beginning. 1.136 (step []) 1.137 - (step [:start]) ; select WRITE-BYTES mode 1.138 - (step (buttons 4)) ; write 4 bytes 1.139 + (step [:start]) ; select WRITE-BYTES mode 1.140 + (step (buttons 4)) ; write 4 bytes 1.141 (step (buttons target-high)) 1.142 (step (buttons target-low)) 1.143 (step (buttons (nth assembly 0))) 1.144 @@ -332,4 +355,3 @@ 1.145 (println program-counters) 1.146 (assert (contains? (set program-counters) target-address)) 1.147 post-jump)) 1.148 -) 1.149 \ No newline at end of file