#ifndef KOREAN_H
#define KOREAN_H

#include "stdafx.h"
#include "scummsys.h"
#include <SDL.h>

#ifndef ABS
#define ABS(x) ((x)>=0?(x):-(x))
#endif

#ifndef MIN
#define	MIN(a,b) (((a)<(b))?(a):(b))
#endif

#ifndef MAX
#define	MAX(a,b) (((a)>(b))?(a):(b))
#endif

#define RGB_TO_16(r,g,b)	(((((r)>>3)&0x1F) << 11) | ((((g)>>2)&0x3F) << 5) | (((b)>>3)&0x1F))
#define RED_FROM_16(x)		((((x)>>11)&0x1F) << 3)
#define GREEN_FROM_16(x)	((((x)>>5)&0x3F) << 2)
#define BLUE_FROM_16(x)		(((x)&0x1F) << 3)
#define GRAY(a)	((RED_FROM_16(a)+GREEN_FROM_16(a)+BLUE_FROM_16(a))/3)
#define R_MIX50(a,b)	((RED_FROM_16(a)   + RED_FROM_16(b)  )/2)
#define G_MIX50(a,b)	((GREEN_FROM_16(a) + GREEN_FROM_16(b))/2)
#define B_MIX50(a,b)	((BLUE_FROM_16(a)  + BLUE_FROM_16(b) )/2)
#define R_MIX75(a,b)	MIN(((RED_FROM_16(a)   + RED_FROM_16(b)  )/3*2),255)
#define G_MIX75(a,b)	MIN(((GREEN_FROM_16(a) + GREEN_FROM_16(b))/3*2),255)
#define B_MIX75(a,b)	MIN(((BLUE_FROM_16(a)  + BLUE_FROM_16(b) )/3*2),255)

extern char gameFN[16];
extern char Kostr[16];

extern bool _kor_mode;
extern bool _kor_font;
extern bool _not_eng;
extern bool isCMI;

#define MAX_KOR 32

typedef struct {
	uint16 xpos, ypos;
	uint8 color;	
	char buffer[1024];
	uint16 delay;
	//uint16 command;
	//bool remain;
	bool remainflag;
	bool remainend;
	bool remainstart;
} STRKOR;
typedef struct {
	long xpos, ypos,xright;
	uint8 color;
	char buffer[1024];
	uint8 remain;
	//bool r_end;
	//bool r_start;
} STRKORSMUSH;

extern STRKOR KorStrings[48];
extern STRKOR kor_str_desc[48];
extern STRKORSMUSH kor_str_smush[48];

typedef struct {
	Uint8 r;
	Uint8 g;
	Uint8 b;
	Uint8 unused;
} KOR_Color;

extern KOR_Color *kpalette;

extern FILE *korOutput;

extern char k_parse_buffer[1024];

extern int xxi;

extern char strBuf[8000][256];

extern void add2stack(char *buf,uint16 xpos,uint16 ypos,short delay,uint8 pal);
extern void add2stack_desc(char *buf,uint16 xpos,uint16 ypos,short delay,uint8 pal);
extern void add2stack_smush(char *buf,long xpos,long ypos,uint8 col,int tmp);
extern void LoadKorFiles();
extern char *TransDescKor(char *buf);
extern char *Convert2Korean(char *buf);
extern Uint16 RGB2(SDL_Surface *screen, Uint8 R, Uint8 G, Uint8 B);
extern int PutFontOutline( SDL_Surface *screen, int xPos,int yPos,int w,int h,
						  uint16 color,char *fmt,... );
extern bool InitXddFont(bool size, char *pHan,char *pEng);
extern bool DeleteKorString();
extern bool LoadKorString(char *gn);

#endif //KOREAN_H