Mousesys.asm 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. include_macros equ 1
  2. include_deb_mac equ 1
  3. include_struc equ 1
  4. include_flags equ 1
  5. include include.asm
  6. start32data
  7. emouse_b dd 0
  8. lock_mouse_x dd ?
  9. lock_mouse_y dd ?
  10. align 4
  11. mousexoff dd 0 ;mouse x offset
  12. no_main_objects equ 24 ;table for which mouse goes with which object
  13. no_linc_objects equ 21
  14. mouse_object_list dd 65
  15. dd 9
  16. dd 66
  17. dd 64
  18. dd 8
  19. dd 63
  20. dd 10
  21. dd 11
  22. dd 71
  23. dd 76
  24. dd 37
  25. dd 36
  26. dd 42
  27. dd 75
  28. dd 79
  29. dd 6
  30. dd 74
  31. dd 39
  32. dd 49
  33. dd 43
  34. dd 34
  35. dd 35
  36. dd 77
  37. dd 38
  38. ; Link cursors
  39. dd 24625
  40. dd 24649
  41. dd 24827
  42. dd 24651
  43. dd 24583
  44. dd 24581
  45. dd 24582
  46. dd 24628
  47. dd 24650
  48. dd 24629
  49. dd 24732
  50. dd 24631
  51. dd 24584
  52. dd 24630
  53. dd 24626
  54. dd 24627
  55. dd 24632
  56. dd 24643
  57. dd 24828
  58. dd 24830
  59. dd 24829
  60. ifdef with_replay
  61. data_saved dd 0 ;used to prevent double checks
  62. endif
  63. end32data
  64. start32code
  65. extrn script:near
  66. extrn sprite_mouse:near
  67. mouse_engine proc
  68. test [mouse_b],-1 ;fucking amiga bodge
  69. jne not_amiga_bodge
  70. mov [logic_talk_button_release],0
  71. not_amiga_bodge:
  72. mov eax,[amouse_x] ;make a copy of the mouse registers
  73. add eax,top_left_x
  74. mov [tmousex],eax
  75. mov eax,[amouse_y]
  76. add eax,top_left_y
  77. mov [tmousey],eax
  78. clear eax ;ensure button not pressed while looking at it
  79. xchg eax,[bmouse_b]
  80. mov [emouse_b],eax
  81. ifdef with_replay
  82. mov [data_saved],0
  83. call check_replay_mouse
  84. endif
  85. test [mouse_stop],-1 ;mouse stop?
  86. jne me_ret
  87. bt [mouse_status],1 ;cursor and buttons?
  88. jnc me_ret
  89. call pointer_engine
  90. bt [mouse_status],2 ;buttons enabled?
  91. jc button_engine_1
  92. me_ret: mov [emouse_b],0 ;don't save up buttons
  93. ret
  94. mouse_engine endp
  95. pointer_engine proc
  96. ; What is the pointer over
  97. ; run get-ons and get-offs
  98. ; using a seperate list of id's has the added advantage
  99. ; of allowing us to set the priority of each item.
  100. ; i.e. people come before floor areas...
  101. mov eax,[mouse_list_no] ;starting mouse list number - the list may change itself
  102. get_mouse_list: fetch_compact edi
  103. pointer_loop: flodswl eax,edi
  104. jife eax,pointer_eol
  105. cmp ax,-1
  106. jne not_address_skip
  107. mov ax,[edi] ;new list id
  108. jmp get_mouse_list
  109. not_address_skip: fetch_compact
  110. bt (cpt[esi]).c_status,4 ;is mouse detectable
  111. jnc pointer_loop
  112. mov eax,[screen] ;on current screen?
  113. cmp ax,(cpt[esi]).c_screen
  114. jne pointer_loop
  115. ; Find the set
  116. mov ax,(cpt[esi]).c_mouse_rel_x ;look at mouse x
  117. add ax,(cpt[esi]).c_xcood
  118. cmp ax,wpt[tmousex]
  119. ja pointer_loop ;too far left?
  120. add ax,(cpt[esi]).c_mouse_size_x
  121. cmp ax,wpt[tmousex]
  122. jc pointer_loop ;too far right?
  123. ; now y
  124. mov ax,(cpt[esi]).c_mouse_rel_y
  125. add ax,(cpt[esi]).c_ycood
  126. cmp ax,wpt[tmousey]
  127. ja pointer_loop ;too high?
  128. add ax,(cpt[esi]).c_mouse_size_y
  129. cmp ax,wpt[tmousey]
  130. jc pointer_loop
  131. ; its a hit
  132. movzx eax,wpt[edi-2] ;get id of item
  133. pointer_eol: ;ax is 0 or id of item beneath cursor
  134. cmp eax,[special_item]
  135. je pe_ret
  136. ; ok, the pointer has a change of circumstances
  137. ; if the cursor is now over nothing then run the
  138. ; get-off script, else, if the cursor is now over something
  139. ; then run the new get-on and set up a new get off
  140. ifdef with_replay
  141. call save_mouse_values
  142. endif
  143. mov [special_item],eax
  144. jife eax,run_get_off
  145. ; ok, the cursor is over something
  146. ; run the get-off if it was previously over something else
  147. mov eax,[get_off]
  148. jife eax,setup_on
  149. call script
  150. setup_on: ;over something so run new get-on
  151. movzx eax,(cpt[esi]).c_mouse_off ;save get off for later
  152. mov [get_off],eax
  153. movzx eax,(cpt[esi]).c_mouse_on
  154. jife eax,pe_ret
  155. jmp script
  156. pe_ret:: ret
  157. pointer_engine endp
  158. run_get_off proc
  159. ; run and clear get off script
  160. clear eax
  161. xchg eax,[get_off]
  162. jife eax,pe_ret
  163. jmp script
  164. run_get_off endp
  165. button_engine_1 proc
  166. ; checks for clicking on special_item
  167. ; "compare the size of this routine to S1 mouse_button"
  168. test [emouse_b],-1 ;anything pressed
  169. je no_button
  170. ; ok, a button is pressed
  171. ifdef with_replay
  172. call save_mouse_values
  173. endif
  174. mov eax,[emouse_b]
  175. mov [button],eax
  176. mov [emouse_b],0
  177. mov eax,[special_item] ;over anything?
  178. jife eax,no_button
  179. fetch_compact
  180. movzx eax,(cpt[esi]).c_mouse_click
  181. jife eax,no_button
  182. jmp script ;do the script
  183. no_button: ret
  184. button_engine_1 endp
  185. fn_disk_mouse proc
  186. ; Turn the mouse into a disk mouse
  187. mov eax,mouse_disk
  188. mov ebx,11
  189. mov ecx,11
  190. call sprite_mouse
  191. mov al,1 ;don't quit from interpreter
  192. ret
  193. fn_disk_mouse endp
  194. fn_normal_mouse proc
  195. mov eax,mouse_normal
  196. clear ebx
  197. clear ecx
  198. call sprite_mouse
  199. mov al,1
  200. ret
  201. fn_normal_mouse endp
  202. fn_no_human proc
  203. test [mouse_stop],-1
  204. jne mouse_locked
  205. and [mouse_status],1 ;preserve stop, kill cursor and buttons
  206. call run_get_off ;clear anything else
  207. call fn_blank_mouse ;no cursor
  208. mouse_locked: mov al,1 ;keep going
  209. ret
  210. fn_no_human endp
  211. fn_set_stop proc
  212. or [mouse_stop],1 ;set the stop flag
  213. mov al,1 ;and keep going
  214. ret
  215. fn_set_stop endp
  216. fn_blank_mouse proc
  217. mov [mousexoff],0 ;re-align mouse
  218. mov eax,mouse_blank
  219. clear ebx
  220. clear ecx
  221. call sprite_mouse
  222. mov al,1
  223. ret
  224. fn_blank_mouse endp
  225. fn_cross_mouse proc
  226. test [object_held],-1
  227. jne fn_close_hand
  228. fn_cross_mouse endp
  229. do_cross_mouse proc
  230. mov eax,mouse_cross
  231. mov ebx,4 ;5
  232. mov ecx,4
  233. call sprite_mouse
  234. mov al,1
  235. ret
  236. do_cross_mouse endp
  237. fn_close_hand proc
  238. ; Indicate we have an object that is not over an object
  239. mov edx,[object_held]
  240. jife edx,fn_normal_mouse ;no object no mouse cursor
  241. ; Find the sprite to go with this object
  242. call find_mouse_cursor
  243. shl eax,1
  244. mov esi,[object_mouse_data] ;get offset into data
  245. movzx ecx,(s ptr[esi]).s_sp_size
  246. imul eax,ecx
  247. add eax,SIZE s
  248. add esi,eax
  249. mov edi,[mice_data] ;transfer data to first mouse sprite
  250. add edi,SIZE s
  251. rep movsb
  252. clear eax
  253. mov ebx,5
  254. mov ecx,5
  255. call sprite_mouse
  256. mov al,1
  257. ret
  258. fn_close_hand endp
  259. fn_open_hand proc
  260. ; Indicate we have an object which is over another object
  261. mov esi,offset mouse_object_list
  262. ; Find the sprite to go with this object
  263. mov edx,[object_held]
  264. call find_mouse_cursor
  265. shl eax,1
  266. inc eax
  267. mov esi,[object_mouse_data] ;get offset into data
  268. movzx ecx,(s ptr[esi]).s_sp_size
  269. imul eax,ecx
  270. add eax,SIZE s
  271. add esi,eax
  272. mov edi,[mice_data] ;transfer data to first mouse sprite
  273. add edi,SIZE s
  274. rep movsb
  275. clear eax
  276. mov ebx,5
  277. mov ecx,5
  278. call sprite_mouse
  279. mov al,1
  280. ret
  281. fn_open_hand endp
  282. fn_cursor_left proc
  283. mov eax,mouse_left
  284. clear ebx
  285. mov ecx,5
  286. call sprite_mouse
  287. mov al,1
  288. ret
  289. fn_cursor_left endp
  290. fn_cursor_right proc
  291. mov eax,mouse_right
  292. mov ebx,9
  293. mov ecx,4
  294. call sprite_mouse
  295. mov al,1
  296. ret
  297. fn_cursor_right endp
  298. fn_cursor_down proc
  299. mov eax,mouse_down
  300. mov ebx,9
  301. mov ecx,4
  302. call sprite_mouse
  303. mov al,1
  304. ret
  305. fn_cursor_down endp
  306. fn_cursor_up proc
  307. mov eax,mouse_up
  308. mov ebx,9
  309. mov ecx,4
  310. call sprite_mouse
  311. mov al,1
  312. ret
  313. fn_cursor_up endp
  314. fn_no_buttons proc
  315. ; remove the mouse buttons
  316. and [mouse_status],0fffffffbh
  317. mov al,1
  318. ret
  319. fn_no_buttons endp
  320. fn_add_buttons proc
  321. mov al,4 ;use this to keep script going
  322. or bpt[mouse_status],al
  323. ret
  324. fn_add_buttons endp
  325. ifdef with_replay
  326. save_mouse_values proc
  327. test [data_saved],-1
  328. jne no_record
  329. mov [data_saved],1
  330. pusha
  331. ; Save a mouse action
  332. ; Sometimes the thing the mouse is interacting with will be slightly off position, basically
  333. ; mega characters. Save certain megas' coordinates so we are sure to hit them
  334. mov eax,[special_item]
  335. cmp eax,1
  336. je save_joey
  337. cmp eax,16
  338. je save_joey
  339. cmp eax,16441
  340. je save_joey
  341. jmp no_save
  342. save_joey: push eax
  343. fetch_compact
  344. mov eax,-2 ;-2 = save joey coords
  345. pop ebx
  346. shl ebx,16
  347. mov bx,(cpt[esi]).c_screen ;save screen x and y
  348. mov cx,(cpt[esi]).c_xcood
  349. shl ecx,16
  350. mov cx,(cpt[esi]).c_ycood
  351. call replay_record_event
  352. no_save: mov eax,[tmousex]
  353. mov ebx,[tmousey]
  354. mov ecx,[emouse_b]
  355. call replay_record_event
  356. popa
  357. no_record: ret
  358. save_mouse_values endp
  359. endif
  360. wait_mouse_not_pressed proc
  361. test [mouse_b],-1
  362. jne wait_mouse_not_pressed
  363. mov [bmouse_b],0
  364. ret
  365. wait_mouse_not_pressed endp
  366. find_mouse_cursor proc
  367. ; Find mouse cursor for item edx
  368. mov esi,offset mouse_object_list
  369. ; Check main game objects
  370. mov eax,no_main_objects
  371. mov ecx,eax
  372. find_mouse1: cmp edx,[esi]
  373. je found_mouse
  374. lea esi,4[esi]
  375. loop find_mouse1
  376. ; Check linc objects
  377. mov eax,no_linc_objects
  378. mov ecx,eax
  379. find_mouse2: cmp edx,[esi]
  380. je found_mouse
  381. lea esi,4[esi]
  382. loop find_mouse2
  383. mov ecx,eax
  384. found_mouse: sub eax,ecx ;calculate sprite number
  385. ret
  386. find_mouse_cursor endp
  387. lock_mouse proc
  388. mov eax,[amouse_x]
  389. mov [lock_mouse_x],eax
  390. mov eax,[amouse_y]
  391. mov [lock_mouse_y],eax
  392. ret
  393. lock_mouse endp
  394. unlock_mouse proc
  395. mov ecx,[lock_mouse_x]
  396. mov [amouse_x],ecx
  397. mov edx,[lock_mouse_y]
  398. mov [amouse_y],edx
  399. mov ax,4
  400. shl ecx,1
  401. int 33h
  402. ret
  403. unlock_mouse endp
  404. end32code
  405. end
  406.