iffroutinebk.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 #320,d2 ;naughty naughty
  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.w #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. * bsr general_delay
  444. quit_save_pic
  445. movem.l (sp)+,a6
  446. exit_save_pic
  447. move.b #0,pointer_state
  448. rts
  449. general_delay
  450. movem.l d0-d7/a0-a6,-(sp)
  451. move.l dosbase,a6
  452. move.l #50*5,d1
  453. jsr delay(a6)
  454. movem.l (sp)+,d0-d7/a0-a6
  455. rts
  456. ********************************
  457. **** CONVERT TO DPAINT COLOURS *
  458. ********************************
  459. convert_to_dpaint_colours
  460. ****d2 contains number
  461. movem.l a0-a1/d0-d3,-(sp)
  462. move.l page_pointer,a0
  463. move.l screen_palette(a0),a0
  464. move.l #dpaint_colours,a1
  465. subq.w #1,d2
  466. convert_dpaint_loop
  467. move.w (a0)+,d1
  468. move.w d1,d3
  469. lsr #8,d3
  470. andi.w #$f,d3
  471. lsl.w #4,d3
  472. move.b d3,(a1)+ ;read
  473. move.w d1,d3
  474. lsr.w #4,d3
  475. andi.w #$f,d3
  476. lsl.w #4,d3
  477. move.b d3,(a1)+ ;green
  478. andi.w #$f,d1
  479. lsl.w #4,d1
  480. move.b d1,(a1)+ ;blue
  481. dbra d2,convert_dpaint_loop
  482. movem.l (sp)+,a0-a1/d0-d3
  483. rts
  484. dpaint_colours
  485. ds.b 3*256 ;max
  486. EVEN
  487. ********************************
  488. **** SETUP BMHD *****
  489. ********************************
  490. setup_bmhd
  491. move.l d1,-(sp)
  492. move.l #main_screen_struct,a0
  493. move.l #save_bmhd,a1
  494. move.w screen_x_size(a0),RWIDTH(a1)
  495. move.w screen_y_size(a0),RHEIGHT(a1)
  496. move.w #0,XPOS(a1)
  497. move.w #0,YPOS(a1)
  498. move.l page_pointer,a0
  499. move.w number_of_planes(a0),d0
  500. move.b d0,numplanes(a1)
  501. move.b #0,PMASK(a1)
  502. move.b #0,TYPECOM(a1)
  503. move.b #0,PAD(a1)
  504. move.w #0,TRANSCOLOUR(a1)
  505. move.b #0,XASPECT(a1)
  506. move.b #0,YASPECT(a1)
  507. move.w #0,PAGEWIDTH(a1)
  508. move.w #0,PAGEHEIGHT(a1)
  509. move.l (sp)+,d1
  510. rts
  511. ********************************
  512. **** SAVE PIC *****
  513. ********************************
  514. save_pic
  515. move.l #save_graphics,file_routine_pointer
  516. bsr display_file_request
  517. rts
  518. ********************************
  519. **** INSERT COLS *****
  520. ********************************
  521. insert_cols
  522. ***send place to put palette in a0
  523. movem.l d0-d7/a0-a2,-(sp)
  524. move.l a0,a2
  525. add.l #256*2,a2 ;lo colour attributes
  526. move.l num_of_cols,d5
  527. divu #3,d5
  528. sub.w #1,d5
  529. move.l colour_map_ptr,a1
  530. insert_colours
  531. moveq #0,d3 ;hi colour
  532. moveq #0,d6 ;lo colour
  533. moveq #0,d4
  534. move.b (a1)+,d3
  535. move.b d3,d6
  536. andi.b #$f,d6
  537. andi.b #$f0,d3
  538. lsl.w #4,d3
  539. lsl.w #8,d6
  540. move.b (a1)+,d4
  541. move.w d4,d7
  542. andi.b #$f,d7
  543. lsl.b #4,d7
  544. or.b d7,d6
  545. andi.b #$f0,d4
  546. or.b d4,d3
  547. move.b (a1)+,d4
  548. move.b d4,d7
  549. andi.b #$f,d7
  550. or.b d7,d6
  551. andi.b #$f0,d4
  552. lsr.w #4,d4
  553. or.w d4,d3
  554. move.w d6,(a2)+ ;lo colour attrib
  555. move.w d3,(a0)+ ;hi colour attrib
  556. moveq #0,d0
  557. dbra d5,insert_colours
  558. movem.l (sp)+,d0-d7/a0-a2
  559. rts
  560. ********************************
  561. **** SAVE RAW DATA *****
  562. ********************************
  563. save_raw_data
  564. moveq #0,d6 ;picture pages offset num
  565. move.w number_of_blocks_to_write_out,d0
  566. move.l #picture_pages,a0
  567. move.w #4-1,d1 ;page count
  568. move.w #0,d2 ;block count
  569. move.l #main_screen_struct,a1
  570. move.l current_map_ptr,a2
  571. moveq #0,d5
  572. moveq #0,d3
  573. move.w screen_x_size(a1),d3
  574. moveq #0,d7
  575. move.w d3,d7
  576. asr.w #3,d7 ;x size of screen
  577. divu map_block_size(a2),d3 ;x blocks
  578. move.w screen_y_size(a1),d5
  579. divu map_block_size(a2),d5 ;y blocks
  580. move.w d3,d4
  581. mulu d5,d4 ;number of blocks in page
  582. move.l (a0,d6),a3 ;page
  583. move.l screen_mem(a3),a3
  584. moveq #0,d0
  585. moveq #0,d3
  586. write_out_pages
  587. bsr write_out_block
  588. *** - See if all blocks of a page done
  589. addq.w #1,d2
  590. cmp.w d2,d4
  591. bne.s not_done_page_yet
  592. add.w d4,d3 ;d3 = value to sub from block count
  593. moveq #0,d2
  594. addq.l #4,d6
  595. move.l (a0,d6),a3 ;get new page
  596. move.l screen_mem(a3),a3
  597. ****
  598. not_done_page_yet
  599. addq.w #1,d0
  600. cmp.w number_of_blocks_to_write_out,d0
  601. bne.s write_out_pages
  602. rts
  603. ********************************
  604. **** WRITE OUT BLOCK *****
  605. ********************************
  606. write_out_block
  607. ***takes in a3 as current page
  608. movem.l d0-d3/d6/a3-a6,-(sp)
  609. *d0 = number of block
  610. sub.w d3,d0 ;get block in page
  611. ext.l d0
  612. moveq #0,d3
  613. move.w screen_x_size(a1),d3
  614. divu map_block_size(a2),d3
  615. divu.w d3,d0
  616. swap d0
  617. move.w d0,d2 ;x blocks in
  618. swap d0
  619. move.w d0,d1 = number of lines down
  620. mulu map_block_size(a2),d1
  621. mulu d7,d1
  622. move.w map_block_size(a2),d0 ;8 16 32
  623. asr.w #3,d0
  624. mulu d0,d2 ;block in
  625. move.l a3,a4
  626. add.l d2,a4
  627. add.l d1,a4 ;block
  628. move.l a4,a6
  629. *******code to write out
  630. move.w map_planes(a2),d0
  631. subq.w #1,d0 ;number of planes
  632. move.l #one_block_buffer,a5
  633. plane_loop
  634. move.w map_block_size(a2),d1
  635. subq.w #1,d1
  636. block_line_loop
  637. cmp.w #8,map_block_size(a2)
  638. bne.s check_16_pos
  639. move.b (a4),(a5)+
  640. bra.s do_all_planes
  641. check_16_pos
  642. cmp.w #16,map_block_size(a2)
  643. bne.s block_write_be_32
  644. move.w (a4),(a5)+
  645. bra.s do_all_planes
  646. block_write_be_32
  647. move.l (a4),(a5)+
  648. do_all_planes
  649. tst.b sliced
  650. bne.s sliced_save
  651. add.l d7,a4 ;next line down
  652. bra.s carry_on_collect
  653. sliced_save
  654. move.w d7,d6
  655. mulu screen_y_size(a2),d6
  656. add.l d7,a4
  657. carry_on_collect
  658. dbra d1,block_line_loop
  659. tst.b sliced
  660. bne.s sliced_save2
  661. move.w d7,d1
  662. mulu screen_y_size(a1),d1
  663. add.l d1,a6
  664. move.l a6,a4
  665. bra.s jump_past_sliced_save
  666. sliced_save2
  667. add.l d7,a6
  668. move.l a6,a4
  669. jump_past_sliced_save
  670. dbra d0,plane_loop
  671. movem.l (sp)+,d0-d3/d6/a3-a6
  672. ***data now in one_block_buffer
  673. ************write block out
  674. movem.l d0-d7/a0-a6,-(sp)
  675. move.l dosbase,a6
  676. move.l save_file_handle,d1
  677. move.l #one_block_buffer,d2
  678. move.w map_block_size(a2),d3
  679. asr.w #3,d3
  680. mulu map_block_size(a2),d3
  681. mulu.w map_planes(a2),d3
  682. jsr write(a6)
  683. movem.l (sp)+,d0-d7/a0-a6
  684. **************write block out
  685. not_done_line_write_block
  686. rts