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