home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / UNIFLEX / UNIFLEX / UniFLEX_Std.Utils1.tar.Z / UniFLEX_Std.Utils1.tar / utils1 / mu-flex < prev    next >
Text File  |  1981-09-01  |  9KB  |  434 lines

  1.  opt pag
  2.  ttl FLEX Copy and Directory
  3.  pag
  4. * FLEX Copy and Directory Utility
  5. *
  6. * Copyright (c) 1980 by
  7. * Technical Systems Consultants, Inc.
  8. * Box 2570, West Lafayette, IN 47906
  9. *
  10. * This utility runs under UniFLEX and when called
  11. * with no parameters, performs a directory listing
  12. * of the FLEX disk in drive #1.  If filenames are
  13. * given, it will copy the specified FLEX file to
  14. * the specified UniFLEX file.  The FLEX disk must
  15. * be single-density and in drive #1.
  16. * Syntax is as follows:
  17. *
  18. *      ++ flex <FLEX filename> <UniFLEX filename> [+r]
  19. *
  20. * where the <FLEX filename> defaults to an extension of
  21. * .TXT.  The optional "+r" parameter causes the file to
  22. * be copied in a raw mode (no space expansion).  All
  23. * FLEX random files will be automatically copied in the
  24. * raw mode with the sector map sectors removed.
  25.  
  26.  
  27.  info UniFLEX flex
  28.  info Version 1, Released August 25, 1980
  29.  info Copyright, (C) 1980, by
  30.  info Technical Systems Consultants, Inc.
  31.  info All rights reserved.
  32.  
  33.  
  34.  
  35. * equates
  36.  
  37. indx equ 1
  38. term equ 5
  39. open equ 10
  40. create equ 11
  41. read equ 12
  42. write equ 13
  43. seek equ 14
  44. status equ 28
  45.  
  46.  
  47.  org $0000
  48.  
  49. * start of program
  50.  
  51. flex ldx #obuf initialize output
  52.  stx obfptr
  53.  clr raw clear raw copy flag
  54.  clr lastch null last character
  55.  
  56. * ensure single user mode
  57.  
  58. * sys status,utmp,rdbuf
  59. * bes stater
  60. * ldd rdbuf+11
  61. * beq opnrd skip if single user
  62. *stater ldx #mumode else, report error
  63. * lbra pexit
  64.  
  65. * open flex disk for read
  66.  
  67. opnrd ldx #iopen point to indirect open
  68.  sys indx do indirect open
  69.  lbes ferror
  70.  std ifd save input file descriptor
  71.  
  72. * see if copy or dir
  73.  
  74.  ldd 0,s get argument count
  75.  cmpd #1 no parameters means dir
  76.  lbeq dir
  77.  cmpd #4 4 means copy w/ option
  78.  bne lookup skip if no option
  79.  ldd [8,s] get option
  80.  cmpd #$2B72 is it "+r" for raw?
  81.  bne lookup skip if not
  82.  stb raw set flag
  83.  
  84. * look for flex file in directory
  85.  
  86. lookup ldd #$0005 directory start T&S
  87.  std rdbuf put in fwd link
  88.  ldu #rdbuf+256 directory pointer
  89. look lbsr nxtent check next entry
  90.  lbeq notfnd skip if end of dir
  91.  lbsr compar found file entry?
  92.  bne look loop if not
  93.  
  94. * found flex file, create uniflex file
  95.  
  96. opnwrt ldx #icreat point to indirect create
  97.  ldy 6,s get filename pointer
  98.  sty 1,x put in indirect function
  99.  sys indx do indirect create
  100.  lbes uerror
  101.  std ofd save output file descriptor
  102.  
  103. * check flex file for random (file sector map)
  104.  
  105.  lda 19,u get random indicator
  106.  beq look2 skip if sequential
  107.  lda #2 set sector skip count
  108.  sta raw force raw mode copy
  109. look2 sta rnd
  110.  ldd 13,u get start T&S
  111.  std rdbuf set into fwd link
  112. skprnd tst rnd past file sector map?
  113.  beq copy
  114.  lbsr sread read one flex sector
  115.  dec rnd decrement skip count
  116.  bra skprnd
  117.  
  118. * copy file to UniFLEX
  119.  
  120. copy ldu #wrtbuf set buffer pointer
  121. copy1 ldd rdbuf check forward link
  122.  lbeq copy8 finished if zero
  123.  lbsr sread read one sector
  124.  ldx #rdbuf+4
  125.  ldb #252
  126.  tst raw doing raw copy?
  127.  bne copy5 skip if so
  128.  lda lastch get last character
  129. copy2 cmpa #$09 was last char a tab?
  130.  bne copy3
  131.  pshs b
  132.  ldb 0,x+ get expansion count
  133.  lda #$20 setup space
  134. expand sta 0,u+ put spaces in buffer
  135.  decb
  136.  bne expand
  137.  puls b
  138.  bra copy4
  139. copy3 lda 0,x+ get character
  140.  beq copy4 strip nulls
  141.  cmpa #$09 strip tabs
  142.  beq copy4
  143.  sta 0,u+ put in write buffer
  144. copy4 decb
  145.  bne copy2
  146.  sta lastch save last character
  147.  bra copy6
  148. copy5 lda 0,x+ get character from flex
  149.  sta 0,u+ put in write buffer
  150.  decb
  151.  bne copy5
  152. copy6 cmpu #hotzne is buffer full
  153.  blo copy1 get more if not
  154.  lbsr flush flush write buffer
  155.  bra copy1 continue
  156.  
  157. copy8 lbsr flush flush write buffer
  158.  ldx #cpycom print "copy completed"
  159.  lbsr pdata
  160.  ldd #0
  161.  sys term terminate task
  162.  
  163.  
  164. *********************************
  165. * directory printer
  166. *********************************
  167.  
  168. dir ldx #dirhd print dir header
  169.  lbsr pdata
  170.  ldd #$0005 directory start T&S
  171.  std rdbuf put in fwd link
  172.  ldu #rdbuf+256 directory pointer
  173. dir2 lbsr nxtent check next entry
  174.  beq dir8 exit if end of dir
  175.  clrb
  176. dir3 lda b,u get a character
  177.  lbsr outch print it
  178.  incb bump count
  179.  cmpb #8 at end of name?
  180.  bne dir3
  181.  lda #'. output period
  182.  lbsr outch
  183. dir4 lda b,u get character
  184.  lbsr outch
  185.  incb
  186.  cmpb #11 at end of extension?
  187.  bne dir4
  188.  ldd 17,u get file size
  189.  lbsr outdec output decimal value
  190.  lda #$0D
  191.  lbsr outch
  192.  bra dir2 do next entry
  193. dir8 lda #$0D
  194.  lbsr outch
  195.  ldd #0
  196.  sys term terminate task
  197.  
  198.  
  199.  
  200. * routine to point to next flex directory entry
  201.  
  202. nxtent leau 24,u get to next entry
  203.  cmpu #rdbuf+256 past buffer end?
  204.  blo nxten2 skip if so
  205.  ldd rdbuf check forward link
  206.  beq nxten9 exit if end of directory
  207.  lbsr sread read next directory sector
  208.  ldu #rdbuf+16 set pointer
  209. nxten2 lda 0,u check first character
  210.  bmi nxtent if deleted entry, try again
  211. nxten9 rts
  212.  
  213. * compare file name to directory entry
  214.  
  215. compar ldx 6,s point to supplied name
  216.  leay 0,u get dir entry pointer
  217.  ldb #8 set name length
  218. compr1 lda 0,x+ get character
  219.  beq compr3
  220.  cmpa #'. at the extension?
  221.  beq compr2 skip if so
  222.  cmpa 0,y+ compare to dir entry
  223.  bne compr9 exit if not equal
  224.  decb
  225.  bne compr1
  226.  lda 0,x+ get next character
  227.  beq compr3
  228.  cmpa #'. should be period
  229.  bne compr9 exit if not
  230. * check supplied extension
  231. compr2 bra compr4 go compare it
  232. * check default extension
  233. compr3 ldx #dfault point to default ext
  234. compr4 tstb at end of entry?
  235.  beq compr5 skip if so
  236.  lda 0,y+ check next character
  237.  bne compr9
  238.  decb
  239.  bne compr4
  240. compr5 ldb #3 set extension length
  241. compr6 lda 0,x+
  242.  bne compr7
  243.  leax -1,x
  244. compr7 cmpa 0,y+ compare to entry
  245.  bne compr9 exit if not same
  246.  decb
  247.  bne compr6
  248. compr9 rts
  249.  
  250. * read one sector from flex
  251.  
  252. sread ldx #iseek point to indirect seek
  253.  ldd rdbuf get track & sector address
  254.  beq sread9
  255.  std 3,x setup trk & sct for seek
  256.  ldd ifd get input file descriptor
  257.  sys indx do indirect seek
  258.  lbes ferror
  259.  ldd ifd get input file descriptor
  260.  sys read,rdbuf,256 read one sector
  261.  lbes ferror
  262. sread9 rts
  263.  
  264. * routine to flush the write buffer
  265.  
  266. flush ldx #iwrite point to indirect write
  267.  tfr u,d get buffer end pointer
  268.  subd #wrtbuf find size of buffer
  269.  std 3,x put in indirect function
  270.  ldd ofd get output file descriptor
  271.  sys indx do indirect write
  272.  lbes uerror
  273.  ldu #wrtbuf reset buffer pointer
  274.  rts
  275.  
  276. * output value in D in decimal
  277.  
  278. outdec ldx obfptr get output buffer ptr
  279.  pshs a
  280.  lda #$20 setup leading space
  281.  sta 0,x+ save in buffer
  282.  puls a
  283.  clr 0,-s set up bookkeeping
  284.  clr 0,-s
  285.  ldy #conlst point to constants
  286. decst4 cmpd 0,y compare number to constant
  287.  blo decst5
  288.  subd 0,y do subtraction of constant
  289.  inc 1,s bump digits counter
  290.  bra decst4
  291. decst5 pshs a save number
  292.  tst 2,s zero digit?
  293.  bne decst6
  294.  tst 1,s any numbers output yet?
  295.  bne decst6
  296.  lda #$20 set up space
  297.  bra decst7
  298. decst6 lda 2,s get digit count
  299.  inc 1,s set 'got one' flag
  300.  ora #$30 make ascii
  301. decst7 sta 0,x+ save in buffer
  302. decst8 puls a reset number
  303.  clr 1,s clear out digit
  304.  leay 2,y bump constant ptr
  305.  cmpy #conend end of list?
  306.  bne decst4
  307.  leas 2,s clean up stack
  308.  orb #$30 make last digit
  309.  stb 0,x+ save in buffer
  310.  stx obfptr update buffer pointer
  311.  rts
  312.  
  313. * print a string of characters
  314.  
  315. pdata lda 0,x+
  316.  beq pdata2
  317.  bsr outch
  318.  bra pdata
  319. pdata2 rts
  320.  
  321. * output a character
  322.  
  323. outch pshs d,x
  324.  tsta replace blank with space
  325.  bne outch1
  326.  lda #$20
  327. outch1 ldx obfptr point to buffer
  328.  sta 0,x+ put character in
  329.  stx obfptr
  330.  cmpa #$0D was it a return?
  331.  bne outch9 exit if not
  332. * flush the terminal output buffer
  333.  ldd obfptr find no. of chars.
  334.  subd #obuf
  335.  ldx #iprint
  336.  std 3,x
  337.  ldd #1 standard output file
  338.  sys indx do indirect write
  339.  ldx #obuf restore buffer pointer
  340.  stx obfptr
  341. outch9 puls d,x,pc
  342.  
  343. * file not found
  344.  
  345. notfnd ldx #ntfnds print file not found
  346.  
  347. * error handlers
  348.  
  349. pexit bsr pdata print string
  350.  ldd #$00FF
  351.  sys term
  352.  
  353. uerror ldx #uermsg
  354.  bra error
  355. ferror ldx #fermsg
  356.  
  357. error pshs d,x save error no. & msg. address
  358.  ldx #err print error header
  359.  bsr pdata
  360.  ldd 0,s restore error number
  361.  lbsr outdec print the number
  362.  ldx 2,s get message address
  363.  bsr pdata
  364.  puls d,x restore error number
  365.  sys term
  366.  
  367.  
  368. * strings and names
  369.  
  370. dfault fcc 'TXT'
  371. devnam fcc '/dev/fdc1',0
  372. utmp fcc '/act/utmp',0
  373. dirhd fcc $D,'Directory of FLEX disk',$D
  374.  fcc 'Name     Ext   Size',$D
  375.  fcc '----     ---   ----',$D,0
  376. cpycom fcc $D,'Copy completed.',$D,0
  377. mumode fcc $D,'Must be in single-user mode.',$D,0
  378. ntfnds fcc $D,'FLEX file not found.',$D,0
  379. err fcc $d,'UniFLEX error',0
  380. uermsg fcc ' with UniFLEX file.',$d,0
  381. fermsg fcc ' with FLEX file.',$d,0
  382.  
  383. * constants for convert
  384.  
  385. conlst fdb 10000
  386.  fdb 1000
  387.  fdb 100
  388.  fdb 10
  389. conend equ * end of list
  390.  
  391.  
  392.  
  393.  
  394.  org (*+511)&!511
  395.  
  396. * read buffer
  397. rdbuf rmb 256
  398.  
  399. * console output buffer
  400. obuf rmb 128
  401.  
  402. * temporary storage
  403.  
  404. iopen fcb open
  405.  fdb devnam,0
  406. icreat fcb create
  407.  fdb 0,$1B
  408. iseek fcb seek
  409.  fdb 0,0,0
  410. iwrite fcb write
  411.  fdb wrtbuf,0
  412. iprint fcb write
  413.  fdb obuf,0
  414.  
  415. rnd rmb 1
  416. raw rmb 1
  417. lastch rmb 1
  418. ifd rmb 2
  419. ofd rmb 2
  420. obfptr rmb 2
  421.  
  422.  
  423.  org (*+511)&!511
  424.  
  425. * write buffer
  426. wrtbuf equ *
  427.  org $1FFF
  428. wbfend fcb 0
  429.  
  430. hotzne equ wbfend-1023
  431.  
  432.  
  433.  end flex
  434.