diff clojure/com/aurellem/gb/rlm_assembly.clj @ 391:2e9b2d27f32f

saving progress...
author Robert McIntyre <rlm@mit.edu>
date Thu, 12 Apr 2012 00:20:16 -0500
parents dbf7b5a2e9e7
children 309614263aa9
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/rlm_assembly.clj	Wed Apr 11 23:40:01 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/rlm_assembly.clj	Thu Apr 12 00:20:16 2012 -0500
     1.3 @@ -191,28 +191,24 @@
     1.4  (defn main-bootstrap-program [start-address]
     1.5    ;; Register Use:
     1.6    
     1.7 -  ;; BC persistent scratch
     1.8 -  ;; 
     1.9 +  ;; ED non-volitale scratch
    1.10 +  
    1.11    ;; A  user-input
    1.12    ;; HL target-address
    1.13 -  ;; D  current-mode
    1.14 -  ;; E  bytes-to-write
    1.15 +  ;; B  bytes-to-write
    1.16 +  ;; C  current-mode
    1.17  
    1.18 -
    1.19 -  ;; Modes are:
    1.20 +  ;; Modes (with codes) are:
    1.21  
    1.22    ;; single-action-modes:
    1.23    ;; SET-MODE
    1.24 -  ;; SET-TARGET-HIGH
    1.25 -  ;; SET-TARGET-LOW
    1.26 -  ;; SET-WRITE-LENGTH
    1.27 -  ;; JUMP
    1.28 +  ;; SET-TARGET-HIGH     0x67 ;; A->H
    1.29 +  ;; SET-TARGET-LOW      0x6F ;; A->L
    1.30 +  ;; JUMP                0xE9 ;; jump to (HL)
    1.31  
    1.32    ;; multi-action-modes
    1.33 -  ;; WRITE
    1.34 +  ;; WRITE               0x47 ;; A->B
    1.35  
    1.36 -  
    1.37 -  
    1.38    (let [[start-high start-low] (disect-bytes-2 start-address)
    1.39          jump-distance (+ (count (frame-metronome))
    1.40                                  (read-user-input))
    1.41 @@ -220,32 +216,46 @@
    1.42          init
    1.43          [0xAF 0x5F 0x57 0x47] ;; 0->A; 0->E; 0->D; 0->B
    1.44  
    1.45 -        
    1.46 +        input
    1.47 +        [0xC1  ;; pop BC so it's not volatile
    1.48 +
    1.49 +         0x4F ;; A->C
    1.50 +         
    1.51 +         0xAF  ;; test for output-mode (bytes-to-write > 0)
    1.52 +         0xB8  ;; (cp A B)
    1.53 +
    1.54 +         0x20       ;; skip input section if
    1.55 +         :to-output ;; we're not in input mode 
    1.56 +              
    1.57 +         
    1.58 +         :to-be-executed
    1.59          
    1.60  
    1.61 -        input
    1.62 -        [0xC1  ;; pop BC so it's not volatile
    1.63 -         ;; some condition
    1.64 -         ;; to skip if not in input
    1.65 -         ;; mode
    1.66 +         ;; write mode to instruction to be executed (pun)
    1.67 +         0xEA
    1.68 +         :to-be-executed-address
    1.69 +         0x18           ;; return
    1.70 +         :to-beginning]
    1.71 +
    1.72 +        output
    1.73 +        [0x05 ;; DEC bytes-to-write (B)
    1.74 +
    1.75 +         0x54 ;;
    1.76 +         0x5D ;; HL->DE  \
    1.77 +              ;;          |
    1.78 +         0x79 ;; C->A     | this mess is all to do 
    1.79 +         0x12 ;; A->(DE)  | 0x22 (LDI (HL), A) without
    1.80 +              ;;          | any repeating nybbles
    1.81 +         0x23 ;; inc HL  /
    1.82 +
    1.83 +         ]
    1.84 +        
    1.85           
    1.86           
    1.87 +
    1.88           
    1.89 -        
    1.90 -         0xE9 ;; jump to (HL)
    1.91  
    1.92 -         0x22 ;; A->(HL) ; inc HL
    1.93 -         
    1.94 -         
    1.95 -         0x57 ;; A->D
    1.96 -         
    1.97 -         0x67 ;; A->H
    1.98 -         0x6F ;; A->L
    1.99 -         
   1.100 -         0x47 ;; A->B
   1.101 -         0x4F ;; A->C
   1.102 -         
   1.103 -         
   1.104 +         0x22 ;; A->(HL) ; inc HL         
   1.105  
   1.106  
   1.107