123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- #include "font.h"
- #include "ascii.h"
- #include "util.h"
- typedef struct tagFont
- {
- LPWORD lpBufChar;
- LPBYTE lpBufGlyph;
- INT nChar;
- } FONT, *LPFONT;
- static LPFONT gpFont = NULL;
- INT
- PAL_InitFont(
- VOID
- )
- {
- FILE *fp;
- if (gpFont != NULL)
- {
-
-
-
- return 0;
- }
- gpFont = (LPFONT)calloc(1, sizeof(FONT));
- if (gpFont == NULL)
- {
- return -1;
- }
-
-
-
- fp = UTIL_OpenRequiredFile("wor16.asc");
-
-
-
- fseek(fp, 0, SEEK_END);
- gpFont->nChar = ftell(fp);
- gpFont->nChar /= 2;
-
-
-
- gpFont->lpBufChar = (LPWORD)calloc(gpFont->nChar, sizeof(WORD));
- if (gpFont->lpBufChar == NULL)
- {
- free(gpFont);
- gpFont = NULL;
- return -1;
- }
- fseek(fp, 0, SEEK_SET);
- fread(gpFont->lpBufChar, sizeof(WORD), gpFont->nChar, fp);
-
-
-
- fclose(fp);
-
-
-
- fp = UTIL_OpenRequiredFile("wor16.fon");
- gpFont->lpBufGlyph = (LPBYTE)calloc(gpFont->nChar, 30);
- if (gpFont->lpBufGlyph == NULL)
- {
- free(gpFont->lpBufChar);
- free(gpFont);
- gpFont = NULL;
- return -1;
- }
-
-
-
- fseek(fp, 0x682, SEEK_SET);
- fread(gpFont->lpBufGlyph, 30, gpFont->nChar, fp);
- fclose(fp);
- return 0;
- }
- VOID
- PAL_FreeFont(
- VOID
- )
- {
- if (gpFont != NULL)
- {
- free(gpFont->lpBufChar);
- free(gpFont->lpBufGlyph);
- free(gpFont);
- }
- gpFont = NULL;
- }
- VOID
- PAL_DrawCharOnSurface(
- WORD wChar,
- SDL_Surface *lpSurface,
- PAL_POS pos,
- BYTE bColor
- )
- {
- int i, j, dx;
- int x = PAL_X(pos), y = PAL_Y(pos);
- LPBYTE pChar;
-
-
-
- if (lpSurface == NULL || gpFont == NULL)
- {
- return;
- }
-
-
-
- for (i = 0; i < gpFont->nChar; i++)
- {
- if (gpFont->lpBufChar[i] == wChar)
- {
- break;
- }
- }
- if (i >= gpFont->nChar)
- {
-
-
-
- return;
- }
- pChar = gpFont->lpBufGlyph + i * 30;
-
-
-
- y *= lpSurface->pitch;
- for (i = 0; i < 30; i++)
- {
- dx = x + ((i & 1) << 3);
- for (j = 0; j < 8; j++)
- {
- if (pChar[i] & (1 << (7 - j)))
- {
- ((LPBYTE)(lpSurface->pixels))[y + dx] = bColor;
- }
- dx++;
- }
- y += (i & 1) * lpSurface->pitch;
- }
- }
- VOID
- PAL_DrawASCIICharOnSurface(
- BYTE bChar,
- SDL_Surface *lpSurface,
- PAL_POS pos,
- BYTE bColor
- )
- {
- int i, j, dx;
- int x = PAL_X(pos), y = PAL_Y(pos);
- LPBYTE pChar = &iso_font[(int)(bChar & ~128) * 15];
-
-
-
- if (lpSurface == NULL)
- {
- return;
- }
-
-
-
- y *= lpSurface->pitch;
- for (i = 0; i < 15; i++)
- {
- dx = x;
- for (j = 0; j < 8; j++)
- {
- if (pChar[i] & (1 << j))
- {
- ((LPBYTE)(lpSurface->pixels))[y + dx] = bColor;
- }
- dx++;
- }
- y += lpSurface->pitch;
- }
- }
|