map_routines.s 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. *Remember the alien map is byte but the main map is word!!!!!
  2. *------------------MAP ROUTINES--------------------------*
  3. MAP_BLOCK_SIZE EQU 2 ;word map
  4. ;hey I dont care if the routines could be combined into 1 - I am on
  5. ; a tight time budget
  6. ****************************************************
  7. ***** DECOMPRESS WORD MAP *****
  8. ****************************************************
  9. Decompress_Word_Map
  10. move.l memory_base,a0
  11. move.l (a0)+,d2 ;total size of compressed map data in bytes
  12. asr.l d2 ;cos word
  13. move.l buffer_map_memory,a2
  14. add.l #((BUFFER_OFFSET*BIGGEST_MAP_X)*MAP_BLOCK_SIZE)+BUFFER_OFFSET*MAP_BLOCK_SIZE,a2
  15. move.l #generic_map_header,a5
  16. move.w map_data_x(a5),d0 ;map x size
  17. move.w map_data_y(a5),d1 ;map y size
  18. move.l a2,a3
  19. move.w d0,d5
  20. get_word_byte
  21. subq.l #1,d2
  22. ble finished_word_read
  23. move.w (a0)+,d4
  24. bclr #15,d4
  25. beq read_word_repeat_data
  26. subq.w #1,d4
  27. straight_loop
  28. move.w (a0)+,(a3)+
  29. ifnd final_version
  30. cmp.l Buffer_Alien_Memory,a3
  31. blt.s not_overwritting2
  32. signal_error_and_wait2
  33. move.w #$f0f,$dff180
  34. btst.b #6,$bfe001
  35. bne.s signal_error_and_wait2
  36. not_overwritting2
  37. endc
  38. subq.l #1,d2
  39. ble.s finished_word_read
  40. subq.w #1,d5
  41. bgt.s dont_reset_pointer
  42. add.l #BIGGEST_MAP_X*MAP_BLOCK_SIZE,a2
  43. move.l a2,a3
  44. move.w d0,d5
  45. dont_reset_pointer
  46. dbra d4,straight_loop
  47. bra.s get_word_byte
  48. read_word_repeat_data
  49. subq.w #1,d4
  50. move.w (a0)+,d6
  51. read_repeat_word_loop
  52. move.w d6,(a3)+
  53. ifnd final_version
  54. cmp.l buffer_alien_memory,a3
  55. blt.s not_overwritting
  56. signal_error_and_wait
  57. move.w #$fff,$dff180
  58. btst.b #6,$bfe001
  59. bne.s signal_error_and_wait
  60. not_overwritting
  61. endc
  62. subq.w #1,d5
  63. bgt.s dont_reset_repeat_word_pointer
  64. add.l #BIGGEST_MAP_X*MAP_BLOCK_SIZE,a2
  65. move.l a2,a3
  66. move.w d0,d5
  67. dont_reset_repeat_word_pointer
  68. dbra d4,read_repeat_word_loop
  69. subq.l #1,d2
  70. ble.s finished_word_read
  71. bra get_word_byte
  72. finished_word_read
  73. rts
  74. ****************************************************
  75. ***** DECOMPRESS BYTE MAP *****
  76. ****************************************************
  77. Decompress_Byte_Map
  78. move.l memory_base,a0
  79. move.l (a0)+,d0
  80. add.l d0,a0 ;alien map data
  81. move.l (a0)+,d2
  82. move.l buffer_alien_memory,a2
  83. * Clear the alien memory just to ensure no unwanted aliens appear
  84. move.l a2,a1
  85. move.w #((BIGGEST_MAP_X*BIGGEST_MAP_Y)/16)-1,d7
  86. Clear_Map_Memory
  87. clr.l (a1)+
  88. clr.l (a1)+
  89. clr.l (a1)+
  90. clr.l (a1)+
  91. dbra d7,Clear_Map_Memory
  92. add.l #(BUFFER_OFFSET*BIGGEST_MAP_X)+BUFFER_OFFSET,a2
  93. move.l #generic_map_header,a5
  94. move.w map_data_x(a5),d0 ;map x size
  95. move.w map_data_y(a5),d1 ;map y size
  96. move.l a2,a3
  97. move.w d0,d5
  98. get_byte_byte
  99. subq.l #1,d2
  100. ble.s finished_byte_read
  101. moveq #0,d4
  102. move.b (a0)+,d4
  103. bclr #7,d4
  104. beq.s read_byte_repeat_data
  105. subq.w #1,d4
  106. straight_byte_loop
  107. move.b (a0)+,(a3)+
  108. ifnd final_version
  109. cmp.l Copy_Store_area,a3
  110. blt.s not_boverwritting
  111. bsignal_error_and_wait
  112. move.w #$0ff,$dff180
  113. btst.b #6,$bfe001
  114. bne.s bsignal_error_and_wait
  115. not_boverwritting
  116. endc
  117. subq.l #1,d2
  118. ble.s finished_byte_read
  119. subq.w #1,d5
  120. bgt.s dont_reset_byte_pointer
  121. add.l #BIGGEST_MAP_X,a2
  122. move.l a2,a3
  123. move.w d0,d5
  124. dont_reset_byte_pointer
  125. dbra d4,straight_byte_loop
  126. bra.s get_byte_byte
  127. read_byte_repeat_data
  128. subq.w #1,d4
  129. move.b (a0)+,d6
  130. read_repeat_byte_loop
  131. move.b d6,(a3)+
  132. ifnd final_version
  133. cmp.l Copy_Store_area,a3
  134. blt.s not_boverwritting2
  135. bsignal_error_and_wait2
  136. move.w #$00f,$dff180
  137. btst.b #6,$bfe001
  138. bne.s bsignal_error_and_wait2
  139. not_boverwritting2
  140. endc
  141. subq.w #1,d5
  142. bgt.s dont_reset_repeat_byte_pointer
  143. add.l #BIGGEST_MAP_X,a2
  144. move.l a2,a3
  145. move.w d0,d5
  146. dont_reset_repeat_byte_pointer
  147. dbra d4,read_repeat_byte_loop
  148. subq.l #1,d2
  149. ble.s finished_byte_read
  150. bra.s get_byte_byte
  151. finished_byte_read
  152. rts
  153. ****************************************************
  154. ***** LOAD MAP DATA *****
  155. ****************************************************
  156. Load_Map_Data
  157. *First clear out map buffers
  158. move.l buffer_map_memory,a0
  159. move.w #(((BIGGEST_MAP_X*BIGGEST_MAP_Y)*MAP_BLOCK_SIZE)/4)-1,d0
  160. clear_map_buffers
  161. clr.l (a0)+
  162. dbra d0,clear_map_buffers
  163. *clear out alien data buffer
  164. move.l buffer_alien_memory,a0
  165. move.w #((BIGGEST_MAP_X*BIGGEST_MAP_Y)/4)-1,d0
  166. clear_alien_map_buffers
  167. clr.l (a0)+
  168. dbra d0,clear_alien_map_buffers
  169. bsr Load_Map_For_Level
  170. tst.l d0
  171. beq.s error_loading_blocks
  172. move.l #Generic_Map_Header,a5
  173. cmp.l #"COMP",map_file_header(a5)
  174. bne.s set_up_pointers ;ooops's not correct map type
  175. load_compressed_map
  176. bsr Decompress_Word_Map
  177. bsr Decompress_Byte_Map
  178. set_up_pointers
  179. move.l buffer_map_memory,a0
  180. move.l buffer_alien_memory,a1
  181. add.l #((BUFFER_OFFSET*BIGGEST_MAP_X)*MAP_BLOCK_SIZE)+BUFFER_OFFSET*MAP_BLOCK_SIZE,a0
  182. add.l #(BUFFER_OFFSET*BIGGEST_MAP_X)+BUFFER_OFFSET,a1
  183. move.l a0,current_map_pointer
  184. move.l a1,current_alien_map_pointer
  185. error_loading_blocks
  186. rts
  187. ****************************************************
  188. ***** CONSTRUCT MAP PAGES *****
  189. ****************************************************
  190. Construct_Map_Pages
  191. move.w #1,d0
  192. bsr Load_Block_Page
  193. clr.w d0
  194. move.w #320,d1
  195. bsr Construct_Map_Page
  196. move.w #2,d0
  197. bsr Load_Block_Page
  198. move.w #320,d0
  199. move.w #320,d1
  200. bsr Construct_Map_Page
  201. move.w #3,d0
  202. bsr Load_Block_Page
  203. move.w #640,d0
  204. move.w #320,d1
  205. bsr Construct_Map_Page
  206. move.w #4,d0
  207. bsr Load_Block_Page
  208. move.w #960,d0
  209. move.w #220,d1
  210. bsr Construct_Map_Page
  211. rts
  212. ****************************************************
  213. ***** CONSTRUCT MAP PAGE *****
  214. ****************************************************
  215. Construct_Map_Page
  216. *send block start number in d0
  217. *send numbers of blocks in d1
  218. movem.l d0-d3/a0-a2,-(sp)
  219. subq.w #1,d1 ;prime block count
  220. move.l Fast_Memory_Base,a0 ;location of block page
  221. add.l #LO_RES_PLANE*4,a0
  222. move.l Background_Block_Graphics,a1
  223. mulu #16*2*4,d0
  224. add.l d0,a1 ;get to dest block
  225. clr.w d2 ;word in page pos
  226. Convert_Block_Mem
  227. move.w #4-1,d3
  228. move.l a0,a2
  229. Convert_Block_Mem_Loop
  230. move.w (a2),(a1)+
  231. move.w 40(a2),(a1)+
  232. move.w 80(a2),(a1)+
  233. move.w 120(a2),(a1)+
  234. move.w 160(a2),(a1)+
  235. move.w 200(a2),(a1)+
  236. move.w 240(a2),(a1)+
  237. move.w 280(a2),(a1)+
  238. move.w 320(a2),(a1)+
  239. move.w 360(a2),(a1)+
  240. move.w 400(a2),(a1)+
  241. move.w 440(a2),(a1)+
  242. move.w 480(a2),(a1)+
  243. move.w 520(a2),(a1)+
  244. move.w 560(a2),(a1)+
  245. move.w 600(a2),(a1)+
  246. add.l #LO_RES_PLANE,a2
  247. dbra d3,Convert_Block_Mem_Loop
  248. addq.l #2,a0
  249. addq.w #1,d2
  250. cmp.w #20,d2
  251. blt.s not_line_yet
  252. clr.w d2
  253. add.l #(40*15),a0
  254. not_line_yet
  255. dbra d1,Convert_Block_Mem
  256. movem.l (sp)+,d0-d3/a0-a2
  257. rts