Mercurial > vba-clojure
changeset 191:893c753f8088
added function to set ROM
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 20:10:09 -0500 |
parents | 9a7a46c4aa1b |
children | fd549c8f42ae |
files | clojure/com/aurellem/gb/experience.clj clojure/com/aurellem/gb/gb_driver.clj clojure/com/aurellem/gb/items.clj clojure/com/aurellem/gb/moves.clj clojure/com/aurellem/gb/pokemon.clj clojure/com/aurellem/gb/species.clj clojure/com/aurellem/gb/status.clj java/src/com/aurellem/gb/Gb.java src/clojure/clojure.cpp src/gb/GB.cpp src/gb/GB.h |
diffstat | 11 files changed, 176 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/gb/experience.clj Thu Mar 22 20:10:09 2012 -0500 1.3 @@ -0,0 +1,67 @@ 1.4 +(ns com.aurellem.gb.experience 1.5 + (:use (com.aurellem.gb gb-driver util constants)) 1.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 1.7 + 1.8 +(def experience-pokemon-1 0xD178) 1.9 + 1.10 +(defn experience-start-address [poke-num] 1.11 + (+ experience-pokemon-1 1.12 + (* pokemon-record-width poke-num))) 1.13 + 1.14 +(def experience-record-width 13) 1.15 + 1.16 +(defn read-experience 1.17 + ([^SaveState state poke-num] 1.18 + (let [start (experience-start-address poke-num) 1.19 + [exp-h 1.20 + exp-m 1.21 + exp-l 1.22 + hp-exp-h 1.23 + hp-exp-l 1.24 + attack-exp-h 1.25 + attack-exp-l 1.26 + defense-exp-h 1.27 + defense-exp-l 1.28 + speed-exp-h 1.29 + speed-exp-l 1.30 + special-exp-h 1.31 + special-exp-l] 1.32 + (subvec (vec (memory state)) 1.33 + start (+ experience-record-width start)) 1.34 + glue-bytes (fn [l h] 1.35 + (+ l (bit-shift-left h 8)))] 1.36 + {:main-exp (+ (glue-bytes exp-l exp-m) 1.37 + (bit-shift-left exp-h 16)) 1.38 + :hp-exp (glue-bytes hp-exp-l hp-exp-h) 1.39 + :attack-exp (glue-bytes attack-exp-l attack-exp-h) 1.40 + :defense-exp (glue-bytes defense-exp-l defense-exp-h) 1.41 + :speed-exp (glue-bytes speed-exp-l speed-exp-h) 1.42 + :special-exp (glue-bytes special-exp-l special-exp-h)})) 1.43 + ([poke-num] 1.44 + (read-experience @current-state poke-num))) 1.45 + 1.46 +(defn give-experience 1.47 + ([^SaveState state poke-num exp] 1.48 + (let [exp* (merge (read-experience state poke-num) 1.49 + exp) 1.50 + 1.51 + disect-bytes 1.52 + (fn [exp] 1.53 + [(bit-shift-right 1.54 + (bit-and exp 0xFF00) 8) 1.55 + (bit-and exp 0xFF)]) 1.56 + 1.57 + raw-exp-data 1.58 + (flatten 1.59 + [(bit-shift-right (bit-and (:main-exp exp*) 0xFF0000) 16) 1.60 + (disect-bytes (:main-exp exp*)) 1.61 + (disect-bytes (:hp-exp exp*)) 1.62 + (disect-bytes (:attack-exp exp*)) 1.63 + (disect-bytes (:defense-exp exp*)) 1.64 + (disect-bytes (:speed-exp exp*)) 1.65 + (disect-bytes (:special-exp exp*))])] 1.66 + (set-memory-range state 1.67 + (experience-start-address poke-num) 1.68 + raw-exp-data))) 1.69 + ([poke-num exp] 1.70 + (give-experience @current-state poke-num exp)))
2.1 --- a/clojure/com/aurellem/gb/gb_driver.clj Thu Mar 22 16:34:10 2012 -0500 2.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj Thu Mar 22 20:10:09 2012 -0500 2.3 @@ -201,6 +201,9 @@ 2.4 (def write-registers! 2.5 (write-cpu-data Gb/NUM_REGISTERS #(Gb/writeRegisters %))) 2.6 2.7 +(def write-rom! 2.8 + (write-cpu-data Gb/ROM_SIZE #(Gb/writeROM %))) 2.9 + 2.10 ;;;;; Registers ;;;;;;;;;;;;;;;;;;;;;;;;;;; 2.11 2.12 (defmacro gen-get-set-register [name index]
3.1 --- a/clojure/com/aurellem/gb/items.clj Thu Mar 22 16:34:10 2012 -0500 3.2 +++ b/clojure/com/aurellem/gb/items.clj Thu Mar 22 20:10:09 2012 -0500 3.3 @@ -3,7 +3,9 @@ 3.4 ;; this is bullshit 3.5 (:import [com.aurellem.gb.gb_driver SaveState])) 3.6 3.7 -(defn game-name [] 3.8 +(defn game-name 3.9 + "return pokemon-yellow header information" 3.10 + [] 3.11 (map char (subvec (vec (memory)) 0x134 0x142))) 3.12 3.13 (def item-list-start 0xD31C)
4.1 --- a/clojure/com/aurellem/gb/moves.clj Thu Mar 22 16:34:10 2012 -0500 4.2 +++ b/clojure/com/aurellem/gb/moves.clj Thu Mar 22 20:10:09 2012 -0500 4.3 @@ -187,7 +187,7 @@ 4.4 (let [start (moves-codes-start poke-num)] 4.5 (vec 4.6 (take-while 4.7 - (partial not= (move-name->move-code :end-of-moves)) 4.8 + (partial not= :end-of-moves) 4.9 (map 4.10 move-code->move-name 4.11 (subvec (vec (memory state)) 4.12 @@ -195,14 +195,15 @@ 4.13 ([poke-num] 4.14 (read-moves @current-state poke-num))) 4.15 4.16 - 4.17 - 4.18 (defn give-moves 4.19 ([^SaveState state pokemon-num moves] 4.20 + (assert (<= (count moves) 4)) 4.21 (set-memory-range 4.22 state 4.23 (moves-codes-start pokemon-num) 4.24 - (map #(move-name->move-code % %) moves))) 4.25 + (map #(move-name->move-code % %) 4.26 + (concat moves 4.27 + (repeat (- 4 (count moves)) :end-of-moves))))) 4.28 ([pokemon-num moves] 4.29 (give-moves @current-state pokemon-num moves)) 4.30 ([moves] 4.31 @@ -216,7 +217,6 @@ 4.32 ;; thus, a move can have up to 63 current pp and up to 4.33 ;; three pp-ups applied. 4.34 4.35 - 4.36 (def pokemon-1-pp-start 0xD187) 4.37 4.38 (defn moves-pp-start [pokemon-num]
5.1 --- a/clojure/com/aurellem/gb/pokemon.clj Thu Mar 22 16:34:10 2012 -0500 5.2 +++ b/clojure/com/aurellem/gb/pokemon.clj Thu Mar 22 20:10:09 2012 -0500 5.3 @@ -1,7 +1,7 @@ 5.4 (ns com.aurellem.gb.pokemon 5.5 (:use (com.aurellem.gb gb-driver util constants characters 5.6 moves types items status dv species 5.7 - 5.8 + experience 5.9 )) 5.10 (:import [com.aurellem.gb.gb_driver SaveState])) 5.11 5.12 @@ -35,6 +35,12 @@ 5.13 raw-names))))) 5.14 ([] (party-names @current-state))) 5.15 5.16 +(defn pokemon-nickname 5.17 + ([^SaveState state poke-num] 5.18 + (nth (party-names state) poke-num)) 5.19 + ([poke-num] 5.20 + (pokemon-nickname @current-state poke-num))) 5.21 + 5.22 (defn rename-pokemon 5.23 ([^SaveState state n new-name] 5.24 (assert (<= 0 n (dec (party-number state)))) 5.25 @@ -185,15 +191,33 @@ 5.26 5.27 (def mint-berry-item-code-gsc 0x54) 5.28 5.29 -(defn pokemon-info [^SaveState state poke-num] 5.30 - (assert (<= 0 poke-num 5)) 5.31 - (let [dv-values (read-DV state poke-num) 5.32 - type (read-type state poke-num) 5.33 - species (read-species state poke-num) 5.34 - 5.35 - ] 5.36 +(defn pokemon-info 5.37 + ([^SaveState state poke-num] 5.38 + (assert (<= 0 poke-num 5)) 5.39 + (let [dv-values (read-DV state poke-num) 5.40 + type (read-type state poke-num) 5.41 + species (read-species state poke-num) 5.42 + species2 (read-species2 state poke-num) 5.43 + moves (read-moves state poke-num) 5.44 + moves-pp (mapv (partial read-pp state 5.45 + poke-num) 5.46 + (range (count moves))) 5.47 + nickname (pokemon-nickname state poke-num) 5.48 + status (read-status state poke-num) 5.49 + experience (read-experience state poke-num) 5.50 + ] 5.51 5.52 - 5.53 + {:name nickname 5.54 + :species species 5.55 + :species2 species2 5.56 + :type type 5.57 + :dv dv-values 5.58 + :moves (zipmap moves moves-pp) 5.59 5.60 - 5.61 - )) 5.62 + :satus status 5.63 + :experience experience 5.64 + } 5.65 + )) 5.66 + ([poke-num] 5.67 + (pokemon-info @current-state poke-num))) 5.68 +
6.1 --- a/clojure/com/aurellem/gb/species.clj Thu Mar 22 16:34:10 2012 -0500 6.2 +++ b/clojure/com/aurellem/gb/species.clj Thu Mar 22 20:10:09 2012 -0500 6.3 @@ -1,5 +1,5 @@ 6.4 (ns com.aurellem.gb.species 6.5 - (:use (com.aurellem.gb gb-driver util)) 6.6 + (:use (com.aurellem.gb gb-driver util constants)) 6.7 (:import [com.aurellem.gb.gb_driver SaveState])) 6.8 6.9 (def species-code->species-name 6.10 @@ -186,3 +186,29 @@ 6.11 (set-species @current-state poke-num species-name))) 6.12 6.13 6.14 +(def pokemon-1-species2-address 0xD16A) 6.15 + 6.16 +(defn pokemon-species2-address [poke-num] 6.17 + (+ pokemon-1-species2-address 6.18 + (* pokemon-record-width poke-num))) 6.19 + 6.20 +(defn read-species2 6.21 + ([^SaveState state poke-num] 6.22 + (species-code->species-name 6.23 + (aget (memory state) 6.24 + (pokemon-species2-address poke-num)))) 6.25 + ([poke-num] 6.26 + (read-species2 @current-state poke-num))) 6.27 + 6.28 +(defn set-species2 6.29 + ([^SaveState state poke-num new-species] 6.30 + (let [species-code (species-name->species-code 6.31 + new-species 6.32 + new-species)] 6.33 + 6.34 + (set-memory state (pokemon-species2-address poke-num) 6.35 + species-code))) 6.36 + ([poke-num new-species] 6.37 + (set-species2 @current-state poke-num new-species))) 6.38 + 6.39 + 6.40 \ No newline at end of file
7.1 --- a/clojure/com/aurellem/gb/status.clj Thu Mar 22 16:34:10 2012 -0500 7.2 +++ b/clojure/com/aurellem/gb/status.clj Thu Mar 22 20:10:09 2012 -0500 7.3 @@ -25,7 +25,16 @@ 7.4 (+ pokemon-1-status-address 7.5 (* poke-num pokemon-record-width))) 7.6 7.7 -(defn give-stat 7.8 +(defn read-status 7.9 + ([^SaveState state poke-num] 7.10 + (assert (<= 0 poke-num 5)) 7.11 + (status-code->status-name 7.12 + (aget (memory state) 7.13 + (pokemon-status-address poke-num)))) 7.14 + ([poke-num] 7.15 + (read-status @current-state poke-num))) 7.16 + 7.17 +(defn give-status 7.18 ([^SaveState state poke-num status] 7.19 (assert (<= 0 poke-num 5)) 7.20 (let [status-code 7.21 @@ -39,7 +48,7 @@ 7.22 ([status] 7.23 (give-stat @current-state 0 status))) 7.24 7.25 -(defn give-stat-all 7.26 +(defn give-status-all 7.27 ([^SaveState state status] 7.28 (reduce (fn [state num] 7.29 (give-stat state num status))
8.1 --- a/java/src/com/aurellem/gb/Gb.java Thu Mar 22 16:34:10 2012 -0500 8.2 +++ b/java/src/com/aurellem/gb/Gb.java Thu Mar 22 20:10:09 2012 -0500 8.3 @@ -109,6 +109,8 @@ 8.4 8.5 public static native void getROM(int[] store); 8.6 8.7 + public static native void writeROM(int[] newROM); 8.8 + 8.9 public static native void getWRAM(int[] store); 8.10 8.11 public static native void getVRAM(int[] store);
9.1 --- a/src/clojure/clojure.cpp Thu Mar 22 16:34:10 2012 -0500 9.2 +++ b/src/clojure/clojure.cpp Thu Mar 22 20:10:09 2012 -0500 9.3 @@ -184,6 +184,20 @@ 9.4 9.5 /* 9.6 * Class: com_aurellem_gb_Gb 9.7 + * Method: writeROM 9.8 + * Signature: ([I)V 9.9 + */ 9.10 +JNIEXPORT void JNICALL Java_com_aurellem_gb_Gb_writeROM 9.11 +(JNIEnv *env, jclass clazz, jintArray arr){ 9.12 + jint *new_rom = env->GetIntArrayElements(arr, 0); 9.13 + writeRom(new_rom); 9.14 + env->ReleaseIntArrayElements(arr, new_rom, 0); 9.15 +} 9.16 + 9.17 + 9.18 + 9.19 +/* 9.20 + * Class: com_aurellem_gb_Gb 9.21 * Method: getWRAM 9.22 * Signature: ([I)V 9.23 */
10.1 --- a/src/gb/GB.cpp Thu Mar 22 16:34:10 2012 -0500 10.2 +++ b/src/gb/GB.cpp Thu Mar 22 20:10:09 2012 -0500 10.3 @@ -3920,6 +3920,13 @@ 10.4 } 10.5 } 10.6 10.7 +void writeRom(int32* new_rom){ 10.8 + int i; 10.9 + for (i = 0; i < gbRomSize; i++){ 10.10 + gbRom[i] = (u8)(0xFF & new_rom[i]); 10.11 + } 10.12 +} 10.13 + 10.14 void storeWRam(int32* store){ 10.15 int i; 10.16 for (i = 0; i < 0x8000; i++){
11.1 --- a/src/gb/GB.h Thu Mar 22 16:34:10 2012 -0500 11.2 +++ b/src/gb/GB.h Thu Mar 22 20:10:09 2012 -0500 11.3 @@ -52,6 +52,8 @@ 11.4 11.5 extern void storeRam(int32 *); 11.6 extern void storeRom(int32 *); 11.7 +extern void writeRom(int32 *); 11.8 + 11.9 extern void storeWRam(int32 *); 11.10 extern void storeVRam(int32 *); 11.11 extern void storeRegisters(int32 *);