graphic_routines.s 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  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-d3/d7,-(sp)
  241. move.l current_map_ptr,a2
  242. move.l #main_screen_struct,a3
  243. subq.w #1,d7
  244. move.w map_block_size(a2),d0
  245. copy_planes
  246. move.l a0,a4
  247. move.l a1,a5
  248. move.w d0,d1
  249. move.w d0,d3
  250. subq.w #1,d3
  251. copy_to_new_position
  252. cmp.w #8,d1
  253. bne.s copy16
  254. move.b (a4),(a5)
  255. bra.s update_line
  256. copy16
  257. cmp.w #16,d1
  258. bne.s must_be_32
  259. move.w (a4),(a5)
  260. bra.s update_line
  261. must_be_32
  262. move.l (a4),(a5)
  263. update_line
  264. moveq #0,d2
  265. move.w screen_x_size(a3),d2
  266. asr.w #3,d2
  267. add.l d2,a4
  268. add.l d2,a5
  269. dbra d3,copy_to_new_position
  270. move.w screen_x_size(a3),d2
  271. asr.w #3,d2
  272. mulu screen_y_size(a3),d2
  273. add.l d2,a1
  274. add.l d2,a0
  275. dbra d7,copy_planes
  276. movem.l (sp)+,a0-a5/d0-d3/d7
  277. rts
  278. ******************************************
  279. **** COPY BLOCK TO BUFFER *****
  280. ******************************************
  281. copy_block_to_buffer
  282. *send a0 and a1 as start and dest
  283. *send number of planes in d7
  284. *a1 contains buffer addr
  285. movem.l a0-a5/d0-d3/d7,-(sp)
  286. move.l current_map_ptr,a2
  287. move.l #main_screen_struct,a3
  288. subq.w #1,d7
  289. move.w map_block_size(a2),d0
  290. buffcopy_planes
  291. move.l a0,a4
  292. move.w d0,d1
  293. move.w d0,d3
  294. subq.w #1,d3
  295. buffcopy_to_new_position
  296. cmp.w #8,d1
  297. bne.s buffcopy16
  298. move.b (a4),(a1)+
  299. bra.s buffupdate_line
  300. buffcopy16
  301. cmp.w #16,d1
  302. bne.s buffmust_be_32
  303. move.w (a4),(a1)+
  304. bra.s buffupdate_line
  305. buffmust_be_32
  306. move.l (a4),(a1)+
  307. buffupdate_line
  308. moveq #0,d2
  309. move.w screen_x_size(a3),d2
  310. asr.w #3,d2
  311. add.l d2,a4
  312. dbra d3,buffcopy_to_new_position
  313. move.w screen_x_size(a3),d2
  314. asr.w #3,d2
  315. mulu screen_y_size(a3),d2
  316. add.l d2,a0
  317. dbra d7,buffcopy_planes
  318. movem.l (sp)+,a0-a5/d0-d3/d7
  319. rts
  320. ******************************************
  321. **** COPY BUFFER TO BLOCK *****
  322. ******************************************
  323. copy_buffer_to_block
  324. *send a0 and a1 as start and dest
  325. *send number of planes in d7
  326. *a0 contains buffer addr
  327. movem.l a0-a5/d0-d3/d7,-(sp)
  328. move.l current_map_ptr,a2
  329. move.l #main_screen_struct,a3
  330. subq.w #1,d7
  331. move.w map_block_size(a2),d0
  332. bloccopy_planes
  333. move.l a1,a4
  334. move.w d0,d1
  335. move.w d0,d3
  336. subq.w #1,d3
  337. bloccopy_to_new_position
  338. cmp.w #8,d1
  339. bne.s bloccopy16
  340. move.b (a0)+,(a4)
  341. bra.s blocupdate_line
  342. bloccopy16
  343. cmp.w #16,d1
  344. bne.s blocmust_be_32
  345. move.w (a0)+,(a4)
  346. bra.s blocupdate_line
  347. blocmust_be_32
  348. move.l (a0)+,(a4)
  349. blocupdate_line
  350. moveq #0,d2
  351. move.w screen_x_size(a3),d2
  352. asr.w #3,d2
  353. add.l d2,a4
  354. dbra d3,bloccopy_to_new_position
  355. move.w screen_x_size(a3),d2
  356. asr.w #3,d2
  357. mulu screen_y_size(a3),d2
  358. add.l d2,a1
  359. dbra d7,bloccopy_planes
  360. movem.l (sp)+,a0-a5/d0-d3/d7
  361. rts
  362. *****CODE TO MOVE A BLOCK
  363. ******************************************
  364. **** GET BLOCK POSITION *****
  365. ******************************************
  366. get_block_position
  367. move.w mouse_x,store_x
  368. move.w mouse_y,store_y
  369. move.l page_pointer,a0
  370. move.w screen_y_pos(a0),store_off_y
  371. move.l page_pointer,store_page
  372. move.w #TO,sprite_to_attach
  373. move.w #MODE_TO_MOVE_BLOCK,block_mode
  374. rts
  375. *******************PLEASE NOTE
  376. *when a picture is loaded it is always loaded into five planes
  377. *of memory this way when copying blocks around there is no
  378. *problem if a block is copied from a five plane picture
  379. *to a one plane picture
  380. *it is up to the user
  381. ******************************************
  382. **** FIND MOVE TO POSITION *****
  383. ******************************************
  384. find_move_to_position
  385. bsr convert_mouse_and_store
  386. move.l page_pointer,a0
  387. move.w d1,d6 ; store for later use
  388. add.w screen_y_pos(a0),d1
  389. move.l screen_mem(a0),a1
  390. asr.w #3,d0
  391. move.l #main_screen_struct,a2
  392. move.w screen_x_size(a2),d4
  393. asr.w #3,d4
  394. mulu d4,d1 ;get position down screen
  395. add.l d1,a1
  396. add.l d0,a1 ; a1 contains dest address
  397. move.l a1,a5
  398. move.l store_page,a3
  399. move.w number_of_planes(a2),d7
  400. move.w d3,d5
  401. add.w store_off_y,d3
  402. move.l screen_mem(a3),a0
  403. asr.w #3,d2
  404. mulu d4,d3
  405. add.l d3,a0
  406. add.l d2,a0 ;a0 contains start address
  407. move.l #block_buffer,a1
  408. bsr copy_block_to_buffer ;in buffer
  409. move.l a0,a1
  410. move.l #blank_buffer,a0
  411. bsr copy_buffer_to_block ; clear out source
  412. move.l #block_buffer,a0
  413. move.l a5,a1
  414. bsr copy_buffer_to_block ; copy to dest
  415. ***blank out position on screen
  416. move.l screen_mem(a2),a1
  417. mulu d4,d5
  418. add.l d5,a1
  419. add.l d2,a1
  420. move.l #blank_buffer,a0
  421. bsr copy_buffer_to_block
  422. move.l #block_buffer,a0
  423. move.l screen_mem(a2),a1
  424. add.l d0,a1
  425. mulu d4,d6
  426. add.l d6,a1
  427. bsr copy_buffer_to_block; copy to screen
  428. *now put back to pick stage
  429. quit_move_block
  430. move.w #PICK,sprite_to_attach
  431. move.w #MODE_MOVE_BLOCK,block_mode
  432. rts
  433. ******************************************
  434. **** GET COPY BLOCK POSITION *****
  435. ******************************************
  436. get_copy_block_position
  437. move.w mouse_x,store_x
  438. move.w mouse_y,store_y
  439. move.l page_pointer,a0
  440. move.w screen_y_pos(a0),store_off_y
  441. move.l page_pointer,store_page
  442. move.w #TO,sprite_to_attach
  443. move.w #MODE_TO_COPY_BLOCK,block_mode
  444. rts
  445. ******************************************
  446. **** FIND COPY TO POSITION *****
  447. ******************************************
  448. find_copy_to_position
  449. bsr convert_mouse_and_store
  450. move.l page_pointer,a0
  451. move.w d1,d6 ; store for later use
  452. add.w screen_y_pos(a0),d1
  453. move.l screen_mem(a0),a1
  454. asr.w #3,d0
  455. move.l #main_screen_struct,a2
  456. move.w screen_x_size(a2),d4
  457. asr.w #3,d4
  458. mulu d4,d1 ;get position down screen
  459. add.l d1,a1
  460. add.l d0,a1 ; a1 contains dest address
  461. move.l store_page,a3
  462. move.w number_of_planes(a2),d7
  463. add.w store_off_y,d3 ;add on old offset
  464. move.l screen_mem(a3),a0
  465. asr.w #3,d2
  466. mulu d4,d3
  467. add.l d3,a0
  468. add.l d2,a0 ;a0 contains start address
  469. bsr copy_block_to_block ; copy into page
  470. move.l screen_mem(a2),a1
  471. add.l d0,a1
  472. mulu d4,d6
  473. add.l d6,a1
  474. bsr copy_block_to_block; copy to screen
  475. *now put back to pick stage
  476. quit_copy_block
  477. move.w #PICK,sprite_to_attach
  478. move.w #MODE_COPY_BLOCK,block_mode
  479. rts
  480. *****CODE TO EXCHANGE A BLOCK
  481. ******************************************
  482. **** GET EXCHANGE BLOCK POSITION *****
  483. ******************************************
  484. get_exchange_block_position
  485. move.w mouse_x,store_x
  486. move.w mouse_y,store_y
  487. move.l page_pointer,a0
  488. move.w screen_y_pos(a0),store_off_y
  489. move.l page_pointer,store_page
  490. move.w #TO,sprite_to_attach
  491. move.w #MODE_TO_EXCHANGE_BLOCK,block_mode
  492. rts
  493. ******************************************
  494. **** FIND EXCHANGE TO POSITION *****
  495. ******************************************
  496. find_exchange_to_position
  497. bsr convert_mouse_and_store
  498. move.l page_pointer,a0
  499. move.w d1,d6 ; store for later use
  500. add.w screen_y_pos(a0),d1
  501. move.l screen_mem(a0),a1
  502. asr.w #3,d0
  503. move.l #main_screen_struct,a2
  504. move.w number_of_planes(a2),d7
  505. move.w screen_x_size(a2),d4
  506. asr.w #3,d4
  507. mulu d4,d1 ;get position down screen
  508. add.l d1,a1
  509. add.l d0,a1 ; a1 contains dest address
  510. move.l a1,a0
  511. move.l #block_buffer,a1
  512. bsr copy_block_to_buffer
  513. move.l a0,a4 ;store dest address
  514. move.l store_page,a3
  515. move.w d3,d5
  516. add.w store_off_y,d3 ;add on old offset
  517. move.l screen_mem(a3),a0
  518. asr.w #3,d2
  519. mulu d4,d3
  520. add.l d3,a0
  521. add.l d2,a0 ;a0 contains start address
  522. move.l #block_buffer2,a1
  523. bsr copy_block_to_buffer
  524. move.l a4,a1 ;dest address
  525. move.l a0,a4 ;store start address
  526. move.l #block_buffer2,a0
  527. bsr copy_buffer_to_block
  528. move.l a4,a1
  529. move.l #block_buffer,a0
  530. bsr copy_buffer_to_block
  531. move.l #block_buffer2,a0
  532. move.l screen_mem(a2),a1
  533. add.l d0,a1
  534. mulu d4,d6
  535. add.l d6,a1
  536. bsr copy_buffer_to_block ; copy to screen position 1
  537. move.l screen_mem(a2),a1
  538. add.l d2,a1
  539. mulu d4,d5
  540. add.l d5,a1
  541. move.l #block_buffer,a0
  542. bsr copy_buffer_to_block ; copy to screen position 2
  543. *now put back to pick stage
  544. move.w #PICK,sprite_to_attach
  545. move.w #MODE_EXCHANGE_BLOCK,block_mode
  546. rts
  547. **** xflip,yflip and rotate funcs
  548. ******************************************
  549. **** GET BLOCK OPS POSITION *****
  550. ******************************************
  551. get_block_ops_position
  552. move.l #block_op_routines,a0
  553. moveq #0,d0
  554. move.w current_block_op,d0
  555. add.l d0,a0
  556. move.l (a0),a0
  557. jsr (a0)
  558. rts
  559. ******************************************
  560. **** XFLIP THE BLOCK *****
  561. ******************************************
  562. xflip_the_block
  563. bsr convert_mouse_and_store
  564. move.l page_pointer,a0
  565. move.l #main_screen_struct,a1
  566. move.w screen_x_size(a1),d2
  567. asr.w #3,d2
  568. move.w d2,d3
  569. move.w d0,-(sp)
  570. move.w d1,-(sp)
  571. add.w screen_y_pos(a0),d1 ; add on offset
  572. move.l screen_mem(a0),a0
  573. asr.w #3,d0
  574. add.l d0,a0
  575. move.w d3,d5 ;for later
  576. mulu screen_y_size(a1),d3 ;for later
  577. move.w number_of_planes(a1),d0
  578. mulu d1,d2 ; y offset on page
  579. add.l d2,a0 ; block position
  580. move.l a0,a4 ; store
  581. move.l #block_buffer,a1 ; dest
  582. move.l current_map_ptr,a2
  583. move.w map_block_size(a2),d2
  584. subq.w #1,d0 ; number of planes
  585. xflip_planes_loop
  586. move.w d2,d6 ; map block size
  587. subq.w #1,d6
  588. move.l a0,a2
  589. block_lines_loop
  590. cmp.w #8,d2
  591. bne.s not_8x8
  592. bsr xflip_8x8
  593. bra.s update_xflip_planes
  594. not_8x8
  595. cmp.w #16,d2
  596. bne.s not_16x16
  597. bsr xflip_16x16
  598. bra.s update_xflip_planes
  599. not_16x16
  600. bsr xflip_32x32
  601. update_xflip_planes
  602. add.l d5,a2 ;move down one page line
  603. dbra d6,block_lines_loop
  604. add.l d3,a0 ;plane size
  605. dbra d0,xflip_planes_loop
  606. move.l a4,a1
  607. move.l #block_buffer,a0
  608. move.l #main_screen_struct,a2
  609. move.w number_of_planes(a2),d7
  610. bsr copy_buffer_to_block
  611. move.l #main_screen_struct,a1
  612. move.l screen_mem(a1),a1
  613. move.w (sp)+,d0
  614. mulu d5,d0
  615. add.l d0,a1
  616. moveq #0,d0
  617. move.w (sp)+,d0
  618. asr.w #3,d0
  619. add.l d0,a1
  620. bsr copy_buffer_to_block
  621. rts
  622. xflip_8x8
  623. movem.l a2-a3/d0,-(sp)
  624. moveq #7,d7
  625. move.b (a2),d4
  626. xflip_8x8_loop
  627. ror.b d4
  628. roxl.b d0
  629. dbra d7,xflip_8x8_loop
  630. move.b d0,(a1)+
  631. movem.l (sp)+,a2-a3/d0
  632. rts
  633. xflip_16x16
  634. movem.l a2-a3/d0,-(sp)
  635. moveq #15,d7
  636. move.w (a2),d4
  637. xflip_16x16_loop
  638. roxr.w d4
  639. roxl.w d0
  640. dbra d7,xflip_16x16_loop
  641. move.w d0,(a1)+
  642. movem.l (sp)+,a2-a3/d0
  643. rts
  644. xflip_32x32
  645. movem.l a2-a3/d0,-(sp)
  646. moveq #31,d7
  647. move.l (a2),d4
  648. xflip_32x32_loop
  649. roxr.l d4
  650. roxl.l d0
  651. dbra d7,xflip_32x32_loop
  652. move.l d0,(a1)+
  653. movem.l (sp)+,a2-a3/d0
  654. rts
  655. ******************************************
  656. **** YFLIP THE BLOCK *****
  657. ******************************************
  658. yflip_the_block
  659. bsr convert_mouse_and_store
  660. move.l page_pointer,a0
  661. move.w screen_y_pos(a0),d2
  662. move.l screen_mem(a0),a0
  663. asr.w #3,d0
  664. add.l d0,a0
  665. move.l #main_screen_struct,a1
  666. move.w screen_x_size(a1),d3
  667. asr.w #3,d3
  668. move.w d1,d4
  669. add.w d2,d4
  670. mulu d3,d4
  671. add.l d4,a0 ;source
  672. move.l a0,a4 ;store
  673. move.l current_map_ptr,a2
  674. move.w map_block_size(a2),d4
  675. move.w number_of_planes(a1),d5
  676. subq.w #1,d5
  677. yflip_planes
  678. move.l a0,a5
  679. move.w d4,d7
  680. subq.w #1,d7
  681. mulu d3,d7 ;end of block
  682. add.l d7,a5 ; end of block
  683. move.w d4,d7
  684. asr.w d7
  685. subq.w #1,d7
  686. move.l a0,a3
  687. yflip_lines
  688. cmp.w #8,d4
  689. bne.s yflip_16
  690. move.b (a3),d6
  691. move.b (a5),(a3)
  692. move.b d6,(a5)
  693. bra.s update_block_line
  694. yflip_16
  695. cmp.w #32,d4
  696. beq.s yflip_32
  697. move.w (a3),d6
  698. move.w (a5),(a3)
  699. move.w d6,(a5)
  700. bra.s update_block_line
  701. yflip_32
  702. move.l (a3),d6
  703. move.l (a5),(a3)
  704. move.l d6,(a5)
  705. update_block_line
  706. add.l d3,a3
  707. sub.l d3,a5
  708. dbra d7,yflip_lines
  709. move.w d3,d7
  710. mulu screen_y_size(a1),d7
  711. add.l d7,a0
  712. dbra d5,yflip_planes
  713. move.w number_of_planes(a1),d7
  714. move.l screen_mem(a1),a1
  715. mulu d3,d1
  716. add.l d1,a1
  717. add.l d0,a1
  718. move.l a4,a0
  719. bsr copy_block_to_block
  720. rts
  721. ******************************************
  722. **** ROTATE THE BLOCK *****
  723. ******************************************
  724. rotate_the_block
  725. bsr convert_mouse_and_store
  726. move.l page_pointer,a0
  727. move.w screen_y_pos(a0),d2
  728. move.l screen_mem(a0),a0
  729. asr.w #3,d0
  730. add.l d0,a0
  731. move.l #main_screen_struct,a1
  732. moveq #0,d3
  733. move.w screen_x_size(a1),d3
  734. asr.w #3,d3
  735. move.w d1,d4
  736. move.w d1,-(sp)
  737. add.w d2,d4
  738. mulu d3,d4
  739. add.l d4,a0 ;source
  740. move.l a0,a5 ;store
  741. move.l current_map_ptr,a2
  742. move.w map_block_size(a2),d4
  743. move.w number_of_planes(a1),d5
  744. subq.w #1,d5
  745. move.l #block_buffer,a4 ;dest
  746. rotate_planes_loop
  747. move.w d4,d2
  748. subq.w #1,d2
  749. move.l a0,a2
  750. rotate_lines_loop
  751. move.l a4,a3
  752. move.w d4,d7
  753. subq.w #1,d7
  754. rotate_bits_loop
  755. cmp.w #8,d4
  756. bne.s check_rot16
  757. move.b (a2),d6
  758. roxl.b d6
  759. move.b d6,(a2)
  760. move.b (a3),d6
  761. roxr.b d6
  762. move.b d6,(a3)+
  763. bra.s update_rot_line
  764. check_rot16
  765. cmp.w #16,d4
  766. bne.s rotate_32
  767. move.w (a2),d6
  768. roxl.w d6
  769. move.w d6,(a2)
  770. move.w (a3),d6
  771. roxr.w d6
  772. move.w d6,(a3)+
  773. bra.s update_rot_line
  774. rotate_32
  775. move.l (a2),d6
  776. roxl.l d6
  777. move.l d6,(a2)
  778. move.l (a3),d6
  779. roxr.l d6
  780. move.l d6,(a3)+
  781. update_rot_line
  782. dbra d7,rotate_bits_loop
  783. add.l d3,a2 ; next line of block
  784. dbra d2,rotate_lines_loop
  785. move.w d3,d7
  786. mulu screen_y_size(a1),d7
  787. add.l d7,a0
  788. move.w d4,d7
  789. asr.w #3,d7
  790. mulu d4,d7
  791. add.l d7,a4
  792. dbra d5,rotate_planes_loop
  793. move.w number_of_planes(a1),d7
  794. move.l #block_buffer,a0
  795. move.l a5,a1
  796. bsr copy_buffer_to_block
  797. move.l #main_screen_struct,a1
  798. move.l screen_mem(a1),a1
  799. move.w (sp)+,d4
  800. mulu d3,d4
  801. add.l d4,a1
  802. add.l d0,a1
  803. bsr copy_buffer_to_block
  804. rts
  805. *****CODE TO COMBINE A BLOCK
  806. ******************************************
  807. **** GET COMBINE BLOCK POSITION *****
  808. ******************************************
  809. get_combine_block_position
  810. move.w mouse_x,store_x
  811. move.w mouse_y,store_y
  812. move.l page_pointer,a0
  813. move.w screen_y_pos(a0),store_off_y
  814. move.l page_pointer,store_page
  815. move.w #WITH,sprite_to_attach
  816. move.w #MODE_TO_COMBINE_BLOCK,block_mode
  817. rts
  818. ******************************************
  819. **** FIND COMBINE WITH POSITION *****
  820. ******************************************
  821. find_combine_with_position
  822. bsr convert_mouse_and_store
  823. move.l a6,-(sp)
  824. moveq #0,d4
  825. move.l page_pointer,a0
  826. move.w d1,-(sp) ; store for later use
  827. add.w screen_y_pos(a0),d1
  828. move.l screen_mem(a0),a1
  829. asr.w #3,d0
  830. move.l d0,-(sp)
  831. move.l #main_screen_struct,a2
  832. move.w number_of_planes(a2),d7
  833. move.w screen_x_size(a2),d4
  834. asr.w #3,d4
  835. mulu d4,d1 ;get position down screen
  836. add.l d1,a1
  837. add.l d0,a1 ; a1 contains dest address
  838. move.l store_page,a3
  839. move.w d3,d5
  840. add.w store_off_y,d3 ;add on old offset
  841. move.l screen_mem(a3),a0
  842. asr.w #3,d2
  843. mulu d4,d3
  844. add.l d3,a0
  845. add.l d2,a0 ;a0 contains start address
  846. move.w #31,d3
  847. move.l #block_buffer,a6
  848. clear_mask_out
  849. clr.l (a6)+
  850. dbra d3,clear_mask_out
  851. move.l current_map_ptr,a4
  852. move.w map_block_size(a4),d2
  853. move.l a0,a6
  854. move.w number_of_planes(a2),d6
  855. subq.w #1,d6
  856. make_mask_planes
  857. move.l #block_buffer,a3
  858. move.l a6,a4
  859. move.w d2,d3
  860. subq.w #1,d3
  861. make_mask
  862. cmp.w #8,d2
  863. bne.s try16gfd
  864. move.b (a3),d5
  865. or.b (a4),d5
  866. move.b d5,(a3)+
  867. bra.s fuck_this
  868. try16gfd
  869. cmp.w #16,d2
  870. bne.s try32fdfds
  871. move.w (a3),d5
  872. or.w (a4),d5
  873. move.w d5,(a3)+
  874. bra.s fuck_this
  875. try32fdfds
  876. move.l (a3),d5
  877. or.l (a4),d5
  878. move.l d5,(a3)+
  879. fuck_this
  880. add.l d4,a4 ;next line
  881. dbra d3,make_mask
  882. move.l d4,d5
  883. mulu screen_y_size(a2),d5
  884. add.l d5,a6
  885. dbra d6,make_mask_planes
  886. **********finish
  887. move.l a1,a5
  888. move.l current_map_ptr,a4
  889. move.w map_block_size(a4),d2
  890. subq.w #1,d7
  891. combine_planes_loop
  892. move.l a0,a3
  893. move.l a1,a4
  894. move.l #block_buffer,a6
  895. move.w d2,d3
  896. subq.w #1,d3
  897. combine_planes_lines_loop
  898. ****add so block buffer in referenced for block mask
  899. cmp.w #8,d2
  900. bne.s combine_16
  901. move.b (a4),d6
  902. move.b (a6)+,d5
  903. not.b d5
  904. and.b d5,d6
  905. or.b (a3),d6
  906. move.b d6,(a4)
  907. bra.s update_combine_line
  908. combine_16
  909. cmp.w #16,d2
  910. bne.s combine_32
  911. move.w (a4),d6
  912. move.w (a6)+,d5
  913. not.w d5
  914. and.w d5,d6
  915. or.w (a3),d6
  916. move.w d6,(a4)
  917. bra.s update_combine_line
  918. combine_32
  919. move.l (a4),d6
  920. move.l (a6)+,d5
  921. not.l d5
  922. and.l d5,d6
  923. or.l (a3),d6
  924. move.l d6,(a4)
  925. update_combine_line
  926. add.l d4,a4
  927. add.l d4,a3
  928. dbra d3,combine_planes_lines_loop
  929. move.l d4,d5
  930. mulu screen_y_size(a2),d5
  931. add.l d5,a0
  932. add.l d5,a1
  933. dbra d7,combine_planes_loop
  934. move.l screen_mem(a2),a1
  935. move.w number_of_planes(a2),d7
  936. move.l (sp)+,d2
  937. add.l d2,a1
  938. move.w (sp)+,d2
  939. mulu d4,d2
  940. add.l d2,a1
  941. move.l a5,a0
  942. bsr copy_block_to_block ; copy to screen position 2
  943. move.l (sp)+,A6
  944. *now put back to pick stage
  945. *user must click exit to get out
  946. move.w #PICK,sprite_to_attach
  947. move.w #MODE_COMBINE_BLOCK,block_mode
  948. rts
  949. current_block_op
  950. dc.w 0
  951. block_op_routines
  952. dc.l xflip_the_block
  953. dc.l yflip_the_block
  954. dc.l rotate_the_block
  955. dc.l enter_block_into_group
  956. dc.l edit_single_block
  957. XFLIP EQU 0
  958. YFLIP EQU 1
  959. ROTATE EQU 2
  960. PICK EQU 1
  961. WITH EQU 2
  962. TO EQU 3
  963. sprite_to_attach
  964. dc.w 0
  965. block_buffer
  966. ds.w 32*5*2
  967. block_buffer2
  968. ds.w 32*5*2
  969. blank_buffer
  970. ds.w 32*5*2
  971. ***************************************
  972. ***** SELECT BLOCK MODE ****
  973. ***************************************
  974. select_block_mode
  975. move.l #detect_generic_button,a0
  976. bsr display_button
  977. move.l clicked_button,a0
  978. moveq #0,d0
  979. move.b button_data(a0),d0
  980. move.w d0,block_mode
  981. sub.w #MODE_XFLIP_BLOCK,d0
  982. move.w d0,current_block_op
  983. move.w #PICK,sprite_to_attach
  984. move.w #1,generic_button_up
  985. rts
  986. generic_button_up
  987. dc.w 0
  988. ***************************************
  989. ***** SELECT RELAVANT MODE ****
  990. ***************************************
  991. select_relavant_mode
  992. move.l #block_mode_table,a0
  993. moveq #0,d0
  994. move.w block_mode,d0
  995. move.l (a0,d0),a0
  996. jsr (a0) ;call function
  997. rts
  998. block_mode
  999. dc.w 0
  1000. MODE_COPY_BLOCK EQU 0
  1001. MODE_EXCHANGE_BLOCK EQU 4
  1002. MODE_MOVE_BLOCK EQU 8
  1003. MODE_COMBINE_BLOCK EQU 12
  1004. MODE_TO_COPY_BLOCK EQU 16
  1005. MODE_TO_EXCHANGE_BLOCK EQU 20
  1006. MODE_TO_MOVE_BLOCK EQU 24
  1007. MODE_TO_COMBINE_BLOCK EQU 28
  1008. MODE_XFLIP_BLOCK EQU 32
  1009. MODE_YFLIP_BLOCK EQU 36
  1010. MODE_ROTATE_BLOCK EQU 40
  1011. MODE_EDIT_BLOCK EQU 44
  1012. MODE_EDIT_SINGLE_BLOCK EQU 48
  1013. block_mode_table
  1014. dc.l get_copy_block_position
  1015. dc.l get_exchange_block_position
  1016. dc.l get_block_position
  1017. dc.l get_combine_block_position
  1018. dc.l find_copy_to_position
  1019. dc.l find_exchange_to_position
  1020. dc.l find_move_to_position
  1021. dc.l find_combine_with_position
  1022. dc.l get_block_ops_position
  1023. dc.l get_block_ops_position
  1024. dc.l get_block_ops_position
  1025. dc.l get_block_ops_position
  1026. dc.l get_block_ops_position