scummvm模拟器是在SDL的基础上开发的,以下的资料或许在汉化scummvm模拟器游戏时会派上用处。
( T) R; U! |: z8 O3 P' C- n# E: h* M: \# ^8 S4 @+ K9 v
原文
4 k8 p9 d( S" I5 ]http://blog.csdn.net/newger/archive/2008/02/26/2121796.aspx4 N- m: n4 g8 Y$ e1 P: H4 {$ f- w
R7 n1 d: E, n; @; i/ ]- u) u大家注意到没有,RA2的中文版本使用的是GBK点阵字库,这样做有一个好处:不管玩家是用的简体还是繁体都能识别显示的文字。 0 p. U! L+ k: E& U( ]5 c
* n. }+ {+ C5 ^4 w
GBK的意思大概是“国家标准汉字扩展字符集”吧,记不清了。但它的确是个好东东,比GB2312、BIG5什么的强多了。因为它包括GB2312、GBK的所有字符而且还补充了很多字,另外,还包括日文、朝鲜文以及大量的符号字符。 . v5 z9 m |/ N: y
+ {1 `; d3 B& \我在UCDOS for win版本里面找到了GBK的点阵字库(HZK12.GBK、HZK14.GBK、HZK16.GBK)。分析了一下,知道了结构。这里是我写的一个演示 程序,程序编译需要有sdl库。遵循“惯例”,按F4切换全屏/窗口状态,Esc退出。程序把标准输出和标准错误重定向到"stdout.txt"和 "stderr.txt"中。
! n) e# a) g a( x1 t: V/ M) S( p2 L) X) q
/ u+ V& n: {, T+ S( A#include <time.h> 2 b$ R, B* g, I- L. K l
#include <stdio.h>
" l& l5 i; |6 N$ Q% q; u4 O# c# m; n#include <stdlib.h>
! ~% R2 @8 C9 B q0 K6 s7 w#include <windows.h>
5 d: p7 B" w+ c! B' t/ F
9 k( M$ _5 Z7 _5 I#include "sdl.h"
, H6 |6 X7 {1 c" \# A0 N#include "SDL_image.h"
b! B! ?. T! j0 f( f0 T) o1 l#include "sfont.h"
/ y+ ^* b( {5 i; n6 w+ R x: s/ x8 O+ a
//---------------------------------------------------------------------------
3 r$ J9 E! R- ]0 @0 _#define STDOUT_FILE "stdout.txt" & U# K; P. y! r2 U- |$ A( u- g
#define STDERR_FILE "stderr.txt"
2 K3 ?# D' i! f2 S4 l$ z" ^& k5 P9 |' X0 q# h4 B F
SDL_Surface *screen;
% y( |# B$ y; I2 _, JUint32 fps;
# L# l. v" S* J. w" LUint32 AppStartTime = 0;
: A$ H t1 @; R4 Q4 _. wUint32 frame_count = 0;
C: ~# q b3 L) ^static Uint32 frames; $ I9 \' b! U g$ g9 v8 X
1 M! A5 L2 g2 ?& A E2 p
SDL_Event event; $ O% x# F# s2 C7 |& G
SDL_Surface * SetMode( int Width, int Height, int BPP, int Flags );
+ {, f# @( q% b+ n% W5 USDL_Surface * LoadBMP( char * filename ); . G+ s4 L5 b3 R6 Y
void MainLoops( int ( * EventFunc)( ), void ( * DrawFunc )( ), int DelayTime );
( x( V6 L& V0 I% ?7 o+ Y2 a8 {* Svoid Blt( SDL_Surface * image, int x, int y ); 7 p4 r0 T* o: {) }7 A! T+ u
void TileBlt( SDL_Surface * image, int x, int y ); 9 b& W1 P. J% ?# {: s8 l! _ K7 C8 {
void SetTransparentColor( SDL_Surface * sprite, int R, int G, int B ); / I6 e6 L1 e6 k5 q
void IoRedirect( ); 7 _! c0 K- \/ s& I$ A
void cleanup_output( ); ( Z; z. W; l7 d
void initfps(); 6 h9 o( ?5 p4 Q; }4 g( y, n
/ E2 h& j1 c; T& x9 a//---------------------------------------------------------------------------
( j. @& Z+ H$ g+ e( k3 p" g8 z+ aUint8 HZK12[574560]; 1 s* Y! W- I9 v8 d) Z3 X
Uint8 HZK14[670320]; 7 w0 i$ }0 e, h# I: t
Uint8 HZK16[766080]; 8 M8 u+ a* _2 f. R, A
BOOL HZ_Init();
# ^7 b/ K3 D K) j6 b& M% GBOOL HZ_TextOut( SDL_Surface * image, int x, int y, int width, int space, unsigned char * str ); ) h$ C5 J2 n7 M& m1 Q; d/ K
//--------------------------------------------------------------------------- + |6 z" T7 R: {* {* o8 [% M
0 `' x: M! ?, R: I9 z* y& xint ProcessEvent( ); 2 J& w; u9 C9 y: P) r" ]
void DrawFrame( );
/ b2 Q% m2 d0 A% t
) q! G4 p$ a/ sSDL_Surface * bg, * font; $ D7 T& c: b. {# f0 \2 Y
int ix, iy, jx, jy; ; z0 o* p8 g; R" P$ Y
int Width = 640; : X+ [$ J. M2 M, Y3 h1 X: X$ y
int Height = 480; ( n; o0 }$ `5 z% z* z
int bpp = 16;
) {# [- P8 r$ ~5 }int ScreenMode = 0;
, i$ s; l5 L: z$ Q0 Z4 ?1 G
$ u0 e% }' Z8 d& rWINAPI WinMain(HINSTANCE hInstPre, HINSTANCE hInstance, LPSTR cmd, int xxx )
3 q" v4 x( o8 S8 m2 h' z& m{ - t1 b, T8 t+ x
char TimeString[256];
1 A3 A7 M) g" S% ?; ltime_t timer;
1 h! S \1 K1 R4 @0 m# h2 E3 B, ystruct tm *tblock; 2 J8 ?3 q4 }- { b9 P. R' i4 ~
7 Y( M( Q1 C8 i" o( M! i6 N
HZ_Init();
! m; q' y; f3 P$ h c( P1 ~0 mIoRedirect( ); 7 c- p# t# w% _8 u; P7 H, f
frames = 0; * x3 H% v+ i+ t
timer = time(NULL);
9 J8 j( J' Y0 a' r& M$ ^$ Htblock = localtime(&timer);
2 p7 L" d. T T/ Q/ U& R' Bstrftime( TimeString, 256, "Time=%Z: %Y-%m-%d %a %H:%M:%S", tblock );
1 e% m; K6 ^ Xprintf( "%s\\n", TimeString );
, J" z( N) I: R- Q0 }: q" U$ ]' ?; s2 }1 T" `+ ?
SetMode( Width, Height, bpp, SDL_SWSURFACE|ScreenMode );
5 l" _0 O& j. x2 X* dSDL_ShowCursor(0);
' H6 }5 ]7 D$ ]. ]) p/ U5 m2 ~SDL_WM_SetCaption( "demo", "demo" ); 0 t2 n0 l* v, t" e4 o+ H
8 C% m5 _4 O( d- V p# }# B' Rbg = IMG_Load( ".\\\\2k_bg.gif" ); ( I" ?5 H: r2 L" R
font = IMG_Load( ".\\\\small.gif" );
1 c6 x/ _6 B& f5 W: |. ?
, x: k+ v$ w1 ]# fInitFont(font);
- I) ]% m1 m/ r% YSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 127 );
; p9 `8 ?3 l; H) L
0 S" _ o: l! M( a+ Z/ v9 G7 qix=iy=0; $ @- ^/ z. c" ]2 s
jx=jy= Height>>1; 7 @6 [4 {0 j K( y9 d
srand( (Uint32)timer ); ' ~, T' I7 S+ ?) P
4 V6 V6 S" R; sMainLoops( ProcessEvent, DrawFrame, 0 ); & P, i8 e7 i$ D3 ^
: ^1 }7 [9 r0 q5 Gprintf( "ScreenMode=%d*%d*%d\\nFPS=%u", Width, Height, bpp, fps );
' u) h3 \/ ]; `( g* s: H, D: T7 m6 N: A8 E" p/ q
return 0; ; B/ c0 E. m! [
} 4 `! ]+ V: s$ S/ i' n; L
3 d& a5 `+ b3 B3 z' Aint ProcessEvent( )
, W- ~3 a% o5 i{ 5 P/ r! o( _! }6 E6 f$ D% y
Uint8 *keystate;
0 v$ x& a$ u! Q9 ^$ v0 j/ W* c& _. w/ \0 d7 {
keystate = SDL_GetKeyState( NULL ); 9 |" T7 q8 {2 M6 h9 m* [
if ( ( keystate[SDLK_ESCAPE] ) || ( keystate[SDLK_q] ) ) ' ]6 ?# @1 d" K$ T2 P
return 0; * T- @9 E% _1 l
if ( keystate[SDLK_F4] ) , M' }5 r) ^9 k! X, H/ l. o
{
3 b3 ]% G% D. H4 A( lif ( ScreenMode )
* s7 M, w8 ~% e" @2 VScreenMode = 0;
4 i, U d- [% R" T" `+ y- U9 I, \3 U2 ?else 8 _" w5 F5 x& W+ U' G( q$ ], B: O
ScreenMode = SDL_FULLSCREEN;
2 p, Q! ^2 d; k1 n' F$ g- Q7 f. _7 I. g& l
SetMode( Width, Height, bpp, SDL_SWSURFACE|ScreenMode );
3 v7 U' f1 n; }: ^5 A$ z _! dinitfps( ); ( C5 L+ k3 b) z" h
}
' A! Y& y$ [3 N, |# ^: v5 t1 y. G7 Y5 b
return 1; ' T9 w$ k& F9 t" E/ O- B
}
& D' T. d0 q* ?8 c$ L
8 H3 l! v7 f) t& ~3 I3 d5 ^5 hvoid DrawFrame( ) ( X0 j2 s# \9 w+ G4 a0 D2 j7 L
{
, p6 H# w- T& Dchar tmp[256]; 5 }* f. `6 o8 k/ z3 @
int step = 4;
! a5 H @' I# U3 k% n" ?; ]7 d7 T3 i7 t$ @- N, {
// ! M5 T5 b6 Z6 {6 z
sprintf( tmp, "TotalFrame=%u", frames );
; N7 a; L$ z! A* M% s! H8 F( E; d, N1 C0 ~/ F7 H5 T
TileBlt( bg, 0, 0 );
% N6 j# |2 i1 n% n; {$ B5 J8 ]+ v( t' U! ]4 f9 t+ \
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 4 );
$ b; p/ p- I( p* A3 c+ M0 z7 T* |PutString( screen, ix % Width - 6, iy % Height - 6, tmp );
) Z& w9 G, Y. Z9 L+ n: W+ u, tSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 8 );
0 S2 D1 R( w# s( z) M9 @8 ePutString( screen, ix % Width - 5, iy % Height - 5, tmp );
9 g) [/ x# K# s% o% ~/ m u4 eSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 16 );
. i* V, W8 Q& ^7 I( X( lPutString( screen, ix % Width - 4, iy % Height - 4, tmp );
- y4 R( t1 i" Z7 H% `$ i" J0 D7 C! ^SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 32 ); 7 M% `" e- ^8 O. B( M: W
PutString( screen, ix % Width - 3, iy % Height - 3, tmp );
7 \% F6 a" y: B7 E) o/ uSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 64 ); - w1 r0 A# t) Y& m! m Q$ J" c! D
PutString( screen, ix % Width - 2, iy % Height - 2, tmp ); $ t9 p! A7 b1 {3 q
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 128 ); 0 c1 j3 S8 ]! z3 b5 p! ?! l
PutString( screen, ix % Width - 1, iy % Height - 1, tmp ); % p; n! `; t6 L" d" |2 T0 t
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 192 );
# S. ~/ V% O6 n# s* xPutString( screen, ix % Width, iy % Height, tmp ); % t+ k5 l& V7 j: N0 J
% e/ V L! k4 Q3 ]& \, kPutString( screen, ix % Width, iy % Height + 40, tmp ); # `# C* L6 T/ C- _8 U
! A) T7 ? U& f/ r
if ( rand( ) % 400 < 2 ) " y# g, ?% j" m7 `" S- o/ u
{
3 g2 B. H* u% l0 W& u+ W2 kjx = rand( ) % ( Width - 10 );
5 h: |. I4 l4 d/ ^" v Bjy = rand( ) % ( Height - 10 );
& b9 ^8 v/ e$ E/ \1 Z7 g} . {: I, _3 ?2 a; X& Q1 t
7 x" Y! C5 r/ k/ c+ _" R) isprintf( tmp, "FPS=%d", fps ); 0 X# i7 [# @! S/ W
PutString( screen, 7, 7, tmp );
$ A, B! a: _! Q/ n3 c8 ]) g+ l//聞波,2000 % x$ s+ E1 ]" G
HZ_TextOut( screen, 10, 300, 16, 0, "十步殺一人,千里不留行");
1 R. b4 {- f) I$ m2 t3 v q% s" hHZ_TextOut( screen, 10, 318, 14, 0, "十步殺一人,千里不留行" );
( m9 ?) A7 y" {/ |HZ_TextOut( screen, 10, 334, 12, 0, "十步殺一人,千里不留行" ); 3 X* q) V+ {" m3 q2 e1 s; g! t9 U* N( z
ix += step; ; S; K0 ^, Q7 ~+ x6 r" X
iy += step;
3 c" n* w5 J6 b$ t5 W! M} 6 U% U* b$ T4 {2 n
//---------------------------------------------------------------------------
- [% ]/ |% l# j9 ~* f6 L F* ?$ E
$ e* J9 H P* Y3 Y7 `5 H4 q3 j//---------------------------------------------------------------------------
8 T9 M) h* S, H% g; o7 PSDL_Surface * SetMode( int Width, int Height, int BPP, int Flags ) 8 z/ A( `/ ]: _4 h+ I
{ # s: a5 |+ }5 m* P* A
/* Initialize the SDL library */ & g. k( y6 W9 B% _$ k
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) + x/ M- K& `2 ~0 D6 v
{ / i+ ^9 `& O L& @
fprintf(stderr, "Couldn't initialize SDL: %s\\n", SDL_GetError( ) ); * T; Q- S9 B3 G: K" J4 m
return NULL;
' D" T2 Z" _7 e4 d2 j; f} % K; O% L; x8 O! X$ ?! e0 x
' ~) _" V7 R( [ t* m# ^/* Clean up on exit */ 6 G S7 v& X5 _& ^4 k9 K. q7 e
atexit(SDL_Quit); + n- i2 s A; v# h; z7 @
6 ~5 _1 `; O# `- j- o/ T1 P1 X5 u# B
/* Initialize the display in a 640x480 8-bit palettized mode */ 7 \# E6 e( I( J* W& _7 Z: n
screen = SDL_SetVideoMode( Width, Height, BPP, Flags ); + C: y9 |* v2 q
if ( screen == NULL ) 0 D! e0 `$ z6 F7 J% |6 a
{
- a/ L. b' B. C( D5 j. yfprintf( stderr, "Couldn't set %dx%dx%d video mode: %s\\n", Width, Height, BPP, SDL_GetError( ) );
6 \! ^; D Y- x; I1 N2 e} $ U# ~8 R9 L* K
7 U( @6 l8 }" w; K jreturn screen; ' W7 J, T5 @+ G1 w6 c) z
} # K( A$ b& b' g' z+ i( V( o, U, Q
//---------------------------------------------------------------------------
. s7 H$ E& w ~# ^& q9 `0 b# h; D7 G! i5 } L, N0 S2 M
void initfps( )
. _/ o( |- Y# r( S7 l{
2 W6 w: X% r7 N# T7 D |) }3 T1 B1 }AppStartTime = SDL_GetTicks();
. M2 _) w' B5 @' s1 R, Pframe_count = 0; # b0 M4 }" h- V1 Y# ^" B
} ! c7 I1 p0 I1 ]9 d R. s
//---------------------------------------------------------------------------
/ Q. L% G9 K5 G; c+ y! j0 h/ v |6 y7 @, C2 }) O2 E% Y) z" W% {
void MainLoops( int ( * EventFunc)( ), void ( * DrawFunc)( ), int DelayTime )
1 o) m, r4 z( t{ ( Z1 u/ n( @' a) P6 P
if ( EventFunc&&DrawFunc ) ~( k; C7 a- h- O5 R
{ ' L% ~5 R" o4 |8 d
memset( &event, 0, sizeof( SDL_Event ) ); 7 {; K. \: }" P
initfps( );
, K* U' E" x# U5 ]( r& r% {, O4 m; G9 j3 z" P" w! ~% ^
while( EventFunc( ) )
" k1 ?, x k L1 I% C{
' L# }2 M) }7 h7 jSDL_PollEvent(&event);
* W. G- H0 u; d( {* wif ( event.type == SDL_ACTIVEEVENT ) ; \0 e- F) t% d& F: `
{ $ f) U! L, V! P
if ( ( ( event.active.state & SDL_APPACTIVE ) == FALSE ) || + m# s) `5 p$ z! F& e6 P& @
( event.active.gain == FALSE ) )
1 [1 n% G2 T& c4 E- |7 d9 F# ^initfps( ); ' L' _0 a0 h. r4 T/ J( P2 B6 q
} 2 `# @' x4 |' R! E! I! F
SDL_PumpEvents();
4 |" S1 ~/ y2 B; v* @: gDrawFunc( ); ' [: Z/ R/ _% c, I5 }! l
SDL_UpdateRect(screen,0, 0, 0, 0); 2 n/ v+ n0 J& K% d: m
frame_count ++;
# M0 u3 j. N$ D, D' L8 dframes ++; . N3 ~+ w1 S( i" L
fps = frame_count * 1000 / ( SDL_GetTicks( ) - AppStartTime );
+ d! a6 ^- F6 C4 q7 L. A% V4 cif ( DelayTime ) SDL_Delay( DelayTime ); 8 j. d+ D3 E8 T8 l* U/ q( `! y
} - k: j2 l& @9 E# b% G% e
} / l* l3 _6 h6 z/ U& C
} % P) `( w6 n" L6 t/ I4 X& }4 U
//---------------------------------------------------------------------------
4 l5 @! O# ^; u( }% U, O1 `, t, z' A7 M& X# S
SDL_Surface * LoadBMP( char * filename ) 1 L8 T8 y5 u q& N0 n7 I" ^. }
{ 8 V$ ~% o4 G0 Q; `1 Q0 m
SDL_Surface * imagebmp, * image;
/ t( d! C+ R: k: |8 U
; u& a+ S/ ]# h0 kimagebmp = SDL_LoadBMP( filename );
. V* o8 y x% ^4 Iif ( imagebmp == NULL ) & n5 \: M& ^' r6 t/ M/ p
return NULL;
$ `& D& Y) s# |! P" m9 a- ^3 F" c+ x9 R
if ( imagebmp->format->palette != NULL ) , ^' [5 c) j' Q! F
{
1 k u" F) _# ySDL_SetColors( screen, imagebmp->format->palette->colors, 0, imagebmp->format->palette->ncolors );
; P. ^; x% \$ _/ q} 1 M; s* S5 q8 R7 @2 O* v& L
3 D& I7 h$ x) K4 }' e# x
/* Convert the image to the video format (maps colors) */ ?2 }% p' G! {- g9 O
image = SDL_DisplayFormat( imagebmp );
- Y% ?3 O1 w$ z/ M1 T- QSDL_FreeSurface( imagebmp ); $ Y$ A; w) c, @& ?3 c5 |: ?% [
/ ?8 A5 N# U; i t- _1 lreturn image;
4 d; C4 k! w- |* `; ^5 D) X}
( C0 n+ L/ }. Y//--------------------------------------------------------------------------- 4 O6 b% W0 U8 N# C
/ _% q5 R5 l* J# z8 p4 k" E
void Blt( SDL_Surface * image, int x, int y ) 5 F7 Z2 f4 J ?- U; S6 E
{ 9 o& [; P y( g$ J1 W* h
int Row, Col, r, c, shiftx, shifty; * `* x6 ?8 y+ Y0 c
SDL_Rect dest, src;
- {2 ^) a+ c6 O* d i, _' W O8 d6 O8 q6 N3 }
/* out of screen */ + o9 H! t4 c" w0 v
if ( ( x > screen->w ) || ( y > screen->h ) || / J; U' j6 l# o& a
( x + image->w < 1 ) || ( y + image->h < 1 ) )
9 N# @# j. E# w% L; H8 hreturn; . H/ R o3 p6 F/ p+ j
/ e; s* T6 U* K4 w$ M) @
src.x = 0; 4 Y5 w* a" \+ V# q8 F, g P$ Z4 ~
src.y = 0; 7 a" ^- h! v7 X. U0 I5 C8 T
src.w = image->w;
2 ^) ]) f: K" i) o+ y8 csrc.h = image->h; / _5 G c" s! P' }/ k) m8 r4 p
dest.x = x; + i5 _" K0 L. y
dest.y = y; & l% C9 d4 y3 N
dest.w = src.w;
/ N: y% A% E+ K4 r5 R# gif ( y < 0 )
) w- s+ {! |, K, J; ~, \{ % N F0 b/ g0 z! S
src.y = 0 - y; * O! L+ a2 C- M$ |; W; k
src.h = image->h + src.y; . ]& t/ \% D* z, i8 j" H$ u8 d
dest.y = 0;
" f: o, u6 F6 `3 N! f6 w! D} " f. u# \: _0 C# E
dest.h = src.h;
% v- A* D6 i& @9 A3 Q! H5 }" e% } t: G
SDL_BlitSurface( image, &src, screen, &dest ); / n% I4 ?# o. S: @! d
}
1 h4 R3 U% `" u! ^//--------------------------------------------------------------------------- - [) s7 |6 u# G/ R- r/ V4 C2 W1 j
* |9 ^* K8 M# J# C
void TileBlt( SDL_Surface * image, int x, int y )
7 j+ Q4 a% f' a5 L& h5 l \* f# ?{ 0 o& i( j6 f- ~
int Row, Col, r, c, shiftx, shifty;
* j- r J0 C+ L5 Z3 {: xSDL_Rect dest, src; 5 w: t; K W E5 F( q
# }( S/ Q! o5 P3 i7 Jshiftx = x % image->w;
, u7 l7 i! O* o8 {' g: x; f- p, jshifty = y % image->h;
8 R0 r" {1 R0 Z$ U* w8 G, I3 x8 M, i ~# U
if ( shiftx >0 ) shiftx -= image->w; 3 v ?3 T. e8 l a) I5 n
if ( shifty >0 ) shifty -= image->h;
% H/ T7 Q, t8 y3 w
4 E; b; h3 D X+ B, BRow = screen->h / image->h + 2;
9 m0 p5 r# H4 f; Q' ^Col = screen->w / image->w + 2;
% F( l, \2 O: J$ u7 v# c
" `4 v$ B f& q5 u3 K6 Idest.x = 0; b% B) x& ^" S( t8 ?( x% u, k
dest.y = 0;
+ M9 q W; e6 V- m* n3 k" rdest.w = image->w; 4 W1 k$ j; t4 `2 q
dest.h = image->h;
( X' R* v3 x3 e4 ^% _; K8 B8 ?src.x = 0;
0 R. p7 w$ R+ zsrc.y = 0; 3 O4 U+ f2 f; Q6 |1 ~- Y
src.w = image->w; ' U+ f* G) U/ G* E g
src.h = image->h;
; I( _0 q# F% q& Q9 E% C( D* t$ k1 d c" W( {
for ( r = 0; r < Row; r ++ )
% G0 M+ }; F* h _+ }{ ! K( p9 [1 X( ^7 [- C
if ( r ) 3 ^& A* ~$ m' T: B8 e0 t
{
0 ]$ L+ G! t! k$ h' r0 G9 n8 [src.y = 0; , B5 p; p k9 o
src.h = image->h; 3 q5 M, x: [! _# d7 V
dest.h = image->h; $ l8 V. F4 U# a- k
dest.y = image->h * r + shifty; 3 U; t, E+ G( L. B. T6 _
} / f! h" M1 |0 ~
else / c4 f* G7 v) z& O; R$ d e9 R6 h! [
{ /* first line ? */
) m, L: N% l. q" U Q/ P/ K3 Xsrc.y = 0 - shifty;
5 [: k$ \% w% u: T" }src.h = image->h; 0 E/ E) R$ V" n7 J3 \
dest.h = image->h + shifty;
' e3 B. a& m2 W2 c& `# G; ^dest.y = 0;
! m) g2 T. \+ i$ P6 r3 r" O% T} * [ i( h3 [' \ Z; \( a
8 i1 t" R% v, a
for ( c = 0; c < Col; c ++ ) 9 l' N( Z: Z% L. J0 c; V! R0 s4 z
{ # I" x- V9 s9 x* k; p
dest.x = image->w * c + shiftx; n! K2 G6 g! P0 R6 z4 @
SDL_BlitSurface( image, &src, screen, &dest ); $ v: y8 e, |$ }) f: G
} P( | i# Q8 m' C4 s5 ^% `
}
% N+ x) I' s, |' W) _" _3 ~}
- f M9 T l* P6 w//--------------------------------------------------------------------------- 2 c9 R2 B& V% J5 M
' G- g9 e" H3 M; H
void SetTransparentColor( SDL_Surface * sprite, int R, int G, int B ) ? c0 B5 w6 y/ _! C4 L
{ . }$ V2 T8 `5 k5 C* U
SDL_SetColorKey( sprite, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB( sprite->format, R, G, B ) );
0 X/ L0 V$ N: c- V9 H2 X6 o$ K} 1 A7 b2 _' `1 ?; }0 f! T# D2 I
//---------------------------------------------------------------------------
. ]- ~$ [1 V# \) b* _7 [' n! `
2 S" f: |7 n; F) y2 t/* Remove the output files if there was no output written */
4 ~% X2 H+ K/ ]static void cleanup_output( ) , ]7 w; r( J$ a. j& t% S9 j9 @
{
' B- o6 r- R! t( Z! n) IFILE *file;
2 e6 n9 t/ S' kint empty; # a* X) P! V3 W$ @. Q. h! J
4 Y8 e3 _. r) `7 B5 S. ]/* Flush the output in case anything is queued */
9 v$ L, X2 r5 m. x7 n! ifclose(stdout);
9 s% y4 e+ }: R4 Dfclose(stderr); 3 M! x$ E, _# n4 o' I
$ D2 L; e+ d- u' S& t. x: D6 W* f/* See if the files have any output in them */
' F) L1 @7 H+ ~file = fopen(STDOUT_FILE, "rb");
# Y6 Z' A, Z4 M, Z/ H9 I, j5 V8 Iif ( file )
! L; O& R, F2 F) V{ ! |3 v a6 Z6 W5 I5 f
empty = (fgetc(file) == EOF) ? 1 : 0;
3 L ]& T' F/ D7 j$ {! [# [6 K9 `fclose(file); & Y$ t' b( q/ M5 U$ f4 Q$ N: Z$ F4 _5 F
if ( empty )
# e: P* n" {2 z" e, {# V- R9 Zremove(STDOUT_FILE);
& b3 ?" B2 Q8 S7 {& Y" N% \} $ r0 K4 e' s p K" \" J1 Y$ b# E
file = fopen(STDERR_FILE, "rb"); 6 f1 A8 O8 w0 U/ n; F
if ( file ) ' S+ I a2 P$ k7 s
{ : D7 V% Z: O0 u7 K
empty = (fgetc(file) == EOF) ? 1 : 0; 4 Z8 p, c9 |4 S, f- n4 {$ y5 {- B
fclose(file);
# U; m5 n t9 x; R5 [9 D. W; a, {if ( empty )
" R# G* I s( b- t) jremove(STDERR_FILE);
, E* T4 U, c4 y}
) n4 k( @1 o( o- i6 o) z} : v$ d& x8 F3 z( a
//---------------------------------------------------------------------------
6 q8 S" V' I4 ^5 S3 d. @( X! B
: _5 y+ }$ o. {; M. g2 \" avoid IoRedirect( )
2 \ K. ?1 ?8 w' u{ 2 L7 O$ ^2 k' F2 {. e4 |0 ~. b/ m
FILE *newfp;
" L. r- w/ N( |5 c8 r3 l7 `' L7 }: m; V- h; N0 v: S
/* Redirect standard standard output */
4 G" z2 O V3 |& jnewfp = freopen(STDOUT_FILE, "w", stdout);
5 G* D( g x! O& }0 y) |; Sif ( newfp == NULL ) ( p6 I4 l! P, [/ I0 M, h
{ /* This happens on NT */
- J E2 @/ y/ h, a& x8 ?; l8 `5 t#if !defined(stdout) . I4 g0 U# s. ~8 W4 {0 M7 _
stdout = fopen(STDOUT_FILE, "w"); 6 w# p7 `; i9 N3 r% }# U( e. R
#else 5 l. L' ]; m$ S# `/ A, A9 c% r, h, O
newfp = fopen(STDOUT_FILE, "w");
, w+ X8 H, q; h0 D* Y' lif ( newfp ) *stdout = *newfp;
# m0 \' m2 T' E#endif
2 S" H* M4 v8 s! Y}
, b. E* \' Q3 z$ C% k# i( N- ] h
( o( K2 r9 Z2 l/ \ a9 ]/* Redirect standard standard error */
" O, g" A$ c* t+ |- a% A2 }( hnewfp = freopen(STDERR_FILE, "w", stderr);
5 o8 o' T6 @3 X) \7 ^5 ^+ ~- cif ( newfp == NULL )
# |" N5 W/ x$ T& X{ /* This happens on NT */ 0 l& y% {" n( l1 s# L: Y2 V" Z
#if !defined(stderr)
h' t7 v" I1 {+ o+ d+ x" o9 n5 bstderr = fopen(STDERR_FILE, "w");
0 E3 G( V( }5 ^" x( O+ T! _) f#else * J+ k; f' @4 B* [; M6 k
newfp = fopen(STDERR_FILE, "w"); / s U2 D( A" r8 f9 N
if ( newfp ) *stderr = *newfp;
F$ C# g( I/ i) O1 i#endif
- n, R! |$ a$ i8 J5 g' r& @} " B i. V8 c. E9 W
; j& T4 ^6 w5 A) l* Bsetvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ " h5 p; p8 y8 o- `' I1 Y4 W Z
setbuf(stderr, NULL); /* No buffering */ 1 o' i4 h3 d. ^" x* x8 } `
atexit(cleanup_output); ; C! u# C, y, d# Z/ B# }: g
} ' w# i5 J/ {5 y/ W
//--------------------------------------------------------------------------- # {0 x( ]1 P# D$ g: b& l* W; ~; a
( u* [/ A& x+ j5 R
BOOL HZ_Init() 5 N8 Y9 w l _+ Z1 d; c
{
5 s ~( U: m T! y) _FILE * file; 0 }: N+ d# |. z& y$ e+ Q& n
3 z t+ w& J! X1 ?file = fopen( ".\\\\HZK16.GBK", "rb" ); / V9 d! Z9 P5 q6 U" _) F
fread( HZK16, 32, 0x5d84, file ); - \ x' F# E* o8 t+ e
fclose( file );
# Q5 q2 y( ^% H1 R/ Afile = fopen( ".\\\\HZK14.GBK", "rb" ); , U* H; P' _" T$ i$ i) B3 }" p$ ]
fread( HZK14, 28, 0x5d84, file );
6 X2 r: D3 f2 Pfclose( file ); ' y2 }4 \, C" c# Y! T
file = fopen( ".\\\\HZK12.GBK", "rb" );
$ d5 T4 J1 d1 H2 Y8 i' W3 Vfread( HZK12, 24, 0x5d84, file ); 8 U/ |( ]3 n: ~: U
fclose( file );
" Q. O0 H. i# T( i2 R4 [8 q& ]+ T! ?& Q7 @& F
return TRUE; % z" E( ]: N" |1 o. z7 H+ G: j% q
}
. p( C ~0 Y5 n* v//---------------------------------------------------------------------------
! A2 \6 @9 |9 X9 z+ ?3 @! D4 H6 ] ?/ k# v- @" u4 h. E, D
BOOL HZ_TextOut( SDL_Surface * image, int x, int y, int width, int space, unsigned char * str ) " Z t+ O+ W U; J' y" ?: m
{
2 d# S9 J% H' h3 E8 s$ w2 RUint8 * bufptr; ( A) Q7 ^" c9 t# c* Z- ^8 c
Uint8 * HZK;
* @! J6 j* f/ T2 V$ M' IUint16 Bits[16]; # i6 {' J) B7 V3 v0 _7 c' `
int i,j,k, m, offset = 0;
: U4 p7 M7 i Gunsigned char q; 2 V4 x4 N3 F" C1 W* ?
unsigned char w;
$ x" I( h; ?" m) {5 Q& X# T& O$ t
switch ( width )
, v9 g* o: ^, a$ B{ : v/ z' m# w/ B3 T% Q% g$ N
case 12: ) j3 L' u- h0 H3 {2 I7 Q7 B# ?
HZK = HZK12; ' G) _) f. M( p r
break; % J* Z$ @# s" L
case 14: 8 x% U5 h: a* D" p. X
HZK = HZK14;
/ Q: N; o2 j9 [break;
; m$ z% x$ V4 m6 F. x; r" Y% d/ \case 16:
! c6 a& s- I( ?+ L/ DHZK = HZK16; 3 |% t7 v8 T8 U1 J
break; " g8 ~- z; E0 [& q* m. h3 Y
default:
3 |: F1 K; G' B/ |2 l) Hreturn FALSE;
0 s$ a1 d* X5 V8 b}
- M9 O; b+ s7 B5 xbufptr = (unsigned char*)image->pixels;
# q/ k* F3 D: W! T# z! X# d
$ ^3 J# M3 v8 A7 bm = strlen( str ); - J" h5 u+ j$ J
for ( k = 0; k < m; k +=2 )
7 v9 _% T# e' I+ a" _{ & a. [1 X. U$ X! W
Uint32 X, Y, Z, M;
0 w6 U6 w2 d. iq = str[k]; 3 L; Y Y; x- ^$ y$ X# K
w = str[k+1];
& F8 W2 {3 t" ^6 G' E, m8 ]6 n0 F# L3 h/ _: w# U, D* f
if ( w > 0xa0 )
' F5 N) H4 k3 M0 l( v9 J{
9 u( A0 G6 j5 n% S- p8 LM = 0x5e; " P9 N1 R( P2 w( K+ w; t/ w6 u$ @
Y = w - 0xa1;
3 x- s% @* w8 N+ zif ( q > 0xa0 )
, S$ h4 L0 ^7 |# Z1 c" |5 e{
?) G) `, P! X( K0 S# ?* Z9 GX = q - 0xa1; ( r/ ?% D) J3 O5 _2 J" g
Z = 0; 4 E2 a9 o( y5 {* f7 r9 J' Z
}
+ W# e; X3 R' a. r5 ^ `4 Pelse
7 R# Q( f0 m0 |) h+ e" x{
: O! _9 i* a d6 v$ O5 OX = q - 0x81;
" W/ b; ]0 k' i8 g7 a' S8 AZ = 0x2284; 4 k, V: ?/ s$ e! ?2 S1 B
}
: D# L7 H; }% d( v2 e* V0 L4 X3 ^}
! P- G0 \. m5 q# I0 eelse
8 e# z d+ K3 s8 {, X/ a{
a0 z; }' C/ m Z& V! w5 PM = 0x60;
9 z, K+ q( |) D% K$ @2 \if ( w > 0x7f ) Y = w - 0x41; + G* t* I |/ `! C8 @& d
else Y = w - 0x40;
8 W- F& a* B. Q4 O4 V: D! }7 o/ z1 L: N& h9 O8 i2 `
if ( q > 0xa0 ) / x6 |1 _4 h. u9 n
{ ! I0 y. i( X! R8 i; |
X = q - 0xa1; : @2 P" B- s6 v
Z = 0x3a44; % a' @& V2 S/ a D" i
}
" }# [. \' O- M% t/ nelse
7 k1 s% }/ U; b/ r0 p{
& a @, W( J/ }9 L% W/ TX = q - 0x81; 1 r8 N) `4 Y6 ]3 C" _# y0 ]
Z = 0x2e44;
' \2 m) U+ x% p}
9 a: v$ C) m: _' [}
8 H1 e; g, h& _- w9 w, u& o) F6 ^memcpy( Bits, HZK + ( X * M + Y + Z ) * width * 2, width * 2 );
, h; h; c' Y7 r8 F5 i' y$ u; @/ t/ E
for ( i = 0; i < width; i ++ ) // row
2 l+ ]. Q6 p& G/ p4 {{ 0 { P- ?- g) ^; W0 L
Uint16 line; 8 H" }3 |: R" W0 @- B
" o ~% p( s; `1 D* ~
line = Bits[ i ];
+ z+ L- @9 v3 v' dline = ( line >> 8 ) + ( line << 8 );
; O& g0 S+ j3 | D% d; B- }$ ] y. p
6 y7 I+ N. }/ Lfor ( j = 0; j < 16 ; j ++ ) //col 0 x9 z. b1 O+ H2 ]/ u7 P4 s
{ 9 |/ x& p* D6 I5 i6 g6 @3 Q
int index; & @6 k& g# J8 z- x$ X/ t- q ?' X8 f
int mask = 1;
0 I5 g! p' T( R0 m2 d' R
! _8 M1 _# w0 Rindex = offset + x + 16 - j - 1 + ( y + i ) * image->pitch / image->format->BytesPerPixel;
8 Q* C, k2 a) b5 z% xmask <<= j;
3 ~2 ?' M+ o+ ~) Rif ( mask & line ) 6 E1 N$ X% E* I( Y* T
{ 8 h' o$ a l% Z" B$ W
bufptr[ index * 2 ] = 0xff; 2 P/ k4 A/ S9 P* a. h' M
bufptr[ index * 2 + 1 ] = 0xff; ) O0 s9 `: c0 j2 [: ^; d, |9 j
} , B9 P& `; b* U% ]# ~
}
[0 R1 U7 Y& _}
9 O- {/ H$ r$ b& L' Loffset += width + space;
6 Y m5 ^4 J" u3 _. G; l}
) \* o; E8 F( p- Dreturn TRUE; 1 g9 }& S# o* M% B( h: F% w
} |