8 ////////////////////////////////////////////////////////////////////////////////
9 SDL_Surface
*screen
= NULL
;
10 Uint32 palette
[256]; // converted
14 ////////////////////////////////////////////////////////////////////////////////
15 static void quitCleanupCB (void) {
16 //if (TTF_WasInit()) TTF_Quit();
21 ////////////////////////////////////////////////////////////////////////////////
23 if (SDL_Init(SDL_INIT_VIDEO
| SDL_INIT_TIMER
) < 0) {
24 fprintf(stderr
, "FATAL: can't set videomode!\n");
27 atexit(quitCleanupCB
);
29 SDL_WM_SetCaption("Awish", "Awish");
30 SDL_EnableKeyRepeat(200, 25);
31 //SDL_EnableUNICODE(1); // just4fun
32 SDL_EnableUNICODE(0); // just4fun
36 void initVideo (void) {
37 screen
= SDL_SetVideoMode(640, 400, 32, SDL_SWSURFACE
/*|SDL_DOUBLEBUF*/);
39 fprintf(stderr
, "FATAL: can't set videomode!\n");
42 //fprintf(stderr, "BPP: %u\n", screen->format->BytesPerPixel);
46 ////////////////////////////////////////////////////////////////////////////////
47 // create 24bpp surface with color key
48 SDL_Surface
*createSurface (int w
, int h
) {
49 //Uint32 rmask, gmask, bmask/*, amask*/;
52 if (w
< 1 || h
< 1) return NULL
;
54 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
65 s = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, w, h, 32, rmask, gmask, bmask, amask);
67 s
= SDL_CreateRGBSurface(SDL_SRCCOLORKEY
, w
, h
, screen
->format
->BitsPerPixel
, screen
->format
->Rmask
, screen
->format
->Gmask
, screen
->format
->Bmask
, screen
->format
->Amask
);
69 SDL_SetColorKey(s
, SDL_SRCCOLORKEY
, palette
[255]);
75 void blitSurfaceEx (SDL_Surface
*dests
, int destx
, int desty
, SDL_Surface
*srcs
, int srcx
, int srcy
, int srcw
, int srch
) {
78 if (srcw
< 0) srcw
= srcs
->w
;
79 if (srch
< 0) srch
= srcs
->h
;
86 SDL_BlitSurface(srcs
, &src
, dests
, &dst
);
90 ////////////////////////////////////////////////////////////////////////////////
91 void lockSurface (SurfaceLock
*lock
, SDL_Surface
*s
) {
95 if (s
!= NULL
&& SDL_MUSTLOCK(s
)) {
96 lock
->needUnlock
= (SDL_LockSurface(s
) == 0);
102 void unlockSurface (SurfaceLock
*lock
) {
103 if (lock
&& lock
->s
&& lock
->needUnlock
) {
104 SDL_UnlockSurface(lock
->s
);
105 lock
->needUnlock
= 0;
110 ////////////////////////////////////////////////////////////////////////////////
111 // surface must be locked!
112 void drawChar (SDL_Surface
*s
, char ch
, int x
, int y
, Uint8 clr
) {
113 unsigned char c
= (unsigned char)(ch
);
115 for (int dy
= 0; dy
< 8; ++dy
) {
116 Uint8 b
= font
[c
][dy
];
118 for (int dx
= 0; dx
< 8; ++dx
) {
119 if (b
&0x80) putPixel2x(s
, x
+dx
, y
+dy
, clr
);
126 void drawString (SDL_Surface
*s
, const char *str
, int x
, int y
, Uint8 clr
) {
127 for (; *str
; ++str
) {
128 drawChar(s
, *str
, x
, y
, clr
);