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 / page < prev    next >
Text File  |  1983-01-07  |  24KB  |  1,044 lines

  1.  opt pag
  2. *
  3. * info UniFLEX Page
  4. *
  5.  ttl UniFLEX Page Utility
  6.  sttl UniFLEX system definitions
  7.  pag
  8.  lib sysdef
  9.  sttl Page utility definitions
  10.  pag
  11.  info UniFLEX page
  12.  info Version 2.01, Released December 21, 1982
  13.  info Copyright, (C) 1981, by
  14.  info Technical Systems Consultants, Inc.
  15.  info All rights reserved.
  16. *
  17. * Misc. equates
  18. *
  19. FSCHR equ 4 character type device
  20. BUFSIZ equ 2048 size of buffer
  21. HDLENT equ 5 number of lines for header
  22. FTLENT equ 4 number of lines for footer
  23. PGLGTH equ 66-FTLENT
  24.  
  25. dump macro
  26.  pshs cc
  27.  dec boo
  28.  bne hiss
  29.  puls cc
  30.  swi
  31. boo fcb &1
  32. hiss puls cc
  33.  endm
  34.  sttl Page main routine
  35.  pag
  36. **
  37. * page utility--formated list utility
  38. *
  39. * FORM: page [+options] file . . .
  40. *
  41. * WHERE:
  42. *    options are:
  43. *                l: print with line numbers,
  44. *                n: pause every n lines,
  45. *                p###: set page length to ###,
  46. *                f: replace a form feed with carriage returns.
  47. *
  48. *    file is: normal UniFLEX file spec.
  49. *
  50. * Program starts here
  51. *
  52.  org $000
  53. *
  54. * Initialize flags and varaibles
  55. *
  56. page sys cpint,3,bcksls
  57.  lda #$20 ascii space character
  58.  ldx #space point to spaces in header
  59. page0 sta 0,x+ put space character in header
  60.  cmpx #tstr end of spaces?
  61.  blo page0 No, keep putting spaces
  62. *
  63. * Determine type of device the stdout file is on
  64. *
  65.  leau 4,s point to arguments
  66.  ldd #1 set file descriptor = stdout
  67.  sys ofstat,stb get status of device
  68.  lda stb+4 get the device modes
  69.  bita #FSCHR is it a character device?
  70.  beq page1 No, not a chacter device.
  71.  inc chrflg Yes, it is a character device=>set flag
  72. *
  73. * Process any options and get count of options
  74. *
  75. page1 ldx 0,u++ point to the first argument
  76.  beq page5 if 0 then done looking
  77.  lda 0,x+ get the first character of argument
  78.  cmpa #'+ is it a "+" sign?
  79.  beq page15 Yes, process an option
  80.  bra page1 No, then keep looking!
  81. page15 inc optcnt increment the count of options
  82. page2 ldb 0,x+ get the option character
  83.  beq page1 look for more
  84.  cmpb #'l is it an "l"?
  85.  beq page4 Yes, go process!
  86.  cmpb #'p page length option?
  87.  beq page45 Yes!
  88.  cmpb #'f Form Feed option?
  89.  beq page46 Yes!
  90.  cmpb #'9 a digit?
  91.  bhi page2 No, illegal option!!!
  92.  cmpb #'0 a digit?
  93.  blo page2 No, illegal option!!!
  94. *
  95. * Process the "n" option
  96. *
  97. page3 leax -1,x point to first digit
  98.  lbsr getnum process number from args.
  99.  sta nopton number of lines/pause
  100.  leax -1,x point back to character
  101.  bra page2 repeat
  102. *
  103. * Process the "l" option
  104. *
  105. page4 inc lopton set the "l" option flag
  106.  bra page2 go look for more options
  107. *
  108. * Process the "p" option
  109. *
  110. page45 lbsr getnum get number
  111.  suba #FTLENT subtract lines for footer
  112.  bgt pag455 if valid result returned
  113.  lda #PGLGTH default page length
  114. pag455 sta pglnth set page length
  115.  leax -1,x point back to character
  116.  bra page2 repeat
  117. *
  118. * Process "f" option
  119. *
  120. page46 inc noff set no FF flag
  121.  bra page2 repeat
  122. *
  123. * Get true file argument count
  124. *   total args-option args
  125. *
  126. page5 leau 4,s first set to first argument pointer
  127.  ldd 0,s get the argument count
  128.  subb optcnt total args-option args
  129. *
  130. * Test for the stdin file
  131. *
  132.  cmpd #1 is file arg count only 1?
  133.  bhi page6 No, more file arguments than stdin
  134.  ldd #0 if only: "page"  => stdin
  135.  inc stdinf set stdin only flag
  136.  bra page7
  137. *
  138. * Process the files to print
  139. *   get each file and open it for read
  140. *
  141. page6 ldx 0,u++ point to an argument
  142.  beq page11 if 0 then all done!
  143.  lda 0,x get first character of argument
  144.  cmpa #'+ is it a "+" sign?
  145.  beq page6 Yes, then ignore this argument
  146. *
  147. * If not an option then open a file
  148. *
  149.  stx iopn2 setup the system open call
  150.  sys ind,iopn do file open for read
  151.  lbes prter on error!
  152. *
  153. * Read file into buffer
  154. *
  155. page7 pshs d save the file descriptor
  156.  bsr init initialize variables for each file
  157. page8 bsr readln read a line of input
  158.  bes page9 End of file
  159.  lbsr writln write out a line of text
  160.  bra page8 repeat until end of file
  161. *
  162. * End of file!
  163. *
  164. page9 lbsr flushb flush final buffer
  165.  ldd 0,s++ get file descriptor
  166.  beq page6 file is stdin => repeat!
  167.  sys close close the file
  168. page10 bra page6 repeat opening files until done!
  169. page11 tst nopton n option set?
  170.  beq pag111 No, not set!
  171.  lbsr writcr put out last CR
  172. pag111 ldd #0 ok status
  173. page12 sys term terminate the task
  174. *
  175. * Handle CTRL-\
  176. *
  177. bcksls ldd #255 set terminate status
  178.  sys term terminate!!!
  179.  sttl Initialize variables for each file
  180.  pag
  181. **
  182. * init--initialize variables for each file
  183. *
  184. * INPUT:
  185. *       x points to the file name
  186. *
  187. init clra
  188.  clrb
  189.  sta lincnt clear line count
  190.  std linnum line number=0
  191.  std pgnum page number=0
  192.  ldd #inbuf point to start of input buffer
  193.  std inend set input buffer to empty
  194.  std inptr start of input buffer
  195.  ldd #outbuf start of output buffer
  196.  std outptr reset output buffer pointer
  197.  ldy #filenm point to file name in header
  198.  tst stdinf stdin only?
  199.  bne init2 Yes, blank fill the filename
  200. init1 lda 0,x+ get character of file name
  201.  beq init2 if at end of file name
  202.  sta 0,y+ put into header
  203.  cmpy #tstr-1 check address
  204.  blo init1 if no overflow
  205. init2 lda #$20 ascii space character
  206. init3 sta 0,y+ pad file name in header with spaces
  207.  cmpy #tstr end of file name in header?
  208.  blo init3 No, keep putting spaces
  209.  rts return
  210.  sttl Read a line of input
  211.  pag
  212. **
  213. * readln--read a line of input
  214. *
  215. * INPUT:
  216. *       stack (2,s) contains the file's file descriptor
  217. *
  218. readln ldy #linbuf point to start of line buffer
  219.  ldx #linbuf point to start of line buffer
  220.  tst nopton n option set?
  221.  bne read22 ignore other processing of options
  222.  lda lincnt get current line count
  223.  bne readl1 Not the top of page
  224. *
  225. * If it is the top of page then get time and page number and
  226. *   print it as a heading.
  227. *
  228.  adda #HDLENT increment line count for header
  229.  sta lincnt replace line count
  230.  sys time,buftim get system time
  231.  ldx #buftim point to system time buffer
  232.  lbsr tmloc get time and date information
  233.  pshs u save the argument pointer
  234.  lbsr tasc convert time and date into ascii string
  235.  puls u restore the argument pointer
  236.  ldd pgnum get the current page number
  237.  addd #1 increment page number
  238.  std pgnum save it
  239.  ldx #pgnm point to string buffer area
  240.  lbsr decst convert pgnum into pgnm
  241.  ldx #header point to the string
  242.  ldy #hedend point to end of header string
  243.  tst noff check for form feed disable
  244.  beq readl5 if no disable in force
  245.  leax 1,x skip form feed
  246.  bra readl5 exit and print heading
  247. readl1 cmpa pglnth at bottom of page?
  248.  blo readl2 No, not at bottom
  249.  bsr footer do footer routine
  250.  clr lincnt reset the line count
  251.  bra readl5 finish up
  252. readl2 lda nopton check for n option
  253.  beq read25 if not set
  254. read22 lda ncount get count for n option
  255.  cmpa nopton ready to set a pause yet?
  256.  blo read25 No, not enough lines!
  257.  lda #$FF UniFLEX pause character
  258.  sta 0,y+ put in line buffer
  259.  clr ncount reset to zero
  260.  bra readl5 finish up
  261. read25 lda #$D Cariage Return
  262.  sta 0,y+ put CR at start of buffer
  263.  tst lopton is l option set?
  264.  beq read35 No, is not set
  265.  ldd linnum get the line number
  266.  addd #1 increment line number
  267.  std linnum save it
  268.  ldx #number
  269.  pshs y save the line buffer pointer
  270.  lbsr decst convert linnum into number
  271.  puls y restore the line buffer pointer
  272. readl3 ldb 0,x+
  273.  stb 0,y+ put line number into front of line buffer
  274.  cmpx #numend end of number?
  275.  blo readl3 Yes, then keep transfering
  276. read35 ldx #linbuf point to start of line buffer
  277. readl4 bsr getch get a character from input buffer
  278.  bes readl6 end of file
  279.  cmpa #$D is character a CR?
  280.  beq read45 Yes, then done
  281.  sta 0,y+ else store the character
  282.  bra readl4 repeat until a CR
  283. read45 inc lincnt next line
  284.  inc ncount bump pause line count
  285. readl5 sty linend put next available position at line end
  286.  clc clear end of file flag
  287. readl6 rts return
  288.  sttl Bottom of page routine
  289.  pag
  290. **
  291. * footer--bottom of page routine
  292. *
  293. * USES:
  294. *     a
  295. *
  296. * Entry:
  297. *     y points to line buffer
  298. *
  299. footer lda #$D CR
  300.  tst noff No FF?
  301.  beq foote1 No!
  302.  sta 0,y+ send out 1 CR to end last line
  303.  sta 0,y+ send out 4 more CRs for footer
  304.  sta 0,y+
  305.  sta 0,y+
  306.  sta 0,y+
  307.  bra foote2
  308. foote1 sta 0,y+ put in one CR to end line
  309. foote2 rts return
  310.  sttl Get input character
  311.  pag
  312. **
  313. * getch--get input character
  314. *
  315. getch pshs x save pointer to line buffer
  316.  ldx inptr pointer into input buffer
  317.  cmpx inend at end of input buffer?
  318.  blo getch2 No, not at end!
  319.  ldd 6,s File Descriptor on the stack!
  320.  sys read,inbuf,BUFSIZ system read
  321.  lbes ioerr error!!?
  322.  ldx #inbuf point to input buffer
  323.  stx inptr reset pointer
  324.  cmpd #0 end of file?
  325.  bne getch1 No, not end of file!
  326.  sec set error bit =>end of file
  327.  puls x,pc restore and return
  328. getch1 addd inptr read count + start of input buffer =
  329.  std inend the end of the input buffer
  330. getch2 lda 0,x+ get a character from buffer
  331.  stx inptr set the input buffer pointer
  332.  clc clear end of file flag
  333.  puls x,pc restore and return
  334.  sttl Write a line of output
  335.  pag
  336. **
  337. * writln--write a line of output
  338. *
  339. * INPUT:
  340. *       x points to the line string to output
  341. *
  342. writln ldy outptr point into output buffer
  343. writl2 lda 0,x+ get chacracter from line or header
  344.  sta 0,y+ put character into output buffer
  345.  cmpy #outend at end of output buffer?
  346.  blo writl5 No, repeat
  347.  ldd #BUFSIZ byte count
  348.  tst chrflg character type device?
  349.  beq writl3 No, not character device
  350.  bsr tpage print on terminal device
  351.  bra writl4 reset and exit
  352. writl3 std iwrtx2 set up system call
  353.  ldd #1 FD=stdout
  354.  sys ind,iwrtx do write
  355.  lbes ioerr error!!!
  356. writl4 ldy #outbuf point to start of output buffer
  357. writl5 cmpx linend at end of line?
  358.  blo writl2 No, keep going!
  359.  sty outptr set output buffer pointer
  360.  rts return
  361.  sttl Print to terminal type device
  362.  pag
  363. **
  364. * tpage--print to terminal type device
  365. *
  366. * Input:
  367. *       d contains the byte count to print
  368. *
  369. * Output:
  370. *       x,d preserved
  371. *
  372. tpage pshs x,d save the write count
  373.  ldx #outbuf point to the output buffer
  374. tpage2 ldd #32 32 bytes at a time
  375.  cmpd 0,s is 32 > remainging bytes in buffer?
  376.  bhs tpage3 Yes, then just print out remaining
  377.  std iwrt2 set system call
  378.  stx iwrt1
  379.  ldd #1 FD=stdout
  380.  sys ind,iwrt do the write
  381.  bes ioerr error!!!
  382.  ldd 0,s get the byte count
  383.  subd #32 subtract the transfered bytes
  384.  std 0,s replace the count
  385.  leax 32,x advance the buffer pointer
  386.  bra tpage2 repeat until byte count < 32
  387. tpage3 stx iwrt1 pointer into output buffer
  388.  puls d get the final byte count
  389.  std iwrt2
  390.  ldd #1 FD=stdout
  391.  sys ind,iwrt do last write
  392.  puls x,pc return
  393.  sttl Convert from number to binary number
  394.  pag
  395. **
  396. * getnum--get number
  397. *
  398. * Entry:
  399. *    x points to first digit
  400. *
  401. * Exit:
  402. *    a contains number
  403. *    b is destroyed
  404. *
  405. getnum clra
  406. getnu1 ldb 0,x+ get digit
  407.  beq getnu2 if 0 then done
  408.  cmpb #'9 not a digit?
  409.  bhi getnu2 Yes, not a digit!
  410.  subb #'0 get a binary digit
  411.  blt getnu2 not a digit!
  412.  sta r0 temporary
  413.  lsla multiply by 10
  414.  lsla
  415.  adda r0
  416.  lsla
  417.  aba add in ones digit
  418.  bra getnu1 repeat
  419. getnu2 rts return
  420.  sttl Print error message routine
  421.  pag
  422. **
  423. * prter--print error message
  424. *
  425. * Input:
  426. *       d has the error number
  427. *
  428. prter std erno save the error number
  429.  ldd #2 FD=stderr
  430.  sys write,ermsg1,ERSZ1
  431.  ldx iopn2 get the file name
  432.  stx iwrt1
  433.  clrb set counter to 0
  434. prter2 lda 0,x+ look for end of name
  435.  beq prter3
  436.  incb increment counter of characters
  437.  bra prter2 repeat until done
  438. prter3 std iwrt2 save the count
  439.  ldd #2 FD=stderr
  440.  sys ind,iwrt output filename
  441.  ldd #2 FD=stderr
  442.  sys write,ermsg2,ERSZ2
  443.  ldd erno get error status
  444.  sys term terminate task
  445.  sttl I/O error routine
  446.  pag
  447. **
  448. * ioerr--I/O error routine
  449. *
  450. * Entry:
  451. *     d has erro number in it
  452. *
  453. ioerr std erno save error number
  454.  ldd #2 FD=stderr
  455.  sys write,ermsg3,ERSZ3 write error message
  456.  ldd erno get error number
  457.  sys term terminate task!
  458.  sttl Flush the output buffer
  459.  pag
  460. **
  461. * flushb--flush the output buffer
  462. *
  463. * Uses:
  464. *    y,d
  465. *
  466. flushb ldy outptr point into output buffer
  467.  tst noff No Form Feed?
  468.  beq flus07 No, has FF!
  469.  lda #$D CR
  470. flus01 ldb lincnt test line count
  471.  cmpb pglnth end of page?
  472.  bhi flus07 Yes, done!
  473.  sta 0,y+
  474.  inc lincnt
  475.  bra flus01
  476. flus07 tst nopton n option set?
  477.  bne flus08 Yes, don't put footer!
  478.  lbsr footer
  479. flus08 tfr y,d buffer pointer
  480.  subd #outbuf get byte count for Xfer
  481.  tst chrflg character type device?
  482.  beq flush1 No, not character device
  483.  lbsr tpage print on terminal device
  484.  bra flush2 reset and exit
  485. flush1 std iwrtx2 set up system call
  486.  ldd #1 FD=stdout
  487.  sys ind,iwrtx do write
  488.  bes ioerr error!!!
  489. flush2 ldy #outbuf point to start of output buffer
  490.  sty outptr set output buffer pointer
  491.  rts return
  492.  sttl Write out a final CR
  493.  pag
  494. **
  495. * writcr--write out a final CR
  496. *
  497. * Uses: x,a
  498. *
  499. writcr ldx outptr point at output buffer
  500.  lda #$D Carriage Return
  501.  sta 0,x+
  502.  stx outptr replace the output buffer pointer
  503.  bsr flushb flush the CR
  504.  rts return
  505.  sttl Get time and date routines
  506.  pag
  507. **
  508. * tmloc
  509. *
  510. * Convert time pointed at by x to vector time (local).
  511. *
  512. tmloc ldd 0,x get time
  513.  std ltime
  514.  ldd 2,x
  515.  std ltime+2
  516.  lda 7,x get day light savings flag
  517.  sta dlflg
  518.  clr eutc init flag
  519.  ldd 5,x get time zone
  520.  bpl tmloc2 west of GMT?
  521.  inc eutc if not - set flag
  522.  coma and make pos number
  523.  comb
  524.  addd #1
  525. tmloc2 std r0+2 save time zone
  526.  ldd #60 calculate zone seconds
  527.  std r1+2
  528.  ldd #0 set hi bytes to 0
  529.  std r0
  530.  std r1
  531.  lbsr lmul calculate time zone seconds
  532.  ldd r0 get result
  533.  std tzn save it
  534.  ldd r0+2
  535.  std tzn+2
  536.  lbsr adjtim adjust time for zone
  537.  ldx #ltime point to time
  538.  bsr tmutc convert to vector
  539.  tst dlflg do dlst?
  540.  beq tmloc6
  541.  lbsr chkdl in dlst?
  542.  bne tmloc6
  543. tmloc5 ldd #3600 adjust for dlst
  544.  addd ltime+2
  545.  std ltime+2
  546.  ldd ltime
  547.  adcb #0
  548.  adca #0
  549.  std ltime
  550.  ldx #ltime point to time
  551.  bsr tmutc convert to vector
  552.  inc daylit set daylit flag
  553. tmloc6 ldx #second point to vector
  554.  rts return
  555.  pag
  556. **
  557. * tmutc
  558. *
  559. * Convert the internal system time (4 bytes
  560. * pointed at by X on entry) to an 18 byte
  561. * vector representing the broken down time.
  562. * The time in this form is UTC (Universal
  563. * Coordinated Time).
  564. *
  565. tmutc ldd #0 set daylight savings word
  566.  std daylit
  567.  ldd 0,x get hi word of time
  568.  std r0 save ir divide register
  569.  ldd 2,x get lo word of time
  570.  std r0+2
  571.  ldd #60*60 seconds*minutes constant
  572.  std r1 set up for divide
  573.  lbsr ldiv min*sec=time % 3600
  574.  ldd work hour*day=time / 3600
  575.  pshs d save min*sec
  576.  ldd #24 set up hours per day constant
  577.  std r1
  578.  lbsr ldiv hours= (hour*day) % 24
  579.  ldd work day= (hour*day) / 24
  580.  std hours set hours word
  581.  ldd r0+2 get day number
  582.  std day save the day
  583.  addd #2 add in day bias (Jan 1 80 => Tue)
  584.  std r0 set up for divide
  585.  ldb #7 days per week constant
  586.  stb r1
  587.  lbsr div wday=(day+2) % 7
  588.  ldb work get result
  589.  clra make into word
  590.  std wday set week day
  591.  puls d get min*sec
  592.  std r0 set up for divide
  593.  ldb #60 seconds per minute
  594.  stb r1
  595.  lbsr div seconds= (min*sec) % 60
  596.  ldb work minutes= (min*sec) / 60
  597.  clra
  598.  std second set seconds word
  599.  ldd r0 get minutes
  600.  std minute save it
  601.  pag
  602. *
  603. * continue tutc for year and month data
  604. *
  605.  clr 0,-s clear year counter
  606. tutc2 ldx #ylen point to year length table
  607.  lda 0,s get year number
  608.  bita #$3 is it leap year?
  609.  bne tutc3
  610.  leax 2,x if so, move to long year value
  611. tutc3 ldd day get day number
  612.  cmpd 0,x day in current year?
  613.  blo tutc4 if 'lt' - we got the year!
  614.  subd 0,x subtract off years days
  615.  std day save new day count
  616.  inc 0,s bump the year count
  617.  bra tutc2 repeat
  618. tutc4 std yday set day of year word
  619.  puls b get year count
  620.  addb #80 add to '1980'
  621.  clra make 16 bits long
  622.  std year save the year
  623.  bitb #$3 is it leap year?
  624.  bne tutc5
  625.  ldd #29 if so, set Feb day count to 29
  626.  std mdays+2
  627. tutc5 ldx #mdays point to month-day table
  628.  clr 0,-s set month count to zero
  629.  ldd yday get day of the year
  630. tutc6 cmpd 0,x in the month?
  631.  blo tutc7 if 'lt' - we got the month!
  632.  inc 0,s bump the month counter
  633.  subd 0,x++ subtract of this month's days
  634.  bra tutc6
  635. tutc7 addd #1 add 1 to month day (day 1 is 1 - not 0!)
  636.  std mday save the month day
  637.  puls b get the month
  638.  std month save it
  639.  ldd #28 reset month - day table
  640.  std mdays+2
  641.  rts return
  642.  pag
  643. **
  644. * chkdl
  645. *
  646. * Check if in dlst - return 'eq' if so.
  647. *
  648. chkdl ldd #119 check for last Sun in Apr
  649.  bsr fixtim
  650.  std fstdl first day of dlst
  651.  ldd #303 last Sun in Oct
  652.  bsr fixtim
  653.  std lstdl last day of dlst
  654.  ldd yday get day of year
  655.  cmpd fstdl up to 1st day yet?
  656.  blo chkdl6
  657.  bhi chkdl4
  658.  ldd hours on the 1st day - so
  659.  cmpd #2 is it 2:00 AM yet?
  660.  blo chkdl6
  661.  bra chkdl5
  662. chkdl4 ldd yday get day of year
  663.  cmpd lstdl past last day of dlst?
  664.  bhi chkdl6
  665.  blo chkdl5
  666.  ldd hours on the last day - so
  667.  cmpd #1 is it 1:00 AM yet?
  668.  bhs chkdl6
  669. chkdl5 sez we are in dlst!
  670.  rts return
  671. chkdl6 clz not in dlst
  672.  rts return
  673.  pag
  674. **
  675. * adjtim
  676. *
  677. * Adjust time for time zone.
  678. *
  679. adjtim ldd ltime+2 get time
  680.  tst eutc east of UTC?
  681.  bne adjti2
  682.  subd r0+2 subtract time zone minutes
  683.  std ltime+2
  684.  ldd ltime get hi part
  685.  sbcb r0+1
  686.  sbca r0
  687.  bra adjti4
  688. adjti2 addd r0+2 add in minutes
  689.  std ltime+2
  690.  ldd ltime
  691.  adcb r0+1
  692.  adca r0
  693. adjti4 std ltime save new time
  694. adjti5 rts return
  695. **
  696. * fixtim
  697. *
  698. * Return the closest day to the date in D
  699. * which is a Sunday.
  700. *
  701. fixtim pshs d save day number
  702.  ldd year get year
  703.  bitb #$3 is it leap year?
  704.  puls d
  705.  bne fixti2
  706.  addd #1 if so - bump day number
  707. fixti2 pshs d save day number
  708.  addd #420 add in 420 so no negatives result
  709.  addd wday add in day of week
  710.  subd yday subtract day of year
  711.  std r0 save result
  712.  ldb #7
  713.  stb r1 set up for divide
  714.  bsr div do: (day+420+wday-yday) % 7
  715.  puls d get day number
  716.  subb work
  717.  sbca #0
  718.  rts return day in d
  719.  pag
  720. **
  721. * Divide routines for time conversion use.  'Ldiv'
  722. * divides a 32 bit number (r0 -> r0+3) by a 16 bit
  723. * number (r1 -> r1+1) and produces a 32 bit result
  724. * in r0 and a 16 bit remainder in 'work'.  'Div'
  725. * divides a 16 bit number (r0 -> r0+1) by an 8 bit
  726. * number (r1) and produces a 16 bit result (r0)
  727. * and an 8 bit remainder (work).
  728. *
  729. div lda #17 set up loop counter
  730.  clrb do initialize
  731.  stb work
  732.  bra div2
  733. div1 ldb work
  734.  subb r1 do subtraction
  735.  bcs div2 s3et new work?
  736.  stb work yes!
  737. div2 rol r0+1 do shift left
  738.  rol r0
  739.  rol work
  740.  deca dec the loop count
  741.  bne div1 repeat?
  742.  com r0 fix up result
  743.  com r0+1
  744.  lsr work fix remainder
  745.  rts
  746.  pag
  747. **
  748. * Long divide
  749. *
  750. ldiv ldb #33 set loop counter
  751.  pshs b
  752.  ldd #0 do init
  753.  std work
  754.  bra ldiv2
  755. ldiv1 ldd work do subtraction
  756.  subd r1
  757.  bcs ldiv2 work > r1 ?
  758.  std work set new work value
  759. ldiv2 rol r0+3 do shifting
  760.  rol r0+2
  761.  rol r0+1
  762.  rol r0
  763.  rol work+1
  764.  rol work
  765.  dec 0,s dec the loop count
  766.  bne ldiv1
  767.  com r0 compliment the result
  768.  com r0+1
  769.  com r0+2
  770.  com r0+3
  771.  lsr work adjust the remainder
  772.  ror work+1
  773.  puls b,pc return
  774.  pag
  775. **
  776. * lmul
  777. *
  778. * Long multiply - 32 bits (r0) X 32 bits (r1).
  779. * Result is in r0.
  780. *
  781. lmul ldb #32 set loop count
  782.  pshs b
  783.  ldd #0 init variables
  784.  std work
  785.  std work+2
  786.  lsr r0 do initial shift
  787.  ror r0+1
  788.  ror r0+2
  789.  ror r0+3
  790. lmul1 bcc lmul2 need to add?
  791.  ldd work+2
  792.  addd r1+2
  793.  std work+2
  794.  ldd work
  795.  adcb r1+1
  796.  adca r1
  797.  std work save result
  798. lmul2 ror work do shifting
  799.  ror work+1
  800.  ror work+2
  801.  ror work+3
  802.  ror r0
  803.  ror r0+1
  804.  ror r0+2
  805.  ror r0+3
  806.  dec 0,s dec the loop count
  807.  bne lmul1 repeat?
  808.  puls b,pc return
  809.  pag
  810. **
  811. * tasc
  812. *
  813. * Convert the time vector data (18 bytes) pointed
  814. * at by x into an ascii string.  Return x pointing
  815. * to the string.
  816. *
  817. tasc tfr x,u save vector pointer
  818.  ldx #tstr point to string
  819.  ldd 4,u get hours
  820.  bsr cvt convert to ascii
  821.  leax 1,x skip the ':'
  822.  ldd 2,u get minutes
  823.  bsr cvt convert to ascii
  824.  leax 1,x skip the ':'
  825.  ldd 0,u get seconds
  826.  bsr cvt convert to ascii
  827.  leax 1,x skip space
  828.  ldd 6,u get day of week
  829.  ldy #dtab point to day table
  830.  bsr tasxfr xfr to string
  831.  ldd 10,u get month
  832.  ldy #mtab point to month table
  833.  bsr tasxfr xfr to string
  834.  ldd 8,u get month day
  835.  bsr cvt convert to ascii
  836.  leax 1,x
  837.  ldd #('1<<8)|'9 set up '19'
  838.  std 0,x save in string
  839.  ldd 12,u get year
  840.  cmpd #100 >100 (year 2000 yet?)
  841.  blo tasc4
  842.  subd #100 remove bias
  843.  pshs d save year
  844.  ldd #('2<<8)|'0 set up '20'
  845.  std 0,x set in string
  846.  puls d reset year
  847. tasc4 leax 2,x
  848.  bsr cvt convert year to ascii
  849.  ldx #tstr point to string
  850.  rts return
  851.  pag
  852. **
  853. * tasxfr
  854. *
  855. * Transfer the 3 bytes of ascii indexed by b
  856. * at y to location pointed at by x.
  857. *
  858. tasxfr pshs b index * 3
  859.  aslb
  860.  addb 0,s+
  861.  leay b,y point to indexed data
  862.  ldd 0,y xfr the data to x
  863.  std 0,x++
  864.  lda 2,y
  865.  sta 0,x
  866.  leax 2,x bump string pointer
  867.  rts return
  868. **
  869. * cvt
  870. *
  871. * Convert number in b to ascii at x.
  872. *
  873. cvt lda #'0 set ascii 0
  874. cvt2 cmpb #10 >10?
  875.  blo cvt4
  876.  subb #10 subtract off 10
  877.  inca bump ascii
  878.  bra cvt2 repeat
  879. cvt4 addb #'0 make 1's ascii
  880.  std 0,x++ save ascii at x
  881.  rts return
  882.  sttl Decimal to string convert routine
  883.  pag
  884. **
  885. * decst
  886. *
  887. * Convert the number in D into an ascii string
  888. * representing a decimal number.  The string
  889. * is pointed at by X (X should be set on entry!)
  890. * Also on exit, D has the length of the string.
  891. * The second entry point, 'decstn' will not print
  892. * leading spaces for leading zeroes, but will
  893. * suppress all leading zero info.  All strings
  894. * start with a space.
  895. *
  896. decst pshs x save user pointer
  897.  clr 0,-s set suppression flag
  898.  bra decst2
  899. *
  900. decstn pshs x save user pointer
  901.  clr 0,-s
  902.  inc 0,s set for no fielding
  903. decst2 pshs a
  904.  lda #$20 setup leading space
  905.  sta 0,x+ save in buffer
  906.  puls a
  907.  clr 0,-s set up bookkeeping
  908.  clr 0,-s
  909.  ldy #conlst point to constants
  910. decst4 cmpd 0,y compare number to constant
  911.  blo decst5
  912.  subd 0,y do subtraction of constant
  913.  inc 1,s bump digits counter
  914.  bra decst4
  915. decst5 pshs a save number
  916.  tst 2,s zero digit?
  917.  bne decst6
  918.  tst 1,s any numbers output yet?
  919.  bne decst6
  920.  tst 3,s doing suppression?
  921.  bne decst8
  922.  lda #$20 set up space
  923.  bra decst7
  924. decst6 lda 2,s get digit count
  925.  inc 1,s set 'got one' flag
  926.  ora #$30 make ascii
  927. decst7 sta 0,x+ save in buffer
  928. decst8 puls a reset number
  929.  clr 1,s clear out digit
  930.  leay 2,y bump constant ptr
  931.  cmpy #conend end of list?
  932.  bne decst4
  933.  leas 3,s clean up stack
  934.  orb #$30 make last digit
  935.  stb 0,x+ save in buffer
  936.  clr 0,x null terminate string
  937.  tfr x,d
  938.  subd 0,s calculate string length
  939.  puls x,pc return
  940.  
  941. * constants for convert
  942.  
  943. conlst fdb 10000
  944.  fdb 1000
  945.  fdb 100
  946.  fdb 10
  947. conend equ * end of list
  948.  sttl Program storage
  949.  pag
  950. *
  951. * constants, strings, and storage
  952. *
  953. *
  954. ermsg1 fcc "Can't open '"
  955. ERSZ1 equ *-ermsg1
  956. ermsg2 fcc "'.",$d
  957. ERSZ2 equ *-ermsg2
  958. ermsg3 fcc "I/O error!",$D
  959. ERSZ3 equ *-ermsg3
  960. *
  961. ylen fdb 365 year length
  962.  fdb 366 leap year
  963. mdays fdb 31,28,31,30,31,30,31,31,30,31,30,31
  964. second fdb 0 seconds (0-59)
  965. minute fdb 0 minutes (0-59)
  966. hours fdb 0 hours (0-23)
  967. wday fdb 0 week day (0-6) 0=Sunday
  968. mday fdb 0 month day (1-31)
  969. month fdb 0 month (0-11)
  970. year fdb 0 year (80+)
  971. yday fdb 0 day of year (0-355)
  972. daylit fdb 0 daylight savings flag
  973. r0 fdb 0,0 regs for div and mul
  974. r1 fdb 0,0
  975. work fdb 0,0
  976. day fdb 0 day temp
  977. ntime fdb 0,0 new time
  978. eutc fcb 0 east of utc flag
  979. fstdl fdb 0 1st day of dlst
  980. lstdl fdb 0 last day of dlst
  981. ltime fdb 0,0 local time
  982. tzn fdb 0,0 time zone seconds
  983. erno fdb 0 error number
  984. linnum fdb 0 line number
  985. pgnum fdb 0 page number
  986. inptr fdb 0 input buffer pointer
  987. inend fdb 0 end of input buffer
  988. outptr fdb 0 output buffer pointer
  989. *
  990. dlflg fcb 0 dlst flag
  991. chrflg fcb 0 character device flag
  992. optcnt fcb 0 option count
  993. lincnt fcb 0 line count
  994. lopton fcb 0
  995. nopton fcb 0
  996. stdinf fcb 0 stdin only flag
  997. pglnth fcb PGLGTH page length
  998. noff fcb 0 no FF flag
  999. ncount fcb 0 pause line count
  1000. *
  1001. iwrt fcb write write call
  1002. iwrt1 fdb 0
  1003. iwrt2 fdb 0 transfer count
  1004. *
  1005. iwrtx fcb write
  1006.  fdb outbuf
  1007. iwrtx2 fdb 0
  1008. *
  1009. iopn fcb open
  1010. iopn2 fdb 0,0
  1011. *
  1012. linbuf rmb 256 line buffer
  1013. linend fdb 0 end of line buffer
  1014. *
  1015. number rmb 6 number string space
  1016.  fcc $0,'=',$20
  1017. numend equ * end number space
  1018. *
  1019. header fcc $C,$D,$D
  1020. filenm rmb 14 file name of header
  1021. space rmb 16 spaces in header
  1022. tstr fcc 'xx:xx:xx xxx xxx xx xxxx'
  1023.  fcc '     Page'
  1024. pgnm rmb 6 page number
  1025.  fcc $0,$D,$D,$0
  1026. hedend equ * end of header
  1027. *
  1028. dtab fcc 'SunMonTueWedThuFriSat'
  1029. *
  1030. mtab fcc 'JanFebMarAprMayJunJulAugSepOctNovDec'
  1031. *
  1032. stb rmb 24 status buffer
  1033. buftim rmb 8 UniFLEX time buffer
  1034.  sttl Buffer area
  1035.  pag
  1036. *
  1037. *
  1038. inbuf rmb BUFSIZ
  1039. *
  1040. outbuf rmb BUFSIZ
  1041. outend equ * end of output buffer
  1042. *
  1043.  end page
  1044.