Mirror of CollapseOS
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

594 linhas
7.7KB

  1. ; The include file with tape utilities exposed as commands, for kernel build
  2. ; *** A library file for MMAP-TAPE bridge, which can be included with the userspace versions of the routines
  3. ; (user routines are below, addressed by the jump table)
  4. ; required syscalls:
  5. ; strncmp
  6. ; fsAlloc
  7. ; fsblkTell
  8. ; the applications require:
  9. ; parseDecimal
  10. ; fsFindFN
  11. .inc "user.h"
  12. .org 0x711f ; 0x7492-0x373
  13. ; for CUTSV 1st block
  14. .equ sv_buffer TAP_RAMEND
  15. ; Parsed arguments
  16. ; block, then byte length
  17. .equ par_blocklen @+256
  18. ; length of the parsed filename
  19. .equ par_namelen @+3
  20. ; pointer to filename in the args
  21. .equ par_filename @+1
  22. .equ TAPUTIL_RAMEND @+2
  23. jp tpbinsv
  24. jp tpbinld
  25. jp tphead
  26. jp tpfilsv
  27. jp tpfilld
  28. jp tpcfssv
  29. jp tpcfsld
  30. jp tpcutsv
  31. ; t_CFSHead
  32. ; t_parseName
  33. ; t_parseOver
  34. ; t_chainEnd
  35. ; t_newFile
  36. ; t_save
  37. ; t_load
  38. ; t_stkStor
  39. ; t_stkRet
  40. ; CFS header preparation (for CUTSV 1st block, for FILLD newfile)
  41. t_CFSHead:
  42. push hl
  43. push bc
  44. push de
  45. ; position in ix
  46. push ix
  47. ld hl, sv_buffer
  48. push hl
  49. pop de
  50. inc de
  51. ld bc, 32
  52. xor a
  53. ld (hl), a
  54. ldir ; clear the header
  55. ld ix, sv_buffer ; for generality
  56. ld a, 'C'
  57. ld (ix+0), a
  58. ld a, 'F'
  59. ld (ix+1), a
  60. ld a, 'S'
  61. ld (ix+2), a
  62. ld hl, par_blocklen ; block length stored by parser
  63. ld a, (hl)
  64. ld (ix+3), a
  65. inc hl ; actual file length stored by parser
  66. ld a, (hl)
  67. ld (ix+4), a
  68. inc hl
  69. ld a, (hl)
  70. ld (ix+5), a
  71. ld bc, 6
  72. ld hl, sv_buffer
  73. add hl, bc
  74. push hl
  75. pop de ; destination for the parsed filename transfer
  76. ld hl, par_namelen ; filename length stored by the parser
  77. ld c, (hl)
  78. ld hl, (par_filename) ; filename pointer stored by the parser
  79. ldir ; copy filename
  80. pop ix
  81. pop de
  82. pop bc
  83. pop hl
  84. ret
  85. ; Parsing of the filename (HL)
  86. t_parseName:
  87. push de
  88. push bc
  89. push hl
  90. push hl
  91. pop de
  92. ld hl, par_filename
  93. ld (hl), e
  94. inc hl
  95. ld (hl), d
  96. pop hl
  97. ld c, 0
  98. .loop:
  99. ld a, (hl)
  100. cp 32
  101. jr z, .end
  102. inc c
  103. inc hl
  104. jr .loop
  105. .end:
  106. push hl
  107. ld hl, par_namelen
  108. ld (hl), c
  109. pop hl
  110. inc hl ; the next argument in HL
  111. pop bc
  112. pop de
  113. ret
  114. ; Parsing of the overwrite flag 'o'
  115. t_parseOver:
  116. push de
  117. ld de, .flag
  118. ld a, 1
  119. call strncmp ; Z - equal (overwrite)
  120. pop de
  121. ret
  122. .flag:
  123. .db 'o'
  124. ; Search for CFS chain end (for binary/CFS loading)
  125. t_chainEnd:
  126. push hl
  127. ld a, (par_blocklen)
  128. ld hl,.dummy ; placeholder name
  129. call fsAlloc
  130. call fsblkTell ; position in HL
  131. ld bc, MMAP_START
  132. add hl, bc
  133. push hl
  134. pop ix ; chainend in ix
  135. pop hl
  136. ret
  137. .dummy:
  138. .db '@', 0
  139. ; New file at the CFS chain end (for binary loading into CFS)
  140. t_newFile:
  141. push de
  142. push hl
  143. push bc
  144. call t_chainEnd
  145. call t_CFSHead
  146. ; start of the new file in ix
  147. push ix
  148. pop de
  149. ld hl, sv_buffer
  150. ld bc, 32
  151. ldir ; copy header to CFS
  152. push de
  153. pop ix ; loading position in ix
  154. pop bc
  155. pop hl
  156. pop de
  157. ret
  158. ; SAVE-BYTES ROM call
  159. ; header/bytes flag set outside
  160. t_save:
  161. ;ld ix,addr
  162. ;ld de,len
  163. ;ld a,head
  164. push iy
  165. ld iy, IYBAS
  166. ; one can not call directly, as RST8 is then called upon break
  167. call 0x04c6 ; SA-BYTES+4 to skip SA/LDRET
  168. jr t_ldret
  169. ; LOAD-BYTES ROM call
  170. t_load:
  171. ;ld ix,addr
  172. ;ld de,len
  173. ;ld a,head
  174. push iy
  175. ld iy, IYBAS
  176. scf
  177. ; one can not call directly, as RST8 is then called upon break
  178. inc d
  179. ex af,af'
  180. dec d
  181. di
  182. ld a, 15
  183. out (254), a
  184. call 1378 ; jump into LD-BYTES
  185. t_ldret:
  186. ld a, (23624) ; restore border
  187. and 0x38
  188. rrca
  189. rrca
  190. rrca
  191. out (254),a
  192. pop iy
  193. ei
  194. ret
  195. ; Stack store (CALL)
  196. t_stkStor:
  197. ld (.stkbc), bc
  198. pop bc
  199. ld (.stkret), bc
  200. ld bc, (.stkbc)
  201. push hl
  202. push bc
  203. push de
  204. push ix
  205. push iy
  206. ld bc, (.stkret)
  207. push bc
  208. ret
  209. .stkbc:
  210. .dw 0
  211. .stkret:
  212. .dw 0
  213. ; Stack restore (JP)
  214. t_stkRet:
  215. pop iy
  216. pop ix
  217. pop de
  218. pop bc
  219. pop hl
  220. ret
  221. ; 2-sec pause between savings
  222. t_pause:
  223. push bc
  224. ld b,100
  225. .loop:
  226. push bc
  227. halt
  228. pop bc
  229. djnz .loop
  230. pop bc
  231. ret
  232. ; *** APPLICATIONS ***
  233. tpbinsv:
  234. call t_stkStor
  235. call parseDecimal
  236. jr z, .arglen
  237. ld de, MMAP_LEN
  238. .arglen:
  239. ld ix, MMAP_START
  240. ld a, 255
  241. call t_save
  242. xor a
  243. jp t_stkRet
  244. tpbinld:
  245. call t_stkStor
  246. call parseDecimal
  247. jp nz, t_stkRet
  248. inc hl
  249. call t_parseOver
  250. jr z, .ovlen
  251. push de
  252. call t_chainEnd
  253. pop de
  254. jr .applen
  255. .ovlen:
  256. ld ix, MMAP_START
  257. .applen:
  258. ld a, 255
  259. call t_load
  260. xor a
  261. jp t_stkRet
  262. tphead:
  263. xor a
  264. inc a
  265. call t_stkStor
  266. call parseDecimal
  267. jp nz, t_stkRet ; ERR no addr
  268. ld ix, sv_buffer
  269. ld a,3
  270. ld (ix+0),3
  271. ld (ix+13),e
  272. ld (ix+14),d
  273. inc hl
  274. call parseDecimal
  275. jp nz, t_stkRet ; ERR no len
  276. ld ix, sv_buffer
  277. ld (ix+11),e
  278. ld (ix+12),d
  279. ld de, 17
  280. xor a
  281. call t_save
  282. xor a
  283. jp t_stkRet
  284. tpfilsv:
  285. xor a
  286. inc a
  287. call t_stkStor
  288. call fsFindFN
  289. jp nz, t_stkRet ; ERR file not found
  290. call fsblkTell ; position in HL
  291. ld bc, MMAP_START
  292. add hl, bc
  293. push hl
  294. pop ix
  295. ld b, (ix+3) ; blocks
  296. ;xor a
  297. ;or b
  298. ;jp z, t_stkRet
  299. ld de, 256
  300. ld hl, 0
  301. .loop:
  302. add hl,de
  303. djnz .loop
  304. ld bc,32
  305. sbc hl,bc
  306. push hl
  307. pop de
  308. push ix
  309. pop hl
  310. add hl,bc
  311. push hl
  312. pop ix
  313. ld a, 255
  314. call t_save
  315. xor a
  316. jp t_stkRet
  317. tpfilld:
  318. call t_stkStor
  319. ld (par_filename), hl
  320. ld b,26
  321. ld c,0
  322. .loop:
  323. ld a,(hl)
  324. cp 32
  325. jr z, .namlen
  326. inc c
  327. inc hl
  328. djnz .loop
  329. .namlen:
  330. ld a, c
  331. ld (par_namelen), a
  332. inc hl
  333. call parseDecimal
  334. jp nz, t_stkRet ; something wrong
  335. ld (par_blocklen+1), de
  336. inc hl
  337. push hl
  338. push de
  339. pop hl
  340. ld de, 256
  341. ld b,1
  342. .div:
  343. sbc hl,de
  344. jr c, .blklen
  345. inc b
  346. jr .div
  347. .blklen:
  348. ld a,b
  349. ld (par_blocklen), a
  350. pop hl
  351. call t_parseOver
  352. jr z, .whole
  353. call t_newFile ; load to ix
  354. jr .load
  355. .whole:
  356. call t_CFSHead ; in sv_buffer
  357. ld de, MMAP_START
  358. ld hl, sv_buffer
  359. ld bc, 32
  360. ldir
  361. push de
  362. pop ix
  363. .load:
  364. ld de, (par_blocklen+1)
  365. ld a,255
  366. call t_load
  367. xor a
  368. jp t_stkRet
  369. tpcfssv:
  370. call t_stkStor
  371. xor a
  372. cp (hl)
  373. jp z, .whole
  374. call fsFindFN
  375. jp nz, .err
  376. call fsblkTell ; position in HL
  377. ld bc, MMAP_START
  378. add hl, bc
  379. push hl
  380. pop ix
  381. ld b, (ix+3) ; blocks
  382. ;xor a
  383. ;or b
  384. ;jp z, t_stkRet
  385. ld de, 256
  386. jr .len
  387. .whole:
  388. ld de, 256
  389. ld ix, MMAP_START
  390. ld hl, MMAP_LEN
  391. ld b,0
  392. .div:
  393. sbc hl,de
  394. jr c, .len
  395. inc b
  396. jr .div
  397. .len:
  398. ; blocklen in B
  399. xor a
  400. or b
  401. jp z, .err
  402. push ix
  403. pop hl
  404. sbc hl,de
  405. push hl
  406. .loop:
  407. pop ix
  408. ld de, 256
  409. add ix, de
  410. ld a, 255
  411. push ix
  412. push bc
  413. call t_save
  414. pop bc
  415. call t_pause
  416. djnz .loop
  417. pop ix
  418. xor a
  419. jp t_stkRet
  420. .err:
  421. xor a
  422. inc a
  423. jp t_stkRet
  424. tpcfsld:
  425. call t_stkStor
  426. call parseDecimal
  427. jr z, .arglen
  428. .deflen:
  429. ld b, 1
  430. jr .flag
  431. .arglen:
  432. xor a
  433. or d
  434. jr nz, .deflen
  435. ld b, e
  436. ld a, b
  437. ld (par_blocklen), a
  438. .flag:
  439. push bc ; cycle counter
  440. inc hl
  441. call t_parseOver
  442. jr z, .whole
  443. call t_chainEnd ; position in ix
  444. jr .load
  445. .whole:
  446. ld ix, MMAP_START
  447. .load:
  448. pop bc
  449. ld de, 256
  450. ; blocklen in B
  451. push ix
  452. pop hl
  453. sbc hl,de
  454. push hl
  455. .loop:
  456. pop ix
  457. ld de, 256
  458. add ix, de
  459. ld a, 255
  460. push ix
  461. push bc
  462. call t_load
  463. pop bc
  464. djnz .loop
  465. pop ix
  466. xor a
  467. jp t_stkRet
  468. tpcutsv:
  469. call t_stkStor
  470. push hl
  471. ld hl, MMAP_START
  472. ld de, .cfslabel
  473. ld a,3
  474. call strncmp
  475. jr nz, .noerr
  476. inc a ; 'CFS'=ERR
  477. pop hl
  478. jp t_stkRet
  479. .cfslabel:
  480. .db "CFS",0
  481. .noerr:
  482. pop hl
  483. cp (hl)
  484. jp z, t_stkRet ; no name provided
  485. ld (par_filename), hl
  486. ld b,26
  487. ld c,0
  488. .loop:
  489. ld a,(hl)
  490. cp 32
  491. jr z, .namlen
  492. inc c
  493. inc hl
  494. djnz .loop
  495. .namlen:
  496. ld a, c
  497. ld (par_namelen), a
  498. inc hl
  499. call parseDecimal
  500. jr z, .arglen
  501. ld de, MMAP_LEN
  502. ld b, 0
  503. jr .deflen
  504. .arglen:
  505. ld b,1
  506. .deflen:
  507. xor a
  508. or d
  509. or e
  510. jp z, t_stkRet ; len=0
  511. ld (par_blocklen+1), de
  512. push de
  513. pop hl
  514. ld de, 256
  515. .div:
  516. sbc hl,de
  517. jr c, .blklen
  518. inc b
  519. jr .div
  520. .blklen:
  521. ld a,b
  522. ld (par_blocklen), a
  523. call t_CFSHead
  524. push bc
  525. ld de, sv_buffer+32
  526. ld hl, MMAP_START
  527. ld bc, 224
  528. ldir
  529. push hl
  530. ld ix, sv_buffer
  531. ld de, 256
  532. ld a, 255
  533. call t_save ; 1st block+meta
  534. pop ix
  535. pop bc
  536. xor a
  537. dec b
  538. jp z, t_stkRet
  539. ld de, 256
  540. push ix
  541. pop hl
  542. sbc hl,de
  543. push hl
  544. .svloop:
  545. pop ix
  546. ld de, 256
  547. add ix, de
  548. ld a, 255
  549. push ix
  550. push bc
  551. call t_save
  552. pop bc
  553. call t_pause
  554. djnz .svloop
  555. pop ix
  556. xor a
  557. jp t_stkRet
  558. ;end