buffer_routines.s 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. ***********************************
  2. **** DISPLAY CURRENT BUFF NAME ****
  3. ***********************************
  4. Display_Current_Buff_Name
  5. moveq.w #1,d3
  6. bsr Draw_Current_Buff_Name
  7. rts
  8. ***********************************
  9. **** REMOVE CURRENT BUFF NAME ****
  10. ***********************************
  11. Remove_Current_Buff_Name
  12. moveq #0,d3
  13. bsr Draw_Current_Buff_Name
  14. rts
  15. ***********************************
  16. **** DRAW CURRENT BUFF NAME ****
  17. ***********************************
  18. Draw_Current_Buff_Name
  19. move.w current_buffer,d0
  20. mulu #buffstructsize,d0
  21. move.l #buffers,a1
  22. add.l d0,a1
  23. add.l #buffername,a1
  24. move.l #button_window_struct,a0
  25. move.w #440+9,d0
  26. move.w #FOURTH_ROW-4,d1
  27. move.w #4,d2
  28. bsr write_button_text
  29. rts
  30. *******************************************
  31. ***** GET BUFFER BOX ****
  32. *******************************************
  33. get_buffer_box
  34. WD btst.b #6,$bfe001
  35. bne.s WD ; press down mouse button (start drag)
  36. bsr convert_mouse_and_store
  37. bsr truncate_values
  38. move.w d0,Image_Start_X
  39. move.w d1,Image_Start_y
  40. drag_box_loop
  41. bsr convert_mouse_and_store
  42. move.l current_map_ptr,a0
  43. bsr truncate_values
  44. move.l #main_screen_struct,a0
  45. move.w d0,Box_X
  46. move.w d1,Box_Y
  47. DrawBoxIn
  48. move.w Image_Start_X,d0
  49. move.w Image_Start_Y,d1
  50. move.w Box_X,d2
  51. move.w Image_Start_Y,d3
  52. bsr EOR_draw_line
  53. move.w Box_X,d0
  54. move.w Image_Start_Y,d1
  55. move.w Box_X,d2
  56. move.w Box_Y,d3
  57. bsr EOR_draw_line
  58. move.w Box_X,d0
  59. move.w Box_Y,d1
  60. move.w Image_Start_X,d2
  61. move.w Box_Y,d3
  62. bsr EOR_draw_line
  63. move.w Image_Start_X,d0
  64. move.w Box_Y,d1
  65. move.w Image_Start_X,d2
  66. move.w Image_Start_Y,d3
  67. bsr EOR_draw_line
  68. Boxsync
  69. move.w $dff006,d0
  70. andi.w #$ff00,d0
  71. bne.s Boxsync Test for zero (box can't draw past)
  72. Delete_Box
  73. move.w Image_Start_X,d0
  74. move.w Image_Start_Y,d1
  75. move.w Box_X,d2
  76. move.w Image_Start_Y,d3
  77. bsr EOR_draw_line
  78. move.w Box_X,d0
  79. move.w Image_Start_Y,d1
  80. move.w Box_X,d2
  81. move.w Box_Y,d3
  82. bsr EOR_draw_line
  83. move.w Box_X,d0
  84. move.w Box_Y,d1
  85. move.w Image_Start_X,d2
  86. move.w Box_Y,d3
  87. bsr EOR_draw_line
  88. move.w Image_Start_X,d0
  89. move.w Box_Y,d1
  90. move.w Image_Start_X,d2
  91. move.w Image_Start_Y,d3
  92. bsr EOR_draw_line
  93. btst.b #6,$bfe001
  94. beq drag_box_loop ; release mouse button (end drag)
  95. move.w Box_X,Image_End_X
  96. move.w Box_Y,Image_End_Y
  97. move.w Image_End_X,d0 ;
  98. cmp.w Image_Start_X,d0
  99. bge.s Box_Drawn_Ok_X
  100. move.w Image_Start_X,Image_End_X
  101. move.w d0,Image_Start_X
  102. Box_Drawn_Ok_X
  103. move.w Image_End_Y,d0 ;
  104. cmp.w Image_Start_Y,d0
  105. bge.s Box_Drawn_Ok_Y
  106. move.w Image_Start_Y,Image_End_Y
  107. move.w d0,Image_Start_Y
  108. Box_Drawn_Ok_Y
  109. moveq #0,d7
  110. cmp.w #MODE_CUT,buffer_mode
  111. bne.s mode_copy_buff
  112. moveq #1,d7
  113. mode_copy_buff
  114. move.w d7,-(sp)
  115. bsr copy_buffer_to_hold
  116. move.w (sp)+,d7
  117. beq.s no_cut
  118. bsr display_undo
  119. bsr make_screen_backup
  120. no_cut
  121. rts
  122. Box_X dc.w 0
  123. Box_Y dc.w 0
  124. Image_Start_Y dc.w 0
  125. Image_End_Y dc.w 0
  126. Image_Start_X dc.w 0
  127. Image_End_X dc.w 0
  128. *******************************************
  129. ***** TRUNCATE VALUES ****
  130. *******************************************
  131. truncate_values
  132. *send in d0 and d1
  133. move.l current_map_ptr,a0
  134. move.w map_xsize(a0),d2
  135. add.w map_x_position,d2
  136. mulu map_block_size(a0),d2
  137. move.w map_ysize(a0),d3
  138. add.w map_y_position,d3
  139. mulu map_block_size(a0),d3
  140. cmp.w d2,d0
  141. ble.s no_trunc_x
  142. move.w d2,d0
  143. no_trunc_x
  144. cmp.w d3,d1
  145. ble.s no_trunc_y
  146. move.w d3,d1
  147. no_trunc_y
  148. rts
  149. *******************************************
  150. ***** CUT BLOCK ****
  151. *******************************************
  152. cut_block
  153. move.w #COPYCUT_BLOCK_MODE,map_function_mode
  154. move.w #PICK,sprite_to_attach
  155. move.w #MODE_CUT,buffer_mode
  156. rts
  157. *******************************************
  158. ***** COPY BLOCK ****
  159. *******************************************
  160. copy_block
  161. move.w #COPYCUT_BLOCK_MODE,map_function_mode
  162. move.w #PICK,sprite_to_attach
  163. move.w #MODE_COPY,buffer_mode
  164. rts
  165. buffer_mode
  166. dc.w 0
  167. MODE_CUT EQU 0
  168. MODE_COPY EQU 1
  169. ********************************************
  170. ****** COPY BUFFER TO HOLD ******
  171. ********************************************
  172. copy_buffer_to_hold
  173. *send in d7 whether to clear original data ( 0 = no clear )
  174. move.w map_x_position,d0
  175. move.w map_y_position,d1
  176. copy_buffer_to_pos
  177. move.l current_buffer_mem,a1
  178. move.l buffer_mem(a1),a2
  179. move.l current_map_ptr,a3
  180. moveq #0,d2
  181. move.w Image_Start_X,d2
  182. divu map_block_size(a3),d2
  183. add.w d2,d0
  184. moveq #0,d2
  185. move.w Image_Start_Y,d2
  186. divu map_block_size(a3),d2
  187. add.w d2,d1
  188. bsr get_map_position
  189. ****start of block in a0
  190. moveq #0,d2
  191. move.w Image_End_X,d2
  192. sub.w Image_Start_X,d2
  193. divu map_block_size(a3),d2 ;x size of block
  194. move.w d2,buffer_xsize(a1)
  195. moveq #0,d3
  196. move.w Image_End_Y,d3
  197. sub.w Image_Start_Y,d3
  198. divu map_block_size(a3),d3 ;y size of block
  199. move.w d3,buffer_ysize(a1)
  200. move.w map_datasize(a3),d6
  201. moveq #0,d5
  202. move.w map_xsize(a3),d5
  203. asl.w d6,d5 ;one line size
  204. tst d2
  205. beq no_refresh_buffer
  206. tst d3
  207. beq no_refresh_buffer
  208. subq.w #1,d2
  209. subq.w #1,d3
  210. copy_y_data_buffer
  211. move.l a0,a4
  212. move.w d2,d4
  213. copy_x_data_buffer
  214. tst d6
  215. beq.s copy_byte_buffer
  216. move.w (a4),(a2)+
  217. tst d7
  218. beq.s no_clear_word_buffer
  219. move.w #0,(a4)
  220. no_clear_word_buffer
  221. addq.l #2,a4
  222. bra.s get_next_block_buffer
  223. copy_byte_buffer
  224. move.b (a4),(a2)+
  225. tst d7
  226. beq.s no_clear_byte_buffer
  227. move.b #0,(a4)
  228. no_clear_byte_buffer
  229. addq.l #1,a4
  230. get_next_block_buffer
  231. dbra d4,copy_x_data_buffer
  232. add.l d5,a0
  233. dbra d3,copy_y_data_buffer
  234. tst d7
  235. beq.s no_refresh_buffer
  236. bsr display_map_on_screen
  237. no_refresh_buffer
  238. rts
  239. ********************************************
  240. ****** PASTE BLOCK ******
  241. ********************************************
  242. paste_block
  243. move.w #TO,sprite_to_attach
  244. move.w #PASTE_BLOCK_MODE,map_function_mode
  245. rts
  246. ********************************************
  247. ****** PASTE HOLD TO MAP ******
  248. ********************************************
  249. paste_hold_to_map
  250. *ensure user not trying to paste non existant buffer
  251. move.l current_buffer_mem,a0
  252. tst.w buffer_xsize(a0)
  253. beq quit_paste
  254. tst.w buffer_ysize(a0)
  255. beq quit_paste
  256. bsr display_undo
  257. bsr make_screen_backup
  258. paste_box_loop
  259. bsr draw_paste_box
  260. pasteBoxsync
  261. move.w $dff006,d0
  262. andi.w #$ff00,d0
  263. bne.s pasteBoxsync Test for zero (box can't draw past)
  264. Delete_pasteBox
  265. bsr delete_paste_box
  266. btst.b #6,$bfe001
  267. beq paste_box_loop ; release mouse button (end drag)
  268. bsr test_for_out_of_bounds
  269. tst d0
  270. bmi quit_paste
  271. move.l current_buffer_mem,a1
  272. move.l buffer_mem(a1),a2
  273. move.l current_map_ptr,a3
  274. bsr convert_mouse_and_store
  275. paste_in_quiet
  276. divu map_block_size(a3),d0
  277. divu map_block_size(a3),d1
  278. add.w map_x_position,d0
  279. add.w map_y_position,d1
  280. paste_in_very_quiet
  281. bsr get_map_position
  282. ****start of block in a0
  283. move.w buffer_xsize(a1),d2
  284. move.w buffer_ysize(a1),d3
  285. moveq #0,d7
  286. move.w d2,d6
  287. add.w d0,d6
  288. cmp.w map_xsize(a3),d6
  289. ble.s no_out_of_bounds_paste_x
  290. sub.w map_xsize(a3),d6
  291. move.w d6,d7
  292. sub.w d6,d2
  293. no_out_of_bounds_paste_x
  294. move.w d3,d6
  295. add.w d1,d6
  296. cmp.w map_ysize(a3),d6
  297. ble.s no_out_of_bounds_paste_y
  298. sub.w map_ysize(a3),d6
  299. sub.w d6,d3 ;new y size to copy in
  300. no_out_of_bounds_paste_y
  301. move.w map_datasize(a3),d6
  302. moveq #0,d5
  303. move.w map_xsize(a3),d5
  304. asl.w d6,d5 ;one line size
  305. asl d6,d7 ;map x remainder
  306. subq.w #1,d2
  307. subq.w #1,d3
  308. paste_y_data_buffer
  309. move.l a0,a4
  310. move.w d2,d4
  311. paste_x_data_buffer
  312. tst d6
  313. beq.s paste_byte_buffer
  314. move.w (a2)+,(a4)+
  315. bra.s get_next_block_buffer_paste
  316. paste_byte_buffer
  317. move.b (a2)+,(a4)+
  318. get_next_block_buffer_paste
  319. dbra d4,paste_x_data_buffer
  320. add.l d7,a2
  321. add.l d5,a0
  322. dbra d3,paste_y_data_buffer
  323. bsr display_map_on_screen
  324. quit_paste
  325. rts
  326. ********************************************
  327. ****** DRAW PASTE BOX ******
  328. ********************************************
  329. draw_paste_box
  330. bsr convert_mouse_and_store
  331. move.l #main_screen_struct,a1
  332. moveq #0,d4
  333. move.l current_map_ptr,a3
  334. move.l current_buffer_mem,a0
  335. move.w buffer_xsize(a0),d4
  336. mulu map_block_size(a3),d4
  337. cmp.w screen_x_size(a1),d4
  338. ble.s withinbounds
  339. move.w screen_x_size(a1),d4
  340. withinbounds
  341. moveq #0,d5
  342. move.w buffer_ysize(a0),d5
  343. mulu map_block_size(a3),d5
  344. cmp.w max_map_screen_pos,d5
  345. ble.s with_y_bounds
  346. move.w max_map_screen_pos,d5
  347. with_y_bounds
  348. move.l #main_screen_struct,a4
  349. move.w screen_x_size(a4),d7
  350. sub.w d4,d7
  351. cmp.w d7,d0
  352. ble.s fits_ok
  353. move.w d7,d0
  354. fits_ok
  355. move.w max_map_screen_pos,d7
  356. sub.w d5,d7
  357. cmp.w d7,d1
  358. ble.s fits_ok_y
  359. move.w d7,d1
  360. fits_ok_y
  361. move.w d0,bx1
  362. move.w d1,by1
  363. move.w d4,bxsize
  364. move.w d5,bysize
  365. draw_paste_box_lines
  366. move.l #main_screen_struct,a0
  367. move.w d0,d2
  368. move.w d1,d3
  369. add.w d5,d3
  370. movem.l d0-d5,-(sp)
  371. bsr EOR_Draw_Line ;left to bot
  372. movem.l (sp)+,d0-d5
  373. add.w d5,d1
  374. add.w d4,d2 ;left to right
  375. movem.l d0-d5,-(sp)
  376. bsr EOR_Draw_Line
  377. movem.l (sp)+,d0-d5
  378. add.w d4,d0
  379. sub.w d5,d3
  380. movem.l d0-d5,-(sp)
  381. bsr EOR_Draw_Line ;right to top
  382. movem.l (sp)+,d0-d5
  383. sub.w d5,d1
  384. sub.w d4,d2
  385. movem.l d0-d5,-(sp)
  386. bsr EOR_Draw_Line ;right to left
  387. movem.l (sp)+,d0-d5
  388. rts
  389. ********************************************
  390. ****** DELETE PASTE BOX ******
  391. ********************************************
  392. delete_paste_box
  393. move.w bx1,d0
  394. move.w by1,d1
  395. move.w bxsize,d4
  396. move.w bysize,d5
  397. bra draw_paste_box_lines
  398. rts
  399. bx1 dc.w 0
  400. by1 dc.w 0
  401. bxsize dc.w 0
  402. bysize dc.w 0
  403. ********************************************
  404. ****** MAKE SCREEN BACKUP ******
  405. ********************************************
  406. make_screen_backup
  407. move.l current_buffer_mem,buffer_temp
  408. move.l undo_buffer1,current_buffer_mem
  409. move.w #0,IMage_Start_X
  410. move.w #0,Image_Start_Y
  411. move.l #main_screen_struct,a1
  412. move.w screen_x_size(a1),d0
  413. move.w max_map_screen_pos,d1
  414. bsr truncate_values
  415. move.w d0,Image_End_X
  416. move.w d1,Image_End_Y
  417. move.w #0,d7
  418. bsr copy_buffer_to_hold
  419. move.l buffer_temp,current_buffer_mem
  420. move.w map_x_position,mp_x_pos
  421. move.w map_y_position,mp_y_pos
  422. rts
  423. mp_x_pos dc.w 0
  424. mp_y_pos dc.w 0
  425. ********************************************
  426. ****** UNDO ******
  427. ********************************************
  428. undo
  429. move.l current_buffer_mem,buffer_temp
  430. move.l undo_buffer2,current_buffer_mem
  431. move.l #main_screen_struct,a0
  432. move.w screen_x_size(a0),d0
  433. move.w max_map_screen_pos,d1
  434. bsr truncate_values
  435. move.w #0,Image_Start_X
  436. move.w #0,Image_Start_Y
  437. move.w d0,Image_End_X
  438. move.w d1,Image_End_Y
  439. move.w #0,d7
  440. move.w mp_x_pos,d0
  441. move.w mp_y_pos,d1
  442. bsr copy_buffer_to_pos
  443. moveq #0,d0
  444. moveq #0,d1
  445. move.w mp_x_pos,d0
  446. move.w mp_y_pos,d1
  447. move.l undo_buffer1,current_buffer_mem
  448. move.l current_map_ptr,a3
  449. move.l current_buffer_mem,a1
  450. move.l buffer_mem(a1),a2
  451. bsr paste_in_very_quiet
  452. move.l undo_buffer1,a0
  453. move.l undo_buffer2,a1
  454. move.l a0,undo_buffer2
  455. move.l a1,undo_buffer1
  456. move.l buffer_temp,current_buffer_mem
  457. bsr display_map_on_screen
  458. rts
  459. buffer_temp
  460. dc.l 0
  461. undo_buffer1
  462. dc.l screen_backup1
  463. undo_buffer2
  464. dc.l screen_backup2
  465. screen_backup1
  466. ds.w 2
  467. ds.b 12
  468. dc.l scr1b
  469. screen_backup2
  470. ds.w 2
  471. ds.b 12
  472. dc.l scr2b