PAGFAULT.ASM 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 A S S O C I A T E S **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Library *
  23. ;* *
  24. ;* File Name : PAGFAULT.ASM *
  25. ;* *
  26. ;* Programmer : Julio R Jerez *
  27. ;* *
  28. ;* Date : April 25,1995 *
  29. ;* *
  30. ;*-------------------------------------------------------------------------*
  31. ;* Functions: *
  32. ;
  33. ; Here are prototypes for the routines defined within this module:
  34. ; VOID Install_Page_Fault_Handle (void) ;
  35. ;
  36. ; ----------------------------------------------------------------
  37. IDEAL ; the product runs in ideal mode
  38. P386 ; use 386 real mode instructions
  39. MODEL USE32 FLAT
  40. LOCALS ?? ; ?? is the symbol for a local
  41. WARN ; generate all warnings we can
  42. JUMPS ; optimize jumps if possible
  43. ;---------------------------------------------------------------------------
  44. ; Make some general equates for easy compatability
  45. ;---------------------------------------------------------------------------
  46. DPMI_INTR EQU 31h
  47. PAGE_FAULT equ 0eh
  48. RESET_VIDEO_MODE equ -1
  49. GLOBAL Install_Page_Fault_Handle : NEAR
  50. GLOBAL Set_Video_Mode : NEAR
  51. GLOBAL Remove_Mouse : NEAR
  52. GLOBAL Remove_Keyboard_Interrupt : NEAR
  53. GLOBAL Remove_Timer_Interrupt : NEAR
  54. DATASEG
  55. Old_Page_Fault_handle DF ?
  56. Page_Fault_SS DD ?
  57. Page_Fault_ESP DD ?
  58. CODESEG
  59. ;***************************************************************************
  60. ;* INSTALL_PAGE_FAULT_HANDLE -- Installs new page fault handle *
  61. ;* This function will install a new page fault handle *
  62. ;* so in the event that we have a program crash thi handle will *
  63. ;* remove all interrupts and then will chain to the default Page *
  64. ;* Fault handle *
  65. ;* *
  66. ;* INPUT: none *
  67. ;* *
  68. ;* *
  69. ;* OUTPUT: none *
  70. ;* *
  71. ;* PROTO: VOID Install_Page_Fault_Handle( void); *
  72. ;* *
  73. ;* HISTORY: 04/25/96 Created *
  74. ;*=========================================================================*
  75. PROC Install_Page_Fault_Handle C NEAR
  76. USES eax,ebx,ecx,edx,esi,edi
  77. mov eax,0202h ; get address of exception handle
  78. mov bl,PAGE_FAULT
  79. int DPMI_INTR
  80. jc ??exit ; not action is taken
  81. ; save addrees of default handle
  82. mov [dword ptr Old_Page_Fault_handle],edx
  83. mov [word ptr Old_Page_Fault_handle+4],cx
  84. ; redirect default handle to a new Page Fault Handle
  85. mov eax,0203h
  86. mov bl,PAGE_FAULT
  87. mov cx,cs
  88. lea edx,[Page_Fault_Handle]
  89. int DPMI_INTR
  90. ??exit:
  91. ret
  92. ENDP Install_Page_Fault_Handle
  93. ;***************************************************************************
  94. ;* PAGE_FAULT_HANDLE -- This *
  95. ;* *
  96. ;* *
  97. ;* *
  98. ;* HISTORY: 04/25/96 Created *
  99. ;*=========================================================================*
  100. PROC Page_Fault_Handle far
  101. ; preserve used registers
  102. push eax
  103. push ebx
  104. ; save Page Fault satck frame
  105. mov ax,ss
  106. mov [Page_Fault_SS],eax
  107. mov [Page_Fault_ESP],esp
  108. ; retrieve application original stack frame
  109. mov eax , [ esp + ( 6 + 2 ) * 4 ]
  110. mov ebx , [ esp + ( 7 + 2 ) * 4 ]
  111. mov ss , bx
  112. mov esp , eax
  113. ; set video mode to standard text mode
  114. push RESET_VIDEO_MODE
  115. call Set_Video_Mode
  116. pop eax
  117. call Remove_Mouse
  118. call Remove_Keyboard_Interrupt
  119. call Remove_Timer_Interrupt
  120. ; restore Page Fault stack frame
  121. mov eax,[Page_Fault_SS]
  122. mov ss , ax
  123. mov esp, [Page_Fault_ESP]
  124. ; restore used registers and chain to default Page Fault Handle
  125. pop ebx
  126. pop eax
  127. jmp [fword Old_Page_Fault_handle]
  128. ENDP Page_Fault_Handle
  129. ;***************************************************************************
  130. ;* End of File. *
  131. ;***************************************************************************
  132. END