diff clojure/com/aurellem/exp/assembly.clj @ 145:412ca096a9ba

major refactoring complete.
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 21:23:46 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clojure/com/aurellem/exp/assembly.clj	Mon Mar 19 21:23:46 2012 -0500
     1.3 @@ -0,0 +1,128 @@
     1.4 +(ns com.aurellem.exp.assembly
     1.5 +   (:use (com.aurellem.gb gb-driver vbm title items))
     1.6 +   (:import [com.aurellem.gb.gb_driver SaveState]))
     1.7 +
     1.8 +
     1.9 +(defn run-item-program
    1.10 +  "This is my first assembly/item program!
    1.11 +   it just increments BC by one.
    1.12 +
    1.13 +   The code places a 3 'great balls' at the beginning of the
    1.14 +   inventory, then directly sets the program counter to start
    1.15 +   executing at the position of the 'great balls' in memory.
    1.16 +
    1.17 +   Since a 'great ball' is represented in memory as 0x03, which
    1.18 +   corresponts to the opcode which increments BC by one, that is
    1.19 +   what happens. Then the program counter to the 0x03 quantity entry
    1.20 +   and BC is incremented again.
    1.21 +
    1.22 +   Obviously, the game crashes more or less immediately after the
    1.23 +   program counter advances past the 'great balls' into the next items
    1.24 +   in the inventory, thus I call shutdown! before anything bad happens."
    1.25 +  []
    1.26 +  (set-inventory (read-state "mid-game") [[:great-ball 3]])
    1.27 +  (print-inventory)
    1.28 +  (println "3 ticks") (tick) (tick) (tick)
    1.29 +  (println "PC before:" (PC))
    1.30 +  (println "BC before:" (BC))
    1.31 +  (PC! (inc item-list-start))
    1.32 +  (println "PC after setting:" (PC))
    1.33 +  (println "data at PC:" (aget (memory) (PC)))
    1.34 +  (println "one tick")
    1.35 +  (tick)
    1.36 +  (println "PC after one tick:" (PC))
    1.37 +  (println "BC after one tick:" (BC))
    1.38 +  (tick)
    1.39 +  (println "PC after two ticks:" (PC))
    1.40 +  (println "BC after two ticks:" (BC))
    1.41 +
    1.42 +  (shutdown!))
    1.43 +
    1.44 +
    1.45 +
    1.46 +
    1.47 +(defn test-opcodes-1
    1.48 +  []
    1.49 +  (let [final-state
    1.50 +        (->
    1.51 +         (read-state "mid-game")
    1.52 +         (set-inv-mem 
    1.53 +          [20 0x02 0x00 0x00 0x02 0x00 0x00
    1.54 +           0x00 0x0 0xFF])
    1.55 +         (print-inventory)
    1.56 +         ;;((fn [_] (println "3 ticks") _))
    1.57 +         (tick) (tick) (tick)
    1.58 +         
    1.59 +         ;;(println "PC before:" (PC))
    1.60 +         ;;(println "BC before:" (BC))
    1.61 +         ;;(println "AF:" (AF))
    1.62 +         (PC! (inc item-list-start))
    1.63 +         (BC! (+ 1 item-list-start))
    1.64 +         ;;(println "PC after setting:" (PC))
    1.65 +         ;;(println "data at PC:" (aget (memory) (PC)))
    1.66 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
    1.67 +         
    1.68 +         ;;(println "one tick")
    1.69 +         (tick)
    1.70 +         ;;(println "PC after one tick:" (PC))
    1.71 +         ;;(println "BC after one tick:" (BC))
    1.72 +         ;;(println "data at PC:" (aget (memory) (PC)))
    1.73 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
    1.74 +         (tick)
    1.75 +         (AF! 0xFFFF)
    1.76 +         ;;(println "PC after two ticks:" (PC))
    1.77 +         ;;(println "BC after two ticks:" (BC))
    1.78 +         ;;(println "data at PC:" (aget (memory) (PC)))
    1.79 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
    1.80 +         (tick)
    1.81 +         ;;(println "PC after three ticks:" (PC))
    1.82 +         ;;(println "BC after three ticks:" (BC))
    1.83 +         ;;(println "data at PC:" (aget (memory) (PC)))
    1.84 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
    1.85 +         (tick)
    1.86 +         ;;(println "PC after four ticks:" (PC))
    1.87 +         ;;(println "BC after four ticks:" (BC))
    1.88 +         ;;(println "data at PC:" (aget (memory) (PC)))
    1.89 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
    1.90 +         (tick)
    1.91 +         ;;(println "PC after five ticks:" (PC))
    1.92 +         ;;(println "BC after five ticks:" (BC))
    1.93 +         ;;(println "data at PC:" (aget (memory) (PC)))
    1.94 +         ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
    1.95 +         (print-inventory)
    1.96 +         )]
    1.97 +    
    1.98 +    (shutdown!)
    1.99 +    final-state))
   1.100 +
   1.101 +
   1.102 +
   1.103 +(defn test-opcodes-2
   1.104 +  []
   1.105 +  (set-inv-mem (read-state "mid-game")
   1.106 +               [20 0x08 0x1D 0xD3 0x00 0x00 0x00
   1.107 +                0x00 0x0 0xFF])
   1.108 +  (print-inventory)
   1.109 +  (println "3 ticks") (tick) (tick) (tick)
   1.110 +  (println "PC before:" (PC))
   1.111 +  (println "SP:" (SP))
   1.112 +  (PC! (inc item-list-start))
   1.113 +  (println "PC after setting:" (PC))
   1.114 +  (println "SP:" (Integer/toBinaryString (SP)))
   1.115 +  (println "data at PC:" (aget (memory) (PC)))
   1.116 +  (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
   1.117 +  (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
   1.118 +  (println "one tick")
   1.119 +  (tick)
   1.120 +  (println "PC after one tick:" (PC))
   1.121 +  (println "data at PC:" (aget (memory) (PC)))
   1.122 +  (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
   1.123 +  (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
   1.124 +  (tick) (tick) (tick)
   1.125 +  (println "PC aftter four tick:" (PC))
   1.126 +  (println "data at PC:" (aget (memory) (PC)))
   1.127 +  (println "data at 0xD31D:" (aget (memory) 0xD31D))
   1.128 +  
   1.129 +  (print-inventory)
   1.130 +  (shutdown!))
   1.131 +