From 42f780a7291397f05db23c70a445a256d2a1fddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=A1k?= Date: Sun, 26 Jan 2025 21:36:03 +0100 Subject: [PATCH] trying to debug, additional rewrites --- AdvMan/MainFrm.cpp | 144 ++++++++--------- game/CMakeLists.txt | 22 ++- game/automap.c | 11 +- game/builder.c | 29 +++- game/chargen.c | 24 +-- game/clk_map.c | 2 +- game/default_font.h | 5 + game/default_font.in.cpp | 14 ++ game/default_font_to_cpp.cmake | 4 + game/dialogy.c | 8 +- game/encrypt.c | 3 +- game/enemy.c | 2 +- game/engine1.c | 44 ++++- game/engine1.h | 2 +- game/engine2.c | 14 +- game/gamesave.c | 26 ++- game/globals.h | 10 +- game/globmap.c | 11 +- game/interfac.c | 132 ++++++++------- game/inv.c | 39 +++-- game/kniha.c | 120 ++++++++------ game/kouzla.c | 2 +- game/macros.c | 4 +- game/menu.c | 27 ++-- game/realgame.c | 59 +++---- game/setup.c | 2 +- game/skeldal.c | 66 ++++---- game/sndandmus.c | 2 +- game/souboje.c | 5 +- game/specproc.c | 4 +- game/temp_storage.cpp | 39 +++++ game/temp_storage.h | 11 ++ game/wizard.c | 2 +- libs/CMakeLists.txt | 2 +- libs/advinst.c | 2 +- libs/base64.h | 174 ++++++++++++++++++++ libs/basicobj.c | 68 ++++---- libs/bgraph.h | 18 +-- libs/bgraph2.c | 14 +- libs/bgraph2a.c | 16 +- libs/bgraph2a.cpp | 2 +- libs/bmouse.c | 2 +- libs/cspells.c | 14 +- libs/devices.c | 2 +- libs/devices.h | 14 +- libs/event.c | 2 +- libs/gui.c | 13 +- libs/inicfg.c | 4 +- libs/memman.c | 2 +- libs/mgfplay.c | 2 +- libs/mgifmapmem.c | 3 +- libs/mgifmem.c | 2 +- libs/mgifplaya.c | 2 +- libs/mouse.h | 24 +++ libs/pcx.c | 2 +- libs/readfont.c | 6 +- libs/strlists.c | 8 +- libs/strlite.c | 4 +- libs/types.h | 11 +- libs/wav.c | 2 +- libs/zvuk.c | 5 +- libs/zvuk.h | 1 - libs/zvuk_dx.cpp | 2 +- platform/CMakeLists.txt | 5 +- platform/int2ascii.c | 30 ++++ platform/istr.c | 23 +++ platform/linux/CMakeLists.txt | 2 + platform/linux/map_file.cpp | 59 +++++++ platform/linux/map_file.h | 4 + platform/linux/timer.cpp | 18 +++ platform/linux/timer.h | 28 ++++ platform/platform.cpp | 7 + platform/{skeldal_win.h => platform.h} | 26 +-- platform/sdl/BGraph2.cpp | 112 +++++++++++++ platform/{BGraph2Dx.h => sdl/BGraph2.h} | 21 ++- platform/sdl/CMakeLists.txt | 2 + platform/sdl/global_context.h | 11 ++ platform/sdl/input.cpp | 28 ++++ platform/sdl/input.h | 31 ++++ platform/sdl/sdl_context.cpp | 186 ++++++++++++++++++++++ platform/sdl/sdl_context.h | 55 +++++++ platform/sdl/sound.cpp | 78 +++++++++ platform/sdl/sound.h | 15 ++ platform/sdl/tests/CMakeLists.txt | 4 +- platform/sdl/tests/sdl_mouse.cpp | 79 +++++++++ platform/sdl/tests/sdl_surface_test.cpp | 73 ++++++--- platform/sdl/tests/sdl_update_texture.cpp | 91 +++++++++++ 87 files changed, 1771 insertions(+), 529 deletions(-) create mode 100644 game/default_font.h create mode 100644 game/default_font.in.cpp create mode 100644 game/default_font_to_cpp.cmake create mode 100644 libs/base64.h create mode 100644 libs/mouse.h create mode 100644 platform/int2ascii.c create mode 100644 platform/istr.c create mode 100644 platform/linux/CMakeLists.txt create mode 100644 platform/linux/map_file.cpp create mode 100644 platform/linux/map_file.h create mode 100644 platform/linux/timer.cpp create mode 100644 platform/linux/timer.h create mode 100644 platform/platform.cpp rename platform/{skeldal_win.h => platform.h} (75%) create mode 100644 platform/sdl/BGraph2.cpp rename platform/{BGraph2Dx.h => sdl/BGraph2.h} (78%) create mode 100644 platform/sdl/global_context.h create mode 100644 platform/sdl/input.cpp create mode 100644 platform/sdl/input.h create mode 100644 platform/sdl/sdl_context.cpp create mode 100644 platform/sdl/sdl_context.h create mode 100644 platform/sdl/sound.cpp create mode 100644 platform/sdl/sound.h create mode 100644 platform/sdl/tests/sdl_mouse.cpp create mode 100644 platform/sdl/tests/sdl_update_texture.cpp diff --git a/AdvMan/MainFrm.cpp b/AdvMan/MainFrm.cpp index 9cdacb8..b0743b6 100644 --- a/AdvMan/MainFrm.cpp +++ b/AdvMan/MainFrm.cpp @@ -67,7 +67,7 @@ static UINT indicators[] = CMainFrame::CMainFrame() { // TODO: add member initialization code here - + } CMainFrame::~CMainFrame() @@ -85,7 +85,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) TRACE0("Failed to create view window\n"); return -1; } - + if (!m_wndToolBar.CreateEx(this, TBSTYLE_BUTTON, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY |BTNS_AUTOSIZE | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) @@ -132,14 +132,14 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) CRect rc; GetClientRect(&rc); ClientToScreen(&rc); - DockControlBar(&m_wndEditoryBar,(UINT)0,CRect(rc.left+180,rc.top+5,rc.left+180,rc.top+5)); - DockControlBar(&m_wndPrekladaceBar,(UINT)0,CRect(rc.left+350,rc.top+5,rc.left+350,rc.top+5)); + DockControlBar(&m_wndEditoryBar,(UINT)0,CRect(rc.left+180,rc.top+5,rc.left+180,rc.top+5)); + DockControlBar(&m_wndPrekladaceBar,(UINT)0,CRect(rc.left+350,rc.top+5,rc.left+350,rc.top+5)); _adv=0; CString untitled; untitled.LoadString(IDS_UNTITLED); - SetTitle(untitled); - + SetTitle(untitled); + SetClassLong(*this,GCL_HICON,(LONG)(theApp.LoadIcon(IDR_MAINFRAME))); return 0; @@ -192,7 +192,7 @@ BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* } -void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) +void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { if (_adv==0) { @@ -205,7 +205,7 @@ void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) } } else - CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); + CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); } #include "DlgNoveDobr.h" @@ -227,7 +227,7 @@ static str_add_wildcard(TSTR_LIST *lst, const char *mask) } } -void CMainFrame::OnFileNovdobrodrust() +void CMainFrame::OnFileNovdobrodrust() { DlgNoveDobr dlg; int id=dlg.DoModal(); @@ -247,29 +247,29 @@ void CMainFrame::OnFileNovdobrodrust() switch (dlg.vOrganizace) { case 0: - cestaGrafika=baseMap+_T("GRFSTENY\\"); - cestaDialogy=baseMap+_T("GRFDIALG\\"); - cestaEnemy=baseMap+_T("GRFENEMY\\"); - cestaItemy=baseMap+_T("GRFITEMS\\"); - cestaPozice=baseMap+_T("SAVEGAME\\"); - cestaZvuky=baseMap+_T("SOUNDS\\"); - cestaBasicGr=baseMap+_T("GRFBASIC\\"); + cestaGrafika=baseMap+_T("GRFSTENY" PATH_SEPARATOR); + cestaDialogy=baseMap+_T("GRFDIALG" PATH_SEPARATOR); + cestaEnemy=baseMap+_T("GRFENEMY" PATH_SEPARATOR); + cestaItemy=baseMap+_T("GRFITEMS" PATH_SEPARATOR); + cestaPozice=baseMap+_T("SAVEGAME" PATH_SEPARATOR); + cestaZvuky=baseMap+_T("SOUNDS" PATH_SEPARATOR); + cestaBasicGr=baseMap+_T("GRFBASIC" PATH_SEPARATOR); break; case 1: - cestaGrafika=baseMap+_T("graphics\\"); - cestaDialogy=baseMap+_T("graphics\\dialogs\\"); - cestaEnemy=baseMap+_T("graphics\\enemies\\"); - cestaItemy=baseMap+_T("graphics\\items\\"); - cestaPozice=baseMap+_T("SAVEGAME\\"); - cestaZvuky=baseMap+_T("SAMPLES\\"); - cestaBasicGr=baseMap+_T("graphics\\basic\\"); + cestaGrafika=baseMap+_T("graphics" PATH_SEPARATOR); + cestaDialogy=baseMap+_T("graphics" PATH_SEPARATOR "dialogs" PATH_SEPARATOR); + cestaEnemy=baseMap+_T("graphics" PATH_SEPARATOR "enemies" PATH_SEPARATOR); + cestaItemy=baseMap+_T("graphics" PATH_SEPARATOR "items"); + cestaPozice=baseMap+_T("SAVEGAME" PATH_SEPARATOR ); + cestaZvuky=baseMap+_T("SAMPLES" PATH_SEPARATOR); + cestaBasicGr=baseMap+_T("graphics" PATH_SEPARATOR "basic" PATH_SEPARATOR); break; case 2: cestaGrafika=baseMap; cestaDialogy=baseMap; cestaEnemy=baseMap; cestaItemy=baseMap; - cestaPozice=baseMap+_T("SAVEGAME\\"); + cestaPozice=baseMap+_T("SAVEGAME" PATH_SEPARATOR); cestaZvuky=baseMap; cestaBasicGr=baseMap; break; @@ -282,7 +282,7 @@ void CMainFrame::OnFileNovdobrodrust() add_field_txt(&_adv,_T("CESTA_POZICE"),cestaPozice); add_field_txt(&_adv,_T("CESTA_ZVUKY"),cestaZvuky); add_field_txt(&_adv,_T("CESTA_BGRAFIKA"),cestaBasicGr); - + add_field_txt(&_adv,_T("DEFAULT_MAP"),dlg.vStartMap); add_field_num(&_adv,_T("CHAR_MIN"),dlg.vMinPostav); add_field_num(&_adv,_T("CHAR_MAX"),dlg.vMaxPostav); @@ -298,7 +298,7 @@ void CMainFrame::OnFileNovdobrodrust() _advPath=pth.GetDirectoryWithDrive(); SetTitle(pth); - + Pathname exePath=Pathname::GetExePath(); @@ -310,7 +310,7 @@ void CMainFrame::OnFileNovdobrodrust() pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaPozice); pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaZvuky); pth.CreateFolder(exePath.GetDirectoryWithDrive()+cestaBasicGr); - + CString basePath=pth.GetDirectoryWithDrive(); TSTR_LIST fileList=create_list(10); @@ -379,11 +379,11 @@ void CMainFrame::OnFileNovdobrodrust() oper.pFrom=buffer; oper.pTo=target; oper.fFlags=0; - SHFileOperation(&oper); + SHFileOperation(&oper); release_list(fileList); _baseMapPath=_advPath+baseMap; - + CFileFind fnd; BOOL f=fnd.FindFile(_baseMapPath+"*.*"); while (f) @@ -396,7 +396,7 @@ void CMainFrame::OnFileNovdobrodrust() } } -void CMainFrame::OnFileNatidobrodrustv() +void CMainFrame::OnFileNatidobrodrustv() { CString filter; filter.LoadString(IDS_ADVFILTER); @@ -429,31 +429,31 @@ void CMainFrame::SetTitle(const _TCHAR *name) SetWindowText(title); } -void CMainFrame::OnEditoryKouzlatab() +void CMainFrame::OnEditoryKouzlatab() { - OpenEditor(_baseMapPath+"KOUZLA.TAB"); + OpenEditor(_baseMapPath+"KOUZLA.TAB"); } -void CMainFrame::OnEditoryPostavytab() +void CMainFrame::OnEditoryPostavytab() { - OpenEditor(_baseMapPath+"POSTAVY.TAB"); + OpenEditor(_baseMapPath+"POSTAVY.TAB"); } -void CMainFrame::OnEditoryItemsscr() +void CMainFrame::OnEditoryItemsscr() { - OpenEditor(_baseMapPath+"ITEMS.SCR"); + OpenEditor(_baseMapPath+"ITEMS.SCR"); } -void CMainFrame::OnEditoryItemspic() +void CMainFrame::OnEditoryItemspic() { - OpenEditor(_baseMapPath+"ITEMS.PIC"); + OpenEditor(_baseMapPath+"ITEMS.PIC"); } -void CMainFrame::OnEditoryWeaponsscr() +void CMainFrame::OnEditoryWeaponsscr() { - OpenEditor(_baseMapPath+"WEAPONS.SCR"); + OpenEditor(_baseMapPath+"WEAPONS.SCR"); } static BOOL CALLBACK BroadcastMsgCallback(HWND wnd, LPARAM lParam) @@ -489,20 +489,20 @@ void CMainFrame::OpenEditor(const char *name) } } -void CMainFrame::OnDestroy() +void CMainFrame::OnDestroy() { SaveBarState("MainFrame"); CFrameWnd::OnDestroy(); - + BroadcastMessage(MSG_CLOSEEDITOR,0,0); release_list(_adv); _adv=0; - + } void CMainFrame::StartApp(const char *appname, CString cmdline, bool wait, const char *folder) -{ +{ SaveAll(); STARTUPINFO nfo; memset(&nfo,0,sizeof(nfo)); @@ -539,7 +539,7 @@ void CMainFrame::StartApp(const char *appname, CString cmdline, bool wait, const { CloseHandle(pi.hThread); if (wait) - { + { int rep=10; bool end; do @@ -554,7 +554,7 @@ void CMainFrame::StartApp(const char *appname, CString cmdline, bool wait, const if (readed==0) break; int cnt=m_wndView.GetWindowTextLength(); if (cnt>20000) - { + { m_wndView.SetSel(0,10000); m_wndView.ReplaceSel(""); cnt=m_wndView.GetWindowTextLength(); @@ -565,16 +565,16 @@ void CMainFrame::StartApp(const char *appname, CString cmdline, bool wait, const m_wndView.ReplaceSel(buff); PeekNamedPipe(pipe,0,0,0,&datalen,0); rep=10; - } + } UpdateWindow(); end=WaitForSingleObject(pi.hProcess,200)==WAIT_TIMEOUT; rep--; } while (rep>0 || end); } - CloseHandle(pi.hProcess); + CloseHandle(pi.hProcess); } - if (wait) + if (wait) { CloseHandle(pipe); CloseHandle(nfo.hStdOutput); @@ -582,55 +582,55 @@ void CMainFrame::StartApp(const char *appname, CString cmdline, bool wait, const SetForegroundWindow(); } -void CMainFrame::OnPekladaePelokouzla() +void CMainFrame::OnPekladaePelokouzla() { CString cmdline=_T("\"")+_baseMapPath+_T("KOUZLA.TAB")+_T("\""); Pathname apppath=Pathname::GetExePath(); - CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\CSPELLS.EXE")); + CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\CSPELLS.EXE")); StartApp(appname,cmdline,true,_baseMapPath); } -void CMainFrame::OnPekladaePelodialogy() +void CMainFrame::OnPekladaePelodialogy() { CString cmdline=_T("\"")+_baseMapPath+_T("DIALOGY.DLG")+_T("\""); Pathname apppath=Pathname::GetExePath(); - CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\CDIALOGY.EXE")); + CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\CDIALOGY.EXE")); StartApp(appname,cmdline,true,_baseMapPath); - + } -void CMainFrame::OnPekladaePelopostavytab() +void CMainFrame::OnPekladaePelopostavytab() { CString cmdline=_T("\"")+_baseMapPath+_T("POSTAVY.TAB\" \"")+_baseMapPath+_T("POSTAVY.DAT")+_T("\""); Pathname apppath=Pathname::GetExePath(); - CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\Lex_Lib.exe")); + CString appname=apppath.GetDirectoryWithDrive()+CString(_T("AdvManData\\Lex_Lib.exe")); StartApp(appname,cmdline,true,_baseMapPath); } -void CMainFrame::OnNstrojeMapedit() +void CMainFrame::OnNstrojeMapedit() { Pathname apppath=Pathname::GetExePath(); apppath.SetFilename(_T("MapEdit.exe")); - StartApp(apppath,CString(_T("\""))+_advName+_T("\""),false); + StartApp(apppath,CString(_T("\""))+_advName+_T("\""),false); } -void CMainFrame::OnNstrojeTestujdobrodrustv() +void CMainFrame::OnNstrojeTestujdobrodrustv() { Pathname apppath=Pathname::GetExePath(); apppath.SetFilename(_T("Skeldal.exe")); - StartApp(apppath,CString(_T("\""))+_advName+_T("\""),false); + StartApp(apppath,CString(_T("\""))+_advName+_T("\""),false); } -void CMainFrame::OnNstrojeTvrcepodlah() +void CMainFrame::OnNstrojeTvrcepodlah() { Pathname apppath=Pathname::GetExePath(); apppath.SetFilename(_T("AdvManData\\Podlahar.exe")); - StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_GRAFIKA")); - + StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_GRAFIKA")); + } -void CMainFrame::OnNstrojeTvrcepaletpronestvry() +void CMainFrame::OnNstrojeTvrcepaletpronestvry() { Pathname apppath=Pathname::GetExePath(); apppath.SetFilename(_T("AdvManData\\ColEdit.exe")); @@ -638,32 +638,32 @@ void CMainFrame::OnNstrojeTvrcepaletpronestvry() } -void CMainFrame::OnNstrojeTvrceikonpropedmty() +void CMainFrame::OnNstrojeTvrceikonpropedmty() { Pathname apppath=Pathname::GetExePath(); apppath.SetFilename(_T("AdvManData\\ItemIcons.exe")); - StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_ITEMY")); + StartApp(apppath,"",false,_advPath+get_text_field(_adv,"CESTA_ITEMY")); } -void CMainFrame::OnEditorySouboradv() +void CMainFrame::OnEditorySouboradv() { AfxMessageBox(IDS_EDITADVWARN,MB_ICONEXCLAMATION); - OpenEditor(_advName); + OpenEditor(_advName); } -void CMainFrame::OnFileZnovunast() +void CMainFrame::OnFileZnovunast() { release_list(_adv); _adv=read_config(_advName); - _baseMapPath=_advPath+get_text_field(_adv,"CESTA_MAPY"); + _baseMapPath=_advPath+get_text_field(_adv,"CESTA_MAPY"); } -void CMainFrame::OnUpdateFileZnovunast(CCmdUI* pCmdUI) +void CMainFrame::OnUpdateFileZnovunast(CCmdUI* pCmdUI) { pCmdUI->Enable(_adv!=0); } -void CMainFrame::OnEditoryDialogy() +void CMainFrame::OnEditoryDialogy() { DlgDialogy dlg; dlg._dlgpath.SetDirectory(_baseMapPath); diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 2bb4b75..5c218ec 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -1,8 +1,19 @@ +add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/default_font.base64 + COMMAND base64 ${CMAKE_CURRENT_LIST_DIR}/boldcz.fon -w 0 > ${CMAKE_BINARY_DIR}/default_font.base64 + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/boldcz.fon) + + +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/default_font.cpp + COMMAND ${CMAKE_COMMAND} -DOUT=${CMAKE_BINARY_DIR}/default_font.cpp -DIN=${CMAKE_BINARY_DIR}/default_font.base64 -DTEMPLATE=${CMAKE_CURRENT_LIST_DIR}/default_font.in.cpp -P ${CMAKE_CURRENT_LIST_DIR}/default_font_to_cpp.cmake + DEPENDS ${CMAKE_BINARY_DIR}/default_font.base64 ${CMAKE_CURRENT_LIST_DIR}/default_font_to_cpp.cmake ${CMAKE_CURRENT_LIST_DIR}/default_font.in.cpp + ) SET(files automap.c clk_map.c dialogy.c dump.cpp enemy.c +engine1.c engine2.c globmap.c inv.c @@ -21,7 +32,14 @@ setup.c chargen.c sndandmus.c specproc.c -temp_storage.cpp) +temp_storage.cpp +${CMAKE_BINARY_DIR}/default_font.cpp +) add_executable(skeldal ${files}) -target_link_libraries(skeldal skeldal_libs skeldal_platform_libs ${SDL2_LIBRARIES} pthread) +target_link_libraries(skeldal + skeldal_libs + skeldal_platform_libs + skeldal_linux + skeldal_sdl + ${SDL2_LIBRARIES} pthread) diff --git a/game/automap.c b/game/automap.c index 2e978eb..554122d 100644 --- a/game/automap.c +++ b/game/automap.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -423,10 +423,10 @@ static void draw_amap_sector(int x,int y,int sector,int mode,int turn,int line1, { switch (j) { - case 0:hor_line(x,y,x+8);break; - case 1:ver_line(x+8,y,y+8);break; - case 2:hor_line(x,y+8,x+8);break; - case 3:ver_line(x,y,y+8);break; + case 0:hor_line32(x,y,x+8);break; + case 1:ver_line32(x+8,y,y+8);break; + case 2:hor_line32(x,y+8,x+8);break; + case 3:ver_line32(x,y,y+8);break; } } } @@ -488,6 +488,7 @@ static void displ_button(char disable,char **text) int sizy[]={18,20,20,21}; int i; + int32_t scr_linelen2 = GetScreenPitch(); cur_disables=disable; set_font(H_FTINY,0); put_picture(LEFT,BOTT,ablock(H_CHARGEN)); diff --git a/game/builder.c b/game/builder.c index 12499e9..c58b749 100644 --- a/game/builder.c +++ b/game/builder.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -189,7 +189,8 @@ void show_money() void anim_sipky(int h,int mode) { - static int phase=0; + int32_t scr_linelen2 = GetScreenPitch(); + static int phase=0; static char drw=0; static short handle=0; @@ -254,6 +255,7 @@ void draw_blood(char mode,int mob_dostal,int mob_dostal_pocet) word *adr; int i; + int32_t scr_linelen2 = GetScreenPitch(); mob_dostal_pocet; if (mode) { if (phase<3) dostal+=mob_dostal_pocet;else dostal=mob_dostal_pocet; @@ -267,13 +269,14 @@ void draw_blood(char mode,int mob_dostal,int mob_dostal_pocet) phase++; put_8bit_clipped(ablock(H_KREVMIN+block-1),adr,i,120,102); set_font(H_FTINY,RGB555(31,31,31)); - itoa(dostal,s,10); + int2ascii(dostal,s,10); set_aligned_position(60+520,51+378,1,1,s);outtext(s); } word *bott_clear(void) { word *bott_scr; + int32_t scr_linelen2 = GetScreenPitch(); int32_t sz; bott_scr=(word *)getmem(sz = scr_linelen2*104*2); @@ -314,6 +317,7 @@ static void bott_draw_normal(void **pp,int32_t *s) word *bott_scr; THUMAN *p; + int32_t scr_linelen2 = GetScreenPitch(); bott_scr=bott_clear(); RedirectScreen(bott_scr); if (battle && cur_mode==MD_INBATTLE) put_picture(0,0,ablock(H_BATTLE_BAR)); @@ -339,12 +343,12 @@ static void bott_draw_normal(void **pp,int32_t *s) else put_picture(PIC_X+x,PIC_Y,ablock(H_LEBKA)); curcolor=0; y=BARS_YS-p->lives*BARS_YS/p->vlastnosti[VLS_MAXHIT]; - if (y) bar(x+ZIVOTY_S,BARS_S,x+ZIVOTY_E,BARS_S+y); + if (y) bar32(x+ZIVOTY_S,BARS_S,x+ZIVOTY_E,BARS_S+y); y=BARS_YS-p->kondice*BARS_YS/p->vlastnosti[VLS_KONDIC]; - if (y) bar(x+KONDIC_S,BARS_S,x+KONDIC_E,BARS_S+y); + if (y) bar32(x+KONDIC_S,BARS_S,x+KONDIC_E,BARS_S+y); if (p->vlastnosti[VLS_MAXMANA]) y=BARS_YS-p->mana*BARS_YS/p->vlastnosti[VLS_MAXMANA];else y=BARS_YS; if (y<0) y=0; - if (y) bar(x+MANA_S,BARS_S,x+MANA_E,BARS_S+y); + if (y) bar32(x+MANA_S,BARS_S,x+MANA_E,BARS_S+y); if (p->sektor!=viewsector) trans_bar25(x,0,74,102); set_font(H_FLITT,p->groupnum==cur_group && !battle?SEL_COLOR:barvy_skupin[p->groupnum]); set_aligned_position(x+36,92,1,0,p->jmeno);outtext(p->jmeno); @@ -459,6 +463,7 @@ static void MaskPutPicture(int x, int y, char mask, word color, char blend, void { short *info=(short *)pic; char *data=(char *)(info+3+256); + int32_t scr_linelen2 = GetScreenPitch(); word *pos=GetScreenAdr()+x+y*scr_linelen2; if (blend) color=color & 0xF7DE; for (y=0;y +#include #include #include #include @@ -59,8 +59,8 @@ typedef struct staty static T_STATY cur_stats; -word color_butt_on[]={0,RGB555(31,27,4),RGB555(30,26,4),RGB555(29,25,4)}; -word color_butt_off[]={0,RGB555(10,10,10),RGB555(10,10,10),RGB555(10,10,10)}; +word color_butt_on[7]={0,RGB555(31,27,4),RGB555(30,26,4),RGB555(29,25,4)}; +word color_butt_off[7]={0,RGB555(10,10,10),RGB555(10,10,10),RGB555(10,10,10)}; typedef struct vlasts @@ -201,6 +201,8 @@ void displ_button(char disable,char **text) int sizy[]={18,20,20,21}; int i; + int32_t scr_linelen2 = GetScreenPitch(); + set_font(H_FTINY,0); put_picture(LEFT,BOTT,ablock(H_GEN_CHARGEN)); for(i=0;i<4;i++) @@ -223,9 +225,11 @@ void displ_button(char disable,char **text) static void draw_other_bar() { int i; + int32_t scr_linelen2 = GetScreenPitch(); + word *bbar=ablock(H_BOTTBAR); word *screen=GetScreenAdr()+(480-102)*scr_linelen2; - for (i=0;i<102;i++,screen+=scr_linelen2,bbar+=scr_linelen2) memcpy(screen,bbar,scr_linelen); + for (i=0;i<102;i++,screen+=scr_linelen2,bbar+=scr_linelen2) memcpy(screen,bbar,scr_linelen2*2); //put_8bit_clipped(ablock(H_GEN_OKBUTT),378*640+520+screen,0,120,102); displ_button(b_disables,b_texty); put_picture(0,0,ablock(H_GEN_TOPBAR)); @@ -280,6 +284,8 @@ static void zobraz_perlu(void) word *b; int xs,ys,xxs; + int32_t scr_linelen2 = GetScreenPitch(); + alock(H_GEN_PERLA); perla=ablock(H_GEN_PERLA); if (pod_perlou==NULL) @@ -505,7 +511,7 @@ static int edit_task=-1; static void edit_name() { if (shut_downing_text) return; - curcolor=0;bar(120,2,120+104,16); + curcolor=0;bar32(120,2,120+104,16); edit_task=add_task(16384,type_text_v2,postavy[cur_edited].jmeno,120,2,104, sizeof(postavy[cur_edited].jmeno)-1,H_FONT6,RGB555(31,31,0),edit_name); } @@ -655,8 +661,8 @@ static void redraw_svitek(char) update_mysky(); schovej_mysku(); curcolor=0; - bar(0,16,30,16+360); - bar(620,16,640,16+360); + bar32(0,16,30,16+360); + bar32(620,16,640,16+360); inv_display_vlastnosti(); display_character(postavy+cur_edited,0); // display_items_wearing(human_selected); @@ -817,7 +823,7 @@ char enter_generator() b_texty[2]=texty[172]; b_texty[3]=texty[173]; def_entries(); - curcolor=0;bar(0,0,639,479); + curcolor=0;bar32(0,0,639,479); cur_angle=315; cur_edited=0; memset(postavy,0,sizeof(postavy)); @@ -890,7 +896,7 @@ char enter_generator() disable_click_map(); schovej_mysku(); curcolor=0; - bar(0,0,639,479); + bar32(0,0,639,479); showview(0,0,0,0); ukaz_mysku(); for(i=0;i<3;i++) diff --git a/game/clk_map.c b/game/clk_map.c index 21bdc25..10d9fec 100644 --- a/game/clk_map.c +++ b/game/clk_map.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/game/default_font.h b/game/default_font.h new file mode 100644 index 0000000..564bc85 --- /dev/null +++ b/game/default_font.h @@ -0,0 +1,5 @@ + + +void *LoadDefaultFont(); + + diff --git a/game/default_font.in.cpp b/game/default_font.in.cpp new file mode 100644 index 0000000..0085906 --- /dev/null +++ b/game/default_font.in.cpp @@ -0,0 +1,14 @@ +#include + + +constexpr binary_data font_data ="@CONTENT@"; + +extern "C" { + +const void *LoadDefaultFont() { + return font_data.begin(); +} + +} + + diff --git a/game/default_font_to_cpp.cmake b/game/default_font_to_cpp.cmake new file mode 100644 index 0000000..e3dfec3 --- /dev/null +++ b/game/default_font_to_cpp.cmake @@ -0,0 +1,4 @@ +file(READ ${IN} CONTENT) + +configure_file(${TEMPLATE} ${OUT} @ONLY) + diff --git a/game/dialogy.c b/game/dialogy.c index c7a4e4b..58cd2b1 100644 --- a/game/dialogy.c +++ b/game/dialogy.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -160,6 +160,7 @@ static void dialog_anim(va_list args) char hid; int spdc=0,cntr=rep,tm,tm2; + int32_t scr_linelen2 = GetScreenPitch(); loc_anim_render_buffer=PIC_Y*scr_linelen2+PIC_X; mgif_install_proc(animace_kouzla); concat(ch,pathtable[SR_DIALOGS],block); @@ -1125,7 +1126,7 @@ static void dark_screen(int time,int gtime) THUMAN *h; i=get_timer_value()+time*50; curcolor=0; - bar(0,17,639,377); + bar32(0,17,639,377); showview(0,0,0,0); while (get_timer_value() #include #include #include @@ -27,7 +28,7 @@ void open_files(char *src,char *tgr) char *c,*d; tgr=alloca(strlen(src)+5); strcpy(tgr,src); - c=strrchr(tgr,'\\'); + c=strrchr(tgr,PATH_SEPARATOR_CHR); d=strrchr(tgr,'.'); if (c>d) d=strchr(tgr,0); strcpy(d,".ENC"); diff --git a/game/enemy.c b/game/enemy.c index 9b72355..4e25098 100644 --- a/game/enemy.c +++ b/game/enemy.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/game/engine1.c b/game/engine1.c index deacae3..1f4c7b9 100644 --- a/game/engine1.c +++ b/game/engine1.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -282,6 +282,8 @@ void create_tables(void) { int x,y; + int32_t scr_linelen2 = GetScreenPitch(); + for (y=0;y639) xl=639;if (xr>639) xr=639; - showtabs.f_table[x][y].lineofs=(y1+MIDDLE_Y)*scr_linelen+xl*2; + showtabs.f_table[x][y].lineofs=(y1+MIDDLE_Y)*2*scr_linelen2+xl*2; showtabs.f_table[x][y].linesize=xr-xl+(xl!=xr); showtabs.f_table[x][y].counter=(y1-points[0][0][yp].y); showtabs.f_table[x][y].txtrofs=(y1+MIDDLE_Y-VIEW_SIZE_Y+F_YMAP_SIZE)*1280+xl*2; @@ -404,7 +406,7 @@ void create_tables(void) xr=xr*(y1-2)/points[0][1][0].y+MIDDLE_X; if (xl<0) xl=0;if (xr<0) xr=0; if (xl>639) xl=639;if (xr>639) xr=639; - showtabs.c_table[x][y].lineofs=(y1+MIDDLE_Y)*scr_linelen+xl*2; + showtabs.c_table[x][y].lineofs=(y1+MIDDLE_Y)*2*scr_linelen2+xl*2; showtabs.c_table[x][y].linesize=xr-xl+(xl!=xr); showtabs.c_table[x][y].counter=points[0][1][yp].y-y1; showtabs.c_table[x][y].txtrofs=(y1+MIDDLE_Y)*1280+xl*2; @@ -433,11 +435,13 @@ void create_zooming(void) { int i,j; + int32_t scr_linelen2 = GetScreenPitch(); + for (j=0;j>5; rev&=3; if (celx<=0) x3d=&showtabs.z_table[-celx][cely]; else x3d=&showtabs.z_table[celx][cely]; @@ -632,7 +638,7 @@ void show_cel(int celx,int cely,void *stena,int xofs,int yofs,char rev) zoom.palette=(word *)((byte *)stena+6+512*(cely)+(secnd_shade?SHADE_STEPS*512:0)); zoom.ycount=realsy+1; zoom.xmax=realsx; - zoom.line_len=scr_linelen; + zoom.line_len=2*scr_linelen2; if (rev) sikma_zprava(); else sikma_zleva(); } @@ -644,6 +650,8 @@ void show_cel2(int celx,int cely,void *stena,int xofs,int yofs,char rev) int txtsx,txtsy,realsx,realsy,x,i; char *p;int plac; + int32_t scr_linelen2 = GetScreenPitch(); + if (stena==NULL) return ; plac=rev>>5; rev&=3; @@ -696,7 +704,7 @@ void show_cel2(int celx,int cely,void *stena,int xofs,int yofs,char rev) zoom.palette=(word *)((byte *)stena+6+512*(cely)+(secnd_shade?SHADE_STEPS*512:0)); zoom.ycount=realsy+1; zoom.xmax=realsx; - zoom.line_len=scr_linelen; + zoom.line_len=scr_linelen2*2; if (rev==2) sikma_zprava(); else sikma_zleva(); } @@ -738,6 +746,8 @@ void draw_floor_ceil(int celx,int cely,char f_c,void *txtr) void OutBuffer2nd(void) { int i; + int32_t scr_linelen2 = GetScreenPitch(); + for (i=0;i<480;i++) memcpy(GetScreenAdr()+i*scr_linelen2,GetBuffer2nd()+i*scr_linelen2,640*2); } @@ -745,6 +755,8 @@ void OutBuffer2nd(void) void CopyBuffer2nd(void) { int i; + int32_t scr_linelen2 = GetScreenPitch(); + for (i=0;i<480;i++) memcpy(GetBuffer2nd()+i*scr_linelen2,GetScreenAdr()+i*scr_linelen2,640*2); } @@ -881,7 +893,7 @@ void report_mode(int mode) }*/ } -__inline void clear_color(void *start,int _size,word _color) +void clear_color(void *start,int _size,word _color) { word *s = (word *)start; int i; @@ -906,6 +918,8 @@ __inline void clear_color(void *start,int _size,word _color) void clear_buff(word *background,word backcolor,int lines) { + int32_t scr_linelen2 = GetScreenPitch(); + if (background!=NULL) put_picture(0,SCREEN_OFFLINE,background);else lines=0; if (lines!=360) for (i=lines;i<360;i++) @@ -915,6 +929,8 @@ void clear_buff(word *background,word backcolor,int lines) void clear_screen(word *screen, word color) { + int32_t scr_linelen2 = GetScreenPitch(); + for (i=0;i<480;i++) clear_color(screen+scr_linelen2*i,640,color); } @@ -925,6 +941,8 @@ void general_engine_init() create_zooming(); clear_screen(GetScreenAdr(),0); clear_screen(GetBuffer2nd(),0); + int32_t scr_linelen2 = GetScreenPitch(); + screen_buffer_size=scr_linelen2*480*2; } @@ -1035,6 +1053,8 @@ void draw_item(int celx,int cely,int posx,int posy,short *txtr,int index) int x,y; int clipl,clipr; int randx,randy; + int32_t scr_linelen2 = GetScreenPitch(); + if (txtr==NULL) return; randx=items_indextab[7-(index & 0x7)][0]; @@ -1057,6 +1077,8 @@ void put_textured_bar(void *src,int x,int y,int xs,int ys,int xofs,int yofs) { word *pos; word *xy; + int32_t scr_linelen2 = GetScreenPitch(); + pos=GetScreenAdr()+x+scr_linelen2*y; xy=src; @@ -1071,6 +1093,7 @@ void draw_placed_texture(short *txtr,int celx,int cely,int posx,int posy,int pos { int x,y; int clipl,clipr; + int32_t scr_linelen2 = GetScreenPitch(); if (txtr==NULL) return; map_pos(celx,cely,posx,posy,posz,&x,&y); @@ -1187,6 +1210,8 @@ void draw_enemy(DRW_ENEMY *drw) int posx,posy,cely; short *ys,yss,*xs,xss; int grcel; + int32_t scr_linelen2 = GetScreenPitch(); + if (drw->stoned) { @@ -1253,6 +1278,8 @@ void draw_player(short *txtr,int celx,int cely,int posx,int posy,int adjust,char { int x,y,yc,lx,sd; int clipl,clipr; + int32_t scr_linelen2 = GetScreenPitch(); + RedirectScreenBufferSecond(); map_pos(celx,cely,posx+64,posy+64,0,&x,&y); @@ -1285,6 +1312,8 @@ void draw_player(short *txtr,int celx,int cely,int posx,int posy,int adjust,char void draw_spectxtr(short *txtr,int celx,int cely,int xpos) { int x,y,lx,clipl,clipr; + int32_t scr_linelen2 = GetScreenPitch(); + map_pos(celx,cely,64,64,0,&x,&y); lx=x; x-=(((*txtr>>1)+xpos)*last_scale*2)/320; @@ -1304,6 +1333,7 @@ void draw_item2(int celx,int cely,int xpos,int ypos,void *txtr,int index) { int x,y,xs,ys,ysc,abc,asc,clipl,clipr; static int indextab[][2]={{0,0},{0,1},{1,0},{-1,0},{1,2},{-1,1},{-2,1},{2,1}}; + int32_t scr_linelen2 = GetScreenPitch(); celx--; asc=(celx<0); diff --git a/game/engine1.h b/game/engine1.h index 400903c..570036a 100644 --- a/game/engine1.h +++ b/game/engine1.h @@ -18,7 +18,7 @@ #define FACTOR_3D 3.33 #define ZOOM_PHASES 9 #define SCREEN_OFFLINE (17) -#define SCREEN_OFFSET (scr_linelen2*SCREEN_OFFLINE) +#define SCREEN_OFFSET (GetScreenPitch()*SCREEN_OFFLINE) #define C_YMAP_SIZE 90 #define F_YMAP_SIZE 199 #define CF_XMAP_SIZE 7 diff --git a/game/engine2.c b/game/engine2.c index ee5adaa..3006a4c 100644 --- a/game/engine2.c +++ b/game/engine2.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include "engine1.h" #include @@ -13,6 +13,7 @@ extern word *screen; void sikma_zleva(void) { + int32_t scr_linelen2 = GetScreenPitch(); word *scr = (word *)zoom.startptr; const word *palette = (word *)zoom.palette; word cy = zoom.ycount; @@ -86,7 +87,7 @@ void sikma_zleva(void) void sikma_zprava(void) { - + int32_t scr_linelen2 = GetScreenPitch(); word *scr = (word *)zoom.startptr; const word *palette = (word *)zoom.palette; word cy = zoom.ycount; @@ -204,6 +205,7 @@ void klicovani_anm_back(void *target,void *source); void klicovani_anm(void *target,void *source,char mirror) //#pragma aux klicovani_anm parm [edi][esi][eax] modify [ecx edx ebx] { + int32_t scr_linelen2 = GetScreenPitch(); word *t = (word *)target; word *s = (word *)source; if (mirror) { @@ -334,6 +336,7 @@ kba_skip:dec ebx void small_anm_buff(void *target,void *buff,void *paleta) //#pragma aux small_anm_buff parm[edi][esi][ebx] modify [eax ecx] { + int32_t scr_linelen2 = GetScreenPitch(); word *t = (word *)target; unsigned char *s = (unsigned char *)buff; word *p = (word *)paleta; @@ -366,6 +369,7 @@ shmab3: zobraz_1 void small_anm_delta(void *target,void *buff,void *paleta) //#pragma aux small_anm_delta parm[edi][esi][ebx] modify [eax ecx] { + int32_t scr_linelen2 = GetScreenPitch(); word *t = (word *)target; word *pal = (word *)paleta; uint32_t *deltastart = (uint32_t *)buff; @@ -444,7 +448,7 @@ shmad4: add edi,scr_linelen void scroll_and_copy(void *pic,void *slide, void *scr, int _size,int shift, void *lineinfo) //#pragma aux scroll_and_copy parm[esi][ebx][edi][ecx][edx][eax] { - + int32_t scr_linelen2 = GetScreenPitch(); word *srcpc = (word *)pic; word *trg = (word *)scr; word *sld = (word *)slide; @@ -569,6 +573,7 @@ sac_end:sub ecx,2 ;odecti counter void enemy_draw(void *src,void *trg,int shade,int scale,int maxspace,int clip) //#pragma aux enemy_draw parm[ESI][EDI][EBX][EDX][EAX][ECX] { + int32_t scr_linelen2 = GetScreenPitch(); word *picinfo = (word *)src; word *screen = (word *)trg; int xtable[800]; @@ -756,6 +761,7 @@ void enemy_draw_transp(void *src,void *trg,void *shade,int scale,int maxspace,in //#pragma aux enemy_draw_transp parm[ESI][EDI][EBX][EDX][EAX][ECX] { + int32_t scr_linelen2 = GetScreenPitch(); word *picinfo = (word *)src; word *screen = (word *)trg; int xtable[800]; @@ -946,6 +952,7 @@ void enemy_draw_mirror_transp(void *src,void *trg,void *shade,int scale,int maxs //#pragma aux enemy_draw_mirror_transp parm[ESI][EDI][EBX][EDX][EAX][ECX] { + int32_t scr_linelen2 = GetScreenPitch(); word *picinfo = (word *)src; word *screen = (word *)trg; int xtable[800]; @@ -1134,6 +1141,7 @@ void enemy_draw_mirror(void *src,void *trg,int shade,int scale,int maxspace,int //#pragma aux enemy_draw_mirror parm[ESI][EDI][EBX][EDX][EAX][ECX] //clip je v poradi vpravo - vlevo (HiLo) { + int32_t scr_linelen2 = GetScreenPitch(); word *picinfo = (word *)src; word *screen = (word *)trg; int xtable[800]; diff --git a/game/gamesave.c b/game/gamesave.c index 3a28995..0f201fc 100644 --- a/game/gamesave.c +++ b/game/gamesave.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -758,27 +758,23 @@ static void MakeSaveGameDir(const char *name) static int save_global_events() { - FILE *f; - char *c; - concat(c,pathtable[SR_TEMP],_GLOBAL_ST ); - f=fopen(c,"wb"); + TMPFILE_WR *f; + f=temp_storage_create(_GLOBAL_ST); if (f==NULL) return 1; - fwrite(GlobEventList,1,sizeof(GlobEventList),f); - fclose(f); + temp_storage_write(GlobEventList,1*sizeof(GlobEventList),f); + temp_storage_close_wr(f); return 0; } static int load_global_events() { - FILE *f; - char *c; + TMPFILE_RD *f; memset(GlobEventList,0,sizeof(GlobEventList)); - concat(c,pathtable[SR_TEMP],_GLOBAL_ST ); - f=fopen(c,"rb"); + f=temp_storage_open(_GLOBAL_ST); if (f==NULL) return 1; - fread(GlobEventList,1,sizeof(GlobEventList),f); - fclose(f); + temp_storage_read(GlobEventList,1*sizeof(GlobEventList),f); + temp_storage_close_rd(f); return 0; } @@ -798,7 +794,6 @@ int save_game(int slotnum,char *gamename) strncpy(gn,gamename,SAVE_NAME_SIZE); if ((r=save_shops())!=0) return r; if ((r=save_basic_info())!=0) return r; - save_leaving_places(); save_book(); save_global_events(); svf=fopen(ssn,"wb"); @@ -841,7 +836,6 @@ int load_game(int slotnum) if (svf==NULL) return 1; fseek(svf,SAVE_NAME_SIZE,SEEK_CUR); r=unpack_all_status(svf); - load_leaving_places(); fclose(svf); open_story_file(); if (r>0) @@ -1420,7 +1414,7 @@ void wire_save_load(char save) load_mode=save; if (slot_list==NULL) read_slot_list(); curcolor=0; - bar(0,17,639,17+360); + bar32(0,17,639,17+360); if (force_save) redraw_save();else redraw_load(); if (save==4) effect_show(NULL);else showview(0,0,0,0); redraw_story_bar(cur_story_pos); diff --git a/game/globals.h b/game/globals.h index 31501eb..d4a334a 100644 --- a/game/globals.h +++ b/game/globals.h @@ -103,7 +103,7 @@ static __inline int rangrnd(int a, int b) {return rnd(b-a+1)+a;} #define TX_LOAD 0 -#define LODKA_POS (SCREEN_OFFLINE+301)*scr_linelen2+GetBuffer2nd() +#define LODKA_POS (SCREEN_OFFLINE+301)*GetBuffer2ndPitch()+GetBuffer2nd() #define LODKA_SIZ 640*60 @@ -119,7 +119,7 @@ static __inline int rangrnd(int a, int b) {return rnd(b-a+1)+a;} #define NOSHADOW(x) ((x)|BGSWITCHBIT) -#define PICTURES "..\\OBRAZKY\\" +#define PICTURES ".." PATH_SEPARATOR "OBRAZKY" PATH_SEPARATOR #define PIC_FADE_PAL_SIZE (10*512+6) #define E_REFRESH 256 //udalost refresh scene @@ -325,7 +325,6 @@ static __inline int rangrnd(int a, int b) {return rnd(b-a+1)+a;} #define SR_FONT 3 #define SR_MAP 4 #define SR_MUSIC 5 -#define SR_TEMP 6 #define SR_BGRAFIKA 7 #define SR_ITEMS 8 #define SR_ENEMIES 9 @@ -749,8 +748,6 @@ void check_players_place(char mode); void add_leaving_place(int sector); -void save_leaving_places(void); -void load_leaving_places(void); int set_leaving_place(void); int get_leaving_place(char *level_name); @@ -1647,8 +1644,7 @@ void fletna_glob_add_note(char note); char *find_map_path(char *filename); //vyhledava jmeno mapy v alternativnich cestach. //Vysledny retezec je nutne uvolnit (free) ! -FILE *enc_open(char *filename,ENCFILE *fil); //dekoduje a otevira TXT soubor (ENC) -void enc_close(ENCFILE *fil); //uzavira dekodovany soubor. +char *enc_open(char *filename); //dekoduje a otevira TXT soubor (ENC) int load_string_list_ex(char ***list,char *filename); int smlouvat_nakup(int cena,int ponuka,int posledni,int puvod,int pocet); diff --git a/game/globmap.c b/game/globmap.c index 830cf41..4afac66 100644 --- a/game/globmap.c +++ b/game/globmap.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -246,9 +246,10 @@ static char test_kriterii(void) break; default: { - char c[200]; - sprintf(c,"%s%s.TMP",pathtable[SR_TEMP],text); - hodn=!access(c,0); + hodn=temp_storage_find(text); +/* char c[200]; + sprintf(c,"%s.TMP",text); + hodn=!access(c,0);*/ } break; } @@ -477,7 +478,7 @@ static char load_index_map(int index) if (h->sektor!=lv && !labyrinth_find_path(h->sektor,lv,(SD_PLAY_IMPS | SD_SECRET),flp_validate2,NULL)) { char c[20]; - bott_disp_text(itoa(i,c,10)); + bott_disp_text(int2ascii(i,c,10)); return 0; } if (!GlobEvent(MAGLOB_LEAVEMAP,viewsector,viewdir)) return 0; diff --git a/game/interfac.c b/game/interfac.c index 312e864..c75590b 100644 --- a/game/interfac.c +++ b/game/interfac.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -42,6 +42,8 @@ void create_frame(int x,int y,int xs,int ys,char clear) word *line; word *col; int i; + int32_t scr_linelen2 = GetScreenPitch(); + x-=VEL_RAMEC; y-=VEL_RAMEC; @@ -75,7 +77,7 @@ void create_frame(int x,int y,int xs,int ys,char clear) x+=VEL_RAMEC;y+=VEL_RAMEC; xs=(xs-1)*VEL_RAMEC; ys=(ys-1)*VEL_RAMEC; - bar(x,y,x+xs-1,y+ys-1); + bar32(x,y,x+xs-1,y+ys-1); } } @@ -650,13 +652,13 @@ static void radio_butts_draw(int x1,int y1,int x2,int y2,OBJREC *o) { int xx1=x1+2,yy1=y1+1,xx2=x1+size-2,yy2=y1+size-3,xxs=(xx1+xx2)>>1,yys=(yy1+yy2)>>1; curcolor=0x0; - line(xx2+1,yy1+2,xxs+2,yy2+2); - line(xx1+1,yys+2,xxs+1,yy2+2); + line32(xx2+1,yy1+2,xxs+2,yy2+2); + line32(xx1+1,yys+2,xxs+1,yy2+2); curcolor=RGB555(31,31,31); - line(xx2,yy1+1,xxs+1,yy2+1); - line(xx1,yys+1,xxs,yy2+1); - line(xx2,yy1,xxs+1,yy2); - line(xx1,yys,xxs,yy2); + line32(xx2,yy1+1,xxs+1,yy2+1); + line32(xx1,yys+1,xxs,yy2+1); + line32(xx2,yy1,xxs+1,yy2); + line32(xx1,yys,xxs,yy2); } draw_border(x1+1,y1+1,size-2,size-2,clt); if (*params) @@ -908,6 +910,7 @@ static void skeldal_checkbox_draw(int x1,int y1,int x2,int y2,OBJREC *o) word *obr; char *data; int phase; + int32_t scr_linelen2 = GetScreenPitch(); y2,x2; data=(char *)o->data; @@ -1321,68 +1324,45 @@ char *find_map_path(char *filename) return p; } -FILE *enc_open(char *filename,ENCFILE *fil) +static char *load_file_to_string(FILE *f, int *size) { + fseek(f,0, SEEK_END); + int sz = ftell(f); + fseek(f, 0 , SEEK_SET); + char *c = getmem(sz+1); + fread(c,1,sz,f); + *size = sz; + c[sz] = 0; + return c; +} + +char *enc_open(char *filename) { FILE *f,*g; char *c,*d,*enc,*temp; int i,j,last=0; + int size; f=fopen(filename,"r"); - if (f!=NULL) - { - fil->f=f; - fil->to_delete=NULL; - return f; - } + if (f!=NULL) { + char *c = load_file_to_string(f, &size); + fclose(f); + return c; + } + enc=alloca(strlen(filename)+5); strcpy(enc,filename); c=strrchr(enc,'.'); if (c==NULL) c=strchr(enc,0); strcpy(c,".ENC"); f=fopen(enc,"rb"); - if (f==NULL) - { - fil->f=NULL; - fil->to_delete=NULL; - return NULL; - } - d=strrchr(enc,'\\');if(d==NULL)d=enc;else d++; - temp=malloc((i=strlen(pathtable[SR_TEMP]))+strlen(d)+1); - strcpy(temp,pathtable[SR_TEMP]); - strcat(temp,d); - d=temp+i; - d=strrchr(d,'.'); - strcpy(d,".dec"); - g=fopen(temp,"wb"); - if (g==NULL) - { - free(temp); - fclose(f); - fil->f=NULL; - fil->to_delete=NULL; - return NULL; - } - i=getc(f); - while (i!=EOF) - { - j=(last+i) & 0xff; - last=j; - putc(j,g); - i=getc(f); - } + if (f==NULL) return NULL; + char *encdata = load_file_to_string(f, &size); fclose(f); - fclose(g); - f=fopen(temp,"r"); - if (f==NULL) - { - free(temp); - fil->f=NULL; - fil->to_delete=NULL; - return NULL; - } - fil->f=f; - fil->to_delete=temp; - return f; + for (int i = 0; i < size; ++i) { + last = (last + encdata[i]) & 0xFF; + encdata[i] = last; + } + return encdata; } void enc_close(ENCFILE *fil) @@ -1397,11 +1377,42 @@ void enc_close(ENCFILE *fil) int load_string_list_ex(TSTR_LIST *list,char *filename) { + char *data = enc_open(filename); + if (data == NULL) return -1; + + if (*list==NULL) *list=create_list(256); + char *d = data; + do { + while (*d && isspace(d)) ++d; + if (!*d) break; + if (*d && *d == ';') { + while (*d && *d != '\n') ++d; + } else { + int idx = 0; + int m = 1; + if (*d == '-') {m = -1;++d;} + while (*d >= '0' && *d <='9') { + idx = idx*10+(*d-'0'); + ++d; + } + if (idx == -1) break; + while (*d && isspace(d)) ++d; + char *b = d; + while (*d && *d != '\n' && *d != '\r') ++d; + if (*d) {*d = 0;++d;} + str_replace(list, idx, b); + } + } while (1); + free(data); + } + /* char c[1024],*p; int i,j,lin=0; FILE *f; ENCFILE fl; + + f=enc_open(filename,&fl); if (*list==NULL) *list=create_list(256); if (f==NULL) return -1; @@ -1447,6 +1458,7 @@ int load_string_list_ex(TSTR_LIST *list,char *filename) enc_close(&fl); return 0; } + */ //------------------------------------------------------------ int smlouvat_nakup(int cena,int ponuka,int posledni,int puvod,int pocet) @@ -1508,7 +1520,7 @@ int smlouvat(int cena,int puvod,int pocet,int money,char mode) cena,puvod,pocet,money;text[0]=0;text[1]=0; add_window(170,130,300,150,H_IDESKA,3,20,20); define(-1,10,15,1,1,0,label,texty[241]); - set_font(H_FBOLD,RGB555(31,31,31));define(-1,150,15,100,13,0,label,itoa(cena,buffer,10)); + set_font(H_FBOLD,RGB555(31,31,31));define(-1,150,15,100,13,0,label,int2ascii(cena,buffer,10)); set_font(H_FBOLD,MSG_COLOR1); define(-1,10,30,1,1,0,label,texty[238]); define(10,150,30,100,13,0,input_line,8);property(def_border(5,BAR_COLOR),NULL,NULL,0);set_default(""); @@ -1579,7 +1591,7 @@ void show_jrc_logo(char *filename) int cntr,cdiff,cpalf,ccc; change_music("?"); - curcolor=0;bar(0,0,639,479); + curcolor=0;bar32(0,0,639,479); showview(0,0,0,0);sleep_ms(1000); concat(s,pathtable[SR_VIDEO],filename); if (open_pcx(s,A_8BIT,&pcx)) return; @@ -1628,7 +1640,7 @@ void show_jrc_logo(char *filename) mix_back_sound(0); } while (cdiff +#include #include #include #include @@ -1223,6 +1223,7 @@ void build_items_called(void **p,int32_t *s) void display_items_wearing(THUMAN *h) { int it; + int32_t scr_linelen2 = GetScreenPitch(); put_picture(4,TOP_OFS,ablock(H_IOBLOUK)); zneplatnit_block(h-postavy+H_POSTAVY); enemy_draw(ablock(h-postavy+H_POSTAVY),GetScreenAdr()+HUMAN_X+HUMAN_Y*scr_linelen2,6,320,HUMAN_Y,640*65536); @@ -1262,7 +1263,7 @@ static void percent_bar(int x,int y,int xs,int ys,int val,int max,char *popis) char s[25]; memcpy(&clt,def_border(3,0),sizeof(clt)); - bar(x,y,x+xs*val/max,ys+y); + bar32(x,y,x+xs*val/max,ys+y); show_textured_button(x-2,y-2,xs+5,ys+5,0,&clt); set_aligned_position(x,y-5,0,2,popis); outtext(popis); @@ -1526,8 +1527,8 @@ void redraw_inventory() update_mysky(); schovej_mysku(); curcolor=0; - bar(0,16,30,16+360); - bar(620,16,640,16+360); + bar32(0,16,30,16+360); + bar32(620,16,640,16+360); if (inv_view_mode==0 && ~human_selected->stare_vls[VLS_KOUZLA] & SPL_DEMON && ~human_selected->vlastnosti[VLS_KOUZLA] & SPL_STONED) display_items_in_inv(human_selected); else inv_display_vlastnosti(); display_items_wearing(human_selected); @@ -2859,7 +2860,7 @@ void enter_shop(int shopid) unwire_proc(); cur_shop=shop_list[i]; curcolor=0; - bar(0,0,639,479); + bar32(0,0,639,479); rebuild_keepers_items(); bott_draw(1); shop_sector=viewsector; @@ -2970,43 +2971,41 @@ void reroll_all_shops() char save_shops() { - FILE *f; + TMPFILE_WR *f; char *c; int res=0; SEND_LOG("(SHOP) Saving shops...",0,0); if (max_shops==0 || shop_hacek==NULL) return 0; - concat(c,pathtable[SR_TEMP],_SHOP_ST); - f=fopen(c,"wb"); + f = temp_storage_create(_SHOP_ST); if (f==NULL) return 1; - fwrite(&max_shops,1,sizeof(max_shops),f); - fwrite(&shop_hacek_size,1,sizeof(shop_hacek_size),f); - res=(fwrite(shop_hacek,1,shop_hacek_size,f)!=(unsigned)shop_hacek_size); - fclose(f); + temp_storage_write(&max_shops,1*sizeof(max_shops),f); + temp_storage_write(&shop_hacek_size,1*sizeof(shop_hacek_size),f); + temp_storage_write(shop_hacek,1*shop_hacek_size,f); + temp_storage_close_wr(f); return res; } char load_saved_shops() { - FILE *f; + TMPFILE_RD *f; char *c; int res=0; int i=0,j=0; SEND_LOG("(SHOP) Loading saved shops...",0,0); - concat(c,pathtable[SR_TEMP],_SHOP_ST); - f=fopen(c,"rb"); + f=temp_storage_open(_SHOP_ST); if (f==NULL) return 0; - fread(&i,1,sizeof(max_shops),f); - fread(&j,1,sizeof(shop_hacek_size),f); + temp_storage_read(&i,1*sizeof(max_shops),f); + temp_storage_read(&j,1*sizeof(shop_hacek_size),f); if (i!=max_shops || j!=shop_hacek_size) { - fclose(f); + temp_storage_close_rd(f); return 0; } - res=(fread(shop_hacek,1,shop_hacek_size,f)!=(unsigned)shop_hacek_size); - fclose(f); + res=(temp_storage_read(shop_hacek,1*shop_hacek_size,f)!=(unsigned)shop_hacek_size); + temp_storage_close_rd(f); rebuild_shops(); return res; } diff --git a/game/kniha.c b/game/kniha.c index e8ecc3b..3e761f7 100644 --- a/game/kniha.c +++ b/game/kniha.c @@ -1,4 +1,4 @@ -#include +#include /* Popis jazyka pro psani textu do knihy @@ -286,25 +286,25 @@ static void break_line() save_buffer(); } -static char read_set(FILE *txt,char *var,char *set) +static char read_set(TMPFILE_RD *txt,char *var,char *set) { int c; char *cc; char d; - fscanf(txt,"%[^=]%c",var,&d); + temp_storage_scanf(txt,"%[^=]%c",var,&d); do - c=fgetc(txt); + c=temp_storage_getc(txt); while (c<33); - if (c=='"') fscanf(txt,"%[^\"]%c%c",set,&d,&d); - else if (c=='\'') fscanf(txt,"%[^']%c%c",set,&d,&d); + if (c=='"') temp_storage_scanf(txt,"%[^\"]%c%c",set,&d,&d); + else if (c=='\'') temp_storage_scanf(txt,"%[^']%c%c",set,&d,&d); else { - ungetc(c,txt); - fscanf(txt,"%[^> ]%c",set,&d); + temp_storage_ungetc(txt); + temp_storage_scanf(txt,"%[^> ]%c",set,&d); } - while(c<33 && c!=EOF) c=fgetc(txt); - if (c!='>') ungetc(c,txt); + while(c<33 && c!=EOF) c=temp_storage_getc(txt); + if (c!='>') temp_storage_ungetc(txt); cc=strchr(var,0); while (cc!=var) { @@ -375,14 +375,14 @@ static void insert_picture(char *filename,int align,int line,int lsize) str_add(&all_text,write_buff); } -static char read_tag(FILE *txt) +static char read_tag(TMPFILE_RD *txt) { char c,var[256],set[256]; int i; - i=fscanf(txt,"%[^> ] %c",var,&c); - while(c<33 && i!=EOF) c=i=fgetc(txt); - if (c!='>') ungetc(c,txt); + i=temp_storage_scanf(txt,"%[^> ] %c",var,&c); + while(c<33 && i!=EOF) c=i=temp_storage_getc(txt); + if (c!='>') temp_storage_ungetc(txt); strupr(var); if (!strcmp(var,PARAGRAPH)) { @@ -432,15 +432,15 @@ static char read_tag(FILE *txt) } -static char skip_section(FILE *txt) +static char skip_section(TMPFILE_RD *txt) { int c; char end=1; - c=fgetc(txt); + c=temp_storage_getc(txt); while (c!=']' && c!=EOF) { - c=fgetc(txt); + c=temp_storage_getc(txt); end=0; } if (c==EOF) end=1; @@ -456,9 +456,9 @@ void prekodovat(char *c) } } -static void read_text(FILE *txt) +static void read_text(TMPFILE_RD *txt) { - int i; + int i = 0; int xs; char ss[2]=" "; char wsp=1; @@ -468,7 +468,7 @@ static void read_text(FILE *txt) xs=0; do { - i=fgetc(txt); + i=temp_storage_getc(txt); if (i==EOF) break; if (i<32) i=32; if (i=='<') @@ -492,7 +492,7 @@ static void read_text(FILE *txt) wsp=1; } else wsp=0; - if (i=='&') i=fgetc(txt); + if (i=='&') i=temp_storage_getc(txt); if (winconv && i>137) i=xlat_table[i-138]; ss[0]=i; xs+=text_width(ss); @@ -507,26 +507,33 @@ static void read_text(FILE *txt) while (1); } -void seek_section(FILE *txt,int sect_number) +static void seek_section(TMPFILE_RD *txt,int sect_number) { int c=0,i; winconv=0; do { - while (c!='[' && c!=EOF) c=fgetc(txt); + while (c!='[' && c!=EOF) c=temp_storage_getc(txt); if (c=='[') { i=-2; - fscanf(txt,"%d",&i); + c = temp_storage_getc(txt); + if (c>='0' && c<='9') { + i = 0; + while (c>='0' && c<='9') { + i = i * 10 +(c - '0'); + c = temp_storage_getc(txt); + } + } if (i==sect_number) { - c=fgetc(txt); + c=temp_storage_getc(txt); while(c!=']') { if (c=='W' || c=='w') winconv=1; if (c=='K' || c=='k') winconv=0; - c=fgetc(txt); + c=temp_storage_getc(txt); } return; } @@ -545,17 +552,22 @@ void seek_section(FILE *txt,int sect_number) void add_text_to_book(char *filename,int odst) { - FILE *txt; - ENCFILE fl; + char *txt; + TMPFILE_RD *fl; set_font(H_FKNIHA,NOSHADOW(0)); if (all_text==NULL) all_text=create_list(256); - txt=enc_open(filename,&fl); + txt=enc_open(filename); if (txt==NULL) return; - seek_section(txt,odst); - read_text(txt); + const char *bookenc = "__bookenc"; + temp_storage_store(bookenc, txt, strlen(txt)); + fl = temp_storage_open(bookenc); + seek_section(fl,odst); + read_text(fl); next_line(1000); - enc_close(&fl); + free(txt); + temp_storage_close_rd(fl); + temp_storage_delete(bookenc); } static char *displ_picture(char *c) @@ -563,6 +575,8 @@ static char *displ_picture(char *c) char *d; int x,y,hn,z,ln,sl; short *sh; + int32_t scr_linelen2 = GetScreenPitch(); + d=write_buff; while (*c!=':') *d++=*c++; @@ -675,41 +689,47 @@ int count_pages() void save_book() { char *c; - FILE *f; + TMPFILE_WR *f; int i,ss; char *tx; if (all_text==NULL) return; - concat(c,pathtable[SR_TEMP],BOOK_FILE); - f=fopen(c,"w");if (f==NULL) return; + + f = temp_storage_create(BOOK_FILE); i=0; ss=str_count(all_text); while (i +#include #include #include #include diff --git a/game/macros.c b/game/macros.c index a458661..75244cf 100644 --- a/game/macros.c +++ b/game/macros.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -569,7 +569,7 @@ static int ma_play_anim(char *filename,char cls) curcolor=0; if (cls) { - bar(0,0,639,479); + bar32(0,0,639,479); showview(0,0,0,0); } mute_all_tracks(1); diff --git a/game/menu.c b/game/menu.c index 2c17b63..a19b0a0 100644 --- a/game/menu.c +++ b/game/menu.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -223,6 +223,7 @@ static void zobraz_podle_masky(char barva,char anim) { char *maska; word *data; + int32_t scr_linelen2 = GetScreenPitch(); word *obr=GetScreenAdr()+300*scr_linelen2+220; word xs,ys; @@ -341,7 +342,7 @@ int enter_menu(char open) } update_mysky(); schovej_mysku(); - curcolor=0;bar(0,0,639,479); + curcolor=0;bar32(0,0,639,479); put_picture(0,0,ablock(H_MENU_BAR)); put_picture(0,56,ablock(H_ANIM)); ukaz_mysku(); @@ -364,7 +365,8 @@ int enter_menu(char open) char *get_next_title(signed char control,char *filename) { - static FILE *titles=NULL; +/* + static TMPFILE_RD *titles=NULL; static ENCFILE fl; static char buffer[81]; char *path,*c; @@ -372,11 +374,11 @@ char *get_next_title(signed char control,char *filename) switch(control) { case 1:concat(path,pathtable[SR_MAP],filename); - titles=enc_open(path,&fl); + titles=enc_open(path); if (titles==NULL) { concat(path,pathtable[SR_DATA],filename); - titles=enc_open(path,&fl); + titles=enc_open(path); if (titles==NULL) { char popis[300]; @@ -393,6 +395,7 @@ char *get_next_title(signed char control,char *filename) case -1:if (titles!=NULL)enc_close(&fl); break; } + */ return NULL; } @@ -448,7 +451,7 @@ static int insert_next_line(int ztrata) if (ll +#include #include #include #include @@ -45,7 +45,7 @@ extern TSTR_LIST texty_v_mape; -static TSTR_LIST leaving_places=NULL; + char pass_zavora=0; @@ -129,9 +129,9 @@ static void preload_percent(int cur,int max) int pos; pos=cur*640/max; if (pos>640) pos=640; - curcolor=RGB555(16,16,16);hor_line(0,476,pos); - curcolor=RGB555(8,8,8);hor_line(0,477,pos); - curcolor=RGB555(31,31,31);hor_line(0,475,pos); + curcolor=RGB555(16,16,16);hor_line32(0,476,pos); + curcolor=RGB555(8,8,8);hor_line32(0,477,pos); + curcolor=RGB555(31,31,31);hor_line32(0,475,pos); showview(0,460,640,20); do_events(); } @@ -181,7 +181,7 @@ char *pripona(char *filename,char *pripona) buff=getmem(strlen(filename)+strlen(pripona)+2); strcpy(buff,filename); - c=strrchr(buff,'\\'); + c=strrchr(buff,PATH_SEPARATOR_CHR); if (c==NULL) c=buff; c=strchr(c,'.'); if (c!=NULL) *c=0; @@ -372,8 +372,7 @@ int load_map(char *filename) suc=load_level_texts(d);free(d); if (!suc && level_texts!=NULL) create_playlist(level_texts[0]); init_tracks(); - play_next_music(&d); - change_music(d); + change_music(get_next_music_from_playlist()); for(r=0;r +#include #include #include #include diff --git a/game/skeldal.c b/game/skeldal.c index 949a9ee..fd83be4 100644 --- a/game/skeldal.c +++ b/game/skeldal.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -27,6 +27,7 @@ #include "engine1.h" #include "wizard.h" #include "version.h" +#include "default_font.h" #include #define CONFIG_NAME SKELDALINI @@ -36,18 +37,18 @@ #define ERR_GENERAL 1 char def_path[]=""; -char graph_path[]="graphics\\"; -char basc_graph[]="graphics\\basic\\"; -char item_graph[]="graphics\\items\\"; -char sample_path[]="samples\\"; -char font_path[]="font\\"; -char map_path[]="maps\\"; -char music_path[]="music\\"; -char org_music_path[]="music\\"; +char graph_path[]="graphics" PATH_SEPARATOR; +char basc_graph[]="graphics" PATH_SEPARATOR "basic" PATH_SEPARATOR; +char item_graph[]="graphics" PATH_SEPARATOR "items" PATH_SEPARATOR; +char sample_path[]="samples" PATH_SEPARATOR; +char font_path[]="font" PATH_SEPARATOR; +char map_path[]="maps" PATH_SEPARATOR; +char music_path[]="music" PATH_SEPARATOR; +char org_music_path[]="music" PATH_SEPARATOR; char temp_path[]="?"; -char enemies_path[]="graphics\\enemies\\"; -char video_path[]="video\\"; -char dialogs_path[]="graphics\\dialogs\\"; +char enemies_path[]="graphics" PATH_SEPARATOR "enemies" PATH_SEPARATOR; +char video_path[]="video" PATH_SEPARATOR; +char dialogs_path[]="graphics" PATH_SEPARATOR "dialogs" PATH_SEPARATOR; char saves_path[]=""; char work_path[]=""; char cd_path[]=""; @@ -311,6 +312,8 @@ int set_video(int mode) { int er=0; + int32_t scr_linelen2 = GetScreenPitch(); + report_mode(1); er=initmode_dx(windowed,windowedzoom,monitor,refresh); /* @@ -345,20 +348,13 @@ int set_video(int mode) default:er=-1; }*/ - screen_buffer_size=scr_linelen*480; + screen_buffer_size=scr_linelen2*2*480; return er; } -int ask_video() - { - int c; - printf("\nJaky videomode?:\n" - " 1) 640x480x256 \n" - " 2) 640x480xHiColor \n"); - c=_bios_keybrd(_KEYBRD_READ)>>8; - if (c==1) exit(0); - return c-1; - } +void purge_temps(char) { + temp_storage_clear(); +} void pcx_fade_decomp(void **p,int32_t *s) { @@ -455,8 +451,10 @@ void set_background(void **p,int32_t *s) char *pic; int counter; + if (!bgr_handle) return; if (bgr_distance==-1) return; + int32_t scr_linelen2 = GetScreenPitch(); data=ablock(bgr_handle); *s=scr_linelen2*360*2; ptr=*p=getmem(*s); @@ -555,14 +553,6 @@ void music_init() set_snd_effect(SND_GFX,init_gfx_vol); set_snd_effect(SND_MUSIC,init_music_vol); path=plugins_path; - if (path==0 || path[0]==0) - path=AutodetectWinAmp(); - if (path!=0 && path[0]!=0) - { - SEND_LOG("(SOUND) Installing plugins, path: %s",path,0); - init_winamp_plugins(path); - if (path!=plugins_path) free(path); - } SEND_LOG("(SOUND) SOUND_DONE Sound Engine should work now",0,0); } @@ -863,6 +853,7 @@ void global_kbd(EVENT_MSG *msg,void **usr) if (msg->msg==E_KEYBOARD) { c=va_arg(msg->data,int)>>8; + int32_t scr_linelen2 = GetScreenPitch(); if (c==';') save_dump(GetScreenAdr(), DxGetResX(), DxGetResY(), scr_linelen2); } return; @@ -957,7 +948,7 @@ char device_error(int chyba,char disk,char info) static void patch_error(int err) { position(0,460); - curcolor=0;bar(0,460,640,479); + curcolor=0;bar32(0,460,640,479); memcpy(charcolors,flat_color(RGB555(31,31,31)),sizeof(charcolors)); curfont=boldcz; switch(err) @@ -1227,7 +1218,10 @@ static void config_skeldal(const char *line) maxi=strlen(c); data=alloca(maxi+1); strcpy(data,c); - if (data[maxi-1]=='\n') data[maxi-1]=0; + while (maxi && (isspace(data[maxi-1]))) { + --maxi; + data[maxi]=0; + } maxi=(sizeof(sinit)/sizeof(INIS)); for(i=0;i +#include #include #include #include diff --git a/game/souboje.c b/game/souboje.c index 65be858..bca94b9 100644 --- a/game/souboje.c +++ b/game/souboje.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -1321,6 +1321,7 @@ void fill_rune(char *d,int i) for(y=378;y<480;y++) { word *z; + int32_t scr_linelen2 = GetScreenPitch(); z=GetScreenAdr()+y*scr_linelen2; for(x=520;x<640;x++) if (*dd++==i) z[x]=z[x]-((z[x] & RGB555(28,28,28))>>2); @@ -1376,6 +1377,7 @@ void display_power_bar(char drw) int coords[][2]={{20,11},{20,41},{20,71}}; int i; + int32_t scr_linelen2 = GetScreenPitch(); schovej_mysku(); put_picture(520,378,ablock(H_POWERBAR)); for(i=0;i<3;i++) @@ -1662,6 +1664,7 @@ void souboje_redrawing() void souboje_stisknout(int d) { + int32_t scr_linelen2 = GetScreenPitch(); update_mysky(); schovej_mysku(); d--; diff --git a/game/specproc.c b/game/specproc.c index 9f19fd4..bd81c77 100644 --- a/game/specproc.c +++ b/game/specproc.c @@ -1,5 +1,5 @@ //Toto je hlavni soubor specialnich procedur pro hru BRANY SKELDALU -#include +#include #include #include #include @@ -233,6 +233,8 @@ static __inline int toInt(float fval) static void OtocObrazPodleMatice(float mx[3][2], word *picture) { + int32_t scr_linelen2 = GetScreenPitch(); + word *trg=GetScreenAdr()+17*scr_linelen2; int x,y; picture+=6; diff --git a/game/temp_storage.cpp b/game/temp_storage.cpp index cace888..b0d32e1 100644 --- a/game/temp_storage.cpp +++ b/game/temp_storage.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -13,6 +15,8 @@ typedef struct _temp_storage_file_wr { typedef struct _temp_storage_file_rd { std::basic_string_view _data; + int skp = 0; + int scan_ret = 0; } TMPFILE_RD; using FileSystem = std::map, std::less<> >; @@ -94,3 +98,38 @@ void temp_storage_skip(TMPFILE_RD *f, int bytes) { auto p = d.substr(0,bytes); d = d.substr(p.size()); } + +void temp_storage_delete(const char *name) { + temp_fsystem.erase(std::string(name)); +} + + +int temp_storage_getc(TMPFILE_RD *f) { + if (f->_data.empty()) return -1; + int r = f->_data[0]; + f->_data = f->_data.substr(1); + return r; +} + +void temp_storage_internal_begin_scanf(TMPFILE_RD *f, const char *format, ...) { + if (f->_data.empty()) { + f->scan_ret = -1; + } + va_list lst; + va_start(lst, format); + f->scan_ret = vsscanf(reinterpret_cast(f->_data.data()), format, lst); + va_end(lst); +} + +int *temp_storage_internal_skip_ptr(TMPFILE_RD *f) { + return &f->skp; +} + +int temp_storage_internal_end_scanf(TMPFILE_RD *f) { + temp_storage_skip(f, f->skp); + return f->scan_ret; +} + +void temp_storage_ungetc(TMPFILE_RD *f) { + f->_data = std::basic_string_view(f->_data.data()-1, f->_data.size()+1); +} diff --git a/game/temp_storage.h b/game/temp_storage.h index 586cc57..62e4d8b 100644 --- a/game/temp_storage.h +++ b/game/temp_storage.h @@ -17,10 +17,21 @@ typedef struct _temp_storage_file_wr TMPFILE_WR; TMPFILE_RD *temp_storage_open(const char *name); TMPFILE_WR *temp_storage_create(const char *name); TMPFILE_WR *temp_storage_append(const char *name); +void temp_storage_delete(const char *name); void temp_storage_close_rd(TMPFILE_RD *f); void temp_storage_close_wr(TMPFILE_WR *f); +int temp_storage_getc(TMPFILE_RD *f); +void temp_storage_ungetc(TMPFILE_RD *f); void temp_storage_write(const void *data, uint32_t size, TMPFILE_WR *f); uint32_t temp_storage_read(void *data, uint32_t size, TMPFILE_RD *f); void temp_storage_skip(TMPFILE_RD *f, int bytes); +int *temp_storage_internal_skip_ptr(TMPFILE_RD *f); +void temp_storage_internal_begin_scanf(TMPFILE_RD *f, const char *format, ... ); +int temp_storage_internal_end_scanf(TMPFILE_RD *f); + + +#define temp_storage_scanf(f, format, ...) (temp_storage_internal_begin_scanf(f, format "%n", __VA_ARGS__, temp_storage_internal_skip_ptr(f)),temp_storage_internal_end_scanf(f)) + + diff --git a/game/wizard.c b/game/wizard.c index 743bc2b..91bf8db 100644 --- a/game/wizard.c +++ b/game/wizard.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index fdec225..e939471 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -13,7 +13,7 @@ SET(files basicobj.c pcx.c strlite.c wav_mem.c - strlists.c + strlists.c swaper.c ) add_library(skeldal_libs ${files}) diff --git a/libs/advinst.c b/libs/advinst.c index a6b5155..e0858c2 100644 --- a/libs/advinst.c +++ b/libs/advinst.c @@ -39,7 +39,7 @@ char disk_finder() } char find_path(char *path) - { + {SEPARATOR char *oldpath; unsigned pismeno='C'; diff --git a/libs/base64.h b/libs/base64.h new file mode 100644 index 0000000..0dfe545 --- /dev/null +++ b/libs/base64.h @@ -0,0 +1,174 @@ +#pragma once +#include + + +class base64_t { +public: + + constexpr base64_t(const char *charset, char terminator):_terminator(terminator) { + for (int i = 0; i < 64; ++i) _charset[i] = charset[i]; + for (char &c: _charmap) c=-1; + for (unsigned int i = 0; i < 64;++i) { + int c = _charset[i]-32; + _charmap[c] = static_cast(i); + } + } + + template + constexpr OutIter encode(InIter beg, InIter end, OutIter out) const { + unsigned int remain = 0; + unsigned int accum = 0; + while (beg != end) { + accum = static_cast(*beg); + ++beg; + if (beg == end) { + remain = 2; + break; + } + accum = (accum << 8) | static_cast(*beg); + ++beg; + if (beg == end) { + remain = 1; + break; + } + accum = (accum << 8) | static_cast(*beg); + ++beg; + *out = _charset[accum >> 18]; + ++out; + *out = _charset[(accum >> 12) & 0x3F]; + ++out; + *out = _charset[(accum >> 6) & 0x3F]; + ++out; + *out = _charset[accum & 0x3F]; + ++out; + accum = 0; + } + switch (remain) { + case 2: *out = _charset[accum >> 2]; + ++out; + *out = _charset[(accum << 4) & 0x3F]; + ++out; + if (_terminator) { + *out = _terminator; + ++out; + *out = _terminator; + ++out; + } + break; + case 1: *out = _charset[accum >> 10]; + ++out; + *out = _charset[(accum >> 4) & 0x3F]; + ++out; + *out = _charset[(accum << 2) & 0x3F]; + ++out; + if (_terminator) { + *out = _terminator; + ++out; + } + break; + default: + break; + } + return out; + } + template + constexpr OutIter decode(InIter beg, InIter end, OutIter out) const { + unsigned int accum = 0; + unsigned int remain = 0; + char c = 0; + + auto load_next = [&]() { + do { + if (beg == end || *beg == _terminator) return false; + auto val = static_cast(*beg)-32; + ++beg; + if (val < 96) { + c = _charmap[val]; + if (c != -1) return true; + } + //skip invalid characters + } while (true); + }; + + while (load_next()) { + accum = c; + if (!load_next()) { + remain = 3; + break; + } + accum = (accum << 6) | c; + if (!load_next()) { + remain = 2; + break; + } + accum = (accum << 6) | c; + if (!load_next()) { + remain = 1; + break; + } + accum = (accum << 6) | c; + *out = static_cast(accum >> 16); + ++out; + *out = static_cast((accum >> 8) & 0xFF); + ++out; + *out = static_cast(accum & 0xFF); + ++out; + } + switch (remain) { + default: break; + case 2: *out = static_cast(accum >> 4); + ++out; + break; + case 1:*out = static_cast(accum >> 10); + ++out; + *out = static_cast((accum >> 2) & 0xFF); + ++out; + break; + } + return out; + } + + +protected: + char _charset[64] = {}; + char _charmap[96] = {}; + char _terminator; + +}; + +inline constexpr auto base64 = base64_t{"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",'='}; +inline constexpr auto base64url = base64_t{"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",'\0'}; + +template +class binary_data { +public: + + static constexpr std::size_t buff_size = (N+3)*3/4; + + constexpr binary_data(const char *txt) { + auto res =base64.decode(txt, txt+N, data); + sz = res - data; + } + + constexpr operator std::basic_string_view() const { + return {data, sz}; + } + + operator std::string_view() const { + return {reinterpret_cast(data), sz}; + } + + + constexpr auto begin() const {return data;} + constexpr auto end() const {return data+sz;} + constexpr std::size_t size() const {return sz;} + +protected: + std::size_t sz = 0; + unsigned char data[buff_size]= {}; +}; + +template +binary_data(const char (&)[N]) -> binary_data; + + diff --git a/libs/basicobj.c b/libs/basicobj.c index 8108403..5ef0865 100644 --- a/libs/basicobj.c +++ b/libs/basicobj.c @@ -1,4 +1,4 @@ -#include +#include // toto je include soubor, jenz je pouzit v knihovne GUI.C #include "types.h" @@ -111,7 +111,7 @@ void button_draw(int x1,int y1,int x2,int y2,OBJREC *o) CTL3D x; char w; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); highlight(&x,o->color); w=*(char *)o->data; x.bsize=2-w; @@ -126,7 +126,7 @@ void button_draw2(int x1,int y1,int x2,int y2,OBJREC *o) CTL3D x; char w; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); highlight(&x,o->color); w=*(char *)o->data; x.bsize=1; @@ -134,8 +134,8 @@ void button_draw2(int x1,int y1,int x2,int y2,OBJREC *o) draw_border(x1+1,y1+1,x2-x1-2,y2-y1-2,&x); if (!w) { - curcolor=x.light;hor_line(x1,y1,x2);hor_line(x1,y1+1,x2); - curcolor=x.shadow;hor_line(x1,y2,x2);hor_line(x1,y2-1,x2); + curcolor=x.light;hor_line32(x1,y1,x2);hor_line32(x1,y1+1,x2); + curcolor=x.shadow;hor_line32(x1,y2,x2);hor_line32(x1,y2-1,x2); } set_aligned_position(((x1+x2)>>1)+(w<<1),((y1+y2)>>1)+(w<<1),1,1,(char *)o->userptr); outtext((char *)o->userptr); @@ -225,7 +225,7 @@ void draw_status_line(char *c) memcpy(&charcolors,&color,sizeof(charcolors)); y=SCR_WIDTH_Y-ysize-3; desktop_y_size=y-3; - bar(0,y,SCR_WIDTH_X-1,SCR_WIDTH_Y-1); + bar32(0,y,SCR_WIDTH_X-1,SCR_WIDTH_Y-1); draw_border(2,y,SCR_WIDTH_X-5,ysize,&ctl); while (text_width(c)>SCR_WIDTH_X) { @@ -324,7 +324,7 @@ void *show_time(EVENT_MSG *msg) void win_label_draw(int x1,int y1,int x2,int y2,OBJREC *o) { - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); set_aligned_position(x1+5,(y1+y2)/2,0,1,(char *)o->userptr); outtext((char *)o->userptr); } @@ -450,18 +450,18 @@ void check_box_draw(int x1,int y1, int x2, int y2,OBJREC *o) x1+=1;y1+=1;x2-=1;y2-=1; x3=x1+(y2-y1); draw_border(x1,y1,x3-x1,y2-y1,def_border(4,curcolor)); - bar(x1,y1,x3,y2); + bar32(x1,y1,x3,y2); if (*(char *)o->data & 1) { curcolor=0x0000; - line(x1,y1,x3,y2);line(x1+1,y1,x3,y2-1);line(x1,y1+1,x3-1,y2); - line(x1,y2,x3,y1);line(x1+1,y2,x3,y1+1);line(x1,y2-1,x3-1,y1); + line32(x1,y1,x3,y2);line32(x1+1,y1,x3,y2-1);line32(x1,y1+1,x3-1,y2); + line32(x1,y2,x3,y1);line32(x1+1,y2,x3,y1+1);line32(x1,y2-1,x3-1,y1); } if (*(char *)o->data & 0x80) { curcolor=0x0000; - hor_line(x1,y1,x3);ver_line(x3,y1,y2); - ver_line(x1,y1,y2);hor_line(x1,y2,x3); + hor_line32(x1,y1,x3);ver_line32(x3,y1,y2); + ver_line32(x1,y1,y2);hor_line32(x1,y2,x3); } else { @@ -551,7 +551,7 @@ void radio_butts_draw(int x1,int y1,int x2,int y2,OBJREC *o) cr=curcolor; highlight(&ctl,curcolor); params=(int32_t *)o->userptr; - if (*params) bar(x1,y1,x2,y2); + if (*params) bar32(x1,y1,x2,y2); step=(y2-y1)/(*(params+1)); size=(step*9)/10; sizpul=size>>1; @@ -561,16 +561,16 @@ void radio_butts_draw(int x1,int y1,int x2,int y2,OBJREC *o) { int j; curcolor=ctl.shadow; - line(x1+sizpul,y1,x1,y1+sizpul); - line(x1,y1+sizpul,x1+sizpul,y1+size-1); + line32(x1+sizpul,y1,x1,y1+sizpul); + line32(x1,y1+sizpul,x1+sizpul,y1+size-1); curcolor=ctl.light; - line(x1+sizpul+1,y1,x1+size,y1+sizpul); - line(x1+size,y1+sizpul,x1+sizpul+1,y1+size-1); + line32(x1+sizpul+1,y1,x1+size,y1+sizpul); + line32(x1+size,y1+sizpul,x1+sizpul+1,y1+size-1); if (*(int32_t *)o->data==i) curcolor=0;else curcolor=cr; for (j=0;j<3;j++) { - hor_line(x1+sizpul-j,y1+sizpul-2+j,x1+sizpul+j); - hor_line(x1+sizpul-j,y1+sizpul+2-j,x1+sizpul+j); + hor_line32(x1+sizpul-j,y1+sizpul-2+j,x1+sizpul+j); + hor_line32(x1+sizpul-j,y1+sizpul+2-j,x1+sizpul+j); } if (*params) { @@ -689,7 +689,7 @@ void input_line_draw(int x1,int y1, int x2, int y2, OBJREC *o) int len; int shift; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); position(x1,y1); c=(char *)o->data; if (!*c) return; @@ -868,7 +868,7 @@ void scroll_button_draw(int x1,int y1,int x2,int y2,OBJREC *o) SCR_BUTTON *param; param=(SCR_BUTTON *)o->userptr; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); highlight(&x,o->color); w=*(char *)o->data; x.bsize=2-w; @@ -963,7 +963,7 @@ void scroll_bar_v_draw(int x1,int y1,int x2,int y2,OBJREC *o) if (barsize>wsize) barsize=wsize; wsize-=barsize; curcolor=p->bgcolor; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); curcolor=o->color; highlight(&ctl,o->color);ctl.bsize=2;ctl.ctldef=0; y=valsize?(*d-p->minvalue)*(wsize+barsize)/valsize:0; @@ -972,7 +972,7 @@ void scroll_bar_v_draw(int x1,int y1,int x2,int y2,OBJREC *o) if (y<0) y=0; y+=y1; draw_border(x1+2,y+2,(x2-x1)-4,barsize-4,&ctl); - if (barsize>4)bar(x1+2,y+2,x2-2,y+barsize-2); + if (barsize>4)bar32(x1+2,y+2,x2-2,y+barsize-2); p->barsize=barsize; } @@ -1076,7 +1076,7 @@ void scroll_bar_h_draw(int x1,int y1,int x2,int y2,OBJREC *o) if (barsize>wsize) barsize=wsize;if (barsize<2) barsize=2; wsize-=barsize; curcolor=p->bgcolor; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); curcolor=o->color; highlight(&ctl,o->color);ctl.bsize=2;ctl.ctldef=0; x=(*d-p->minvalue)*wsize/valsize; @@ -1085,7 +1085,7 @@ void scroll_bar_h_draw(int x1,int y1,int x2,int y2,OBJREC *o) if (x<0) x=0; x+=x1; draw_border(x+2,y1+2,barsize-4,(y2-y1)-4,&ctl); - if (barsize>4)bar(x+2,y1+2,x+barsize-2,y2-2); + if (barsize>4)bar32(x+2,y1+2,x+barsize-2,y2-2); p->barsize=barsize; } @@ -1234,17 +1234,17 @@ void resizer_draw(int x1,int y1,int x2,int y2,OBJREC *o) highlight(&ctl,o->color); curcolor=o->color; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); curcolor=ctl.light; - line(x2-1,y1+1,x1+1,y2-1); - line(x2-1,(y1+y2)>>1,(x1+x2)>>1,y2-1); + line32(x2-1,y1+1,x1+1,y2-1); + line32(x2-1,(y1+y2)>>1,(x1+x2)>>1,y2-1); curcolor=ctl.shadow; - line(x2-1,y1+4,x1+4,y2-1); - line(x2-1,y1+2,x2-1,y1+4); - line(x1+2,y2-1,x1+4,y2-1); - line(x2-1,((y1+y2)>>1)+4,((x1+x2)>>1)+4,y2-1); - line(x2-1,((y1+y2)>>1)+2,x2-1,((y1+y2)>>1)+4); - line(((x1+x2)>>1)+2,y2-1,((x1+x2)>>1)+4,y2-1); + line32(x2-1,y1+4,x1+4,y2-1); + line32(x2-1,y1+2,x2-1,y1+4); + line32(x1+2,y2-1,x1+4,y2-1); + line32(x2-1,((y1+y2)>>1)+4,((x1+x2)>>1)+4,y2-1); + line32(x2-1,((y1+y2)>>1)+2,x2-1,((y1+y2)>>1)+4); + line32(((x1+x2)>>1)+2,y2-1,((x1+x2)>>1)+4,y2-1); } void resizer_event(EVENT_MSG *msg,OBJREC *o) diff --git a/libs/bgraph.h b/libs/bgraph.h index 54985d5..b20ba01 100644 --- a/libs/bgraph.h +++ b/libs/bgraph.h @@ -1,22 +1,20 @@ #include "types.h" -#define line line32 -#define hor_line hor_line32 -#define ver_line ver_line32 -#define bar bar32 -#define point point32 + + + word *GetScreenAdr(); -int32_t GetScreenSizeBytes(); word *GetBuffer2nd(); +int32_t GetScreenPitch(); +int32_t GetBuffer2ndPitch(); +int32_t GetScreenSizeBytes(); + void RedirectScreen(word *newaddr); void RestoreScreen(); void RedirectScreenBufferSecond(); extern word curcolor,charcolors[7]; -extern int32_t scr_linelen; -extern int32_t scr_linelen2; -extern int32_t dx_linelen; extern word *curfont,*writepos,writeposx; extern byte fontdsize; extern byte *palmem,*xlatmem; @@ -29,7 +27,7 @@ extern char no_restore_mode; static __inline word *getadr32(longint x,longint y) { - return GetScreenAdr()+scr_linelen2*y+x; + return GetScreenAdr()+GetScreenPitch()*y+x; } static __inline void point32(longint x,longint y, word color) diff --git a/libs/bgraph2.c b/libs/bgraph2.c index 54fc0bf..a1be205 100644 --- a/libs/bgraph2.c +++ b/libs/bgraph2.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" //#include //#include @@ -13,9 +13,6 @@ word *screen; word curcolor,charcolors[7] = {0x0000,RGB555(0,31,0),RGB555(0,28,0),RGB555(0,24,0),RGB555(0,20,0),0x0000,0x0000}; -int32_t scr_linelen; -int32_t scr_linelen2; -int32_t dx_linelen; word *curfont,*writepos,writeposx; byte fontdsize=0; byte *palmem=NULL,*xlatmem=NULL; @@ -302,7 +299,6 @@ int initmode_dx(char inwindow, char zoom, char monitor, int refresh) if (!DXInit64(inwindow,zoom,monitor,refresh)) return -1; showview=showview_dx; screenstate=1; - scr_linelen2=scr_linelen/2; return 0; } @@ -659,10 +655,10 @@ void set_aligned_position(int x,int y,char alignx,char aligny,char *text) void rectangle(int x1,int y1,int x2,int y2,int color) { curcolor=color; - hor_line(x1,y1,x2); - hor_line(x1,y2,x2); - ver_line(x1,y1,y2); - ver_line(x2,y1,y2); + hor_line32(x1,y1,x2); + hor_line32(x1,y2,x2); + ver_line32(x1,y1,y2); + ver_line32(x2,y1,y2); } void *create_special_palette() diff --git a/libs/bgraph2a.c b/libs/bgraph2a.c index 3289c23..70eed2e 100644 --- a/libs/bgraph2a.c +++ b/libs/bgraph2a.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include "bgraph.h" @@ -19,6 +19,7 @@ void bar32(int x1,int y1, int x2, int y2) if (y1<0) y1=0; if (x2>mx) x2=mx; if (y2>my) y2=my; + int32_t scr_linelen2 = GetScreenPitch(); for (i=y1,begline=GetScreenAdr()+scr_linelen2*i;i<=y2;i++,begline+=scr_linelen2) { for (j=x1;j<=x2;j++) begline[j]=curcolor; @@ -38,6 +39,7 @@ void hor_line32(int x1,int y1,int x2) if (x1>x2) swap_int(x1,x2); if (x1<0) x1=0; if (x2>mx) x2=mx; + int32_t scr_linelen2 = GetScreenPitch(); begline=GetScreenAdr()+scr_linelen2*y1; for (i=x1;imx) return; if (y1<0) y1=0; if (y2>my) y2=my; + int32_t scr_linelen2 = GetScreenPitch(); begline=GetScreenAdr()+scr_linelen2*y1+x1; for (i=y1;i<=y2;i++,begline+=scr_linelen2) *begline=curcolor; } @@ -71,6 +74,7 @@ void hor_line_xor(int x1,int y1,int x2) if (x1>x2) swap_int(x1,x2); if (x1<0) x1=0; if (x2>mx) x2=mx; + int32_t scr_linelen2 = GetScreenPitch(); begline=GetScreenAdr()+scr_linelen2*y1; for (i=x1;imx) return; if (y1<0) y1=0; if (y2>my) y2=my; + int32_t scr_linelen2 = GetScreenPitch(); begline=GetScreenAdr()+scr_linelen2*y1+x1; for (i=y1;i<=y2;i++,begline+=scr_linelen2) *begline^=curcolor; } @@ -119,6 +124,7 @@ void line_32(int x,int y,int xs,int ys) void char_32(word *posit,word *font,char znak) //#pragma aux char_32 parm [edi] [esi] [eax] modify [eax ebx ecx edx] { + int32_t scr_linelen2 = GetScreenPitch(); word *edi = posit; unsigned char *esi = (unsigned char *)font; @@ -305,6 +311,7 @@ chsend: and eax,0ffffh void put_picture(word x,word y,void *p) //#pragma aux put_picture parm [esi] [eax] [edi] modify [ebx ecx edx] { + int32_t scr_linelen2 = GetScreenPitch(); word *adr=GetScreenAdr()+scr_linelen2*y+x; word *data=p; word xs=data[0]; @@ -375,6 +382,7 @@ void put_picture(word x,word y,void *p) } void get_picture(word x,word y,word xs,word ys,void *p) { + int32_t scr_linelen2 = GetScreenPitch(); word *adr=GetScreenAdr()+scr_linelen2*y+x; word *data=p; word xss=xs; @@ -403,7 +411,7 @@ void get_picture(word x,word y,word xs,word ys,void *p) void put_image(word *image,word *target,int start_line,int sizex,int sizey) //#pragma aux put_image parm [ESI][EDI][EAX][EBX][EDX] modify [ECX] { - + int32_t scr_linelen2 = GetScreenPitch(); word *esi = image; word *edi = target; int eax = start_line; @@ -457,6 +465,7 @@ puti_lp:mov ecx,ebx void put_8bit_clipped(void *src,void *trg,int startline,int velx,int vely) //#pragma aux put_8bit_clipped parm [ESI][EDI][EAX][EBX][EDX] modify [ECX]; { + int32_t scr_linelen2 = GetScreenPitch(); if (src==NULL) return; { word *esi = src; @@ -529,6 +538,7 @@ void put_textured_bar_(void *src,void *trg,int xsiz,int ysiz,int xofs,int yofs) //#pragma aux put_textured_bar_ parm [EBX][EDI][EDX][ECX][ESI][EAX]; { + int32_t scr_linelen2 = GetScreenPitch(); word *imghdr = (word *)src; word cx = imghdr[0]; word cy = imghdr[1]; @@ -633,6 +643,7 @@ ptb_skip2: void trans_bar(int x,int y,int xs,int ys,int barva) { + int32_t scr_linelen2 = GetScreenPitch(); word *begline; int x1=x; int y1=y; @@ -674,6 +685,7 @@ void trans_bar25(int x,int y,int xs,int ys) int y2=y+ys-1; int i,j; + int32_t scr_linelen2 = GetScreenPitch(); int mx = DxGetResX() - 1; int my = DxGetResY() - 1; diff --git a/libs/bgraph2a.cpp b/libs/bgraph2a.cpp index 388cca1..b9e0001 100644 --- a/libs/bgraph2a.cpp +++ b/libs/bgraph2a.cpp @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include "bgraph.h" #include diff --git a/libs/bmouse.c b/libs/bmouse.c index 6b26e6c..638085f 100644 --- a/libs/bmouse.c +++ b/libs/bmouse.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include "bgraph.h" #include "event.h" diff --git a/libs/cspells.c b/libs/cspells.c index cbf57d2..26f474b 100644 --- a/libs/cspells.c +++ b/libs/cspells.c @@ -132,7 +132,7 @@ const char *GetLexLibPath() static char c[MAX_PATH]; char *z; GetModuleFileName(0,c,MAX_PATH); - z=strrchr(c,'\\')+1; + z=strrchr(c,PATH_SEPARATOR_CHR)+1; strcpy(z,"lex_lib.exe"); return c; } @@ -149,8 +149,8 @@ main(int argc,char *argv[]) exit(0); } puts(""); - puts("Probh kompilace:"); - puts(" Spoutm program LEX_LIB.EXE\n"); + puts("Prob�h� kompilace:"); + puts(" Spou�t�m program LEX_LIB.EXE\n"); putenv("DOS4G=QUIET"); z=(char *)malloc(strlen(argv[1])+10); sprintf(z,"\"%s\"",argv[1]); @@ -162,8 +162,8 @@ main(int argc,char *argv[]) puts("Nemohu spustit program lex_lib.exe"); exit(1); } - puts("Byla kompilovna tato kouzla:"); - puts("slo, zatek, jmeno:"); + puts("Byla kompilov�na tato kouzla:"); + puts("��slo, za��tek, jmeno:"); puts("======================"); memset(kouzla_tab,0,sizeof(kouzla_tab)); init("temp.$$$"); @@ -172,8 +172,8 @@ main(int argc,char *argv[]) fclose(source); save_tab("kouzla.dat"); remove("temp.$$$"); - puts("Kompilace spn..."); - printf("Dlka kdu: %d (+%d)",codesize,sizeof(kouzla_tab)); + puts("Kompilace �sp��n�..."); + printf("D�lka k�du: %d (+%d)",codesize,sizeof(kouzla_tab)); } diff --git a/libs/devices.c b/libs/devices.c index 446baf5..7e8337c 100644 --- a/libs/devices.c +++ b/libs/devices.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include #include diff --git a/libs/devices.h b/libs/devices.h index 96f249d..4eed645 100644 --- a/libs/devices.h +++ b/libs/devices.h @@ -3,6 +3,7 @@ #include "types.h" #include "event.h" +#include "mouse.h" typedef struct tms_basic_info { int mouse_event; @@ -14,21 +15,8 @@ typedef struct tms_basic_info signed short mouse_di; }TMS_BASIC_INFO; -typedef struct ms_event - { - char event; - word x,y; - char tl1,tl2,tl3; - word event_type; - }MS_EVENT; - extern TMS_BASIC_INFO ms_basic_info; -extern char ms_fake_mode; -//int install_mouse_handler(); -//int deinstall_mouse_handler(); -//void hranice_mysky(int x1,int y1,int x2,int y2); -void get_ms_event(MS_EVENT *event); int lock_region (void *address, unsigned length); void keyboard(EVENT_MSG *msg,void *user_data); char ms_get_keycount(); diff --git a/libs/event.c b/libs/event.c index 052ac91..1450516 100644 --- a/libs/event.c +++ b/libs/event.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include "types.h" diff --git a/libs/gui.c b/libs/gui.c index 5f85969..e5e6ade 100644 --- a/libs/gui.c +++ b/libs/gui.c @@ -1,4 +1,4 @@ -#include +#include //Gui system - object system + graphic #include "types.h" #include @@ -64,11 +64,11 @@ void draw_border(integer x,integer y,integer xs,integer ys,CTL3D *btype) { x--;y--;xs+=2;ys+=2; if (j & 1) curcolor=btype->shadow; else curcolor=btype->light; - hor_line(x,y,xs+x); - ver_line(x,y,ys+y); + hor_line32(x,y,xs+x); + ver_line32(x,y,ys+y); if (j & 1) curcolor=btype->light; else curcolor=btype->shadow; - hor_line(x,y+ys,xs+x); - ver_line(x+xs,y,ys+y); + hor_line32(x,y+ys,xs+x); + ver_line32(x+xs,y,ys+y); j>>=1; } curcolor=c; @@ -231,6 +231,7 @@ void absolute_window(WINDOW *w,OBJREC *o, int *x, int *y) { int i,j; word *a; + int32_t scr_linelen2 = GetScreenPitch(); for (i=y;i<=y+ys;i++) { @@ -434,7 +435,7 @@ void redraw_desktop_call(EVENT_MSG *msg,void **data) if (gui_background==NULL) { curcolor=DESK_TOP_COLOR; - bar(0,0,SCR_WIDTH_X,SCR_WIDTH_Y-1); + bar32(0,0,SCR_WIDTH_X,SCR_WIDTH_Y-1); } else put_picture(0,0,gui_background); diff --git a/libs/inicfg.c b/libs/inicfg.c index 0dd715f..aa55a1e 100644 --- a/libs/inicfg.c +++ b/libs/inicfg.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -104,7 +104,7 @@ void add_field_num(TSTR_LIST *ls,const char *name,int32_t number) { char buff[20]; - itoa(number,buff,10); + int2ascii(number,buff,10); add_field_txt(ls,name,buff); } diff --git a/libs/memman.c b/libs/memman.c index 18732db..d27de1a 100644 --- a/libs/memman.c +++ b/libs/memman.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include #include diff --git a/libs/mgfplay.c b/libs/mgfplay.c index b0a18bc..901e844 100644 --- a/libs/mgfplay.c +++ b/libs/mgfplay.c @@ -1,4 +1,4 @@ -#include +#include // MOTION GIF - LZW komprimovana animace v rozliseni 320x180 256 barev avsak // upravena pro prehravani v HICOLOR pro konkretni rezim (32768 barev) diff --git a/libs/mgifmapmem.c b/libs/mgifmapmem.c index a7e6bc3..5aeee60 100644 --- a/libs/mgifmapmem.c +++ b/libs/mgifmapmem.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include "types.h" @@ -53,6 +53,7 @@ static void StretchImageHQ(word *src, word *trg, uint32_t linelen, char full) static void PlayMGFFile(void *file, MGIF_PROC proc,int ypos,char full) { + int32_t scr_linelen2 = GetScreenPitch(); mgif_install_proc(proc); sound=PrepareVideoSound(22050,256*1024); mgif_accnums[0]=mgif_accnums[1]=0; diff --git a/libs/mgifmem.c b/libs/mgifmem.c index e01b365..e275b32 100644 --- a/libs/mgifmem.c +++ b/libs/mgifmem.c @@ -1,4 +1,4 @@ -#include +#include #include #include "types.h" #include "memman.h" diff --git a/libs/mgifplaya.c b/libs/mgifplaya.c index f2e743a..a6c2b43 100644 --- a/libs/mgifplaya.c +++ b/libs/mgifplaya.c @@ -1,4 +1,4 @@ -#include +#include #include "types.h" #include #include diff --git a/libs/mouse.h b/libs/mouse.h new file mode 100644 index 0000000..2024b17 --- /dev/null +++ b/libs/mouse.h @@ -0,0 +1,24 @@ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __SKELDAL__MOUSE__ +#define __SKELDAL__MOUSE__ +typedef struct ms_event + { + char event; + uint16_t x,y; + char tl1,tl2,tl3; + uint16_t event_type; + }MS_EVENT; + + +void get_ms_event(MS_EVENT *event); + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/libs/pcx.c b/libs/pcx.c index c373d4d..414b13b 100644 --- a/libs/pcx.c +++ b/libs/pcx.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/libs/readfont.c b/libs/readfont.c index 3a6fce6..1aba932 100644 --- a/libs/readfont.c +++ b/libs/readfont.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include "types.h" @@ -17,8 +17,8 @@ int bott_line; int base_line; int top_ofs; -char znaky[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" +char znaky[]="0123456789A�BC�D�E��FGHI�JKL��MN�O�PQR�S�T�U��VWXY�Z�" + "a�bc�d�e��fghi�jkl��mn�o�pqr�s�t�u��vwxy�z�" "~!@#$%^&*()_+|-=\\[]{};':,./<>?"; void load_font_pic(char *filename) diff --git a/libs/strlists.c b/libs/strlists.c index d3d7563..a38e658 100644 --- a/libs/strlists.c +++ b/libs/strlists.c @@ -1,4 +1,4 @@ -#include +#include #include "strlite.c" #include "devices.h" @@ -100,7 +100,7 @@ void string_list_draw(int x1,int y1,int x2,int y2,OBJREC *o) xs=x2-x1;ys=y2-y1; p=o->userptr; ls=p->list; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); y=y1;p->maxitems=str_count(ls); for(j=p->maxitems-1;j>=0;j--) if (ls[j]!=NULL) break; j++; @@ -124,7 +124,7 @@ void string_list_draw(int x1,int y1,int x2,int y2,OBJREC *o) if (i==*(int *)(o->data)) { curcolor=p->selcolor; - bar(x1,y,x2,y+znh-1); + bar32(x1,y,x2,y+znh-1); } position(x1,y); for(j=0,x=x1,savech[0]=c[j]; @@ -145,7 +145,7 @@ void string_list_draw(int x1,int y1,int x2,int y2,OBJREC *o) int dif=y2-(y+znh); p->topline-=(dif*2/3)/znh+1; curcolor=savcolor; - bar(x1,y1,x2,y2); + bar32(x1,y1,x2,y2); } } while (p->topline && y+2*znh +#include #include "strlite.h" #include #include @@ -14,7 +14,7 @@ TSTR_LIST create_list(int count) size_t *s=(size_t *)malloc(count*sizeof(*p)+sizeof(size_t)); if (p==NULL) return NULL; *s = count; - p = (TSTR_LIST)s; + p = (TSTR_LIST)(s+1); for(i=0;i +#include #include #include #include diff --git a/libs/zvuk.c b/libs/zvuk.c index 12c6dca..007df08 100644 --- a/libs/zvuk.c +++ b/libs/zvuk.c @@ -2,10 +2,9 @@ #include //#include //#include -#include + #include #include -#include #include "zvuk.h" //#include "pcspeak.h" @@ -101,7 +100,7 @@ int bxbass=0; static int gfxvol=255; int32_t blength; static char depack[32768]; -void (__far __interrupt *oldvect)(); +//void (__far __interrupt *oldvect)(); static char swap_chans=0; char da_xlat[256]; // Xlat tabulka pro DA a PC Speaker; diff --git a/libs/zvuk.h b/libs/zvuk.h index 03c8b39..76b5df5 100644 --- a/libs/zvuk.h +++ b/libs/zvuk.h @@ -27,7 +27,6 @@ char start_mixing(); void stop_mixing(); void play_sample(int channel,void *sample,int32_t size,int32_t lstart,int32_t sfreq,int type); void set_channel_volume(int channel,int left,int right); -void init_winamp_plugins(const char *path); void set_end_of_song_callback(const char * (*cb)(void *), void *ctx); void fade_music(); diff --git a/libs/zvuk_dx.cpp b/libs/zvuk_dx.cpp index 98d5639..fe73453 100644 --- a/libs/zvuk_dx.cpp +++ b/libs/zvuk_dx.cpp @@ -1,5 +1,5 @@ #define INITGUID -#include +#include #include #include #include diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index 612169c..18eee6a 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -1,6 +1,7 @@ -SET(files error.cpp legacy_coroutines.cpp) +SET(files error.cpp legacy_coroutines.cpp platform.cpp int2ascii.c istr.c) add_library(skeldal_platform_libs ${files}) set_property(TARGET skeldal_platform_libs PROPERTY CXX_STANDARD 20) -add_subdirectory(sdl) \ No newline at end of file +add_subdirectory(sdl) +add_subdirectory(linux) \ No newline at end of file diff --git a/platform/int2ascii.c b/platform/int2ascii.c new file mode 100644 index 0000000..5c3e7f3 --- /dev/null +++ b/platform/int2ascii.c @@ -0,0 +1,30 @@ +#include "platform.h" + + + +static char *render_int(char *where, int i, int radix) { + if (i == 0) return where; + char *r = render_int(where, i/radix, radix); + int p = i % radix; + if (p<=0) { + *r = p + '0'; + } else { + *r = p + 'A' - 10; + } + return r+1; +} + +const char * int2ascii(int i, char *c, int radix) { + if (i == 0) { + c[0] = '0'; + c[1] = 0; + return c; + } + if (i<0) { + c[0] = '-'; + *render_int(c+1,-i,radix) = 0; + } else { + *render_int(c,i,radix) = 0; + } + return c; +} diff --git a/platform/istr.c b/platform/istr.c new file mode 100644 index 0000000..09816e5 --- /dev/null +++ b/platform/istr.c @@ -0,0 +1,23 @@ +#include "platform.h" + +#include +int stricmp(const char *a, const char *b) { + while (*a && *b) { + char ca = toupper(*a); + char cb = toupper(*b); + if (cacb) return 1; + ++a; + ++b; + } + if (*a) return 1; + if (*b) return -1; + return 0; +} + +void strupr(char *c) { + while (*c) { + *c = toupper(*c); + ++c; + } +} diff --git a/platform/linux/CMakeLists.txt b/platform/linux/CMakeLists.txt new file mode 100644 index 0000000..c0caaa2 --- /dev/null +++ b/platform/linux/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_library(skeldal_linux map_file.cpp timer.cpp) \ No newline at end of file diff --git a/platform/linux/map_file.cpp b/platform/linux/map_file.cpp new file mode 100644 index 0000000..d28967b --- /dev/null +++ b/platform/linux/map_file.cpp @@ -0,0 +1,59 @@ + +extern "C" { +#include "map_file.h" +} + +#include +#include +#include +#include +#include +#include + +// Funkce pro mapování souboru do paměti +void* map_file_to_memory(const char *name, size_t *sz) { + if (!name || !sz) { + return NULL; + } + + // Otevření souboru pro čtení + int fd = open(name, O_RDONLY); + if (fd == -1) { + perror("Chyba při otevírání souboru"); + return NULL; + } + + // Získání velikosti souboru + struct stat st; + if (fstat(fd, &st) == -1) { + perror("Chyba při získávání velikosti souboru"); + close(fd); + return NULL; + } + *sz = st.st_size; + + // Namapování souboru do paměti + void *mapped = mmap(NULL, *sz, PROT_READ, MAP_PRIVATE, fd, 0); + if (mapped == MAP_FAILED) { + perror("Chyba při mapování souboru"); + close(fd); + return NULL; + } + + // Zavření souborového popisovače (není již potřeba po mmap) + close(fd); + + return mapped; +} + +// Funkce pro zrušení mapování +void unmap_file(void *ptr, size_t sz) { + if (!ptr || sz == 0) { + return; + } + + // Zrušení mapování + if (munmap(ptr, sz) == -1) { + perror("Chyba při rušení mapování"); + } +} diff --git a/platform/linux/map_file.h b/platform/linux/map_file.h new file mode 100644 index 0000000..e4495ed --- /dev/null +++ b/platform/linux/map_file.h @@ -0,0 +1,4 @@ +#include +#include +void *map_file_to_memory(const char *name, size_t *sz); +void unmap_file(void *ptr, size_t sz); diff --git a/platform/linux/timer.cpp b/platform/linux/timer.cpp new file mode 100644 index 0000000..6295e85 --- /dev/null +++ b/platform/linux/timer.cpp @@ -0,0 +1,18 @@ +#include "timer.h" +#include +#include "../platform.h" + +#include +int get_timer_value() { + auto n = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(n.time_since_epoch()).count()/TIMERSPEED; +} + +uint32_t get_game_tick_count() { + auto n = std::chrono::steady_clock::now(); + return std::chrono::duration_cast(n.time_since_epoch()).count(); +} + +void sleep_ms(uint32_t x) { + std::this_thread::sleep_for(std::chrono::milliseconds(x)); +} diff --git a/platform/linux/timer.h b/platform/linux/timer.h new file mode 100644 index 0000000..3d5acb5 --- /dev/null +++ b/platform/linux/timer.h @@ -0,0 +1,28 @@ +/* + * timer.h + * + * Created on: 26. 1. 2025 + * Author: ondra + */ + +#ifndef PLATFORM_LINUX_TIMER_H_ +#define PLATFORM_LINUX_TIMER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int get_timer_value(); +uint32_t get_game_tick_count(); +void sleep_ms(uint32_t); + +#ifdef __cplusplus +} +#endif + + + + +#endif /* PLATFORM_LINUX_TIMER_H_ */ diff --git a/platform/platform.cpp b/platform/platform.cpp new file mode 100644 index 0000000..29c602d --- /dev/null +++ b/platform/platform.cpp @@ -0,0 +1,7 @@ + +extern "C" { +void install_wizard() { + +} + +} diff --git a/platform/skeldal_win.h b/platform/platform.h similarity index 75% rename from platform/skeldal_win.h rename to platform/platform.h index 1e2bc34..3437f5d 100644 --- a/platform/skeldal_win.h +++ b/platform/platform.h @@ -6,7 +6,7 @@ #define BGSWITCHBIT 0x0020 -#define SKELDALINI "WSKELDAL.INI" +#define SKELDALINI "wskeldal.ini" #ifdef __cplusplus extern "C" @@ -17,31 +17,17 @@ extern "C" #define _KEYBRD_READY 0 #define _KEYBRD_READ 1 -#define TIMERSPEED 20; +#define TIMERSPEED 20 uint32_t _bios_keybrd(int mode); -//LRESULT GameMainWindowWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - - -void CheckMessageQueue(); - -//void DSReportWindowCreation(HWND hWindow); -char *AutodetectWinAmp(); - -#ifdef __cplusplus - } -#endif - #define RGB888(r,g,b) ((unsigned short)((((r)<<8)&0xF800) | (((g)<<3) & 0x7C0) | ((b)>>3))) #define RGB555(r,g,b) ((unsigned short)(((r)<<11) | ((g)<<6) | (b))) #pragma warning (disable : 4244 4761 4133) -void *LoadDefaultFont(); -void *LoadResourceFont(const char *name); void *map_file_to_memory(const char *name, size_t *sz); void unmap_file(void *ptr, size_t sz); @@ -56,13 +42,17 @@ int stricmp(const char *a, const char *b); #define MIN(a, b) ((a)<(b)?(a):(b)) #define MAX(a, b) ((a)>(b)?(a):(b)) void strupr(char *c); -const char * itoa(int i, char *c, int radix); +const char * int2ascii(int i, char *c, int radix); uint32_t get_game_tick_count(); void sleep_ms(uint32_t); +#ifdef __cplusplus + } +#endif + //------------- BGRAPH DX wrapper ------------------- -#include "BGraph2Dx.h" +#include "sdl/BGraph2.h" #define WM_RELOADMAP (WM_APP+215) #define E_RELOADMAP 40 diff --git a/platform/sdl/BGraph2.cpp b/platform/sdl/BGraph2.cpp new file mode 100644 index 0000000..a2e6b70 --- /dev/null +++ b/platform/sdl/BGraph2.cpp @@ -0,0 +1,112 @@ +#include "BGraph2.h" + +#include "sdl_context.h" +#include "global_context.h" + + +static std::unique_ptr screen_buffer; +static std::unique_ptr buffer2nd; +static uint16_t *render_target; +static uint16_t screen_pitch = 640; + +char DXInit64(char inwindow,int zoom,int monitor, int refresh) { + + SDLContext::DisplayMode mode; + if (inwindow) { + if (zoom) { + mode = SDLContext::double_window; + } else { + mode = SDLContext::native_window; + } + } else { + mode = SDLContext::fullscreen; + } + + screen_pitch = 640; + get_sdl_global_context().init_screen(mode, "Skeldal"); //todo allow change + screen_buffer = std::make_unique(screen_pitch*480); + buffer2nd = std::make_unique(screen_pitch*480); + render_target = screen_buffer.get(); + + return 0; +} + +void DXCloseMode() { + get_sdl_global_context().close_screen(); +} + + +uint16_t *GetScreenAdr() { + return render_target; +} +uint16_t *GetBuffer2nd() { + return buffer2nd.get(); + +} +int32_t GetScreenPitch() { + return screen_pitch; +} +int32_t GetBuffer2ndPitch() { + return screen_pitch; +} +int32_t GetScreenSizeBytes() { + return screen_pitch * 480 * 2; +} + +void RedirectScreen(uint16_t *newaddr) { + render_target = newaddr; +} +void RestoreScreen() { + render_target = screen_buffer.get(); +} +void RedirectScreenBufferSecond() { + render_target = buffer2nd.get(); +} +int DxGetResX() { + return 640; +} +int DxGetResY() { + return 480; +} +void setvesa_displaystart(int x,int y){ + +} +void StripBlt(void *data, unsigned int startline, uint32_t width) { + + unsigned short *start=startline*GetScreenPitch()+GetScreenAdr(); + while (width--) + { + memcpy(start,data,640*2); + data=(void *)(reinterpret_cast(data)+get_sdl_global_context().get_surface_pitch()); + start=start+GetScreenPitch(); + } + +} + +void DXCopyRects64(unsigned short x,unsigned short y,unsigned short xs,unsigned short ys) { + get_sdl_global_context().present_rect(screen_buffer.get(), screen_pitch, x,y,xs,ys); + +} + +void *DxPrepareWalk(int ypos) { + return 0; +} +void DxZoomWalk(void *handle, int ypos, int *points,float phase, void *lodka) { + +} +void DxDoneWalk(void *handle) { + +} + +void *DxPrepareTurn(int ypos) { + return 0; +} +void DxTurn(void *handle, char right, int ypos,int border, float phase, void *lodka) { + +} +void DxDoneTurn(void *handle) { + +} +void DxTurnLeftRight(char right, float phase, int border, int ypos, int *last) { + +} diff --git a/platform/BGraph2Dx.h b/platform/sdl/BGraph2.h similarity index 78% rename from platform/BGraph2Dx.h rename to platform/sdl/BGraph2.h index 38f3be4..2b689d4 100644 --- a/platform/BGraph2Dx.h +++ b/platform/sdl/BGraph2.h @@ -1,3 +1,5 @@ +#include + #ifndef __BGRAPH_DX_WRAPPER_ #define __BGRAPH_DX_WRAPPER_ @@ -5,21 +7,26 @@ extern "C" { #endif -extern int32_t scr_linelen; -extern int32_t scr_linelen2; -extern int32_t dx_linelen; +uint16_t *GetScreenAdr(); +uint16_t *GetBuffer2nd(); +int32_t GetScreenPitch(); +int32_t GetBuffer2ndPitch(); +int32_t GetScreenSizeBytes(); + +void RedirectScreen(uint16_t *newaddr); +void RestoreScreen(); +void RedirectScreenBufferSecond(); //inicializuje a otevira rezim 640x480x16b v DX - otevre okno, pripravi vse pro beh hry //Vraci 1 pri uspechu -char DXInit64(char inwindow,int zoom,int monitor, int refresh); +char DXInit64(char inwindow,int zoom,int monitor, int refresh); //uzavre rezim grafiky void DXCloseMode(); //void DXCopyRects32(unsigned short x,unsigned short y,unsigned short xs,unsigned short ys); void DXCopyRects64(unsigned short x,unsigned short y,unsigned short xs,unsigned short ys); -void DXCopyRects64zoom2(unsigned short x,unsigned short y,unsigned short xs,unsigned short ys); void *DxPrepareWalk(int ypos); void DxZoomWalk(void *handle, int ypos, int *points,float phase, void *lodka); @@ -35,8 +42,6 @@ void DxDialogs(char enable); void setvesa_displaystart(int x,int y); -extern int32_t scr_linelen; -extern int32_t scr_linelen2; void DxSetInitResolution(int x, int y); int DxGetResX(); @@ -55,4 +60,4 @@ void StripBlt(void *data, unsigned int startline, uint32_t width); #endif -#endif \ No newline at end of file +#endif diff --git a/platform/sdl/CMakeLists.txt b/platform/sdl/CMakeLists.txt index 88c0516..b4e0582 100644 --- a/platform/sdl/CMakeLists.txt +++ b/platform/sdl/CMakeLists.txt @@ -1 +1,3 @@ add_subdirectory(tests) + +add_library(skeldal_sdl sdl_context.cpp BGraph2.cpp input.cpp sound.cpp) \ No newline at end of file diff --git a/platform/sdl/global_context.h b/platform/sdl/global_context.h new file mode 100644 index 0000000..0e7a244 --- /dev/null +++ b/platform/sdl/global_context.h @@ -0,0 +1,11 @@ +#pragma once + +#include "sdl_context.h" + +inline SDLContext &get_sdl_global_context () { + static SDLContext sdl_global_context; + return sdl_global_context; +} + + + diff --git a/platform/sdl/input.cpp b/platform/sdl/input.cpp new file mode 100644 index 0000000..332734c --- /dev/null +++ b/platform/sdl/input.cpp @@ -0,0 +1,28 @@ +#include "global_context.h" +#include "input.h" + +char get_control_key_state() { + return 0; //todo +} +char get_shift_key_state() { + return 0; //todo +} +uint32_t _bios_keybrd(int mode) { + return 0; +} + +void SetWheelMapping(char up, char down) { //todo + +} + +static MS_EVENT ms_event = {}; + + + +void get_ms_event(MS_EVENT *event) { + *event = ms_event; +} + +void ShareCPU() { + +} diff --git a/platform/sdl/input.h b/platform/sdl/input.h new file mode 100644 index 0000000..dcf2bfb --- /dev/null +++ b/platform/sdl/input.h @@ -0,0 +1,31 @@ +/* + * input.h + * + * Created on: 26. 1. 2025 + * Author: ondra + */ + +#ifndef PLATFORM_SDL_INPUT_H_ +#define PLATFORM_SDL_INPUT_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +char get_control_key_state(); +char get_shift_key_state(); +uint32_t _bios_keybrd(int mode); +void SetWheelMapping(char up, char down); +void get_ms_event(MS_EVENT *event); +void ShareCPU(); + +#ifdef __cplusplus +} +#endif + + +#endif /* PLATFORM_SDL_INPUT_H_ */ diff --git a/platform/sdl/sdl_context.cpp b/platform/sdl/sdl_context.cpp new file mode 100644 index 0000000..184bec5 --- /dev/null +++ b/platform/sdl/sdl_context.cpp @@ -0,0 +1,186 @@ +#include "sdl_context.h" +#include "../platform.h" + +#include +void SDLContext::SDL_Deleter::operator ()(SDL_Window* window) { + SDL_DestroyWindow(window); +} + +void SDLContext::SDL_Deleter::operator ()(SDL_Renderer* renderer) { + SDL_DestroyRenderer(renderer); +} + +void SDLContext::SDL_Deleter::operator ()(SDL_Surface* surface) { + SDL_FreeSurface(surface); +} + +void SDLContext::SDL_Deleter::operator ()(SDL_Texture* texture) { + SDL_DestroyTexture(texture); +} + +struct SDL_INIT_Context { + + SDL_INIT_Context() { + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0) { + SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); + exit(1); + } + inited = true; + } + ~SDL_INIT_Context() { + SDL_Quit(); + } + + + bool inited = false; +}; + +static SDL_INIT_Context init_context = {}; + +SDLContext::SDLContext() { + if (!init_context.inited) throw std::runtime_error("SDL not inited"); + +} + +void SDLContext::init_screen(DisplayMode mode, const char *title) { + char buff[256]; + + int width = 640; + int height = 480; + if (mode == double_window) { + width*=2; + height*=2; + } + SDL_Window *window = SDL_CreateWindow(title, + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + width, height, SDL_WINDOW_RESIZABLE|(mode==fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0)); + + if (!window) { + snprintf(buff, sizeof(buff), "SDL Error create window: %s\n", SDL_GetError()); + throw std::runtime_error(buff); + } + + _window.reset(window); + SDL_Renderer *renderer = SDL_CreateRenderer(_window.get(), -1, 0); + if (!renderer) { + snprintf(buff,sizeof(buff), "Chyba při vytváření rendereru: %s\n", SDL_GetError()); + throw std::runtime_error(buff); + } + _renderer.reset(renderer); + // Vytvoření softwarového backbufferu (surface) + SDL_Surface *backbuffer = SDL_CreateRGBSurfaceWithFormat(0, 640, 480, 16, SDL_PIXELFORMAT_RGB565); + if (!backbuffer) { + snprintf(buff,sizeof(buff), "Chyba při vytváření surface: %s\n", SDL_GetError()); + throw std::runtime_error(buff); + } + _surface.reset(backbuffer); + // Vytvoření textury pro zobrazení backbufferu + SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, 640, 480); + if (!texture) { + snprintf(buff, sizeof(buff), "Chyba při vytváření textury: %s\n", SDL_GetError()); + throw std::runtime_error(buff); + } + _texture.reset(texture); + + SDL_LockSurface(_surface.get()); + + if (!_timer_event) _timer_event = SDL_RegisterEvents(1); + _fullscreen_mode = mode == fullscreen; +} + +void SDLContext::close_screen() { + SDL_UnlockSurface(_surface.get()); + _texture.reset(); + _surface.reset(); + _renderer.reset(); + _window.reset(); + +} + +uint16_t* SDLContext::get_surface_addr() { + return reinterpret_cast(_surface->pixels); +} + + +int32_t SDLContext::get_surface_pitch() { + return _surface->pitch; +} + + +void SDLContext::charge_timer() { + _active_timer = SDL_AddTimer(1000/TIMERSPEED, [](Uint32 interval, void *param) -> Uint32 { + SDLContext *me = reinterpret_cast(param); + SDL_Event* event = (SDL_Event*)param; + event->type = me->_timer_event; + SDL_PushEvent(event); + return 0; + }, this); + +} +void SDLContext::pool_events() { + if (!_active_timer.has_value()) charge_timer(); + SDL_Event e; + while (true) { + if (SDL_WaitEvent(&e)) { + if (e.type == SDL_QUIT) { + _quit_requested = true; + return; + } + if (e.type == _timer_event) { + break; + } + if (e.type == SDL_KEYDOWN) { + if (e.key.keysym.sym == SDLK_RETURN && (e.key.keysym.mod & KMOD_ALT)) { + _fullscreen_mode = !_fullscreen_mode; + SDL_SetWindowFullscreen(_window.get(), _fullscreen_mode ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + } + } else if (e.type == SDL_MOUSEMOTION) { + int mouseX = e.motion.x; + int mouseY = e.motion.y; + int windowWidth; + int windowHeight; + SDL_GetWindowSize(_window.get(), &windowWidth, &windowHeight); + float normalizedX = (float)mouseX / windowWidth; + float normalizedY = (float)mouseY / windowHeight; + ms_event.event = 1; + ms_event.event_type = 1; + ms_event.x = (int16_t)(640*normalizedX); + ms_event.y = (int16_t)(480*normalizedY); + } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { + int mouseX = e.button.x; + int mouseY = e.button.y; + int button = e.button.button; + int up = e.type == SDL_MOUSEBUTTONUP?1:0; + ms_event.event = 1; + ms_event.event_type = (1<<(2*button-1+up)); + switch (button) { + default: break; + case 1: ms_event.tl1 = !up; break; + case 2: ms_event.tl2 = !up; break; + case 3: ms_event.tl3 = !up; break; + } + } + + } else { + throw std::runtime_error("SDL_WaitEvent error"); + } + } + charge_timer(); + +} + +void SDLContext::present_rect(uint16_t *pixels, unsigned int pitch, + unsigned int x, unsigned int y, unsigned int xs, unsigned ys) { + + auto beg = pixels + y * pitch + y; + SDL_Rect r = {static_cast(x), + static_cast(y), + static_cast(xs), + static_cast(ys)}; + SDL_UpdateTexture(_texture.get(), &r, beg, pitch*2); + SDL_RenderClear(_renderer.get()); + SDL_RenderCopy(_renderer.get(), _texture.get(), NULL, NULL); + SDL_RenderPresent(_renderer.get()); + + +} diff --git a/platform/sdl/sdl_context.h b/platform/sdl/sdl_context.h new file mode 100644 index 0000000..18d46a6 --- /dev/null +++ b/platform/sdl/sdl_context.h @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include +#include + +class SDLContext { +public: + + SDLContext(); + + enum DisplayMode { + native_window, + double_window, + fullscreen + }; + + + void init_screen(DisplayMode mode, const char *title); + + void close_screen(); + + + uint16_t *get_surface_addr(); + int32_t get_surface_pitch(); + + + void pool_events(); + + void present_rect(uint16_t *pixels, unsigned int pitch, unsigned int x, unsigned int y, unsigned int xs,unsigned ys); + +protected: + + struct SDL_Deleter { + void operator()(SDL_Window *); + void operator()(SDL_Renderer *); + void operator()(SDL_Surface *); + void operator()(SDL_Texture *); + }; + + MS_EVENT ms_event; + + std::unique_ptr _window; + std::unique_ptr _renderer; + std::unique_ptr _surface; + std::unique_ptr _texture; + + std::optional _active_timer; + Uint32 _timer_event = 0; + + bool _quit_requested = false; + bool _fullscreen_mode = false; + void charge_timer(); +}; diff --git a/platform/sdl/sound.cpp b/platform/sdl/sound.cpp new file mode 100644 index 0000000..968e44d --- /dev/null +++ b/platform/sdl/sound.cpp @@ -0,0 +1,78 @@ +#include "../platform.h" +#include + +void set_mixing_device(int mix_dev,int mix_freq,...) { + +} +char start_mixing() { + return 0; +} +void stop_mixing() { + +} +void play_sample(int channel,void *sample,int32_t size,int32_t lstart,int32_t sfreq,int type) { + +} +void set_channel_volume(int channel,int left,int right) { + +} +void set_end_of_song_callback(const char * (*cb)(void *), void *ctx) { + +} + +void fade_music() { + +} +int mix_back_sound(int synchro) { + return 0; +} + +//int open_backsound(char *filename); +void change_music(const char *filename) { + +} + +//char *device_name(int device); +//void force_music_volume(int volume); + +//void set_backsnd_freq(int freq); + +char get_channel_state(int channel) { + return 0; +} +void get_channel_volume(int channel,int *left,int *right) { + +} +void mute_channel(int channel) { + +} +void chan_break_loop(int channel) { + +} +void chan_break_ext(int channel,void *org_sample,int32_t size_sample) { + +} + +char set_snd_effect(int funct,int data) { + return 0; +} +char check_snd_effect(int funct) { + return 0; +} +int get_snd_effect(int funct) { + return 0; +} + +void *PrepareVideoSound(int mixfreq, int buffsize) { + return 0; +} +char LoadNextVideoFrame(void *buffer, char *data, int size, short *xlat, short *accnums, int32_t *writepos) { + return 0; + +} +void DoneVideoSound(void *buffer) { + +} + + + diff --git a/platform/sdl/sound.h b/platform/sdl/sound.h new file mode 100644 index 0000000..b1f0614 --- /dev/null +++ b/platform/sdl/sound.h @@ -0,0 +1,15 @@ +/* + * sound.h + * + * Created on: 26. 1. 2025 + * Author: ondra + */ + +#ifndef PLATFORM_SDL_SOUND_H_ +#define PLATFORM_SDL_SOUND_H_ + + + + + +#endif /* PLATFORM_SDL_SOUND_H_ */ diff --git a/platform/sdl/tests/CMakeLists.txt b/platform/sdl/tests/CMakeLists.txt index 89e1abb..27334fc 100644 --- a/platform/sdl/tests/CMakeLists.txt +++ b/platform/sdl/tests/CMakeLists.txt @@ -1,6 +1,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/) -set(testFiles sdl_minimal_test.cpp sdl_surface_test.cpp +set(testFiles sdl_minimal_test.cpp sdl_surface_test.cpp + sdl_mouse.cpp + sdl_update_texture.cpp ) foreach (testFile ${testFiles}) diff --git a/platform/sdl/tests/sdl_mouse.cpp b/platform/sdl/tests/sdl_mouse.cpp new file mode 100644 index 0000000..4d7508c --- /dev/null +++ b/platform/sdl/tests/sdl_mouse.cpp @@ -0,0 +1,79 @@ +#include +#include + +int main(int argc, char* argv[]) { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + std::cerr << "SDL_Init Error: " << SDL_GetError() << std::endl; + return 1; + } + + SDL_Window* window = SDL_CreateWindow("SDL Mouse Event Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_RESIZABLE); + if (!window) { + std::cerr << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl; + SDL_Quit(); + return 1; + } + + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + std::cerr << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl; + SDL_DestroyWindow(window); + SDL_Quit(); + return 1; + } + + SDL_Event e; + bool quit = false; + int isFullscreen = 0; + + while (!quit) { + while (SDL_PollEvent(&e)) { + if (e.type == SDL_QUIT) { + quit = true; + } else if (e.type == SDL_MOUSEMOTION) { + // Získání souřadnic myši + int mouseX = e.motion.x, mouseY = e.motion.y; + + // Přepočet souřadnic na poměr vůči rozměrům okna + int windowWidth, windowHeight; + SDL_GetWindowSize(window, &windowWidth, &windowHeight); + + float normalizedX = (float)mouseX / windowWidth; + float normalizedY = (float)mouseY / windowHeight; + + std::cout << "Mouse moved to: (" << mouseX << ", " << mouseY << ") -> Normalized: (" + << normalizedX << ", " << normalizedY << ")" << std::endl; + } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { + int mouseX = e.button.x, mouseY = e.button.y; + int button = e.button.button; + + if (e.type == SDL_MOUSEBUTTONDOWN) { + std::cout << "Mouse button pressed at: (" << mouseX << ", " << mouseY << ") button " << button << std::endl; + } else { + std::cout << "Mouse button released at: (" << mouseX << ", " << mouseY << ") button " << button << std::endl; + } + } else if (e.type == SDL_MOUSEWHEEL) { + if (e.wheel.y > 0) { + std::cout << "Mouse wheel scrolled up." << std::endl; + } else if (e.wheel.y < 0) { + std::cout << "Mouse wheel scrolled down." << std::endl; + } + } else if (e.type == SDL_KEYDOWN) { + if (e.key.keysym.sym == SDLK_RETURN && (e.key.keysym.mod & KMOD_ALT)) { + // Přepnutí mezi fullscreen a oknem + isFullscreen = !isFullscreen; + SDL_SetWindowFullscreen(window, isFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + } + } + } + + // Renderování a další logika hry + SDL_RenderClear(renderer); + SDL_RenderPresent(renderer); + } + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + return 0; +} diff --git a/platform/sdl/tests/sdl_surface_test.cpp b/platform/sdl/tests/sdl_surface_test.cpp index 339748c..822083d 100644 --- a/platform/sdl/tests/sdl_surface_test.cpp +++ b/platform/sdl/tests/sdl_surface_test.cpp @@ -4,7 +4,7 @@ #define WIDTH 640 #define HEIGHT 480 - +#define PITCH 1024 // Pro optimalizaci paměti (pitch může být širší než WIDTH) int main(int argc, char *argv[]) { // Inicializace SDL @@ -14,14 +14,14 @@ int main(int argc, char *argv[]) { } // Vytvoření SDL okna - SDL_Window *window = SDL_CreateWindow("DOS Game Port", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, 0); + SDL_Window *window = SDL_CreateWindow("DOS Game Port", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_RESIZABLE); if (!window) { fprintf(stderr, "Chyba při vytváření okna: %s\n", SDL_GetError()); SDL_Quit(); return 1; } - // Vytvoření rendereru (pouze pro zobrazení) + // Vytvoření SDL rendereru SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if (!renderer) { fprintf(stderr, "Chyba při vytváření rendereru: %s\n", SDL_GetError()); @@ -30,9 +30,9 @@ int main(int argc, char *argv[]) { return 1; } - // Vytvoření SDL Surface (backbuffer) - SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565,SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT); - if (!texture) { + // Vytvoření softwarového backbufferu (surface) + SDL_Surface *backbuffer = SDL_CreateRGBSurfaceWithFormat(0, PITCH, HEIGHT, 16, SDL_PIXELFORMAT_RGB565); + if (!backbuffer) { fprintf(stderr, "Chyba při vytváření surface: %s\n", SDL_GetError()); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); @@ -40,31 +40,56 @@ int main(int argc, char *argv[]) { return 1; } - void *raw_pixels; - int pitch; - SDL_LockTexture(texture, NULL, &raw_pixels, &pitch); - // Přímý přístup do paměti surface - Uint16 *pixels = reinterpret_cast(raw_pixels); - printf("Adresa pixelů: %p, pitch: %d bajtů\n", (void *)pixels, pitch); - - // Software rendering - příklad kreslení do paměti - for (int y = 0; y < HEIGHT; y++) { - for (int x = 0; x < WIDTH; x++) { - Uint16 color = (x ^ y) & 0xFFFF; // Příklad barvy - pixels[y * (pitch / 2) + x] = color; // Zápis pixelu - } + // Vytvoření textury pro zobrazení backbufferu + SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT); + if (!texture) { + fprintf(stderr, "Chyba při vytváření textury: %s\n", SDL_GetError()); + SDL_FreeSurface(backbuffer); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + return 1; } - SDL_UnlockTexture(texture); + // Hlavní smyčka + int running = 1; + int frame = 0; + while (running) { + frame++; + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = 0; + } + } - SDL_RenderClear(renderer); - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_RenderPresent(renderer); + // Přímý přístup do paměti backbufferu + Uint16 *pixels = (Uint16 *)backbuffer->pixels; + int pitch = backbuffer->pitch / 2; // Pitch v počtu pixelů (ne bajtů) - SDL_Delay(3000); // Zobrazení okna na 3 sekundy + // Software rendering - příklad (čtení a zápis do backbufferu) + for (int y = 0; y < HEIGHT; y++) { + for (int x = 0; x < WIDTH; x++) { + Uint16 color = (x ^ y ^ frame) & 0xFFFF; // Vzor barvy (testovací) + pixels[y * pitch + x] = color; // Zápis pixelu + } + } + + // Kopírování backbufferu do textury + SDL_UpdateTexture(texture, NULL, backbuffer->pixels, backbuffer->pitch); + + // Vykreslení textury na obrazovku + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); + + // Zpoždění pro demonstraci (30 FPS) + SDL_Delay(1000 / 30); + } // Uvolnění zdrojů SDL_DestroyTexture(texture); + SDL_FreeSurface(backbuffer); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); diff --git a/platform/sdl/tests/sdl_update_texture.cpp b/platform/sdl/tests/sdl_update_texture.cpp new file mode 100644 index 0000000..0d1a976 --- /dev/null +++ b/platform/sdl/tests/sdl_update_texture.cpp @@ -0,0 +1,91 @@ +#include +#include +#include + +#define WIDTH 640 +#define HEIGHT 480 +#define PITCH 1024 // Pro optimalizaci paměti (pitch může být širší než WIDTH) + +int main(int argc, char *argv[]) { + // Inicializace SDL + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + fprintf(stderr, "Chyba při inicializaci SDL: %s\n", SDL_GetError()); + return 1; + } + + // Vytvoření SDL okna + SDL_Window *window = SDL_CreateWindow("DOS Game Port", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_RESIZABLE); + if (!window) { + fprintf(stderr, "Chyba při vytváření okna: %s\n", SDL_GetError()); + SDL_Quit(); + return 1; + } + + + // Vytvoření SDL rendereru + SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + fprintf(stderr, "Chyba při vytváření rendereru: %s\n", SDL_GetError()); + SDL_DestroyWindow(window); + SDL_Quit(); + return 1; + } + + + // Vytvoření textury pro zobrazení backbufferu + SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, WIDTH, HEIGHT); + if (!texture) { + fprintf(stderr, "Chyba při vytváření textury: %s\n", SDL_GetError()); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + return 1; + } + + uint16_t *pixels = new uint16_t[HEIGHT*WIDTH]; + int pitch = WIDTH; + + + // Hlavní smyčka + int running = 1; + int frame = 0; + while (running) { + frame++; + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = 0; + } + } + + // Přímý přístup do paměti backbufferu + + // Software rendering - příklad (čtení a zápis do backbufferu) + for (int y = 0; y < HEIGHT; y++) { + for (int x = 0; x < WIDTH; x++) { + Uint16 color = (x ^ y ^ frame) & 0xFFFF; // Vzor barvy (testovací) + pixels[y * pitch + x] = color; // Zápis pixelu + } + } + + // Kopírování backbufferu do textury + SDL_UpdateTexture(texture, NULL, pixels, pitch*2); + + // Vykreslení textury na obrazovku + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); + + // Zpoždění pro demonstraci (30 FPS) + SDL_Delay(1000 / 30); + } + + // Uvolnění zdrojů + SDL_DestroyTexture(texture); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + delete [] pixels; + + return 0; +}