diff --git a/Makefile b/Makefile index df9823d..99fcad1 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,13 @@ SDL_CFLAGS := $(shell sdl2-config --cflags) -SDL_LFLAGS := $(shell sdl2-config --libs) -luuid -limm32 -lole32 -loleaut32 -lversion +SDL_LFLAGS := -lSDL2_ttf $(shell sdl2-config --libs) CXXFLAGS = -Isrc -Isrc/sys -D_SYSTEM3 -D_DEBUG_CONSOLE -MMD $(SDL_CFLAGS) -LIBS = -lgdi32 -lgdiplus -lwinmm +LIBS = -lfreetype -lharfbuzz -lglib-2.0 -lpng -lbz2 -lz -lintl -liconv \ + -luuid -limm32 -lole32 -loleaut32 -lversion -lgdi32 -lgdiplus -lwinmm -lws2_32 OBJS = src/fileio.o \ - src/winmain.o \ + src/sdlmain.o \ src/sys/ags.o \ src/sys/ags_bmp.o \ src/sys/ags_cursor.o \ diff --git a/src/common.h b/src/common.h index bd78886..f85c605 100644 --- a/src/common.h +++ b/src/common.h @@ -8,6 +8,7 @@ #define _COMMON_H_ #include +#include // tchar.h shim typedef char _TCHAR; diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp new file mode 100644 index 0000000..2bd187d --- /dev/null +++ b/src/sdlmain.cpp @@ -0,0 +1,67 @@ +#include "common.h" +#include "sys/nact.h" + +_TCHAR g_root[_MAX_PATH]; +HINSTANCE g_hinst; +SDL_Window* g_window; + +int main(int argc, char *argv[]) +{ + // モジュールパスå�–å¾— + GetModuleFileName(NULL, g_root, _MAX_PATH); + int p = _tcslen(g_root); + while(g_root[p] != _T('\\')) { + p--; + } + g_root[p + 1] = _T('\0'); + + g_hinst = (HINSTANCE)::GetModuleHandle(NULL); + + SDL_Init(SDL_INIT_VIDEO); + + // ウィンドウ表示 + _TCHAR buf[128]; +#if defined(_SYSTEM1) + _tcscpy_s(buf, 128, _T("Scenario Decoder SYSTEM1")); +#elif defined(_SYSTEM2) + _tcscpy_s(buf, 128, _T("Scenario Decoder SYSTEM2")); +#else + _tcscpy_s(buf, 128, _T("Scenario Decoder SYSTEM3")); +#endif + + g_window = SDL_CreateWindow(buf, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 400, 0); + + // MCI åˆ�期化 + //initialize_mci(); + + // system3 åˆ�期化 + NACT* nact = new NACT(); + + _TCHAR title[128]; + if(nact->get_title(title, 128)) { +#if defined(_SYSTEM1) + _stprintf_s(buf, 128, _T("Scenario Decoder SYSTEM1 - %s"), title); +#elif defined(_SYSTEM2) + _stprintf_s(buf, 128, _T("Scenario Decoder SYSTEM2 - %s"), title); +#else + _stprintf_s(buf, 128, _T("Scenario Decoder SYSTEM3 - %s"), title); +#endif + wchar_t wbuf[128]; + MultiByteToWideChar(CP_ACP, 0, buf, -1, wbuf, 128); + WideCharToMultiByte(CP_UTF8, 0, wbuf, -1, buf, 128, NULL, NULL); + + SDL_SetWindowTitle(g_window, buf); + } + + nact->mainloop(); + + SDL_DestroyWindow(g_window); + + // system3 開放 + delete nact; + + // MCI 開放 + //release_mci(); + + return 0; +} diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index 7388d06..83a128c 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -7,10 +7,9 @@ #include "ags.h" #include "crc32.h" #include "../fileio.h" -using namespace Gdiplus; extern _TCHAR g_root[_MAX_PATH]; -extern HWND g_hwnd; +extern SDL_Window* g_window; #define SET_TEXT(n, x1, y1, x2, y2, f) { \ text_w[n].sx = x1; \ @@ -36,126 +35,37 @@ extern HWND g_hwnd; AGS::AGS(NACT* parent) : nact(parent) { - // GDI+�‰Šú‰» - GdiplusStartup(&gdiToken, &gdiSI, NULL); - - HDC hdc = GetDC(g_hwnd); + sdlRenderer = SDL_CreateRenderer(g_window, -1, 0); + SDL_RenderSetLogicalSize(sdlRenderer, 640, 400); + sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, 640, 400); // TOOD: pixelformat? // DIBSection 8bpp * 3 (•\, — , ƒ�ƒjƒ…�[) for(int i = 0; i < 3; i++) { - lpBufScreen[i] = (LPBYTE)GlobalAlloc(GPTR, sizeof(BITMAPINFO)); - lpDibScreen[i] = (LPBITMAPINFO)lpBufScreen[i]; - lpDibScreen[i]->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - lpDibScreen[i]->bmiHeader.biWidth = 640; - lpDibScreen[i]->bmiHeader.biHeight = 480; - lpDibScreen[i]->bmiHeader.biPlanes = 1; - lpDibScreen[i]->bmiHeader.biBitCount = 32; - lpDibScreen[i]->bmiHeader.biCompression = BI_RGB; - lpDibScreen[i]->bmiHeader.biSizeImage = 0; - lpDibScreen[i]->bmiHeader.biXPelsPerMeter = 0; - lpDibScreen[i]->bmiHeader.biYPelsPerMeter = 0; - lpDibScreen[i]->bmiHeader.biClrUsed = 0; - lpDibScreen[i]->bmiHeader.biClrImportant = 0; - hBmpScreen[i] = CreateDIBSection(hdc, lpDibScreen[i], DIB_RGB_COLORS, (PVOID*)&lpBmpScreen[i], NULL, 0); - hdcDibScreen[i] = CreateCompatibleDC(hdc); - SelectObject(hdcDibScreen[i], hBmpScreen[i]); - memset(lpBmpScreen[i], 0, 640 * 480 * sizeof(DWORD)); + hBmpScreen[i] = SDL_CreateRGBSurface(0, 640, 480, 32, 0, 0, 0, 0); + SDL_LockSurface(hBmpScreen[i]); + + // TODO: clear surface + // memset(lpBmpScreen[i], 0, 640 * 480 * sizeof(DWORD)); // ‰¼‘zVRAM‚ւ̃|ƒCƒ“ƒ^Žæ“¾ for(int j = 0; j < 480; j++) { - vram[i][j] = &lpBmpScreen[i][640 * (479 - j)]; + vram[i][j] = surface_line(hBmpScreen[i], j); } } // DIBSection 24bpp * 1 (�Å�I�o—Í�æ) - lpBufDest = (LPBYTE)GlobalAlloc(GPTR, sizeof(BITMAPINFO)); - lpDibDest = (LPBITMAPINFO)lpBufDest; - lpDibDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - lpDibDest->bmiHeader.biWidth = 640; - lpDibDest->bmiHeader.biHeight = 480; - lpDibDest->bmiHeader.biPlanes = 1; - lpDibDest->bmiHeader.biBitCount = 32; - lpDibDest->bmiHeader.biCompression = BI_RGB; - lpDibDest->bmiHeader.biSizeImage = 0; - lpDibDest->bmiHeader.biXPelsPerMeter = 0; - lpDibDest->bmiHeader.biYPelsPerMeter = 0; - lpDibDest->bmiHeader.biClrUsed = 0; - lpDibDest->bmiHeader.biClrImportant = 0; - hBmpDest = CreateDIBSection(hdc, lpDibDest, DIB_RGB_COLORS, (PVOID*)&lpBmpDest, NULL, 0); - hdcDibDest = CreateCompatibleDC(hdc); - SelectObject(hdcDibDest, hBmpDest); - memset(lpBmpDest, 0, 640 * 480 * sizeof(DWORD)); - - // DIBSection 24bpp * 1 (ƒeƒLƒXƒg•`‰æ) - lpBufText = (LPBYTE)GlobalAlloc(GPTR, sizeof(BITMAPINFO)); - lpDibText = (LPBITMAPINFO)lpBufText; - lpDibText->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - lpDibText->bmiHeader.biWidth = 64; - lpDibText->bmiHeader.biHeight = 64; - lpDibText->bmiHeader.biPlanes = 1; - lpDibText->bmiHeader.biBitCount = 32; - lpDibText->bmiHeader.biCompression = BI_RGB; - lpDibText->bmiHeader.biSizeImage = 0; - lpDibText->bmiHeader.biXPelsPerMeter = 0; - lpDibText->bmiHeader.biYPelsPerMeter = 0; - lpDibText->bmiHeader.biClrUsed = 0; - lpDibText->bmiHeader.biClrImportant = 0; - hBmpText = CreateDIBSection(hdc, lpDibText, DIB_RGB_COLORS, (PVOID*)&lpBmpText, NULL, 0); - hdcDibText = CreateCompatibleDC(hdc); - SelectObject(hdcDibText, hBmpText); -// memset(lpBmpText, 0, 64 * 64 * sizeof(DWORD)); - - // DIBSection 24bpp * 1 (ƒ�ƒjƒ…�[•`‰æ) - lpBufMenu = (LPBYTE)GlobalAlloc(GPTR, sizeof(BITMAPINFO)); - lpDibMenu = (LPBITMAPINFO)lpBufMenu; - lpDibMenu->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - lpDibMenu->bmiHeader.biWidth = 64; - lpDibMenu->bmiHeader.biHeight = 64; - lpDibMenu->bmiHeader.biPlanes = 1; - lpDibMenu->bmiHeader.biBitCount = 32; - lpDibMenu->bmiHeader.biCompression = BI_RGB; - lpDibMenu->bmiHeader.biSizeImage = 0; - lpDibMenu->bmiHeader.biXPelsPerMeter = 0; - lpDibMenu->bmiHeader.biYPelsPerMeter = 0; - lpDibMenu->bmiHeader.biClrUsed = 0; - lpDibMenu->bmiHeader.biClrImportant = 0; - hBmpMenu = CreateDIBSection(hdc, lpDibMenu, DIB_RGB_COLORS, (PVOID*)&lpBmpMenu, NULL, 0); - hdcDibMenu = CreateCompatibleDC(hdc); - SelectObject(hdcDibMenu, hBmpMenu); -// memset(lpBmpMenu, 0, 64 * 64 * sizeof(DWORD)); - - ReleaseDC(g_hwnd, hdc); + hBmpDest = SDL_CreateRGBSurface(0, 640, 480, 32, 0, 0, 0, 0); + SDL_LockSurface(hBmpDest); + // TODO: clear surface // ƒtƒHƒ“ƒg - LOGFONT logfont; - logfont.lfEscapement = 0; - logfont.lfOrientation = 0; - logfont.lfWeight = FW_NORMAL; - logfont.lfItalic = FALSE; - logfont.lfUnderline = FALSE; - logfont.lfStrikeOut = FALSE; - logfont.lfCharSet = SHIFTJIS_CHARSET; - logfont.lfOutPrecision = OUT_TT_PRECIS; - logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; - logfont.lfQuality = NONANTIALIASED_QUALITY; //DEFAULT_QUALITY; - logfont.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; - _tcscpy_s(logfont.lfFaceName, LF_FACESIZE, _T("‚l‚r ƒSƒVƒbƒN")); - - logfont.lfHeight = 16; - logfont.lfWidth = 8; - hFont16 = CreateFontIndirect(&logfont); - logfont.lfHeight = 24; - logfont.lfWidth = 12; - hFont24 = CreateFontIndirect(&logfont); - logfont.lfHeight = 32; - logfont.lfWidth = 16; - hFont32 = CreateFontIndirect(&logfont); - logfont.lfHeight = 48; - logfont.lfWidth = 24; - hFont48 = CreateFontIndirect(&logfont); - logfont.lfHeight = 64; - logfont.lfWidth = 32; - hFont64 = CreateFontIndirect(&logfont); + TTF_Init(); + const char fontfile[] = "MTLc3m.ttf"; + hFont16 = TTF_OpenFont(fontfile, 16); + hFont24 = TTF_OpenFont(fontfile, 24); + hFont32 = TTF_OpenFont(fontfile, 32); + hFont48 = TTF_OpenFont(fontfile, 48); + hFont64 = TTF_OpenFont(fontfile, 64); // ƒJ�[ƒ\ƒ‹�‰Šú‰» for(int i = 0; i < 10; i++) { @@ -327,7 +237,6 @@ AGS::AGS(NACT* parent) : nact(parent) text_dest_y = text_w[0].sy + 2; text_space = 2; text_font_size = 16; - old_text_font_size = 0; #if defined(_SYSTEM1) text_font_color = 15 + 16; text_frame_color = 15 + 16; @@ -342,7 +251,6 @@ AGS::AGS(NACT* parent) : nact(parent) menu_dest_x = 2; menu_dest_y = 0; menu_font_size = 16; - old_menu_font_size = 0; #if defined(_SYSTEM1) menu_font_color = 15 + 16; menu_frame_color = 15 + 16; @@ -401,33 +309,18 @@ AGS::~AGS() } // ƒtƒHƒ“ƒgŠJ•ú - DeleteObject(hFont16); - DeleteObject(hFont24); - DeleteObject(hFont32); - DeleteObject(hFont48); - DeleteObject(hFont64); + TTF_CloseFont(hFont16); + TTF_CloseFont(hFont24); + TTF_CloseFont(hFont32); + TTF_CloseFont(hFont48); + TTF_CloseFont(hFont64); - // DIBSectionŠJ•ú + // surfaceŠJ•ú for(int i = 0; i < 3; i++) { - DeleteDC(hdcDibScreen[i]); - DeleteObject(hBmpScreen[i]); - GlobalFree(lpBufScreen[i]); + SDL_FreeSurface(hBmpScreen[i]); } - DeleteDC(hdcDibDest); - DeleteObject(hBmpDest); - GlobalFree(lpBufDest); - - DeleteDC(hdcDibText); - DeleteObject(hBmpText); - GlobalFree(lpBufText); - - DeleteDC(hdcDibMenu); - DeleteObject(hBmpMenu); - GlobalFree(lpBufMenu); - - // GDI+ŠJ•ú - GdiplusShutdown(gdiToken); + SDL_FreeSurface(hBmpDest); } void AGS::set_palette(int index, int r, int g, int b) @@ -455,12 +348,12 @@ void AGS::set_pixel(int dest, int x, int y, uint8 color) void AGS::fade_start() { - memcpy(fader_screen, lpBmpDest, sizeof(fader_screen)); + memcpy(fader_screen, hBmpDest->pixels, sizeof(fader_screen)); } void AGS::fade_end() { - memcpy(lpBmpDest, fader_screen, sizeof(fader_screen)); + memcpy(hBmpDest->pixels, fader_screen, sizeof(fader_screen)); } void AGS::fade_out(int depth, bool white) @@ -471,7 +364,7 @@ void AGS::fade_out(int depth, bool white) fader = true; for(int y = 0; y < 480; y += 4) { - uint32* dest = &lpBmpDest[640 * (479 - y - fy) + fx]; + uint32* dest = surface_line(hBmpDest, y + fy) + fx; for(int x = 0; x < 640; x += 4) { dest[x] = white ? 0xffffff : 0; } @@ -489,8 +382,8 @@ void AGS::fade_in(int depth) fader = (depth == 15) ? false : true; for(int y = 0; y < 480; y += 4) { - uint32* src = &fader_screen[640 * (479 - y - fy) + fx]; - uint32* dest = &lpBmpDest[640 * (479 - y - fy) + fx]; + uint32* src = &fader_screen[640 * (y + fy) + fx]; + uint32* dest = surface_line(hBmpDest, y + fy) + fx; for(int x = 0; x < 640; x += 4) { dest[x] = src[x]; } @@ -505,7 +398,7 @@ void AGS::flush_screen(bool update) if(update) { for(int y = 0; y < screen_height; y++) { uint32* src = vram[0][y]; - uint32* dest = &lpBmpDest[640 * (479 - y)]; + uint32* dest = surface_line(hBmpDest, y); for(int x = 0; x < 640; x++) { #if defined(_SYSTEM3) // ‚ ‚ä‚Ý‚¿‚á‚ñ•¨Œê ƒtƒ‹ƒJƒ‰�[ŽÀŽÊ”Å @@ -525,7 +418,7 @@ void AGS::draw_screen(int sx, int sy, int width, int height) if(fader) { for(int y = sy; y < (sy + height) && y < 480; y++) { uint32* src = vram[0][y]; - uint32* dest = &fader_screen[640 * (479 - y)]; + uint32* dest = &fader_screen[640 * y]; for(int x = sx; x < (sx + width) && x < 640; x++) { uint32 a=src[x]; #if defined(_SYSTEM3) @@ -540,7 +433,7 @@ void AGS::draw_screen(int sx, int sy, int width, int height) } else { for(int y = sy; y < (sy + height) && y < 480; y++) { uint32* src = vram[0][y]; - uint32* dest = &lpBmpDest[640 * (479 - y)]; + uint32* dest = surface_line(hBmpDest, y); for(int x = sx; x < (sx + width) && x < 640; x++) { uint32 a=src[x]; #if defined(_SYSTEM3) @@ -558,22 +451,13 @@ void AGS::draw_screen(int sx, int sy, int width, int height) void AGS::invalidate_screen(int sx, int sy, int width, int height) { - RECT rect; - rect.left = sx; - rect.top = sy; - rect.right = sx + width; - rect.bottom = sy + height; - - InvalidateRect(g_hwnd, &rect, FALSE); - UpdateWindow(g_hwnd); -} - -void AGS::update_screen(HDC hdc, int sx, int sy, int width, int height) -{ - if(screen_height == 400) { - BitBlt(hdc, sx, sy, width, height, hdcDibDest, sx, sy + (scroll - 400), SRCCOPY); - } else { - BitBlt(hdc, sx, sy, width, height, hdcDibDest, sx, sy, SRCCOPY); - } + SDL_UnlockSurface(hBmpDest); + uint32* pixels = surface_line(hBmpDest, screen_height == 400 ? sy + (scroll - 400) : sy) + sx; + SDL_Rect rect = {sx, sy, width, height}; + SDL_UpdateTexture(sdlTexture, &rect, pixels, hBmpDest->pitch); + SDL_RenderClear(sdlRenderer); + SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); + SDL_RenderPresent(sdlRenderer); + SDL_LockSurface(hBmpDest); } diff --git a/src/sys/ags.h b/src/sys/ags.h index 23652ed..efc8279 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -8,10 +8,10 @@ #define _AGS_H_ #include -#include #include #include "../common.h" #include "nact.h" +#include // ƒtƒF�[ƒh�ˆ—� static const int fade_x[16] = {0, 2, 2, 0, 1, 3, 3, 1, 1, 3, 3, 1, 0, 2, 2, 0}; @@ -32,49 +32,29 @@ static inline uint32 SETPALETTE16(uint32 R, uint32 G, uint32 B) return SETPALETTE256(R, G, B); } +inline uint32* surface_line(SDL_Surface* surface, int y) +{ + return (uint32*)((uint8*)surface->pixels + surface->pitch * y); +} + class AGS { protected: NACT* nact; private: - // GDI+ - Gdiplus::GdiplusStartupInput gdiSI; - ULONG_PTR gdiToken; + SDL_Renderer* sdlRenderer; + SDL_Texture* sdlTexture; - // DIBSection 8bpp * 3 (•\, — , ƒ�ƒjƒ…�[) - HDC hdcDibScreen[3]; - HBITMAP hBmpScreen[3]; - LPBYTE lpBufScreen[3]; - LPDWORD lpBmpScreen[3]; - LPBITMAPINFO lpDibScreen[3]; - - // DIBSection 24bpp (�Å�I�o—Í�æ) - HDC hdcDibDest; - HBITMAP hBmpDest; - LPBYTE lpBufDest; - LPDWORD lpBmpDest; - LPBITMAPINFO lpDibDest; - - // DIBSection 24bpp (ƒeƒLƒXƒg•`‰æ) - HDC hdcDibText; - HBITMAP hBmpText; - LPBYTE lpBufText; - LPDWORD lpBmpText; - LPBITMAPINFO lpDibText; - - // DIBSection 24bpp (ƒ�ƒjƒ…�[•`‰æ) - HDC hdcDibMenu; - HBITMAP hBmpMenu; - LPBYTE lpBufMenu; - LPDWORD lpBmpMenu; - LPBITMAPINFO lpDibMenu; + // Surface + SDL_Surface* hBmpScreen[3]; // 8bpp * 3 (•\, — , ƒ�ƒjƒ…�[) + SDL_Surface* hBmpDest; // DIBSection 24bpp (�Å�I�o—Í�æ) // ƒtƒHƒ“ƒg - HFONT hFont16; - HFONT hFont24; - HFONT hFont32; - HFONT hFont48; - HFONT hFont64; + TTF_Font* hFont16; + TTF_Font* hFont24; + TTF_Font* hFont32; + TTF_Font* hFont48; + TTF_Font* hFont64; // ƒJ�[ƒ\ƒ‹ HCURSOR hArrow; @@ -118,7 +98,6 @@ public: AGS(NACT* parent); ~AGS(); - void update_screen(HDC hdc, int sx, int sy, int width, int height); void flush_screen(bool update); void load_cg(int page, int transparent); @@ -172,7 +151,6 @@ public: int text_dest_y; int text_space; int text_font_size; - int old_text_font_size; uint8 text_font_color; uint8 text_frame_color; uint8 text_back_color; @@ -182,7 +160,6 @@ public: int menu_dest_x; int menu_dest_y; int menu_font_size; - int old_menu_font_size; uint8 menu_font_color; uint8 menu_frame_color; uint8 menu_back_color; diff --git a/src/sys/ags_bmp.cpp b/src/sys/ags_bmp.cpp index 748da72..c1590ca 100644 --- a/src/sys/ags_bmp.cpp +++ b/src/sys/ags_bmp.cpp @@ -19,6 +19,8 @@ void AGS::load_bmp(const _TCHAR *file_path) } if(extract_cg) { + assert(false); +#if 0 // BMP“Ç‚Ý�ž‚Ý WCHAR wszFilePath[_MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, file_path, -1, wszFilePath, _MAX_PATH); @@ -38,5 +40,6 @@ void AGS::load_bmp(const _TCHAR *file_path) // BMPŠJ•ú delete pBitmap; +#endif } } diff --git a/src/sys/ags_draw.cpp b/src/sys/ags_draw.cpp index bd4aef6..a51970b 100644 --- a/src/sys/ags_draw.cpp +++ b/src/sys/ags_draw.cpp @@ -87,7 +87,17 @@ void AGS::copy(int sx, int sy, int ex, int ey, int dx, int dy) draw_screen(dx, dy, width, height); } #else - BitBlt(hdcDibScreen[dest_screen], dx, dy, ex - sx + 1, ey - sy + 1, hdcDibScreen[src_screen], sx, sy, SRCCOPY); + int width = ex - sx + 1; + int height = ey - sy + 1; + SDL_Rect srcrect = {sx, sy, width, height}; + SDL_Rect destrect = {dx, dy, width, height}; + + SDL_UnlockSurface(hBmpScreen[src_screen]); + SDL_UnlockSurface(hBmpScreen[dest_screen]); + SDL_BlitSurface(hBmpScreen[src_screen], &srcrect, hBmpScreen[dest_screen], &destrect); + SDL_LockSurface(hBmpScreen[dest_screen]); + SDL_LockSurface(hBmpScreen[src_screen]); + if(dest_screen == 0) { draw_screen(dx, dy, ex - sx + 1, ey - sy + 1); } @@ -103,8 +113,15 @@ void AGS::gcopy(int gsc, int gde, int glx, int gly, int gsw) int sy = gsc / 80; int dx = (gde % 80) * 8; int dy = gde / 80; + SDL_Rect srcrect = {sx, sy, glx * 8, gly}; + SDL_Rect destrect = {dx, dy, glx * 8, gly}; + + SDL_UnlockSurface(hBmpScreen[src]); + SDL_UnlockSurface(hBmpScreen[dest]); + SDL_BlitSurface(hBmpScreen[src], &srcrect, hBmpScreen[dest], &destrect); + SDL_LockSurface(hBmpScreen[dest]); + SDL_LockSurface(hBmpScreen[src]); - BitBlt(hdcDibScreen[dest], dx, dy, glx * 8, gly, hdcDibScreen[src], sx, sy, SRCCOPY); if(dest == 0) { draw_screen(dx, dy, glx * 8, gly); } @@ -112,10 +129,13 @@ void AGS::gcopy(int gsc, int gde, int glx, int gly, int gsw) void AGS::paint(int x, int y, uint8 color) { + assert(false); +#if 0 HBRUSH hBrush = CreateSolidBrush(RGB(color, color, color)); SelectObject(hdcDibScreen[0], hBrush); ExtFloodFill(hdcDibScreen[0], x, y, GetPixel(hdcDibScreen[0], x, y), FLOODFILLSURFACE); draw_screen(0, 0, 640, screen_height); +#endif } void AGS::draw_box(int index) diff --git a/src/sys/ags_text.cpp b/src/sys/ags_text.cpp index 33335cf..f79204c 100644 --- a/src/sys/ags_text.cpp +++ b/src/sys/ags_text.cpp @@ -8,43 +8,6 @@ void AGS::draw_text(char string[]) { - // ƒtƒHƒ“ƒgƒTƒCƒY‚Ì•Ï�XŒã�Aˆê“x‚¾‚¯�X�V‚·‚é - if(draw_menu) { - if(old_menu_font_size != menu_font_size) { - if(menu_font_size == 16) { - SelectObject(hdcDibMenu, hFont16); - } else if(menu_font_size == 24) { - SelectObject(hdcDibMenu, hFont24); - } else if(menu_font_size == 32) { - SelectObject(hdcDibMenu, hFont32); - } else if(menu_font_size == 48) { - SelectObject(hdcDibMenu, hFont48); - } else if(menu_font_size == 64) { - SelectObject(hdcDibMenu, hFont64); - } - SetBkMode(hdcDibMenu, TRANSPARENT); - SetTextColor(hdcDibMenu, RGB(255, 255, 255)); - old_menu_font_size = menu_font_size; - } - } else { - if(old_text_font_size != text_font_size) { - if(text_font_size == 16) { - SelectObject(hdcDibText, hFont16); - } else if(text_font_size == 24) { - SelectObject(hdcDibText, hFont24); - } else if(text_font_size == 32) { - SelectObject(hdcDibText, hFont32); - } else if(text_font_size == 48) { - SelectObject(hdcDibText, hFont48); - } else if(text_font_size == 64) { - SelectObject(hdcDibText, hFont64); - } - SetBkMode(hdcDibText, TRANSPARENT); - SetTextColor(hdcDibText, RGB(255, 255, 255)); - old_text_font_size = text_font_size; - } - } - int p = 0; while(string[p] != '\0') { @@ -92,6 +55,7 @@ void AGS::draw_char(int dest, int dest_x, int dest_y, uint16 code, int size, uin { char string[3]; int length; + SDL_Color white = {0xff, 0xff, 0xff}; // ƒpƒ^�[ƒ“Žæ“¾ if(code > 0xff) { @@ -104,18 +68,32 @@ void AGS::draw_char(int dest, int dest_x, int dest_y, uint16 code, int size, uin string[1] = '\0'; length = 1; } - memset(draw_menu ? lpBmpMenu : lpBmpText, 0, 64 * 64 * sizeof(DWORD)); - ExtTextOut(draw_menu ? hdcDibMenu : hdcDibText, 0, 0, NULL, NULL, string, length, NULL); + Uint16 buf[2]; + MultiByteToWideChar(CP_ACP, 0, string, length, (LPWSTR)buf, 2); + + TTF_Font* font = NULL; + switch (size) { + case 16: font = hFont16; break; + case 24: font = hFont24; break; + case 32: font = hFont32; break; + case 48: font = hFont48; break; + case 64: font = hFont64; break; + } + + SDL_Surface* fs = TTF_RenderGlyph_Solid(font, buf[0], white); // ƒpƒ^�[ƒ“�o—Í - for(int y = 0; y < size && y < 64 && dest_y + y < 480; y++) { - uint32 *pattern = draw_menu ? &lpBmpMenu[64 * (63 - y)] : &lpBmpText[64 * (63 - y)]; - for(int x = 0; x < size && x < 64 && dest_x + x < 640; x++) { + // TODO: Blit? + for(int y = 0; y < size && y < fs->w && dest_y + y < 480; y++) { + uint8 *pattern = (uint8*)surface_line(fs, y); // FIXME: do not assume 8bpp + for(int x = 0; x < size && x < fs->h && dest_x + x < 640; x++) { if(pattern[x] != 0) { vram[dest][dest_y + y][dest_x + x] = color; } } } + + SDL_FreeSurface(fs); } void AGS::draw_gaiji(int dest, int dest_x, int dest_y, uint16 code, int size, uint8 color) diff --git a/src/sys/ags_window.cpp b/src/sys/ags_window.cpp index 7b96817..1e2c476 100644 --- a/src/sys/ags_window.cpp +++ b/src/sys/ags_window.cpp @@ -94,7 +94,7 @@ void AGS::open_text_window(int index, bool erase) text_w[index - 1].screen_height = height; for(int y = 0; y < height && y + sy < 480; y++) { - uint32* scr = fader ? &fader_screen[640 * (479 - y - sy) + sx] : &lpBmpDest[640 * (479 - y - sy) + sx]; + uint32* scr = fader ? &fader_screen[640 * (y + sy) + sx] : surface_line(hBmpDest, y + sy) + sx; for(int x = 0; x < width && x + sx < 640; x++) { uint32 col = vram[0][y + sy][x + sx]; if(!(col & 0x80000000)) { @@ -156,7 +156,7 @@ void AGS::close_text_window(int index, bool update) text_w[index - 1].window_height = height; for(int y = 0; y < height && y + sy < 480; y++) { - uint32* scr = fader ? &fader_screen[640 * (479 - y - sy) + sx] : &lpBmpDest[640 * (479 - y - sy) + sx]; + uint32* scr = fader ? &fader_screen[640 * (y + sy) + sx] : surface_line(hBmpDest, y + sy) + sx; for(int x = 0; x < width && x + sx < 640; x++) { uint32 col = vram[0][y + sy][x + sx]; if(!(col & 0x80000000)) { @@ -197,7 +197,8 @@ void AGS::close_text_window(int index, bool update) void AGS::clear_menu_window() { - memset(lpBmpScreen[2], menu_back_color, 640 * 480 * sizeof(DWORD)); + // TODO: use draw function + memset(hBmpScreen[2]->pixels, menu_back_color, 640 * 480 * sizeof(DWORD)); } void AGS::open_menu_window(int index) @@ -228,7 +229,7 @@ void AGS::open_menu_window(int index) menu_w[index - 1].screen_height = wheight; for(int y = 0; y < wheight && y + wsy < 480; y++) { - uint32* scr = fader ? &fader_screen[640 * (479 - y - wsy) + wsx] : &lpBmpDest[640 * (479 - y - wsy) + wsx]; + uint32* scr = fader ? &fader_screen[640 * (y + wsy) + wsx] : surface_line(hBmpDest, y + wsy) + wsx; for(int x = 0; x < wwidth && x + wsx < 640; x++) { uint32 col = vram[0][y + wsy][x + wsx]; if(!(col & 0x80000000)) { diff --git a/src/sys/mako.cpp b/src/sys/mako.cpp index 6cbca1b..03672df 100644 --- a/src/sys/mako.cpp +++ b/src/sys/mako.cpp @@ -7,8 +7,6 @@ #include "mako.h" #include "dri.h" -extern HWND g_hwnd; - MAKO::MAKO(NACT* parent) : nact(parent) { // AMUS.DAT, AMSE.DAT @@ -107,7 +105,8 @@ void MAKO::play_music(int page) if(current_music) { bool next_cdda = (page < 100 && cd_track[page]) ? true : false; if(cdda_play && !next_cdda) { - PostMessage(g_hwnd, WM_USER, 0, 0); + // TODO: fix + // PostMessage(g_hwnd, WM_USER, 0, 0); } else if(!cdda_play && next_cdda) { params.next_music = 0; } @@ -119,7 +118,8 @@ void MAKO::play_music(int page) if(page < 100 && cd_track[page]) { // CD-DA‚Å�Ä�¶ - PostMessage(g_hwnd, WM_USER, cd_track[page] + 1, 0); + // TODO: fix + // PostMessage(g_hwnd, WM_USER, cd_track[page] + 1, 0); cdda_play = true; } else { // MIDI‚Å�Ä�¶ @@ -133,7 +133,8 @@ void MAKO::stop_music() // Œ»�Ý�Ä�¶’†‚Ì�ê�‡‚Í’âŽ~‚·‚é if(current_music) { if(cdda_play) { - PostMessage(g_hwnd, WM_USER, 0, 0); + // TODO: fix + // PostMessage(g_hwnd, WM_USER, 0, 0); } else { params.next_music = 0; } @@ -165,7 +166,8 @@ void MAKO::notify_mci(int status) if(cdda_play) { current_loop++; if(current_loop < current_max || current_max == 0) { - PostMessage(g_hwnd, WM_USER, cd_track[current_music] + 1, 0); + // TODO: fix + // PostMessage(g_hwnd, WM_USER, cd_track[current_music] + 1, 0); } else { current_music = current_mark = current_loop = 0; cdda_play = false; diff --git a/src/sys/nact.cpp b/src/sys/nact.cpp index 87c5220..64ae6e1 100644 --- a/src/sys/nact.cpp +++ b/src/sys/nact.cpp @@ -21,13 +21,11 @@ #include "../fileio.h" extern _TCHAR g_root[_MAX_PATH]; -extern HWND g_hwnd; // �‰Šú‰» NACT::NACT() { - memset(key, 0, sizeof(key)); mouse_x = mouse_y = 0; // ƒfƒoƒbƒOƒRƒ“ƒ\�[ƒ‹‹N“® @@ -128,21 +126,11 @@ NACT::NACT() joyGetDevCaps(JOYSTICKID1, &joycaps, sizeof(JOYCAPS)); } - // ƒ�ƒCƒ“ƒXƒŒƒbƒh‹N“® - params.nact = this; params.terminate = false; - hThread = SDL_CreateThread(thread, "NactThread", ¶ms); } NACT::~NACT() { - // ƒ�ƒCƒ“ƒXƒŒƒbƒh�I—¹ - params.terminate = true; - if(hThread) { - SDL_WaitThread(hThread, NULL); - } - hThread = NULL; - // ŠeŽíƒNƒ‰ƒXŠJ•ú if(ags) { delete ags; @@ -160,16 +148,12 @@ NACT::~NACT() release_console(); } -int NACT::thread(void* pvoid) +void NACT::mainloop() { - volatile PPARAMS pparams; - pparams = (PPARAMS)pvoid; int sleep_cnt = 0; - SDL_SetThreadPriority(SDL_THREAD_PRIORITY_NORMAL); - - while(!pparams->terminate) { - pparams->nact->execute(); + while(!params.terminate) { + execute(); // 512ƒRƒ}ƒ“ƒhŽÀ�s–ˆ‚ÉSleep(10) if(!(sleep_cnt = (sleep_cnt + 1) & 0x1ff)) { SDL_Delay(10); @@ -177,7 +161,6 @@ int NACT::thread(void* pvoid) SDL_Delay(0); } } - return 0; } // ƒRƒ}ƒ“ƒhƒp�[ƒT @@ -192,7 +175,7 @@ void NACT::execute() // ’v–½“I‚ȃGƒ‰�[”­�¶ or �³�í�I—¹ if(fatal_error) { if(!post_quit) { - PostMessage(g_hwnd, WM_CLOSE, 0, 0); + params.terminate = true; } post_quit = true; return; @@ -437,30 +420,11 @@ int NACT::get_screen_height() return ags->screen_height; } -void NACT::update_screen(HDC hdc, int sx, int sy, int width, int height) -{ - ags->update_screen(hdc, sx, sy, width, height); -} - void NACT::notify_mci(int status) { mako->notify_mci(status); } -void NACT::key_down(int val) -{ - key[val] = 1; -} - -void NACT::key_up(int val) -{ - if(val == -1) { - memset(key, 0, sizeof(key)); - } else { - key[val] = 0; - } -} - void NACT::select_cursor() { ags->select_cursor(); diff --git a/src/sys/nact.h b/src/sys/nact.h index 6c458c6..a6d4bad 100644 --- a/src/sys/nact.h +++ b/src/sys/nact.h @@ -215,7 +215,6 @@ private: int joy_num; JOYCAPS joycaps; - uint8 key[256]; int mouse_x, mouse_y; uint32 calc_crc32(); @@ -225,14 +224,10 @@ private: // ƒ�ƒCƒ“ƒXƒŒƒbƒh typedef struct { - NACT* nact; bool terminate; } PARAMS, *PPARAMS; PARAMS params; - static int thread(void* pvoid); - SDL_Thread* hThread; - // ƒfƒoƒbƒOƒ�ƒO void initialize_console(); void release_console(); @@ -242,12 +237,11 @@ public: NACT(); ~NACT(); + void mainloop(); + int get_screen_height(); - void update_screen(HDC hdc, int sx, int sy, int width, int height); void notify_mci(int status); - void key_down(int val); - void key_up(int val); void select_cursor(); void select_sound(int dev); diff --git a/src/sys/nact_input.cpp b/src/sys/nact_input.cpp index 1dbeb4b..f9f939e 100644 --- a/src/sys/nact_input.cpp +++ b/src/sys/nact_input.cpp @@ -6,21 +6,35 @@ #include "nact.h" -extern HWND g_hwnd; +static bool pump_events() +{ + SDL_Event e; + while (SDL_PollEvent(&e)) { + switch (e.type) { + case SDL_QUIT: + return true; + } + } + return false; +} uint8 NACT::get_key() { uint8 val = 0; + params.terminate = pump_events(); + // ƒL�[ƒ{�[ƒh�•ƒ}ƒEƒX - if(key[VK_UP ] || key[VK_NUMPAD8]) val |= 0x01; - if(key[VK_DOWN ] || key[VK_NUMPAD2]) val |= 0x02; - if(key[VK_LEFT ] || key[VK_NUMPAD4]) val |= 0x04; - if(key[VK_RIGHT ] || key[VK_NUMPAD6]) val |= 0x08; - if(key[VK_RETURN] || key[VK_LBUTTON]) val |= 0x10; - if(key[VK_SPACE ] || key[VK_RBUTTON]) val |= 0x20; - if(key[VK_ESCAPE] ) val |= 0x40; - if(key[VK_TAB ] ) val |= 0x80; + const Uint8* key = SDL_GetKeyboardState(NULL); + Uint32 mouse = SDL_GetMouseState(NULL, NULL); + if(key[SDL_SCANCODE_UP ] || key[SDL_SCANCODE_KP_8 ]) val |= 0x01; + if(key[SDL_SCANCODE_DOWN ] || key[SDL_SCANCODE_KP_2 ]) val |= 0x02; + if(key[SDL_SCANCODE_LEFT ] || key[SDL_SCANCODE_KP_4 ]) val |= 0x04; + if(key[SDL_SCANCODE_RIGHT ] || key[SDL_SCANCODE_KP_6 ]) val |= 0x08; + if(key[SDL_SCANCODE_RETURN] || (mouse & SDL_BUTTON(1))) val |= 0x10; + if(key[SDL_SCANCODE_SPACE ] || (mouse & SDL_BUTTON(3))) val |= 0x20; + if(key[SDL_SCANCODE_ESCAPE] ) val |= 0x40; + if(key[SDL_SCANCODE_TAB ] ) val |= 0x80; // ƒ}ƒEƒXˆÚ“®‚Å•ûŒü“ü—͂̓Tƒ|�[ƒg‚µ‚È‚¢ @@ -44,19 +58,12 @@ uint8 NACT::get_key() void NACT::get_cursor(int* x, int* y) { - POINT pt; - GetCursorPos(&pt); - ScreenToClient(g_hwnd, &pt); - *x = pt.x; - *y = pt.y; + params.terminate = pump_events(); + SDL_GetMouseState(x, y); } void NACT::set_cursor(int x, int y) { - POINT pt; - pt.x = x; - pt.y = y; - ClientToScreen(g_hwnd, &pt); - SetCursorPos(pt.x, pt.y); + // TODO: implement } diff --git a/src/sys/nact_sys1.cpp b/src/sys/nact_sys1.cpp index 66f7eda..9c33ea4 100644 --- a/src/sys/nact_sys1.cpp +++ b/src/sys/nact_sys1.cpp @@ -1042,8 +1042,6 @@ void NACT::cmd_l() scenario_page = next_page; scenario_addr = next_addr; -// ags->old_text_font_size = 0; -// ags->old__menu_font_fize = 0; mako->play_music(next_music); } delete fio; diff --git a/src/sys/nact_sys2.cpp b/src/sys/nact_sys2.cpp index a2d0873..0983218 100644 --- a/src/sys/nact_sys2.cpp +++ b/src/sys/nact_sys2.cpp @@ -1113,8 +1113,6 @@ void NACT::cmd_l() scenario_page = next_page; scenario_addr = next_addr; -// ags->old_text_font_size = 0; -// ags->old__menu_font_fize = 0; mako->play_music(next_music); } delete fio; diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index 0186e14..efb40e3 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -20,7 +20,6 @@ extern _TCHAR g_root[_MAX_PATH]; extern HINSTANCE g_hinst; -extern HWND g_hwnd; void NACT::cmd_calc() { @@ -1033,8 +1032,6 @@ void NACT::cmd_l() scenario_page = next_page; scenario_addr = next_addr; -// ags->old_text_font_size = 0; -// ags->old_menu_font_size = 0; mako->play_music(next_music); } delete fio; @@ -1549,7 +1546,8 @@ void NACT::cmd_y() break; case 27: tvar_maxlen = param; - DialogBoxParam(g_hinst, MAKEINTRESOURCE(IDD_DIALOG1), g_hwnd, TextDialogProc, (LPARAM)this); + // TODO: fix + // DialogBoxParam(g_hinst, MAKEINTRESOURCE(IDD_DIALOG1), g_hwnd, TextDialogProc, (LPARAM)this); break; case 28: ags->text_space = (param == 0) ? 2 : 0; @@ -1740,7 +1738,8 @@ void NACT::cmd_y() break; case 232: if(ags->screen_height != param ? 480 : 400) { - SendMessage(g_hwnd, WM_USER + 2, param ? 480 : 400, 0); + // TODO: fix + // SendMessage(g_hwnd, WM_USER + 2, param ? 480 : 400, 0); ags->screen_height = param ? 480 : 400; } break; diff --git a/src/winmain.cpp b/src/winmain.cpp deleted file mode 100644 index 9410c71..0000000 --- a/src/winmain.cpp +++ /dev/null @@ -1,452 +0,0 @@ -/* - ALICE SOFT SYSTEM 3 for Win32 - - [ WinMain ] -*/ - -#include -#include -#include -#include -#include -#include "common.h" -#if defined(_SYSTEM1) -#include "res1/resource.h" -#elif defined(_SYSTEM2) -#include "res2/resource.h" -#else -#include "res3/resource.h" -#endif -#include "sys/nact.h" - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow); -LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam); - -// ƒtƒ‹ƒXƒNƒŠ�[ƒ“ -void set_window(HWND hWnd, BOOL full); -void show_menu_bar(HWND hWnd); -void hide_menu_bar(HWND hWnd); - -BOOL fullscreen_now = FALSE; -BOOL menuloop_now = FALSE; - -// MCIƒfƒoƒCƒX -void initialize_mci(); -void release_mci(); -void play_mci(HWND hWnd, int index); -void stop_mci(); - -_TCHAR g_root[_MAX_PATH]; -HINSTANCE g_hinst; -HWND g_hwnd = NULL; -HMENU g_hmenu = NULL; - -NACT* nact; - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR szCmdLine, int iCmdShow) -{ - // ƒ‚ƒWƒ…�[ƒ‹ƒpƒXŽæ“¾ - GetModuleFileName(NULL, g_root, _MAX_PATH); - int p = _tcslen(g_root); - while(g_root[p] != _T('\\')) { - p--; - } - g_root[p + 1] = _T('\0'); - - g_hinst = hInstance; - - // ƒEƒBƒ“ƒhƒE‚Ì•\ަˆÊ’u‚ðŽæ“¾‚·‚é - RECT rect = {0, 0, 640, 400}; - AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, TRUE); - - HDC hdc = CreateDC(_T("DISPLAY"), NULL, NULL, NULL); - int width = GetDeviceCaps(hdc, HORZRES); - int height = GetDeviceCaps(hdc, VERTRES); - int dest_x = (int)((width - (rect.right - rect.left)) / 2); - int dest_y = (int)((height - (rect.bottom - rect.top)) / 2); -// dest_x = (dest_x < 0) ? 0 : dest_x; - dest_y = (dest_y < 0) ? 0 : dest_y; - - // ƒEƒBƒ“ƒhƒE�¶�¬ - WNDCLASS wndclass; - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = (WNDPROC)WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = g_hinst; - wndclass.hIcon = LoadIcon(g_hinst, MAKEINTRESOURCE(IDI_ICON1)); - wndclass.hCursor = 0; - wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); - wndclass.lpszClassName = _T("CWINDOW"); - RegisterClass(&wndclass); - - // ƒEƒBƒ“ƒhƒE•\ަ - _TCHAR buf[128]; -#if defined(_SYSTEM1) - _tcscpy_s(buf, 128, _T("Scenario Decoder SYSTEM1")); -#elif defined(_SYSTEM2) - _tcscpy_s(buf, 128, _T("Scenario Decoder SYSTEM2")); -#else - _tcscpy_s(buf, 128, _T("Scenario Decoder SYSTEM3")); -#endif - - g_hwnd = CreateWindow(_T("CWINDOW"), buf, - WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, - dest_x, dest_y, rect.right - rect.left, rect.bottom - rect.top, - NULL, NULL, g_hinst, NULL); - ShowWindow(g_hwnd, iCmdShow); - UpdateWindow(g_hwnd); - - // ƒ�ƒjƒ…�[•\ަ - show_menu_bar(g_hwnd); - - // MCI �‰Šú‰» - initialize_mci(); - - // system3 �‰Šú‰» - nact = new NACT(); - - _TCHAR title[128]; - if(nact->get_title(title, 128)) { -#if defined(_SYSTEM1) - _stprintf_s(buf, 128, _T("Scenario Decoder SYSTEM1 - %s"), title); -#elif defined(_SYSTEM2) - _stprintf_s(buf, 128, _T("Scenario Decoder SYSTEM2 - %s"), title); -#else - _stprintf_s(buf, 128, _T("Scenario Decoder SYSTEM3 - %s"), title); -#endif - SetWindowText(g_hwnd, buf); - } - - // ƒ�ƒCƒ“ƒ‹�[ƒv - MSG msg; - while(GetMessage(&msg,NULL,0,0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - // system3 ŠJ•ú - if(nact) { - delete nact; - } - - // MCI ŠJ•ú - release_mci(); - - // ƒtƒ‹ƒXƒNƒŠ�[ƒ“‚©‚畜‹A - if(fullscreen_now) { - ChangeDisplaySettings(NULL, 0); - } - -#ifdef _DEBUG - // ƒ�ƒ‚ƒŠƒŠ�[ƒNŒŸ�o - _CrtDumpMemoryLeaks(); -#endif - - return msg.wParam; -} - -LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) -{ - RECT rect; - HDC hdc; - PAINTSTRUCT ps; - - switch(iMsg) { - case WM_CLOSE: - if(g_hmenu != NULL && IsMenu(g_hmenu)) { - DestroyMenu(g_hmenu); - } - DestroyWindow(hWnd); - break; - - case WM_DESTROY: - PostQuitMessage(0); - break; - - case WM_PAINT: - if(GetUpdateRect(hWnd, &rect, TRUE)) { - hdc = BeginPaint(hWnd, &ps); - if(nact) { - nact->update_screen(hdc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); - } - EndPaint(hWnd, &ps); - } - return 0; - - case WM_ENTERMENULOOP: - menuloop_now = true; - break; - - case WM_EXITMENULOOP: - if(fullscreen_now && menuloop_now) { - hide_menu_bar(hWnd); - } - menuloop_now = false; - break; - - case WM_MOUSEMOVE: - if(fullscreen_now && !menuloop_now) { - POINTS p = MAKEPOINTS(lParam); - if(p.y == 0) { - show_menu_bar(hWnd); - } else if(p.y > 32) { - hide_menu_bar(hWnd); - } - } - break; - - case WM_LBUTTONDOWN: - if(nact) { - nact->key_down(VK_LBUTTON); - } - break; - - case WM_LBUTTONUP: - if(nact) { - nact->key_up(VK_LBUTTON); - } - break; - - case WM_RBUTTONDOWN: - if(nact) { - nact->key_down(VK_RBUTTON); - } - break; - - case WM_RBUTTONUP: - if(nact) { - nact->key_up(VK_RBUTTON); - } - break; - - case WM_KILLFOCUS: - if(nact) { - nact->key_up(-1); - } - break; - - case WM_KEYDOWN: - if(nact) { - uint8 code = LOBYTE(wParam); - nact->key_down(code); - } - break; - - case WM_KEYUP: - if(nact) { - uint8 code = LOBYTE(wParam); - nact->key_up(code); - } - break; - - case WM_SETCURSOR: - if(nact) { - nact->select_cursor(); - } - break; - - case MM_MCINOTIFY: - if(nact) { - if(wParam == MCI_NOTIFY_SUCCESSFUL) { - nact->notify_mci(0); - } else if(wParam == MCI_NOTIFY_FAILURE) { - nact->notify_mci(-1); - } - } - break; - - case WM_USER: - if(wParam) { - play_mci(hWnd, wParam); - } else { - stop_mci(); - } - break; - - case WM_USER + 2: -// if(fullscreen_now) { -// set_window(hWnd, FALSE); -// } - rect.left = rect.top = 0; - rect.right = 640; - rect.bottom = wParam; - AdjustWindowRectEx(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_VISIBLE, TRUE, 0); - SetWindowPos(hWnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER); - break; - - case WM_ACTIVATEAPP: - if(fullscreen_now) { - set_window(hWnd, FALSE); - } - break; - - case WM_INITMENUPOPUP: - if(LOWORD(lParam) == 1) { - EnableMenuItem((HMENU)wParam, ID_SCREEN_WINDOW, fullscreen_now ? MF_ENABLED : MF_GRAYED); - EnableMenuItem((HMENU)wParam, ID_SCREEN_FULL, fullscreen_now ? MF_GRAYED : MF_ENABLED); - } else if(LOWORD(lParam) == 3) { - if(nact) { - CheckMenuItem((HMENU)wParam, ID_TEXT_SKIP, nact->text_skip_enb ? MF_CHECKED : MF_UNCHECKED); - CheckMenuItem((HMENU)wParam, ID_TEXT_WAIT, nact->text_wait_enb ? MF_CHECKED : MF_UNCHECKED); - } - } - break; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case ID_RESTART: - // restart nact - if(nact) { - delete nact; - } - nact = new NACT(); - - // update screen - rect.left = rect.top = 0; - rect.right = 640; - rect.bottom = 480; - InvalidateRect(hWnd, &rect, FALSE); - UpdateWindow(g_hwnd); - break; - - case ID_EXIT: - SendMessage(hWnd, WM_CLOSE, 0, 0); - break; - - case ID_SCREEN_WINDOW: - if(fullscreen_now) { - set_window(hWnd, FALSE); - } - break; - - case ID_SCREEN_FULL: - if(!fullscreen_now) { - set_window(hWnd, TRUE); - } - break; - - case ID_SOUND_FM: - if(nact) { - nact->select_sound(0); - } - break; - - case ID_SOUND_CD: - if(nact) { - nact->select_sound(1); - } - break; - - case ID_TEXT_SKIP: - if(nact) { - nact->text_skip_enb = !nact->text_skip_enb; - } - break; - - case ID_TEXT_WAIT: - if(nact) { - nact->text_wait_enb = !nact->text_wait_enb; - } - break; - } - break; - } - return DefWindowProc(hWnd, iMsg, wParam, lParam) ; -} - -// ƒtƒ‹ƒXƒNƒŠ�[ƒ“ - -void set_window(HWND hWnd, BOOL full) -{ - static LONG style = WS_VISIBLE; - static int dest_x = 0, dest_y = 0; - WINDOWPLACEMENT place; - place.length = sizeof(WINDOWPLACEMENT); - - if(full && !fullscreen_now) { - // ƒtƒ‹ƒXƒNƒŠ�[ƒ“‚ɈÚ�s - DEVMODE dev; - HDC hdc = GetDC(NULL); - ZeroMemory(&dev, sizeof(dev)); - dev.dmSize = sizeof(dev); - dev.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; - dev.dmBitsPerPel = GetDeviceCaps(hdc, BITSPIXEL); - dev.dmPelsWidth = 640; - dev.dmPelsHeight = 480; - ReleaseDC(NULL, hdc); - - if(ChangeDisplaySettings(&dev, CDS_TEST) == DISP_CHANGE_SUCCESSFUL) { - GetWindowPlacement(hWnd, &place); - dest_x = place.rcNormalPosition.left; - dest_y = place.rcNormalPosition.top; - ChangeDisplaySettings(&dev, CDS_FULLSCREEN); - style = GetWindowLong(hWnd, GWL_STYLE); - SetWindowLong(hWnd, GWL_STYLE, WS_VISIBLE); - SetWindowPos(hWnd, HWND_TOP, 0, 0, 640, 480, SWP_SHOWWINDOW); - SetCursorPos(320, 200); - fullscreen_now = TRUE; - hide_menu_bar(hWnd); - } - } else if(!full && fullscreen_now) { - // ƒtƒ‹ƒXƒNƒŠ�[ƒ“‚©‚畜‹A - RECT rect = {0, 0, 640, nact ? nact->get_screen_height() : 400}; -// if(nact) { -// rect.bottom = nact->get_screen_height(); -// } - AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, TRUE); - ChangeDisplaySettings(NULL, 0); - SetWindowLong(hWnd, GWL_STYLE, style); - SetWindowPos(hWnd, HWND_TOP, dest_x, dest_y, rect.right - rect.left, rect.bottom - rect.top, SWP_SHOWWINDOW); - fullscreen_now = FALSE; - show_menu_bar(g_hwnd); - } -} - -void show_menu_bar(HWND hWnd) -{ - if(!(g_hmenu != NULL && IsMenu(g_hmenu))) { - g_hmenu = LoadMenu((HINSTANCE)GetModuleHandle(0), MAKEINTRESOURCE(IDR_MENU1)); - SetMenu(hWnd, g_hmenu); - } -} - -void hide_menu_bar(HWND hWnd) -{ - if(g_hmenu != NULL && IsMenu(g_hmenu)) { - SetMenu(hWnd, NULL); - DestroyMenu(g_hmenu); - g_hmenu = NULL; - } -} - -// MCIƒfƒoƒCƒX - -void initialize_mci() -{ - mciSendString(_T("open cdaudio"), NULL, 0, NULL); - mciSendString(_T("set cdaudio time format tmsf"), NULL, 0, NULL); - mciSendString(_T("set cdaudio audio all on"), NULL, 0, NULL); - mciSendString(_T("stop cdaudio"), NULL, 0, NULL); -} - -void release_mci() -{ - mciSendString(_T("stop cdaudio"), NULL, 0, NULL); - mciSendString(_T("close cdaudio"), NULL, 0, NULL); -} - -void play_mci(HWND hWnd, int index) -{ - _TCHAR string[_MAX_PATH]; - - _stprintf_s(string, _MAX_PATH, _T("play cdaudio from %d to %d notify"), index, index + 1); - mciSendString(string, NULL, 0, hWnd); -} - -void stop_mci() -{ - mciSendString(_T("stop cdaudio"), NULL, 0, NULL); -} -