view clojure/com/aurellem/gb/characters.clj @ 233:49a709c555f2

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