Mercurial > vba-clojure
changeset 123:c9a280b8bd1c
saving progress.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 17 Mar 2012 00:29:34 -0500 |
parents | e85b53994fac |
children | f8dadd9478a5 |
files | clojure/com/aurellem/assembly.clj |
diffstat | 1 files changed, 104 insertions(+), 87 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/assembly.clj Fri Mar 16 20:55:28 2012 -0500 1.2 +++ b/clojure/com/aurellem/assembly.clj Sat Mar 17 00:29:34 2012 -0500 1.3 @@ -181,9 +181,7 @@ 1.4 0xCA ;D32B ; if bit-0 is not 1 1.5 0x44 ;D32C ; GOTO not-v-blank 1.6 0xD3 ;D32D 1.7 - 1.8 ;;; in v-blank mode 1.9 - 1.10 ;; if v-blank-prev was 0, 1.11 ;; increment frame-count 1.12 1.13 @@ -443,107 +441,125 @@ 1.14 (dotimes [_ 90000] (step (view-memory @current-state 0xD352)))) 1.15 1.16 (defn write-memory-assembly [] 1.17 - [0x18 ;D31D ; jump over 1.18 - 0x02 ;D31E ; the next 2 bytes 1.19 - 0x00 ;D31F ; frame-count 1.20 - 0x00 ;D320 ; v-blank-prev 1.21 + [ 1.22 + ;; Main Timing Loop 1.23 + ;; Constantly check for v-blank and Trigger main state machine on 1.24 + ;; every transtion from v-blank to non-v-blank. 1.25 1.26 - 0xFA ;D321 1.27 - 0x41 ;D322 ; load (FF41) into A 1.28 - 0xFF ;D323 ; this contains mode flags 1.29 + 0x18 ; D31D ; Variable declaration 1.30 + 0x02 ; D31E 1.31 + 0x00 ; D31F ; frame-count 1.32 + 0x00 ; D320 ; v-blank-prev 1.33 + 1.34 + 0xFA ; D321 ; load v-blank mode flags into A 1.35 + 0x41 ; D322 1.36 + 0xFF ; D323 1.37 + 1.38 + ;; Branch dependent on v-blank. v-blank happens when the last two 1.39 + ;; bits in A are "01" 1.40 + 0xCB ; D324 1.41 + 0x4F ; D325 1.42 + 1.43 + 0xC2 ; D326 ; if bit-1 is not 0, then 1.44 + 0x44 ; D327 ; GOTO non-v-blank. 1.45 + 0xD3 ; D328 1.46 + 1.47 + 0xCB ; D329 1.48 + 0x47 ; D32A 1.49 + 1.50 + 0xCA ; D32B ; if bit-0 is not 1, then 1.51 + 0x44 ; D32C ; GOTO non-v-blank. 1.52 + 0xD3 ; D32D 1.53 + 1.54 + ;; V-Blank 1.55 + ;; Activate state-machine if this is a transition event. 1.56 + 1.57 + 0xFA ; D32E ; load v-bank-prev into A 1.58 + 0x20 ; D32F 1.59 + 0xD3 ; D330 1.60 + 1.61 + 0xFE ; D331 ; compare A to 0. 1.62 + 0x00 ; D332 1.63 + 1.64 + ;; set v-blank-prev to 1. 1.65 + 0x3E ; D333 ; load 1 into A. 1.66 + 0x01 ; D334 1.67 1.68 - ;; if we're in v-blank, the bit-1 is 0 1.69 - ;; and bit-2 is 1 Otherwise, it is not v-blank. 1.70 - 0xCB ;D324 ; test bit-1 of A 1.71 - 0x4F ;D325 1.72 + 0xEA ; D335 ; load A into v-blank-prev 1.73 + 0x20 ; D336 1.74 + 0xD3 ; D337 1.75 1.76 - 0xC2 ;D326 ; if bit-1 is not 0 1.77 - 0x44 ;D327 ; GOTO not-v-blank 1.78 - 0xD3 ;D328 1.79 + ;; if v-blank-prev was 0, activate state-machine 1.80 + 0xC2 ; D338 ; if v-blank-prev 1.81 + 0x46 ; D339 ; was 0, 1.82 + 0xD3 ; D33A ; GOTO state-machine 1.83 + 1.84 + 0xC3 ; D33B 1.85 + 0x1D ; D33C 1.86 + 0xD3 ; D33D ; GOTO beginning 1.87 + ;; END V-blank 1.88 + 1.89 + ;; Non-V-Blank 1.90 + ;; Set v-blank-prev to 0 1.91 + 0x3E ; D33E ; load 0 into A 1.92 + 0x00 ; D33F 1.93 + 1.94 + 0xEA ; D340 ; load A into v-blank-prev 1.95 + 0x20 ; D341 1.96 + 0xD3 ; D342 1.97 1.98 - 0xCB ;D329 ; test bit-0 of A 1.99 - 0x47 ;D32A 1.100 + 0xC3 ; D343 1.101 + 0x1D ; D344 1.102 + 0xD3 ; D345 ; GOTO beginning 1.103 + ;; END Not-V-Blank 1.104 1.105 - 0xCA ;D32B ; if bit-0 is not 1 1.106 - 0x44 ;D32C ; GOTO not-v-blank 1.107 - 0xD3 ;D32D 1.108 + ;; Main State Machine -- Input Section 1.109 + ;; This is called once every frame. 1.110 + ;; It collects input and uses it to drive the 1.111 + ;; state transitions. 1.112 + 1.113 + ;; Increment frame-count 1.114 + 0xFA ; D346 ; load frame-count into A 1.115 + 0x1F ; D347 1.116 + 0xD3 ; D348 1.117 1.118 - ;;; in v-blank mode 1.119 + 0x3C ; D349 ; inc A 1.120 1.121 - ;; if v-blank-prev was 0, 1.122 - ;; increment frame-count 1.123 + 0xEA ; D34A 1.124 + 0x1F ; D34B ; load A into frame-count 1.125 + 0xD3 ; D34C 1.126 1.127 - 0xFA ;D32E ; load v-blank-prev to A 1.128 - 0x20 ;D32F 1.129 - 0xD3 ;D330 1.130 + 0x00 ; D34D ; glue :) 1.131 + 1.132 + 1.133 + ;;;;;;;;; BEGIN RLM DEBUG 1.134 + 0xC3 ;; jump to beginning 1.135 + 0x1D 1.136 + 0xD3 1.137 1.138 - 0xCB ;D331 1.139 - 0x47 ;D332 ; test bit-0 of A 1.140 + ;;;;;;;;; END RLM DEBUG 1.141 1.142 - 0x20 ;D333 ; skip next section 1.143 - 0x07 ;D334 ; if v-blank-prev was not zero 1.144 1.145 - ;; v-blank was 0, increment frame-count 1.146 - 0xFA ;D335 ; load frame-count into A 1.147 - 0x1F ;D336 1.148 - 0xD3 ;D337 1.149 - 1.150 - 0x3C ;D338 ; inc A 1.151 - 1.152 - 0xEA ;D339 ; load A into frame-count 1.153 - 0x1F ;D33A 1.154 - 0xD3 ;D33B 1.155 - 1.156 - ;; set v-blank-prev to 1 1.157 - 0x3E ;D33C ; load 1 into A 1.158 - 0x01 ;D33D 1.159 - 1.160 - 0xEA ;D33E ; load A into v-blank-prev 1.161 - 0x20 ;D33F 1.162 - 0xD3 ;D340 1.163 - 1.164 - 0xC3 ;D341 ; GOTO input handling code 1.165 - 0x4E ;D342 1.166 - 0xD3 ;D343 1.167 - 1.168 - ;;; not in v-blank mode 1.169 - ;; set v-blank-prev to 0 1.170 - 0x3E ;D344 ; load 0 into A 1.171 - 0x00 ;D345 1.172 - 1.173 - 0xEA ;D346 ; load A into v-blank-prev 1.174 - 0x20 ;D347 1.175 - 0xD3 ;D348 1.176 - 1.177 - 0xC3 ;D349 ; return to beginning 1.178 - 0x1D ;D34A 1.179 - 0xD3 ;D34B 1.180 - 1.181 - 0x00 ;D34C ; these are here 1.182 - 0x00 ;D34D ; for glue 1.183 - 1.184 - 1.185 - ;;; calculate input number based on button presses 1.186 0x18 ;D34E ; skip next 3 bytes 1.187 0x03 ;D34F 1.188 - ;D350 1.189 + ;D350 1.190 (Integer/parseInt "00100000" 2) ; select directional pad 1.191 - ;D351 1.192 + ;D351 1.193 (Integer/parseInt "00010000" 2) ; select buttons 1.194 0x00 ;D352 ; input-number 1.195 1.196 - ;; select directional pad, store low bits in B 1.197 + ;; select directional pad; store low bits in B 1.198 1.199 0xFA ;D353 ; load (D350) into A 1.200 0x50 ;D354 --> 1.201 - 0xD3 ;D355 --> D31F 1.202 + 0xD3 ;D355 --> D350 1.203 1.204 0xEA ;D356 ; load (A), which is 1.205 0x00 ;D357 --> ; 00010000, into FF00 1.206 0xFF ;D358 --> FF00 1.207 1.208 0x06 ;D359 1.209 - ;D35A 1.210 + ;D35A 1.211 (Integer/parseInt "11110000" 2) ; "11110000" -> B 1.212 0xFA ;D35B ; (FF00) -> A 1.213 0x00 ;D35C 1.214 @@ -554,11 +570,11 @@ 1.215 0xA0 ;D360 ; (AND A B) -> A 1.216 0x47 ;D361 ; A -> B 1.217 1.218 - ;; select buttons store bottom bits in C 1.219 + ;; select buttons; store bottom bits in C 1.220 1.221 0xFA ;D362 ; load (D351) into A 1.222 0x51 ;D363 --> 1.223 - 0xD3 ;D364 --> D31F 1.224 + 0xD3 ;D364 --> D351 1.225 1.226 0xEA ;D365 ; load (A), which is 1.227 0x00 ;D366 --> ; 00001000, into FF00 1.228 @@ -584,11 +600,9 @@ 1.229 0x52 ;D373 1.230 0xD3 ;D374 1.231 1.232 - 0xC3 ;D375 ; GOTO state machine 1.233 - ;;0x1D 1.234 - 0x80 ;D376 1.235 + 0xC3 ;D375 ; secret jump :) 1.236 + 0x1D ;D376 1.237 0xD3 ;D377 1.238 - 1.239 0x00 ;D378 1.240 0x00 ;D379 1.241 0x00 ;D37A 1.242 @@ -761,6 +775,7 @@ 1.243 ]) 1.244 1.245 1.246 + 1.247 (def frame-count 0xD31F) 1.248 (def input 0xD352) 1.249 (def current-mode 0xD382) 1.250 @@ -782,12 +797,14 @@ 1.251 (defn test-mode-2 [] 1.252 (-> 1.253 (write-memory) 1.254 - (view-memory bytes-to-write) 1.255 - (view-memory start-point) 1.256 + (view-memory frame-count) 1.257 (step) 1.258 (step [:a]) 1.259 (step [:b]) 1.260 (step [:start]) 1.261 (step []) 1.262 - (view-memory bytes-to-write) 1.263 - (view-memory start-point))) 1.264 \ No newline at end of file 1.265 + (view-memory frame-count))) 1.266 + 1.267 + 1.268 + 1.269 +