new_fileio.s 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. draw_box
  2. move.l a0,Box_BMAP
  3. move.w d0,Box_TLx
  4. move.w d1,Box_TLy
  5. move.w d2,Box_BRx
  6. move.w d3,Box_BRy
  7. move.w Box_TLx,d0
  8. move.w Box_TLy,d1
  9. move.w Box_BRx,d2
  10. move.w Box_TLy,d3
  11. bsr Draw_Line
  12. move.l Box_BMAP,a0
  13. move.w Box_BRx,d0
  14. move.w Box_TLy,d1
  15. move.w Box_BRx,d2
  16. move.w Box_BRy,d3
  17. bsr Draw_Line
  18. move.l Box_BMAP,a0
  19. move.w Box_BRx,d0
  20. move.w Box_BRy,d1
  21. move.w Box_TLx,d2
  22. move.w Box_BRy,d3
  23. bsr Draw_Line
  24. move.l Box_BMAP,a0
  25. move.w Box_TLx,d0
  26. move.w Box_BRy,d1
  27. move.w Box_TLx,d2
  28. move.w Box_TLy,d3
  29. bsr Draw_Line
  30. rts
  31. Box_BMAP dc.l 0
  32. Box_TLx dc.w 0
  33. Box_TLy dc.w 0
  34. Box_BRx dc.w 0
  35. Box_BRy dc.w 0
  36. LockDosList EQU -$28e
  37. NextDosEntry EQU -$2b2
  38. delay equ -168
  39. MAX_FILES EQU 79*2
  40. open_dos move.l 4.w,a6 ;open dos lib
  41. lea DosLib(pc),a1
  42. jsr -408(A6)
  43. move.l d0,DosBase
  44. move.l Info_Block,d0
  45. andi.l #$fffffffc,d0
  46. move.l d0,Info_Block
  47. rts
  48. close_dos move.l 4.w,a6
  49. move.l dosbase(pc),a1
  50. jmp -414(a6) ;close dos
  51. MEM_FIX EQU 1234567
  52. rsreset
  53. FH_Filename rs.l 1 ; pointer to null terminated filename
  54. FH_Memory_Type rs.l 1 ; ie MEM_CHIP,FAST,CLEAR etc. or MEM_FIX for fixed addresses
  55. FH_Memory rs.l 1 ; pointer to memory used by that file
  56. FH_Length rs.l 1 ; Length (in bytes) on the file.
  57. rsreset
  58. Current_Filename
  59. ds.b 108+108 ; just in case of maximum
  60. even
  61. CRLF dc.b 10,13,0
  62. even
  63. File_Routine_Pointer dc.l 0 ; *SET BY EACH ROUTINE THAT USES IT
  64. Current_File dc.l 0
  65. lock dc.l 0
  66. dosbase dc.l 0
  67. doslib dc.b "dos.library",0
  68. even
  69. Info_Block dc.l Info_Structure
  70. ds.b 4
  71. Info_Structure ds.b 260
  72. even
  73. LoadAnyOldFile
  74. ; a0 sent with pointer to file handle structure
  75. ; d0 returned with error number, d0 = 0 = no errors
  76. movem.l d1-d7/a0-a6,-(sp)
  77. move.l a0,File_Handle_Structure
  78. cmp.l #MEM_FIX,FH_Memory_Type(a0) ; requires allocation?
  79. beq Dont_Need_To_Deallocate
  80. tst.l FH_Memory(a0)
  81. beq Dont_Need_To_Deallocate
  82. move.l FH_Memory(a0),a1
  83. move.l FH_Length(a0),d0
  84. move.l EXEC,a6
  85. jsr -210(a6) ; de-allocate
  86. move.l File_Handle_Structure,a0
  87. clr.l FH_Memory(a0)
  88. clr.l FH_Length(a0)
  89. Dont_Need_To_Deallocate
  90. move.l FH_FileName(a0),d1
  91. move.l #-2,d2 ; mode read
  92. move.l dosbase,a6
  93. jsr -84(a6) ; lock
  94. tst.l d0
  95. beq DOS_Error_while_loading
  96. move.l d0,lock
  97. move.l lock,d1
  98. move.l Info_Block,d2
  99. move.l dosbase,a6
  100. jsr -102(a6)
  101. tst.l d0
  102. beq DOS_Error_while_loading
  103. move.l Info_Block,a1
  104. move.l 124(a1),d0
  105. move.l File_Handle_Structure,a0
  106. move.l d0,FH_Length(a0)
  107. cmp.l #MEM_FIX,FH_Memory_Type(a0) ; requires allocation?
  108. beq Dont_Need_To_allocate
  109. move.l exec,a6
  110. move.l File_Handle_Structure,a0
  111. move.l FH_Memory_Type(a0),d1
  112. jsr -198(a6) ; allocate
  113. tst.l d0
  114. beq Couldnt_Allocate_File
  115. move.l File_Handle_Structure,a0
  116. move.l d0,FH_Memory(a0)
  117. Dont_Need_To_allocate
  118. move.l FH_FileName(a0),d1
  119. move.l #MODE_OLD,d2
  120. move.l dosbase,a6
  121. jsr OPEN(a6)
  122. tst.l d0
  123. beq DOS_Error_while_loading
  124. move.l d0,Current_File_Handle
  125. move.l File_Handle_Structure,a0
  126. move.l Current_File_Handle,d1
  127. move.l FH_Memory(a0),d2
  128. move.l FH_Length(a0),d3
  129. move.l dosbase,a6
  130. jsr READ(a6)
  131. tst.l d0
  132. bne.s File_Loaded_Ok
  133. move.l Current_File_Handle,d1
  134. move.l dosbase,a6
  135. jsr CLOSE(a6)
  136. move.l lock,d1
  137. move.l dosbase,a6
  138. jsr -90(a6) ; Un-lock
  139. bra.s DOS_Error_while_loading
  140. File_Loaded_Ok
  141. move.l Current_File_Handle,d1
  142. move.l dosbase,a6
  143. jsr CLOSE(a6)
  144. move.l lock,d1
  145. move.l dosbase,a6
  146. jsr -90(a6) ; Un-lock
  147. moveq.l #0,d0
  148. bra.s exit_load_routine
  149. Couldnt_Allocate_File
  150. move.l #1001,d0
  151. bra.s exit_load_routine
  152. move.l lock,d1
  153. move.l dosbase,a6
  154. jsr -90(a6) ; Un-lock
  155. DOS_Error_while_loading
  156. movem.l a0-a6/d0-d7,-(sp)
  157. move.l dosbase,a6
  158. move.l #50*5,d1
  159. jsr delay(a6)
  160. move.l dosbase,a6
  161. jsr -132(a6)
  162. movem.l (sp)+,a0-a6/d0-d7
  163. exit_load_routine
  164. movem.l (sp)+,d1-d7/a0-a6
  165. rts
  166. SaveAnyOldFile
  167. ; a0 sent with pointer to file handle structure
  168. ; d0 returned with error number, d0 = 0 = no errors
  169. movem.l d1-d7/a0-a6,-(sp)
  170. move.l a0,File_Handle_Structure
  171. move.l FH_FileName(a0),d1
  172. move.l #MODE_NEW,d2
  173. move.l dosbase,a6
  174. jsr OPEN(a6)
  175. tst.l d0
  176. beq DOS_Error_while_saving
  177. move.l d0,Current_File_Handle
  178. move.l File_Handle_Structure,a0
  179. move.l Current_File_Handle,d1
  180. move.l FH_Memory(a0),d2
  181. move.l FH_Length(a0),d3
  182. move.l dosbase,a6
  183. jsr Write(a6)
  184. tst.l d0
  185. bne.s File_Saved_Ok
  186. move.l Current_File_Handle,d1
  187. move.l dosbase,a6
  188. jsr CLOSE(a6)
  189. bra.s DOS_Error_while_saving
  190. File_Saved_Ok
  191. move.l Current_File_Handle,d1
  192. move.l dosbase,a6
  193. jsr CLOSE(a6)
  194. moveq.l #0,d0
  195. bra.s exit_save_routine
  196. DOS_Error_while_saving
  197. movem.l a0-a6/d0-d7,-(sp)
  198. move.l dosbase,a6
  199. move.l #50*5,d1
  200. jsr delay(a6)
  201. move.l dosbase,a6
  202. jsr -132(a6)
  203. movem.l (sp)+,a0-a6/d0-d7
  204. exit_save_routine
  205. movem.l (sp)+,d1-d7/a0-a6
  206. rts
  207. File_Handle_Structure dc.l 0
  208. Current_File_Handle dc.l 0
  209. char_position dc.w 0
  210. get_pressed_key jmp Read_Keyboard
  211. ;/* Clear_Word_Chunk
  212. * ----------------
  213. * $Inputs: a0.l = Window Structure
  214. * d0.w = Top (in words)
  215. * d1.w = Left
  216. * d2.w = Width (in words)
  217. * d3.w = Height
  218. */
  219. Clear_Word_Chunk
  220. ifnd hard_only
  221. bsr own_the_blitter
  222. endc
  223. movem.l a1-a6,-(sp)
  224. move.l screen_mem(a0),a2
  225. move.l #main_screen_struct,a1
  226. andi.l #$FFFF,d0
  227. asl.w #1,d0
  228. add.l d0,a2
  229. asl.w #1,d2
  230. move.w screen_x_size(a1),d4
  231. asr.w #3,d4
  232. mulu.w d4,d1
  233. add.l d1,a2
  234. sub.w d2,d4 ;overall modulus
  235. asl.w #6,d3
  236. lsr.w #1,d2 ; put back to words for blit
  237. or.w d2,d3
  238. move.w #2-1,d7 ; only first two planes
  239. clear_chunk
  240. btst #14,DMACONR(a6)
  241. bne.s clear_chunk
  242. move.w #$0000,bltadat(a6)
  243. move.l a2,bltdpt(a6)
  244. move.w d4,bltdmod(a6)
  245. move.w #$01f0,bltcon0(a6)
  246. clr.w bltcon1(a6)
  247. move.l #$ffffffff,bltafwm(a6)
  248. move.w d3,bltsize(a6)
  249. moveq #0,d0
  250. move.w screen_x_size(a1),d0
  251. asr.w #3,d0
  252. mulu screen_y_size(a1),d0
  253. add.l d0,a2
  254. dbra d7,clear_chunk
  255. movem.l (sp)+,a1-a6
  256. ifnd hard_only
  257. bsr disown_the_blitter
  258. endc
  259. rts
  260. own_the_blitter
  261. movem.l d0-d7/a0-a6,-(sp)
  262. move.l graphics_lib_ptr,a6
  263. jsr ownblitter(a6)
  264. movem.l (sp)+,d0-d7/a0-a6
  265. rts
  266. disown_the_blitter
  267. movem.l d0-d7/a0-a6,-(sp)
  268. move.l graphics_lib_ptr,a6
  269. jsr disownblitter(a6)
  270. movem.l (sp)+,d0-d7/a0-a6
  271. rts
  272. path.txt: dc.b 'scratch:',0
  273. cnop 0,4
  274. display_file_request:
  275. movem.l d1-d7/a0-a6,-(sp)
  276. bsr switch_screens
  277. lea path.txt,a0 ;save default path...
  278. move.l a0,a1
  279. lea current_filename,a2 ;filename buffer
  280. bsr reqon
  281. movem.l (sp)+,d1-d7/a0-a6
  282. tst.l d0
  283. beq.s no_call
  284. move.l File_Routine_Pointer,d0
  285. beq.s no_call
  286. move.l a0,-(sp)
  287. move.l d0,a0
  288. jsr (a0)
  289. move.l (sp)+,a0
  290. tst.l d0
  291. rts
  292. no_call: bsr Remove_File_Request
  293. tst.l d0
  294. rts
  295. Remove_File_Request
  296. movem.l d0-a6,-(sp)
  297. bsr DeAllocReqMem
  298. bsr CloseReqTools
  299. bsr switch_screens
  300. movem.l (sp)+,d0-a6
  301. rts
  302. cnop 0,4
  303. reqon: move.l a2,a5
  304. lea path(pc),a3
  305. move.l a0,(a3) ;default path...
  306. move.l a1,TitlePtr-path(a3)
  307. bsr OpenReqTools
  308. bsr AllocReqMem
  309. lea Wild_Tags(pc),a0 ;standard file req
  310. lea Blk_Tags(pc),a1 ;we want block attr`s
  311. move.l TitlePtr(pc),a3 ;requester msg
  312. bsr _RequestFile
  313. tst.l d0
  314. rts
  315. cnop 0,4
  316. OpenReqTools: lea RTName(pc),a1
  317. move.l 4.w,a6
  318. jsr -408(a6)
  319. lea _ReqToolsBase(pc),a0
  320. move.l d0,(a0)
  321. rts
  322. cnop 0,4
  323. CloseReqTools: move.l 4.w,a6
  324. move.l _ReqToolsBase(pc),d0
  325. beq.s RTNotOpen
  326. move.l d0,a1
  327. jsr -414(a6)
  328. lea _ReqToolsBase(pc),a0
  329. clr.l (a0)
  330. RTNotOpen rts
  331. *-------------- Allocate File-Requester structure memory..
  332. RTFI_Dirs = $80000032
  333. RTFI_Flags = $80000028
  334. TAG_DONE = 0
  335. rtfi_Dir = $10
  336. RT_FILEREQ = $0
  337. ifd TREV
  338. RT_FLAGS = $A
  339. endc
  340. FREQF_PATGAD = $1
  341. _LVOrtAllocRequestA = $FFFFFFE2
  342. _LVOrtFreeRequest = $FFFFFFDC
  343. _LVOrtFileRequestA = $FFFFFFCA
  344. _LVOrtChangeReqAttrA = $FFFFFFD0
  345. cnop 0,4
  346. AllocReqMem move.l #RT_FILEREQ,d0
  347. suba.l a0,a0
  348. move.l _ReqToolsBase(pc),a6
  349. jsr _LVOrtAllocRequestA(a6)
  350. lea RTReqPtr(pc),a0
  351. move.l d0,(a0)
  352. rts
  353. cnop 0,4
  354. DeAllocReqMem: move.l RTReqPtr(pc),d0
  355. beq.s AllocNot
  356. move.l d0,a1
  357. move.l _ReqToolsBase(pc),d1
  358. beq.s AllocNot
  359. move.l d1,a6
  360. jsr _LVOrtFreeRequest(a6)
  361. lea RTReqPtr(pc),a0
  362. clr.l (a0)
  363. AllocNot rts
  364. * $Inputs: a0.l = wildcards, etc . tags
  365. * a1.l = individual attribute tags
  366. * a2.l = body of requester..
  367. * a3.l = title
  368. *
  369. * $Outputs: d0.l = d0 (result-code)
  370. cnop 0,4
  371. _RequestFile: lea TempName(pc),a2
  372. sf.b (a2)
  373. bsr Do_FileRequest
  374. tst.l d0
  375. beq.s no_name
  376. move.l RTReqPtr(pc),a1 ;& a path name!
  377. move.l rtfi_Dir(a1),a0
  378. move.l a5,a1
  379. bytecopy: move.b (a0)+,(a1)+
  380. bne.s bytecopy
  381. cmp.b #":",-2(a1)
  382. bne.s add_slash
  383. tst.b -(a1)
  384. bra.s no_slash
  385. add_slash: tst.b -(a1)
  386. move.b #"/",(a1)+
  387. no_slash: move.l a2,a0
  388. bytecopy2: move.b (a0)+,(a1)+
  389. bne.s bytecopy2
  390. clr.b (a1)+
  391. move.l a5,a0
  392. moveq #1,d0 ;return success on name..
  393. no_name: tst.l d0
  394. rts
  395. cnop 0,4
  396. Do_FileRequest movem.l d1-d7/a0-a6,-(sp)
  397. move.l a1,a0
  398. move.l RTReqPtr(pc),a1 ;& a path name!
  399. move.l _ReqToolsBase(pc),a6
  400. jsr _LVOrtChangeReqAttrA(a6)
  401. move.l RTReqPtr(pc),a1
  402. jsr _LVOrtFileRequestA(a6)
  403. movem.l (sp)+,d1-d7/a0-a6
  404. rts
  405. cnop 0,4
  406. RTName: dc.b 'reqtools.library',0
  407. even
  408. Wild_Tags: dc.l RTFI_Flags,FREQF_PATGAD
  409. dc.l TAG_DONE
  410. Blk_Tags: dc.l RTFI_Dirs
  411. path dc.l 0
  412. dc.l TAG_DONE
  413. _ReqToolsBase: ds.l 1
  414. RTReqPtr: ds.l 1
  415. TitlePtr: ds.l 1
  416. LoadPtr: ds.l 1
  417. TempName: ds.b 256
  418. even