OVGALOCK.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. // Filename : OVGALOCK.CPP
  21. // Description : object to vga_front.temp_unlock and temp_restore_lock
  22. // Onwer : Gilbert Luis
  23. // Mainly used by ODPLAY.CPP to separate OVGA.H
  24. // some GUID initialization problems exist if OVGA.H is included in ODPLAY.CPP
  25. #include <OSYS.h>
  26. #include <OVGALOCK.h>
  27. #include <OVGABUF.h>
  28. #include <OVGA.h>
  29. #include <OFILE.h>
  30. #include <OMOUSE.h>
  31. VgaFrontLock::VgaFrontLock()
  32. {
  33. vga_front.temp_unlock();
  34. }
  35. VgaFrontLock::~VgaFrontLock()
  36. {
  37. vga_front.temp_restore_lock();
  38. }
  39. void VgaFrontLock::re_lock()
  40. {
  41. vga_front.temp_restore_lock();
  42. }
  43. void VgaFrontLock::re_unlock()
  44. {
  45. vga_front.temp_unlock();
  46. }
  47. VgaCustomPalette::VgaCustomPalette(char *fileName)
  48. {
  49. backup_pal = NULL;
  50. if( save_palette() && fileName)
  51. set_custom_palette(fileName);
  52. }
  53. VgaCustomPalette::~VgaCustomPalette()
  54. {
  55. restore_palette();
  56. if( backup_pal)
  57. mem_del(backup_pal);
  58. }
  59. int VgaCustomPalette::save_palette()
  60. {
  61. // ------ allocate space --------//
  62. if( !backup_pal )
  63. backup_pal = mem_add( sizeof(PALETTEENTRY) * 256);
  64. // ------- get current palette --------//
  65. if( vga.dd_pal->GetEntries(0, 0, 256, (PALETTEENTRY *)backup_pal) )
  66. {
  67. // get palette fail, free backup_pal to indicate save_palette failed
  68. mem_del(backup_pal);
  69. backup_pal = NULL;
  70. return 0;
  71. }
  72. else
  73. return 1;
  74. }
  75. int VgaCustomPalette::set_custom_palette(char *fileName)
  76. {
  77. PALETTEENTRY palEntry[256];
  78. char palBuf[256][3];
  79. File palFile;
  80. palFile.file_open(fileName);
  81. palFile.file_seek(8); // bypass the header info
  82. palFile.file_read(palBuf, 256*3);
  83. palFile.file_close();
  84. for(int i=0; i<256; i++)
  85. {
  86. palEntry[i].peRed = palBuf[i][0];
  87. palEntry[i].peGreen = palBuf[i][1];
  88. palEntry[i].peBlue = palBuf[i][2];
  89. palEntry[i].peFlags = 0;
  90. }
  91. return !vga.dd_pal->SetEntries(0, 0, 256, palEntry);
  92. }
  93. int VgaCustomPalette::restore_palette()
  94. {
  95. if( backup_pal)
  96. return !vga.dd_pal->SetEntries(0, 0, 256, (PALETTEENTRY *)backup_pal);
  97. else
  98. return 1;
  99. }
  100. MouseDispCount::MouseDispCount()
  101. {
  102. // set cursor position
  103. SetCursorPos( mouse.cur_x, mouse.cur_y);
  104. // show cursor
  105. mouse.hide();
  106. // #### patch begin Gilbert 9/1 #######//
  107. vga_front.temp_unlock();
  108. // #### patch end Gilbert 9/1 #######//
  109. ShowCursor(TRUE);
  110. }
  111. MouseDispCount::~MouseDispCount()
  112. {
  113. // set cursor position
  114. POINT winMousePos;
  115. GetCursorPos(&winMousePos);
  116. mouse.cur_x = winMousePos.x;
  117. mouse.cur_y = winMousePos.y;
  118. // hide cursor
  119. ShowCursor(FALSE);
  120. // #### patch begin Gilbert 9/1 #######//
  121. vga_front.temp_restore_lock();
  122. // #### patch end Gilbert 9/1 #######//
  123. mouse.show();
  124. int ev = mouse.get_event();
  125. ev = mouse.get_event();
  126. }