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 / time < prev    next >
Text File  |  1981-09-01  |  8KB  |  438 lines

  1.  opt pag,nol
  2.  ttl UniFLEX Time
  3.  pag
  4.  lib sysdef
  5.  opt lis
  6.  pag
  7.  
  8.  info UniFLEX time
  9.  info Version 1, Released January 19, 1981
  10.  info Copyright, (C) 1981, by
  11.  info Technical Systems Consultants, Inc.
  12.  info All rights reserved.
  13.  
  14. * definitions
  15.  
  16. ENOTB equ 21 not binary
  17. BHDBT equ $8a basic file header
  18. BHDBT2 equ $9a new basic header (v2.0)
  19. PHDBT0 equ $8b Pascal (normal) header byte ***GDT
  20. PHDBT1 equ $8c Pascal (system) ***GDT
  21. BUFSIZ equ 256 buffer size
  22.  
  23. * time starts here
  24.  
  25. tim ldd 0,s get arg count
  26.  cmpd #1
  27.  lbls err1 if 1 - error
  28.  ldd #cshln set shell name
  29.  std sargls
  30.  sys time,tstrt get current time
  31.  leax 4,s point to args
  32.  ldu #arglst point to arg list
  33. tim1 ldd 0,x++ copy args to list
  34.  std 0,u++
  35.  bne tim1 repeat to end of list
  36.  ldx arglst point to first arg
  37.  ldy #comnd point to command buffer
  38. tim2 lda 0,x+ get a character
  39.  sta 0,y+ xfr to command buffer
  40.  bne tim2 end?
  41.  leax -1,x back up to term
  42. tim25 cmpx arglst back to beginning?
  43.  beq tim3
  44.  lda 0,-x get previous character
  45.  cmpa #'/ is it /?
  46.  bne tim25
  47.  leax 1,x eat slash
  48. tim3 stx arglst set first arg (cmnd name)
  49.  sys fork
  50.  bra doit go exec command
  51.  pshs d save task id
  52.  sys cpint,2,1 ignore INTERRUPT signal
  53. tim4 sys wait wait for task
  54.  cmpd 0,s is it him?
  55.  bne tim4
  56.  puls d
  57.  stx tstat save status
  58.  lbra fin go finish up
  59.  
  60.  pag
  61.  
  62. * execute command
  63.  
  64. doit clr rtcnt clear out retry counter
  65.  sys exec,comnd,arglst exec program
  66.  cmpd #ENOTB file not binary?
  67.  beq trya
  68.  lda comnd check first char
  69.  cmpa #'/ is it path head?
  70.  beq doit3
  71.  inc rtcnt bump retry count
  72.  sys exec,retry1,arglst try 'bin/...'
  73.  cmpd #ENOTB not binary?
  74.  beq trya
  75.  inc rtcnt bump counter
  76.  sys exec,retry2,arglst try '/bin/...'
  77.  cmpd #ENOTB not binary?
  78.  beq trya
  79.  inc rtcnt bump retry count
  80.  sys exec,retry3,arglst try '/usr/bin/...'
  81.  cmpd #ENOTB
  82.  beq trya
  83. doit3 ldd #1 if here, error!
  84.  sys write,ermsg1,ERSIZ1
  85.  ldx #comnd
  86.  ldd #0
  87. doit4 lda 0,x+
  88.  beq doit5
  89.  incb
  90.  bra doit4
  91. doit5 tst b
  92.  beq doit7
  93.  std doit6+5 save as arg
  94.  ldd #1 set file desc
  95. doit6 sys write,comnd,0
  96. doit7 ldd #1
  97.  sys write,ermsg2,ERSIZ2
  98.  ldd #$ff set error status
  99.  sys term terminate this guy!
  100.  
  101.  pag
  102.  
  103. *
  104. * trya
  105. *
  106. * Try to execute ascii file.
  107. *
  108.  
  109. trya ldx #rtclst point to list
  110.  lda rtcnt get retry count
  111.  asla
  112.  leax a,x point to retry number
  113.  ldd 0,x get pointer
  114.  std iopn2 set in open call
  115.  std arglst
  116.  sys ind,iopn open file
  117.  bes trya6
  118.  pshs d save file desc
  119.  clr smbuf
  120.  sys read,smbuf,2 read 1st 2 characters
  121.  puls d get fd
  122.  sys close close the file
  123.  lda smbuf get 1st char
  124.  bmi trybas basic file?
  125.  cmpa #$20 is it ascii?
  126.  blo trya6
  127. trya4 sys exec,cshell,sargls execute a shell
  128. trya6 lbra doit3 report error
  129.  
  130. rtclst fdb comnd,retry1,retry2,retry3
  131.  
  132. trybas cmpa #BHDBT is it basic file?
  133.  beq trybs2
  134.  cmpa #BHDBT2 new basic?
  135.  bne tryP try Pascal program ***GDT
  136. trybs2 sys exec,cbasic,sargls try basic execution
  137.  lbra doit3 error?
  138.  
  139. tryP cmpa #PHDBT0 normal Pascal program? ***GDT
  140.  bne tryP1 no - try system ***GDT
  141.  sys exec,Pscl0,sargls try Pascal execution ***GDT
  142.  lbra doit3 error ***GDT
  143. tryP1 cmpa #PHDBT1 Pascal system program? ***GDT
  144.  lbne doit3 no - error ***GDT
  145.  sys exec,Pscl1,sargls try to execute program ***GDT
  146.  lbra doit3 error ***GDT
  147. err1 ldd #2 report syntax error
  148.  sys write,syrms,SYSIZ
  149.  ldd #$ff set status
  150.  sys term exit
  151.  
  152.  pag
  153.  
  154. *
  155. * finish up and report times
  156. *
  157.  
  158. fin sys time,tend get current time
  159.  sys ttime,ttbuf get task info
  160.  lda tend+4 get tenths secs
  161.  suba tstrt+4 calc real time difference
  162.  sta rtt
  163.  ldd tend+2
  164.  sbcb tstrt+3
  165.  sbca tstrt+2
  166.  std rt save real time
  167.  tst rtt
  168.  bpl fin2
  169.  lda #10 fix negative tenths
  170.  adda rtt
  171.  sta rtt
  172. fin2 ldd ttbuf+6 get user time
  173.  std r0
  174.  ldd ttbuf+8
  175.  std r0+2
  176.  ldd #10 divide by 10
  177.  std r1
  178.  jsr ldiv
  179.  ldb work+1 get remainder (.1 seconds)
  180.  stb utt
  181.  ldd r0+2 get seconds
  182.  std ut
  183.  ldd ttbuf+10 get system time
  184.  std r0
  185.  ldd ttbuf+12
  186.  std r0+2
  187.  ldd #10 divide by 10
  188.  std r1
  189.  jsr ldiv
  190.  ldb work+1 get .1 seconds
  191.  stb stt
  192.  ldd r0+2 get seconds
  193.  std st
  194.  ldd #1 output rt message
  195.  sys write,m1,M1
  196.  ldx #rt output real time
  197.  jsr ptm
  198.  ldd #1 output user time message
  199.  sys write,m2,M2
  200.  ldx #ut
  201.  jsr ptm output user time
  202.  ldd #1 output sys message
  203.  sys write,m3,M3
  204.  ldx #st output system time
  205.  jsr ptm
  206.  ldd tstat get term status
  207.  sys term exit
  208.  
  209.  pag
  210.  
  211. *
  212. * print time
  213. *
  214.  
  215. ptm pshs x save time ptr
  216.  ldd 0,x get seconds
  217.  std r0
  218.  ldb #60 divide by 60
  219.  stb r1 for minutes
  220.  jsr div
  221.  ldd r0 get minutes
  222.  ldx #obfr point to output buffer
  223.  jsr decstn output number
  224.  std iwrt2 save length
  225.  leax d,x
  226.  lda #': output ':'
  227.  sta 0,x+
  228.  stx optr save ptr
  229.  ldb work get seconds
  230.  clra
  231.  jsr decstn output it
  232.  leax d,x
  233.  addd #2 adjust count
  234.  addd iwrt2
  235.  std iwrt2
  236.  lda #'. output '.'
  237.  sta 0,x+
  238.  stx optr
  239.  puls x point to time
  240.  ldb 2,x get tenths of seconds
  241.  clra
  242.  ldx optr get output ptr
  243.  jsr decstn output number
  244.  leax d,x
  245.  addd iwrt2 adjust count
  246.  addd #1
  247.  std iwrt2
  248.  lda #$d output cr
  249.  sta 0,x
  250.  ldd #1 get file desc
  251.  sys ind,iwrt output number info
  252.  rts return
  253.  
  254.  pag
  255.  
  256. *
  257. * decst
  258. *
  259. * Convert the number in D into an ascii string
  260. * representing a decimal number.  The string
  261. * is pointed at by X (X should be set on entry!)
  262. * Also on exit, D has the length of the string.
  263. * The second entry point, 'decstn' will not print
  264. * leading spaces for leading zeroes, but will
  265. * suppress all leading zero info.  All strings
  266. * start with a space.
  267. *
  268.  
  269. decst pshs x save user pointer
  270.  clr 0,-s set suppression flag
  271.  bra decst2
  272. *
  273. decstn pshs x save user pointer
  274.  clr 0,-s
  275.  inc 0,s set for no fielding
  276. decst2 clr 0,-s set up bookkeeping
  277.  clr 0,-s
  278.  ldy #conlst point to constants
  279. decst4 cmpd 0,y compare number to constant
  280.  blo decst5
  281.  subd 0,y do subtraction of constant
  282.  inc 1,s bump digits counter
  283.  bra decst4
  284. decst5 pshs a save number
  285.  tst 2,s zero digit?
  286.  bne decst6
  287.  tst 1,s any numbers output yet?
  288.  bne decst6
  289.  tst 3,s doing suppression?
  290.  bne decst8
  291.  lda #$20 set up space
  292.  bra decst7
  293. decst6 lda 2,s get digit count
  294.  inc 1,s set 'got one' flag
  295.  ora #$30 make ascii
  296. decst7 sta 0,x+ save in buffer
  297. decst8 puls a reset number
  298.  clr 1,s clear out digit
  299.  leay 2,y bump constant ptr
  300.  cmpy #conend end of list?
  301.  bne decst4
  302.  leas 3,s clean up stack
  303.  orb #$30 make last digit
  304.  stb 0,x+ save in buffer
  305.  clr 0,x null terminate string
  306.  tfr x,d
  307.  subd 0,s calculate string length
  308.  puls x,pc return
  309.  
  310. * constants for convert
  311.  
  312. conlst fdb 10000
  313.  fdb 1000
  314.  fdb 100
  315.  fdb 10
  316. conend equ * end of list
  317.  
  318.  pag
  319.  
  320. *
  321. * Divide routines for time conversion use.  'Ldiv'
  322. * divides a 32 bit number (r0 -> r0+3) by a 16 bit
  323. * number (r1 -> r1+1) and produces a 32 bit result
  324. * in r0 and a 16 bit remainder in 'work'.  'Div'
  325. * divides a 16 bit number (r0 -> r0+1) by an 8 bit
  326. * number (r1) and produces a 16 bit result (r0)
  327. * and an 8 bit remainder (work).
  328. *
  329.  
  330. div lda #17 set up loop counter
  331.  clrb do initialize
  332.  stb work
  333.  bra div2
  334. div1 ldb work
  335.  subb r1 do subtraction
  336.  bcs div2 s3et new work?
  337.  stb work yes!
  338. div2 rol r0+1 do shift left
  339.  rol r0
  340.  rol work
  341.  deca dec the loop count
  342.  bne div1 repeat?
  343.  com r0 fix up result
  344.  com r0+1
  345.  lsr work fix remainder
  346.  rts
  347.  
  348.  
  349.  pag
  350.  
  351. *
  352. * Long divide
  353. *
  354.  
  355. ldiv ldb #33 set loop counter
  356.  pshs b
  357.  ldd #0 do init
  358.  std work
  359.  bra ldiv2
  360. ldiv1 ldd work do subtraction
  361.  subd r1
  362.  bcs ldiv2 work > r1 ?
  363.  std work set new work value
  364. ldiv2 rol r0+3 do shifting
  365.  rol r0+2
  366.  rol r0+1
  367.  rol r0
  368.  rol work+1
  369.  rol work
  370.  dec 0,s dec the loop count
  371.  bne ldiv1
  372.  com r0 compliment the result
  373.  com r0+1
  374.  com r0+2
  375.  com r0+3
  376.  lsr work adjust the remainder
  377.  ror work+1
  378.  puls b,pc return
  379.  
  380.  
  381. *
  382. * data section
  383. *
  384.  
  385. m1 fcc 'Elapsed real time - '
  386. M1 equ *-m1
  387. m2 fcc 'User CPU time - '
  388. M2 equ *-m2
  389. m3 fcc 'System CPU time - '
  390. M3 equ *-m3
  391. ermsg1 fcc "Can't execute '"
  392. ERSIZ1 equ *-ermsg1
  393. ermsg2 fcc "'",$d
  394. ERSIZ2 equ *-ermsg2
  395. syrms fcc 'Syntax error.',$d
  396. SYSIZ equ *-syrms
  397. cshell fcc '/bin/shell',0
  398. cbasic fcc '/bin/basic',0
  399. Pscl0 fcc '/bin/nrun',0 ***GDT
  400. Pscl1 fcc '/bin/sys_rt',0 ***GDT
  401. cshln fcc 'shell',0
  402.  
  403. r0 fdb 0,0 regs for div and mul
  404. r1 fdb 0,0
  405. work fdb 0,0
  406. tstrt rzb 8 time start
  407. tend rzb 8 time end
  408. ttbuf rzb 14 ttime buffer
  409. smbuf fdb 0 buffer for file header
  410. tstat fdb 0 term status
  411. rtcnt fcb 0 retry counter
  412. optr fdb 0 output pointer
  413. rt fdb 0
  414. rtt fcb 0 real time storage
  415. ut fdb 0 user time
  416. utt fcb 0
  417. st fdb 0 system time
  418. stt fcb 0
  419.  
  420. iopn fcb open ind open call
  421. iopn2 fdb 0,0
  422.  
  423. iwrt fcb write
  424.  fdb obfr
  425. iwrt2 fdb 0
  426.  
  427.  
  428. retry3 fcc '/usr'
  429. retry2 fcc '/'
  430. retry1 fcc 'bin/'
  431. comnd rzb 64 command name buffer
  432. obfr rzb 32
  433.  
  434. sargls rmb 2 shell arg list
  435. arglst rzb BUFSIZ argument list for exec
  436.  
  437.  end tim
  438.