00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define DISABLED_BEHAVIOR
00041
00042
00043 #define WIN32_LEAN_AND_MEAN
00044 #include <windows.h>
00045 #include <windowsx.h>
00046 #include <winuser.h>
00047 #include <mmsystem.h>
00048 #include <Assert.h>
00049
00050 #include "sal.h"
00051
00052 #include <stdio.h>
00053 #include <dos.h>
00054 #include <malloc.h>
00055 #include <direct.h>
00056 #include <io.h>
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 static S32 desktop_w;
00074 static S32 desktop_h;
00075
00076 static S32 cursor_state;
00077 static S32 show_count;
00078
00079 static char debug_log_filename[256];
00080 static S32 log_to_file;
00081
00082 static S32 app_minimized;
00083 static S32 app_active;
00084 static S32 app_terminated;
00085
00086 static SALEXITCB exit_callback;
00087 static SALFOCUSCB focus_callback;
00088 static WNDPROC window_callback;
00089 static WNDPROC OldWindowProc;
00090 static HANDLE hSem;
00091
00092 static S32 mode_change_request;
00093
00094 static HINSTANCE hAppInstance;
00095 static HINSTANCE hDLLInstance;
00096 static char szMyAppName[512];
00097 static HWND hWnd;
00098 static HANDLE hHook;
00099
00100 static S32 SAL_preference[N_SAL_PREFS];
00101
00102 static S32 mode_change_allowed;
00103 static S32 current_window_mode;
00104 static S32 current_bpp;
00105 static S32 current_size_X;
00106 static S32 current_size_Y;
00107
00108 static LOGPALETTE *pLogPal;
00109 static BITMAPINFO *pbmi;
00110 static BITMAPINFOHEADER *pbmih;
00111
00112 static SAL_RGB32 palette_state[256];
00113
00114
00115
00116
00117
00118 static SAL_WINAREA area;
00119
00120 static S32 desktop_bpp;
00121 static U32 desktop_R_bitmask;
00122 static U32 desktop_G_bitmask;
00123 static U32 desktop_B_bitmask;
00124
00125 static U32 DIB_R_bitmask;
00126 static U32 DIB_G_bitmask;
00127 static U32 DIB_B_bitmask;
00128
00129 static U32 DIB_R_Shift;
00130 static U32 DIB_G_Shift;
00131 static U32 DIB_B_Shift;
00132
00133 static S32 DIB_active;
00134
00135 static U8 *lpDIBBuffer;
00136 static HBITMAP hDIB;
00137 static HPALETTE hPalette;
00138
00139 static S32 palette_change_request;
00140
00141 static RECT original_window_rect;
00142 static SAL_WINAREA original_area;
00143 static LONG OldWindowLong_GWL_STYLE;
00144 static LONG OldWindowLong_GWL_EXSTYLE;
00145
00146 static RECT unconstrained_rect;
00147 static S32 constrain_state;
00148 static S32 constrain_request;
00149
00150 static HDC Context;
00151 static HBITMAP DefaultBitmap;
00152
00153 extern "C" long FAR PASCAL MyWndProc(HWND hWindow, UINT message,
00154 WPARAM wParam, LPARAM lParam);
00155
00156
00157
00158
00159
00160
00161
00162 BOOL WINAPI DllMain(HINSTANCE hinstDLL,
00163 DWORD fdwReason,
00164 LPVOID lpvReserved)
00165 {
00166 if (fdwReason == DLL_PROCESS_ATTACH)
00167 {
00168 hDLLInstance = hinstDLL;
00169 }
00170
00171 return TRUE;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 void serve_queue(void)
00181 {
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 RECT *client_screen_rect(void)
00223 {
00224 static RECT rect;
00225 POINT ul,lr;
00226
00227 GetClientRect(hWnd, &rect);
00228
00229 ul.x = rect.left;
00230 ul.y = rect.top;
00231 lr.x = rect.right;
00232 lr.y = rect.bottom;
00233
00234 ClientToScreen(hWnd, &ul);
00235 ClientToScreen(hWnd, &lr);
00236
00237 SetRect(&rect, ul.x, ul.y,
00238 lr.x-1, lr.y-1);
00239
00240 return ▭
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 void MOUSE_event(unsigned long wParam, unsigned long lParam)
00250 {
00251 }
00252
00253 void KEYDOWN_event(unsigned long wParam, unsigned long lParam)
00254 {
00255 }
00256
00257 void KEYUP_event(unsigned long wParam, unsigned long lParam)
00258 {
00259 }
00260
00261 void CHAR_event(unsigned long wParam, unsigned long lParam)
00262 {
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272 void DIB_shutdown(void)
00273 {
00274 if (constrain_state)
00275 {
00276 #ifndef DISABLED_BEHAVIOR
00277 ClipCursor(&unconstrained_rect);
00278 #endif
00279 constrain_request = 0;
00280 }
00281
00282 if (DIB_active && SAL_is_app_active())
00283 {
00284 SAL_wipe_surface(SAL_BACK_SURFACE, 0);
00285 SAL_flip_surface();
00286 }
00287
00288 if (hDIB != NULL)
00289 {
00290 DeleteObject(hDIB);
00291 hDIB = NULL;
00292 }
00293
00294 if (hPalette != NULL)
00295 {
00296 DeleteObject(hPalette);
00297 hPalette = NULL;
00298 }
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 DIB_active = 0;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328 S32 DIB_startup(S32 display_size_X,
00329 S32 display_size_Y,
00330 S32 display_bpp)
00331 {
00332 HDC hdc;
00333 COLORREF color,save;
00334 RECT window_rect;
00335
00336 area.x = 0;
00337 area.y = 0;
00338 area.width = display_size_X;
00339 area.height = display_size_Y;
00340 original_area = area;
00341
00342 GetWindowRect(hWnd, &window_rect);
00343 original_window_rect = window_rect;
00344
00345 OldWindowLong_GWL_STYLE = GetWindowLong(hWnd, GWL_STYLE);
00346 OldWindowLong_GWL_EXSTYLE = GetWindowLong(hWnd, GWL_EXSTYLE);
00347
00348 display_size_X = area.width;
00349 display_size_Y = area.height;
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497 if (constrain_state)
00498 {
00499 constrain_request = 1;
00500 }
00501
00502
00503
00504
00505
00506 hDIB = NULL;
00507 lpDIBBuffer = NULL;
00508 hPalette = NULL;
00509
00510 pbmih->biSize = sizeof(BITMAPINFOHEADER);
00511 pbmih->biWidth = (display_size_X);
00512 pbmih->biHeight = -(display_size_Y);
00513 pbmih->biPlanes = 1;
00514 pbmih->biBitCount = (U16) display_bpp;
00515 pbmih->biSizeImage = 0;
00516 pbmih->biXPelsPerMeter = 0;
00517 pbmih->biYPelsPerMeter = 0;
00518 pbmih->biClrUsed = 0;
00519 pbmih->biClrImportant = 0;
00520
00521
00522
00523
00524
00525 hdc = GetDC(hWnd);
00526
00527 desktop_bpp = GetDeviceCaps(hdc, BITSPIXEL) *
00528 GetDeviceCaps(hdc, PLANES);
00529
00530 SAL_debug_printf("SAL: Desktop = %dx%d, %d BPP\n",desktop_w,
00531 desktop_h,
00532 desktop_bpp);
00533
00534 if(desktop_bpp > 8)
00535 {
00536 HBITMAP TempBmp;
00537 BITMAPINFO TempInfo;
00538 OSVERSIONINFO WinVer;
00539
00540 memset(&WinVer, 0, sizeof(OSVERSIONINFO));
00541 WinVer.dwOSVersionInfoSize =sizeof(OSVERSIONINFO);
00542
00543 GetVersionEx(&WinVer);
00544 if(WinVer.dwPlatformId == VER_PLATFORM_WIN32_NT)
00545 {
00546 TempBmp =CreateCompatibleBitmap(hdc, 8, 8);
00547 if(TempBmp)
00548 {
00549 memset(&TempInfo, 0, sizeof(BITMAPINFO));
00550 TempInfo.bmiHeader.biSize =sizeof(BITMAPINFO);
00551 TempInfo.bmiHeader.biBitCount =(U16)desktop_bpp;
00552 TempInfo.bmiHeader.biCompression =BI_BITFIELDS;
00553
00554 if(GetDIBits(hdc, TempBmp, 0, 0, NULL, &TempInfo, DIB_RGB_COLORS))
00555 {
00556 desktop_R_bitmask =*((U32 *)&TempInfo.bmiColors[0]);
00557 desktop_G_bitmask =*((U32 *)&TempInfo.bmiColors[1]);
00558 desktop_B_bitmask =*((U32 *)&TempInfo.bmiColors[2]);
00559
00560 SAL_debug_printf("(%x-%x-%x)\n", desktop_R_bitmask, desktop_G_bitmask, desktop_B_bitmask);
00561 }
00562 DeleteObject(TempBmp);
00563 }
00564 }
00565 else
00566 {
00567 save = GetPixel(hdc,0,0);
00568
00569 SetPixel(hdc,0,0,RGB(0x08,0x08,0x08));
00570
00571 color = GetPixel(hdc,0,0) & 0xffffff;
00572
00573 SAL_debug_printf("SAL: Desktop pixel format = 0x%X ",color);
00574
00575 switch (color)
00576 {
00577
00578
00579
00580
00581 case 0x000000:
00582
00583 SAL_debug_printf("(5-5-5)\n");
00584
00585 desktop_R_bitmask = 0x007c00;
00586 desktop_G_bitmask = 0x0003e0;
00587 desktop_B_bitmask = 0x00001f;
00588 break;
00589
00590
00591
00592
00593
00594 case 0x000800:
00595
00596 SAL_debug_printf("(5-6-5)\n");
00597
00598 desktop_R_bitmask = 0x00f800;
00599 desktop_G_bitmask = 0x0007e0;
00600 desktop_B_bitmask = 0x00001f;
00601 break;
00602
00603
00604
00605
00606
00607 case 0x080808:
00608
00609 SAL_debug_printf("(8-8-8)\n");
00610
00611 desktop_R_bitmask = 0xff0000;
00612 desktop_G_bitmask = 0x00ff00;
00613 desktop_B_bitmask = 0x0000ff;
00614 break;
00615
00616 default:
00617
00618 SAL_debug_printf("(Unsupported, using 5-6-5)\n");
00619
00620 if ((desktop_bpp == 15) || (desktop_bpp == 16))
00621 {
00622 desktop_R_bitmask = 0x00f800;
00623 desktop_G_bitmask = 0x0007e0;
00624 desktop_B_bitmask = 0x00001f;
00625 }
00626 break;
00627 }
00628
00629 SetPixel(hdc,0,0,save);
00630 }
00631 }
00632 ReleaseDC(hWnd, hdc);
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645 switch (display_bpp)
00646 {
00647 case 8:
00648
00649 pbmih->biCompression = BI_RGB;
00650
00651 hPalette = CreatePalette(pLogPal);
00652 palette_change_request = TRUE;
00653 break;
00654
00655 case 16:
00656
00657 pbmih->biCompression = BI_BITFIELDS;
00658
00659 if ((desktop_bpp == 15) || (desktop_bpp == 16))
00660 {
00661 *(U32 *) (&(pbmi->bmiColors[0])) = desktop_R_bitmask;
00662 *(U32 *) (&(pbmi->bmiColors[1])) = desktop_G_bitmask;
00663 *(U32 *) (&(pbmi->bmiColors[2])) = desktop_B_bitmask;
00664 DIB_R_bitmask = desktop_R_bitmask;
00665 DIB_G_bitmask = desktop_G_bitmask;
00666 DIB_B_bitmask = desktop_B_bitmask;
00667
00668 }
00669 else
00670 {
00671 *(U32 *) (&(pbmi->bmiColors[0])) = 0x00f800;
00672 *(U32 *) (&(pbmi->bmiColors[1])) = 0x0007e0;
00673 *(U32 *) (&(pbmi->bmiColors[2])) = 0x00001f;
00674 DIB_R_bitmask = 0x00f800;
00675 DIB_G_bitmask = 0x0007e0;
00676 DIB_B_bitmask = 0x00001f;
00677 }
00678 break;
00679
00680 case 24:
00681
00682 pbmih->biCompression = BI_BITFIELDS;
00683
00684 *(U32 *) (&(pbmi->bmiColors[0])) = 0xff0000;
00685 *(U32 *) (&(pbmi->bmiColors[1])) = 0x00ff00;
00686 *(U32 *) (&(pbmi->bmiColors[2])) = 0x0000ff;
00687 DIB_R_bitmask = 0xff0000;
00688 DIB_G_bitmask = 0x00ff00;
00689 DIB_B_bitmask = 0x0000ff;
00690 break;
00691 }
00692
00693
00694
00695
00696
00697 hdc = GetDC(hWnd);
00698
00699 hDIB = CreateDIBSection(hdc,
00700 pbmi,
00701 DIB_RGB_COLORS,
00702 (void **) &lpDIBBuffer,
00703 NULL,
00704 0);
00705
00706 ReleaseDC(hWnd, hdc);
00707
00708 if (hDIB == NULL)
00709 {
00710 SAL_error_box(NULL,"CreateDIBSection() failed\n");
00711 DIB_shutdown();
00712 return FALSE;
00713 }
00714
00715
00716
00717
00718
00719 DIB_active = 1;
00720
00721 return TRUE;
00722 }
00723
00724
00725
00726
00727
00728
00729
00730 void DIB_refresh_surface(void)
00731 {
00732 HDC hdc;
00733
00734 hdc = GetDC(hWnd);
00735
00736
00737
00738
00739
00740
00741
00742 if (desktop_bpp == 8)
00743 {
00744 SelectPalette(hdc,
00745 hPalette,
00746 0);
00747
00748 if (palette_change_request)
00749 {
00750 palette_change_request = 0;
00751 RealizePalette(hdc);
00752 }
00753 }
00754
00755
00756
00757
00758
00759 SetStretchBltMode(hdc, COLORONCOLOR);
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779 StretchDIBits(hdc,
00780 0,
00781 0,
00782 current_size_X,
00783 current_size_Y,
00784 0,
00785 0,
00786 current_size_X,
00787 current_size_Y,
00788 lpDIBBuffer,
00789 pbmi,
00790 DIB_RGB_COLORS,
00791 SRCCOPY);
00792
00793 ReleaseDC(hWnd, hdc);
00794 }
00795
00796
00797
00798
00799
00800
00801
00802 void DIB_flip_surface(void)
00803 {
00804
00805
00806
00807
00808 if (!SAL_is_app_active())
00809 {
00810 Sleep(10);
00811 }
00812 else
00813 {
00814 DIB_refresh_surface();
00815
00816 }
00817
00818 }
00819
00820 DXDEF void WINAPI SAL_blit_surface(void)
00821 {
00822 DIB_flip_surface();
00823 }
00824
00825
00826
00827
00828
00829
00830 void DIB_wipe_surface (S32 surface,
00831 U32 color)
00832 {
00833 memset(lpDIBBuffer,
00834 color,
00835 current_size_X * current_size_Y * (current_bpp / 8));
00836 }
00837
00838
00839
00840
00841
00842
00843
00844 void DIB_lock_surface (S32 surface,
00845 U8 **ptr,
00846 S32 *pitch)
00847 {
00848 if (ptr != NULL)
00849 {
00850 *ptr = lpDIBBuffer;
00851 }
00852
00853 if (pitch != NULL)
00854 {
00855 *pitch = current_size_X * (current_bpp / 8);
00856 }
00857 }
00858
00859
00860
00861
00862
00863
00864
00865 void DIB_release_surface (S32 surface,
00866 S32 perform_flip)
00867 {
00868 if (perform_flip)
00869 {
00870 SAL_flip_surface();
00871 }
00872 }
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886 DXDEF S32 WINAPI SAL_startup(BOOL FileLog)
00887 {
00888 log_to_file = FileLog;
00889 strcpy(debug_log_filename, "debug.txt");
00890
00891 app_active = FALSE;
00892 app_terminated = FALSE;
00893 app_minimized = FALSE;
00894
00895 show_count = 0;
00896 cursor_state = 1;
00897 constrain_state = 0;
00898 constrain_request = 0;
00899
00900 area.width = -1;
00901
00902 focus_callback = NULL;
00903 window_callback = NULL;
00904 hWnd = NULL;
00905 hHook = NULL;
00906 mode_change_request = FALSE;
00907 hSem = NULL;
00908
00909 DIB_active = FALSE;
00910
00911 mode_change_allowed = FALSE;
00912 current_window_mode = SAL_FULLSCREEN;
00913 current_bpp = 0;
00914 current_size_X = 0;
00915 current_size_Y = 0;
00916
00917 palette_change_request = FALSE;
00918
00919
00920
00921
00922 #ifndef DISABLED_BEHAVIOR
00923 GetClipCursor(&unconstrained_rect);
00924 #endif
00925
00926
00927
00928
00929
00930
00931
00932
00933 pLogPal = (LOGPALETTE *)
00934 malloc (sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256));
00935
00936 if (pLogPal == NULL)
00937 {
00938 return 0;
00939 }
00940
00941 memset(pLogPal,0, sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256));
00942
00943 pLogPal->palVersion = 0x300;
00944 pLogPal->palNumEntries = 256;
00945
00946 pbmi = (BITMAPINFO *)
00947 malloc(sizeof (BITMAPINFOHEADER) + (sizeof (RGBQUAD) * 256));
00948
00949 if (pbmi == NULL)
00950 {
00951 free(pLogPal);
00952 return 0;
00953 }
00954
00955 memset(pbmi, 0, sizeof (BITMAPINFOHEADER) + (sizeof (RGBQUAD) * 256));
00956
00957 pbmih = &(pbmi->bmiHeader);
00958
00959 return TRUE;
00960 }
00961
00962
00963
00964
00965
00966
00967
00968 DXDEF void WINAPI SAL_shutdown(void)
00969 {
00970
00971
00972
00973
00974
00975
00976 if (DIB_active)
00977 {
00978 DIB_shutdown();
00979 }
00980
00981 if (pbmi != NULL)
00982 {
00983 free(pbmi);
00984 pbmi = NULL;
00985 }
00986
00987 if (pLogPal != NULL)
00988 {
00989 free(pLogPal);
00990 pLogPal = NULL;
00991 }
00992 }
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003 DXDEF S32 WINAPI SAL_set_preference(U32 number, S32 value)
01004 {
01005 S32 old;
01006
01007 old = SAL_preference[number];
01008
01009 SAL_preference[number] = value;
01010
01011 return old;
01012 }
01013
01014
01015
01016
01017
01018
01019
01020 DXDEF S32 WINAPI SAL_get_preference(U32 number)
01021 {
01022 return SAL_preference[number];
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033 DXDEF void __cdecl SAL_debug_printf(char *fmt, ...)
01034 {
01035 static char work_string[4096];
01036 FILE *log;
01037
01038 if ((fmt == NULL) || (strlen(fmt) > sizeof(work_string)))
01039 {
01040 strcpy(work_string, "(String missing or too large)");
01041 }
01042 else
01043 {
01044 va_list ap;
01045
01046 va_start(ap,
01047 fmt);
01048
01049 vsprintf(work_string,
01050 fmt,
01051 ap);
01052
01053 va_end (ap);
01054 }
01055
01056 if (log_to_file)
01057 {
01058 log = fopen(debug_log_filename,"a+t");
01059
01060 if (log != NULL)
01061 {
01062 fprintf(log,"%s\n",work_string);
01063 fclose(log);
01064 }
01065 }
01066
01067 OutputDebugString(work_string);
01068 }
01069
01070
01071
01072
01073
01074
01075
01076 DXDEF void __cdecl SAL_error_box(C8 *caption, C8 *fmt, ...)
01077 {
01078 static char work_string[4096];
01079 S32 restore_cursor;
01080
01081 restore_cursor = cursor_state;
01082
01083 if (!cursor_state)
01084 {
01085 #ifndef DISABLED_BEHAVIOR
01086 ShowCursor(1);
01087 #endif
01088 }
01089
01090 if ((fmt == NULL) || (strlen(fmt) > sizeof(work_string)))
01091 {
01092 strcpy(work_string, "(String missing or too large)");
01093 }
01094 else
01095 {
01096 va_list ap;
01097
01098 va_start(ap,
01099 fmt);
01100
01101 vsprintf(work_string,
01102 fmt,
01103 ap);
01104
01105 va_end (ap);
01106 }
01107
01108 SAL_debug_printf("%s\n",work_string);
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118 if (caption == NULL)
01119 {
01120 MessageBox(hWnd,
01121 work_string,
01122 "SAL Error",
01123 MB_OK);
01124 }
01125 else
01126 {
01127 MessageBox(hWnd,
01128 work_string,
01129 caption,
01130 MB_OK);
01131 }
01132
01133 if (!restore_cursor)
01134 {
01135 #ifndef DISABLED_BEHAVIOR
01136 ShowCursor(0);
01137 #endif
01138 }
01139 }
01140
01141 DXDEF BOOL WINAPI SAL_set_main_window(HWND hWindow)
01142 {
01143 hWnd = hWindow;
01144
01145 app_active = TRUE;
01146
01147
01148
01149
01150
01151
01152 return TRUE;
01153 }
01154
01155
01156
01157
01158
01159
01160 DXDEF S32 WINAPI SAL_set_display_mode (S32 display_size_X,
01161 S32 display_size_Y,
01162 S32 display_bpp,
01163 S32 initial_window_mode,
01164 S32 allow_mode_switch)
01165 {
01166 S32 result;
01167
01168
01169
01170
01171
01172 if (DIB_active)
01173 {
01174 DIB_shutdown();
01175 }
01176
01177
01178
01179
01180
01181 if (show_count < 1)
01182 {
01183
01184
01185
01186
01187 if (cursor_state)
01188 {
01189 cursor_state = 0;
01190 #ifndef DISABLED_BEHAVIOR
01191 ShowCursor(0);
01192 #endif
01193
01194 }
01195 }
01196 else
01197 {
01198
01199
01200
01201
01202 if (!cursor_state)
01203 {
01204 cursor_state = 1;
01205 #ifndef DISABLED_BEHAVIOR
01206 ShowCursor(1);
01207 #endif
01208 }
01209 }
01210
01211
01212
01213
01214
01215 if (initial_window_mode == SAL_FULLSCREEN)
01216 {
01217
01218
01219
01220
01221 }
01222 else if (initial_window_mode == SAL_WINDOW)
01223 {
01224
01225
01226
01227
01228 result = DIB_startup(display_size_X,
01229 display_size_Y,
01230 display_bpp);
01231 }
01232 else if (initial_window_mode == SAL_TRY_FULLSCREEN)
01233 {
01234 assert(0);
01235
01236
01237
01238
01239
01240
01241 }
01242 else
01243 {
01244
01245
01246
01247
01248 return FALSE;
01249 }
01250
01251
01252
01253
01254
01255 if (result)
01256 {
01257 mode_change_allowed = allow_mode_switch;
01258 current_window_mode = initial_window_mode;
01259 current_bpp = display_bpp;
01260 current_size_X = display_size_X;
01261 current_size_Y = display_size_Y;
01262 }
01263
01264 return result;
01265 }
01266
01267
01268
01269
01270
01271
01272
01273 DXDEF S32 WINAPI SAL_window_status (void)
01274 {
01275 return current_window_mode;
01276 }
01277
01278
01279
01280
01281
01282
01283
01284 DXDEF void WINAPI SAL_client_area (SAL_WINAREA *area)
01285 {
01286 RECT *rect;
01287
01288 if (DIB_active)
01289 {
01290 rect = client_screen_rect();
01291
01292 area->x = rect->left;
01293 area->y = rect->top;
01294 area->width = rect->right - rect->left + 1;
01295 area->height = rect->bottom - rect->top + 1;
01296 }
01297
01298 }
01299
01300
01301
01302
01303
01304
01305
01306 DXDEF void WINAPI SAL_window_area (SAL_WINAREA *area)
01307 {
01308 RECT window_rect;
01309
01310 if (DIB_active)
01311 {
01312 GetWindowRect(hWnd, &window_rect);
01313
01314 area->x = window_rect.left;
01315 area->y = window_rect.top;
01316 area->width = window_rect.right - window_rect.left + 1;
01317 area->height = window_rect.bottom - window_rect.top + 1;
01318 }
01319
01320 }
01321
01322
01323
01324
01325
01326
01327
01328 DXDEF S32 WINAPI SAL_is_app_active (void)
01329 {
01330 return app_active;
01331 }
01332
01333
01334
01335
01336
01337
01338
01339 DXDEF SALFOCUSCB WINAPI SAL_register_focus_callback (SALFOCUSCB fn)
01340 {
01341 SALFOCUSCB old;
01342
01343 old = focus_callback;
01344
01345 focus_callback = fn;
01346
01347 return old;
01348 }
01349
01350
01351
01352
01353
01354
01355
01356 DXDEF WNDPROC WINAPI SAL_register_WNDPROC (WNDPROC fn)
01357 {
01358 WNDPROC old;
01359
01360 old = window_callback;
01361
01362 window_callback = fn;
01363
01364 return old;
01365 }
01366
01367
01368
01369
01370
01371
01372
01373 DXDEF void WINAPI SAL_serve_message_queue(void)
01374 {
01375 S32 result;
01376
01377 serve_queue();
01378
01379 if (mode_change_request && mode_change_allowed)
01380 {
01381 mode_change_request = 0;
01382
01383 result = SAL_set_display_mode(
01384 current_size_X,
01385 current_size_Y,
01386 current_bpp,
01387 current_window_mode ^ (SAL_FULLSCREEN ^ SAL_WINDOW),
01388 TRUE);
01389
01390
01391
01392
01393
01394 if (!result)
01395 {
01396 SAL_debug_printf("SAL: SAL_set_display_mode() failed, restoring old mode\n");
01397
01398 SAL_set_display_mode(
01399 current_size_X,
01400 current_size_Y,
01401 current_bpp,
01402 current_window_mode,
01403 TRUE);
01404 }
01405 }
01406 }
01407
01408
01409
01410
01411
01412
01413
01414 DXDEF void WINAPI SAL_set_palette_entry (S32 index,
01415 SAL_RGB32 *entry,
01416 S32 wait_flag)
01417 {
01418
01419
01420
01421
01422 if (current_bpp != 8)
01423 {
01424 return;
01425 }
01426
01427
01428
01429
01430
01431 palette_state[index] = *entry;
01432
01433 pLogPal->palPalEntry[index].peRed = pbmi->bmiColors[index].rgbRed = (unsigned char) entry->r;
01434 pLogPal->palPalEntry[index].peGreen = pbmi->bmiColors[index].rgbGreen = (unsigned char) entry->g;
01435 pLogPal->palPalEntry[index].peBlue = pbmi->bmiColors[index].rgbBlue = (unsigned char) entry->b;
01436 pLogPal->palPalEntry[index].peFlags = NULL;
01437
01438
01439
01440
01441
01442
01443 if (DIB_active)
01444 {
01445 if (hPalette != NULL)
01446 {
01447 DeleteObject(hPalette);
01448 }
01449
01450 hPalette = CreatePalette(pLogPal);
01451
01452 palette_change_request = TRUE;
01453 }
01454 }
01455
01456
01457
01458
01459
01460
01461
01462 DXDEF void WINAPI SAL_get_palette_entry (S32 index,
01463 SAL_RGB32 *entry)
01464 {
01465 *entry = palette_state[index];
01466 }
01467
01468
01469
01470
01471
01472
01473
01474 DXDEF void WINAPI SAL_set_palette_range (S32 index,
01475 S32 num_entries,
01476 SAL_RGB32 *entry_list,
01477 S32 wait_flag)
01478 {
01479 S32 i;
01480 S32 j;
01481
01482
01483
01484
01485
01486 if (current_bpp != 8)
01487 {
01488 return;
01489 }
01490
01491
01492
01493
01494
01495 for (i=0; i < num_entries; i++)
01496 {
01497 palette_state[index+i] = entry_list[i];
01498 }
01499
01500 for (i=0, j=index; i < num_entries; i++, j++)
01501 {
01502 pLogPal->palPalEntry[j].peRed = pbmi->bmiColors[j].rgbRed = (unsigned char) entry_list[i].r;
01503 pLogPal->palPalEntry[j].peGreen = pbmi->bmiColors[j].rgbGreen = (unsigned char) entry_list[i].g;
01504 pLogPal->palPalEntry[j].peBlue = pbmi->bmiColors[j].rgbBlue = (unsigned char) entry_list[i].b;
01505 pLogPal->palPalEntry[j].peFlags = NULL;
01506 }
01507
01508
01509
01510
01511
01512
01513 if (DIB_active)
01514 {
01515 if (hPalette != NULL)
01516 {
01517 DeleteObject(hPalette);
01518 }
01519
01520 hPalette = CreatePalette(pLogPal);
01521
01522 palette_change_request = TRUE;
01523 }
01524 }
01525
01526
01527
01528
01529
01530
01531
01532 DXDEF void WINAPI SAL_get_palette_range (S32 index,
01533 S32 num_entries,
01534 SAL_RGB32 *entry_list)
01535 {
01536 for (int i=0; i < num_entries; i++)
01537 {
01538 entry_list[i] = palette_state[index+i];
01539 }
01540 }
01541
01542
01543
01544
01545
01546
01547
01548 DXDEF void WINAPI SAL_flip_surface (void)
01549 {
01550 if (DIB_active)
01551 {
01552 DIB_flip_surface();
01553 }
01554 }
01555
01556
01557
01558
01559
01560
01561
01562 DXDEF void WINAPI SAL_wipe_surface (S32 surface,
01563 U32 color)
01564 {
01565 if (DIB_active)
01566 {
01567 DIB_wipe_surface(surface, color);
01568 }
01569 }
01570
01571
01572
01573
01574
01575
01576
01577 DXDEF void WINAPI SAL_lock_surface (S32 surface,
01578 U8 **ptr,
01579 S32 *pitch)
01580 {
01581 if (DIB_active)
01582 {
01583 DIB_lock_surface(surface, ptr, pitch);
01584 }
01585 }
01586
01587
01588
01589
01590
01591
01592
01593 DXDEF void WINAPI SAL_release_surface (S32 surface,
01594 S32 perform_flip)
01595 {
01596 if (DIB_active)
01597 {
01598 DIB_release_surface(surface, perform_flip);
01599 }
01600 }
01601
01602
01603
01604
01605
01606
01607
01608 DXDEF void WINAPI SAL_lock_region (S32 surface,
01609 SAL_REGION region,
01610 U8 **ptr,
01611 S32 *pitch)
01612 {
01613
01614 }
01615
01616
01617
01618
01619
01620
01621
01622 DXDEF void WINAPI SAL_release_region (S32 surface,
01623 SAL_REGION region)
01624 {
01625 }
01626
01627
01628
01629
01630
01631
01632
01633 DXDEF void WINAPI SAL_show_system_mouse (void)
01634 {
01635 ++show_count;
01636
01637 if (show_count == 1)
01638 {
01639
01640
01641
01642
01643
01644 if (!cursor_state)
01645 {
01646 cursor_state = 1;
01647 #ifndef DISABLED_BEHAVIOR
01648 ShowCursor(1);
01649 #endif
01650 }
01651 }
01652 }
01653
01654
01655
01656
01657
01658
01659
01660 DXDEF void WINAPI SAL_hide_system_mouse (void)
01661 {
01662 --show_count;
01663
01664 if (show_count == 0)
01665 {
01666
01667
01668
01669
01670
01671 if (cursor_state)
01672 {
01673 cursor_state = 0;
01674 #ifndef DISABLED_BEHAVIOR
01675 ShowCursor(0);
01676 #endif
01677 }
01678 }
01679 }
01680
01681
01682
01683
01684
01685
01686
01687 DXDEF void WINAPI SAL_constrain_mouse(void)
01688 {
01689 constrain_state = 1;
01690
01691 if (DIB_active)
01692 {
01693 constrain_request = 1;
01694 }
01695 }
01696
01697
01698
01699
01700
01701
01702
01703 DXDEF void WINAPI SAL_unconstrain_mouse(void)
01704 {
01705 constrain_state = 0;
01706
01707 if (DIB_active)
01708 {
01709 #ifndef DISABLED_BEHAVIOR
01710 ClipCursor(&unconstrained_rect);
01711 #endif
01712 constrain_request = 0;
01713 }
01714 }
01715
01716
01717
01718
01719
01720
01721
01722 DXDEF void WINAPI SAL_get_pixel_format(S32 *pixel_pitch,
01723 S32 *bytes_per_pixel,
01724 S32 *R_shift,
01725 U32 *R_mask,
01726 S32 *R_width,
01727 S32 *G_shift,
01728 U32 *G_mask,
01729 S32 *G_width,
01730 S32 *B_shift,
01731 U32 *B_mask,
01732 S32 *B_width)
01733
01734 {
01735 S32 red_shift;
01736 U32 red_mask;
01737 S32 red_width;
01738 S32 grn_shift;
01739 U32 grn_mask;
01740 S32 grn_width;
01741 S32 blu_shift;
01742 U32 blu_mask;
01743 S32 blu_width;
01744 S32 i;
01745
01746
01747
01748
01749
01750
01751
01752
01753 if (current_bpp == 8)
01754 {
01755 if (pixel_pitch != NULL) *pixel_pitch = 1;
01756 if (bytes_per_pixel != NULL) *bytes_per_pixel = 1;
01757
01758 return;
01759 }
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769 if (DIB_active)
01770 {
01771 if (pixel_pitch != NULL) *pixel_pitch = (current_bpp / 8);
01772 if (bytes_per_pixel != NULL) *bytes_per_pixel = (current_bpp / 8);
01773
01774 red_mask = DIB_R_bitmask;
01775 grn_mask = DIB_G_bitmask;
01776 blu_mask = DIB_B_bitmask;
01777 }
01778
01779
01780
01781
01782
01783 for (i=31; i >= 0; i--)
01784 {
01785 if (red_mask & (1 << i))
01786 {
01787 red_shift = i;
01788 }
01789
01790 if (grn_mask & (1 << i))
01791 {
01792 grn_shift = i;
01793 }
01794
01795 if (blu_mask & (1 << i))
01796 {
01797 blu_shift = i;
01798 }
01799 }
01800
01801 for (i=0; i <= 31; i++)
01802 {
01803 if (red_mask & (1 << i))
01804 {
01805 red_width = i - red_shift + 1;
01806 }
01807
01808 if (grn_mask & (1 << i))
01809 {
01810 grn_width = i - grn_shift + 1;
01811 }
01812
01813 if (blu_mask & (1 << i))
01814 {
01815 blu_width = i - blu_shift + 1;
01816 }
01817 }
01818
01819
01820
01821
01822 if (R_shift != NULL) *R_shift = red_shift;
01823 if (G_shift != NULL) *G_shift = grn_shift;
01824 if (B_shift != NULL) *B_shift = blu_shift;
01825
01826 if (R_mask != NULL) *R_mask = red_mask;
01827 if (G_mask != NULL) *G_mask = grn_mask;
01828 if (B_mask != NULL) *B_mask = blu_mask;
01829
01830 if (R_width != NULL) *R_width = red_width;
01831 if (G_width != NULL) *G_width = grn_width;
01832 if (B_width != NULL) *B_width = blu_width;
01833 }
01834
01835 DXDEF HBITMAP WINAPI GetDIBHandle(void)
01836 {
01837 return hDIB;
01838 }
01839
01840 DXDEF void WINAPI SAL_GetBackBufferDC(HDC *dc)
01841 {
01842 if (DIB_active)
01843 {
01844 *dc = CreateCompatibleDC ( 0 );
01845 DefaultBitmap = SelectBitmap ( *dc, hDIB );
01846 }
01847 }
01848
01849 DXDEF void WINAPI SAL_ReleaseBackBufferDC(HDC dc)
01850 {
01851
01852 if (DIB_active)
01853 {
01854 SelectBitmap ( dc, DefaultBitmap );
01855 DeleteDC ( dc );
01856 DeleteObject ( DefaultBitmap );
01857 }
01858 }