• R/O
  • SSH
  • HTTPS

marathon: コミット


コミットメタ情報

リビジョン484 (tree)
日時2008-07-12 14:06:22
作者ookawa_mi

ログメッセージ

*** empty log message ***

変更サマリ

差分

--- marathon/trunk/AlephOneJP/RenderOther/TextStrings.cpp (nonexistent)
+++ marathon/trunk/AlephOneJP/RenderOther/TextStrings.cpp (revision 484)
@@ -0,0 +1,500 @@
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 2 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+ Text-String Collection
21+ by Loren Petrich,
22+ April 20, 2000
23+
24+ This is the implementation of my replacement for MacOS STR# resources
25+*/
26+
27+
28+#include <string.h>
29+#include "cseries.h"
30+#include "TextStrings.h"
31+
32+#include "XML_ElementParser.h"
33+
34+
35+// Private objects: the string collections, which form a linked list.
36+class StringSet
37+{
38+ short ID;
39+ size_t NumStrings;
40+ // Pointer to string pointers:
41+ unsigned char **Strings;
42+
43+public:
44+ // What's the ID
45+ short GetID() {return ID;}
46+
47+ // How many strings (contiguous from index zero)
48+ size_t CountStrings();
49+
50+ // Create a stringset with some ID
51+ StringSet(short _ID);
52+ ~StringSet();
53+
54+ // Assumes a MacOS Pascal string; the resulting string will have
55+ // a null byte at the end.
56+ void Add(size_t Index, unsigned char *String);
57+
58+ // Get a string; return NULL if not found
59+ unsigned char *GetString(size_t Index);
60+
61+ // Delete a string
62+ void Delete(size_t Index);
63+
64+ // For making a linked list (I'll let Rhys Hill find more efficient data structures)
65+ StringSet *Next;
66+};
67+
68+
69+// How many strings (contiguous from index zero)
70+size_t StringSet::CountStrings()
71+{
72+ size_t StringCount = 0;
73+
74+ for (size_t k=0; k<NumStrings; k++)
75+ {
76+ if (Strings[k])
77+ StringCount++;
78+ else
79+ break;
80+ }
81+
82+ return StringCount;
83+}
84+
85+
86+StringSet::StringSet(short _ID)
87+{
88+ // Of course
89+ ID = _ID;
90+
91+ NumStrings = 16; // Reasonable starting number; what Sun uses in Java
92+ Strings = new unsigned char *[NumStrings];
93+
94+ // Set all the string pointers to NULL
95+ objlist_clear(Strings,NumStrings);
96+
97+ // Last, but not least:
98+ Next = NULL;
99+}
100+
101+StringSet::~StringSet()
102+{
103+ for (size_t k=0; k<NumStrings; k++)
104+ {
105+ unsigned char *StringPtr = Strings[k];
106+ if (StringPtr) delete []StringPtr;
107+ }
108+ delete []Strings;
109+}
110+
111+// Assumes a MacOS Pascal string; the resulting string will have
112+// a null byte at the end.
113+void StringSet::Add(size_t Index, unsigned char *String)
114+{
115+ if (Index < 0) return;
116+
117+ // Replace string list with longer one if necessary
118+ size_t NewNumStrings = NumStrings;
119+ while (Index >= NewNumStrings) {NewNumStrings <<= 1;}
120+
121+ if (NewNumStrings > NumStrings)
122+ {
123+ unsigned char **NewStrings = new unsigned char *[NewNumStrings];
124+ objlist_clear(NewStrings+NumStrings,(NewNumStrings-NumStrings));
125+ objlist_copy(NewStrings,Strings,NumStrings);
126+ delete []Strings;
127+ Strings = NewStrings;
128+ NumStrings = NewNumStrings;
129+ }
130+
131+ // Delete the old string if necessary
132+ if (Strings[Index]) delete []Strings[Index];
133+
134+ unsigned short Length = String[0] << 8 | String[1];
135+ unsigned char *_String = new unsigned char[Length+3];
136+ memcpy(_String,String,Length+2);
137+ _String[Length+2] = 0; // for making an in-place C string
138+// printf("[%d]:%s\n",Index,_String+2);
139+ Strings[Index] = _String;
140+}
141+
142+// Get a string; return NULL if not found
143+unsigned char *StringSet::GetString(size_t Index)
144+{
145+ if (Index < 0 || Index >= NumStrings) return NULL;
146+
147+ return Strings[Index];
148+}
149+
150+// Delete a string
151+void StringSet::Delete(size_t Index)
152+{
153+ if (Index < 0 || Index >= NumStrings) return;
154+
155+ unsigned char *StringPtr = Strings[Index];
156+ if (StringPtr) {delete []StringPtr; Strings[Index] = 0;}
157+}
158+
159+static StringSet *StringSetRoot = NULL;
160+
161+static StringSet *FindStringSet(short ID)
162+{
163+ StringSet *PrevStringSet = NULL, *CurrStringSet = StringSetRoot;
164+ while(CurrStringSet)
165+ {
166+ PrevStringSet = CurrStringSet;
167+ if (CurrStringSet->GetID() == ID) break;
168+ CurrStringSet = CurrStringSet->Next;
169+ }
170+
171+ // Add to the end if not found
172+ if (!CurrStringSet)
173+ {
174+ StringSet *NewStringSet = new StringSet(ID);
175+ assert(NewStringSet);
176+ if (PrevStringSet)
177+ PrevStringSet->Next = NewStringSet;
178+ else
179+ StringSetRoot = NewStringSet;
180+ CurrStringSet = NewStringSet;
181+ }
182+
183+ return CurrStringSet;
184+}
185+
186+// Error strings
187+static const char IndexNotFound[] = "\"index\" attribute not found";
188+
189+
190+// Parser of a set of strings
191+
192+class XML_StringSetParser: public XML_ElementParser
193+{
194+public:
195+ // Pointer to current stringset
196+ StringSet *CurrStringSet;
197+
198+ // Callbacks
199+ bool Start() {CurrStringSet = NULL; return true;}
200+ bool HandleAttribute(const char *Tag, const char *Value);
201+ bool AttributesDone();
202+
203+ XML_StringSetParser(): XML_ElementParser("stringset") {}
204+};
205+
206+bool XML_StringSetParser::HandleAttribute(const char *Tag, const char *Value)
207+{
208+ if (StringsEqual(Tag,"index"))
209+ {
210+ short ID;
211+ if (ReadInt16Value(Value,ID))
212+ {
213+ CurrStringSet = FindStringSet(ID);
214+ return true;
215+ }
216+ else return false;
217+ }
218+ UnrecognizedTag();
219+ return false;
220+}
221+
222+bool XML_StringSetParser::AttributesDone()
223+{
224+ if (!CurrStringSet)
225+ {
226+ ErrorString = IndexNotFound;
227+ return false;
228+ }
229+ return true;
230+}
231+
232+static XML_StringSetParser StringSetParser;
233+
234+
235+// Parser of a single string
236+
237+
238+class XML_StringParser: public XML_ElementParser
239+{
240+ // Check presence of index; having a DTD-using XML parser would
241+ // make this check unnecessary
242+ bool IndexPresent;
243+
244+ // Was the string loaded? If not, then load a blank string at the end
245+ bool StringLoaded;
246+
247+public:
248+ // Callbacks
249+ bool Start();
250+ bool End();
251+ bool HandleAttribute(const char *Tag, const char *Value);
252+ bool AttributesDone();
253+ bool HandleString(const char *String, int Length);
254+
255+ // The string's index value
256+ short Index;
257+
258+ XML_StringParser(): XML_ElementParser("string") {}
259+};
260+
261+
262+bool XML_StringParser::Start() {
263+
264+ IndexPresent = false;
265+ StringLoaded = false;
266+ return true;
267+}
268+
269+bool XML_StringParser::HandleAttribute(const char *Tag, const char *Value)
270+{
271+ if (StringsEqual(Tag,"index"))
272+ {
273+ if (ReadInt16Value(Value,Index))
274+ {
275+ IndexPresent = true;
276+ return true;
277+ }
278+ else return false;
279+ }
280+ UnrecognizedTag();
281+ return false;
282+}
283+
284+bool XML_StringParser::HandleString(const char *String, int Length)
285+{
286+ // Copy into Pascal string
287+ Str255 StringBuffer;
288+ DeUTF8_Pas(String,Length,StringBuffer,1020);
289+
290+ // Load!
291+ assert(StringSetParser.CurrStringSet);
292+ StringSetParser.CurrStringSet->Add(Index,StringBuffer);
293+
294+ StringLoaded = true;
295+ return true;
296+}
297+
298+bool XML_StringParser::AttributesDone()
299+{
300+ if (!IndexPresent)
301+ {
302+ ErrorString = IndexNotFound;
303+ return false;
304+ }
305+ return true;
306+}
307+
308+bool XML_StringParser::End()
309+{
310+ if (!StringLoaded)
311+ {
312+ // Load an empty string
313+ unsigned char StringBuffer[1];
314+ StringBuffer[0] = 0;
315+ assert(StringSetParser.CurrStringSet);
316+ StringSetParser.CurrStringSet->Add(Index,StringBuffer);
317+ }
318+
319+ return true;
320+}
321+
322+static XML_StringParser StringParser;
323+
324+
325+// Public routines:
326+
327+
328+// Set up a string in the repository; a repeated call will replace an old string
329+void TS_PutString(short ID, short Index, unsigned char *String)
330+{
331+ // Search for string set:
332+ StringSet *CurrStringSet = FindStringSet(ID);
333+ CurrStringSet->Add(Index,String);
334+}
335+
336+
337+// ZZZ: Set up a C-string in the repository; a repeated call will replace an old string
338+void TS_PutCString(short ID, short Index, const char *String)
339+{
340+ // Search for string set: (FindStringSet() creates a new one if necessary)
341+ StringSet *CurrStringSet = FindStringSet(ID);
342+
343+ // Create a PString of the incoming CString, truncate to fit
344+ unsigned char thePStringStagingBuffer[1024];
345+
346+ size_t theStringLength = strlen(String);
347+
348+ if(theStringLength > 1020)
349+ theStringLength = 1020;
350+
351+ // Fill in the string length.
352+ // thePStringStagingBuffer[0] = (char)theStringLength;
353+ ((short*)(thePStringStagingBuffer))[0] = theStringLength;
354+
355+ // Copy exactly the string bytes (no termination etc.)
356+ memcpy(&(thePStringStagingBuffer[2]), String, theStringLength);
357+
358+ // Add() copies the string, so using the stack here is OK.
359+ CurrStringSet->Add(Index,thePStringStagingBuffer);
360+}
361+
362+
363+// Returns a pointer to a string; if the ID and the index do not point to a valid string,
364+// this function will then return NULL
365+unsigned char *TS_GetString(short ID, size_t Index)
366+{
367+ // Search for string set:
368+ StringSet *PrevStringSet = NULL, *CurrStringSet = StringSetRoot;
369+
370+ while(CurrStringSet)
371+ {
372+ if (CurrStringSet->GetID() == ID) break;
373+ PrevStringSet = CurrStringSet;
374+ CurrStringSet = CurrStringSet->Next;
375+ }
376+
377+ if (!CurrStringSet) return NULL;
378+
379+ return CurrStringSet->GetString(Index);
380+}
381+
382+
383+// Here is that string in C form
384+char *TS_GetCString(short ID, size_t Index)
385+{
386+ unsigned char *String = TS_GetString(ID,Index);
387+ if (!String) return NULL;
388+
389+ // Move away from the length byte to the first content byte
390+ return (char *)(String+2);
391+}
392+
393+
394+// Checks on the presence of a string set
395+bool TS_IsPresent(short ID)
396+{
397+ // Search for string set:
398+ StringSet *PrevStringSet = NULL, *CurrStringSet = StringSetRoot;
399+
400+ while(CurrStringSet)
401+ {
402+ if (CurrStringSet->GetID() == ID) return true;
403+ PrevStringSet = CurrStringSet;
404+ CurrStringSet = CurrStringSet->Next;
405+ }
406+
407+ return false;
408+}
409+
410+
411+// Count the strings (contiguous from index zero)
412+size_t TS_CountStrings(short ID)
413+{
414+ // Search for string set:
415+ StringSet *PrevStringSet = NULL, *CurrStringSet = StringSetRoot;
416+
417+ while(CurrStringSet)
418+ {
419+ if (CurrStringSet->GetID() == ID) break;
420+ PrevStringSet = CurrStringSet;
421+ CurrStringSet = CurrStringSet->Next;
422+ }
423+
424+ if (!CurrStringSet) return 0;
425+
426+ return CurrStringSet->CountStrings();
427+}
428+
429+
430+// Deletes a string, should one ever want to do that
431+void TS_DeleteString(short ID, short Index)
432+{
433+ // Search for string set:
434+ StringSet *PrevStringSet = NULL, *CurrStringSet = StringSetRoot;
435+
436+ while(CurrStringSet)
437+ {
438+ if (CurrStringSet->GetID() == ID) break;
439+ PrevStringSet = CurrStringSet;
440+ CurrStringSet = CurrStringSet->Next;
441+ }
442+
443+ if (!CurrStringSet) return;
444+
445+ CurrStringSet->Delete(Index);
446+}
447+
448+
449+// Deletes the stringset with some ID
450+void TS_DeleteStringSet(short ID)
451+{
452+ // Search for string set:
453+ StringSet *PrevStringSet = NULL, *CurrStringSet = StringSetRoot;
454+
455+ while(CurrStringSet)
456+ {
457+ if (CurrStringSet->GetID() == ID) break;
458+ PrevStringSet = CurrStringSet;
459+ CurrStringSet = CurrStringSet->Next;
460+ }
461+
462+ if (!CurrStringSet) return;
463+
464+ // Get the next string set:
465+ StringSet *NextStringSet = CurrStringSet->Next;
466+
467+ // Clip out that string set
468+ if (PrevStringSet)
469+ PrevStringSet->Next = NextStringSet;
470+ else
471+ StringSetRoot = NextStringSet;
472+
473+ delete CurrStringSet;
474+}
475+
476+
477+// Deletes all of the stringsets
478+void TS_DeleteAllStrings()
479+{
480+ StringSet *CurrStringSet = StringSetRoot;
481+
482+ while(CurrStringSet)
483+ {
484+ StringSet *NextStringSet = CurrStringSet->Next;
485+ delete CurrStringSet;
486+ CurrStringSet = NextStringSet;
487+ }
488+
489+ StringSetRoot = NULL;
490+}
491+
492+
493+// Set up a text-string XML parser and return a pointer to it
494+// Don't try to delete it when one is finished with it
495+XML_ElementParser *TS_GetParser()
496+{
497+ StringSetParser.AddChild(&StringParser);
498+ return &StringSetParser;
499+}
500+
--- marathon/trunk/AlephOneJP/RenderOther/HUDRenderer.cpp (nonexistent)
+++ marathon/trunk/AlephOneJP/RenderOther/HUDRenderer.cpp (revision 484)
@@ -0,0 +1,841 @@
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 2 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+
22+/*
23+ * HUDRenderer.cpp - HUD rendering base class and data
24+ *
25+ * Written in 2001 by Christian Bauer
26+ */
27+
28+#include "HUDRenderer.h"
29+#include "network.h" // NetDisplayPings(), NetGetLatency()
30+#include "lua_script.h" // texture palette
31+
32+using namespace std;
33+
34+/*
35+ * Move rectangle
36+ */
37+
38+static inline void offset_rect(screen_rectangle *rect, short dx, short dy)
39+{
40+ rect->top += dy;
41+ rect->left += dx;
42+ rect->bottom += dy;
43+ rect->right += dx;
44+}
45+
46+
47+/*
48+ * Update all HUD elements
49+ */
50+
51+bool HUD_Class::update_everything(short time_elapsed)
52+{
53+ ForceUpdate = false;
54+
55+ if (!LuaTexturePaletteSize())
56+ {
57+
58+ update_motion_sensor(time_elapsed);
59+ update_inventory_panel((time_elapsed == NONE) ? true : false);
60+ update_weapon_panel((time_elapsed == NONE) ? true : false);
61+ update_ammo_display((time_elapsed == NONE) ? true : false);
62+ update_suit_energy(time_elapsed);
63+ update_suit_oxygen(time_elapsed);
64+
65+ // Draw the message area if the player count is greater than one
66+ if (dynamic_world->player_count > 1)
67+ draw_message_area(time_elapsed);
68+ }
69+ else
70+ {
71+ int size;
72+ // some good looking break points, based on 640x160
73+ if (LuaTexturePaletteSize() <= 5)
74+ size = 128;
75+ else if (LuaTexturePaletteSize() <= 16)
76+ size = 80;
77+ else if (LuaTexturePaletteSize() <= 36)
78+ size = 53;
79+ else if (LuaTexturePaletteSize() <= 64)
80+ size = 40;
81+ else if (LuaTexturePaletteSize() <= 100)
82+ size = 32;
83+ else if (LuaTexturePaletteSize() <= 144)
84+ size = 26;
85+ else
86+ size = 20;
87+
88+ int rows = 160 / size;
89+ int cols = 640 / size;
90+
91+ int x_offset = (640 - cols * size) / 2;
92+ int y_offset = (160 - rows * size) / 2;
93+
94+ for (int i = 0; i < LuaTexturePaletteSize(); ++i)
95+ {
96+ if (LuaTexturePaletteTexture(i) != UNONE)
97+ DrawTexture(LuaTexturePaletteTexture(i), (i % cols) * size + x_offset, 320 + y_offset + (i / cols) * size, size - 1);
98+ }
99+
100+ if (LuaTexturePaletteSelected() >= 0)
101+ {
102+ int i = LuaTexturePaletteSelected();
103+ screen_rectangle r;
104+ r.left = (i % cols) * size + x_offset;
105+ r.right = r.left + size;
106+ r.top = 320 + y_offset + (i / cols) * size;
107+ r.bottom = r.top + size;
108+ FrameRect(&r, _inventory_text_color);
109+ }
110+
111+ ForceUpdate = true;
112+ }
113+
114+ return ForceUpdate;
115+}
116+
117+
118+/*
119+ * Update energy bar
120+ */
121+
122+void HUD_Class::update_suit_energy(short time_elapsed)
123+{
124+ /* time_elapsed==NONE means force redraw */
125+ if (time_elapsed==NONE || (interface_state.shield_is_dirty))
126+ {
127+ // LP addition: display needs to be updated
128+ ForceUpdate = true;
129+
130+ screen_rectangle *shield_rect= get_interface_rectangle(_shield_rect);
131+ short width= shield_rect->right-shield_rect->left;
132+ short actual_width, suit_energy;
133+ short background_shape_id, bar_shape_id, bar_top_shape_id;
134+
135+ suit_energy = current_player->suit_energy%PLAYER_MAXIMUM_SUIT_ENERGY;
136+
137+ if( !suit_energy &&
138+ current_player->suit_energy==PLAYER_MAXIMUM_SUIT_ENERGY ||
139+ current_player->suit_energy==2*PLAYER_MAXIMUM_SUIT_ENERGY ||
140+ current_player->suit_energy==3*PLAYER_MAXIMUM_SUIT_ENERGY)
141+ {
142+ suit_energy= PLAYER_MAXIMUM_SUIT_ENERGY;
143+ }
144+
145+ actual_width= (suit_energy*width)/PLAYER_MAXIMUM_SUIT_ENERGY;
146+
147+ /* Setup the bars.. */
148+ if(current_player->suit_energy>2*PLAYER_MAXIMUM_SUIT_ENERGY)
149+ {
150+ background_shape_id= _double_energy_bar;
151+ bar_shape_id= _triple_energy_bar;
152+ bar_top_shape_id= _triple_energy_bar_right;
153+ }
154+ else if(current_player->suit_energy>PLAYER_MAXIMUM_SUIT_ENERGY)
155+ {
156+ background_shape_id= _energy_bar;
157+ bar_shape_id= _double_energy_bar;
158+ bar_top_shape_id= _double_energy_bar_right;
159+ }
160+ else
161+ {
162+ background_shape_id= _empty_energy_bar;
163+ bar_shape_id= _energy_bar;
164+ bar_top_shape_id= _energy_bar_right;
165+ if(current_player->suit_energy<0) actual_width= 0;
166+ }
167+
168+ draw_bar(shield_rect, actual_width,
169+ BUILD_DESCRIPTOR(_collection_interface, bar_top_shape_id),
170+ BUILD_DESCRIPTOR(_collection_interface, bar_shape_id),
171+ BUILD_DESCRIPTOR(_collection_interface, background_shape_id));
172+
173+ interface_state.shield_is_dirty= false;
174+ }
175+}
176+
177+
178+/*
179+ * Update oxygen bar
180+ */
181+
182+void HUD_Class::update_suit_oxygen(short time_elapsed)
183+{
184+ static short delay_time= 0;
185+
186+ /* Redraw the oxygen only if the interface is visible and only if enough delay has passed.. */
187+ if(((delay_time-= time_elapsed)<0) || time_elapsed==NONE || interface_state.oxygen_is_dirty)
188+ {
189+ // LP addition: display needs to be updated
190+ ForceUpdate = true;
191+
192+ screen_rectangle *oxygen_rect= get_interface_rectangle(_oxygen_rect);
193+ short width, actual_width;
194+ short suit_oxygen;
195+
196+ suit_oxygen= MIN(current_player->suit_oxygen, PLAYER_MAXIMUM_SUIT_OXYGEN);
197+ width= oxygen_rect->right-oxygen_rect->left;
198+ actual_width= (suit_oxygen*width)/PLAYER_MAXIMUM_SUIT_OXYGEN;
199+
200+ draw_bar(oxygen_rect, actual_width,
201+ BUILD_DESCRIPTOR(_collection_interface, _oxygen_bar_right),
202+ BUILD_DESCRIPTOR(_collection_interface, _oxygen_bar),
203+ BUILD_DESCRIPTOR(_collection_interface, _empty_oxygen_bar));
204+
205+ delay_time= DELAY_TICKS_BETWEEN_OXYGEN_REDRAW;
206+ interface_state.oxygen_is_dirty= false;
207+ }
208+}
209+
210+
211+/*
212+ * A change of weapon has occurred, change the weapon display panel
213+ */
214+
215+void HUD_Class::update_weapon_panel(bool force_redraw)
216+{
217+ if(force_redraw || interface_state.weapon_is_dirty)
218+ {
219+ // LP addition: display needs to be updated
220+ ForceUpdate = true;
221+
222+ char *weapon_name = temporary;
223+ struct weapon_interface_data *definition;
224+ screen_rectangle *destination= get_interface_rectangle(_weapon_display_rect);
225+ screen_rectangle source;
226+ short desired_weapon= get_player_desired_weapon(current_player_index);
227+
228+ /* Now we have to erase, because the panel won't do it for us.. */
229+ FillRect(destination, _inventory_background_color);
230+
231+ if(desired_weapon != NONE)
232+ {
233+ assert(desired_weapon>=0 && desired_weapon<short(MAXIMUM_WEAPON_INTERFACE_DEFINITIONS));
234+
235+ definition= weapon_interface_definitions+desired_weapon;
236+
237+ /* Check if it is a multi weapon */
238+ if(definition->multi_weapon)
239+ {
240+ if (definition->multiple_unusable_shape != UNONE)
241+ {
242+ /* always draw the single */
243+ if (definition->weapon_panel_shape != UNONE)
244+ DrawShapeAtXY(definition->weapon_panel_shape,
245+ definition->standard_weapon_panel_left,
246+ definition->standard_weapon_panel_top);
247+
248+ if(current_player->items[definition->item_id]>1)
249+ {
250+ if (definition->multiple_shape != UNONE)
251+ DrawShapeAtXY(
252+ definition->multiple_shape,
253+ definition->standard_weapon_panel_left + definition->multiple_delta_x,
254+ definition->standard_weapon_panel_top + definition->multiple_delta_y);
255+ }
256+ else
257+ {
258+ /* Draw the empty one.. */
259+ DrawShapeAtXY(
260+ definition->multiple_unusable_shape,
261+ definition->standard_weapon_panel_left + definition->multiple_delta_x,
262+ definition->standard_weapon_panel_top + definition->multiple_delta_y);
263+ }
264+ }
265+ else
266+ {
267+ if(current_player->items[definition->item_id]>1)
268+ {
269+ if (definition->multiple_shape != UNONE)
270+ DrawShapeAtXY(
271+ definition->multiple_shape,
272+ definition->standard_weapon_panel_left + definition->multiple_delta_x,
273+ definition->standard_weapon_panel_top + definition->multiple_delta_y);
274+ } else {
275+ if (definition->weapon_panel_shape != UNONE)
276+ DrawShapeAtXY(definition->weapon_panel_shape,
277+ definition->standard_weapon_panel_left,
278+ definition->standard_weapon_panel_top);
279+ }
280+ }
281+ } else {
282+ /* Slam it to the screen! */
283+ if(definition->weapon_panel_shape != UNONE)
284+ {
285+ DrawShapeAtXY(definition->weapon_panel_shape,
286+ definition->standard_weapon_panel_left,
287+ definition->standard_weapon_panel_top);
288+ }
289+ }
290+
291+ /* Get the weapon name.. */
292+ if(desired_weapon != _weapon_ball)
293+ {
294+#define strWEAPON_NAME_LIST 137
295+ getcstr(weapon_name, strWEAPON_NAME_LIST, desired_weapon);
296+ } else {
297+ short item_index;
298+
299+ /* Which ball do they actually have? */
300+ for(item_index= BALL_ITEM_BASE; item_index<BALL_ITEM_BASE+MAXIMUM_NUMBER_OF_PLAYERS; ++item_index)
301+ {
302+ if(current_player->items[item_index]>0) break;
303+ }
304+ assert(item_index != BALL_ITEM_BASE+MAXIMUM_NUMBER_OF_PLAYERS);
305+ get_item_name(weapon_name, item_index, false);
306+ }
307+
308+ /* Draw the weapon name.. */
309+ source= *destination;
310+ source.top= definition->weapon_name_start_y;
311+ source.bottom= definition->weapon_name_end_y;
312+ if(definition->weapon_name_start_x != NONE)
313+ {
314+ source.left= definition->weapon_name_start_x;
315+ }
316+
317+ if(definition->weapon_name_end_x != NONE)
318+ {
319+ source.right= definition->weapon_name_end_x;
320+ }
321+
322+ DrawText(weapon_name, &source, _center_horizontal|_center_vertical,
323+ _weapon_name_font, _inventory_text_color);
324+
325+ /* And make sure that the ammo knows it needs to update */
326+ interface_state.ammo_is_dirty= true;
327+ }
328+ interface_state.weapon_is_dirty= false;
329+ }
330+}
331+
332+
333+/*
334+ * Update ammunition display
335+ */
336+
337+void HUD_Class::update_ammo_display(bool force_redraw)
338+{
339+ if(force_redraw || interface_state.ammo_is_dirty)
340+ {
341+ // LP addition: display needs to be updated
342+ ForceUpdate = true;
343+
344+ draw_ammo_display_in_panel(_primary_interface_ammo);
345+ draw_ammo_display_in_panel(_secondary_interface_ammo);
346+ interface_state.ammo_is_dirty= false;
347+ }
348+}
349+
350+
351+/*
352+ * Update inventory display
353+ */
354+
355+void HUD_Class::update_inventory_panel(bool force_redraw)
356+{
357+ /* changed_item gets erased first.. */
358+ /* This should probably go to a gworld first, or something */
359+ short section_items[NUMBER_OF_ITEMS];
360+ short section_counts[NUMBER_OF_ITEMS];
361+ short section_count, loop;
362+ short item_type, current_row;
363+
364+ if(INVENTORY_IS_DIRTY(current_player) || force_redraw)
365+ {
366+ // LP addition: display needs to be updated
367+ ForceUpdate = true;
368+
369+ screen_rectangle *destination= get_interface_rectangle(_inventory_rect);
370+ screen_rectangle text_rectangle;
371+ short max_lines= max_displayable_inventory_lines();
372+
373+ /* Recalculate and redraw.. */
374+ item_type= GET_CURRENT_INVENTORY_SCREEN(current_player);
375+
376+ /* Reset the row.. */
377+ current_row= 0;
378+ if(!NetDisplayPings() && item_type!=_network_statistics)
379+ {
380+ /* Get the types and names */
381+ calculate_player_item_array(current_player_index, item_type,
382+ section_items, section_counts, &section_count);
383+ }
384+
385+ /* Draw the header. */
386+ if (NetDisplayPings())
387+ strcpy(temporary, "PING");
388+ else
389+ get_header_name(temporary, item_type);
390+ draw_inventory_header(temporary, current_row++);
391+
392+ /* Erase the panel.. */
393+ text_rectangle= *destination;
394+ text_rectangle.top+= _get_font_line_height(_interface_font);
395+ FillRect(&text_rectangle, _inventory_background_color);
396+
397+#if !defined(DISABLE_NETWORKING)
398+ if (NetDisplayPings() || item_type==_network_statistics)
399+ {
400+ char remaining_time[16];
401+ int seconds = dynamic_world->game_information.game_time_remaining / TICKS_PER_SECOND;
402+ if (seconds / 60 < 1000) // start counting down at 999 minutes
403+ {
404+ sprintf(remaining_time, "%d:%02d", seconds/60, seconds%60);
405+ draw_inventory_time(remaining_time, current_row-1); // compensate for current_row++ above
406+ } else if (GET_GAME_OPTIONS() & _game_has_kill_limit)
407+ {
408+ switch (GET_GAME_TYPE())
409+ {
410+ case _game_of_kill_monsters:
411+ case _game_of_cooperative_play:
412+ case _game_of_king_of_the_hill:
413+ case _game_of_kill_man_with_ball:
414+ case _game_of_tag:
415+
416+ short player_index;
417+ int kill_limit = INT_MAX;
418+ for (player_index = 0; player_index < dynamic_world->player_count;++player_index)
419+ {
420+ struct player_data *player = get_player_data(player_index);
421+
422+ int kills_left = dynamic_world->game_information.kill_limit - (player->total_damage_given.kills - player->damage_taken[player_index].kills);
423+ if (kills_left < kill_limit) kill_limit = kills_left;
424+ }
425+ char kills_left[4];
426+ sprintf(kills_left, "%d", kill_limit);
427+ draw_inventory_time(kills_left, current_row-1);
428+ break;
429+ }
430+ }
431+
432+ if (NetDisplayPings())
433+ {
434+ for (loop = 0; loop < dynamic_world->player_count; ++loop)
435+ {
436+ screen_rectangle dest_rect;
437+ struct player_data *player = get_player_data(loop);
438+ short width;
439+
440+ calculate_inventory_rectangle_from_offset(&dest_rect, current_row++);
441+ if (NetGetLatency(loop) == kNetLatencyInvalid)
442+ {
443+ sprintf(temporary, " ");
444+ }
445+ else if (NetGetLatency(loop) == kNetLatencyDisconnected)
446+ {
447+ sprintf(temporary, "DC");
448+ }
449+ else
450+ {
451+ sprintf(temporary, "%i", NetGetLatency(loop));
452+ }
453+
454+ width = _text_width(temporary, _interface_font);
455+ dest_rect.right -= width;
456+ dest_rect.left += TEXT_INSET;
457+
458+ char name_with_index[MAX_NET_PLAYER_NAME_LENGTH + 2];
459+ sprintf(name_with_index, "%i %s", loop, player->name);
460+ DrawText(name_with_index, &dest_rect, _center_vertical, _interface_font, PLAYER_COLOR_BASE_INDEX + player->color);
461+
462+ dest_rect.right += width;
463+ dest_rect.left = dest_rect.right-width;
464+ DrawText(temporary, &dest_rect, _center_vertical, _interface_font, PLAYER_COLOR_BASE_INDEX + player->color);
465+ }
466+ }
467+ else
468+ {
469+
470+ struct player_ranking_data rankings[MAXIMUM_NUMBER_OF_PLAYERS];
471+
472+ calculate_player_rankings(rankings);
473+
474+ /* Calculate the network statistics. */
475+ for(loop= 0; loop<dynamic_world->player_count; ++loop)
476+ {
477+ screen_rectangle dest_rect;
478+ struct player_data *player= get_player_data(rankings[loop].player_index);
479+ short width;
480+
481+ calculate_inventory_rectangle_from_offset(&dest_rect, current_row++);
482+ calculate_ranking_text(temporary, rankings[loop].ranking);
483+
484+ /* Draw the player name.. */
485+ width= _text_width(temporary, _interface_font);
486+ dest_rect.right-= width;
487+ dest_rect.left+= TEXT_INSET;
488+ DrawText(player->name, &dest_rect, _center_vertical,
489+ _interface_font, PLAYER_COLOR_BASE_INDEX+player->color);
490+
491+ /* Now draw the ranking_text */
492+ dest_rect.right+= width;
493+ dest_rect.left= dest_rect.right-width;
494+ DrawText(temporary, &dest_rect, _center_vertical,
495+ _interface_font, PLAYER_COLOR_BASE_INDEX+player->color);
496+ }
497+ }
498+ }
499+ else
500+#endif // !defined(DISABLE_NETWORKING)
501+ {
502+ /* Draw the items. */
503+ for(loop= 0; loop<section_count && current_row<max_lines; ++loop)
504+ {
505+ bool valid_in_this_environment;
506+
507+ /* Draw the item */
508+ get_item_name(temporary, section_items[loop], (section_counts[loop]!=1));
509+ valid_in_this_environment= item_valid_in_current_environment(section_items[loop]);
510+ draw_inventory_item(temporary, section_counts[loop], current_row++, false, valid_in_this_environment);
511+ }
512+ }
513+
514+ SET_INVENTORY_DIRTY_STATE(current_player, false);
515+ }
516+}
517+
518+
519+/*
520+ * Draw the text in the rectangle, starting at the given offset, on the
521+ * far left. Headers also have their backgrounds erased first.
522+ */
523+
524+void HUD_Class::draw_inventory_header(char *text, short offset)
525+{
526+ screen_rectangle destination;
527+
528+ calculate_inventory_rectangle_from_offset(&destination, offset);
529+
530+ /* Erase.. */
531+ FillRect(&destination, _inventory_header_background_color);
532+
533+ /* Now draw the text. */
534+ destination.left+= TEXT_INSET;
535+ DrawText(text, &destination, _center_vertical, _interface_font,
536+ _inventory_text_color);
537+}
538+
539+/*
540+ * Draw the time in the far right of the rectangle; does not erase the background...should always be called after
541+ * draw_inventory_header
542+ */
543+void HUD_Class::draw_inventory_time(char *text, short offset)
544+{
545+
546+ screen_rectangle destination;
547+
548+ calculate_inventory_rectangle_from_offset(&destination, offset);
549+
550+ destination.left = destination.right - _text_width(text, _interface_font) - TEXT_INSET;
551+ DrawText(text, &destination, _center_vertical, _interface_font, _inventory_text_color);
552+}
553+
554+
555+/*
556+ * Calculate inventory rectangle
557+ */
558+
559+void HUD_Class::calculate_inventory_rectangle_from_offset(screen_rectangle *r, short offset)
560+{
561+ screen_rectangle *inventory_rect= get_interface_rectangle(_inventory_rect);
562+ short line_height= _get_font_line_height(_interface_font);
563+
564+ *r= *inventory_rect;
565+ r->top += offset*line_height;
566+ r->bottom= r->top + line_height;
567+}
568+
569+
570+/*
571+ * Calculate number of visible inventory lines
572+ */
573+
574+short HUD_Class::max_displayable_inventory_lines(void)
575+{
576+ screen_rectangle *destination= get_interface_rectangle(_inventory_rect);
577+ return (destination->bottom-destination->top)/_get_font_line_height(_interface_font);
578+}
579+
580+
581+/*
582+ * Draw health/oxygen bar
583+ */
584+
585+void HUD_Class::draw_bar(screen_rectangle *rectangle, short width,
586+ shape_descriptor top_piece, shape_descriptor full_bar,
587+ shape_descriptor background_texture)
588+{
589+ screen_rectangle destination= *rectangle;
590+ screen_rectangle source;
591+ screen_rectangle bar_section;
592+
593+ /* Draw the background (right). */
594+ destination.left+= width;
595+ source= destination;
596+
597+ offset_rect(&source, -rectangle->left, -rectangle->top);
598+ DrawShape(background_texture, &destination, &source);
599+
600+ /* Draw the top bit.. */
601+ if(width>2*TOP_OF_BAR_WIDTH)
602+ {
603+ DrawShapeAtXY(top_piece, rectangle->left+width-TOP_OF_BAR_WIDTH,
604+ rectangle->top);
605+ } else {
606+ destination= *rectangle;
607+
608+ /* Gotta take lines off the top, so that the bottom stuff is still visible.. */
609+ destination.left= rectangle->left+width/2+width%2;
610+ destination.right= destination.left+width/2;
611+
612+ source= destination;
613+ offset_rect(&source, -source.left+TOP_OF_BAR_WIDTH-width/2, -source.top);
614+ DrawShape(top_piece, &destination, &source);
615+ }
616+
617+ /* Copy the bar.. */
618+ bar_section= *rectangle;
619+ bar_section.right= bar_section.left+width-TOP_OF_BAR_WIDTH;
620+
621+ if(bar_section.left<bar_section.right)
622+ {
623+ screen_rectangle bar_section_source= bar_section;
624+
625+ offset_rect(&bar_section_source, -rectangle->left, -rectangle->top);
626+ DrawShape(full_bar, &bar_section, &bar_section_source);
627+ }
628+}
629+
630+
631+/*
632+ * Draw ammo display
633+ */
634+
635+void HUD_Class::draw_ammo_display_in_panel(short trigger_id)
636+{
637+ struct weapon_interface_data *current_weapon_data;
638+ struct weapon_interface_ammo_data *current_ammo_data;
639+ short ammunition_count;
640+ short desired_weapon= get_player_desired_weapon(current_player_index);
641+
642+ /* Based on desired weapon, so we can get ammo updates as soon as we change */
643+ if(desired_weapon != NONE)
644+ {
645+ current_weapon_data= weapon_interface_definitions+desired_weapon;
646+ current_ammo_data= &current_weapon_data->ammo_data[trigger_id];
647+
648+ if(trigger_id==_primary_interface_ammo)
649+ {
650+ ammunition_count= get_player_weapon_ammo_count(current_player_index, desired_weapon, _primary_weapon);
651+ } else {
652+ ammunition_count= get_player_weapon_ammo_count(current_player_index, desired_weapon, _secondary_weapon);
653+ }
654+
655+ /* IF we have ammo for this trigger.. */
656+ if(current_ammo_data->type!=_unused_interface_data && ammunition_count!=NONE)
657+ {
658+ if(current_ammo_data->type==_uses_energy)
659+ {
660+ /* Energy beam weapon-> progress bar type.. */
661+ short fill_height;
662+ screen_rectangle bounds;
663+
664+ /* Pin it.. */
665+ ammunition_count= PIN(ammunition_count, 0, current_ammo_data->ammo_across);
666+ fill_height= (ammunition_count*(current_ammo_data->delta_y-2))/current_ammo_data->ammo_across;
667+
668+ /* Setup the energy left bar... */
669+ bounds.left= current_ammo_data->screen_left;
670+ bounds.right= current_ammo_data->screen_left+current_ammo_data->delta_x;
671+ bounds.bottom= current_ammo_data->screen_top+current_ammo_data->delta_y;
672+ bounds.top= current_ammo_data->screen_top;
673+
674+ /* Frame the rectangle */
675+ FrameRect(&bounds, current_ammo_data->bullet);
676+
677+ /* Inset the rectangle.. */
678+ bounds.left+=1; bounds.right-=1; bounds.bottom-= 1; bounds.top+=1;
679+
680+ /* Fill with the full stuff.. */
681+ bounds.top= bounds.bottom-fill_height;
682+ FillRect(&bounds, current_ammo_data->bullet);
683+
684+ /* Now erase the rest of the rectangle */
685+ bounds.bottom= bounds.top;
686+ bounds.top= current_ammo_data->screen_top+1;
687+
688+ /* Fill it. */
689+ FillRect(&bounds, current_ammo_data->empty_bullet);
690+
691+ /* We be done.. */
692+ } else {
693+ /* Uses ammunition, a little trickier.. */
694+ short row, x, y;
695+ screen_rectangle destination, source;
696+ short max, partial_row_count;
697+
698+ x= current_ammo_data->screen_left;
699+ y= current_ammo_data->screen_top;
700+
701+ destination.left= x;
702+ destination.top= y;
703+
704+ /* Pin it.. */
705+ max= current_ammo_data->ammo_down*current_ammo_data->ammo_across;
706+ ammunition_count= PIN(ammunition_count, 0, max);
707+
708+ /* Draw all of the full rows.. */
709+ for(row=0; row<(ammunition_count/current_ammo_data->ammo_across); ++row)
710+ {
711+ DrawShapeAtXY(current_ammo_data->bullet,
712+ x, y);
713+ y+= current_ammo_data->delta_y;
714+ }
715+
716+ /* Draw the partially used row.. */
717+ partial_row_count= ammunition_count%current_ammo_data->ammo_across;
718+ if(partial_row_count)
719+ {
720+ /* If we use ammo from right to left.. */
721+ if(current_ammo_data->right_to_left)
722+ {
723+ /* Draw the unused part of the row.. */
724+ destination.left= x, destination.top= y;
725+ destination.right= x+(partial_row_count*current_ammo_data->delta_x);
726+ destination.bottom= y+current_ammo_data->delta_y;
727+ source= destination;
728+ offset_rect(&source, -source.left, -source.top);
729+ DrawShape(current_ammo_data->bullet, &destination, &source);
730+
731+ /* Draw the used part of the row.. */
732+ destination.left= destination.right,
733+ destination.right= destination.left+(current_ammo_data->ammo_across-partial_row_count)*current_ammo_data->delta_x;
734+ source= destination;
735+ offset_rect(&source, -source.left, -source.top);
736+ DrawShape(current_ammo_data->empty_bullet, &destination, &source);
737+ } else {
738+ /* Draw the used part of the row.. */
739+ destination.left= x, destination.top= y;
740+ destination.right= x+(current_ammo_data->ammo_across-partial_row_count)*current_ammo_data->delta_x;
741+ destination.bottom= y+current_ammo_data->delta_y;
742+ source= destination;
743+ offset_rect(&source, -source.left, -source.top);
744+ DrawShape(current_ammo_data->empty_bullet, &destination, &source);
745+
746+ /* Draw the unused part of the row */
747+ destination.left= destination.right;
748+ destination.right= destination.left+(partial_row_count*current_ammo_data->delta_x);
749+ source= destination;
750+ offset_rect(&source, -source.left, -source.top);
751+ DrawShape(current_ammo_data->bullet, &destination, &source);
752+ }
753+ y+= current_ammo_data->delta_y;
754+ }
755+
756+ /* Draw the remaining rows. */
757+ x= current_ammo_data->screen_left;
758+ for(row=0; row<(max-ammunition_count)/current_ammo_data->ammo_across; ++row)
759+ {
760+ DrawShapeAtXY(current_ammo_data->empty_bullet,
761+ x, y);
762+ y+= current_ammo_data->delta_y;
763+ }
764+ }
765+ }
766+ }
767+}
768+
769+
770+/*
771+ * Draw inventory item
772+ */
773+
774+void HUD_Class::draw_inventory_item(char *text, short count,
775+ short offset, bool erase_first, bool valid_in_this_environment)
776+{
777+ screen_rectangle destination, text_destination;
778+ char *count_text = temporary;
779+ short color;
780+
781+ calculate_inventory_rectangle_from_offset(&destination, offset);
782+
783+ /* Select the color for the text.. */
784+ color= (valid_in_this_environment) ? (_inventory_text_color) : (_invalid_weapon_color);
785+
786+ /* Erase on items that changed only in count.. */
787+ if(erase_first)
788+ {
789+ FillRect(&destination, _inventory_background_color);
790+ } else {
791+ /* Unfortunately, we must always erase the numbers.. */
792+ text_destination= destination;
793+ text_destination.right= text_destination.left+NAME_OFFSET+TEXT_INSET;
794+ FillRect(&text_destination, _inventory_background_color);
795+ }
796+
797+ /* Draw the text name.. */
798+ text_destination= destination;
799+ text_destination.left+= NAME_OFFSET+TEXT_INSET;
800+ DrawText(text, &text_destination, _center_vertical, _interface_font, color);
801+
802+ /* Draw the text count-> Change the font!! */
803+ text_destination= destination;
804+ text_destination.left+= TEXT_INSET;
805+ sprintf(count_text, "%3d", count);
806+ DrawText(count_text, &text_destination, _center_vertical, _interface_item_count_font, color);
807+}
808+
809+
810+/*
811+ * Draw player name
812+ */
813+
814+void HUD_Class::draw_player_name(void)
815+{
816+ struct player_data *player= get_player_data(current_player_index);
817+ screen_rectangle *player_name_rect= get_interface_rectangle(_player_name_rect);
818+
819+ DrawText(player->name, player_name_rect,
820+ _center_vertical | _center_horizontal, _player_name_font,
821+ player->color+PLAYER_COLOR_BASE_INDEX);
822+}
823+
824+
825+/*
826+ * Draw the message area, and then put messages or player name in the buffer
827+ */
828+
829+#define MESSAGE_AREA_X_OFFSET 291
830+#define MESSAGE_AREA_Y_OFFSET 321
831+
832+void HUD_Class::draw_message_area(short time_elapsed)
833+{
834+ if(time_elapsed == NONE)
835+ {
836+ DrawShapeAtXY(
837+ BUILD_DESCRIPTOR(_collection_interface, _network_panel),
838+ MESSAGE_AREA_X_OFFSET, MESSAGE_AREA_Y_OFFSET);
839+ draw_player_name();
840+ }
841+}
--- marathon/trunk/AlephOneJP/CSeries/csstrings.cpp (nonexistent)
+++ marathon/trunk/AlephOneJP/CSeries/csstrings.cpp (revision 484)
@@ -0,0 +1,466 @@
1+/*
2+ CSSTRINGS.CPP
3+
4+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
5+ and the "Aleph One" developers.
6+
7+ This program is free software; you can redistribute it and/or modify
8+ it under the terms of the GNU General Public License as published by
9+ the Free Software Foundation; either version 2 of the License, or
10+ (at your option) any later version.
11+
12+ This program is distributed in the hope that it will be useful,
13+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ GNU General Public License for more details.
16+
17+ This license is contained in the file "COPYING",
18+ which is included with this source code; it is available online at
19+ http://www.gnu.org/licenses/gpl.html
20+
21+ // LP addition: use XML as source of strings (Apr 20, 2000)
22+
23+ // LP (Aug 28, 2001): Added "fdprintf" -- used like dprintf, but writes to file AlephOneDebugLog.txt
24+
25+ Sept-Nov 2001 (Woody Zenfell): added a few new pstring-oriented routines
26+
27+ Jan 25, 2002 (Br'fin (Jeremy Parsons)):
28+ Added TARGET_API_MAC_CARBON for Carbon.h
29+ Carbon logging utilites directly format the pascal string as
30+ c2pstr is obsolete and I didn't want to allocate the memory
31+ to use CopyCStringToPascal
32+
33+ May 10, 2005 (Woody Zenfell): merged almost-identical-but-annoyingly-not-quite
34+ csstrings.cpp (Macintosh) and csstrings_sdl.cpp into this file.
35+ */
36+
37+// When building SDL, XML_ElementParser.h, when included here, whined that Str255 was undefined.
38+// (presumably, carbon target acts similarly without precompiled headers)
39+// So, here you go, XML_ElementParser.h.
40+// This is an ugly hack. Please fix.
41+typedef unsigned char Str255[1024];
42+
43+#include <stdio.h>
44+#include <stdarg.h>
45+#include <string.h>
46+
47+#if defined(EXPLICIT_CARBON_HEADER)
48+# include <Carbon/Carbon.h>
49+#endif
50+
51+#include "csstrings.h"
52+#include "TextStrings.h"
53+#include "Logging.h"
54+
55+#include <map>
56+
57+using namespace std;
58+
59+char temporary[1024];
60+
61+
62+
63+/*
64+ * Count number of strings with given resid
65+ */
66+size_t countstr(
67+ short resid)
68+{
69+ return TS_CountStrings(resid);
70+}
71+
72+
73+
74+/*
75+ * Get pascal string
76+ */
77+unsigned char *getpstr(
78+ unsigned char *string,
79+ short resid,
80+ size_t item)
81+{
82+ unsigned char *CollString = TS_GetString(resid,item);
83+ if (CollString)
84+ {
85+ memcpy(string,CollString,(((short*)(CollString))[0])+1);
86+ }
87+ else
88+ {
89+ string[0] = 0;
90+ }
91+ return string;
92+}
93+
94+
95+
96+/*
97+ * Get C string
98+ */
99+char *getcstr(
100+ char *string,
101+ short resid,
102+ size_t item)
103+{
104+ unsigned char *CollString = TS_GetString(resid,item);
105+ if (CollString)
106+ {
107+ // The C string is offset one from the Pascal string
108+ memcpy(string,CollString+2,(((short*)(CollString))[0])+1);
109+ string[(((short*)(CollString))[0])+1] = 0;
110+ }
111+ else
112+ {
113+ string[0] = 0;
114+ }
115+ return string;
116+}
117+
118+
119+
120+/*
121+ * Copy pascal string
122+ */
123+unsigned char *pstrcpy(
124+ unsigned char *dst,
125+ const unsigned char *src)
126+{
127+ memcpy(dst,src,(((short*)(src))[0])+1);
128+ return dst;
129+}
130+
131+
132+
133+/*
134+ * Create String Vector
135+ */
136+
137+const vector<string> build_stringvector_from_stringset (int resid)
138+{
139+ vector<string> result;
140+ int index = 0;
141+
142+ while (TS_GetCString(resid, index) != NULL) {
143+ result.push_back (string (TS_GetCString(resid, index)));
144+ index++;
145+ }
146+
147+ return result;
148+}
149+
150+/*
151+ * String format routines
152+ */
153+char *csprintf(
154+ char *buffer,
155+ const char *format,
156+ ...)
157+{
158+ va_list list;
159+
160+ va_start(list,format);
161+ vsprintf(buffer,format,list);
162+ va_end(list);
163+ return buffer;
164+}
165+
166+
167+
168+unsigned char *psprintf(
169+ unsigned char *buffer,
170+ const char *format,
171+ ...)
172+{
173+ va_list list;
174+
175+ va_start(list,format);
176+ vsprintf((char *)buffer+2,format,list);
177+ va_end(list);
178+ int Len = strlen((char *)buffer+2);
179+ ((short*)(buffer))[0] = Len;
180+ return buffer;
181+}
182+
183+
184+
185+// dprintf() is obsolete with the general logging framework. Migrate to log* (see Logging.h)
186+// (if Logging doesn't do what you need, improve it :) )
187+void
188+dprintf(const char* format, ...) {
189+ va_list list;
190+ va_start(list, format);
191+ GetCurrentLogger()->logMessageV(logDomain, logAnomalyLevel, "unknown", 0, format, list);
192+ va_end(list);
193+}
194+
195+
196+
197+// fdprintf() is obsolete with the general logging framework. Migrate to log* (see Logging.h)
198+// (if Logging doesn't do what you need, improve it :) )
199+void
200+fdprintf(const char* format, ...) {
201+ va_list list;
202+ va_start(list, format);
203+ GetCurrentLogger()->logMessageV(logDomain, logAnomalyLevel, "unknown", 0, format, list);
204+ va_end(list);
205+}
206+
207+
208+
209+void copy_string_to_pstring (const std::string &s, unsigned char* dst, int maxlen)
210+{
211+ dst[0] = s.copy (reinterpret_cast<char *>(dst+2), maxlen);
212+}
213+
214+
215+
216+void copy_string_to_cstring (const std::string &s, char* dst, int maxlen)
217+{
218+ dst [s.copy (dst, maxlen)] = '\0';
219+}
220+
221+
222+
223+const std::string pstring_to_string (const unsigned char* ps)
224+{
225+ return std::string(reinterpret_cast<const char*>(ps) + 1, ps[0]);
226+}
227+
228+
229+
230+/*
231+ * String conversion routines (ZZZ)
232+ */
233+
234+// a1 prefix is to avoid conflict with any already-existing functions.
235+
236+// In-place conversion of Pstring to Cstring
237+char *a1_p2cstr(unsigned char* inoutStringBuffer)
238+{
239+ unsigned char length = ((short*)(inoutStringBuffer))[0];
240+ memmove(inoutStringBuffer, &inoutStringBuffer[2], length);
241+ inoutStringBuffer[length] = '\0';
242+ return (char *)inoutStringBuffer;
243+}
244+
245+
246+
247+// In-place conversion of Cstring to Pstring. Quietly truncates string to 255 chars.
248+unsigned char *a1_c2pstr(char *inoutStringBuffer)
249+{
250+ size_t length = strlen(inoutStringBuffer);
251+ if (length > 1020)
252+ length = 1020;
253+ memmove(&inoutStringBuffer[2], inoutStringBuffer, length);
254+ ((short*)(inoutStringBuffer))[0] = length;
255+ return (unsigned char *)inoutStringBuffer;
256+}
257+
258+
259+
260+// ZZZ: added for safety
261+// Overwrites total_byte_count of Pstring 'dest' with nonoverlapping Pstring 'source' and null padding
262+unsigned char *pstrncpy(unsigned char *dest, const unsigned char *source, size_t total_byte_count)
263+{
264+ size_t source_count = ((short*)(source))[0];
265+ if (total_byte_count <= source_count) {
266+ // copy truncated
267+ ((short*)(dest))[0] = (unsigned char)total_byte_count - 1;
268+ memcpy(&dest[2], &source[2], ((short*)(dest))[0]);
269+ return dest;
270+ } else {
271+ // copy full
272+ memcpy(dest, source, source_count + 1);
273+ if (source_count + 1 < total_byte_count) {
274+ // pad
275+ memset(&dest[source_count + 1], 0, total_byte_count - (source_count + 1));
276+ }
277+ return dest;
278+ }
279+}
280+
281+
282+
283+// ZZZ: added for convenience
284+// Duplicate a Pstring. Result should be free()d when no longer needed.
285+unsigned char *pstrdup(const unsigned char *inString)
286+{
287+ unsigned char *out = (unsigned char *)malloc(((short*)(inString))[0] + 1);
288+ pstrcpy(out, inString);
289+ return out;
290+}
291+
292+class MacRomanUnicodeConverter
293+{
294+public:
295+ MacRomanUnicodeConverter();
296+ inline uint16 ToUnicode(char c) {
297+ return mac_roman_to_unicode_table[(unsigned char) c];
298+ }
299+
300+ inline char ToMacRoman(uint16 c) {
301+ if (c <= 0x7f) return c;
302+ std::map<uint16, char>::iterator it = unicode_to_mac_roman.find(c);
303+ if (it != unicode_to_mac_roman.end())
304+ return it->second;
305+ else
306+ return '?';
307+ }
308+
309+private:
310+
311+ static uint16 mac_roman_to_unicode_table[256];
312+ static std::map<uint16, char> unicode_to_mac_roman;
313+ static bool initialized;
314+};
315+
316+// from ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/APPLE/ROMAN.TXT
317+uint16 MacRomanUnicodeConverter::mac_roman_to_unicode_table[256] = {
318+ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
319+ 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
320+ 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
321+ 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
322+ 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
323+ 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
324+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
325+ 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
326+ 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
327+ 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
328+ 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
329+ 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
330+ 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
331+ 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
332+ 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
333+ 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
334+ 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
335+ 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
336+ 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
337+ 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
338+ 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
339+ 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
340+ 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
341+ 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8,
342+ 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
343+ 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
344+ 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
345+ 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02,
346+ 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
347+ 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
348+ 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
349+ 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7
350+};
351+
352+std::map<uint16, char> MacRomanUnicodeConverter::unicode_to_mac_roman;
353+bool MacRomanUnicodeConverter::initialized = false;
354+
355+MacRomanUnicodeConverter::MacRomanUnicodeConverter()
356+{
357+ if (!initialized)
358+ {
359+ for (unsigned char c = 0x80; c < 0xff; c++)
360+ {
361+ unicode_to_mac_roman[mac_roman_to_unicode_table[c]] = (char) c;
362+ }
363+ initialized = true;
364+ }
365+}
366+
367+static MacRomanUnicodeConverter macRomanUnicodeConverter;
368+
369+void mac_roman_to_unicode(const char *input, uint16 *output)
370+{
371+ const char *p = input;
372+
373+ while (*p)
374+ {
375+ *output++ = macRomanUnicodeConverter.ToUnicode(*p++);
376+ }
377+ *output = 0x0;
378+}
379+
380+void mac_roman_to_unicode(const char *input, uint16 *output, int max_len)
381+{
382+ const char *p = input;
383+
384+ while (*p && --max_len > 0)
385+ {
386+ *output++ = macRomanUnicodeConverter.ToUnicode(*p++);
387+ }
388+ *output = 0x0;
389+}
390+
391+uint16 mac_roman_to_unicode(char c)
392+{
393+ return macRomanUnicodeConverter.ToUnicode(c);
394+}
395+
396+char unicode_to_mac_roman(uint16 c)
397+{
398+ return macRomanUnicodeConverter.ToMacRoman(c);
399+}
400+
401+static void unicode_to_utf8(uint16 c, string& output)
402+{
403+ if (c < 0x80)
404+ {
405+ output += c;
406+ }
407+ else if (c < 0x800)
408+ {
409+ output += (0xc0 | c >> 6);
410+ output += (0x80 | c & 0x3f);
411+ }
412+ else
413+ {
414+ output += (0xe0 | c >> 12);
415+ output += (0x80 | c >> 6 & 0x3f);
416+ output += (0x80 | c & 0x3f);
417+ }
418+}
419+
420+static uint16 utf8_to_unicode(const char *s, int &chars_used)
421+{
422+ const unsigned char *input = (unsigned char *) s;
423+ if ((unsigned char) input[0] < 0x80)
424+ {
425+ chars_used = 1;
426+ return input[0];
427+ }
428+ else if ((unsigned char) input[0] < 0xe0)
429+ {
430+ chars_used = 2;
431+ return ((input[0] & 0x1f) << 6) | (input[1] & 0x3f);
432+ }
433+ else
434+ {
435+ chars_used = 3;
436+ return ((input[0] & 0xf) << 12) | ((input[1] & 0x3f) << 6) | (input[2] & 0x3f);
437+ }
438+}
439+
440+std::string mac_roman_to_utf8(const std::string& input)
441+{
442+ const char *p = input.data();
443+ std::string output;
444+ while (*p)
445+ {
446+ uint16 uc = mac_roman_to_unicode(*p++);
447+ unicode_to_utf8(uc, output);
448+ }
449+
450+ return output;
451+}
452+
453+std::string utf8_to_mac_roman(const std::string& input)
454+{
455+ const char *p = input.data();
456+ std::string output;
457+ while (*p)
458+ {
459+ int advance = 0;
460+ uint16 uc = utf8_to_unicode(p, advance);
461+ output += unicode_to_mac_roman(uc);
462+ p += advance;
463+ }
464+
465+ return output;
466+}
--- marathon/trunk/AlephOneJP/CSeries/cseries.h (nonexistent)
+++ marathon/trunk/AlephOneJP/CSeries/cseries.h (revision 484)
@@ -0,0 +1,139 @@
1+/*
2+
3+ Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 2 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+*/
21+// Loren Petrich: the author(s) of the "cseries" files is not given, but is probably
22+// either Bo Lindbergh, Mihai Parparita, or both, given their efforts in getting the
23+// code working initially.
24+// AS: It was almost certainly Bo Lindbergh
25+#ifndef _CSERIES
26+#define _CSERIES
27+
28+#ifdef HAVE_CONFIG_H
29+#include "config.h"
30+#else
31+#define VERSION "unknown version"
32+#endif
33+
34+#include <SDL.h>
35+#include <SDL_byteorder.h>
36+#include <time.h>
37+#include <string>
38+
39+#define DEBUG
40+
41+#ifndef __MVCPP__
42+
43+// mwcc doesn't accept "using namespace std;" otherwise
44+namespace std {};
45+
46+#elif __MVCPP__
47+
48+using namespace std; // Visual C++ doesn't like that other way of using the namespace.
49+#if _MSC_VER < 1300
50+#define for if(false) {} else for // solves a bug in MSVC prior to MSVC7 for the "redeclared" initializers used in for loops.
51+#endif
52+
53+//#define VERSION "1.0"
54+
55+#endif
56+
57+/*
58+ * Endianess definitions
59+ */
60+
61+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
62+#define ALEPHONE_LITTLE_ENDIAN 1
63+#else
64+#undef ALEPHONE_LITTLE_ENDIAN
65+#endif
66+
67+
68+/*
69+ * Data types with specific bit width
70+ */
71+
72+#include "cstypes.h"
73+
74+/*
75+ * Emulation of MacOS data types and definitions
76+ */
77+#if !defined(SDL_RFORK_HACK)// && !defined(TARGET_API_MAC_CARBON)
78+
79+//#if defined(__APPLE__) && defined(__MACH__)
80+// if we're on the right platform, we can use the real thing (and get headers for functions we might want to use)
81+//#include <CoreFoundation/CoreFoundation.h>
82+//#elif !defined(TARGET_API_MAC_CARBON)
83+typedef int OSErr;
84+typedef unsigned char Str255[1024];
85+
86+struct Rect {
87+ int16 top, left;
88+ int16 bottom, right;
89+};
90+
91+const int noErr = 0;
92+//#endif
93+
94+struct RGBColor {
95+ uint16 red, green, blue;
96+};
97+
98+const int kFontIDMonaco = 4;
99+const int kFontIDCourier = 22;
100+
101+#else
102+# if !defined(TARGET_API_MAC_CARBON)
103+# define DEBUGASSERTMSG
104+# endif
105+# ifdef DEBUG
106+# define WAS_DEBUG
107+//AS: this is ugly...
108+
109+# undef DEBUG
110+# endif
111+# if !defined(TARGET_API_MAC_CARBON)
112+# define dialog CHEESEOFDEATH
113+# define DialogPtr mDialogPtr
114+# include <MacTypes.h>
115+# include <Quickdraw.h>
116+# undef dialog
117+# undef DialogPtr
118+# endif
119+# ifdef WAS_DEBUG
120+# define DEBUG
121+# endif
122+#endif
123+
124+/*
125+ * Include CSeries headers
126+ */
127+
128+#include "cstypes.h"
129+#include "csmacros.h"
130+#include "cscluts.h"
131+#include "csstrings.h"
132+#include "csfonts.h"
133+#include "cspixels.h"
134+#include "csalerts.h"
135+#include "csdialogs.h"
136+#include "csmisc.h"
137+
138+
139+#endif
--- marathon/trunk/AlephOneJP/CSeries/csstrings.h (nonexistent)
+++ marathon/trunk/AlephOneJP/CSeries/csstrings.h (revision 484)
@@ -0,0 +1,109 @@
1+/* csstrings.h
2+
3+ Copyright (C) 1991-2001 and beyond by Bo Lindbergh
4+ and the "Aleph One" developers.
5+
6+ This program is free software; you can redistribute it and/or modify
7+ it under the terms of the GNU General Public License as published by
8+ the Free Software Foundation; either version 2 of the License, or
9+ (at your option) any later version.
10+
11+ This program is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ GNU General Public License for more details.
15+
16+ This license is contained in the file "COPYING",
17+ which is included with this source code; it is available online at
18+ http://www.gnu.org/licenses/gpl.html
19+
20+
21+// LP (Aug 28, 2001): Added "fdprintf" -- used like dprintf, but writes to file AlephOneDebugLog.txt
22+
23+ Sept-Nov 2001 (Woody Zenfell): added new routines; gave pstrcpy a "const" parameter qualifier.
24+*/
25+
26+#ifndef _CSERIES_STRINGS_
27+#define _CSERIES_STRINGS_
28+
29+#if defined(__GNUC__)
30+#define PRINTF_STYLE_ARGS(n,m) __attribute__((format(printf,n,m)))
31+#else
32+#define PRINTF_STYLE_ARGS(n,m)
33+#endif
34+
35+#include "cstypes.h"
36+#include <string>
37+#include <vector>
38+
39+extern char temporary[1024];
40+#define ptemporary (*(Str255 *)temporary)
41+
42+extern size_t countstr(
43+ short resid);
44+
45+extern unsigned char *getpstr(
46+ unsigned char *string,
47+ short resid,
48+ size_t item);
49+
50+extern char *getcstr(
51+ char *string,
52+ short resid,
53+ size_t item);
54+
55+// jkvw addition
56+extern const std::vector<std::string> build_stringvector_from_stringset (int resid);
57+
58+// ZZZ: changed to 'const' on src parameter
59+extern unsigned char *pstrcpy(
60+ unsigned char *dst,
61+ const unsigned char *src);
62+
63+// START ZZZ additions
64+extern unsigned char* pstrncpy(
65+ unsigned char* dest,
66+ const unsigned char* source,
67+ size_t total_byte_count);
68+
69+extern unsigned char* pstrdup(
70+ const unsigned char* source);
71+
72+extern unsigned char* a1_c2pstr(
73+ char* inoutStringBuffer);
74+
75+extern char* a1_p2cstr(
76+ unsigned char* inoutStringBuffer);
77+// END ZZZ additions
78+
79+extern char *csprintf(
80+ char *buffer,
81+ const char *format,
82+ ...) PRINTF_STYLE_ARGS(2,3);
83+
84+extern unsigned char *psprintf(
85+ unsigned char *buffer,
86+ const char *format,
87+ ...) PRINTF_STYLE_ARGS(2,3);
88+
89+extern void dprintf(
90+ const char *format,
91+ ...) PRINTF_STYLE_ARGS(1,2);
92+
93+extern void fdprintf(
94+ const char *format,
95+ ...) PRINTF_STYLE_ARGS(1,2);
96+
97+// jkvw additions
98+extern void copy_string_to_pstring (const std::string &s, unsigned char* dst, int maxlen = 255);
99+extern void copy_string_to_cstring (const std::string &s, char* dst, int maxlen = 255);
100+
101+extern const std::string pstring_to_string (const unsigned char* ps);
102+
103+extern uint16 mac_roman_to_unicode(char c);
104+extern char unicode_to_mac_roman(uint16 c);
105+extern void mac_roman_to_unicode(const char *input, uint16 *output);
106+extern void mac_roman_to_unicode(const char *input, uint16 *output, int max_len);
107+std::string mac_roman_to_utf8(const std::string& input);
108+std::string utf8_to_mac_roman(const std::string& input);
109+#endif
--- marathon/trunk/AlephOneJP/CSeries/converter.cpp (nonexistent)
+++ marathon/trunk/AlephOneJP/CSeries/converter.cpp (revision 484)
@@ -0,0 +1,110 @@
1+/*
2+ * converter.cpp
3+ * AlephOne-OSX10.4
4+ *
5+ * Created by みちあき on 08/06/24.
6+ * Copyright 2008 __MyCompanyName__. All rights reserved.
7+ *
8+ */
9+
10+#include "converter.h"
11+typedef unsigned short uint16;
12+#include <string.h>
13+#include <iconv.h>
14+extern "C" {
15+char* sjis2utf8(const char* str, size_t len) {
16+ static char text[1024];
17+ memset(text,0,1024);
18+ const char* strp = str;
19+ char* retp = text;
20+ size_t sz = 1024;
21+ iconv_t i = iconv_open("UTF-8", "SHIFT-JIS");
22+ iconv_t j = iconv_open("UTF-8", "MACROMAN");
23+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
24+ strp = str;
25+ retp = text;
26+ sz = 1024;
27+ iconv(j, &strp, &len, &retp, &sz);
28+ }
29+ if( text[strlen(text)-1] == 13) { text[strlen(text)-1] = 0; }
30+ iconv_close(i);
31+ iconv_close(j);
32+ return text;
33+}
34+
35+uint16* sjis2utf16(const char* str, size_t len) {
36+ static uint16 text[1024];
37+ memset(text,0,2048);
38+ const char* strp = str;
39+ char* retp = (char*)text;
40+ size_t sz = 1024;
41+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
42+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
43+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
44+ strp = str;
45+ retp = (char*)text;
46+ sz = 1024;
47+ iconv(j, &strp, &len, &retp, &sz);
48+ }
49+ iconv_close(i);
50+ iconv_close(j);
51+ return text;
52+}
53+
54+uint16* utf82utf16(const char* str, size_t len) {
55+ static uint16 text[1024];
56+ memset(text,0,2048);
57+ const char* strp = str;
58+ char* retp = (char*)text;
59+ size_t sz = 1024;
60+ iconv_t i = iconv_open("UCS-2-INTERNAL", "UTF-8");
61+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
62+ }
63+ iconv_close(i);
64+ return text;
65+}
66+
67+char* utf162utf8(const uint16* str, size_t len) {
68+ static char text[1024];
69+ memset(text,0,1024);
70+ len *= 2;
71+ const char* strp = (const char*)str;
72+ char* retp = text;
73+ size_t sz = 1024;
74+ iconv_t i = iconv_open("UTF-8", "UCS-2-INTERNAL");
75+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
76+ }
77+ iconv_close(i);
78+ return text;
79+}
80+
81+uint16 sjisChar(char* in, int* step) {
82+ size_t len;
83+ if( *in == 13 ) { if( step ) *step += 1; return 13; }
84+ if( step ) {
85+ if( (unsigned char)*in >= 0x81 && (unsigned char)*in <= 0xa0 || (unsigned char)*in >= 0xe0 ) {
86+ *step += 2;
87+ len = 2;
88+ } else {
89+ *step += 1;
90+ len = 1;
91+ }
92+ }
93+ uint16 text[2];
94+ memset(text,0,4);
95+ const char* strp = in;
96+ char* retp = (char*)text;
97+ size_t sz = 4;
98+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
99+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
100+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
101+ strp = in;
102+ retp = (char*)text;
103+ sz = 4;
104+ iconv(j, &strp, &len, &retp, &sz);
105+ }
106+ iconv_close(i);
107+ iconv_close(j);
108+ return text[0];
109+}
110+};
--- marathon/trunk/AlephOneJP/CSeries/converter.h (nonexistent)
+++ marathon/trunk/AlephOneJP/CSeries/converter.h (revision 484)
@@ -0,0 +1,20 @@
1+/*
2+ * converter.h
3+ * AlephOne-OSX10.4
4+ *
5+ * Created by みちあき on 08/06/24.
6+ * Copyright 2008 __MyCompanyName__. All rights reserved.
7+ *
8+ */
9+#include <stdlib.h>
10+#ifdef __cplusplus
11+extern "C" {
12+#endif
13+char* sjis2utf8(const char* str, size_t len);
14+unsigned short* sjis2utf16(const char* str, size_t len);
15+unsigned short* utf82utf16(const char* str, size_t len);
16+char* utf162utf8(const unsigned short* str, size_t len);
17+
18+#ifdef __cplusplus
19+};
20+#endif
--- marathon/trunk/AlephOne/src/AlephOne-20080621/Source_Files/CSeries/converter.cpp (nonexistent)
+++ marathon/trunk/AlephOne/src/AlephOne-20080621/Source_Files/CSeries/converter.cpp (revision 484)
@@ -0,0 +1,110 @@
1+/*
2+ * converter.cpp
3+ * AlephOne-OSX10.4
4+ *
5+ * Created by みちあき on 08/06/24.
6+ * Copyright 2008 __MyCompanyName__. All rights reserved.
7+ *
8+ */
9+
10+#include "converter.h"
11+typedef unsigned short uint16;
12+#include <string.h>
13+#include <iconv.h>
14+extern "C" {
15+char* sjis2utf8(const char* str, size_t len) {
16+ static char text[1024];
17+ memset(text,0,1024);
18+ const char* strp = str;
19+ char* retp = text;
20+ size_t sz = 1024;
21+ iconv_t i = iconv_open("UTF-8", "SHIFT-JIS");
22+ iconv_t j = iconv_open("UTF-8", "MACROMAN");
23+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
24+ strp = str;
25+ retp = text;
26+ sz = 1024;
27+ iconv(j, &strp, &len, &retp, &sz);
28+ }
29+ if( text[strlen(text)-1] == 13) { text[strlen(text)-1] = 0; }
30+ iconv_close(i);
31+ iconv_close(j);
32+ return text;
33+}
34+
35+uint16* sjis2utf16(const char* str, size_t len) {
36+ static uint16 text[1024];
37+ memset(text,0,2048);
38+ const char* strp = str;
39+ char* retp = (char*)text;
40+ size_t sz = 1024;
41+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
42+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
43+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
44+ strp = str;
45+ retp = (char*)text;
46+ sz = 1024;
47+ iconv(j, &strp, &len, &retp, &sz);
48+ }
49+ iconv_close(i);
50+ iconv_close(j);
51+ return text;
52+}
53+
54+uint16* utf82utf16(const char* str, size_t len) {
55+ static uint16 text[1024];
56+ memset(text,0,2048);
57+ const char* strp = str;
58+ char* retp = (char*)text;
59+ size_t sz = 1024;
60+ iconv_t i = iconv_open("UCS-2-INTERNAL", "UTF-8");
61+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
62+ }
63+ iconv_close(i);
64+ return text;
65+}
66+
67+char* utf162utf8(const uint16* str, size_t len) {
68+ static char text[1024];
69+ memset(text,0,1024);
70+ len *= 2;
71+ const char* strp = (const char*)str;
72+ char* retp = text;
73+ size_t sz = 1024;
74+ iconv_t i = iconv_open("UTF-8", "UCS-2-INTERNAL");
75+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
76+ }
77+ iconv_close(i);
78+ return text;
79+}
80+
81+uint16 sjisChar(char* in, int* step) {
82+ size_t len;
83+ if( *in == 13 ) { if( step ) *step += 1; return 13; }
84+ if( step ) {
85+ if( (unsigned char)*in >= 0x81 && (unsigned char)*in <= 0xa0 || (unsigned char)*in >= 0xe0 ) {
86+ *step += 2;
87+ len = 2;
88+ } else {
89+ *step += 1;
90+ len = 1;
91+ }
92+ }
93+ uint16 text[2];
94+ memset(text,0,4);
95+ const char* strp = in;
96+ char* retp = (char*)text;
97+ size_t sz = 4;
98+ iconv_t i = iconv_open("UCS-2-INTERNAL", "SHIFT-JIS");
99+ iconv_t j = iconv_open("UCS-2-INTERNAL", "MACROMAN");
100+ if( iconv(i, &strp, &len, &retp, &sz) == -1 ) {
101+ strp = in;
102+ retp = (char*)text;
103+ sz = 4;
104+ iconv(j, &strp, &len, &retp, &sz);
105+ }
106+ iconv_close(i);
107+ iconv_close(j);
108+ return text[0];
109+}
110+};
--- marathon/trunk/AlephOne/src/AlephOne-20080621/Source_Files/CSeries/converter.h (nonexistent)
+++ marathon/trunk/AlephOne/src/AlephOne-20080621/Source_Files/CSeries/converter.h (revision 484)
@@ -0,0 +1,20 @@
1+/*
2+ * converter.h
3+ * AlephOne-OSX10.4
4+ *
5+ * Created by みちあき on 08/06/24.
6+ * Copyright 2008 __MyCompanyName__. All rights reserved.
7+ *
8+ */
9+#include <stdlib.h>
10+#ifdef __cplusplus
11+extern "C" {
12+#endif
13+char* sjis2utf8(const char* str, size_t len);
14+unsigned short* sjis2utf16(const char* str, size_t len);
15+unsigned short* utf82utf16(const char* str, size_t len);
16+char* utf162utf8(const unsigned short* str, size_t len);
17+
18+#ifdef __cplusplus
19+};
20+#endif
旧リポジトリブラウザで表示