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 >
Wrap
Text File
|
1983-06-13
|
11KB
|
570 lines
opt pag,nol
ttl Who Utility
lib sysdef
opt lis
pag
info UniFLEX who
info Version 1, Released August 25, 1980
info Copyright, (C) 1980, by
info Technical Systems Consultants, Inc.
info All rights reserved.
* Who utility
org 0
who sys open,usrfil,0 oprn user file
bes who6 error?
pshs d save file desc
sys read,buf,1024 read in file
bes who6 errors?
ldx #buf point to date
stx bufpt set file begin
leax d,x point to end
stx bufend set end
puls d get file desc
sys close close the file
sys time,wtime get system time (tzone info needed)
who4 bsr getlin get line from file buffer
beq who6 end of file?
lbsr cvtim convert time
ldd #1 set file desc
sys write,outbuf,20 output line
ldd #1 set file desc
sys write,tstr,13 output time
ldx #tstr fix up date string
lda #$20
sta 8,x
sta 12,x
bra who4 repeat
who6 ldd #0 set term status
sys term terminate task
* getlin
getlin ldx bufpt get file pointer
cmpx bufend eof?
beq getli6 if so, return
ldd 0,x get entry
bne getli1 is it null?
leax 16,x bump to next
stx bufpt save new point
bra getlin
getli1 ldy #outbuf point to output line
ldb #10 set count
leax 2,x point to user name
getli2 lda 0,x+ get a character
beq getli3 is it null?
sta 0,y+ save in out buf
decb dec the count
bne getli2
bra getli4
getli3 lda #$20 set up space
sta 0,y+ save in buffer
decb dec the count
bne getli3 repeat?
getli4 ldx bufpt get buffer start
ldd 0,x get tty name
std outb2 save in out buf
leax 16,x advance to next entry
stx bufpt save pos
clz set status
getli6 rts return
*
* cvtim
*
* Convert time to ascii
*
cvtim ldx bufpt get time pointer
ldd -4,x xfr time to buffer
std wtime
ldd -2,x
std wtime+2
ldx #wtime point to time
lbsr tmloc convert time
lbsr tasc convert to ascii
ldx #tstr point to string
leax 5,x remove what we don't want
ldy #tstr+12 point to month
ldb #7 set count
cvtim2 lda 0,y+
sta 0,x+
decb
bne cvtim2
lda #$d set cr term
sta 0,x
rts return
pag
*
* tmloc
*
* Convert time pointed at by x to vector time (local).
*
tmloc ldd 0,x get time
std ltime
ldd 2,x
std ltime+2
lda 7,x get day light savings flag
sta dlflg
clr eutc init flag
ldd 5,x get time zone
bpl tmloc2 west of GMT?
inc eutc if not - set flag
coma and make pos number
comb
addd #1
tmloc2 std r0+2 save time zone
ldd #60 calculate zone seconds
std r1+2
ldd #0 set hi bytes to 0
std r0
std r1
lbsr lmul calculate time zone seconds
ldd r0 get result
std tzn save it
ldd r0+2
std tzn+2
lbsr adjtim adjust time for zone
ldx #ltime point to time
lbsr tmutc convert to vector
tst dlflg do dlst?
beq tmloc6
lbsr chkdl in dlst?
bne tmloc6
tmloc5 ldd #3600 adjust for dlst
addd ltime+2
std ltime+2
ldd ltime
adcb #0
adca #0
std ltime
ldx #ltime point to time
lbsr tmutc convert to vector
inc daylit set daylit flag
tmloc6 ldx #second point to vector
rts return
pag
*
* tmutc
*
* Convert the internal system time (4 bytes
* pointed at by X on entry) to an 18 byte
* vector representing the broken down time.
* The time in this form is UTC (Universal
* Coordinated Time).
*
tmutc ldd #0 set daylight savings word
std daylit
ldd 0,x get hi word of time
std r0 save ir divide register
ldd 2,x get lo word of time
std r0+2
ldd #60*60 seconds*minutes constant
std r1 set up for divide
lbsr ldiv min*sec=time % 3600
ldd work hour*day=time / 3600
pshs d save min*sec
ldd #24 set up hours per day constant
std r1
lbsr ldiv hours= (hour*day) % 24
ldd work day= (hour*day) / 24
std hours set hours word
ldd r0+2 get day number
std day save the day
addd #2 add in day bias (Jan 1 80 => Tue)
std r0 set up for divide
ldb #7 days per week constant
stb r1
lbsr div wday=(day+2) % 7
ldb work get result
clra make into word
std wday set week day
puls d get min*sec
std r0 set up for divide
ldb #60 seconds per minute
stb r1
lbsr div seconds= (min*sec) % 60
ldb work minutes= (min*sec) / 60
clra
std second set seconds word
ldd r0 get minutes
std minute save it
pag
* continue tutc for year and month data
clr 0,-s clear year counter
tutc2 ldx #ylen point to year length table
lda 0,s get year number
bita #$3 is it leap year?
bne tutc3
leax 2,x if so, move to long year value
tutc3 ldd day get day number
cmpd 0,x day in current year?
blo tutc4 if 'lt' - we got the year!
subd 0,x subtract off years days
std day save new day count
inc 0,s bump the year count
bra tutc2 repeat
tutc4 std yday set day of year word
puls b get year count
addb #80 add to '1980'
clra make 16 bits long
std year save the year
bitb #$3 is it leap year?
bne tutc5
ldd #29 if so, set Feb day count to 29
std mdays+2
tutc5 ldx #mdays point to month-day table
clr 0,-s set month count to zero
ldd yday get day of the year
tutc6 cmpd 0,x in the month?
blo tutc7 if 'lt' - we got the month!
inc 0,s bump the month counter
subd 0,x++ subtract of this month's days
bra tutc6
tutc7 addd #1 add 1 to month day (day 1 is 1 - not 0!)
std mday save the month day
puls b get the month
std month save it
ldd #28 reset month - day table
std mdays+2
rts return
pag
*
* chkdl
*
* Check if in dlst - return 'eq' if so.
*
chkdl ldd #119 check for last Sun in Apr
bsr fixtim
std fstdl first day of dlst
ldd #303 last Sun in Oct
bsr fixtim
std lstdl last day of dlst
ldd yday get day of year
cmpd fstdl up to 1st day yet?
blo chkdl6
bhi chkdl4
ldd hours on the 1st day - so
cmpd #2 is it 2:00 AM yet?
blo chkdl6
bra chkdl5
chkdl4 ldd yday get day of year
cmpd lstdl past last day of dlst?
bhi chkdl6
blo chkdl5
ldd hours on the last day - so
cmpd #1 is it 1:00 AM yet?
bhs chkdl6
chkdl5 sez we are in dlst!
rts return
chkdl6 clz not in dlst
rts return
pag
*
* adjtim
*
* Adjust time for time zone.
*
adjtim ldd ltime+2 get time
tst eutc east of UTC?
bne adjti2
subd r0+2 subtract time zone minutes
std ltime+2
ldd ltime get hi part
sbcb r0+1
sbca r0
bra adjti4
adjti2 addd r0+2 add in minutes
std ltime+2
ldd ltime
adcb r0+1
adca r0
adjti4 std ltime save new time
adjti5 rts return
*
* fixtim
*
* Return the closest day to the date in D
* which is a Sunday.
*
fixtim pshs d save day number
ldd year get year
bitb #$3 is it leap year?
puls d
bne fixti2
addd #1 if so - bump day number
fixti2 pshs d save day number
addd #420 add in 420 so no negatives result
addd wday add in day of week
subd yday subtract day of year
std r0 save result
ldb #7
stb r1 set up for divide
lbsr div do: (day+420+wday-yday) % 7
puls d get day number
subb work
sbca #0
rts return day in d
pag
*
* Divide routines for time conversion use. 'Ldiv'
* divides a 32 bit number (r0 -> r0+3) by a 16 bit
* number (r1 -> r1+1) and produces a 32 bit result
* in r0 and a 16 bit remainder in 'work'. 'Div'
* divides a 16 bit number (r0 -> r0+1) by an 8 bit
* number (r1) and produces a 16 bit result (r0)
* and an 8 bit remainder (work).
*
div lda #17 set up loop counter
clrb do initialize
stb work
bra div2
div1 ldb work
subb r1 do subtraction
bcs div2 s3et new work?
stb work yes!
div2 rol r0+1 do shift left
rol r0
rol work
deca dec the loop count
bne div1 repeat?
com r0 fix up result
com r0+1
lsr work fix remainder
rts
pag
*
* Long divide
*
ldiv ldb #33 set loop counter
pshs b
ldd #0 do init
std work
bra ldiv2
ldiv1 ldd work do subtraction
subd r1
bcs ldiv2 work > r1 ?
std work set new work value
ldiv2 rol r0+3 do shifting
rol r0+2
rol r0+1
rol r0
rol work+1
rol work
dec 0,s dec the loop count
bne ldiv1
com r0 compliment the result
com r0+1
com r0+2
com r0+3
lsr work adjust the remainder
ror work+1
puls b,pc return
pag
*
* lmul
*
* Long multiply - 32 bits (r0) X 32 bits (r1).
* Result is in r0.
*
lmul ldb #32 set loop count
pshs b
ldd #0 init variables
std work
std work+2
lsr r0 do initial shift
ror r0+1
ror r0+2
ror r0+3
lmul1 bcc lmul2 need to add?
ldd work+2
addd r1+2
std work+2
ldd work
adcb r1+1
adca r1
std work save result
lmul2 ror work do shifting
ror work+1
ror work+2
ror work+3
ror r0
ror r0+1
ror r0+2
ror r0+3
dec 0,s dec the loop count
bne lmul1 repeat?
puls b,pc return
pag
*
* tasc
*
* Convert the time vector data (18 bytes) pointed
* at by x into an ascii string. Return x pointing
* to the string.
*
tasc tfr x,u save vector pointer
ldx #tstr point to string
ldd 4,u get hours
lbsr cvt convert to ascii
leax 1,x skip the ':'
ldd 2,u get minutes
lbsr cvt convert to ascii
leax 1,x skip the ':'
ldd 0,u get seconds
lbsr cvt convert to ascii
leax 1,x skip space
ldd 6,u get day of week
ldy #dtab point to day table
bsr tasxfr xfr to string
ldd 10,u get month
ldy #mtab point to month table
bsr tasxfr xfr to string
ldd 8,u get month day
bsr cvt convert to ascii
leax 1,x
ldd #('1<<8)|'9 set up '19'
std 0,x save in string
ldd 12,u get year
cmpd #100 >100 (year 2000 yet?)
blo tasc4
subd #100 remove bias
pshs d save year
ldd #('2<<8)|'0 set up '20'
std 0,x set in string
puls d reset year
tasc4 leax 2,x
bsr cvt convert year to ascii
ldx #tstr point to string
rts return
pag
*
* tasxfr
*
* Transfer the 3 bytes of ascii indexed by b
* at y to location pointed at by x.
*
tasxfr pshs b index * 3
aslb
addb 0,s+
leay b,y point to indexed data
ldd 0,y xfr the data to x
std 0,x++
lda 2,y
sta 0,x
leax 2,x bump string pointer
rts return
*
* cvt
*
* Convert number in b to ascii at x.
*
cvt lda #'0 set ascii 0
cvt2 cmpb #10 >10?
blo cvt4
subb #10 subtract off 10
inca bump ascii
bra cvt2 repeat
cvt4 addb #'0 make 1's ascii
std 0,x++ save ascii at x
rts return
pag
*
* Strings and constants
*
ylen fdb 365 year length
fdb 366 leap year
mdays fdb 31,28,31,30,31,30,31,31,30,31,30,31
tstr fcc 'xx:xx:xx xxx xxx xx xxxx',$d,0
dtab fcc 'SunMonTueWedThuFriSat'
mtab fcc 'JanFebMarAprMayJunJulAugSepOctNovDec'
second fdb 0 seconds (0-59)
minute fdb 0 minutes (0-59)
hours fdb 0 hours (0-23)
wday fdb 0 week day (0-6) 0=Sunday
mday fdb 0 month day (1-31)
month fdb 0 month (0-11)
year fdb 0 year (80+)
yday fdb 0 day of year (0-355)
daylit fdb 0 daylight savings flag
r0 fdb 0,0 regs for div and mul
r1 fdb 0,0
work fdb 0,0
day fdb 0 day temp
ntime fdb 0,0 new time
eutc fcb 0 east of utc flag
fstdl fdb 0 1st day of dlst
lstdl fdb 0 last day of dlst
dlflg fcb 0 dlst flag
ltime fdb 0,0 local time
tzn fdb 0,0 time zone seconds
* data section
usrfil fcc '/act/utmp',0
outbuf rmb 10
fcc ' tty'
outb2 fdb 0
fcc ' '
bufpt fdb 0 buffer pointer
bufend fdb 0 buffer end pointer
wtime fdb 0,0,0,0 time buffer
org $C00
buf rmb 1024
end who