/* --------------------------------------- 关闭通讯接口 --------------------------------------- */ static bool_t qst_com_close ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { sQstComm* ctx; CR_NOUSE(argc); CR_NOUSE(argv); ctx = (sQstComm*)parm; if (ctx->comm.thrd == NULL) return (FALSE); ctx->comm.quit = TRUE; thread_wait(ctx->comm.thrd); thread_del(ctx->comm.thrd); ctx->comm.thrd = NULL; ctx->comm.quit = FALSE; SAFE_FREE(ctx->comm.title); qst_update_title(ctx); CR_VCALL(ctx->bufs)->reput(ctx->bufs, 0); ctx->size = 0; return (TRUE); }
/* --------------------------------------- 保存窗口位置 --------------------------------------- */ static bool_t qst_com_win_save ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { RECT win; sQstComm* ctx; CR_NOUSE(argc); CR_NOUSE(argv); /* 获取窗口位置 */ ctx = (sQstComm*)parm; if (!GetWindowRect(ctx->hwnd, &win)) return (FALSE); sint_t x1 = win.left; sint_t y1 = win.top; uint_t ww = win.right - win.left; uint_t hh = win.bottom - win.top; /* 保存窗口位置 */ return (misc_desk_save(WIN_ICONF, x1, y1, ww, hh)); }
/* --------------------------------------- 加载窗口位置 --------------------------------------- */ static bool_t qst_com_win_load ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { sint_t x1, y1; uint_t ww, hh; CR_NOUSE(argc); CR_NOUSE(argv); /* 保存窗口位置 */ if (!misc_desk_load(WIN_ICONF, &x1, &y1, &ww, &hh)) return (FALSE); sQstComm* ctx; /* 设置窗口位置 */ ctx = (sQstComm*)parm; misc_bring2top(ctx->hwnd, NULL); return (SetWindowPos(ctx->hwnd, HWND_TOP, (int)x1, (int)y1, (int)ww, (int)hh, SWP_SHOWWINDOW)); }
/* ======================================= WinMain 程序入口 ======================================= */ int WINAPI WinMain ( __CR_IN__ HINSTANCE curt_app, __CR_IN__ HINSTANCE prev_app, __CR_IN__ LPSTR cmd_line, __CR_IN__ int cmd_show ) { uint_t argc; ansi_t** argv; CR_NOUSE(curt_app); CR_NOUSE(prev_app); CR_NOUSE(cmd_show); /* 只允许一个例程 */ if (misc_is_running(EXE_XNAME)) return (QST_ERROR); /* 建立 CrHack 系统 */ if (!set_app_type(CR_APP_GUI)) return (QST_ERROR); /* 获取命令行参数, 不包括进程文件名 */ argv = misc_get_param(cmd_line, &argc); /* 参数解析 <网页文件> */ if (argc < 1) return (QST_ERROR); g_html = argv[0]; /* 标准 VCL 过程开始 */ try { Application->Initialize(); Application->Title = WIN_TITLE; Application->CreateForm(__classid(TfrmMain), &frmMain); Application->Run(); } catch (Exception &exception) { Application->ShowException(&exception); } catch (...) { try { throw Exception(""); } catch (Exception &exception) { Application->ShowException(&exception); } } return (QST_OKAY); }
/* --------------------------------------- 离屏表面使用的空函数 --------------------------------------- */ static bool_t iGFX2_DX8S_flip ( __CR_IN__ iGFX2* that, __CR_IN__ bool_t sync ) { CR_NOUSE(that); CR_NOUSE(sync); return (FALSE); }
/* --------------------------------------- 获取视频大小 --------------------------------------- */ static bool_t iXMM_FMOD_video_size ( __CR_IN__ iXMMEDIA* that, __CR_OT__ uint_t* width, __CR_OT__ uint_t* height ) { CR_NOUSE(that); CR_NOUSE(width); CR_NOUSE(height); return (FALSE); }
/* --------------------------------------- 设置视频窗口 --------------------------------------- */ static bool_t iXMM_FMOD_video_setwin ( __CR_IO__ iXMMEDIA* that, __CR_IN__ hwnd_t hwnd, __CR_IN__ bool_t full ) { CR_NOUSE(that); CR_NOUSE(hwnd); CR_NOUSE(full); return (FALSE); }
/* --------------------------------------- 设置后台调色板 --------------------------------------- */ static bool_t iGFX2_FB_setPal ( __CR_IN__ iGFX2* that, __CR_IN__ uint_t start, __CR_IN__ uint_t count ) { /* 不支持 */ CR_NOUSE(that); CR_NOUSE(start); CR_NOUSE(count); return (FALSE); }
/* ======================================= 打开目录对话框回调 ======================================= */ int CALLBACK BrowseCallbackProc ( __CR_IN__ HWND hwnd, __CR_IN__ UINT message, __CR_IN__ LPARAM lparam, __CR_IN__ LPARAM pdata ) { CR_NOUSE(pdata); CR_NOUSE(lparam); if (message == BFFM_INITIALIZED) SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)g_root); return (0); }
/* --------------------------------------- 显示窗口位置 --------------------------------------- */ static bool_t qst_com_win_show ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { sQstComm* ctx; CR_NOUSE(argc); CR_NOUSE(argv); ctx = (sQstComm*)parm; misc_bring2top(ctx->hwnd, NULL); return (TRUE); }
/* --------------------------------------- 解锁后台缓冲 --------------------------------------- */ static void_t iGFX2_FB_unlock ( __CR_IN__ iGFX2* that ) { CR_NOUSE(that); }
/* --------------------------------------- 是否是视频 --------------------------------------- */ static bool_t iXMM_FMOD_is_video ( __CR_IN__ iXMMEDIA* that ) { CR_NOUSE(that); return (FALSE); }
/* ======================================= FlsAlloc ======================================= */ unsigned long __stdcall myFlsAlloc ( __CR_IN__ void* lpCallback ) { CR_NOUSE(lpCallback); return (TlsAlloc()); }
/* --------------------------------------- 引擎插件释放回调 --------------------------------------- */ static void_t engine_fmodex_free ( __CR_IO__ sENGINE* engine ) { fmodex_kill(); CR_NOUSE(engine); }
/* ======================================= 获取绘图插件接口 (同名) ======================================= */ CR_API iGFX2* create_canvas ( __CR_IN__ void_t* handle, __CR_IN__ uint_t scn_cw, __CR_IN__ uint_t scn_ch, __CR_IN__ uint_t scn_fmt, __CR_IN__ bool_t full, __CR_IN__ const int32u* param, __CR_IN__ uint_t count ) { CR_NOUSE(param); CR_NOUSE(count); CR_NOUSE(scn_fmt); return ((iGFX2*)create_dx8_canvas((sDX8_HDLE*)handle, scn_cw, scn_ch, full)); }
/* --------------------------------------- 加载配置文件 --------------------------------------- */ static bool_t qst_com_cfg_load ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { sQstComm* ctx; CR_NOUSE(argc); CR_NOUSE(argv); ctx = (sQstComm*)parm; qst_load_cfg(&ctx->cfgs); qst_set_viewer(ctx); return (TRUE); }
/* --------------------------------------- 离屏表面使用的空函数 --------------------------------------- */ static bool_t iGFX2_DX8S_reset ( __CR_IN__ iGFX2* that ) { CR_NOUSE(that); return (FALSE); }
/* ======================================= SZ20 文件读取 ======================================= */ CR_API sFMT_DAT* load_ms_sz20 ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { leng_t pksz; leng_t unsz; void_t* data; void_t* temp; sFMT_DAT* rett; sSZ20_HDR head; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sSZ20_HDR))) return (NULL); if (mem_cmp(head.tag, "SZ\x20\x88\xF0\x27\x33\xD1", 8) != 0) return (NULL); /* 读取所有后续数据 */ temp = CR_VCALL(datin)->get(datin, &pksz, FALSE); if (temp == NULL) return (NULL); /* 分配目标数据缓冲 */ head.unsize = DWORD_LE(head.unsize); data = mem_malloc32(head.unsize); if (data == NULL) { mem_free(temp); return (NULL); } unsz = (leng_t)(head.unsize); pksz = uncompr_lzss(data, unsz, temp, pksz, 0x20); mem_free(temp); if (pksz != unsz) goto _failure; /* 返回读取的文件数据 */ rett = struct_new(sFMT_DAT); if (rett == NULL) goto _failure; CR_NOUSE(param); rett->type = CR_FMTZ_DEC; rett->unsz = unsz; rett->pksz = dati_get_size(datin); rett->data = data; rett->infor = "Microsoft Compressed (SZ20) file"; return (rett); _failure: mem_free(data); return (NULL); }
/* --------------------------------------- 锁住后台缓冲 --------------------------------------- */ static sIMAGE* iGFX2_DX8M_lock ( __CR_IN__ iGFX2* that ) { /* 不支持 */ CR_NOUSE(that); return (NULL); }
/* ======================================= LCMapStringEx ======================================= */ int __stdcall myLCMapStringEx ( __CR_IN__ void* lpLocaleName, __CR_IN__ unsigned long dwMapFlags, __CR_IN__ void* lpSrcStr, __CR_IN__ int cchSrc, __CR_IN__ void* lpDestStr, __CR_IN__ int cchDest, __CR_IN__ void* lpVersionInformation, __CR_IN__ void* lpReserved, __CR_IN__ unsigned long sortHandle ) { CR_NOUSE(lpVersionInformation); CR_NOUSE(lpReserved); CR_NOUSE(sortHandle); return (LCMapStringW(myLocaleNameToLCID(lpLocaleName), dwMapFlags, lpSrcStr, cchSrc, lpDestStr, cchDest)); }
/* --------------------------------------- 改变屏幕大小 --------------------------------------- */ static bool_t iGFX2_FB_reset ( __CR_IN__ iGFX2* that ) { /* 不支持 */ CR_NOUSE(that); return (FALSE); }
/* ======================================= TGL IEL1 文件读取 ======================================= */ CR_API sFMT_DAT* load_tgl_iel1 ( __CR_IO__ iDATIN* datin, __CR_IN__ const sLOADER* param ) { leng_t pksz; leng_t unsz; void_t* data; void_t* temp; sFMT_DAT* rett; sIEL1_HDR head; /* 这个参数可能为空 */ if (datin == NULL) return (NULL); /* 读取 & 检查头部 */ if (!(CR_VCALL(datin)->geType(datin, &head, sIEL1_HDR))) return (NULL); if (head.magic != mk_tag4("IEL1")) return (NULL); /* 读取所有后续数据 */ temp = CR_VCALL(datin)->get(datin, &pksz, FALSE); if (temp == NULL) return (NULL); /* 分配目标数据缓冲 */ head.unsize = DWORD_LE(head.unsize); data = mem_malloc32(head.unsize); if (data == NULL) { mem_free(temp); return (NULL); } unsz = (leng_t)(head.unsize); pksz = uncompr_lzss(data, unsz, temp, pksz, 0); mem_free(temp); if (pksz != unsz) goto _failure; /* 返回读取的文件数据 */ rett = struct_new(sFMT_DAT); if (rett == NULL) goto _failure; CR_NOUSE(param); rett->type = CR_FMTZ_DEC; rett->unsz = unsz; rett->pksz = dati_get_size(datin); rett->data = data; rett->infor = "TGL LZSS Compressed file (IEL1)"; return (rett); _failure: mem_free(data); return (NULL); }
/* ======================================= DLL 入口点 ======================================= */ BOOL WINAPI DllMain ( __CR_IN__ HANDLE hinst, __CR_IN__ DWORD reason, __CR_UU__ LPVOID reserved ) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; } CR_NOUSE(hinst); CR_NOUSE(reserved); return (TRUE); }
/* --------------------------------------- 清除回调 --------------------------------------- */ static void_t tex_fill ( __CR_OT__ D3DXVECTOR4* pOut, __CR_IN__ D3DXVECTOR2* pTexCoord, __CR_IN__ D3DXVECTOR2* pTexelSize, __CR_IN__ LPVOID pData ) { D3DXVECTOR4* fill; CR_NOUSE(pTexCoord); CR_NOUSE(pTexelSize); fill = (D3DXVECTOR4*)pData; pOut->x = fill->x; pOut->y = fill->y; pOut->z = fill->z; pOut->w = fill->w; }
/* --------------------------------------- 创建文字绘制对象 (GDI 字体) --------------------------------------- */ static bool_t qst_crh_winfont ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { leng_t len; LOGFONTA font; CR_NOUSE(parm); /* 参数解析 <Height> <FaceName> [Weight] [Width] [CharSet] [Quality] [Italic] [Underline] [StrikeOut] [Escapement] [Orientation] */ if (argc < 3) return (FALSE); if (s_gdi_calls == NULL) return (FALSE); /* 填充字体生成结构 */ struct_zero(&font, LOGFONTA); font.lfCharSet = DEFAULT_CHARSET; font.lfQuality = ANTIALIASED_QUALITY; font.lfHeight = (LONG)str2intxA(argv[1]); if ((len = str_lenA(argv[2])) >= LF_FACESIZE) len = LF_FACESIZE - 1; chr_cpyA(font.lfFaceName, argv[2], len); if (argc > 3) font.lfWeight = (LONG)str2intxA(argv[3]); if (argc > 4) font.lfWidth = (LONG)str2intxA(argv[4]); if (argc > 5) font.lfCharSet = (BYTE)str2intxA(argv[5]); if (argc > 6) font.lfQuality = (BYTE)str2intxA(argv[6]); if (argc > 7) font.lfItalic = (BYTE)str2intxA(argv[7]); if (argc > 8) font.lfUnderline = (BYTE)str2intxA(argv[8]); if (argc > 9) font.lfStrikeOut = (BYTE)str2intxA(argv[9]); if (argc > 10) font.lfEscapement = (LONG)str2intxA(argv[10]); if (argc > 11) font.lfOrientation = (LONG)str2intxA(argv[11]); /* 生成文字输出对象 */ if (s_font != NULL) CR_VCALL(s_font)->release(s_font); s_font = s_gdi_calls->create_fontA(&font); if (s_font == NULL) return (FALSE); return (TRUE); }
/* ======================================= 串口发送字符串 ======================================= */ CR_API sint_t fputc ( __CR_IN__ sint_t ch, __CR_IN__ FILE* fp ) { CR_NOUSE(fp); while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); USART_SendData(USART1, (byte_t)ch); return (ch); }
/* --------------------------------------- 显示后台缓冲 --------------------------------------- */ static bool_t iGFX2_FB_flip ( __CR_IN__ iGFX2* that, __CR_IN__ bool_t sync ) { iGFX2_FB* real = (iGFX2_FB*)that; CR_NOUSE(sync); mem_cpy(real->m_main, real->__back__.data, real->m_size); return (TRUE); }
/* --------------------------------------- 标准32位色转8888 --------------------------------------- */ extern cpix_t pixel_cnvt32 ( __CR_IN__ const int32u* pal, __CR_IN__ cl32_t color ) { cpix_t cnvt; CR_NOUSE(pal); cnvt.val = color; return (cnvt); }
/* --------------------------------------- 清除通讯内容 --------------------------------------- */ static bool_t qst_com_clear ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { sQstComm* ctx; CTextOper* opr; CR_NOUSE(argc); CR_NOUSE(argv); ctx = (sQstComm*)parm; opr = (CTextOper*)ctx->oper; _ENTER_COM_SINGLE_ opr->clear(); _LEAVE_COM_SINGLE_ return (TRUE); }
/* --------------------------------------- 创建文字绘制对象 (UCDOS 点阵) --------------------------------------- */ static bool_t qst_crh_ucfont ( __CR_IN__ void_t* parm, __CR_IN__ uint_t argc, __CR_IN__ ansi_t** argv ) { iDATIN* asc; iDATIN* hzk; iDATIN* chr; ansi_t name[MAX_PATHA]; uint_t size, xspc, yspc; CR_NOUSE(parm); /* 参数解析 <Size> <XSpace> <YSpace> [Suffix] */ if (argc < 4) return (FALSE); /* 加载点阵字库文件 */ size = str2intxA(argv[1]); if (argc == 4) { sprintf(name, QST_PATH_SOURCE "ucfont\\HZK%u", size); } else { sprintf(name, QST_PATH_SOURCE "ucfont\\HZK%u%c", size, (argv[4])[0]); } hzk = create_disk_inA(name); if (hzk == NULL) return (FALSE); sprintf(name, QST_PATH_SOURCE "ucfont\\ASC%u", size); asc = create_disk_inA(name); sprintf(name, QST_PATH_SOURCE "ucfont\\HZK%uT", size); chr = create_disk_inA(name); /* 创建 UCDOS 点阵汉字绘制对象 */ xspc = str2intxA(argv[2]); yspc = str2intxA(argv[3]); if (s_font != NULL) CR_VCALL(s_font)->release(s_font); s_font = create_ucdos_font(asc, hzk, chr, size, xspc, yspc); if (s_font == NULL) { CR_VCALL(hzk)->release(hzk); if (asc != NULL) CR_VCALL(asc)->release(asc); if (chr != NULL) CR_VCALL(chr)->release(chr); return (FALSE); } return (TRUE); }