From b1abbf6bfec5c072d4270774a7740cb4098962ad Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 3 Sep 2019 17:33:29 +0100 Subject: [PATCH] Reindented most of the files (still work to be done there) Now support the BW and Color IROM Internal EEPROM support is now nearly correct (still some odd thing happening) --- oswan/col.txt | 65 + oswan/main.cpp | 1035 +++--- oswan/resource.h | 2 +- oswan/source/2xSaI.cpp | 1467 +++++---- oswan/source/SDLptc.h | 441 +-- oswan/source/audio.cpp | 1832 ++++++----- oswan/source/filters/2xsai.h | 83 +- oswan/source/filters/doubled.h | 389 ++- oswan/source/filters/filter_partA.h | 23 +- oswan/source/filters/filter_partB.h | 52 +- oswan/source/filters/filter_partC.h | 157 +- oswan/source/filters/filter_partD.h | 11 +- oswan/source/filters/filter_partE.h | 8 +- oswan/source/filters/halfscanlines.h | 127 +- oswan/source/filters/interpolate.h | 327 +- oswan/source/filters/scanlines.h | 117 +- oswan/source/filters/special.h | 125 +- oswan/source/filters/standard.h | 99 +- oswan/source/filters/super2xsai.h | 85 +- oswan/source/filters/supereagle.h | 85 +- oswan/source/gpu.cpp | 3264 +++++++++++-------- oswan/source/ieeprom.h | 265 +- oswan/source/initialIo.h | 512 +-- oswan/source/io.cpp | 1062 ++++--- oswan/source/log.cpp | 18 +- oswan/source/memory.cpp | 361 ++- oswan/source/memory.h | 3 + oswan/source/nec/nec.cpp | 4411 +++++++++++++++++++++----- oswan/source/nec/nec.h | 35 +- oswan/source/nec/necea.h | 236 +- oswan/source/nec/necinstr.h | 512 +-- oswan/source/nec/necintrf.h | 12 +- oswan/source/nec/necmodrm.h | 29 +- oswan/source/rom.cpp | 169 +- oswan/source/rom.h | 16 +- oswan/source/temp/key.h | 264 +- oswan/source/ticker.h | 2 +- oswan/source/ws.cpp | 531 ++-- oswan/ws.txt | 65 + 39 files changed, 11857 insertions(+), 6440 deletions(-) create mode 100644 oswan/col.txt create mode 100644 oswan/ws.txt diff --git a/oswan/col.txt b/oswan/col.txt new file mode 100644 index 0000000..eeee786 --- /dev/null +++ b/oswan/col.txt @@ -0,0 +1,65 @@ +00000000 ff ff ff ff ff ff c0 ff 00 00 00 00 00 00 00 00 |................| +00000010 00 00 00 00 00 00 00 00 00 00 7f 00 ff ff ff ff |................| +00000020 ff ff ff ff ff ff ff ff ff ff 00 00 00 00 00 00 |................| +00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff |................| +00000050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000060 00 fc ff 01 ff fd ff fd ff fd ff fd ff fd ff fd |................| +00000070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000080 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000100 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000120 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000130 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000140 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000150 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000160 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000170 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000180 00 00 03 03 00 00 00 40 80 00 00 00 00 00 00 00 |.......@........| +00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +000001b0 87 05 8c 09 05 0c 8b 0c 90 00 00 02 00 4c a5 00 |.............L..| +000001c0 80 00 00 00 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +000001d0 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +000001e0 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +000001f0 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +00000200 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000210 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000220 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000230 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000240 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000250 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000260 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000270 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000280 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000290 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000300 00 00 06 06 06 06 06 00 00 00 00 00 01 80 0f 00 |................| +00000310 01 01 01 0f 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000320 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000330 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000340 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000350 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000360 21 19 18 0e 0f 1c 1d 21 0b 18 00 00 00 00 00 00 |!......!........| +00000370 20 01 01 21 01 04 00 01 00 98 3c 7f 4a 01 35 01 | ..!......<.J.5.| +00000380 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000390 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000400 diff --git a/oswan/main.cpp b/oswan/main.cpp index b48456e..60e1c3a 100644 --- a/oswan/main.cpp +++ b/oswan/main.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include //#include "resource.h" @@ -102,34 +102,37 @@ char old_rom_path[4096]; //////////////////////////////////////////////////////////////////////////////// char *gui_getRomPath(HWND hWnd) { - static OPENFILENAME ofn; // common dialog box structure - static char szFile[260]; // buffer for file name - HWND hwnd; // owner window - HANDLE hf; // file handle - static char oldDir[1024]; + static OPENFILENAME ofn; // common dialog box structure + static char szFile[260]; // buffer for file name + HWND hwnd; // owner window + HANDLE hf; // file handle + static char oldDir[1024]; - InitCommonControls(); - _getcwd(oldDir,1024); - szFile[0]=0; - // Initialize OPENFILENAME - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = NULL; - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Wonderswan mono\0*.ws\0Wonderswan color\0*.wsc\0\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - ofn.hInstance=NULL; - // Display the Open dialog box. + InitCommonControls(); + _getcwd(oldDir,1024); + szFile[0]=0; + // Initialize OPENFILENAME + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = NULL; + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Wonderswan mono\0*.ws\0Wonderswan color\0*.wsc\0\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + ofn.hInstance=NULL; + // Display the Open dialog box. - if (GetOpenFileName(&ofn)==TRUE) - return(ofn.lpstrFile); - chdir(oldDir); - return(NULL); + if (GetOpenFileName(&ofn)==TRUE) + { + return(ofn.lpstrFile); + } + + chdir(oldDir); + return(NULL); } //////////////////////////////////////////////////////////////////////////////// // @@ -144,34 +147,37 @@ char *gui_getRomPath(HWND hWnd) //////////////////////////////////////////////////////////////////////////////// char *gui_loadState(HWND hWnd) { - static OPENFILENAME ofn; // common dialog box structure - static char szFile[260]; // buffer for file name - HWND hwnd; // owner window - HANDLE hf; // file handle - static char oldDir[1024]; + static OPENFILENAME ofn; // common dialog box structure + static char szFile[260]; // buffer for file name + HWND hwnd; // owner window + HANDLE hf; // file handle + static char oldDir[1024]; - InitCommonControls(); - _getcwd(oldDir,1024); - szFile[0]=0; - // Initialize OPENFILENAME - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = NULL; - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Wonderswan state\0*.wss\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - ofn.hInstance=NULL; - // Display the Open dialog box. + InitCommonControls(); + _getcwd(oldDir,1024); + szFile[0]=0; + // Initialize OPENFILENAME + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = NULL; + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Wonderswan state\0*.wss\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + ofn.hInstance=NULL; + // Display the Open dialog box. - if (GetOpenFileName(&ofn)==TRUE) - return(ofn.lpstrFile); - chdir(oldDir); - return(NULL); + if (GetOpenFileName(&ofn)==TRUE) + { + return(ofn.lpstrFile); + } + + chdir(oldDir); + return(NULL); } //////////////////////////////////////////////////////////////////////////////// // @@ -186,34 +192,37 @@ char *gui_loadState(HWND hWnd) //////////////////////////////////////////////////////////////////////////////// char *gui_saveState(HWND hWnd) { - static OPENFILENAME ofn; // common dialog box structure - static char szFile[260]; // buffer for file name - HWND hwnd; // owner window - HANDLE hf; // file handle - static char oldDir[1024]; + static OPENFILENAME ofn; // common dialog box structure + static char szFile[260]; // buffer for file name + HWND hwnd; // owner window + HANDLE hf; // file handle + static char oldDir[1024]; - InitCommonControls(); - _getcwd(oldDir,1024); - szFile[0]=0; - // Initialize OPENFILENAME - ZeroMemory(&ofn, sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = NULL; - ofn.lpstrFile = szFile; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Wonderswan state\0*.wss\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = 0; - ofn.hInstance=NULL; - // Display the Open dialog box. + InitCommonControls(); + _getcwd(oldDir,1024); + szFile[0]=0; + // Initialize OPENFILENAME + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = NULL; + ofn.lpstrFile = szFile; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFilter = "Wonderswan state\0*.wss\0"; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = 0; + ofn.hInstance=NULL; + // Display the Open dialog box. - if (GetSaveFileName(&ofn)==TRUE) - return(ofn.lpstrFile); - chdir(oldDir); - return(NULL); + if (GetSaveFileName(&ofn)==TRUE) + { + return(ofn.lpstrFile); + } + + chdir(oldDir); + return(NULL); } //////////////////////////////////////////////////////////////////////////////// // @@ -228,188 +237,281 @@ char *gui_saveState(HWND hWnd) //////////////////////////////////////////////////////////////////////////////// BOOL CALLBACK GuiMainDialogProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { - static BOOL bButton = FALSE; + static BOOL bButton = FALSE; - switch(message) - { - case WM_INITDIALOG: - break; - - case WM_CLOSE: - { - gui_mainDialogRunning=0; - DestroyWindow(hWnd); - return 1; - } - case WM_COMMAND: - { - - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_LOAD)) - { - ws_rom_path=gui_getRomPath(hWnd); - if (ws_rom_path) - SendMessage(hWnd, WM_CLOSE, 0,0); - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_SAVESTATE)) - { - char *path=gui_saveState(hWnd); - if (path) - { - int err=ws_saveState(path); - if (err==0) - MessageBox(hWnd,"State cannot be saved","Error",MB_OK); - else - SendMessage(hWnd, WM_CLOSE, 0,0); - } - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_LOADSTATE)) - { - char *path=gui_loadState(hWnd); - if (path) - { - int err=ws_loadState(path); - if (err==0) - MessageBox(hWnd,"State cannot be loaded","Error",MB_OK); - else - if (err==-1) - MessageBox(hWnd,"Please load the correct rom first","Error",MB_OK); - else - SendMessage(hWnd, WM_CLOSE, 0,0); - } - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_RESET)) - { - gui_command=GUI_COMMAND_RESET; - SendMessage(hWnd, WM_CLOSE, 0,0); - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_CONTINUE)) - { - SendMessage(hWnd, WM_CLOSE, 0,0); - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_EXIT)) - { - SendMessage(hWnd, WM_CLOSE, 0,0); - app_terminate=1; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_STANDARD_MODE)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_STANDARD_MODE),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=0; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_DOUBLESIZE_MODE)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_DOUBLESIZE_MODE),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=1; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SCANLINES_MODE)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SCANLINES_MODE),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=2; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_50PRCTSCANLINES_MODE)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_50PRCTSCANLINES_MODE),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=3; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SPECIAL_MODE)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SPECIAL_MODE),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=4; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_2XSAI)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_2XSAI),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=5; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SUPER2XSAI)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SUPER2XSAI),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=6; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SUPEREAGLE)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SUPEREAGLE),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_videoEnhancementType=7; - gui_command=GUI_COMMAND_FILTER_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_FULLSCREEN)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_FULLSCREEN),BM_GETCHECK ,0,0)==BST_CHECKED) - app_fullscreen=1; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_WINDOWED)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_WINDOWED),BM_GETCHECK ,0,0)==BST_CHECKED) - app_fullscreen=0; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_COLOUR_DEFAULT)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_COLOUR_DEFAULT),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_colourScheme=COLOUR_SCHEME_DEFAULT; - gui_command=GUI_COMMAND_SCHEME_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_COLOUR_AMBER)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_COLOUR_AMBER),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_colourScheme=COLOUR_SCHEME_AMBER; - gui_command=GUI_COMMAND_SCHEME_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_COLOUR_GREEN)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_COLOUR_GREEN),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_colourScheme=COLOUR_SCHEME_GREEN; - gui_command=GUI_COMMAND_SCHEME_CHANGE; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SYSTEM_AUTODETECT)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SYSTEM_AUTODETECT),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_system=WS_SYSTEM_AUTODETECT; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SYSTEM_COLOR)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SYSTEM_COLOR),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_system=WS_SYSTEM_COLOR; - return 1; - } - if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SYSTEM_MONO)) - { - if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SYSTEM_MONO),BM_GETCHECK ,0,0)==BST_CHECKED) - ws_system=WS_SYSTEM_MONO; - return 1; - } - } - } - if(message == WM_INITDIALOG) - return(TRUE); - return (FALSE); + switch(message) + { + case WM_INITDIALOG: + break; + + case WM_CLOSE: + { + gui_mainDialogRunning=0; + DestroyWindow(hWnd); + return 1; + } + + case WM_COMMAND: + { + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_LOAD)) + { + ws_rom_path=gui_getRomPath(hWnd); + + if (ws_rom_path) + { + SendMessage(hWnd, WM_CLOSE, 0,0); + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_SAVESTATE)) + { + char *path=gui_saveState(hWnd); + + if (path) + { + int err=ws_saveState(path); + + if (err==0) + { + MessageBox(hWnd,"State cannot be saved","Error",MB_OK); + } + else + { + SendMessage(hWnd, WM_CLOSE, 0,0); + } + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_LOADSTATE)) + { + char *path=gui_loadState(hWnd); + + if (path) + { + int err=ws_loadState(path); + + if (err==0) + { + MessageBox(hWnd,"State cannot be loaded","Error",MB_OK); + } + else if (err==-1) + { + MessageBox(hWnd,"Please load the correct rom first","Error",MB_OK); + } + else + { + SendMessage(hWnd, WM_CLOSE, 0,0); + } + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_RESET)) + { + gui_command=GUI_COMMAND_RESET; + SendMessage(hWnd, WM_CLOSE, 0,0); + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_CONTINUE)) + { + SendMessage(hWnd, WM_CLOSE, 0,0); + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_BUTTON_EXIT)) + { + SendMessage(hWnd, WM_CLOSE, 0,0); + app_terminate=1; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_STANDARD_MODE)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_STANDARD_MODE),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=0; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_DOUBLESIZE_MODE)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_DOUBLESIZE_MODE),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=1; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SCANLINES_MODE)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SCANLINES_MODE),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=2; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_50PRCTSCANLINES_MODE)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_50PRCTSCANLINES_MODE),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=3; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SPECIAL_MODE)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SPECIAL_MODE),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=4; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_2XSAI)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_2XSAI),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=5; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SUPER2XSAI)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SUPER2XSAI),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=6; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SUPEREAGLE)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SUPEREAGLE),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_videoEnhancementType=7; + } + + gui_command=GUI_COMMAND_FILTER_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_FULLSCREEN)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_FULLSCREEN),BM_GETCHECK,0,0)==BST_CHECKED) + { + app_fullscreen=1; + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_WINDOWED)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_WINDOWED),BM_GETCHECK,0,0)==BST_CHECKED) + { + app_fullscreen=0; + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_COLOUR_DEFAULT)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_COLOUR_DEFAULT),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_colourScheme=COLOUR_SCHEME_DEFAULT; + } + + gui_command=GUI_COMMAND_SCHEME_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_COLOUR_AMBER)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_COLOUR_AMBER),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_colourScheme=COLOUR_SCHEME_AMBER; + } + + gui_command=GUI_COMMAND_SCHEME_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_COLOUR_GREEN)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_COLOUR_GREEN),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_colourScheme=COLOUR_SCHEME_GREEN; + } + + gui_command=GUI_COMMAND_SCHEME_CHANGE; + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SYSTEM_AUTODETECT)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SYSTEM_AUTODETECT),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_system=WS_SYSTEM_AUTODETECT; + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SYSTEM_COLOR)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SYSTEM_COLOR),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_system=WS_SYSTEM_COLOR; + } + + return 1; + } + + if ((HIWORD(wParam)==BN_CLICKED)&&(LOWORD(wParam)==IDC_RADIO_SYSTEM_MONO)) + { + if (SendMessage(GetDlgItem(hWnd, IDC_RADIO_SYSTEM_MONO),BM_GETCHECK,0,0)==BST_CHECKED) + { + ws_system=WS_SYSTEM_MONO; + } + + return 1; + } + } + } + + if(message == WM_INITDIALOG) + { + return(TRUE); + } + + return (FALSE); } //////////////////////////////////////////////////////////////////////////////// // @@ -424,100 +526,132 @@ BOOL CALLBACK GuiMainDialogProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM //////////////////////////////////////////////////////////////////////////////// void gui_open(void) { - HWND hwnd, hCtrl; - MSG msg; + HWND hwnd, hCtrl; + MSG msg; - gui_command=GUI_COMMAND_NONE; - InitCommonControls(); - ws_rom_path=NULL; - hwnd = CreateDialog(gui_hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, (DLGPROC)GuiMainDialogProc); + gui_command=GUI_COMMAND_NONE; + InitCommonControls(); + ws_rom_path=NULL; + hwnd = CreateDialog(gui_hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, (DLGPROC)GuiMainDialogProc); - if (hwnd==NULL) - { - MessageBox(NULL,"Cannot create gui","Error",MB_OK); - return; - } - if (ws_colourScheme==COLOUR_SCHEME_DEFAULT) - SendMessage(GetDlgItem(hwnd, IDC_COLOUR_DEFAULT),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_colourScheme==COLOUR_SCHEME_AMBER) - SendMessage(GetDlgItem(hwnd, IDC_COLOUR_AMBER),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_colourScheme==COLOUR_SCHEME_GREEN) - SendMessage(GetDlgItem(hwnd, IDC_COLOUR_GREEN),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); + if (hwnd==NULL) + { + MessageBox(NULL,"Cannot create gui","Error",MB_OK); + return; + } - if (ws_videoEnhancementType==0) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_STANDARD_MODE),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==1) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_DOUBLESIZE_MODE),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==2) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SCANLINES_MODE),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==3) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_50PRCTSCANLINES_MODE),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==4) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SPECIAL_MODE),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==5) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_2XSAI),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==6) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SUPER2XSAI),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_videoEnhancementType==7) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SUPEREAGLE),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); + if (ws_colourScheme==COLOUR_SCHEME_DEFAULT) + { + SendMessage(GetDlgItem(hwnd, IDC_COLOUR_DEFAULT),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_colourScheme==COLOUR_SCHEME_AMBER) + { + SendMessage(GetDlgItem(hwnd, IDC_COLOUR_AMBER),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_colourScheme==COLOUR_SCHEME_GREEN) + { + SendMessage(GetDlgItem(hwnd, IDC_COLOUR_GREEN),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } - if (app_fullscreen) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_FULLSCREEN),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - SendMessage(GetDlgItem(hwnd, IDC_RADIO_WINDOWED),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); + if (ws_videoEnhancementType==0) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_STANDARD_MODE),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==1) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_DOUBLESIZE_MODE),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==2) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SCANLINES_MODE),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==3) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_50PRCTSCANLINES_MODE),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==4) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SPECIAL_MODE),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==5) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_2XSAI),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==6) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SUPER2XSAI),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_videoEnhancementType==7) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SUPEREAGLE),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } - if (ws_system==WS_SYSTEM_AUTODETECT) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SYSTEM_AUTODETECT),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_system==WS_SYSTEM_COLOR) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SYSTEM_COLOR),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); - else - if (ws_system==WS_SYSTEM_MONO) - SendMessage(GetDlgItem(hwnd, IDC_RADIO_SYSTEM_MONO),BM_SETCHECK ,(WPARAM)BST_CHECKED,0); + if (app_fullscreen) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_FULLSCREEN),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_WINDOWED),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } - gui_mainDialogRunning=1; - ShowWindow(hwnd, SW_SHOWDEFAULT); - UpdateWindow(hwnd); + if (ws_system==WS_SYSTEM_AUTODETECT) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SYSTEM_AUTODETECT),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_system==WS_SYSTEM_COLOR) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SYSTEM_COLOR),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } + else if (ws_system==WS_SYSTEM_MONO) + { + SendMessage(GetDlgItem(hwnd, IDC_RADIO_SYSTEM_MONO),BM_SETCHECK,(WPARAM)BST_CHECKED,0); + } - while(gui_mainDialogRunning) - { - if (GetMessage(&msg, hwnd, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - DestroyWindow(hwnd); + gui_mainDialogRunning=1; + ShowWindow(hwnd, SW_SHOWDEFAULT); + UpdateWindow(hwnd); + + while(gui_mainDialogRunning) + { + if (GetMessage(&msg, hwnd, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + DestroyWindow(hwnd); } #endif int ws_mk_savpath() { - char *w; + char *w; - if (sram_path_explicit) return 0; + if (sram_path_explicit) + { + return 0; + } - if (ws_sram_path != NULL) free(ws_sram_path); - ws_sram_path = (char *)malloc(strlen(ws_rom_path) + 2); - strcpy(ws_sram_path, ws_rom_path); - w = strrchr(ws_sram_path, '.'); - if (NULL == w) - { - strcpy(ws_sram_path, "error.sav"); - return 1; - } - strcpy(w, ".sav"); - return 0; + if (ws_sram_path != NULL) + { + free(ws_sram_path); + } + + ws_sram_path = (char *)malloc(strlen(ws_rom_path) + 2); + strcpy(ws_sram_path, ws_rom_path); + w = strrchr(ws_sram_path, '.'); + + if (NULL == w) + { + strcpy(ws_sram_path, "error.sav"); + return 1; + } + + strcpy(w, ".sav"); + return 0; } @@ -556,95 +690,150 @@ int ws_mk_savpath() int main(int argc, char *argv[]) { - atexit(SDL_Quit); - SDL_Init(SDL_INIT_TIMER); - if (!log_init(LOG_PATH)) printf("Warning: cannot open log file %s\n",LOG_PATH); - fprintf(log_get(),"Wonderswan emulator v0.70/portable (built at: %s %s)\n",__DATE__,__TIME__); - //fprintf(log_get(),"port hacking by hmaon@bumba.net\n"); - ws_videoEnhancementType=1; - //ws_system = WS_SYSTEM_AUTODETECT; - ws_system = WS_SYSTEM_COLOR; + atexit(SDL_Quit); + SDL_Init(SDL_INIT_TIMER); - Init_2xSaI(555); - ws_rom_path = NULL; - /*gui_hInstance=hInstance; - gui_open();*/ + if (!log_init(LOG_PATH)) + { + printf("Warning: cannot open log file %s\n",LOG_PATH); + } - // the hard-core UI, a command line: - for (int n = 1; n < argc; ++n) - { - if (argv[n][0] == '-') - { - switch(argv[n][1]) - { - case 'E': - if (++n < argc) ws_videoEnhancementType = atoi(argv[n]); - else - { - fprintf(stderr, "\n0 - plain\n1 - doubled\n2 - scanlines\n3 - 1/2 bright scanlines\n4 - \"special\"\n5 - 2xSaI\n6 - Super2xSaI (default)\n7 - SuperEagle\n\n"); - exit(1); - } + fprintf(log_get(),"Wonderswan emulator v0.70/portable (built at: %s %s)\n",__DATE__,__TIME__); + //fprintf(log_get(),"port hacking by hmaon@bumba.net\n"); + ws_videoEnhancementType=1; + //ws_system = WS_SYSTEM_AUTODETECT; + ws_system = WS_SYSTEM_COLOR; - break; - case 'C': - if (++n < argc) ws_cyclesByLine = atoi(argv[n]); - fprintf(log_get(), "Cycles by line set to %d\n", ws_cyclesByLine); - break; - case 'w': - if (++n < argc) ws_system = atoi(argv[n]); - fprintf(log_get(), "WonderSwan set to %d\n", ws_system); - break; - case 's': - if (++n < argc) ws_sram_path = argv[n]; - sram_path_explicit = 1; - break; + Init_2xSaI(555); + ws_rom_path = NULL; + /*gui_hInstance=hInstance; + gui_open();*/ - default: - break; - } - } else - { - ws_rom_path = argv[n]; - ws_mk_savpath(); - } - } + // the hard-core UI, a command line: + for (int n = 1; n < argc; ++n) + { + if (argv[n][0] == '-') + { + switch(argv[n][1]) + { + case 'E': + if (++n < argc) + { + ws_videoEnhancementType = atoi(argv[n]); + } + else + { + fprintf(stderr, "\n0 - plain\n1 - doubled\n2 - scanlines\n3 - 1/2 bright scanlines\n4 - \"special\"\n5 - 2xSaI\n6 - Super2xSaI (default)\n7 - SuperEagle\n\n"); + exit(1); + } - while (!app_terminate) - { - if (!ws_rom_path) - { - app_gameRunning=0; - //gui_open(); - exit(0); // nothing to wait for at the moment... - } - if (ws_rom_path) - { - if (ws_init(ws_rom_path)) - { - app_rotated=ws_rotated(); - app_gameRunning=1; - ws_set_system(ws_system); - if (ws_system == WS_SYSTEM_COLOR) - ws_gpu_operatingInColor=1; - ws_set_colour_scheme(ws_colourScheme); - ws_buildHalfBrightnessTable(); - ws_reset(); - switch (ws_videoEnhancementType) - { - case 0: ws_emulate_standard(); break; - case 1: ws_emulate_doubled(); break; - case 2: ws_emulate_scanlines(); break; - case 3: ws_emulate_halfBrightnessScanlines(); break; - case 4: ws_emulate_special(); break; - case 5: ws_emulate_2xSaI(); break; - case 6: ws_emulate_Super2xSaI(); break; - case 7: ws_emulate_SuperEagle(); break; - } - } - ws_done(); - } - } - log_done(); - return(0); + break; + + case 'C': + if (++n < argc) + { + ws_cyclesByLine = atoi(argv[n]); + } + + fprintf(log_get(), "Cycles by line set to %d\n", ws_cyclesByLine); + break; + + case 'w': + if (++n < argc) + { + ws_system = atoi(argv[n]); + } + + fprintf(log_get(), "WonderSwan set to %d\n", ws_system); + break; + + case 's': + if (++n < argc) + { + ws_sram_path = argv[n]; + } + + sram_path_explicit = 1; + break; + + default: + break; + } + } + else + { + ws_rom_path = argv[n]; + ws_mk_savpath(); + } + } + + while (!app_terminate) + { + if (!ws_rom_path) + { + app_gameRunning=0; + //gui_open(); + exit(0); // nothing to wait for at the moment... + } + + if (ws_rom_path) + { + if (ws_init(ws_rom_path)) + { + app_rotated=ws_rotated(); + app_gameRunning=1; + ws_set_system(ws_system); + + if (ws_system == WS_SYSTEM_COLOR) + { + ws_gpu_operatingInColor=1; + } + + ws_set_colour_scheme(ws_colourScheme); + ws_buildHalfBrightnessTable(); + ws_reset(); + + switch (ws_videoEnhancementType) + { + case 0: + ws_emulate_standard(); + break; + + case 1: + ws_emulate_doubled(); + break; + + case 2: + ws_emulate_scanlines(); + break; + + case 3: + ws_emulate_halfBrightnessScanlines(); + break; + + case 4: + ws_emulate_special(); + break; + + case 5: + ws_emulate_2xSaI(); + break; + + case 6: + ws_emulate_Super2xSaI(); + break; + + case 7: + ws_emulate_SuperEagle(); + break; + } + } + + ws_done(); + } + } + + log_done(); + return(0); } diff --git a/oswan/resource.h b/oswan/resource.h index 05fe485..9078fe9 100644 --- a/oswan/resource.h +++ b/oswan/resource.h @@ -39,7 +39,7 @@ #define IDC_RADIO_SUPEREAGLE 1022 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 108 diff --git a/oswan/source/2xSaI.cpp b/oswan/source/2xSaI.cpp index eafef77..901e079 100644 --- a/oswan/source/2xSaI.cpp +++ b/oswan/source/2xSaI.cpp @@ -4,7 +4,7 @@ * (c) Copyright 1996 - 2001 Gary Henderson (gary@daniver.demon.co.uk) and * Jerremy Koot (jkoot@snes9x.com) * - * Super FX C emulator code + * Super FX C emulator code * (c) Copyright 1997 - 1999 Ivar (Ivar@snes9x.com) and * Gary Henderson. * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_. @@ -50,111 +50,168 @@ static u32 greenMask = 0x7E0; int Init_2xSaI(u32 BitFormat) { - if (BitFormat == 565) { - colorMask = 0xF7DEF7DE; - lowPixelMask = 0x08210821; - qcolorMask = 0xE79CE79C; - qlowpixelMask = 0x18631863; - redblueMask = 0xF81F; - greenMask = 0x7E0; - } else if (BitFormat == 555) { - colorMask = 0x7BDE7BDE; - lowPixelMask = 0x04210421; - qcolorMask = 0x739C739C; - qlowpixelMask = 0x0C630C63; - redblueMask = 0x7C1F; - greenMask = 0x3E0; - } else { - return 0; - } + if (BitFormat == 565) + { + colorMask = 0xF7DEF7DE; + lowPixelMask = 0x08210821; + qcolorMask = 0xE79CE79C; + qlowpixelMask = 0x18631863; + redblueMask = 0xF81F; + greenMask = 0x7E0; + } + else if (BitFormat == 555) + { + colorMask = 0x7BDE7BDE; + lowPixelMask = 0x04210421; + qcolorMask = 0x739C739C; + qlowpixelMask = 0x0C630C63; + redblueMask = 0x7C1F; + greenMask = 0x3E0; + } + else + { + return 0; + } - return 1; + return 1; } static inline int GetResult1 (u32 A, u32 B, u32 C, u32 D, - u32 /* E */) + u32 /* E */) { - int x = 0; - int y = 0; - int r = 0; + int x = 0; + int y = 0; + int r = 0; - if (A == C) + if (A == C) + { x += 1; - else if (B == C) + } + else if (B == C) + { y += 1; - if (A == D) + } + + if (A == D) + { x += 1; - else if (B == D) + } + else if (B == D) + { y += 1; - if (x <= 1) + } + + if (x <= 1) + { r += 1; - if (y <= 1) + } + + if (y <= 1) + { r -= 1; - return r; + } + + return r; } static inline int GetResult2 (u32 A, u32 B, u32 C, u32 D, - u32 /* E */) + u32 /* E */) { - int x = 0; - int y = 0; - int r = 0; - - if (A == C) - x += 1; - else if (B == C) - y += 1; - if (A == D) - x += 1; - else if (B == D) - y += 1; - if (x <= 1) - r -= 1; - if (y <= 1) - r += 1; - return r; + int x = 0; + int y = 0; + int r = 0; + + if (A == C) + { + x += 1; + } + else if (B == C) + { + y += 1; + } + + if (A == D) + { + x += 1; + } + else if (B == D) + { + y += 1; + } + + if (x <= 1) + { + r -= 1; + } + + if (y <= 1) + { + r += 1; + } + + return r; } static inline int GetResult (u32 A, u32 B, u32 C, u32 D) { - int x = 0; - int y = 0; - int r = 0; - - if (A == C) - x += 1; - else if (B == C) - y += 1; - if (A == D) - x += 1; - else if (B == D) - y += 1; - if (x <= 1) - r += 1; - if (y <= 1) - r -= 1; - return r; + int x = 0; + int y = 0; + int r = 0; + + if (A == C) + { + x += 1; + } + else if (B == C) + { + y += 1; + } + + if (A == D) + { + x += 1; + } + else if (B == D) + { + y += 1; + } + + if (x <= 1) + { + r += 1; + } + + if (y <= 1) + { + r -= 1; + } + + return r; } static inline u32 INTERPOLATE (u32 A, u32 B) { - if (A != B) { - return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + - (A & B & lowPixelMask)); - } else - return A; + if (A != B) + { + return (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + + (A & B & lowPixelMask)); + } + else + { + return A; + } } static inline u32 Q_INTERPOLATE (u32 A, u32 B, u32 C, u32 D) { - register u32 x = ((A & qcolorMask) >> 2) + - ((B & qcolorMask) >> 2) + - ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2); - register u32 y = (A & qlowpixelMask) + - (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask); - - y = (y >> 2) & qlowpixelMask; - return x + y; + register u32 x = ((A & qcolorMask) >> 2) + + ((B & qcolorMask) >> 2) + + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2); + register u32 y = (A & qlowpixelMask) + + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask); + + y = (y >> 2) & qlowpixelMask; + return x + y; } #define BLUE_MASK565 0x001F001F @@ -166,608 +223,718 @@ static inline u32 Q_INTERPOLATE (u32 A, u32 B, u32 C, u32 D) #define GREEN_MASK555 0x03E003E0 void Super2xSaI (u8 *srcPtr, u32 srcPitch, - u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, - int width, int height) + u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, + int width, int height) { - u16 *bP; - u8 *dP; - u32 inc_bP; - u32 Nextline = srcPitch >> 1; + u16 *bP; + u8 *dP; + u32 inc_bP; + u32 Nextline = srcPitch >> 1; - { + { inc_bP = 1; - - for (; height; height--) { - bP = (u16 *) srcPtr; - dP = (u8 *) dstPtr; - - for (u32 finish = width; finish; finish -= inc_bP) { - u32 color4, color5, color6; - u32 color1, color2, color3; - u32 colorA0, colorA1, colorA2, colorA3, - colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; - u32 product1a, product1b, product2a, product2b; - - //--------------------------------------- B1 B2 - // 4 5 6 S2 - // 1 2 3 S1 - // A1 A2 - - colorB0 = *(bP - Nextline - 1); - colorB1 = *(bP - Nextline); - colorB2 = *(bP - Nextline + 1); - colorB3 = *(bP - Nextline + 2); - - color4 = *(bP - 1); - color5 = *(bP); - color6 = *(bP + 1); - colorS2 = *(bP + 2); - - color1 = *(bP + Nextline - 1); - color2 = *(bP + Nextline); - color3 = *(bP + Nextline + 1); - colorS1 = *(bP + Nextline + 2); - - colorA0 = *(bP + Nextline + Nextline - 1); - colorA1 = *(bP + Nextline + Nextline); - colorA2 = *(bP + Nextline + Nextline + 1); - colorA3 = *(bP + Nextline + Nextline + 2); - - //-------------------------------------- - if (color2 == color6 && color5 != color3) { - product2b = product1b = color2; - } else if (color5 == color3 && color2 != color6) { - product2b = product1b = color5; - } else if (color5 == color3 && color2 == color6) { - register int r = 0; - - r += GetResult (color6, color5, color1, colorA1); - r += GetResult (color6, color5, color4, colorB1); - r += GetResult (color6, color5, colorA2, colorS1); - r += GetResult (color6, color5, colorB2, colorS2); - - if (r > 0) - product2b = product1b = color6; - else if (r < 0) - product2b = product1b = color5; - else { - product2b = product1b = INTERPOLATE (color5, color6); - } - } else { - if (color6 == color3 && color3 == colorA1 - && color2 != colorA2 && color3 != colorA0) - product2b = - Q_INTERPOLATE (color3, color3, color3, color2); - else if (color5 == color2 && color2 == colorA2 - && colorA1 != color3 && color2 != colorA3) - product2b = - Q_INTERPOLATE (color2, color2, color2, color3); - else - product2b = INTERPOLATE (color2, color3); - - if (color6 == color3 && color6 == colorB1 - && color5 != colorB2 && color6 != colorB0) - product1b = - Q_INTERPOLATE (color6, color6, color6, color5); - else if (color5 == color2 && color5 == colorB2 - && colorB1 != color6 && color5 != colorB3) - product1b = - Q_INTERPOLATE (color6, color5, color5, color5); - else - product1b = INTERPOLATE (color5, color6); - } - - if (color5 == color3 && color2 != color6 && color4 == color5 - && color5 != colorA2) - product2a = INTERPOLATE (color2, color5); - else - if (color5 == color1 && color6 == color5 - && color4 != color2 && color5 != colorA0) - product2a = INTERPOLATE (color2, color5); - else - product2a = color2; - - if (color2 == color6 && color5 != color3 && color1 == color2 - && color2 != colorB2) - product1a = INTERPOLATE (color2, color5); - else - if (color4 == color2 && color3 == color2 - && color1 != color5 && color2 != colorB0) - product1a = INTERPOLATE (color2, color5); - else - product1a = color5; - - product1a = product1a | (product1b << 16); - product2a = product2a | (product2b << 16); - - *((u32 *) dP) = product1a; - *((u32 *) (dP + dstPitch)) = product2a; - - bP += inc_bP; - dP += sizeof (u32); - } // end of for ( finish= width etc..) - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; + + for (; height; height--) + { + bP = (u16 *) srcPtr; + dP = (u8 *) dstPtr; + + for (u32 finish = width; finish; finish -= inc_bP) + { + u32 color4, color5, color6; + u32 color1, color2, color3; + u32 colorA0, colorA1, colorA2, colorA3, + colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; + u32 product1a, product1b, product2a, product2b; + + //--------------------------------------- B1 B2 + // 4 5 6 S2 + // 1 2 3 S1 + // A1 A2 + + colorB0 = *(bP - Nextline - 1); + colorB1 = *(bP - Nextline); + colorB2 = *(bP - Nextline + 1); + colorB3 = *(bP - Nextline + 2); + + color4 = *(bP - 1); + color5 = *(bP); + color6 = *(bP + 1); + colorS2 = *(bP + 2); + + color1 = *(bP + Nextline - 1); + color2 = *(bP + Nextline); + color3 = *(bP + Nextline + 1); + colorS1 = *(bP + Nextline + 2); + + colorA0 = *(bP + Nextline + Nextline - 1); + colorA1 = *(bP + Nextline + Nextline); + colorA2 = *(bP + Nextline + Nextline + 1); + colorA3 = *(bP + Nextline + Nextline + 2); + + //-------------------------------------- + if (color2 == color6 && color5 != color3) + { + product2b = product1b = color2; + } + else if (color5 == color3 && color2 != color6) + { + product2b = product1b = color5; + } + else if (color5 == color3 && color2 == color6) + { + register int r = 0; + + r += GetResult (color6, color5, color1, colorA1); + r += GetResult (color6, color5, color4, colorB1); + r += GetResult (color6, color5, colorA2, colorS1); + r += GetResult (color6, color5, colorB2, colorS2); + + if (r > 0) + { + product2b = product1b = color6; + } + else if (r < 0) + { + product2b = product1b = color5; + } + else + { + product2b = product1b = INTERPOLATE (color5, color6); + } + } + else + { + if (color6 == color3 && color3 == colorA1 + && color2 != colorA2 && color3 != colorA0) + product2b = + Q_INTERPOLATE (color3, color3, color3, color2); + else if (color5 == color2 && color2 == colorA2 + && colorA1 != color3 && color2 != colorA3) + product2b = + Q_INTERPOLATE (color2, color2, color2, color3); + else + { + product2b = INTERPOLATE (color2, color3); + } + + if (color6 == color3 && color6 == colorB1 + && color5 != colorB2 && color6 != colorB0) + product1b = + Q_INTERPOLATE (color6, color6, color6, color5); + else if (color5 == color2 && color5 == colorB2 + && colorB1 != color6 && color5 != colorB3) + product1b = + Q_INTERPOLATE (color6, color5, color5, color5); + else + { + product1b = INTERPOLATE (color5, color6); + } + } + + if (color5 == color3 && color2 != color6 && color4 == color5 + && color5 != colorA2) + { + product2a = INTERPOLATE (color2, color5); + } + else if (color5 == color1 && color6 == color5 + && color4 != color2 && color5 != colorA0) + { + product2a = INTERPOLATE (color2, color5); + } + else + { + product2a = color2; + } + + if (color2 == color6 && color5 != color3 && color1 == color2 + && color2 != colorB2) + { + product1a = INTERPOLATE (color2, color5); + } + else if (color4 == color2 && color3 == color2 + && color1 != color5 && color2 != colorB0) + { + product1a = INTERPOLATE (color2, color5); + } + else + { + product1a = color5; + } + + product1a = product1a | (product1b << 16); + product2a = product2a | (product2b << 16); + + *((u32 *) dP) = product1a; + *((u32 *) (dP + dstPitch)) = product2a; + + bP += inc_bP; + dP += sizeof (u32); + } // end of for ( finish= width etc..) + + srcPtr += srcPitch; + dstPtr += dstPitch * 2; // deltaPtr += srcPitch; } // endof: for (; height; height--) - } + } } -void SuperEagle (u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, - u8 *dstPtr, u32 dstPitch, int width, int height) +void SuperEagle (u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, + u8 *dstPtr, u32 dstPitch, int width, int height) { - u8 *dP; - u16 *bP; - //u16 *xP; - u32 inc_bP; + u8 *dP; + u16 *bP; + //u16 *xP; + u32 inc_bP; - { - inc_bP = 1; - - u32 Nextline = srcPitch >> 1; - - for (; height; height--) { - bP = (u16 *) srcPtr; + { + inc_bP = 1; + + u32 Nextline = srcPitch >> 1; + + for (; height; height--) + { + bP = (u16 *) srcPtr; // xP = (u16 *) deltaPtr; - dP = dstPtr; - for (u32 finish = width; finish; finish -= inc_bP) { - u32 color4, color5, color6; - u32 color1, color2, color3; - u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; - u32 product1a, product1b, product2a, product2b; - - colorB1 = *(bP - Nextline); - colorB2 = *(bP - Nextline + 1); - - color4 = *(bP - 1); - color5 = *(bP); - color6 = *(bP + 1); - colorS2 = *(bP + 2); - - color1 = *(bP + Nextline - 1); - color2 = *(bP + Nextline); - color3 = *(bP + Nextline + 1); - colorS1 = *(bP + Nextline + 2); - - colorA1 = *(bP + Nextline + Nextline); - colorA2 = *(bP + Nextline + Nextline + 1); - - // -------------------------------------- - if (color2 == color6 && color5 != color3) { - product1b = product2a = color2; - if ((color1 == color2) || (color6 == colorB2)) { - product1a = INTERPOLATE (color2, color5); - product1a = INTERPOLATE (color2, product1a); - // product1a = color2; - } else { - product1a = INTERPOLATE (color5, color6); - } - - if ((color6 == colorS2) || (color2 == colorA1)) { - product2b = INTERPOLATE (color2, color3); - product2b = INTERPOLATE (color2, product2b); - // product2b = color2; - } else { - product2b = INTERPOLATE (color2, color3); - } - } else if (color5 == color3 && color2 != color6) { - product2b = product1a = color5; - - if ((colorB1 == color5) || (color3 == colorS1)) { - product1b = INTERPOLATE (color5, color6); - product1b = INTERPOLATE (color5, product1b); - // product1b = color5; - } else { - product1b = INTERPOLATE (color5, color6); - } - - if ((color3 == colorA2) || (color4 == color5)) { - product2a = INTERPOLATE (color5, color2); - product2a = INTERPOLATE (color5, product2a); - // product2a = color5; - } else { - product2a = INTERPOLATE (color2, color3); - } - - } else if (color5 == color3 && color2 == color6) { - register int r = 0; - - r += GetResult (color6, color5, color1, colorA1); - r += GetResult (color6, color5, color4, colorB1); - r += GetResult (color6, color5, colorA2, colorS1); - r += GetResult (color6, color5, colorB2, colorS2); - - if (r > 0) { - product1b = product2a = color2; - product1a = product2b = INTERPOLATE (color5, color6); - } else if (r < 0) { - product2b = product1a = color5; - product1b = product2a = INTERPOLATE (color5, color6); - } else { - product2b = product1a = color5; - product1b = product2a = color2; - } - } else { - product2b = product1a = INTERPOLATE (color2, color6); - product2b = - Q_INTERPOLATE (color3, color3, color3, product2b); - product1a = - Q_INTERPOLATE (color5, color5, color5, product1a); - - product2a = product1b = INTERPOLATE (color5, color3); - product2a = - Q_INTERPOLATE (color2, color2, color2, product2a); - product1b = - Q_INTERPOLATE (color6, color6, color6, product1b); - - // product1a = color5; - // product1b = color6; - // product2a = color2; - // product2b = color3; - } - product1a = product1a | (product1b << 16); - product2a = product2a | (product2b << 16); - - *((u32 *) dP) = product1a; - *((u32 *) (dP + dstPitch)) = product2a; + dP = dstPtr; + + for (u32 finish = width; finish; finish -= inc_bP) + { + u32 color4, color5, color6; + u32 color1, color2, color3; + u32 colorA1, colorA2, colorB1, colorB2, colorS1, colorS2; + u32 product1a, product1b, product2a, product2b; + + colorB1 = *(bP - Nextline); + colorB2 = *(bP - Nextline + 1); + + color4 = *(bP - 1); + color5 = *(bP); + color6 = *(bP + 1); + colorS2 = *(bP + 2); + + color1 = *(bP + Nextline - 1); + color2 = *(bP + Nextline); + color3 = *(bP + Nextline + 1); + colorS1 = *(bP + Nextline + 2); + + colorA1 = *(bP + Nextline + Nextline); + colorA2 = *(bP + Nextline + Nextline + 1); + + // -------------------------------------- + if (color2 == color6 && color5 != color3) + { + product1b = product2a = color2; + + if ((color1 == color2) || (color6 == colorB2)) + { + product1a = INTERPOLATE (color2, color5); + product1a = INTERPOLATE (color2, product1a); + // product1a = color2; + } + else + { + product1a = INTERPOLATE (color5, color6); + } + + if ((color6 == colorS2) || (color2 == colorA1)) + { + product2b = INTERPOLATE (color2, color3); + product2b = INTERPOLATE (color2, product2b); + // product2b = color2; + } + else + { + product2b = INTERPOLATE (color2, color3); + } + } + else if (color5 == color3 && color2 != color6) + { + product2b = product1a = color5; + + if ((colorB1 == color5) || (color3 == colorS1)) + { + product1b = INTERPOLATE (color5, color6); + product1b = INTERPOLATE (color5, product1b); + // product1b = color5; + } + else + { + product1b = INTERPOLATE (color5, color6); + } + + if ((color3 == colorA2) || (color4 == color5)) + { + product2a = INTERPOLATE (color5, color2); + product2a = INTERPOLATE (color5, product2a); + // product2a = color5; + } + else + { + product2a = INTERPOLATE (color2, color3); + } + + } + else if (color5 == color3 && color2 == color6) + { + register int r = 0; + + r += GetResult (color6, color5, color1, colorA1); + r += GetResult (color6, color5, color4, colorB1); + r += GetResult (color6, color5, colorA2, colorS1); + r += GetResult (color6, color5, colorB2, colorS2); + + if (r > 0) + { + product1b = product2a = color2; + product1a = product2b = INTERPOLATE (color5, color6); + } + else if (r < 0) + { + product2b = product1a = color5; + product1b = product2a = INTERPOLATE (color5, color6); + } + else + { + product2b = product1a = color5; + product1b = product2a = color2; + } + } + else + { + product2b = product1a = INTERPOLATE (color2, color6); + product2b = + Q_INTERPOLATE (color3, color3, color3, product2b); + product1a = + Q_INTERPOLATE (color5, color5, color5, product1a); + + product2a = product1b = INTERPOLATE (color5, color3); + product2a = + Q_INTERPOLATE (color2, color2, color2, product2a); + product1b = + Q_INTERPOLATE (color6, color6, color6, product1b); + + // product1a = color5; + // product1b = color6; + // product2a = color2; + // product2b = color3; + } + + product1a = product1a | (product1b << 16); + product2a = product2a | (product2b << 16); + + *((u32 *) dP) = product1a; + *((u32 *) (dP + dstPitch)) = product2a; // *xP = color5; - - bP += inc_bP; + + bP += inc_bP; // xP += inc_bP; - dP += sizeof (u32); - } // end of for ( finish= width etc..) - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; + dP += sizeof (u32); + } // end of for ( finish= width etc..) + + srcPtr += srcPitch; + dstPtr += dstPitch * 2; // deltaPtr += srcPitch; - } // endof: for (height; height; height--) - } + } // endof: for (height; height; height--) + } } void _2xSaI (u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, - u8 *dstPtr, u32 dstPitch, int width, int height) + u8 *dstPtr, u32 dstPitch, int width, int height) { - u8 *dP; - u16 *bP; - u32 inc_bP; - - { - inc_bP = 1; - - u32 Nextline = srcPitch >> 1; - - for (; height; height--) { - bP = (u16 *) srcPtr; - dP = dstPtr; - - for (u32 finish = width; finish; finish -= inc_bP) { - - register u32 colorA, colorB; - u32 colorC, colorD, - colorE, colorF, colorG, colorH, - colorI, colorJ, colorK, colorL, - - colorM, colorN, colorO, colorP; - u32 product, product1, product2; - - //--------------------------------------- - // Map of the pixels: I|E F|J - // G|A B|K - // H|C D|L - // M|N O|P - colorI = *(bP - Nextline - 1); - colorE = *(bP - Nextline); - colorF = *(bP - Nextline + 1); - colorJ = *(bP - Nextline + 2); - - colorG = *(bP - 1); - colorA = *(bP); - colorB = *(bP + 1); - colorK = *(bP + 2); - - colorH = *(bP + Nextline - 1); - colorC = *(bP + Nextline); - colorD = *(bP + Nextline + 1); - colorL = *(bP + Nextline + 2); - - colorM = *(bP + Nextline + Nextline - 1); - colorN = *(bP + Nextline + Nextline); - colorO = *(bP + Nextline + Nextline + 1); - colorP = *(bP + Nextline + Nextline + 2); - - if ((colorA == colorD) && (colorB != colorC)) { - if (((colorA == colorE) && (colorB == colorL)) || - ((colorA == colorC) && (colorA == colorF) - && (colorB != colorE) && (colorB == colorJ))) { - product = colorA; - } else { - product = INTERPOLATE (colorA, colorB); - } - - if (((colorA == colorG) && (colorC == colorO)) || - ((colorA == colorB) && (colorA == colorH) - && (colorG != colorC) && (colorC == colorM))) { - product1 = colorA; - } else { - product1 = INTERPOLATE (colorA, colorC); - } - product2 = colorA; - } else if ((colorB == colorC) && (colorA != colorD)) { - if (((colorB == colorF) && (colorA == colorH)) || - ((colorB == colorE) && (colorB == colorD) - && (colorA != colorF) && (colorA == colorI))) { - product = colorB; - } else { - product = INTERPOLATE (colorA, colorB); - } - - if (((colorC == colorH) && (colorA == colorF)) || - ((colorC == colorG) && (colorC == colorD) - && (colorA != colorH) && (colorA == colorI))) { - product1 = colorC; - } else { - product1 = INTERPOLATE (colorA, colorC); - } - product2 = colorB; - } else if ((colorA == colorD) && (colorB == colorC)) { - if (colorA == colorB) { - product = colorA; - product1 = colorA; - product2 = colorA; - } else { - register int r = 0; - - product1 = INTERPOLATE (colorA, colorC); - product = INTERPOLATE (colorA, colorB); - - r += - GetResult1 (colorA, colorB, colorG, colorE, - colorI); - r += - GetResult2 (colorB, colorA, colorK, colorF, - colorJ); - r += - GetResult2 (colorB, colorA, colorH, colorN, - colorM); - r += - GetResult1 (colorA, colorB, colorL, colorO, - colorP); - - if (r > 0) - product2 = colorA; - else if (r < 0) - product2 = colorB; - else { - product2 = - Q_INTERPOLATE (colorA, colorB, colorC, - colorD); - } - } - } else { - product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD); - - if ((colorA == colorC) && (colorA == colorF) - && (colorB != colorE) && (colorB == colorJ)) { - product = colorA; - } else if ((colorB == colorE) && (colorB == colorD) - && (colorA != colorF) && (colorA == colorI)) { - product = colorB; - } else { - product = INTERPOLATE (colorA, colorB); - } - - if ((colorA == colorB) && (colorA == colorH) - && (colorG != colorC) && (colorC == colorM)) { - product1 = colorA; - } else if ((colorC == colorG) && (colorC == colorD) - && (colorA != colorH) && (colorA == colorI)) { - product1 = colorC; - } else { - product1 = INTERPOLATE (colorA, colorC); - } - } - - product = colorA | (product << 16); - product1 = product1 | (product2 << 16); - *((s32 *) dP) = product; - *((u32 *) (dP + dstPitch)) = product1; - - bP += inc_bP; - dP += sizeof (u32); - } // end of for ( finish= width etc..) - - srcPtr += srcPitch; - dstPtr += dstPitch * 2; + u8 *dP; + u16 *bP; + u32 inc_bP; + + { + inc_bP = 1; + + u32 Nextline = srcPitch >> 1; + + for (; height; height--) + { + bP = (u16 *) srcPtr; + dP = dstPtr; + + for (u32 finish = width; finish; finish -= inc_bP) + { + + register u32 colorA, colorB; + u32 colorC, colorD, + colorE, colorF, colorG, colorH, + colorI, colorJ, colorK, colorL, + + colorM, colorN, colorO, colorP; + u32 product, product1, product2; + + //--------------------------------------- + // Map of the pixels: I|E F|J + // G|A B|K + // H|C D|L + // M|N O|P + colorI = *(bP - Nextline - 1); + colorE = *(bP - Nextline); + colorF = *(bP - Nextline + 1); + colorJ = *(bP - Nextline + 2); + + colorG = *(bP - 1); + colorA = *(bP); + colorB = *(bP + 1); + colorK = *(bP + 2); + + colorH = *(bP + Nextline - 1); + colorC = *(bP + Nextline); + colorD = *(bP + Nextline + 1); + colorL = *(bP + Nextline + 2); + + colorM = *(bP + Nextline + Nextline - 1); + colorN = *(bP + Nextline + Nextline); + colorO = *(bP + Nextline + Nextline + 1); + colorP = *(bP + Nextline + Nextline + 2); + + if ((colorA == colorD) && (colorB != colorC)) + { + if (((colorA == colorE) && (colorB == colorL)) || + ((colorA == colorC) && (colorA == colorF) + && (colorB != colorE) && (colorB == colorJ))) + { + product = colorA; + } + else + { + product = INTERPOLATE (colorA, colorB); + } + + if (((colorA == colorG) && (colorC == colorO)) || + ((colorA == colorB) && (colorA == colorH) + && (colorG != colorC) && (colorC == colorM))) + { + product1 = colorA; + } + else + { + product1 = INTERPOLATE (colorA, colorC); + } + + product2 = colorA; + } + else if ((colorB == colorC) && (colorA != colorD)) + { + if (((colorB == colorF) && (colorA == colorH)) || + ((colorB == colorE) && (colorB == colorD) + && (colorA != colorF) && (colorA == colorI))) + { + product = colorB; + } + else + { + product = INTERPOLATE (colorA, colorB); + } + + if (((colorC == colorH) && (colorA == colorF)) || + ((colorC == colorG) && (colorC == colorD) + && (colorA != colorH) && (colorA == colorI))) + { + product1 = colorC; + } + else + { + product1 = INTERPOLATE (colorA, colorC); + } + + product2 = colorB; + } + else if ((colorA == colorD) && (colorB == colorC)) + { + if (colorA == colorB) + { + product = colorA; + product1 = colorA; + product2 = colorA; + } + else + { + register int r = 0; + + product1 = INTERPOLATE (colorA, colorC); + product = INTERPOLATE (colorA, colorB); + + r += + GetResult1 (colorA, colorB, colorG, colorE, + colorI); + r += + GetResult2 (colorB, colorA, colorK, colorF, + colorJ); + r += + GetResult2 (colorB, colorA, colorH, colorN, + colorM); + r += + GetResult1 (colorA, colorB, colorL, colorO, + colorP); + + if (r > 0) + { + product2 = colorA; + } + else if (r < 0) + { + product2 = colorB; + } + else + { + product2 = + Q_INTERPOLATE (colorA, colorB, colorC, + colorD); + } + } + } + else + { + product2 = Q_INTERPOLATE (colorA, colorB, colorC, colorD); + + if ((colorA == colorC) && (colorA == colorF) + && (colorB != colorE) && (colorB == colorJ)) + { + product = colorA; + } + else if ((colorB == colorE) && (colorB == colorD) + && (colorA != colorF) && (colorA == colorI)) + { + product = colorB; + } + else + { + product = INTERPOLATE (colorA, colorB); + } + + if ((colorA == colorB) && (colorA == colorH) + && (colorG != colorC) && (colorC == colorM)) + { + product1 = colorA; + } + else if ((colorC == colorG) && (colorC == colorD) + && (colorA != colorH) && (colorA == colorI)) + { + product1 = colorC; + } + else + { + product1 = INTERPOLATE (colorA, colorC); + } + } + + product = colorA | (product << 16); + product1 = product1 | (product2 << 16); + *((s32 *) dP) = product; + *((u32 *) (dP + dstPitch)) = product1; + + bP += inc_bP; + dP += sizeof (u32); + } // end of for ( finish= width etc..) + + srcPtr += srcPitch; + dstPtr += dstPitch * 2; // deltaPtr += srcPitch; - } // endof: for (height; height; height--) - } + } // endof: for (height; height; height--) + } } static u32 Bilinear (u32 A, u32 B, u32 x) { - unsigned long areaA, areaB; - unsigned long result; - - if (A == B) - return A; - - areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits - areaA = 0x20 - areaB; - - A = (A & redblueMask) | ((A & greenMask) << 16); - B = (B & redblueMask) | ((B & greenMask) << 16); - - result = ((areaA * A) + (areaB * B)) >> 5; - - return (result & redblueMask) | ((result >> 16) & greenMask); + unsigned long areaA, areaB; + unsigned long result; + + if (A == B) + { + return A; + } + + areaB = (x >> 11) & 0x1f; // reduce 16 bit fraction to 5 bits + areaA = 0x20 - areaB; + + A = (A & redblueMask) | ((A & greenMask) << 16); + B = (B & redblueMask) | ((B & greenMask) << 16); + + result = ((areaA * A) + (areaB * B)) >> 5; + + return (result & redblueMask) | ((result >> 16) & greenMask); } static u32 Bilinear4 (u32 A, u32 B, u32 C, u32 D, u32 x, - u32 y) + u32 y) { - unsigned long areaA, areaB, areaC, areaD; - unsigned long result, xy; - - x = (x >> 11) & 0x1f; - y = (y >> 11) & 0x1f; - xy = (x * y) >> 5; - - A = (A & redblueMask) | ((A & greenMask) << 16); - B = (B & redblueMask) | ((B & greenMask) << 16); - C = (C & redblueMask) | ((C & greenMask) << 16); - D = (D & redblueMask) | ((D & greenMask) << 16); - - areaA = 0x20 + xy - x - y; - areaB = x - xy; - areaC = y - xy; - areaD = xy; - - result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5; - - return (result & redblueMask) | ((result >> 16) & greenMask); + unsigned long areaA, areaB, areaC, areaD; + unsigned long result, xy; + + x = (x >> 11) & 0x1f; + y = (y >> 11) & 0x1f; + xy = (x * y) >> 5; + + A = (A & redblueMask) | ((A & greenMask) << 16); + B = (B & redblueMask) | ((B & greenMask) << 16); + C = (C & redblueMask) | ((C & greenMask) << 16); + D = (D & redblueMask) | ((D & greenMask) << 16); + + areaA = 0x20 + xy - x - y; + areaB = x - xy; + areaC = y - xy; + areaD = xy; + + result = ((areaA * A) + (areaB * B) + (areaC * C) + (areaD * D)) >> 5; + + return (result & redblueMask) | ((result >> 16) & greenMask); } void Scale_2xSaI (u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, - u8 *dstPtr, u32 dstPitch, - u32 dstWidth, u32 dstHeight, int width, int height) + u8 *dstPtr, u32 dstPitch, + u32 dstWidth, u32 dstHeight, int width, int height) { - u8 *dP; - u16 *bP; - - u32 w; - u32 h; - u32 dw; - u32 dh; - u32 hfinish; - u32 wfinish; - - u32 Nextline = srcPitch >> 1; - - wfinish = (width - 1) << 16; // convert to fixed point - dw = wfinish / (dstWidth - 1); - hfinish = (height - 1) << 16; // convert to fixed point - dh = hfinish / (dstHeight - 1); - - for (h = 0; h < hfinish; h += dh) { - u32 y1, y2; - - y1 = h & 0xffff; // fraction part of fixed point - bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch)); - dP = dstPtr; - y2 = 0x10000 - y1; - - w = 0; - - for (; w < wfinish;) { - u32 A, B, C, D; - u32 E, F, G, H; - u32 I, J, K, L; - u32 x1, x2, a1, f1, f2; - u32 position, product1; - - position = w >> 16; - A = bP[position]; // current pixel - B = bP[position + 1]; // next pixel - C = bP[position + Nextline]; - D = bP[position + Nextline + 1]; - E = bP[position - Nextline]; - F = bP[position - Nextline + 1]; - G = bP[position - 1]; - H = bP[position + Nextline - 1]; - I = bP[position + 2]; - J = bP[position + Nextline + 2]; - K = bP[position + Nextline + Nextline]; - L = bP[position + Nextline + Nextline + 1]; - - x1 = w & 0xffff; // fraction part of fixed point - x2 = 0x10000 - x1; - - /*0*/ - if (A == B && C == D && A == C) - product1 = A; - else /*1*/ if (A == D && B != C) { - f1 = (x1 >> 1) + (0x10000 >> 2); - f2 = (y1 >> 1) + (0x10000 >> 2); - if (y1 <= f1 && A == J && A != E) // close to B - { - a1 = f1 - y1; - product1 = Bilinear (A, B, a1); - } else if (y1 >= f1 && A == G && A != L) // close to C - { - a1 = y1 - f1; - product1 = Bilinear (A, C, a1); - } - else if (x1 >= f2 && A == E && A != J) // close to B - { - a1 = x1 - f2; - product1 = Bilinear (A, B, a1); - } - else if (x1 <= f2 && A == L && A != G) // close to C - { - a1 = f2 - x1; - product1 = Bilinear (A, C, a1); - } - else if (y1 >= x1) // close to C - { - a1 = y1 - x1; - product1 = Bilinear (A, C, a1); - } - else if (y1 <= x1) // close to B - { - a1 = x1 - y1; - product1 = Bilinear (A, B, a1); - } + u8 *dP; + u16 *bP; + + u32 w; + u32 h; + u32 dw; + u32 dh; + u32 hfinish; + u32 wfinish; + + u32 Nextline = srcPitch >> 1; + + wfinish = (width - 1) << 16; // convert to fixed point + dw = wfinish / (dstWidth - 1); + hfinish = (height - 1) << 16; // convert to fixed point + dh = hfinish / (dstHeight - 1); + + for (h = 0; h < hfinish; h += dh) + { + u32 y1, y2; + + y1 = h & 0xffff; // fraction part of fixed point + bP = (u16 *) (srcPtr + ((h >> 16) * srcPitch)); + dP = dstPtr; + y2 = 0x10000 - y1; + + w = 0; + + for (; w < wfinish;) + { + u32 A, B, C, D; + u32 E, F, G, H; + u32 I, J, K, L; + u32 x1, x2, a1, f1, f2; + u32 position, product1; + + position = w >> 16; + A = bP[position]; // current pixel + B = bP[position + 1]; // next pixel + C = bP[position + Nextline]; + D = bP[position + Nextline + 1]; + E = bP[position - Nextline]; + F = bP[position - Nextline + 1]; + G = bP[position - 1]; + H = bP[position + Nextline - 1]; + I = bP[position + 2]; + J = bP[position + Nextline + 2]; + K = bP[position + Nextline + Nextline]; + L = bP[position + Nextline + Nextline + 1]; + + x1 = w & 0xffff; // fraction part of fixed point + x2 = 0x10000 - x1; + + /*0*/ + if (A == B && C == D && A == C) + { + product1 = A; + } + else /*1*/ if (A == D && B != C) + { + f1 = (x1 >> 1) + (0x10000 >> 2); + f2 = (y1 >> 1) + (0x10000 >> 2); + + if (y1 <= f1 && A == J && A != E) // close to B + { + a1 = f1 - y1; + product1 = Bilinear (A, B, a1); + } + else if (y1 >= f1 && A == G && A != L) // close to C + { + a1 = y1 - f1; + product1 = Bilinear (A, C, a1); + } + else if (x1 >= f2 && A == E && A != J) // close to B + { + a1 = x1 - f2; + product1 = Bilinear (A, B, a1); + } + else if (x1 <= f2 && A == L && A != G) // close to C + { + a1 = f2 - x1; + product1 = Bilinear (A, C, a1); + } + else if (y1 >= x1) // close to C + { + a1 = y1 - x1; + product1 = Bilinear (A, C, a1); + } + else if (y1 <= x1) // close to B + { + a1 = x1 - y1; + product1 = Bilinear (A, B, a1); + } + } + else + + /*2*/ + if (B == C && A != D) + { + f1 = (x1 >> 1) + (0x10000 >> 2); + f2 = (y1 >> 1) + (0x10000 >> 2); + + if (y2 >= f1 && B == H && B != F) // close to A + { + a1 = y2 - f1; + product1 = Bilinear (B, A, a1); + } + else if (y2 <= f1 && B == I && B != K) // close to D + { + a1 = f1 - y2; + product1 = Bilinear (B, D, a1); + } + else if (x2 >= f2 && B == F && B != H) // close to A + { + a1 = x2 - f2; + product1 = Bilinear (B, A, a1); + } + else if (x2 <= f2 && B == K && B != I) // close to D + { + a1 = f2 - x2; + product1 = Bilinear (B, D, a1); + } + else if (y2 >= x1) // close to A + { + a1 = y2 - x1; + product1 = Bilinear (B, A, a1); + } + else if (y2 <= x1) // close to D + { + a1 = x1 - y2; + product1 = Bilinear (B, D, a1); + } + } + /*3*/ + else + { + product1 = Bilinear4 (A, B, C, D, x1, y1); + } + + //end First Pixel + *(u32 *) dP = product1; + dP += 2; + w += dw; } - else - /*2*/ - if (B == C && A != D) - { - f1 = (x1 >> 1) + (0x10000 >> 2); - f2 = (y1 >> 1) + (0x10000 >> 2); - if (y2 >= f1 && B == H && B != F) // close to A - { - a1 = y2 - f1; - product1 = Bilinear (B, A, a1); - } - else if (y2 <= f1 && B == I && B != K) // close to D - { - a1 = f1 - y2; - product1 = Bilinear (B, D, a1); - } - else if (x2 >= f2 && B == F && B != H) // close to A - { - a1 = x2 - f2; - product1 = Bilinear (B, A, a1); - } - else if (x2 <= f2 && B == K && B != I) // close to D - { - a1 = f2 - x2; - product1 = Bilinear (B, D, a1); - } - else if (y2 >= x1) // close to A - { - a1 = y2 - x1; - product1 = Bilinear (B, A, a1); - } - else if (y2 <= x1) // close to D - { - a1 = x1 - y2; - product1 = Bilinear (B, D, a1); - } - } - /*3*/ - else - { - product1 = Bilinear4 (A, B, C, D, x1, y1); - } - - //end First Pixel - *(u32 *) dP = product1; - dP += 2; - w += dw; - } - dstPtr += dstPitch; - } + + dstPtr += dstPitch; + } } diff --git a/oswan/source/SDLptc.h b/oswan/source/SDLptc.h index 5233b7c..5d0c6bf 100644 --- a/oswan/source/SDLptc.h +++ b/oswan/source/SDLptc.h @@ -16,230 +16,301 @@ typedef Sint32 int32; #define stricmp strcasecmp #endif -class Error { +class Error +{ public: - Error(const char *message) { - strcpy(_message, message); - } + Error(const char *message) + { + strcpy(_message, message); + } - void report(void) { - printf("Error: %s\n", _message); - } + void report(void) + { + printf("Error: %s\n", _message); + } private: - char _message[1024]; + char _message[1024]; }; -class Area { +class Area +{ public: - Area(int left, int top, int right, int bottom) { - _left = left; - _top = top; - _right = right; - _bottom = bottom; - } + Area(int left, int top, int right, int bottom) + { + _left = left; + _top = top; + _right = right; + _bottom = bottom; + } - int left(void) const { - return(_left); - } - int right(void) const { - return(_right); - } - int top(void) const { - return(_top); - } - int bottom(void) const { - return(_bottom); - } - int width(void) const { - return(_right-_left); - } - int height(void) const { - return(_bottom-_top); - } + int left(void) const + { + return(_left); + } + int right(void) const + { + return(_right); + } + int top(void) const + { + return(_top); + } + int bottom(void) const + { + return(_bottom); + } + int width(void) const + { + return(_right-_left); + } + int height(void) const + { + return(_bottom-_top); + } private: - int _left, _top, _right, _bottom; + int _left, _top, _right, _bottom; }; - -class Format { + +class Format +{ public: - Format(int bpp, int maskR = 0, int maskG = 0, int maskB = 0) { - _bpp = bpp; - _maskR = maskR; - _maskG = maskG; - _maskB = maskB; - } + Format(int bpp, int maskR = 0, int maskG = 0, int maskB = 0) + { + _bpp = bpp; + _maskR = maskR; + _maskG = maskG; + _maskB = maskB; + } - Uint8 BPP(void) const { return(_bpp); } - Uint32 MaskR(void) const { return(_maskR); } - Uint32 MaskG(void) const { return(_maskG); } - Uint32 MaskB(void) const { return(_maskB); } + Uint8 BPP(void) const + { + return(_bpp); + } + Uint32 MaskR(void) const + { + return(_maskR); + } + Uint32 MaskG(void) const + { + return(_maskG); + } + Uint32 MaskB(void) const + { + return(_maskB); + } private: - Uint8 _bpp; - Uint32 _maskR, _maskG, _maskB; + Uint8 _bpp; + Uint32 _maskR, _maskG, _maskB; }; -class Surface { +class Surface +{ public: - Surface(int w, int h, const Format &format) { - surface = SDL_AllocSurface(SDL_SWSURFACE, w, h, format.BPP(), - format.MaskR(),format.MaskG(),format.MaskB(),0); - if ( surface == NULL ) { - throw Error(SDL_GetError()); - } - nupdates = 0; - is_console = 0; - } - Surface(void) { - nupdates = 0; - is_console = 1; - } - virtual ~Surface() { - if ( ! is_console ) { - SDL_FreeSurface(surface); - } - } + Surface(int w, int h, const Format &format) + { + surface = SDL_AllocSurface(SDL_SWSURFACE, w, h, format.BPP(), + format.MaskR(),format.MaskG(),format.MaskB(),0); - virtual int width(void) { - return surface->w; - } - virtual int height(void) { - return surface->h; - } - virtual int pitch(void) { - return surface->pitch; - } + if ( surface == NULL ) + { + throw Error(SDL_GetError()); + } - virtual void palette(int32 *pcolors) { - SDL_Color colors[256]; + nupdates = 0; + is_console = 0; + } + Surface(void) + { + nupdates = 0; + is_console = 1; + } + virtual ~Surface() + { + if ( ! is_console ) + { + SDL_FreeSurface(surface); + } + } - for ( int i=0; i<256; ++i ) { - colors[i].r = (pcolors[i]>>16)&0xFF; - colors[i].g = (pcolors[i]>>8)&0xFF; - colors[i].b = (pcolors[i]>>0)&0xFF; - } - SDL_SetColors(surface, colors, 0, 256); - } + virtual int width(void) + { + return surface->w; + } + virtual int height(void) + { + return surface->h; + } + virtual int pitch(void) + { + return surface->pitch; + } - virtual void *lock(void) { - if ( SDL_MUSTLOCK(surface) ) { - while ( SDL_LockSurface(surface) < 0 ) { - SDL_Delay(10); - } - } - return (Uint8 *)surface->pixels; - } + virtual void palette(int32 *pcolors) + { + SDL_Color colors[256]; - virtual void unlock(void) { - if ( SDL_MUSTLOCK(surface) ) { - SDL_UnlockSurface(surface); - } - } + for ( int i=0; i<256; ++i ) + { + colors[i].r = (pcolors[i]>>16)&0xFF; + colors[i].g = (pcolors[i]>>8)&0xFF; + colors[i].b = (pcolors[i]>>0)&0xFF; + } - virtual void copy(Surface &dst, - const Area &srcarea, const Area &dstarea) { - SDL_Rect srcrect, dstrect; - srcrect.x = srcarea.left(); - srcrect.y = srcarea.top(); - srcrect.w = srcarea.width(); - srcrect.h = srcarea.height(); - dstrect.x = dstarea.left(); - dstrect.y = dstarea.top(); - dstrect.w = dstarea.width(); - dstrect.h = dstarea.height(); - SDL_BlitSurface(surface, &srcrect, dst.surface, &dstrect); - dst.updates[dst.nupdates++] = dstrect; - } - virtual void copy(Surface &dst) { - SDL_Rect srcrect, dstrect; - srcrect.x = 0; - srcrect.y = 0; - srcrect.w = surface->w; - srcrect.h = surface->h; - dstrect.x = 0; - dstrect.y = 0; - dstrect.w = surface->w; - dstrect.h = surface->h; - SDL_LowerBlit(surface, &srcrect, dst.surface, &dstrect); - dst.updates[dst.nupdates++] = dstrect; - } + SDL_SetColors(surface, colors, 0, 256); + } - virtual void update(void) { - SDL_UpdateRects(surface, nupdates, updates); - nupdates = 0; - } + virtual void *lock(void) + { + if ( SDL_MUSTLOCK(surface) ) + { + while ( SDL_LockSurface(surface) < 0 ) + { + SDL_Delay(10); + } + } + + return (Uint8 *)surface->pixels; + } + + virtual void unlock(void) + { + if ( SDL_MUSTLOCK(surface) ) + { + SDL_UnlockSurface(surface); + } + } + + virtual void copy(Surface &dst, + const Area &srcarea, const Area &dstarea) + { + SDL_Rect srcrect, dstrect; + srcrect.x = srcarea.left(); + srcrect.y = srcarea.top(); + srcrect.w = srcarea.width(); + srcrect.h = srcarea.height(); + dstrect.x = dstarea.left(); + dstrect.y = dstarea.top(); + dstrect.w = dstarea.width(); + dstrect.h = dstarea.height(); + SDL_BlitSurface(surface, &srcrect, dst.surface, &dstrect); + dst.updates[dst.nupdates++] = dstrect; + } + virtual void copy(Surface &dst) + { + SDL_Rect srcrect, dstrect; + srcrect.x = 0; + srcrect.y = 0; + srcrect.w = surface->w; + srcrect.h = surface->h; + dstrect.x = 0; + dstrect.y = 0; + dstrect.w = surface->w; + dstrect.h = surface->h; + SDL_LowerBlit(surface, &srcrect, dst.surface, &dstrect); + dst.updates[dst.nupdates++] = dstrect; + } + + virtual void update(void) + { + SDL_UpdateRects(surface, nupdates, updates); + nupdates = 0; + } protected: - SDL_Surface *surface; - int nupdates; - SDL_Rect updates[1]; /* Definitely increase this.. */ - int is_console; + SDL_Surface *surface; + int nupdates; + SDL_Rect updates[1]; /* Definitely increase this.. */ + int is_console; }; -class Console : public Surface { - int fullscreen; +class Console : public Surface +{ + int fullscreen; public: - Console() : Surface() { - fullscreen=0; - } - ~Console() { - - SDL_Quit(); - } - void close(void) - { - SDL_Quit(); - } - void option(char *option) - { - if (!stricmp(option,"fullscreen output")) - fullscreen=1; - else - if (!stricmp(option,"windowed output")) - fullscreen=0; - } - void open(const char *title, int width, int height, const Format &format) { - Uint32 flags; + Console() : Surface() + { + fullscreen=0; + } + ~Console() + { - if ( SDL_InitSubSystem(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 ) { - throw Error(SDL_GetError()); - } - //flags = (SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN); - flags = (SDL_HWSURFACE|SDL_HWPALETTE); - if (fullscreen) - flags|=SDL_FULLSCREEN; - surface = SDL_SetVideoMode(width, height, 0, flags); - if ( surface == NULL ) { - throw Error(SDL_GetError()); - } - SDL_WM_SetCaption(title, title); - } + SDL_Quit(); + } + void close(void) + { + SDL_Quit(); + } + void option(char *option) + { + if (!stricmp(option,"fullscreen output")) + { + fullscreen=1; + } + else if (!stricmp(option,"windowed output")) + { + fullscreen=0; + } + } + void open(const char *title, int width, int height, const Format &format) + { + Uint32 flags; - int key(void) { - SDL_Event event; - int keyevent; + if ( SDL_InitSubSystem(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 ) + { + throw Error(SDL_GetError()); + } - keyevent = 0; - while ( SDL_PollEvent(&event) ) { - /* Real key events trigger this function */ - if ( event.type == SDL_KEYDOWN ) { - keyevent = 1; - } - /* So do quit events -- let the app know about it */ - if ( event.type == SDL_QUIT ) { - keyevent = 1; - } - } - return(keyevent); - } + //flags = (SDL_HWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN); + flags = (SDL_HWSURFACE|SDL_HWPALETTE); + + if (fullscreen) + { + flags|=SDL_FULLSCREEN; + } + + surface = SDL_SetVideoMode(width, height, 0, flags); + + if ( surface == NULL ) + { + throw Error(SDL_GetError()); + } + + SDL_WM_SetCaption(title, title); + } + + int key(void) + { + SDL_Event event; + int keyevent; + + keyevent = 0; + + while ( SDL_PollEvent(&event) ) + { + /* Real key events trigger this function */ + if ( event.type == SDL_KEYDOWN ) + { + keyevent = 1; + } + + /* So do quit events -- let the app know about it */ + if ( event.type == SDL_QUIT ) + { + keyevent = 1; + } + } + + return(keyevent); + } private: diff --git a/oswan/source/audio.cpp b/oswan/source/audio.cpp index 8c73276..4930d84 100644 --- a/oswan/source/audio.cpp +++ b/oswan/source/audio.cpp @@ -4,7 +4,7 @@ // // Sound information thanks to toshi (wscamp wonderswan emulator) // Note that sound is far from perfect for now. -// +// // fixes by zalas 2002-08-21 // // @@ -33,31 +33,31 @@ #include -#define SNDP ws_ioRam[0x80] -#define SNDV ws_ioRam[0x88] -#define SNDSWP ws_ioRam[0x8C] -#define SWPSTP ws_ioRam[0x8D] -#define NSCTL ws_ioRam[0x8E] -#define WAVDTP ws_ioRam[0x8F] -#define SNDMOD ws_ioRam[0x90] -#define SNDOUT ws_ioRam[0x91] -#define PCSRL ws_ioRam[0x92] -#define PCSRH ws_ioRam[0x93] -#define DMASL ws_ioRam[0x40] -#define DMASH ws_ioRam[0x41] -#define DMASB ws_ioRam[0x42] -#define DMADB ws_ioRam[0x43] -#define DMADL ws_ioRam[0x44] -#define DMADH ws_ioRam[0x45] -#define DMACL ws_ioRam[0x46] -#define DMACH ws_ioRam[0x47] -#define DMACTL ws_ioRam[0x48] -#define SDMASL ws_ioRam[0x4A] -#define SDMASH ws_ioRam[0x4B] -#define SDMASB ws_ioRam[0x4C] -#define SDMACL ws_ioRam[0x4E] -#define SDMACH ws_ioRam[0x4F] -#define SDMACTL ws_ioRam[0x52] +#define SNDP ws_ioRam[0x80] +#define SNDV ws_ioRam[0x88] +#define SNDSWP ws_ioRam[0x8C] +#define SWPSTP ws_ioRam[0x8D] +#define NSCTL ws_ioRam[0x8E] +#define WAVDTP ws_ioRam[0x8F] +#define SNDMOD ws_ioRam[0x90] +#define SNDOUT ws_ioRam[0x91] +#define PCSRL ws_ioRam[0x92] +#define PCSRH ws_ioRam[0x93] +#define DMASL ws_ioRam[0x40] +#define DMASH ws_ioRam[0x41] +#define DMASB ws_ioRam[0x42] +#define DMADB ws_ioRam[0x43] +#define DMADL ws_ioRam[0x44] +#define DMADH ws_ioRam[0x45] +#define DMACL ws_ioRam[0x46] +#define DMACH ws_ioRam[0x47] +#define DMACTL ws_ioRam[0x48] +#define SDMASL ws_ioRam[0x4A] +#define SDMASH ws_ioRam[0x4B] +#define SDMASB ws_ioRam[0x4C] +#define SDMACL ws_ioRam[0x4E] +#define SDMACH ws_ioRam[0x4F] +#define SDMACTL ws_ioRam[0x52] #define BPS 44100 #define BPSMAX AUDIO_MAX_FREQUENCY @@ -71,35 +71,37 @@ #define PH POFF+PDIV*8 #define PL POFF-PDIV*7 -int WaveMap; -int ChPerInit; -int SwpTime; -int SwpStep; -unsigned int SwpCurPeriod; +int WaveMap; +int ChPerInit; +int SwpTime; +int SwpStep; +unsigned int SwpCurPeriod; -int MainVol=15; +int MainVol=15; int HardVol=3; -int ChCurVol[6]={-1,-1,-1,-1,-1,-1}; -int ChCurPer[6]={-1,-1,-1,-1,-1,-1}; -long ChCurPan[6]={-1,-1,-1,-1,-1,-1}; +int ChCurVol[6]= {-1,-1,-1,-1,-1,-1}; +int ChCurPer[6]= {-1,-1,-1,-1,-1,-1}; +long ChCurPan[6]= {-1,-1,-1,-1,-1,-1}; -unsigned char PData[4][BUFSIZE]; -unsigned char PDataP[BUFSIZEP<<4]; -unsigned char PDataN[8][BUFSIZEN]; +unsigned char PData[4][BUFSIZE]; +unsigned char PDataP[BUFSIZEP<<4]; +unsigned char PDataN[8][BUFSIZEN]; -int RandData[BUFSIZEN]; +int RandData[BUFSIZEN]; -int CntSwp=0; -int PcmWrPos=0; +int CntSwp=0; +int PcmWrPos=0; -const long TblChVol[16]={ // n/15 n=0~15 - -10000,-2352,-1750,-1398,-1148,-954,-796,-662, - -546,-444,-352,-269,-194,-124,-60,0 -}; +const long TblChVol[16]= // n/15 n=0~15 +{ + -10000,-2352,-1750,-1398,-1148,-954,-796,-662, + -546,-444,-352,-269,-194,-124,-60,0 + }; -const long TblMainVol[4]={ // 1,1/2,1/4,1/8 - 0,-602,-1204,-1806 +const long TblMainVol[4]= // 1,1/2,1/4,1/8 +{ + 0,-602,-1204,-1806 }; //////////////////////////////////////////////////////////////////////////////// @@ -120,7 +122,7 @@ HAC ws_audio_sweep_voice; AUDIOWAVE ws_audio_pcm_wave[4]; AUDIOWAVE ws_audio_noise_wave; AUDIOWAVE ws_audio_sweep_wave; - + UINT32 ws_audio_channel_isPlaying[6]; static unsigned int ws_audio_log; @@ -137,12 +139,12 @@ static unsigned int ws_audio_log; //////////////////////////////////////////////////////////////////////////////// void ws_audio_init(void) { - fprintf(log_get(), "audio init\n"); - fflush(log_get()); - ws_audio_log=0; - ws_audio_seal_init(); - ws_audio_reset(); - SDL_PauseAudio(0); + fprintf(log_get(), "audio init\n"); + fflush(log_get()); + ws_audio_log=0; + ws_audio_seal_init(); + ws_audio_reset(); + SDL_PauseAudio(0); } //////////////////////////////////////////////////////////////////////////////// // @@ -157,18 +159,24 @@ void ws_audio_init(void) //////////////////////////////////////////////////////////////////////////////// void ws_audio_reset(void) { - WaveMap=-1; - for (int i=0;i<6;i++) - { - ws_audio_stop_channel(i); - ws_audio_play_channel(i); - ws_audio_set_channel_frequency(i,0); - if (i!=4) - ws_audio_set_channel_pan(i,0,0); - ws_audio_clear_channel(i); - } - ws_audio_set_channel_frequency(4,0); - ws_audio_set_channel_frequency(4,1792); + WaveMap=-1; + + for (int i=0; i<6; i++) + { + ws_audio_stop_channel(i); + ws_audio_play_channel(i); + ws_audio_set_channel_frequency(i,0); + + if (i!=4) + { + ws_audio_set_channel_pan(i,0,0); + } + + ws_audio_clear_channel(i); + } + + ws_audio_set_channel_frequency(4,0); + ws_audio_set_channel_frequency(4,1792); } //////////////////////////////////////////////////////////////////////////////// // @@ -183,194 +191,245 @@ void ws_audio_reset(void) //////////////////////////////////////////////////////////////////////////////// void ws_audio_port_write(Uint32 port, Uint8 value) { - Uint32 n,i,j,k,b; + Uint32 n,i,j,k,b; - //printf("0x%2x <- 0x%2x\n", port, (Uint32)value); + //printf("0x%2x <- 0x%2x\n", port, (Uint32)value); - ws_ioRam[port]=value; + ws_ioRam[port]=value; - switch (port) - { - case 0x48: if (value&0x80) - { - n=(DMACH<<8)|DMACL; - i=(DMASB<<16)|(DMASH<<8)|DMASL; - j=(DMADH<<8)|DMADL; - for(k=0;k>16)&0xFF); - DMASH=(Uint8)((i>>8)&0xFF); - DMASL=(Uint8)(i&0xFF); - DMADB=(Uint8)((j>>16)&0xFF); - DMADH=(Uint8)((j>>8)&0xFF); - DMADL=(Uint8)(j&0xFF); - DMACH=(Uint8)((n>>8)&0xFF); - DMACL=(Uint8)(n&0xFF); - value&=0x7F; - } - break; - case 0x80: - case 0x81: i=(((unsigned int)ws_ioRam[0x81])<<8)+((unsigned int)ws_ioRam[0x80]); - ws_audio_set_channel_frequency(0,i); - dbgprintf("0x%2x ... freq = 0x%x\n", port, i); - break; - case 0x82: - case 0x83: i=(((unsigned int)ws_ioRam[0x83])<<8)+((unsigned int)ws_ioRam[0x82]); - ws_audio_set_channel_frequency(1,i); - break; - case 0x84: - case 0x85: i=(((unsigned int)ws_ioRam[0x85])<<8)+((unsigned int)ws_ioRam[0x84]); - ws_audio_set_channel_frequency(2,i); - break; - case 0x86: - case 0x87: i=(((unsigned int)(ws_ioRam[0x87]&0x07))<<8)+((unsigned int)ws_ioRam[0x86]); - ws_audio_set_channel_frequency(5,i); - ws_audio_set_channel_frequency(3,i); - break; - case 0x88: - dbgprintf("0x88 <- 0x%2x\n", value); - // fflush(stdout); - ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); - break; - case 0x89: - dbgprintf("0x89 <- 0x%2x\n", value); - // fflush(stdout); - ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); - break; - case 0x8A: - ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); - break; - case 0x8B: - ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); - ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); - break; - case 0x8C: - SwpStep=(signed char)value; - break; - case 0x8D: - //SwpTime=(((unsigned int)value)+1)<<5; - SwpTime=(((unsigned int)value)+1)<<5; - break; - case 0x8E: - dbgprintf("0x8E <- 0x%2x = %d %d %d %d %d %d %d %d \n", value, value & 0x80 ? 1 : 0, value & 0x40 ? 1 : 0, value & 0x20 ? 1 : 0, value & 0x10 ? 1 : 0, value & 8 ? 1 : 0, value & 4 ? 1 : 0, value & 2 ? 1 : 0, value & 1); - //fflush(stdout); /* ctl */ - if (value & 0x10) - { - ws_audio_set_channel_pdata(5,value&0x07); - } else - { - // hmmm.. shut up! - } - break; - case 0x8F: - WaveMap=((unsigned int)value)<<6; - break; - case 0x90: - dbgprintf("0x90 <- 0x%2x = %d %d %d %d %d %d %d %d \n", value, value & 0x80 ? 1 : 0, value & 0x40 ? 1 : 0, value & 0x20 ? 1 : 0, value & 0x10 ? 1 : 0, value & 8 ? 1 : 0, value & 4 ? 1 : 0, value & 2 ? 1 : 0, value & 1); - //fflush(stdout); /* ctl */ + switch (port) + { + case 0x48: + if (value&0x80) + { + n=(DMACH<<8)|DMACL; + i=(DMASB<<16)|(DMASH<<8)|DMASL; + j=(DMADH<<8)|DMADL; - if (value&0x01) - { - ws_audio_play_channel(0); + for(k=0; k>16)&0xFF); + DMASH=(Uint8)((i>>8)&0xFF); + DMASL=(Uint8)(i&0xFF); + DMADB=(Uint8)((j>>16)&0xFF); + DMADH=(Uint8)((j>>8)&0xFF); + DMADL=(Uint8)(j&0xFF); + DMACH=(Uint8)((n>>8)&0xFF); + DMACL=(Uint8)(n&0xFF); + value&=0x7F; + } + + break; + + case 0x80: + case 0x81: + i=(((unsigned int)ws_ioRam[0x81])<<8)+((unsigned int)ws_ioRam[0x80]); + ws_audio_set_channel_frequency(0,i); + dbgprintf("0x%2x ... freq = 0x%x\n", port, i); + break; + + case 0x82: + case 0x83: + i=(((unsigned int)ws_ioRam[0x83])<<8)+((unsigned int)ws_ioRam[0x82]); + ws_audio_set_channel_frequency(1,i); + break; + + case 0x84: + case 0x85: + i=(((unsigned int)ws_ioRam[0x85])<<8)+((unsigned int)ws_ioRam[0x84]); + ws_audio_set_channel_frequency(2,i); + break; + + case 0x86: + case 0x87: + i=(((unsigned int)(ws_ioRam[0x87]&0x07))<<8)+((unsigned int)ws_ioRam[0x86]); + ws_audio_set_channel_frequency(5,i); + ws_audio_set_channel_frequency(3,i); + break; + + case 0x88: + dbgprintf("0x88 <- 0x%2x\n", value); + // fflush(stdout); + ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); + break; + + case 0x89: + dbgprintf("0x89 <- 0x%2x\n", value); + // fflush(stdout); + ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); + break; + + case 0x8A: + ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); + break; + + case 0x8B: + ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); + ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); + break; + + case 0x8C: + SwpStep=(signed char)value; + break; + + case 0x8D: + //SwpTime=(((unsigned int)value)+1)<<5; + SwpTime=(((unsigned int)value)+1)<<5; + break; + + case 0x8E: + dbgprintf("0x8E <- 0x%2x = %d %d %d %d %d %d %d %d \n", value, value & 0x80 ? 1 : 0, value & 0x40 ? 1 : 0, value & 0x20 ? 1 : 0, value & 0x10 ? 1 : 0, value & 8 ? 1 : 0, value & 4 ? 1 : 0, value & 2 ? 1 : 0, value & 1); + + //fflush(stdout); /* ctl */ + if (value & 0x10) + { + ws_audio_set_channel_pdata(5,value&0x07); + } + else + { + // hmmm.. shut up! + } + + break; + + case 0x8F: + WaveMap=((unsigned int)value)<<6; + break; + + case 0x90: + dbgprintf("0x90 <- 0x%2x = %d %d %d %d %d %d %d %d \n", value, value & 0x80 ? 1 : 0, value & 0x40 ? 1 : 0, value & 0x20 ? 1 : 0, value & 0x10 ? 1 : 0, value & 8 ? 1 : 0, value & 4 ? 1 : 0, value & 2 ? 1 : 0, value & 1); + + //fflush(stdout); /* ctl */ + + if (value&0x01) + { + ws_audio_play_channel(0); // for(int ii=0;ii<32;ii++) // fprintf(log_get(),"%02X ",PData[0][ii]); // fprintf(log_get(),"\n"); - } - else - ws_audio_stop_channel(0); + } + else + { + ws_audio_stop_channel(0); + } - if ((value&0x22)==0x02) - ws_audio_play_channel(1); - else - ws_audio_stop_channel(1); + if ((value&0x22)==0x02) + { + ws_audio_play_channel(1); + } + else + { + ws_audio_stop_channel(1); + } - if (value&0x04) - ws_audio_play_channel(2); - else - ws_audio_stop_channel(2); + if (value&0x04) + { + ws_audio_play_channel(2); + } + else + { + ws_audio_stop_channel(2); + } - if ((value&0x88)==0x08) - ws_audio_play_channel(3); - else - ws_audio_stop_channel(3); + if ((value&0x88)==0x08) + { + ws_audio_play_channel(3); + } + else + { + ws_audio_stop_channel(3); + } - if ((value&0x88)==0x88) - ws_audio_play_channel(5); - else - ws_audio_stop_channel(5); - break; - case 0x91: -/* printf("Channels [ %c %c %c %c %c %c %c %c ]\n", - (value>>0)&1?'S':'M', - (value>>1)&1?'H':'l', - (value>>2)&1?'H':'l', - (value>>3)&1?'E':' ', - (value>>4)&1?'4':' ', - (value>>5)&1?'5':' ', - (value>>6)&1?'6':' ', - (value>>7)&1?'E':' '); - //0x91 <- %x\n", value); - fflush(stdout);*/ - //MainVol=0; - value|=0x80; - HardVol = (value>>1)&0x3; + if ((value&0x88)==0x88) + { + ws_audio_play_channel(5); + } + else + { + ws_audio_stop_channel(5); + } - ws_ioRam[port]=value; // Always have external speaker + break; - value=ws_ioRam[0x88]; + case 0x91: + /* printf("Channels [ %c %c %c %c %c %c %c %c ]\n", + (value>>0)&1?'S':'M', + (value>>1)&1?'H':'l', + (value>>2)&1?'H':'l', + (value>>3)&1?'E':' ', + (value>>4)&1?'4':' ', + (value>>5)&1?'5':' ', + (value>>6)&1?'6':' ', + (value>>7)&1?'E':' '); + //0x91 <- %x\n", value); + fflush(stdout);*/ + //MainVol=0; + value|=0x80; + HardVol = (value>>1)&0x3; - ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); + ws_ioRam[port]=value; // Always have external speaker - value=ws_ioRam[0x89]; + value=ws_ioRam[0x88]; - ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); + ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); - value=ws_ioRam[0x8A]; + value=ws_ioRam[0x89]; - ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); + ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); - value=ws_ioRam[0x8B]; + value=ws_ioRam[0x8A]; - ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); + ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); - ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); + value=ws_ioRam[0x8B]; - break; - case 0x92: - dbgprintf("0x92 <- 0x%2x\n", value); fflush(stdout); - break; - case 0x93: - dbgprintf("0x93 <- 0x%2x\n", value); fflush(stdout); - break; - case 0x94: - dbgprintf("0x94 <- 0x%2x\n", value); fflush(stdout); - MainVol=(value&0x0f)>>2; - value=ws_ioRam[0x88]; + ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); - ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); + ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); - value=ws_ioRam[0x89]; + break; - ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); + case 0x92: + dbgprintf("0x92 <- 0x%2x\n", value); + fflush(stdout); + break; - value=ws_ioRam[0x8A]; + case 0x93: + dbgprintf("0x93 <- 0x%2x\n", value); + fflush(stdout); + break; - ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); + case 0x94: + dbgprintf("0x94 <- 0x%2x\n", value); + fflush(stdout); + MainVol=(value&0x0f)>>2; + value=ws_ioRam[0x88]; - value=ws_ioRam[0x8B]; + ws_audio_set_channel_pan(0,(value&0xF0)>>4,value&0x0F); - ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); + value=ws_ioRam[0x89]; - ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); + ws_audio_set_channel_pan(1,(value&0xF0)>>4,value&0x0F); - break; - } + value=ws_ioRam[0x8A]; + + ws_audio_set_channel_pan(2,(value&0xF0)>>4,value&0x0F); + + value=ws_ioRam[0x8B]; + + ws_audio_set_channel_pan(3,(value&0xF0)>>4,value&0x0F); + + ws_audio_set_channel_pan(5,(value&0xF0)>>4,value&0x0F); + + break; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -385,7 +444,7 @@ void ws_audio_port_write(Uint32 port, Uint8 value) //////////////////////////////////////////////////////////////////////////////// BYTE ws_audio_port_read(BYTE port) { - return(ws_ioRam[port]); + return(ws_ioRam[port]); } //////////////////////////////////////////////////////////////////////////////// // @@ -400,7 +459,7 @@ BYTE ws_audio_port_read(BYTE port) //////////////////////////////////////////////////////////////////////////////// void ws_audio_done(void) { - ws_audio_seal_done(); + ws_audio_seal_done(); } //////////////////////////////////////////////////////////////////////////////// // @@ -416,77 +475,84 @@ void ws_audio_done(void) unsigned int ws_audio_mrand(unsigned int Degree) { #define BIT(n) (1<InputBit-1; - int XorReg=0; - int Masked; + static POLYNOMIAL *pTbl=TblMask; + static int ShiftReg=pTbl->InputBit-1; + int XorReg=0; + int Masked; - if(pTbl->N!=Degree) - { - pTbl=TblMask; - while(pTbl->N) - { - if(pTbl->N==Degree) - { - break; - } - pTbl++; - } - if(!pTbl->N) - { - pTbl--; - } + if(pTbl->N!=Degree) + { + pTbl=TblMask; - ShiftReg&=pTbl->InputBit-1; - if(!ShiftReg) - { - ShiftReg=pTbl->InputBit-1; - } - } + while(pTbl->N) + { + if(pTbl->N==Degree) + { + break; + } - Masked=ShiftReg&pTbl->Mask; - while(Masked) - { - XorReg^=Masked&0x01; - Masked>>=1; - } + pTbl++; + } - if(XorReg) - { - ShiftReg|=pTbl->InputBit; - } - else - { - ShiftReg&=~pTbl->InputBit; - } - ShiftReg>>=1; + if(!pTbl->N) + { + pTbl--; + } - return ShiftReg; + ShiftReg&=pTbl->InputBit-1; + + if(!ShiftReg) + { + ShiftReg=pTbl->InputBit-1; + } + } + + Masked=ShiftReg&pTbl->Mask; + + while(Masked) + { + XorReg^=Masked&0x01; + Masked>>=1; + } + + if(XorReg) + { + ShiftReg|=pTbl->InputBit; + } + else + { + ShiftReg&=~pTbl->InputBit; + } + + ShiftReg>>=1; + + return ShiftReg; } @@ -503,141 +569,148 @@ unsigned int ws_audio_mrand(unsigned int Degree) //////////////////////////////////////////////////////////////////////////////// int ws_audio_seal_init(void) { - int i, j; - AUDIOINFO info; - AUDIOCAPS caps; - UINT rc; - UINT nDevId; - - fprintf(log_get(),"audio: using seal audio library\n"); - /* initialize audio library */ - AInitialize(); + int i, j; + AUDIOINFO info; + AUDIOCAPS caps; + UINT rc; + UINT nDevId; - /* show registered device drivers */ - fprintf(log_get(),"audio: registered sound devices:\n"); - for (nDevId = 0; nDevId < AGetAudioNumDevs(); nDevId++) { - AGetAudioDevCaps(nDevId, &caps); - fprintf(log_get(),"audio: %2d. %s\n", nDevId, caps.szProductName); - } + fprintf(log_get(),"audio: using seal audio library\n"); + /* initialize audio library */ + AInitialize(); - /* open audio device */ - //info.nDeviceId = AUDIO_DEVICE_MAPPER; - info.nDeviceId = 0; - info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO; // | AUDIO_MIXER_BASS; - info.nSampleRate = 44100; - if ((rc = AOpenAudio(&info)) != AUDIO_ERROR_NONE) - { - CHAR szText[80]; - AGetErrorText(rc, szText, sizeof(szText) - 1); - fprintf(log_get(),"audio: error: %s\n", szText); fflush(log_get()); - return(0); - } - - // open 6 voices ( 4 pcm, one noise, and one sweep) - AOpenVoices(6); + /* show registered device drivers */ + fprintf(log_get(),"audio: registered sound devices:\n"); - // create the 4 pcm channels - for (i=0;i<4;i++) - { - // create the channel - ACreateAudioVoice(&ws_audio_pcm_voice[i]); - ASetVoiceVolume ( ws_audio_pcm_voice[i], AUDIO_MAX_VOLUME); - ASetVoicePanning ( ws_audio_pcm_voice[i], AUDIO_MIN_PANNING); + for (nDevId = 0; nDevId < AGetAudioNumDevs(); nDevId++) + { + AGetAudioDevCaps(nDevId, &caps); + fprintf(log_get(),"audio: %2d. %s\n", nDevId, caps.szProductName); + } + + /* open audio device */ + //info.nDeviceId = AUDIO_DEVICE_MAPPER; + info.nDeviceId = 0; + info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO; // | AUDIO_MIXER_BASS; + info.nSampleRate = 44100; + + if ((rc = AOpenAudio(&info)) != AUDIO_ERROR_NONE) + { + CHAR szText[80]; + AGetErrorText(rc, szText, sizeof(szText) - 1); + fprintf(log_get(),"audio: error: %s\n", szText); + fflush(log_get()); + return(0); + } + + // open 6 voices ( 4 pcm, one noise, and one sweep) + AOpenVoices(6); + + // create the 4 pcm channels + for (i=0; i<4; i++) + { + // create the channel + ACreateAudioVoice(&ws_audio_pcm_voice[i]); + ASetVoiceVolume ( ws_audio_pcm_voice[i], AUDIO_MAX_VOLUME); + ASetVoicePanning ( ws_audio_pcm_voice[i], AUDIO_MIN_PANNING); - // create a looped sound buffer - ws_audio_pcm_wave[i].nSampleRate = info.nSampleRate; - ws_audio_pcm_wave[i].dwLength = BUFSIZE; - ws_audio_pcm_wave[i].dwLoopStart = 0; - ws_audio_pcm_wave[i].dwLoopEnd = ws_audio_pcm_wave[i].dwLength; - ws_audio_pcm_wave[i].wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; + // create a looped sound buffer + ws_audio_pcm_wave[i].nSampleRate = info.nSampleRate; + ws_audio_pcm_wave[i].dwLength = BUFSIZE; + ws_audio_pcm_wave[i].dwLoopStart = 0; + ws_audio_pcm_wave[i].dwLoopEnd = ws_audio_pcm_wave[i].dwLength; + ws_audio_pcm_wave[i].wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; - ACreateAudioData(&ws_audio_pcm_wave[i]); - - // channel is not playing yet - ws_audio_channel_isPlaying[i]=0; + ACreateAudioData(&ws_audio_pcm_wave[i]); - // clear the channel - ws_audio_clear_channel(i); - } + // channel is not playing yet + ws_audio_channel_isPlaying[i]=0; - // create the noise channel - { - // create the channel - ACreateAudioVoice(&ws_audio_noise_voice); - ASetVoiceVolume ( ws_audio_noise_voice, AUDIO_MAX_VOLUME); - ASetVoicePanning ( ws_audio_noise_voice, AUDIO_MAX_PANNING>>1); + // clear the channel + ws_audio_clear_channel(i); + } + + // create the noise channel + { + // create the channel + ACreateAudioVoice(&ws_audio_noise_voice); + ASetVoiceVolume ( ws_audio_noise_voice, AUDIO_MAX_VOLUME); + ASetVoicePanning ( ws_audio_noise_voice, AUDIO_MAX_PANNING>>1); - // create a looped sound buffer - ws_audio_noise_wave.nSampleRate = info.nSampleRate; - ws_audio_noise_wave.dwLength = (BUFSIZEP<<4); - ws_audio_noise_wave.dwLoopStart = 0; - ws_audio_noise_wave.dwLoopEnd = ws_audio_noise_wave.dwLength; - ws_audio_noise_wave.wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; + // create a looped sound buffer + ws_audio_noise_wave.nSampleRate = info.nSampleRate; + ws_audio_noise_wave.dwLength = (BUFSIZEP<<4); + ws_audio_noise_wave.dwLoopStart = 0; + ws_audio_noise_wave.dwLoopEnd = ws_audio_noise_wave.dwLength; + ws_audio_noise_wave.wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; - ACreateAudioData(&ws_audio_noise_wave); - - // channel is not playing yet - ws_audio_channel_isPlaying[4]=0; + ACreateAudioData(&ws_audio_noise_wave); - // clear the channel - ws_audio_clear_channel(4); - } + // channel is not playing yet + ws_audio_channel_isPlaying[4]=0; - // create the sweep channel - { - // create the channel - ACreateAudioVoice(&ws_audio_sweep_voice); - ASetVoiceVolume ( ws_audio_sweep_voice, AUDIO_MAX_VOLUME); - ASetVoicePanning ( ws_audio_sweep_voice, AUDIO_MAX_PANNING); + // clear the channel + ws_audio_clear_channel(4); + } + + // create the sweep channel + { + // create the channel + ACreateAudioVoice(&ws_audio_sweep_voice); + ASetVoiceVolume ( ws_audio_sweep_voice, AUDIO_MAX_VOLUME); + ASetVoicePanning ( ws_audio_sweep_voice, AUDIO_MAX_PANNING); - // create a looped sound buffer - ws_audio_sweep_wave.nSampleRate = info.nSampleRate; - ws_audio_sweep_wave.dwLength = BUFSIZEN; - ws_audio_sweep_wave.dwLoopStart = 0; - ws_audio_sweep_wave.dwLoopEnd = ws_audio_sweep_wave.dwLength; - ws_audio_sweep_wave.wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; + // create a looped sound buffer + ws_audio_sweep_wave.nSampleRate = info.nSampleRate; + ws_audio_sweep_wave.dwLength = BUFSIZEN; + ws_audio_sweep_wave.dwLoopStart = 0; + ws_audio_sweep_wave.dwLoopEnd = ws_audio_sweep_wave.dwLength; + ws_audio_sweep_wave.wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_LOOP; - ACreateAudioData(&ws_audio_sweep_wave); - - // channel is not playing yet - ws_audio_channel_isPlaying[5]=0; + ACreateAudioData(&ws_audio_sweep_wave); - // clear the channel - ws_audio_clear_channel(5); - } - - // initialize the noise channel data - int rand; - for(i=0;i<8;i++) - { - for(j=0;jBPSMAX) - Freq=BPSMAX; + Freq=3072000/(2048-Period); - else - if(FreqBPSMAX) + { + Freq=BPSMAX; + } + + else if(Freq10000) volume=10000; - volume=((volume+10000)*0x3f)/20000; - if(volume<-10000) - volume=-10000;*/ - volume=(Vol+1)*(MainVol+1)*(HardVol+1)/16-1; - if (Channel==5) - ASetVoiceVolume(ws_audio_sweep_voice,volume); - else - if (Channel==4) - { - ASetVoiceVolume(ws_audio_noise_voice,volume); - } - else - { - ASetVoiceVolume(ws_audio_pcm_voice[Channel],volume); + //volume=TblChVol[ChCurVol[Channel]]+TblMainVol[MainVol]; + /* if (volume>10000) volume=10000; + volume=((volume+10000)*0x3f)/20000; + if(volume<-10000) + volume=-10000;*/ + volume=(Vol+1)*(MainVol+1)*(HardVol+1)/16-1; + + if (Channel==5) + { + ASetVoiceVolume(ws_audio_sweep_voice,volume); + } + else if (Channel==4) + { + ASetVoiceVolume(ws_audio_noise_voice,volume); + } + else + { + ASetVoiceVolume(ws_audio_pcm_voice[Channel],volume); // fprintf(log_get(),"set Channel[%d] volume to %02X (%02X*%02X)\n",Channel,volume,Vol,MainVol); - } + } } //////////////////////////////////////////////////////////////////////////////// // @@ -876,52 +979,65 @@ void ws_audio_set_channel_volume(int Channel,int Vol) //////////////////////////////////////////////////////////////////////////////// void ws_audio_set_channel_pan(int Channel,int Left,int Right) { - long pan; + long pan; - const long TblPan[16][16]= - { - { 0, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000}, - {-10000, 0, 602, 954, 1204, 1398, 1556, 1690, 1806, 1908, 2000, 2082, 2158, 2228, 2292, 2352}, - {-10000, -602, 0, 352, 602, 796, 954, 1088, 1204, 1306, 1398, 1481, 1556, 1626, 1690, 1750}, - {-10000, -954, -352, 0, 250, 444, 602, 736, 852, 954, 1046, 1129, 1204, 1274, 1338, 1398}, - {-10000, -1204, -602, -250, 0, 194, 352, 486, 602, 704, 796, 879, 954, 1024, 1088, 1148}, - {-10000, -1398, -796, -444, -194, 0, 158, 292, 408, 511, 602, 685, 760, 830, 894, 954}, - {-10000, -1556, -954, -602, -352, -158, 0, 134, 250, 352, 444, 526, 602, 672, 736, 796}, - {-10000, -1690, -1088, -736, -486, -292, -134, 0, 116, 218, 310, 393, 468, 538, 602, 662}, - {-10000, -1806, -1204, -852, -602, -408, -250, -116, 0, 102, 194, 277, 352, 422, 486, 546}, - {-10000, -1908, -1306, -954, -704, -511, -352, -218, -102, 0, 92, 174, 250, 319, 384, 444}, - {-10000, -2000, -1398, -1046, -796, -602, -444, -310, -194, -92, 0, 83, 158, 228, 292, 352}, - {-10000, -2082, -1481, -1129, -879, -685, -526, -393, -277, -174, -83, 0, 76, 145, 209, 269}, - {-10000, -2158, -1556, -1204, -954, -760, -602, -468, -352, -250, -158, -76, 0, 70, 134, 194}, - {-10000, -2228, -1626, -1274, -1024, -830, -672, -538, -422, -319, -228, -145, -70, 0, 64, 124}, - {-10000, -2292, -1690, -1338, -1088, -894, -736, -602, -486, -384, -292, -209, -134, -64, 0, 60}, - {-10000, -2352, -1750, -1398, -1148, -954, -796, -662, -546, -444, -352, -269, -194, -124, -60, 0}, - }; + const long TblPan[16][16]= + { + { 0, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000}, + {-10000, 0, 602, 954, 1204, 1398, 1556, 1690, 1806, 1908, 2000, 2082, 2158, 2228, 2292, 2352}, + {-10000, -602, 0, 352, 602, 796, 954, 1088, 1204, 1306, 1398, 1481, 1556, 1626, 1690, 1750}, + {-10000, -954, -352, 0, 250, 444, 602, 736, 852, 954, 1046, 1129, 1204, 1274, 1338, 1398}, + {-10000, -1204, -602, -250, 0, 194, 352, 486, 602, 704, 796, 879, 954, 1024, 1088, 1148}, + {-10000, -1398, -796, -444, -194, 0, 158, 292, 408, 511, 602, 685, 760, 830, 894, 954}, + {-10000, -1556, -954, -602, -352, -158, 0, 134, 250, 352, 444, 526, 602, 672, 736, 796}, + {-10000, -1690, -1088, -736, -486, -292, -134, 0, 116, 218, 310, 393, 468, 538, 602, 662}, + {-10000, -1806, -1204, -852, -602, -408, -250, -116, 0, 102, 194, 277, 352, 422, 486, 546}, + {-10000, -1908, -1306, -954, -704, -511, -352, -218, -102, 0, 92, 174, 250, 319, 384, 444}, + {-10000, -2000, -1398, -1046, -796, -602, -444, -310, -194, -92, 0, 83, 158, 228, 292, 352}, + {-10000, -2082, -1481, -1129, -879, -685, -526, -393, -277, -174, -83, 0, 76, 145, 209, 269}, + {-10000, -2158, -1556, -1204, -954, -760, -602, -468, -352, -250, -158, -76, 0, 70, 134, 194}, + {-10000, -2228, -1626, -1274, -1024, -830, -672, -538, -422, -319, -228, -145, -70, 0, 64, 124}, + {-10000, -2292, -1690, -1338, -1088, -894, -736, -602, -486, -384, -292, -209, -134, -64, 0, 60}, + {-10000, -2352, -1750, -1398, -1148, -954, -796, -662, -546, -444, -352, -269, -194, -124, -60, 0}, + }; - if(Left>Right) - ws_audio_set_channel_volume(Channel,Left); - else - ws_audio_set_channel_volume(Channel,Right); + if(Left>Right) + { + ws_audio_set_channel_volume(Channel,Left); + } + else + { + ws_audio_set_channel_volume(Channel,Right); + } - pan=TblPan[Left][Right]; + pan=TblPan[Left][Right]; - if(ChCurPan[Channel]==pan) - return; + if(ChCurPan[Channel]==pan) + { + return; + } - ChCurPan[Channel]=pan; + ChCurPan[Channel]=pan; - if (pan>10000) pan=10000; - pan=((pan+10000)*AUDIO_MAX_PANNING)/20000; - - if (Channel==5) - ASetVoicePanning(ws_audio_sweep_voice,pan); - else - if (Channel==4) - ASetVoicePanning(ws_audio_noise_voice,pan); - else - { - ASetVoicePanning(ws_audio_pcm_voice[Channel],pan); - } + if (pan>10000) + { + pan=10000; + } + + pan=((pan+10000)*AUDIO_MAX_PANNING)/20000; + + if (Channel==5) + { + ASetVoicePanning(ws_audio_sweep_voice,pan); + } + else if (Channel==4) + { + ASetVoicePanning(ws_audio_noise_voice,pan); + } + else + { + ASetVoicePanning(ws_audio_pcm_voice[Channel],pan); + } } //////////////////////////////////////////////////////////////////////////////// // @@ -936,27 +1052,27 @@ void ws_audio_set_channel_pan(int Channel,int Left,int Right) //////////////////////////////////////////////////////////////////////////////// void ws_audio_set_channel_pdata(int Channel,int Index) { - unsigned char *pData; + unsigned char *pData; - if(Channel==5) - { - pData=PDataN[Index]; + if(Channel==5) + { + pData=PDataN[Index]; - memcpy(ws_audio_sweep_wave.lpData, pData, ws_audio_sweep_wave.dwLength); - AWriteAudioData(&ws_audio_sweep_wave, 0, ws_audio_sweep_wave.dwLength); - } - else if(Channel==4) - { - pData=PDataP; - memcpy(ws_audio_noise_wave.lpData, pData, ws_audio_noise_wave.dwLength); - AWriteAudioData(&ws_audio_noise_wave, 0, ws_audio_noise_wave.dwLength); - } - else - { - pData=PData[Channel]; - memcpy(ws_audio_pcm_wave[Channel].lpData, pData, ws_audio_pcm_wave[Channel].dwLength); - AWriteAudioData(&ws_audio_pcm_wave[Channel], 0, ws_audio_pcm_wave[Channel].dwLength); - } + memcpy(ws_audio_sweep_wave.lpData, pData, ws_audio_sweep_wave.dwLength); + AWriteAudioData(&ws_audio_sweep_wave, 0, ws_audio_sweep_wave.dwLength); + } + else if(Channel==4) + { + pData=PDataP; + memcpy(ws_audio_noise_wave.lpData, pData, ws_audio_noise_wave.dwLength); + AWriteAudioData(&ws_audio_noise_wave, 0, ws_audio_noise_wave.dwLength); + } + else + { + pData=PData[Channel]; + memcpy(ws_audio_pcm_wave[Channel].lpData, pData, ws_audio_pcm_wave[Channel].dwLength); + AWriteAudioData(&ws_audio_pcm_wave[Channel], 0, ws_audio_pcm_wave[Channel].dwLength); + } } //////////////////////////////////////////////////////////////////////////////// // @@ -971,18 +1087,22 @@ void ws_audio_set_channel_pdata(int Channel,int Index) //////////////////////////////////////////////////////////////////////////////// void ws_audio_set_channels_pbuf(int Addr,int Data) { - int i,j; - - i=(Addr&0x30)>>4; - for(j=(Addr&0x0F)<<1;j>4; + + for(j=(Addr&0x0F)<<1; j>4)-7)); - PData[i][j] = (Data&0x0f)*17-128; - PData[i][j+1] = ((Data>>4)&0x0f)*17-128; - } - if((Addr&0x0F)==0x0F) - ws_audio_set_channel_pdata(i,0); + PData[i][j] = (Data&0x0f)*17-128; + PData[i][j+1] = ((Data>>4)&0x0f)*17-128; + } + + if((Addr&0x0F)==0x0F) + { + ws_audio_set_channel_pdata(i,0); + } } //////////////////////////////////////////////////////////////////////////////// // @@ -997,11 +1117,11 @@ void ws_audio_set_channels_pbuf(int Addr,int Data) //////////////////////////////////////////////////////////////////////////////// void ws_audio_rst_channel(int Channel) { - if(Channel==2) - { - ws_audio_set_channel_frequency(2,ChPerInit); - SwpCurPeriod=ChPerInit; - } + if(Channel==2) + { + ws_audio_set_channel_frequency(2,ChPerInit); + SwpCurPeriod=ChPerInit; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -1016,36 +1136,43 @@ void ws_audio_rst_channel(int Channel) //////////////////////////////////////////////////////////////////////////////// int ws_audio_int(void) { - unsigned int value; - static int i; + unsigned int value; + static int i; - if((SwpStep)&&(SNDMOD&0x40)) - { - if(CntSwp<0) - { - CntSwp=SwpTime; - SwpCurPeriod+=SwpStep; - SwpCurPeriod&=0x7FF; - value=3072000/(2048-SwpCurPeriod); - if(value>100000) - { - value=100000; - ws_audio_set_channel_volume(2,0); - } - if(value<100) - { - value=100; - } - ASetVoiceFrequency(ws_audio_pcm_voice[2],value); - } - CntSwp--; - } - i++; - if(i>=BUFSIZEN) - { - i=0; - } - return RandData[i]; + if((SwpStep)&&(SNDMOD&0x40)) + { + if(CntSwp<0) + { + CntSwp=SwpTime; + SwpCurPeriod+=SwpStep; + SwpCurPeriod&=0x7FF; + value=3072000/(2048-SwpCurPeriod); + + if(value>100000) + { + value=100000; + ws_audio_set_channel_volume(2,0); + } + + if(value<100) + { + value=100; + } + + ASetVoiceFrequency(ws_audio_pcm_voice[2],value); + } + + CntSwp--; + } + + i++; + + if(i>=BUFSIZEN) + { + i=0; + } + + return RandData[i]; } //////////////////////////////////////////////////////////////////////////////// // @@ -1063,25 +1190,30 @@ DWORD TickZ=0,PcmCount; void ws_audio_set_pcm(int Data) { - DWORD tick; - PDataP[PCMPos++]=(unsigned char)(Data+128); - //tick=GetTickCount(); - tick=SDL_GetTicks(); - PcmCount++; - if(tick>=TickZ) - { - TickZ=tick+125; - PcmCount<<=3; - if(PcmCount>=10000) - { - PcmCount=12000; - } - ASetVoiceFrequency(ws_audio_noise_voice,PcmCount); - PcmCount=0; - } + DWORD tick; + PDataP[PCMPos++]=(unsigned char)(Data+128); + //tick=GetTickCount(); + tick=SDL_GetTicks(); + PcmCount++; - if(PCMPos>=BUFSIZEP) - ws_audio_flash_pcm(); + if(tick>=TickZ) + { + TickZ=tick+125; + PcmCount<<=3; + + if(PcmCount>=10000) + { + PcmCount=12000; + } + + ASetVoiceFrequency(ws_audio_noise_voice,PcmCount); + PcmCount=0; + } + + if(PCMPos>=BUFSIZEP) + { + ws_audio_flash_pcm(); + } } //////////////////////////////////////////////////////////////////////////////// // @@ -1096,31 +1228,33 @@ void ws_audio_set_pcm(int Data) //////////////////////////////////////////////////////////////////////////////// void ws_audio_flash_pcm(void) { - //int result; - //void *ptr1,*ptr2; - DWORD len1; //,len2; - - const DWORD WrPos[16]= - { - BUFSIZEP*0,BUFSIZEP*1,BUFSIZEP*2,BUFSIZEP*3, - BUFSIZEP*4,BUFSIZEP*5,BUFSIZEP*6,BUFSIZEP*7, - BUFSIZEP*8,BUFSIZEP*9,BUFSIZEP*10,BUFSIZEP*11, - BUFSIZEP*12,BUFSIZEP*13,BUFSIZEP*14,BUFSIZEP*15, - }; + //int result; + //void *ptr1,*ptr2; + DWORD len1; //,len2; - len1=BUFSIZEP; + const DWORD WrPos[16]= + { + BUFSIZEP*0,BUFSIZEP*1,BUFSIZEP*2,BUFSIZEP*3, + BUFSIZEP*4,BUFSIZEP*5,BUFSIZEP*6,BUFSIZEP*7, + BUFSIZEP*8,BUFSIZEP*9,BUFSIZEP*10,BUFSIZEP*11, + BUFSIZEP*12,BUFSIZEP*13,BUFSIZEP*14,BUFSIZEP*15, + }; - if (ws_audio_noise_wave.lpData == NULL) - return; + len1=BUFSIZEP; - memcpy(&ws_audio_noise_wave.lpData[WrPos[PcmWrPos]], PDataP, len1); - AWriteAudioData(&ws_audio_noise_wave, 0, ws_audio_noise_wave.dwLength); + if (ws_audio_noise_wave.lpData == NULL) + { + return; + } + + memcpy(&ws_audio_noise_wave.lpData[WrPos[PcmWrPos]], PDataP, len1); + AWriteAudioData(&ws_audio_noise_wave, 0, ws_audio_noise_wave.dwLength); - PcmWrPos++; - PcmWrPos&=0xF; - memset(PDataP,PL,sizeof(PDataP)); - PCMPos=0; + PcmWrPos++; + PcmWrPos&=0xF; + memset(PDataP,PL,sizeof(PDataP)); + PCMPos=0; } //////////////////////////////////////////////////////////////////////////////// @@ -1136,11 +1270,11 @@ void ws_audio_flash_pcm(void) //////////////////////////////////////////////////////////////////////////////// void ws_audio_write_byte(Uint32 offset, Uint8 value) { - if (!((offset-WaveMap)&0xFFC0)) - { - ws_audio_set_channels_pbuf(offset&0x003F,value); - internalRam[offset]=value; - } + if (!((offset-WaveMap)&0xFFC0)) + { + ws_audio_set_channels_pbuf(offset&0x003F,value); + internalRam[offset]=value; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -1154,11 +1288,12 @@ void ws_audio_write_byte(Uint32 offset, Uint8 value) // //////////////////////////////////////////////////////////////////////////////// void ws_audio_process(void) -{ - Uint32 i, j, b; - i=ws_audio_int(); - PCSRL=(Uint8)(i&0xFF); - PCSRH=(Uint8)((i>>8)&0xFF); +{ + Uint32 i, j, b; + i=ws_audio_int(); + PCSRL=(Uint8)(i&0xFF); + PCSRH=(Uint8)((i>>8)&0xFF); + /*if ((SDMACTL & 0x98) == 0x98) { // Hyper voice v = Page[SDMASB + b][SDMASA + index++]; @@ -1182,48 +1317,60 @@ void ws_audio_process(void) return v; } else */ - if((SDMACTL&0x88)==0x80) - { - i=(SDMACH<<8)|SDMACL; - j=(SDMASB<<16)|(SDMASH<<8)|SDMASL; - b=cpu_readmem20(j); - if(!ws_audio_channel_isPlaying[5]) - b=0x80; - ws_ioRam[0x89]=b; - i--; - j++; - if(i<32) - { - i=0; - SDMACTL&=0x7F; - } - SDMASB=(Uint8)((j>>16)&0xFF); - SDMASH=(Uint8)((j>>8)&0xFF); - SDMASL=(Uint8)(j&0xFF); - SDMACH=(Uint8)((i>>8)&0xFF); - SDMACL=(Uint8)(i&0xFF); - } - else if((SNDMOD&0x22)==0x22) - { - b=ws_ioRam[0x89]; - if(!ws_audio_channel_isPlaying[4]) - b=0x80; - } - else - { - b=0x80; - } - b>>=1; - b+=0x40; - if(b>0xAA) - { - b=0xAA; - } - else if(b<0x55) - { - b=0x55; - } - ws_audio_set_pcm(b); + if((SDMACTL&0x88)==0x80) + { + i=(SDMACH<<8)|SDMACL; + j=(SDMASB<<16)|(SDMASH<<8)|SDMASL; + b=cpu_readmem20(j); + + if(!ws_audio_channel_isPlaying[5]) + { + b=0x80; + } + + ws_ioRam[0x89]=b; + i--; + j++; + + if(i<32) + { + i=0; + SDMACTL&=0x7F; + } + + SDMASB=(Uint8)((j>>16)&0xFF); + SDMASH=(Uint8)((j>>8)&0xFF); + SDMASL=(Uint8)(j&0xFF); + SDMACH=(Uint8)((i>>8)&0xFF); + SDMACL=(Uint8)(i&0xFF); + } + else if((SNDMOD&0x22)==0x22) + { + b=ws_ioRam[0x89]; + + if(!ws_audio_channel_isPlaying[4]) + { + b=0x80; + } + } + else + { + b=0x80; + } + + b>>=1; + b+=0x40; + + if(b>0xAA) + { + b=0xAA; + } + else if(b<0x55) + { + b=0x55; + } + + ws_audio_set_pcm(b); } //////////////////////////////////////////////////////////////////////////////// // @@ -1238,80 +1385,90 @@ void ws_audio_process(void) //////////////////////////////////////////////////////////////////////////////// void ws_audio_readState(int fp) { - long lpdwPosition; - long lpdwFrequency; - unsigned int lpnVolume; - unsigned int lpnPanning; - int lpnStatus; - unsigned char *pData; + long lpdwPosition; + long lpdwFrequency; + unsigned int lpnVolume; + unsigned int lpnPanning; + int lpnStatus; + unsigned char *pData; - read(fp,&PCMPos,sizeof(DWORD)); - read(fp,&TickZ,sizeof(DWORD)); - read(fp,&PcmCount,sizeof(DWORD)); - read(fp,&WaveMap,sizeof(int)); - read(fp,&ChPerInit,sizeof(int)); - read(fp,&SwpTime,sizeof(int)); - read(fp,&SwpStep,sizeof(int)); - read(fp,&SwpCurPeriod,sizeof(int)); - read(fp,&MainVol,sizeof(int)); - read(fp,&CntSwp,sizeof(int)); - read(fp,&PcmWrPos,sizeof(int)); + read(fp,&PCMPos,sizeof(DWORD)); + read(fp,&TickZ,sizeof(DWORD)); + read(fp,&PcmCount,sizeof(DWORD)); + read(fp,&WaveMap,sizeof(int)); + read(fp,&ChPerInit,sizeof(int)); + read(fp,&SwpTime,sizeof(int)); + read(fp,&SwpStep,sizeof(int)); + read(fp,&SwpCurPeriod,sizeof(int)); + read(fp,&MainVol,sizeof(int)); + read(fp,&CntSwp,sizeof(int)); + read(fp,&PcmWrPos,sizeof(int)); - read(fp,ws_audio_channel_isPlaying,sizeof(UINT32)*6); + read(fp,ws_audio_channel_isPlaying,sizeof(UINT32)*6); - read(fp,PData,sizeof(unsigned char)*4*BUFSIZE); - read(fp,PDataP,sizeof(unsigned char)*(BUFSIZEP<<4)); - read(fp,PDataN,sizeof(unsigned char)*8*BUFSIZEN); - read(fp,PDataN,sizeof(int)*BUFSIZEN); + read(fp,PData,sizeof(unsigned char)*4*BUFSIZE); + read(fp,PDataP,sizeof(unsigned char)*(BUFSIZEP<<4)); + read(fp,PDataN,sizeof(unsigned char)*8*BUFSIZEN); + read(fp,PDataN,sizeof(int)*BUFSIZEN); - for (int i=0;i<4;i++) - { - read(fp,&lpdwPosition,sizeof(long)); - read(fp,&lpdwFrequency,sizeof(long)); - read(fp,&lpnVolume,sizeof(unsigned int)); - read(fp,&lpnPanning,sizeof(unsigned int)); - read(fp,&lpnStatus,sizeof(int)); - ASetVoicePosition(ws_audio_pcm_voice[i],lpdwPosition); - ASetVoiceFrequency(ws_audio_pcm_voice[i], lpdwFrequency); - ASetVoiceVolume(ws_audio_pcm_voice[i], lpnVolume); - ASetVoicePanning(ws_audio_pcm_voice[i], lpnPanning); - pData=PData[i]; - memcpy(ws_audio_pcm_wave[i].lpData, pData, ws_audio_pcm_wave[i].dwLength); - AWriteAudioData(&ws_audio_pcm_wave[i], 0, ws_audio_pcm_wave[i].dwLength); - if (ws_audio_channel_isPlaying[i]) - APlayVoice(ws_audio_pcm_voice[i], &ws_audio_pcm_wave[i]); - } - ASetVoicePosition(ws_audio_noise_voice,lpdwPosition); - ASetVoiceFrequency(ws_audio_noise_voice, lpdwFrequency); - ASetVoiceVolume(ws_audio_noise_voice, lpnVolume); - ASetVoicePanning(ws_audio_noise_voice, lpnPanning); - pData=PDataP; - memcpy(ws_audio_noise_wave.lpData, pData, ws_audio_noise_wave.dwLength); - AWriteAudioData(&ws_audio_noise_wave, 0, ws_audio_noise_wave.dwLength); - if (ws_audio_channel_isPlaying[4]) - APlayVoice(ws_audio_noise_voice, &ws_audio_noise_wave); - - read(fp,&lpdwPosition,sizeof(long)); - read(fp,&lpdwFrequency,sizeof(long)); - read(fp,&lpnVolume,sizeof(unsigned int)); - read(fp,&lpnPanning,sizeof(unsigned int)); - read(fp,&lpnStatus,sizeof(int)); + for (int i=0; i<4; i++) + { + read(fp,&lpdwPosition,sizeof(long)); + read(fp,&lpdwFrequency,sizeof(long)); + read(fp,&lpnVolume,sizeof(unsigned int)); + read(fp,&lpnPanning,sizeof(unsigned int)); + read(fp,&lpnStatus,sizeof(int)); + ASetVoicePosition(ws_audio_pcm_voice[i],lpdwPosition); + ASetVoiceFrequency(ws_audio_pcm_voice[i], lpdwFrequency); + ASetVoiceVolume(ws_audio_pcm_voice[i], lpnVolume); + ASetVoicePanning(ws_audio_pcm_voice[i], lpnPanning); + pData=PData[i]; + memcpy(ws_audio_pcm_wave[i].lpData, pData, ws_audio_pcm_wave[i].dwLength); + AWriteAudioData(&ws_audio_pcm_wave[i], 0, ws_audio_pcm_wave[i].dwLength); - ASetVoicePosition(ws_audio_sweep_voice,lpdwPosition); - ASetVoiceFrequency(ws_audio_sweep_voice, lpdwFrequency); - ASetVoiceVolume(ws_audio_sweep_voice, lpnVolume); - ASetVoicePanning(ws_audio_sweep_voice, lpnPanning); - pData=PDataN[0]; - memcpy(ws_audio_sweep_wave.lpData, pData, ws_audio_sweep_wave.dwLength); - AWriteAudioData(&ws_audio_sweep_wave, 0, ws_audio_sweep_wave.dwLength); - if (ws_audio_channel_isPlaying[5]) - APlayVoice(ws_audio_sweep_voice, &ws_audio_sweep_wave); - - read(fp,&lpdwPosition,sizeof(long)); - read(fp,&lpdwFrequency,sizeof(long)); - read(fp,&lpnVolume,sizeof(unsigned int)); - read(fp,&lpnPanning,sizeof(unsigned int)); - read(fp,&lpnStatus,sizeof(int)); + if (ws_audio_channel_isPlaying[i]) + { + APlayVoice(ws_audio_pcm_voice[i], &ws_audio_pcm_wave[i]); + } + } + + ASetVoicePosition(ws_audio_noise_voice,lpdwPosition); + ASetVoiceFrequency(ws_audio_noise_voice, lpdwFrequency); + ASetVoiceVolume(ws_audio_noise_voice, lpnVolume); + ASetVoicePanning(ws_audio_noise_voice, lpnPanning); + pData=PDataP; + memcpy(ws_audio_noise_wave.lpData, pData, ws_audio_noise_wave.dwLength); + AWriteAudioData(&ws_audio_noise_wave, 0, ws_audio_noise_wave.dwLength); + + if (ws_audio_channel_isPlaying[4]) + { + APlayVoice(ws_audio_noise_voice, &ws_audio_noise_wave); + } + + read(fp,&lpdwPosition,sizeof(long)); + read(fp,&lpdwFrequency,sizeof(long)); + read(fp,&lpnVolume,sizeof(unsigned int)); + read(fp,&lpnPanning,sizeof(unsigned int)); + read(fp,&lpnStatus,sizeof(int)); + + ASetVoicePosition(ws_audio_sweep_voice,lpdwPosition); + ASetVoiceFrequency(ws_audio_sweep_voice, lpdwFrequency); + ASetVoiceVolume(ws_audio_sweep_voice, lpnVolume); + ASetVoicePanning(ws_audio_sweep_voice, lpnPanning); + pData=PDataN[0]; + memcpy(ws_audio_sweep_wave.lpData, pData, ws_audio_sweep_wave.dwLength); + AWriteAudioData(&ws_audio_sweep_wave, 0, ws_audio_sweep_wave.dwLength); + + if (ws_audio_channel_isPlaying[5]) + { + APlayVoice(ws_audio_sweep_voice, &ws_audio_sweep_wave); + } + + read(fp,&lpdwPosition,sizeof(long)); + read(fp,&lpdwFrequency,sizeof(long)); + read(fp,&lpnVolume,sizeof(unsigned int)); + read(fp,&lpnPanning,sizeof(unsigned int)); + read(fp,&lpnStatus,sizeof(int)); } //////////////////////////////////////////////////////////////////////////////// // @@ -1326,66 +1483,67 @@ void ws_audio_readState(int fp) //////////////////////////////////////////////////////////////////////////////// void ws_audio_writeState(int fp) { - int32_t lpdwPosition; - int32_t lpdwFrequency; - uint16_t lpnVolume; - uint16_t lpnPanning; - int8_t lpnStatus; + int32_t lpdwPosition; + int32_t lpdwFrequency; + uint16_t lpnVolume; + uint16_t lpnPanning; + int8_t lpnStatus; - write(fp,&PCMPos,sizeof(DWORD)); - write(fp,&TickZ,sizeof(DWORD)); - write(fp,&PcmCount,sizeof(DWORD)); - write(fp,&WaveMap,sizeof(int)); - write(fp,&ChPerInit,sizeof(int)); - write(fp,&SwpTime,sizeof(int)); - write(fp,&SwpStep,sizeof(int)); - write(fp,&SwpCurPeriod,sizeof(int)); - write(fp,&MainVol,sizeof(int)); - write(fp,&CntSwp,sizeof(int)); - write(fp,&PcmWrPos,sizeof(int)); + write(fp,&PCMPos,sizeof(DWORD)); + write(fp,&TickZ,sizeof(DWORD)); + write(fp,&PcmCount,sizeof(DWORD)); + write(fp,&WaveMap,sizeof(int)); + write(fp,&ChPerInit,sizeof(int)); + write(fp,&SwpTime,sizeof(int)); + write(fp,&SwpStep,sizeof(int)); + write(fp,&SwpCurPeriod,sizeof(int)); + write(fp,&MainVol,sizeof(int)); + write(fp,&CntSwp,sizeof(int)); + write(fp,&PcmWrPos,sizeof(int)); - write(fp,ws_audio_channel_isPlaying,sizeof(UINT32)*6); + write(fp,ws_audio_channel_isPlaying,sizeof(UINT32)*6); - write(fp,PData,sizeof(unsigned char)*4*BUFSIZE); - write(fp,PDataP,sizeof(unsigned char)*(BUFSIZEP<<4)); - write(fp,PDataN,sizeof(unsigned char)*8*BUFSIZEN); - write(fp,PDataN,sizeof(int)*BUFSIZEN); + write(fp,PData,sizeof(unsigned char)*4*BUFSIZE); + write(fp,PDataP,sizeof(unsigned char)*(BUFSIZEP<<4)); + write(fp,PDataN,sizeof(unsigned char)*8*BUFSIZEN); + write(fp,PDataN,sizeof(int)*BUFSIZEN); - for (int i=0;i<4;i++) - { - AGetVoicePosition(ws_audio_pcm_voice[i],&lpdwPosition); - AGetVoiceFrequency(ws_audio_pcm_voice[i], &lpdwFrequency); - AGetVoiceVolume(ws_audio_pcm_voice[i], &lpnVolume); - AGetVoicePanning(ws_audio_pcm_voice[i], &lpnPanning); - AGetVoiceStatus(ws_audio_pcm_voice[i], &lpnStatus); - - write(fp,&lpdwPosition,sizeof(long)); - write(fp,&lpdwFrequency,sizeof(long)); - write(fp,&lpnVolume,sizeof(unsigned int)); - write(fp,&lpnPanning,sizeof(unsigned int)); - write(fp,&lpnStatus,sizeof(int)); - } - AGetVoicePosition(ws_audio_noise_voice,&lpdwPosition); - AGetVoiceFrequency(ws_audio_noise_voice, &lpdwFrequency); - AGetVoiceVolume(ws_audio_noise_voice, &lpnVolume); - AGetVoicePanning(ws_audio_noise_voice, &lpnPanning); - AGetVoiceStatus(ws_audio_noise_voice, &lpnStatus); - - write(fp,&lpdwPosition,sizeof(long)); - write(fp,&lpdwFrequency,sizeof(long)); - write(fp,&lpnVolume,sizeof(unsigned int)); - write(fp,&lpnPanning,sizeof(unsigned int)); - write(fp,&lpnStatus,sizeof(int)); + for (int i=0; i<4; i++) + { + AGetVoicePosition(ws_audio_pcm_voice[i],&lpdwPosition); + AGetVoiceFrequency(ws_audio_pcm_voice[i], &lpdwFrequency); + AGetVoiceVolume(ws_audio_pcm_voice[i], &lpnVolume); + AGetVoicePanning(ws_audio_pcm_voice[i], &lpnPanning); + AGetVoiceStatus(ws_audio_pcm_voice[i], &lpnStatus); - AGetVoicePosition(ws_audio_sweep_voice,&lpdwPosition); - AGetVoiceFrequency(ws_audio_sweep_voice, &lpdwFrequency); - AGetVoiceVolume(ws_audio_sweep_voice, &lpnVolume); - AGetVoicePanning(ws_audio_sweep_voice, &lpnPanning); - AGetVoiceStatus(ws_audio_sweep_voice, &lpnStatus); - - write(fp,&lpdwPosition,sizeof(long)); - write(fp,&lpdwFrequency,sizeof(long)); - write(fp,&lpnVolume,sizeof(unsigned int)); - write(fp,&lpnPanning,sizeof(unsigned int)); - write(fp,&lpnStatus,sizeof(int)); + write(fp,&lpdwPosition,sizeof(long)); + write(fp,&lpdwFrequency,sizeof(long)); + write(fp,&lpnVolume,sizeof(unsigned int)); + write(fp,&lpnPanning,sizeof(unsigned int)); + write(fp,&lpnStatus,sizeof(int)); + } + + AGetVoicePosition(ws_audio_noise_voice,&lpdwPosition); + AGetVoiceFrequency(ws_audio_noise_voice, &lpdwFrequency); + AGetVoiceVolume(ws_audio_noise_voice, &lpnVolume); + AGetVoicePanning(ws_audio_noise_voice, &lpnPanning); + AGetVoiceStatus(ws_audio_noise_voice, &lpnStatus); + + write(fp,&lpdwPosition,sizeof(long)); + write(fp,&lpdwFrequency,sizeof(long)); + write(fp,&lpnVolume,sizeof(unsigned int)); + write(fp,&lpnPanning,sizeof(unsigned int)); + write(fp,&lpnStatus,sizeof(int)); + + AGetVoicePosition(ws_audio_sweep_voice,&lpdwPosition); + AGetVoiceFrequency(ws_audio_sweep_voice, &lpdwFrequency); + AGetVoiceVolume(ws_audio_sweep_voice, &lpnVolume); + AGetVoicePanning(ws_audio_sweep_voice, &lpnPanning); + AGetVoiceStatus(ws_audio_sweep_voice, &lpnStatus); + + write(fp,&lpdwPosition,sizeof(long)); + write(fp,&lpdwFrequency,sizeof(long)); + write(fp,&lpnVolume,sizeof(unsigned int)); + write(fp,&lpnPanning,sizeof(unsigned int)); + write(fp,&lpnStatus,sizeof(int)); } diff --git a/oswan/source/filters/2xsai.h b/oswan/source/filters/2xsai.h index 813510f..f8501aa 100644 --- a/oswan/source/filters/2xsai.h +++ b/oswan/source/filters/2xsai.h @@ -11,46 +11,49 @@ //////////////////////////////////////////////////////////////////////////////// void ws_emulate_2xSaI(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144*2,224*2,format); - #include "filter_partB.h" - console.open(app_window_title,144*2,224*2,format); +#include "filter_partA.h" - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144*2,224*2,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int16 *vs = (int16 *)surface->lock(); - _2xSaI ((u8*)backbuffer,144*2, NULL,(u8*)vs, surfacePitch<<1,144,224); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - int16 *vs = (int16 *)surface->lock(); - _2xSaI ((u8*)backbuffer,224*2, NULL,(u8*)vs, surfacePitch<<1,224,144); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + _2xSaI ((u8*)backbuffer,144*2, NULL,(u8*)vs, surfacePitch<<1,144,224); + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + int16 *vs = (int16 *)surface->lock(); + _2xSaI ((u8*)backbuffer,224*2, NULL,(u8*)vs, surfacePitch<<1,224,144); + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/doubled.h b/oswan/source/filters/doubled.h index 093d4b8..3f5d998 100644 --- a/oswan/source/filters/doubled.h +++ b/oswan/source/filters/doubled.h @@ -11,20 +11,36 @@ //////////////////////////////////////////////////////////////////////////////// __inline void ws_drawDoubledScanline(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; + register int32 *vs_alias=(int32*)vs; + register int32 data; - for (int pixel=0;pixel<224;pixel+=8) - { - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - } + for (int pixel=0; pixel<224; pixel+=8) + { + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -39,20 +55,36 @@ __inline void ws_drawDoubledScanline(int16 *vs, int16 *backbuffer_alias) //////////////////////////////////////////////////////////////////////////////// __inline void ws_drawDoubledRotatedScanline(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; + register int32 *vs_alias=(int32*)vs; + register int32 data; - for (int pixel=0;pixel<144;pixel+=8) - { - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - } + for (int pixel=0; pixel<144; pixel+=8) + { + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -70,83 +102,147 @@ uint16 ws_halfBrightnessTable[32]; __inline void ws_drawDoubledHalfBrightnessScanline(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; - - for (int pixel=0;pixel<224;pixel+=4) - { - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - } + register int32 *vs_alias=(int32*)vs; + register int32 data; + + for (int pixel=0; pixel<224; pixel+=4) + { + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + } } __inline void ws_drawDoubledHalfBrightnessScanlineSpecialEven(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; - - for (int pixel=0;pixel<224;pixel+=4) - { - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - } + register int32 *vs_alias=(int32*)vs; + register int32 data; + + for (int pixel=0; pixel<224; pixel+=4) + { + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + } } __inline void ws_drawDoubledHalfBrightnessScanlineSpecialOdd(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; - - for (int pixel=0;pixel<224;pixel+=4) - { - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - } + register int32 *vs_alias=(int32*)vs; + register int32 data; + + for (int pixel=0; pixel<224; pixel+=4) + { + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + } } __inline void ws_drawDoubledHalfBrightnessRotatedScanline(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; - - for (int pixel=0;pixel<144;pixel+=4) - { - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - } + register int32 *vs_alias=(int32*)vs; + register int32 data; + + for (int pixel=0; pixel<144; pixel+=4) + { + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + } } __inline void ws_drawDoubledHalfBrightnessRotatedScanlineSpecialEven(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; - - for (int pixel=0;pixel<144;pixel+=4) - { - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - } + register int32 *vs_alias=(int32*)vs; + register int32 data; + + for (int pixel=0; pixel<144; pixel+=4) + { + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + } } __inline void ws_drawDoubledHalfBrightnessRotatedScanlineSpecialOdd(int16 *vs, int16 *backbuffer_alias) { - register int32 *vs_alias=(int32*)vs; - register int32 data; - - for (int pixel=0;pixel<144;pixel+=4) - { - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data|=(data<<16); *vs_alias++=data; - data=*backbuffer_alias++; data=M_HALFBRIGHTNESS(data); data|=(data<<16); *vs_alias++=data; - } + register int32 *vs_alias=(int32*)vs; + register int32 data; + + for (int pixel=0; pixel<144; pixel+=4) + { + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data|=(data<<16); + *vs_alias++=data; + data=*backbuffer_alias++; + data=M_HALFBRIGHTNESS(data); + data|=(data<<16); + *vs_alias++=data; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -161,60 +257,69 @@ __inline void ws_drawDoubledHalfBrightnessRotatedScanlineSpecialOdd(int16 *vs, i //////////////////////////////////////////////////////////////////////////////// void ws_emulate_doubled(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144*2,224*2,format); - #include "filter_partB.h" - console.open(app_window_title,144*2,224*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144*2,224*2,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<224;line++) - { - ws_drawDoubledRotatedScanline(vs,backbuffer_alias); - vs+=surfacePitch; - ws_drawDoubledRotatedScanline(vs,backbuffer_alias); - vs+=surfacePitch; - backbuffer_alias+=144; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<144;line++) - { - ws_drawDoubledScanline(vs,backbuffer_alias); - vs+=surfacePitch; - ws_drawDoubledScanline(vs,backbuffer_alias); - vs+=surfacePitch; - backbuffer_alias+=224; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<224; line++) + { + ws_drawDoubledRotatedScanline(vs,backbuffer_alias); + vs+=surfacePitch; + ws_drawDoubledRotatedScanline(vs,backbuffer_alias); + vs+=surfacePitch; + backbuffer_alias+=144; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<144; line++) + { + ws_drawDoubledScanline(vs,backbuffer_alias); + vs+=surfacePitch; + ws_drawDoubledScanline(vs,backbuffer_alias); + vs+=surfacePitch; + backbuffer_alias+=224; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/filter_partA.h b/oswan/source/filters/filter_partA.h index 659879e..63e4d2e 100644 --- a/oswan/source/filters/filter_partA.h +++ b/oswan/source/filters/filter_partA.h @@ -1,14 +1,15 @@ - //Sint32 startTime, endTime, totalFrames; - //Uint32 nNormalLast=0; - //Sint32 nNormalFrac=0; - //Sint32 nTime=0, - Sint32 nCount=0; int i=0; +//Sint32 startTime, endTime, totalFrames; +//Uint32 nNormalLast=0; +//Sint32 nNormalFrac=0; +//Sint32 nTime=0, +Sint32 nCount=0; +int i=0; - double dTime = 0.0, dNormalLast = 0.0, dTemp; - Sint32 surfacePitch; +double dTime = 0.0, dNormalLast = 0.0, dTemp; +Sint32 surfacePitch; - // 15 bits RGB555 - Format format(16,0x007c00,0x00003e0,0x0000001f); - Console console; - Surface *surface; +// 15 bits RGB555 +Format format(16,0x007c00,0x00003e0,0x0000001f); +Console console; +Surface *surface; diff --git a/oswan/source/filters/filter_partB.h b/oswan/source/filters/filter_partB.h index 4936663..690a9ae 100644 --- a/oswan/source/filters/filter_partB.h +++ b/oswan/source/filters/filter_partB.h @@ -1,23 +1,29 @@ - int16 *backbuffer=(int16*)malloc(224*144*sizeof(int16)); - memset(backbuffer,0x00,224*144*sizeof(int16)); - surfacePitch=(surface->pitch()>>1); - console.option("DirectX"); - if (app_fullscreen) - console.option("fullscreen output"); - else - console.option("windowed output"); - console.option("fixed window"); - console.option("center window"); - //totalFrames=0; - //startTime=clock(); - //nNormalLast=0;// Last value of timeGetTime() - //nNormalFrac=0; // Extra fraction we did - //nNormalLast=timeGetTime(); - // hopefully, we only care about time delta, not time of day... - //nNormalLast = SDL_GetTicks(); - dNormalLast = (double) SDL_GetTicks(); - // filter change - if (gui_command==GUI_COMMAND_FILTER_CHANGE) - { - ws_loadState("oswan.wss"); - } +int16 *backbuffer=(int16*)malloc(224*144*sizeof(int16)); +memset(backbuffer,0x00,224*144*sizeof(int16)); +surfacePitch=(surface->pitch()>>1); +console.option("DirectX"); + +if (app_fullscreen) +{ + console.option("fullscreen output"); +} +else +{ + console.option("windowed output"); +} + +console.option("fixed window"); +console.option("center window"); +//totalFrames=0; +//startTime=clock(); +//nNormalLast=0;// Last value of timeGetTime() +//nNormalFrac=0; // Extra fraction we did +//nNormalLast=timeGetTime(); +// hopefully, we only care about time delta, not time of day... +//nNormalLast = SDL_GetTicks(); +dNormalLast = (double) SDL_GetTicks(); +// filter change +if (gui_command==GUI_COMMAND_FILTER_CHANGE) +{ + ws_loadState("oswan.wss"); +} diff --git a/oswan/source/filters/filter_partC.h b/oswan/source/filters/filter_partC.h index 4026006..2718477 100644 --- a/oswan/source/filters/filter_partC.h +++ b/oswan/source/filters/filter_partC.h @@ -1,77 +1,100 @@ - //nTime=SDL_GetTicks()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage - dTemp = (double) SDL_GetTicks(); - dTime = dTemp - dNormalLast; +//nTime=SDL_GetTicks()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage +dTemp = (double) SDL_GetTicks(); +dTime = dTemp - dNormalLast; - // nTime est en mili-secondes. - // détermine le nombre de trames à passer + 1 - //nCount = (Sint32) ((((double)nTime)*600.0 - (double)nNormalFrac) / 10000.0); - nCount = (Sint32) (dTime * 0.07547); // does this calculation make sense? - // 75.47Hz vblank is according to wstech22.txt - //printf("%d ", nCount); +// nTime est en mili-secondes. +// détermine le nombre de trames à passer + 1 +//nCount = (Sint32) ((((double)nTime)*600.0 - (double)nNormalFrac) / 10000.0); +nCount = (Sint32) (dTime * 0.07547); // does this calculation make sense? +// 75.47Hz vblank is according to wstech22.txt +//printf("%d ", nCount); - // si le nombre de trames à passer + 1 est nul ou négatif, - // ne rien faire pendant 2 ms - //AUpdateAudio(); - if (nCount<=0) - { - SDL_Delay(2); - } // No need to do anything for a bit - else - { - //nNormalFrac+=nCount*10000; // - //nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames - //nNormalFrac%=600; // - //dNormalLast = dTemp; - dNormalLast += nCount * (1/0.07547); +// si le nombre de trames à passer + 1 est nul ou négatif, +// ne rien faire pendant 2 ms +//AUpdateAudio(); +if (nCount<=0) +{ + SDL_Delay(2); +} // No need to do anything for a bit +else +{ + //nNormalFrac+=nCount*10000; // + //nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames + //nNormalFrac%=600; // + //dNormalLast = dTemp; + dNormalLast += nCount * (1/0.07547); - // Pas plus de 9 (10-1) trames non affichées - if (nCount>10) - nCount=10; + // Pas plus de 9 (10-1) trames non affichées + if (nCount>10) + { + nCount=10; + } -/* - ws_key_start=0; - ws_key_left=0; - ws_key_right=0; - ws_key_up=0; - ws_key_down=0; - ws_key_button_1=0; - ws_key_button_2=0; -*/ - int ws_key_esc=0; + /* + ws_key_start=0; + ws_key_left=0; + ws_key_right=0; + ws_key_up=0; + ws_key_down=0; + ws_key_button_1=0; + ws_key_button_2=0; + */ + int ws_key_esc=0; - #include "source/temp/key.h" - if (ws_key_esc) - { - console.close(); - if (ws_rom_path) - strcpy(old_rom_path,ws_rom_path); - //gui_open(); +#include "source/temp/key.h" + + if (ws_key_esc) + { + console.close(); + + if (ws_rom_path) + { + strcpy(old_rom_path,ws_rom_path); + } + + //gui_open(); #ifndef GUI_OPEN_WARNED //#warning XXX something ought to take place here... #define GUI_OPEN_WARNED #endif - app_terminate = 1; + app_terminate = 1; - if ((ws_rom_path!=NULL)||(app_terminate)) - break; - if (gui_command) - { - if (gui_command==GUI_COMMAND_RESET) - ws_reset(); - if (gui_command==GUI_COMMAND_SCHEME_CHANGE) - ws_set_colour_scheme(ws_colourScheme); - if (gui_command==GUI_COMMAND_FILTER_CHANGE) - { - ws_saveState("oswan.wss"); - ws_rom_path=old_rom_path; - delete surface; - return; - } - } - console.option("DirectX"); - if (app_fullscreen) - console.option("fullscreen output"); - else - console.option("windowed output"); - console.option("fixed window"); - console.option("center window"); + if ((ws_rom_path!=NULL)||(app_terminate)) + { + break; + } + + if (gui_command) + { + if (gui_command==GUI_COMMAND_RESET) + { + ws_reset(); + } + + if (gui_command==GUI_COMMAND_SCHEME_CHANGE) + { + ws_set_colour_scheme(ws_colourScheme); + } + + if (gui_command==GUI_COMMAND_FILTER_CHANGE) + { + ws_saveState("oswan.wss"); + ws_rom_path=old_rom_path; + delete surface; + return; + } + } + + console.option("DirectX"); + + if (app_fullscreen) + { + console.option("fullscreen output"); + } + else + { + console.option("windowed output"); + } + + console.option("fixed window"); + console.option("center window"); diff --git a/oswan/source/filters/filter_partD.h b/oswan/source/filters/filter_partD.h index 793ac9d..3c90889 100644 --- a/oswan/source/filters/filter_partD.h +++ b/oswan/source/filters/filter_partD.h @@ -1,10 +1,11 @@ - } +} - for (i=0;ilock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<224;line++) - { - ws_drawDoubledRotatedScanline(vs,backbuffer_alias); - vs+=surfacePitch; - ws_drawDoubledHalfBrightnessRotatedScanline(vs,backbuffer_alias); - vs+=surfacePitch; - backbuffer_alias+=144; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<144;line++) - { - ws_drawDoubledScanline(vs,backbuffer_alias); - vs+=surfacePitch; - ws_drawDoubledHalfBrightnessScanline(vs,backbuffer_alias); - vs+=surfacePitch; - backbuffer_alias+=224; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<224; line++) + { + ws_drawDoubledRotatedScanline(vs,backbuffer_alias); + vs+=surfacePitch; + ws_drawDoubledHalfBrightnessRotatedScanline(vs,backbuffer_alias); + vs+=surfacePitch; + backbuffer_alias+=144; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<144; line++) + { + ws_drawDoubledScanline(vs,backbuffer_alias); + vs+=surfacePitch; + ws_drawDoubledHalfBrightnessScanline(vs,backbuffer_alias); + vs+=surfacePitch; + backbuffer_alias+=224; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/interpolate.h b/oswan/source/filters/interpolate.h index ba89122..8467a1d 100644 --- a/oswan/source/filters/interpolate.h +++ b/oswan/source/filters/interpolate.h @@ -16,26 +16,28 @@ #define NB_BUFFERS_DIV 3 void ws_mergeBackbuffers(int16 **buffers) { - int16 *buffersAlias[NB_BUFFERS+1]; + int16 *buffersAlias[NB_BUFFERS+1]; - memcpy(buffersAlias,buffers,sizeof(int16*)*(NB_BUFFERS+1)); + memcpy(buffersAlias,buffers,sizeof(int16*)*(NB_BUFFERS+1)); - for (int i=0;i<224*144;i++) - { - int r,g,b; - r=g=b=0; - for (int j=0;j>=NB_BUFFERS_DIV; - g>>=NB_BUFFERS_DIV; - b>>=NB_BUFFERS_DIV; - *buffersAlias[NB_BUFFERS]++=(r<<10)|(g<<5)|b; - } + for (int i=0; i<224*144; i++) + { + int r,g,b; + r=g=b=0; + + for (int j=0; j>=NB_BUFFERS_DIV; + g>>=NB_BUFFERS_DIV; + b>>=NB_BUFFERS_DIV; + *buffersAlias[NB_BUFFERS]++=(r<<10)|(g<<5)|b; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -50,139 +52,180 @@ void ws_mergeBackbuffers(int16 **buffers) //////////////////////////////////////////////////////////////////////////////// void ws_emulate_standard_interpolate(void) { - #define KEY_ENTER 0x0D - #define KEY_ESC 0x1b - #define KEY_UP 0x26 - #define KEY_DOWN 0x28 - #define KEY_LEFT 0x25 - #define KEY_RIGHT 0x27 - #define KEY_BUTTON1 0x57 - #define KEY_BUTTON2 0x58 +#define KEY_ENTER 0x0D +#define KEY_ESC 0x1b +#define KEY_UP 0x26 +#define KEY_DOWN 0x28 +#define KEY_LEFT 0x25 +#define KEY_RIGHT 0x27 +#define KEY_BUTTON1 0x57 +#define KEY_BUTTON2 0x58 - uint32 startTime, endTime, totalFrames; - unsigned int nNormalLast=0; - int nNormalFrac=0; - int nTime=0,nCount=0; int i=0; + uint32 startTime, endTime, totalFrames; + unsigned int nNormalLast=0; + int nNormalFrac=0; + int nTime=0,nCount=0; + int i=0; - // 15 bits RGB555 - Format format(16,0x007c00,0x00003e0,0x0000001f); - Console console; - Surface *surface; - if (app_rotated) - surface=new Surface(144,224,format); - else - surface=new Surface(224,144,format); + // 15 bits RGB555 + Format format(16,0x007c00,0x00003e0,0x0000001f); + Console console; + Surface *surface; - console.option("DirectX"); - if (app_fullscreen) - console.option("fullscreen output"); - else - console.option("windowed output"); - console.option("fixed window"); - console.option("center window"); + if (app_rotated) + { + surface=new Surface(144,224,format); + } + else + { + surface=new Surface(224,144,format); + } - console.open("Oswan",224,144,format); - int16 *backbuffer[NB_BUFFERS+1]; - for (int fr=0;fr10) - nCount=10; + console.option("fixed window"); + console.option("center window"); -/* - ws_key_start=0; - ws_key_left=0; - ws_key_right=0; - ws_key_up=0; - ws_key_down=0; - ws_key_button_1=0; - ws_key_button_2=0; -*/ int ws_key_esc=0; + console.open("Oswan",224,144,format); + int16 *backbuffer[NB_BUFFERS+1]; - #include "./source/temp/key.h" - if (ws_key_esc) - { - console.close(); - strcpy(old_rom_path,ws_rom_path); - gui_open(); + for (int fr=0; frlock(); - memcpy(vs,backbuffer[NB_BUFFERS],224*144*2); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - endTime=clock(); - float fps=totalFrames/(((float)(endTime-startTime))/(float)CLOCKS_PER_SEC); - printf("%f fps (%i %% the original speed)\n",fps, (int)((fps*100)/60)); - console.close(); - delete surface; + while (1) + { + nTime=timeGetTime()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage + // nTime est en mili-secondes. + // détermine le nombre de trames à passer + 1 + nCount=(nTime*600 - nNormalFrac) /10000; + + // si le nombre de trames à passer + 1 est nul ou négatif, + // ne rien faire pendant 2 ms + if (nCount<=0) + { + Sleep(2); + } // No need to do anything for a bit + else + { + nNormalFrac+=nCount*10000; // + nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames + nNormalFrac%=600; // + + // Pas plus de 9 (10-1) trames non affichées + if (nCount>10) + { + nCount=10; + } + + /* + ws_key_start=0; + ws_key_left=0; + ws_key_right=0; + ws_key_up=0; + ws_key_down=0; + ws_key_button_1=0; + ws_key_button_2=0; + */ int ws_key_esc=0; + +#include "./source/temp/key.h" + + if (ws_key_esc) + { + console.close(); + strcpy(old_rom_path,ws_rom_path); + gui_open(); + + if ((ws_rom_path!=NULL)||(app_terminate)) + { + break; + } + + if (gui_command) + { + if (gui_command==GUI_COMMAND_RESET) + { + ws_reset(); + } + + if (gui_command==GUI_COMMAND_SCHEME_CHANGE) + { + ws_set_colour_scheme(ws_colourScheme); + } + + if (gui_command==GUI_COMMAND_FILTER_CHANGE) + { + ws_saveState("oswan.wss"); + ws_rom_path=old_rom_path; + delete surface; + return; + } + } + + console.option("DirectX"); + + if (app_fullscreen) + { + console.option("fullscreen output"); + } + else + { + console.option("windowed output"); + } + + console.option("fixed window"); + console.option("center window"); + console.open("Oswan",224,144,format); + } + + + for (i=0; ilock(); + memcpy(vs,backbuffer[NB_BUFFERS],224*144*2); + surface->unlock(); + surface->copy(console); + console.update(); + } + } + + endTime=clock(); + float fps=totalFrames/(((float)(endTime-startTime))/(float)CLOCKS_PER_SEC); + printf("%f fps (%i %% the original speed)\n",fps, (int)((fps*100)/60)); + console.close(); + delete surface; } diff --git a/oswan/source/filters/scanlines.h b/oswan/source/filters/scanlines.h index 891bddf..00fd817 100644 --- a/oswan/source/filters/scanlines.h +++ b/oswan/source/filters/scanlines.h @@ -11,58 +11,67 @@ //////////////////////////////////////////////////////////////////////////////// void ws_emulate_scanlines(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144*2,224*2,format); - #include "filter_partB.h" - console.open(app_window_title,144*2,224*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144*2,224*2,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<224;line++) - { - ws_drawDoubledRotatedScanline(vs,backbuffer_alias); - vs+=surfacePitch; - vs+=surfacePitch; - backbuffer_alias+=144; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<144;line++) - { - ws_drawDoubledScanline(vs,backbuffer_alias); - vs+=surfacePitch; - vs+=surfacePitch; - backbuffer_alias+=224; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<224; line++) + { + ws_drawDoubledRotatedScanline(vs,backbuffer_alias); + vs+=surfacePitch; + vs+=surfacePitch; + backbuffer_alias+=144; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<144; line++) + { + ws_drawDoubledScanline(vs,backbuffer_alias); + vs+=surfacePitch; + vs+=surfacePitch; + backbuffer_alias+=224; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/special.h b/oswan/source/filters/special.h index 57b582c..06bf0af 100644 --- a/oswan/source/filters/special.h +++ b/oswan/source/filters/special.h @@ -11,61 +11,72 @@ //////////////////////////////////////////////////////////////////////////////// void ws_emulate_special(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144*2,224*2,format); - #include "filter_partB.h" - console.open(app_window_title,144*2,224*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144*2,224*2,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<224;line++) - { - ws_drawDoubledHalfBrightnessRotatedScanlineSpecialEven(vs,backbuffer_alias); - vs+=surfacePitch; - ws_drawDoubledHalfBrightnessRotatedScanlineSpecialOdd(vs,backbuffer_alias); - vs+=surfacePitch; - backbuffer_alias+=144; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - while (!ws_executeLine(backbuffer,1)); - int16 *vs = (int16 *)surface->lock(); - int16 *backbuffer_alias=backbuffer; - for (int line=0;line<144;line++) - { - ws_drawDoubledHalfBrightnessScanlineSpecialEven(vs,backbuffer_alias); - vs+=surfacePitch; - ws_drawDoubledHalfBrightnessScanlineSpecialOdd(vs,backbuffer_alias); - vs+=surfacePitch; - backbuffer_alias+=224; - } - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<224; line++) + { + ws_drawDoubledHalfBrightnessRotatedScanlineSpecialEven(vs,backbuffer_alias); + vs+=surfacePitch; + ws_drawDoubledHalfBrightnessRotatedScanlineSpecialOdd(vs,backbuffer_alias); + vs+=surfacePitch; + backbuffer_alias+=144; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + + while (!ws_executeLine(backbuffer,1)); + + int16 *vs = (int16 *)surface->lock(); + int16 *backbuffer_alias=backbuffer; + + for (int line=0; line<144; line++) + { + ws_drawDoubledHalfBrightnessScanlineSpecialEven(vs,backbuffer_alias); + vs+=surfacePitch; + ws_drawDoubledHalfBrightnessScanlineSpecialOdd(vs,backbuffer_alias); + vs+=surfacePitch; + backbuffer_alias+=224; + } + + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/standard.h b/oswan/source/filters/standard.h index 9d6bb69..dd303ea 100644 --- a/oswan/source/filters/standard.h +++ b/oswan/source/filters/standard.h @@ -11,12 +11,14 @@ //////////////////////////////////////////////////////////////////////////////// void ws_rotate_backbuffer(int16 *backbuffer) { - static int16 temp[224*144]; - memcpy(temp,backbuffer,224*144*2); + static int16 temp[224*144]; + memcpy(temp,backbuffer,224*144*2); - for (int line=0;line<144;line++) - for (int column=0;column<224;column++) - backbuffer[line+((223-column)<<7)+((223-column)<<4)]=temp[column+(line<<7)+(line<<6)+(line<<5)]; + for (int line=0; line<144; line++) + for (int column=0; column<224; column++) + { + backbuffer[line+((223-column)<<7)+((223-column)<<4)]=temp[column+(line<<7)+(line<<6)+(line<<5)]; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -31,45 +33,50 @@ void ws_rotate_backbuffer(int16 *backbuffer) //////////////////////////////////////////////////////////////////////////////// void ws_emulate_standard(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144,224,format); - #include "filter_partB.h" - surfacePitch>>=1; - console.open(app_window_title,144,224,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144,224,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int32 *vs = (int32 *)surface->lock(); - memcpy(vs,backbuffer,224*144*2); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224,144,format); - #include "filter_partB.h" - console.open(app_window_title,224,144,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224,144,format); - #include "filter_partD.h" - int32 *vs = (int32 *)surface->lock(); - memcpy(vs,backbuffer,224*144*2); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144,224,format); +#include "filter_partB.h" + surfacePitch>>=1; + console.open(app_window_title,144,224,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144,224,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int32 *vs = (int32 *)surface->lock(); + memcpy(vs,backbuffer,224*144*2); + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224,144,format); +#include "filter_partB.h" + console.open(app_window_title,224,144,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224,144,format); +#include "filter_partD.h" + int32 *vs = (int32 *)surface->lock(); + memcpy(vs,backbuffer,224*144*2); + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/super2xsai.h b/oswan/source/filters/super2xsai.h index eb2de17..42b21e1 100644 --- a/oswan/source/filters/super2xsai.h +++ b/oswan/source/filters/super2xsai.h @@ -11,44 +11,49 @@ //////////////////////////////////////////////////////////////////////////////// void ws_emulate_Super2xSaI(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144*2,224*2,format); - #include "filter_partB.h" - console.open(app_window_title,144*2,224*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144*2,224*2,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int16 *vs = (int16 *)surface->lock(); - Super2xSaI ((u8*)backbuffer,144*2, NULL,(u8*)vs, surfacePitch<<1,144,224); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - int16 *vs = (int16 *)surface->lock(); - Super2xSaI ((u8*)backbuffer,224*2, NULL,(u8*)vs, surfacePitch<<1,224,144); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + Super2xSaI ((u8*)backbuffer,144*2, NULL,(u8*)vs, surfacePitch<<1,144,224); + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + int16 *vs = (int16 *)surface->lock(); + Super2xSaI ((u8*)backbuffer,224*2, NULL,(u8*)vs, surfacePitch<<1,224,144); + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/filters/supereagle.h b/oswan/source/filters/supereagle.h index 3cf0434..2a136fa 100644 --- a/oswan/source/filters/supereagle.h +++ b/oswan/source/filters/supereagle.h @@ -11,44 +11,49 @@ //////////////////////////////////////////////////////////////////////////////// void ws_emulate_SuperEagle(void) { - #include "filter_partA.h" - if (app_rotated) - { - surface=new Surface(144*2,224*2,format); - #include "filter_partB.h" - console.open(app_window_title,144*2,224*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,144*2,224*2,format); - #include "filter_partD.h" - ws_rotate_backbuffer(backbuffer); - int16 *vs = (int16 *)surface->lock(); - SuperEagle ((u8*)backbuffer,144*2, NULL,(u8*)vs, surfacePitch<<1,144,224); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } - else - { - surface=new Surface(224*2,144*2,format); - #include "filter_partB.h" - console.open(app_window_title,224*2,144*2,format); - while (1) - { - #include "filter_partC.h" - console.open(app_window_title,224*2,144*2,format); - #include "filter_partD.h" - int16 *vs = (int16 *)surface->lock(); - SuperEagle ((u8*)backbuffer,224*2, NULL,(u8*)vs, surfacePitch<<1,224,144); - surface->unlock(); - surface->copy(console); - console.update(); - } - } - #include "filter_partE.h" - } +#include "filter_partA.h" + + if (app_rotated) + { + surface=new Surface(144*2,224*2,format); +#include "filter_partB.h" + console.open(app_window_title,144*2,224*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,144*2,224*2,format); +#include "filter_partD.h" + ws_rotate_backbuffer(backbuffer); + int16 *vs = (int16 *)surface->lock(); + SuperEagle ((u8*)backbuffer,144*2, NULL,(u8*)vs, surfacePitch<<1,144,224); + surface->unlock(); + surface->copy(console); + console.update(); + } + } + +#include "filter_partE.h" +} +else +{ + surface=new Surface(224*2,144*2,format); +#include "filter_partB.h" + console.open(app_window_title,224*2,144*2,format); + + while (1) + { +#include "filter_partC.h" + console.open(app_window_title,224*2,144*2,format); +#include "filter_partD.h" + int16 *vs = (int16 *)surface->lock(); + SuperEagle ((u8*)backbuffer,224*2, NULL,(u8*)vs, surfacePitch<<1,224,144); + surface->unlock(); + surface->copy(console); + console.update(); + } +} + +#include "filter_partE.h" +} } diff --git a/oswan/source/gpu.cpp b/oswan/source/gpu.cpp index ee19bec..29f9125 100644 --- a/oswan/source/gpu.cpp +++ b/oswan/source/gpu.cpp @@ -27,8 +27,8 @@ #include "io.h" #include "gpu.h" -#ifdef STATISTICS - #include "ticker.h" +#ifdef STATISTICS +#include "ticker.h" #endif //////////////////////////////////////////////////////////////////////////////// // @@ -45,10 +45,10 @@ extern uint8 *internalRam; enum VideoModes { - DISPLAY_MODE_GRAY = 0, - DISPLAY_MODE_2BPP = 4, - DISPLAY_MODE_P_4BPP = 7, - DISPLAY_MODE_L_4BPP = 6, + DISPLAY_MODE_GRAY = 0, + DISPLAY_MODE_2BPP = 4, + DISPLAY_MODE_P_4BPP = 7, + DISPLAY_MODE_L_4BPP = 6, }; //////////////////////////////////////////////////////////////////////////////// @@ -62,22 +62,22 @@ enum VideoModes // // //////////////////////////////////////////////////////////////////////////////// -#ifdef STATISTICS - long ws_4_shades_tiles_cache_update_time=0; - long ws_4_colors_tiles_cache_update_time=0; - long ws_16_colors_packed_tiles_cache_update_time=0; - long ws_16_colors_layered_tiles_cache_update_time=0; +#ifdef STATISTICS +long ws_4_shades_tiles_cache_update_time=0; +long ws_4_colors_tiles_cache_update_time=0; +long ws_16_colors_packed_tiles_cache_update_time=0; +long ws_16_colors_layered_tiles_cache_update_time=0; - long ws_4_shades_tiles_cache_update_number=0; - long ws_4_colors_tiles_cache_update_number=0; - long ws_16_colors_packed_tiles_cache_update_number=0; - long ws_16_colors_layered_tiles_cache_update_number=0; +long ws_4_shades_tiles_cache_update_number=0; +long ws_4_colors_tiles_cache_update_number=0; +long ws_16_colors_packed_tiles_cache_update_number=0; +long ws_16_colors_layered_tiles_cache_update_number=0; - long ws_background_color_rendering_time=0; - long ws_background_rendering_time=0; - long ws_foreground_rendering_time=0; - long ws_priority_0_sprites_rendering_time=0; - long ws_priority_1_sprites_rendering_time=0; +long ws_background_color_rendering_time=0; +long ws_background_rendering_time=0; +long ws_foreground_rendering_time=0; +long ws_priority_0_sprites_rendering_time=0; +long ws_priority_1_sprites_rendering_time=0; #endif //////////////////////////////////////////////////////////////////////////////// // @@ -109,24 +109,25 @@ int ws_gpu_forceMonoSystemBool=0; #define SHADE_COLOR_GREEN 1.00 #define SHADE_COLOR_BLUE 1.00 -int16 ws_colour_scheme_default[16]={ - RGB555(SHADE_COLOR_RED*30,SHADE_COLOR_GREEN*30,SHADE_COLOR_BLUE*30), - RGB555(SHADE_COLOR_RED*28,SHADE_COLOR_GREEN*28,SHADE_COLOR_BLUE*28), - RGB555(SHADE_COLOR_RED*26,SHADE_COLOR_GREEN*26,SHADE_COLOR_BLUE*26), - RGB555(SHADE_COLOR_RED*24,SHADE_COLOR_GREEN*24,SHADE_COLOR_BLUE*24), - RGB555(SHADE_COLOR_RED*22,SHADE_COLOR_GREEN*22,SHADE_COLOR_BLUE*22), - RGB555(SHADE_COLOR_RED*20,SHADE_COLOR_GREEN*20,SHADE_COLOR_BLUE*20), - RGB555(SHADE_COLOR_RED*18,SHADE_COLOR_GREEN*18,SHADE_COLOR_BLUE*18), - RGB555(SHADE_COLOR_RED*16,SHADE_COLOR_GREEN*16,SHADE_COLOR_BLUE*16), - RGB555(SHADE_COLOR_RED*14,SHADE_COLOR_GREEN*14,SHADE_COLOR_BLUE*14), - RGB555(SHADE_COLOR_RED*12,SHADE_COLOR_GREEN*12,SHADE_COLOR_BLUE*12), - RGB555(SHADE_COLOR_RED*10,SHADE_COLOR_GREEN*10,SHADE_COLOR_BLUE*10), - RGB555(SHADE_COLOR_RED*8,SHADE_COLOR_GREEN*8,SHADE_COLOR_BLUE*8), - RGB555(SHADE_COLOR_RED*6,SHADE_COLOR_GREEN*6,SHADE_COLOR_BLUE*6), - RGB555(SHADE_COLOR_RED*4,SHADE_COLOR_GREEN*4,SHADE_COLOR_BLUE*4), - RGB555(SHADE_COLOR_RED*2,SHADE_COLOR_GREEN*2,SHADE_COLOR_BLUE*2), - RGB555(SHADE_COLOR_RED*0,SHADE_COLOR_GREEN*0,SHADE_COLOR_BLUE*0) - }; +int16 ws_colour_scheme_default[16]= +{ + RGB555(SHADE_COLOR_RED*30,SHADE_COLOR_GREEN*30,SHADE_COLOR_BLUE*30), + RGB555(SHADE_COLOR_RED*28,SHADE_COLOR_GREEN*28,SHADE_COLOR_BLUE*28), + RGB555(SHADE_COLOR_RED*26,SHADE_COLOR_GREEN*26,SHADE_COLOR_BLUE*26), + RGB555(SHADE_COLOR_RED*24,SHADE_COLOR_GREEN*24,SHADE_COLOR_BLUE*24), + RGB555(SHADE_COLOR_RED*22,SHADE_COLOR_GREEN*22,SHADE_COLOR_BLUE*22), + RGB555(SHADE_COLOR_RED*20,SHADE_COLOR_GREEN*20,SHADE_COLOR_BLUE*20), + RGB555(SHADE_COLOR_RED*18,SHADE_COLOR_GREEN*18,SHADE_COLOR_BLUE*18), + RGB555(SHADE_COLOR_RED*16,SHADE_COLOR_GREEN*16,SHADE_COLOR_BLUE*16), + RGB555(SHADE_COLOR_RED*14,SHADE_COLOR_GREEN*14,SHADE_COLOR_BLUE*14), + RGB555(SHADE_COLOR_RED*12,SHADE_COLOR_GREEN*12,SHADE_COLOR_BLUE*12), + RGB555(SHADE_COLOR_RED*10,SHADE_COLOR_GREEN*10,SHADE_COLOR_BLUE*10), + RGB555(SHADE_COLOR_RED*8,SHADE_COLOR_GREEN*8,SHADE_COLOR_BLUE*8), + RGB555(SHADE_COLOR_RED*6,SHADE_COLOR_GREEN*6,SHADE_COLOR_BLUE*6), + RGB555(SHADE_COLOR_RED*4,SHADE_COLOR_GREEN*4,SHADE_COLOR_BLUE*4), + RGB555(SHADE_COLOR_RED*2,SHADE_COLOR_GREEN*2,SHADE_COLOR_BLUE*2), + RGB555(SHADE_COLOR_RED*0,SHADE_COLOR_GREEN*0,SHADE_COLOR_BLUE*0) +}; // green #undef SHADE_COLOR_RED #undef SHADE_COLOR_GREEN @@ -135,24 +136,25 @@ int16 ws_colour_scheme_default[16]={ #define SHADE_COLOR_GREEN 0.90 #define SHADE_COLOR_BLUE 0.20 -int16 ws_colour_scheme_green[16]={ - RGB555(SHADE_COLOR_RED*30,SHADE_COLOR_GREEN*30,SHADE_COLOR_BLUE*30), - RGB555(SHADE_COLOR_RED*28,SHADE_COLOR_GREEN*28,SHADE_COLOR_BLUE*28), - RGB555(SHADE_COLOR_RED*26,SHADE_COLOR_GREEN*26,SHADE_COLOR_BLUE*26), - RGB555(SHADE_COLOR_RED*24,SHADE_COLOR_GREEN*24,SHADE_COLOR_BLUE*24), - RGB555(SHADE_COLOR_RED*22,SHADE_COLOR_GREEN*22,SHADE_COLOR_BLUE*22), - RGB555(SHADE_COLOR_RED*20,SHADE_COLOR_GREEN*20,SHADE_COLOR_BLUE*20), - RGB555(SHADE_COLOR_RED*18,SHADE_COLOR_GREEN*18,SHADE_COLOR_BLUE*18), - RGB555(SHADE_COLOR_RED*16,SHADE_COLOR_GREEN*16,SHADE_COLOR_BLUE*16), - RGB555(SHADE_COLOR_RED*14,SHADE_COLOR_GREEN*14,SHADE_COLOR_BLUE*14), - RGB555(SHADE_COLOR_RED*12,SHADE_COLOR_GREEN*12,SHADE_COLOR_BLUE*12), - RGB555(SHADE_COLOR_RED*10,SHADE_COLOR_GREEN*10,SHADE_COLOR_BLUE*10), - RGB555(SHADE_COLOR_RED*8,SHADE_COLOR_GREEN*8,SHADE_COLOR_BLUE*8), - RGB555(SHADE_COLOR_RED*6,SHADE_COLOR_GREEN*6,SHADE_COLOR_BLUE*6), - RGB555(SHADE_COLOR_RED*4,SHADE_COLOR_GREEN*4,SHADE_COLOR_BLUE*4), - RGB555(SHADE_COLOR_RED*2,SHADE_COLOR_GREEN*2,SHADE_COLOR_BLUE*2), - RGB555(SHADE_COLOR_RED*0,SHADE_COLOR_GREEN*0,SHADE_COLOR_BLUE*0) - }; +int16 ws_colour_scheme_green[16]= +{ + RGB555(SHADE_COLOR_RED*30,SHADE_COLOR_GREEN*30,SHADE_COLOR_BLUE*30), + RGB555(SHADE_COLOR_RED*28,SHADE_COLOR_GREEN*28,SHADE_COLOR_BLUE*28), + RGB555(SHADE_COLOR_RED*26,SHADE_COLOR_GREEN*26,SHADE_COLOR_BLUE*26), + RGB555(SHADE_COLOR_RED*24,SHADE_COLOR_GREEN*24,SHADE_COLOR_BLUE*24), + RGB555(SHADE_COLOR_RED*22,SHADE_COLOR_GREEN*22,SHADE_COLOR_BLUE*22), + RGB555(SHADE_COLOR_RED*20,SHADE_COLOR_GREEN*20,SHADE_COLOR_BLUE*20), + RGB555(SHADE_COLOR_RED*18,SHADE_COLOR_GREEN*18,SHADE_COLOR_BLUE*18), + RGB555(SHADE_COLOR_RED*16,SHADE_COLOR_GREEN*16,SHADE_COLOR_BLUE*16), + RGB555(SHADE_COLOR_RED*14,SHADE_COLOR_GREEN*14,SHADE_COLOR_BLUE*14), + RGB555(SHADE_COLOR_RED*12,SHADE_COLOR_GREEN*12,SHADE_COLOR_BLUE*12), + RGB555(SHADE_COLOR_RED*10,SHADE_COLOR_GREEN*10,SHADE_COLOR_BLUE*10), + RGB555(SHADE_COLOR_RED*8,SHADE_COLOR_GREEN*8,SHADE_COLOR_BLUE*8), + RGB555(SHADE_COLOR_RED*6,SHADE_COLOR_GREEN*6,SHADE_COLOR_BLUE*6), + RGB555(SHADE_COLOR_RED*4,SHADE_COLOR_GREEN*4,SHADE_COLOR_BLUE*4), + RGB555(SHADE_COLOR_RED*2,SHADE_COLOR_GREEN*2,SHADE_COLOR_BLUE*2), + RGB555(SHADE_COLOR_RED*0,SHADE_COLOR_GREEN*0,SHADE_COLOR_BLUE*0) +}; // amber #undef SHADE_COLOR_RED #undef SHADE_COLOR_GREEN @@ -161,24 +163,25 @@ int16 ws_colour_scheme_green[16]={ #define SHADE_COLOR_GREEN 0.61 #define SHADE_COLOR_BLUE 0.00 -int16 ws_colour_scheme_amber[16]={ - RGB555(SHADE_COLOR_RED*30,SHADE_COLOR_GREEN*30,SHADE_COLOR_BLUE*30), - RGB555(SHADE_COLOR_RED*28,SHADE_COLOR_GREEN*28,SHADE_COLOR_BLUE*28), - RGB555(SHADE_COLOR_RED*26,SHADE_COLOR_GREEN*26,SHADE_COLOR_BLUE*26), - RGB555(SHADE_COLOR_RED*24,SHADE_COLOR_GREEN*24,SHADE_COLOR_BLUE*24), - RGB555(SHADE_COLOR_RED*22,SHADE_COLOR_GREEN*22,SHADE_COLOR_BLUE*22), - RGB555(SHADE_COLOR_RED*20,SHADE_COLOR_GREEN*20,SHADE_COLOR_BLUE*20), - RGB555(SHADE_COLOR_RED*18,SHADE_COLOR_GREEN*18,SHADE_COLOR_BLUE*18), - RGB555(SHADE_COLOR_RED*16,SHADE_COLOR_GREEN*16,SHADE_COLOR_BLUE*16), - RGB555(SHADE_COLOR_RED*14,SHADE_COLOR_GREEN*14,SHADE_COLOR_BLUE*14), - RGB555(SHADE_COLOR_RED*12,SHADE_COLOR_GREEN*12,SHADE_COLOR_BLUE*12), - RGB555(SHADE_COLOR_RED*10,SHADE_COLOR_GREEN*10,SHADE_COLOR_BLUE*10), - RGB555(SHADE_COLOR_RED*8,SHADE_COLOR_GREEN*8,SHADE_COLOR_BLUE*8), - RGB555(SHADE_COLOR_RED*6,SHADE_COLOR_GREEN*6,SHADE_COLOR_BLUE*6), - RGB555(SHADE_COLOR_RED*4,SHADE_COLOR_GREEN*4,SHADE_COLOR_BLUE*4), - RGB555(SHADE_COLOR_RED*2,SHADE_COLOR_GREEN*2,SHADE_COLOR_BLUE*2), - RGB555(SHADE_COLOR_RED*0,SHADE_COLOR_GREEN*0,SHADE_COLOR_BLUE*0) - }; +int16 ws_colour_scheme_amber[16]= +{ + RGB555(SHADE_COLOR_RED*30,SHADE_COLOR_GREEN*30,SHADE_COLOR_BLUE*30), + RGB555(SHADE_COLOR_RED*28,SHADE_COLOR_GREEN*28,SHADE_COLOR_BLUE*28), + RGB555(SHADE_COLOR_RED*26,SHADE_COLOR_GREEN*26,SHADE_COLOR_BLUE*26), + RGB555(SHADE_COLOR_RED*24,SHADE_COLOR_GREEN*24,SHADE_COLOR_BLUE*24), + RGB555(SHADE_COLOR_RED*22,SHADE_COLOR_GREEN*22,SHADE_COLOR_BLUE*22), + RGB555(SHADE_COLOR_RED*20,SHADE_COLOR_GREEN*20,SHADE_COLOR_BLUE*20), + RGB555(SHADE_COLOR_RED*18,SHADE_COLOR_GREEN*18,SHADE_COLOR_BLUE*18), + RGB555(SHADE_COLOR_RED*16,SHADE_COLOR_GREEN*16,SHADE_COLOR_BLUE*16), + RGB555(SHADE_COLOR_RED*14,SHADE_COLOR_GREEN*14,SHADE_COLOR_BLUE*14), + RGB555(SHADE_COLOR_RED*12,SHADE_COLOR_GREEN*12,SHADE_COLOR_BLUE*12), + RGB555(SHADE_COLOR_RED*10,SHADE_COLOR_GREEN*10,SHADE_COLOR_BLUE*10), + RGB555(SHADE_COLOR_RED*8,SHADE_COLOR_GREEN*8,SHADE_COLOR_BLUE*8), + RGB555(SHADE_COLOR_RED*6,SHADE_COLOR_GREEN*6,SHADE_COLOR_BLUE*6), + RGB555(SHADE_COLOR_RED*4,SHADE_COLOR_GREEN*4,SHADE_COLOR_BLUE*4), + RGB555(SHADE_COLOR_RED*2,SHADE_COLOR_GREEN*2,SHADE_COLOR_BLUE*2), + RGB555(SHADE_COLOR_RED*0,SHADE_COLOR_GREEN*0,SHADE_COLOR_BLUE*0) +}; uint8 *ws_tile_cache; uint8 *ws_hflipped_tile_cache; @@ -202,12 +205,20 @@ uint8 *wsc_modified_tile; //////////////////////////////////////////////////////////////////////////////// void ws_gpu_set_colour_scheme(int scheme) { - switch (scheme) - { - case COLOUR_SCHEME_DEFAULT: memcpy(ws_shades,ws_colour_scheme_default,16*sizeof(int16)); break; - case COLOUR_SCHEME_AMBER : memcpy(ws_shades,ws_colour_scheme_amber,16*sizeof(int16)); break; - case COLOUR_SCHEME_GREEN : memcpy(ws_shades,ws_colour_scheme_green,16*sizeof(int16)); break; - } + switch (scheme) + { + case COLOUR_SCHEME_DEFAULT: + memcpy(ws_shades,ws_colour_scheme_default,16*sizeof(int16)); + break; + + case COLOUR_SCHEME_AMBER : + memcpy(ws_shades,ws_colour_scheme_amber,16*sizeof(int16)); + break; + + case COLOUR_SCHEME_GREEN : + memcpy(ws_shades,ws_colour_scheme_green,16*sizeof(int16)); + break; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -222,9 +233,9 @@ void ws_gpu_set_colour_scheme(int scheme) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_forceColorSystem(void) { - ws_gpu_forceColorSystemBool=1; - ws_gpu_forceMonoSystemBool=0; - ws_gpu_operatingInColor=1; + ws_gpu_forceColorSystemBool=1; + ws_gpu_forceMonoSystemBool=0; + ws_gpu_operatingInColor=1; } //////////////////////////////////////////////////////////////////////////////// // @@ -239,9 +250,9 @@ void ws_gpu_forceColorSystem(void) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_forceMonoSystem(void) { - ws_gpu_forceColorSystemBool=0; - ws_gpu_forceMonoSystemBool=1; - ws_gpu_operatingInColor=0; + ws_gpu_forceColorSystemBool=0; + ws_gpu_forceMonoSystemBool=1; + ws_gpu_operatingInColor=0; } //////////////////////////////////////////////////////////////////////////////// // @@ -256,26 +267,26 @@ void ws_gpu_forceMonoSystem(void) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_init(void) { - ws_tile_cache = (uint8*)malloc(512*8*8); - wsc_tile_cache = (uint8*)malloc(1024*8*8); + ws_tile_cache = (uint8*)malloc(512*8*8); + wsc_tile_cache = (uint8*)malloc(1024*8*8); - ws_hflipped_tile_cache = (uint8*)malloc(512*8*8); - wsc_hflipped_tile_cache = (uint8*)malloc(1024*8*8); + ws_hflipped_tile_cache = (uint8*)malloc(512*8*8); + wsc_hflipped_tile_cache = (uint8*)malloc(1024*8*8); - ws_modified_tile = (uint8*)malloc(512); - wsc_modified_tile = (uint8*)malloc(1024); + ws_modified_tile = (uint8*)malloc(512); + wsc_modified_tile = (uint8*)malloc(1024); - memset(ws_tile_cache,0x00,512*8*8); - memset(wsc_tile_cache,0x00,1024*8*8); + memset(ws_tile_cache,0x00,512*8*8); + memset(wsc_tile_cache,0x00,1024*8*8); - memset(ws_hflipped_tile_cache,0x00,512*8*8); - memset(wsc_hflipped_tile_cache,0x00,1024*8*8); + memset(ws_hflipped_tile_cache,0x00,512*8*8); + memset(wsc_hflipped_tile_cache,0x00,1024*8*8); - memset(ws_modified_tile,0x01,512); - memset(wsc_modified_tile,0x01,1024); + memset(ws_modified_tile,0x01,512); + memset(wsc_modified_tile,0x01,1024); - ws_gpu_forceColorSystemBool=0; - ws_gpu_forceMonoSystemBool=0; + ws_gpu_forceColorSystemBool=0; + ws_gpu_forceMonoSystemBool=0; } //////////////////////////////////////////////////////////////////////////////// // @@ -290,33 +301,45 @@ void ws_gpu_init(void) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_done(void) { - free(ws_tile_cache); - free(wsc_tile_cache); - free(ws_hflipped_tile_cache); - free(wsc_hflipped_tile_cache); - free(ws_modified_tile); - free(wsc_modified_tile); -#ifdef STATISTICS - printf("Statistics:\n"); - printf("\tcache:\n"); - if (ws_4_shades_tiles_cache_update_number) - printf("\t\t4 shades tiles update time : %i\n",ws_4_shades_tiles_cache_update_time/ws_4_shades_tiles_cache_update_number); - if (ws_4_colors_tiles_cache_update_number) - printf("\t\t4 colors tiles update time : %i\n",ws_4_colors_tiles_cache_update_time/ws_4_colors_tiles_cache_update_number); - if (ws_16_colors_packed_tiles_cache_update_number) - printf("\t\t16 colors packed tiles update time : %i\n",ws_16_colors_packed_tiles_cache_update_time/ws_16_colors_packed_tiles_cache_update_number); - if (ws_16_colors_layered_tiles_cache_update_number) - printf("\t\t16 colors layered tiles update time: %i\n",ws_16_colors_layered_tiles_cache_update_time/ws_16_colors_layered_tiles_cache_update_number); + free(ws_tile_cache); + free(wsc_tile_cache); + free(ws_hflipped_tile_cache); + free(wsc_hflipped_tile_cache); + free(ws_modified_tile); + free(wsc_modified_tile); +#ifdef STATISTICS + printf("Statistics:\n"); + printf("\tcache:\n"); - printf("\tscanline rendering:\n"); - long total= ws_background_color_rendering_time+ws_background_rendering_time+ - ws_foreground_rendering_time+ws_priority_0_sprites_rendering_time+ - ws_priority_1_sprites_rendering_time; - printf("\t\tbackground color : %4i (%3i %%)\n",ws_background_color_rendering_time,(ws_background_color_rendering_time*100)/total); - printf("\t\tbackground : %4i (%3i %%)\n",ws_background_rendering_time,(ws_background_rendering_time*100)/total); - printf("\t\tforeground : %4i (%3i %%)\n",ws_foreground_rendering_time,(ws_foreground_rendering_time*100)/total); - printf("\t\tpriority 0 sprites : %4i (%3i %%)\n",ws_priority_0_sprites_rendering_time,(ws_priority_0_sprites_rendering_time*100)/total); - printf("\t\tpriority 1 sprites : %4i (%3i %%)\n",ws_priority_1_sprites_rendering_time,(ws_priority_1_sprites_rendering_time*100)/total); + if (ws_4_shades_tiles_cache_update_number) + { + printf("\t\t4 shades tiles update time : %i\n",ws_4_shades_tiles_cache_update_time/ws_4_shades_tiles_cache_update_number); + } + + if (ws_4_colors_tiles_cache_update_number) + { + printf("\t\t4 colors tiles update time : %i\n",ws_4_colors_tiles_cache_update_time/ws_4_colors_tiles_cache_update_number); + } + + if (ws_16_colors_packed_tiles_cache_update_number) + { + printf("\t\t16 colors packed tiles update time : %i\n",ws_16_colors_packed_tiles_cache_update_time/ws_16_colors_packed_tiles_cache_update_number); + } + + if (ws_16_colors_layered_tiles_cache_update_number) + { + printf("\t\t16 colors layered tiles update time: %i\n",ws_16_colors_layered_tiles_cache_update_time/ws_16_colors_layered_tiles_cache_update_number); + } + + printf("\tscanline rendering:\n"); + long total= ws_background_color_rendering_time+ws_background_rendering_time+ + ws_foreground_rendering_time+ws_priority_0_sprites_rendering_time+ + ws_priority_1_sprites_rendering_time; + printf("\t\tbackground color : %4i (%3i %%)\n",ws_background_color_rendering_time,(ws_background_color_rendering_time*100)/total); + printf("\t\tbackground : %4i (%3i %%)\n",ws_background_rendering_time,(ws_background_rendering_time*100)/total); + printf("\t\tforeground : %4i (%3i %%)\n",ws_foreground_rendering_time,(ws_foreground_rendering_time*100)/total); + printf("\t\tpriority 0 sprites : %4i (%3i %%)\n",ws_priority_0_sprites_rendering_time,(ws_priority_0_sprites_rendering_time*100)/total); + printf("\t\tpriority 1 sprites : %4i (%3i %%)\n",ws_priority_1_sprites_rendering_time,(ws_priority_1_sprites_rendering_time*100)/total); #endif } //////////////////////////////////////////////////////////////////////////////// @@ -332,16 +355,16 @@ void ws_gpu_done(void) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_changeVideoMode(uint8 value) { - if (ws_videoMode != (value>>5)) - { - ws_videoMode = value >> 5; + if (ws_videoMode != (value>>5)) + { + ws_videoMode = value >> 5; // if (ws_videoMode==4) // ws_videoMode=2; - - // mark all tiles dirty - memset(wsc_modified_tile,0x01,1024); - memset(ws_modified_tile,0x01,512); - } + + // mark all tiles dirty + memset(wsc_modified_tile,0x01,1024); + memset(ws_modified_tile,0x01,512); + } } //////////////////////////////////////////////////////////////////////////////// // @@ -356,10 +379,10 @@ void ws_gpu_changeVideoMode(uint8 value) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_reset(void) { - memset(wsc_modified_tile,0x01,1024); - memset(ws_modified_tile,0x01,512); - ws_gpu_scanline=0; - ws_gpu_changeVideoMode(0x00); + memset(wsc_modified_tile,0x01,1024); + memset(ws_modified_tile,0x01,512); + ws_gpu_scanline=0; + ws_gpu_changeVideoMode(0x00); } //////////////////////////////////////////////////////////////////////////////// // @@ -374,8 +397,8 @@ void ws_gpu_reset(void) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_clearCache(void) { - memset(wsc_modified_tile,0x01,1024); - memset(ws_modified_tile,0x01,512); + memset(wsc_modified_tile,0x01,1024); + memset(ws_modified_tile,0x01,512); } //////////////////////////////////////////////////////////////////////////////// // @@ -388,222 +411,247 @@ void ws_gpu_clearCache(void) // // //////////////////////////////////////////////////////////////////////////////// -uint8 *ws_tileCache_getTileRow(uint32 tileIndex, uint32 line, - uint32 vFlip, uint32 hFlip, uint32 bank) +uint8 *ws_tileCache_getTileRow(uint32 tileIndex, uint32 line, + uint32 vFlip, uint32 hFlip, uint32 bank) { - if (ws_gpu_operatingInColor) - { - if (bank) - tileIndex+=512; + if (ws_gpu_operatingInColor) + { + if (bank) + { + tileIndex+=512; + } - // need to update tile cache ? - // 4 colors tiles - if ((ws_videoMode == DISPLAY_MODE_2BPP) && ( ws_modified_tile[tileIndex]) ) - { -#ifdef STATISTICS - ws_4_colors_tiles_cache_update_time+=-ticker(); + // need to update tile cache ? + // 4 colors tiles + if ((ws_videoMode == DISPLAY_MODE_2BPP) && ( ws_modified_tile[tileIndex]) ) + { +#ifdef STATISTICS + ws_4_colors_tiles_cache_update_time+=-ticker(); #endif - uint8 *tileInCachePtr = &wsc_tile_cache[tileIndex<<6]; - uint8 *hflippedTileInCachePtr = &wsc_hflipped_tile_cache[tileIndex<<6]; - uint16 *tileInRamPtr = (uint16*)&internalRam[0x2000+(tileIndex<<4)]; - uint16 tileLine; + uint8 *tileInCachePtr = &wsc_tile_cache[tileIndex<<6]; + uint8 *hflippedTileInCachePtr = &wsc_hflipped_tile_cache[tileIndex<<6]; + uint16 *tileInRamPtr = (uint16*)&internalRam[0x2000+(tileIndex<<4)]; + uint16 tileLine; - for (int line=0;line<8;line++) - { - tileLine=*tileInRamPtr++; + for (int line=0; line<8; line++) + { + tileLine=*tileInRamPtr++; - tileInCachePtr[0]=((tileLine&0x80)>>7)|((tileLine&0x8000)>>14); - hflippedTileInCachePtr[7]=tileInCachePtr[0]; - tileInCachePtr[1]=((tileLine&0x40)>>6)|((tileLine&0x4000)>>13); - hflippedTileInCachePtr[6]=tileInCachePtr[1]; - tileInCachePtr[2]=((tileLine&0x20)>>5)|((tileLine&0x2000)>>12); - hflippedTileInCachePtr[5]=tileInCachePtr[2]; - tileInCachePtr[3]=((tileLine&0x10)>>4)|((tileLine&0x1000)>>11); - hflippedTileInCachePtr[4]=tileInCachePtr[3]; - tileInCachePtr[4]=((tileLine&0x08)>>3)|((tileLine&0x0800)>>10); - hflippedTileInCachePtr[3]=tileInCachePtr[4]; - tileInCachePtr[5]=((tileLine&0x04)>>2)|((tileLine&0x0400)>>9); - hflippedTileInCachePtr[2]=tileInCachePtr[5]; - tileInCachePtr[6]=((tileLine&0x02)>>1)|((tileLine&0x0200)>>8); - hflippedTileInCachePtr[1]=tileInCachePtr[6]; - tileInCachePtr[7]=((tileLine&0x01)>>0)|((tileLine&0x0100)>>7); - hflippedTileInCachePtr[0]=tileInCachePtr[7]; + tileInCachePtr[0]=((tileLine&0x80)>>7)|((tileLine&0x8000)>>14); + hflippedTileInCachePtr[7]=tileInCachePtr[0]; + tileInCachePtr[1]=((tileLine&0x40)>>6)|((tileLine&0x4000)>>13); + hflippedTileInCachePtr[6]=tileInCachePtr[1]; + tileInCachePtr[2]=((tileLine&0x20)>>5)|((tileLine&0x2000)>>12); + hflippedTileInCachePtr[5]=tileInCachePtr[2]; + tileInCachePtr[3]=((tileLine&0x10)>>4)|((tileLine&0x1000)>>11); + hflippedTileInCachePtr[4]=tileInCachePtr[3]; + tileInCachePtr[4]=((tileLine&0x08)>>3)|((tileLine&0x0800)>>10); + hflippedTileInCachePtr[3]=tileInCachePtr[4]; + tileInCachePtr[5]=((tileLine&0x04)>>2)|((tileLine&0x0400)>>9); + hflippedTileInCachePtr[2]=tileInCachePtr[5]; + tileInCachePtr[6]=((tileLine&0x02)>>1)|((tileLine&0x0200)>>8); + hflippedTileInCachePtr[1]=tileInCachePtr[6]; + tileInCachePtr[7]=((tileLine&0x01)>>0)|((tileLine&0x0100)>>7); + hflippedTileInCachePtr[0]=tileInCachePtr[7]; - tileInCachePtr+=8; - hflippedTileInCachePtr+=8; - } - ws_modified_tile[tileIndex]=0; -#ifdef STATISTICS - ws_4_colors_tiles_cache_update_time+=ticker(); - ws_4_colors_tiles_cache_update_number++; + tileInCachePtr+=8; + hflippedTileInCachePtr+=8; + } + + ws_modified_tile[tileIndex]=0; +#ifdef STATISTICS + ws_4_colors_tiles_cache_update_time+=ticker(); + ws_4_colors_tiles_cache_update_number++; #endif - } - else if (wsc_modified_tile[tileIndex]) - { - // 16 colors by tile layered mode - if (ws_videoMode == DISPLAY_MODE_L_4BPP) - { -#ifdef STATISTICS - ws_16_colors_layered_tiles_cache_update_time+=-ticker(); + } + else if (wsc_modified_tile[tileIndex]) + { + // 16 colors by tile layered mode + if (ws_videoMode == DISPLAY_MODE_L_4BPP) + { +#ifdef STATISTICS + ws_16_colors_layered_tiles_cache_update_time+=-ticker(); #endif - uint8 *tileInCachePtr = &wsc_tile_cache[tileIndex<<6]; - uint8 *hflippedTileInCachePtr = &wsc_hflipped_tile_cache[tileIndex<<6]; - uint32 *tileInRamPtr = (uint32*)&internalRam[0x4000+(tileIndex<<5)]; - uint32 tileLine; + uint8 *tileInCachePtr = &wsc_tile_cache[tileIndex<<6]; + uint8 *hflippedTileInCachePtr = &wsc_hflipped_tile_cache[tileIndex<<6]; + uint32 *tileInRamPtr = (uint32*)&internalRam[0x4000+(tileIndex<<5)]; + uint32 tileLine; - for (int line=0;line<8;line++) - { - tileLine=*tileInRamPtr++; - - tileInCachePtr[0]=((tileLine&0x00000080)>>7)|((tileLine&0x00008000)>>14)| - ((tileLine&0x00800000)>>21)|((tileLine&0x80000000)>>28); - hflippedTileInCachePtr[7]=tileInCachePtr[0]; + for (int line=0; line<8; line++) + { + tileLine=*tileInRamPtr++; - tileInCachePtr[1]=((tileLine&0x00000040)>>6)|((tileLine&0x00004000)>>13)| - ((tileLine&0x00400000)>>20)|((tileLine&0x40000000)>>27); - hflippedTileInCachePtr[6]=tileInCachePtr[1]; - - tileInCachePtr[2]=((tileLine&0x00000020)>>5)|((tileLine&0x00002000)>>12)| - ((tileLine&0x00200000)>>19)|((tileLine&0x20000000)>>26); - hflippedTileInCachePtr[5]=tileInCachePtr[2]; - - tileInCachePtr[3]=((tileLine&0x00000010)>>4)|((tileLine&0x00001000)>>11)| - ((tileLine&0x00100000)>>18)|((tileLine&0x10000000)>>25); - hflippedTileInCachePtr[4]=tileInCachePtr[3]; - - tileInCachePtr[4]=((tileLine&0x00000008)>>3)|((tileLine&0x00000800)>>10)| - ((tileLine&0x00080000)>>17)|((tileLine&0x08000000)>>24); - hflippedTileInCachePtr[3]=tileInCachePtr[4]; - - tileInCachePtr[5]=((tileLine&0x00000004)>>2)|((tileLine&0x00000400)>>9)| - ((tileLine&0x00040000)>>16)|((tileLine&0x04000000)>>23); - hflippedTileInCachePtr[2]=tileInCachePtr[5]; - - tileInCachePtr[6]=((tileLine&0x00000002)>>1)|((tileLine&0x00000200)>>8)| - ((tileLine&0x00020000)>>15)|((tileLine&0x02000000)>>22); - hflippedTileInCachePtr[1]=tileInCachePtr[6]; - - tileInCachePtr[7]=((tileLine&0x00000001)>>0)|((tileLine&0x00000100)>>7)| - ((tileLine&0x00010000)>>14)|((tileLine&0x01000000)>>21); - hflippedTileInCachePtr[0]=tileInCachePtr[7]; + tileInCachePtr[0]=((tileLine&0x00000080)>>7)|((tileLine&0x00008000)>>14)| + ((tileLine&0x00800000)>>21)|((tileLine&0x80000000)>>28); + hflippedTileInCachePtr[7]=tileInCachePtr[0]; - tileInCachePtr+=8; - hflippedTileInCachePtr+=8; - } -#ifdef STATISTICS - ws_16_colors_layered_tiles_cache_update_time+=ticker(); - ws_16_colors_layered_tiles_cache_update_number++; + tileInCachePtr[1]=((tileLine&0x00000040)>>6)|((tileLine&0x00004000)>>13)| + ((tileLine&0x00400000)>>20)|((tileLine&0x40000000)>>27); + hflippedTileInCachePtr[6]=tileInCachePtr[1]; + + tileInCachePtr[2]=((tileLine&0x00000020)>>5)|((tileLine&0x00002000)>>12)| + ((tileLine&0x00200000)>>19)|((tileLine&0x20000000)>>26); + hflippedTileInCachePtr[5]=tileInCachePtr[2]; + + tileInCachePtr[3]=((tileLine&0x00000010)>>4)|((tileLine&0x00001000)>>11)| + ((tileLine&0x00100000)>>18)|((tileLine&0x10000000)>>25); + hflippedTileInCachePtr[4]=tileInCachePtr[3]; + + tileInCachePtr[4]=((tileLine&0x00000008)>>3)|((tileLine&0x00000800)>>10)| + ((tileLine&0x00080000)>>17)|((tileLine&0x08000000)>>24); + hflippedTileInCachePtr[3]=tileInCachePtr[4]; + + tileInCachePtr[5]=((tileLine&0x00000004)>>2)|((tileLine&0x00000400)>>9)| + ((tileLine&0x00040000)>>16)|((tileLine&0x04000000)>>23); + hflippedTileInCachePtr[2]=tileInCachePtr[5]; + + tileInCachePtr[6]=((tileLine&0x00000002)>>1)|((tileLine&0x00000200)>>8)| + ((tileLine&0x00020000)>>15)|((tileLine&0x02000000)>>22); + hflippedTileInCachePtr[1]=tileInCachePtr[6]; + + tileInCachePtr[7]=((tileLine&0x00000001)>>0)|((tileLine&0x00000100)>>7)| + ((tileLine&0x00010000)>>14)|((tileLine&0x01000000)>>21); + hflippedTileInCachePtr[0]=tileInCachePtr[7]; + + tileInCachePtr+=8; + hflippedTileInCachePtr+=8; + } + +#ifdef STATISTICS + ws_16_colors_layered_tiles_cache_update_time+=ticker(); + ws_16_colors_layered_tiles_cache_update_number++; #endif - } - else - // 16 colors by tile packed mode - if (ws_videoMode == DISPLAY_MODE_P_4BPP) - { -#ifdef STATISTICS - ws_16_colors_packed_tiles_cache_update_time+=-ticker(); -#endif - uint8 *tileInCachePtr = &wsc_tile_cache[tileIndex<<6]; - uint8 *hflippedTileInCachePtr = &wsc_hflipped_tile_cache[tileIndex<<6]; - uint32 *tileInRamPtr = (uint32*)&internalRam[0x4000+(tileIndex<<5)]; - uint32 tileLine; + } + else - for (int line=0;line<8;line++) - { - tileLine=*tileInRamPtr++; - - tileInCachePtr[0]=(tileLine>>4)&0x0f; - hflippedTileInCachePtr[7]=tileInCachePtr[0]; - tileInCachePtr[1]=(tileLine>>0)&0x0f; - hflippedTileInCachePtr[6]=tileInCachePtr[1]; - tileInCachePtr[2]=(tileLine>>12)&0x0f; - hflippedTileInCachePtr[5]=tileInCachePtr[2]; - tileInCachePtr[3]=(tileLine>>8)&0x0f; - hflippedTileInCachePtr[4]=tileInCachePtr[3]; - tileInCachePtr[4]=(tileLine>>20)&0x0f; - hflippedTileInCachePtr[3]=tileInCachePtr[4]; - tileInCachePtr[5]=(tileLine>>16)&0x0f; - hflippedTileInCachePtr[2]=tileInCachePtr[5]; - tileInCachePtr[6]=(tileLine>>28)&0x0f; - hflippedTileInCachePtr[1]=tileInCachePtr[6]; - tileInCachePtr[7]=(tileLine>>24)&0x0f; - hflippedTileInCachePtr[0]=tileInCachePtr[7]; + // 16 colors by tile packed mode + if (ws_videoMode == DISPLAY_MODE_P_4BPP) + { +#ifdef STATISTICS + ws_16_colors_packed_tiles_cache_update_time+=-ticker(); +#endif + uint8 *tileInCachePtr = &wsc_tile_cache[tileIndex<<6]; + uint8 *hflippedTileInCachePtr = &wsc_hflipped_tile_cache[tileIndex<<6]; + uint32 *tileInRamPtr = (uint32*)&internalRam[0x4000+(tileIndex<<5)]; + uint32 tileLine; - tileInCachePtr+=8; - hflippedTileInCachePtr+=8; - - } -#ifdef STATISTICS - ws_16_colors_packed_tiles_cache_update_time+=ticker(); - ws_16_colors_packed_tiles_cache_update_number++; -#endif - } - else - { - // unknown mode - } - // tile cache updated - wsc_modified_tile[tileIndex]=0; - } - if (vFlip) - line=7-line; - if (hFlip) - return(&wsc_hflipped_tile_cache[(tileIndex<<6)+(line<<3)]); - else - return(&wsc_tile_cache[(tileIndex<<6)+(line<<3)]); - - } - else - { - // need to update tile cache ? - if (ws_modified_tile[tileIndex]) - { -#ifdef STATISTICS - ws_4_shades_tiles_cache_update_time+=-ticker(); -#endif - uint8 *tileInCachePtr = &ws_tile_cache[tileIndex<<6]; - uint8 *hflippedTileInCachePtr = &ws_hflipped_tile_cache[(tileIndex<<6)+7]; - uint32 *tileInRamPtr = (uint32*)&internalRam[0x2000+(tileIndex<<4)]; - uint32 tileLine; + for (int line=0; line<8; line++) + { + tileLine=*tileInRamPtr++; - for (int line=0;line<4;line++) - { - tileLine=*tileInRamPtr++; - - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x80)>>7)|((tileLine&0x8000)>>14); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x40)>>6)|((tileLine&0x4000)>>13); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x20)>>5)|((tileLine&0x2000)>>12); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x10)>>4)|((tileLine&0x1000)>>11); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x08)>>3)|((tileLine&0x0800)>>10); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x04)>>2)|((tileLine&0x0400)>>9); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x02)>>1)|((tileLine&0x0200)>>8); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x01)>>0)|((tileLine&0x0100)>>7); - hflippedTileInCachePtr+=16; - tileLine>>=16; - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x80)>>7)|((tileLine&0x8000)>>14); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x40)>>6)|((tileLine&0x4000)>>13); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x20)>>5)|((tileLine&0x2000)>>12); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x10)>>4)|((tileLine&0x1000)>>11); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x08)>>3)|((tileLine&0x0800)>>10); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x04)>>2)|((tileLine&0x0400)>>9); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x02)>>1)|((tileLine&0x0200)>>8); - *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x01)>>0)|((tileLine&0x0100)>>7); - hflippedTileInCachePtr+=16; - } - // tile cache updated - ws_modified_tile[tileIndex]=0; -#ifdef STATISTICS - ws_4_shades_tiles_cache_update_time+=ticker(); - ws_4_shades_tiles_cache_update_number++; + tileInCachePtr[0]=(tileLine>>4)&0x0f; + hflippedTileInCachePtr[7]=tileInCachePtr[0]; + tileInCachePtr[1]=(tileLine>>0)&0x0f; + hflippedTileInCachePtr[6]=tileInCachePtr[1]; + tileInCachePtr[2]=(tileLine>>12)&0x0f; + hflippedTileInCachePtr[5]=tileInCachePtr[2]; + tileInCachePtr[3]=(tileLine>>8)&0x0f; + hflippedTileInCachePtr[4]=tileInCachePtr[3]; + tileInCachePtr[4]=(tileLine>>20)&0x0f; + hflippedTileInCachePtr[3]=tileInCachePtr[4]; + tileInCachePtr[5]=(tileLine>>16)&0x0f; + hflippedTileInCachePtr[2]=tileInCachePtr[5]; + tileInCachePtr[6]=(tileLine>>28)&0x0f; + hflippedTileInCachePtr[1]=tileInCachePtr[6]; + tileInCachePtr[7]=(tileLine>>24)&0x0f; + hflippedTileInCachePtr[0]=tileInCachePtr[7]; + + tileInCachePtr+=8; + hflippedTileInCachePtr+=8; + + } + +#ifdef STATISTICS + ws_16_colors_packed_tiles_cache_update_time+=ticker(); + ws_16_colors_packed_tiles_cache_update_number++; #endif - } - if (vFlip) - line=7-line; - if (hFlip) - return(&ws_hflipped_tile_cache[(tileIndex<<6)+(line<<3)]); - else - return(&ws_tile_cache[(tileIndex<<6)+(line<<3)]); - } - return(NULL); + } + else + { + // unknown mode + } + + // tile cache updated + wsc_modified_tile[tileIndex]=0; + } + + if (vFlip) + { + line=7-line; + } + + if (hFlip) + { + return(&wsc_hflipped_tile_cache[(tileIndex<<6)+(line<<3)]); + } + else + { + return(&wsc_tile_cache[(tileIndex<<6)+(line<<3)]); + } + + } + else + { + // need to update tile cache ? + if (ws_modified_tile[tileIndex]) + { +#ifdef STATISTICS + ws_4_shades_tiles_cache_update_time+=-ticker(); +#endif + uint8 *tileInCachePtr = &ws_tile_cache[tileIndex<<6]; + uint8 *hflippedTileInCachePtr = &ws_hflipped_tile_cache[(tileIndex<<6)+7]; + uint32 *tileInRamPtr = (uint32*)&internalRam[0x2000+(tileIndex<<4)]; + uint32 tileLine; + + for (int line=0; line<4; line++) + { + tileLine=*tileInRamPtr++; + + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x80)>>7)|((tileLine&0x8000)>>14); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x40)>>6)|((tileLine&0x4000)>>13); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x20)>>5)|((tileLine&0x2000)>>12); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x10)>>4)|((tileLine&0x1000)>>11); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x08)>>3)|((tileLine&0x0800)>>10); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x04)>>2)|((tileLine&0x0400)>>9); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x02)>>1)|((tileLine&0x0200)>>8); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x01)>>0)|((tileLine&0x0100)>>7); + hflippedTileInCachePtr+=16; + tileLine>>=16; + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x80)>>7)|((tileLine&0x8000)>>14); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x40)>>6)|((tileLine&0x4000)>>13); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x20)>>5)|((tileLine&0x2000)>>12); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x10)>>4)|((tileLine&0x1000)>>11); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x08)>>3)|((tileLine&0x0800)>>10); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x04)>>2)|((tileLine&0x0400)>>9); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x02)>>1)|((tileLine&0x0200)>>8); + *hflippedTileInCachePtr--=*tileInCachePtr++=((tileLine&0x01)>>0)|((tileLine&0x0100)>>7); + hflippedTileInCachePtr+=16; + } + + // tile cache updated + ws_modified_tile[tileIndex]=0; +#ifdef STATISTICS + ws_4_shades_tiles_cache_update_time+=ticker(); + ws_4_shades_tiles_cache_update_number++; +#endif + } + + if (vFlip) + { + line=7-line; + } + + if (hFlip) + { + return(&ws_hflipped_tile_cache[(tileIndex<<6)+(line<<3)]); + } + else + { + return(&ws_tile_cache[(tileIndex<<6)+(line<<3)]); + } + } + + return(NULL); } //////////////////////////////////////////////////////////////////////////////// // @@ -617,64 +665,90 @@ uint8 *ws_tileCache_getTileRow(uint32 tileIndex, uint32 line, // //////////////////////////////////////////////////////////////////////////////// void ws_drawClippedSpriteLine(int16 *framebuffer, uint16 scanline, - uint32 x, uint32 y, uint32 tileIndex, uint32 paletteIndex, - uint32 vFlip, uint32 hFlip, - uint32 clip_x0, uint32 clip_y0, uint32 clip_x1, uint32 clip_y1) + uint32 x, uint32 y, uint32 tileIndex, uint32 paletteIndex, + uint32 vFlip, uint32 hFlip, + uint32 clip_x0, uint32 clip_y0, uint32 clip_x1, uint32 clip_y1) { - - if ((scanline(y+7))) - return; - if (((x+7=clip_x1))) - return; + + if ((scanline(y+7))) + { + return; + } + + if (((x+7=clip_x1))) + { + return; + } + // if (!((y+7=clip_y1))) // return; - if(scanline>clip_y0 && scanlineclip_x1) - nbPixels=(clip_x1-x); - framebuffer+=x; + if(scanline>clip_y0 && scanlineclip_x1) + { + nbPixels=(clip_x1-x); + } + + framebuffer+=x; + + if (ws_gpu_operatingInColor) + { + int16 *wsc_paletteAlias=&wsc_palette[paletteIndex<<4]; + + while (nbPixels) + { + if (*ws_tileRow) + { + *framebuffer=wsc_paletteAlias[*ws_tileRow]; + } + + framebuffer++; + ws_tileRow++; + nbPixels--; + } + } + else + { + int16 *ws_paletteAlias=&ws_palette[paletteIndex<<2]; + + if (paletteIndex&0x04) + { + while (nbPixels) + { + if (*ws_tileRow) + { + *framebuffer=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + framebuffer++; + ws_tileRow++; + nbPixels--; + } + } + else + { + while (nbPixels) + { + *framebuffer=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + framebuffer++; + ws_tileRow++; + nbPixels--; + } + } + } } //////////////////////////////////////////////////////////////////////////////// // @@ -690,852 +764,1377 @@ void ws_drawClippedSpriteLine(int16 *framebuffer, uint16 scanline, void ws_gpu_renderScanline(int16 *framebuffer) { - if (ws_gpu_scanline>143) - return; -#ifdef STATISTICS - long startTime=ticker(); + if (ws_gpu_scanline>143) + { + return; + } + +#ifdef STATISTICS + long startTime=ticker(); #endif - framebuffer+=(224*ws_gpu_scanline); + framebuffer+=(224*ws_gpu_scanline); - // fill with background color - int16 backgroundColor; - if (ws_gpu_operatingInColor) - backgroundColor=wsc_palette[ws_ioRam[0x01]]; - else - backgroundColor=ws_shades[ws_paletteColors[ws_palette[((ws_ioRam[0x01]&0xf0)>>2)+(ws_ioRam[0x01]&0x03)]]]; + // fill with background color + int16 backgroundColor; - for (int i=0;i<224;i++) - framebuffer[i]=backgroundColor; -#ifdef STATISTICS - ws_background_color_rendering_time=ticker(); + if (ws_gpu_operatingInColor) + { + backgroundColor=wsc_palette[ws_ioRam[0x01]]; + } + else + { + backgroundColor=ws_shades[ws_paletteColors[ws_palette[((ws_ioRam[0x01]&0xf0)>>2)+(ws_ioRam[0x01]&0x03)]]]; + } + + for (int i=0; i<224; i++) + { + framebuffer[i]=backgroundColor; + } + +#ifdef STATISTICS + ws_background_color_rendering_time=ticker(); #endif - // render background layer - if (ws_ioRam[0x00]&0x01) - { - int ws_bgScroll_x=ws_ioRam[0x10]; - int ws_bgScroll_y=ws_ioRam[0x11]; - - // seek to the first tile - ws_bgScroll_y=(ws_bgScroll_y+ws_gpu_scanline)&0xff; - // note: byte ordering assumptions! - int ws_currentTile=(ws_bgScroll_x>>3); - uint16 *ws_bgScrollRamBase=(uint16*)(internalRam+(((uint32)ws_ioRam[0x07]&0x0f)<<11)+ - ((ws_bgScroll_y&0xfff8)<<3)); - - int lineInTile = ws_bgScroll_y&0x07; - int columnInTile = ws_bgScroll_x&0x07; - - int16 *scanlinePtr=framebuffer; + // render background layer + if (ws_ioRam[0x00]&0x01) + { + int ws_bgScroll_x=ws_ioRam[0x10]; + int ws_bgScroll_y=ws_ioRam[0x11]; - if (ws_gpu_operatingInColor) - { - // render the first clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_bgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - ws_tileRow+=columnInTile; - for (int i=columnInTile;i<8;i++) - { - if (*ws_tileRow) - *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; - ws_tileRow++; - } - } + // seek to the first tile + ws_bgScroll_y=(ws_bgScroll_y+ws_gpu_scanline)&0xff; - // render the tiles between them - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<4]; + // note: byte ordering assumptions! + int ws_currentTile=(ws_bgScroll_x>>3); + uint16 *ws_bgScrollRamBase=(uint16*)(internalRam+(((uint32)ws_ioRam[0x07]&0x0f)<<11)+ + ((ws_bgScroll_y&0xfff8)<<3)); - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - } + int lineInTile = ws_bgScroll_y&0x07; + int columnInTile = ws_bgScroll_x&0x07; - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_bgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - + int16 *scanlinePtr=framebuffer; - for (int i=0;i>9)&0x0f)<<2]; - ws_tileRow+=columnInTile; + if (ws_gpu_operatingInColor) + { + // render the first clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_bgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + ws_tileRow+=columnInTile; - if ((tileInfo>>9)&0x04) - { - for (int i=columnInTile;i<8;i++) - { - if (*ws_tileRow) - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; - ws_tileRow++; - } - } - else - { - for (int i=columnInTile;i<8;i++) - { - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; - ws_tileRow++; - } - } - } - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<2]; - - if ((tileInfo>>9)&0x04) - { - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - } - else - { - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - } + for (int i=columnInTile; i<8; i++) + { + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } - } + scanlinePtr++; + ws_tileRow++; + } + } - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_bgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; - + // render the tiles between them + int nbTiles=28; - if ((tileInfo>>9)&0x04) - { - for (int i=0;i>9)&0x0f)<<4]; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_bgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + + + for (int i=0; i>9)&0x0f)<<2]; + ws_tileRow+=columnInTile; + + if ((tileInfo>>9)&0x04) + { + for (int i=columnInTile; i<8; i++) + { + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + } + } + else + { + for (int i=columnInTile; i<8; i++) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + } + } + } + + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<2]; + + if ((tileInfo>>9)&0x04) + { + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + } + else + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + } + + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_bgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; + + + if ((tileInfo>>9)&0x04) + { + for (int i=0; iws_ioRam[0x05];i--) - { - uint32 spr=*ws_sprRamBase--; + // seek to first sprite + ws_sprRamBase+=ws_ioRam[0x06]-1; - if (!(spr&0x2000)) - { - // sprite window on ? - if ((ws_ioRam[0x00]&0x08)&&(spr&0x1000)&&(ws_sprWindow_x0!=ws_sprWindow_x1)) - { - ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, - spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, - ws_sprWindow_x0,ws_sprWindow_y0,ws_sprWindow_x1,ws_sprWindow_y1); - } - else - { - ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, - spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, - //0,0,224,144); - 0,0,224,0); - } - } - } - } -#ifdef STATISTICS - ws_priority_0_sprites_rendering_time=ticker(); -#endif - // render foreground layer - if (ws_ioRam[0x00]&0x02) - { - int ws_fgWindow_x0=ws_ioRam[0x08]; - //int ws_fgWindow_y0=ws_ioRam[0x09]; - int ws_fgWindow_x1=ws_ioRam[0x0a]; - //int ws_fgWindow_y1=ws_ioRam[0x0b]; - int ws_fgScroll_x=ws_ioRam[0x12]; - int ws_fgScroll_y=ws_ioRam[0x13]; + for (int i=ws_ioRam[0x06]; i>ws_ioRam[0x05]; i--) + { + uint32 spr=*ws_sprRamBase--; - int windowMode=ws_ioRam[0x00]&0x30; - - // seek to the first tile - ws_fgScroll_y=(ws_fgScroll_y+ws_gpu_scanline)&0xff; + if (!(spr&0x2000)) + { + // sprite window on ? + if ((ws_ioRam[0x00]&0x08)&&(spr&0x1000)&&(ws_sprWindow_x0!=ws_sprWindow_x1)) + { + ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, + spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, + ws_sprWindow_x0,ws_sprWindow_y0,ws_sprWindow_x1,ws_sprWindow_y1); + } + else + { + ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, + spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, + //0,0,224,144); + 0,0,224,0); + } + } + } + } - // note: byte ordering assumptions! - int ws_currentTile=(ws_fgScroll_x>>3); - uint16 *ws_fgScrollRamBase=(uint16*)(internalRam+(((uint32)ws_ioRam[0x07]&0xf0)<<7)+ - ((ws_fgScroll_y&0xfff8)<<3)); - - int lineInTile = ws_fgScroll_y&0x07; - int columnInTile = ws_fgScroll_x&0x07; - - int16 *scanlinePtr=framebuffer; - - - // window disabled - if (!windowMode) - { - if (ws_gpu_operatingInColor) - { - // render the first clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - - ws_tileRow+=columnInTile; - - for (int i=columnInTile;i<8;i++) - { - if (*ws_tileRow) - *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; - ws_tileRow++; - } - } - - // render the tiles between them - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<4]; - - - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; - } - - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - - - for (int i=0;i>9)&0x0f)<<2]; - ws_tileRow+=columnInTile; - if ((tileInfo>>9)&0x04) - { - for (int i=columnInTile;i<8;i++) - { - if (*ws_tileRow) - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; - ws_tileRow++; - } - } - else - { - for (int i=columnInTile;i<8;i++) - { - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; - ws_tileRow++; - } - } - } - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<2]; - - if ((tileInfo>>9)&0x04) - { - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - if (*ws_tileRow) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - } - else - { - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; - } - } - - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; - - - if ((tileInfo>>9)&0x04) - { - for (int i=0;i>9)&0x0f)<<4]; - - ws_tileRow+=columnInTile; - - for (int i=columnInTile;i<8;i++) - { - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) - *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - - // render the tiles between them - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<4]; - - - - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - } - - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - - - for (int i=0;i=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) - *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - } - else - { - // render the first clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - - int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; - ws_tileRow+=columnInTile; - - for (int i=columnInTile;i<8;i++) - { - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<2]; - - - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - } - - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; - - - for (int i=0;i=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - } - } - else - // foreground layer displayed only outside the window - if (windowMode==0x30) - { - int column=0; - if (ws_gpu_operatingInColor) - { - // render the first clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - - ws_tileRow+=columnInTile; - - for (int i=columnInTile;i<8;i++) - { - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) - *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - - // render the tiles between them - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<4]; - - - - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - scanlinePtr++; ws_tileRow++; column++; - } - - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; - - - for (int i=0;iws_fgWindow_x1))) - *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - } - else - { - // render the first clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - - int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; - ws_tileRow+=columnInTile; - - for (int i=columnInTile;i<8;i++) - { - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - int nbTiles=28; - if (columnInTile) - nbTiles=27; - - for (int i=0;i>9)&0x0f)<<2]; - - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - if ((*ws_tileRow)&&((columnws_fgWindow_x1))) *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - scanlinePtr++; ws_tileRow++; column++; - } - - // render the last clipped tile - if (columnInTile) - { - uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; - ws_currentTile++; - uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, - tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); - int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; - - - for (int i=0;iws_fgWindow_x1))) - *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; - column++; - scanlinePtr++; - ws_tileRow++; - } - } - } - } - else - { - // unknown - } - } -#ifdef STATISTICS - ws_foreground_rendering_time=ticker(); +#ifdef STATISTICS + ws_priority_0_sprites_rendering_time=ticker(); #endif - // render sprites - if (ws_ioRam[0x00]&0x04) - { - int ws_sprWindow_x0=ws_ioRam[0x0c]; - int ws_sprWindow_y0=ws_ioRam[0x0d]; - int ws_sprWindow_x1=ws_ioRam[0x0e]; - int ws_sprWindow_y1=ws_ioRam[0x0f]; + + // render foreground layer + if (ws_ioRam[0x00]&0x02) + { + int ws_fgWindow_x0=ws_ioRam[0x08]; + //int ws_fgWindow_y0=ws_ioRam[0x09]; + int ws_fgWindow_x1=ws_ioRam[0x0a]; + //int ws_fgWindow_y1=ws_ioRam[0x0b]; + int ws_fgScroll_x=ws_ioRam[0x12]; + int ws_fgScroll_y=ws_ioRam[0x13]; + + int windowMode=ws_ioRam[0x00]&0x30; + + // seek to the first tile + ws_fgScroll_y=(ws_fgScroll_y+ws_gpu_scanline)&0xff; + + // note: byte ordering assumptions! + int ws_currentTile=(ws_fgScroll_x>>3); + uint16 *ws_fgScrollRamBase=(uint16*)(internalRam+(((uint32)ws_ioRam[0x07]&0xf0)<<7)+ + ((ws_fgScroll_y&0xfff8)<<3)); + + int lineInTile = ws_fgScroll_y&0x07; + int columnInTile = ws_fgScroll_x&0x07; + + int16 *scanlinePtr=framebuffer; + + + // window disabled + if (!windowMode) + { + if (ws_gpu_operatingInColor) + { + // render the first clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + + ws_tileRow+=columnInTile; + + for (int i=columnInTile; i<8; i++) + { + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + } + } + + // render the tiles between them + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<4]; + + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + + + for (int i=0; i>9)&0x0f)<<2]; + ws_tileRow+=columnInTile; + + if ((tileInfo>>9)&0x04) + { + for (int i=columnInTile; i<8; i++) + { + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + } + } + else + { + for (int i=columnInTile; i<8; i++) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + } + } + } + + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<2]; + + if ((tileInfo>>9)&0x04) + { + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + + if (*ws_tileRow) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + } + else + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + scanlinePtr++; + ws_tileRow++; + } + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; + + + if ((tileInfo>>9)&0x04) + { + for (int i=0; i>9)&0x0f)<<4]; + + ws_tileRow+=columnInTile; + + for (int i=columnInTile; i<8; i++) + { + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + + // render the tiles between them + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<4]; + + + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + + + for (int i=0; i=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + } + else + { + // render the first clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + + int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; + ws_tileRow+=columnInTile; + + for (int i=columnInTile; i<8; i++) + { + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<2]; + + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&(column>=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; + + + for (int i=0; i=ws_fgWindow_x0)&&(column<=ws_fgWindow_x1)) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + } + } + else + + // foreground layer displayed only outside the window + if (windowMode==0x30) + { + int column=0; + + if (ws_gpu_operatingInColor) + { + // render the first clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + + ws_tileRow+=columnInTile; + + for (int i=columnInTile; i<8; i++) + { + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + + // render the tiles between them + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<4]; + + + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *wsc_paletteAlias=&wsc_palette[((tileInfo>>9)&0x0f)<<4]; + + + for (int i=0; iws_fgWindow_x1))) + { + *scanlinePtr=wsc_paletteAlias[*ws_tileRow]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + } + else + { + // render the first clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + + int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; + ws_tileRow+=columnInTile; + + for (int i=columnInTile; i<8; i++) + { + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + + int nbTiles=28; + + if (columnInTile) + { + nbTiles=27; + } + + for (int i=0; i>9)&0x0f)<<2]; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + + if ((*ws_tileRow)&&((columnws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + scanlinePtr++; + ws_tileRow++; + column++; + } + + // render the last clipped tile + if (columnInTile) + { + uint16 tileInfo=ws_fgScrollRamBase[ws_currentTile&0x1f]; + ws_currentTile++; + uint8 *ws_tileRow=ws_tileCache_getTileRow( tileInfo&0x1ff, lineInTile, + tileInfo&0x8000, tileInfo&0x4000, tileInfo&0x2000); + int16 *ws_paletteAlias=&ws_palette[((tileInfo>>9)&0x0f)<<2]; + + + for (int i=0; iws_fgWindow_x1))) + { + *scanlinePtr=ws_shades[ws_paletteColors[ws_paletteAlias[*ws_tileRow]]]; + } + + column++; + scanlinePtr++; + ws_tileRow++; + } + } + } + } + else + { + // unknown + } + } + +#ifdef STATISTICS + ws_foreground_rendering_time=ticker(); +#endif + + // render sprites + if (ws_ioRam[0x00]&0x04) + { + int ws_sprWindow_x0=ws_ioRam[0x0c]; + int ws_sprWindow_y0=ws_ioRam[0x0d]; + int ws_sprWindow_x1=ws_ioRam[0x0e]; + int ws_sprWindow_y1=ws_ioRam[0x0f]; // int ws_sprWindow_x1=ws_sprWindow_x0+ws_ioRam[0x0e]; // int ws_sprWindow_y1=ws_sprWindow_y0+ws_ioRam[0x0f]; - uint32 *ws_sprRamBase=(uint32*)(internalRam+(((uint32)ws_ioRam[0x04])<<9)); + uint32 *ws_sprRamBase=(uint32*)(internalRam+(((uint32)ws_ioRam[0x04])<<9)); - // seek to first sprite - ws_sprRamBase+=ws_ioRam[0x06]-1; + // seek to first sprite + ws_sprRamBase+=ws_ioRam[0x06]-1; - for (int i=ws_ioRam[0x06];i>ws_ioRam[0x05];i--) - { - uint32 spr=*ws_sprRamBase--; - - if (spr&0x2000) - { - // sprite window on ? - if ((ws_ioRam[0x00]&0x08)&&(spr&0x1000)&&(ws_sprWindow_x0!=ws_sprWindow_x1)) - { - ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, - spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, - ws_sprWindow_x0,ws_sprWindow_y0,ws_sprWindow_x1,ws_sprWindow_y1); - } - else - { - ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, - spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, - // 0,0,224,144); - 0,0,224,0); - } - } - } - } -#ifdef STATISTICS - ws_priority_1_sprites_rendering_time=ticker(); + for (int i=ws_ioRam[0x06]; i>ws_ioRam[0x05]; i--) + { + uint32 spr=*ws_sprRamBase--; - ws_priority_1_sprites_rendering_time-=ws_foreground_rendering_time; - ws_foreground_rendering_time-=ws_priority_0_sprites_rendering_time; - ws_priority_0_sprites_rendering_time-=ws_background_rendering_time; - ws_background_rendering_time-=ws_background_color_rendering_time; - ws_background_color_rendering_time-=startTime; + if (spr&0x2000) + { + // sprite window on ? + if ((ws_ioRam[0x00]&0x08)&&(spr&0x1000)&&(ws_sprWindow_x0!=ws_sprWindow_x1)) + { + ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, + spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, + ws_sprWindow_x0,ws_sprWindow_y0,ws_sprWindow_x1,ws_sprWindow_y1); + } + else + { + ws_drawClippedSpriteLine(framebuffer,ws_gpu_scanline,(spr&0xff000000)>>24, (spr&0x00ff0000)>>16, + spr&0x1ff,8+((spr&0xe00)>>9),spr&0x4000,spr&0x8000, + // 0,0,224,144); + 0,0,224,0); + } + } + } + } + +#ifdef STATISTICS + ws_priority_1_sprites_rendering_time=ticker(); + + ws_priority_1_sprites_rendering_time-=ws_foreground_rendering_time; + ws_foreground_rendering_time-=ws_priority_0_sprites_rendering_time; + ws_priority_0_sprites_rendering_time-=ws_background_rendering_time; + ws_background_rendering_time-=ws_background_color_rendering_time; + ws_background_color_rendering_time-=startTime; #endif } //////////////////////////////////////////////////////////////////////////////// @@ -1551,46 +2150,57 @@ void ws_gpu_renderScanline(int16 *framebuffer) //////////////////////////////////////////////////////////////////////////////// void ws_gpu_write_byte(DWORD offset, BYTE value) { - // ws 4 color tiles - if ((offset>=0x2000)&&(offset<0x4000)) - { - if (internalRam[offset]!=value) - ws_modified_tile[(offset&0x1fff)>>4]=1; - // update the ram - internalRam[offset]=value; - } - if (ws_gpu_operatingInColor) - { - // wsc 16 color tiles bank 0 - if ((offset>=0x4000)&&(offset<0x8000)) - { - if (internalRam[offset]!=value) - wsc_modified_tile[(offset&0x3fff)>>5]=1; - } - else - // wsc 16 color tiles bank 1 - if ((offset>=0x8000)&&(offset<0xC000)) - { - if (internalRam[offset]!=value) - wsc_modified_tile[512+((offset&0x3fff)>>5)]=1; - } + // ws 4 color tiles + if ((offset>=0x2000)&&(offset<0x4000)) + { + if (internalRam[offset]!=value) + { + ws_modified_tile[(offset&0x1fff)>>4]=1; + } - // update the ram - internalRam[offset]=value; - // palette ram - if (offset>=0xfe00) - { - // RGB444 format - uint16 color=(internalRam[(offset&0xfffe)+1]); - color<<=8; - color|=(internalRam[(offset&0xfffe)]); + // update the ram + internalRam[offset]=value; + } - wsc_palette[(offset&0x1ff)>>1]=RGB555(((color>>8)&0x0f)<<1,((color>>4)&0x0f)<<1,(color&0x0f)<<1); - } - } - else - if (offset<0x4000) - internalRam[offset]=value; + if (ws_gpu_operatingInColor) + { + // wsc 16 color tiles bank 0 + if ((offset>=0x4000)&&(offset<0x8000)) + { + if (internalRam[offset]!=value) + { + wsc_modified_tile[(offset&0x3fff)>>5]=1; + } + } + else + + // wsc 16 color tiles bank 1 + if ((offset>=0x8000)&&(offset<0xC000)) + { + if (internalRam[offset]!=value) + { + wsc_modified_tile[512+((offset&0x3fff)>>5)]=1; + } + } + + // update the ram + internalRam[offset]=value; + + // palette ram + if (offset>=0xfe00) + { + // RGB444 format + uint16 color=(internalRam[(offset&0xfffe)+1]); + color<<=8; + color|=(internalRam[(offset&0xfffe)]); + + wsc_palette[(offset&0x1ff)>>1]=RGB555(((color>>8)&0x0f)<<1,((color>>4)&0x0f)<<1,(color&0x0f)<<1); + } + } + else if (offset<0x4000) + { + internalRam[offset]=value; + } } //////////////////////////////////////////////////////////////////////////////// // @@ -1606,42 +2216,57 @@ void ws_gpu_write_byte(DWORD offset, BYTE value) unsigned int ws_gpu_unknownPort; int ws_gpu_port_write(DWORD port,BYTE value) { - ws_gpu_unknownPort=0; - switch (port) - { - case 0x60: ws_gpu_changeVideoMode(value); - return 0; - case 0x1C: ws_paletteColors[0]=value&0xf; - ws_paletteColors[1]=(value>>4)&0xf; - return 0; - case 0x1D: ws_paletteColors[2]=value&0xf; - ws_paletteColors[3]=(value>>4)&0xf; - return 0; - case 0x1E: ws_paletteColors[4]=value&0xf; - ws_paletteColors[5]=(value>>4)&0xf; - return 0; - case 0x1F: ws_paletteColors[6]=value&0xf; - ws_paletteColors[7]=(value>>4)&0xf; - return 0; - default: ws_gpu_unknownPort=1; - } - if ((port>=0x20)&&(port<=0x3f)) - { - ws_gpu_unknownPort=0; - port-=0x20; - int paletteIndex=port>>1; - if (port&0x01) - { - ws_palette[(paletteIndex<<2)+2]=value&0x7; - ws_palette[(paletteIndex<<2)+3]=(value>>4)&0x7; - } - else - { - ws_palette[(paletteIndex<<2)+0]=value&0x7; - ws_palette[(paletteIndex<<2)+1]=(value>>4)&0x7; - } - } - return ws_gpu_unknownPort; + ws_gpu_unknownPort=0; + + switch (port) + { + case 0x60: + ws_gpu_changeVideoMode(value); + return 0; + + case 0x1C: + ws_paletteColors[0]=value&0xf; + ws_paletteColors[1]=(value>>4)&0xf; + return 0; + + case 0x1D: + ws_paletteColors[2]=value&0xf; + ws_paletteColors[3]=(value>>4)&0xf; + return 0; + + case 0x1E: + ws_paletteColors[4]=value&0xf; + ws_paletteColors[5]=(value>>4)&0xf; + return 0; + + case 0x1F: + ws_paletteColors[6]=value&0xf; + ws_paletteColors[7]=(value>>4)&0xf; + return 0; + + default: + ws_gpu_unknownPort=1; + } + + if ((port>=0x20)&&(port<=0x3f)) + { + ws_gpu_unknownPort=0; + port-=0x20; + int paletteIndex=port>>1; + + if (port&0x01) + { + ws_palette[(paletteIndex<<2)+2]=value&0x7; + ws_palette[(paletteIndex<<2)+3]=(value>>4)&0x7; + } + else + { + ws_palette[(paletteIndex<<2)+0]=value&0x7; + ws_palette[(paletteIndex<<2)+1]=(value>>4)&0x7; + } + } + + return ws_gpu_unknownPort; } //////////////////////////////////////////////////////////////////////////////// // @@ -1656,30 +2281,43 @@ int ws_gpu_port_write(DWORD port,BYTE value) //////////////////////////////////////////////////////////////////////////////// BYTE ws_gpu_port_read(BYTE port) { - switch(port) - { - case 0xa0: - if (ws_gpu_forceColorSystemBool) - return ws_ioRam[0xa0]|2; - else - if (ws_gpu_forceMonoSystemBool) - return ws_ioRam[0xa0]&(~0x02); - else - { - if (ws_gpu_operatingInColor) - return ws_ioRam[0xa0]|2; - else - return ws_ioRam[0xa0]&(~0x02); - } - break; - case 0xaa: - return vblank_count&0xff; - case 0xab: - return (vblank_count>>8)&0xff; - case 0xac: - return (vblank_count>>16)&0xff; - case 0xad: - return (vblank_count>>24)&0xff; - } - return(ws_ioRam[port]); + switch(port) + { + case 0xa0: + if (ws_gpu_forceColorSystemBool) + { + return ws_ioRam[0xa0]|2; + } + else if (ws_gpu_forceMonoSystemBool) + { + return ws_ioRam[0xa0]&(~0x02); + } + else + { + if (ws_gpu_operatingInColor) + { + return ws_ioRam[0xa0]|2; + } + else + { + return ws_ioRam[0xa0]&(~0x02); + } + } + + break; + + case 0xaa: + return vblank_count&0xff; + + case 0xab: + return (vblank_count>>8)&0xff; + + case 0xac: + return (vblank_count>>16)&0xff; + + case 0xad: + return (vblank_count>>24)&0xff; + } + + return(ws_ioRam[port]); } diff --git a/oswan/source/ieeprom.h b/oswan/source/ieeprom.h index 75051f6..095e25a 100644 --- a/oswan/source/ieeprom.h +++ b/oswan/source/ieeprom.h @@ -9,92 +9,183 @@ // ////////////////////////////////////////////////////////////////////////////// -uint8 internalEeprom[]= +uint8_t DefaultBWEEprom[]= { - 0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253, - 0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 135,5,140,9,5,12,139,12,144,0x00,0x00,2, - 0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127, - 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, - 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, - 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, - 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, - 0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00, - 1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 'D'-54,'A'-54,'V'-54,'I'-54,'D'-54,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,32,1,1,33,1,4,0x00,1, - 0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, - 0xff,0xff,0xff,0xff + 0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253, + 0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 135,5,140,9,5,12,139,12,144,0x00,0x00,2, + 0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00, + 1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 'W'-54,'O'-54,'N'-54,'D'-54,'E'-54,'R'-54,'S'-54,'W'-54,'A'-54,'N'-54,0x00,0x00,0x00,0x00,0x00, + 0x00,32,1,1,33,1,4,0x00,1, + 0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff +}; + + +uint8_t DefaultColorEEprom[]= +{ + 0xff,0xff,0xff,0xff,0xff,0xff,192,0xff,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,127,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00,252,0xff,1,0xff,253,0xff,253,0xff,253,0xff,253, + 0xff,253,0xff,253,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00,0x00,3,3,0x00,0x00,0x00,64,128,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 135,5,140,9,5,12,139,12,144,0x00,0x00,2, + 0x00,76,165,0x00,128,0x00,0x00,0x00,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,127,0xff,127, + 0xff,127,0xff,127,0xff,127,0xff,127,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x00,0x00,6,6,6,6,6,0x00,0x00,0x00,0x00,0x00, + 1,128,15,0x00,1,1,1,15,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 'W'-54,'O'-54,'N'-54,'D'-54,'E'-54,'R'-54,'S'-54,'W'-54,'A'-54,'N'-54,0x00,0x00,0x00,0x00,0x00, + 0x00,32,1,1,33,1,4,0x00,1, + 0x00,152,60,127,74,1,53,1,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff }; diff --git a/oswan/source/initialIo.h b/oswan/source/initialIo.h index 5b4f113..9c3a43d 100644 --- a/oswan/source/initialIo.h +++ b/oswan/source/initialIo.h @@ -11,261 +11,261 @@ uint8 initialIoValue[256]= { - 0x00,//0 - 0x00,//1 - 0x9d,//2 - 0xbb,//3 - 0x00,//4 - 0x00,//5 - 0x00,//6 - 0x26,//7 - 0xfe,//8 - 0xde,//9 - 0xf9,//a - 0xfb,//b - 0xdb,//c - 0xd7,//d - 0x7f,//e - 0xf5,//f - 0x00,//10 - 0x00,//11 - 0x00,//12 - 0x00,//13 - 0x01,//14 - 0x00,//15 - 0x9e,//16 - 0x9b,//17 - 0x00,//18 - 0x00,//19 - 0x00,//1a - 0x00,//1b - 0x99,//1c - 0xfd,//1d - 0xb7,//1e - 0xdf,//1f - 0x30,//20 - 0x57,//21 - 0x75,//22 - 0x76,//23 - 0x15,//24 - 0x73,//25 - 0x77,//26 - 0x77,//27 - 0x20,//28 - 0x75,//29 - 0x50,//2a - 0x36,//2b - 0x70,//2c - 0x67,//2d - 0x50,//2e - 0x77,//2f - 0x57,//30 - 0x54,//31 - 0x75,//32 - 0x77,//33 - 0x75,//34 - 0x17,//35 - 0x37,//36 - 0x73,//37 - 0x50,//38 - 0x57,//39 - 0x60,//3a - 0x77,//3b - 0x70,//3c - 0x77,//3d - 0x10,//3e - 0x73,//3f - 0x00,//40 - 0x00,//41 - 0x00,//42 - 0x00,//43 - 0x00,//44 - 0x00,//45 - 0x00,//46 - 0x00,//47 - 0x00,//48 - 0x00,//49 - 0x00,//4a - 0x00,//4b - 0x00,//4c - 0x00,//4d - 0x00,//4e - 0x00,//4f - 0x00,//50 - 0x00,//51 - 0x00,//52 - 0x00,//53 - 0x00,//54 - 0x00,//55 - 0x00,//56 - 0x00,//57 - 0x00,//58 - 0x00,//59 - 0x00,//5a - 0x00,//5b - 0x00,//5c - 0x00,//5d - 0x00,//5e - 0x00,//5f - 0x0a,//60 - 0x00,//61 - 0x00,//62 - 0x00,//63 - 0x00,//64 - 0x00,//65 - 0x00,//66 - 0x00,//67 - 0x00,//68 - 0x00,//69 - 0x00,//6a - 0x0f,//6b - 0x00,//6c - 0x00,//6d - 0x00,//6e - 0x00,//6f - 0x00,//70 - 0x00,//71 - 0x00,//72 - 0x00,//73 - 0x00,//74 - 0x00,//75 - 0x00,//76 - 0x00,//77 - 0x00,//78 - 0x00,//79 - 0x00,//7a - 0x00,//7b - 0x00,//7c - 0x00,//7d - 0x00,//7e - 0x00,//7f - 0x00,//80 - 0x00,//81 - 0x00,//82 - 0x00,//83 - 0x00,//84 - 0x00,//85 - 0x00,//86 - 0x00,//87 - 0x00,//88 - 0x00,//89 - 0x00,//8a - 0x00,//8b - 0x00,//8c - 0x1f,//8d 1d ? - 0x00,//8e - 0x00,//8f - 0x00,//90 - 0x00,//91 - 0x00,//92 - 0x00,//93 - 0x00,//94 - 0x00,//95 - 0x00,//96 - 0x00,//97 - 0x00,//98 - 0x00,//99 - 0x00,//9a - 0x00,//9b - 0x00,//9c - 0x00,//9d - 0x03,//9e - 0x00,//9f - 0x87-2,//a0 - 0x00,//a1 - 0x00,//a2 - 0x00,//a3 - 0x0,//a4 2b - 0x0,//a5 7f - 0x4f,//a6 - 0xff,//a7 cf ? - 0x00,//a8 - 0x00,//a9 - 0x00,//aa - 0x00,//ab - 0x00,//ac - 0x00,//ad - 0x00,//ae - 0x00,//af - 0x00,//b0 - 0xdb,//b1 - 0x00,//b2 - 0x00,//b3 - 0x00,//b4 - 0x40,//b5 - 0x00,//b6 - 0x00,//b7 - 0x00,//b8 - 0x00,//b9 - 0x01,//ba - 0x00,//bb - 0x42,//bc - 0x00,//bd - 0x83,//be - 0x00,//bf - 0x2f,//c0 - 0x3f,//c1 - 0xff,//c2 - 0xff,//c3 - 0x00,//c4 - 0x00,//c5 - 0x00,//c6 - 0x00,//c7 + 0x00,//0 + 0x00,//1 + 0x9d,//2 + 0xbb,//3 + 0x00,//4 + 0x00,//5 + 0x00,//6 + 0x26,//7 + 0xfe,//8 + 0xde,//9 + 0xf9,//a + 0xfb,//b + 0xdb,//c + 0xd7,//d + 0x7f,//e + 0xf5,//f + 0x00,//10 + 0x00,//11 + 0x00,//12 + 0x00,//13 + 0x01,//14 + 0x00,//15 + 0x9e,//16 + 0x9b,//17 + 0x00,//18 + 0x00,//19 + 0x00,//1a + 0x00,//1b + 0x99,//1c + 0xfd,//1d + 0xb7,//1e + 0xdf,//1f + 0x30,//20 + 0x57,//21 + 0x75,//22 + 0x76,//23 + 0x15,//24 + 0x73,//25 + 0x77,//26 + 0x77,//27 + 0x20,//28 + 0x75,//29 + 0x50,//2a + 0x36,//2b + 0x70,//2c + 0x67,//2d + 0x50,//2e + 0x77,//2f + 0x57,//30 + 0x54,//31 + 0x75,//32 + 0x77,//33 + 0x75,//34 + 0x17,//35 + 0x37,//36 + 0x73,//37 + 0x50,//38 + 0x57,//39 + 0x60,//3a + 0x77,//3b + 0x70,//3c + 0x77,//3d + 0x10,//3e + 0x73,//3f + 0x00,//40 + 0x00,//41 + 0x00,//42 + 0x00,//43 + 0x00,//44 + 0x00,//45 + 0x00,//46 + 0x00,//47 + 0x00,//48 + 0x00,//49 + 0x00,//4a + 0x00,//4b + 0x00,//4c + 0x00,//4d + 0x00,//4e + 0x00,//4f + 0x00,//50 + 0x00,//51 + 0x00,//52 + 0x00,//53 + 0x00,//54 + 0x00,//55 + 0x00,//56 + 0x00,//57 + 0x00,//58 + 0x00,//59 + 0x00,//5a + 0x00,//5b + 0x00,//5c + 0x00,//5d + 0x00,//5e + 0x00,//5f + 0x0a,//60 + 0x00,//61 + 0x00,//62 + 0x00,//63 + 0x00,//64 + 0x00,//65 + 0x00,//66 + 0x00,//67 + 0x00,//68 + 0x00,//69 + 0x00,//6a + 0x0f,//6b + 0x00,//6c + 0x00,//6d + 0x00,//6e + 0x00,//6f + 0x00,//70 + 0x00,//71 + 0x00,//72 + 0x00,//73 + 0x00,//74 + 0x00,//75 + 0x00,//76 + 0x00,//77 + 0x00,//78 + 0x00,//79 + 0x00,//7a + 0x00,//7b + 0x00,//7c + 0x00,//7d + 0x00,//7e + 0x00,//7f + 0x00,//80 + 0x00,//81 + 0x00,//82 + 0x00,//83 + 0x00,//84 + 0x00,//85 + 0x00,//86 + 0x00,//87 + 0x00,//88 + 0x00,//89 + 0x00,//8a + 0x00,//8b + 0x00,//8c + 0x1f,//8d 1d ? + 0x00,//8e + 0x00,//8f + 0x00,//90 + 0x00,//91 + 0x00,//92 + 0x00,//93 + 0x00,//94 + 0x00,//95 + 0x00,//96 + 0x00,//97 + 0x00,//98 + 0x00,//99 + 0x00,//9a + 0x00,//9b + 0x00,//9c + 0x00,//9d + 0x03,//9e + 0x00,//9f + 0x80,//a0 + 0x00,//a1 + 0x00,//a2 + 0x00,//a3 + 0x0,//a4 2b + 0x0,//a5 7f + 0x4f,//a6 + 0xff,//a7 cf ? + 0x00,//a8 + 0x00,//a9 + 0x00,//aa + 0x00,//ab + 0x00,//ac + 0x00,//ad + 0x00,//ae + 0x00,//af + 0x00,//b0 + 0xdb,//b1 + 0x00,//b2 + 0x00,//b3 + 0x00,//b4 + 0x40,//b5 + 0x00,//b6 + 0x00,//b7 + 0x00,//b8 + 0x00,//b9 + 0x01,//ba + 0x00,//bb + 0x42,//bc + 0x00,//bd + 0x83,//be + 0x00,//bf + 0x2f,//c0 + 0x3f,//c1 + 0xff,//c2 + 0xff,//c3 + 0x00,//c4 + 0x00,//c5 + 0x00,//c6 + 0x00,//c7 - 0xd1,//c8? - 0xd1,//c9 - 0xd1,//ca - 0xd1,//cb - 0xd1,//cc - 0xd1,//cd - 0xd1,//ce - 0xd1,//cf - 0xd1,//d0 - 0xd1,//d1 - 0xd1,//d2 - 0xd1,//d3 - 0xd1,//d4 - 0xd1,//d5 - 0xd1,//d6 - 0xd1,//d7 - 0xd1,//d8 - 0xd1,//d9 - 0xd1,//da - 0xd1,//db - 0xd1,//dc - 0xd1,//dd - 0xd1,//de - 0xd1,//df - 0xd1,//e0 - 0xd1,//e1 - 0xd1,//e2 - 0xd1,//e3 - 0xd1,//e4 - 0xd1,//e5 - 0xd1,//e6 - 0xd1,//e7 - 0xd1,//e8 - 0xd1,//e9 - 0xd1,//ea - 0xd1,//eb - 0xd1,//ec - 0xd1,//ed - 0xd1,//ee - 0xd1,//ef - 0xd1,//f0 - 0xd1,//f1 - 0xd1,//f2 - 0xd1,//f3 - 0xd1,//f4 - 0xd1,//f5 - 0xd1,//f6 - 0xd1,//f7 - 0xd1,//f8 - 0xd1,//f9 - 0xd1,//fa - 0xd1,//fb - 0xd1,//fc - 0xd1,//fd - 0xd1,//fe - 0xd1 //ff + 0xd1,//c8? + 0xd1,//c9 + 0xd1,//ca + 0xd1,//cb + 0xd1,//cc + 0xd1,//cd + 0xd1,//ce + 0xd1,//cf + 0xd1,//d0 + 0xd1,//d1 + 0xd1,//d2 + 0xd1,//d3 + 0xd1,//d4 + 0xd1,//d5 + 0xd1,//d6 + 0xd1,//d7 + 0xd1,//d8 + 0xd1,//d9 + 0xd1,//da + 0xd1,//db + 0xd1,//dc + 0xd1,//dd + 0xd1,//de + 0xd1,//df + 0xd1,//e0 + 0xd1,//e1 + 0xd1,//e2 + 0xd1,//e3 + 0xd1,//e4 + 0xd1,//e5 + 0xd1,//e6 + 0xd1,//e7 + 0xd1,//e8 + 0xd1,//e9 + 0xd1,//ea + 0xd1,//eb + 0xd1,//ec + 0xd1,//ed + 0xd1,//ee + 0xd1,//ef + 0xd1,//f0 + 0xd1,//f1 + 0xd1,//f2 + 0xd1,//f3 + 0xd1,//f4 + 0xd1,//f5 + 0xd1,//f6 + 0xd1,//f7 + 0xd1,//f8 + 0xd1,//f9 + 0xd1,//fa + 0xd1,//fb + 0xd1,//fc + 0xd1,//fd + 0xd1,//fe + 0xd1 //ff }; diff --git a/oswan/source/io.cpp b/oswan/source/io.cpp index 1f17e10..6699f18 100644 --- a/oswan/source/io.cpp +++ b/oswan/source/io.cpp @@ -17,31 +17,37 @@ #include /* UNIX standard function definitions */ #include /* Error number definitions */ #include /* POSIX terminal control definitions */ +#include #include "log.h" #include "rom.h" #include "./nec/nec.h" #include "initialIo.h" -#include "ieeprom.h" #include "gpu.h" #include "audio.h" +#include "memory.h" -extern uint8 *externalEeprom; -extern uint32 externalEepromAddressMask; -extern uint32 romAddressMask; +extern uint8 *externalEeprom; +extern uint32 externalEepromAddressMask; +extern uint32 romAddressMask; +extern char *internalEeprom; -uint8 *ws_ioRam=NULL; +uint8_t iee_WriteEnable = false; +uint8_t iee_SelAddress = 0; -uint8 ws_key_start; -uint8 ws_key_left; -uint8 ws_key_right; -uint8 ws_key_up; -uint8 ws_key_down; -uint8 ws_key_button_1; -uint8 ws_key_button_2; -uint8 ws_key_flipped; -int rtcDataRegisterReadCount=0; +uint8 *ws_ioRam=NULL; + +uint8 ws_key_start; +uint8 ws_key_left; +uint8 ws_key_right; +uint8 ws_key_up; +uint8 ws_key_down; +uint8 ws_key_button_1; +uint8 ws_key_button_2; +uint8 ws_key_flipped; + +int rtcDataRegisterReadCount=0; //////////////////////////////////////////////////////////////////////////////// // @@ -56,20 +62,26 @@ int rtcDataRegisterReadCount=0; //////////////////////////////////////////////////////////////////////////////// void ws_io_reset(void) { - ws_key_start=0; - ws_key_left=0; - ws_key_right=0; - ws_key_up=0; - ws_key_down=0; - ws_key_button_1=0; - ws_key_button_2=0; - int i; - for (i=0;i<0x100;i++) - ws_ioRam[i]= initialIoValue[i]; - for (i=0;i<0xc9;i++) - cpu_writeport(i,initialIoValue[i]); + ws_key_start=0; + ws_key_left=0; + ws_key_right=0; + ws_key_up=0; + ws_key_down=0; + ws_key_button_1=0; + ws_key_button_2=0; + int i; - rtcDataRegisterReadCount=0; + for (i=0; i<0x100; i++) + { + ws_ioRam[i]= initialIoValue[i]; + } + + /*for (i=0; i<0xc9; i++) + { + cpu_writeport(i,initialIoValue[i]); + }*/ + + rtcDataRegisterReadCount=0; } //////////////////////////////////////////////////////////////////////////////// // @@ -84,11 +96,13 @@ void ws_io_reset(void) //////////////////////////////////////////////////////////////////////////////// void ws_io_init(void) { - if (ws_ioRam==NULL) - ws_ioRam=(uint8*)malloc(0x100); + if (ws_ioRam==NULL) + { + ws_ioRam=(uint8*)malloc(0x100); + } - ws_io_reset(); - ws_key_flipped=0; + ws_io_reset(); + ws_key_flipped=0; } //////////////////////////////////////////////////////////////////////////////// // @@ -103,7 +117,7 @@ void ws_io_init(void) //////////////////////////////////////////////////////////////////////////////// void ws_io_flipControls(void) { - ws_key_flipped=!ws_key_flipped; + ws_key_flipped=!ws_key_flipped; } //////////////////////////////////////////////////////////////////////////////// // @@ -118,8 +132,10 @@ void ws_io_flipControls(void) //////////////////////////////////////////////////////////////////////////////// void ws_io_done(void) { - if (ws_ioRam==NULL) - free(ws_ioRam); + if (ws_ioRam==NULL) + { + free(ws_ioRam); + } } /* Serial port */ @@ -135,7 +151,7 @@ void open_serial() if (serialfd < 0) { serialfd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY); - + //set_baudrate(serial_speed); serial_have_data = 0; } @@ -144,37 +160,41 @@ void open_serial() void set_baudrate(int speed) { struct termios options; + if (serialfd < 0) + { return; - + } + tcgetattr(serialfd, &options); - + options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; - + if (speed == BDR_9600) { cfsetispeed(&options, B9600); } else { - cfsetospeed(&options, B38400); + cfsetospeed(&options, B38400); } + #if 0 options.c_cflag &= ~CNEW_RTSCTS; #else options.c_cflag &= ~CRTSCTS; #endif options.c_cflag |= (CLOCAL | CREAD); - + options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); - + options.c_oflag &= ~OPOST; - + tcsetattr(serialfd, TCSANOW, &options); - + /* Make sure read is not blocking */ fcntl(serialfd, F_SETFL, FNDELAY); } @@ -191,28 +211,34 @@ void check_serial_data() { unsigned char buf[10]; int f; + if (serialfd < 0) + { return; - + } + if (serial_have_data == 0) { f = read(serialfd, buf, 1); + if (f > 0) { - printf("Ho [%d]!\n", f);fflush(stdout); + printf("Ho [%d]!\n", f); + fflush(stdout); serial_have_data = 0x01; serial_data = buf[0]; } } + if(serial_have_data > 0) { /* Gen an int if enabled */ - if(ws_ioRam[0xB2] & 0x04) - { - ws_ioRam[0xb6] &= ~ 0x04; + if(ws_ioRam[0xB2] & 0x04) + { + ws_ioRam[0xb6] &= ~ 0x04; printf("INNNNNTTTT!!!!!!!"); - nec_int((ws_ioRam[0xb0]+3)*4); - } + nec_int((ws_ioRam[0xb0]+3)*4); + } } } @@ -220,25 +246,35 @@ unsigned char read_serial() { unsigned char buf[10]; int f; + if (serialfd < 0) + { return 0xFF; + } + if (serial_have_data > 0) { serial_have_data = 0; return serial_data; } + f = read(serialfd, buf, 1); - + if (f == 1) + { return buf[0]; - + } + return 0x42; } void write_serial(unsigned char value) { if (serialfd < 0) + { return; + } + write(serialfd, &value, 1); } @@ -256,215 +292,268 @@ void write_serial(unsigned char value) //////////////////////////////////////////////////////////////////////////////// BYTE cpu_readport(BYTE port) { - int w1,w2; - BYTE retVal = 0; + int w1,w2; + BYTE retVal = 0; - if ((port >= 0xBA) && (port <= 0xBE)) - { - printf("Reading IEEP %02X\n", port); - } - + /*if ((port >= 0xBA) && (port <= 0xBE)) + { + printf("Reading IEEP %02X\n", port); + }*/ - switch (port) - { - case 0x4e: - case 0x4f: - case 0x50: - case 0x51: - case 0x80: - case 0x81: - case 0x82: - case 0x83: - case 0x84: - case 0x85: - case 0x86: - case 0x87: - case 0x88: - case 0x89: - case 0x8a: - case 0x8b: - case 0x8c: - case 0x8d: - case 0x8e: - case 0x8f: - case 0x90: - case 0x91: - case 0x92: - case 0x93: - case 0x94: - return(ws_audio_port_read(port)); - //case 0xaa: return 0xff; - /*case 0xb3: // ??? - if (ws_ioRam[0xb3]<0x80) - return 0; - - if (ws_ioRam[0xb3]<0xc0) - return 0x84; - - return 0xc4;*/ - case 0xb5: - w1=ws_ioRam[0xb5]; - if(w1&0x40) - { - w2=0x00; - if (ws_key_flipped) - w2=(ws_key_start<<1); - else - w2=(ws_key_start<<1)|(ws_key_button_1<<2)|(ws_key_button_2<<3); - return (uint8)((w1&0xf0)|w2); - } - if(w1&0x20) - { - w2=0x00; - if (ws_key_flipped) - w2=(ws_key_button_1)|(ws_key_button_2<<2); - else - w2=(ws_key_up<<0)|(ws_key_right<<1)|(ws_key_down<<2)|(ws_key_left<<3); - return (uint8)((w1&0xf0)|w2); - } - if(w1&0x10) - { - w2=0x00; - if (ws_key_flipped) - w2=(ws_key_up<<1)|(ws_key_right<<2)|(ws_key_down<<3)|(ws_key_left); - return (uint8)((w1&0xf0)|w2); - } - break; - case 0xbe: // internal eeprom status/command register - // ack eeprom write - if(ws_ioRam[0xbe]&0x20) - return ws_ioRam[0xbe]|2; - // ack eeprom read - if(ws_ioRam[0xbe]&0x10) - return ws_ioRam[0xbe]|1; - - // else ack both - return ws_ioRam[0xbe]|3; - case 0xba: // eeprom even byte read - w1=((((uint16)ws_ioRam[0xbd])<<8)|((uint16)ws_ioRam[0xbc])); - w1=(w1<<1)&0x3ff; - return internalEeprom[w1]; - case 0xbb: // eeprom odd byte read - w1=((((uint16)ws_ioRam[0xbd])<<8)|((uint16)ws_ioRam[0xbc])); - w1=((w1<<1)+1)&0x3ff; - return internalEeprom[w1]; - case 0xc0 : // ??? - retVal = ((ws_ioRam[0xc0]&0xf)|0x20); - goto exit; + switch (port) + { + case 0x4e: + case 0x4f: + case 0x50: + case 0x51: + case 0x80: + case 0x81: + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8a: + case 0x8b: + case 0x8c: + case 0x8d: + case 0x8e: + case 0x8f: + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + return(ws_audio_port_read(port)); - case 0xc4: // external eeprom even byte read - w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&(externalEepromAddressMask); - retVal = externalEeprom[w1]; - goto exit; + //case 0xaa: return 0xff; + /*case 0xb3: // ??? + if (ws_ioRam[0xb3]<0x80) + return 0; - case 0xc5: // external eeprom odd byte read - w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&(externalEepromAddressMask); - retVal = externalEeprom[w1+1]; - goto exit; + if (ws_ioRam[0xb3]<0xc0) + return 0x84; - case 0xc8: // external eeprom status/command register - // ack eeprom write - if(ws_ioRam[0xc8]&0x20) - { - retVal = ws_ioRam[0xc8]|2; - goto exit; - } + return 0xc4;*/ + case 0xb5: + w1=ws_ioRam[0xb5]; - // ack eeprom read - if(ws_ioRam[0xc8]&0x10) - { - retVal = ws_ioRam[0xc8]|1; - goto exit; - } - - // else ack both - retVal = ws_ioRam[0xc8]|3; - goto exit; + if(w1&0x40) + { + w2=0x00; - case 0xca : // RTC Command and status register - // set ack to always 1 - retVal = (ws_ioRam[0xca]|0x80); - goto exit; - case 0xcb : // RTC data register + if (ws_key_flipped) + { + w2=(ws_key_start<<1); + } + else + { + w2=(ws_key_start<<1)|(ws_key_button_1<<2)|(ws_key_button_2<<3); + } - if(ws_ioRam[0xca]==0x15) // get time command - { - struct tm *newtime; - time_t long_time; - time( &long_time ); - newtime = localtime( &long_time ); + return (uint8)((w1&0xf0)|w2); + } - #define BCD(value) ((value/10)<<4)|(value%10) - switch(rtcDataRegisterReadCount) - { - case 0: rtcDataRegisterReadCount++; - retVal = BCD(newtime->tm_year-100); - goto exit; - case 1: rtcDataRegisterReadCount++; - retVal = BCD(newtime->tm_mon); - goto exit; - case 2: rtcDataRegisterReadCount++; - retVal = BCD(newtime->tm_mday); - goto exit; - case 3: rtcDataRegisterReadCount++; - retVal = BCD(newtime->tm_wday); - goto exit; - case 4: rtcDataRegisterReadCount++; - retVal = BCD(newtime->tm_hour); - goto exit; - case 5: rtcDataRegisterReadCount++; - retVal = BCD(newtime->tm_min); - goto exit; - case 6: rtcDataRegisterReadCount=0; - retVal = BCD(newtime->tm_sec); - goto exit; - } - return 0; - } - else - { - // set ack - retVal = (ws_ioRam[0xcb]|0x80); - goto exit; - } + if(w1&0x20) + { + w2=0x00; - case 0xD0: - retVal = 0; - goto exit; + if (ws_key_flipped) + { + w2=(ws_key_button_1)|(ws_key_button_2<<2); + } + else + { + w2=(ws_key_up<<0)|(ws_key_right<<1)|(ws_key_down<<2)|(ws_key_left<<3); + } + + return (uint8)((w1&0xf0)|w2); + } + + if(w1&0x10) + { + w2=0x00; + + if (ws_key_flipped) + { + w2=(ws_key_up<<1)|(ws_key_right<<2)|(ws_key_down<<3)|(ws_key_left); + } + + return (uint8)((w1&0xf0)|w2); + } + + break; + + case 0xbe: // internal eeprom status/command register + + // ack eeprom write + if(ws_ioRam[0xbe]&0x20) + { + return ws_ioRam[0xbe]|2; + } + + // ack eeprom read + if(ws_ioRam[0xbe]&0x10) + { + return ws_ioRam[0xbe]|1; + } + + // else ack both + return ws_ioRam[0xbe]|3; + + case 0xba: // eeprom even byte read + return internalEeprom[iee_SelAddress]; + + case 0xbb: // eeprom odd byte read + return internalEeprom[iee_SelAddress + 1]; + + case 0xc0 : // ??? + retVal = ((ws_ioRam[0xc0]&0xf)|0x20); + goto exit; + + case 0xc4: // external eeprom even byte read + w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&(externalEepromAddressMask); + retVal = externalEeprom[w1]; + goto exit; + + case 0xc5: // external eeprom odd byte read + w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&(externalEepromAddressMask); + retVal = externalEeprom[w1+1]; + goto exit; + + case 0xc8: // external eeprom status/command register + + // ack eeprom write + if(ws_ioRam[0xc8]&0x20) + { + retVal = ws_ioRam[0xc8]|2; + goto exit; + } + + // ack eeprom read + if(ws_ioRam[0xc8]&0x10) + { + retVal = ws_ioRam[0xc8]|1; + goto exit; + } + + // else ack both + retVal = ws_ioRam[0xc8]|3; + goto exit; + + case 0xca : // RTC Command and status register + // set ack to always 1 + retVal = (ws_ioRam[0xca]|0x80); + goto exit; + + case 0xcb : // RTC data register + + if(ws_ioRam[0xca]==0x15) // get time command + { + struct tm *newtime; + time_t long_time; + time( &long_time ); + newtime = localtime( &long_time ); + +#define BCD(value) ((value/10)<<4)|(value%10) + + switch(rtcDataRegisterReadCount) + { + case 0: + rtcDataRegisterReadCount++; + retVal = BCD(newtime->tm_year-100); + goto exit; + + case 1: + rtcDataRegisterReadCount++; + retVal = BCD(newtime->tm_mon); + goto exit; + + case 2: + rtcDataRegisterReadCount++; + retVal = BCD(newtime->tm_mday); + goto exit; + + case 3: + rtcDataRegisterReadCount++; + retVal = BCD(newtime->tm_wday); + goto exit; + + case 4: + rtcDataRegisterReadCount++; + retVal = BCD(newtime->tm_hour); + goto exit; + + case 5: + rtcDataRegisterReadCount++; + retVal = BCD(newtime->tm_min); + goto exit; + + case 6: + rtcDataRegisterReadCount=0; + retVal = BCD(newtime->tm_sec); + goto exit; + } + + return 0; + } + else + { + // set ack + retVal = (ws_ioRam[0xcb]|0x80); + goto exit; + } + + case 0xD0: + retVal = 0; + goto exit; /* Serial port link.. */ case 0xB1: retVal = read_serial(); printf("RS232: Read %02X\n", retVal); goto exit; - + case 0xB3: check_serial_data(); + if (ws_ioRam[0xB3] & 0x80) + { retVal = (ws_ioRam[0xB3] & ~1) | serial_have_data | 0x04; + } else + { retVal = 0x00; + } + printf("<<< 0xD0) - printf("ReadIO %02X <= %02X\n", port, retVal); + { + printf("ReadIO %02X <= %02X\n", port, retVal); + } + break; - - } - retVal = ws_gpu_port_read(port); + + } + + retVal = ws_gpu_port_read(port); exit: - return retVal; + return retVal; } //////////////////////////////////////////////////////////////////////////////// // @@ -479,37 +568,39 @@ exit: //////////////////////////////////////////////////////////////////////////////// void cpu_writeport(DWORD port,BYTE value) { - //unsigned short F0dbg = 0; - int w1; //,w2; - int unknown_io_port=0; + //unsigned short F0dbg = 0; + int w1; //,w2; + int unknown_io_port=0; - if ((port >= 0xBA) && (port <= 0xBE)) + /*if ((port >= 0xBA) && (port <= 0xBE)) { printf("Writing IEEP %02X <= %02X\n", port, value); + }*/ + + if ((ws_ioRam[port]==value) && (port < 0xF0) && ((port < 0xB0) || (port > 0xBF)) ) + { + return; } - if ((ws_ioRam[port]==value) && (port < 0xF0) && ((port < 0xB0) || (port > 0xBF)) ) - return; - - ws_ioRam[port]=value; - - switch (port) - { - /* GPU IOs */ - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - case 0x08: - case 0x09: - case 0x0A: - case 0x0B: - case 0x0C: - case 0x0D: + ws_ioRam[port]=value; + + switch (port) + { + /* GPU IOs */ + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: case 0x0E: case 0x0F: case 0x10: @@ -517,108 +608,143 @@ void cpu_writeport(DWORD port,BYTE value) case 0x12: case 0x13: case 0x14: - break; - case 0x15: printf("Icons %c %c %c %c %c %c %c %c\n", - (value>>7)&1?'?':' ', - (value>>6)&1?'?':' ', - (value>>5)&1?'3':' ', - (value>>4)&1?'2':' ', - (value>>3)&1?'1':' ', - (value>>2)&1?'H':' ', - (value>>1)&1?'V':' ', - (value>>0)&1?'S':' ' - ); break; + break; + + case 0x15: + printf("Icons %c %c %c %c %c %c %c %c\n", + (value>>7)&1?'?':' ', + (value>>6)&1?'?':' ', + (value>>5)&1?'3':' ', + (value>>4)&1?'2':' ', + (value>>3)&1?'1':' ', + (value>>2)&1?'H':' ', + (value>>1)&1?'V':' ', + (value>>0)&1?'S':' ' + ); + break; /* Palettes ? */ - case 0x1C: case 0x25: case 0x2F: case 0x38: - case 0x1D: case 0x26: case 0x30: case 0x39: - case 0x1E: case 0x27: case 0x31: case 0x3A: - case 0x1F: case 0x28: case 0x32: case 0x3B: - case 0x20: case 0x29: case 0x33: case 0x3C: - case 0x21: case 0x2A: case 0x34: case 0x3E: - case 0x22: case 0x2B: case 0x35: case 0x3F: - case 0x23: case 0x2C: case 0x36: - case 0x24: case 0x2E: case 0x37: - break; - - /* DMAs */ + case 0x1C: + case 0x25: + case 0x2F: + case 0x38: + case 0x1D: + case 0x26: + case 0x30: + case 0x39: + case 0x1E: + case 0x27: + case 0x31: + case 0x3A: + case 0x1F: + case 0x28: + case 0x32: + case 0x3B: + case 0x20: + case 0x29: + case 0x33: + case 0x3C: + case 0x21: + case 0x2A: + case 0x34: + case 0x3E: + case 0x22: + case 0x2B: + case 0x35: + case 0x3F: + case 0x23: + case 0x2C: + case 0x36: + case 0x24: + case 0x2E: + case 0x37: + break; + + /* DMAs */ case 0x40: case 0x41: case 0x42: case 0x43: - case 0x44: + case 0x44: case 0x45: case 0x46: case 0x47: - break; + break; - case 0x48: // DMA + case 0x48: // DMA - // bit 7 set to start dma transfer - if(value&0x80) - { - int dma_start = (((DWORD)ws_ioRam[0x41])<<8)|(((DWORD)ws_ioRam[0x40]))|(((DWORD)ws_ioRam[0x42])<<16); - int dma_end = (((DWORD)ws_ioRam[0x45])<<8)|(((DWORD)ws_ioRam[0x44]))|(((DWORD)ws_ioRam[0x43])<<16); - int dma_size = (((DWORD)ws_ioRam[0x47])<<8)|(((DWORD)ws_ioRam[0x46])); - for(int ix=0;ix>8); - ws_ioRam[0x40]=(BYTE)(dma_start&0xff); - ws_ioRam[0x45]=(BYTE)(dma_end>>8); - ws_ioRam[0x44]=(BYTE)(dma_end&0xff); - ws_ioRam[0x48]=0; - } - break; + // bit 7 set to start dma transfer + if(value&0x80) + { + int dma_start = (((DWORD)ws_ioRam[0x41])<<8)|(((DWORD)ws_ioRam[0x40]))|(((DWORD)ws_ioRam[0x42])<<16); + int dma_end = (((DWORD)ws_ioRam[0x45])<<8)|(((DWORD)ws_ioRam[0x44]))|(((DWORD)ws_ioRam[0x43])<<16); + int dma_size = (((DWORD)ws_ioRam[0x47])<<8)|(((DWORD)ws_ioRam[0x46])); + + for(int ix=0; ix>8); + ws_ioRam[0x40]=(BYTE)(dma_start&0xff); + ws_ioRam[0x45]=(BYTE)(dma_end>>8); + ws_ioRam[0x44]=(BYTE)(dma_end&0xff); + ws_ioRam[0x48]=0; + } + + break; /* Audio */ case 0x4a: case 0x4b: case 0x4c: case 0x4d: - case 0x4e: - case 0x4f: - ws_audio_port_write(port, value); - break; - - /* DMA Start! */ - case 0x52: break; - - /* GPU (again) */ - case 0x60: - break; - - /* Audio */ - case 0x80: - case 0x81: - case 0x82: - case 0x83: - case 0x84: - case 0x85: - case 0x86: - case 0x87: - case 0x88: - case 0x89: - case 0x8a: - case 0x8b: - case 0x8c: - case 0x8d: - case 0x8e: - case 0x8f: - case 0x90: - case 0x91: - case 0x92: - case 0x93: - case 0x94: - ws_audio_port_write(port,value); - break; - - /* Hardeware */ - case 0xA0: + case 0x4e: + case 0x4f: + ws_audio_port_write(port, value); break; - + + /* DMA Start! */ + case 0x52: + break; + + /* GPU (again) */ + case 0x60: + break; + + /* Audio */ + case 0x80: + case 0x81: + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8a: + case 0x8b: + case 0x8c: + case 0x8d: + case 0x8e: + case 0x8f: + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + ws_audio_port_write(port,value); + break; + + /* Hardware */ + case 0xA0: + /* Force cart handshake to be set */ + ws_ioRam[port] |= 0x80; + break; + /*Timers */ case 0xA2: case 0xA4: @@ -630,92 +756,218 @@ void cpu_writeport(DWORD port,BYTE value) case 0xAA: case 0xAB: break; - + /* Hardware */ - case 0xB0: break; - case 0xB1: write_serial(value); /*printf("RS232 TX: %02X\n", value);*/ break; - case 0xB2: break; - case 0xB3: printf(">>>>RS232STA: %02X [%c%c%cxx%c%c%c]\n", value, - (value & 0x80)?'E':'d', - (value & 0x40)?'3':'9', - (value & 0x20)?'R':'n', - (value & 0x04)?'E':'f', - (value & 0x02)?'V':'n', - (value & 0x01)?'D':'e' - ); - -/* Serial status: 7 = Enable, 6 = baudrate, 5 = Overrun reset - 2 = Send Buffer empty - 1 = Overrun - 0 = Data Received - */ + case 0xB0: + break; + + case 0xB1: + write_serial(value); /*printf("RS232 TX: %02X\n", value);*/ break; + + case 0xB2: + break; + + case 0xB3: + printf(">>>>RS232STA: %02X [%c%c%cxx%c%c%c]\n", value, + (value & 0x80)?'E':'d', + (value & 0x40)?'3':'9', + (value & 0x20)?'R':'n', + (value & 0x04)?'E':'f', + (value & 0x02)?'V':'n', + (value & 0x01)?'D':'e' + ); + + /* Serial status: 7 = Enable, 6 = baudrate, 5 = Overrun reset + 2 = Send Buffer empty + 1 = Overrun + 0 = Data Received + */ serial_speed = ((value&040) == 0x00)?BDR_9600:BDR_38400; + if ((value & 0x80) == 0x80) { open_serial(); set_baudrate(serial_speed); check_serial_data(); } - break; - + + break; + case 0xB5: break; + /* buttons */ case 0xB6: break; /* Internal EEPROM */ - case 0xba: w1=(((((WORD)ws_ioRam[0xbd])<<8)|((WORD)ws_ioRam[0xbc]))); - w1=(w1<<1)&0x3ff; - internalEeprom[w1]=value; - return; - case 0xbb: w1=(((((WORD)ws_ioRam[0xbd])<<8)|((WORD)ws_ioRam[0xbc]))); - w1=((w1<<1)+1)&0x3ff; - internalEeprom[w1]=value; - return; - case 0xBC: case 0xBD: case 0xBE: break; - - + case 0xba: /* DATA Low */ + if (iee_WriteEnable) + { + printf("@ %X <- %X\n", iee_SelAddress, value); + internalEeprom[iee_SelAddress]=value; + } + msync(internalEeprom, 1024, MS_SYNC); + break; + + case 0xbb: /* Data High */ + if (iee_WriteEnable) + { + printf("@ %X <- %X\n", iee_SelAddress + 1, value); + internalEeprom[iee_SelAddress + 1]=value; + } + msync(internalEeprom, 1024, MS_SYNC); + break; + + case 0xBC: /* Address Low */ + case 0xBD: /* Address High */ + break; + case 0xBE: /* Command / Status */ + { + enum + { + EEPROM_SUBCOMMAND = 0, + EEPROM_WRITE, + EEPROM_READ, + EEPROM_ERASE, + EEPROM_WRITEDISABLE, + EEPROM_WRITEALL, + EEPROM_ERASEALL, + EEPROM_WRITEENABLE + }; + uint8_t address, command, subcmd; + + address = (ws_ioRam[0xBD] << 8) | ws_ioRam[0xBC]; + + if (ws_gpu_operatingInColor) + { + command = (address >> 11) & 0x3; + address = address & 0x3FF; + subcmd = (address >> 8) & 0x03; + } + else + { + command = (address >> 6) & 0x3; + address = address & 0x3F; + subcmd = (address >> 4) & 0x03; + } + + if (command == EEPROM_SUBCOMMAND) + { + command = EEPROM_WRITEDISABLE + subcmd; + } + + printf("IEEP: [%X:%X:%X] -> %X : %d : %d\n", ws_ioRam[0xBC], ws_ioRam[0xBD], ws_ioRam[0xBE], address, command, subcmd); + + if (value & 0x40) + { + /* Sub command */ + printf("IEEP: Sub\n"); + if (command == EEPROM_WRITEENABLE) + { + printf("IEEP: Write Enable\n"); + iee_WriteEnable = true; + } + else if (command == EEPROM_WRITEDISABLE) + { + printf("IEEP: Write Disable\n"); + iee_WriteEnable = false; + } + else if (command == EEPROM_ERASEALL) + { + printf("IEEP: Erase All\n"); + if (ws_gpu_operatingInColor) + { + memset(internalEeprom, 0, COLOR_IEEPROM_SIZE); + } + else + { + memset(internalEeprom, 0, BW_IEEPROM_SIZE); + } + } + } + else if (value & 0x20) + { + /* Write */ + printf("IEEP: Write"); + iee_SelAddress = address; + } + else if (value & 0x10) + { + /* Read */ + printf("IEEP: Read"); + iee_SelAddress = address; + } + } + break; + + /* MBC */ - case 0xC0: case 0xC1: case 0xC2: case 0xC3: break; - case 0xc4: w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&externalEepromAddressMask; - externalEeprom[w1]=value; - return; - - case 0xc5: w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&externalEepromAddressMask; - externalEeprom[w1+1]=value; - return; + case 0xC0: + case 0xC1: + case 0xC2: + case 0xC3: + break; - case 0xC6: case 0xC7: case 0xC8: break; + case 0xc4: + w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&externalEepromAddressMask; + externalEeprom[w1]=value; + return; - case 0xca: if(value==0x15) - rtcDataRegisterReadCount=0; - break; - break; + case 0xc5: + w1=(((((WORD)ws_ioRam[0xc7])<<8)|((WORD)ws_ioRam[0xc6]))<<1)&externalEepromAddressMask; + externalEeprom[w1+1]=value; + return; - case 0xCB: break; + case 0xC6: + case 0xC7: + case 0xC8: + break; - case 0xF0: break; - case 0xF1: printf("%d\n", (signed short)((value << 8) | ws_ioRam[0xF0])); break; - case 0xF2: printf("%c", value); fflush(stdout); break; - - case 0xB7: break; /* Somwthing to write there, but what? */ + case 0xca: + if(value==0x15) + { + rtcDataRegisterReadCount=0; + } - default: - unknown_io_port=1; - } - if ((ws_gpu_port_write(port,value) == 1) && (unknown_io_port == 1)) - { - fprintf(log_get(),"WriteIO(%02X, %02X);\n",port, value); - } - /*if (port >= 0xC0) - { - fprintf(log_get(),"WriteMBCIO(%02X, %02X);\n",port, value); - }*/ + break; + break; -// if ((ws_gpu_unknownPort)&&(unknown_io_port)) -// { -// fprintf(log_get(),"io: writing 0x%.2x to unknown port 0x%.2x\n",value,port); -// } + case 0xCB: + break; + + case 0xF0: + break; + + case 0xF1: + printf("%d\n", (signed short)((value << 8) | ws_ioRam[0xF0])); + break; + + case 0xF2: + printf("%c", value); + fflush(stdout); + break; + + case 0xB7: + break; /* Somwthing to write there, but what? */ + + default: + unknown_io_port=1; + } + + if ((ws_gpu_port_write(port,value) == 1) && (unknown_io_port == 1)) + { + fprintf(log_get(),"WriteIO(%02X, %02X);\n",port, value); + } + + /*if (port >= 0xC0) + { + fprintf(log_get(),"WriteMBCIO(%02X, %02X);\n",port, value); + }*/ + +// if ((ws_gpu_unknownPort)&&(unknown_io_port)) +// { +// fprintf(log_get(),"io: writing 0x%.2x to unknown port 0x%.2x\n",value,port); +// } } diff --git a/oswan/source/log.cpp b/oswan/source/log.cpp index 0e344ed..f9a0fae 100644 --- a/oswan/source/log.cpp +++ b/oswan/source/log.cpp @@ -27,11 +27,15 @@ FILE *log_stream=NULL; ////////////////////////////////////////////////////////////////////////////// int log_init(char *path) { - //log_stream=fopen(path,"wrt"); - log_stream = stdout; - if (log_stream==NULL) - return(0); - return(1); + //log_stream=fopen(path,"wrt"); + log_stream = stdout; + + if (log_stream==NULL) + { + return(0); + } + + return(1); } ////////////////////////////////////////////////////////////////////////////// // @@ -45,7 +49,7 @@ int log_init(char *path) ////////////////////////////////////////////////////////////////////////////// FILE *log_get(void) { - return(log_stream); + return(log_stream); } ////////////////////////////////////////////////////////////////////////////// // @@ -59,5 +63,5 @@ FILE *log_get(void) ////////////////////////////////////////////////////////////////////////////// void log_done(void) { - fclose(log_stream); + fclose(log_stream); } diff --git a/oswan/source/memory.cpp b/oswan/source/memory.cpp index 8755cb0..37f75f6 100644 --- a/oswan/source/memory.cpp +++ b/oswan/source/memory.cpp @@ -15,12 +15,19 @@ #include #include #include +#include +#include +#include +#include +#include #include "log.h" #include "rom.h" #include "./nec/nec.h" #include "io.h" #include "gpu.h" #include "audio.h" +#include "memory.h" +#include "ieeprom.h" //////////////////////////////////////////////////////////////////////////////// // @@ -33,21 +40,31 @@ // // //////////////////////////////////////////////////////////////////////////////// -#define IO_ROM_BANK_BASE_SELECTOR 0xC0 +#define IO_ROM_BANK_BASE_SELECTOR 0xC0 -uint8 *ws_rom; -uint8 *ws_staticRam; -uint8 *internalRam; -uint8 *externalEeprom; +uint8 *ws_rom; +uint8 *ws_staticRam; +uint8 *internalRam; +uint8 *externalEeprom; +char *internalBWIRom; +char *internalColorIRom; + +char *internalBWEeprom; +char *internalColorEeprom; + +char *internalEeprom; extern uint8 *ws_ioRam; -uint16 ws_rom_checksum; +uint16 ws_rom_checksum; -uint32 sramAddressMask; -uint32 externalEepromAddressMask; -uint32 romAddressMask; +uint8 ws_haveColorIRom; +uint8 ws_haveBWIRom; + +uint32 sramAddressMask; +uint32 externalEepromAddressMask; +uint32 romAddressMask; uint32 romSize; int ws_sram_dirty = 0; @@ -66,24 +83,26 @@ void dump_memory() fp = fopen("sram.bin", "wb"); fwrite(ws_staticRam, 1, 0x10000, fp); fclose(fp); - + fp = fopen("rom.bin", "wb"); fwrite(ws_rom, 1, romSize, fp); fclose(fp); - + fp = fopen("memorydump.bin", "wb"); fwrite(internalRam, 1, 0x10000, fp); /* page 1 */ fwrite(&(ws_staticRam[0 & sramAddressMask]), 1, 0x10000, fp); fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+2]&((romSize>>16)-1))<<16)]), 1, 0x10000, fp); fwrite(&(ws_rom[((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+3]&((romSize>>16)-1))<<16)]), 1, 0x10000, fp); + for(i = 4; i < 0x10; i++) { int romBank=(256-(((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR]&0xf)<<4)|(i&0xf))); fwrite(&(ws_rom[(unsigned)(romSize-(romBank<<16))]), 1, 0x10000, fp); - } + } + fclose(fp); - + fp = fopen("registers.bin", "wb"); fwrite(ws_ioRam, 1, 256, fp); fclose(fp); @@ -109,24 +128,25 @@ void dump_memory() //////////////////////////////////////////////////////////////////////////////// void cpu_writemem20(DWORD addr,BYTE value) { - uint32 offset=addr&0xffff; - uint32 bank=addr>>16; + uint32 offset=addr&0xffff; + uint32 bank=addr>>16; - // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM - if (!bank) - { - ws_gpu_write_byte(offset,value); - ws_audio_write_byte(offset,value); - } - else - // 1 - SRAM (cart) - if (bank==1) - { - ws_staticRam[offset&sramAddressMask]=value; - ws_sram_dirty = 1; - } + // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM + if (!bank) + { + ws_gpu_write_byte(offset,value); + ws_audio_write_byte(offset,value); + } + else - // other banks are read-only + // 1 - SRAM (cart) + if (bank==1) + { + ws_staticRam[offset&sramAddressMask]=value; + ws_sram_dirty = 1; + } + + // other banks are read-only } //////////////////////////////////////////////////////////////////////////////// // @@ -141,28 +161,137 @@ void cpu_writemem20(DWORD addr,BYTE value) //////////////////////////////////////////////////////////////////////////////// BYTE cpu_readmem20(DWORD addr) { - uint32 offset=addr&0xffff; - uint32 bank=addr>>16; - - switch (bank) - { - case 0: // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM - if (ws_gpu_operatingInColor) - return(internalRam[offset]); - else - if (offset<0x4000) - return(internalRam[offset]); - return(0x90); + uint32 offset=addr&0xffff; + uint32 bank=addr>>16; + uint16 romBank; + uint8_t hwReg; + BYTE ret; - case 1: // 1 - SRAM (cart) - return ws_staticRam[offset&sramAddressMask]; - case 2: - case 3: return ws_rom[offset+((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+bank]&((romSize>>16)-1))<<16)]; - default: - int romBank=(256-(((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR]&0xf)<<4)|(bank&0xf))); - return ws_rom[(unsigned)(offset+romSize-(romBank<<16))]; - } - return(0xff); + switch (bank) + { + case 0: // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM + if (ws_gpu_operatingInColor) + { + return(internalRam[offset]); + } + else if (offset<0x4000) + { + return(internalRam[offset]); + } + + return(0x90); + + case 1: // 1 - SRAM (cart) + return ws_staticRam[offset&sramAddressMask]; + + case 2: + case 3: + return ws_rom[offset+((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR+bank]&((romSize>>16)-1))<<16)]; + + case 0xF: + hwReg = ws_ioRam[0xA0]; + + if (!(hwReg & 1)) + { + if (ws_gpu_operatingInColor && ws_haveColorIRom) + { + if (addr >= 0xFE000) + { + ret = internalColorIRom[addr & ~0xFE000]; + return ret; + } + } + else if (!ws_gpu_operatingInColor && ws_haveBWIRom) + { + if (addr >= 0xFF000) + { + ret = internalBWIRom[addr & ~0xFF000]; + return ret; + } + } + } + // fall through + + default: + romBank = (256-(((ws_ioRam[IO_ROM_BANK_BASE_SELECTOR]&0xf)<<4)|(bank&0xf))); + return ws_rom[(unsigned)(offset+romSize-(romBank<<16))]; + } + + return(0xff); +} +//////////////////////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +// +// +// +// +// +//////////////////////////////////////////////////////////////////////////////// +char *load_file(char *filename) +{ + int fd; + char *ret_ptr; + struct stat FileStat; + + fd = open(filename, O_RDWR); + + fstat(fd, &FileStat); + + printf("Trying to load %s, size = %lu...\n",filename, FileStat.st_size); + + ret_ptr = (char *)mmap(NULL, FileStat.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + + close(fd); + + if (ret_ptr == MAP_FAILED) + { + ret_ptr = NULL; + } + + return ret_ptr; +} +//////////////////////////////////////////////////////////////////////////////// +// +//////////////////////////////////////////////////////////////////////////////// +// +// +// +// +// +// +// +//////////////////////////////////////////////////////////////////////////////// +char *create_file(char *filename, uint32_t size, uint8_t *data) +{ + int fd; + char *ret_ptr; + + printf("Trying to create %s, size = %u...\n",filename, size); + fd = open(filename, O_CREAT | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_TRUNC); + fchmod(fd, 0644); + close(fd); + sync(); + + fd = open(filename, O_RDWR); + + write(fd, data, size); + close(fd); + sync(); + + fd = open(filename, O_RDWR); + ret_ptr = (char *)mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + + close(fd); + + if (ret_ptr == MAP_FAILED) + { + ret_ptr = NULL; + } + + return ret_ptr; } //////////////////////////////////////////////////////////////////////////////// // @@ -177,18 +306,54 @@ BYTE cpu_readmem20(DWORD addr) //////////////////////////////////////////////////////////////////////////////// void ws_memory_init(uint8 *rom, uint32 wsRomSize) { - ws_romHeaderStruct *ws_romHeader; - - ws_rom=rom; - romSize=wsRomSize; - ws_romHeader=ws_rom_getHeader(ws_rom,romSize); - ws_rom_checksum=ws_romHeader->checksum; - internalRam=(uint8*)malloc(0x10000); - ws_staticRam=(uint8*)malloc(0x10000); - externalEeprom=(uint8*)malloc(131072);//ws_rom_eepromSize(ws_rom,romSize)); - sramAddressMask=ws_rom_sramSize(ws_rom,romSize)-1; - externalEepromAddressMask=ws_rom_eepromSize(ws_rom,romSize)-1; - romAddressMask=romSize-1; + ws_romHeaderStruct *ws_romHeader; + + ws_rom=rom; + romSize=wsRomSize; + ws_romHeader=ws_rom_getHeader(ws_rom,romSize); + ws_rom_checksum=ws_romHeader->checksum; + internalRam=(uint8*)malloc(0x10000); + ws_staticRam=(uint8*)malloc(0x10000); + externalEeprom=(uint8*)malloc(131072);//ws_rom_eepromSize(ws_rom,romSize)); + sramAddressMask=ws_rom_sramSize(ws_rom,romSize)-1; + externalEepromAddressMask=ws_rom_eepromSize(ws_rom,romSize)-1; + + internalBWIRom = load_file("ws_irom.bin"); + internalColorIRom = load_file("wsc_irom.bin"); + + internalBWEeprom = load_file("ws_ieeprom.bin"); + if ( internalBWEeprom == NULL ) + { + internalBWEeprom = create_file("ws_ieeprom.bin", BW_IEEPROM_SIZE, DefaultBWEEprom); + } + + internalColorEeprom = load_file("wsc_ieeprom.bin"); + if ( internalColorEeprom == NULL ) + { + internalColorEeprom = create_file("wsc_ieeprom.bin", COLOR_IEEPROM_SIZE, DefaultColorEEprom); + } + + internalEeprom = internalBWEeprom; + if (ws_gpu_operatingInColor) + { + internalEeprom = internalColorEeprom; + } + + ws_haveBWIRom = false; + ws_haveColorIRom = false; + + if (internalBWIRom != NULL) + { + printf("Color IROM Found!\n"); + ws_haveBWIRom = true; + } + if (internalColorIRom != NULL) + { + printf("B&W IROM Found!\n"); + ws_haveColorIRom = true; + } + + romAddressMask=romSize-1; } //////////////////////////////////////////////////////////////////////////////// // @@ -203,8 +368,8 @@ void ws_memory_init(uint8 *rom, uint32 wsRomSize) //////////////////////////////////////////////////////////////////////////////// void ws_memory_reset(void) { - memset(internalRam,0,0x10000); - //memset(ws_staticRam,0,0x10000); // should the sram really be cleared? ... + memset(internalRam,0,0x10000); + //memset(ws_staticRam,0,0x10000); // should the sram really be cleared? ... } //////////////////////////////////////////////////////////////////////////////// // @@ -219,10 +384,10 @@ void ws_memory_reset(void) //////////////////////////////////////////////////////////////////////////////// void ws_memory_done(void) { - free(ws_rom); - free(ws_staticRam); - free(internalRam); - free(externalEeprom); + free(ws_rom); + free(ws_staticRam); + free(internalRam); + free(externalEeprom); } //////////////////////////////////////////////////////////////////////////////// // @@ -235,9 +400,9 @@ void ws_memory_done(void) // // //////////////////////////////////////////////////////////////////////////////// -uint8 *memory_getRom(void) +uint8 *memory_getRom(void) { - return(ws_rom); + return(ws_rom); } //////////////////////////////////////////////////////////////////////////////// // @@ -250,9 +415,9 @@ uint8 *memory_getRom(void) // // //////////////////////////////////////////////////////////////////////////////// -uint32 memory_getRomSize(void) +uint32 memory_getRomSize(void) { - return(romSize); + return(romSize); } //////////////////////////////////////////////////////////////////////////////// // @@ -265,44 +430,46 @@ uint32 memory_getRomSize(void) // // //////////////////////////////////////////////////////////////////////////////// -uint16 memory_getRomCrc(void) +uint16 memory_getRomCrc(void) { - return(ws_rom_checksum); + return(ws_rom_checksum); } void ws_sram_load(char *path) { - FILE *f; - //size_t read; + FILE *f; + //size_t read; - f = fopen(path, "r"); - if (NULL == f) - { - memset(ws_staticRam, 0, 0x10000); - return; - } + f = fopen(path, "r"); - /*read = */fread(ws_staticRam, 1, 0x8000, f); - //fprintf(log_get(), "read 0x%x (of 0x%x?) bytes of save ram from %s\n", read, ws_rom_sramSize(ws_rom, romSize), path); - fclose(f); + if (NULL == f) + { + memset(ws_staticRam, 0, 0x10000); + return; + } + + /*read = */fread(ws_staticRam, 1, 0x8000, f); + //fprintf(log_get(), "read 0x%x (of 0x%x?) bytes of save ram from %s\n", read, ws_rom_sramSize(ws_rom, romSize), path); + fclose(f); } void ws_sram_save(char *path) { - FILE *f; - //size_t wrote; + FILE *f; + //size_t wrote; - f = fopen(path, "wb"); - if (NULL == f) - { - fprintf(log_get(), "error opening %s for writing save ram. (%s)\n", path, strerror(errno)); - return; - } + f = fopen(path, "wb"); - /*wrote = */fwrite(ws_staticRam, 1, 0x8000, f); - fflush(f); - //fprintf(log_get(), "wrote 0x%x bytes of save ram to %s\n", wrote, path); - fclose(f); + if (NULL == f) + { + fprintf(log_get(), "error opening %s for writing save ram. (%s)\n", path, strerror(errno)); + return; + } + + /*wrote = */fwrite(ws_staticRam, 1, 0x8000, f); + fflush(f); + //fprintf(log_get(), "wrote 0x%x bytes of save ram to %s\n", wrote, path); + fclose(f); } diff --git a/oswan/source/memory.h b/oswan/source/memory.h index 0e9c6ac..f1b5e34 100644 --- a/oswan/source/memory.h +++ b/oswan/source/memory.h @@ -30,5 +30,8 @@ void ws_sram_save(char *path); void dump_memory(); +#define BW_IEEPROM_SIZE (1024) +#define COLOR_IEEPROM_SIZE (1024) + #endif diff --git a/oswan/source/nec/nec.cpp b/oswan/source/nec/nec.cpp index a56787e..23d8c7f 100644 --- a/oswan/source/nec/nec.cpp +++ b/oswan/source/nec/nec.cpp @@ -2,9 +2,9 @@ NEC V30MZ(V20/V30/V33) emulator - Small changes made by toshi (Cycle count macros changed , "THROUGH" macro added) + Small changes made by toshi (Cycle count macros changed , "THROUGH" macro added) - Small changes made by dox@space.pl (Corrected bug in NEG instruction , different AUX flag handling in some opcodes) + Small changes made by dox@space.pl (Corrected bug in NEG instruction , different AUX flag handling in some opcodes) (Re)Written June-September 2000 by Bryan McPhail (mish@tendril.co.uk) based on code by Oliver Bergmann (Raul_Bloodworth@hotmail.com) who based code @@ -73,37 +73,41 @@ static UINT8 parity_table[256]; void nec_reset (void *param) { - unsigned int i,j,c; - BREGS reg_name[8]={ AL, CL, DL, BL, AH, CH, DH, BH }; + unsigned int i,j,c; + BREGS reg_name[8]= { AL, CL, DL, BL, AH, CH, DH, BH }; - memset( &I, 0, sizeof(I) ); + memset( &I, 0, sizeof(I) ); - no_interrupt=0; - I.sregs[CS] = 0xffff; + no_interrupt=0; + I.sregs[CS] = 0xffff; - for (i = 0;i < 256; i++) - { - for (j = i, c = 0; j > 0; j >>= 1) - if (j & 1) c++; - parity_table[i] = !(c & 1); - } + for (i = 0; i < 256; i++) + { + for (j = i, c = 0; j > 0; j >>= 1) + if (j & 1) + { + c++; + } - I.ZeroVal = I.ParityVal = 1; - SetMD(1); /* set the mode-flag = native mode */ + parity_table[i] = !(c & 1); + } - for (i = 0; i < 256; i++) - { - Mod_RM.reg.b[i] = reg_name[(i & 0x38) >> 3]; - Mod_RM.reg.w[i] = (WREGS) ( (i & 0x38) >> 3) ; - } + I.ZeroVal = I.ParityVal = 1; + SetMD(1); /* set the mode-flag = native mode */ - for (i = 0xc0; i < 0x100; i++) - { - Mod_RM.RM.w[i] = (WREGS)( i & 7 ); - Mod_RM.RM.b[i] = (BREGS)reg_name[i & 7]; - } + for (i = 0; i < 256; i++) + { + Mod_RM.reg.b[i] = reg_name[(i & 0x38) >> 3]; + Mod_RM.reg.w[i] = (WREGS) ( (i & 0x38) >> 3) ; + } + + for (i = 0xc0; i < 0x100; i++) + { + Mod_RM.RM.w[i] = (WREGS)( i & 7 ); + Mod_RM.RM.b[i] = (BREGS)reg_name[i & 7]; + } } void nec_exit (void) @@ -116,40 +120,42 @@ void nec_exit (void) void nec_int(DWORD wektor) { - - DWORD dest_seg, dest_off; - if(I.IF) - { - i_pushf(); - I.TF = I.IF = 0; - dest_off = ReadWord(wektor); - dest_seg = ReadWord(wektor+2); - PUSH(I.sregs[CS]); - PUSH(I.ip); - I.ip = (WORD)dest_off; - I.sregs[CS] = (WORD)dest_seg; - } + DWORD dest_seg, dest_off; + + if(I.IF) + { + i_pushf(); + I.TF = I.IF = 0; + dest_off = ReadWord(wektor); + dest_seg = ReadWord(wektor+2); + PUSH(I.sregs[CS]); + PUSH(I.ip); + I.ip = (WORD)dest_off; + I.sregs[CS] = (WORD)dest_seg; + } } static void nec_interrupt(uint32_t int_num, /*BOOLEAN*/ int md_flag) { - UINT32 dest_seg, dest_off; + UINT32 dest_seg, dest_off; - if (int_num == UINT32_MAX) - return; + if (int_num == UINT32_MAX) + { + return; + } - i_pushf(); - I.TF = I.IF = 0; - + i_pushf(); + I.TF = I.IF = 0; - dest_off = ReadWord((int_num)*4); - dest_seg = ReadWord((int_num)*4+2); - PUSH(I.sregs[CS]); - PUSH(I.ip); - I.ip = (WORD)dest_off; - I.sregs[CS] = (WORD)dest_seg; + dest_off = ReadWord((int_num)*4); + dest_seg = ReadWord((int_num)*4+2); + + PUSH(I.sregs[CS]); + PUSH(I.ip); + I.ip = (WORD)dest_off; + I.sregs[CS] = (WORD)dest_seg; } @@ -161,567 +167,2799 @@ static void nec_interrupt(uint32_t int_num, /*BOOLEAN*/ int md_flag) #define OP(num,func_name) static void func_name(void) -OP( 0x00, i_add_br8 ) { DEF_br8; ADDB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x01, i_add_wr16 ) { DEF_wr16; ADDW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x02, i_add_r8b ) { DEF_r8b; ADDB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x03, i_add_r16w ) { DEF_r16w; ADDW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x04, i_add_ald8 ) { DEF_ald8; ADDB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x05, i_add_axd16) { DEF_axd16; ADDW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x06, i_push_es ) { PUSH(I.sregs[ES]); CLK(2); } -OP( 0x07, i_pop_es ) { POP(I.sregs[ES]); CLK(3); } - -OP( 0x08, i_or_br8 ) { DEF_br8; ORB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x09, i_or_wr16 ) { DEF_wr16; ORW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x0a, i_or_r8b ) { DEF_r8b; ORB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x0b, i_or_r16w ) { DEF_r16w; ORW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x0c, i_or_ald8 ) { DEF_ald8; ORB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x0d, i_or_axd16 ) { DEF_axd16; ORW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x0e, i_push_cs ) { PUSH(I.sregs[CS]); CLK(2); } -OP( 0x0f, i_pre_nec ) { UINT32 ModRM, tmp, tmp2; /* pop cs at V30MZ? */ - switch (FETCH) { - case 0x10 : BITOP_BYTE; CLKS(3,3,4); tmp2 = I.regs.b[CL] & 0x7; I.ZeroVal = (tmp & (1<>8)&0xf); tmp &= 0xff; PutbackRMByte(ModRM,tmp); CLKM(9,15); break; - case 0x2a : ModRM = FETCH; tmp = GetRMByte(ModRM); tmp2 = (I.regs.b[AL] & 0xf)<<4; I.regs.b[AL] = (I.regs.b[AL] & 0xf0) | (tmp&0xf); tmp = tmp2 | (tmp>>4); PutbackRMByte(ModRM,tmp); CLKM(13,19); break; - case 0x31 : ModRM = FETCH; ModRM=0; break; - case 0x33 : ModRM = FETCH; ModRM=0; break; - case 0x92 : CLK(2); break; /* V25/35 FINT */ - case 0xe0 : ModRM = FETCH; ModRM=0; break; - case 0xf0 : ModRM = FETCH; ModRM=0; break; - case 0xff : ModRM = FETCH; ModRM=0; break; - default: break; - } +OP( 0x00, i_add_br8 ) +{ + DEF_br8; + ADDB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); +} +OP( 0x01, i_add_wr16 ) +{ + DEF_wr16; + ADDW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); +} +OP( 0x02, i_add_r8b ) +{ + DEF_r8b; + ADDB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x03, i_add_r16w ) +{ + DEF_r16w; + ADDW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x04, i_add_ald8 ) +{ + DEF_ald8; + ADDB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x05, i_add_axd16) +{ + DEF_axd16; + ADDW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x06, i_push_es ) +{ + PUSH(I.sregs[ES]); + CLK(2); +} +OP( 0x07, i_pop_es ) +{ + POP(I.sregs[ES]); + CLK(3); } -OP( 0x10, i_adc_br8 ) { DEF_br8; src+=CF; ADDB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x11, i_adc_wr16 ) { DEF_wr16; src+=CF; ADDW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x12, i_adc_r8b ) { DEF_r8b; src+=CF; ADDB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x13, i_adc_r16w ) { DEF_r16w; src+=CF; ADDW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x14, i_adc_ald8 ) { DEF_ald8; src+=CF; ADDB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x15, i_adc_axd16) { DEF_axd16; src+=CF; ADDW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x16, i_push_ss ) { PUSH(I.sregs[SS]); CLK(2); } -OP( 0x17, i_pop_ss ) { POP(I.sregs[SS]); CLK(3); no_interrupt=1; } - -OP( 0x18, i_sbb_br8 ) { DEF_br8; src+=CF; SUBB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x19, i_sbb_wr16 ) { DEF_wr16; src+=CF; SUBW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x1a, i_sbb_r8b ) { DEF_r8b; src+=CF; SUBB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x1b, i_sbb_r16w ) { DEF_r16w; src+=CF; SUBW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x1c, i_sbb_ald8 ) { DEF_ald8; src+=CF; SUBB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x1d, i_sbb_axd16) { DEF_axd16; src+=CF; SUBW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x1e, i_push_ds ) { PUSH(I.sregs[DS]); CLK(2); } -OP( 0x1f, i_pop_ds ) { POP(I.sregs[DS]); CLK(3); } - -OP( 0x20, i_and_br8 ) { DEF_br8; ANDB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x21, i_and_wr16 ) { DEF_wr16; ANDW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x22, i_and_r8b ) { DEF_r8b; ANDB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x23, i_and_r16w ) { DEF_r16w; ANDW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x24, i_and_ald8 ) { DEF_ald8; ANDB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x25, i_and_axd16) { DEF_axd16; ANDW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x26, i_es ) { seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; } -OP( 0x27, i_daa ) { ADJ4(6,0x60); CLK(10); } - -OP( 0x28, i_sub_br8 ) { DEF_br8; SUBB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x29, i_sub_wr16 ) { DEF_wr16; SUBW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x2a, i_sub_r8b ) { DEF_r8b; SUBB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x2b, i_sub_r16w ) { DEF_r16w; SUBW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x2c, i_sub_ald8 ) { DEF_ald8; SUBB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x2d, i_sub_axd16) { DEF_axd16; SUBW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x2e, i_cs ) { seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; } -OP( 0x2f, i_das ) { ADJ4(-6,-0x60); CLK(10); } - -OP( 0x30, i_xor_br8 ) { DEF_br8; XORB; PutbackRMByte(ModRM,dst); CLKM(3,1); } -OP( 0x31, i_xor_wr16 ) { DEF_wr16; XORW; PutbackRMWord(ModRM,dst); CLKM(3,1); } -OP( 0x32, i_xor_r8b ) { DEF_r8b; XORB; RegByte(ModRM)=dst; CLKM(2,1); } -OP( 0x33, i_xor_r16w ) { DEF_r16w; XORW; RegWord(ModRM)=dst; CLKM(2,1); } -OP( 0x34, i_xor_ald8 ) { DEF_ald8; XORB; I.regs.b[AL]=dst; CLK(1); } -OP( 0x35, i_xor_axd16) { DEF_axd16; XORW; I.regs.w[AW]=dst; CLK(1); } -OP( 0x36, i_ss ) { seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; } -OP( 0x37, i_aaa ) { ADJB(6,1); CLK(9); } - -OP( 0x38, i_cmp_br8 ) { DEF_br8; SUBB; CLKM(2,1); } -OP( 0x39, i_cmp_wr16 ) { DEF_wr16; SUBW; CLKM(2,1); } -OP( 0x3a, i_cmp_r8b ) { DEF_r8b; SUBB; CLKM(2,1); } -OP( 0x3b, i_cmp_r16w ) { DEF_r16w; SUBW; CLKM(2,1); } -OP( 0x3c, i_cmp_ald8 ) { DEF_ald8; SUBB; CLK(1); } -OP( 0x3d, i_cmp_axd16) { DEF_axd16; SUBW; CLK(1); } -OP( 0x3e, i_ds ) { seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; CLK(1); nec_instruction[FETCHOP](); seg_prefix=FALSE; } -OP( 0x3f, i_aas ) { ADJB(-6,-1); CLK(9); } - -OP( 0x40, i_inc_ax ) { IncWordReg(AW); CLK(1); } -OP( 0x41, i_inc_cx ) { IncWordReg(CW); CLK(1); } -OP( 0x42, i_inc_dx ) { IncWordReg(DW); CLK(1); } -OP( 0x43, i_inc_bx ) { IncWordReg(BW); CLK(1); } -OP( 0x44, i_inc_sp ) { IncWordReg(SP); CLK(1); } -OP( 0x45, i_inc_bp ) { IncWordReg(BP); CLK(1); } -OP( 0x46, i_inc_si ) { IncWordReg(IX); CLK(1); } -OP( 0x47, i_inc_di ) { IncWordReg(IY); CLK(1); } - -OP( 0x48, i_dec_ax ) { DecWordReg(AW); CLK(1); } -OP( 0x49, i_dec_cx ) { DecWordReg(CW); CLK(1); } -OP( 0x4a, i_dec_dx ) { DecWordReg(DW); CLK(1); } -OP( 0x4b, i_dec_bx ) { DecWordReg(BW); CLK(1); } -OP( 0x4c, i_dec_sp ) { DecWordReg(SP); CLK(1); } -OP( 0x4d, i_dec_bp ) { DecWordReg(BP); CLK(1); } -OP( 0x4e, i_dec_si ) { DecWordReg(IX); CLK(1); } -OP( 0x4f, i_dec_di ) { DecWordReg(IY); CLK(1); } - -OP( 0x50, i_push_ax ) { PUSH(I.regs.w[AW]); CLK(1); } -OP( 0x51, i_push_cx ) { PUSH(I.regs.w[CW]); CLK(1); } -OP( 0x52, i_push_dx ) { PUSH(I.regs.w[DW]); CLK(1); } -OP( 0x53, i_push_bx ) { PUSH(I.regs.w[BW]); CLK(1); } -OP( 0x54, i_push_sp ) { PUSH(I.regs.w[SP]); CLK(1); } -OP( 0x55, i_push_bp ) { PUSH(I.regs.w[BP]); CLK(1); } -OP( 0x56, i_push_si ) { PUSH(I.regs.w[IX]); CLK(1); } -OP( 0x57, i_push_di ) { PUSH(I.regs.w[IY]); CLK(1); } - -OP( 0x58, i_pop_ax ) { POP(I.regs.w[AW]); CLK(1); } -OP( 0x59, i_pop_cx ) { POP(I.regs.w[CW]); CLK(1); } -OP( 0x5a, i_pop_dx ) { POP(I.regs.w[DW]); CLK(1); } -OP( 0x5b, i_pop_bx ) { POP(I.regs.w[BW]); CLK(1); } -OP( 0x5c, i_pop_sp ) { POP(I.regs.w[SP]); CLK(1); } -OP( 0x5d, i_pop_bp ) { POP(I.regs.w[BP]); CLK(1); } -OP( 0x5e, i_pop_si ) { POP(I.regs.w[IX]); CLK(1); } -OP( 0x5f, i_pop_di ) { POP(I.regs.w[IY]); CLK(1); } - -OP( 0x60, i_pusha ) { - uint32_t tmp=I.regs.w[SP]; - PUSH(I.regs.w[AW]); - PUSH(I.regs.w[CW]); - PUSH(I.regs.w[DW]); - PUSH(I.regs.w[BW]); - PUSH(tmp); - PUSH(I.regs.w[BP]); - PUSH(I.regs.w[IX]); - PUSH(I.regs.w[IY]); - CLK(9); +OP( 0x08, i_or_br8 ) +{ + DEF_br8; + ORB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); } -OP( 0x61, i_popa ) { - uint32_t tmp; - POP(I.regs.w[IY]); - POP(I.regs.w[IX]); - POP(I.regs.w[BP]); - POP(tmp); - POP(I.regs.w[BW]); - POP(I.regs.w[DW]); - POP(I.regs.w[CW]); - POP(I.regs.w[AW]); - (void)tmp; // We need to uppop something and need tmp - CLK(8); +OP( 0x09, i_or_wr16 ) +{ + DEF_wr16; + ORW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); } -OP( 0x62, i_chkind ) { - UINT32 low,high,tmp; - GetModRM; - low = GetRMWord(ModRM); - high= GetnextRMWord; - tmp= RegWord(ModRM); - if (tmphigh) { - nec_interrupt(5,0); - CLK(7); - } - CLK(13); +OP( 0x0a, i_or_r8b ) +{ + DEF_r8b; + ORB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x0b, i_or_r16w ) +{ + DEF_r16w; + ORW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x0c, i_or_ald8 ) +{ + DEF_ald8; + ORB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x0d, i_or_axd16 ) +{ + DEF_axd16; + ORW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x0e, i_push_cs ) +{ + PUSH(I.sregs[CS]); + CLK(2); +} +OP( 0x0f, i_pre_nec ) +{ + UINT32 ModRM, tmp, tmp2; /* pop cs at V30MZ? */ + + switch (FETCH) + { + case 0x10 : + BITOP_BYTE; + CLKS(3,3,4); + tmp2 = I.regs.b[CL] & 0x7; + I.ZeroVal = (tmp & (1<>8)&0xf); + tmp &= 0xff; + PutbackRMByte(ModRM,tmp); + CLKM(9,15); + break; + + case 0x2a : + ModRM = FETCH; + tmp = GetRMByte(ModRM); + tmp2 = (I.regs.b[AL] & 0xf)<<4; + I.regs.b[AL] = (I.regs.b[AL] & 0xf0) | (tmp&0xf); + tmp = tmp2 | (tmp>>4); + PutbackRMByte(ModRM,tmp); + CLKM(13,19); + break; + + case 0x31 : + ModRM = FETCH; + ModRM=0; + break; + + case 0x33 : + ModRM = FETCH; + ModRM=0; + break; + + case 0x92 : + CLK(2); + break; /* V25/35 FINT */ + + case 0xe0 : + ModRM = FETCH; + ModRM=0; + break; + + case 0xf0 : + ModRM = FETCH; + ModRM=0; + break; + + case 0xff : + ModRM = FETCH; + ModRM=0; + break; + + default: + break; + } +} + +OP( 0x10, i_adc_br8 ) +{ + DEF_br8; + src+=CF; + ADDB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); +} +OP( 0x11, i_adc_wr16 ) +{ + DEF_wr16; + src+=CF; + ADDW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); +} +OP( 0x12, i_adc_r8b ) +{ + DEF_r8b; + src+=CF; + ADDB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x13, i_adc_r16w ) +{ + DEF_r16w; + src+=CF; + ADDW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x14, i_adc_ald8 ) +{ + DEF_ald8; + src+=CF; + ADDB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x15, i_adc_axd16) +{ + DEF_axd16; + src+=CF; + ADDW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x16, i_push_ss ) +{ + PUSH(I.sregs[SS]); + CLK(2); +} +OP( 0x17, i_pop_ss ) +{ + POP(I.sregs[SS]); + CLK(3); + no_interrupt=1; +} + +OP( 0x18, i_sbb_br8 ) +{ + DEF_br8; + src+=CF; + SUBB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); +} +OP( 0x19, i_sbb_wr16 ) +{ + DEF_wr16; + src+=CF; + SUBW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); +} +OP( 0x1a, i_sbb_r8b ) +{ + DEF_r8b; + src+=CF; + SUBB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x1b, i_sbb_r16w ) +{ + DEF_r16w; + src+=CF; + SUBW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x1c, i_sbb_ald8 ) +{ + DEF_ald8; + src+=CF; + SUBB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x1d, i_sbb_axd16) +{ + DEF_axd16; + src+=CF; + SUBW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x1e, i_push_ds ) +{ + PUSH(I.sregs[DS]); + CLK(2); +} +OP( 0x1f, i_pop_ds ) +{ + POP(I.sregs[DS]); + CLK(3); +} + +OP( 0x20, i_and_br8 ) +{ + DEF_br8; + ANDB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); +} +OP( 0x21, i_and_wr16 ) +{ + DEF_wr16; + ANDW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); +} +OP( 0x22, i_and_r8b ) +{ + DEF_r8b; + ANDB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x23, i_and_r16w ) +{ + DEF_r16w; + ANDW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x24, i_and_ald8 ) +{ + DEF_ald8; + ANDB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x25, i_and_axd16) +{ + DEF_axd16; + ANDW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x26, i_es ) +{ + seg_prefix=TRUE; + prefix_base=I.sregs[ES]<<4; + CLK(1); + nec_instruction[FETCHOP](); + seg_prefix=FALSE; +} +OP( 0x27, i_daa ) +{ + ADJ4(6,0x60); + CLK(10); +} + +OP( 0x28, i_sub_br8 ) +{ + DEF_br8; + SUBB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); +} +OP( 0x29, i_sub_wr16 ) +{ + DEF_wr16; + SUBW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); +} +OP( 0x2a, i_sub_r8b ) +{ + DEF_r8b; + SUBB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x2b, i_sub_r16w ) +{ + DEF_r16w; + SUBW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x2c, i_sub_ald8 ) +{ + DEF_ald8; + SUBB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x2d, i_sub_axd16) +{ + DEF_axd16; + SUBW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x2e, i_cs ) +{ + seg_prefix=TRUE; + prefix_base=I.sregs[CS]<<4; + CLK(1); + nec_instruction[FETCHOP](); + seg_prefix=FALSE; +} +OP( 0x2f, i_das ) +{ + ADJ4(-6,-0x60); + CLK(10); +} + +OP( 0x30, i_xor_br8 ) +{ + DEF_br8; + XORB; + PutbackRMByte(ModRM,dst); + CLKM(3,1); +} +OP( 0x31, i_xor_wr16 ) +{ + DEF_wr16; + XORW; + PutbackRMWord(ModRM,dst); + CLKM(3,1); +} +OP( 0x32, i_xor_r8b ) +{ + DEF_r8b; + XORB; + RegByte(ModRM)=dst; + CLKM(2,1); +} +OP( 0x33, i_xor_r16w ) +{ + DEF_r16w; + XORW; + RegWord(ModRM)=dst; + CLKM(2,1); +} +OP( 0x34, i_xor_ald8 ) +{ + DEF_ald8; + XORB; + I.regs.b[AL]=dst; + CLK(1); +} +OP( 0x35, i_xor_axd16) +{ + DEF_axd16; + XORW; + I.regs.w[AW]=dst; + CLK(1); +} +OP( 0x36, i_ss ) +{ + seg_prefix=TRUE; + prefix_base=I.sregs[SS]<<4; + CLK(1); + nec_instruction[FETCHOP](); + seg_prefix=FALSE; +} +OP( 0x37, i_aaa ) +{ + ADJB(6,1); + CLK(9); +} + +OP( 0x38, i_cmp_br8 ) +{ + DEF_br8; + SUBB; + CLKM(2,1); +} +OP( 0x39, i_cmp_wr16 ) +{ + DEF_wr16; + SUBW; + CLKM(2,1); +} +OP( 0x3a, i_cmp_r8b ) +{ + DEF_r8b; + SUBB; + CLKM(2,1); +} +OP( 0x3b, i_cmp_r16w ) +{ + DEF_r16w; + SUBW; + CLKM(2,1); +} +OP( 0x3c, i_cmp_ald8 ) +{ + DEF_ald8; + SUBB; + CLK(1); +} +OP( 0x3d, i_cmp_axd16) +{ + DEF_axd16; + SUBW; + CLK(1); +} +OP( 0x3e, i_ds ) +{ + seg_prefix=TRUE; + prefix_base=I.sregs[DS]<<4; + CLK(1); + nec_instruction[FETCHOP](); + seg_prefix=FALSE; +} +OP( 0x3f, i_aas ) +{ + ADJB(-6,-1); + CLK(9); +} + +OP( 0x40, i_inc_ax ) +{ + IncWordReg(AW); + CLK(1); +} +OP( 0x41, i_inc_cx ) +{ + IncWordReg(CW); + CLK(1); +} +OP( 0x42, i_inc_dx ) +{ + IncWordReg(DW); + CLK(1); +} +OP( 0x43, i_inc_bx ) +{ + IncWordReg(BW); + CLK(1); +} +OP( 0x44, i_inc_sp ) +{ + IncWordReg(SP); + CLK(1); +} +OP( 0x45, i_inc_bp ) +{ + IncWordReg(BP); + CLK(1); +} +OP( 0x46, i_inc_si ) +{ + IncWordReg(IX); + CLK(1); +} +OP( 0x47, i_inc_di ) +{ + IncWordReg(IY); + CLK(1); +} + +OP( 0x48, i_dec_ax ) +{ + DecWordReg(AW); + CLK(1); +} +OP( 0x49, i_dec_cx ) +{ + DecWordReg(CW); + CLK(1); +} +OP( 0x4a, i_dec_dx ) +{ + DecWordReg(DW); + CLK(1); +} +OP( 0x4b, i_dec_bx ) +{ + DecWordReg(BW); + CLK(1); +} +OP( 0x4c, i_dec_sp ) +{ + DecWordReg(SP); + CLK(1); +} +OP( 0x4d, i_dec_bp ) +{ + DecWordReg(BP); + CLK(1); +} +OP( 0x4e, i_dec_si ) +{ + DecWordReg(IX); + CLK(1); +} +OP( 0x4f, i_dec_di ) +{ + DecWordReg(IY); + CLK(1); +} + +OP( 0x50, i_push_ax ) +{ + PUSH(I.regs.w[AW]); + CLK(1); +} +OP( 0x51, i_push_cx ) +{ + PUSH(I.regs.w[CW]); + CLK(1); +} +OP( 0x52, i_push_dx ) +{ + PUSH(I.regs.w[DW]); + CLK(1); +} +OP( 0x53, i_push_bx ) +{ + PUSH(I.regs.w[BW]); + CLK(1); +} +OP( 0x54, i_push_sp ) +{ + PUSH(I.regs.w[SP]); + CLK(1); +} +OP( 0x55, i_push_bp ) +{ + PUSH(I.regs.w[BP]); + CLK(1); +} +OP( 0x56, i_push_si ) +{ + PUSH(I.regs.w[IX]); + CLK(1); +} +OP( 0x57, i_push_di ) +{ + PUSH(I.regs.w[IY]); + CLK(1); +} + +OP( 0x58, i_pop_ax ) +{ + POP(I.regs.w[AW]); + CLK(1); +} +OP( 0x59, i_pop_cx ) +{ + POP(I.regs.w[CW]); + CLK(1); +} +OP( 0x5a, i_pop_dx ) +{ + POP(I.regs.w[DW]); + CLK(1); +} +OP( 0x5b, i_pop_bx ) +{ + POP(I.regs.w[BW]); + CLK(1); +} +OP( 0x5c, i_pop_sp ) +{ + POP(I.regs.w[SP]); + CLK(1); +} +OP( 0x5d, i_pop_bp ) +{ + POP(I.regs.w[BP]); + CLK(1); +} +OP( 0x5e, i_pop_si ) +{ + POP(I.regs.w[IX]); + CLK(1); +} +OP( 0x5f, i_pop_di ) +{ + POP(I.regs.w[IY]); + CLK(1); +} + +OP( 0x60, i_pusha ) +{ + uint32_t tmp=I.regs.w[SP]; + PUSH(I.regs.w[AW]); + PUSH(I.regs.w[CW]); + PUSH(I.regs.w[DW]); + PUSH(I.regs.w[BW]); + PUSH(tmp); + PUSH(I.regs.w[BP]); + PUSH(I.regs.w[IX]); + PUSH(I.regs.w[IY]); + CLK(9); +} +OP( 0x61, i_popa ) +{ + uint32_t tmp; + POP(I.regs.w[IY]); + POP(I.regs.w[IX]); + POP(I.regs.w[BP]); + POP(tmp); + POP(I.regs.w[BW]); + POP(I.regs.w[DW]); + POP(I.regs.w[CW]); + POP(I.regs.w[AW]); + (void)tmp; // We need to uppop something and need tmp + CLK(8); +} +OP( 0x62, i_chkind ) +{ + UINT32 low,high,tmp; + GetModRM; + low = GetRMWord(ModRM); + high= GetnextRMWord; + tmp= RegWord(ModRM); + + if (tmphigh) + { + nec_interrupt(5,0); + CLK(7); + } + + CLK(13); } /* OP 0x64 - 0x67 is nop at V30MZ */ -OP( 0x64, i_repnc ) { UINT32 next = FETCHOP; UINT16 c = I.regs.w[CW]; - switch(next) { /* Segments */ - case 0x26: seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; next = FETCHOP; CLK(2); break; - case 0x2e: seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; next = FETCHOP; CLK(2); break; - case 0x36: seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break; - case 0x3e: seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; next = FETCHOP; CLK(2); break; - } +OP( 0x64, i_repnc ) +{ + UINT32 next = FETCHOP; + UINT16 c = I.regs.w[CW]; - switch(next) { - case 0x6c: CLK(2); if (c) do { i_insb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0x6d: CLK(2); if (c) do { i_insw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0x6e: CLK(2); if (c) do { i_outsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0x6f: CLK(2); if (c) do { i_outsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xa4: CLK(2); if (c) do { i_movsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xa5: CLK(2); if (c) do { i_movsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xa6: CLK(2); if (c) do { i_cmpsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xa7: CLK(2); if (c) do { i_cmpsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xaa: CLK(2); if (c) do { i_stosb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xab: CLK(2); if (c) do { i_stosw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xac: CLK(2); if (c) do { i_lodsb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xad: CLK(2); if (c) do { i_lodsw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xae: CLK(2); if (c) do { i_scasb(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - case 0xaf: CLK(2); if (c) do { i_scasw(); c--; } while (c>0 && !CF); I.regs.w[CW]=c; break; - default: nec_instruction[next](); - } - seg_prefix=FALSE; + switch(next) /* Segments */ + { + case 0x26: + seg_prefix=TRUE; + prefix_base=I.sregs[ES]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x2e: + seg_prefix=TRUE; + prefix_base=I.sregs[CS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x36: + seg_prefix=TRUE; + prefix_base=I.sregs[SS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x3e: + seg_prefix=TRUE; + prefix_base=I.sregs[DS]<<4; + next = FETCHOP; + CLK(2); + break; + } + + switch(next) + { + case 0x6c: + CLK(2); + + if (c) do + { + i_insb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0x6d: + CLK(2); + + if (c) do + { + i_insw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0x6e: + CLK(2); + + if (c) do + { + i_outsb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0x6f: + CLK(2); + + if (c) do + { + i_outsw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xa4: + CLK(2); + + if (c) do + { + i_movsb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xa5: + CLK(2); + + if (c) do + { + i_movsw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xa6: + CLK(2); + + if (c) do + { + i_cmpsb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xa7: + CLK(2); + + if (c) do + { + i_cmpsw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xaa: + CLK(2); + + if (c) do + { + i_stosb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xab: + CLK(2); + + if (c) do + { + i_stosw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xac: + CLK(2); + + if (c) do + { + i_lodsb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xad: + CLK(2); + + if (c) do + { + i_lodsw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xae: + CLK(2); + + if (c) do + { + i_scasb(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + case 0xaf: + CLK(2); + + if (c) do + { + i_scasw(); + c--; + } + while (c>0 && !CF); + + I.regs.w[CW]=c; + break; + + default: + nec_instruction[next](); + } + + seg_prefix=FALSE; } -OP( 0x65, i_repc ) { UINT32 next = FETCHOP; UINT16 c = I.regs.w[CW]; - switch(next) { /* Segments */ - case 0x26: seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; next = FETCHOP; CLK(2); break; - case 0x2e: seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; next = FETCHOP; CLK(2); break; - case 0x36: seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break; - case 0x3e: seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; next = FETCHOP; CLK(2); break; - } +OP( 0x65, i_repc ) +{ + UINT32 next = FETCHOP; + UINT16 c = I.regs.w[CW]; - switch(next) { - case 0x6c: CLK(2); if (c) do { i_insb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0x6d: CLK(2); if (c) do { i_insw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0x6e: CLK(2); if (c) do { i_outsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0x6f: CLK(2); if (c) do { i_outsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xa4: CLK(2); if (c) do { i_movsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xa5: CLK(2); if (c) do { i_movsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xa6: CLK(2); if (c) do { i_cmpsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xa7: CLK(2); if (c) do { i_cmpsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xaa: CLK(2); if (c) do { i_stosb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xab: CLK(2); if (c) do { i_stosw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xac: CLK(2); if (c) do { i_lodsb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xad: CLK(2); if (c) do { i_lodsw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xae: CLK(2); if (c) do { i_scasb(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - case 0xaf: CLK(2); if (c) do { i_scasw(); c--; } while (c>0 && CF); I.regs.w[CW]=c; break; - default: nec_instruction[next](); - } - seg_prefix=FALSE; + switch(next) /* Segments */ + { + case 0x26: + seg_prefix=TRUE; + prefix_base=I.sregs[ES]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x2e: + seg_prefix=TRUE; + prefix_base=I.sregs[CS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x36: + seg_prefix=TRUE; + prefix_base=I.sregs[SS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x3e: + seg_prefix=TRUE; + prefix_base=I.sregs[DS]<<4; + next = FETCHOP; + CLK(2); + break; + } + + switch(next) + { + case 0x6c: + CLK(2); + + if (c) do + { + i_insb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0x6d: + CLK(2); + + if (c) do + { + i_insw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0x6e: + CLK(2); + + if (c) do + { + i_outsb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0x6f: + CLK(2); + + if (c) do + { + i_outsw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xa4: + CLK(2); + + if (c) do + { + i_movsb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xa5: + CLK(2); + + if (c) do + { + i_movsw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xa6: + CLK(2); + + if (c) do + { + i_cmpsb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xa7: + CLK(2); + + if (c) do + { + i_cmpsw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xaa: + CLK(2); + + if (c) do + { + i_stosb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xab: + CLK(2); + + if (c) do + { + i_stosw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xac: + CLK(2); + + if (c) do + { + i_lodsb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xad: + CLK(2); + + if (c) do + { + i_lodsw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xae: + CLK(2); + + if (c) do + { + i_scasb(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + case 0xaf: + CLK(2); + + if (c) do + { + i_scasw(); + c--; + } + while (c>0 && CF); + + I.regs.w[CW]=c; + break; + + default: + nec_instruction[next](); + } + + seg_prefix=FALSE; } -OP( 0x68, i_push_d16 ) { UINT32 tmp; FETCHWORD(tmp); PUSH(tmp); CLK(1); } -OP( 0x69, i_imul_d16 ) { UINT32 tmp; DEF_r16w; FETCHWORD(tmp); dst = (INT32)((INT16)src)*(INT32)((INT16)tmp); I.CarryVal = I.OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); RegWord(ModRM)=(WORD)dst; CLKM(4,3);} -OP( 0x6a, i_push_d8 ) { UINT32 tmp = (WORD)((INT16)((INT8)FETCH)); PUSH(tmp); CLK(1); } -OP( 0x6b, i_imul_d8 ) { UINT32 src2; DEF_r16w; src2= (WORD)((INT16)((INT8)FETCH)); dst = (INT32)((INT16)src)*(INT32)((INT16)src2); I.CarryVal = I.OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); RegWord(ModRM)=(WORD)dst; CLKM(4,3); } -OP( 0x6c, i_insb ) { PutMemB(ES,I.regs.w[IY],read_port(I.regs.w[DW])); I.regs.w[IY]+= -2 * I.DF + 1; CLK(6); } -OP( 0x6d, i_insw ) { PutMemB(ES,I.regs.w[IY],read_port(I.regs.w[DW])); PutMemB(ES,(I.regs.w[IY]+1)&0xffff,read_port((I.regs.w[DW]+1)&0xffff)); I.regs.w[IY]+= -4 * I.DF + 2; CLK(6); } -OP( 0x6e, i_outsb ) { write_port(I.regs.w[DW],GetMemB(DS,I.regs.w[IX])); I.regs.w[IX]+= -2 * I.DF + 1; CLK(7); } -OP( 0x6f, i_outsw ) { write_port(I.regs.w[DW],GetMemB(DS,I.regs.w[IX])); write_port((I.regs.w[DW]+1)&0xffff,GetMemB(DS,(I.regs.w[IX]+1)&0xffff)); I.regs.w[IX]+= -4 * I.DF + 2; CLK(7); } - -OP( 0x70, i_jo ) { JMP( OF); CLK(1); } -OP( 0x71, i_jno ) { JMP(!OF); CLK(1); } -OP( 0x72, i_jc ) { JMP( CF); CLK(1); } -OP( 0x73, i_jnc ) { JMP(!CF); CLK(1); } -OP( 0x74, i_jz ) { JMP( ZF); CLK(1); } -OP( 0x75, i_jnz ) { JMP(!ZF); CLK(1); } -OP( 0x76, i_jce ) { JMP(CF || ZF); CLK(1); } -OP( 0x77, i_jnce ) { JMP(!(CF || ZF)); CLK(1); } -OP( 0x78, i_js ) { JMP( SF); CLK(1); } -OP( 0x79, i_jns ) { JMP(!SF); CLK(1); } -OP( 0x7a, i_jp ) { JMP( PF); CLK(1); } -OP( 0x7b, i_jnp ) { JMP(!PF); CLK(1); } -OP( 0x7c, i_jl ) { JMP((SF!=OF)&&(!ZF)); CLK(1); } -OP( 0x7d, i_jnl ) { JMP((ZF)||(SF==OF)); CLK(1); } -OP( 0x7e, i_jle ) { JMP((ZF)||(SF!=OF)); CLK(1); } -OP( 0x7f, i_jnle ) { JMP((SF==OF)&&(!ZF)); CLK(1); } - -OP( 0x80, i_80pre ) { UINT32 dst, src; GetModRM; dst = GetRMByte(ModRM); src = FETCH; - CLKM(3,1) - switch (ModRM & 0x38) { - case 0x00: ADDB; PutbackRMByte(ModRM,dst); break; - case 0x08: ORB; PutbackRMByte(ModRM,dst); break; - case 0x10: src+=CF; ADDB; PutbackRMByte(ModRM,dst); break; - case 0x18: src+=CF; SUBB; PutbackRMByte(ModRM,dst); break; - case 0x20: ANDB; PutbackRMByte(ModRM,dst); break; - case 0x28: SUBB; PutbackRMByte(ModRM,dst); break; - case 0x30: XORB; PutbackRMByte(ModRM,dst); break; - case 0x38: SUBB; break; /* CMP */ - } +OP( 0x68, i_push_d16 ) +{ + UINT32 tmp; + FETCHWORD(tmp); + PUSH(tmp); + CLK(1); +} +OP( 0x69, i_imul_d16 ) +{ + UINT32 tmp; + DEF_r16w; + FETCHWORD(tmp); + dst = (INT32)((INT16)src)*(INT32)((INT16)tmp); + I.CarryVal = I.OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); + RegWord(ModRM)=(WORD)dst; + CLKM(4,3); +} +OP( 0x6a, i_push_d8 ) +{ + UINT32 tmp = (WORD)((INT16)((INT8)FETCH)); + PUSH(tmp); + CLK(1); +} +OP( 0x6b, i_imul_d8 ) +{ + UINT32 src2; + DEF_r16w; + src2= (WORD)((INT16)((INT8)FETCH)); + dst = (INT32)((INT16)src)*(INT32)((INT16)src2); + I.CarryVal = I.OverVal = (((INT32)dst) >> 15 != 0) && (((INT32)dst) >> 15 != -1); + RegWord(ModRM)=(WORD)dst; + CLKM(4,3); +} +OP( 0x6c, i_insb ) +{ + PutMemB(ES,I.regs.w[IY],read_port(I.regs.w[DW])); + I.regs.w[IY]+= -2 * I.DF + 1; + CLK(6); +} +OP( 0x6d, i_insw ) +{ + PutMemB(ES,I.regs.w[IY],read_port(I.regs.w[DW])); + PutMemB(ES,(I.regs.w[IY]+1)&0xffff,read_port((I.regs.w[DW]+1)&0xffff)); + I.regs.w[IY]+= -4 * I.DF + 2; + CLK(6); +} +OP( 0x6e, i_outsb ) +{ + write_port(I.regs.w[DW],GetMemB(DS,I.regs.w[IX])); + I.regs.w[IX]+= -2 * I.DF + 1; + CLK(7); +} +OP( 0x6f, i_outsw ) +{ + write_port(I.regs.w[DW],GetMemB(DS,I.regs.w[IX])); + write_port((I.regs.w[DW]+1)&0xffff,GetMemB(DS,(I.regs.w[IX]+1)&0xffff)); + I.regs.w[IX]+= -4 * I.DF + 2; + CLK(7); } -OP( 0x81, i_81pre ) { UINT32 dst, src; GetModRM; dst = GetRMWord(ModRM); src = FETCH; src+= (FETCH << 8); - CLKM(3,1) - switch (ModRM & 0x38) { - case 0x00: ADDW; PutbackRMWord(ModRM,dst); break; - case 0x08: ORW; PutbackRMWord(ModRM,dst); break; - case 0x10: src+=CF; ADDW; PutbackRMWord(ModRM,dst); break; - case 0x18: src+=CF; SUBW; PutbackRMWord(ModRM,dst); break; - case 0x20: ANDW; PutbackRMWord(ModRM,dst); break; - case 0x28: SUBW; PutbackRMWord(ModRM,dst); break; - case 0x30: XORW; PutbackRMWord(ModRM,dst); break; - case 0x38: SUBW; break; /* CMP */ - } +OP( 0x70, i_jo ) +{ + JMP( OF); + CLK(1); +} +OP( 0x71, i_jno ) +{ + JMP(!OF); + CLK(1); +} +OP( 0x72, i_jc ) +{ + JMP( CF); + CLK(1); +} +OP( 0x73, i_jnc ) +{ + JMP(!CF); + CLK(1); +} +OP( 0x74, i_jz ) +{ + JMP( ZF); + CLK(1); +} +OP( 0x75, i_jnz ) +{ + JMP(!ZF); + CLK(1); +} +OP( 0x76, i_jce ) +{ + JMP(CF || ZF); + CLK(1); +} +OP( 0x77, i_jnce ) +{ + JMP(!(CF || ZF)); + CLK(1); +} +OP( 0x78, i_js ) +{ + JMP( SF); + CLK(1); +} +OP( 0x79, i_jns ) +{ + JMP(!SF); + CLK(1); +} +OP( 0x7a, i_jp ) +{ + JMP( PF); + CLK(1); +} +OP( 0x7b, i_jnp ) +{ + JMP(!PF); + CLK(1); +} +OP( 0x7c, i_jl ) +{ + JMP((SF!=OF)&&(!ZF)); + CLK(1); +} +OP( 0x7d, i_jnl ) +{ + JMP((ZF)||(SF==OF)); + CLK(1); +} +OP( 0x7e, i_jle ) +{ + JMP((ZF)||(SF!=OF)); + CLK(1); +} +OP( 0x7f, i_jnle ) +{ + JMP((SF==OF)&&(!ZF)); + CLK(1); } -OP( 0x82, i_82pre ) { UINT32 dst, src; GetModRM; dst = GetRMByte(ModRM); src = (BYTE)((INT8)FETCH); - CLKM(3,1) - switch (ModRM & 0x38) { - case 0x00: ADDB; PutbackRMByte(ModRM,dst); break; - case 0x08: ORB; PutbackRMByte(ModRM,dst); break; - case 0x10: src+=CF; ADDB; PutbackRMByte(ModRM,dst); break; - case 0x18: src+=CF; SUBB; PutbackRMByte(ModRM,dst); break; - case 0x20: ANDB; PutbackRMByte(ModRM,dst); break; - case 0x28: SUBB; PutbackRMByte(ModRM,dst); break; - case 0x30: XORB; PutbackRMByte(ModRM,dst); break; - case 0x38: SUBB; break; /* CMP */ - } +OP( 0x80, i_80pre ) +{ + UINT32 dst, src; + GetModRM; + dst = GetRMByte(ModRM); + src = FETCH; + CLKM(3,1) + + switch (ModRM & 0x38) + { + case 0x00: + ADDB; + PutbackRMByte(ModRM,dst); + break; + + case 0x08: + ORB; + PutbackRMByte(ModRM,dst); + break; + + case 0x10: + src+=CF; + ADDB; + PutbackRMByte(ModRM,dst); + break; + + case 0x18: + src+=CF; + SUBB; + PutbackRMByte(ModRM,dst); + break; + + case 0x20: + ANDB; + PutbackRMByte(ModRM,dst); + break; + + case 0x28: + SUBB; + PutbackRMByte(ModRM,dst); + break; + + case 0x30: + XORB; + PutbackRMByte(ModRM,dst); + break; + + case 0x38: + SUBB; + break; /* CMP */ + } } -OP( 0x83, i_83pre ) { UINT32 dst, src; GetModRM; dst = GetRMWord(ModRM); src = (WORD)((INT16)((INT8)FETCH)); - CLKM(3,1) - switch (ModRM & 0x38) { - case 0x00: ADDW; PutbackRMWord(ModRM,dst); break; - case 0x08: ORW; PutbackRMWord(ModRM,dst); break; - case 0x10: src+=CF; ADDW; PutbackRMWord(ModRM,dst); break; - case 0x18: src+=CF; SUBW; PutbackRMWord(ModRM,dst); break; - case 0x20: ANDW; PutbackRMWord(ModRM,dst); break; - case 0x28: SUBW; PutbackRMWord(ModRM,dst); break; - case 0x30: XORW; PutbackRMWord(ModRM,dst); break; - case 0x38: SUBW; break; /* CMP */ - } +OP( 0x81, i_81pre ) +{ + UINT32 dst, src; + GetModRM; + dst = GetRMWord(ModRM); + src = FETCH; + src+= (FETCH << 8); + CLKM(3,1) + + switch (ModRM & 0x38) + { + case 0x00: + ADDW; + PutbackRMWord(ModRM,dst); + break; + + case 0x08: + ORW; + PutbackRMWord(ModRM,dst); + break; + + case 0x10: + src+=CF; + ADDW; + PutbackRMWord(ModRM,dst); + break; + + case 0x18: + src+=CF; + SUBW; + PutbackRMWord(ModRM,dst); + break; + + case 0x20: + ANDW; + PutbackRMWord(ModRM,dst); + break; + + case 0x28: + SUBW; + PutbackRMWord(ModRM,dst); + break; + + case 0x30: + XORW; + PutbackRMWord(ModRM,dst); + break; + + case 0x38: + SUBW; + break; /* CMP */ + } } -OP( 0x84, i_test_br8 ) { DEF_br8; ANDB; CLKM(2,1); } -OP( 0x85, i_test_wr16 ) { DEF_wr16; ANDW; CLKM(2,1); } -OP( 0x86, i_xchg_br8 ) { DEF_br8; RegByte(ModRM)=dst; PutbackRMByte(ModRM,src); CLKM(5,3); } -OP( 0x87, i_xchg_wr16 ) { DEF_wr16; RegWord(ModRM)=dst; PutbackRMWord(ModRM,src); CLKM(5,3); } +OP( 0x82, i_82pre ) +{ + UINT32 dst, src; + GetModRM; + dst = GetRMByte(ModRM); + src = (BYTE)((INT8)FETCH); + CLKM(3,1) -OP( 0x88, i_mov_br8 ) { UINT8 src; GetModRM; src = RegByte(ModRM); PutRMByte(ModRM,src); CLKM(1,1); } -OP( 0x89, i_mov_wr16 ) { UINT16 src; GetModRM; src = RegWord(ModRM); PutRMWord(ModRM,src); CLKM(1,1); } -OP( 0x8a, i_mov_r8b ) { UINT8 src; GetModRM; src = GetRMByte(ModRM); RegByte(ModRM)=src; CLKM(1,1); } -OP( 0x8b, i_mov_r16w ) { UINT16 src; GetModRM; src = GetRMWord(ModRM); RegWord(ModRM)=src; CLKM(1,1); } -OP( 0x8c, i_mov_wsreg ) { GetModRM; PutRMWord(ModRM,I.sregs[(ModRM & 0x38) >> 3]); CLKM(1,1); } -OP( 0x8d, i_lea ) { UINT16 ModRM = FETCH; (void)(*GetEA[ModRM])(); RegWord(ModRM)=EO; CLK(1); } -OP( 0x8e, i_mov_sregw ) { UINT16 src; GetModRM; src = GetRMWord(ModRM); CLKM(3,2); - switch (ModRM & 0x38) { - case 0x00: I.sregs[ES] = src; break; /* mov es,ew */ - case 0x08: I.sregs[CS] = src; break; /* mov cs,ew */ - case 0x10: I.sregs[SS] = src; break; /* mov ss,ew */ - case 0x18: I.sregs[DS] = src; break; /* mov ds,ew */ - default: ; - } - no_interrupt=1; -} -OP( 0x8f, i_popw ) { UINT16 tmp; GetModRM; POP(tmp); PutRMWord(ModRM,tmp); CLKM(3,1); } -OP( 0x90, i_nop ) { CLK(1); - /* Cycle skip for idle loops (0: NOP 1: JMP 0) */ - if (no_interrupt==0 && nec_ICount>0 && (PEEKOP((I.sregs[CS]<<4)+I.ip))==0xeb && (PEEK((I.sregs[CS]<<4)+I.ip+1))==0xfd) - nec_ICount%=15; -} -OP( 0x91, i_xchg_axcx ) { XchgAWReg(CW); CLK(3); } -OP( 0x92, i_xchg_axdx ) { XchgAWReg(DW); CLK(3); } -OP( 0x93, i_xchg_axbx ) { XchgAWReg(BW); CLK(3); } -OP( 0x94, i_xchg_axsp ) { XchgAWReg(SP); CLK(3); } -OP( 0x95, i_xchg_axbp ) { XchgAWReg(BP); CLK(3); } -OP( 0x96, i_xchg_axsi ) { XchgAWReg(IX); CLK(3); } -OP( 0x97, i_xchg_axdi ) { XchgAWReg(IY); CLK(3); } + switch (ModRM & 0x38) + { + case 0x00: + ADDB; + PutbackRMByte(ModRM,dst); + break; -OP( 0x98, i_cbw ) { I.regs.b[AH] = (I.regs.b[AL] & 0x80) ? 0xff : 0; CLK(1); } -OP( 0x99, i_cwd ) { I.regs.w[DW] = (I.regs.b[AH] & 0x80) ? 0xffff : 0; CLK(1); } -OP( 0x9a, i_call_far ) { UINT32 tmp, tmp2; FETCHWORD(tmp); FETCHWORD(tmp2); PUSH(I.sregs[CS]); PUSH(I.ip); I.ip = (WORD)tmp; I.sregs[CS] = (WORD)tmp2; CLK(10); } + case 0x08: + ORB; + PutbackRMByte(ModRM,dst); + break; + + case 0x10: + src+=CF; + ADDB; + PutbackRMByte(ModRM,dst); + break; + + case 0x18: + src+=CF; + SUBB; + PutbackRMByte(ModRM,dst); + break; + + case 0x20: + ANDB; + PutbackRMByte(ModRM,dst); + break; + + case 0x28: + SUBB; + PutbackRMByte(ModRM,dst); + break; + + case 0x30: + XORB; + PutbackRMByte(ModRM,dst); + break; + + case 0x38: + SUBB; + break; /* CMP */ + } +} + +OP( 0x83, i_83pre ) +{ + UINT32 dst, src; + GetModRM; + dst = GetRMWord(ModRM); + src = (WORD)((INT16)((INT8)FETCH)); + CLKM(3,1) + + switch (ModRM & 0x38) + { + case 0x00: + ADDW; + PutbackRMWord(ModRM,dst); + break; + + case 0x08: + ORW; + PutbackRMWord(ModRM,dst); + break; + + case 0x10: + src+=CF; + ADDW; + PutbackRMWord(ModRM,dst); + break; + + case 0x18: + src+=CF; + SUBW; + PutbackRMWord(ModRM,dst); + break; + + case 0x20: + ANDW; + PutbackRMWord(ModRM,dst); + break; + + case 0x28: + SUBW; + PutbackRMWord(ModRM,dst); + break; + + case 0x30: + XORW; + PutbackRMWord(ModRM,dst); + break; + + case 0x38: + SUBW; + break; /* CMP */ + } +} + +OP( 0x84, i_test_br8 ) +{ + DEF_br8; + ANDB; + CLKM(2,1); +} +OP( 0x85, i_test_wr16 ) +{ + DEF_wr16; + ANDW; + CLKM(2,1); +} +OP( 0x86, i_xchg_br8 ) +{ + DEF_br8; + RegByte(ModRM)=dst; + PutbackRMByte(ModRM,src); + CLKM(5,3); +} +OP( 0x87, i_xchg_wr16 ) +{ + DEF_wr16; + RegWord(ModRM)=dst; + PutbackRMWord(ModRM,src); + CLKM(5,3); +} + +OP( 0x88, i_mov_br8 ) +{ + UINT8 src; + GetModRM; + src = RegByte(ModRM); + PutRMByte(ModRM,src); + CLKM(1,1); +} +OP( 0x89, i_mov_wr16 ) +{ + UINT16 src; + GetModRM; + src = RegWord(ModRM); + PutRMWord(ModRM,src); + CLKM(1,1); +} +OP( 0x8a, i_mov_r8b ) +{ + UINT8 src; + GetModRM; + src = GetRMByte(ModRM); + RegByte(ModRM)=src; + CLKM(1,1); +} +OP( 0x8b, i_mov_r16w ) +{ + UINT16 src; + GetModRM; + src = GetRMWord(ModRM); + RegWord(ModRM)=src; + CLKM(1,1); +} +OP( 0x8c, i_mov_wsreg ) +{ + GetModRM; + PutRMWord(ModRM,I.sregs[(ModRM & 0x38) >> 3]); + CLKM(1,1); +} +OP( 0x8d, i_lea ) +{ + UINT16 ModRM = FETCH; + (void)(*GetEA[ModRM])(); + RegWord(ModRM)=EO; + CLK(1); +} +OP( 0x8e, i_mov_sregw ) +{ + UINT16 src; + GetModRM; + src = GetRMWord(ModRM); + CLKM(3,2); + + switch (ModRM & 0x38) + { + case 0x00: + I.sregs[ES] = src; + break; /* mov es,ew */ + + case 0x08: + I.sregs[CS] = src; + break; /* mov cs,ew */ + + case 0x10: + I.sregs[SS] = src; + break; /* mov ss,ew */ + + case 0x18: + I.sregs[DS] = src; + break; /* mov ds,ew */ + + default: + ; + } + + no_interrupt=1; +} +OP( 0x8f, i_popw ) +{ + UINT16 tmp; + GetModRM; + POP(tmp); + PutRMWord(ModRM,tmp); + CLKM(3,1); +} +OP( 0x90, i_nop ) +{ + CLK(1); + + /* Cycle skip for idle loops (0: NOP 1: JMP 0) */ + if (no_interrupt==0 && nec_ICount>0 && (PEEKOP((I.sregs[CS]<<4)+I.ip))==0xeb && (PEEK((I.sregs[CS]<<4)+I.ip+1))==0xfd) + { + nec_ICount%=15; + } +} +OP( 0x91, i_xchg_axcx ) +{ + XchgAWReg(CW); + CLK(3); +} +OP( 0x92, i_xchg_axdx ) +{ + XchgAWReg(DW); + CLK(3); +} +OP( 0x93, i_xchg_axbx ) +{ + XchgAWReg(BW); + CLK(3); +} +OP( 0x94, i_xchg_axsp ) +{ + XchgAWReg(SP); + CLK(3); +} +OP( 0x95, i_xchg_axbp ) +{ + XchgAWReg(BP); + CLK(3); +} +OP( 0x96, i_xchg_axsi ) +{ + XchgAWReg(IX); + CLK(3); +} +OP( 0x97, i_xchg_axdi ) +{ + XchgAWReg(IY); + CLK(3); +} + +OP( 0x98, i_cbw ) +{ + I.regs.b[AH] = (I.regs.b[AL] & 0x80) ? 0xff : 0; + CLK(1); +} +OP( 0x99, i_cwd ) +{ + I.regs.w[DW] = (I.regs.b[AH] & 0x80) ? 0xffff : 0; + CLK(1); +} +OP( 0x9a, i_call_far ) +{ + UINT32 tmp, tmp2; + FETCHWORD(tmp); + FETCHWORD(tmp2); + PUSH(I.sregs[CS]); + PUSH(I.ip); + I.ip = (WORD)tmp; + I.sregs[CS] = (WORD)tmp2; + CLK(10); +} OP( 0x9b, i_wait ) { ; } -OP( 0x9c, i_pushf ) { PUSH( CompressFlags() ); CLK(2); } -OP( 0x9d, i_popf ) { UINT32 tmp; POP(tmp); ExpandFlags(tmp); CLK(3);} -OP( 0x9e, i_sahf ) { UINT32 tmp = (CompressFlags() & 0xff00) | (I.regs.b[AH] & 0xd5); ExpandFlags(tmp); CLK(4); } -OP( 0x9f, i_lahf ) { I.regs.b[AH] = CompressFlags() & 0xff; CLK(2); } - -OP( 0xa0, i_mov_aldisp ) { UINT32 addr; FETCHWORD(addr); I.regs.b[AL] = GetMemB(DS, addr); CLK(1); } -OP( 0xa1, i_mov_axdisp ) { UINT32 addr; FETCHWORD(addr); I.regs.b[AL] = GetMemB(DS, addr); I.regs.b[AH] = GetMemB(DS, (addr+1)&0xffff); CLK(1); } -OP( 0xa2, i_mov_dispal ) { UINT32 addr; FETCHWORD(addr); PutMemB(DS, addr, I.regs.b[AL]); CLK(1); } -OP( 0xa3, i_mov_dispax ) { UINT32 addr; FETCHWORD(addr); PutMemB(DS, addr, I.regs.b[AL]); PutMemB(DS, (addr+1)&0xffff, I.regs.b[AH]); CLK(1); } -OP( 0xa4, i_movsb ) { UINT32 tmp = GetMemB(DS,I.regs.w[IX]); PutMemB(ES,I.regs.w[IY], tmp); I.regs.w[IY] += -2 * I.DF + 1; I.regs.w[IX] += -2 * I.DF + 1; CLK(5); } -OP( 0xa5, i_movsw ) { UINT32 tmp = GetMemW(DS,I.regs.w[IX]); PutMemW(ES,I.regs.w[IY], tmp); I.regs.w[IY] += -4 * I.DF + 2; I.regs.w[IX] += -4 * I.DF + 2; CLK(5); } -OP( 0xa6, i_cmpsb ) { UINT32 src = GetMemB(ES, I.regs.w[IY]); UINT32 dst = GetMemB(DS, I.regs.w[IX]); SUBB; I.regs.w[IY] += -2 * I.DF + 1; I.regs.w[IX] += -2 * I.DF + 1; CLK(6); } -OP( 0xa7, i_cmpsw ) { UINT32 src = GetMemW(ES, I.regs.w[IY]); UINT32 dst = GetMemW(DS, I.regs.w[IX]); SUBW; I.regs.w[IY] += -4 * I.DF + 2; I.regs.w[IX] += -4 * I.DF + 2; CLK(6); } - -OP( 0xa8, i_test_ald8 ) { DEF_ald8; ANDB; CLK(1); } -OP( 0xa9, i_test_axd16 ) { DEF_axd16; ANDW; CLK(1); } -OP( 0xaa, i_stosb ) { PutMemB(ES,I.regs.w[IY],I.regs.b[AL]); I.regs.w[IY] += -2 * I.DF + 1; CLK(3); } -OP( 0xab, i_stosw ) { PutMemW(ES,I.regs.w[IY],I.regs.w[AW]); I.regs.w[IY] += -4 * I.DF + 2; CLK(3); } -OP( 0xac, i_lodsb ) { I.regs.b[AL] = GetMemB(DS,I.regs.w[IX]); I.regs.w[IX] += -2 * I.DF + 1; CLK(3); } -OP( 0xad, i_lodsw ) { I.regs.w[AW] = GetMemW(DS,I.regs.w[IX]); I.regs.w[IX] += -4 * I.DF + 2; CLK(3); } -OP( 0xae, i_scasb ) { UINT32 src = GetMemB(ES, I.regs.w[IY]); UINT32 dst = I.regs.b[AL]; SUBB; I.regs.w[IY] += -2 * I.DF + 1; CLK(4); } -OP( 0xaf, i_scasw ) { UINT32 src = GetMemW(ES, I.regs.w[IY]); UINT32 dst = I.regs.w[AW]; SUBW; I.regs.w[IY] += -4 * I.DF + 2; CLK(4); } - -OP( 0xb0, i_mov_ald8 ) { I.regs.b[AL] = FETCH; CLK(1); } -OP( 0xb1, i_mov_cld8 ) { I.regs.b[CL] = FETCH; CLK(1); } -OP( 0xb2, i_mov_dld8 ) { I.regs.b[DL] = FETCH; CLK(1); } -OP( 0xb3, i_mov_bld8 ) { I.regs.b[BL] = FETCH; CLK(1); } -OP( 0xb4, i_mov_ahd8 ) { I.regs.b[AH] = FETCH; CLK(1); } -OP( 0xb5, i_mov_chd8 ) { I.regs.b[CH] = FETCH; CLK(1); } -OP( 0xb6, i_mov_dhd8 ) { I.regs.b[DH] = FETCH; CLK(1); } -OP( 0xb7, i_mov_bhd8 ) { I.regs.b[BH] = FETCH; CLK(1); } - -OP( 0xb8, i_mov_axd16 ) { I.regs.b[AL] = FETCH; I.regs.b[AH] = FETCH; CLK(1); } -OP( 0xb9, i_mov_cxd16 ) { I.regs.b[CL] = FETCH; I.regs.b[CH] = FETCH; CLK(1); } -OP( 0xba, i_mov_dxd16 ) { I.regs.b[DL] = FETCH; I.regs.b[DH] = FETCH; CLK(1); } -OP( 0xbb, i_mov_bxd16 ) { I.regs.b[BL] = FETCH; I.regs.b[BH] = FETCH; CLK(1); } -OP( 0xbc, i_mov_spd16 ) { I.regs.b[SPL] = FETCH; I.regs.b[SPH] = FETCH; CLK(1); } -OP( 0xbd, i_mov_bpd16 ) { I.regs.b[BPL] = FETCH; I.regs.b[BPH] = FETCH; CLK(1); } -OP( 0xbe, i_mov_sid16 ) { I.regs.b[IXL] = FETCH; I.regs.b[IXH] = FETCH; CLK(1); } -OP( 0xbf, i_mov_did16 ) { I.regs.b[IYL] = FETCH; I.regs.b[IYH] = FETCH; CLK(1); } - -OP( 0xc0, i_rotshft_bd8 ) { - UINT32 src, dst; UINT8 c; - GetModRM; src = (uint32_t)GetRMByte(ModRM); dst=src; - c=FETCH; - c&=0x1f; - CLKM(5,3); - if (c) switch (ModRM & 0x38) { - case 0x00: do { ROL_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x08: do { ROR_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x10: do { ROLC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x18: do { RORC_BYTE; c--; } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x20: SHL_BYTE(c); I.AuxVal = 1; break;// - case 0x28: SHR_BYTE(c); I.AuxVal = 1; break;// - case 0x30: break; - case 0x38: SHRA_BYTE(c); break; - } +OP( 0x9c, i_pushf ) +{ + PUSH( CompressFlags() ); + CLK(2); +} +OP( 0x9d, i_popf ) +{ + UINT32 tmp; + POP(tmp); + ExpandFlags(tmp); + CLK(3); +} +OP( 0x9e, i_sahf ) +{ + UINT32 tmp = (CompressFlags() & 0xff00) | (I.regs.b[AH] & 0xd5); + ExpandFlags(tmp); + CLK(4); +} +OP( 0x9f, i_lahf ) +{ + I.regs.b[AH] = CompressFlags() & 0xff; + CLK(2); } -OP( 0xc1, i_rotshft_wd8 ) { - UINT32 src, dst; UINT8 c; - GetModRM; src = (uint32_t)GetRMWord(ModRM); dst=src; - c=FETCH; - c&=0x1f; - CLKM(5,3); - if (c) switch (ModRM & 0x38) { - case 0x00: do { ROL_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x08: do { ROR_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x10: do { ROLC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x18: do { RORC_WORD; c--; } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x20: SHL_WORD(c); I.AuxVal = 1; break; - case 0x28: SHR_WORD(c); I.AuxVal = 1; break; - case 0x30: break; - case 0x38: SHRA_WORD(c); break; - } +OP( 0xa0, i_mov_aldisp ) +{ + UINT32 addr; + FETCHWORD(addr); + I.regs.b[AL] = GetMemB(DS, addr); + CLK(1); +} +OP( 0xa1, i_mov_axdisp ) +{ + UINT32 addr; + FETCHWORD(addr); + I.regs.b[AL] = GetMemB(DS, addr); + I.regs.b[AH] = GetMemB(DS, (addr+1)&0xffff); + CLK(1); +} +OP( 0xa2, i_mov_dispal ) +{ + UINT32 addr; + FETCHWORD(addr); + PutMemB(DS, addr, I.regs.b[AL]); + CLK(1); +} +OP( 0xa3, i_mov_dispax ) +{ + UINT32 addr; + FETCHWORD(addr); + PutMemB(DS, addr, I.regs.b[AL]); + PutMemB(DS, (addr+1)&0xffff, I.regs.b[AH]); + CLK(1); +} +OP( 0xa4, i_movsb ) +{ + UINT32 tmp = GetMemB(DS,I.regs.w[IX]); + PutMemB(ES,I.regs.w[IY], tmp); + I.regs.w[IY] += -2 * I.DF + 1; + I.regs.w[IX] += -2 * I.DF + 1; + CLK(5); +} +OP( 0xa5, i_movsw ) +{ + UINT32 tmp = GetMemW(DS,I.regs.w[IX]); + PutMemW(ES,I.regs.w[IY], tmp); + I.regs.w[IY] += -4 * I.DF + 2; + I.regs.w[IX] += -4 * I.DF + 2; + CLK(5); +} +OP( 0xa6, i_cmpsb ) +{ + UINT32 src = GetMemB(ES, I.regs.w[IY]); + UINT32 dst = GetMemB(DS, I.regs.w[IX]); + SUBB; + I.regs.w[IY] += -2 * I.DF + 1; + I.regs.w[IX] += -2 * I.DF + 1; + CLK(6); +} +OP( 0xa7, i_cmpsw ) +{ + UINT32 src = GetMemW(ES, I.regs.w[IY]); + UINT32 dst = GetMemW(DS, I.regs.w[IX]); + SUBW; + I.regs.w[IY] += -4 * I.DF + 2; + I.regs.w[IX] += -4 * I.DF + 2; + CLK(6); } -OP( 0xc2, i_ret_d16 ) { UINT32 count = FETCH; count += FETCH << 8; POP(I.ip); I.regs.w[SP]+=count; CLK(6); } -OP( 0xc3, i_ret ) { POP(I.ip); CLK(6); } -OP( 0xc4, i_les_dw ) { GetModRM; WORD tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; I.sregs[ES] = GetnextRMWord; CLK(6); } -OP( 0xc5, i_lds_dw ) { GetModRM; WORD tmp = GetRMWord(ModRM); RegWord(ModRM)=tmp; I.sregs[DS] = GetnextRMWord; CLK(6); } -OP( 0xc6, i_mov_bd8 ) { GetModRM; PutImmRMByte(ModRM); CLK(1); } -OP( 0xc7, i_mov_wd16 ) { GetModRM; PutImmRMWord(ModRM); CLK(1); } - -OP( 0xc8, i_enter ) { - UINT32 nb = FETCH; - UINT32 i,level; - - CLK(19); - nb += FETCH << 8; - level = FETCH; - PUSH(I.regs.w[BP]); - I.regs.w[BP]=I.regs.w[SP]; - I.regs.w[SP] -= nb; - for (i=1;i0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x08: do { ROR_BYTE; c--; CLK(1); } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x10: do { ROLC_BYTE; c--; CLK(1); } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x18: do { RORC_BYTE; c--; CLK(1); } while (c>0); PutbackRMByte(ModRM,(BYTE)dst); break; - case 0x20: SHL_BYTE(c); I.AuxVal = 1; break; - case 0x28: SHR_BYTE(c); I.AuxVal = 1;break; - case 0x30: break; - case 0x38: SHRA_BYTE(c); break; - } +OP( 0xb8, i_mov_axd16 ) +{ + I.regs.b[AL] = FETCH; + I.regs.b[AH] = FETCH; + CLK(1); +} +OP( 0xb9, i_mov_cxd16 ) +{ + I.regs.b[CL] = FETCH; + I.regs.b[CH] = FETCH; + CLK(1); +} +OP( 0xba, i_mov_dxd16 ) +{ + I.regs.b[DL] = FETCH; + I.regs.b[DH] = FETCH; + CLK(1); +} +OP( 0xbb, i_mov_bxd16 ) +{ + I.regs.b[BL] = FETCH; + I.regs.b[BH] = FETCH; + CLK(1); +} +OP( 0xbc, i_mov_spd16 ) +{ + I.regs.b[SPL] = FETCH; + I.regs.b[SPH] = FETCH; + CLK(1); +} +OP( 0xbd, i_mov_bpd16 ) +{ + I.regs.b[BPL] = FETCH; + I.regs.b[BPH] = FETCH; + CLK(1); +} +OP( 0xbe, i_mov_sid16 ) +{ + I.regs.b[IXL] = FETCH; + I.regs.b[IXH] = FETCH; + CLK(1); +} +OP( 0xbf, i_mov_did16 ) +{ + I.regs.b[IYL] = FETCH; + I.regs.b[IYH] = FETCH; + CLK(1); } -OP( 0xd3, i_rotshft_wcl ) { - UINT32 src, dst; UINT8 c; GetModRM; src = (UINT32)GetRMWord(ModRM); dst=src; - c=I.regs.b[CL]; - c&=0x1f; - CLKM(5,3); - if (c) switch (ModRM & 0x38) { - case 0x00: do { ROL_WORD; c--; CLK(1); } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x08: do { ROR_WORD; c--; CLK(1); } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x10: do { ROLC_WORD; c--; CLK(1); } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x18: do { RORC_WORD; c--; CLK(1); } while (c>0); PutbackRMWord(ModRM,(WORD)dst); break; - case 0x20: SHL_WORD(c); I.AuxVal = 1; break; - case 0x28: SHR_WORD(c); I.AuxVal = 1; break; - case 0x30: break; - case 0x38: SHRA_WORD(c); break; - } +OP( 0xc0, i_rotshft_bd8 ) +{ + UINT32 src, dst; + UINT8 c; + GetModRM; + src = (uint32_t)GetRMByte(ModRM); + dst=src; + c=FETCH; + c&=0x1f; + CLKM(5,3); + + if (c) switch (ModRM & 0x38) + { + case 0x00: + do + { + ROL_BYTE; + c--; + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x08: + do + { + ROR_BYTE; + c--; + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x10: + do + { + ROLC_BYTE; + c--; + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x18: + do + { + RORC_BYTE; + c--; + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x20: + SHL_BYTE(c); + I.AuxVal = 1; + break;// + + case 0x28: + SHR_BYTE(c); + I.AuxVal = 1; + break;// + + case 0x30: + break; + + case 0x38: + SHRA_BYTE(c); + break; + } } -OP( 0xd4, i_aam ) { /*UINT32 mult=FETCH; mult=0;*/ I.regs.b[AH] = I.regs.b[AL] / 10; I.regs.b[AL] %= 10; SetSZPF_Word(I.regs.w[AW]); CLK(17); } -OP( 0xd5, i_aad ) { /*UINT32 mult=FETCH; mult=0;*/ I.regs.b[AL] = I.regs.b[AH] * 10 + I.regs.b[AL]; I.regs.b[AH] = 0; SetSZPF_Byte(I.regs.b[AL]); CLK(6); } -OP( 0xd6, i_setalc ) { I.regs.b[AL] = (CF)?0xff:0x00; CLK(3); } /* nop at V30MZ? */ -OP( 0xd7, i_trans ) { UINT32 dest = (I.regs.w[BW]+I.regs.b[AL])&0xffff; I.regs.b[AL] = GetMemB(DS, dest); CLK(5); } -OP( 0xd8, i_fpo ) { /*GetModRM;*/ CLK(3); } /* nop at V30MZ? */ +OP( 0xc1, i_rotshft_wd8 ) +{ + UINT32 src, dst; + UINT8 c; + GetModRM; + src = (uint32_t)GetRMWord(ModRM); + dst=src; + c=FETCH; + c&=0x1f; + CLKM(5,3); -OP( 0xe0, i_loopne ) { INT8 disp = (INT8)FETCH; I.regs.w[CW]--; if (!ZF && I.regs.w[CW]) { I.ip = (WORD)(I.ip+disp); CLK(6); } else CLK(3); } -OP( 0xe1, i_loope ) { INT8 disp = (INT8)FETCH; I.regs.w[CW]--; if ( ZF && I.regs.w[CW]) { I.ip = (WORD)(I.ip+disp); CLK(6); } else CLK(3); } -OP( 0xe2, i_loop ) { INT8 disp = (INT8)FETCH; I.regs.w[CW]--; if (I.regs.w[CW]) { I.ip = (WORD)(I.ip+disp); CLK(5); } else CLK(2); } -OP( 0xe3, i_jcxz ) { INT8 disp = (INT8)FETCH; if (I.regs.w[CW] == 0) { I.ip = (WORD)(I.ip+disp); CLK(4); } else CLK(1); } -OP( 0xe4, i_inal ) { UINT8 port = FETCH; I.regs.b[AL] = read_port(port); CLK(6); } -OP( 0xe5, i_inax ) { UINT8 port = FETCH; I.regs.b[AL] = read_port(port); I.regs.b[AH] = read_port(port+1); CLK(6); } -OP( 0xe6, i_outal ) { UINT8 port = FETCH; write_port(port, I.regs.b[AL]); CLK(6); } -OP( 0xe7, i_outax ) { UINT8 port = FETCH; write_port(port, I.regs.b[AL]); write_port(port+1, I.regs.b[AH]); CLK(6); } + if (c) switch (ModRM & 0x38) + { + case 0x00: + do + { + ROL_WORD; + c--; + } + while (c>0); -OP( 0xe8, i_call_d16 ) { UINT32 tmp; FETCHWORD(tmp); PUSH(I.ip); I.ip = (WORD)(I.ip+(INT16)tmp); CLK(5); } -OP( 0xe9, i_jmp_d16 ) { UINT32 tmp; FETCHWORD(tmp); I.ip = (WORD)(I.ip+(INT16)tmp); CLK(4); } -OP( 0xea, i_jmp_far ) { UINT32 tmp,tmp1; FETCHWORD(tmp); FETCHWORD(tmp1); I.sregs[CS] = (WORD)tmp1; I.ip = (WORD)tmp; CLK(7); } -OP( 0xeb, i_jmp_d8 ) { int tmp = (int)((INT8)FETCH); CLK(4); - if (tmp==-2 && no_interrupt==0 && nec_ICount>0) nec_ICount%=12; /* cycle skip */ - I.ip = (WORD)(I.ip+tmp); + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x08: + do + { + ROR_WORD; + c--; + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x10: + do + { + ROLC_WORD; + c--; + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x18: + do + { + RORC_WORD; + c--; + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x20: + SHL_WORD(c); + I.AuxVal = 1; + break; + + case 0x28: + SHR_WORD(c); + I.AuxVal = 1; + break; + + case 0x30: + break; + + case 0x38: + SHRA_WORD(c); + break; + } } -OP( 0xec, i_inaldx ) { I.regs.b[AL] = read_port(I.regs.w[DW]); CLK(6);} -OP( 0xed, i_inaxdx ) { UINT32 port = I.regs.w[DW]; I.regs.b[AL] = read_port(port); I.regs.b[AH] = read_port(port+1); CLK(6); } -OP( 0xee, i_outdxal ) { write_port(I.regs.w[DW], I.regs.b[AL]); CLK(6); } -OP( 0xef, i_outdxax ) { UINT32 port = I.regs.w[DW]; write_port(port, I.regs.b[AL]); write_port(port+1, I.regs.b[AH]); CLK(6); } -OP( 0xf0, i_lock ) { no_interrupt=1; CLK(1); } +OP( 0xc2, i_ret_d16 ) +{ + UINT32 count = FETCH; + count += FETCH << 8; + POP(I.ip); + I.regs.w[SP]+=count; + CLK(6); +} +OP( 0xc3, i_ret ) +{ + POP(I.ip); + CLK(6); +} +OP( 0xc4, i_les_dw ) +{ + GetModRM; + WORD tmp = GetRMWord(ModRM); + RegWord(ModRM)=tmp; + I.sregs[ES] = GetnextRMWord; + CLK(6); +} +OP( 0xc5, i_lds_dw ) +{ + GetModRM; + WORD tmp = GetRMWord(ModRM); + RegWord(ModRM)=tmp; + I.sregs[DS] = GetnextRMWord; + CLK(6); +} +OP( 0xc6, i_mov_bd8 ) +{ + GetModRM; + PutImmRMByte(ModRM); + CLK(1); +} +OP( 0xc7, i_mov_wd16 ) +{ + GetModRM; + PutImmRMWord(ModRM); + CLK(1); +} + +OP( 0xc8, i_enter ) +{ + UINT32 nb = FETCH; + UINT32 i,level; + + CLK(19); + nb += FETCH << 8; + level = FETCH; + PUSH(I.regs.w[BP]); + I.regs.w[BP]=I.regs.w[SP]; + I.regs.w[SP] -= nb; + + for (i=1; i0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x08: + do + { + ROR_BYTE; + c--; + CLK(1); + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x10: + do + { + ROLC_BYTE; + c--; + CLK(1); + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x18: + do + { + RORC_BYTE; + c--; + CLK(1); + } + while (c>0); + + PutbackRMByte(ModRM,(BYTE)dst); + break; + + case 0x20: + SHL_BYTE(c); + I.AuxVal = 1; + break; + + case 0x28: + SHR_BYTE(c); + I.AuxVal = 1; + break; + + case 0x30: + break; + + case 0x38: + SHRA_BYTE(c); + break; + } +} + +OP( 0xd3, i_rotshft_wcl ) +{ + UINT32 src, dst; + UINT8 c; + GetModRM; + src = (UINT32)GetRMWord(ModRM); + dst=src; + c=I.regs.b[CL]; + c&=0x1f; + CLKM(5,3); + + if (c) switch (ModRM & 0x38) + { + case 0x00: + do + { + ROL_WORD; + c--; + CLK(1); + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x08: + do + { + ROR_WORD; + c--; + CLK(1); + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x10: + do + { + ROLC_WORD; + c--; + CLK(1); + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x18: + do + { + RORC_WORD; + c--; + CLK(1); + } + while (c>0); + + PutbackRMWord(ModRM,(WORD)dst); + break; + + case 0x20: + SHL_WORD(c); + I.AuxVal = 1; + break; + + case 0x28: + SHR_WORD(c); + I.AuxVal = 1; + break; + + case 0x30: + break; + + case 0x38: + SHRA_WORD(c); + break; + } +} + +OP( 0xd4, i_aam ) +{ + /*UINT32 mult=FETCH; mult=0;*/ I.regs.b[AH] = I.regs.b[AL] / 10; + I.regs.b[AL] %= 10; + SetSZPF_Word(I.regs.w[AW]); + CLK(17); +} +OP( 0xd5, i_aad ) +{ + /*UINT32 mult=FETCH; mult=0;*/ I.regs.b[AL] = I.regs.b[AH] * 10 + I.regs.b[AL]; + I.regs.b[AH] = 0; + SetSZPF_Byte(I.regs.b[AL]); + CLK(6); +} +OP( 0xd6, i_setalc ) +{ + I.regs.b[AL] = (CF)?0xff:0x00; /* nop at V30MZ? */ + CLK(3); +} +OP( 0xd7, i_trans ) +{ + UINT32 dest = (I.regs.w[BW]+I.regs.b[AL])&0xffff; + I.regs.b[AL] = GetMemB(DS, dest); + CLK(5); +} +OP( 0xd8, i_fpo ) +{ + /*GetModRM;*/ CLK(3); /* nop at V30MZ? */ +} + +OP( 0xe0, i_loopne ) +{ + INT8 disp = (INT8)FETCH; + I.regs.w[CW]--; + + if (!ZF && I.regs.w[CW]) + { + I.ip = (WORD)(I.ip+disp); + CLK(6); + } + else + { + CLK(3); + } +} +OP( 0xe1, i_loope ) +{ + INT8 disp = (INT8)FETCH; + I.regs.w[CW]--; + + if ( ZF && I.regs.w[CW]) + { + I.ip = (WORD)(I.ip+disp); + CLK(6); + } + else + { + CLK(3); + } +} +OP( 0xe2, i_loop ) +{ + INT8 disp = (INT8)FETCH; + I.regs.w[CW]--; + + if (I.regs.w[CW]) + { + I.ip = (WORD)(I.ip+disp); + CLK(5); + } + else + { + CLK(2); + } +} +OP( 0xe3, i_jcxz ) +{ + INT8 disp = (INT8)FETCH; + + if (I.regs.w[CW] == 0) + { + I.ip = (WORD)(I.ip+disp); + CLK(4); + } + else + { + CLK(1); + } +} +OP( 0xe4, i_inal ) +{ + UINT8 port = FETCH; + I.regs.b[AL] = read_port(port); + CLK(6); +} +OP( 0xe5, i_inax ) +{ + UINT8 port = FETCH; + I.regs.b[AL] = read_port(port); + I.regs.b[AH] = read_port(port+1); + CLK(6); +} +OP( 0xe6, i_outal ) +{ + UINT8 port = FETCH; + write_port(port, I.regs.b[AL]); + CLK(6); +} +OP( 0xe7, i_outax ) +{ + UINT8 port = FETCH; + write_port(port, I.regs.b[AL]); + write_port(port+1, I.regs.b[AH]); + CLK(6); +} + +OP( 0xe8, i_call_d16 ) +{ + UINT32 tmp; + FETCHWORD(tmp); + PUSH(I.ip); + I.ip = (WORD)(I.ip+(INT16)tmp); + CLK(5); +} +OP( 0xe9, i_jmp_d16 ) +{ + UINT32 tmp; + FETCHWORD(tmp); + //printf("@ %04X -> %04X\n", I.ip-3, tmp); + I.ip = (WORD)(I.ip+(INT16)tmp); + CLK(4); +} +OP( 0xea, i_jmp_far ) +{ + UINT32 tmp,tmp1; + FETCHWORD(tmp); + FETCHWORD(tmp1); + I.sregs[CS] = (WORD)tmp1; + I.ip = (WORD)tmp; + CLK(7); +} +OP( 0xeb, i_jmp_d8 ) +{ + int tmp = (int)((INT8)FETCH); + CLK(4); + + if (tmp==-2 && no_interrupt==0 && nec_ICount>0) + { + nec_ICount%=12; /* cycle skip */ + } + + I.ip = (WORD)(I.ip+tmp); +} +OP( 0xec, i_inaldx ) +{ + I.regs.b[AL] = read_port(I.regs.w[DW]); + CLK(6); +} +OP( 0xed, i_inaxdx ) +{ + UINT32 port = I.regs.w[DW]; + I.regs.b[AL] = read_port(port); + I.regs.b[AH] = read_port(port+1); + CLK(6); +} +OP( 0xee, i_outdxal ) +{ + write_port(I.regs.w[DW], I.regs.b[AL]); + CLK(6); +} +OP( 0xef, i_outdxax ) +{ + UINT32 port = I.regs.w[DW]; + write_port(port, I.regs.b[AL]); + write_port(port+1, I.regs.b[AH]); + CLK(6); +} + +OP( 0xf0, i_lock ) +{ + no_interrupt=1; + CLK(1); +} #define THROUGH \ if(nec_ICount<0){ \ if(seg_prefix) \ @@ -730,124 +2968,788 @@ OP( 0xf0, i_lock ) { no_interrupt=1; CLK(1); } I.ip-=(UINT16)2; \ break;} -OP( 0xf2, i_repne ) { UINT32 next = FETCHOP; UINT16 c = I.regs.w[CW]; - switch(next) { /* Segments */ - case 0x26: seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; next = FETCHOP; CLK(2); break; - case 0x2e: seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; next = FETCHOP; CLK(2); break; - case 0x36: seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break; - case 0x3e: seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; next = FETCHOP; CLK(2); break; - } +OP( 0xf2, i_repne ) +{ + UINT32 next = FETCHOP; + UINT16 c = I.regs.w[CW]; - switch(next) { - case 0x6c: CLK(2); if (c) do { i_insb(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0x6d: CLK(2); if (c) do { i_insw(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0x6e: CLK(2); if (c) do { i_outsb(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0x6f: CLK(2); if (c) do { i_outsw(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xa4: CLK(2); if (c) do { i_movsb(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xa5: CLK(2); if (c) do { i_movsw(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xa6: CLK(5); if (c) do { THROUGH; i_cmpsb(); c--; CLK(3); } while (c>0 && ZF==0); I.regs.w[CW]=c; break; - case 0xa7: CLK(5); if (c) do { THROUGH; i_cmpsw(); c--; CLK(3); } while (c>0 && ZF==0); I.regs.w[CW]=c; break; - case 0xaa: CLK(2); if (c) do { i_stosb(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xab: CLK(2); if (c) do { i_stosw(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xac: CLK(2); if (c) do { i_lodsb(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xad: CLK(2); if (c) do { i_lodsw(); c--; } while (c>0); I.regs.w[CW]=c; break; - case 0xae: CLK(5); if (c) do { THROUGH; i_scasb(); c--; CLK(5); } while (c>0 && ZF==0); I.regs.w[CW]=c; break; - case 0xaf: CLK(5); if (c) do { THROUGH; i_scasw(); c--; CLK(5); } while (c>0 && ZF==0); I.regs.w[CW]=c; break; - default: nec_instruction[next](); - } - seg_prefix=FALSE; + switch(next) /* Segments */ + { + case 0x26: + seg_prefix=TRUE; + prefix_base=I.sregs[ES]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x2e: + seg_prefix=TRUE; + prefix_base=I.sregs[CS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x36: + seg_prefix=TRUE; + prefix_base=I.sregs[SS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x3e: + seg_prefix=TRUE; + prefix_base=I.sregs[DS]<<4; + next = FETCHOP; + CLK(2); + break; + } + + switch(next) + { + case 0x6c: + CLK(2); + + if (c) do + { + i_insb(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0x6d: + CLK(2); + + if (c) do + { + i_insw(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0x6e: + CLK(2); + + if (c) do + { + i_outsb(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0x6f: + CLK(2); + + if (c) do + { + i_outsw(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xa4: + CLK(2); + + if (c) do + { + i_movsb(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xa5: + CLK(2); + + if (c) do + { + i_movsw(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xa6: + CLK(5); + + if (c) do + { + THROUGH; + i_cmpsb(); + c--; + CLK(3); + } + while (c>0 && ZF==0); + + I.regs.w[CW]=c; + break; + + case 0xa7: + CLK(5); + + if (c) do + { + THROUGH; + i_cmpsw(); + c--; + CLK(3); + } + while (c>0 && ZF==0); + + I.regs.w[CW]=c; + break; + + case 0xaa: + CLK(2); + + if (c) do + { + i_stosb(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xab: + CLK(2); + + if (c) do + { + i_stosw(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xac: + CLK(2); + + if (c) do + { + i_lodsb(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xad: + CLK(2); + + if (c) do + { + i_lodsw(); + c--; + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xae: + CLK(5); + + if (c) do + { + THROUGH; + i_scasb(); + c--; + CLK(5); + } + while (c>0 && ZF==0); + + I.regs.w[CW]=c; + break; + + case 0xaf: + CLK(5); + + if (c) do + { + THROUGH; + i_scasw(); + c--; + CLK(5); + } + while (c>0 && ZF==0); + + I.regs.w[CW]=c; + break; + + default: + nec_instruction[next](); + } + + seg_prefix=FALSE; } -OP( 0xf3, i_repe ) { UINT32 next = FETCHOP; UINT16 c = I.regs.w[CW]; - switch(next) { /* Segments */ - case 0x26: seg_prefix=TRUE; prefix_base=I.sregs[ES]<<4; next = FETCHOP; CLK(2); break; - case 0x2e: seg_prefix=TRUE; prefix_base=I.sregs[CS]<<4; next = FETCHOP; CLK(2); break; - case 0x36: seg_prefix=TRUE; prefix_base=I.sregs[SS]<<4; next = FETCHOP; CLK(2); break; - case 0x3e: seg_prefix=TRUE; prefix_base=I.sregs[DS]<<4; next = FETCHOP; CLK(2); break; - } +OP( 0xf3, i_repe ) +{ + UINT32 next = FETCHOP; + UINT16 c = I.regs.w[CW]; - switch(next) { - case 0x6c: CLK(5); if (c) do { THROUGH; i_insb(); c--; CLK( 0); } while (c>0); I.regs.w[CW]=c; break; - case 0x6d: CLK(5); if (c) do { THROUGH; i_insw(); c--; CLK( 0); } while (c>0); I.regs.w[CW]=c; break; - case 0x6e: CLK(5); if (c) do { THROUGH; i_outsb(); c--; CLK(-1); } while (c>0); I.regs.w[CW]=c; break; - case 0x6f: CLK(5); if (c) do { THROUGH; i_outsw(); c--; CLK(-1); } while (c>0); I.regs.w[CW]=c; break; - case 0xa4: CLK(5); if (c) do { THROUGH; i_movsb(); c--; CLK( 2); } while (c>0); I.regs.w[CW]=c; break; - case 0xa5: CLK(5); if (c) do { THROUGH; i_movsw(); c--; CLK( 2); } while (c>0); I.regs.w[CW]=c; break; - case 0xa6: CLK(5); if (c) do { THROUGH; i_cmpsb(); c--; CLK( 4); } while (c>0 && ZF==1); I.regs.w[CW]=c; break; - case 0xa7: CLK(5); if (c) do { THROUGH; i_cmpsw(); c--; CLK( 4); } while (c>0 && ZF==1); I.regs.w[CW]=c; break; - case 0xaa: CLK(5); if (c) do { THROUGH; i_stosb(); c--; CLK( 3); } while (c>0); I.regs.w[CW]=c; break; - case 0xab: CLK(5); if (c) do { THROUGH; i_stosw(); c--; CLK( 3); } while (c>0); I.regs.w[CW]=c; break; - case 0xac: CLK(5); if (c) do { THROUGH; i_lodsb(); c--; CLK( 3); } while (c>0); I.regs.w[CW]=c; break; - case 0xad: CLK(5); if (c) do { THROUGH; i_lodsw(); c--; CLK( 3); } while (c>0); I.regs.w[CW]=c; break; - case 0xae: CLK(5); if (c) do { THROUGH; i_scasb(); c--; CLK( 4); } while (c>0 && ZF==1); I.regs.w[CW]=c; break; - case 0xaf: CLK(5); if (c) do { THROUGH; i_scasw(); c--; CLK( 4); } while (c>0 && ZF==1); I.regs.w[CW]=c; break; - default: nec_instruction[next](); - } - seg_prefix=FALSE; + switch(next) /* Segments */ + { + case 0x26: + seg_prefix=TRUE; + prefix_base=I.sregs[ES]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x2e: + seg_prefix=TRUE; + prefix_base=I.sregs[CS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x36: + seg_prefix=TRUE; + prefix_base=I.sregs[SS]<<4; + next = FETCHOP; + CLK(2); + break; + + case 0x3e: + seg_prefix=TRUE; + prefix_base=I.sregs[DS]<<4; + next = FETCHOP; + CLK(2); + break; + } + + switch(next) + { + case 0x6c: + CLK(5); + + if (c) do + { + THROUGH; + i_insb(); + c--; + CLK( 0); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0x6d: + CLK(5); + + if (c) do + { + THROUGH; + i_insw(); + c--; + CLK( 0); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0x6e: + CLK(5); + + if (c) do + { + THROUGH; + i_outsb(); + c--; + CLK(-1); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0x6f: + CLK(5); + + if (c) do + { + THROUGH; + i_outsw(); + c--; + CLK(-1); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xa4: + CLK(5); + + if (c) do + { + THROUGH; + i_movsb(); + c--; + CLK( 2); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xa5: + CLK(5); + + if (c) do + { + THROUGH; + i_movsw(); + c--; + CLK( 2); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xa6: + CLK(5); + + if (c) do + { + THROUGH; + i_cmpsb(); + c--; + CLK( 4); + } + while (c>0 && ZF==1); + + I.regs.w[CW]=c; + break; + + case 0xa7: + CLK(5); + + if (c) do + { + THROUGH; + i_cmpsw(); + c--; + CLK( 4); + } + while (c>0 && ZF==1); + + I.regs.w[CW]=c; + break; + + case 0xaa: + CLK(5); + + if (c) do + { + THROUGH; + i_stosb(); + c--; + CLK( 3); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xab: + CLK(5); + + if (c) do + { + THROUGH; + i_stosw(); + c--; + CLK( 3); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xac: + CLK(5); + + if (c) do + { + THROUGH; + i_lodsb(); + c--; + CLK( 3); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xad: + CLK(5); + + if (c) do + { + THROUGH; + i_lodsw(); + c--; + CLK( 3); + } + while (c>0); + + I.regs.w[CW]=c; + break; + + case 0xae: + CLK(5); + + if (c) do + { + THROUGH; + i_scasb(); + c--; + CLK( 4); + } + while (c>0 && ZF==1); + + I.regs.w[CW]=c; + break; + + case 0xaf: + CLK(5); + + if (c) do + { + THROUGH; + i_scasw(); + c--; + CLK( 4); + } + while (c>0 && ZF==1); + + I.regs.w[CW]=c; + break; + + default: + nec_instruction[next](); + } + + seg_prefix=FALSE; +} +OP( 0xf4, i_hlt ) +{ + //printf("Halted @ %04X:%04X...\n", I.sregs[CS], I.ip - 1); + nec_ICount=0; } -OP( 0xf4, i_hlt ) { nec_ICount=0; } -OP( 0xf5, i_cmc ) { I.CarryVal = !CF; CLK(4); } -OP( 0xf6, i_f6pre ) { UINT32 tmp; UINT32 uresult,uresult2; INT32 result,result2; - GetModRM; tmp = GetRMByte(ModRM); - switch (ModRM & 0x38) { - case 0x00: tmp &= FETCH; I.CarryVal = I.OverVal = I.AuxVal=0; SetSZPF_Byte(tmp); CLKM(2,1); break; /* TEST */ - case 0x08: break; - case 0x10: PutbackRMByte(ModRM,~tmp); CLKM(3,1); break; /* NOT */ - - case 0x18: I.CarryVal=(tmp!=0);tmp=(~tmp)+1; SetSZPF_Byte(tmp); PutbackRMByte(ModRM,tmp&0xff); CLKM(3,1); break; /* NEG */ - case 0x20: uresult = I.regs.b[AL]*tmp; I.regs.w[AW]=(WORD)uresult; I.CarryVal=I.OverVal=(I.regs.b[AH]!=0); CLKM(4,3); break; /* MULU */ - case 0x28: result = (INT16)((INT8)I.regs.b[AL])*(INT16)((INT8)tmp); I.regs.w[AW]=(WORD)result; I.CarryVal=I.OverVal=(I.regs.b[AH]!=0); CLKM(4,3); break; /* MUL */ - case 0x30: if (tmp) { DIVUB; } else nec_interrupt(0,0); CLKM(16,15); break; - case 0x38: if (tmp) { DIVB; } else nec_interrupt(0,0); CLKM(18,17); break; +OP( 0xf5, i_cmc ) +{ + I.CarryVal = !CF; + CLK(4); +} +OP( 0xf6, i_f6pre ) +{ + UINT32 tmp; + UINT32 uresult,uresult2; + INT32 result,result2; + GetModRM; + tmp = GetRMByte(ModRM); + + switch (ModRM & 0x38) + { + case 0x00: + tmp &= FETCH; + I.CarryVal = I.OverVal = I.AuxVal=0; + SetSZPF_Byte(tmp); + CLKM(2,1); + break; /* TEST */ + + case 0x08: + break; + + case 0x10: + PutbackRMByte(ModRM,~tmp); + CLKM(3,1); + break; /* NOT */ + + case 0x18: + I.CarryVal=(tmp!=0); + tmp=(~tmp)+1; + SetSZPF_Byte(tmp); + PutbackRMByte(ModRM,tmp&0xff); + CLKM(3,1); + break; /* NEG */ + + case 0x20: + uresult = I.regs.b[AL]*tmp; + I.regs.w[AW]=(WORD)uresult; + I.CarryVal=I.OverVal=(I.regs.b[AH]!=0); + CLKM(4,3); + break; /* MULU */ + + case 0x28: + result = (INT16)((INT8)I.regs.b[AL])*(INT16)((INT8)tmp); + I.regs.w[AW]=(WORD)result; + I.CarryVal=I.OverVal=(I.regs.b[AH]!=0); + CLKM(4,3); + break; /* MUL */ + + case 0x30: + if (tmp) + { + DIVUB; + } + else + { + nec_interrupt(0,0); + } + + CLKM(16,15); + break; + + case 0x38: + if (tmp) + { + DIVB; + } + else + { + nec_interrupt(0,0); + } + + CLKM(18,17); + break; } } -OP( 0xf7, i_f7pre ) { UINT32 tmp,tmp2; UINT32 uresult,uresult2; INT32 result,result2; - GetModRM; tmp = GetRMWord(ModRM); - switch (ModRM & 0x38) { - case 0x00: FETCHWORD(tmp2); tmp &= tmp2; I.CarryVal = I.OverVal = I.AuxVal=0; SetSZPF_Word(tmp); CLKM(2,1); break; /* TEST */ - case 0x08: break; - case 0x10: PutbackRMWord(ModRM,~tmp); CLKM(3,1); break; /* NOT */ - case 0x18: I.CarryVal=(tmp!=0); tmp=(~tmp)+1; SetSZPF_Word(tmp); PutbackRMWord(ModRM,tmp&0xffff); CLKM(3,1); break; /* NEG */ - case 0x20: uresult = I.regs.w[AW]*tmp; I.regs.w[AW]=uresult&0xffff; I.regs.w[DW]=((UINT32)uresult)>>16; I.CarryVal=I.OverVal=(I.regs.w[DW]!=0); CLKM(4,3); break; /* MULU */ - case 0x28: result = (INT32)((INT16)I.regs.w[AW])*(INT32)((INT16)tmp); I.regs.w[AW]=result&0xffff; I.regs.w[DW]=result>>16; I.CarryVal=I.OverVal=(I.regs.w[DW]!=0); CLKM(4,3); break; /* MUL */ - case 0x30: if (tmp) { DIVUW; } else nec_interrupt(0,0); CLKM(24,23); break; - case 0x38: if (tmp) { DIVW; } else nec_interrupt(0,0); CLKM(25,24); break; - } +OP( 0xf7, i_f7pre ) +{ + UINT32 tmp,tmp2; + UINT32 uresult,uresult2; + INT32 result,result2; + GetModRM; + tmp = GetRMWord(ModRM); + + switch (ModRM & 0x38) + { + case 0x00: + FETCHWORD(tmp2); + tmp &= tmp2; + I.CarryVal = I.OverVal = I.AuxVal=0; + SetSZPF_Word(tmp); + CLKM(2,1); + break; /* TEST */ + + case 0x08: + break; + + case 0x10: + PutbackRMWord(ModRM,~tmp); + CLKM(3,1); + break; /* NOT */ + + case 0x18: + I.CarryVal=(tmp!=0); + tmp=(~tmp)+1; + SetSZPF_Word(tmp); + PutbackRMWord(ModRM,tmp&0xffff); + CLKM(3,1); + break; /* NEG */ + + case 0x20: + uresult = I.regs.w[AW]*tmp; + I.regs.w[AW]=uresult&0xffff; + I.regs.w[DW]=((UINT32)uresult)>>16; + I.CarryVal=I.OverVal=(I.regs.w[DW]!=0); + CLKM(4,3); + break; /* MULU */ + + case 0x28: + result = (INT32)((INT16)I.regs.w[AW])*(INT32)((INT16)tmp); + I.regs.w[AW]=result&0xffff; + I.regs.w[DW]=result>>16; + I.CarryVal=I.OverVal=(I.regs.w[DW]!=0); + CLKM(4,3); + break; /* MUL */ + + case 0x30: + if (tmp) + { + DIVUW; + } + else + { + nec_interrupt(0,0); + } + + CLKM(24,23); + break; + + case 0x38: + if (tmp) + { + DIVW; + } + else + { + nec_interrupt(0,0); + } + + CLKM(25,24); + break; + } } -OP( 0xf8, i_clc ) { I.CarryVal = 0; CLK(4); } -OP( 0xf9, i_stc ) { I.CarryVal = 1; CLK(4); } -OP( 0xfa, i_di ) { SetIF(0); CLK(4); } -OP( 0xfb, i_ei ) { SetIF(1); CLK(4); } -OP( 0xfc, i_cld ) { SetDF(0); CLK(4); } -OP( 0xfd, i_std ) { SetDF(1); CLK(4); } -OP( 0xfe, i_fepre ) { UINT32 tmp, tmp1; GetModRM; tmp=GetRMByte(ModRM); - switch(ModRM & 0x38) { - case 0x00: tmp1 = tmp+1; I.OverVal = (tmp==0x7f); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(BYTE)tmp1); CLKM(3,1); break; /* INC */ - case 0x08: tmp1 = tmp-1; I.OverVal = (tmp==0x80); SetAF(tmp1,tmp,1); SetSZPF_Byte(tmp1); PutbackRMByte(ModRM,(BYTE)tmp1); CLKM(3,1); break; /* DEC */ - } +OP( 0xf8, i_clc ) +{ + I.CarryVal = 0; + CLK(4); } -OP( 0xff, i_ffpre ) { UINT32 tmp, tmp1; GetModRM; tmp=GetRMWord(ModRM); - switch(ModRM & 0x38) { - case 0x00: tmp1 = tmp+1; I.OverVal = (tmp==0x7fff); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(WORD)tmp1); CLKM(3,1); break; /* INC */ - case 0x08: tmp1 = tmp-1; I.OverVal = (tmp==0x8000); SetAF(tmp1,tmp,1); SetSZPF_Word(tmp1); PutbackRMWord(ModRM,(WORD)tmp1); CLKM(3,1); break; /* DEC */ - case 0x10: PUSH(I.ip); I.ip = (WORD)tmp; CLKM(6,5); break; /* CALL */ - case 0x18: tmp1 = I.sregs[CS]; I.sregs[CS] = GetnextRMWord; PUSH(tmp1); PUSH(I.ip); I.ip = tmp; CLKM(12,1); break; /* CALL FAR */ - case 0x20: I.ip = tmp; CLKM(5,4); break; /* JMP */ - case 0x28: I.ip = tmp; I.sregs[CS] = GetnextRMWord; CLKM(10,1); break; /* JMP FAR */ - case 0x30: PUSH(tmp); CLKM(2,1); break; - default: ; - } +OP( 0xf9, i_stc ) +{ + I.CarryVal = 1; + CLK(4); +} +OP( 0xfa, i_di ) +{ + SetIF(0); + CLK(4); +} +OP( 0xfb, i_ei ) +{ + SetIF(1); + CLK(4); +} +OP( 0xfc, i_cld ) +{ + SetDF(0); + CLK(4); +} +OP( 0xfd, i_std ) +{ + SetDF(1); + CLK(4); +} +OP( 0xfe, i_fepre ) +{ + UINT32 tmp, tmp1; + GetModRM; + tmp=GetRMByte(ModRM); + + switch(ModRM & 0x38) + { + case 0x00: + tmp1 = tmp+1; + I.OverVal = (tmp==0x7f); + SetAF(tmp1,tmp,1); + SetSZPF_Byte(tmp1); + PutbackRMByte(ModRM,(BYTE)tmp1); + CLKM(3,1); + break; /* INC */ + + case 0x08: + tmp1 = tmp-1; + I.OverVal = (tmp==0x80); + SetAF(tmp1,tmp,1); + SetSZPF_Byte(tmp1); + PutbackRMByte(ModRM,(BYTE)tmp1); + CLKM(3,1); + break; /* DEC */ + } +} +OP( 0xff, i_ffpre ) +{ + UINT32 tmp, tmp1; + GetModRM; + tmp=GetRMWord(ModRM); + + switch(ModRM & 0x38) + { + case 0x00: + tmp1 = tmp+1; + I.OverVal = (tmp==0x7fff); + SetAF(tmp1,tmp,1); + SetSZPF_Word(tmp1); + PutbackRMWord(ModRM,(WORD)tmp1); + CLKM(3,1); + break; /* INC */ + + case 0x08: + tmp1 = tmp-1; + I.OverVal = (tmp==0x8000); + SetAF(tmp1,tmp,1); + SetSZPF_Word(tmp1); + PutbackRMWord(ModRM,(WORD)tmp1); + CLKM(3,1); + break; /* DEC */ + + case 0x10: + PUSH(I.ip); + I.ip = (WORD)tmp; + CLKM(6,5); + break; /* CALL */ + + case 0x18: + tmp1 = I.sregs[CS]; + I.sregs[CS] = GetnextRMWord; + PUSH(tmp1); + PUSH(I.ip); + I.ip = tmp; + CLKM(12,1); + break; /* CALL FAR */ + + case 0x20: + //printf("@ %04X -> %04X\n", I.ip, tmp); + I.ip = tmp; + CLKM(5,4); + break; /* JMP */ + + case 0x28: + I.ip = tmp; + I.sregs[CS] = GetnextRMWord; + + //printf("New CS: %04X, New IP: %04X\n", I.sregs[CS], I.ip); + + CLKM(10,1); + break; /* JMP FAR */ + + case 0x30: + PUSH(tmp); + CLKM(2,1); + break; + + default: + ; + } } static void i_invalid(void) { - CLK(10); + CLK(10); } /*****************************************************************************/ @@ -855,68 +3757,149 @@ static void i_invalid(void) uint32_t nec_get_reg(int regnum) { - switch( regnum ) - { - case NEC_IP: return I.ip; - case NEC_SP: return I.regs.w[SP]; - case NEC_FLAGS: return CompressFlags(); - case NEC_AW: return I.regs.w[AW]; - case NEC_CW: return I.regs.w[CW]; - case NEC_DW: return I.regs.w[DW]; - case NEC_BW: return I.regs.w[BW]; - case NEC_BP: return I.regs.w[BP]; - case NEC_IX: return I.regs.w[IX]; - case NEC_IY: return I.regs.w[IY]; - case NEC_ES: return I.sregs[ES]; - case NEC_CS: return I.sregs[CS]; - case NEC_SS: return I.sregs[SS]; - case NEC_DS: return I.sregs[DS]; - case NEC_VECTOR: return I.int_vector; - case NEC_PENDING: return I.pending_irq; - case NEC_NMI_STATE: return I.nmi_state; - case NEC_IRQ_STATE: return I.irq_state; - } - return 0; + switch( regnum ) + { + case NEC_IP: + return I.ip; + + case NEC_SP: + return I.regs.w[SP]; + + case NEC_FLAGS: + return CompressFlags(); + + case NEC_AW: + return I.regs.w[AW]; + + case NEC_CW: + return I.regs.w[CW]; + + case NEC_DW: + return I.regs.w[DW]; + + case NEC_BW: + return I.regs.w[BW]; + + case NEC_BP: + return I.regs.w[BP]; + + case NEC_IX: + return I.regs.w[IX]; + + case NEC_IY: + return I.regs.w[IY]; + + case NEC_ES: + return I.sregs[ES]; + + case NEC_CS: + return I.sregs[CS]; + + case NEC_SS: + return I.sregs[SS]; + + case NEC_DS: + return I.sregs[DS]; + + case NEC_VECTOR: + return I.int_vector; + + case NEC_PENDING: + return I.pending_irq; + + case NEC_NMI_STATE: + return I.nmi_state; + + case NEC_IRQ_STATE: + return I.irq_state; + } + + return 0; } void nec_set_irq_line(int irqline, int state); void nec_set_reg(int regnum, uint32_t val) { - switch( regnum ) - { - case NEC_IP: I.ip = val; break; - case NEC_SP: I.regs.w[SP] = val; break; - case NEC_FLAGS: ExpandFlags(val); break; - case NEC_AW: I.regs.w[AW] = val; break; - case NEC_CW: I.regs.w[CW] = val; break; - case NEC_DW: I.regs.w[DW] = val; break; - case NEC_BW: I.regs.w[BW] = val; break; - case NEC_BP: I.regs.w[BP] = val; break; - case NEC_IX: I.regs.w[IX] = val; break; - case NEC_IY: I.regs.w[IY] = val; break; - case NEC_ES: I.sregs[ES] = val; break; - case NEC_CS: I.sregs[CS] = val; break; - case NEC_SS: I.sregs[SS] = val; break; - case NEC_DS: I.sregs[DS] = val; break; - case NEC_VECTOR: I.int_vector = val; break; - } + switch( regnum ) + { + case NEC_IP: + I.ip = val; + break; + + case NEC_SP: + I.regs.w[SP] = val; + break; + + case NEC_FLAGS: + ExpandFlags(val); + break; + + case NEC_AW: + I.regs.w[AW] = val; + break; + + case NEC_CW: + I.regs.w[CW] = val; + break; + + case NEC_DW: + I.regs.w[DW] = val; + break; + + case NEC_BW: + I.regs.w[BW] = val; + break; + + case NEC_BP: + I.regs.w[BP] = val; + break; + + case NEC_IX: + I.regs.w[IX] = val; + break; + + case NEC_IY: + I.regs.w[IY] = val; + break; + + case NEC_ES: + I.sregs[ES] = val; + break; + + case NEC_CS: + I.sregs[CS] = val; + break; + + case NEC_SS: + I.sregs[SS] = val; + break; + + case NEC_DS: + I.sregs[DS] = val; + break; + + case NEC_VECTOR: + I.int_vector = val; + break; + } } int nec_execute(int cycles) { - - nec_ICount=cycles; + + nec_ICount=cycles; // cpu_type=V30; - while(nec_ICount>0) { + while(nec_ICount>0) + { - nec_instruction[FETCHOP](); + nec_instruction[FETCHOP](); // nec_ICount++; - } + } - return cycles - nec_ICount; + return cycles - nec_ICount; } diff --git a/oswan/source/nec/nec.h b/oswan/source/nec/nec.h index 5ab8ef6..7a8b1b1 100644 --- a/oswan/source/nec/nec.h +++ b/oswan/source/nec/nec.h @@ -1,9 +1,9 @@ BYTE cpu_readport(BYTE); void cpu_writeport(DWORD,BYTE); -#define cpu_readop cpu_readmem20 -#define cpu_readop_arg cpu_readmem20 +#define cpu_readop cpu_readmem20 +#define cpu_readop_arg cpu_readmem20 void cpu_writemem20(DWORD,BYTE); -BYTE cpu_readmem20(DWORD); +BYTE cpu_readmem20(DWORD); typedef enum { ES, CS, SS, DS } SREGS; typedef enum { AW, CW, DW, BW, SP, BP, IX, IY } WREGS; @@ -11,25 +11,26 @@ typedef enum { AL,AH,CL,CH,DL,DH,BL,BH,SPL,SPH,BPL,BPH,IXL,IXH,IYL,IYH } BREGS; #pragma pack(1) typedef union -{ /* eight general registers */ - UINT16 w[8]; /* viewed as 16 bits registers */ - UINT8 b[16]; /* or as 8 bit registers */ +{ + /* eight general registers */ + UINT16 w[8]; /* viewed as 16 bits registers */ + UINT8 b[16]; /* or as 8 bit registers */ } necbasicregs; typedef struct { - necbasicregs regs; - UINT16 sregs[4]; + necbasicregs regs; + UINT16 sregs[4]; - UINT16 ip; + UINT16 ip; - INT32 SignVal; - INT32 AuxVal, OverVal, ZeroVal, CarryVal, ParityVal; /* 0 or non-0 valued flags */ - UINT8 TF, IF, DF, MF; /* 0 or 1 valued flags */ /* OB[19.07.99] added Mode Flag V30 */ - UINT32 int_vector; - UINT32 pending_irq; - UINT32 nmi_state; - UINT32 irq_state; - int (*irq_callback)(int irqline); + INT32 SignVal; + INT32 AuxVal, OverVal, ZeroVal, CarryVal, ParityVal; /* 0 or non-0 valued flags */ + UINT8 TF, IF, DF, MF; /* 0 or 1 valued flags */ /* OB[19.07.99] added Mode Flag V30 */ + UINT32 int_vector; + UINT32 pending_irq; + UINT32 nmi_state; + UINT32 irq_state; + int (*irq_callback)(int irqline); } nec_Regs; #pragma pack() diff --git a/oswan/source/nec/necea.h b/oswan/source/nec/necea.h index 12fb93f..c86511a 100644 --- a/oswan/source/nec/necea.h +++ b/oswan/source/nec/necea.h @@ -3,58 +3,196 @@ static UINT32 EA; static UINT16 EO; static UINT16 E16; -static unsigned EA_000(void) { EO=I.regs.w[BW]+I.regs.w[IX]; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_001(void) { EO=I.regs.w[BW]+I.regs.w[IY]; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_002(void) { EO=I.regs.w[BP]+I.regs.w[IX]; EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_003(void) { EO=I.regs.w[BP]+I.regs.w[IY]; EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_004(void) { EO=I.regs.w[IX]; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_005(void) { EO=I.regs.w[IY]; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_006(void) { EO=FETCH; EO+=FETCH<<8; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_007(void) { EO=I.regs.w[BW]; EA=DefaultBase(DS)+EO; return EA; } +static unsigned EA_000(void) +{ + EO=I.regs.w[BW]+I.regs.w[IX]; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_001(void) +{ + EO=I.regs.w[BW]+I.regs.w[IY]; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_002(void) +{ + EO=I.regs.w[BP]+I.regs.w[IX]; + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_003(void) +{ + EO=I.regs.w[BP]+I.regs.w[IY]; + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_004(void) +{ + EO=I.regs.w[IX]; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_005(void) +{ + EO=I.regs.w[IY]; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_006(void) +{ + EO=FETCH; + EO+=FETCH<<8; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_007(void) +{ + EO=I.regs.w[BW]; + EA=DefaultBase(DS)+EO; + return EA; +} -static unsigned EA_100(void) { EO=(I.regs.w[BW]+I.regs.w[IX]+(INT8)FETCH); EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_101(void) { EO=(I.regs.w[BW]+I.regs.w[IY]+(INT8)FETCH); EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_102(void) { EO=(I.regs.w[BP]+I.regs.w[IX]+(INT8)FETCH); EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_103(void) { EO=(I.regs.w[BP]+I.regs.w[IY]+(INT8)FETCH); EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_104(void) { EO=(I.regs.w[IX]+(INT8)FETCH); EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_105(void) { EO=(I.regs.w[IY]+(INT8)FETCH); EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_106(void) { EO=(I.regs.w[BP]+(INT8)FETCH); EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_107(void) { EO=(I.regs.w[BW]+(INT8)FETCH); EA=DefaultBase(DS)+EO; return EA; } +static unsigned EA_100(void) +{ + EO=(I.regs.w[BW]+I.regs.w[IX]+(INT8)FETCH); + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_101(void) +{ + EO=(I.regs.w[BW]+I.regs.w[IY]+(INT8)FETCH); + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_102(void) +{ + EO=(I.regs.w[BP]+I.regs.w[IX]+(INT8)FETCH); + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_103(void) +{ + EO=(I.regs.w[BP]+I.regs.w[IY]+(INT8)FETCH); + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_104(void) +{ + EO=(I.regs.w[IX]+(INT8)FETCH); + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_105(void) +{ + EO=(I.regs.w[IY]+(INT8)FETCH); + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_106(void) +{ + EO=(I.regs.w[BP]+(INT8)FETCH); + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_107(void) +{ + EO=(I.regs.w[BW]+(INT8)FETCH); + EA=DefaultBase(DS)+EO; + return EA; +} -static unsigned EA_200(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BW]+I.regs.w[IX]+(INT16)E16; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_201(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BW]+I.regs.w[IY]+(INT16)E16; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_202(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BP]+I.regs.w[IX]+(INT16)E16; EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_203(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BP]+I.regs.w[IY]+(INT16)E16; EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_204(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[IX]+(INT16)E16; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_205(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[IY]+(INT16)E16; EA=DefaultBase(DS)+EO; return EA; } -static unsigned EA_206(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BP]+(INT16)E16; EA=DefaultBase(SS)+EO; return EA; } -static unsigned EA_207(void) { E16=FETCH; E16+=FETCH<<8; EO=I.regs.w[BW]+(INT16)E16; EA=DefaultBase(DS)+EO; return EA; } +static unsigned EA_200(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[BW]+I.regs.w[IX]+(INT16)E16; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_201(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[BW]+I.regs.w[IY]+(INT16)E16; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_202(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[BP]+I.regs.w[IX]+(INT16)E16; + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_203(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[BP]+I.regs.w[IY]+(INT16)E16; + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_204(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[IX]+(INT16)E16; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_205(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[IY]+(INT16)E16; + EA=DefaultBase(DS)+EO; + return EA; +} +static unsigned EA_206(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[BP]+(INT16)E16; + EA=DefaultBase(SS)+EO; + return EA; +} +static unsigned EA_207(void) +{ + E16=FETCH; + E16+=FETCH<<8; + EO=I.regs.w[BW]+(INT16)E16; + EA=DefaultBase(DS)+EO; + return EA; +} -static unsigned (*GetEA[192])(void)={ - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, +static unsigned (*GetEA[192])(void)= +{ + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, + EA_000, EA_001, EA_002, EA_003, EA_004, EA_005, EA_006, EA_007, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, + EA_100, EA_101, EA_102, EA_103, EA_104, EA_105, EA_106, EA_107, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, - EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207 + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207, + EA_200, EA_201, EA_202, EA_203, EA_204, EA_205, EA_206, EA_207 }; diff --git a/oswan/source/nec/necinstr.h b/oswan/source/nec/necinstr.h index 7a7e31e..5bf6205 100644 --- a/oswan/source/nec/necinstr.h +++ b/oswan/source/nec/necinstr.h @@ -248,260 +248,260 @@ static void i_wait(void); void (*nec_instruction[256])(void) = { - i_add_br8, /* 0x00 */ - i_add_wr16, /* 0x01 */ - i_add_r8b, /* 0x02 */ - i_add_r16w, /* 0x03 */ - i_add_ald8, /* 0x04 */ - i_add_axd16, /* 0x05 */ - i_push_es, /* 0x06 */ - i_pop_es, /* 0x07 */ - i_or_br8, /* 0x08 */ - i_or_wr16, /* 0x09 */ - i_or_r8b, /* 0x0a */ - i_or_r16w, /* 0x0b */ - i_or_ald8, /* 0x0c */ - i_or_axd16, /* 0x0d */ - i_push_cs, /* 0x0e */ - i_pre_nec /* 0x0f */, - i_adc_br8, /* 0x10 */ - i_adc_wr16, /* 0x11 */ - i_adc_r8b, /* 0x12 */ - i_adc_r16w, /* 0x13 */ - i_adc_ald8, /* 0x14 */ - i_adc_axd16, /* 0x15 */ - i_push_ss, /* 0x16 */ - i_pop_ss, /* 0x17 */ - i_sbb_br8, /* 0x18 */ - i_sbb_wr16, /* 0x19 */ - i_sbb_r8b, /* 0x1a */ - i_sbb_r16w, /* 0x1b */ - i_sbb_ald8, /* 0x1c */ - i_sbb_axd16, /* 0x1d */ - i_push_ds, /* 0x1e */ - i_pop_ds, /* 0x1f */ - i_and_br8, /* 0x20 */ - i_and_wr16, /* 0x21 */ - i_and_r8b, /* 0x22 */ - i_and_r16w, /* 0x23 */ - i_and_ald8, /* 0x24 */ - i_and_axd16, /* 0x25 */ - i_es, /* 0x26 */ - i_daa, /* 0x27 */ - i_sub_br8, /* 0x28 */ - i_sub_wr16, /* 0x29 */ - i_sub_r8b, /* 0x2a */ - i_sub_r16w, /* 0x2b */ - i_sub_ald8, /* 0x2c */ - i_sub_axd16, /* 0x2d */ - i_cs, /* 0x2e */ - i_das, /* 0x2f */ - i_xor_br8, /* 0x30 */ - i_xor_wr16, /* 0x31 */ - i_xor_r8b, /* 0x32 */ - i_xor_r16w, /* 0x33 */ - i_xor_ald8, /* 0x34 */ - i_xor_axd16, /* 0x35 */ - i_ss, /* 0x36 */ - i_aaa, /* 0x37 */ - i_cmp_br8, /* 0x38 */ - i_cmp_wr16, /* 0x39 */ - i_cmp_r8b, /* 0x3a */ - i_cmp_r16w, /* 0x3b */ - i_cmp_ald8, /* 0x3c */ - i_cmp_axd16, /* 0x3d */ - i_ds, /* 0x3e */ - i_aas, /* 0x3f */ - i_inc_ax, /* 0x40 */ - i_inc_cx, /* 0x41 */ - i_inc_dx, /* 0x42 */ - i_inc_bx, /* 0x43 */ - i_inc_sp, /* 0x44 */ - i_inc_bp, /* 0x45 */ - i_inc_si, /* 0x46 */ - i_inc_di, /* 0x47 */ - i_dec_ax, /* 0x48 */ - i_dec_cx, /* 0x49 */ - i_dec_dx, /* 0x4a */ - i_dec_bx, /* 0x4b */ - i_dec_sp, /* 0x4c */ - i_dec_bp, /* 0x4d */ - i_dec_si, /* 0x4e */ - i_dec_di, /* 0x4f */ - i_push_ax, /* 0x50 */ - i_push_cx, /* 0x51 */ - i_push_dx, /* 0x52 */ - i_push_bx, /* 0x53 */ - i_push_sp, /* 0x54 */ - i_push_bp, /* 0x55 */ - i_push_si, /* 0x56 */ - i_push_di, /* 0x57 */ - i_pop_ax, /* 0x58 */ - i_pop_cx, /* 0x59 */ - i_pop_dx, /* 0x5a */ - i_pop_bx, /* 0x5b */ - i_pop_sp, /* 0x5c */ - i_pop_bp, /* 0x5d */ - i_pop_si, /* 0x5e */ - i_pop_di, /* 0x5f */ - i_pusha, /* 0x60 */ - i_popa, /* 0x61 */ - i_chkind, /* 0x62 */ - i_invalid, /* 0x63 */ - i_repnc, /* 0x64 */ - i_repc, /* 0x65 */ - i_invalid, /* 0x66 */ - i_invalid, /* 0x67 */ - i_push_d16, /* 0x68 */ - i_imul_d16, /* 0x69 */ - i_push_d8, /* 0x6a */ - i_imul_d8, /* 0x6b */ - i_insb, /* 0x6c */ - i_insw, /* 0x6d */ - i_outsb, /* 0x6e */ - i_outsw, /* 0x6f */ - i_jo, /* 0x70 */ - i_jno, /* 0x71 */ - i_jc, /* 0x72 */ - i_jnc, /* 0x73 */ - i_jz, /* 0x74 */ - i_jnz, /* 0x75 */ - i_jce, /* 0x76 */ - i_jnce, /* 0x77 */ - i_js, /* 0x78 */ - i_jns, /* 0x79 */ - i_jp, /* 0x7a */ - i_jnp, /* 0x7b */ - i_jl, /* 0x7c */ - i_jnl, /* 0x7d */ - i_jle, /* 0x7e */ - i_jnle, /* 0x7f */ - i_80pre, /* 0x80 */ - i_81pre, /* 0x81 */ - i_82pre, /* 0x82 */ - i_83pre, /* 0x83 */ - i_test_br8, /* 0x84 */ - i_test_wr16, /* 0x85 */ - i_xchg_br8, /* 0x86 */ - i_xchg_wr16, /* 0x87 */ - i_mov_br8, /* 0x88 */ - i_mov_wr16, /* 0x89 */ - i_mov_r8b, /* 0x8a */ - i_mov_r16w, /* 0x8b */ - i_mov_wsreg, /* 0x8c */ - i_lea, /* 0x8d */ - i_mov_sregw, /* 0x8e */ - i_popw, /* 0x8f */ - i_nop, /* 0x90 */ - i_xchg_axcx, /* 0x91 */ - i_xchg_axdx, /* 0x92 */ - i_xchg_axbx, /* 0x93 */ - i_xchg_axsp, /* 0x94 */ - i_xchg_axbp, /* 0x95 */ - i_xchg_axsi, /* 0x97 */ - i_xchg_axdi, /* 0x97 */ - i_cbw, /* 0x98 */ - i_cwd, /* 0x99 */ - i_call_far, /* 0x9a */ - i_wait, /* 0x9b */ - i_pushf, /* 0x9c */ - i_popf, /* 0x9d */ - i_sahf, /* 0x9e */ - i_lahf, /* 0x9f */ - i_mov_aldisp, /* 0xa0 */ - i_mov_axdisp, /* 0xa1 */ - i_mov_dispal, /* 0xa2 */ - i_mov_dispax, /* 0xa3 */ - i_movsb, /* 0xa4 */ - i_movsw, /* 0xa5 */ - i_cmpsb, /* 0xa6 */ - i_cmpsw, /* 0xa7 */ - i_test_ald8, /* 0xa8 */ - i_test_axd16, /* 0xa9 */ - i_stosb, /* 0xaa */ - i_stosw, /* 0xab */ - i_lodsb, /* 0xac */ - i_lodsw, /* 0xad */ - i_scasb, /* 0xae */ - i_scasw, /* 0xaf */ - i_mov_ald8, /* 0xb0 */ - i_mov_cld8, /* 0xb1 */ - i_mov_dld8, /* 0xb2 */ - i_mov_bld8, /* 0xb3 */ - i_mov_ahd8, /* 0xb4 */ - i_mov_chd8, /* 0xb5 */ - i_mov_dhd8, /* 0xb6 */ - i_mov_bhd8, /* 0xb7 */ - i_mov_axd16, /* 0xb8 */ - i_mov_cxd16, /* 0xb9 */ - i_mov_dxd16, /* 0xba */ - i_mov_bxd16, /* 0xbb */ - i_mov_spd16, /* 0xbc */ - i_mov_bpd16, /* 0xbd */ - i_mov_sid16, /* 0xbe */ - i_mov_did16, /* 0xbf */ - i_rotshft_bd8, /* 0xc0 */ - i_rotshft_wd8, /* 0xc1 */ - i_ret_d16, /* 0xc2 */ - i_ret, /* 0xc3 */ - i_les_dw, /* 0xc4 */ - i_lds_dw, /* 0xc5 */ - i_mov_bd8, /* 0xc6 */ - i_mov_wd16, /* 0xc7 */ - i_enter, /* 0xc8 */ - i_leave, /* 0xc9 */ - i_retf_d16, /* 0xca */ - i_retf, /* 0xcb */ - i_int3, /* 0xcc */ - i_int, /* 0xcd */ - i_into, /* 0xce */ - i_iret, /* 0xcf */ - i_rotshft_b, /* 0xd0 */ - i_rotshft_w, /* 0xd1 */ - i_rotshft_bcl, /* 0xd2 */ - i_rotshft_wcl, /* 0xd3 */ - i_aam, /* 0xd4 */ - i_aad, /* 0xd5 */ - i_setalc, - i_trans, /* 0xd7 */ - i_fpo, /* 0xd8 */ - i_fpo, /* 0xd9 */ - i_fpo, /* 0xda */ - i_fpo, /* 0xdb */ - i_fpo, /* 0xdc */ - i_fpo, /* 0xdd */ - i_fpo, /* 0xde */ - i_fpo, /* 0xdf */ - i_loopne, /* 0xe0 */ - i_loope, /* 0xe1 */ - i_loop, /* 0xe2 */ - i_jcxz, /* 0xe3 */ - i_inal, /* 0xe4 */ - i_inax, /* 0xe5 */ - i_outal, /* 0xe6 */ - i_outax, /* 0xe7 */ - i_call_d16, /* 0xe8 */ - i_jmp_d16, /* 0xe9 */ - i_jmp_far, /* 0xea */ - i_jmp_d8, /* 0xeb */ - i_inaldx, /* 0xec */ - i_inaxdx, /* 0xed */ - i_outdxal, /* 0xee */ - i_outdxax, /* 0xef */ - i_lock, /* 0xf0 */ - i_invalid, /* 0xf1 */ - i_repne, /* 0xf2 */ - i_repe, /* 0xf3 */ - i_hlt, /* 0xf4 */ - i_cmc, /* 0xf5 */ - i_f6pre, /* 0xf6 */ - i_f7pre, /* 0xf7 */ - i_clc, /* 0xf8 */ - i_stc, /* 0xf9 */ - i_di, /* 0xfa */ - i_ei, /* 0xfb */ - i_cld, /* 0xfc */ - i_std, /* 0xfd */ - i_fepre, /* 0xfe */ - i_ffpre /* 0xff */ + i_add_br8, /* 0x00 */ + i_add_wr16, /* 0x01 */ + i_add_r8b, /* 0x02 */ + i_add_r16w, /* 0x03 */ + i_add_ald8, /* 0x04 */ + i_add_axd16, /* 0x05 */ + i_push_es, /* 0x06 */ + i_pop_es, /* 0x07 */ + i_or_br8, /* 0x08 */ + i_or_wr16, /* 0x09 */ + i_or_r8b, /* 0x0a */ + i_or_r16w, /* 0x0b */ + i_or_ald8, /* 0x0c */ + i_or_axd16, /* 0x0d */ + i_push_cs, /* 0x0e */ + i_pre_nec /* 0x0f */, + i_adc_br8, /* 0x10 */ + i_adc_wr16, /* 0x11 */ + i_adc_r8b, /* 0x12 */ + i_adc_r16w, /* 0x13 */ + i_adc_ald8, /* 0x14 */ + i_adc_axd16, /* 0x15 */ + i_push_ss, /* 0x16 */ + i_pop_ss, /* 0x17 */ + i_sbb_br8, /* 0x18 */ + i_sbb_wr16, /* 0x19 */ + i_sbb_r8b, /* 0x1a */ + i_sbb_r16w, /* 0x1b */ + i_sbb_ald8, /* 0x1c */ + i_sbb_axd16, /* 0x1d */ + i_push_ds, /* 0x1e */ + i_pop_ds, /* 0x1f */ + i_and_br8, /* 0x20 */ + i_and_wr16, /* 0x21 */ + i_and_r8b, /* 0x22 */ + i_and_r16w, /* 0x23 */ + i_and_ald8, /* 0x24 */ + i_and_axd16, /* 0x25 */ + i_es, /* 0x26 */ + i_daa, /* 0x27 */ + i_sub_br8, /* 0x28 */ + i_sub_wr16, /* 0x29 */ + i_sub_r8b, /* 0x2a */ + i_sub_r16w, /* 0x2b */ + i_sub_ald8, /* 0x2c */ + i_sub_axd16, /* 0x2d */ + i_cs, /* 0x2e */ + i_das, /* 0x2f */ + i_xor_br8, /* 0x30 */ + i_xor_wr16, /* 0x31 */ + i_xor_r8b, /* 0x32 */ + i_xor_r16w, /* 0x33 */ + i_xor_ald8, /* 0x34 */ + i_xor_axd16, /* 0x35 */ + i_ss, /* 0x36 */ + i_aaa, /* 0x37 */ + i_cmp_br8, /* 0x38 */ + i_cmp_wr16, /* 0x39 */ + i_cmp_r8b, /* 0x3a */ + i_cmp_r16w, /* 0x3b */ + i_cmp_ald8, /* 0x3c */ + i_cmp_axd16, /* 0x3d */ + i_ds, /* 0x3e */ + i_aas, /* 0x3f */ + i_inc_ax, /* 0x40 */ + i_inc_cx, /* 0x41 */ + i_inc_dx, /* 0x42 */ + i_inc_bx, /* 0x43 */ + i_inc_sp, /* 0x44 */ + i_inc_bp, /* 0x45 */ + i_inc_si, /* 0x46 */ + i_inc_di, /* 0x47 */ + i_dec_ax, /* 0x48 */ + i_dec_cx, /* 0x49 */ + i_dec_dx, /* 0x4a */ + i_dec_bx, /* 0x4b */ + i_dec_sp, /* 0x4c */ + i_dec_bp, /* 0x4d */ + i_dec_si, /* 0x4e */ + i_dec_di, /* 0x4f */ + i_push_ax, /* 0x50 */ + i_push_cx, /* 0x51 */ + i_push_dx, /* 0x52 */ + i_push_bx, /* 0x53 */ + i_push_sp, /* 0x54 */ + i_push_bp, /* 0x55 */ + i_push_si, /* 0x56 */ + i_push_di, /* 0x57 */ + i_pop_ax, /* 0x58 */ + i_pop_cx, /* 0x59 */ + i_pop_dx, /* 0x5a */ + i_pop_bx, /* 0x5b */ + i_pop_sp, /* 0x5c */ + i_pop_bp, /* 0x5d */ + i_pop_si, /* 0x5e */ + i_pop_di, /* 0x5f */ + i_pusha, /* 0x60 */ + i_popa, /* 0x61 */ + i_chkind, /* 0x62 */ + i_invalid, /* 0x63 */ + i_repnc, /* 0x64 */ + i_repc, /* 0x65 */ + i_invalid, /* 0x66 */ + i_invalid, /* 0x67 */ + i_push_d16, /* 0x68 */ + i_imul_d16, /* 0x69 */ + i_push_d8, /* 0x6a */ + i_imul_d8, /* 0x6b */ + i_insb, /* 0x6c */ + i_insw, /* 0x6d */ + i_outsb, /* 0x6e */ + i_outsw, /* 0x6f */ + i_jo, /* 0x70 */ + i_jno, /* 0x71 */ + i_jc, /* 0x72 */ + i_jnc, /* 0x73 */ + i_jz, /* 0x74 */ + i_jnz, /* 0x75 */ + i_jce, /* 0x76 */ + i_jnce, /* 0x77 */ + i_js, /* 0x78 */ + i_jns, /* 0x79 */ + i_jp, /* 0x7a */ + i_jnp, /* 0x7b */ + i_jl, /* 0x7c */ + i_jnl, /* 0x7d */ + i_jle, /* 0x7e */ + i_jnle, /* 0x7f */ + i_80pre, /* 0x80 */ + i_81pre, /* 0x81 */ + i_82pre, /* 0x82 */ + i_83pre, /* 0x83 */ + i_test_br8, /* 0x84 */ + i_test_wr16, /* 0x85 */ + i_xchg_br8, /* 0x86 */ + i_xchg_wr16, /* 0x87 */ + i_mov_br8, /* 0x88 */ + i_mov_wr16, /* 0x89 */ + i_mov_r8b, /* 0x8a */ + i_mov_r16w, /* 0x8b */ + i_mov_wsreg, /* 0x8c */ + i_lea, /* 0x8d */ + i_mov_sregw, /* 0x8e */ + i_popw, /* 0x8f */ + i_nop, /* 0x90 */ + i_xchg_axcx, /* 0x91 */ + i_xchg_axdx, /* 0x92 */ + i_xchg_axbx, /* 0x93 */ + i_xchg_axsp, /* 0x94 */ + i_xchg_axbp, /* 0x95 */ + i_xchg_axsi, /* 0x97 */ + i_xchg_axdi, /* 0x97 */ + i_cbw, /* 0x98 */ + i_cwd, /* 0x99 */ + i_call_far, /* 0x9a */ + i_wait, /* 0x9b */ + i_pushf, /* 0x9c */ + i_popf, /* 0x9d */ + i_sahf, /* 0x9e */ + i_lahf, /* 0x9f */ + i_mov_aldisp, /* 0xa0 */ + i_mov_axdisp, /* 0xa1 */ + i_mov_dispal, /* 0xa2 */ + i_mov_dispax, /* 0xa3 */ + i_movsb, /* 0xa4 */ + i_movsw, /* 0xa5 */ + i_cmpsb, /* 0xa6 */ + i_cmpsw, /* 0xa7 */ + i_test_ald8, /* 0xa8 */ + i_test_axd16, /* 0xa9 */ + i_stosb, /* 0xaa */ + i_stosw, /* 0xab */ + i_lodsb, /* 0xac */ + i_lodsw, /* 0xad */ + i_scasb, /* 0xae */ + i_scasw, /* 0xaf */ + i_mov_ald8, /* 0xb0 */ + i_mov_cld8, /* 0xb1 */ + i_mov_dld8, /* 0xb2 */ + i_mov_bld8, /* 0xb3 */ + i_mov_ahd8, /* 0xb4 */ + i_mov_chd8, /* 0xb5 */ + i_mov_dhd8, /* 0xb6 */ + i_mov_bhd8, /* 0xb7 */ + i_mov_axd16, /* 0xb8 */ + i_mov_cxd16, /* 0xb9 */ + i_mov_dxd16, /* 0xba */ + i_mov_bxd16, /* 0xbb */ + i_mov_spd16, /* 0xbc */ + i_mov_bpd16, /* 0xbd */ + i_mov_sid16, /* 0xbe */ + i_mov_did16, /* 0xbf */ + i_rotshft_bd8, /* 0xc0 */ + i_rotshft_wd8, /* 0xc1 */ + i_ret_d16, /* 0xc2 */ + i_ret, /* 0xc3 */ + i_les_dw, /* 0xc4 */ + i_lds_dw, /* 0xc5 */ + i_mov_bd8, /* 0xc6 */ + i_mov_wd16, /* 0xc7 */ + i_enter, /* 0xc8 */ + i_leave, /* 0xc9 */ + i_retf_d16, /* 0xca */ + i_retf, /* 0xcb */ + i_int3, /* 0xcc */ + i_int, /* 0xcd */ + i_into, /* 0xce */ + i_iret, /* 0xcf */ + i_rotshft_b, /* 0xd0 */ + i_rotshft_w, /* 0xd1 */ + i_rotshft_bcl, /* 0xd2 */ + i_rotshft_wcl, /* 0xd3 */ + i_aam, /* 0xd4 */ + i_aad, /* 0xd5 */ + i_setalc, + i_trans, /* 0xd7 */ + i_fpo, /* 0xd8 */ + i_fpo, /* 0xd9 */ + i_fpo, /* 0xda */ + i_fpo, /* 0xdb */ + i_fpo, /* 0xdc */ + i_fpo, /* 0xdd */ + i_fpo, /* 0xde */ + i_fpo, /* 0xdf */ + i_loopne, /* 0xe0 */ + i_loope, /* 0xe1 */ + i_loop, /* 0xe2 */ + i_jcxz, /* 0xe3 */ + i_inal, /* 0xe4 */ + i_inax, /* 0xe5 */ + i_outal, /* 0xe6 */ + i_outax, /* 0xe7 */ + i_call_d16, /* 0xe8 */ + i_jmp_d16, /* 0xe9 */ + i_jmp_far, /* 0xea */ + i_jmp_d8, /* 0xeb */ + i_inaldx, /* 0xec */ + i_inaxdx, /* 0xed */ + i_outdxal, /* 0xee */ + i_outdxax, /* 0xef */ + i_lock, /* 0xf0 */ + i_invalid, /* 0xf1 */ + i_repne, /* 0xf2 */ + i_repe, /* 0xf3 */ + i_hlt, /* 0xf4 */ + i_cmc, /* 0xf5 */ + i_f6pre, /* 0xf6 */ + i_f7pre, /* 0xf7 */ + i_clc, /* 0xf8 */ + i_stc, /* 0xf9 */ + i_di, /* 0xfa */ + i_ei, /* 0xfb */ + i_cld, /* 0xfc */ + i_std, /* 0xfd */ + i_fepre, /* 0xfe */ + i_ffpre /* 0xff */ }; diff --git a/oswan/source/nec/necintrf.h b/oswan/source/nec/necintrf.h index 0849b9d..539e2d8 100644 --- a/oswan/source/nec/necintrf.h +++ b/oswan/source/nec/necintrf.h @@ -4,10 +4,12 @@ -enum { - NEC_IP=1, NEC_AW, NEC_CW, NEC_DW, NEC_BW, NEC_SP, NEC_BP, NEC_IX, NEC_IY, - NEC_FLAGS, NEC_ES, NEC_CS, NEC_SS, NEC_DS, - NEC_VECTOR, NEC_PENDING, NEC_NMI_STATE, NEC_IRQ_STATE }; +enum +{ + NEC_IP=1, NEC_AW, NEC_CW, NEC_DW, NEC_BW, NEC_SP, NEC_BP, NEC_IX, NEC_IY, + NEC_FLAGS, NEC_ES, NEC_CS, NEC_SS, NEC_DS, + NEC_VECTOR, NEC_PENDING, NEC_NMI_STATE, NEC_IRQ_STATE +}; /* Public variables */ extern int nec_ICount; @@ -59,7 +61,7 @@ extern unsigned v33_dasm(char *buffer, unsigned pc); */ void nec_set_reg(int,unsigned); -int nec_execute(int cycles); +int nec_execute(int cycles); unsigned nec_get_reg(int regnum); void nec_reset (void *param); void nec_int(DWORD wektor); diff --git a/oswan/source/nec/necmodrm.h b/oswan/source/nec/necmodrm.h index 41870b5..21b9704 100644 --- a/oswan/source/nec/necmodrm.h +++ b/oswan/source/nec/necmodrm.h @@ -1,12 +1,15 @@ -static struct { - struct { - WREGS w[256]; - BREGS b[256]; - } reg; - struct { - WREGS w[256]; - BREGS b[256]; - } RM; +static struct +{ + struct + { + WREGS w[256]; + BREGS b[256]; + } reg; + struct + { + WREGS w[256]; + BREGS b[256]; + } RM; } Mod_RM; #define RegWord(ModRM) I.regs.w[Mod_RM.reg.w[ModRM]] @@ -44,10 +47,10 @@ static struct { WriteWord( EA , val); \ } \ } - + #define GetRMByte(ModRM) \ ((ModRM) >= 0xc0 ? I.regs.b[Mod_RM.RM.b[ModRM]] : ReadByte( (*GetEA[ModRM])() )) - + #define PutRMByte(ModRM,val) \ { \ if (ModRM >= 0xc0) \ @@ -65,7 +68,7 @@ static struct { WriteByte( EA , FETCH ); \ } \ } - + #define PutbackRMByte(ModRM,val) \ { \ if (ModRM >= 0xc0) \ @@ -78,7 +81,7 @@ static struct { UINT32 ModRM = FETCH,src,dst; \ src = RegByte(ModRM); \ dst = GetRMByte(ModRM) - + #define DEF_wr16 \ UINT32 ModRM = FETCH,src,dst; \ src = RegWord(ModRM); \ diff --git a/oswan/source/rom.cpp b/oswan/source/rom.cpp index 4e641ee..ca1a647 100644 --- a/oswan/source/rom.cpp +++ b/oswan/source/rom.cpp @@ -31,21 +31,24 @@ //////////////////////////////////////////////////////////////////////////////// uint8 *ws_rom_load(char *path, uint32 *romSize) { - uint8 *rom=NULL; - Uint32 filepos; - FILE *fp=fopen(path,"rb"); - if (fp==NULL) - return(NULL); + uint8 *rom=NULL; + Uint32 filepos; + FILE *fp=fopen(path,"rb"); - fseek(fp,0,SEEK_END); - //fgetpos(fp,&filepos); - filepos = ftell(fp); - *romSize=(uint32)filepos; - fseek(fp,0,SEEK_SET); - rom=(uint8*)malloc(*romSize); - fread(rom,1,*romSize,fp); - fclose(fp); - return(rom); + if (fp==NULL) + { + return(NULL); + } + + fseek(fp,0,SEEK_END); + //fgetpos(fp,&filepos); + filepos = ftell(fp); + *romSize=(uint32)filepos; + fseek(fp,0,SEEK_SET); + rom=(uint8*)malloc(*romSize); + fread(rom,1,*romSize,fp); + fclose(fp); + return(rom); } //////////////////////////////////////////////////////////////////////////////// // @@ -60,30 +63,66 @@ uint8 *ws_rom_load(char *path, uint32 *romSize) //////////////////////////////////////////////////////////////////////////////// void ws_rom_dumpInfo(uint8 *wsrom, uint32 romSize) { - ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,romSize); + ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,romSize); - fprintf(log_get(),"rom: developper Id 0x%.2x\n",romHeader->developperId); - fprintf(log_get(),"rom: cart Id 0x%.2x\n",romHeader->cartId); - fprintf(log_get(),"rom: minimum system %s\n",(romHeader->minimumSupportSystem==WS_SYSTEM_MONO)?"Wonderswan mono":"Wonderswan color"); - fprintf(log_get(),"rom: size %i Mbits\n",(romSize>>20)<<3); - fprintf(log_get(),"rom: eeprom "); - switch (romHeader->eepromSize&0xf) - { - case WS_EEPROM_SIZE_NONE: { fprintf(log_get(),"none\n"); break; } - case WS_EEPROM_SIZE_64k: { fprintf(log_get(),"64 kb\n"); break; } - case WS_EEPROM_SIZE_256k: { fprintf(log_get(),"256 kb\n"); break; } - } - fprintf(log_get(),"rom: sram "); - switch (romHeader->eepromSize&0xf0) - { - case WS_SRAM_SIZE_NONE: { fprintf(log_get(),"none\n"); break; } - case WS_SRAM_SIZE_1k: { fprintf(log_get(),"1 kb\n"); break; } - case WS_SRAM_SIZE_16k: { fprintf(log_get(),"16 kb\n"); break; } - case WS_SRAM_SIZE_8k: { fprintf(log_get(),"8 kn\n"); break; } - } - - fprintf(log_get(),"rom: rtc %s\n",(romHeader->realtimeClock)?"Yes":"None"); - fprintf(log_get(),"checksum 0x%.4x\n",romHeader->checksum); + fprintf(log_get(),"rom: developper Id 0x%.2x\n",romHeader->developperId); + fprintf(log_get(),"rom: cart Id 0x%.2x\n",romHeader->cartId); + fprintf(log_get(),"rom: minimum system %s\n",(romHeader->minimumSupportSystem==WS_SYSTEM_MONO)?"Wonderswan mono":"Wonderswan color"); + fprintf(log_get(),"rom: size %i Mbits\n",(romSize>>20)<<3); + fprintf(log_get(),"rom: eeprom "); + + switch (romHeader->eepromSize&0xf) + { + case WS_EEPROM_SIZE_NONE: + { + fprintf(log_get(),"none\n"); + break; + } + + case WS_EEPROM_SIZE_64k: + { + fprintf(log_get(),"64 kb\n"); + break; + } + + case WS_EEPROM_SIZE_256k: + { + fprintf(log_get(),"256 kb\n"); + break; + } + } + + fprintf(log_get(),"rom: sram "); + + switch (romHeader->eepromSize&0xf0) + { + case WS_SRAM_SIZE_NONE: + { + fprintf(log_get(),"none\n"); + break; + } + + case WS_SRAM_SIZE_1k: + { + fprintf(log_get(),"1 kb\n"); + break; + } + + case WS_SRAM_SIZE_16k: + { + fprintf(log_get(),"16 kb\n"); + break; + } + + case WS_SRAM_SIZE_8k: + { + fprintf(log_get(),"8 kn\n"); + break; + } + } + + fprintf(log_get(),"rom: rtc %s\n",(romHeader->realtimeClock)?"Yes":"None"); + fprintf(log_get(),"checksum 0x%.4x\n",romHeader->checksum); } @@ -100,10 +139,10 @@ void ws_rom_dumpInfo(uint8 *wsrom, uint32 romSize) //////////////////////////////////////////////////////////////////////////////// ws_romHeaderStruct *ws_rom_getHeader(uint8 *wsrom, uint32 wsromSize) { - ws_romHeaderStruct *wsromHeader=(ws_romHeaderStruct *)malloc(sizeof(ws_romHeaderStruct)); + ws_romHeaderStruct *wsromHeader=(ws_romHeaderStruct *)malloc(sizeof(ws_romHeaderStruct)); - memcpy(wsromHeader,wsrom+(wsromSize-10),10); - return(wsromHeader); + memcpy(wsromHeader,wsrom+(wsromSize-10),10); + return(wsromHeader); } //////////////////////////////////////////////////////////////////////////////// // @@ -118,15 +157,24 @@ ws_romHeaderStruct *ws_rom_getHeader(uint8 *wsrom, uint32 wsromSize) //////////////////////////////////////////////////////////////////////////////// uint32 ws_rom_sramSize(uint8 *wsrom, uint32 wsromSize) { - ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize); - switch (romHeader->eepromSize&0xf0) - { - case WS_SRAM_SIZE_NONE: return(0); - case WS_SRAM_SIZE_1k: return(0x400); - case WS_SRAM_SIZE_16k: return(0x4000); - case WS_SRAM_SIZE_8k: return(0x2000); - } - return(0); + ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize); + + switch (romHeader->eepromSize&0xf0) + { + case WS_SRAM_SIZE_NONE: + return(0); + + case WS_SRAM_SIZE_1k: + return(0x400); + + case WS_SRAM_SIZE_16k: + return(0x4000); + + case WS_SRAM_SIZE_8k: + return(0x2000); + } + + return(0); } //////////////////////////////////////////////////////////////////////////////// // @@ -141,13 +189,20 @@ uint32 ws_rom_sramSize(uint8 *wsrom, uint32 wsromSize) //////////////////////////////////////////////////////////////////////////////// uint32 ws_rom_eepromSize(uint8 *wsrom, uint32 wsromSize) { - ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize); - switch (romHeader->eepromSize&0xf) - { - case WS_EEPROM_SIZE_NONE: return(0); - case WS_EEPROM_SIZE_64k: return(0x10000); - case WS_EEPROM_SIZE_256k: return(0x40000); - } - return(0); + ws_romHeaderStruct *romHeader=ws_rom_getHeader(wsrom,wsromSize); + + switch (romHeader->eepromSize&0xf) + { + case WS_EEPROM_SIZE_NONE: + return(0); + + case WS_EEPROM_SIZE_64k: + return(0x10000); + + case WS_EEPROM_SIZE_256k: + return(0x40000); + } + + return(0); } diff --git a/oswan/source/rom.h b/oswan/source/rom.h index 7f9b601..d08731c 100644 --- a/oswan/source/rom.h +++ b/oswan/source/rom.h @@ -38,14 +38,14 @@ typedef struct ws_romHeaderStruct { - uint8 developperId; - uint8 minimumSupportSystem; - uint8 cartId; - uint8 romSize; - uint8 eepromSize; - uint8 additionnalCapabilities; - uint8 realtimeClock; - uint16 checksum; + uint8 developperId; + uint8 minimumSupportSystem; + uint8 cartId; + uint8 romSize; + uint8 eepromSize; + uint8 additionnalCapabilities; + uint8 realtimeClock; + uint16 checksum; } ws_romHeaderStruct; diff --git a/oswan/source/temp/key.h b/oswan/source/temp/key.h index 05dc99a..de6d22d 100644 --- a/oswan/source/temp/key.h +++ b/oswan/source/temp/key.h @@ -1,98 +1,174 @@ - static int testJoystick=1; - if (testJoystick==1) - { - testJoystick=0; - fprintf(log_get(),"%i joysticks were found.\n\n", SDL_NumJoysticks() ); - fprintf(log_get(),"The names of the joysticks are:\n"); - for(int tti=0; tti < SDL_NumJoysticks(); tti++ ) - fprintf(log_get()," %s\n", SDL_JoystickName(tti)); - SDL_JoystickEventState(SDL_ENABLE); - joystick = SDL_JoystickOpen(0); - } - else - { - if (joystick!=NULL) - { - SDL_JoystickClose(0); - SDL_JoystickEventState(SDL_ENABLE); - joystick = SDL_JoystickOpen(0); - } - } - - while ( SDL_PollEvent(&app_input_event) ) - { - if ( app_input_event.type == SDL_QUIT ) - { - ws_key_esc = 1; - } - } - if (joystick) - { - if (SDL_JoystickGetButton(joystick,0)) - ws_key_start=1; - else - ws_key_start=0; - if (SDL_JoystickGetButton(joystick,1)) - ws_key_button_1=1; - else - ws_key_button_1=0; - if (SDL_JoystickGetButton(joystick,2)) - ws_key_button_2=1; - else - ws_key_button_2=0; +static int testJoystick=1; + +if (testJoystick==1) +{ + testJoystick=0; + fprintf(log_get(),"%i joysticks were found.\n\n", SDL_NumJoysticks() ); + fprintf(log_get(),"The names of the joysticks are:\n"); + + for(int tti=0; tti < SDL_NumJoysticks(); tti++ ) + { + fprintf(log_get()," %s\n", SDL_JoystickName(tti)); + } + + SDL_JoystickEventState(SDL_ENABLE); + joystick = SDL_JoystickOpen(0); +} +else +{ + if (joystick!=NULL) + { + SDL_JoystickClose(0); + SDL_JoystickEventState(SDL_ENABLE); + joystick = SDL_JoystickOpen(0); + } +} + +while ( SDL_PollEvent(&app_input_event) ) +{ + if ( app_input_event.type == SDL_QUIT ) + { + ws_key_esc = 1; + } +} + +if (joystick) +{ + if (SDL_JoystickGetButton(joystick,0)) + { + ws_key_start=1; + } + else + { + ws_key_start=0; + } + + if (SDL_JoystickGetButton(joystick,1)) + { + ws_key_button_1=1; + } + else + { + ws_key_button_1=0; + } + + if (SDL_JoystickGetButton(joystick,2)) + { + ws_key_button_2=1; + } + else + { + ws_key_button_2=0; + } - if (SDL_JoystickGetAxis(joystick,0)<-7000) - ws_key_left=1; - else - ws_key_left=0; - if (SDL_JoystickGetAxis(joystick,0)>7000) - ws_key_right=1; - else - ws_key_right=0; + if (SDL_JoystickGetAxis(joystick,0)<-7000) + { + ws_key_left=1; + } + else + { + ws_key_left=0; + } - if (SDL_JoystickGetAxis(joystick,1)<-7000) - ws_key_up=1; - else - ws_key_up=0; - if (SDL_JoystickGetAxis(joystick,1)>7000) - ws_key_down=1; - else - ws_key_down=0; - } - else - { - ws_key_start=0; - ws_key_left=0; - ws_key_right=0; - ws_key_up=0; - ws_key_down=0; - ws_key_button_1=0; - ws_key_button_2=0; - } - uint8 *keystate = SDL_GetKeyState(NULL); - if ( keystate[SDLK_d]) - { - dump_memory(); - } - if ( keystate[SDLK_ESCAPE] ) - ws_key_esc = 1; - if ( keystate[SDLK_UP] ) - ws_key_up=1; - if ( keystate[SDLK_DOWN] ) - ws_key_down=1; - if ( keystate[SDLK_RIGHT] ) - ws_key_right=1; - if ( keystate[SDLK_LEFT] ) - ws_key_left=1; - if (keystate[SDLK_RETURN]) - ws_key_start=1; - if (keystate[SDLK_c]) - ws_key_button_1=1; - if (keystate[SDLK_x]) - ws_key_button_2=1; - if (keystate[SDLK_p]) - ws_cyclesByLine+=10; - if (keystate[SDLK_o]) - ws_cyclesByLine-=10; + if (SDL_JoystickGetAxis(joystick,0)>7000) + { + ws_key_right=1; + } + else + { + ws_key_right=0; + } + + if (SDL_JoystickGetAxis(joystick,1)<-7000) + { + ws_key_up=1; + } + else + { + ws_key_up=0; + } + + if (SDL_JoystickGetAxis(joystick,1)>7000) + { + ws_key_down=1; + } + else + { + ws_key_down=0; + } +} +else +{ + ws_key_start=0; + ws_key_left=0; + ws_key_right=0; + ws_key_up=0; + ws_key_down=0; + ws_key_button_1=0; + ws_key_button_2=0; +} + +uint8 *keystate = SDL_GetKeyState(NULL); + +if ( keystate[SDLK_d]) +{ + dump_memory(); +} + +if ( keystate[SDLK_r]) +{ + printf("Boop\n"); + ws_reset(); +} + +if ( keystate[SDLK_ESCAPE] ) +{ + ws_key_esc = 1; +} + +if ( keystate[SDLK_UP] ) +{ + ws_key_up=1; +} + +if ( keystate[SDLK_DOWN] ) +{ + ws_key_down=1; +} + +if ( keystate[SDLK_RIGHT] ) +{ + ws_key_right=1; +} + +if ( keystate[SDLK_LEFT] ) +{ + ws_key_left=1; +} + +if (keystate[SDLK_RETURN]) +{ + ws_key_start=1; +} + +if (keystate[SDLK_c]) +{ + ws_key_button_1=1; +} + +if (keystate[SDLK_x]) +{ + ws_key_button_2=1; +} + +if (keystate[SDLK_p]) +{ + ws_cyclesByLine+=10; +} + +if (keystate[SDLK_o]) +{ + ws_cyclesByLine-=10; +} diff --git a/oswan/source/ticker.h b/oswan/source/ticker.h index e222eee..c4ccf4d 100644 --- a/oswan/source/ticker.h +++ b/oswan/source/ticker.h @@ -1,5 +1,5 @@ extern "C" { -long ticker(); + long ticker(); }; diff --git a/oswan/source/ws.cpp b/oswan/source/ws.cpp index b5dc4b1..ebe93ec 100644 --- a/oswan/source/ws.cpp +++ b/oswan/source/ws.cpp @@ -70,27 +70,30 @@ extern int ws_sram_dirty; void ws_patchRom(void) { - uint8 *rom=memory_getRom(); - uint32 romSize=memory_getRomSize(); + uint8 *rom=memory_getRom(); + uint32 romSize=memory_getRomSize(); - fprintf(log_get(),"developper Id: 0x%.2x\nGame Id: 0x%.2x\n",rom[romSize-10],rom[romSize-8]); + fprintf(log_get(),"developper Id: 0x%.2x\nGame Id: 0x%.2x\n",rom[romSize-10],rom[romSize-8]); - /* - if((rom[romSize-10]==0x01)&&(rom[romSize-8]==0x27)) // Detective Conan - { - // WS cpu is using cache/pipeline or - // there's protected ROM bank where - // pointing CS - - rom[0xfffe8]=0xea; - rom[0xfffe9]=0x00; - rom[0xfffea]=0x00; - rom[0xfffeb]=0x00; - rom[0xfffec]=0x20; - - }*/ + /* + if((rom[romSize-10]==0x01)&&(rom[romSize-8]==0x27)) // Detective Conan + { + // WS cpu is using cache/pipeline or + // there's protected ROM bank where + // pointing CS - if (!ws_cyclesByLine) ws_cyclesByLine=256; + rom[0xfffe8]=0xea; + rom[0xfffe9]=0x00; + rom[0xfffea]=0x00; + rom[0xfffeb]=0x00; + rom[0xfffec]=0x20; + + }*/ + + if (!ws_cyclesByLine) + { + ws_cyclesByLine=256; + } } //////////////////////////////////////////////////////////////////////////////// @@ -106,29 +109,37 @@ void ws_patchRom(void) //////////////////////////////////////////////////////////////////////////////// int ws_init(char *rompath) { - uint8 *rom; - uint32 romSize; + uint8 *rom; + uint32 romSize; - if ((rom=ws_rom_load(rompath,&romSize))==NULL) - { - printf("Error: cannot load %s\n",rompath); - return(0); - } - - if (rompath[strlen(rompath)-1]=='c') - ws_gpu_operatingInColor=1; - else - ws_gpu_operatingInColor=0; + if ((rom=ws_rom_load(rompath,&romSize))==NULL) + { + printf("Error: cannot load %s\n",rompath); + return(0); + } - ws_memory_init(rom,romSize); - ws_patchRom(); - ws_sram_load(ws_sram_path); - ws_io_init(); - ws_audio_init(); - ws_gpu_init(); - if (ws_rotated()) - ws_io_flipControls(); - return(1); + if (rompath[strlen(rompath)-1]=='c') + { + ws_gpu_operatingInColor=1; + } + else + { + ws_gpu_operatingInColor=0; + } + + ws_memory_init(rom,romSize); + ws_patchRom(); + ws_sram_load(ws_sram_path); + ws_io_init(); + ws_audio_init(); + ws_gpu_init(); + + if (ws_rotated()) + { + ws_io_flipControls(); + } + + return(1); } //////////////////////////////////////////////////////////////////////////////// // @@ -143,12 +154,12 @@ int ws_init(char *rompath) //////////////////////////////////////////////////////////////////////////////// void ws_reset(void) { - ws_memory_reset(); - ws_io_reset(); - ws_audio_reset(); - ws_gpu_reset(); - nec_reset(NULL); - nec_set_reg(NEC_SP,0x2000); + ws_memory_reset(); + ws_io_reset(); + ws_audio_reset(); + ws_gpu_reset(); + nec_reset(NULL); + nec_set_reg(NEC_SP,0x2000); } //////////////////////////////////////////////////////////////////////////////// // @@ -163,84 +174,107 @@ void ws_reset(void) //////////////////////////////////////////////////////////////////////////////// int ws_executeLine(int16 *framebuffer, int renderLine) { - int drawWholeScreen=0; - - ws_audio_process(); + int drawWholeScreen=0; - // update scanline register - ws_ioRam[2]=ws_gpu_scanline; + ws_audio_process(); - ws_cycles=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); - ws_cycles+=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); + // update scanline register + ws_ioRam[2]=ws_gpu_scanline; - if(ws_cycles>=ws_cyclesByLine+ws_cyclesByLine) - ws_skip=ws_cycles/ws_cyclesByLine; - else - ws_skip=1; - ws_cycles%=ws_cyclesByLine; + ws_cycles=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); + ws_cycles+=nec_execute((ws_cyclesByLine>>1)+(rand()&7)); - for(uint32 uI=0;uI=ws_cyclesByLine+ws_cyclesByLine) + { + ws_skip=ws_cycles/ws_cyclesByLine; + } + else + { + ws_skip=1; + } - ws_gpu_scanline++; - if(ws_gpu_scanline==144) - drawWholeScreen=1; + ws_cycles%=ws_cyclesByLine; + + for(uint32 uI=0; uI158) + { + ws_gpu_scanline=0; + { + if((ws_ioRam[0xb2]&32))/*VBLANK END INT*/ + { + if(ws_ioRam[0xa7]!=0x35)/*Beatmania Fix*/ + { + ws_ioRam[0xb6]&=~32; + nec_int((ws_ioRam[0xb0]+5)*4); + } + } + } + } + + ws_ioRam[2]=ws_gpu_scanline; + + if(drawWholeScreen) + { + + if(ws_ioRam[0xb2]&64) /*VBLANK INT*/ + { + ws_ioRam[0xb6]&=~64; + nec_int((ws_ioRam[0xb0]+6)*4); + } + + vblank_count++; + } - } - if(ws_gpu_scanline>158) - { - ws_gpu_scanline=0; - { - if((ws_ioRam[0xb2]&32))/*VBLANK END INT*/ - { - if(ws_ioRam[0xa7]!=0x35)/*Beatmania Fix*/ - { - ws_ioRam[0xb6]&=~32; - nec_int((ws_ioRam[0xb0]+5)*4); - } - } - } - } - ws_ioRam[2]=ws_gpu_scanline; - if(drawWholeScreen) - { - - if(ws_ioRam[0xb2]&64) /*VBLANK INT*/ - { - ws_ioRam[0xb6]&=~64; - nec_int((ws_ioRam[0xb0]+6)*4); - } - vblank_count++; - } if(ws_ioRam[0xa4]&&(ws_ioRam[0xb2]&128)) /*HBLANK INT*/ { - - if(!ws_ioRam[0xa5]) - ws_ioRam[0xa5]=ws_ioRam[0xa4]; - if(ws_ioRam[0xa5]) - ws_ioRam[0xa5]--; - if((!ws_ioRam[0xa5])&&(ws_ioRam[0xb2]&128)) - { - - ws_ioRam[0xb6]&=~128; - nec_int((ws_ioRam[0xb0]+7)*4); - } - } - if((ws_ioRam[0x2]==ws_ioRam[0x3])&&(ws_ioRam[0xb2]&16)) /*SCANLINE INT*/ - { - ws_ioRam[0xb6]&=~16; - nec_int((ws_ioRam[0xb0]+4)*4); - } + if(!ws_ioRam[0xa5]) + { + ws_ioRam[0xa5]=ws_ioRam[0xa4]; + } - if (drawWholeScreen && ws_sram_dirty) - { - ws_sram_save(ws_sram_path); - ws_sram_dirty = 0; - } - return(drawWholeScreen); + if(ws_ioRam[0xa5]) + { + ws_ioRam[0xa5]--; + } + + if((!ws_ioRam[0xa5])&&(ws_ioRam[0xb2]&128)) + { + + ws_ioRam[0xb6]&=~128; + nec_int((ws_ioRam[0xb0]+7)*4); + + } + } + + if((ws_ioRam[0x2]==ws_ioRam[0x3])&&(ws_ioRam[0xb2]&16)) /*SCANLINE INT*/ + { + ws_ioRam[0xb6]&=~16; + nec_int((ws_ioRam[0xb0]+4)*4); + } + + if (drawWholeScreen && ws_sram_dirty) + { + ws_sram_save(ws_sram_path); + ws_sram_dirty = 0; + } + + return(drawWholeScreen); } //////////////////////////////////////////////////////////////////////////////// // @@ -255,10 +289,10 @@ int ws_executeLine(int16 *framebuffer, int renderLine) //////////////////////////////////////////////////////////////////////////////// void ws_done(void) { - ws_memory_done(); - ws_io_done(); - ws_audio_done(); - ws_gpu_done(); + ws_memory_done(); + ws_io_done(); + ws_audio_done(); + ws_gpu_done(); } //////////////////////////////////////////////////////////////////////////////// // @@ -273,7 +307,7 @@ void ws_done(void) //////////////////////////////////////////////////////////////////////////////// void ws_set_colour_scheme(int scheme) { - ws_gpu_set_colour_scheme(scheme); + ws_gpu_set_colour_scheme(scheme); } //////////////////////////////////////////////////////////////////////////////// // @@ -288,11 +322,14 @@ void ws_set_colour_scheme(int scheme) //////////////////////////////////////////////////////////////////////////////// void ws_set_system(int system) { - if (system==WS_SYSTEM_COLOR) - ws_gpu_forceColorSystem(); - else - if (system==WS_SYSTEM_MONO) - ws_gpu_forceMonoSystem(); + if (system==WS_SYSTEM_COLOR) + { + ws_gpu_forceColorSystem(); + } + else if (system==WS_SYSTEM_MONO) + { + ws_gpu_forceMonoSystem(); + } } //////////////////////////////////////////////////////////////////////////////// // @@ -307,59 +344,65 @@ void ws_set_system(int system) //////////////////////////////////////////////////////////////////////////////// #define MacroLoadNecRegisterFromFile(F,R) \ read(fp,&value,sizeof(value)); \ - nec_set_reg(R,value); + nec_set_reg(R,value); int ws_loadState(char *statepath) { - fprintf(log_get(),"loading %s\n",statepath); - uint16 crc=memory_getRomCrc(); - uint16 newCrc; - unsigned value; - uint8 ws_newVideoMode; + fprintf(log_get(),"loading %s\n",statepath); + uint16 crc=memory_getRomCrc(); + uint16 newCrc; + unsigned value; + uint8 ws_newVideoMode; - int fp = open(statepath,O_BINARY|O_RDONLY); - if (fp == -1) - return(0); - read(fp, &newCrc, 2); - if (newCrc!=crc) - { - return(-1); - } - MacroLoadNecRegisterFromFile(fp,NEC_IP); - MacroLoadNecRegisterFromFile(fp,NEC_AW); - MacroLoadNecRegisterFromFile(fp,NEC_BW); - MacroLoadNecRegisterFromFile(fp,NEC_CW); - MacroLoadNecRegisterFromFile(fp,NEC_DW); - MacroLoadNecRegisterFromFile(fp,NEC_CS); - MacroLoadNecRegisterFromFile(fp,NEC_DS); - MacroLoadNecRegisterFromFile(fp,NEC_ES); - MacroLoadNecRegisterFromFile(fp,NEC_SS); - MacroLoadNecRegisterFromFile(fp,NEC_IX); - MacroLoadNecRegisterFromFile(fp,NEC_IY); - MacroLoadNecRegisterFromFile(fp,NEC_BP); - MacroLoadNecRegisterFromFile(fp,NEC_SP); - MacroLoadNecRegisterFromFile(fp,NEC_FLAGS); - MacroLoadNecRegisterFromFile(fp,NEC_VECTOR); - MacroLoadNecRegisterFromFile(fp,NEC_PENDING); - MacroLoadNecRegisterFromFile(fp,NEC_NMI_STATE); - MacroLoadNecRegisterFromFile(fp,NEC_IRQ_STATE); - - read(fp,internalRam,65536); - read(fp,ws_staticRam,65536); - read(fp,ws_ioRam,256); - read(fp,ws_paletteColors,8); - read(fp,ws_palette,16*4*2); - read(fp,wsc_palette,16*16*2); - read(fp,&ws_newVideoMode,1); - read(fp,&ws_gpu_scanline,1); - read(fp,externalEeprom,131072); + int fp = open(statepath,O_BINARY|O_RDONLY); - ws_audio_readState(fp); - close(fp); - - // force a video mode change to make all tiles dirty - ws_gpu_clearCache(); - return(1); + if (fp == -1) + { + return(0); + } + + read(fp, &newCrc, 2); + + if (newCrc!=crc) + { + return(-1); + } + + MacroLoadNecRegisterFromFile(fp,NEC_IP); + MacroLoadNecRegisterFromFile(fp,NEC_AW); + MacroLoadNecRegisterFromFile(fp,NEC_BW); + MacroLoadNecRegisterFromFile(fp,NEC_CW); + MacroLoadNecRegisterFromFile(fp,NEC_DW); + MacroLoadNecRegisterFromFile(fp,NEC_CS); + MacroLoadNecRegisterFromFile(fp,NEC_DS); + MacroLoadNecRegisterFromFile(fp,NEC_ES); + MacroLoadNecRegisterFromFile(fp,NEC_SS); + MacroLoadNecRegisterFromFile(fp,NEC_IX); + MacroLoadNecRegisterFromFile(fp,NEC_IY); + MacroLoadNecRegisterFromFile(fp,NEC_BP); + MacroLoadNecRegisterFromFile(fp,NEC_SP); + MacroLoadNecRegisterFromFile(fp,NEC_FLAGS); + MacroLoadNecRegisterFromFile(fp,NEC_VECTOR); + MacroLoadNecRegisterFromFile(fp,NEC_PENDING); + MacroLoadNecRegisterFromFile(fp,NEC_NMI_STATE); + MacroLoadNecRegisterFromFile(fp,NEC_IRQ_STATE); + + read(fp,internalRam,65536); + read(fp,ws_staticRam,65536); + read(fp,ws_ioRam,256); + read(fp,ws_paletteColors,8); + read(fp,ws_palette,16*4*2); + read(fp,wsc_palette,16*16*2); + read(fp,&ws_newVideoMode,1); + read(fp,&ws_gpu_scanline,1); + read(fp,externalEeprom,131072); + + ws_audio_readState(fp); + close(fp); + + // force a video mode change to make all tiles dirty + ws_gpu_clearCache(); + return(1); } //////////////////////////////////////////////////////////////////////////////// // @@ -378,69 +421,85 @@ int ws_loadState(char *statepath) int ws_saveState(char *statepath) { - uint16 crc=memory_getRomCrc(); - unsigned value; - char *newPath; - fprintf(log_get(),"saving %s\n",statepath); - - newPath=new char[1024]; - if (strlen(statepath)<4) - sprintf(newPath,"%s.wss",statepath); - else - { - int len=strlen(statepath); - if ((statepath[len-1]!='s')&&(statepath[len-1]!='S')) - sprintf(newPath,"%s.wss",statepath); - else - if ((statepath[len-2]!='s')&&(statepath[len-2]!='S')) - sprintf(newPath,"%s.wss",statepath); - else - if ((statepath[len-3]!='w')&&(statepath[len-3]!='w')) - sprintf(newPath,"%s.wss",statepath); - else - if (statepath[len-4]!='.') - sprintf(newPath,"%s.wss",statepath); - else - sprintf(newPath,"%s",statepath); - } - int fp=open(newPath,O_BINARY|O_RDWR|O_CREAT); - delete newPath; - if (fp==-1) - return(0); - write(fp,&crc,2); - MacroStoreNecRegisterToFile(fp,NEC_IP); - MacroStoreNecRegisterToFile(fp,NEC_AW); - MacroStoreNecRegisterToFile(fp,NEC_BW); - MacroStoreNecRegisterToFile(fp,NEC_CW); - MacroStoreNecRegisterToFile(fp,NEC_DW); - MacroStoreNecRegisterToFile(fp,NEC_CS); - MacroStoreNecRegisterToFile(fp,NEC_DS); - MacroStoreNecRegisterToFile(fp,NEC_ES); - MacroStoreNecRegisterToFile(fp,NEC_SS); - MacroStoreNecRegisterToFile(fp,NEC_IX); - MacroStoreNecRegisterToFile(fp,NEC_IY); - MacroStoreNecRegisterToFile(fp,NEC_BP); - MacroStoreNecRegisterToFile(fp,NEC_SP); - MacroStoreNecRegisterToFile(fp,NEC_FLAGS); - MacroStoreNecRegisterToFile(fp,NEC_VECTOR); - MacroStoreNecRegisterToFile(fp,NEC_PENDING); - MacroStoreNecRegisterToFile(fp,NEC_NMI_STATE); - MacroStoreNecRegisterToFile(fp,NEC_IRQ_STATE); + uint16 crc=memory_getRomCrc(); + unsigned value; + char *newPath; + fprintf(log_get(),"saving %s\n",statepath); - write(fp,internalRam,65536); - write(fp,ws_staticRam,65536); - write(fp,ws_ioRam,256); - write(fp,ws_paletteColors,8); - write(fp,ws_palette,16*4*2); - write(fp,wsc_palette,16*16*2); - write(fp,&ws_videoMode,1); - write(fp,&ws_gpu_scanline,1); - write(fp,externalEeprom,131072); - - ws_audio_writeState(fp); - close(fp); + newPath=new char[1024]; - return(1); + if (strlen(statepath)<4) + { + sprintf(newPath,"%s.wss",statepath); + } + else + { + int len=strlen(statepath); + + if ((statepath[len-1]!='s')&&(statepath[len-1]!='S')) + { + sprintf(newPath,"%s.wss",statepath); + } + else if ((statepath[len-2]!='s')&&(statepath[len-2]!='S')) + { + sprintf(newPath,"%s.wss",statepath); + } + else if ((statepath[len-3]!='w')&&(statepath[len-3]!='w')) + { + sprintf(newPath,"%s.wss",statepath); + } + else if (statepath[len-4]!='.') + { + sprintf(newPath,"%s.wss",statepath); + } + else + { + sprintf(newPath,"%s",statepath); + } + } + + int fp=open(newPath,O_BINARY|O_RDWR|O_CREAT); + delete newPath; + + if (fp==-1) + { + return(0); + } + + write(fp,&crc,2); + MacroStoreNecRegisterToFile(fp,NEC_IP); + MacroStoreNecRegisterToFile(fp,NEC_AW); + MacroStoreNecRegisterToFile(fp,NEC_BW); + MacroStoreNecRegisterToFile(fp,NEC_CW); + MacroStoreNecRegisterToFile(fp,NEC_DW); + MacroStoreNecRegisterToFile(fp,NEC_CS); + MacroStoreNecRegisterToFile(fp,NEC_DS); + MacroStoreNecRegisterToFile(fp,NEC_ES); + MacroStoreNecRegisterToFile(fp,NEC_SS); + MacroStoreNecRegisterToFile(fp,NEC_IX); + MacroStoreNecRegisterToFile(fp,NEC_IY); + MacroStoreNecRegisterToFile(fp,NEC_BP); + MacroStoreNecRegisterToFile(fp,NEC_SP); + MacroStoreNecRegisterToFile(fp,NEC_FLAGS); + MacroStoreNecRegisterToFile(fp,NEC_VECTOR); + MacroStoreNecRegisterToFile(fp,NEC_PENDING); + MacroStoreNecRegisterToFile(fp,NEC_NMI_STATE); + MacroStoreNecRegisterToFile(fp,NEC_IRQ_STATE); + + write(fp,internalRam,65536); + write(fp,ws_staticRam,65536); + write(fp,ws_ioRam,256); + write(fp,ws_paletteColors,8); + write(fp,ws_palette,16*4*2); + write(fp,wsc_palette,16*16*2); + write(fp,&ws_videoMode,1); + write(fp,&ws_gpu_scanline,1); + write(fp,externalEeprom,131072); + + ws_audio_writeState(fp); + close(fp); + + return(1); } //////////////////////////////////////////////////////////////////////////////// // @@ -455,8 +514,8 @@ int ws_saveState(char *statepath) //////////////////////////////////////////////////////////////////////////////// int ws_rotated(void) { - uint8 *rom=memory_getRom(); - uint32 romSize=memory_getRomSize(); - - return(rom[romSize-4]&1); + uint8 *rom=memory_getRom(); + uint32 romSize=memory_getRomSize(); + + return(rom[romSize-4]&1); } diff --git a/oswan/ws.txt b/oswan/ws.txt new file mode 100644 index 0000000..26cc754 --- /dev/null +++ b/oswan/ws.txt @@ -0,0 +1,65 @@ +00000000 ff ff ff ff ff ff c0 ff 00 00 00 00 00 00 00 00 |................| +00000010 00 00 00 00 00 00 00 00 00 00 7f 00 ff ff ff ff |................| +00000020 ff ff ff ff ff ff ff ff ff ff 00 00 00 00 00 00 |................| +00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff |................| +00000050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000060 00 fc ff 01 ff fd ff fd ff fd ff fd ff fd ff fd |................| +00000070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000080 ff ff ff ff 01 00 ff ff ff ff ff ff ff ff ff ff |................| +00000090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000000f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000100 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000120 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000130 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000140 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000150 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000160 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000170 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000180 00 00 03 03 00 00 00 40 80 00 00 00 00 00 00 00 |.......@........| +00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +000001b0 87 05 8c 09 05 0c 8b 0c 90 00 00 02 00 4c a5 00 |.............L..| +000001c0 80 00 00 00 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +000001d0 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +000001e0 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +000001f0 ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f ff 7f |................| +00000200 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000210 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000220 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000230 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000240 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000250 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000260 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000270 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000280 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000290 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000002e0 21 19 18 0e 0f 1c 1d 21 0b 18 00 25 00 00 00 00 |!......!...%....| +000002f0 20 01 01 21 01 04 21 00 01 98 3c 7f 4b 02 36 01 | ..!..!...<.K.6.| +00000300 00 00 06 06 06 06 06 00 00 00 00 00 01 80 0f 00 |................| +00000310 01 01 01 0f 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000320 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000330 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000340 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000350 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000360 21 19 18 0e 0f 1c 1d 21 0b 18 00 00 00 00 00 00 |!......!........| +00000370 20 01 01 21 01 04 00 01 00 98 3c 7f 4a 01 35 01 | ..!......<.J.5.| +00000380 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000390 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +000003f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +00000400