IPXREAL.ASM 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 : VQLIB *
  23. ;* *
  24. ;* File Name : HANDLER.ASM *
  25. ;* *
  26. ;* Programmer : Bill Randolph *
  27. ;* *
  28. ;* Start Date : April 7, 1995 *
  29. ;* *
  30. ;* Last Update : April 7, 1995 [BRR] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* IPXHandler -- callback routine for IPX *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. ;********************* Model & Processor Directives ************************
  37. IDEAL
  38. MODEL LARGE
  39. P386N
  40. LOCALS ??
  41. ;******************************** Includes *********************************
  42. ;******************************** Defines ***********************************
  43. ;****************************** Declarations ********************************
  44. GLOBAL IPXHandler:FAR
  45. ;********************************* Code ************************************
  46. CODESEG
  47. ;---------------------------------------------------------------------------
  48. ; The markers let the application verify that it's mapping this memory
  49. ; correctly.
  50. ;---------------------------------------------------------------------------
  51. Marker1 DW 1111h ; placeholder to find data start
  52. ;---------------------------------------------------------------------------
  53. ; This is the IPX Event Control Block:
  54. ;---------------------------------------------------------------------------
  55. ECB_LinkAddress DD ?
  56. ECB_EventServiceRoutine DD ? ; Event Handler ptr
  57. ECB_InUse DB ? ; 0 = event is complete
  58. ECB_CompletionCode DB ? ; 0 = OK, IPX error otherwise
  59. ECB_SocketNumber DW ? ; socket to listen/send on
  60. ECB_ConnectionID DW ?
  61. ECB_RestOfWorkspace DW ?
  62. ECB_DriverWorkSpace DB 12 DUP (?)
  63. ECB_ImmediateAddress DB 6 DUP (?) ; bridge address
  64. ECB_PacketCount DW ? ; # data areas (2)
  65. ECB_HeaderAddress DD ? ; ptr to IPX header buffer
  66. ECB_HeaderLength DW ? ; length of IPX header buffer
  67. ECB_PacketAddress DD ? ; ptr to packet buffer
  68. ECB_PacketLength DW ? ; length of packet buffer
  69. ;---------------------------------------------------------------------------
  70. ; The rest of the variables are for telling IPX which buffer to store the
  71. ; next incoming packet in. They must be initialized by the application.
  72. ;---------------------------------------------------------------------------
  73. NumBufs DW 0 ; # buffers provided by app
  74. BufferFlags DD 0 ; array of in-use flags (1 = in use)
  75. PacketSize DW 0 ; total size of 1 buf (incl IPX hdr)
  76. FirstPacketBuf DD 0 ; ptr to 1st packet buffer
  77. CurIndex DW 0 ; current packet/flag index
  78. CurPacketBuf DD 0 ; ptr to current packet buf
  79. FuncOffset DW StartLabel ; offset of our routine
  80. ;---------------------------------------------------------------------------
  81. ; These values are for preventing re-entrancy; they're currently not used.
  82. ;---------------------------------------------------------------------------
  83. Semaphore DB 0 ; prevents re-entrancy
  84. ReEntrantCount DW 0 ; times we've been called re-entrantly
  85. ;---------------------------------------------------------------------------
  86. ; Local stack space
  87. ;---------------------------------------------------------------------------
  88. StackPtr DW 0 ; saved copy of stack ptr
  89. StackSeg DW 0 ; saved copy of stack seg
  90. StackPtr_int DW 0 ; our internal stack ptr
  91. StackSeg_int DW 0 ; our internal stack seg
  92. StackCheck DW 1234h ; check for stack overflow
  93. DW 256 DUP (0) ; stack storage space
  94. StackSpace DW 0 ; label for our stack space
  95. ;---------------------------------------------------------------------------
  96. ; These bytes mark the end of the real-mode data area
  97. ;---------------------------------------------------------------------------
  98. Marker2 DW 2222h ; placeholder to find data end
  99. ;***************************************************************************
  100. ;* IPXHandler -- IPX callback routine *
  101. ;* *
  102. ;* This routine is assembled as a stand-alone executable, then loaded *
  103. ;* into low DOS memory by a protected-mode application. *
  104. ;* *
  105. ;* INPUT: *
  106. ;* none. *
  107. ;* *
  108. ;* OUTPUT: *
  109. ;* none. *
  110. ;* *
  111. ;* WARNINGS: *
  112. ;* none. *
  113. ;* *
  114. ;* HISTORY: *
  115. ;* 04/07/1995 BRR : Created. *
  116. ;*=========================================================================*
  117. label StartLabel
  118. PROC IPXHandler C FAR USES
  119. ;...................................................................
  120. ; Turn off interrupts; make sure memory copies go forward
  121. ;...................................................................
  122. pushf
  123. cli
  124. cld
  125. ;...................................................................
  126. ; Set up segment registers to point DS to CS
  127. ;...................................................................
  128. push ds
  129. push ax
  130. mov ax,cs
  131. mov ds,ax
  132. ;...................................................................
  133. ; Set up our local stack; save SS & SP first.
  134. ;...................................................................
  135. mov [StackSeg],ss
  136. mov [StackPtr],sp
  137. mov [StackPtr_int], OFFSET StackSpace
  138. mov [StackSeg_int], SEG StackSpace
  139. lss sp, [DWORD PTR StackPtr_int]
  140. ;...................................................................
  141. ; Save all registers
  142. ;...................................................................
  143. pushad
  144. push es
  145. ;...................................................................
  146. ; If we've been called re-entrantly, just exit
  147. ;...................................................................
  148. cmp [Semaphore],0
  149. jz ??Start_Handler
  150. add [ReEntrantCount],1
  151. jmp ??Exit_Handler
  152. ??Start_Handler:
  153. ;...................................................................
  154. ; Set our semaphore
  155. ;...................................................................
  156. mov [Semaphore],1
  157. ;-------------------------------------------------------------------
  158. ; Set 'CurIndex' to the index of the next-available receive buffer,
  159. ; and 'CurPacketBuf to the next-available packet buffer
  160. ;-------------------------------------------------------------------
  161. ;...................................................................
  162. ; Get 'CurIndex' & increment it. Wrap to 0 if we reach 'NumBufs'
  163. ; Since I'm treating 'CurPacketBuf' as a long integer (and not as
  164. ; a segment:offset), the entire data area can't be larger than 64K.
  165. ;...................................................................
  166. mov dx,[CurIndex] ; DX = CurIndex
  167. mov eax,[CurPacketBuf] ; EAX = current packet buffer addr
  168. inc dx ; DX = next index
  169. add ax,[PacketSize] ; EAX = next buffer ptr
  170. cmp dx,[NumBufs] ; see if DX is past # buffers
  171. jb ??Get_Flag
  172. mov dx,0 ; wrap to 1st index
  173. mov eax,[FirstPacketBuf] ; wrap to 1st packet buffer
  174. ??Get_Flag:
  175. ;...................................................................
  176. ; Get the next buffer-in-use flag; if it's 0, load [CurIndex] with
  177. ; the value of SI (the next index). If it's 1, skip the updating of
  178. ; the index, flag & buffer ptr.
  179. ; DX = new CurIndex
  180. ; EAX = new CurPacketBuf
  181. ;...................................................................
  182. les di,[BufferFlags] ; ES:DI = BufferFlags address
  183. mov bx,di ; BX = DI + new CurIndex
  184. add bx,dx
  185. cmp [BYTE PTR es:bx],0 ; compare next flag to 0 (avail)
  186. jne ??Set_ECB ; if not avail, skip setting new values
  187. ;...................................................................
  188. ; The next buffer is available; so, set this buffer's In-Use flag
  189. ; to 1, and move on to the next buffer. Do not set this buffer's
  190. ; flag to 1 until we move on to the next buffer, to prevent the
  191. ; application from reading the currently-in-use packet buffer.
  192. ; DX = new CurIndex
  193. ; EAX = new CurPacketBuf
  194. ; ES:DI = BufferFlags address
  195. ;...................................................................
  196. mov bx,di ; BX = DI + old CurIndex
  197. add bx,[CurIndex]
  198. mov [BYTE PTR es:bx],1 ; set old BufferFlags value to in-use
  199. mov [CurIndex],dx ; save new index
  200. mov [CurPacketBuf],eax ; save new packet address
  201. ;-------------------------------------------------------------------
  202. ; Set up the Event Control Block to tell IPX to start listening.
  203. ; The following entries are filled in by the app, and should be left
  204. ; alone:
  205. ; - EventServiceRoutine
  206. ; - SocketNumber
  207. ; The rest should be re-initialized. Note that EBX is now pointing
  208. ; to an unavailable buffer if the next buffer was already in use;
  209. ; so it must be reloaded with the correct buffer address from
  210. ; [CurPacketBuf].
  211. ;-------------------------------------------------------------------
  212. ??Set_ECB:
  213. mov [ECB_LinkAddress],0 ; default
  214. mov [ECB_InUse],0 ; default
  215. mov [ECB_CompletionCode],0 ; default
  216. mov [ECB_ConnectionID],0 ; default
  217. mov [ECB_RestOfWorkspace],0 ; default
  218. mov [ECB_DriverWorkSpace],0 ; default
  219. mov [ECB_ImmediateAddress],0 ; default
  220. mov [ECB_PacketCount],2 ; use 2 data areas
  221. mov ebx,[CurPacketBuf] ; get current buffer address
  222. mov [ECB_HeaderAddress],ebx ; set header address
  223. mov [ECB_HeaderLength],30 ; size of IPX header
  224. add ebx,30 ; point to past the header
  225. mov [ECB_PacketAddress],ebx ; set packet data address
  226. mov ax,[PacketSize] ; get size of one buffer
  227. sub ax,30 ; remove size of IPX header
  228. mov [ECB_PacketLength],ax ; set size of packet data
  229. ;-------------------------------------------------------------------
  230. ; Clear the IPX header for this packet
  231. ;-------------------------------------------------------------------
  232. les di,[ECB_HeaderAddress] ; ES:DI = IPX Listen Header
  233. mov cx,30 ; (30 bytes = size of header)
  234. mov al,0
  235. rep stosb ; clear to 0's
  236. ;-------------------------------------------------------------------
  237. ; Command IPX to start listening again.
  238. ;-------------------------------------------------------------------
  239. mov bx,4 ; IPX code for Listen
  240. mov ax,ds ; ES = segment of ListenECB
  241. mov es,ax
  242. mov ax,OFFSET ECB_LinkAddress
  243. mov si,ax ; ES:SI = address of ECB
  244. int 07ah ; call IPX interrupt
  245. ;...................................................................
  246. ; Clear our semaphore
  247. ;...................................................................
  248. mov [Semaphore],0
  249. ??Exit_Handler:
  250. ;...................................................................
  251. ; Pop values from our local stack
  252. ;...................................................................
  253. pop es
  254. popad
  255. ;...................................................................
  256. ; Check our stack-check value; if the stack has overflowed, generate
  257. ; a debugger break.
  258. ;...................................................................
  259. cmp [StackCheck],1234h
  260. je ??Restore_Stack
  261. int 3
  262. ;...................................................................
  263. ; Restore the stack to its previous value
  264. ;...................................................................
  265. ??Restore_Stack:
  266. lss sp, [DWORD PTR StackPtr]
  267. ;...................................................................
  268. ; Pop the rest of the registers
  269. ;...................................................................
  270. pop ax
  271. pop ds
  272. popf
  273. ret
  274. ENDP IPXHandler
  275. END
  276. ;************************** End of handler.asm *****************************