KEYIREAL.ASM 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476
  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 : Westwood 32 bit Library *
  23. ;* (Mouse Routines)
  24. ;* *
  25. ;* File Name : KEYIREAL.ASM *
  26. ;* *
  27. ;* Programmer : Philip W. Gorrow *
  28. ;* *
  29. ;* Start Date : May 21, 1992 *
  30. ;* *
  31. ;* Last Update : July 13, 1994 [PWG] *
  32. ;* *
  33. ;* This file sort of breaks the standard of keeping all of the keyboard *
  34. ;* and mouse routines isolated. This is done because the mouse and *
  35. ;* the keyboard share data, and the best way to do this is to put *
  36. ;* them in the same segment. This should probably be split into several *
  37. ;* include files to help make the code clearer once it is finally put *
  38. ;* together. *
  39. ;* *
  40. ;*-------------------------------------------------------------------------*
  41. ;* Functions: *
  42. ;* KeyNum_Translate -- Translates extended keynums to normal keynums *
  43. ;* Stuff_Key_Word -- Stuffs a word of data into keyboard buffer *
  44. ;* Stuff_Key_Num -- Stuffs a key num code into the circular buffer *
  45. ;* Keystroke_Interrupt -- Real mode handler of input from the keyboard *
  46. ;* Break_Interrupt -- Handles the break key interrupt *
  47. ;* Call_Interrupt_Chain -- Function PM calls to call RM interrupt chain *
  48. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  49. ;* *
  50. ;* Keyboard driver -- 8086 Assembly portion; *
  51. ;* updated by: Phil Gorrow for 32 bit Protected Mode *
  52. ;***************************************************************************
  53. ;---------------------------------------------------------------------------
  54. ; Set the assembly directives
  55. ;---------------------------------------------------------------------------
  56. IDEAL ; the product runs in ideal mode
  57. P386N ; use 386 real mode instructions
  58. MODEL TINY ; code must be tiny so it fits
  59. LOCALS ?? ; ?? is the symbol for a local
  60. WARN ; generate all warnings we can
  61. JUMPS ; optimize jumps if possible
  62. ;---------------------------------------------------------------------------
  63. ; Include all of the keyboard specific defines
  64. ;---------------------------------------------------------------------------
  65. INCLUDE "keyboard.inc"
  66. CONDHIDE EQU 08000H ; bit for testing conditional region
  67. CONDHIDDEN EQU 04000H ; bit for testing conditional hidden
  68. RESTORE_VISIBLE_PAGE EQU 0
  69. STORE_VISIBLE_PAGE EQU 1
  70. GLOBAL set_vesa_page :near
  71. GLOBAL set_vesa_window :near
  72. GLOBAL get_vesa_window :near
  73. GLOBAL next_vesa_page :near
  74. ECHOON equ 0
  75. ;---------------------------------------------------------------------------
  76. ; WARNING!!!! All of the following code segment variables are shared by
  77. ; the protected mode interrupt. Do not change these unless you make the
  78. ; proper changes to KEYSTRUC.INC. If you do not know what you are doing,
  79. ; find someone who does!!!
  80. ;---------------------------------------------------------------------------
  81. CODESEG
  82. ;---------------------------------------------------------------------------
  83. ; Begin definition of Keyboard specific variables
  84. ;---------------------------------------------------------------------------
  85. SoundOn DW 1 ; toggled by alt S
  86. MusicOn DW 1 ; toggled by alt M
  87. KeyFlags DD REPEATON+CTRLALTTURBO ; all but repeat for now
  88. Break DW 0
  89. KeyMouseMove DB -1,0,1
  90. DB -16,0,16
  91. ScreenEdge DW 320/2,0 ; North
  92. DW 319,0 ; North-East
  93. DW 319,138/2 ; East
  94. DW 319,137 ; South-East
  95. DW 320/2,137 ; South
  96. DW 0,137 ; South-West
  97. DW 0,138/2 ; West
  98. DW 0,0 ; North-West
  99. DW 320/2,138/2 ; Center
  100. Bits DB 01H,02H,04H,08H,10H,20H,40H,80H
  101. CondPassKey DW 0220H, 0320H, 060CH, 070DH, 066AH
  102. DW 0669H, 0230H, 0330H, 007DH, 017DH
  103. DW 025AH, 035AH, 0200H, 0410H, 046EH
  104. DW 026EH, 007CH
  105. CondPassCond DW CTRLSON, CTRLSON, CTRLALTTURBO, CTRLALTTURBO, CTRLALTTURBO
  106. DW CTRLALTTURBO, CTRLCON, CTRLCON, SCROLLLOCKON, SCROLLLOCKON
  107. DW PAUSEON, PAUSEON, BREAKON, TASKSWITCHABLE, TASKSWITCHABLE
  108. DW TASKSWITCHABLE, BREAKON
  109. EscRoutine DD 0 ; vector to execute on esc key press (0=none)
  110. ; Extended raw keycodes to be converted to Westwood keycodes.
  111. ExtCodes DB 038H,01DH,052H,053H,04BH,047H,04FH,048H,050H,049H
  112. DB 051H,04DH,035H,01CH,037H
  113. DB 046H
  114. ; The matching Westwood keycodes.
  115. ExtNums DB 62, 64, 75, 76, 79, 80, 81, 83, 84, 85
  116. DB 86, 89, 95, 108, 124, 0
  117. ; If extended mapping is disabled, then these codes really are...
  118. ExtRemap DB 60, 58, 99, 104, 92, 91, 93, 96, 98, 101
  119. DB 103, 102, 55, 43, 124, 0
  120. ExtRemapEnd DB 0
  121. ExtKeyboard DB 0 ; flag for 101/102-key keyboard
  122. KeyBuffer DW 128 DUP(0) ; set to empty
  123. KeyBufferHead DD 0 ; set to first entry
  124. KeyBufferTail DD 0 ; set to head for empty buffer
  125. KeyLock DW 0 ; num and caps lock bits
  126. KeyNums DB 127,110,002,003,004,005,006,007,008,009,010,011,012,013,015,016
  127. DB 017,018,019,020,021,022,023,024,025,026,027,028,043,058,031,032
  128. DB 033,034,035,036,037,038,039,040,041,001,044,029,046,047,048,049
  129. DB 050,051,052,053,054,055,057,100,060,061,030,112,113,114,115,116
  130. DB 117,118,119,120,121,090,125,091,096,101,105,092,097,102,106,093
  131. DB 098,103,099,104,127,127,127,122,123
  132. KeysCapsLock DB 0,0,0FEH,087H,0FFH,0C0H,01FH,0,0,0,0,0,0,0,0,0
  133. KeysNumLock DB 0,0,0,0,0,0,0,0,0,0,0,038H,0EFH,1,0,0
  134. KeysUpDown DB 16 DUP(0) ; set to all keys up
  135. KeyStream DB 16 DUP(0) ; set to all keys up
  136. PassCount DW 0
  137. KeyStreamIndex DW 0
  138. LastKeyE0 DB 0
  139. LastKeyE1 DB 0
  140. ;
  141. ; Westwood key number values of keys to pass through
  142. ;
  143. ; CAPS, LEFT_SHIFT, RIGHT_SHIFT, LEFT_CTRL, LEFT_ALT,
  144. ; RIGHT_ALT, RIGHT_CTRL, NUM_LOCK, UNKNOWN
  145. PassAlways DB 30, 44, 57, 58, 60, 62, 64, 90, 128, 128
  146. PassAlwaysEnd DB 128 ; invalid code to END PassAlways
  147. CtrlFlags DB 0
  148. Buffer DW ?
  149. Time DW ?
  150. ADJUST = 1 ; do not modify DRD
  151. XYAdjust DB -ADJUST, -ADJUST ; 91 -> upleft
  152. DB -ADJUST, 0 ; 92 -> left
  153. DB -ADJUST, ADJUST ; 93 -> downleft
  154. DB 0, 0 ; 94 illegal
  155. DB 0, 0 ; 95 illegal
  156. DB 0, -ADJUST ; 96 -> up
  157. DB 0, 0 ; 97 illegal (center)
  158. DB 0, ADJUST ; 98 -> down
  159. DB 0, 0 ; 99 illegal
  160. DB 0, 0 ; 100 illegal
  161. DB ADJUST, -ADJUST ; 101 -> upright
  162. DB ADJUST, 0 ; 102 -> right
  163. DB ADJUST, ADJUST ; 103 -> downright
  164. EdgeConv DW 8,2,8,6,4,3,8,5,8,8,8,8,0,1,8,7
  165. MouseUpdate DW 0
  166. MouseX DW 0,0
  167. LocalMouseX DW 0
  168. MouseY DW 0,0
  169. LocalMouseY DW 0
  170. IsExtKey DB 0
  171. ExtIndex DW 0
  172. KeyOldRMI DD 0 ; The origianl RM interrupt seg:off.
  173. KeyOldPMIOffset DD 0 ; The origianl PM interrupt offset
  174. KeyOldPMISelector DD 0 ; The original PM interrupt segment.
  175. KeyCodeOffset DW RM_Keystroke_Interrupt ; Offset of the code in the RM stuff.
  176. CallKeyRMIntOffset DW Call_Interrupt_Chain ; Offset of function to call DOS timer interrupt.
  177. CallKeyRMIntAddr DD 0 ; PM address of CallRealIntOffset for speed.
  178. PMIssuedKeyInt DD 0
  179. BrkOldRMI DD 0 ; The origianl RM interrupt seg:off.
  180. BrkOldPMIOffset DD 0 ; The origianl PM interrupt offset
  181. BrkOldPMISelector DD 0 ; The original PM interrupt segment.
  182. BrkCodeOffset DW RM_Break_Interrupt ; Offset of the code in the RM stuff.
  183. CallBrkRMIntOffset DW 0
  184. CallBrkRMIntAddr DD 0 ; PM address of CallRealIntOffset for speed.
  185. PMIssuedBrkInt DD 0
  186. KeyIntDisabled DD 0
  187. DbgOldPMIOffset DD 0 ; The origianl PM interrupt offset
  188. DbgOldPMISelector DD 0 ; The original PM interrupt segment.
  189. ;---------------------------------------------------------------------------
  190. ; Begin definition of Mouse Specific Variables for real mode
  191. ;---------------------------------------------------------------------------
  192. Button DB 0 ; current value of the mouse button
  193. MDisabled DB 0 ; Is the mouse driver disabled
  194. MInput DB 1 ; Defaults to mouse input allowed.
  195. Adjust DW 0 ; flag to adjust coordinates if necessary
  196. MouseStepX DW 0 ; step values if the mouse moves at
  197. MouseStepY DW 0 ; more than one pixel at a time
  198. MouseOffsetX DW 0 ; Fractional step values used if a mouse
  199. MouseOffsetY DW 0 ; moves at less than one pixel at a time
  200. MState DW 0,0 ; Tracks if mouse is hidden (TRUE) or not (FALSE)
  201. MouseXOld DW 0 ; Holds last MouseX and MouseY to determine if
  202. MouseYOld DW 0 ; mouse needs to be redrawn
  203. MCState DW 0 ; Tracks if mouse conditional hidden (TRUE) or not
  204. MouseCXLeft DW 0,0 ; Conditional hide mouse left x position
  205. MouseCYUpper DW 0,0 ; Conditional hide mouse top y position
  206. MouseCXRight DW 0,0 ; Conditional hide mouse right x position
  207. MouseCYLower DW 0,0 ; Conditional hide mouse lower y position
  208. MouseCursor DD 0 ; Pointer to the mouse cursor to draw
  209. MouseCursorSize DW 0 ; Pointer to buffer mouse is saved in
  210. MouseBuffer DD 0 ; Pointer to buffer mouse is saved in
  211. MouseXHot DW 0,0 ; Offset to mouse's x hot spot
  212. MouseYHot DW 0,0 ; Offset to mouse's y hot spot
  213. MouseBuffX DW 0,0 ; X position background was saved at
  214. MouseBuffY DW 0,0 ; Y position background was saved at
  215. MouseBuffW DW 0,0 ; Width of the region saved for mouse
  216. MouseBuffH DW 0,0 ; Height of the region saved for mouse
  217. MouseWidth DW 0,0 ; Mouse cursor theoretical width
  218. MouseHeight DW 0,0 ; Mouse cursor theoretical height
  219. MouseCodeOffset DW RM_Mouse_Interrupt ; Offset of the code in the RM stuff.
  220. MouseRight DW 0,0
  221. MouseBottom DW 0,0
  222. ShadowPtr dw 0
  223. DrawMousePtr dw 0
  224. VGAMouseDraw dw VGA_Draw_Mouse
  225. VGAMouseShadow dw VGA_Mouse_Shadow_Buffer
  226. VESAMouseDraw dw VESA_Draw_Mouse
  227. VESAMouseShadow dw VESA_Mouse_Shadow_Buffer
  228. VesaPtr dd 0
  229. banktable dd 8 dup ( 0 )
  230. Adjust_XPos dw 0 , 0
  231. Adjust_YPos dw 0 , 0
  232. current_page dw 0
  233. ;***************************************************************************
  234. ;* KEYNUM_TRANSLATE -- Translates extended keynums to normal keynums *
  235. ;* *
  236. ;* INPUT: UWORD the keynum to translate *
  237. ;* *
  238. ;* OUTPUT: WORD the translated keynum *
  239. ;* *
  240. ;* PROTO: UWORD KeyNum_Translate(UWORD keynum); *
  241. ;* *
  242. ;* HISTORY: *
  243. ;* 07/11/1994 PWG : Created. *
  244. ;*=========================================================================*
  245. GLOBAL KeyNum_Translate:FAR
  246. PROC KeyNum_Translate C FAR
  247. USES cx,di,es,ds
  248. ARG keycode:WORD
  249. mov ax,cs ; since we are in tiny model
  250. mov ds,ax ; set cs = ds
  251. mov es,ax ; set es up for scansb
  252. mov ax,[keycode]
  253. test [WORD PTR KeyFlags],TRACKEXT
  254. jne short ??fini
  255. mov cx,ExtRemap-ExtNums
  256. mov di,OFFSET ExtNums
  257. repne scasb
  258. jcxz short ??fini ; No match found.
  259. mov di,OFFSET ExtRemapEnd
  260. dec di
  261. sub di,cx
  262. mov al,[es:di]
  263. ??fini:
  264. ret
  265. ENDP KeyNum_Translate
  266. ;***************************************************************************
  267. ;* STUFF_KEY_WORD -- Stuffs a word of data into keyboard buffer *
  268. ;* *
  269. ;* INPUT: WORD the code to stick into the circular buffer *
  270. ;* *
  271. ;* OUTPUT: WORD !=0 is sucessful, ==0 is not enough room *
  272. ;* *
  273. ;* PROTO: VOID Stuff_Key_WORD(WORD code); *
  274. ;* *
  275. ;* HISTORY: *
  276. ;* 07/11/1994 PWG : Created. *
  277. ;*=========================================================================*
  278. GLOBAL C Stuff_Key_WORD:FAR
  279. PROC Stuff_Key_WORD C FAR
  280. USES si,bx,ds
  281. ARG code:WORD
  282. mov ax,cs ; since we are in tiny model
  283. mov ds,ax ; set cs = ds
  284. mov ax,[WORD PTR KeyBufferTail]
  285. mov si,ax
  286. add ax,2
  287. and ax,0FFh ; New KeyBufferTail value.
  288. cmp [WORD PTR KeyBufferHead],ax
  289. je short ??noroom
  290. mov bx,[code]
  291. mov [KeyBuffer+si],bx ; Record the keystroke.
  292. mov [WORD PTR KeyBufferTail],ax
  293. xor ax,ax
  294. ret
  295. ??noroom:
  296. mov ax,1
  297. ret
  298. ENDP Stuff_Key_WORD
  299. ;***************************************************************************
  300. ;* STUFF_KEY_NUM -- Stuffs a key num code into the circular buffer *
  301. ;* *
  302. ;* INPUT: WORD the keycode to stuff *
  303. ;* *
  304. ;* OUTPUT: WORD !=0 is sucessful, ==0 is not enough room *
  305. ;* *
  306. ;* PROTO: VOID Stuff_Key_Num(WORD keynum); *
  307. ;* *
  308. ;* HISTORY: *
  309. ;* 07/11/1994 PWG : Created. *
  310. ;*=========================================================================*
  311. GLOBAL C Stuff_Key_Num:FAR
  312. PROC Stuff_Key_Num C FAR
  313. USES bx,cx,dx,di,si,ds
  314. ARG keycode:WORD
  315. LOCAL tail:WORD ; Original keybuffer tail (safety copy).
  316. LOCAL size:WORD ; Size of write.
  317. pushf
  318. cli ; disable interrupts
  319. ; Abort key recognition if in record mode and unable
  320. ; to output key due to simultaneous DOS operation.
  321. mov ax,cs ; since we are in tiny model
  322. mov ds,ax ; set cs = ds
  323. ; Record the mouse position to be stuffed into buffer.
  324. mov ax,[MouseX]
  325. mov [LocalMouseX],ax
  326. mov ax,[MouseY]
  327. mov [LocalMouseY],ax
  328. ??cando:
  329. mov ax,[keycode] ; get the code
  330. or ax,ax ; Null keycodes are not recorded.
  331. jne short ??validkey
  332. jmp ??exit
  333. ??validkey:
  334. test [WORD PTR KeyFlags],KEYMOUSE ; is the numeric keypad moving the mouse?
  335. je ??no_pad_move
  336. ; ALT-cursor keys are undefined. Pass them on to the program.
  337. test ah,ALTPRESS ; is either alt key down?
  338. jne ??no_pad_move
  339. test [WORD PTR KeyFlags],SIMLBUTTON ; are we simulating left mouse presses
  340. je short ??chkinsert
  341. cmp al,KN_RETURN
  342. je short ??forceleft
  343. cmp al,KN_SPACE
  344. je short ??forceleft
  345. cmp al,KN_KEYPAD_RETURN
  346. je short ??forceleft
  347. ??chkinsert:
  348. cmp al,KN_INSERT
  349. jne short ??regular
  350. ??forceleft:
  351. mov al,KN_LMOUSE
  352. or [Button],1 ; Left mouse bit.
  353. test ah,KEYRELEASE
  354. je ??mousefake
  355. and [Button],NOT 1
  356. jmp ??mousefake
  357. ??regular:
  358. cmp al,KN_DELETE
  359. jne short ??regular2
  360. mov al,KN_RMOUSE
  361. or [Button],2 ; Right mouse bit.
  362. test ah,KEYRELEASE
  363. je ??mousefake
  364. and [Button],NOT 2
  365. jmp ??mousefake
  366. ??regular2:
  367. ; DRD correction to ignore key releases for key mouse movement
  368. test ah,KEYRELEASE
  369. jne ??no_pad_move
  370. cmp al,KN_CENTER
  371. je short ??pad_move
  372. cmp al,KN_UPLEFT ; less than upleft?
  373. jb ??no_pad_move ; yes, then it isn't a keypad key
  374. cmp al,KN_DOWNRIGHT ; greater than downright?
  375. ja ??no_pad_move ; yes, then it isn't a keypad key
  376. cmp al,KN_DOWNLEFT ; is it UPLEFT, LEFT, or DOWNLEFT?
  377. jbe short ??pad_move
  378. cmp al,KN_UPRIGHT ; is it UPRIGHT, RIGHT, or DOWNRIGHT?
  379. jae short ??pad_move
  380. cmp al,KN_UP ; up?
  381. je short ??pad_move
  382. cmp al,KN_DOWN ; down?
  383. jne ??no_pad_move
  384. ??pad_move:
  385. ; DRD correction to use ch for ah
  386. mov ch,ah ; save shift-ctrl-alt-rlse status
  387. xor ah,ah ; get rid of any bits
  388. sub al,KN_UPLEFT ; get a number between 0 and 12
  389. mov bx,ax
  390. shl bx,1 ; double for WORD index
  391. add bx,OFFSET XYAdjust
  392. mov ax,[bx] ; get x,y add value
  393. mov bl,ah
  394. cbw
  395. xchg ax,bx
  396. cbw
  397. xchg ax,bx ; AX = mouse x delta, BX = mouse y delta
  398. ; DRD correction to use ch
  399. ; The CTRL key moves the mouse to the edge of the screen.
  400. test ch,CTRLPRESS ; is either ctrl key down?
  401. jne short ??ctrlon ; if so, ctrl is on
  402. ; DRD correction to use ch
  403. ; use fast speed of the mouse move if the shift key is held down.
  404. mov dx,1 ; for slow speed
  405. test ch,SHIFTPRESS ; is either shift key down?
  406. je short ??normspeed ; if not then neither shift is down
  407. ??doublespeed:
  408. add dx,3 ; for fast speed
  409. ??normspeed:
  410. add bx,dx ; add speed for y index
  411. mov bl,[KeyMouseMove+bx] ; get speed for y delta
  412. xchg ax,bx ; swap with ax to extend sign
  413. cbw
  414. xchg ax,bx
  415. xchg bx,dx ; save mouse y delta
  416. add bx,ax ; add speed for x index
  417. mov al,[KeyMouseMove+bx] ; get speed for x delta
  418. cbw
  419. xchg bx,dx ; restore mouse y delta
  420. jmp short ??ctrloff
  421. ??ctrlon:
  422. ; Table lookup method for determining hotkey positions for CTRL
  423. ; cursor combination. This algorithm is hard coded for an ADJUST
  424. ; value of 3. If this value changed, then this section will also
  425. ; have to be modified.
  426. and bx,011b ; Y = 1, 0, 3
  427. and ax,011b ; X = 1, 0, 3
  428. ; Table lookup method for determining hotkey positions for CTRL
  429. ; cursor combination. This algorithm is hard coded.
  430. ; -1, 0, 1
  431. and bx,011b ; Y = 3, 0, 1
  432. and ax,011b ; X = 3, 0, 1
  433. shl bx,1
  434. shl bx,1
  435. or bx,ax ; Lookup index.
  436. ; Convert raw index into logical (clockwise) index.
  437. shl bx,1
  438. mov bx,[EdgeConv+bx]
  439. shl bx,1
  440. shl bx,1
  441. mov ax,[ScreenEdge+bx] ; New absolute X
  442. mov bx,[ScreenEdge+bx+2] ; New absolute Y
  443. mov [LocalMouseX],ax
  444. mov [LocalMouseY],bx
  445. ??set_xyz:
  446. mov ax,[LocalMouseX] ; get new mouse x,y
  447. mov bx,[LocalMouseY]
  448. jmp short ??set_xy
  449. ; Process a normal faked mouse move.
  450. ??ctrloff:
  451. ; DRD change
  452. add [LocalMouseX],ax ; save it in our local
  453. jns short ??not_negative_x
  454. xor ax,ax
  455. mov [LocalMouseX],ax ; clear our local
  456. ??not_negative_x:
  457. ; DRD change
  458. add [LocalMouseY],bx ; save it in our local
  459. jns short ??not_negative_y
  460. xor bx,bx
  461. mov [LocalMouseY],bx ; clear our local
  462. ??not_negative_y:
  463. mov ax,[LocalMouseX] ; get new mouse x,y
  464. mov bx,[LocalMouseY]
  465. cmp ax,MAX_X_PIXEL ; bigger than
  466. jle short ??check_y
  467. mov ax,MAX_X_PIXEL
  468. ??check_y:
  469. cmp bx,MAX_Y_PIXEL ; bigger than
  470. jle short ??set_xy
  471. mov bx,MAX_Y_PIXEL
  472. ??set_xy:
  473. mov [LocalMouseX],ax
  474. mov [LocalMouseY],bx
  475. mov [MouseX],ax
  476. mov [MouseY],bx
  477. cmp [MouseUpdate],0 ; wait until mouse interrupt is done
  478. jne short ??noshow
  479. call Low_Hide_Mouse
  480. call Low_Show_Mouse
  481. ??noshow:
  482. mov ax,KN_MOUSE_MOVE
  483. ??mousefake:
  484. mov [keycode],ax ; Fake a MOUSE_MOVE event.
  485. ??no_pad_move:
  486. ; Fetch working pointers to the keyboard ends.
  487. mov si,[WORD KeyBufferTail]
  488. mov [tail],si ; Safety record.
  489. mov di,[WORD PTR KeyBufferHead]
  490. ; Record the base keycode (if there is room).
  491. push ax
  492. call Stuff_Key_WORD
  493. add sp,2
  494. or ax,ax
  495. jne short ??jmpnoroom
  496. ; Also record the mouse coordinates if necessary.
  497. mov ax,[keycode] ; get key code
  498. cmp al,KN_MOUSE_MOVE ; mouse move?
  499. je short ??recordmouse ; yes? then record the mouse cooordinates
  500. cmp al,KN_LMOUSE
  501. je short ??recordmouse
  502. cmp al,KN_RMOUSE
  503. je short ??recordmouse
  504. jmp short ??ok
  505. ??jmpnoroom:
  506. jmp ??noroom
  507. ; Record mouse coordinate X.
  508. ??recordmouse:
  509. push [LocalMouseX]
  510. call Stuff_Key_WORD
  511. add sp,2
  512. or ax,ax
  513. jne ??jmpnoroom
  514. add [size],2
  515. ; Record mouse coordinate Y.
  516. push [LocalMouseY]
  517. call Stuff_Key_WORD
  518. add sp,2
  519. or ax,ax
  520. jne ??jmpnoroom
  521. add [size],2
  522. ??ok:
  523. ; If PASSBREAKS is not active and this is a keyboard
  524. ; break AND it is not a mouse event, then don't put
  525. ; it into the buffer.
  526. mov bx,0101h ; Bit control tools.
  527. mov ax,[keycode]
  528. cmp al,KN_MOUSE_MOVE
  529. je short ??notreal
  530. cmp al,127
  531. je short ??notreal
  532. test ah,KEYRELEASE
  533. je short ??real
  534. xor bl,bl
  535. test [WORD PTR KeyFlags],PASSBREAKS
  536. jne short ??real
  537. cmp al,KN_LMOUSE
  538. je short ??real
  539. cmp al,KN_RMOUSE
  540. je short ??real
  541. ??notreal:
  542. mov [WORD PTR KeyBufferTail],si ; Nullify any KeyBufferTail changes.
  543. ??real:
  544. ; Update the KeysUpDown bit array.
  545. mov di,ax
  546. and di,07Fh
  547. mov cl,3
  548. shr di,cl ; DI = Byte offset into bit table.
  549. mov cl,al
  550. and cl,0111b ; CL = Bit offset into bit table byte.
  551. shl bx,cl
  552. not bh
  553. ; If this is a reapeat key and the key is already being held
  554. ; down, then don't stuff it into the keyboard buffer.
  555. test bl,[KeysUpDown+di]
  556. je short ??notalready
  557. test [WORD PTR KeyFlags],REPEATON
  558. jne short ??notalready
  559. mov [WORD PTR KeyBufferTail],si ; Nullify any KeyBufferTail changes.
  560. ??notalready:
  561. and [KeysUpDown+di],bh ; Force key bit to zero.
  562. or [KeysUpDown+di],bl ; Insert key bit as appropriate.
  563. ;??notreal:
  564. ; Successful keybuffer stuff could result in a
  565. ??norecord:
  566. mov ax,1
  567. jmp short ??exit
  568. ; Unsuccessful keybuffer stuff.
  569. ??noroom:
  570. mov ax,[tail]
  571. mov [WORD PTR KeyBufferTail],ax
  572. xor ax,ax ; Signal an error.
  573. ??exit:
  574. popf
  575. ret
  576. ENDP Stuff_Key_Num
  577. ;***********************************************************
  578. ;***************************************************************************
  579. ;* KEYSTROKE_INTERRUPT -- Handles input that comes from the keyboard *
  580. ;* *
  581. ;* This routine intercepts the key codes on their way to the *
  582. ;* BIOS. With the adjustment of the Flags described above *
  583. ;* you can get a wide variety of effects. *
  584. ;* *
  585. ;* INPUT: none *
  586. ;* *
  587. ;* OUTPUT: none *
  588. ;* *
  589. ;* WARNINGS: This is an interrupt function *
  590. ;* *
  591. ;* HISTORY: *
  592. ;* 07/13/1994 PWG : Created. *
  593. ;*=========================================================================*
  594. label RM_Keystroke_Interrupt
  595. GLOBAL C Keystroke_Interrupt:FAR
  596. PROC Keystroke_Interrupt C FAR
  597. IF 0
  598. push ax
  599. inc ax
  600. pop ax
  601. iret
  602. ELSE
  603. push ax
  604. push bx
  605. push cx
  606. push di
  607. push ds
  608. push dx
  609. push es
  610. push si
  611. cld
  612. mov ax,cs ; set ds to cs to avoid cs overide
  613. mov ds,ax
  614. cmp [WORD PTR PMIssuedKeyInt],0; Check to see if PM made Int call.
  615. mov [WORD PTR PMIssuedKeyInt],0; Make it false.
  616. jne ??passcode ; if so, just call Int Chain.
  617. mov dx,[WORD PTR KeyFlags]
  618. ;*** The following fix allows proper caps and num lock tracking on Tandy
  619. ; 10-6-89 LJC, DRD
  620. and [KeyLock],NOT (NUMLOCK OR CAPSLOCK); assume caps and num inactive
  621. mov ax,040H ; BIOS segment
  622. mov es,ax ; put in es
  623. test [BYTE PTR es:017H],040H ; test Caps lock bit in BIOS
  624. je short ??bioscapsoff ; skip activate code
  625. or [KeyLock],CAPSLOCK ; Caps Lock active
  626. ??bioscapsoff:
  627. test [BYTE PTR es:017H],020H ; test Num lock bit in BIOS
  628. je short ??biosnumoff ; skip activate code
  629. or [KeyLock],NUMLOCK ; Num Lock active
  630. ??biosnumoff:
  631. mov [ExtKeyboard],TRUE ; assume 101/102-key keyboard
  632. test [BYTE PTR es:096H],010H ; test for 101/102-key keyboard
  633. jne short ??extkeyboard ; skip deactivate code
  634. mov [ExtKeyboard],FALSE ; no 101/102-key keyboard
  635. ??extkeyboard:
  636. mov ax,cs ; set ds to cs to avoid cs overide
  637. mov es,ax
  638. cld ; clear direction flag for strings
  639. xor ah,ah ; clear ctrl flags to 0
  640. mov bx,0101H ; set key to a make by default
  641. in al,KEYDATA ; get a code from the keyboard
  642. ;
  643. ; New CODE to montior key stream
  644. ;
  645. mov bx,[KeyStreamIndex]
  646. mov [KeyStream+bx],al
  647. inc bx
  648. and bx,15
  649. mov [KeyStreamIndex],bx
  650. mov bx,0101H ; set key to a make by default
  651. ;
  652. ; END OF SEQUENCE
  653. ;
  654. ;
  655. ; Handle the PAUSE key being pressed. If it is pressed, then
  656. ; signal that the next two input codes are to be thrown out.
  657. ;
  658. cmp al,0E1H ; see if this is a pause/break
  659. jne short ??notpcode ; not a pause/break start code
  660. mov [LastKeyE1],3 ; absorb this and next two codes
  661. ??notpcode:
  662. cmp [LastKeyE1],0 ; are we in a pause/break code
  663. je short ??notpause ; no, just keep going
  664. dec [LastKeyE1] ; yes, dec the count
  665. test dx,PAUSEON ; should it pass these codes
  666. jne ??passcode ; pass the code
  667. jmp ??absorbcode ; don't pass code
  668. ??notpause:
  669. ;
  670. ; Record any extended key codes that arrive. They will be
  671. ; taken into account with the next code.
  672. ;
  673. cmp al,0E0H ; is it an extended code
  674. jne short ??notextcode ; if not skip to handle key
  675. mov [LastKeyE0],TRUE ; set the extended code to 1
  676. ??jmppasscode:
  677. jmp ??passcode ; always pass E0s
  678. ??notextcode:
  679. ;
  680. ; Check and acknowledge if the key is a make or a break.
  681. ;
  682. test al,080H ; test for high bit
  683. je short ??make ; if off its a make
  684. xor bl,bl ; set make/break to break
  685. and al,07FH ; clear high bit
  686. or ah,KEYRELEASE ; CDY NEW -- ABSENT IN OLD CODE
  687. ??make:
  688. ;
  689. ; Translate the raw keycode into the Westwood keycode.
  690. ;
  691. cmp [LastKeyE0],FALSE ; was the prev byte an E0?
  692. je short ??normal ; if not it is a normal key
  693. mov [LastKeyE0],FALSE ; if so clear for next read
  694. mov [IsExtKey],TRUE ; it is an extended key
  695. mov di,OFFSET ExtCodes ; get offset of extended codes table
  696. mov cx,(ExtNums-ExtCodes) ; get number of entrys in ext table
  697. repne scasb ; look for a match
  698. jcxz ??absorbcode ; Not recognized, so throw it away.
  699. mov al,[(ExtNums - ExtCodes) - 1 + di] ; get the match
  700. mov [IsExtKey],FALSE ; it is not an extended key
  701. jmp short ??notext
  702. ??normal:
  703. cmp al,07Ah
  704. jne short ??normok
  705. mov al,128
  706. jmp short ??notext
  707. ??normok:
  708. mov di,ax ; use code as an index
  709. and di,007Fh ; Mask off any release bit.
  710. mov al,[KeyNums+di] ; get the key number of this key
  711. ??notext:
  712. ;
  713. ; Test and set the CTRL bit.
  714. ;
  715. test [KeysUpDown+8],001H ; is the right ctrl down?
  716. jne short ??ctrlon ; if so, ctrl is on
  717. test [KeysUpDown+7],004H ; is the left ctrl down?
  718. je short ??ctrloff ; if not, neither are down, no ctrl
  719. ; DRD
  720. ; check for CTRL-NUMLOCK for pause on some keyboards
  721. cmp al,KN_NUMLOCK ; check for CTRL-NUMLOCK
  722. jne short ??ctrlon
  723. cmp [ExtKeyboard],TRUE ; if 101/102-key keyboard it is ok
  724. je short ??ctrlon
  725. test dx,PAUSEON ; should it pass these codes
  726. jne short ??ctrlon ; pass the code
  727. jmp ??absorbcode ; don't pass code
  728. ??ctrlon:
  729. or ah,CTRLPRESS ; or on the ctrl bit in flags
  730. ??ctrloff:
  731. ;
  732. ; Test and set the ALT bit.
  733. ;
  734. test [KeysUpDown + 7],050H ; is either alt key down?
  735. je short ??altoff
  736. or ah,ALTPRESS ; or on the alt bit in flags
  737. ??altoff:
  738. ;
  739. ; Remap the keyboard keys if this is requested. (Do not set DGROUP
  740. ; as it is unecessary)
  741. push ax
  742. call KeyNum_Translate
  743. add sp,2
  744. ;------ Set the shift bit if necessary.
  745. test [KeysUpDown+5],010H ; is the left shift down?
  746. jne short ??shifton ; if so the shift is on
  747. test [KeysUpDown+7],002H ; is the right shift down?
  748. je short ??shiftoff ; if not then neither shift is down
  749. ??shifton:
  750. or ah,SHIFTPRESS ; or on the shift bit in flags
  751. ??shiftoff:
  752. ;
  753. ;------ Toggle the shift state if the caps lock key is on (if necessary).
  754. ;
  755. mov di,ax
  756. and di,07Fh
  757. shr di,1
  758. shr di,1
  759. shr di,1
  760. mov bx,ax
  761. and bx,07Fh
  762. and bl,0111b
  763. mov ch,[Bits+bx] ; get the bit to test
  764. test [KeyLock],CAPSLOCK ; is the caps lock on?
  765. je short ??capsoff ; if not don't worry about it
  766. test ch,[KeysCapsLock+di] ; get code for keycaps
  767. je short ??capsoff ; its not effected
  768. xor ah,SHIFTPRESS ; toggle the shift flag
  769. ??capsoff:
  770. ;
  771. ;------ Toggle the shift state if the num-lock key is on (if necessary).
  772. ;
  773. test [KeyLock],NUMLOCK ; is the num lock key on?
  774. je short ??numlockoff ; if not don't worry about it
  775. test ch,[KeysNumLock+di] ; get code for numlock
  776. je short ??numlockoff ; if not effected skip toggle
  777. xor ah,SHIFTPRESS ; toggle the shift flag if effected
  778. ??numlockoff:
  779. ;------ Remember the current control/shift/alt bit settings for later use.
  780. ;??noshiftever:
  781. mov [CtrlFlags],ah ; save off shift-ctrl-alt flags
  782. ; for the mouse and joystick routines
  783. ; to use in stuffing key into the
  784. ; keyboard buffer.
  785. IF DEBUG
  786. cmp [KeyIntDisabled],1
  787. jne ??not_currently_disabled
  788. cmp ax,115 ; is it the F4 key
  789. je ??disable
  790. cmp ax,118 ; is it less then F7 key
  791. jb ??justpass
  792. cmp ax,120 ; is it greater than F9 key
  793. ja ??justpass
  794. ??disable:
  795. mov [KeyIntDisabled],0
  796. ??justpass:
  797. jmp ??passcode
  798. ??not_currently_disabled:
  799. cmp ax,125
  800. jne ??not_toggle
  801. mov [KeyIntDisabled],1
  802. jmp ??absorbcode
  803. ENDIF
  804. ??not_toggle:
  805. ;------ The CTRL-ALT-DEL key combination always gets passed to the system.
  806. cmp ax,0668H ; is it ctrl alt del?
  807. je ??passcode
  808. cmp ax,064CH ; is it ctrl alt ext del?
  809. je ??passcode ; if so don't add it to the buffer
  810. ;------ Special Ctrl-C check.
  811. cmp ax,0230h
  812. je short ??breaker
  813. cmp ax,027Eh
  814. jne short ??nobreak
  815. ??breaker:
  816. mov [Break],1
  817. ??nobreak:
  818. ;------ Check for Music and Sound control keys.
  819. cmp ax,0420H ; is this an alt s
  820. jne short ??checkmusic ; toggle the Sound variable
  821. push ax
  822. mov ax,[SoundOn]
  823. xor ax,01H
  824. push ax
  825. add sp,2
  826. pop ax
  827. ??checkmusic:
  828. cmp ax,0434H ; is this an alt m
  829. jne short ??esc ; toggle the Music variable
  830. push ax
  831. mov ax,[MusicOn]
  832. xor ax,01H
  833. push ax
  834. add sp,2
  835. pop ax
  836. ??esc:
  837. push ax
  838. call Stuff_Key_Num
  839. pop ax
  840. ??skipstuff:
  841. ;------ Do the special ESC routine if necessary.
  842. cmp al,110 ; is this the esc key?
  843. jne short ??noroutine ; if not goto the pass always
  844. cmp [WORD PTR EscRoutine+2],0 ;if vector is 0 don't jump
  845. je short ??noroutine
  846. push ax
  847. call [EscRoutine]
  848. pop ax
  849. ??noroutine:
  850. ;------ Check to see if the key is to be passed to the system or not.
  851. mov di,OFFSET PassAlways ; get offset to table
  852. mov cx,(PassAlwaysEnd - PassAlways) ; get number of pass always CDY JLB MOD 7/11 was +1
  853. repne scasb ; look for a match
  854. or cx,cx ; see if there was no match
  855. jne ??passcode ; CDY JLB 7/11 optimization
  856. ??passalways:
  857. ; now check for conditional passes
  858. mov di,OFFSET CondPassKey ; get offset to cond key table
  859. mov cx,(CondPassCond-CondPassKey) ; get number of entries
  860. shr cx,1 ; cut in half for words
  861. repne scasw ; look for a match
  862. jcxz short ??notcondpass ; OPTIMIZATION CDY JLB
  863. mov bx,[(CondPassCond - CondPassKey) - 2 + di]
  864. and bx,dx ; are the conditions met?
  865. je short ??notcondpass ; NO... check normally.
  866. jmp short ??passcode ; YES... pass back to system.
  867. ;
  868. ;------ Last check before passing keycode back to the system.
  869. ;
  870. ??notcondpass:
  871. test dx,FILTERONLY ; is the filter only flag on?
  872. je short ??absorbcode ; if not, absorb the code.
  873. ??passcode:
  874. pop si
  875. pop es
  876. pop dx
  877. pop ds
  878. pop di
  879. pop cx
  880. pop bx
  881. pop ax
  882. inc [cs:PassCount]
  883. jmp [cs:KeyOldRMI]
  884. ??absorbcode:
  885. in al,KEYCTRL ; get the control port
  886. mov ah,al
  887. or al,080H ; reset bit for keyboard
  888. out KEYCTRL,al
  889. xchg ah,al ; get orig control data
  890. out KEYCTRL,al ; restore control data
  891. mov ax,040h ; BIOS paragraph is always @ 040h
  892. mov es,ax ; put in es as BIOS paragraph
  893. mov al,[es:96h] ; get extended keys
  894. and al,0FDh ; turn off last key e0 flag
  895. mov [es:96h],al ; set extended keys
  896. mov al,CLEARISR ; value to clear In Service Register
  897. out INTCHIP0,al ; 8259 interrupt chip controller 0
  898. pop si
  899. pop es
  900. pop dx
  901. pop ds
  902. pop di
  903. pop cx
  904. pop bx
  905. pop ax
  906. iret
  907. ENDIF
  908. ENDP Keystroke_Interrupt
  909. ;***************************************************************************
  910. ;* Break interrupt routines begin here!
  911. ;***************************************************************************
  912. ;***************************************************************************
  913. ;* BREAK_INTERRUPT -- Handles the break key interrupt *
  914. ;* *
  915. ;* INPUT: none *
  916. ;* *
  917. ;* OUTPUT: none *
  918. ;* *
  919. ;* WARNINGS: This is an interrupt routine. *
  920. ;* *
  921. ;* HISTORY: *
  922. ;* 07/13/1994 PWG : Created. *
  923. ;*=========================================================================*
  924. label RM_Break_Interrupt
  925. GLOBAL C Break_Interrupt:FAR
  926. PROC Break_Interrupt C FAR
  927. pushf
  928. push ax
  929. push es
  930. mov ax,0B000h ; ES:DI = Mono RAM address.
  931. mov es,ax
  932. inc [BYTE PTR es:0]
  933. pop es
  934. pop ax
  935. popf
  936. iret
  937. ENDP Break_Interrupt
  938. ;**************************************************************************
  939. ;* CALL_INTERRUPT_CHAIN -- Function PM calls to call the RM interrupt chain*
  940. ;* *
  941. ;* *
  942. ;* INPUT: none *
  943. ;* *
  944. ;* OUTPUT: none *
  945. ;* *
  946. ;* HISTORY: *
  947. ;* 07/08/1994 SKB : Created. *
  948. ;*=========================================================================*
  949. Call_Interrupt_Chain:
  950. pushf
  951. call Keystroke_Interrupt ;[KeyOldRMI]
  952. retf
  953. ;----------------------------------------------------------------------------
  954. ; LOW_HIDE_MOUSE:
  955. ;
  956. ; This function hides the mouse cursor on the screen if it was shown. It
  957. ; will not hide the mouse if it is already hidden.
  958. ;
  959. ; PROTOTYPE:
  960. ;
  961. ; VOID Low_Hide_Mouse(VOID);
  962. ;
  963. ; NOTE: does not check if mouse is currently being updated.
  964. ;
  965. ;----------------------------------------------------------------------------
  966. GLOBAL C Low_Hide_Mouse:FAR
  967. PROC Low_Hide_Mouse C FAR
  968. USES ax,bx,cx,dx,ds
  969. mov ax,cs ; since we are in tiny model
  970. mov ds,ax ; set cs = ds
  971. cmp [MDisabled],0 ; check if mouse is disabled
  972. jne short ??end
  973. cmp [MState],0 ; check if it was hidden before
  974. jne short ??endnodraw ; no need to hide again
  975. ;------ Move the saved graphic buffer to the seenpage to hide the mouse.
  976. ; call Buffer_To_Page C,[buffx],[buffy],[buffw],[buffh],[MouseBuffer],SEENPAGE
  977. mov ax,RESTORE_VISIBLE_PAGE
  978. push ax
  979. push cs
  980. call [ ShadowPtr ]
  981. add sp,2
  982. ;------ Record that the mouse has been hidden.
  983. ??endnodraw:
  984. add [MState],1
  985. adc [MState],0
  986. ??end:
  987. ret
  988. ENDP Low_Hide_Mouse
  989. ;----------------------------------------------------------------------------
  990. ;----------------------------------------------------------------------------
  991. ; LOW_SHOW_MOUSE:
  992. ;
  993. ; This function displays the mouse cursor on the screen if it was hidden.
  994. ;
  995. ; PROTOTYPE:
  996. ; VOID Low_Show_Mouse(VOID);
  997. ;
  998. ; NOTE: does not check if mouse is currently being updated.
  999. ;----------------------------------------------------------------------------
  1000. GLOBAL C Low_Show_Mouse:FAR
  1001. PROC Low_Show_Mouse C FAR
  1002. USES ax,bx,cx,dx,si,di,ds,es
  1003. LOCAL mousex:WORD ; Draw X position.
  1004. LOCAL mousey:WORD ; Draw Y position.
  1005. mov ax,cs ; since we are in tiny model
  1006. mov ds,ax ; set cs = ds
  1007. ;----- Don't show the mouse if it is not hidden, disabled.
  1008. cmp [MDisabled],0 ; is the mouse disabled
  1009. jne ??exit ; if so then exit
  1010. cmp [MState],0 ; is the mouse already visible
  1011. je ??exit ; if so then exit
  1012. dec [MState]
  1013. cmp [MState],0 ; can the mouse be shown
  1014. jne short ??exit
  1015. ;------ Determine the drawing position of the mouse.
  1016. mov cx,[MouseWidth] ; Theoretical buffer width (pixel).
  1017. mov dx,[MouseHeight] ; Theoretical buffer height (pixel).
  1018. mov ax,[MouseX]
  1019. ; sub ax,[MouseXHot]
  1020. mov [mousex],ax ; Draw X pixel.
  1021. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1022. IF 0
  1023. ; jns short ??xnotneg
  1024. ; add cx,ax ; Reduce width accordingly.
  1025. ; mov ax,0
  1026. ??xnotneg:
  1027. ENDIF
  1028. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1029. mov bx,[MouseY]
  1030. ; sub bx,[MouseYHot]
  1031. mov [mousey],bx ; Draw Y pixel.
  1032. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1033. IF 0
  1034. ; jns short ??ynotneg
  1035. ; add dx,bx ; Reduce height of mouse accordingly.
  1036. ; mov bx,0
  1037. ??ynotneg:
  1038. ENDIF
  1039. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1040. ;------ Determine the theoretical coordinates and dimensions of the
  1041. ; area the mouse shape will be rendered upon.
  1042. mov [MouseBuffX],ax
  1043. mov [MouseBuffY],bx
  1044. mov [MouseBuffW],cx
  1045. mov [MouseBuffH],dx
  1046. ;------ Move the area that will be drawn upon, to the graphic buffer.
  1047. mov ax,STORE_VISIBLE_PAGE
  1048. push ax
  1049. push cs
  1050. call [ ShadowPtr ]
  1051. add sp,2
  1052. ;------ Draw the mouse shape to the seenpage.
  1053. push [mousey]
  1054. push [mousex]
  1055. push cs
  1056. call [ DrawMousePtr ]
  1057. add sp,4
  1058. ??exit:
  1059. ret
  1060. ENDP Low_Show_Mouse
  1061. ;----------------------------------------------------------------------------
  1062. ;----------------------------------------------------------------------------
  1063. GLOBAL C Mouse_KeyNum:FAR
  1064. PROC Mouse_KeyNum C FAR
  1065. USES bx
  1066. ARG state:WORD ; Current mouse state.
  1067. LOCAL keynum:WORD ; Determined keynum.
  1068. mov ax,cs ; since we are in tiny model
  1069. mov ds,ax ; set cs = ds
  1070. mov [keynum],KN_MOUSE_MOVE ; Presume just a mouse move.
  1071. mov bx,[state]
  1072. mov ax,bx
  1073. xor bl,[Button] ; Bits of state change.
  1074. je short ??fini
  1075. mov [Button],al ; Record new mouse state.
  1076. test bl,0010b
  1077. je short ??notright
  1078. mov [keynum],KN_RMOUSE
  1079. test al,0010b
  1080. jne short ??notright
  1081. or [keynum],0800h ; Release bit on.
  1082. ??notright:
  1083. ; DRD
  1084. ; note: the left mouse button has priority over the right mouse button
  1085. ; this should be changed at a later date to process them independently
  1086. test bl,0001b
  1087. je short ??notleft
  1088. mov [keynum],KN_LMOUSE
  1089. test al,0001b
  1090. jne short ??notleft
  1091. or [keynum],0800h ; Release bit on.
  1092. ??notleft:
  1093. ??fini:
  1094. mov ax,[keynum]
  1095. ret
  1096. ENDP Mouse_KeyNum
  1097. ;----------------------------------------------------------------------------
  1098. ;----------------------------------------------------------------------------
  1099. ; MOUSE_INT:
  1100. ;
  1101. ; This routine is called automatically when the Mouse_Int is installed. It
  1102. ; automatically updates the global variables stored in the code segment so
  1103. ; that the mouse information is automatically known at all times.
  1104. ;
  1105. ; INPUTS (from int): AX = condition mask ( bit 0 == cursor position chg,
  1106. ; bit 1 == left button press,
  1107. ; bit 2 == left button release,
  1108. ; bit 3 == right button press,
  1109. ; bit 4 == right button release,
  1110. ; 5-15 == not used )
  1111. ; BX = button state ( bit 0 == left button down,
  1112. ; bit 1 == right button down,
  1113. ; bit 2 == middle button down.
  1114. ; 3-15 == not used )
  1115. ; CX = cursor coordinate (horizontal axis)
  1116. ; DX = cursor coordinate (vertical axis)
  1117. ; DI = horizontal mouse count (mickeys)
  1118. ; SI = vertical mouse count (mickeys)
  1119. ;
  1120. ; RETURNS: none
  1121. ;
  1122. ; MODIFIES: modifies the variables _Button, _ButtonChange,
  1123. ; _MouseX,_MouseY,_ButtonLatch
  1124. ;
  1125. ; PROTOTYPE:
  1126. ; This routine is called from an interrupt.
  1127. ;----------------------------------------------------------------------------
  1128. label RM_Mouse_Interrupt
  1129. PROC Mouse_Int C FAR
  1130. USES ax,bx,cx,dx,ds,si,es,di
  1131. LOCAL cond:WORD ; Local copy of mouse event.
  1132. LOCAL state:WORD ; Local copy of button state.
  1133. ;------ Current mouse state button flag globals update.
  1134. mov [state],bx
  1135. mov [cond],ax
  1136. mov ax,cs ; since we are in tiny model
  1137. mov ds,ax ; set cs = ds
  1138. ;------ Process the mouse interrupt only if the mouse is enabled (whether
  1139. ; present or not).
  1140. cmp [MDisabled],0
  1141. jne ??exit
  1142. cmp [MInput],0
  1143. je ??exit
  1144. ;------ This was added because of missing mouse presses and
  1145. ; releases during a mouse update.
  1146. mov ax,[cond]
  1147. and ax,0001EH ; bits for left and right press and release
  1148. jne short ??dopress_release
  1149. cmp [MouseUpdate],0 ; if mouse move and mouse updating exit
  1150. jne ??exit
  1151. ??dopress_release:
  1152. ;------ In EEGA mode mouse X coordinates as 0..639. Make adjustment
  1153. ; to keep within 0..319 range.
  1154. cmp [Adjust],1 ; if the x coordinate is returned
  1155. jne short ??noadjust ; incorrectly then
  1156. shr cx,1 ; adjust x coord from 640 pixel screen
  1157. ??noadjust:
  1158. ; scale mouse posX and PosY
  1159. ; cmp [Adjust_XPos] , 0
  1160. ; jz short ??no_scaleX
  1161. ; push dx
  1162. ; mov ax , [MouseRight]
  1163. ; imul cx
  1164. ; idiv [Adjust_XPos]
  1165. ; mov cx , ax
  1166. ; pop dx
  1167. ??no_scaleX:
  1168. ; cmp [Adjust_YPos] , 0
  1169. ; jz short ??no_scaleY
  1170. ; mov ax , [MouseBottom]
  1171. ; imul dx
  1172. ; idiv [Adjust_YPos]
  1173. ; mov dx , ax
  1174. ??no_scaleY:
  1175. ;------ Keep mouse within screen bounds.
  1176. cmp cx,[MouseRight] ; in EGAMODE, the mouse may go to 320
  1177. jb short ??boundX_ok ; force it to stay at least one pixel
  1178. mov cx,[MouseRight] ; on the screen
  1179. dec cx
  1180. ??boundX_ok:
  1181. cmp dx,[MouseBottom] ; in EGAMODE, the mouse may go to 320
  1182. jb short ??boundY_ok ; force it to stay at least one pixel
  1183. mov dx,[MouseBottom] ; on the screen
  1184. dec dx
  1185. ??boundY_ok:
  1186. IF 0
  1187. ;------ Remap the middle button to equal the right button.
  1188. test bx,04h
  1189. je ??noremap
  1190. or bx,0010b ; Set the right button bit.
  1191. ??noremap:
  1192. ENDIF
  1193. mov [MouseX],cx ; and store in mouse x
  1194. mov [MouseY],dx ; store y coord in mouse y
  1195. test [KeyFlags],KEYMOUSE
  1196. jne short ??nostuffit
  1197. call Mouse_KeyNum C,[state] ; Convert mouse state to key number code.
  1198. call Stuff_Key_Num C,ax ; Record mouse keynumber code.
  1199. ??nostuffit:
  1200. ;------ The check for Mouse in the middle of updating CAN NOT BE MOVED
  1201. ; any farther up because mouse presses and releases will be LOST!!
  1202. cmp [MouseUpdate],0
  1203. jne ??exit
  1204. ;??jexit:
  1205. ; jmp ??exit
  1206. christopher:
  1207. ??chkxy:
  1208. ;------ Signal that no mouse updating can occur at this time.
  1209. ; cmp [_MouseUpdate],0
  1210. ; jne ??exit
  1211. ; mov [_MouseUpdate],1
  1212. ;------ Perform any X movement grid adjustment.
  1213. cmp [MouseStepX],0 ; are we stepping on the X?
  1214. je short ??no_x_step ; no x
  1215. mov ax,cx ; get current x_pixel
  1216. mov cx,dx ; save dx - it is trashed by idiv
  1217. sub ax,[MouseOffsetX] ; get offset difference
  1218. mov bx,[MouseStepX] ; get step in bx for idiv
  1219. cwd ; extend ax -> dx:ax
  1220. idiv bx ; divide by Step X
  1221. imul bx ; ax = div * Step X
  1222. add ax,[MouseOffsetX] ; normalize to region offset
  1223. mov dx,cx ; restore dx (new MouseY)
  1224. mov cx,ax ; set cx (new MouseX)
  1225. ??no_x_step:
  1226. ;------ Perform any Y movement grid adjustment.
  1227. cmp [MouseStepY],0 ; are we stepping on the Y
  1228. je short ??no_step ; no y
  1229. mov ax,dx ; get current y_pixel
  1230. sub ax,[MouseOffsetY] ; get offset difference
  1231. mov bx,[MouseStepY] ; get step in bx for idiv
  1232. cwd ; extend ax -> dx:ax
  1233. idiv bx ; divide by Step Y
  1234. imul bx ; ax = div * Step Y
  1235. add ax,[MouseOffsetY] ; normalize to region offset
  1236. mov dx,ax ; set dx (new MouseY)
  1237. ??no_step:
  1238. ;------ Here is where we store the new MouseX and MouseY values
  1239. ; mov [MouseX],cx ; and store in mouse x
  1240. ; mov [MouseY],dx ; store y coord in mouse y
  1241. ;------ If the mouse is hidden or its position hasn't changed, then
  1242. ; perform no action.
  1243. cmp [MState],0
  1244. jne short ??updateend
  1245. cmp [MouseXOld],cx
  1246. jne short ??doit
  1247. cmp [MouseYOld],dx
  1248. je short ??updateend
  1249. ??doit:
  1250. ;------ At this point we KNOW the mouse has moved.
  1251. mov ax,[MCState]
  1252. and ax,CONDHIDE+CONDHIDDEN
  1253. cmp ax,CONDHIDE+CONDHIDDEN
  1254. je short ??condcheck ; If already hidden.
  1255. ;------ We know that the mouse is visible, we must hide it
  1256. ; before we update its position.
  1257. call Low_Hide_Mouse
  1258. ;------ Conditional region check goes here. If the mouse falls within the
  1259. ; conditional region, it gets marked as hidden and no other processing
  1260. ; occurs.
  1261. test [MCState],CONDHIDE
  1262. je short ??condok
  1263. ??condcheck:
  1264. cmp cx,[MouseCXLeft] ; check adjusted x region
  1265. jb short ??condok
  1266. cmp cx,[MouseCXRight]
  1267. ja short ??condok
  1268. cmp dx,[MouseCYUpper] ; check adjusted y region
  1269. jb short ??condok
  1270. cmp dx,[MouseCYLower]
  1271. ja short ??condok
  1272. or [MCState],CONDHIDDEN ; flag as conditional hidden
  1273. jmp short ??updateend
  1274. ;------ The mouse coordinates and flags pass all of the tests, proceed
  1275. ; with rendering the mouse.
  1276. ??condok:
  1277. call Low_Show_Mouse
  1278. ;------ Final clean up and exit.
  1279. ??updateend:
  1280. mov [MouseXOld],cx
  1281. mov [MouseYOld],dx
  1282. ??exit:
  1283. ret
  1284. ENDP Mouse_Int
  1285. ;***************************************************************************
  1286. ;***************************************************************************
  1287. ;***************************************************************************
  1288. ;* MOUSE_SHADOW_BUFFER -- Handles storing and restoring the mouse buffer *
  1289. ;* *
  1290. ;* INPUT: int store - indicates whether we are storing the buffer or *
  1291. ;* not. *
  1292. ;* *
  1293. ;* OUTPUT: none *
  1294. ;* *
  1295. ;* PROTO: Asm callable only! *
  1296. ;* *
  1297. ;* HISTORY: *
  1298. ;* 10/27/1994 PWG : Created. *
  1299. ;*=========================================================================*
  1300. GLOBAL C VGA_Mouse_Shadow_Buffer:FAR
  1301. PROC VGA_Mouse_Shadow_Buffer C FAR
  1302. USES ax,bx,cx,dx,di,si,ds,es
  1303. ARG store:WORD
  1304. local x0 : word
  1305. local y0 : word
  1306. local x1 : word
  1307. local y1 : word
  1308. local buffx0 : word
  1309. local buffy0 : word
  1310. ;*=========================================================================*
  1311. ;* Since we are in tiny model point ds to cs
  1312. ;*=========================================================================*
  1313. mov ax,cs ; since we are in tiny model
  1314. mov ds,ax ; set cs = ds
  1315. ;*=========================================================================*
  1316. ; Direction flag must be forward in this routine.
  1317. ;*=========================================================================*
  1318. cld
  1319. ;*===================================================================
  1320. ;* Copy of X, Y, Width and Height into local registers
  1321. ;*===================================================================
  1322. mov ax,[MouseBuffX]
  1323. mov bx,[MouseBuffY]
  1324. sub ax , [ MouseXHot ]
  1325. sub bx , [ MouseYHot ]
  1326. mov [ x0 ] , ax
  1327. mov [ y0 ] , bx
  1328. add ax , [MouseBuffW]
  1329. add bx , [MouseBuffH]
  1330. mov [ x1 ] , ax
  1331. mov [ y1 ] , bx
  1332. mov [ buffx0 ] , 0
  1333. mov ax , [ word ptr MouseBuffer ]
  1334. mov [ buffy0 ] , ax
  1335. ;*===================================================================
  1336. ;* Bounds check source X. Y.
  1337. ;*===================================================================
  1338. xor ax , ax
  1339. xor dx , dx
  1340. mov cx , [ x0 ]
  1341. mov bx , [ x1 ]
  1342. add cx , cx
  1343. adc ax , ax
  1344. add bx , bx
  1345. adc dx , dx
  1346. mov cx , [ x0 ]
  1347. mov bx , [ x1 ]
  1348. sub cx , [ MouseRight ]
  1349. sub bx , [ MouseRight ]
  1350. dec cx
  1351. dec bx
  1352. add cx , cx
  1353. adc ax , ax
  1354. add bx , bx
  1355. adc dx , dx
  1356. mov cx , [ y0 ]
  1357. mov bx , [ y1 ]
  1358. add cx , cx
  1359. adc ax , ax
  1360. add bx , bx
  1361. adc dx , dx
  1362. mov cx , [ y0 ]
  1363. mov bx , [ y1 ]
  1364. sub cx , [MouseBottom]
  1365. sub bx , [MouseBottom]
  1366. dec cx
  1367. dec bx
  1368. add cx , cx
  1369. adc ax , ax
  1370. add bx , bx
  1371. adc dx , dx
  1372. xor al , 5
  1373. xor dl , 5
  1374. mov ah , al
  1375. test dl , al
  1376. jnz ??out
  1377. or al , dl
  1378. jz ??acepted
  1379. test ah , 1000b
  1380. jz ??scr_left_ok
  1381. mov bx , [ x0 ]
  1382. neg bx
  1383. mov [ buffx0 ] , bx
  1384. mov [ x0 ] , 0
  1385. ??scr_left_ok:
  1386. test ah , 0010b
  1387. jz ??scr_bottom_ok
  1388. push dx
  1389. mov ax , [ y0 ]
  1390. neg ax
  1391. mul [MouseBuffW]
  1392. add [ buffy0 ] , ax
  1393. mov [ y0 ] , 0
  1394. pop dx
  1395. ??scr_bottom_ok:
  1396. test dl , 0100b
  1397. jz ??scr_right_ok
  1398. mov ax , [MouseRight] ; get width into register
  1399. mov [ x1 ] , ax
  1400. ??scr_right_ok:
  1401. test dl , 0001b
  1402. jz ??acepted
  1403. mov ax , [MouseBottom] ; get width into register
  1404. mov [ y1 ] , ax
  1405. ??acepted:
  1406. ;*===================================================================
  1407. ;* Get the offset into the screen.
  1408. ;*===================================================================
  1409. mov ax,0A000h
  1410. mov es,ax
  1411. mov ax , [ y0 ]
  1412. mul [ MouseRight ]
  1413. mov dx , [MouseRight]
  1414. mov di , ax
  1415. add di , [ x0 ]
  1416. ;*===================================================================
  1417. ;* Adjust the source for the top clip.
  1418. ;*===================================================================
  1419. mov bx , [ MouseWidth ] ; turn this into an offset
  1420. lds si , [ MouseBuffer ]
  1421. mov si , [ buffy0 ] ; edx points to source
  1422. add si , [ buffx0 ] ; plus clipped lines
  1423. ;*===================================================================
  1424. ;* Calculate the bytes per row add value
  1425. ;*===================================================================
  1426. mov ax , [ x1 ]
  1427. mov cx , [ y1 ]
  1428. sub ax , [ x0 ]
  1429. jle ??out
  1430. sub cx , [ y0 ]
  1431. jle ??out
  1432. sub dx , ax
  1433. sub bx , ax
  1434. push bp
  1435. cmp [store],RESTORE_VISIBLE_PAGE ; are we restoring page?
  1436. jne ??store_entry ; if not the go to store
  1437. ;*===================================================================
  1438. ;* Handle restoring the buffer to the visible page
  1439. ;*===================================================================
  1440. mov bp , cx
  1441. ??restore_loop:
  1442. mov cx,ax ; get number to really write
  1443. rep movsb ; store them into the buffer
  1444. add si,bx ; move past right clipped pixels
  1445. add di,dx ; adjust dest to next line
  1446. dec bp ; decrement number of rows to do
  1447. jnz ??restore_loop ; if more to do, do it
  1448. pop bp
  1449. IF ECHOON
  1450. mov ax , 0b000h
  1451. mov di , 12 * 80 + 10
  1452. mov es, ax
  1453. mov al , 'V'
  1454. mov [es:di],al
  1455. mov al,2
  1456. mov [es:di+1],al
  1457. ENDIF
  1458. ret
  1459. ;*===================================================================
  1460. ;* Handle soting the visible page into the Mouse Shadow Buffer
  1461. ;*===================================================================
  1462. ??store_entry:
  1463. xchg si,di ; xchg the source and the dest
  1464. mov bp , cx
  1465. push es ; need to swap es and ds but
  1466. push ds ; cant xchg so pop them on the
  1467. pop es ; stack and pop them off the
  1468. pop ds ; wrong way intentionally.
  1469. ??store_loop:
  1470. mov cx,ax ; get number to really write
  1471. rep movsb ; store them into the buffer
  1472. add si,dx ; move past right clipped pixels
  1473. add di,bx ; adjust dest to next line
  1474. dec bp ; decrement number of rows to do
  1475. jnz ??store_loop ; if more to do, do it
  1476. pop bp
  1477. ??out:
  1478. IF ECHOON
  1479. mov ax , 0b000h
  1480. mov di , 12 * 80 + 12
  1481. mov es, ax
  1482. mov al , 'G'
  1483. mov [es:di],al
  1484. mov al,2
  1485. mov [es:di+1],al
  1486. ENDIF
  1487. ret
  1488. ENDP VGA_Mouse_Shadow_Buffer
  1489. ;***************************************************************************
  1490. GLOBAL C VGA_Draw_Mouse:FAR
  1491. PROC VGA_Draw_Mouse C FAR
  1492. USES ax,bx,cx,dx,di,si,ds,es
  1493. ARG mousex:WORD
  1494. ARG mousey:WORD
  1495. local x0 : word
  1496. local y0 : word
  1497. local x1 : word
  1498. local y1 : word
  1499. local buffx0 : word
  1500. local buffy0 : word
  1501. ;*=========================================================================*
  1502. ;* Since we are in tiny model point ds to cs
  1503. ;*=========================================================================*
  1504. mov ax,cs ; since we are in tiny model
  1505. mov ds,ax ; set cs = ds
  1506. ;*===================================================================
  1507. ;* Pre-initialize the left, right and topclip values to zero.
  1508. ;*===================================================================
  1509. mov ax, [ mousex ]
  1510. mov bx , [ mousey ]
  1511. sub ax , [ MouseXHot ]
  1512. sub bx , [ MouseYHot ]
  1513. mov [ x0 ] , ax
  1514. mov [ y0 ] , bx
  1515. add ax, [ MouseWidth ]
  1516. add bx, [ MouseHeight ]
  1517. mov [ x1 ] , ax
  1518. mov [ y1 ] , bx
  1519. mov [ buffx0 ] , 0
  1520. les ax , [ MouseCursor ]
  1521. mov [ buffy0 ] , ax
  1522. ;*===================================================================
  1523. ;* Bounds check source X. Y.
  1524. ;*===================================================================
  1525. xor ax , ax
  1526. xor dx , dx
  1527. mov cx , [ x0 ]
  1528. mov bx , [ x1 ]
  1529. add cx , cx
  1530. adc ax , ax
  1531. add bx , bx
  1532. adc dx , dx
  1533. mov cx , [ x0 ]
  1534. mov bx , [ x1 ]
  1535. sub cx , [ MouseRight ]
  1536. sub bx , [ MouseRight ]
  1537. dec cx
  1538. dec bx
  1539. add cx , cx
  1540. adc ax , ax
  1541. add bx , bx
  1542. adc dx , dx
  1543. mov cx , [ y0 ]
  1544. mov bx , [ y1 ]
  1545. add cx , cx
  1546. adc ax , ax
  1547. add bx , bx
  1548. adc dx , dx
  1549. mov cx , [ y0 ]
  1550. mov bx , [ y1 ]
  1551. sub cx , [MouseBottom]
  1552. sub bx , [MouseBottom]
  1553. dec cx
  1554. dec bx
  1555. add cx , cx
  1556. adc ax , ax
  1557. add bx , bx
  1558. adc dx , dx
  1559. xor al , 5
  1560. xor dl , 5
  1561. mov ah , al
  1562. test dl , al
  1563. jnz ??out
  1564. or al , dl
  1565. jz ??acepted
  1566. test ah , 1000b
  1567. jz ??scr_left_ok
  1568. mov bx , [ x0 ]
  1569. neg bx
  1570. mov [ buffx0 ] , bx
  1571. mov [ x0 ] , 0
  1572. ??scr_left_ok:
  1573. test ah , 0010b
  1574. jz ??scr_bottom_ok
  1575. push dx
  1576. mov ax , [ y0 ]
  1577. neg ax
  1578. mul [MouseWidth]
  1579. add [ buffy0 ] , ax
  1580. mov [ y0 ] , 0
  1581. pop dx
  1582. ??scr_bottom_ok:
  1583. test dl , 0100b
  1584. jz ??scr_right_ok
  1585. mov bx , [MouseRight] ; get width into register
  1586. mov [ x1 ] , bx
  1587. ??scr_right_ok:
  1588. test dl , 0001b
  1589. jz ??acepted
  1590. mov bx , [MouseBottom] ; get width into register
  1591. mov [ y1 ] , bx
  1592. ??acepted:
  1593. mov ax , [ y0 ]
  1594. mul [ MouseRight ]
  1595. mov dx , [MouseRight]
  1596. mov di , ax
  1597. add di , [ x0 ]
  1598. ;*===================================================================
  1599. ;* Adjust the source for the top clip.
  1600. ;*===================================================================
  1601. mov bx , [MouseWidth] ; turn this into an offset
  1602. mov si , [ buffy0 ] ; edx points to source
  1603. add si , [ buffx0 ] ; plus clipped lines
  1604. ;*===================================================================
  1605. ;* Calculate the bytes per row add value
  1606. ;*===================================================================
  1607. mov ax , 0a000h
  1608. mov ds , ax
  1609. mov ax , [ x1 ]
  1610. mov cx , [ y1 ]
  1611. sub ax , [ x0 ]
  1612. jle ??out
  1613. sub cx , [ y0 ]
  1614. jle ??out
  1615. sub dx , ax
  1616. sub bx , ax
  1617. ;*===================================================================
  1618. ;* Handle restoring the buffer to the visible page
  1619. ;*===================================================================
  1620. ??top_loop:
  1621. mov ah,al
  1622. ??inner_loop:
  1623. mov ch , [es:si]
  1624. inc esi
  1625. or ch,ch
  1626. jz ??inc_edi
  1627. mov [di],ch
  1628. ??inc_edi:
  1629. inc di
  1630. dec ah
  1631. jnz ??inner_loop
  1632. add si,bx ; move past right clipped pixels
  1633. add di,dx ; adjust dest to next line
  1634. dec cl ; decrement number of rows to do
  1635. jnz ??top_loop ; if more to do, do it
  1636. ??out:
  1637. IF ECHOON
  1638. mov ax , 0b000h
  1639. mov di , 12 * 80 + 14
  1640. mov es, ax
  1641. mov al , 'A'
  1642. mov [es:di],al
  1643. mov al,2
  1644. mov [es:di+1],al
  1645. ENDIF
  1646. ret
  1647. ENDP VGA_Draw_Mouse
  1648. ;***************************************************************************
  1649. ;***************************************************************************
  1650. ;***************************************************************************
  1651. ;* MOUSE_SHADOW_BUFFER -- Handles storing and restoring the mouse buffer *
  1652. ;* *
  1653. ;* INPUT: int store - indicates whether we are storing the buffer or *
  1654. ;* not. *
  1655. ;* *
  1656. ;* OUTPUT: none *
  1657. ;* *
  1658. ;* PROTO: Asm callable only! *
  1659. ;* *
  1660. ;* HISTORY: *
  1661. ;* 10/27/1994 PWG : Created. *
  1662. ;*=========================================================================*
  1663. GLOBAL C VESA_Mouse_Shadow_Buffer:FAR
  1664. PROC VESA_Mouse_Shadow_Buffer C FAR
  1665. USES ax,bx,cx,dx,di,si,ds,es
  1666. ARG store:WORD
  1667. local x0 : word
  1668. local y0 : word
  1669. local x1 : word
  1670. local y1 : word
  1671. local buffx0 : word
  1672. local buffy0 : word
  1673. ;*=========================================================================*
  1674. ;* Since we are in tiny model point ds to cs
  1675. ;*=========================================================================*
  1676. mov ax,cs ; since we are in tiny model
  1677. mov ds,ax ; set cs = ds
  1678. call get_vesa_window
  1679. mov [ app_vesa_window ] , dx
  1680. ;*=========================================================================*
  1681. ; Direction flag must be forward in this routine.
  1682. ;*=========================================================================*
  1683. cld
  1684. ;*===================================================================
  1685. ;* Copy of X, Y, Width and Height into local registers
  1686. ;*===================================================================
  1687. mov ax,[MouseBuffX]
  1688. mov bx,[MouseBuffY]
  1689. sub ax , [ MouseXHot ]
  1690. sub bx , [ MouseYHot ]
  1691. mov [ x0 ] , ax
  1692. mov [ y0 ] , bx
  1693. add ax , [MouseBuffW]
  1694. add bx , [MouseBuffH]
  1695. mov [ x1 ] , ax
  1696. mov [ y1 ] , bx
  1697. mov [ buffx0 ] , 0
  1698. mov ax , [ word ptr MouseBuffer ]
  1699. mov [ buffy0 ] , ax
  1700. ;*===================================================================
  1701. ;* Bounds check source X. Y.
  1702. ;*===================================================================
  1703. xor ax , ax
  1704. xor dx , dx
  1705. mov cx , [ x0 ]
  1706. mov bx , [ x1 ]
  1707. add cx , cx
  1708. adc ax , ax
  1709. add bx , bx
  1710. adc dx , dx
  1711. mov cx , [ x0 ]
  1712. mov bx , [ x1 ]
  1713. sub cx , [ MouseRight ]
  1714. sub bx , [ MouseRight ]
  1715. dec cx
  1716. dec bx
  1717. add cx , cx
  1718. adc ax , ax
  1719. add bx , bx
  1720. adc dx , dx
  1721. mov cx , [ y0 ]
  1722. mov bx , [ y1 ]
  1723. add cx , cx
  1724. adc ax , ax
  1725. add bx , bx
  1726. adc dx , dx
  1727. mov cx , [ y0 ]
  1728. mov bx , [ y1 ]
  1729. sub cx , [MouseBottom]
  1730. sub bx , [MouseBottom]
  1731. dec cx
  1732. dec bx
  1733. add cx , cx
  1734. adc ax , ax
  1735. add bx , bx
  1736. adc dx , dx
  1737. xor al , 5
  1738. xor dl , 5
  1739. mov ah , al
  1740. test dl , al
  1741. jnz ??out
  1742. or al , dl
  1743. jz ??acepted
  1744. test ah , 1000b
  1745. jz ??scr_left_ok
  1746. mov bx , [ x0 ]
  1747. neg bx
  1748. mov [ buffx0 ] , bx
  1749. mov [ x0 ] , 0
  1750. ??scr_left_ok:
  1751. test ah , 0010b
  1752. jz ??scr_bottom_ok
  1753. push dx
  1754. mov ax , [ y0 ]
  1755. neg ax
  1756. mul [MouseBuffW]
  1757. add [ buffy0 ] , ax
  1758. mov [ y0 ] , 0
  1759. pop dx
  1760. ??scr_bottom_ok:
  1761. test dl , 0100b
  1762. jz ??scr_right_ok
  1763. mov ax , [MouseRight] ; get width into register
  1764. mov [ x1 ] , ax
  1765. ??scr_right_ok:
  1766. test dl , 0001b
  1767. jz ??acepted
  1768. mov ax , [MouseBottom] ; get width into register
  1769. mov [ y1 ] , ax
  1770. ??acepted:
  1771. ;*===================================================================
  1772. ;* Get the offset into the screen.
  1773. ;*===================================================================
  1774. mov ax,0A000h
  1775. mov es,ax
  1776. mov ax , [ y0 ]
  1777. mul [ MouseRight ]
  1778. add ax , [ x0 ]
  1779. adc dx , 0
  1780. mov di , ax
  1781. call set_vesa_page
  1782. mov dx , [MouseRight]
  1783. ;*===================================================================
  1784. ;* Adjust the source for the top clip.
  1785. ;*===================================================================
  1786. mov bx , [ MouseWidth ] ; turn this into an offset
  1787. lds si , [ MouseBuffer ]
  1788. mov si , [ buffy0 ] ; edx points to source
  1789. add si , [ buffx0 ] ; plus clipped lines
  1790. ;*===================================================================
  1791. ;* Calculate the bytes per row add value
  1792. ;*===================================================================
  1793. mov ax , [ x1 ]
  1794. mov cx , [ y1 ]
  1795. sub ax , [ x0 ]
  1796. jle ??out
  1797. sub cx , [ y0 ]
  1798. jle ??out
  1799. sub dx , ax
  1800. sub bx , ax
  1801. cmp [store],RESTORE_VISIBLE_PAGE ; are we restoring page?
  1802. jne ??store_entry ; if not the go to store
  1803. ;*===================================================================
  1804. ;* Handle restoring the buffer to the visible page
  1805. ;*===================================================================
  1806. ??restore_loop:
  1807. mov ah,al
  1808. ??res_inner_loop:
  1809. mov ch , [si]
  1810. mov [es:di],ch
  1811. inc si
  1812. inc di
  1813. jnz ??res_same_page
  1814. call next_vesa_page
  1815. ??res_same_page:
  1816. dec ah
  1817. jnz ??res_inner_loop
  1818. add si,bx ; move past right clipped pixels
  1819. add di,dx ; adjust dest to next line
  1820. jnc ??res_same_page1
  1821. call next_vesa_page
  1822. ??res_same_page1:
  1823. dec cl ; decrement number of rows to do
  1824. jnz ??restore_loop
  1825. IF ECHOON
  1826. mov ax , 0b000h
  1827. mov di , 10 * 80 + 10
  1828. mov es,ax
  1829. mov al ,'v'
  1830. mov [es:di],al
  1831. mov al,2
  1832. mov [es:di+1],al
  1833. ENDIF
  1834. jmp ??out
  1835. ;*===================================================================
  1836. ;* Handle soting the visible page into the Mouse Shadow Buffer
  1837. ;*===================================================================
  1838. ??store_entry:
  1839. mov ah,al
  1840. ??store_inner_loop:
  1841. mov ch , [es:di]
  1842. mov [si],ch
  1843. inc si
  1844. inc di
  1845. jnz ??store_same_page
  1846. call next_vesa_page
  1847. ??store_same_page:
  1848. dec ah
  1849. jnz ??store_inner_loop
  1850. add si,bx ; move past right clipped pixels
  1851. add di,dx ; adjust dest to next line
  1852. jnc ??store_same_page1
  1853. call next_vesa_page
  1854. ??store_same_page1:
  1855. dec cl ; decrement number of rows to do
  1856. jnz ??store_entry
  1857. ??out:
  1858. IF ECHOON
  1859. mov ax , 0b000h
  1860. mov di , 10 * 80 + 14
  1861. mov es,ax
  1862. mov al ,'e'
  1863. mov [es:di],al
  1864. mov al,2
  1865. mov [es:di+1],al
  1866. ENDIF
  1867. mov dx , [ app_vesa_window ]
  1868. call set_vesa_window
  1869. ret
  1870. ENDP VESA_Mouse_Shadow_Buffer
  1871. ;***************************************************************************
  1872. GLOBAL C VESA_Draw_Mouse:FAR
  1873. PROC VESA_Draw_Mouse C FAR
  1874. USES ax,bx,cx,dx,di,si,ds,es
  1875. ARG mousex:WORD
  1876. ARG mousey:WORD
  1877. local x0 : word
  1878. local y0 : word
  1879. local x1 : word
  1880. local y1 : word
  1881. local buffx0 : word
  1882. local buffy0 : word
  1883. local app_vesa_window : word
  1884. ;*=========================================================================*
  1885. ;* Since we are in tiny model point ds to cs
  1886. ;*=========================================================================*
  1887. mov ax,cs ; since we are in tiny model
  1888. mov ds,ax ; set cs = ds
  1889. call get_vesa_window
  1890. mov [ app_vesa_window ] , dx
  1891. ;*===================================================================
  1892. ;* Pre-initialize the left, right and topclip values to zero.
  1893. ;*===================================================================
  1894. mov ax, [ mousex ]
  1895. mov bx , [ mousey ]
  1896. sub ax , [ MouseXHot ]
  1897. sub bx , [ MouseYHot ]
  1898. mov [ x0 ] , ax
  1899. mov [ y0 ] , bx
  1900. add ax, [ MouseWidth ]
  1901. add bx, [ MouseHeight ]
  1902. mov [ x1 ] , ax
  1903. mov [ y1 ] , bx
  1904. mov [ buffx0 ] , 0
  1905. les ax , [ MouseCursor ]
  1906. mov [ buffy0 ] , ax
  1907. ;*===================================================================
  1908. ;* Bounds check source X. Y.
  1909. ;*===================================================================
  1910. xor ax , ax
  1911. xor dx , dx
  1912. mov cx , [ x0 ]
  1913. mov bx , [ x1 ]
  1914. add cx , cx
  1915. adc ax , ax
  1916. add bx , bx
  1917. adc dx , dx
  1918. mov cx , [ x0 ]
  1919. mov bx , [ x1 ]
  1920. sub cx , [ MouseRight ]
  1921. sub bx , [ MouseRight ]
  1922. dec cx
  1923. dec bx
  1924. add cx , cx
  1925. adc ax , ax
  1926. add bx , bx
  1927. adc dx , dx
  1928. mov cx , [ y0 ]
  1929. mov bx , [ y1 ]
  1930. add cx , cx
  1931. adc ax , ax
  1932. add bx , bx
  1933. adc dx , dx
  1934. mov cx , [ y0 ]
  1935. mov bx , [ y1 ]
  1936. sub cx , [MouseBottom]
  1937. sub bx , [MouseBottom]
  1938. dec cx
  1939. dec bx
  1940. add cx , cx
  1941. adc ax , ax
  1942. add bx , bx
  1943. adc dx , dx
  1944. xor al , 5
  1945. xor dl , 5
  1946. mov ah , al
  1947. test dl , al
  1948. jnz ??out
  1949. or al , dl
  1950. jz ??acepted
  1951. test ah , 1000b
  1952. jz ??scr_left_ok
  1953. mov bx , [ x0 ]
  1954. neg bx
  1955. mov [ buffx0 ] , bx
  1956. mov [ x0 ] , 0
  1957. ??scr_left_ok:
  1958. test ah , 0010b
  1959. jz ??scr_bottom_ok
  1960. push dx
  1961. mov ax , [ y0 ]
  1962. neg ax
  1963. mul [MouseWidth]
  1964. add [ buffy0 ] , ax
  1965. mov [ y0 ] , 0
  1966. pop dx
  1967. ??scr_bottom_ok:
  1968. test dl , 0100b
  1969. jz ??scr_right_ok
  1970. mov ax , [MouseRight] ; get width into register
  1971. mov [ x1 ] , ax
  1972. ??scr_right_ok:
  1973. test dl , 0001b
  1974. jz ??acepted
  1975. mov ax , [MouseBottom] ; get width into register
  1976. mov [ y1 ] , ax
  1977. ??acepted:
  1978. mov ax , [ y0 ]
  1979. mul [ MouseRight ]
  1980. add ax , [ x0 ]
  1981. adc dx , 0
  1982. mov di , ax
  1983. call set_vesa_page
  1984. mov dx , [MouseRight]
  1985. ;*===================================================================
  1986. ;* Adjust the source for the top clip.
  1987. ;*===================================================================
  1988. mov bx , [MouseWidth] ; turn this into an offset
  1989. mov si , [ buffy0 ] ; edx points to source
  1990. add si , [ buffx0 ] ; plus clipped lines
  1991. ;*===================================================================
  1992. ;* Calculate the bytes per row add value
  1993. ;*===================================================================
  1994. mov ax , 0a000h
  1995. mov ds , ax
  1996. mov ax , [ x1 ]
  1997. mov cx , [ y1 ]
  1998. sub ax , [ x0 ]
  1999. jle ??out
  2000. sub cx , [ y0 ]
  2001. jle ??out
  2002. sub dx , ax
  2003. sub bx , ax
  2004. ;*===================================================================
  2005. ;* Handle restoring the buffer to the visible page
  2006. ;*===================================================================
  2007. ??top_loop:
  2008. mov ah,al
  2009. ??inner_loop:
  2010. mov ch , [es:si]
  2011. inc si
  2012. or ch,ch
  2013. jz ??inc_edi
  2014. mov [di],ch
  2015. ??inc_edi:
  2016. inc di
  2017. jnz ??same_page
  2018. call next_vesa_page
  2019. ??same_page:
  2020. dec ah
  2021. jnz ??inner_loop
  2022. add si,bx ; move past right clipped pixels
  2023. add di,dx ; adjust dest to next line
  2024. jnc ??same_page1
  2025. call next_vesa_page
  2026. ??same_page1:
  2027. dec cl ; decrement number of rows to do
  2028. jnz ??top_loop ; if more to do, do it
  2029. ??out:
  2030. IF ECHOON
  2031. mov ax , 0b000h
  2032. mov di , 10 * 80 + 14
  2033. mov es, ax
  2034. mov al , 's'
  2035. mov [es:di],al
  2036. mov al,2
  2037. mov [es:di+1],al
  2038. mov di , 10 * 80 + 16
  2039. mov al , 'a'
  2040. mov [es:di],al
  2041. mov al,2
  2042. mov [es:di+1],al
  2043. ENDIF
  2044. mov dx , [ app_vesa_window ]
  2045. call set_vesa_window
  2046. ret
  2047. ENDP VESA_Draw_Mouse
  2048. ;************************************************************************
  2049. PROC get_vesa_window C near
  2050. uses ax,bx
  2051. mov ax , 04f05h
  2052. mov bh , 1
  2053. mov bl , 0
  2054. call [ dword ptr cs: VesaPtr ]
  2055. ret
  2056. ENDP
  2057. ;************************************************************************
  2058. PROC set_vesa_window C near
  2059. uses ax,bx,dx
  2060. mov ax , 04f05h
  2061. mov bh , 0
  2062. mov bl , 0
  2063. call [ dword ptr cs: VesaPtr ]
  2064. ret
  2065. ENDP
  2066. ;***************************************************************************
  2067. PROC set_vesa_page C near
  2068. USES ax,bx,dx
  2069. mov bx , dx
  2070. shl bx , 2
  2071. mov [ cs: current_page ] , bx
  2072. mov dx , [ word ptr cs:banktable + bx ]
  2073. mov ax , 04f05h
  2074. mov bh , 0
  2075. mov bl , 0
  2076. call [ dword ptr cs: VesaPtr ]
  2077. ret
  2078. ENDP set_vesa_page
  2079. PROC next_vesa_page C near
  2080. USES ax,bx,dx
  2081. mov bx , [ cs: current_page ]
  2082. add bx , 4
  2083. mov [ cs:current_page ] , bx
  2084. mov dx , [ word ptr cs:banktable + bx ]
  2085. mov ax , 04f05h
  2086. mov bh , 0
  2087. mov bl , 0
  2088. call [ dword ptr cs: VesaPtr ]
  2089. ret
  2090. ENDP next_vesa_page
  2091. ;***********************************************************
  2092. END