scummvm模拟器是在SDL的基础上开发的,以下的资料或许在汉化scummvm模拟器游戏时会派上用处。 0 E5 a v( N6 W
! e9 i0 P# [/ g/ M$ \原文: f4 z3 k) g/ e% j' o
http://blog.csdn.net/newger/archive/2008/02/26/2121796.aspx
" s$ x3 a3 C+ z/ |( g0 y
& V! c( \) z! I/ C, l: L大家注意到没有,RA2的中文版本使用的是GBK点阵字库,这样做有一个好处:不管玩家是用的简体还是繁体都能识别显示的文字。 * @8 @: h2 K6 a* V( B; j, F
3 g: [- z3 x$ S" t- p, I3 B7 }* ?1 s+ w; `GBK的意思大概是“国家标准汉字扩展字符集”吧,记不清了。但它的确是个好东东,比GB2312、BIG5什么的强多了。因为它包括GB2312、GBK的所有字符而且还补充了很多字,另外,还包括日文、朝鲜文以及大量的符号字符。
: D4 J4 I! ?. n5 | x' X4 A; H3 Z- [
我在UCDOS for win版本里面找到了GBK的点阵字库(HZK12.GBK、HZK14.GBK、HZK16.GBK)。分析了一下,知道了结构。这里是我写的一个演示 程序,程序编译需要有sdl库。遵循“惯例”,按F4切换全屏/窗口状态,Esc退出。程序把标准输出和标准错误重定向到"stdout.txt"和 "stderr.txt"中。
9 @/ y% ?0 B3 R2 ` x0 y
0 p, k, M, R- N: s* l6 n# y1 F# Y7 h. y4 Z: i- ~
#include <time.h> % k8 [; q- z% z4 V ^
#include <stdio.h>
/ y0 M7 s4 E3 H#include <stdlib.h>
9 I" [! ~, S2 S2 m5 \' O#include <windows.h>
: s5 {4 ] p. V1 F! \ E) B. E/ S/ D
#include "sdl.h" ' X# U2 J( S2 k6 ]# K4 x/ y0 [* |! y( N
#include "SDL_image.h"
& A6 d9 K$ f V( t$ u5 L5 j#include "sfont.h"
2 B( v2 q; _0 ^ v
# U# C/ |, l5 x" T I7 x//--------------------------------------------------------------------------- : k6 k: T }/ J' k, _ e! I9 Z, O" N
#define STDOUT_FILE "stdout.txt" * |, N! W, Q& Q) t/ g6 G
#define STDERR_FILE "stderr.txt" + f& k$ ~$ G, h9 U7 Y' @
. k0 L' H: Z6 N) w, l7 m* {
SDL_Surface *screen; 4 e* R" t D/ L
Uint32 fps;
6 I; ]7 L7 d2 s! B7 w2 n0 A1 V' uUint32 AppStartTime = 0;
" |8 J! q' l: KUint32 frame_count = 0;
: r$ q8 g5 p% kstatic Uint32 frames;
" G0 e0 u' h& F- D
# L5 k$ X9 q" D" s5 T" U# O4 GSDL_Event event;
( v* T Q2 n! wSDL_Surface * SetMode( int Width, int Height, int BPP, int Flags );
5 _7 |! W/ C, c9 ~! j) U" hSDL_Surface * LoadBMP( char * filename ); 4 l1 k5 H) M+ y2 _ ?6 h
void MainLoops( int ( * EventFunc)( ), void ( * DrawFunc )( ), int DelayTime );
% E& t# W, w( S( Y- |void Blt( SDL_Surface * image, int x, int y );
$ h8 c% J7 j3 R. y! a. G; xvoid TileBlt( SDL_Surface * image, int x, int y ); 1 k4 [- J/ L2 u1 j X# R0 t# [+ Q5 U
void SetTransparentColor( SDL_Surface * sprite, int R, int G, int B );
& f( y0 ~- S$ r' P" u- Fvoid IoRedirect( ); ! {5 }/ ?4 c5 R, q
void cleanup_output( ); ! P2 g( f7 z0 n; B2 u7 z; r( Z" N
void initfps(); , E, `# _& \% [4 U4 X
3 e1 ?- g. H% l7 w) k; h
//---------------------------------------------------------------------------
! O3 t* W9 S% ]( }9 y/ O/ _Uint8 HZK12[574560]; * }% Q6 L! }/ p* j
Uint8 HZK14[670320]; , ]: o5 }4 l) K9 s2 F8 ]% E- y
Uint8 HZK16[766080];
. o2 W6 K4 `3 o# G9 f9 f2 H! C( |BOOL HZ_Init();
# E4 Q- j6 i) O8 F6 U+ dBOOL HZ_TextOut( SDL_Surface * image, int x, int y, int width, int space, unsigned char * str ); + [* t+ _ `; \& r R& E
//--------------------------------------------------------------------------- & l. z: d5 g4 {; v# H2 H% E2 J
0 k- `6 Q, Z) I9 m: `0 X: W5 Mint ProcessEvent( );
& I, \- C' G2 C3 Gvoid DrawFrame( ); # z7 s8 ]2 f( S# s* H* w( n J
' u) c7 x- L1 }7 O
SDL_Surface * bg, * font; . W' e% Z8 m* |) C
int ix, iy, jx, jy; 0 Q' J# R9 t% t @; z
int Width = 640; . s* W4 N2 g$ a7 v+ I
int Height = 480; 3 Q1 R( P5 U' s- I: v* j6 e s
int bpp = 16; ( l0 M8 q; J5 O G. P4 `
int ScreenMode = 0; 4 |$ W# M$ d* N
/ a }, [! ^% @4 _" D) YWINAPI WinMain(HINSTANCE hInstPre, HINSTANCE hInstance, LPSTR cmd, int xxx ) " S: q2 |5 U: O1 v. T
{
/ \9 [, t% \7 V0 b' ^char TimeString[256]; ( S3 q+ u5 P6 J1 B5 B6 f ]
time_t timer;
7 N$ h+ E2 t! w- Qstruct tm *tblock; / m& w: [' g- W' n. i
8 ]+ B) g* J7 I. V% SHZ_Init(); * V. }6 ]) x2 \- X
IoRedirect( ); ( M9 G& E5 m; [. s
frames = 0;
: e% f2 E- L9 _- \timer = time(NULL); " Q7 d2 o& U8 R4 `
tblock = localtime(&timer);
' z5 J1 K* M+ @+ astrftime( TimeString, 256, "Time=%Z: %Y-%m-%d %a %H:%M:%S", tblock ); 8 \% S; I H/ N2 x6 E: [% D: u. Z$ d
printf( "%s\\n", TimeString );
: c/ r/ b9 V7 ~ U1 w; n# `
) G1 \/ l* h+ O( @/ vSetMode( Width, Height, bpp, SDL_SWSURFACE|ScreenMode );
( ]. C8 v2 m* \+ ASDL_ShowCursor(0);
; R0 E' K& \0 m6 V; x8 a! kSDL_WM_SetCaption( "demo", "demo" );
v0 n) I# U1 u7 \% F
0 `/ g# }! R7 X$ m7 A% Rbg = IMG_Load( ".\\\\2k_bg.gif" ); - M1 C3 L, L0 e. ^
font = IMG_Load( ".\\\\small.gif" ); $ l& p9 J& S0 C3 l: ?+ }
" d$ B) M- w+ Y3 }( dInitFont(font); # l8 I G1 w" f" i
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 127 );
$ V0 P, Y. p6 Y/ E+ t* j
) g/ I! I1 h: e) y- J$ i! Aix=iy=0;
- r6 W3 G; m) x/ D Yjx=jy= Height>>1; 6 U2 W' r1 n V2 q3 f
srand( (Uint32)timer );
2 L3 Q" U, n" K: V* Q8 b
) ?0 [4 I/ [9 \) m1 s) r& jMainLoops( ProcessEvent, DrawFrame, 0 ); 2 P: P8 v3 U/ U$ j! H }
4 U+ [- v4 t$ W6 M/ @+ tprintf( "ScreenMode=%d*%d*%d\\nFPS=%u", Width, Height, bpp, fps ); . i. D) g4 E, c* ?+ \) B
& r* M; a0 v G1 Ureturn 0;
5 @' t3 l2 l( z5 F} # ^8 Q% ^( A1 q/ \$ e: |: T
t- F, c! X; [# ]. \2 b7 W
int ProcessEvent( )
8 F8 G4 ~6 d2 O4 s{
. o$ R* N& p* [; @4 L. l% W: OUint8 *keystate;
& f8 }9 x- {/ g$ h
* o+ V; G2 {9 ?- Q7 ukeystate = SDL_GetKeyState( NULL ); ' f# _5 W2 D8 w }0 B9 s
if ( ( keystate[SDLK_ESCAPE] ) || ( keystate[SDLK_q] ) ) : R$ E* d* g8 S1 a* Z+ r
return 0; 3 k% m' w+ h9 _
if ( keystate[SDLK_F4] )
2 C& j+ T6 A- h" V3 V8 i{ - s6 @/ B5 I J& V9 [0 z$ g
if ( ScreenMode )
! h9 A; U$ e3 {1 H7 `ScreenMode = 0;
6 E1 M/ K* |0 felse - T0 v. a; f! j# d& o- R
ScreenMode = SDL_FULLSCREEN; : u) I* d+ G+ ^6 A3 C+ X/ T. v
& ]; r: n! P+ _1 N
SetMode( Width, Height, bpp, SDL_SWSURFACE|ScreenMode );
% [( L! l3 u7 A. ^0 b/ t7 Qinitfps( );
- \, t' p9 M' z- d} , h+ U) c2 s7 Q% f
7 X- |0 n7 K4 C2 e- Z G( lreturn 1;
; _! K$ h' {* ]. A$ C- P} 4 ~1 Y& E+ G: m4 s6 d8 g
7 }9 t% A5 \0 O+ P. r! Mvoid DrawFrame( ) % b4 @: \0 @/ x/ s% ]# h
{ 9 w& K5 I$ W K/ e9 K& k: z
char tmp[256]; ' M& D) }! R! i! i: _4 z
int step = 4;
7 B' y" I7 y& q; d6 o. P
; w f/ R0 V" l7 W//
k z1 S3 A+ {1 }' Z6 H' x4 ~* `9 Dsprintf( tmp, "TotalFrame=%u", frames );
, l8 h6 z* d* s' N' Y- D8 _+ E. r; L1 r; Q! T
TileBlt( bg, 0, 0 ); 8 a4 C+ X! v* y8 b+ A
8 h7 \/ r2 S" h9 D' v8 {1 pSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 4 );
# D- ^0 E: h! e( l* g$ [3 e8 uPutString( screen, ix % Width - 6, iy % Height - 6, tmp ); , Z) b) }9 }; ]- x; j- z
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 8 );
/ m% Q$ B7 t) y) xPutString( screen, ix % Width - 5, iy % Height - 5, tmp );
& M1 e# x+ F, S: L5 G9 D/ y1 QSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 16 );
, B [/ }! t: K# V2 N' `PutString( screen, ix % Width - 4, iy % Height - 4, tmp );
( q+ Q1 @) `2 Z3 r. R) |5 t: u lSDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 32 );
5 V5 X, m# P' b! V2 lPutString( screen, ix % Width - 3, iy % Height - 3, tmp ); 6 A. [/ R: P4 d' h+ s2 `- F
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 64 ); * n% ^, |# j- R. X/ F! I
PutString( screen, ix % Width - 2, iy % Height - 2, tmp ); , x( m1 Z9 A9 ]& ~/ \) j
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 128 );
1 K$ a" {; v# }3 f9 y" c; U' i5 A4 X- I: RPutString( screen, ix % Width - 1, iy % Height - 1, tmp ); : \7 `- F: j& {
SDL_SetAlpha( font, SDL_SRCALPHA|SDL_RLEACCEL, 192 ); 7 U( L6 J9 U* e9 k
PutString( screen, ix % Width, iy % Height, tmp );
, A$ O6 E% n; i: A( T& L
2 w" J5 V- e$ |; X0 T& ]3 wPutString( screen, ix % Width, iy % Height + 40, tmp ); & [9 s$ R( y) M5 k+ {$ m
0 t y" {) \" L# N9 \
if ( rand( ) % 400 < 2 ) 3 s5 Y9 w3 @# r% ^; k4 ^
{
) m, l5 \4 z6 r5 s7 Y4 @5 m- m/ Zjx = rand( ) % ( Width - 10 );
# {/ J' c( R! [+ Ijy = rand( ) % ( Height - 10 ); * q# n) p$ _7 b
}
) B6 f. y1 r- \
! y6 Q1 j2 q7 x( a! Bsprintf( tmp, "FPS=%d", fps ); * C' [( |1 p' [9 h. i9 W+ y
PutString( screen, 7, 7, tmp );
( k) h" l0 u* [4 C+ r& g8 |1 M//聞波,2000 . ?8 U: E4 r+ _& i6 O, A' ^9 j
HZ_TextOut( screen, 10, 300, 16, 0, "十步殺一人,千里不留行");
% [1 s+ Z5 E* K/ c. f; ~+ q; nHZ_TextOut( screen, 10, 318, 14, 0, "十步殺一人,千里不留行" );
" w! J5 X; u0 w' V1 O$ aHZ_TextOut( screen, 10, 334, 12, 0, "十步殺一人,千里不留行" ); 4 p- e: S8 S7 s% W8 \6 l6 o" n
ix += step;
9 k8 M. X4 m" ~$ a2 Tiy += step; 0 Q! i* K" W; h
}
6 Y6 Y" P( s' E& R( I//--------------------------------------------------------------------------- 4 S& g5 q0 ]& r
8 t1 v- P5 A' O" w% ~4 p9 W4 @//--------------------------------------------------------------------------- Y% Q4 t+ i6 q1 Q( F) C
SDL_Surface * SetMode( int Width, int Height, int BPP, int Flags ) , o7 B. k. g# C2 L2 k3 @
{ 1 y8 ?& z. c/ _ T# v
/* Initialize the SDL library */
0 X) t& r3 m7 f! m: K# K2 ?if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) 1 |) O, e* M: h$ |3 H6 b% b
{ 8 ^2 b* c3 P0 G8 w9 S
fprintf(stderr, "Couldn't initialize SDL: %s\\n", SDL_GetError( ) );
4 i8 J7 H8 e& mreturn NULL;
5 C9 R% N3 B% x& h/ a# h& T} ! k& E6 p1 |9 M7 R# G$ k! C) p, \
9 [% ], H! ]( K" U4 ^! l& I1 P3 }/* Clean up on exit */ & C" d, n4 O2 ?0 `7 a7 r/ J% r; r
atexit(SDL_Quit); 8 e. F( g0 @3 x
( b, H3 I6 | {+ ?8 M* |/* Initialize the display in a 640x480 8-bit palettized mode */
- }7 X5 t4 [% j/ {screen = SDL_SetVideoMode( Width, Height, BPP, Flags ); 2 f1 `2 D/ A% S+ c& _9 y
if ( screen == NULL )
5 a/ k4 E0 J& R4 K{
, g U; Q2 E* N4 @& U5 n! ^, @fprintf( stderr, "Couldn't set %dx%dx%d video mode: %s\\n", Width, Height, BPP, SDL_GetError( ) );
3 H2 P# `! b- g% a; z; W} 1 F7 M: l' I' x0 m! W% a7 q
# I2 m" `! }' G1 |! u* M+ ^return screen;
: ]& B0 ~% q/ O, ]% ]4 U% ~% d}
: t, P% F7 V/ b/ B* ?9 {//---------------------------------------------------------------------------
1 T6 j0 t5 C' D3 c" w% J0 t' N% T' {/ F
void initfps( ) 9 P5 _) t: d8 l3 H. m! D) ^$ w
{
. v9 H5 s7 b" j& S8 yAppStartTime = SDL_GetTicks(); + {! _+ T/ E4 z9 R d! W
frame_count = 0;
" {& O0 M+ d& R$ ?) r) ^0 L}
* x' `" C) s( h( P//---------------------------------------------------------------------------
1 N( _: h: w0 ^5 f$ @4 y
4 B0 m" ]1 \2 Q. o3 S, evoid MainLoops( int ( * EventFunc)( ), void ( * DrawFunc)( ), int DelayTime ) ( U; S8 K/ t6 l0 j' K
{
7 n5 n- x/ H) Vif ( EventFunc&&DrawFunc )
9 m5 a9 a7 V8 [6 W5 g8 X" H{
, H; D# O2 p& Y# T9 Qmemset( &event, 0, sizeof( SDL_Event ) ); x. x) x; K$ k; k$ n4 T
initfps( );
6 M3 J4 z) ?1 _" O3 a! Z! N# L- ^9 E7 u: Q
while( EventFunc( ) ) ! c; g! `2 k( p1 G: {
{
4 e& `( e- Q! L% sSDL_PollEvent(&event); / {- W8 ~) }3 ^5 [4 v
if ( event.type == SDL_ACTIVEEVENT ) 1 {8 S' N, {& _
{ : p, M6 f: l9 Q2 I' m* H, Q
if ( ( ( event.active.state & SDL_APPACTIVE ) == FALSE ) ||
& d) \) W8 d& t( event.active.gain == FALSE ) )
6 [ z2 Y/ u2 y! E- v5 zinitfps( );
' x" C! }" W3 U! Z! z} 4 [# d- o `; z. t6 x3 z
SDL_PumpEvents(); . q7 z8 l+ S' E( k6 c+ f" m
DrawFunc( );
# _. y$ O9 T( N* b0 V7 g9 CSDL_UpdateRect(screen,0, 0, 0, 0); . o) Z" s9 }0 h& d8 L9 i
frame_count ++; , [3 o; L# Q5 ^5 n- O
frames ++; . q9 }1 |1 P$ b C2 H+ b; q# N
fps = frame_count * 1000 / ( SDL_GetTicks( ) - AppStartTime );
; J' ~8 O6 m2 Cif ( DelayTime ) SDL_Delay( DelayTime );
* d' k+ p- Z$ M7 S" [' b& \6 p} 4 x; o) U8 u9 C4 @+ I: C0 t
}
# l* G+ |; \8 ^0 T9 \}
% ]& \- F6 {4 K6 K% p8 S//---------------------------------------------------------------------------
2 w( N" ^( p; Q( I" m( O( J9 |; v+ x, ^
SDL_Surface * LoadBMP( char * filename )
! V/ o; ^7 X, |% \3 C2 M" ?- S, _{
6 L4 R5 }3 w* A K% ^0 s- eSDL_Surface * imagebmp, * image;
. ]1 l( f G: _; o2 B4 c& i- J/ p/ e y& U+ V9 \( _7 J% Z2 `
imagebmp = SDL_LoadBMP( filename );
4 D Y4 j8 u \' W: uif ( imagebmp == NULL )
$ Q( |) n; I& |1 ?& Xreturn NULL; # S: Y) L2 g9 \# M% y( h- Q
2 ?6 l& M% i) T- p2 p2 S& P
if ( imagebmp->format->palette != NULL ) : N& c5 d# G$ v1 U$ Y0 j
{
, s. ~/ d% I' p) u- C& ]* USDL_SetColors( screen, imagebmp->format->palette->colors, 0, imagebmp->format->palette->ncolors );
. O" w8 \8 v" |# h}
' [3 B' K6 |( H
! Z0 w# X( s, d1 L$ D1 a0 y2 O/* Convert the image to the video format (maps colors) */
$ s' [+ x, l* Pimage = SDL_DisplayFormat( imagebmp ); + o' T f& ?4 q1 J3 D
SDL_FreeSurface( imagebmp ); ; `% j+ w5 d# Z& d
" t( `3 N7 ^( ]1 R8 creturn image;
/ Q, F8 b3 n: s1 O0 b; z/ E}
. ]: T2 P& \* D2 d0 o//---------------------------------------------------------------------------
8 h7 O$ x9 |( m$ l9 ?
9 y& U" W4 J& H# ~3 F/ M; M' t4 s( Mvoid Blt( SDL_Surface * image, int x, int y ) 9 H8 [- k# o2 t m8 U6 \ o
{
( w1 N/ e( U( H ~int Row, Col, r, c, shiftx, shifty; ' ` w( b# t7 U- k) M- o
SDL_Rect dest, src; 3 N) p/ ^5 K9 |. C! D# S
- z0 q( Z& ]2 y6 h! X
/* out of screen */ + t: L$ r5 ]" t& u6 T
if ( ( x > screen->w ) || ( y > screen->h ) || @4 i* [2 g5 k9 g" r
( x + image->w < 1 ) || ( y + image->h < 1 ) )
& R& B; {2 h. _6 `/ C: breturn; + Z& f" `4 |& W5 w" x. y" M
& d2 c9 q/ O( ~src.x = 0; 2 T! X& g# b5 X8 w( c/ a) Z
src.y = 0;
) m0 A: g( N0 Asrc.w = image->w;
1 R7 R$ h" z1 \ @. }/ _1 H' q, Xsrc.h = image->h;
4 R) v8 {7 v! Jdest.x = x;
8 @. Z' O& n `5 t; ldest.y = y;
$ R/ n# P/ ?# b( I' s ~! Gdest.w = src.w; 2 \' F f8 p# z) e. f: q u
if ( y < 0 ) ; Q6 T# ~8 b& U# Z
{
2 f1 J# D3 s8 T+ G0 }& \src.y = 0 - y; 4 E" r( O$ m2 Q
src.h = image->h + src.y;
- p* I; Q8 C9 j0 o* C: j2 idest.y = 0;
0 A1 E4 ]' ]$ L# \}
/ f0 ~9 b% D5 J" ]* C3 z4 n3 q8 fdest.h = src.h; 0 q. N+ G' v) m( \; C; ~# f
1 @+ B4 P( U# a K/ O6 c
SDL_BlitSurface( image, &src, screen, &dest );
4 G5 S! U8 U. K) T}
& q+ A0 x8 }$ J0 s; b1 a+ _! L) `//--------------------------------------------------------------------------- - \# M1 `- I" v( H
8 V+ m4 d% F3 O7 w1 U+ ~
void TileBlt( SDL_Surface * image, int x, int y )
* o* B( }5 m V{
, s! V4 ^8 M* `int Row, Col, r, c, shiftx, shifty; / s a1 F& g5 \2 T+ N* l" y
SDL_Rect dest, src; ! s# ^- K% }" s
! F, k9 r% I( {- tshiftx = x % image->w;
; v8 U3 D4 F' `' `shifty = y % image->h;
2 D. S9 L m' }) n7 N+ K8 _5 I" D4 S; Y ]( q0 ]) F
if ( shiftx >0 ) shiftx -= image->w; 7 S! v3 N# X8 r3 f- v7 [0 d, {
if ( shifty >0 ) shifty -= image->h; ' i3 L7 L/ x$ s: [
% O9 d5 U, F IRow = screen->h / image->h + 2; & M9 Z1 i+ }& v/ g- {/ {
Col = screen->w / image->w + 2;
2 P" Q4 ~; J& T/ l1 @( ~" [2 ], `" P4 D! \1 b' o( W: L# D4 V
dest.x = 0;
/ J k5 h/ Y" Z! P! Q8 S5 Fdest.y = 0; ! S, V# G* M7 u0 { R% r
dest.w = image->w;
/ ? {5 z5 Z! W6 n5 T! Odest.h = image->h;
8 r; Z) S3 S0 A$ P5 ysrc.x = 0;
0 i1 L5 n ?. v% f8 y$ `src.y = 0; 8 d& j( V& m- p0 V. y% ~& H" W
src.w = image->w;
/ J2 \6 ?5 H' ~3 J% Vsrc.h = image->h; & m, r, ?) |! {! S8 B3 ^
- c& Z9 B& I. u8 U5 tfor ( r = 0; r < Row; r ++ )
% ?2 H. h0 z3 L8 N- C! f" E7 I1 h% Y{
7 [+ V1 m' m# x8 `if ( r ) 0 _( a# V* P4 y7 s* z
{ 2 K6 K/ U/ j1 H' g$ t$ }. p
src.y = 0;
4 a7 M6 g% R/ T. m1 Usrc.h = image->h;
3 t( {. J# }4 f6 V/ sdest.h = image->h; * g$ x c8 O% P+ S I: |- N
dest.y = image->h * r + shifty;
/ t/ u6 _( G+ T& S s0 X% J} 8 M h" A0 e& i! c8 k# A
else
9 p$ b1 o. Y: C6 ]& @{ /* first line ? */ , \9 J0 @ ^5 R' m) \) k9 h6 M
src.y = 0 - shifty; / k/ d+ C# C" I
src.h = image->h;
: s3 T- B7 U2 Bdest.h = image->h + shifty; ; g# `' p$ a# {7 A2 w/ ~8 P" I
dest.y = 0; 1 s/ S; A L& C6 J+ F; ~, d- l
} / h8 d$ b6 E* W
; P1 Y& E7 X1 G% N) a7 {! i6 Ufor ( c = 0; c < Col; c ++ )
6 f* M- T. l( O' z{
# Y% V9 `" j' e- ldest.x = image->w * c + shiftx; : X) M: w3 j- v. \- {* \7 u
SDL_BlitSurface( image, &src, screen, &dest );
1 P( `7 X- W( {3 E# b& H+ |} - i9 X% u6 o) R9 C+ b; U0 c: N
}
6 V8 B3 h6 h: `4 a7 u}
" q. K, Q8 c% p; W* J1 I+ C# P//---------------------------------------------------------------------------
, t$ x+ E" h$ o7 I
$ e6 y. a2 N w _" J( [void SetTransparentColor( SDL_Surface * sprite, int R, int G, int B )
4 x4 j) T) h1 P2 V: L9 ~{
* V- g8 E' r5 L+ m+ a! X( aSDL_SetColorKey( sprite, SDL_SRCCOLORKEY|SDL_RLEACCEL, SDL_MapRGB( sprite->format, R, G, B ) );
/ j, u/ L% x8 d X}
( _% e; G, B- F+ Q9 s) m7 M//---------------------------------------------------------------------------
. e# V* {% E' P' o1 q/ {/ s- J: N. Q1 F5 i1 r' |) Y- p; ?
/* Remove the output files if there was no output written */ : m# ]4 f U) U+ z7 S% b* x0 C. R5 V
static void cleanup_output( )
d# ?" A1 E8 [& D{
* l# e0 z6 Q3 S0 jFILE *file;
) t& k7 \5 m. U/ A. E, lint empty;
! _# B2 Y; N% \) A& g- ]
% r! \" m) l& f0 d! z* z1 X/* Flush the output in case anything is queued */
' H) J: y3 X( n1 W* Cfclose(stdout); % Z& L/ L* \; `. k" A0 ]/ M0 q
fclose(stderr); # K6 f& a2 B3 x8 |# T+ D6 q$ [
% [+ a' G4 q2 M- M0 {4 M0 g E( Q
/* See if the files have any output in them */
# N) N* @, C: Z+ P* n7 cfile = fopen(STDOUT_FILE, "rb"); - s# X ^( x; k$ S* W- A
if ( file ) R1 E6 s( T4 x1 V4 |# N
{ 3 W% T7 L* @0 k" k' a4 S
empty = (fgetc(file) == EOF) ? 1 : 0; 9 j. K! a! P. r6 l# ]2 n1 v v
fclose(file);
4 [: y4 o% e/ qif ( empty ) a/ [" R p I: l0 N
remove(STDOUT_FILE); ) ] L! M& N" D8 j
}
+ f" S& B/ y( T$ f& |/ `file = fopen(STDERR_FILE, "rb"); 7 l+ j$ D5 [9 }: y! p* A* m: N) M
if ( file )
) i; y( c/ A8 y j$ c{ 3 M; r" J2 t \; H1 k \ S- a }3 U
empty = (fgetc(file) == EOF) ? 1 : 0;
7 j7 Q& U/ S! vfclose(file);
, ]% s. |6 ?" F- t$ d; y% g, bif ( empty )
& n- z( c3 T$ e% W' Rremove(STDERR_FILE);
9 J0 `# \4 F- {) k4 s, p} 9 I. \/ I6 p4 y. y ~9 c* n- b# G
} # Q) x9 j& H0 P
//--------------------------------------------------------------------------- ' d5 U: C. X: s$ I1 n" D
4 T/ V9 Z; H4 ^" l" N. X
void IoRedirect( ) . F1 g1 \) x& p) x) v7 l
{
: `7 b g6 c) F( c4 `9 e6 W# M) pFILE *newfp; ! W }& |7 f. K5 U! E0 T7 A$ ?/ d
# v7 y- h$ i3 }8 ?$ p& d& Y0 z# d$ t
/* Redirect standard standard output */
7 h9 p% i5 q0 v+ s+ @2 ~3 Anewfp = freopen(STDOUT_FILE, "w", stdout); % s1 N0 X& X, I: J
if ( newfp == NULL )
3 j- ~# K& g# G6 h1 P{ /* This happens on NT */
: V( f% D0 G6 h3 V4 _7 t#if !defined(stdout)
4 I6 Q1 c+ U* ^6 R$ t& Hstdout = fopen(STDOUT_FILE, "w"); - d/ u4 D* o/ N& d$ x
#else
+ E* s3 O$ b' Gnewfp = fopen(STDOUT_FILE, "w");
- U. u! [: W' n' R5 [$ h2 M* Sif ( newfp ) *stdout = *newfp;
( |6 U- C3 m! {" p) ?#endif 6 `+ M; O8 v8 W! `0 `. w
} ' D% x1 t8 i" a% T4 n- C C( q' U
3 P) [" X- o* l5 d
/* Redirect standard standard error */
) _8 @5 i& G, h2 x/ F3 I( _! knewfp = freopen(STDERR_FILE, "w", stderr); 4 O5 U! _+ c* e8 }2 _( Y
if ( newfp == NULL ) 2 {2 B4 q/ U" x. D
{ /* This happens on NT */
) q! U" r( M2 N; B6 A! G#if !defined(stderr) * s5 Y/ _1 [8 m7 d
stderr = fopen(STDERR_FILE, "w"); $ h4 u3 n3 J* ^. u0 h( ^
#else * L! ~3 P! z, l- B) B; S
newfp = fopen(STDERR_FILE, "w");
: b' }! x% }) `if ( newfp ) *stderr = *newfp;
J/ X( V% G8 q6 s5 s' Z#endif
" I* V/ ~7 s) U0 e8 c" [ ~}
' p/ i7 G+ d0 g7 `; q- m- X* S7 G) I1 k G; X j* K
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */
; ?7 a, h; U! q: o3 |1 z. P5 O+ |setbuf(stderr, NULL); /* No buffering */
# \, w$ I; b- u) G& B' l. ~# m- Aatexit(cleanup_output); % W% _: P$ y( d" s7 e
} 3 m* S d" u! ?! Y- ^, O
//--------------------------------------------------------------------------- 7 A1 O) Y: w5 D2 b4 u
3 ^- [ _/ r% Q1 t; jBOOL HZ_Init() : g8 Z7 z: \7 R& T% M6 X
{ # O! M j- Q9 U- R2 K- {" H0 y
FILE * file;
% i% f [) A9 _5 L* N
: C; H4 F- A8 B+ }0 ]5 E& z) C% [* Dfile = fopen( ".\\\\HZK16.GBK", "rb" ); . E7 F2 ^/ Y% B+ u2 m) d! Q
fread( HZK16, 32, 0x5d84, file );
+ ?5 N% y2 Y. b8 Hfclose( file );
( S* r( C$ [, R" D! m5 b) y# ofile = fopen( ".\\\\HZK14.GBK", "rb" ); * i( E6 w [+ o2 s- `; |
fread( HZK14, 28, 0x5d84, file ); 9 a4 S* l8 _6 `5 e# K" T
fclose( file );
" x0 f% D: x4 ^2 ~/ ~file = fopen( ".\\\\HZK12.GBK", "rb" ); 4 g4 T: O4 q: `9 M
fread( HZK12, 24, 0x5d84, file ); - E! l) [4 o$ H n W* n
fclose( file ); * r+ e$ Y- i: c; J# F5 x
D5 h, P! I) c: g8 s Preturn TRUE;
& W) T- t( p! N' }1 y, S* m} 8 V$ W# K! e2 k0 } a2 j0 i
//--------------------------------------------------------------------------- 5 N! R( |' ]8 G- N6 i8 z* a7 `
: k& ?9 S2 o$ Z3 M+ pBOOL HZ_TextOut( SDL_Surface * image, int x, int y, int width, int space, unsigned char * str ) , G$ f7 N9 U E, a8 {
{
/ b, |/ i! s8 I. R! h; K8 BUint8 * bufptr;
8 t' a9 N) ~" T0 K! W0 FUint8 * HZK;
! S$ B4 m# w; XUint16 Bits[16]; , D1 C& F) \& ^; m1 L' q0 U
int i,j,k, m, offset = 0; * [1 Y/ ^2 H% i- L0 a5 c6 Q m
unsigned char q;
( J0 e8 P+ |) n5 Cunsigned char w; " }: E- ^5 M& Q# E+ c$ h
( \! Q* b x, k; |* }) H
switch ( width ) 1 p$ r* o, P* W2 s3 w+ g' V
{
; ~ Y/ m0 g1 l6 A9 S5 rcase 12: 8 z7 \. ~5 J" A' W2 M0 o A) Z
HZK = HZK12;
2 T0 [* a' J! C: b: {break; - F6 x: {% F2 P( ]2 I
case 14:
$ E$ ~$ }3 P7 g( N# U! x( r, WHZK = HZK14; - b( {2 j# i; \
break; 3 Y+ x5 X" i+ D9 z9 @
case 16:
' r6 u1 L$ i( z7 l* W: O0 qHZK = HZK16;
3 B0 c7 r: W' a; j( {* ^break;
+ f% V5 {- O/ ^default:
+ v Z6 F2 e9 ^7 [7 ]return FALSE; , t+ x- F, g5 m+ o$ a4 F% t2 Q( ]7 N
} ) L, [0 R) n2 q
bufptr = (unsigned char*)image->pixels;
X1 T8 S$ l+ S9 O% @0 f9 h6 I: m$ n6 O* N
m = strlen( str ); & ?) f, N# i% E' H7 v
for ( k = 0; k < m; k +=2 ) - ?/ |8 Z6 y2 n$ ^4 U
{ 5 `! \) D5 ^' i' } a+ d! A
Uint32 X, Y, Z, M; , k' M" `% L% x' @$ S
q = str[k];
( w8 K# x0 v1 A$ z& Qw = str[k+1]; ( n# N: }. w- e) _
! L* j- i! C- |' f3 @! M
if ( w > 0xa0 ) - }8 k8 U% T8 L2 `0 M6 D
{
2 i, E |# S% R3 y. E0 V, c# BM = 0x5e; : }, |/ w% I/ ^
Y = w - 0xa1; 6 `! q" W2 b, w. ~) d8 V5 t
if ( q > 0xa0 ) 2 U4 t9 N$ [3 T' Y. O. z6 S
{
2 i$ |7 S; \# a- E. a4 xX = q - 0xa1;
% q7 ?7 u$ C& `% s- M2 \& U& YZ = 0; 2 q6 N- N/ F7 `; H
}
7 L' F/ C8 C/ d, A' Z5 s) Qelse 9 Q, c1 i! X- t
{
. J5 O( ~' A% b/ {) r5 _+ Y' H: PX = q - 0x81; * p- h p4 f/ E7 A9 i& B
Z = 0x2284; 5 p1 L' [0 x4 ~1 C
} # [. G7 Y; L1 m0 S) |0 d
} * X, H# Q! P! z$ W
else
, }+ B2 A: p8 B3 n9 x% B{ / ~/ E1 Y2 Y; z3 A% q" I9 A5 m
M = 0x60;
- p' N/ l& K2 J8 o6 [if ( w > 0x7f ) Y = w - 0x41; " d( P; A3 _! O) p
else Y = w - 0x40; ( R' c ?7 D2 U
/ {% C& C! Q2 E" Mif ( q > 0xa0 ) : U: P6 T2 P: z6 u% n I9 w
{ + L2 L/ J0 l0 G# t# D8 D) [" q$ w
X = q - 0xa1;
3 C& a% U: m9 g) BZ = 0x3a44; 2 ]! Z; t3 N1 h5 y
} + h1 f2 n% j$ k3 [/ S3 ^: U2 D. d
else 2 [2 T" S3 t9 I0 p
{ 9 U P. |! e+ o: }- e
X = q - 0x81;
( U3 T8 S! |' U WZ = 0x2e44;
* k6 B4 Z8 z" F4 v. p7 g) D7 o} $ |& p% ~* ?# [
} 2 l8 C3 Q8 B9 g0 `8 \1 g
memcpy( Bits, HZK + ( X * M + Y + Z ) * width * 2, width * 2 );
/ ?0 ^& [' f2 a/ g% s8 R- j( y
for ( i = 0; i < width; i ++ ) // row
4 C6 {& H1 Z% g3 R& O{
5 E$ M" J( L9 j8 ^Uint16 line;
" J) v1 {4 n8 ]+ X, E% Y9 o. }: H y0 C+ i# x) ]
line = Bits[ i ]; 7 y$ f+ F6 p. R3 ?+ T
line = ( line >> 8 ) + ( line << 8 );
, D' E5 N. r; D8 x
! k$ Y& n* r# B* r. \, V! Vfor ( j = 0; j < 16 ; j ++ ) //col
; p! h3 ]: L$ H{ 6 H6 _6 t2 \ s) g% F" C
int index;
# p2 d. M; c) Y+ ~5 A9 Z3 tint mask = 1;
$ T& ^, a+ \2 ~$ S( `
0 h, X# T- p/ L0 \index = offset + x + 16 - j - 1 + ( y + i ) * image->pitch / image->format->BytesPerPixel; ) o) w1 o5 R- R7 C: `6 r* G3 n
mask <<= j; S* s) t5 c7 w9 W0 e8 @
if ( mask & line )
- n% Q1 T! O) K1 Y Z( n) c# D! @8 w; s{
9 _7 y0 M% ~% _: ^) a q7 Xbufptr[ index * 2 ] = 0xff;
. i+ a7 p& R8 J4 Qbufptr[ index * 2 + 1 ] = 0xff; , E3 Y# N' e) X6 N8 t6 Y) d" F% G/ s
}
1 T( e/ z1 D& B, `0 D}
* j/ \7 l) T2 U3 e* c$ ~" s} $ j" ?9 w; e/ i0 I4 S
offset += width + space;
1 b# _- j) E: O& {}
/ Z1 m; T' E* S& kreturn TRUE;
: t7 H+ D, A/ P( o} |