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
|
ocsenave@213
|
18 :n-times [0x50 0x09 0x05 0xCD 0x11 0x0]
|
ocsenave@213
|
19
|
ocsenave@213
|
20
|
ocsenave@213
|
21 })
|
ocsenave@213
|
22
|
ocsenave@234
|
23
|
ocsenave@234
|
24
|
ocsenave@234
|
25 (def meta-characters
|
ocsenave@234
|
26 {0x00 "non-meta text follows"
|
ocsenave@234
|
27 0x01 "load text from RAM (nn)"
|
ocsenave@234
|
28 0x02 "BCD number (nn)C" ;; C is 3 flags and 5 length bits."
|
ocsenave@234
|
29 0x03 "store text in RAM (nn)"
|
ocsenave@234
|
30 0x04 "draw box (nn)WH"
|
ocsenave@234
|
31 0x05 "BEGIN text on textbox line 2"
|
ocsenave@234
|
32 0x06 "wait for A or B"
|
ocsenave@234
|
33 0x07 "scrolling text"
|
ocsenave@234
|
34 0x08 "BEGIN routine"
|
ocsenave@234
|
35 0x09 "load RAM (nn) hex-to-dec. (nn)BC. B is bytes to read, C is
|
ocsenave@234
|
36 digits to display"
|
ocsenave@234
|
37 0x0A "wait 30 vblanks iff you pressed A or B"
|
ocsenave@234
|
38
|
ocsenave@234
|
39 0x0B "sound: got item"
|
ocsenave@234
|
40 0x0E "sound: learned skill"
|
ocsenave@234
|
41 0x0F "sound: got rarecandy" ;; incidentally, same as 'got item'
|
ocsenave@234
|
42 0x10 "sound: caught pokemon!"
|
ocsenave@234
|
43 0x11 "sound: gave OAK the parcel"
|
ocsenave@234
|
44 0x12 "sound: same as 0x10???"
|
ocsenave@234
|
45 0x13 "sound: new data added"
|
ocsenave@234
|
46 0x14 "sound: cry-nidorina"
|
ocsenave@234
|
47 0x15 "sound: cry-pidgeot"
|
ocsenave@234
|
48 0x16 "sound: cry-dewgong"
|
ocsenave@234
|
49
|
ocsenave@234
|
50 0x4E "new line"
|
ocsenave@234
|
51 0x51 "new page"
|
ocsenave@234
|
52 0x55 "scroll page"
|
ocsenave@234
|
53 0x50 "END command" ;; the pair 0x50 0x50 ??
|
ocsenave@234
|
54 0x57 "END command"
|
ocsenave@234
|
55 0x58 "END after you press A or B"
|
ocsenave@234
|
56 })
|
ocsenave@234
|
57
|
ocsenave@234
|
58
|
ocsenave@234
|
59
|
ocsenave@234
|
60
|
rlm@225
|
61 (def end-of-name-sentinel 0x00)
|
ocsenave@213
|
62
|
rlm@145
|
63 (def character-code->character
|
rlm@145
|
64 {
|
ocsenave@213
|
65 0x0 "" ;; separator character?
|
ocsenave@213
|
66 0x58 "\n"
|
rlm@225
|
67 ;;0x00 "<";;"end-of-name-sentinel" ;; begin messsage
|
ocsenave@213
|
68 ;;0x49 "\n //" ;; ocsenave: pagebreak pokedex
|
ocsenave@213
|
69 ;;0x4E "\n..." ; ocsenave: clearscroll pokedex page
|
ocsenave@227
|
70 ;;0x4F "\n" ; newline
|
ocsenave@213
|
71 ;;0x50 "#";;"end-of-pokemon-name-sentinel"
|
ocsenave@227
|
72 ;;0x51 "\n\n" ;; ocsenave: clear screen
|
ocsenave@213
|
73 0x52 "[RED]" ;;ocsenave: placeholder for your name?
|
ocsenave@194
|
74 0x54 "[POKE]"
|
ocsenave@227
|
75 ;;0x55 "_" ;; ocsenave: breaking space?
|
ocsenave@213
|
76 ;0x57 ">" ;; ocsenave: end message
|
ocsenave@213
|
77 ;0x5F ">" ;; ocsenave: end pokedex entry??
|
rlm@145
|
78 0x60 "A-bold"
|
rlm@145
|
79 0x61 "B-bold"
|
rlm@145
|
80 0x62 "C-bold"
|
rlm@145
|
81 0x63 "D-bold"
|
rlm@145
|
82 0x64 "E-bold"
|
rlm@145
|
83 0x65 "F-bold"
|
rlm@145
|
84 0x66 "G-bold"
|
rlm@145
|
85 0x67 "H-bold"
|
rlm@145
|
86 0x68 "I-bold"
|
rlm@145
|
87 0x69 "V-bold"
|
rlm@145
|
88 0x6A "S-bold"
|
rlm@145
|
89 0x6B "L-bold"
|
rlm@145
|
90 0x6C "M-bold"
|
ocsenave@194
|
91 0x7F " " ;space
|
rlm@145
|
92 0x80 "A"
|
rlm@145
|
93 0x81 "B"
|
rlm@145
|
94 0x82 "C"
|
rlm@145
|
95 0x83 "D"
|
rlm@145
|
96 0x84 "E"
|
rlm@145
|
97 0x85 "F"
|
rlm@145
|
98 0x86 "G"
|
rlm@145
|
99 0x87 "H"
|
rlm@145
|
100 0x88 "I"
|
rlm@145
|
101 0x89 "J"
|
rlm@145
|
102 0x8A "K"
|
rlm@145
|
103 0x8B "L"
|
rlm@145
|
104 0x8C "M"
|
rlm@145
|
105 0x8D "N"
|
rlm@145
|
106 0x8E "O"
|
rlm@145
|
107 0x8F "P"
|
rlm@145
|
108 0x90 "Q"
|
rlm@145
|
109 0x91 "R"
|
rlm@145
|
110 0x92 "S"
|
rlm@145
|
111 0x93 "T"
|
rlm@145
|
112 0x94 "U"
|
rlm@145
|
113 0x95 "V"
|
rlm@145
|
114 0x96 "W"
|
rlm@145
|
115 0x97 "X"
|
rlm@145
|
116 0x98 "Y"
|
rlm@145
|
117 0x99 "Z"
|
rlm@145
|
118 0x9A "("
|
rlm@145
|
119 0x9B ")"
|
rlm@145
|
120 0x9C ":"
|
rlm@145
|
121 0x9D ";"
|
rlm@145
|
122 0xA0 "a"
|
rlm@145
|
123 0xA1 "b"
|
rlm@145
|
124 0xA2 "c"
|
rlm@145
|
125 0xA3 "d"
|
rlm@145
|
126 0xA4 "e"
|
rlm@145
|
127 0xA5 "f"
|
rlm@145
|
128 0xA6 "g"
|
rlm@145
|
129 0xA7 "h"
|
rlm@145
|
130 0xA8 "i"
|
rlm@145
|
131 0xA9 "j"
|
rlm@145
|
132 0xAA "k"
|
rlm@145
|
133 0xAB "l"
|
rlm@145
|
134 0xAC "m"
|
rlm@145
|
135 0xAD "n"
|
rlm@145
|
136 0xAE "o"
|
rlm@145
|
137 0xAF "p"
|
rlm@145
|
138 0xB0 "q"
|
rlm@145
|
139 0xB1 "r"
|
rlm@145
|
140 0xB2 "s"
|
rlm@145
|
141 0xB3 "t"
|
rlm@145
|
142 0xB4 "u"
|
rlm@145
|
143 0xB5 "v"
|
rlm@145
|
144 0xB6 "w"
|
rlm@145
|
145 0xB7 "x"
|
rlm@145
|
146 0xB8 "y"
|
rlm@145
|
147 0xB9 "z"
|
ocsenave@194
|
148 0xBA "[e]" ;é
|
ocsenave@194
|
149 0xBB "'d" ;ocsenave
|
ocsenave@194
|
150 0xBC "'l" ;ocsenave
|
ocsenave@194
|
151 0xBD "'s" ;ocsenave
|
ocsenave@194
|
152 0xBE "'t" ;ocsenave
|
ocsenave@194
|
153 0xBF "'v" ; ocsenave
|
ocsenave@194
|
154
|
rlm@145
|
155 0xE0 "'"
|
rlm@145
|
156 0xE1 "PK"
|
rlm@145
|
157 0xE2 "MN"
|
rlm@148
|
158 0xE3 "-"
|
ocsenave@194
|
159 0xE4 "'r" ;ocsenave
|
ocsenave@194
|
160 0xE5 "'m" ;ocsenave
|
rlm@145
|
161 0xE6 "?"
|
rlm@145
|
162 0xE7 "!"
|
rlm@145
|
163 0xE8 "."
|
rlm@145
|
164 0xEF "male-symbol"
|
ocsenave@194
|
165 0xF0 "$" ;;"pokemon-money-symbol"
|
rlm@145
|
166 0xF1 "."
|
rlm@145
|
167 0xF2 "/"
|
rlm@145
|
168 0xF3 ","
|
ocsenave@194
|
169 0xF4 ", "
|
ocsenave@194
|
170 0xF5 "female-symbol" ;; ocsenave
|
rlm@145
|
171 0xF6 "0 "
|
rlm@145
|
172 0xF7 "1"
|
rlm@145
|
173 0xF8 "2"
|
rlm@145
|
174 0xF9 "3"
|
rlm@145
|
175 0xFA "4"
|
rlm@145
|
176 0xFB "5"
|
rlm@145
|
177 0xFC "6"
|
rlm@145
|
178 0xFD "7"
|
rlm@145
|
179 0xFE "8"
|
rlm@145
|
180 0xFF "9"
|
rlm@145
|
181 })
|
rlm@145
|
182
|
rlm@145
|
183 (def character->character-code
|
rlm@145
|
184 (zipmap (vals character-code->character)
|
rlm@145
|
185 (keys character-code->character)))
|
rlm@145
|
186
|
rlm@145
|
187 (defn str->character-codes [s]
|
rlm@145
|
188 (map character->character-code (map str s)))
|
rlm@145
|
189
|
rlm@145
|
190 (defn character-codes->str [codes]
|
rlm@145
|
191 (apply str
|
rlm@145
|
192 (map #(character-code->character
|
rlm@145
|
193 %
|
rlm@145
|
194 (format "[0x%02X]" %))
|
rlm@145
|
195 codes)))
|
rlm@145
|
196
|
rlm@176
|
197 (defn print-text
|
rlm@176
|
198 ([^SaveState state begin end]
|
rlm@176
|
199 (dorun
|
rlm@176
|
200 (map (fn [character-code line]
|
rlm@176
|
201 (println
|
rlm@176
|
202 (format "0x%04X: " line)
|
rlm@176
|
203 (str (character-code->character character-code))))
|
rlm@176
|
204 (subvec (vec (memory state)) begin end)
|
rlm@176
|
205 (range begin end)))
|
rlm@176
|
206 state)
|
rlm@176
|
207 ([begin end]
|
rlm@176
|
208 (print-text @current-state begin end)))
|
rlm@176
|
209
|
rlm@176
|
210 (defn read-name [codes]
|
rlm@176
|
211 (character-codes->str
|
rlm@176
|
212 (take-while
|
rlm@176
|
213 (partial not= end-of-name-marker) codes)))
|