Scr_int.asm 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. include_macros equ 1
  2. include_deb_mac equ 1
  3. include_scripts equ 1
  4. include_files equ 1
  5. include_flags equ 1
  6. include include.asm
  7. include script.asm
  8. start32data
  9. script_no dw ? ;store for the script number
  10. align 4
  11. script_compact dd ? ;store for the current compact
  12. module_start dd ? ;address of the start of this module
  13. int_stack dd 20 dup (?) ;the interpreter stack
  14. jump_table dd push_variable ;0
  15. dd less_than ;1
  16. dd push_number ;2
  17. dd not_equal ;3
  18. dd if_and ;4
  19. dd skip_zero ;5
  20. dd pop_var ;6
  21. dd minus ;7
  22. dd plus ;8
  23. dd skip_always ;9
  24. dd if_or ;10
  25. dd call_mcode ;11
  26. dd more_than ;12
  27. dd script_exit ;13
  28. dd switch ;14
  29. dd push_offset ;15
  30. dd pop_offset ;16
  31. dd is_equal ;17
  32. dd skip_nz ;18
  33. dd script_exit ;19 Not really needed
  34. dd restart_script
  35. module_list dd 16 dup (0)
  36. forward1b_lab equ jobsworth_speech
  37. no_forwards1b equ 63
  38. forward_list1b dd jobs_speech
  39. dd jobs_s4
  40. dd jobs_alarmed
  41. dd joey_recycle
  42. dd shout_sss
  43. dd joey_mission
  44. dd trans_mission
  45. dd slot_mission
  46. dd corner_mission
  47. dd joey_logic
  48. dd gordon_speech
  49. dd joey_button_mission
  50. dd lob_dad_speech
  51. dd lob_son_speech
  52. dd guard_speech
  53. dd mantrach_speech
  54. dd wreck_speech
  55. dd anita_speech
  56. dd lamb_factory
  57. dd fore_speech
  58. dd joey_42_miss
  59. dd joey_junction_miss
  60. dd welder_mission
  61. dd joey_weld_mission
  62. dd radman_speech
  63. dd link_7_29
  64. dd link_29_7
  65. dd lamb_to_3
  66. dd lamb_to_2
  67. dd burke_speech
  68. dd burke_1
  69. dd burke_2
  70. dd dr_burke_1
  71. dd jason_speech
  72. dd joey_bellevue
  73. dd anchor_speech
  74. dd anchor_mission
  75. dd joey_pc_mission
  76. dd hook_mission
  77. dd trevor_speech
  78. dd joey_factory
  79. dd helga_speech
  80. dd joey_helga_mission
  81. dd gall_bellevue
  82. dd glass_mission
  83. dd lamb_fact_return
  84. dd lamb_leave_garden
  85. dd lamb_start_29
  86. dd lamb_bellevue
  87. dd cable_mission
  88. dd foster_tour
  89. dd lamb_tour
  90. dd foreman_logic
  91. dd lamb_leave_factory
  92. dd lamb_bell_logic
  93. dd lamb_fact_2
  94. dd start90
  95. dd 0
  96. dd 0
  97. dd link_28_31
  98. dd link_31_28
  99. dd exit_linc
  100. dd death_script
  101. forward2b_lab equ ref_std_on
  102. no_forwards2b equ 7
  103. forward_list2b dd std_on
  104. dd std_exit_left_on
  105. dd std_exit_right_on
  106. dd advisor_188
  107. dd shout_action
  108. dd mega_click
  109. dd mega_action
  110. forward3b_lab equ ref_danielle_speech
  111. no_forwards3b equ 21
  112. forward_list3b dd dani_speech
  113. dd danielle_go_home
  114. dd spunky_go_home
  115. dd henri_speech
  116. dd buzzer_speech
  117. dd foster_visit_dani
  118. dd danielle_logic
  119. dd jukebox_speech
  120. dd vincent_speech
  121. dd eddie_speech
  122. dd blunt_speech
  123. dd dani_answer_phone
  124. dd spunky_see_video
  125. dd spunky_bark_at_foster
  126. dd spunky_smells_food
  127. dd barry_speech
  128. dd colston_speech
  129. dd gall_speech
  130. dd babs_speech
  131. dd chutney_speech
  132. dd foster_enter_court
  133. forward4b_lab equ ref_walter_speech
  134. no_forwards4b equ 14
  135. forward_list4b dd walter_speech
  136. dd joey_medic
  137. dd joey_med_logic
  138. dd joey_med_mission72
  139. dd ken_logic
  140. dd ken_speech
  141. dd ken_mission_hand
  142. dd sc70_iris_opened
  143. dd sc70_iris_closed
  144. dd foster_enter_boardroom
  145. dd bored_room
  146. dd foster_enter_new_boardroom
  147. dd hobs_end
  148. dd sc82_jobs_sss
  149. forward5b_lab equ start_info_window
  150. no_forwards5b equ 7
  151. forward_list5b dd set_up_info_window
  152. dd slab_on
  153. dd up_mouse
  154. dd down_mouse
  155. dd left_mouse
  156. dd right_mouse
  157. dd disconnect_foster
  158. end32data
  159. start32code
  160. extrn load_file:near
  161. init_script proc
  162. mov esi,offset forward_list1b
  163. mov edi,offset forward1b_lab
  164. mov ecx,no_forwards1b
  165. rep movsd
  166. mov esi,offset forward_list2b
  167. mov edi,offset forward2b_lab
  168. mov ecx,no_forwards2b
  169. rep movsd
  170. mov esi,offset forward_list3b
  171. mov edi,offset forward3b_lab
  172. mov ecx,no_forwards3b
  173. rep movsd
  174. mov esi,offset forward_list4b
  175. mov edi,offset forward4b_lab
  176. mov ecx,no_forwards4b
  177. rep movsd
  178. mov esi,offset forward_list5b
  179. mov edi,offset forward5b_lab
  180. mov ecx,no_forwards5b
  181. rep movsd
  182. ret
  183. init_script endp
  184. check_module_loaded proc
  185. ; Make sure module eax is loaded
  186. mov ebx,[offset module_list + eax*4] ;already in?
  187. jifne ebx,mod_in
  188. push eax ;load it
  189. add eax,f_module_0
  190. clear edx
  191. call load_file
  192. pop ebx
  193. mov [offset module_list + ebx*4],eax
  194. mod_in: ret
  195. check_module_loaded endp
  196. script proc
  197. ; process a script
  198. ; low level interface to interpreter
  199. ; eax defines the script.
  200. ; Bit 0-11 - Script number
  201. ; Bit 12-15 - Module number
  202. ; Bit 16-31 - Script offset (if any)
  203. ; esi holds mega compact if relevant
  204. ifdef debug_42
  205. bt [_debug_flag],df_script
  206. jnc no_debug
  207. printf "Doing Script %x",eax
  208. debug_compact esi,"Into Script"
  209. no_debug:
  210. endif
  211. mov [script_no],ax
  212. mov [script_compact],esi
  213. movzx ebx,ah
  214. and ah,0fh
  215. shr ebx,2
  216. mov esi,module_list[ebx] ;get module address
  217. jifne esi,module_present
  218. ; The module has not been loaded: What do we do?
  219. push eax
  220. push ebx
  221. shr ebx,2 ;get module number
  222. add ebx,f_module_0 ;and get module file
  223. mov eax,ebx
  224. clear edx ;allocate memory for this module
  225. call load_file
  226. mov esi,eax ;module address
  227. pop ebx
  228. mov module_list[ebx],esi ;module has been loaded
  229. pop eax
  230. module_present: mov [module_start],esi
  231. cherror ax,a,[esi],em_internal_error
  232. ; Check whether we have an offset or what
  233. test eax,0ffff0000h
  234. jne got_offset
  235. shl eax,1 ;turn number into pointer
  236. mov ax,[eax+esi] ;get new offset
  237. shl ax,1
  238. add esi,eax ;and go
  239. jmp interpreter
  240. got_offset: shr eax,15 ;get offset
  241. add eax,[module_start] ;point into module data
  242. mov esi,eax
  243. interpreter: ;Go do that script
  244. ; esi is pointer to script data
  245. mov edi,offset int_stack
  246. ; And now interpret.....
  247. inter_loop: movzx eax,wpt[esi] ;get a command
  248. inc esi
  249. inc esi
  250. jmp jump_table[eax*4]
  251. ; Skip if non zero
  252. skip_nz:: flodswl eax,esi
  253. sub edi,4
  254. test dpt [edi],-1
  255. je inter_loop
  256. cwde
  257. add esi,eax
  258. jmp inter_loop
  259. ; Skip if zero
  260. skip_zero:: flodswl eax,esi
  261. sub di,4
  262. test dpt [edi],-1
  263. jne inter_loop
  264. add esi,eax
  265. jmp inter_loop
  266. ; Push a variable on to the stack
  267. push_variable:: flodswl eax,esi ;get variable number
  268. mov eax,[offset script_variables+eax] ;get variable contents
  269. stosd ;and put them on the stack
  270. jmp inter_loop
  271. ; if (di-2) < (di-4) leave 1 on the stack, else leave 0
  272. less_than:: mov eax,[edi-8]
  273. cmp eax,[edi-4]
  274. jc leave_1
  275. leave_0:: sub edi,4
  276. mov dpt [edi-4],0
  277. jmp inter_loop
  278. leave_1:: sub edi,4
  279. mov dpt [edi-4],1
  280. jmp inter_loop
  281. ; if (di-2) != (di-4) leave 1 on the stack, else leave 0
  282. not_equal:: mov eax,[edi-4]
  283. cmp eax,[edi-8]
  284. jne leave_1
  285. jmp leave_0
  286. ; Non logical and (=1 if both non zero)
  287. if_and:: test dpt [edi-4],-1
  288. je leave_0
  289. test dpt [edi-8],-1
  290. je leave_0
  291. jmp leave_1
  292. ; if (di-8) > (di-4) leave 1 on the stack, else leave 0
  293. more_than:: mov eax,[edi-4]
  294. cmp eax,[edi-8]
  295. ; If (-8) > (-4) then carry should be set. Changed from "jna leave_0"
  296. jc leave_1
  297. jmp leave_0
  298. ; If (a2) == (a2+2) leave 1 on the stack, else leave 0
  299. is_equal:: mov eax,[edi-4]
  300. cmp eax,[edi-8]
  301. je leave_1
  302. jmp leave_0
  303. ; Non logical or (=1 if either non zero)
  304. if_or:: test dpt [edi-4],-1
  305. jne leave_1
  306. test dpt [edi-8],-1
  307. jne leave_1
  308. jmp leave_0
  309. ; Push a number on to the stack
  310. push_number:: flodswl eax,esi
  311. stosd
  312. jmp inter_loop
  313. ; Pop a value into a variable
  314. pop_var:: flodswl eax,esi
  315. sub edi,4
  316. mov ebx,[edi]
  317. mov [offset script_variables+eax],ebx
  318. jmp inter_loop
  319. ; Subtract two numbers
  320. minus:: sub edi,4
  321. mov eax,[edi]
  322. sub [edi-4],eax
  323. jmp inter_loop
  324. ; Add two numbers
  325. plus:: sub edi,4
  326. mov eax,[edi]
  327. add [edi-4],eax
  328. jmp inter_loop
  329. skip_always:: flodswl eax,esi
  330. add esi,eax
  331. jmp inter_loop
  332. ; Call an mcode routine
  333. call_mcode:: flodswl eax,esi ;get number of parameters
  334. cmp ax,1
  335. jc param_0
  336. je param_1
  337. cmp ax,3
  338. jc param_2
  339. param_3: sub edi,4
  340. mov ecx,[edi]
  341. param_2: sub edi,4
  342. mov ebx,[edi]
  343. param_1: sub edi,4
  344. mov eax,[edi]
  345. param_0: movzx edx,wpt[esi] ;get mcode number
  346. add esi,2
  347. ; Save what we need from possible recalls of the interpreter
  348. push edi ;save the stack pointer
  349. push esi
  350. mov di,[script_no] ;use edi so script no sneaks thru to fn_routine (debug only)
  351. push edi
  352. mov esi,[module_start]
  353. push esi
  354. mov esi,[script_compact]
  355. push esi
  356. call mcode_table[edx]
  357. pop esi
  358. mov [script_compact],esi
  359. pop esi
  360. mov [module_start],esi
  361. pop esi
  362. mov [script_no],si
  363. pop esi
  364. pop edi
  365. ; The mcode returns 0 for halt script at this point, non zero for continue
  366. and eax,0ffffh ;strip top bits anyway
  367. jne inter_loop
  368. ; We want to leave the interpreter with the current script location
  369. ; esi is instriction counter
  370. script_halt: mov eax,esi
  371. sub eax,[module_start] ;get offset into script
  372. shl eax,15 ;and whisk it away
  373. mov ax,[script_no] ;get script number back
  374. mov esi,[script_compact]
  375. ret ;and return
  376. ; This script has finished
  377. script_exit:: movzx eax,[script_no]
  378. mov esi,[script_compact]
  379. ret ;Shirley there must be more to it than this
  380. restart_script:: ;restart the current script
  381. movzx eax,[script_no]
  382. mov esi,[script_compact]
  383. jmp script
  384. switch:: movzx ecx,wpt[esi] ;get number of cases
  385. add esi,2
  386. sub edi,4 ;and value to switch on
  387. mov eax,[edi]
  388. sw_loop: cmp ax,[esi]
  389. je got_value
  390. add esi,4
  391. floop sw_loop
  392. flodswl eax,esi
  393. add esi,eax ;use the default
  394. sub esi,2
  395. jmp inter_loop
  396. got_value: mov ax,[esi+2] ;move on to case
  397. add esi,eax
  398. add esi,2
  399. jmp inter_loop
  400. ; Push a compact access
  401. push_offset:: flodswl eax,esi ;get offset
  402. add eax,[script_compact]
  403. movzx eax,wpt[eax] ;assume all words
  404. stosd
  405. jmp inter_loop
  406. ; pop a value into a compact
  407. pop_offset:: flodswl eax,esi ;get offset
  408. add eax,[script_compact]
  409. sub edi,4
  410. mov bx,[edi] ;get value
  411. mov [eax],bx
  412. jmp inter_loop
  413. script endp
  414. end32code
  415. end
  416.