VESAHOOK.ASM 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. ;
  2. ; Command & Conquer Red Alert(tm)
  3. ; Copyright 2025 Electronic Arts Inc.
  4. ;
  5. ; This program is free software: you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation, either version 3 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;
  18. ;***************************************************************************
  19. ;** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Vesa Hookup *
  23. ;* *
  24. ;* *
  25. ;* Programmer : Julio R. Jerez *
  26. ;* *
  27. ;* Start Date : Jan 31, 1995 *
  28. ;* *
  29. ;* *
  30. ;*-------------------------------------------------------------------------*
  31. IDEAL
  32. P386
  33. MODEL USE32 FLAT
  34. INCLUDE "svgaprim.inc"
  35. DPMI_INTR equ 031h
  36. LOCALS ??
  37. ;//////////////////////////////////////////////////////////////////////////////////////
  38. ;/////////////////////////////////// Prototypes //////////////////////////////////////
  39. GLOBAL RMVesaVector : DWORD
  40. GLOBAL RMVesaRegs : DWORD
  41. GLOBAL RMVesaVectorSel : DWORD
  42. GLOBAL Vesa_Hook : NEAR
  43. GLOBAL Remove_Vesa : NEAR
  44. GLOBAL VesaFunc : dword
  45. ;//////////////////////////////////////////////////////////////////////////////////////
  46. ;//////////////////////////////////////// Data ////////////////////////////////////////
  47. DATASEG
  48. ; The current time we will just include the real mode stuff
  49. ; into the protected mode code and then copy it down. The C side of
  50. ; this will handle this method or reading it off of disk in the real
  51. ; method.
  52. LABEL RealDataStart BYTE
  53. include "VesaReal.ibn"
  54. LABEL RealDataEnd BYTE
  55. RMVesaVectorSel DD 0
  56. ;//////////////////////////////////////////////////////////////////////////////////////
  57. ;//////////////////////////////////////// Code ////////////////////////////////////////
  58. CODESEG
  59. PROC Vesa_Hook C Near
  60. USES ebx,ecx,edx,ecx,edi,esi
  61. ARG vesa_ptr:DWORD
  62. ; Are they attempting to set timer again?
  63. cmp [RMVesaVectorSel],0
  64. jnz ??exit
  65. ; now allocate real mode memory and copy the rm binary down to it.
  66. mov eax,0100h ; set function number
  67. lea ebx , [RealDataEnd]
  68. sub ebx , offset RealDataStart
  69. push ebx
  70. add ebx , 15 + 040h
  71. shr ebx,4 ; convert to pages.
  72. int DPMI_INTR ; do call.
  73. pop ecx
  74. jc ??error ; check for error.
  75. ; set up source and destination pointers for the copy.
  76. shl edx , 16
  77. mov [ RMVesaVectorSel ] , edx
  78. shl eax,4 ; convert segment to offset.
  79. mov edi , ecx
  80. xor esi , esi
  81. ; push ecx
  82. ; push eax
  83. ; mov ecx , eax
  84. ; shld ebx,ecx,16
  85. ; mov eax,0600h ; function number.
  86. ; int DPMI_INTR ; do call.
  87. ; pop eax
  88. ; pop ecx
  89. ; jc ??error ; eax = 8 if mem err, eax = 9 if invalid mem region.
  90. lea esi , [ RealDataStart]
  91. lea edi , [ eax + 040h ] ; put it into esi for copy.
  92. rep movsb ; write RM bin to RM memory.
  93. mov edx,[vesa_ptr] ; Setup vesa funtion
  94. mov [ eax + 40h - 4 ] , edx
  95. ; Chain the Real Vesa funcion interrupt to any avilable
  96. ; Interrupt vector so We make sure that the Real Mode
  97. ; Keyboard Interrupt service get called at debuging time
  98. ; of the library.
  99. mov [ RMVesaRegs ] , eax
  100. shl eax , 12
  101. lea edi , [ eax + 040h ] ; ofsset of VesaFunc
  102. mov bl , 060h
  103. mov bh , 6
  104. mov eax , 200h
  105. ??find:
  106. int DPMI_INTR
  107. jc ??error
  108. or cx,dx
  109. jz ??found
  110. inc bl
  111. dec bh
  112. jnz ??find
  113. jmp ??error
  114. ??found:
  115. mov eax , 0201h
  116. mov edx , edi
  117. shld ecx , edx , 16
  118. and ebx , 0ffh
  119. mov [ RMVesaVector ] , ebx
  120. int DPMI_INTR
  121. jc ??error
  122. ??exit:
  123. xor eax,eax ; signal an error.
  124. ret
  125. ??error:
  126. mov eax , -1
  127. ret
  128. ENDP
  129. PROC Remove_Vesa C Near
  130. USES ebx,ecx,edx,ecx,edi,esi
  131. ARG vesa_ptr:DWORD
  132. ; Are they attempting to set timer again?
  133. mov [VesaFunc],0
  134. cmp [RMVesaVectorSel],0
  135. jz ??exit
  136. mov ebx , [ RMVesaVector ]
  137. test ebx , ebx
  138. jz ??exit
  139. mov eax , 0201h
  140. xor edx , edx
  141. xor ecx , ecx
  142. int DPMI_INTR
  143. mov [ RMVesaVector ] , 0
  144. jc ??exit
  145. ; mov eax , 0601h
  146. ; mov ecx , [ RMVesaRegs ]
  147. ; shld ebx , ecx , 16
  148. ; lea edi , [RealDataEnd]
  149. ; sub edi , offset RealDataStart
  150. ; add edi , 15 + 040h
  151. ; xor esi , esi
  152. ; int DPMI_INTR
  153. ; jc ??exit
  154. mov eax,0101h ; set function number
  155. mov edx ,[RMVesaVectorSel]
  156. test edx , edx
  157. jz ??exit
  158. shr edx , 16
  159. int DPMI_INTR ; do call.
  160. mov [RMVesaVectorSel],0
  161. ??exit:
  162. ret
  163. ENDP
  164. END