1 /* Hey EMACS -*- linux-c -*- */
2 /* $Id: type2str.c 2601 2007-07-14 08:49:30Z roms $ */
3
4 /* TiEmu - Tiemu Is an EMUlator
5 *
6 * Copyright (c) 2000-2001, Thomas Corvazier, Romain Lievin
7 * Copyright (c) 2001-2003, Romain Lievin
8 * Copyright (c) 2003, Julien Blache
9 * Copyright (c) 2004, Romain Li�vin
10 * Copyright (c) 2005, Romain Li�vin
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
25 */
26
27 /*
28 Type conversion routines
29 */
30
31 #include <stdio.h>
32 #include <string.h>
33
34 #include "intl.h"
35 #include "ti68k_def.h"
36 #include "bkpts.h"
37
ti68k_calctype_to_string(int type)38 const char *ti68k_calctype_to_string(int type)
39 {
40 switch(type)
41 {
42 case TI89: return "TI89";
43 case TI92: return "TI92";
44 case TI92p: return "TI92+";
45 case V200: return "V200PLT";
46 case TI89t: return "TI89t";
47 default: return "none";
48 }
49 }
50
ti68k_string_to_calctype(const char * str)51 int ti68k_string_to_calctype(const char *str)
52 {
53 if(!strcmp(str, "TI89"))
54 return TI89;
55 else if(!strcmp(str, "TI92"))
56 return TI92;
57 else if(!strcmp(str, "TI92+"))
58 return TI92p;
59 else if(!strcmp(str, "V200PLT"))
60 return V200;
61 else if(!strcmp(str, "TI89t"))
62 return TI89t;
63
64 return 0;
65 }
66
ti68k_romtype_to_string(int type)67 const char *ti68k_romtype_to_string(int type)
68 {
69 switch(type)
70 {
71 case 0: return "EPROM";
72 case FLASH_ROM: return "FLASH";
73 }
74
75 return 0;
76 }
77
ti68k_string_to_romtype(const char * str)78 int ti68k_string_to_romtype(const char *str)
79 {
80 if(!strcmp(str, "EPROM"))
81 return 0;
82 else if(!strcmp(str, "FLASH"))
83 return FLASH_ROM;
84
85 return 0;
86 }
87
ti68k_hwtype_to_string(int type)88 const char *ti68k_hwtype_to_string(int type)
89 {
90 switch(type)
91 {
92 case HW1: return "HW1";
93 case HW2: return "HW2";
94 case HW3: return "HW3";
95 case HW4: return "HW4";
96 default: return "none";
97 }
98 }
99
ti68k_string_to_hwtype(const char * str)100 int ti68k_string_to_hwtype(const char *str)
101 {
102 if(!strcmp(str, "HW1"))
103 return HW1;
104 else if(!strcmp(str, "HW2"))
105 return HW2;
106 else if(!strcmp(str, "HW3"))
107 return HW3;
108 else if(!strcmp(str, "HW4"))
109 return HW4;
110
111 return 0;
112 }
113
ti68k_exception_to_string(int number)114 const char *ti68k_exception_to_string(int number)
115 {
116 switch(number)
117 {
118 case 0: return _("Initial SSP");
119 case 1: return _("Initial PC");
120 case 2: return _("Bus Error vector");
121 case 3: return _("Address Error vector");
122 case 4: return _("Illegal Instruction vector");
123 case 5: return _("Zero Divide vector");
124 case 6: return _("CHK Instruction vector");
125 case 7: return _("TRAPV Instruction vector");
126 case 8: return _("Privilege Violation vector");
127 case 9: return _("Trace vector");
128 case 10: return _("Line 1010 Emulator vectors");
129 case 11: return _("Line 1111 Emulator vectors");
130 case 12: return _("Unassigned, reserved");
131 case 13: return _("Unassigned, reserved");
132 case 14: return _("Unassigned, reserved");
133 case 15: return _("Uninitialised Interrupt vector");
134 case 16: return _("Unassigned, reserved");
135 case 17: return _("Unassigned, reserved");
136 case 18: return _("Unassigned, reserved");
137 case 19: return _("Unassigned, reserved");
138 case 20: return _("Unassigned, reserved");
139 case 21: return _("Unassigned, reserved");
140 case 22: return _("Unassigned, reserved");
141 case 23: return _("Unassigned, reserved");
142 case 24: return _("Spurious Interrupt vector");
143 case 25: return _("Level 1 Interrupt auto-vectors");
144 case 26: return _("Level 2 Interrupt auto-vectors");
145 case 27: return _("Level 3 Interrupt auto-vectors");
146 case 28: return _("Level 4 Interrupt auto-vectors");
147 case 29: return _("Level 5 Interrupt auto-vectors");
148 case 30: return _("Level 6 Interrupt auto-vectors");
149 case 31: return _("Level 7 Interrupt auto-vectors");
150 case 32: return _("TRAP #0 Instruction vectors");
151 case 33: return _("TRAP #1 Instruction vectors");
152 case 34: return _("TRAP #2 Instruction vectors");
153 case 35: return _("TRAP #3 Instruction vectors");
154 case 36: return _("TRAP #4 Instruction vectors");
155 case 37: return _("TRAP #5 Instruction vectors");
156 case 38: return _("TRAP #6 Instruction vectors");
157 case 39: return _("TRAP #7 Instruction vectors");
158 case 40: return _("TRAP #8 Instruction vectors");
159 case 41: return _("TRAP #9 Instruction vectors");
160 case 42: return _("TRAP #10 Instruction vectors");
161 case 43: return _("TRAP #11 Instruction vectors");
162 case 44: return _("TRAP #12 Instruction vectors");
163 case 45: return _("TRAP #13 Instruction vectors");
164 case 46: return _("TRAP #14 Instruction vectors");
165 case 47: return _("TRAP #15 Instruction vectors");
166 case 48:
167 case 49:
168 case 50:
169 case 51:
170 case 52:
171 case 53:
172 case 54:
173 case 55:
174 case 56:
175 case 57:
176 case 58:
177 case 59:
178 case 60:
179 case 61:
180 case 62:
181 case 63: return _("Unassigned, reserved");
182 case 64: return _("User Interrupt vectors");
183
184 default: return _("User Interrupt vectors");
185 }
186 }
187
ti68k_bkpt_cause_to_string(int type)188 const char *ti68k_bkpt_cause_to_string(int type)
189 {
190 switch(type)
191 {
192 case BK_CAUSE_ACCESS: return _("access");
193 case BK_CAUSE_RANGE: return _("access range");
194 case BK_CAUSE_ADDRESS: return _("address");
195 case BK_CAUSE_EXCEPTION:return _("exception");
196 case BK_CAUSE_PGMENTRY: return _("prgm entry");
197 case BK_CAUSE_PROTECT: return _("hw protection");
198 case BK_CAUSE_BIT: return _("bit change");
199 default: return _("unknown");
200 }
201 }
202
203
ti68k_bkpt_type_to_string(int type)204 const char *ti68k_bkpt_type_to_string(int type)
205 {
206 switch(type)
207 {
208 case BK_TYPE_ACCESS: return _("access");
209 case BK_TYPE_RANGE: return _("range");
210 case BK_TYPE_CODE: return _("code");
211 case BK_TYPE_EXCEPTION: return _("exception");
212 case BK_TYPE_PGMENTRY: return _("prgm entry");
213 case BK_TYPE_PROTECT: return _("hw protection");
214 case BK_TYPE_BIT: return _("bit change");
215 default: return _("unknown");
216 }
217 }
218
ti68k_string_to_bkpt_type(const char * str)219 int ti68k_string_to_bkpt_type(const char *str)
220 {
221 if(!strcmp(str, _("access")))
222 return BK_TYPE_ACCESS;
223 else if(!strcmp(str, _("range")))
224 return BK_TYPE_RANGE;
225 else if(!strcmp(str, _("code")))
226 return BK_TYPE_CODE;
227 else if(!strcmp(str, _("exception")))
228 return BK_TYPE_EXCEPTION;
229 else if(!strcmp(str, _("prgm entry")))
230 return BK_TYPE_PGMENTRY;
231 else if(!strcmp(str, _("hw protection")))
232 return BK_TYPE_PROTECT;
233 else if(!strcmp(str, _("bit change")))
234 return BK_TYPE_BIT;
235
236 return 0;
237 }
238
ti68k_bkpt_mode_to_string(int type,int mode)239 const char *ti68k_bkpt_mode_to_string(int type, int mode)
240 {
241 // don't use type, it's implicit.
242 if( (mode & BK_READ) && !(mode & BK_WRITE) )
243 {
244 if(mode & BK_BYTE)
245 return "byte-read";
246 else if(mode & BK_WORD)
247 return "word-read";
248 else if(mode & BK_LONG)
249 return "long-read";
250 else
251 return "read";
252 }
253 else if( !(mode & BK_READ) && (mode & BK_WRITE) )
254 {
255 if(mode & BK_BYTE)
256 return "byte-write";
257 else if(mode & BK_WORD)
258 return "word-write";
259 else if(mode & BK_LONG)
260 return "long-write";
261 else
262 return "write";
263 }
264 else if( (mode & BK_READ) && (mode & BK_WRITE) )
265 {
266 if(mode & BK_BYTE)
267 return "r/w byte";
268 else if(mode & BK_WORD)
269 return "r/w word";
270 else if(mode & BK_LONG)
271 return "r/w long";
272 else
273 return "r/w";
274 }
275
276 return "unknown (bug)";
277 }
278
ti68k_string_to_bkpt_mode(const char * str)279 int ti68k_string_to_bkpt_mode(const char * str)
280 {
281 if(!strcmp(str, "any") || !strcmp(str, "r/w"))
282 return BK_READ | BK_WRITE;
283 else if(!strcmp(str, "read"))
284 return BK_READ;
285 else if(!strcmp(str, "write"))
286 return BK_WRITE;
287 else if(!strcmp(str, "byte-read"))
288 return BK_READ_BYTE;
289 else if(!strcmp(str, "word-read"))
290 return BK_READ_WORD;
291 else if(!strcmp(str, "long-read"))
292 return BK_READ_LONG;
293 else if(!strcmp(str, "byte-write"))
294 return BK_WRITE_BYTE;
295 else if(!strcmp(str, "word-write"))
296 return BK_WRITE_WORD;
297 else if(!strcmp(str, "long-write"))
298 return BK_WRITE_LONG;
299 else if(!strcmp(str, "r/w byte"))
300 return BK_RW_BYTE;
301 else if(!strcmp(str, "r/w word"))
302 return BK_RW_WORD;
303 else if(!strcmp(str, "r/w long"))
304 return BK_RW_LONG;
305 else
306 return 0;
307 }
308