iffroutine.s 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. *****************************************************************
  2. * MODULE TITLE :iffroutine *
  3. * *
  4. * DESCRIPTION :iff loader and iff saver *
  5. * *
  6. * *
  7. * *
  8. * NAME DATE *
  9. * *
  10. * LIST OF ROUTINES :load_graphics *
  11. * insert_byte *
  12. * dealloc_pic_mem *
  13. * find_in_mem *
  14. * setup_plane_offsets *
  15. * save_graphics *
  16. * setup_bmhd *
  17. * save_pic *
  18. * *
  19. *****************************************************************
  20. ********************************
  21. **** LOAD GRAPHICS *****
  22. ********************************
  23. load_graphics
  24. move.b #1,pointer_state
  25. move.l a6,-(sp)
  26. *send in file handle in d0
  27. *returns pointer to struct containing pic mem pointers in a0
  28. move.l d0,graphics_handle
  29. move.l d0,d1
  30. move.l #buffer,d2
  31. move.l #4,d3
  32. move.l dosbase,a5
  33. jsr READ(a5)
  34. cmp.l #'FORM',buffer
  35. beq.s ok_so_far
  36. move.w #1000,d0
  37. bra exit_with_error
  38. ok_so_far
  39. move.l graphics_handle,d1 ;read size of file
  40. move.l #buffer,d2
  41. move.l #4,d3
  42. move.l dosbase,a6
  43. jsr READ(a6)
  44. move.l 4,a6 ; exec
  45. move.l buffer,d0 ; mem to allocate
  46. move.l #MEM_PUBLIC+MEM_CLEAR,d1 ; chip and clear
  47. jsr -198(a6) ; try
  48. tst.l d0
  49. bne alloc_pic_size
  50. move.w #1001,d0
  51. bra exit_with_error
  52. alloc_pic_size
  53. move.l d0,pic_pointer
  54. move.l d0,d2
  55. move.l buffer,d3
  56. move.l graphics_handle,d1
  57. move.l dosbase,a6
  58. jsr READ(a6) ;read in all data
  59. move.l pic_pointer,a1
  60. move.l #'BMHD',d0
  61. bsr find_in_mem
  62. move.l (a1)+,header_size
  63. move.l a1,picture_details
  64. move.l #'CMAP',d0
  65. bsr find_in_mem
  66. move.l (a1)+,num_of_cols
  67. move.l a1,colour_map_ptr
  68. move.l page_pointer,a3
  69. move.l screen_palette(a3),a0
  70. bsr insert_cols
  71. move.l #'BODY',d0
  72. bsr find_in_mem
  73. move.l (a1)+,size_of_pic
  74. move.l a1,picture_data ;at last we are here
  75. move.l picture_details,a0
  76. move.w RWIDTH(a0),screen_x_size(a3)
  77. move.w RHEIGHT(a0),screen_y_size(a3)
  78. moveq #0,d0
  79. move.b NUMPLANES(a0),d0
  80. move.w d0,number_of_planes(a3)
  81. move.w #0,screen_y_pos(a3)
  82. move.l page_pointer,a0
  83. move.l screen_palette(a0),a1
  84. bsr setup_screen_colours
  85. bsr setup_plane_offsets
  86. bsr clear_old_data
  87. **set up pointers and variables so decompression is super quick
  88. move.l page_pointer,a3
  89. move.l #main_screen_struct,a5
  90. moveq #0,d3
  91. move.l current_plane,d3
  92. asl.w #2,d3
  93. move.w screen_x_size(a5),d4
  94. move.w number_of_planes(a3),d7
  95. asl.w #2,d7
  96. moveq #0,d6 ; pixel count
  97. move.w RWIDTH(a3),d5 ; image loaded size
  98. add.w #15,d5
  99. andi.w #$fff0,d5
  100. move.l #plane_positions,a2
  101. ***Finished setup
  102. move.l picture_data,a1
  103. move.l picture_details,a0
  104. cmp.b #0,TYPECOM(a0)
  105. beq.s call_uncom
  106. bsr compressed_data
  107. bra.s finished_uncom
  108. call_uncom
  109. bsr uncompressed_data
  110. finished_uncom
  111. bsr dealloc_pic_mem
  112. bra.s quit_ld_grap
  113. exit_with_error
  114. move.l #-1,a1
  115. quit_ld_grap
  116. move.l dosbase,a6
  117. move.l graphics_handle,d1
  118. jsr close(a6)
  119. bsr general_delay
  120. move.b #0,pointer_state
  121. move.l (sp)+,a6
  122. rts
  123. compressed_data
  124. moveq #0,d0
  125. move.b (a1)+,d0 ;pointer to pic data
  126. subq.l #1,size_of_pic
  127. move.b d0,d1
  128. bmi repeat_data
  129. addq.b #1,d1
  130. bra.s read_and_insert
  131. loop_read
  132. tst.l size_of_pic
  133. bgt.s compressed_data
  134. rts
  135. read_and_insert
  136. moveq #0,d0
  137. move.b (a1)+,d0 ;pointer to pic data
  138. subq.l #1,size_of_pic
  139. subq.b #1,d1
  140. bsr insert_byte
  141. tst.b d1
  142. bne.s read_and_insert
  143. bra loop_read
  144. repeat_data
  145. cmp.b #-128,d1
  146. bne.s do_something
  147. subq.l #1,size_of_pic
  148. bra loop_read
  149. do_something
  150. neg.b d1
  151. addq.b #1,d1
  152. moveq #0,d0
  153. move.b (a1)+,d0 ;pointer to pic data
  154. subq.l #1,size_of_pic
  155. repeat_loop
  156. bsr insert_byte
  157. subq.b #1,d1
  158. bne.s repeat_loop
  159. bra.s loop_read
  160. uncompressed_data
  161. moveq #0,d0
  162. move.b (a1)+,d0 ;pointer to pic data
  163. subq.l #1,size_of_pic
  164. bsr insert_byte
  165. cmp.l #0,size_of_pic
  166. bgt.s uncompressed_data
  167. rts
  168. ********************************
  169. **** INSERT BYTE *****
  170. ********************************
  171. insert_byte
  172. move.l (a2,d3),a4
  173. move.b d0,(a4)
  174. addq.l #1,(a2,d3)
  175. addq.w #8,d6 ;pixel count
  176. cmp.w d6,d4 ;pix count
  177. bne.s not_done_line
  178. bra.s update_planes
  179. not_done_line
  180. cmp.w d6,d5
  181. bne.s not_done_yet
  182. moveq #0,d2
  183. move.w main_screen_struct+screen_x_size,d2
  184. sub.w d6,d2
  185. asr.w #3,d2
  186. add.l d2,(a2,d3) move onto next line
  187. update_planes
  188. moveq #0,d6
  189. addq.w #4,d3
  190. cmp.w d7,d3 ;compare curent plane with number of planes
  191. bne.s not_done_line
  192. moveq #0,d3
  193. not_done_yet
  194. rts
  195. ********************************
  196. **** DEALLOC PIC MEM *****
  197. ********************************
  198. dealloc_pic_mem
  199. move.l 4,a6 ; deallocate mem
  200. move.l buffer,d0
  201. move.l pic_pointer,a1
  202. jsr -210(a6)
  203. rts
  204. ********************************
  205. **** ALLOCATE SCREEN MEM *****
  206. ********************************
  207. allocate_screen_mem
  208. ****PLEASE NOTE - bodgy code is about
  209. ****THE picture structs allocate the same size as the screen
  210. ****but the x and y size contained in the struct are that of the
  211. ****graphic image
  212. movem.l a0-a6/d0-d7,-(sp)
  213. *** SEE IF NEED TO DEALLOCATE OLD PICTURE
  214. move.l page_pointer,a0
  215. tst.l screen_mem(a0)
  216. beq.s no_need_to_deallocate
  217. move.l #main_screen_struct,a4
  218. move.w screen_x_size(a4),d0
  219. asr.w #3,d0
  220. mulu screen_y_size(a4),d0
  221. mulu number_of_planes(a0),d0
  222. move.l screen_mem(a0),a1
  223. move.l 4,a6
  224. jsr -210(a6)
  225. no_need_to_deallocate
  226. *****NOW TRY AND ALLOCATE NEW ONE
  227. move.l #main_screen_struct,a0
  228. move.w screen_x_size(a0),d0
  229. asr.w #3,d0
  230. mulu screen_y_size(a0),d0
  231. move.l page_pointer,a0
  232. mulu number_of_planes(a0),d0
  233. move.l 4,a6
  234. move.l #MEM_PUBLIC+MEM_CLEAR,d1
  235. jsr -198(a6)
  236. tst.l d0
  237. bne.s got_the_mem
  238. move.l #main_screen_colours+2,a2
  239. move.w #$fff,(a2)
  240. got_the_mem
  241. move.l page_pointer,a0
  242. move.l d0,screen_mem(a0)
  243. movem.l (sp)+,a0-a6/d0-d7
  244. rts
  245. ********************************
  246. **** CLEAR_OLD_DATA *****
  247. ********************************
  248. clear_old_data
  249. movem.l a0/d0,-(sp)
  250. move.l #main_screen_struct,a0
  251. moveq #0,d0
  252. move.w screen_x_size(a0),d0
  253. asr.w #3,d0
  254. mulu screen_y_size(a0),d0
  255. asr.w #2,d0
  256. mulu number_of_planes(a0),d0
  257. move.l page_pointer,a0
  258. move.l screen_mem(a0),a0
  259. subq.w #1,d0
  260. clear_old_data_loop
  261. clr.l (a0)+
  262. dbra d0,clear_old_data_loop
  263. no_clear_old
  264. movem.l (sp)+,a0/d0
  265. ********************************
  266. **** FIND IN MEM *****
  267. ********************************
  268. find_in_mem
  269. move.l a1,a0
  270. set_up_loop
  271. move.w #3,d2
  272. moveq #0,d1
  273. test_in_loop
  274. rol.l #8,d1
  275. or.b (a0)+,d1
  276. dbra d2,test_in_loop
  277. cmp.l d1,d0
  278. beq.s found_the_text
  279. add.l #1,a1
  280. bra.s find_in_mem
  281. found_the_text
  282. add.l #4,a1 ;get past text
  283. rts
  284. ********************************
  285. **** SETUP PLANE OFFSETS *****
  286. ********************************
  287. setup_plane_offsets
  288. movem.l a0-a1/d0-d1,-(sp)
  289. move.l #main_screen_struct,a0
  290. moveq #0,d0
  291. move.w screen_x_size(a0),d0
  292. asr.w #3,d0
  293. mulu screen_y_size(a0),d0
  294. move.w number_of_planes(a0),d1
  295. subq.w #1,d1
  296. move.l #plane_positions,a0
  297. move.l page_pointer,a1
  298. move.l screen_mem(a1),a1
  299. calculate_offsets
  300. move.l a1,(a0)+
  301. add.l d0,a1
  302. dbra d1,calculate_offsets
  303. movem.l (sp)+,a0-a1/d0-d1
  304. rts
  305. ********************************
  306. **** SAVE GRAPHICS *****
  307. ********************************
  308. save_graphics
  309. move.b #1,pointer_state
  310. bsr remove_file_request
  311. movem.l a6,-(sp)
  312. move.l dosbase,a6
  313. move.l #current_filename,d1
  314. move.l #MODE_NEW,d2
  315. jsr OPEN(a6)
  316. tst.l d0
  317. bne.s go_and_save_pic
  318. movem.l (sp)+,a6
  319. bsr display_error
  320. bra exit_save_pic
  321. go_and_save_pic
  322. move.l d0,save_file_handle
  323. tst.b save_format
  324. bne.s save_dpaint_file
  325. bsr save_raw_data
  326. bra fin_save_pic
  327. save_dpaint_file
  328. ***write out header
  329. move.l #"FORM",save_buffer
  330. move.l d0,d1
  331. move.l #save_buffer,d2
  332. move.l #4,d3
  333. jsr WRITE(a6)
  334. ***calculate size of file
  335. move.l #main_screen_struct,a0
  336. move.w screen_x_size(a0),d0
  337. asr.w #3,d0
  338. mulu screen_y_size(a0),d0
  339. mulu number_of_planes_to_save,d0 ;size of pic
  340. add.l #4+4+4+4+4+4+4,d0 ;BMHD,CMAP,BODY text, BMHDSIZE and BODY SIZE + number of colours
  341. add.l #size_of_bmhd,d0
  342. move.w number_of_planes_to_save,d1
  343. move.w #1,d2
  344. asl.w d1,d2
  345. mulu #3,d2
  346. add.l d2,d0 ;colours
  347. move.l d0,save_buffer
  348. move.l save_file_handle,d1
  349. move.l #save_buffer,d2
  350. move.l #4,d3
  351. jsr WRITE(a6)
  352. ****write bmhd
  353. move.l #"ILBM",save_buffer
  354. move.l save_file_handle,d1
  355. move.l #save_buffer,d2
  356. move.l #4,d3
  357. jsr WRITE(a6)
  358. move.l #"BMHD",save_buffer
  359. move.l save_file_handle,d1
  360. move.l #save_buffer,d2
  361. move.l #4,d3
  362. jsr WRITE(a6)
  363. move.l #size_of_bmhd,save_buffer
  364. move.l save_file_handle,d1
  365. move.l #save_buffer,d2
  366. move.l #4,d3
  367. jsr WRITE(a6)
  368. bsr setup_bmhd
  369. move.l save_file_handle,d1
  370. move.l #save_bmhd,d2
  371. move.l #size_of_bmhd,d3
  372. jsr WRITE(a6)
  373. ****do colourmap
  374. move.l #"CMAP",save_buffer
  375. move.l save_file_handle,d1
  376. move.l #save_buffer,d2
  377. move.l #4,d3
  378. jsr WRITE(a6)
  379. move.w number_of_planes_to_save,d1
  380. move.w #1,d2
  381. asl.w d1,d2
  382. mulu #3,d2
  383. move.l d2,save_buffer
  384. move.l save_file_handle,d1
  385. move.l #save_buffer,d2
  386. move.l #4,d3
  387. jsr WRITE(a6)
  388. move.w number_of_planes_to_save,d1
  389. move.w #1,d2
  390. asl.w d1,d2
  391. move.l d2,d3
  392. bsr convert_to_dpaint_colours ;uses d2
  393. mulu #3,d3 ;number of bytes
  394. move.l save_file_handle,d1
  395. move.l #dpaint_colours,d2
  396. jsr WRITE(a6)
  397. ****do body
  398. move.l #"BODY",save_buffer
  399. move.l save_file_handle,d1
  400. move.l #save_buffer,d2
  401. move.l #4,d3
  402. jsr WRITE(a6)
  403. move.l #main_screen_struct,a0
  404. move.w screen_x_size(a0),d0
  405. asr.w #3,d0
  406. mulu screen_y_size(a0),d0
  407. mulu number_of_planes_to_save,d0
  408. move.l d0,save_buffer
  409. move.l save_file_handle,d1
  410. move.l #save_buffer,d2
  411. move.l #4,d3
  412. jsr WRITE(a6)
  413. ****write out body data
  414. move.l #main_screen_struct,a0
  415. move.w screen_y_size(a0),d0
  416. moveq #0,d1
  417. move.w screen_x_size(a0),d1
  418. asr.w #3,d1
  419. move.l page_pointer,a0
  420. move.l screen_mem(a0),a1
  421. subq.w #1,d0
  422. write_pic_loop
  423. move.l a1,a2
  424. move.w number_of_planes_to_save,d2
  425. subq.w #1,d2
  426. write_plane_pic_loop
  427. movem.l a0-a2/d0-d2,-(sp) ;write line
  428. move.l d1,d3 ;size
  429. move.l save_file_handle,d1 ;handle
  430. move.l a2,d2 ;place to get from
  431. jsr write(a6)
  432. movem.l (sp)+,a0-a2/d0-d2
  433. move.l d1,d4
  434. move.l #main_screen_struct,a0
  435. mulu screen_y_size(a0),d4 ;plane size
  436. add.l d4,a2
  437. dbra d2,write_plane_pic_loop
  438. add.l d1,a1
  439. dbra d0,write_pic_loop
  440. fin_save_pic
  441. move.l save_file_handle,d1
  442. jsr CLOSE(a6)
  443. quit_save_pic
  444. movem.l (sp)+,a6
  445. exit_save_pic
  446. move.b #0,pointer_state
  447. rts
  448. general_delay
  449. movem.l d0-d7/a0-a6,-(sp)
  450. move.l dosbase,a6
  451. move.l #50*5,d1
  452. jsr delay(a6)
  453. movem.l (sp)+,d0-d7/a0-a6
  454. rts
  455. ********************************
  456. **** CONVERT TO DPAINT COLOURS *
  457. ********************************
  458. convert_to_dpaint_colours
  459. ****d2 contains number
  460. movem.l a0-a1/d0-d3,-(sp)
  461. move.l page_pointer,a0
  462. move.l screen_palette(a0),a0
  463. move.l #dpaint_colours,a1
  464. subq.w #1,d2
  465. convert_dpaint_loop
  466. move.w (a0)+,d1
  467. move.w d1,d3
  468. lsr #8,d3
  469. andi.w #$f,d3
  470. lsl.w #4,d3
  471. move.b d3,(a1)+ ;read
  472. move.w d1,d3
  473. lsr.w #4,d3
  474. andi.w #$f,d3
  475. lsl.w #4,d3
  476. move.b d3,(a1)+ ;green
  477. andi.w #$f,d1
  478. lsl.w #4,d1
  479. move.b d1,(a1)+ ;blue
  480. dbra d2,convert_dpaint_loop
  481. movem.l (sp)+,a0-a1/d0-d3
  482. rts
  483. dpaint_colours
  484. ds.b 3*256 ;max
  485. EVEN
  486. ********************************
  487. **** SETUP BMHD *****
  488. ********************************
  489. setup_bmhd
  490. move.l d1,-(sp)
  491. move.l #main_screen_struct,a0
  492. move.l #save_bmhd,a1
  493. move.w screen_x_size(a0),RWIDTH(a1)
  494. move.w screen_y_size(a0),RHEIGHT(a1)
  495. move.w #0,XPOS(a1)
  496. move.w #0,YPOS(a1)
  497. move.l page_pointer,a0
  498. move.w number_of_planes(a0),d0
  499. move.b d0,numplanes(a1)
  500. move.b #0,PMASK(a1)
  501. move.b #0,TYPECOM(a1)
  502. move.b #0,PAD(a1)
  503. move.w #0,TRANSCOLOUR(a1)
  504. move.b #0,XASPECT(a1)
  505. move.b #0,YASPECT(a1)
  506. move.w #0,PAGEWIDTH(a1)
  507. move.w #0,PAGEHEIGHT(a1)
  508. move.l (sp)+,d1
  509. rts
  510. ********************************
  511. **** SAVE PIC *****
  512. ********************************
  513. save_pic
  514. move.l #save_graphics,file_routine_pointer
  515. bsr display_file_request
  516. rts
  517. ********************************
  518. **** INSERT COLS *****
  519. ********************************
  520. insert_cols
  521. ***send place to put palette in a0
  522. movem.l d0-d7/a0-a2,-(sp)
  523. move.l a0,a2
  524. add.l #256*2,a2 ;lo colour attributes
  525. move.l num_of_cols,d5
  526. divu #3,d5
  527. sub.w #1,d5
  528. move.l colour_map_ptr,a1
  529. insert_colours
  530. moveq #0,d3 ;hi colour
  531. moveq #0,d6 ;lo colour
  532. moveq #0,d4
  533. move.b (a1)+,d3
  534. move.b d3,d6
  535. andi.b #$f,d6
  536. andi.b #$f0,d3
  537. lsl.w #4,d3
  538. lsl.w #8,d6
  539. move.b (a1)+,d4
  540. move.w d4,d7
  541. andi.b #$f,d7
  542. lsl.b #4,d7
  543. or.b d7,d6
  544. andi.b #$f0,d4
  545. or.b d4,d3
  546. move.b (a1)+,d4
  547. move.b d4,d7
  548. andi.b #$f,d7
  549. or.b d7,d6
  550. andi.b #$f0,d4
  551. lsr.w #4,d4
  552. or.w d4,d3
  553. move.w d6,(a2)+ ;lo colour attrib
  554. move.w d3,(a0)+ ;hi colour attrib
  555. moveq #0,d0
  556. dbra d5,insert_colours
  557. movem.l (sp)+,d0-d7/a0-a2
  558. rts
  559. ********************************
  560. **** SAVE RAW DATA *****
  561. ********************************
  562. save_raw_data
  563. moveq #0,d6 ;picture pages offset num
  564. move.w number_of_blocks_to_write_out,d0
  565. move.l #picture_pages,a0
  566. move.w #4-1,d1 ;page count
  567. move.w #0,d2 ;block count
  568. move.l #main_screen_struct,a1
  569. move.l current_map_ptr,a2
  570. moveq #0,d5
  571. moveq #0,d3
  572. move.w screen_x_size(a1),d3
  573. moveq #0,d7
  574. move.w d3,d7
  575. asr.w #3,d7 ;x size of screen
  576. divu map_block_size(a2),d3 ;x blocks
  577. move.w screen_y_size(a1),d5
  578. divu map_block_size(a2),d5 ;y blocks
  579. move.w d3,d4
  580. mulu d5,d4 ;number of blocks in page
  581. move.l (a0,d6),a3 ;page
  582. move.l screen_mem(a3),a3
  583. moveq #0,d0
  584. moveq #0,d3
  585. write_out_pages
  586. bsr write_out_block
  587. *** - See if all blocks of a page done
  588. addq.w #1,d2
  589. cmp.w d2,d4
  590. bne.s not_done_page_yet
  591. add.w d4,d3 ;d3 = value to sub from block count
  592. moveq #0,d2
  593. addq.l #4,d6
  594. move.l (a0,d6),a3 ;get new page
  595. move.l screen_mem(a3),a3
  596. ****
  597. not_done_page_yet
  598. addq.w #1,d0
  599. cmp.w number_of_blocks_to_write_out,d0
  600. bne.s write_out_pages
  601. rts
  602. ********************************
  603. **** WRITE OUT BLOCK *****
  604. ********************************
  605. write_out_block
  606. ***takes in a3 as current page
  607. movem.l d0-d3/d6/a3-a6,-(sp)
  608. *d0 = number of block
  609. sub.w d3,d0 ;get block in page
  610. ext.l d0
  611. moveq #0,d3
  612. move.w screen_x_size(a1),d3
  613. divu map_block_size(a2),d3
  614. divu.w d3,d0
  615. swap d0
  616. move.w d0,d2 ;x blocks in
  617. swap d0
  618. move.w d0,d1 = number of lines down
  619. mulu map_block_size(a2),d1
  620. mulu d7,d1
  621. move.w map_block_size(a2),d0 ;8 16 32
  622. asr.w #3,d0
  623. mulu d0,d2 ;block in
  624. move.l a3,a4
  625. add.l d2,a4
  626. add.l d1,a4 ;block
  627. move.l a4,a6
  628. *******code to write out
  629. move.w map_planes(a2),d0
  630. subq.w #1,d0 ;number of planes
  631. move.l #one_block_buffer,a5
  632. plane_loop
  633. move.w map_block_size(a2),d1
  634. subq.w #1,d1
  635. block_line_loop
  636. cmp.w #8,map_block_size(a2)
  637. bne.s check_16_pos
  638. move.b (a4),(a5)+
  639. bra.s do_all_planes
  640. check_16_pos
  641. cmp.w #16,map_block_size(a2)
  642. bne.s block_write_be_32
  643. move.w (a4),(a5)+
  644. bra.s do_all_planes
  645. block_write_be_32
  646. move.l (a4),(a5)+
  647. do_all_planes
  648. tst.b sliced
  649. bne.s sliced_save
  650. add.l d7,a4 ;next line down
  651. bra.s carry_on_collect
  652. sliced_save
  653. move.w d7,d6
  654. mulu screen_y_size(a2),d6
  655. add.l d7,a4
  656. carry_on_collect
  657. dbra d1,block_line_loop
  658. tst.b sliced
  659. bne.s sliced_save2
  660. move.w d7,d1
  661. mulu screen_y_size(a1),d1
  662. add.l d1,a6
  663. move.l a6,a4
  664. bra.s jump_past_sliced_save
  665. sliced_save2
  666. add.l d7,a6
  667. move.l a6,a4
  668. jump_past_sliced_save
  669. dbra d0,plane_loop
  670. movem.l (sp)+,d0-d3/d6/a3-a6
  671. ***data now in one_block_buffer
  672. ************write block out
  673. movem.l d0-d7/a0-a6,-(sp)
  674. move.l dosbase,a6
  675. move.l save_file_handle,d1
  676. move.l #one_block_buffer,d2
  677. move.w map_block_size(a2),d3
  678. asr.w #3,d3
  679. mulu map_block_size(a2),d3
  680. mulu.w map_planes(a2),d3
  681. jsr write(a6)
  682. movem.l (sp)+,d0-d7/a0-a6
  683. **************write block out
  684. not_done_line_write_block
  685. rts