graphic_routines.s 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. **********************************
  2. **** DISPLAY_GRAPHIC_LIST *****
  3. **********************************
  4. display_graphic_buttons
  5. move.l #top_level_list,a0
  6. bsr remove_button_list
  7. move.l #graphic_page_buttons,a0 ;depress current page
  8. moveq #0,d0
  9. move.w current_page,d0
  10. asl.w #2,d0
  11. move.l (a0,d0.w),a0
  12. move.b #1,button_start(a0)
  13. move.w #2,edit_mode
  14. move.l #graphic_list,a0
  15. bsr display_button_list
  16. bsr clear_screen
  17. bsr reset_all_page_positions
  18. bsr display_graphic_page
  19. rts
  20. **********************************
  21. **** REMOVE_GRAPHIC_LIST *****
  22. **********************************
  23. remove_graphic_buttons
  24. move.l #graphic_list,a0
  25. bsr remove_button_list
  26. move.w #0,edit_mode
  27. move.w #0,sprite_to_attach
  28. tst generic_button_up
  29. beq.s button_not_up
  30. move.l #detect_generic_button,a0
  31. bsr remove_button
  32. button_not_up
  33. move.l #top_level_list,a0
  34. bsr display_button_list
  35. bsr clear_screen
  36. bsr reset_all_page_positions
  37. rts
  38. **********************************
  39. **** CANCEL BLOCK OPS *****
  40. **********************************
  41. cancel_block_ops
  42. move.l #detect_generic_button,a0
  43. bsr remove_button
  44. move.w #0,generic_button_up
  45. move.w #0,sprite_to_attach
  46. rts
  47. **********************************
  48. **** RESET ALL PAGE POSITIONS *****
  49. **********************************
  50. reset_all_page_positions
  51. move.l #picture_pages,a0
  52. move.w #5-1,d0
  53. reset_all
  54. move.l (a0),a1
  55. move.w #0,screen_y_pos(a1)
  56. addq.l #4,a0
  57. dbra d0,reset_all
  58. rts
  59. **********************************
  60. **** LOAD AN IMAGE FILE *****
  61. **********************************
  62. Load_an_Image_File
  63. move.l #Read_IFF_Image_File,File_Routine_Pointer
  64. bsr display_file_request
  65. rts
  66. **********************************
  67. **** READ IFF IMAGE FILE *****
  68. **********************************
  69. Read_IFF_Image_File
  70. movem.l a6,-(sp)
  71. move.l #Current_Filename,d1
  72. move.l #MODE_OLD,d2
  73. move.l dosbase,a6
  74. jsr Open(a6)
  75. movem.l (sp)+,a6
  76. tst.l d0
  77. beq.s couldnt_load_it
  78. movem.l d0,-(sp)
  79. bsr remove_file_request
  80. movem.l (sp)+,d0
  81. movem.l d0/a0,-(sp)
  82. move.w current_page,d0
  83. mulu #FILENAME_LENGTH,d0
  84. move.l #Current_Filename,a0
  85. jsr Set_Project_Information
  86. movem.l (sp)+,d0/a0
  87. bsr Load_Graphics
  88. cmp.l #-1,a1
  89. bne.s no_errors_here
  90. bsr error_routine
  91. rts
  92. couldnt_load_it
  93. bsr display_error
  94. rts
  95. no_errors_here
  96. bsr display_graphic_page
  97. rts
  98. ************************************
  99. **** DISPLAY GRAPHIC PAGE ****
  100. ************************************
  101. display_graphic_page
  102. move.l page_pointer,a0
  103. move.l screen_palette(a0),a1
  104. bsr setup_screen_colours
  105. move.l #main_screen_struct,a2
  106. move.w screen_y_pos(a0),d0
  107. move.w screen_x_size(a2),d1
  108. asr.w #3,d1
  109. mulu d0,d1
  110. move.w number_of_planes(a0),d7
  111. move.l screen_mem(a0),a0
  112. beq.s quit_display_page
  113. data_present
  114. add.l d1,a0
  115. move.l screen_mem(a2),a1
  116. move.w screen_x_size(a2),d0
  117. asr.w #3,d0
  118. mulu screen_y_size(a2),d0
  119. mulu d7,d0
  120. asr.l #2,d0
  121. subq.w #1,d0
  122. fill_loop
  123. move.l (a0)+,(a1)+
  124. dbra d0,fill_loop
  125. quit_display_page
  126. jsr Display_Overlays
  127. rts
  128. ********************************
  129. **** CHANGE PAGE *****
  130. ********************************
  131. change_page
  132. move.l clicked_button,a0
  133. moveq #0,d0
  134. move.b button_data(a0),d0
  135. subq.w #1,d0
  136. cmp.w current_page,d0
  137. bne.s not_clicked_on_same_butt
  138. move.b #DEPRESSED,button_start(a0)
  139. bra.s update_gr_button
  140. not_clicked_on_same_butt
  141. moveq #0,d1
  142. move.w current_page,d1
  143. move.w d0,current_page
  144. move.l #graphic_page_buttons,a0
  145. asl.w #2,d1
  146. move.l (a0,d1.w),a0
  147. move.b #NOT_DEPRESSED,button_start(a0)
  148. update_gr_button
  149. bsr remove_button
  150. bsr display_button
  151. move.l #picture_pages,a0
  152. moveq #0,d0
  153. move.w current_page,d0
  154. asl.w #2,d0
  155. move.l (a0,d0.w),page_pointer
  156. bsr display_graphic_page
  157. rts
  158. current_page
  159. dc.w 0
  160. ***************************************
  161. **** CHANGE GRAPHICS POSITION UP *****
  162. ***************************************
  163. change_graphics_position_up
  164. move.l #main_screen_struct,a0
  165. move.w screen_y_size(a0),d0
  166. sub.w #BUTTON_WINDOW_OFFSET,d0 ; gives part of screen hiding
  167. move.l page_pointer,a0
  168. tst.l screen_mem(a0)
  169. beq.s no_more_scroll
  170. cmp.w screen_y_pos(a0),d0
  171. beq.s no_more_scroll
  172. move.l current_map_ptr,a1
  173. move.w map_block_size(a1),d0
  174. add.w d0,screen_y_pos(a0)
  175. bsr display_graphic_page
  176. no_more_scroll
  177. rts
  178. ******************************************
  179. **** CHANGE GRAPHICS POSITION DOWN *****
  180. ******************************************
  181. change_graphics_position_down
  182. move.l page_pointer,a0
  183. tst.l screen_mem(a0)
  184. beq.s no_more_scroll
  185. cmp.w #0,screen_y_pos(a0)
  186. ble.s no_more_scrolld
  187. move.l current_map_ptr,a1
  188. move.w map_block_size(a1),d0
  189. sub.w d0,screen_y_pos(a0)
  190. bsr display_graphic_page
  191. no_more_scrolld
  192. rts
  193. store_x dc.w 0
  194. store_y dc.w 0
  195. store_off_y dc.w 0
  196. store_page dc.l 0
  197. ******************************************
  198. **** CONVERT MOUSE AND STORE *****
  199. ******************************************
  200. convert_mouse_and_store
  201. move.l a0,-(sp)
  202. moveq #0,d0
  203. moveq #0,d1
  204. moveq #0,d2
  205. moveq #0,d3
  206. move.w mouse_x,d0
  207. move.w mouse_y,d1
  208. move.w store_x,d2
  209. move.w store_y,d3
  210. move.l current_map_ptr,a0
  211. cmp.w #8,map_block_size(a0)
  212. bne.s check_if_16
  213. andi.w #$fff8,d0
  214. andi.w #$fff8,d1
  215. andi.w #$fff8,d2
  216. andi.w #$fff8,d3
  217. bra.s done_blocks
  218. check_if_16
  219. cmp.w #16,map_block_size(a0)
  220. bne.s check_if_32
  221. andi.w #$fff0,d0
  222. andi.w #$fff0,d1
  223. andi.w #$fff0,d2
  224. andi.w #$fff0,d3
  225. bra.s done_blocks
  226. check_if_32
  227. andi.w #$ffe0,d0
  228. andi.w #$ffe0,d1
  229. andi.w #$ffe0,d2
  230. andi.w #$ffe0,d3
  231. done_blocks
  232. move.l (sp)+,a0
  233. rts
  234. ******************************************
  235. **** COPY BLOCK TO BLOCK *****
  236. ******************************************
  237. copy_block_to_block
  238. *send a0 and a1 as start and dest
  239. *send number of planes in d7
  240. movem.l a0-a5/d0-d7,-(sp)
  241. move.l current_map_ptr,a2
  242. move.l #main_screen_struct,a3
  243. subq.w #1,d7
  244. moveq #0,d5
  245. move.w screen_x_size(a3),d5
  246. asr.w #3,d5
  247. move.l d5,d6
  248. mulu screen_y_size(a3),d6
  249. move.w map_block_size(a2),d0
  250. cmp.w #8,d0
  251. beq.s do_8bit_pl
  252. cmp.w #16,d0
  253. beq.s do_16bit_pl
  254. do_32bit_pl move.l a0,a4
  255. move.l a1,a5
  256. move.w d0,d3
  257. subq.w #1,d3
  258. do_32bit move.l (a4),(a5) * copy LONGWORD (32 bits)
  259. add.l d5,a4
  260. add.l d5,a5
  261. dbf d3,do_32bit
  262. add.l d6,a1
  263. add.l d6,a0
  264. dbf d7,do_32bit_pl
  265. movem.l (sp)+,a0-a5/d0-d7
  266. rts
  267. cnop 0,4
  268. do_8bit_pl move.l a0,a4
  269. move.l a1,a5
  270. move.w d0,d3
  271. subq.w #1,d3
  272. do_8bit move.b (a4),(a5) * copy BYTE (8 bits)
  273. add.l d5,a4
  274. add.l d5,a5
  275. dbf d3,do_8bit
  276. add.l d6,a1
  277. add.l d6,a0
  278. dbf d7,do_8bit_pl
  279. movem.l (sp)+,a0-a5/d0-d7
  280. rts
  281. cnop 0,4
  282. do_16bit_pl move.l a0,a4
  283. move.l a1,a5
  284. move.w d0,d3
  285. subq.w #1,d3
  286. do_16bit move.w (a4),(a5) * copy WORD (16 bits)
  287. add.l d5,a4
  288. add.l d5,a5
  289. dbf d3,do_16bit
  290. add.l d6,a1
  291. add.l d6,a0
  292. dbf d7,do_16bit_pl
  293. movem.l (sp)+,a0-a5/d0-d7
  294. rts
  295. ******************************************
  296. **** COPY BLOCK TO BUFFER *****
  297. ******************************************
  298. copy_block_to_buffer
  299. *send a0 and a1 as start and dest
  300. *send number of planes in d7
  301. *a1 contains buffer addr
  302. movem.l a0-a5/d0-d3/d7,-(sp)
  303. move.l current_map_ptr,a2
  304. move.l #main_screen_struct,a3
  305. subq.w #1,d7
  306. move.w map_block_size(a2),d0
  307. buffcopy_planes
  308. move.l a0,a4
  309. move.w d0,d1
  310. move.w d0,d3
  311. subq.w #1,d3
  312. buffcopy_to_new_position
  313. cmp.w #8,d1
  314. bne.s buffcopy16
  315. move.b (a4),(a1)+
  316. bra.s buffupdate_line
  317. buffcopy16
  318. cmp.w #16,d1
  319. bne.s buffmust_be_32
  320. move.w (a4),(a1)+
  321. bra.s buffupdate_line
  322. buffmust_be_32
  323. move.l (a4),(a1)+
  324. buffupdate_line
  325. moveq #0,d2
  326. move.w screen_x_size(a3),d2
  327. asr.w #3,d2
  328. add.l d2,a4
  329. dbra d3,buffcopy_to_new_position
  330. move.w screen_x_size(a3),d2
  331. asr.w #3,d2
  332. mulu screen_y_size(a3),d2
  333. add.l d2,a0
  334. dbra d7,buffcopy_planes
  335. movem.l (sp)+,a0-a5/d0-d3/d7
  336. rts
  337. ******************************************
  338. **** COPY BUFFER TO BLOCK *****
  339. ******************************************
  340. copy_buffer_to_block
  341. *send a0 and a1 as start and dest
  342. *send number of planes in d7
  343. *a0 contains buffer addr
  344. movem.l a0-a5/d0-d3/d7,-(sp)
  345. move.l current_map_ptr,a2
  346. move.l #main_screen_struct,a3
  347. subq.w #1,d7
  348. move.w map_block_size(a2),d0
  349. bloccopy_planes
  350. move.l a1,a4
  351. move.w d0,d1
  352. move.w d0,d3
  353. subq.w #1,d3
  354. bloccopy_to_new_position
  355. cmp.w #8,d1
  356. bne.s bloccopy16
  357. move.b (a0)+,(a4)
  358. bra.s blocupdate_line
  359. bloccopy16
  360. cmp.w #16,d1
  361. bne.s blocmust_be_32
  362. move.w (a0)+,(a4)
  363. bra.s blocupdate_line
  364. blocmust_be_32
  365. move.l (a0)+,(a4)
  366. blocupdate_line
  367. moveq #0,d2
  368. move.w screen_x_size(a3),d2
  369. asr.w #3,d2
  370. add.l d2,a4
  371. dbra d3,bloccopy_to_new_position
  372. move.w screen_x_size(a3),d2
  373. asr.w #3,d2
  374. mulu screen_y_size(a3),d2
  375. add.l d2,a1
  376. dbra d7,bloccopy_planes
  377. movem.l (sp)+,a0-a5/d0-d3/d7
  378. rts
  379. *****CODE TO MOVE A BLOCK
  380. ******************************************
  381. **** GET BLOCK POSITION *****
  382. ******************************************
  383. get_block_position
  384. move.w mouse_x,store_x
  385. move.w mouse_y,store_y
  386. move.l page_pointer,a0
  387. move.w screen_y_pos(a0),store_off_y
  388. move.l page_pointer,store_page
  389. move.w #TO,sprite_to_attach
  390. move.w #MODE_TO_MOVE_BLOCK,block_mode
  391. rts
  392. *******************PLEASE NOTE
  393. *when a picture is loaded it is always loaded into five planes
  394. *of memory this way when copying blocks around there is no
  395. *problem if a block is copied from a five plane picture
  396. *to a one plane picture
  397. *it is up to the user
  398. ******************************************
  399. **** FIND MOVE TO POSITION *****
  400. ******************************************
  401. find_move_to_position
  402. bsr convert_mouse_and_store
  403. move.l page_pointer,a0
  404. move.w d1,d6 ; store for later use
  405. add.w screen_y_pos(a0),d1
  406. move.l screen_mem(a0),a1
  407. asr.w #3,d0
  408. move.l #main_screen_struct,a2
  409. move.w screen_x_size(a2),d4
  410. asr.w #3,d4
  411. mulu d4,d1 ;get position down screen
  412. add.l d1,a1
  413. add.l d0,a1 ; a1 contains dest address
  414. move.l a1,a5
  415. move.l store_page,a3
  416. move.w number_of_planes(a2),d7
  417. move.w d3,d5
  418. add.w store_off_y,d3
  419. move.l screen_mem(a3),a0
  420. asr.w #3,d2
  421. mulu d4,d3
  422. add.l d3,a0
  423. add.l d2,a0 ;a0 contains start address
  424. move.l #block_buffer,a1
  425. bsr copy_block_to_buffer ;in buffer
  426. move.l a0,a1
  427. move.l #blank_buffer,a0
  428. bsr copy_buffer_to_block ; clear out source
  429. move.l #block_buffer,a0
  430. move.l a5,a1
  431. bsr copy_buffer_to_block ; copy to dest
  432. ***blank out position on screen
  433. move.l screen_mem(a2),a1
  434. mulu d4,d5
  435. add.l d5,a1
  436. add.l d2,a1
  437. move.l #blank_buffer,a0
  438. bsr copy_buffer_to_block
  439. move.l #block_buffer,a0
  440. move.l screen_mem(a2),a1
  441. add.l d0,a1
  442. mulu d4,d6
  443. add.l d6,a1
  444. bsr copy_buffer_to_block; copy to screen
  445. *now put back to pick stage
  446. quit_move_block
  447. move.w #PICK,sprite_to_attach
  448. move.w #MODE_MOVE_BLOCK,block_mode
  449. rts
  450. ******************************************
  451. **** GET COPY BLOCK POSITION *****
  452. ******************************************
  453. get_copy_block_position
  454. move.w mouse_x,store_x
  455. move.w mouse_y,store_y
  456. move.l page_pointer,a0
  457. move.w screen_y_pos(a0),store_off_y
  458. move.l page_pointer,store_page
  459. move.w #TO,sprite_to_attach
  460. move.w #MODE_TO_COPY_BLOCK,block_mode
  461. rts
  462. ******************************************
  463. **** FIND COPY TO POSITION *****
  464. ******************************************
  465. find_copy_to_position
  466. bsr convert_mouse_and_store
  467. move.l page_pointer,a0
  468. move.w d1,d6 ; store for later use
  469. add.w screen_y_pos(a0),d1
  470. move.l screen_mem(a0),a1
  471. asr.w #3,d0
  472. move.l #main_screen_struct,a2
  473. move.w screen_x_size(a2),d4
  474. asr.w #3,d4
  475. mulu d4,d1 ;get position down screen
  476. add.l d1,a1
  477. add.l d0,a1 ; a1 contains dest address
  478. move.l store_page,a3
  479. move.w number_of_planes(a2),d7
  480. add.w store_off_y,d3 ;add on old offset
  481. move.l screen_mem(a3),a0
  482. asr.w #3,d2
  483. mulu d4,d3
  484. add.l d3,a0
  485. add.l d2,a0 ;a0 contains start address
  486. bsr copy_block_to_block ; copy into page
  487. move.l screen_mem(a2),a1
  488. add.l d0,a1
  489. mulu d4,d6
  490. add.l d6,a1
  491. bsr copy_block_to_block; copy to screen
  492. *now put back to pick stage
  493. quit_copy_block
  494. move.w #PICK,sprite_to_attach
  495. move.w #MODE_COPY_BLOCK,block_mode
  496. rts
  497. *****CODE TO EXCHANGE A BLOCK
  498. ******************************************
  499. **** GET EXCHANGE BLOCK POSITION *****
  500. ******************************************
  501. get_exchange_block_position
  502. move.w mouse_x,store_x
  503. move.w mouse_y,store_y
  504. move.l page_pointer,a0
  505. move.w screen_y_pos(a0),store_off_y
  506. move.l page_pointer,store_page
  507. move.w #TO,sprite_to_attach
  508. move.w #MODE_TO_EXCHANGE_BLOCK,block_mode
  509. rts
  510. ******************************************
  511. **** FIND EXCHANGE TO POSITION *****
  512. ******************************************
  513. find_exchange_to_position
  514. bsr convert_mouse_and_store
  515. move.l page_pointer,a0
  516. move.w d1,d6 ; store for later use
  517. add.w screen_y_pos(a0),d1
  518. move.l screen_mem(a0),a1
  519. asr.w #3,d0
  520. move.l #main_screen_struct,a2
  521. move.w number_of_planes(a2),d7
  522. move.w screen_x_size(a2),d4
  523. asr.w #3,d4
  524. mulu d4,d1 ;get position down screen
  525. add.l d1,a1
  526. add.l d0,a1 ; a1 contains dest address
  527. move.l a1,a0
  528. move.l #block_buffer,a1
  529. bsr copy_block_to_buffer
  530. move.l a0,a4 ;store dest address
  531. move.l store_page,a3
  532. move.w d3,d5
  533. add.w store_off_y,d3 ;add on old offset
  534. move.l screen_mem(a3),a0
  535. asr.w #3,d2
  536. mulu d4,d3
  537. add.l d3,a0
  538. add.l d2,a0 ;a0 contains start address
  539. move.l #block_buffer2,a1
  540. bsr copy_block_to_buffer
  541. move.l a4,a1 ;dest address
  542. move.l a0,a4 ;store start address
  543. move.l #block_buffer2,a0
  544. bsr copy_buffer_to_block
  545. move.l a4,a1
  546. move.l #block_buffer,a0
  547. bsr copy_buffer_to_block
  548. move.l #block_buffer2,a0
  549. move.l screen_mem(a2),a1
  550. add.l d0,a1
  551. mulu d4,d6
  552. add.l d6,a1
  553. bsr copy_buffer_to_block ; copy to screen position 1
  554. move.l screen_mem(a2),a1
  555. add.l d2,a1
  556. mulu d4,d5
  557. add.l d5,a1
  558. move.l #block_buffer,a0
  559. bsr copy_buffer_to_block ; copy to screen position 2
  560. *now put back to pick stage
  561. move.w #PICK,sprite_to_attach
  562. move.w #MODE_EXCHANGE_BLOCK,block_mode
  563. rts
  564. **** xflip,yflip and rotate funcs
  565. ******************************************
  566. **** GET BLOCK OPS POSITION *****
  567. ******************************************
  568. get_block_ops_position
  569. move.l #block_op_routines,a0
  570. moveq #0,d0
  571. move.w current_block_op,d0
  572. add.l d0,a0
  573. move.l (a0),a0
  574. jsr (a0)
  575. rts
  576. ******************************************
  577. **** XFLIP THE BLOCK *****
  578. ******************************************
  579. xflip_the_block
  580. bsr convert_mouse_and_store
  581. move.l page_pointer,a0
  582. move.l #main_screen_struct,a1
  583. move.w screen_x_size(a1),d2
  584. asr.w #3,d2
  585. move.w d2,d3
  586. move.w d0,-(sp)
  587. move.w d1,-(sp)
  588. add.w screen_y_pos(a0),d1 ; add on offset
  589. move.l screen_mem(a0),a0
  590. asr.w #3,d0
  591. add.l d0,a0
  592. move.w d3,d5 ;for later
  593. mulu screen_y_size(a1),d3 ;for later
  594. move.w number_of_planes(a1),d0
  595. mulu d1,d2 ; y offset on page
  596. add.l d2,a0 ; block position
  597. move.l a0,a4 ; store
  598. move.l #block_buffer,a1 ; dest
  599. move.l current_map_ptr,a2
  600. move.w map_block_size(a2),d2
  601. subq.w #1,d0 ; number of planes
  602. xflip_planes_loop
  603. move.w d2,d6 ; map block size
  604. subq.w #1,d6
  605. move.l a0,a2
  606. block_lines_loop
  607. cmp.w #8,d2
  608. bne.s not_8x8
  609. bsr xflip_8x8
  610. bra.s update_xflip_planes
  611. not_8x8
  612. cmp.w #16,d2
  613. bne.s not_16x16
  614. bsr xflip_16x16
  615. bra.s update_xflip_planes
  616. not_16x16
  617. bsr xflip_32x32
  618. update_xflip_planes
  619. add.l d5,a2 ;move down one page line
  620. dbra d6,block_lines_loop
  621. add.l d3,a0 ;plane size
  622. dbra d0,xflip_planes_loop
  623. move.l a4,a1
  624. move.l #block_buffer,a0
  625. move.l #main_screen_struct,a2
  626. move.w number_of_planes(a2),d7
  627. bsr copy_buffer_to_block
  628. move.l #main_screen_struct,a1
  629. move.l screen_mem(a1),a1
  630. move.w (sp)+,d0
  631. mulu d5,d0
  632. add.l d0,a1
  633. moveq #0,d0
  634. move.w (sp)+,d0
  635. asr.w #3,d0
  636. add.l d0,a1
  637. bsr copy_buffer_to_block
  638. rts
  639. xflip_8x8
  640. movem.l a2-a3/d0,-(sp)
  641. moveq #7,d7
  642. move.b (a2),d4
  643. xflip_8x8_loop
  644. ror.b d4
  645. roxl.b d0
  646. dbra d7,xflip_8x8_loop
  647. move.b d0,(a1)+
  648. movem.l (sp)+,a2-a3/d0
  649. rts
  650. xflip_16x16
  651. movem.l a2-a3/d0,-(sp)
  652. moveq #15,d7
  653. move.w (a2),d4
  654. xflip_16x16_loop
  655. roxr.w d4
  656. roxl.w d0
  657. dbra d7,xflip_16x16_loop
  658. move.w d0,(a1)+
  659. movem.l (sp)+,a2-a3/d0
  660. rts
  661. xflip_32x32
  662. movem.l a2-a3/d0,-(sp)
  663. moveq #31,d7
  664. move.l (a2),d4
  665. xflip_32x32_loop
  666. roxr.l d4
  667. roxl.l d0
  668. dbra d7,xflip_32x32_loop
  669. move.l d0,(a1)+
  670. movem.l (sp)+,a2-a3/d0
  671. rts
  672. ******************************************
  673. **** YFLIP THE BLOCK *****
  674. ******************************************
  675. yflip_the_block
  676. bsr convert_mouse_and_store
  677. move.l page_pointer,a0
  678. move.w screen_y_pos(a0),d2
  679. move.l screen_mem(a0),a0
  680. asr.w #3,d0
  681. add.l d0,a0
  682. move.l #main_screen_struct,a1
  683. move.w screen_x_size(a1),d3
  684. asr.w #3,d3
  685. move.w d1,d4
  686. add.w d2,d4
  687. mulu d3,d4
  688. add.l d4,a0 ;source
  689. move.l a0,a4 ;store
  690. move.l current_map_ptr,a2
  691. move.w map_block_size(a2),d4
  692. move.w number_of_planes(a1),d5
  693. subq.w #1,d5
  694. yflip_planes
  695. move.l a0,a5
  696. move.w d4,d7
  697. subq.w #1,d7
  698. mulu d3,d7 ;end of block
  699. add.l d7,a5 ; end of block
  700. move.w d4,d7
  701. asr.w d7
  702. subq.w #1,d7
  703. move.l a0,a3
  704. yflip_lines
  705. cmp.w #8,d4
  706. bne.s yflip_16
  707. move.b (a3),d6
  708. move.b (a5),(a3)
  709. move.b d6,(a5)
  710. bra.s update_block_line
  711. yflip_16
  712. cmp.w #32,d4
  713. beq.s yflip_32
  714. move.w (a3),d6
  715. move.w (a5),(a3)
  716. move.w d6,(a5)
  717. bra.s update_block_line
  718. yflip_32
  719. move.l (a3),d6
  720. move.l (a5),(a3)
  721. move.l d6,(a5)
  722. update_block_line
  723. add.l d3,a3
  724. sub.l d3,a5
  725. dbra d7,yflip_lines
  726. move.w d3,d7
  727. mulu screen_y_size(a1),d7
  728. add.l d7,a0
  729. dbra d5,yflip_planes
  730. move.w number_of_planes(a1),d7
  731. move.l screen_mem(a1),a1
  732. mulu d3,d1
  733. add.l d1,a1
  734. add.l d0,a1
  735. move.l a4,a0
  736. bsr copy_block_to_block
  737. rts
  738. ******************************************
  739. **** ROTATE THE BLOCK *****
  740. ******************************************
  741. rotate_the_block
  742. bsr convert_mouse_and_store
  743. move.l page_pointer,a0
  744. move.w screen_y_pos(a0),d2
  745. move.l screen_mem(a0),a0
  746. asr.w #3,d0
  747. add.l d0,a0
  748. move.l #main_screen_struct,a1
  749. moveq #0,d3
  750. move.w screen_x_size(a1),d3
  751. asr.w #3,d3
  752. move.w d1,d4
  753. move.w d1,-(sp)
  754. add.w d2,d4
  755. mulu d3,d4
  756. add.l d4,a0 ;source
  757. move.l a0,a5 ;store
  758. move.l current_map_ptr,a2
  759. move.w map_block_size(a2),d4
  760. move.w number_of_planes(a1),d5
  761. subq.w #1,d5
  762. move.l #block_buffer,a4 ;dest
  763. rotate_planes_loop
  764. move.w d4,d2
  765. subq.w #1,d2
  766. move.l a0,a2
  767. rotate_lines_loop
  768. move.l a4,a3
  769. move.w d4,d7
  770. subq.w #1,d7
  771. rotate_bits_loop
  772. cmp.w #8,d4
  773. bne.s check_rot16
  774. move.b (a2),d6
  775. roxl.b d6
  776. move.b d6,(a2)
  777. move.b (a3),d6
  778. roxr.b d6
  779. move.b d6,(a3)+
  780. bra.s update_rot_line
  781. check_rot16
  782. cmp.w #16,d4
  783. bne.s rotate_32
  784. move.w (a2),d6
  785. roxl.w d6
  786. move.w d6,(a2)
  787. move.w (a3),d6
  788. roxr.w d6
  789. move.w d6,(a3)+
  790. bra.s update_rot_line
  791. rotate_32
  792. move.l (a2),d6
  793. roxl.l d6
  794. move.l d6,(a2)
  795. move.l (a3),d6
  796. roxr.l d6
  797. move.l d6,(a3)+
  798. update_rot_line
  799. dbra d7,rotate_bits_loop
  800. add.l d3,a2 ; next line of block
  801. dbra d2,rotate_lines_loop
  802. move.w d3,d7
  803. mulu screen_y_size(a1),d7
  804. add.l d7,a0
  805. move.w d4,d7
  806. asr.w #3,d7
  807. mulu d4,d7
  808. add.l d7,a4
  809. dbra d5,rotate_planes_loop
  810. move.w number_of_planes(a1),d7
  811. move.l #block_buffer,a0
  812. move.l a5,a1
  813. bsr copy_buffer_to_block
  814. move.l #main_screen_struct,a1
  815. move.l screen_mem(a1),a1
  816. move.w (sp)+,d4
  817. mulu d3,d4
  818. add.l d4,a1
  819. add.l d0,a1
  820. bsr copy_buffer_to_block
  821. rts
  822. *****CODE TO COMBINE A BLOCK
  823. ******************************************
  824. **** GET COMBINE BLOCK POSITION *****
  825. ******************************************
  826. get_combine_block_position
  827. move.w mouse_x,store_x
  828. move.w mouse_y,store_y
  829. move.l page_pointer,a0
  830. move.w screen_y_pos(a0),store_off_y
  831. move.l page_pointer,store_page
  832. move.w #WITH,sprite_to_attach
  833. move.w #MODE_TO_COMBINE_BLOCK,block_mode
  834. rts
  835. ******************************************
  836. **** FIND COMBINE WITH POSITION *****
  837. ******************************************
  838. find_combine_with_position
  839. bsr convert_mouse_and_store
  840. move.l a6,-(sp)
  841. moveq #0,d4
  842. move.l page_pointer,a0
  843. move.w d1,-(sp) ; store for later use
  844. add.w screen_y_pos(a0),d1
  845. move.l screen_mem(a0),a1
  846. asr.w #3,d0
  847. move.l d0,-(sp)
  848. move.l #main_screen_struct,a2
  849. move.w number_of_planes(a2),d7
  850. move.w screen_x_size(a2),d4
  851. asr.w #3,d4
  852. mulu d4,d1 ;get position down screen
  853. add.l d1,a1
  854. add.l d0,a1 ; a1 contains dest address
  855. move.l store_page,a3
  856. move.w d3,d5
  857. add.w store_off_y,d3 ;add on old offset
  858. move.l screen_mem(a3),a0
  859. asr.w #3,d2
  860. mulu d4,d3
  861. add.l d3,a0
  862. add.l d2,a0 ;a0 contains start address
  863. move.w #31,d3
  864. move.l #block_buffer,a6
  865. clear_mask_out
  866. clr.l (a6)+
  867. dbra d3,clear_mask_out
  868. move.l current_map_ptr,a4
  869. move.w map_block_size(a4),d2
  870. move.l a0,a6
  871. move.w number_of_planes(a2),d6
  872. subq.w #1,d6
  873. make_mask_planes
  874. move.l #block_buffer,a3
  875. move.l a6,a4
  876. move.w d2,d3
  877. subq.w #1,d3
  878. make_mask
  879. cmp.w #8,d2
  880. bne.s try16gfd
  881. move.b (a3),d5
  882. or.b (a4),d5
  883. move.b d5,(a3)+
  884. bra.s fuck_this
  885. try16gfd
  886. cmp.w #16,d2
  887. bne.s try32fdfds
  888. move.w (a3),d5
  889. or.w (a4),d5
  890. move.w d5,(a3)+
  891. bra.s fuck_this
  892. try32fdfds
  893. move.l (a3),d5
  894. or.l (a4),d5
  895. move.l d5,(a3)+
  896. fuck_this
  897. add.l d4,a4 ;next line
  898. dbra d3,make_mask
  899. move.l d4,d5
  900. mulu screen_y_size(a2),d5
  901. add.l d5,a6
  902. dbra d6,make_mask_planes
  903. **********finish
  904. move.l a1,a5
  905. move.l current_map_ptr,a4
  906. move.w map_block_size(a4),d2
  907. subq.w #1,d7
  908. combine_planes_loop
  909. move.l a0,a3
  910. move.l a1,a4
  911. move.l #block_buffer,a6
  912. move.w d2,d3
  913. subq.w #1,d3
  914. combine_planes_lines_loop
  915. ****add so block buffer in referenced for block mask
  916. cmp.w #8,d2
  917. bne.s combine_16
  918. move.b (a4),d6
  919. move.b (a6)+,d5
  920. not.b d5
  921. and.b d5,d6
  922. or.b (a3),d6
  923. move.b d6,(a4)
  924. bra.s update_combine_line
  925. combine_16
  926. cmp.w #16,d2
  927. bne.s combine_32
  928. move.w (a4),d6
  929. move.w (a6)+,d5
  930. not.w d5
  931. and.w d5,d6
  932. or.w (a3),d6
  933. move.w d6,(a4)
  934. bra.s update_combine_line
  935. combine_32
  936. move.l (a4),d6
  937. move.l (a6)+,d5
  938. not.l d5
  939. and.l d5,d6
  940. or.l (a3),d6
  941. move.l d6,(a4)
  942. update_combine_line
  943. add.l d4,a4
  944. add.l d4,a3
  945. dbra d3,combine_planes_lines_loop
  946. move.l d4,d5
  947. mulu screen_y_size(a2),d5
  948. add.l d5,a0
  949. add.l d5,a1
  950. dbra d7,combine_planes_loop
  951. move.l screen_mem(a2),a1
  952. move.w number_of_planes(a2),d7
  953. move.l (sp)+,d2
  954. add.l d2,a1
  955. move.w (sp)+,d2
  956. mulu d4,d2
  957. add.l d2,a1
  958. move.l a5,a0
  959. bsr copy_block_to_block ; copy to screen position 2
  960. move.l (sp)+,A6
  961. *now put back to pick stage
  962. *user must click exit to get out
  963. move.w #PICK,sprite_to_attach
  964. move.w #MODE_COMBINE_BLOCK,block_mode
  965. rts
  966. current_block_op
  967. dc.w 0
  968. block_op_routines
  969. dc.l xflip_the_block
  970. dc.l yflip_the_block
  971. dc.l rotate_the_block
  972. dc.l enter_block_into_group
  973. dc.l edit_single_block
  974. XFLIP EQU 0
  975. YFLIP EQU 1
  976. ROTATE EQU 2
  977. PICK EQU 1
  978. WITH EQU 2
  979. TO EQU 3
  980. sprite_to_attach
  981. dc.w 0
  982. block_buffer
  983. ds.w 32*5*2
  984. block_buffer2
  985. ds.w 32*5*2
  986. blank_buffer
  987. ds.w 32*5*2
  988. ***************************************
  989. ***** SELECT BLOCK MODE ****
  990. ***************************************
  991. select_block_mode
  992. move.l #detect_generic_button,a0
  993. bsr display_button
  994. move.l clicked_button,a0
  995. moveq #0,d0
  996. move.b button_data(a0),d0
  997. move.w d0,block_mode
  998. sub.w #MODE_XFLIP_BLOCK,d0
  999. move.w d0,current_block_op
  1000. move.w #PICK,sprite_to_attach
  1001. move.w #1,generic_button_up
  1002. rts
  1003. generic_button_up
  1004. dc.w 0
  1005. ***************************************
  1006. ***** SELECT RELAVANT MODE ****
  1007. ***************************************
  1008. select_relavant_mode
  1009. move.l #block_mode_table,a0
  1010. moveq #0,d0
  1011. move.w block_mode,d0
  1012. move.l (a0,d0),a0
  1013. jsr (a0) ;call function
  1014. rts
  1015. block_mode
  1016. dc.w 0
  1017. MODE_COPY_BLOCK EQU 0
  1018. MODE_EXCHANGE_BLOCK EQU 4
  1019. MODE_MOVE_BLOCK EQU 8
  1020. MODE_COMBINE_BLOCK EQU 12
  1021. MODE_TO_COPY_BLOCK EQU 16
  1022. MODE_TO_EXCHANGE_BLOCK EQU 20
  1023. MODE_TO_MOVE_BLOCK EQU 24
  1024. MODE_TO_COMBINE_BLOCK EQU 28
  1025. MODE_XFLIP_BLOCK EQU 32
  1026. MODE_YFLIP_BLOCK EQU 36
  1027. MODE_ROTATE_BLOCK EQU 40
  1028. MODE_EDIT_BLOCK EQU 44
  1029. MODE_EDIT_SINGLE_BLOCK EQU 48
  1030. block_mode_table
  1031. dc.l get_copy_block_position
  1032. dc.l get_exchange_block_position
  1033. dc.l get_block_position
  1034. dc.l get_combine_block_position
  1035. dc.l find_copy_to_position
  1036. dc.l find_exchange_to_position
  1037. dc.l find_move_to_position
  1038. dc.l find_combine_with_position
  1039. dc.l get_block_ops_position
  1040. dc.l get_block_ops_position
  1041. dc.l get_block_ops_position
  1042. dc.l get_block_ops_position
  1043. dc.l get_block_ops_position