Grid.asm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. include_macros equ 1
  2. include_struc equ 1
  3. include_deb_mac equ 1
  4. include_error_codes equ 1
  5. include include.asm
  6. grid_file_start equ 60000 ;number of first grid file
  7. start32data
  8. game_grids dd ? ;pointer to game grid data
  9. grid_convert_table db 0 ;0
  10. db 1 ;1
  11. db 2 ;2
  12. db 3 ;3
  13. db 4 ;4
  14. db 5 ;5
  15. db 6 ;6
  16. db 7 ;7
  17. db 8 ;8
  18. db 9 ;9
  19. db 10 ;10
  20. db 11 ;11
  21. db 12 ;12
  22. db 13 ;13
  23. db 14 ;14
  24. db 15 ;15
  25. db 16 ;16
  26. db 17 ;17
  27. db 18 ;18
  28. db 19 ;19
  29. db 20 ;20
  30. db 21 ;21
  31. db 22 ;22
  32. db 23 ;23
  33. db 24 ;24
  34. db 25 ;25
  35. db 26 ;26
  36. db 27 ;27
  37. db 28 ;28
  38. db 29 ;29
  39. db 30 ;30
  40. db 31 ;31
  41. db 32 ;32
  42. db 33 ;33
  43. db 34 ;34
  44. db -1 ;35
  45. db 35 ;36
  46. db 36 ;37
  47. db 37 ;38
  48. db 38 ;39
  49. db 39 ;40
  50. db 40 ;41
  51. db 41 ;42
  52. db -1 ;43
  53. db 42 ;44
  54. db 43 ;45
  55. db 44 ;46
  56. db 45 ;47
  57. db 46 ;48
  58. db -1 ;49
  59. db -1 ;50
  60. db -1 ;51
  61. db -1 ;52
  62. db -1 ;53
  63. db -1 ;54
  64. db -1 ;55
  65. db -1 ;56
  66. db -1 ;57
  67. db -1 ;58
  68. db -1 ;59
  69. db -1 ;60
  70. db -1 ;61
  71. db -1 ;62
  72. db -1 ;63
  73. db -1 ;64
  74. db 47 ;65
  75. db tot_no_grids ;66
  76. db 48 ;67
  77. db 49 ;68
  78. db 50 ;69
  79. db 51 ;70
  80. db 52 ;71
  81. db 53 ;72
  82. db 54 ;73
  83. db 55 ;74
  84. db 56 ;75
  85. db 57 ;76
  86. db 58 ;77
  87. db 59 ;78
  88. db 60 ;79
  89. db -1 ;80
  90. db 61 ;81
  91. db 62 ;82
  92. db -1 ;83
  93. db -1 ;84
  94. db -1 ;85
  95. db -1 ;86
  96. db -1 ;87
  97. db -1 ;88
  98. db tot_no_grids ;89
  99. db 63 ;90
  100. db 64 ;91
  101. db 65 ;92
  102. db 66 ;93
  103. db 67 ;94
  104. db 68 ;95
  105. db 69 ;96
  106. end32data
  107. start32code
  108. extrn my_malloc:near
  109. extrn load_file:near
  110. initialise_grids proc
  111. mov eax,tot_no_grids*grid_size
  112. call my_malloc
  113. mov [game_grids],eax
  114. ret
  115. initialise_grids endp
  116. load_grids proc
  117. mov eax,grid_file_start
  118. mov ecx,tot_no_grids
  119. mov edx,[game_grids]
  120. grid_loop: push eax
  121. push ecx
  122. push edx
  123. call load_file
  124. pop edx
  125. add edx,grid_size
  126. pop ecx
  127. pop eax
  128. inc eax
  129. floop grid_loop
  130. ifndef s1_demo ;single disk demos never get that far
  131. ; Reloading the grids can sometimes cause problems
  132. ; eg when reichs door is open the door grid bit gets replaced so you can't get back in (or out)
  133. test [reich_door_flag],-1
  134. je reich_closed
  135. mov esi,offset reich_door_20
  136. mov eax,256
  137. mov ebx,280
  138. mov ecx,1
  139. call fn_remove_grid
  140. endif
  141. reich_closed:
  142. ret
  143. load_grids endp
  144. remove_object_from_walk proc
  145. call get_grid_values
  146. je no_walk
  147. fn_remove_object_from_walk::
  148. otw_loop: btr [ebx],ecx
  149. dec ecx
  150. jns novf
  151. add ebx,4
  152. mov ecx,1fh
  153. novf: floop edx,otw_loop
  154. no_walk: mov al,1 ;don't quit from interpreter
  155. ret
  156. remove_object_from_walk endp
  157. object_to_walk proc
  158. call get_grid_values
  159. je no_walk
  160. fn_object_to_walk::
  161. otw_loop: bts [ebx],ecx
  162. dec ecx
  163. jns novf
  164. add ebx,4
  165. mov ecx,1fh
  166. novf: floop edx,otw_loop
  167. no_walk: mov al,1 ;don't quit from interpreter
  168. ret
  169. object_to_walk endp
  170. get_grid_values proc
  171. ; esi is object compact
  172. movzx ebx,(cpt[esi]).c_ycood ;get y coordinate
  173. movzx ecx,(cpt[esi]).c_xcood
  174. movzx edx,(cpt[esi]).c_mega_set ;get correct set
  175. movzx edx,wpt c_grid_width[esi+edx] ;get block width
  176. fn_get_grid_values::
  177. ; ebx = y
  178. ; ecx = x
  179. ; edx = width-1
  180. sub ebx,top_left_y
  181. jc off_screen
  182. shr ebx,3 ;turn into blocks
  183. cmp ebx,GRID_Y
  184. jnc off_screen
  185. imul ebx,ebx,40 ;turn into bits
  186. ; Look at x coordinate
  187. shr ecx,3 ;turn into blocks
  188. inc edx ;Value is offset for 68000 dbf
  189. sub ecx,top_left_x/8 ;remove left value
  190. jnc x_ok
  191. add edx,ecx ;adjust width
  192. jnc off_screen
  193. je off_screen
  194. x_ok: ;x is ok on left. Check right
  195. mov eax,game_screen_width/8
  196. sub eax,ecx
  197. jbe off_screen
  198. sub eax,edx
  199. jnc x2_ok
  200. add edx,eax
  201. jnc off_screen
  202. je off_screen
  203. x2_ok: add ecx,ebx ;bit position of start
  204. mov ebx,ecx ;get dword offset
  205. and ebx,0ffffffe0h
  206. shr ebx,3 ;bits to bytes
  207. add ebx,[game_grids]
  208. movzx eax,(cpt[esi]).c_screen ;get correct screen
  209. mov al,bpt[offset grid_convert_table+eax]
  210. cherror al,nc,tot_no_grids+1,em_internal_error
  211. imul eax,eax,grid_size
  212. add ebx,eax
  213. and ecx,01fh ;bit number
  214. sub ecx,01fh
  215. neg ecx
  216. or al,1 ;clear z flag
  217. ret
  218. off_screen: clear eax
  219. ret
  220. get_grid_values endp
  221. end32code
  222. end
  223.