# HG changeset patch # User Robert McIntyre # Date 1333872051 18000 # Node ID 93e74ed34305da8db1149c6270c2d2e07bf95580 # Parent 92f0011925d2e07ed58d7b18b5e1fc5715608c53 rewriting basic-writer assemly so that it is valid items diff -r 92f0011925d2 -r 93e74ed34305 clojure/com/aurellem/gb/items.clj --- a/clojure/com/aurellem/gb/items.clj Sat Apr 07 12:31:12 2012 -0500 +++ b/clojure/com/aurellem/gb/items.clj Sun Apr 08 03:00:51 2012 -0500 @@ -142,7 +142,7 @@ 0xEA :TM34 ;; bide 0xEB :TM35 ;; metronome 0xEC :TM36 ;; self destruct - 0xED :TM37 ;; eggbomb + 0xED :TM37 ;; egg bomb 0xEE :TM38 ;; fire blast 0xEF :TM39 ;; swift 0xF0 :TM40 ;; skull bash @@ -167,9 +167,9 @@ (zipmap (vals item-code->item-name) (keys item-code->item-name))) -(defn inventory [^SaveState state] - (let [items (item-list state)] - (map +(defn raw-inventory->inventory + [raw-inventory] + (map (fn [[item-code quantity]] [(item-code->item-name item-code @@ -177,7 +177,12 @@ quantity]) (partition 2 - (next (take-while (partial not= 255) items)))))) + raw-inventory))) + +(defn inventory [^SaveState state] + (let [items (item-list state)] + (raw-inventory->inventory + (next (take-while (partial not= 255) items))))) (defn print-inventory ([] (print-inventory @current-state)) diff -r 92f0011925d2 -r 93e74ed34305 clojure/com/aurellem/run/bootstrap_0.clj --- a/clojure/com/aurellem/run/bootstrap_0.clj Sat Apr 07 12:31:12 2012 -0500 +++ b/clojure/com/aurellem/run/bootstrap_0.clj Sun Apr 08 03:00:51 2012 -0500 @@ -874,4 +874,147 @@ (d-print "============== end") (d-ticks 20))) - \ No newline at end of file +;;TMs at celadon store --- +;;01 (any-number) mega punch +;;02 (any-number) razor wind +;;05 (any-number) mega kick +;;07 (any-number) hyper beam +;;09 (any-number) take down +;;13 (only 1) ice beam +;;17 (any-number) submission +;;18 (only 1) counter +;;32 (any-number) double team +;;33 (any-number) reflect +;;37 (any-number) egg bomb +;;48 (only 1) rock slide +;;49 (only 1) tri attack + + +;; no-ops +;; 0x00 +;; 0xB8 - 0xBF (compares) :garbage +;; 0x3F clear carry flag :s.s.ticket +;; 0x37 set carry flag :guard-spec [!] +;; 0x33 increment SP :poke-doll [!] +;; 0x3B decrement SP :coin + +;;0x7F A->A :garbage +;;0x40 B->B :gold-teeth +;;0x49 C->C :poke-flute +;;0x52 D->D :elixer +;;0x5B E->E :garbage +;;0x6D L->L :garbage +;;0x64 H->H :garbage + + +;;0xC5 push BC :HM02 +;;0xD5 push DE :TM13 (ice-beam) +;;0xE5 push HL :TM29 (psychic) +;;0xF5 push AF :TM45 (thunder-wave) + +;; 0xA7 (AND A A) :garbage +;; 0xB7 (OR A A) :garbage + +;; 0x2F (CPL A) :leaf-stone + + +(defn item-writer + "This is the basic writer, optimized to be made of valid + item-quantity pairs." + [target-address limit return-address] + (let [[target-high target-low] (disect-bytes-2 target-address) + [return-high return-low] (disect-bytes-2 return-address)] + (flatten + [ + ;;0xC5 ;; push junk onto stack + ;;0xD5 + ;;0xE5 + ;;0xF5 + 0x37 ;; (item-hack) set cary flag no-op + 0x1E ;; load limit into E + limit + 0x3F ;; (item-hack) set carry flag no-op + + ;; load 1 into C. + 0x0E ;; C == 1 means input-first nybble + 0x01 ;; C == 0 means input-second nybble + + 0x21 ;; load target into HL + target-low + target-high + 0x37 ;; (item-hack) set carry flag no-op + + 0x2F ;; (item-hack) cpl A + 0x2F ;; (item-hack) cpl A --together a spacer no-op + + 0x00 ;; (item-hack) no-op + 0xF3 ;; disable interrupts + ;; Input Section + + 0x3E ;; load 0x20 into A, to measure buttons + 0x10 + + 0x00 ;; (item-hack) no-op + 0xE0 ;; load A into [FF00] + 0x00 + + 0xF0 ;; load 0xFF00 into A to get + 0x00 ;; button presses + + 0xE6 + 0x0F ;; select bottom four bits of A + 0x37 ;; (item-hack) set carry flag no-op + + 0x00 ;; (item-hack) no-op + 0xB8 ;; see if input is different (CP A B) + + 0x33 ;; (item-hack) (INC SP) + 0x28 ;; repeat above steps if input is not different + ;; (jump relative backwards if B != A) + 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37) + + 0x47 ;; load A into B + + 0x0D ;; dec C + ;; branch based on C: + 0x20 ;; JR NZ + 0x07 ;; skip "input first nybble" below + + + ;; input first nybble + + 0xCB + 0x37 ;; swap nybbles on A + + 0x57 ;; A -> D + + 0x18 + 0xEC ;; literal -20 -- go back to input section + + ;; input second nybble + + 0x0C ;; inc C + + 0xE6 ;; select bottom bits + 0x0F + + 0xB2 ;; (OR A D) -> A + + 0x22 ;; (do (A -> (HL)) (INC HL)) + + 0x1D ;; (DEC E) + + 0x20 ;; jump back to input section if not done + 0xE4 ;; literal -28 + + ;; cleanup + ;;0xF1 + ;;0xE1 + ;;0xD1 + ;;0xC1 + + 0xFB ;; re-enable interrupts + + 0xC3 + return-low + return-high ])))