idarray.asm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. ; $Id$
  2. ; MegaZeux
  3. ;
  4. ; Copyright (C) 1996 Greg Janson
  5. ; Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. ;
  7. ; This program is free software; you can redistribute it and/or
  8. ; modify it under the terms of the GNU General Public License as
  9. ; published by the Free Software Foundation; either version 2 of
  10. ; the License, or (at your option) any later version.
  11. ;
  12. ; This program is distributed in the hope that it will be useful,
  13. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ; General Public License for more details.
  16. ;
  17. ; You should have received a copy of the GNU General Public License
  18. ; along with this program; if not, write to the Free Software
  19. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. ;
  21. ; This file contains functions for manipulating the level arrays
  22. ;
  23. Ideal
  24. include "idarray.inc"
  25. include "data.inc"
  26. include "const.inc"
  27. p186
  28. JUMPS
  29. include "model.inc"
  30. Codeseg
  31. ;
  32. ; Place an id/color/param combo in an array position, moving current to
  33. ; "under" status if possible, and clearing original "under". If placing an
  34. ; "under", then automatically clear lower no matter what. Also mark as
  35. ; updated.
  36. ;
  37. proc id_place far
  38. arg array_x:word,array_y:word,id:byte,color:byte,param:byte
  39. local @@saved_id:byte
  40. push ax bx dx ds es di
  41. mov ax,SEG update_done
  42. mov ds,ax
  43. ;
  44. ; Calculate offset within arrays
  45. ;
  46. mov ax,[max_bxsiz] ; Multiply 100 by
  47. mul [array_y] ; Y pos,
  48. add ax,[array_x] ; add X pos,
  49. mov bx,ax ; and move into BX.
  50. push bx
  51. offset_entry:
  52. ; BX = Array offset
  53. les di,[ds:update_done] ; Mark as "updated"
  54. or [BYTE PTR es:di+bx],1
  55. les di,[ds:level_id] ; Load address of level_id in es:di
  56. mov bl,[es:di+bx] ; Load current id
  57. mov [@@saved_id],bl ; Save id
  58. mov di,OFFSET flags ; Load offset of flags array
  59. flipflag bh,bh ; Clear upper bx
  60. add bl,bl ; BX * 2 (id<128)
  61. ; BX=offset into flags array,
  62. ; in ds:di
  63. mov ax,[ds:di+bx] ; Get flags word
  64. pop bx ; Restore array offset
  65. ; AX contains flags word for id
  66. testflag ax,A_SPEC_STOOD
  67. jnz @@sensor
  68. and ax,A_UNDER ; Can id "go under"?
  69. jz @@no_under ; No...
  70. ; Get flags for id being PLACED.
  71. push bx
  72. mov bl,[id]
  73. add bl,bl
  74. flipflag bh,bh
  75. mov ax,[ds:di+bx]
  76. pop bx
  77. testflag ax,A_UNDER
  78. jnz @@no_under ; If placing an UNDER, then ERASE
  79. ; current under.
  80. ; Yes. Move id/param/color to
  81. ; "under"
  82. @@under_ok:
  83. cmp [id],127
  84. jne @@under_ok_normal
  85. ; Save double under
  86. mov al,[@@saved_id] ; Load id
  87. les di,[ds:level_under_id] ; Load location of under_id's
  88. xchg [es:di+bx],al ; Save id in "under"
  89. mov [under_player_id],al
  90. les di,[ds:level_param]
  91. mov al,[es:di+bx] ; Load param
  92. les di,[ds:level_under_param]
  93. xchg [es:di+bx],al ; Save param in "under"
  94. mov [under_player_param],al
  95. les di,[ds:level_color]
  96. mov al,[es:di+bx] ; Load color
  97. les di,[ds:level_under_color]
  98. xchg [es:di+bx],al ; Save color in "under"
  99. mov [under_player_color],al
  100. jmp @@under_done ; Skip @@no_under part
  101. @@under_ok_normal:
  102. mov al,[@@saved_id] ; Load id
  103. les di,[ds:level_under_id] ; Load location of under_id's
  104. mov [es:di+bx],al ; Save id in "under"
  105. les di,[ds:level_param]
  106. mov al,[es:di+bx] ; Load param
  107. les di,[ds:level_under_param]
  108. mov [es:di+bx],al ; Save param in "under"
  109. les di,[ds:level_color]
  110. mov al,[es:di+bx] ; Load color
  111. les di,[ds:level_under_color]
  112. mov [es:di+bx],al ; Save color in "under"
  113. jmp @@under_done ; Skip @@no_under part
  114. @@sensor:
  115. cmp [id],127
  116. jne @@no_under
  117. ; Player -> sensor = ok
  118. jmp @@under_ok
  119. @@no_under:
  120. les di,[ds:level_under_id] ; Load location of under_id's
  121. ; al=0 'cause of prev. and
  122. xor al,al
  123. mov [es:di+bx],al ; Clear "under" id
  124. les di,[ds:level_under_param]
  125. mov [es:di+bx],al ; Clear "under" param
  126. les di,[ds:level_under_color]
  127. mov [BYTE PTR es:di+bx],7 ; Clear "under" color
  128. @@under_done:
  129. les di,[ds:level_id]
  130. mov al,[id]
  131. mov [es:di+bx],al ; Store new id
  132. les di,[ds:level_color]
  133. mov al,[color]
  134. mov [es:di+bx],al ; Store new color
  135. les di,[ds:level_param]
  136. mov al,[param]
  137. mov [es:di+bx],al ; Store new param
  138. pop di es ds dx bx ax
  139. ret
  140. endp id_place
  141. ; "blank" is just that- irrevelant and usually blank.
  142. proc offs_place_id far
  143. arg offs:word,junk:word,id:byte,color:byte,param:byte
  144. push ax bx dx ds es di
  145. ;
  146. ; Calculate offset within arrays, jump within above function
  147. ;
  148. mov ax,SEG update_done
  149. mov ds,ax
  150. mov bx,[offs]
  151. push bx
  152. jmp offset_entry
  153. endp offs_place_id
  154. proc id_place_asm near
  155. arg array_x:word,array_y:word,id_color:word,param:byte
  156. local @@saved_id:byte
  157. push ax bx cx dx es di
  158. mov ax,SEG level_id
  159. mov ds,ax
  160. ;
  161. ; Calculate offset within arrays
  162. ;
  163. mov bx,[array_y]
  164. mov ax,[max_bxsiz] ; Multiply 100 by
  165. mul bx ; Y pos,
  166. add ax,[array_x]
  167. mov bx,ax
  168. mov cx,bx
  169. ;
  170. ; BX = Array offset
  171. ;
  172. les di,[ds:update_done] ; Mark as "updated"
  173. or [BYTE PTR es:di+bx],1
  174. les di,[ds:level_id] ; Load address of level_id in es:di
  175. mov bl,[es:di+bx] ; Load current id
  176. mov [@@saved_id],bl ; Save id
  177. mov di,OFFSET flags ; Load offset of flags array
  178. xor bh,bh ; Clear upper bx
  179. add bl,bl ; BX * 2 (id<128)
  180. ;
  181. ; BX=offset into flags array, in ds:di
  182. ;
  183. mov ax,[ds:di+bx] ; Get flags word
  184. mov bx,cx ; Restore array offset
  185. ; AX contains flags word for id
  186. testflag ax,A_SPEC_STOOD
  187. jnz @@sensor
  188. and ax,A_UNDER ; Can id "go under"?
  189. jz @@no_under ; No...
  190. ; Get flags for id being PLACED.
  191. ;
  192. mov bl,[BYTE LOW id_color]
  193. add bl,bl
  194. xor bh,bh
  195. mov ax,[ds:di+bx]
  196. mov bx,cx
  197. testflag ax,A_UNDER
  198. jnz @@no_under ; If placing an UNDER, then ERASE current under.
  199. ;
  200. ; Yes. Move id/param/color to "under"
  201. ;
  202. @@under_ok:
  203. cmp [BYTE PTR id_color],127
  204. jne @@under_ok_normal
  205. ; Save double under
  206. mov al,[@@saved_id] ; Load id
  207. les di,[ds:level_under_id] ; Load location of under_id's
  208. xchg [es:di+bx],al ; Save id in "under"
  209. mov [under_player_id],al
  210. les di,[ds:level_param]
  211. mov al,[es:di+bx] ; Load param
  212. les di,[ds:level_under_param]
  213. xchg [es:di+bx],al ; Save param in "under"
  214. mov [under_player_param],al
  215. les di,[ds:level_color]
  216. mov al,[es:di+bx] ; Load color
  217. les di,[ds:level_under_color]
  218. xchg [es:di+bx],al ; Save color in "under"
  219. mov [under_player_color],al
  220. jmp @@under_done ; Skip @@no_under part
  221. @@under_ok_normal:
  222. mov al,[@@saved_id] ; Load id
  223. les di,[ds:level_under_id] ; Load location of under_id's
  224. mov [es:di+bx],al ; Save id in "under"
  225. les di,[ds:level_param]
  226. mov al,[es:di+bx] ; Load param
  227. les di,[ds:level_under_param]
  228. mov [es:di+bx],al ; Save param in "under"
  229. les di,[ds:level_color]
  230. mov al,[es:di+bx] ; Load color
  231. les di,[ds:level_under_color]
  232. mov [es:di+bx],al ; Save color in "under"
  233. jmp @@under_done ; Skip @@no_under part
  234. @@sensor:
  235. cmp [BYTE PTR id_color],127
  236. jne @@no_under
  237. ; Player -> sensor = ok
  238. jmp @@under_ok
  239. @@no_under:
  240. les di,[ds:level_under_id] ; Load location of under_id's
  241. mov [BYTE PTR es:di+bx],0 ; Clear "under" id
  242. les di,[ds:level_under_param]
  243. mov [BYTE PTR es:di+bx],0 ; Clear "under" param
  244. les di,[ds:level_under_color]
  245. mov [BYTE PTR es:di+bx],7 ; Clear "under" color
  246. @@under_done:
  247. les di,[ds:level_id]
  248. mov ax,[id_color]
  249. mov [es:di+bx],al ; Store new id
  250. les di,[ds:level_color]
  251. mov [es:di+bx],ah ; Store new color
  252. les di,[ds:level_param]
  253. mov al,[param]
  254. mov [es:di+bx],al ; Store new param
  255. pop di es dx cx bx ax
  256. ret
  257. endp id_place_asm
  258. ;
  259. ; Clears (both main and "under") an id in array position given by parameters.
  260. ;
  261. proc id_clear
  262. arg array_x:word,array_y:word
  263. push ax bx dx es ds di
  264. mov ax,SEG level_id
  265. mov ds,ax
  266. ;
  267. ; Calculate offset within arrays
  268. ;
  269. mov ax,[max_bxsiz] ; Multiply 100 by
  270. mul [array_y] ; Y pos,
  271. add ax,[array_x] ; add X pos,
  272. mov bx,ax ; and move into BX.
  273. les di,[ds:level_id] ; Load address of level_id in es:di
  274. xor al,al
  275. ;
  276. ; BX = Array offset ES:DI = Level Id DS: = Near segment
  277. ;
  278. mov [BYTE PTR es:di+bx],al ; Clear ID
  279. les di,[ds:level_param]
  280. mov [BYTE PTR es:di+bx],al ; Clear param
  281. les di,[ds:level_under_id]
  282. mov [BYTE PTR es:di+bx],al ; Clear under id
  283. les di,[ds:level_under_param]
  284. mov [BYTE PTR es:di+bx],al ; Clear under param
  285. les di,[ds:level_color]
  286. mov [BYTE PTR es:di+bx],7 ; Clear color (grey)
  287. les di,[ds:level_under_color]
  288. mov [BYTE PTR es:di+bx],7 ; Clear under color (grey)
  289. les di,[ds:update_done]
  290. or [BYTE PTR es:di+bx],1 ; Mark as updated
  291. pop di ds es dx bx ax
  292. ret
  293. endp id_clear
  294. ;
  295. ; Removes the top at the given array position, moving any "under" up.
  296. ;
  297. proc id_remove_top
  298. arg array_x:word,array_y:word
  299. push ax bx dx es ds di
  300. mov ax,SEG level_id
  301. mov ds,ax
  302. ;
  303. ; Calculate offset within arrays
  304. ;
  305. mov ax,[max_bxsiz] ; Multiply 100 by
  306. mul [array_y] ; Y pos,
  307. add ax,[array_x] ; add X pos,
  308. mov bx,ax ; and move into BX.
  309. offset_enter_remid:
  310. ;
  311. ; BX = Array offset ES:DI = Level Under Id DS: = Near segment
  312. ;
  313. les di,[ds:level_id]
  314. cmp [BYTE PTR es:di+bx],127
  315. jne @@normal_clear
  316. les di,[ds:level_under_id] ; Load seg:offs of level_under_id
  317. xor al,al
  318. xchg al,[under_player_id]
  319. xchg al,[es:di+bx] ; Load under id
  320. les di,[ds:level_id]
  321. mov [BYTE PTR es:di+bx],al ; Save in normal position
  322. les di,[ds:level_under_param]
  323. xor al,al
  324. xchg al,[under_player_param]
  325. xchg al,[es:di+bx] ; Load under param
  326. les di,[ds:level_param]
  327. mov [BYTE PTR es:di+bx],al ; Save in normal position
  328. les di,[ds:level_under_color]
  329. mov al,7
  330. xchg al,[under_player_color]
  331. xchg al,[es:di+bx] ; Load under color
  332. les di,[ds:level_color]
  333. mov [BYTE PTR es:di+bx],al ; Save in normal position
  334. jmp @@thingydone
  335. @@normal_clear:
  336. les di,[ds:level_under_id] ; Load seg:offs of level_under_id
  337. mov al,[es:di+bx] ; Load under id
  338. mov [BYTE PTR es:di+bx],0 ; then clear it
  339. les di,[ds:level_id]
  340. mov [BYTE PTR es:di+bx],al ; Save in normal position
  341. les di,[ds:level_under_param]
  342. mov al,[es:di+bx] ; Load under param
  343. mov [BYTE PTR es:di+bx],0 ; then clear it
  344. les di,[ds:level_param]
  345. mov [BYTE PTR es:di+bx],al ; Save in normal position
  346. les di,[ds:level_under_color]
  347. mov al,[es:di+bx] ; Load under color
  348. mov [BYTE PTR es:di+bx],7 ; then clear it (with grey)
  349. les di,[ds:level_color]
  350. mov [BYTE PTR es:di+bx],al ; Save in normal position
  351. @@thingydone:
  352. les di,[ds:update_done]
  353. or [BYTE PTR es:di+bx],1 ; Mark as done
  354. pop di ds es dx bx ax
  355. ret
  356. endp id_remove_top
  357. ; "blank" is a junk word
  358. proc offs_remove_id far
  359. arg offs:word,blank:word
  360. push ax bx dx es ds di
  361. ;
  362. ; Calculate offset within arrays and jump to within above
  363. ;
  364. mov ax,SEG level_id
  365. mov ds,ax
  366. mov bx,[offs]
  367. jmp offset_enter_remid
  368. endp offs_remove_id
  369. ;
  370. ; Removes any "under" from the given array position
  371. ;
  372. proc id_remove_under
  373. arg array_x:word,array_y:word
  374. push ax bx dx es ds di
  375. mov ax,SEG level_id
  376. mov ds,ax
  377. ;
  378. ; Calculate offset within arrays
  379. ;
  380. mov ax,[max_bxsiz] ; Multiply 100 by
  381. mul [array_y] ; Y pos,
  382. add ax,[array_x] ; add X pos,
  383. mov bx,ax ; and move into BX.
  384. les di,[ds:level_under_id]
  385. xor al,al
  386. ;
  387. ; BX = Array offset ES:DI = Level Under Id DS: = Near segment
  388. ;
  389. mov [BYTE PTR es:di+bx],al ; Clear under id
  390. les di,[ds:level_under_param]
  391. mov [BYTE PTR es:di+bx],al ; Clear under param
  392. les di,[ds:level_under_color]
  393. mov [BYTE PTR es:di+bx],7 ; Clear under color (grey)
  394. les di,[ds:update_done]
  395. or [BYTE PTR es:di+bx],1 ; Mark as done
  396. pop di ds es dx bx ax
  397. ret
  398. endp id_remove_under
  399. ends
  400. end