Function.asm 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. include_macros equ 1
  2. include_deb_mac equ 1
  3. include_struc equ 1
  4. include_sequates equ 1
  5. include_scripts equ 1
  6. include_flags equ 1
  7. include_logic equ 1
  8. include_error_codes equ 1
  9. include include.asm
  10. start32data
  11. max_objects equ 30
  12. object_list dd max_objects dup (?)
  13. tmousex dd ?
  14. tmousey dd ?
  15. new_safe_x dd ?
  16. new_safe_y dd ?
  17. current_section dd -1
  18. end32data
  19. start32save_data
  20. save_current_section dd -1
  21. past_intro dd 0 ;set when past intro sequence
  22. end32save_data
  23. start32code
  24. extrn logic_turn:near
  25. extrn logic_simple_anim:near
  26. extrn logic_anim:near
  27. extrn logic_script:near
  28. extrn remove_object_from_walk:near
  29. fn_get_to proc
  30. ; always load a get-to script- S2(28Aug92tw)
  31. ; does NOT check to see if we're at the place
  32. ; this is because with doorways you walk to different
  33. ; places according to whether the door is open or closed
  34. ; so if you click on a closed door you walk to the closed
  35. ; door & open it - if you then click again you run the
  36. ; same get-to which will now walk you through the door
  37. ; because its open. this is also the reason that the
  38. ; action mode is passed here - because some get-to's
  39. ; need to know what you're going to do in order to get
  40. ; you to the right place - strange - but true
  41. ; esi is compact
  42. ; eax is target place id
  43. ; ebx is mode - doors need to know at get-to stage
  44. ; - before the action script
  45. mov (cpt [esi]).c_up_flag,bx ;save mode for action script
  46. push eax ;save target place id
  47. movzx eax,(cpt [esi]).c_place ;where we currently are
  48. add (cpt [esi]).c_mode,4 ;next level up
  49. fetch_compact edi
  50. mov edi,(cpt [edi]).c_get_to_table ;get get to table
  51. pop eax
  52. cherror edi,e,0,em_internal_error
  53. get_to_loop: cmp ax,[edi] ;found entry?
  54. je load_script
  55. cherror wpt [edi],e,-1,em_internal_error ;if we get to end (-1) then place is missing
  56. lea edi,4[edi]
  57. jmp get_to_loop
  58. load_script: movzx ebx,(cpt [esi]).c_mode ;get current mode
  59. movzx eax,wpt 2[edi] ;get new script
  60. mov c_base_sub[esi+ebx],eax
  61. clear eax ;drop out of script
  62. ret ;but stay in script mode
  63. fn_get_to endp
  64. fn_ar proc
  65. ; Set mega esi to route to eax=x,ebx=y
  66. mov (cpt [esi]).c_down_flag,1 ;assume failure in-case logic is interupted by speech (esp Joey)
  67. mov (cpt [esi]).c_ar_target_x,ax
  68. mov (cpt [esi]).c_ar_target_y,bx
  69. mov (cpt [esi]).c_logic,l_ar ;Set to AR mode
  70. and (cpt [esi]).c_xcood,0fff8h
  71. and (cpt [esi]).c_ycood,0fff8h
  72. clear eax ;drop out of script
  73. ret
  74. fn_ar endp
  75. fn_leaving proc
  76. ; mega is leaving this place for the next
  77. ; sub 1 from previous place's at flag S2(14Oct92tw)
  78. ; also clear the previous at-watch flag
  79. ; its possible that neither may have been set...
  80. ; * inc'ing & dec'ing has the effect of
  81. ; showing us how many people are at a place
  82. ; and not just anyone here, yes or no
  83. mov (cpt[esi]).c_at_watch,0 ;clear the previous place's
  84. ;at watch flag - there might
  85. ;not have been one
  86. movzx eax,(cpt[esi]).c_leaving ;get the previous flag
  87. jife ax,no_previous_flag
  88. sub dpt [offset script_variables+eax],1 ;decrement the script variable
  89. mov (cpt[esi]).c_leaving,0 ;I shall do this only once
  90. no_previous_flag: mov al,1 ;keep going
  91. ret
  92. fn_leaving endp
  93. fn_ar_animate proc
  94. ; Set compact to animation
  95. mov (cpt[esi]).c_mood,0 ;high level 'not stood still'
  96. mov (cpt[esi]).c_logic,l_ar_anim
  97. clear eax ;drop out of script
  98. ret
  99. fn_ar_animate endp
  100. fn_turn_to proc
  101. ; turn compact esi to direction al
  102. mov ebx,eax
  103. clear eax
  104. mov al,20 ;5 tables = 5 dwords
  105. mul (cpt[esi]).c_dir ;get current direction
  106. mov (cpt[esi]).c_dir,bx ;set new direction
  107. add ax,(cpt[esi]).c_mega_set
  108. lea eax,(cpt[esi+eax]).c_turn_table_up
  109. mov eax,[eax+ebx*4] ;get direction data
  110. jife eax,no_turn
  111. mov (cpt[esi]).c_turn_prog,eax ;put turn program in
  112. mov (cpt[esi]).c_logic,l_turning
  113. call logic_turn
  114. clear eax ;drop out of script
  115. ret
  116. no_turn: mov al,1 ;keep going
  117. ret
  118. fn_turn_to endp
  119. fn_set_to_stand proc
  120. ; run the appropriate animation for what
  121. ; direction the mega is facing S2(3Sep92tw)
  122. ; the animator returns to script mode
  123. ; * processes first stand cycle to avoid gaps
  124. mov (cpt[esi]).c_mood,1 ;high level stood still
  125. movzx eax,(cpt[esi]).c_dir ;get direction
  126. movzx ebx,(cpt[esi]).c_mega_set ;get mega set
  127. lea ebx,(cpt[ebx+esi]).c_stand_up
  128. mov ebx,[ebx+eax*4] ;get pointer to data
  129. flodsws ax,ebx ;get frames offset
  130. mov (cpt[esi]).c_offset,ax
  131. mov (cpt[esi]).c_grafix_prog,ebx
  132. mov (cpt[esi]).c_logic,l_simple_mod
  133. call logic_simple_anim
  134. clear eax ;drop out of script
  135. ret
  136. fn_set_to_stand endp
  137. fn_foreground proc
  138. ; Make sprite eax a foreground sprite
  139. fetch_compact
  140. and bpt(cpt[esi]).c_status,0f8h
  141. or bpt(cpt[esi]).c_status,st_foreground
  142. mov eax,1
  143. ret
  144. fn_foreground endp
  145. fn_toggle_grid proc
  146. ; Toggle a mega's grid plotting
  147. mov al,st_grid_plot ;use this to continue script
  148. xor bpt(cpt[esi]).c_status,al
  149. ret
  150. fn_toggle_grid endp
  151. fn_run_anim_mod proc
  152. ; Set to l_animate mode
  153. ; coordinates yes
  154. ; sync no
  155. ; eax is animation number
  156. fetch_compact edi
  157. ; edi points to animation data
  158. flodsws ax,edi ;get sprite set
  159. mov (cpt[esi]).c_offset,ax
  160. mov (cpt[esi]).c_grafix_prog,edi
  161. mov (cpt[esi]).c_logic,l_mod_animate
  162. call logic_anim
  163. clear eax ;drop from script
  164. ret
  165. fn_run_anim_mod endp
  166. fn_reset_id proc
  167. ; used when a mega is to be restarted
  168. ; eg - when a smaller mega turn to larger
  169. ; - a mega changes rooms...
  170. ; eax is id, ebx is reset block
  171. fetch_compact
  172. mov eax,ebx
  173. fetch_compact edi
  174. reset_loop: movzx eax,wpt[edi]
  175. add edi,2
  176. cmp ax,-1
  177. je done
  178. flodsws bx,edi
  179. mov [esi+eax],bx
  180. jmp reset_loop
  181. done: ret ;ax=-1 for continue script
  182. fn_reset_id endp
  183. fn_inc_mega_set proc
  184. ; esi is mega
  185. mov eax,next_mega_set ;use this to continue script
  186. add (cpt[esi]).c_mega_set,ax
  187. ret
  188. fn_inc_mega_set endp
  189. fn_dec_mega_set proc
  190. mov eax,next_mega_set ;use this to continue script
  191. sub (cpt[esi]).c_mega_set,ax
  192. ret
  193. fn_dec_mega_set endp
  194. fn_sort proc
  195. ; Set mega eax to sort mode
  196. fetch_compact
  197. and bpt(cpt[esi]).c_status,0f8h
  198. mov al,st_sort ;use this to continue script
  199. or bpt(cpt[esi]).c_status,al
  200. ret
  201. fn_sort endp
  202. fn_add_human proc
  203. ; reintroduce the mouse so that the human
  204. ; can control the player
  205. ; could still be stwitched out at high-level
  206. test [mouse_stop],-1
  207. jne mouse_is_locked
  208. or [mouse_status],6 ;cursor & mouse
  209. mov eax,[new_safe_x]
  210. mov [tmousex],eax ;restore cursor x and y
  211. mov eax,[new_safe_y]
  212. mov [tmousey],eax
  213. cmp [amouse_y],2 ;stop mouse activating top line
  214. jnc no_y_cor
  215. mov [amouse_y],2
  216. no_y_cor:
  217. ; force the pointer engine into running a get-off
  218. ; even if it's over nothing
  219. ; KWIK-FIX
  220. ; get off may contain script to remove mouse pointer text
  221. ; surely this script should be run just in case
  222. ; I am going to try it anyway
  223. mov eax,[get_off]
  224. jife eax,no_get_off
  225. call script
  226. no_get_off: mov [special_item],-1
  227. mov [get_off],reset_mouse
  228. mouse_is_locked: mov al,1
  229. ret
  230. fn_add_human endp
  231. fn_interact proc
  232. ; esi is compact
  233. ; eax is target id
  234. add (cpt[esi]).c_mode,4 ;next level up
  235. mov (cpt[esi]).c_logic,l_script
  236. fetch_compact edi
  237. movzx eax,(cpt[edi]).c_action_script ;get target action script
  238. movzx ebx,(cpt[esi]).c_mode ;put into correct mode
  239. mov c_base_sub[esi+ebx],eax
  240. clear eax ;drop out of script
  241. ret
  242. fn_interact endp
  243. fn_await_sync proc
  244. test (cpt[esi]).c_sync,-1
  245. jne that_was_quick
  246. ; Set compact to l_wait_sync
  247. mov (cpt[esi]).c_logic,l_wait_sync
  248. clear eax ;drop out of script
  249. ret
  250. that_was_quick: mov al,1
  251. ret
  252. fn_await_sync endp
  253. fn_pause proc
  254. ; Set mega to l_pause
  255. ; wait eax cycles
  256. mov (cpt[esi]).c_flag,ax
  257. mov (cpt[esi]).c_logic,l_pause
  258. clear eax ;drop out of script
  259. ret
  260. fn_pause endp
  261. fn_send_sync proc
  262. ; Send a sync to a mega
  263. ; eax is mega
  264. ; ebx is sync value
  265. fetch_compact
  266. mov (cpt[esi]).c_sync,bx
  267. clear eax ;drop out of script
  268. ret
  269. fn_send_sync endp
  270. fn_quit proc
  271. clear eax ;just drop out of the script
  272. ret
  273. fn_quit endp
  274. fn_run_frames proc
  275. ; Set to l_frames
  276. ; sync checks but not on this first cycle
  277. ; eax is sequence number
  278. fetch_compact edi
  279. mov (cpt[esi]).c_logic,l_frames
  280. mov ax,[edi]
  281. mov (cpt[esi]).c_offset,ax
  282. add edi,2
  283. cherror wpt[edi],e,0,em_internal_error
  284. mov (cpt[esi]).c_grafix_prog,edi
  285. call logic_simple_anim
  286. clear eax ;drop out of script
  287. ret
  288. fn_run_frames endp
  289. fn_set_alternate proc
  290. ; change current script
  291. ; takes a whole cycle
  292. ; esi is mega
  293. ; ax is script
  294. mov (cpt[esi]).c_alt,ax
  295. mov (cpt[esi]).c_logic,l_alt
  296. clear eax ;stop the script
  297. ret
  298. fn_set_alternate endp
  299. fn_simple_mod proc
  300. ; set to l_simple_mod mode S2(19Nov92tw)
  301. ; as FN_run_anim_mod except we ignore
  302. ; the x,y coordinates in the sequence data
  303. ; eax is anim seq number
  304. fetch_compact edi
  305. flodsws ax,edi
  306. and eax,0ffffh
  307. mov (cpt[esi]).c_offset,ax
  308. cherror wpt[edi],e,0,em_internal_error
  309. mov (cpt[esi]).c_grafix_prog,edi
  310. mov (cpt[esi]).c_logic,l_simple_mod
  311. call logic_simple_anim
  312. clear eax
  313. ret
  314. fn_simple_mod endp
  315. fn_random proc
  316. ; eax is a number to and the random number with
  317. push eax
  318. call do_random
  319. pop ebx
  320. movzx eax,wpt[random+2]
  321. and eax,ebx
  322. mov [rnd],eax
  323. mov al,1 ;continue script
  324. ret
  325. fn_random endp
  326. fn_clear_stop proc
  327. mov [mouse_stop],0
  328. mov al,1
  329. ret
  330. fn_clear_stop endp
  331. fn_idle proc
  332. ; set the player idling
  333. mov (cpt[esi]).c_logic,0
  334. mov al,1 ;script continues
  335. ret
  336. fn_idle endp
  337. fn_kill_id proc
  338. ; remove compact eax from game
  339. jife eax,fk_ret ;id 0 = kill text
  340. push esi
  341. fetch_compact
  342. bt (cpt[esi]).c_status,7 ;plotted into grid?
  343. jnc not_on_grid
  344. call remove_object_from_walk
  345. not_on_grid: mov (cpt[esi]).c_status,0
  346. pop esi
  347. fk_ret: mov al,1 ;continue
  348. ret
  349. fn_kill_id endp
  350. fn_start_menu proc
  351. ; initialise the top menu bar S2(9Oct92tw)
  352. ; eax contains the address of the 1st object (o0 for game menu, k0 for linc)
  353. add eax,offset script_variables
  354. push eax
  355. ; (1) FIRST, SET UP THE 2 ARROWS SO THEY APPEAR ON SCREEN
  356. mov edx,[screen]
  357. mov eax,47
  358. fetch_compact
  359. mov (cpt[esi]).c_status,st_mouse+st_foreground+st_logic+st_recreate
  360. mov (cpt[esi]).c_screen,dx
  361. mov eax,48
  362. fetch_compact
  363. mov (cpt[esi]).c_status,st_mouse+st_foreground+st_logic+st_recreate
  364. mov (cpt[esi]).c_screen,dx
  365. ; (2) COPY OBJECTS FROM NON-ZERO INVENTORY VARIABLES INTO OBJECT DISPLAY LIST (& COUNT THEM)
  366. ; sort the objects and pad with blanks
  367. pop esi
  368. mov edi,offset object_list
  369. mov ecx,max_objects
  370. clear edx
  371. menu_create: lodsd
  372. jife eax,empty_slot
  373. stosd
  374. inc edx
  375. empty_slot: loop menu_create
  376. mov [menu_length],edx ;save menu length
  377. ; (3) OK, NOW TOP UP THE LIST WITH THE REQUIRED NO. OF BLANK OBJECTS (for min display length 11)
  378. cmp edx,11
  379. jnc stage_4
  380. mov eax,51 ;id of first blank
  381. mov ecx,11
  382. sub ecx,edx
  383. do_blank: stosd
  384. inc eax
  385. loop do_blank
  386. ; (4) KILL ID's OF ALL 20 OBJECTS SO UNWANTED ICONS (SCROLLED OFF) DON'T REMAIN ON SCREEN
  387. ; (There should be a better way of doing this - only kill id of 12th item when menu has scrolled right)
  388. stage_4: mov esi,offset object_list
  389. mov ecx,max_objects
  390. reset_icons_loop: lodsd
  391. jife eax,menu_5
  392. fetch_compact edi
  393. mov (cpt[edi]).c_status,st_logic
  394. loop reset_icons_loop
  395. ; (5) NOW FIND OUT WHICH OBJECT TO START THE DISPLAY FROM (depending on scroll offset)
  396. menu_5: mov esi,offset object_list
  397. cmp edx,11 ;check we can scroll
  398. jnc can_scroll
  399. mov [scroll_offset],0
  400. jmp stage_6
  401. can_scroll: mov ebx,[scroll_offset]
  402. sub edx,11 ;make edx no we can scroll
  403. cmp ebx,edx
  404. jc calc_bytes
  405. mov ebx,edx
  406. mov [scroll_offset],ebx
  407. calc_bytes: shl ebx,2 ;no of bytes to skip in object list
  408. add esi,ebx
  409. ; (6) AND FINALLY, INITIALISE THE 11 OBJECTS SO THEY APPEAR ON SCREEEN
  410. stage_6: mov edx,[menu] ;check if id_std_menu_logic
  411. ;sub edx,id_std_menu_logic
  412. mov ebp,[screen]
  413. mov ecx,11
  414. mov ebx,128+28 ;rolling x coordinate
  415. menu_int_loop: lodsd
  416. fetch_compact edi
  417. mov (cpt[edi]).c_status,st_mouse+st_foreground+st_logic+st_recreate
  418. mov (cpt[edi]).c_screen,bp
  419. mov (cpt[edi]).c_xcood,bx
  420. add bx,24
  421. mov (cpt[edi]).c_ycood,112
  422. cmp edx,2
  423. jne next_object
  424. mov (cpt[edi]).c_ycood,136 ;set y-coord to fully down because menu fully down
  425. ; and so player might be scrolling new icons into view
  426. next_object: loop menu_int_loop
  427. mov al,1 ;carry on
  428. ret
  429. fn_start_menu endp
  430. fn_assign_base proc
  431. ; start id processing a base script S2(26Aug92tw)
  432. ; used when player clicks on something, or,
  433. ; when a mega is to have a new base... etc.
  434. ; eax is id
  435. ; ebx is script
  436. fetch_compact
  437. mov (cpt[esi]).c_mode,c_base_mode
  438. mov (cpt[esi]).c_logic,l_script
  439. mov (cpt[esi]).c_base_sub,ebx
  440. mov al,1 ;keep going
  441. ret
  442. fn_assign_base endp
  443. fn_toggle_mouse proc
  444. ; Toggle the mouse highlighting
  445. ; eax is id
  446. fetch_compact
  447. xor (cpt[esi]).c_status,st_mouse
  448. mov al,1
  449. ret
  450. fn_toggle_mouse endp
  451. fn_move_items proc
  452. ; Move a list of id's to another screen
  453. ; eax is list number
  454. ; ebx is screen number
  455. mov edi,[offset move_list+eax*4]
  456. move_loop: flodswl eax,edi
  457. jife eax,move_done
  458. fetch_compact
  459. mov (cpt[esi]).c_screen,bx
  460. jmp move_loop
  461. move_done: mov al,1
  462. ret
  463. fn_move_items endp
  464. fn_send_fast_sync proc
  465. ; send a sync to a mega, continue with current script
  466. ; eax is mega id
  467. ; ebx is sync value
  468. fetch_compact
  469. mov (cpt[esi]).c_sync,bx
  470. mov al,1
  471. ret
  472. fn_send_fast_sync endp
  473. fn_background proc
  474. ; set us to background
  475. and (cpt[esi]).c_status,0fff8h
  476. or (cpt[esi]).c_status,st_background
  477. mov al,1
  478. ret
  479. fn_background endp
  480. fn_we_wait proc
  481. ; We have hit another mega
  482. ; we are going to wait for it to move
  483. ; esi is us
  484. ; eax is it's id
  485. mov (cpt[esi]).c_waiting_for,ax
  486. fn_we_wait endp
  487. ;NOWT IN YERE
  488. stop_and_wait proc
  489. ; 2nd entry point called from logic_ar_animate
  490. add (cpt[esi]).c_mode,4
  491. movzx eax,(cpt[esi]).c_stop_script
  492. movzx ebx,(cpt[esi]).c_mode
  493. mov c_base_sub[esi+ebx],eax
  494. mov (cpt[esi]).c_logic,l_script
  495. jmp logic_script
  496. stop_and_wait endp
  497. fn_no_sprite_engine proc
  498. ; stop the compact printing S2(29Oct92tw)
  499. ; remove foreground, background & sort
  500. and (cpt[esi]).c_status,0fff8h
  501. mov al,1
  502. ret
  503. fn_no_sprite_engine endp
  504. fn_face_id proc
  505. ; return the direction to turn to face another id
  506. ; esi is us
  507. ; eax is id to turn to
  508. ; pass back result in c_just_flag
  509. fetch_compact edi
  510. mov ax,(cpt[esi]).c_xcood
  511. sub ax,(cpt[edi]).c_xcood ;check left
  512. jnc its_to_left
  513. ; we're to the left
  514. neg ax
  515. mov (cpt[esi]).c_get_to_flag,3
  516. jmp vertical_check
  517. its_to_left: mov (cpt[esi]).c_get_to_flag,2
  518. vertical_check: ;now check y
  519. ; ax is x diff
  520. mov bx,(cpt[esi]).c_ycood
  521. ; we must find the true bottom of the sprite
  522. ; it is not enough to use y coord because changing
  523. ; sprite offsets can ruin the formula - instead we
  524. ; will use the bottom of the mouse collision area
  525. mov cx,(cpt[edi]).c_ycood
  526. add cx,(cpt[edi]).c_mouse_rel_y
  527. add cx,(cpt[edi]).c_mouse_size_y
  528. sub bx,cx
  529. jnc its_above
  530. neg bx
  531. cmp bx,ax ;check if hor > ver
  532. jc end_of_fn
  533. mov (cpt[esi]).c_get_to_flag,1 ;we will face down
  534. end_of_fn: mov al,1
  535. ret
  536. its_above: cmp bx,ax
  537. jc end_of_fn
  538. mov (cpt[esi]).c_get_to_flag,0
  539. mov al,1
  540. ret
  541. fn_face_id endp
  542. fn_start_sub proc
  543. ; Run a subroutine
  544. add (cpt[esi]).c_mode,4
  545. movzx ebx,(cpt[esi]).c_mode
  546. mov c_base_sub[esi+ebx],eax
  547. clear eax ;drop out
  548. ret
  549. fn_start_sub endp
  550. fn_send_request proc
  551. ; send an interaction script to id
  552. ; eax is id of target
  553. ; ebx is script
  554. fetch_compact
  555. mov (cpt[esi]).c_request,bx
  556. clear eax ;drop out
  557. ret
  558. fn_send_request endp
  559. fn_check_request proc
  560. ; check for interaction request S2(23Sep92tw)
  561. ; setup if found
  562. ; should be called from base -
  563. ; (anything above base will be destroyed)
  564. mov al,1 ;assume script continue
  565. test (cpt[esi]).c_request,-1
  566. je fcr_ret
  567. mov (cpt[esi]).c_mode,c_action_mode ;into action mode
  568. movzx ebx,(cpt[esi]).c_request ;get script
  569. mov (cpt[esi]).c_action_sub,ebx
  570. clear eax ;drop from script
  571. mov (cpt[esi]).c_request,ax ;and trash request
  572. fcr_ret: ret
  573. fn_check_request endp
  574. fn_stop_mode proc
  575. ; switch compact into stop mode
  576. mov (cpt[esi]).c_logic,l_stopped
  577. clear eax ;stop the script
  578. ret
  579. fn_stop_mode endp
  580. fn_fetch_place proc
  581. ; fetch the c_place of a mega
  582. fetch_compact
  583. movzx eax,(cpt[esi]).c_place
  584. mov [result],eax
  585. mov al,1
  586. ret
  587. fn_fetch_place endp
  588. fn_custom_joey proc
  589. ; return id's x & y coordinate & c_mood (i.e. stood still yes/no)
  590. ; used by Joey-Logic - done in code like this because scripts can't
  591. ; get access to another megas compact as easily
  592. fetch_compact
  593. movzx eax,(cpt[esi]).c_xcood
  594. mov [player_x],eax
  595. movzx eax,(cpt[esi]).c_ycood
  596. mov [player_y],eax
  597. movzx eax,(cpt[esi]).c_mood
  598. mov [player_mood],eax
  599. movzx eax,(cpt[esi]).c_screen
  600. mov [player_screen],eax
  601. mov al,1
  602. ret
  603. fn_custom_joey endp
  604. fn_test_list proc
  605. ; a list of compacts are checked against an x & y coordinate
  606. ; eax is list id
  607. ; ebx = x
  608. ; ecx = y
  609. mov [result],0 ;assume fail
  610. fetch_compact
  611. test_loop: test wpt[esi],-1 ;end of list?
  612. je test_end
  613. cmp bx,[esi] ;left x
  614. jc next
  615. cmp bx,2[esi] ;right x
  616. jnc next
  617. cmp cx,4[esi] ;top y
  618. jc next
  619. cmp cx,6[esi] ;bottom y
  620. jnc next
  621. movzx eax,wpt 8[esi] ;get value
  622. mov [result],eax
  623. next: add esi,10
  624. jmp test_loop
  625. test_end: mov al,1
  626. ret
  627. fn_test_list endp
  628. fn_person_here proc
  629. ; is id eax in room ebx
  630. mov [result],1 ;start with yes
  631. fetch_compact
  632. cmp bx,(cpt[esi]).c_screen
  633. je fph_ret
  634. mov [result],0 ;nope
  635. fph_ret: mov al,1
  636. ret
  637. fn_person_here endp
  638. fn_unhighlight proc
  639. ; eax is item to unhighlight
  640. fetch_compact
  641. dec (cpt[esi]).c_frame
  642. mov (cpt[esi]).c_get_to_flag,0
  643. mov al,1
  644. ret
  645. fn_unhighlight endp
  646. fn_new_list proc
  647. ; Reset the chooser list
  648. mov edi,offset text1
  649. clear eax
  650. mov ecx,16
  651. rep stosd
  652. mov al,1
  653. ret
  654. fn_new_list endp
  655. fn_ask_this proc
  656. ; eax is text number
  657. ; ebx is animation number
  658. ; find first free position
  659. mov esi,offset text1
  660. find_hole: test dpt[esi],-1
  661. je found_hole
  662. add esi,8
  663. jmp find_hole
  664. found_hole: mov [esi],eax
  665. mov 4[esi],ebx
  666. mov al,1
  667. ret
  668. fn_ask_this endp
  669. fn_chooser proc
  670. ; setup the text questions to be clicked on
  671. ; read from text1 until 0 S2(2Oct92tw)
  672. bts [system_flags],sf_choosing ;can't save/restore while choosing
  673. push esi
  674. mov [the_chosen_one],0 ;clear result
  675. mov edi,offset text1
  676. mov ebx,top_left_y ;rolling coordinate
  677. chooser_loop: mov eax,[edi] ;text number
  678. jife eax,set_up_player
  679. lea edi,4[edi]
  680. push edi
  681. push eax
  682. push ebx
  683. mov ebx,game_screen_width
  684. clear ecx ;no logic
  685. mov dl,241 ;255
  686. clear ebp ;no centre
  687. call low_text_manager
  688. ; stipple the text, eax points to data
  689. movzx ebx,(s ptr[eax]).s_height
  690. movzx edx,(s ptr[eax]).s_width
  691. shr edx,1
  692. stipple_loop: mov ecx,edx
  693. stip_loop: test bpt[eax],-1 ;only change 0's
  694. jne no_stip
  695. mov bpt[eax],1
  696. no_stip: lea eax,2[eax]
  697. floop ecx,stip_loop
  698. inc eax
  699. floop ebx,stipple_loop
  700. pop ebx
  701. pop eax
  702. pop edi
  703. ; esi is text compact
  704. mov (cpt[esi]).c_get_to_flag,ax ;text number
  705. mov eax,[edi] ;get animation number
  706. lea edi,4[edi]
  707. mov (cpt[esi]).c_down_flag,ax
  708. or (cpt[esi]).c_status,st_mouse ;mouse detects
  709. mov (cpt[esi]).c_xcood,top_left_x ;set coordinates
  710. mov (cpt[esi]).c_ycood,bx
  711. add ebx,12
  712. jmp chooser_loop
  713. set_up_player: pop esi
  714. cmp edi,offset text1 ;check for nowt to choose
  715. je nowt
  716. mov (cpt[esi]).c_logic,l_choose ;player frozen until choice made
  717. call fn_add_human ;bring back mouse
  718. clear eax ;stop script
  719. ret
  720. nowt: mov al,1
  721. ret
  722. fn_chooser endp
  723. fn_highlight proc
  724. ; Highlight text item in new colour
  725. ; eax is item number
  726. ; ebx is new pen
  727. ; as it turns out the new pens are either 11 or 12
  728. ; 11 for highlight, 12 for unhighlight
  729. sub ebx,11
  730. xor bl,1
  731. add bl,241
  732. fetch_compact ;get item compact number
  733. movzx eax,(cpt[esi]).c_flag ;get id of data item
  734. fetch_item ;get address of text data
  735. call change_text_sprite_colour
  736. mov al,1 ;continue
  737. ret
  738. fn_highlight endp
  739. fn_text_kill proc
  740. ; Kill of text items that are mouse detectable
  741. mov eax,first_text_compact ;first id
  742. mov ecx,10 ;10 items
  743. trash_text_loop: push eax
  744. fetch_compact
  745. pop eax
  746. bt (cpt[esi]).c_status,4 ;st_mouse?
  747. jnc not_die
  748. mov (cpt[esi]).c_status,0 ;remove item
  749. not_die: inc eax
  750. loop trash_text_loop
  751. mov al,1
  752. ret
  753. fn_text_kill endp
  754. fn_text_kill2 proc
  755. ; Kill all text items,
  756. mov eax,first_text_compact ;first id
  757. mov ecx,10 ;10 items
  758. trash_text_loop: push eax
  759. fetch_compact
  760. mov (cpt[esi]).c_status,0 ;remove item
  761. pop eax
  762. inc eax
  763. loop trash_text_loop
  764. mov al,1
  765. ret
  766. fn_text_kill2 endp
  767. fn_fetch_y proc
  768. ; this is really daft, done for the furnace room where the c_status
  769. ; of the lifter depends upon the players y_cood - strange, but true S2(5Feb93tw)
  770. ; eax is id to fetch y coordinate of
  771. fetch_compact
  772. movzx eax,(cpt[esi]).c_ycood
  773. mov [result],eax
  774. mov al,1
  775. ret
  776. fn_fetch_y endp
  777. fn_alt_set_alternate proc
  778. ; this is the alternate set alternate routine
  779. ; change the current script S2(9feb93tw)
  780. ; takes a whole cycle
  781. ; eax is target
  782. ; ebx is script
  783. fetch_compact
  784. mov (cpt[esi]).c_alt,bx
  785. mov (cpt[esi]).c_logic,l_alt
  786. clear eax
  787. ret
  788. fn_alt_set_alternate endp
  789. fn_mouse_on proc
  790. ; switch on the mouse highlighting
  791. ; eax is item to affect
  792. fetch_compact
  793. or (cpt[esi]).c_status,st_mouse
  794. mov al,1
  795. ret
  796. fn_mouse_on endp
  797. fn_mouse_off proc
  798. ; switch on the mouse highlighting
  799. ; eax is item to affect
  800. fetch_compact
  801. and (cpt[esi]).c_status,NOT st_mouse
  802. mov al,1
  803. ret
  804. fn_mouse_off endp
  805. fn_change_name proc
  806. ; eax is id
  807. ; ebx is new text number
  808. fetch_compact
  809. mov (cpt[esi]).c_cursor_text,bx
  810. mov al,1
  811. ret
  812. fn_change_name endp
  813. fn_they_start_sub proc
  814. ; eax is mega
  815. ; ebx is script number
  816. fetch_compact
  817. add (cpt[esi]).c_mode,4
  818. movzx ecx,(cpt[esi]).c_mode
  819. mov c_base_sub[esi+ecx],ebx
  820. mov al,1
  821. ret
  822. fn_they_start_sub endp
  823. fn_set_mega_set proc
  824. ; eax is mega
  825. ; ebx is set no
  826. fetch_compact
  827. imul ebx,next_mega_set
  828. mov (cpt[esi]).c_mega_set,bx
  829. mov al,1
  830. ret
  831. fn_set_mega_set endp
  832. fn_arrived proc
  833. ; mega has arrived at a place
  834. ; called by get-to script
  835. ; esi is mega
  836. ; eax is script variable to increment
  837. mov (cpt[esi]).c_leaving,ax
  838. inc dpt[offset script_variables+eax]
  839. mov al,1
  840. ret
  841. fn_arrived endp
  842. fn_no_sprites_a6 proc
  843. ; stop the compact printing
  844. ; remove foreground, background and sort
  845. ; eax is is
  846. fetch_compact
  847. and (cpt[esi]).c_status,0fff8h
  848. mov al,1
  849. ret
  850. fn_no_sprites_a6 endp
  851. fn_plot_grid proc
  852. ; eax = x
  853. ; ebx = y
  854. ; ecx = width
  855. dec ecx ;make dbf compatible
  856. mov edx,ecx
  857. mov ecx,eax
  858. call fn_get_grid_values
  859. je skip_this
  860. call fn_object_to_walk
  861. skip_this: mov al,1
  862. ret
  863. fn_plot_grid endp
  864. fn_remove_grid proc
  865. ; eax = x
  866. ; ebx = y
  867. ; ecx = width
  868. mov edx,ecx
  869. mov ecx,eax
  870. call fn_get_grid_values
  871. je skip_this
  872. call fn_remove_object_from_walk
  873. skip_this: mov al,1
  874. ret
  875. fn_remove_grid endp
  876. fn_new_background proc
  877. ; set id eax to background
  878. fetch_compact
  879. and (cpt[esi]).c_status,0fff8h
  880. or (cpt[esi]).c_status,st_background
  881. mov al,1
  882. ret
  883. fn_new_background endp
  884. fn_clear_request proc
  885. ; target has not responded to sync
  886. ; eax is id of target
  887. fetch_compact
  888. mov (cpt[esi]).c_request,0
  889. mov al,1
  890. ret
  891. fn_clear_request endp
  892. fn_eyeball proc
  893. ; set 'result' to frame no. pointing to foster, according to table used
  894. ; eg. FN_eyeball (id_eye_90_table);
  895. fetch_compact edi ;eye table
  896. mov eax,id_blue_foster
  897. fetch_compact
  898. movzx eax,(cpt[esi]).c_xcood ;168 < x < 416
  899. sub eax,168
  900. shr eax,3
  901. movzx ebx,(cpt[esi]).c_ycood ;256 < y < 296
  902. sub ebx,256
  903. shl ebx,2
  904. and ebx,0ffe0h
  905. add eax,ebx
  906. shl eax,1
  907. movzx eax,wpt[eax+edi] ;get frame no
  908. add eax,s91
  909. mov [result],eax
  910. mov al,1
  911. ret
  912. fn_eyeball endp
  913. fn_leave_section proc
  914. ifdef s1_demo
  915. program_error em_game_over
  916. endif
  917. cmp eax,5 ;linc section has different mouse cursors
  918. jne not_linc
  919. mov eax,60301
  920. call replace_mouse_cursors
  921. not_linc: mov al,1
  922. ret
  923. fn_leave_section endp
  924. fn_enter_section proc
  925. ifdef s1_demo
  926. cmp eax,2
  927. jc sec_ok
  928. program_error em_game_over
  929. sec_ok:
  930. endif
  931. mov [cur_section],eax
  932. cmp eax,5 ;section 5 has different mouse icons
  933. jne not_linc
  934. push eax
  935. mov eax,60302
  936. call replace_mouse_cursors
  937. pop eax
  938. not_linc: cmp eax,[current_section]
  939. je same_section
  940. mov [current_section],eax
  941. mov [save_current_section],eax
  942. inc eax
  943. call load_section_music
  944. call load_grids
  945. same_section: mov al,1
  946. ret
  947. fn_enter_section endp
  948. fn_save_coods proc
  949. mov eax,[tmousex]
  950. mov [safex],eax
  951. mov eax,[tmousey]
  952. mov [safey],eax
  953. mov al,1
  954. ret
  955. fn_save_coods endp
  956. fn_skip_intro_code proc
  957. ; This is the point at which the game re-starts
  958. ; To get the restart data the game must be saved now, on the final version, however
  959. ; the code must be compatible with the version that saved the game but not do any
  960. ; actual saving
  961. ; The save code must therefore be kept in the final version but disabled
  962. ; This is done by replacing a nop instruction with a ret for the final version
  963. mov al,1 ;disable escape past intro on all versions
  964. mov bpt [past_intro],al
  965. ifdef save_restart_file
  966. nop ;This nop...
  967. else
  968. ret ;...will become this ret
  969. endif
  970. mov edx,[restart_name_p]
  971. call c2_save_game_to_disk ;On final version this call is never reached
  972. mov al,1
  973. ret
  974. fn_skip_intro_code endp
  975. fn_new_swing_seq proc
  976. ; Only certain files work on pc
  977. cmp eax,85
  978. je do_seq
  979. cmp eax,106
  980. je do_seq
  981. cmp eax,75
  982. je do_seq
  983. cmp eax,15
  984. je do_seq
  985. jmp no_seq
  986. do_seq: fetch_item
  987. dec bpt[esi]
  988. call start_timer_sequence
  989. no_seq: mov al,1
  990. ret
  991. fn_new_swing_seq endp
  992. fn_wait_swing_end proc
  993. ifndef no_timer
  994. test [tseq_frames],-1
  995. jne fn_wait_swing_end
  996. else
  997. mov [tseq_frames],0
  998. endif
  999. mov al,1
  1000. ret
  1001. fn_wait_swing_end endp
  1002. anim_sequence proc
  1003. ; esi points to the data
  1004. push es
  1005. mov es,[screen_segment]
  1006. clear eax
  1007. lodsb ;no frames
  1008. mov ecx,eax
  1009. ;dec ecx
  1010. frame_loop: push ecx
  1011. clear edi
  1012. clear ecx
  1013. do_frame: lodsb ;no to skip
  1014. add edi,eax
  1015. cmp al,-1
  1016. je do_frame
  1017. diffy: lodsb ;no to do
  1018. mov cl,al
  1019. rep movsb
  1020. cmp al,-1
  1021. je diffy
  1022. cmp edi,game_screen_height*game_screen_width
  1023. jc do_frame
  1024. call stabilise
  1025. clear eax
  1026. pop ecx
  1027. floop ecx,frame_loop
  1028. pop es
  1029. no_seq:: mov al,1
  1030. ret
  1031. anim_sequence endp
  1032. fn_printf proc
  1033. ifdef debug_42
  1034. printf "fn_printf %d",eax
  1035. call debug_printf
  1036. endif
  1037. mov al,1
  1038. ret
  1039. fn_printf endp
  1040. ifdef debug_42
  1041. debug_printf proc
  1042. pusha
  1043. mov ebx,70
  1044. call status_int
  1045. call debug_loop
  1046. popa
  1047. ret
  1048. debug_printf endp
  1049. endif
  1050. fn_blank_screen proc
  1051. call clear_screen
  1052. mov al,1
  1053. ret
  1054. fn_blank_screen endp
  1055. fn_fetch_x proc
  1056. ; fetch x of compact eax
  1057. fetch_compact
  1058. movzx eax,(cpt[esi]).c_xcood
  1059. mov [result],eax
  1060. mov al,1
  1061. ret
  1062. fn_fetch_x endp
  1063. fn_quit_to_dos proc
  1064. program_error em_game_over
  1065. fn_quit_to_dos endp
  1066. end32code
  1067. end
  1068.