Replay.asm 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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. ifdef with_replay
  7. ; These routines control the recording and replaying of replay files
  8. rp_mem_block equ 2000 ;size of allocation chumks
  9. mouse_event_size equ 16 ;size of mouse event data
  10. rfn_recording equ 0 ;set when recording
  11. rfn_replaying equ 1 ;set when replaying
  12. rfn_replay_skip_scr equ 2 ;skip until next screen change
  13. rfn_replay_skip_cmd equ 3 ;skip till next event
  14. rfn_replay_skip_all equ 4 ;skip forever
  15. rfn_replay_skip_ms equ 5 ;skip until mouse returns (fn_add_human)
  16. xrfn_skip_mask equ 3ch
  17. else
  18. rfn_replay_skip_ms equ 0 ;skip until mouse returns (fn_add_human)
  19. xrfn_skip_mask equ 1h
  20. endif
  21. start32data
  22. replay_flagn dd 0
  23. ifdef with_replay
  24. replay_f_name db "sky.rpl",0
  25. align 4
  26. replay_handle dd 0 ;handle for replay file
  27. replay_data dd 0 ;pointer to replay data
  28. replay_data_len dd ? ;amount of data allocated for replay
  29. replay_data_ptr dd ? ;pointer into data
  30. db_next_cycle dd ? ;copy of next game cycle for replaying
  31. endif
  32. end32data
  33. start32code
  34. check_replay_skip proc
  35. ifndef with_replay
  36. test [replay_flagn],xrfn_skip_mask
  37. je not_skipping
  38. push esi
  39. mov esi,offset foster
  40. test (cpt[esi]).c_logic,-1
  41. je stop_skippp
  42. cmp [screen],101
  43. je stop_skippp
  44. test [look_through],-1
  45. jne stop_skippp
  46. cmp (cpt[esi]).c_logic,12
  47. jne not_still
  48. stop_skippp: btr [replay_flagn],rfn_replay_skip_ms
  49. not_still: pop esi
  50. endif
  51. ; return carry set if we are supposed to be skipping
  52. test [replay_flagn],xrfn_skip_mask
  53. jne skipping
  54. not_skipping: clc
  55. ret
  56. skipping: stc
  57. ret
  58. check_replay_skip endp
  59. check_replay_key proc
  60. ; space moves on to next event, tab to next room change and '=' until end of replay file
  61. ; '`' stops fast replay
  62. ifdef with_replay
  63. cmp al,9
  64. jne not_tab
  65. bts [replay_flagn],rfn_replay_skip_scr ;skip until next screen change
  66. jmp done
  67. not_tab: cmp ax,' '
  68. jne not_space
  69. bts [replay_flagn],rfn_replay_skip_cmd ;skip until next replayed mouse command
  70. jmp done
  71. not_space: cmp ax,'='
  72. jne not_equaals
  73. bts [replay_flagn],rfn_replay_skip_all ;skip until further notice
  74. jmp done
  75. not_equaals:
  76. else
  77. bt [system_flags],sf_allow_quick
  78. jnc not_valid
  79. endif
  80. cmp ax,96
  81. jne not_untab
  82. and [replay_flagn],NOT xrfn_skip_mask ;cancel all skips
  83. jmp done
  84. not_untab: cmp ax,'q'
  85. jne not_valid
  86. bts [replay_flagn],rfn_replay_skip_ms ;skip until foster is not doing anything or choosing text
  87. done: clc
  88. ret
  89. not_valid: stc
  90. ret
  91. check_replay_key endp
  92. ifdef with_replay
  93. extrn replay_mouse:near
  94. switch_replay_to_record proc
  95. ; If we are replaying a replay file then switch over to recording
  96. bt [replay_flagn],rfn_replaying
  97. jnc no_replaying
  98. ; Take the data replayed and rewrite it for record
  99. push offset replay_f_name
  100. call _open_for_write__Npc
  101. ; mov ah,3ch ;create a new file
  102. ; clear ecx
  103. ; mov edx,offset replay_f_name
  104. ; int 21h
  105. ; jnc op_ok
  106. ; mov eax,-1
  107. ;op_ok:
  108. mov [replay_handle],eax
  109. ; Write out data
  110. mov edx,[replay_data]
  111. mov ecx,[replay_data_ptr]
  112. mov ebx,eax
  113. mov ah,40h
  114. int 21h
  115. btr [replay_flagn],rfn_replaying
  116. bts [replay_flagn],rfn_recording
  117. call increase_replay_space
  118. no_replaying: ret
  119. switch_replay_to_record endp
  120. start_up_replay_file proc
  121. ; Control the replay start up status
  122. test [_do_a_replay],-1 ;replay or record
  123. jne do_replay
  124. ; Open a new replay file for recording
  125. ; If a file is already open we must have loaded a saved game, even if this is just the restart file
  126. test [replay_handle],-1
  127. jne alrdy_open
  128. push offset replay_f_name
  129. call _open_for_write__Npc
  130. ; mov ah,3ch
  131. ; clear ecx
  132. ; mov edx,offset replay_f_name
  133. ; int 21h
  134. ; jnc op_ok
  135. ; mov eax,-1
  136. ;op_ok:
  137. mov [replay_handle],eax
  138. ; Allocate data for recording
  139. mov eax,rp_mem_block
  140. call my_malloc
  141. mov [replay_data],eax
  142. mov [replay_data_len],rp_mem_block
  143. mov [replay_data_ptr],0
  144. alrdy_open: bts [replay_flagn],rfn_recording
  145. ret
  146. do_replay: ;first check if we want to start from a save game
  147. ; push [replay_flagn]
  148. ; call control_panel
  149. ; pop [replay_flagn]
  150. ; open up the replay file, read the data and put it after any loaded from a save game
  151. push offset replay_f_name
  152. call _open_for_read__Npc
  153. ; mov ax,3d00h
  154. ; mov edx,offset replay_f_name
  155. ; int 21h
  156. ; jnc fopen
  157. ; cherror al,e,al,em_internal_error
  158. ;fopen:
  159. cherror eax,nc,200,em_internal_error
  160. mov [replay_handle],eax
  161. ; Find the size of this file
  162. clear edx
  163. clear ecx
  164. mov ebx,eax
  165. mov ax,4202h
  166. int 21h
  167. ; Make room for this file
  168. add eax,[replay_data_len]
  169. push eax
  170. call my_malloc
  171. mov esi,[replay_data]
  172. mov edi,eax
  173. mov [replay_data],eax
  174. mov ecx,[replay_data_len]
  175. rep movsb
  176. pop eax
  177. xchg [replay_data_len],eax
  178. push eax
  179. ; so load the data
  180. clear edx ;file pointer back to 0
  181. clear ecx
  182. mov ebx,[replay_handle]
  183. mov ax,4200h
  184. int 21h
  185. mov edx,[replay_data]
  186. pop eax
  187. add edx,eax
  188. mov ecx,-1
  189. mov ah,3fh
  190. int 21h
  191. mov [replay_data_ptr],0 ;start from the beginning
  192. bts [replay_flagn],rfn_replaying
  193. ret
  194. start_up_replay_file endp
  195. replay_changed_screen proc
  196. ; We have changed screen so stop `skip till change screen'
  197. btr [replay_flagn],rfn_replay_skip_scr
  198. ret
  199. replay_changed_screen endp
  200. replay_say_something proc
  201. ; We have changed screen so stop `skip till change screen'
  202. bt [replay_flagn],rfn_replay_skip_ms
  203. ret
  204. replay_say_something endp
  205. replay_record_event proc
  206. ; A mouse event has occured, record it
  207. ; eax = mouse x
  208. ; ebx = mouse y
  209. ; ecx = mouse b
  210. bt [replay_flagn],rfn_replaying ;no record if in replay
  211. jc still_room
  212. mov edx,[replay_data]
  213. add edx,[replay_data_ptr] ;point to where data is going
  214. mov 4[edx],eax
  215. mov 8[edx],ebx
  216. mov 12[edx],ecx
  217. mov eax,[game_cycle]
  218. mov [edx],eax
  219. add [replay_data_ptr],mouse_event_size
  220. ; write data to file
  221. mov ecx,mouse_event_size
  222. mov ebx,[replay_handle]
  223. mov ah,40h
  224. int 21h
  225. ; Now check there is room for more events
  226. mov eax,[replay_data_ptr]
  227. add eax,mouse_event_size
  228. cmp eax,[replay_data_len]
  229. jc still_room
  230. call increase_replay_space
  231. still_room: ret
  232. replay_record_event endp
  233. check_replay_mouse proc
  234. ; We maybe skipping up until foster is waiting or choosing
  235. mov esi,offset foster
  236. test (cpt[esi]).c_logic,-1
  237. je stop_skippp
  238. cmp [screen],101
  239. je stop_skippp
  240. test [look_through],-1
  241. jne stop_skippp
  242. cmp (cpt[esi]).c_logic,12
  243. jne not_still
  244. stop_skippp: btr [replay_flagn],rfn_replay_skip_ms
  245. not_still:
  246. ; check if a new mouse state is waiting
  247. bt [replay_flagn],rfn_replaying ;no replay if in record
  248. jnc no_replay
  249. mov edx,[replay_data] ;point to next data
  250. add edx,[replay_data_ptr]
  251. mov eax,[edx]
  252. mov [db_next_cycle],eax
  253. mov eax,[game_cycle] ;do we need a new fing
  254. cmp eax,[edx]
  255. jc no_replay
  256. mov eax,4[edx] ;get mouse x
  257. cmp eax,-1 ;-1 for do control panel
  258. je do_control
  259. cmp eax,-2 ;-2 for get joey coordinates
  260. je do_joey
  261. cmp eax,-3 ;-3 for check random
  262. je do_randomm
  263. cmp eax,-4
  264. je do_stop_voc
  265. jmp normal_event
  266. do_control: ;Call up control panel
  267. mov ax,96
  268. call check_replay_key
  269. call control_panel
  270. jmp next_event
  271. do_joey: ;set mega coordinates
  272. mov eax,8[edx] ;screen
  273. shr eax,16
  274. fetch_compact
  275. mov eax,8[edx] ;screen
  276. mov (cpt[esi]).c_screen,ax
  277. mov eax,12[edx] ;x and y
  278. mov (cpt[esi]).c_ycood,ax
  279. shr eax,16
  280. mov (cpt[esi]).c_xcood,ax
  281. jmp spec_done
  282. do_randomm: mov eax,8[edx] ;random value
  283. ;cherror eax,ne,[random],em_internal_error
  284. jmp spec_done
  285. do_stop_voc: ;voc stopped here
  286. call fn_stop_voc
  287. add [replay_data_ptr],mouse_event_size
  288. spec_done: ;check we haven't overrun
  289. add [replay_data_ptr],mouse_event_size
  290. mov edx,[replay_data_ptr] ;check there are more
  291. cmp edx,[replay_data_len]
  292. jnc replay_fini
  293. jmp check_replay_mouse
  294. normal_event: mov [tmousex],eax
  295. sub eax,top_left_x
  296. cherror eax,nc,320,em_internal_error
  297. mov [amouse_x],eax
  298. mov ebx,8[edx]
  299. mov [tmousey],ebx
  300. sub ebx,top_left_y
  301. cherror ebx,nc,192,em_internal_error
  302. mov [amouse_y],ebx
  303. mov ecx,12[edx]
  304. mov [emouse_b],ecx
  305. call replay_mouse
  306. next_event: btr [replay_flagn],rfn_replay_skip_cmd
  307. add [replay_data_ptr],mouse_event_size
  308. mov edx,[replay_data_ptr] ;check there are more
  309. cmp edx,[replay_data_len]
  310. jc still_replay
  311. ; Replay file has ended
  312. replay_fini: call switch_replay_to_record
  313. and [replay_flagn],NOT xrfn_skip_mask ;cancel all skips
  314. call control_panel
  315. still_replay: ;mov eax,[next_mouse_cycle]
  316. ;mov ebx,7
  317. ifdef debug_42
  318. ;call status_int
  319. endif
  320. no_replay: ret
  321. check_replay_mouse endp
  322. increase_replay_space proc
  323. ; Do a manual realloc
  324. add [replay_data_len],rp_mem_block
  325. mov eax,[replay_data_len]
  326. call my_malloc
  327. mov esi,[replay_data]
  328. mov edi,eax
  329. xchg [replay_data],eax
  330. mov ecx,[replay_data_ptr]
  331. rep movsb
  332. call my_free
  333. ret
  334. increase_replay_space endp
  335. rewrite_replay_file proc
  336. ; A saved game has been loaded and with it the replay data. Rewrite a new sky.rpl
  337. mov ebx,[replay_handle] ;open the file if it isn't already
  338. jifne ebx,fopen
  339. push offset replay_f_name
  340. call _open_for_write__Npc
  341. ; mov ah,3ch
  342. ; clear ecx
  343. ; mov edx,offset replay_f_name
  344. ; int 21h
  345. mov [replay_handle],eax
  346. mov ebx,eax
  347. fopen: mov ax,4200h ;return file pointer to start
  348. clear ecx
  349. clear edx
  350. int 21h
  351. mov edx,[replay_data]
  352. mov ecx,[replay_data_len]
  353. mov ah,40h
  354. int 21h
  355. ret
  356. rewrite_replay_file endp
  357. endif
  358. end32code
  359. end
  360.