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 / who.old < prev    next >
Text File  |  1983-06-13  |  11KB  |  570 lines

  1.  opt pag,nol
  2.  ttl Who Utility
  3.  lib sysdef
  4.  opt lis
  5.  pag
  6.  info UniFLEX who
  7.  info Version 1, Released August 25, 1980
  8.  info Copyright, (C) 1980, by
  9.  info Technical Systems Consultants, Inc.
  10.  info All rights reserved.
  11.  
  12. * Who utility
  13.  
  14.  org 0
  15.  
  16. who sys open,usrfil,0 oprn user file
  17.  bes who6 error?
  18.  pshs d save file desc
  19.  sys read,buf,1024 read in file
  20.  bes who6 errors?
  21.  ldx #buf point to date
  22.  stx bufpt set file begin
  23.  leax d,x point to end
  24.  stx bufend set end
  25.  puls d get file desc
  26.  sys close close the file
  27.  sys time,wtime get system time (tzone info needed)
  28. who4 bsr getlin get line from file buffer
  29.  beq who6 end of file?
  30.  lbsr cvtim convert time
  31.  ldd #1 set file desc
  32.  sys write,outbuf,20 output line
  33.  ldd #1 set file desc
  34.  sys write,tstr,13 output time
  35.  ldx #tstr fix up date string
  36.  lda #$20
  37.  sta 8,x
  38.  sta 12,x
  39.  bra who4 repeat
  40. who6 ldd #0 set term status
  41.  sys term terminate task
  42.  
  43. * getlin
  44.  
  45. getlin ldx bufpt get file pointer
  46.  cmpx bufend eof?
  47.  beq getli6 if so, return
  48.  ldd 0,x get entry
  49.  bne getli1 is it null?
  50.  leax 16,x bump to next
  51.  stx bufpt save new point
  52.  bra getlin
  53. getli1 ldy #outbuf point to output line
  54.  ldb #10 set count
  55.  leax 2,x point to user name
  56. getli2 lda 0,x+ get a character
  57.  beq getli3 is it null?
  58.  sta 0,y+ save in out buf
  59.  decb dec the count
  60.  bne getli2
  61.  bra getli4
  62. getli3 lda #$20 set up space
  63.  sta 0,y+ save in buffer
  64.  decb dec the count
  65.  bne getli3 repeat?
  66. getli4 ldx bufpt get buffer start
  67.  ldd 0,x get tty name
  68.  std outb2 save in out buf
  69.  leax 16,x advance to next entry
  70.  stx bufpt save pos
  71.  clz set status
  72. getli6 rts return
  73.  
  74.  
  75. *
  76. * cvtim
  77. *
  78. * Convert time to ascii
  79. *
  80.  
  81. cvtim ldx bufpt get time pointer
  82.  ldd -4,x xfr time to buffer
  83.  std wtime
  84.  ldd -2,x
  85.  std wtime+2
  86.  ldx #wtime point to time
  87.  lbsr tmloc convert time
  88.  lbsr tasc convert to ascii
  89.  ldx #tstr point to string
  90.  leax 5,x remove what we don't want
  91.  ldy #tstr+12 point to month
  92.  ldb #7 set count
  93. cvtim2 lda 0,y+
  94.  sta 0,x+
  95.  decb
  96.  bne cvtim2
  97.  lda #$d set cr term
  98.  sta 0,x
  99.  rts return
  100.  
  101.  pag
  102.  
  103. *
  104. * tmloc
  105. *
  106. * Convert time pointed at by x to vector time (local).
  107. *
  108.  
  109. tmloc ldd 0,x get time
  110.  std ltime
  111.  ldd 2,x
  112.  std ltime+2
  113.  lda 7,x get day light savings flag
  114.  sta dlflg
  115.  clr eutc init flag
  116.  ldd 5,x get time zone
  117.  bpl tmloc2 west of GMT?
  118.  inc eutc if not - set flag
  119.  coma and make pos number
  120.  comb
  121.  addd #1
  122. tmloc2 std r0+2 save time zone
  123.  ldd #60 calculate zone seconds
  124.  std r1+2
  125.  ldd #0 set hi bytes to 0
  126.  std r0
  127.  std r1
  128.  lbsr lmul calculate time zone seconds
  129.  ldd r0 get result
  130.  std tzn save it
  131.  ldd r0+2
  132.  std tzn+2
  133.  lbsr adjtim adjust time for zone
  134.  ldx #ltime point to time
  135.  lbsr tmutc convert to vector
  136.  tst dlflg do dlst?
  137.  beq tmloc6
  138.  lbsr chkdl in dlst?
  139.  bne tmloc6
  140. tmloc5 ldd #3600 adjust for dlst
  141.  addd ltime+2
  142.  std ltime+2
  143.  ldd ltime
  144.  adcb #0
  145.  adca #0
  146.  std ltime
  147.  ldx #ltime point to time
  148.  lbsr tmutc convert to vector
  149.  inc daylit set daylit flag
  150. tmloc6 ldx #second point to vector
  151.  rts return
  152.  
  153.  pag
  154.  
  155. *
  156. * tmutc
  157. *
  158. * Convert the internal system time (4 bytes
  159. * pointed at by X on entry) to an 18 byte
  160. * vector representing the broken down time.
  161. * The time in this form is UTC (Universal
  162. * Coordinated Time).
  163. *
  164.  
  165. tmutc ldd #0 set daylight savings word
  166.  std daylit
  167.  ldd 0,x get hi word of time
  168.  std r0 save ir divide register
  169.  ldd 2,x get lo word of time
  170.  std r0+2
  171.  ldd #60*60 seconds*minutes constant
  172.  std r1 set up for divide
  173.  lbsr ldiv min*sec=time % 3600
  174.  ldd work hour*day=time / 3600
  175.  pshs d save min*sec
  176.  ldd #24 set up hours per day constant
  177.  std r1
  178.  lbsr ldiv hours= (hour*day) % 24
  179.  ldd work day= (hour*day) / 24
  180.  std hours set hours word
  181.  ldd r0+2 get day number
  182.  std day save the day
  183.  addd #2 add in day bias (Jan 1 80 => Tue)
  184.  std r0 set up for divide
  185.  ldb #7 days per week constant
  186.  stb r1
  187.  lbsr div wday=(day+2) % 7
  188.  ldb work get result
  189.  clra make into word
  190.  std wday set week day
  191.  puls d get min*sec
  192.  std r0 set up for divide
  193.  ldb #60 seconds per minute
  194.  stb r1
  195.  lbsr div seconds= (min*sec) % 60
  196.  ldb work minutes= (min*sec) / 60
  197.  clra
  198.  std second set seconds word
  199.  ldd r0 get minutes
  200.  std minute save it
  201.  
  202.  pag
  203.  
  204. * continue tutc for year and month data
  205.  
  206.  clr 0,-s clear year counter
  207. tutc2 ldx #ylen point to year length table
  208.  lda 0,s get year number
  209.  bita #$3 is it leap year?
  210.  bne tutc3
  211.  leax 2,x if so, move to long year value
  212. tutc3 ldd day get day number
  213.  cmpd 0,x day in current year?
  214.  blo tutc4 if 'lt' - we got the year!
  215.  subd 0,x subtract off years days
  216.  std day save new day count
  217.  inc 0,s bump the year count
  218.  bra tutc2 repeat
  219. tutc4 std yday set day of year word
  220.  puls b get year count
  221.  addb #80 add to '1980'
  222.  clra make 16 bits long
  223.  std year save the year
  224.  bitb #$3 is it leap year?
  225.  bne tutc5
  226.  ldd #29 if so, set Feb day count to 29
  227.  std mdays+2
  228. tutc5 ldx #mdays point to month-day table
  229.  clr 0,-s set month count to zero
  230.  ldd yday get day of the year
  231. tutc6 cmpd 0,x in the month?
  232.  blo tutc7 if 'lt' - we got the month!
  233.  inc 0,s bump the month counter
  234.  subd 0,x++ subtract of this month's days
  235.  bra tutc6
  236. tutc7 addd #1 add 1 to month day (day 1 is 1 - not 0!)
  237.  std mday save the month day
  238.  puls b get the month
  239.  std month save it
  240.  ldd #28 reset month - day table
  241.  std mdays+2
  242.  rts return
  243.  
  244.  pag
  245.  
  246. *
  247. * chkdl
  248. *
  249. * Check if in dlst - return 'eq' if so.
  250. *
  251.  
  252. chkdl ldd #119 check for last Sun in Apr
  253.  bsr fixtim
  254.  std fstdl first day of dlst
  255.  ldd #303 last Sun in Oct
  256.  bsr fixtim
  257.  std lstdl last day of dlst
  258.  ldd yday get day of year
  259.  cmpd fstdl up to 1st day yet?
  260.  blo chkdl6
  261.  bhi chkdl4
  262.  ldd hours on the 1st day - so
  263.  cmpd #2 is it 2:00 AM yet?
  264.  blo chkdl6
  265.  bra chkdl5
  266. chkdl4 ldd yday get day of year
  267.  cmpd lstdl past last day of dlst?
  268.  bhi chkdl6
  269.  blo chkdl5
  270.  ldd hours on the last day - so
  271.  cmpd #1 is it 1:00 AM yet?
  272.  bhs chkdl6
  273. chkdl5 sez we are in dlst!
  274.  rts return
  275. chkdl6 clz not in dlst
  276.  rts return
  277.  
  278.  pag
  279.  
  280. *
  281. * adjtim
  282. *
  283. * Adjust time for time zone.
  284. *
  285.  
  286. adjtim ldd ltime+2 get time
  287.  tst eutc east of UTC?
  288.  bne adjti2
  289.  subd r0+2 subtract time zone minutes
  290.  std ltime+2
  291.  ldd ltime get hi part
  292.  sbcb r0+1
  293.  sbca r0
  294.  bra adjti4
  295. adjti2 addd r0+2 add in minutes
  296.  std ltime+2
  297.  ldd ltime
  298.  adcb r0+1
  299.  adca r0
  300. adjti4 std ltime save new time
  301. adjti5 rts return
  302.  
  303. *
  304. * fixtim
  305. *
  306. * Return the closest day to the date in D
  307. * which is a Sunday.
  308. *
  309.  
  310. fixtim pshs d save day number
  311.  ldd year get year
  312.  bitb #$3 is it leap year?
  313.  puls d
  314.  bne fixti2
  315.  addd #1 if so - bump day number
  316. fixti2 pshs d save day number
  317.  addd #420 add in 420 so no negatives result
  318.  addd wday add in day of week
  319.  subd yday subtract day of year
  320.  std r0 save result
  321.  ldb #7
  322.  stb r1 set up for divide
  323.  lbsr div do: (day+420+wday-yday) % 7
  324.  puls d get day number
  325.  subb work
  326.  sbca #0
  327.  rts return day in d
  328.  
  329.  pag
  330.  
  331. *
  332. * Divide routines for time conversion use.  'Ldiv'
  333. * divides a 32 bit number (r0 -> r0+3) by a 16 bit
  334. * number (r1 -> r1+1) and produces a 32 bit result
  335. * in r0 and a 16 bit remainder in 'work'.  'Div'
  336. * divides a 16 bit number (r0 -> r0+1) by an 8 bit
  337. * number (r1) and produces a 16 bit result (r0)
  338. * and an 8 bit remainder (work).
  339. *
  340.  
  341. div lda #17 set up loop counter
  342.  clrb do initialize
  343.  stb work
  344.  bra div2
  345. div1 ldb work
  346.  subb r1 do subtraction
  347.  bcs div2 s3et new work?
  348.  stb work yes!
  349. div2 rol r0+1 do shift left
  350.  rol r0
  351.  rol work
  352.  deca dec the loop count
  353.  bne div1 repeat?
  354.  com r0 fix up result
  355.  com r0+1
  356.  lsr work fix remainder
  357.  rts
  358.  
  359.  
  360.  pag
  361.  
  362. *
  363. * Long divide
  364. *
  365.  
  366. ldiv ldb #33 set loop counter
  367.  pshs b
  368.  ldd #0 do init
  369.  std work
  370.  bra ldiv2
  371. ldiv1 ldd work do subtraction
  372.  subd r1
  373.  bcs ldiv2 work > r1 ?
  374.  std work set new work value
  375. ldiv2 rol r0+3 do shifting
  376.  rol r0+2
  377.  rol r0+1
  378.  rol r0
  379.  rol work+1
  380.  rol work
  381.  dec 0,s dec the loop count
  382.  bne ldiv1
  383.  com r0 compliment the result
  384.  com r0+1
  385.  com r0+2
  386.  com r0+3
  387.  lsr work adjust the remainder
  388.  ror work+1
  389.  puls b,pc return
  390.  
  391.  pag
  392.  
  393. *
  394. * lmul
  395. *
  396. * Long multiply - 32 bits (r0) X 32 bits (r1).
  397. * Result is in r0.
  398. *
  399.  
  400. lmul ldb #32 set loop count
  401.  pshs b
  402.  ldd #0 init variables
  403.  std work
  404.  std work+2
  405.  lsr r0 do initial shift
  406.  ror r0+1
  407.  ror r0+2
  408.  ror r0+3
  409. lmul1 bcc lmul2 need to add?
  410.  ldd work+2
  411.  addd r1+2
  412.  std work+2
  413.  ldd work
  414.  adcb r1+1
  415.  adca r1
  416.  std work save result
  417. lmul2 ror work do shifting
  418.  ror work+1
  419.  ror work+2
  420.  ror work+3
  421.  ror r0
  422.  ror r0+1
  423.  ror r0+2
  424.  ror r0+3
  425.  dec 0,s dec the loop count
  426.  bne lmul1 repeat?
  427.  puls b,pc return
  428.  
  429.  pag
  430.  
  431. *
  432. * tasc
  433. *
  434. * Convert the time vector data (18 bytes) pointed
  435. * at by x into an ascii string.  Return x pointing
  436. * to the string.
  437. *
  438.  
  439. tasc tfr x,u save vector pointer
  440.  ldx #tstr point to string
  441.  ldd 4,u get hours
  442.  lbsr cvt convert to ascii
  443.  leax 1,x skip the ':'
  444.  ldd 2,u get minutes
  445.  lbsr cvt convert to ascii
  446.  leax 1,x skip the ':'
  447.  ldd 0,u get seconds
  448.  lbsr cvt convert to ascii
  449.  leax 1,x skip space
  450.  ldd 6,u get day of week
  451.  ldy #dtab point to day table
  452.  bsr tasxfr xfr to string
  453.  ldd 10,u get month
  454.  ldy #mtab point to month table
  455.  bsr tasxfr xfr to string
  456.  ldd 8,u get month day
  457.  bsr cvt convert to ascii
  458.  leax 1,x
  459.  ldd #('1<<8)|'9 set up '19'
  460.  std 0,x save in string
  461.  ldd 12,u get year
  462.  cmpd #100 >100 (year 2000 yet?)
  463.  blo tasc4
  464.  subd #100 remove bias
  465.  pshs d save year
  466.  ldd #('2<<8)|'0 set up '20'
  467.  std 0,x set in string
  468.  puls d reset year
  469. tasc4 leax 2,x
  470.  bsr cvt convert year to ascii
  471.  ldx #tstr point to string
  472.  rts return
  473.  
  474.  pag
  475.  
  476. *
  477. * tasxfr
  478. *
  479. * Transfer the 3 bytes of ascii indexed by b
  480. * at y to location pointed at by x.
  481. *
  482.  
  483. tasxfr pshs b index * 3
  484.  aslb
  485.  addb 0,s+
  486.  leay b,y point to indexed data
  487.  ldd 0,y xfr the data to x
  488.  std 0,x++
  489.  lda 2,y
  490.  sta 0,x
  491.  leax 2,x bump string pointer
  492.  rts return
  493.  
  494. *
  495. * cvt
  496. *
  497. * Convert number in b to ascii at x.
  498. *
  499.  
  500. cvt lda #'0 set ascii 0
  501. cvt2 cmpb #10 >10?
  502.  blo cvt4
  503.  subb #10 subtract off 10
  504.  inca bump ascii
  505.  bra cvt2 repeat
  506. cvt4 addb #'0 make 1's ascii
  507.  std 0,x++ save ascii at x
  508.  rts return
  509.  
  510.  pag
  511.  
  512. *
  513. * Strings and constants
  514. *
  515.  
  516. ylen fdb 365 year length
  517.  fdb 366 leap year
  518.  
  519. mdays fdb 31,28,31,30,31,30,31,31,30,31,30,31
  520.  
  521.  
  522. tstr fcc 'xx:xx:xx xxx xxx xx xxxx',$d,0
  523.  
  524. dtab fcc 'SunMonTueWedThuFriSat'
  525.  
  526. mtab fcc 'JanFebMarAprMayJunJulAugSepOctNovDec'
  527.  
  528. second fdb 0 seconds (0-59)
  529. minute fdb 0 minutes (0-59)
  530. hours fdb 0 hours (0-23)
  531. wday fdb 0 week day (0-6) 0=Sunday
  532. mday fdb 0 month day (1-31)
  533. month fdb 0 month (0-11)
  534. year fdb 0 year (80+)
  535. yday fdb 0 day of year (0-355)
  536. daylit fdb 0 daylight savings flag
  537.  
  538.  
  539. r0 fdb 0,0 regs for div and mul
  540. r1 fdb 0,0
  541. work fdb 0,0
  542. day fdb 0 day temp
  543. ntime fdb 0,0 new time
  544. eutc fcb 0 east of utc flag
  545. fstdl fdb 0 1st day of dlst
  546. lstdl fdb 0 last day of dlst
  547. dlflg fcb 0 dlst flag
  548. ltime fdb 0,0 local time
  549. tzn fdb 0,0 time zone seconds
  550.  
  551.  
  552. * data section
  553.  
  554. usrfil fcc '/act/utmp',0
  555.  
  556. outbuf rmb 10
  557.  fcc '  tty'
  558. outb2 fdb 0
  559.  fcc '   '
  560.  
  561. bufpt fdb 0 buffer pointer
  562. bufend fdb 0 buffer end pointer
  563. wtime fdb 0,0,0,0 time buffer
  564.  
  565.  org $C00
  566.  
  567. buf rmb 1024
  568.  
  569.  end who
  570.