home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBODSG / TSHELL.MAC < prev    next >
Text File  |  2000-06-30  |  14KB  |  672 lines

  1.     title    'tShell (c) 1985 S. Kluger, all rights reserved'
  2.     name    ('tShell')
  3. .z80
  4. ;
  5. ;    prerelease blues:
  6. ; start:
  7. ;    11/29/85    cold start, drawn up TSHELL.DEF
  8. ;    12/01/85    part 1 and 2
  9. ;    12/05/85    finished up main code
  10. ;    12/08/85    main code bug free
  11. ;    12/09/85    first live test, added hook for drive redef
  12. ;    12/11/85    completed user area lockout, rewrote TIMECL code
  13. ;    12/13/85    completed user 31 exception, added "CNTROL" to
  14. ;            prevent access across network for some fcns,
  15. ;            added terminal config block and access code
  16. ;    12/14/85    moved signon message to login program (from usrsom)
  17. ;    12/15/85    added printer/print mode setup
  18. ;    12/20/85    added return dskast function
  19. ;    12/21/85    added set dskast function, added remote lock
  20. ;    12/22/85    added system reset date/time function, added TIMECL
  21. ;            suppress code to SCREEN byte
  22. ;    12/25/85    fixed AUTUSR bug
  23. ;    01/01/86    changed for USRSUP, added fcn 16,17,18,19
  24. ;    01/02/86    added sneaky serial # check
  25. ;    01/04/86    fixed problem in fcn 15 when date not set
  26. ;
  27. ; alpha:
  28. ; beta:
  29. ;    release updates:
  30. ;
  31. ;
  32. ;    serial number/version stuff
  33. ;
  34. vers    equ    152h        ; version (1.52)
  35. orig    equ    24
  36. unit    equ    623
  37. shel    equ    1        ; internal serial #
  38. ;
  39.     aseg
  40. ?orig?    equ    orig        ; set up serial number origin...
  41. ?unit?    equ    unit        ; and unit.
  42.     public    ?orig?,?unit?
  43. ;
  44. ;
  45. ;    +-----------------------+
  46. ;    | part 1 - data storage |
  47. ;    +-----------------------+
  48. ;
  49. ;
  50.     dseg
  51. ;
  52.     include    TSHELL.DEF
  53.     include TERMINAL.CFG
  54. ;
  55. drvtbl:    ds    16*3        ; slave's original DSKAST
  56. flag31:    db    0        ; user 31 access flag
  57. srhsav:    db    0        ; search drive save
  58. ;
  59. fcntbl:    dw    xxfc00        ; get parameter block
  60.     dw    xxfc01        ; set parameter block
  61.     dw    xxfc02        ; log off (clear pb and dskast)
  62.     dw    xxfc03        ; send console message
  63.     dw    xxfc04        ; allow/disallow user 31 access
  64.     dw    xxfc05        ; spy on user/attach remote
  65.     dw    xxfc06        ; reset this processor
  66.     dw    xxfc07        ; abort current process
  67.     dw    xxfc08        ; get terminal configuration
  68.     dw    xxfc09        ; set terminal configuration
  69.     dw    xxfc10        ; return dskast
  70.     dw    xxfc11        ; set dskast
  71.     dw    xxfc12        ; lock remote attach
  72.     dw    xxfc13        ; unlock remote attach
  73.     dw    xxfc14        ; return last system reset date/time
  74.     dw    xxfc15        ; set reset date/time
  75.     dw    xxfc16        ; return master node
  76.     dw    xxfc17        ; suspend until date/time
  77.     dw    xxfc18        ; execute program
  78.     dw    xxfc19        ; return tShell serial number
  79. nmbfcn    equ    ($-fcntbl)/2    ; number of functions
  80. ;
  81. lrsdt:    dw    0        ; last reset date
  82. lrstm:    dw    0        ;   time
  83. lrsst:    dw    0        ;   tick
  84. locked:    db    0        ; locked flag
  85. abcpf:    db    0        ; flag to abort current process
  86. resflg:    db    0        ; reset active flag
  87. twxflg:    db    0        ; twix active flag
  88. twxbuf:    ds    128        ; twix message buffer
  89. execut:    db    0        ; execute flag
  90. execp:    dw    execl
  91. execl:    ds    128        ; execute buffer
  92. ;
  93. id:    db    '.tShell.'
  94. ;
  95. ;
  96. ;    +-------------------------+
  97. ;    | part 2 - initialization |
  98. ;    +-------------------------+
  99. ;
  100.     common    /?init?/
  101. ;
  102. usrin@::
  103.     ld    de,tshpr
  104.     call    crproc##    ; create rsp
  105.     ld    a,(autusr##)    ; get autusr byte
  106.     and    80h        ; see if default logon privileged
  107.     jr    nz,.nsru.    ;   do not patch SRUFCN
  108.     ld    a,0c3h        ; patch SRUFCN
  109.     ld    (srufcn##+12),a
  110.     ld    hl,sruint
  111.     ld    (srufcn##+13),hl
  112. .nsru.:    ld    hl,timecl    ; patch timecl
  113.     ld    (cmdint##+12),hl
  114.     ld    de,drvtbl    ; move the dskast
  115.     ld    hl,dskast##
  116.     ld    bc,16*3
  117.     ldir
  118.     ld    a,(srhdrv##)    ; get and save search drive
  119.     ld    (srhsav),a
  120.     ld    hl,(conast##+1)    ; get console entry point
  121.     ld    (consol),hl    ; store it here
  122.     ld    hl,conint    ; get intercept address
  123.     ld    (conast##+1),hl    ; redirect console
  124.     ld    a,nmbfcn
  125.     ld    hl,id
  126.     ret
  127. ;
  128. ;    +------------------------+
  129. ;    | part 3 - mainline code |
  130. ;    +------------------------+
  131. ;
  132.     cseg
  133. ;
  134. usrfc@::
  135.     push    hl
  136.     push    de
  137.     push    bc
  138.     call    xxfc15
  139.     pop    bc
  140.     pop    de
  141.     pop    hl
  142.     ld    a,l        ; get function number
  143.     cp    nmbfcn+1    ; in range?
  144.     jr    c,..uok.    ;   yes, process fcn
  145.     ld    a,0ffh
  146.     ret
  147. ;
  148. ..uok.:    ld    h,0        ; hl=function #
  149.     add    hl,hl
  150.     push    de        ; save de
  151.     ld    de,fcntbl
  152.     add    hl,de        ; hl points to fcn address
  153.     pop    de
  154.     ld    a,(hl)
  155.     inc    hl
  156.     ld    h,(hl)
  157.     ld    l,a
  158.     jp    (hl)        ; execute function
  159. ;
  160. ;    +----------------------------------+
  161. ;    | function 0 - get parameter block |
  162. ;    +----------------------------------+
  163. ;
  164. xxfc00:    ld    d,b        ; move destination (dma)
  165.     ld    e,c
  166.     ld    hl,LCLID    ; point to source
  167. gspb:    ld    bc,128
  168.     ldir
  169.     xor    a        ; set ok flag
  170.     ret
  171. ;
  172. ;    +----------------------------------+
  173. ;    | function 1 - set parameter block |
  174. ;    |      and log user on       |
  175. ;    +----------------------------------+
  176. ;
  177. xxfc01:    call    cntrol        ; see if authorized
  178.     ret    nz
  179.     ld    a,(LCLLGD)    ; get logged flag
  180.     or    a        ; logged?
  181.     ret    nz        ;   yes, barf
  182.     dec    a        ; make a=ff
  183.     ld    (LCLLGD),a    ; set logged true
  184.     ld    h,b        ; move source (dma)
  185.     ld    l,c
  186.     ld    de,LCLID
  187.     call    gspb        ; wrap up
  188.     ld    a,(LCLDPR)    ; get default printer/queue
  189.     ld    (queptr##),a    ; reset it
  190.     ld    a,(LCLDPM)    ; get default print mode
  191.     ld    (prtmod##),a    ; reset it
  192.     ld    a,(LCLSHD)    ; get defined search drive
  193.     ld    (srhdrv##),a    ; set new search drive
  194.     call    redef        ; effect drive redefinition
  195.     ld    b,8        ; 16 drives to process twice
  196.     ld    hl,dskast##    ; patch target
  197.     ld    a,(LCLDRA+1)    ; get access for A..H
  198.     call    ..sds.        ; patch
  199.     ld    b,8        ; the next 8
  200.     ld    a,(LCLDRA)    ; access for J..P
  201.     call    ..sds.
  202.     xor    a        ; set ok flag
  203.     ret
  204. ;
  205. ..sds.:    rra            ; drive bit into carry
  206.     jr    c,.sdx.        ; skip if allowed
  207.     ld    (hl),0ffh    ;   else patch to offline
  208. .sdx.:    inc    hl
  209.     inc    hl
  210.     inc    hl        ; point to next drive
  211.     djnz    ..sds.        ; repeat until 8 drives done
  212.     ret
  213. ;
  214. ;    +----------------------+
  215. ;    | function 2 - log off |
  216. ;    +----------------------+
  217. ;
  218. xxfc02:    call    cntrol        ; authorization check
  219.     ret    nz
  220.     ld    hl,LCLID    ; clear pb
  221.     ld    b,128
  222. ..lof.:    ld    (hl),0
  223.     inc    hl
  224.     djnz    ..lof.
  225.     ld    hl,drvtbl    ; restore dskast
  226.     ld    de,dskast##
  227.     ld    bc,16*3
  228.     ldir
  229.     xor    a
  230.     ld    (flag31),a    ; set 31 access flag off
  231.     ld    a,(srhsav)    ; reset search drive
  232.     ld    (srhdrv##),a
  233.     ret
  234. ;
  235. ;    +-----------------------------------+
  236. ;    | function 3 - send console message |
  237. ;    +-----------------------------------+
  238. ;
  239. xxfc03:    ld    h,b
  240.     ld    l,c
  241.     ld    de,twxbuf
  242.     ld    bc,128
  243.     ldir
  244.     ld    a,0ffh
  245.     ld    (twxflg),a
  246.     ret
  247. ;
  248. ;    +-----------------------------+
  249. ;    | function 4 - user 31 access |
  250. ;    +-----------------------------+
  251. ;
  252. xxfc04:    call    cntrol        ; authorized?
  253.     ret    nz
  254.     ld    hl,flag31    ; point to access flag
  255.     ld    a,(hl)        ; get it to a
  256.     cpl            ; complement (toggle) it
  257.     ld    (hl),a        ; save it
  258.     ret            ; a returns status
  259. ;
  260. ;    +--------------------------+
  261. ;    | function 5 - spy on user |
  262. ;    +--------------------------+
  263. ;
  264. xxfc05:    xor    a            ; not implemented
  265.     ret
  266. ;
  267. ;    +----------------------------+
  268. ;    | function 6 - reset station |
  269. ;    +----------------------------+
  270. ;
  271. xxfc06:    ld    a,0ffh
  272.     ld    (resflg),a        ; set reset flag
  273.     ret
  274. ;
  275. ;    +------------------------------------+
  276. ;    | function 7 - abort current process |
  277. ;    +------------------------------------+
  278. ;
  279. xxfc07:    ld    a,0ffh        ; set abort flag, so that the guy...
  280.     ld    (abcpf),a    ; ...gets blown off at next console I/O
  281.     ret
  282. ;
  283. ;    +-----------------------------------------+
  284. ;    | function 8 - get terminal configuration |
  285. ;    +-----------------------------------------+
  286. ;
  287. xxfc08:    call    cntrol        ; allowed?
  288.     ret    nz        ; no, return undone
  289.     ld    d,b        ; move destination
  290.     ld    e,c        ;   into bc
  291.     ld    hl,TCFBLK    ; source to hl
  292. .gspb:    jp    gspb        ; move
  293. ;
  294. ;    +-----------------------------------------+
  295. ;    | function 9 - set terminal configuration |
  296. ;    +-----------------------------------------+
  297. ;
  298. xxfc09:    call    cntrol        ; allowed?
  299.     ret    nz        ; no, return undone
  300.     ld    h,b        ; move source
  301.     ld    l,c        ;   into hl
  302.     ld    de,TCFBLK    ; set up destination
  303.     jr    .gspb        ; move it
  304. ;    
  305. ;    +-----------------------------+
  306. ;    | function 10 - return dskast |
  307. ;    +-----------------------------+
  308. ;
  309. xxfc10:    call    cntrol        ; local call?
  310.     ret    nz        ;   no, barf
  311.     ld    d,b        ; move destingation
  312.     ld    e,c
  313.     ld    hl,dskast##
  314.     jr    .gspb
  315. ;
  316. ;    +--------------------------+
  317. ;    | function 11 - set dskast |
  318. ;    +--------------------------+
  319. ;
  320. xxfc11:    call    cntrol        ; local call?
  321.     ret    nz        ;   no, ignore
  322.     ld    a,(LCLLV)    ; get access byte
  323.     and    3        ; mask priv level
  324.     sub    2        ; see if full
  325.     ret    nz        ;   no, ignore
  326.     ld    h,b        ; move source
  327.     ld    l,c
  328.     ld    de,dskast##
  329.     ld    bc,16*3
  330.     ldir
  331.     xor    a        ; return ok
  332.     ret
  333. ;
  334. ;    +----------------------------------+
  335. ;    | function 12 - lock remote attach |
  336. ;    +----------------------------------+
  337. ;
  338. xxfc12:    ld    a,(locked)    ; get locked flag
  339.     inc    a        ; test it
  340.     ret    z        ; return if locked
  341.     ld    a,0ffh
  342. .lunl.:    ld    (locked),a    ; lock
  343.     ret
  344. ;
  345. ;    +------------------------------------+
  346. ;    | function 13 - unlock remote attach |
  347. ;    +------------------------------------+
  348. ;
  349. xxfc13:    xor    a
  350.     jr    .lunl.
  351. ;
  352. ;    +---------------------------------------------+
  353. ;    | function 14 - return last system reset time |
  354. ;    +---------------------------------------------+
  355. ;
  356. xxfc14:    ld    hl,(lrsdt)        ; get last reset date
  357.     ld    de,(lrstm)        ;   hours and minutes
  358.     ld    bc,(lrsst)        ;   seconds and tick count
  359.     ret
  360. ;
  361. ;    +-----------------------------------+
  362. ;    | function 15 - set reset date/time |
  363. ;    +-----------------------------------+
  364. ;
  365. xxfc15:    ld    c,10
  366.     call    otntry##
  367.     ld    a,0ffh
  368.     bit    7,h
  369.     ret    nz            ; invalid date/time
  370.     ld    (lrsdt),hl
  371.     ld    (lrstm),de
  372.     ld    (lrsst),bc
  373.     ld    a,0c9h
  374.     ld    (xxfc15),a        ; inhibit re-entry
  375.     ret
  376. ;
  377. ;    +----------------------------------+
  378. ;    | function 16 - return master node |
  379. ;    +----------------------------------+
  380. ;
  381. xxfc16:    ld    hl,(defdid##)
  382.     ret
  383. ;
  384. ;    +-----------------------------+
  385. ;    | function 17 - suspend until |
  386. ;    +-----------------------------+
  387. ;
  388. xxfc17:    push    iy
  389.     push    bc            ; save pointer to dma buffer
  390.     ld    c,10
  391.     call    otntry##        ; get date and time
  392.     pop    iy            ; pointer into IY
  393.     ld    a,l
  394.     cp    (iy)
  395.     jr    nz,.17.n        ; skip if negative compare
  396.     ld    a,h
  397.     cp    (iy+1)
  398.     jr    nz,.17.n
  399.     ld    a,e
  400.     cp    (iy+2)
  401.     jr    nz,.17.n
  402.     ld    a,d
  403.     cp    (iy+3)
  404. .17.n:    push    iy
  405.     pop    bc
  406.     pop    iy
  407.     ret    z            ; return if done
  408.     push    bc
  409.     ld    c,2
  410.     ld    de,60            ; else wait a second
  411.     call    otntry##
  412.     pop    bc
  413.     jr    xxfc17
  414. ;
  415. ;    +------------------------------------+
  416. ;    | function 18 - execute command line |
  417. ;    +------------------------------------+
  418. ;
  419. xxfc18:    ld    h,b
  420.     ld    l,c
  421.     ld    de,execl
  422.     ld    a,(hl)
  423.     or    a
  424.     ret    z
  425.     call    gspb
  426.     ld    hl,execl
  427.     ld    (execp),hl
  428.     ld    a,1
  429.     ld    (execut),a
  430.     ret
  431. ;
  432. ;    +------------------------------------+
  433. ;    | function 19 - return serial number |
  434. ;    +------------------------------------+
  435. ;
  436. xxfc19:    ld    hl,shel        ; return serial #
  437.     ld    de,vers        ; and version #
  438.     ld    bc,unit
  439.     ld    a,orig
  440.     ret
  441. ;
  442. ;
  443. ;    +---------------------------+
  444. ;    | part 4 - resident process |
  445. ;    +---------------------------+
  446. ;
  447. ;
  448. tshpr:    ld    c,12
  449.     call    otntry##
  450.     ld    hl,unit
  451.     or    a
  452.     sbc    hl,de
  453.     jr    nz,.crash
  454.     ld    c,2            ; do it once a second
  455.     ld    de,60
  456.     call    otntry##
  457.     ld    a,(resflg)        ; get reset flag
  458.     inc    a
  459.     jr    nz,.tshnr        ; skip if no reset
  460.     ld    c,2
  461.     ld    de,240            ; delay 4 seconds
  462.     call    otntry##
  463.     call    xreset##        ; call external reset
  464. .crash:    di
  465.     halt
  466. ;
  467. .tshnr:    ld    a,(twxflg)        ; get twix flag
  468.     inc    a
  469.     call    z,sndtwx        ; send twix if there
  470.     jp    tshpr            ; and loop
  471. ;
  472. sndtwx:    ld    hl,twxbuf        ; point to buffer
  473.     ld    a,(hl)            ; get length
  474.     or    a            ; empty?
  475.     ret    z            ; yes, return
  476.     ld    b,a
  477.     inc    hl
  478. ..stwx:    push    bc
  479.     push    hl
  480.     ld    a,(conast##)
  481.     ld    d,a
  482.     ld    e,2
  483.     ld    c,(hl)
  484.     call    condra##
  485.     pop    hl
  486.     pop    bc
  487.     inc    hl
  488.     djnz    ..stwx
  489. ;
  490. ;
  491. ;    +-------------------------+
  492. ;    | part 5 - intercept code |
  493. ;    +-------------------------+
  494. ;
  495. ; 1. set user number intercept
  496. ;
  497. sruint:    call    chkusr        ; check user access
  498.     ret    nc        ; ignore if restricted
  499.     ld    (ix+40h),a    ;   else store user number
  500.     ret
  501. ;
  502. ; 2. prompt display intercept
  503. ;
  504. timecl:    ld    a,(clblen##+9)
  505.     or    a        ;if prompt inhibit...
  506.     jr    nz,skip        ;...then don't display time
  507.     ld    a,(LCLSCM)    ; get screen byte
  508.     bit    6,a        ; see if TIMECL disabled
  509.     jr    nz,skip        ;   skip if disabled
  510.     ld    c,10
  511.     call    otntry##    ; get time
  512.     ld    a,d        ; get hours
  513.     call    bytout
  514.     ld    (timst+1),hl
  515.     ld    a,e        ; get minutes
  516.     call    bytout
  517.     ld    (timst+4),hl
  518.     ld    c,12
  519.     call    ocntry##
  520.     ld    a,d
  521.     add    a,'A'
  522.     ld    (sta),a
  523.     ld    a,e
  524.     call    bytout
  525.     ld    (net),hl
  526.     call    dms##
  527. timst:    db    '[00:00 '
  528. sta:    db    'A'
  529. net:    db    '00] ',80h
  530. skip:    ld    a,(ix+40h)
  531.     ret
  532. ;
  533. bytout:    ld    l,'0'-1
  534. ..l:    inc    l
  535.     sub    10
  536.     jr    nc,..l
  537.     add    a,'0'+10
  538.     ld    h,a
  539.     ret
  540. ;
  541. ; 3. console I/O intercept
  542. ;
  543. conint:    ld    a,(abcpf)    ; get abort flag
  544.     inc    a
  545.     jr    nz,.nabrt    ; don't abort
  546.     ld    (abcpf),a
  547.     call    dms##        ; let the sucker know
  548.     0dh,0ah,0ah,7
  549.     '[OPERATOR TERMINATED]',0dh,0ah,80h
  550.     jp    errxit##    ; trash him
  551. ;
  552. .nabrt:    ld    a,(execut)
  553.     or    a
  554.     jr    z,.nexec
  555.     call    .exab            ; abort whatever we're doing
  556.     ld    a,e
  557.     cp    2
  558.     jr    nc,.nexec
  559.     ld    hl,(execp)
  560.     inc    hl
  561.     or    a
  562.     jr    nz,.exns
  563.     ld    a,(execl)
  564.     or    a
  565.     ret    z
  566.     ld    c,(hl)
  567.     ld    a,0ffh
  568.     ret
  569. ;
  570. .exns:    ld    a,(execl)
  571.     dec    a
  572.     ld    (execl),a
  573.     jp    m,doexe
  574.     ld    (execp),hl
  575.     ld    a,(hl)
  576.     ret
  577. ;
  578. doexe:    xor    a
  579.     ld    (execut),a
  580. .nexec:    jp    0        ; patched later
  581. consol    equ    $-2
  582.  
  583. ;
  584. .exab:    ld    a,0c9h
  585.     ld    (.exab),a
  586.     jp    errxit##
  587. ;
  588. ;    +------------------------------+
  589. ;    | part 6 - utility subroutines |
  590. ;    +------------------------------+
  591. ;
  592. ;
  593. ; 1. check user
  594. ;    input:  A = desired user area
  595. ;    output: C = allowed or NC = restricted
  596. ;         no registers altered
  597. ;
  598. chkusr:    and    1fh            ; make 0..1f
  599.     push    hl
  600.     ld    hl,LCLLGD
  601.     bit    7,(hl)
  602.     pop    hl
  603.     scf
  604.     ccf
  605.     ret    z        ; exit if unlogged
  606.     cp    31        ; user 31 requested?
  607.     jr    nz,n.31.    ;   no, continue normally
  608.     push    hl
  609.     ld    hl,flag31    ; point to user 31 access flag
  610.     inc    (hl)
  611.     dec    (hl)
  612.     pop    hl        ; Z if flag off
  613.     jr    z,n.31.        ; check if maybe authorized anyway
  614.     scf
  615.     ret            ; say yes
  616. ;
  617. n.31.:    push    bc
  618.     push    hl
  619.     ld    c,a        ; save requested user area
  620.     ld    a,(LCLLV)    ; get his access level
  621.     and    3        ; mask acl
  622.     cp    2        ; check if full access
  623.     ld    a,c
  624.     scf            ; preset true
  625.     jr    z,.n.res    ; skip if authorized
  626.     cp    8        ; over 7?
  627.     ld    hl,LCLUSA
  628.     jr    c,..ck..
  629.     cp    16        ; over 15?
  630.     inc    hl
  631.     jr    c,..ck..
  632.     cp    24        ; over 23
  633.     inc    hl
  634.     jr    c,..ck..
  635.     inc    hl
  636. ..ck..:    and    7        ; make 0..7
  637.     ld    b,a        ; into counter
  638.     inc    b        ; iterate at least once
  639.     ld    a,(hl)        ; get access bits
  640. ..ckl.:    rra            ; move bits around
  641.     djnz    ..ckl.        ;   until right one is in CY
  642.     ld    a,c        ; get user area back
  643. .n.res:    pop    hl        ; restore hl
  644.     pop    bc        ; restore bc
  645.     ret
  646. ;
  647. ; 2. dskast patch for drive re-definition
  648. ;    no input, output, all regs used
  649. ;    NOTE: for testing, redef is allowed for A:
  650. ;
  651. redef:
  652.     ret            ; later
  653.  
  654. ;
  655. ; 3. check for authorization.
  656. ;    a call here verifies that DE=FFFF
  657. ;
  658. cntrol:    inc    de
  659.     ld    a,d
  660.     or    e
  661.     ld    a,0ffh        ; set false
  662.     ret
  663.  
  664.  
  665.  
  666.     end
  667.         ; check if maybe authorized anyway
  668.     scf
  669.     ret            ; say yes
  670. ;
  671. n.31.:    push    bc
  672.     push