annotate clojure/com/aurellem/gb/characters.clj @ 235:5becef6312b9

working on item-injection; fixed off-by-one error in print-pokedex.
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 20:05:47 -0500
parents d5dddf33543c
children 30ced394823a
rev   line source
rlm@145 1 (ns com.aurellem.gb.characters
rlm@176 2 (:use (com.aurellem.gb gb-driver constants))
rlm@145 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@145 4
ocsenave@213 5
ocsenave@213 6 (def pronouns
ocsenave@213 7 ;; Note: 0x0 seems to be the end-of-name sentinel
ocsenave@213 8 {
ocsenave@213 9 ;; what is 0x57? what is 0x0?
ocsenave@213 10 :RED [0x52]
ocsenave@213 11 :BLUE [0x53]
ocsenave@213 12 :opponent [0x01 0x49 0xD0 0x0]
ocsenave@213 13 :turn-pokemon [0x5A]
ocsenave@213 14 :off-turn-pokemon [0x59]
ocsenave@213 15 :your-pokemon [0x01 0x08 0xD0 0x0]
ocsenave@213 16 :opponent-pokemon [0x50 0x01 0xD9 0xCF 0x0]
ocsenave@213 17 :n-times [0x50 0x09 0x05 0xCD 0x11 0x0]
ocsenave@213 18 })
ocsenave@213 19
rlm@225 20 (def end-of-name-sentinel 0x00)
ocsenave@213 21
rlm@145 22 (def character-code->character
rlm@145 23 {
ocsenave@213 24 0x0 "" ;; separator character?
ocsenave@213 25 0x58 "\n"
rlm@225 26 ;;0x00 "<";;"end-of-name-sentinel" ;; begin messsage
ocsenave@213 27 ;;0x49 "\n //" ;; ocsenave: pagebreak pokedex
ocsenave@213 28 ;;0x4E "\n..." ; ocsenave: clearscroll pokedex page
ocsenave@227 29 ;;0x4F "\n" ; newline
ocsenave@213 30 ;;0x50 "#";;"end-of-pokemon-name-sentinel"
ocsenave@227 31 ;;0x51 "\n\n" ;; ocsenave: clear screen
ocsenave@213 32 0x52 "[RED]" ;;ocsenave: placeholder for your name?
ocsenave@194 33 0x54 "[POKE]"
ocsenave@227 34 ;;0x55 "_" ;; ocsenave: breaking space?
ocsenave@213 35 ;0x57 ">" ;; ocsenave: end message
ocsenave@213 36 ;0x5F ">" ;; ocsenave: end pokedex entry??
rlm@145 37 0x60 "A-bold"
rlm@145 38 0x61 "B-bold"
rlm@145 39 0x62 "C-bold"
rlm@145 40 0x63 "D-bold"
rlm@145 41 0x64 "E-bold"
rlm@145 42 0x65 "F-bold"
rlm@145 43 0x66 "G-bold"
rlm@145 44 0x67 "H-bold"
rlm@145 45 0x68 "I-bold"
rlm@145 46 0x69 "V-bold"
rlm@145 47 0x6A "S-bold"
rlm@145 48 0x6B "L-bold"
rlm@145 49 0x6C "M-bold"
ocsenave@194 50 0x7F " " ;space
rlm@145 51 0x80 "A"
rlm@145 52 0x81 "B"
rlm@145 53 0x82 "C"
rlm@145 54 0x83 "D"
rlm@145 55 0x84 "E"
rlm@145 56 0x85 "F"
rlm@145 57 0x86 "G"
rlm@145 58 0x87 "H"
rlm@145 59 0x88 "I"
rlm@145 60 0x89 "J"
rlm@145 61 0x8A "K"
rlm@145 62 0x8B "L"
rlm@145 63 0x8C "M"
rlm@145 64 0x8D "N"
rlm@145 65 0x8E "O"
rlm@145 66 0x8F "P"
rlm@145 67 0x90 "Q"
rlm@145 68 0x91 "R"
rlm@145 69 0x92 "S"
rlm@145 70 0x93 "T"
rlm@145 71 0x94 "U"
rlm@145 72 0x95 "V"
rlm@145 73 0x96 "W"
rlm@145 74 0x97 "X"
rlm@145 75 0x98 "Y"
rlm@145 76 0x99 "Z"
rlm@145 77 0x9A "("
rlm@145 78 0x9B ")"
rlm@145 79 0x9C ":"
rlm@145 80 0x9D ";"
rlm@145 81 0xA0 "a"
rlm@145 82 0xA1 "b"
rlm@145 83 0xA2 "c"
rlm@145 84 0xA3 "d"
rlm@145 85 0xA4 "e"
rlm@145 86 0xA5 "f"
rlm@145 87 0xA6 "g"
rlm@145 88 0xA7 "h"
rlm@145 89 0xA8 "i"
rlm@145 90 0xA9 "j"
rlm@145 91 0xAA "k"
rlm@145 92 0xAB "l"
rlm@145 93 0xAC "m"
rlm@145 94 0xAD "n"
rlm@145 95 0xAE "o"
rlm@145 96 0xAF "p"
rlm@145 97 0xB0 "q"
rlm@145 98 0xB1 "r"
rlm@145 99 0xB2 "s"
rlm@145 100 0xB3 "t"
rlm@145 101 0xB4 "u"
rlm@145 102 0xB5 "v"
rlm@145 103 0xB6 "w"
rlm@145 104 0xB7 "x"
rlm@145 105 0xB8 "y"
rlm@145 106 0xB9 "z"
ocsenave@194 107 0xBA "[e]" ;é
ocsenave@194 108 0xBB "'d" ;ocsenave
ocsenave@194 109 0xBC "'l" ;ocsenave
ocsenave@194 110 0xBD "'s" ;ocsenave
ocsenave@194 111 0xBE "'t" ;ocsenave
ocsenave@194 112 0xBF "'v" ; ocsenave
ocsenave@194 113
rlm@145 114 0xE0 "'"
rlm@145 115 0xE1 "PK"
rlm@145 116 0xE2 "MN"
rlm@148 117 0xE3 "-"
ocsenave@194 118 0xE4 "'r" ;ocsenave
ocsenave@194 119 0xE5 "'m" ;ocsenave
rlm@145 120 0xE6 "?"
rlm@145 121 0xE7 "!"
rlm@145 122 0xE8 "."
rlm@145 123 0xEF "male-symbol"
ocsenave@194 124 0xF0 "$" ;;"pokemon-money-symbol"
rlm@145 125 0xF1 "."
rlm@145 126 0xF2 "/"
rlm@145 127 0xF3 ","
ocsenave@194 128 0xF4 ", "
ocsenave@194 129 0xF5 "female-symbol" ;; ocsenave
rlm@145 130 0xF6 "0 "
rlm@145 131 0xF7 "1"
rlm@145 132 0xF8 "2"
rlm@145 133 0xF9 "3"
rlm@145 134 0xFA "4"
rlm@145 135 0xFB "5"
rlm@145 136 0xFC "6"
rlm@145 137 0xFD "7"
rlm@145 138 0xFE "8"
rlm@145 139 0xFF "9"
rlm@145 140 })
rlm@145 141
rlm@145 142 (def character->character-code
rlm@145 143 (zipmap (vals character-code->character)
rlm@145 144 (keys character-code->character)))
rlm@145 145
rlm@145 146 (defn str->character-codes [s]
rlm@145 147 (map character->character-code (map str s)))
rlm@145 148
rlm@145 149 (defn character-codes->str [codes]
rlm@145 150 (apply str
rlm@145 151 (map #(character-code->character
rlm@145 152 %
rlm@145 153 (format "[0x%02X]" %))
rlm@145 154 codes)))
rlm@145 155
rlm@176 156 (defn print-text
rlm@176 157 ([^SaveState state begin end]
rlm@176 158 (dorun
rlm@176 159 (map (fn [character-code line]
rlm@176 160 (println
rlm@176 161 (format "0x%04X: " line)
rlm@176 162 (str (character-code->character character-code))))
rlm@176 163 (subvec (vec (memory state)) begin end)
rlm@176 164 (range begin end)))
rlm@176 165 state)
rlm@176 166 ([begin end]
rlm@176 167 (print-text @current-state begin end)))
rlm@176 168
rlm@176 169 (defn read-name [codes]
rlm@176 170 (character-codes->str
rlm@176 171 (take-while
rlm@176 172 (partial not= end-of-name-marker) codes)))