annotate clojure/com/aurellem/exp/assembly.clj @ 613:e1dcad3ce967

misc. fixes.
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Nov 2012 11:36:07 -0600
parents 412ca096a9ba
children
rev   line source
rlm@145 1 (ns com.aurellem.exp.assembly
rlm@145 2 (:use (com.aurellem.gb gb-driver vbm title items))
rlm@145 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@145 4
rlm@145 5
rlm@145 6 (defn run-item-program
rlm@145 7 "This is my first assembly/item program!
rlm@145 8 it just increments BC by one.
rlm@145 9
rlm@145 10 The code places a 3 'great balls' at the beginning of the
rlm@145 11 inventory, then directly sets the program counter to start
rlm@145 12 executing at the position of the 'great balls' in memory.
rlm@145 13
rlm@145 14 Since a 'great ball' is represented in memory as 0x03, which
rlm@145 15 corresponts to the opcode which increments BC by one, that is
rlm@145 16 what happens. Then the program counter to the 0x03 quantity entry
rlm@145 17 and BC is incremented again.
rlm@145 18
rlm@145 19 Obviously, the game crashes more or less immediately after the
rlm@145 20 program counter advances past the 'great balls' into the next items
rlm@145 21 in the inventory, thus I call shutdown! before anything bad happens."
rlm@145 22 []
rlm@145 23 (set-inventory (read-state "mid-game") [[:great-ball 3]])
rlm@145 24 (print-inventory)
rlm@145 25 (println "3 ticks") (tick) (tick) (tick)
rlm@145 26 (println "PC before:" (PC))
rlm@145 27 (println "BC before:" (BC))
rlm@145 28 (PC! (inc item-list-start))
rlm@145 29 (println "PC after setting:" (PC))
rlm@145 30 (println "data at PC:" (aget (memory) (PC)))
rlm@145 31 (println "one tick")
rlm@145 32 (tick)
rlm@145 33 (println "PC after one tick:" (PC))
rlm@145 34 (println "BC after one tick:" (BC))
rlm@145 35 (tick)
rlm@145 36 (println "PC after two ticks:" (PC))
rlm@145 37 (println "BC after two ticks:" (BC))
rlm@145 38
rlm@145 39 (shutdown!))
rlm@145 40
rlm@145 41
rlm@145 42
rlm@145 43
rlm@145 44 (defn test-opcodes-1
rlm@145 45 []
rlm@145 46 (let [final-state
rlm@145 47 (->
rlm@145 48 (read-state "mid-game")
rlm@145 49 (set-inv-mem
rlm@145 50 [20 0x02 0x00 0x00 0x02 0x00 0x00
rlm@145 51 0x00 0x0 0xFF])
rlm@145 52 (print-inventory)
rlm@145 53 ;;((fn [_] (println "3 ticks") _))
rlm@145 54 (tick) (tick) (tick)
rlm@145 55
rlm@145 56 ;;(println "PC before:" (PC))
rlm@145 57 ;;(println "BC before:" (BC))
rlm@145 58 ;;(println "AF:" (AF))
rlm@145 59 (PC! (inc item-list-start))
rlm@145 60 (BC! (+ 1 item-list-start))
rlm@145 61 ;;(println "PC after setting:" (PC))
rlm@145 62 ;;(println "data at PC:" (aget (memory) (PC)))
rlm@145 63 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
rlm@145 64
rlm@145 65 ;;(println "one tick")
rlm@145 66 (tick)
rlm@145 67 ;;(println "PC after one tick:" (PC))
rlm@145 68 ;;(println "BC after one tick:" (BC))
rlm@145 69 ;;(println "data at PC:" (aget (memory) (PC)))
rlm@145 70 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
rlm@145 71 (tick)
rlm@145 72 (AF! 0xFFFF)
rlm@145 73 ;;(println "PC after two ticks:" (PC))
rlm@145 74 ;;(println "BC after two ticks:" (BC))
rlm@145 75 ;;(println "data at PC:" (aget (memory) (PC)))
rlm@145 76 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
rlm@145 77 (tick)
rlm@145 78 ;;(println "PC after three ticks:" (PC))
rlm@145 79 ;;(println "BC after three ticks:" (BC))
rlm@145 80 ;;(println "data at PC:" (aget (memory) (PC)))
rlm@145 81 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
rlm@145 82 (tick)
rlm@145 83 ;;(println "PC after four ticks:" (PC))
rlm@145 84 ;;(println "BC after four ticks:" (BC))
rlm@145 85 ;;(println "data at PC:" (aget (memory) (PC)))
rlm@145 86 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
rlm@145 87 (tick)
rlm@145 88 ;;(println "PC after five ticks:" (PC))
rlm@145 89 ;;(println "BC after five ticks:" (BC))
rlm@145 90 ;;(println "data at PC:" (aget (memory) (PC)))
rlm@145 91 ;;(println "data at " (BC) "(BC):" (aget (memory) (BC)))
rlm@145 92 (print-inventory)
rlm@145 93 )]
rlm@145 94
rlm@145 95 (shutdown!)
rlm@145 96 final-state))
rlm@145 97
rlm@145 98
rlm@145 99
rlm@145 100 (defn test-opcodes-2
rlm@145 101 []
rlm@145 102 (set-inv-mem (read-state "mid-game")
rlm@145 103 [20 0x08 0x1D 0xD3 0x00 0x00 0x00
rlm@145 104 0x00 0x0 0xFF])
rlm@145 105 (print-inventory)
rlm@145 106 (println "3 ticks") (tick) (tick) (tick)
rlm@145 107 (println "PC before:" (PC))
rlm@145 108 (println "SP:" (SP))
rlm@145 109 (PC! (inc item-list-start))
rlm@145 110 (println "PC after setting:" (PC))
rlm@145 111 (println "SP:" (Integer/toBinaryString (SP)))
rlm@145 112 (println "data at PC:" (aget (memory) (PC)))
rlm@145 113 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
rlm@145 114 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
rlm@145 115 (println "one tick")
rlm@145 116 (tick)
rlm@145 117 (println "PC after one tick:" (PC))
rlm@145 118 (println "data at PC:" (aget (memory) (PC)))
rlm@145 119 (println "data at 0xD31D:" (Integer/toBinaryString (aget (memory) 0xD31D)))
rlm@145 120 (println "data at 0xD31E:" (Integer/toBinaryString (aget (memory) 0xD31E)))
rlm@145 121 (tick) (tick) (tick)
rlm@145 122 (println "PC aftter four tick:" (PC))
rlm@145 123 (println "data at PC:" (aget (memory) (PC)))
rlm@145 124 (println "data at 0xD31D:" (aget (memory) 0xD31D))
rlm@145 125
rlm@145 126 (print-inventory)
rlm@145 127 (shutdown!))
rlm@145 128