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 / flex < prev    next >
Text File  |  1984-05-02  |  9KB  |  462 lines

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