home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / SYSUTL / TSRWRK32.ZIP / UNMARK.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-06  |  23.5 KB  |  796 lines

  1. Title    UnMark.ASM -- Replaces TurboPower RELEASE Version 2.8
  2. ;v3.2 Toad Hall Tweak
  3.  
  4. CSEG    Segment Public Para   ;Version 3.1 31-May-1989 - 03:10
  5.     Assume    CS:CSEG,DS:CSEG
  6.  
  7.     Org 0100h
  8. Main    Proc    Far
  9.     Jmp Start
  10.  
  11. UsageMsg    DB  13,'   ',9,10
  12. DB 'UnMark replaces RELEASE ver 2.8 by TurboPower Software',13,10,9
  13. DB '======================================================',13,10,9
  14. DB 'UnMark, like RELEASE, removes memory-resident programs',13,10,9
  15. DB 'and restores interrupt vectors to pre[F]Mark addresses.',13,10,10,9
  16. DB 'UnMark will UpDate the WATCH data area when WATCH has',13,10,9
  17. DB 'been installed ahead of the [F]Mark that is removed.',13,10,10,9
  18. DB 'UnMark also releases any Lotus/Intel expanded memory',13,10,9
  19. DB 'used by TSR programs which it releases.',13,10,10,9
  20. DB '/Keep [F]Mark and /No EMS RELEASE options are NOT',13,10,9
  21. DB 'implemented in UnMark.  The UnMark syntax is:',13,10,10,9
  22. DB 'UNMARK [[FilePath\]MarkName] [Options]',13,10,10,9
  23. DB 9,'[/]?',9,'Write this Help screen',13,10,10,9
  24. DB 'Other Options MUST begin with a "/" character:',13,10,10
  25. DB 9,9,'/D',9,"Display MCBs",13,10
  26. DB 9,9,'/R',9,'Leave 8259 interrupt controller as is',13,10
  27. DB 9,9,'/S',9,'STUFF Keyboard Buffer (<=14 bytes+CR)'
  28.  
  29. crlf        DB  13,10,"$",8,32,26    ; You can >TYPE UnMark.COM
  30. emsID        DB  'EMMXXXX0'
  31. markID        DB  '3.2 TSR '        ; ID of [F]Marks 7 bytes    v3.2
  32. watchM        DB  'WATCHER$'        ; or Watch ID = 12 bytes
  33. header        DB  ' MCB Block Len User  Release? $'
  34. trumsg        DB  '  True  $'
  35. falmsg        DB  ' False  $'
  36. mrkmsg        DB  '[F]Mark$PARAMETER'
  37. pgmmsg        DB  'Program$'
  38. envmsg        DB  'Environ$'
  39. trapmsg        DB  'Trapped$'
  40. notfound    DB  13,10,'NO '
  41. wasfound    DB  '[F]Mark found',13,10,"$"
  42. protected$    DB  13,10,'Protected Mark Encountered!',13,10,"$"
  43. fileError    DB  13,10,'Error Reading FMark File!',13,10,"$"
  44. releasErr    DB  13,10,'Release Failed!',13,10,'$'
  45. rammsg        DB  'RAM bytes available: '
  46. free$        DB  6 DUP(' '),13,10,"$"
  47. flagd        DB  0            ; Display MCBs IF Set
  48. flagr        DB  0            ; Reset 8259 UNLESS Set
  49. ascii_tbl    DB  "!#$%&()-1234567890:'@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_{}~"
  50. NUMCHARS    equ $ - ascii_tbl
  51. scanc_tbl    label    byte
  52.     DB  2,4,5,6,8,10,11,12,2,3,4,5,6,7,8,9,10,11,39,40,3,30,48,46
  53.     DB  32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47
  54.     DB  17,45,21,44,43,7,12,26,27,41,0
  55. stuff_buf DW    15 DUP(1C0Dh)
  56. errlvl    DW    4C00h            ; Set for Program Exit
  57. pflaga    DW    0            ; Set if Protected Mark
  58. mflaga    DW    0            ; [F]Mark PSP When Found
  59. watchf    DW    0            ; PSP of Watch When Found
  60. fmarkf    DW    0            ; Set if FMark File Found
  61. MKPARM    equ    offset BUFFER        ; Command [F]Mark Name
  62. mrklen    DW    ?            ; Length of Name
  63. MCBBUF    equ    MKPARM  +  40h        ; MCB Table and [F]Mark
  64. mcbend    DW    ?            ; End of MCB area
  65. VECTOR    equ    MCBBUF  + 400h        ; Interrupt Vectors, EGA and
  66. PARENT    equ    VECTOR  + 418h        ; ICA areas plus Parent Word
  67. EMSCNT    equ    PARENT  +   2h        ; EMS Handle Count and MAP
  68. EMSMAP    equ    EMSCNT  +   2h        ; from [F]Mark Storage
  69.                     ; <= 100h bytes for MAP
  70.  
  71. Start:    xor    ax,ax            ; Zero
  72.     mov    cx,2048            ; data
  73.     mov    di,MKPARM        ; buffer
  74.     rep    stosw            ; words
  75.     mov    di,MKPARM        ; Set for [F]Mark ID
  76.     mov    si,81h            ; Get Command
  77.     call    Ploop            ; Parameter(s)
  78.     mov    ah,9            ; If NO ?
  79.     jnc    DoNew            ; Then New Line
  80.      mov    dx,offset UsageMsg    ; Else Display
  81.      int    21h            ; Syntax Message
  82.      jmp    Exit            ; and Exit
  83.  
  84. DoNew:    mov    dx,offset crlf        ; Display
  85.     int    21h            ; New Line
  86.     mov    dx,MKPARM        ; Calculate and
  87.     sub    di,dx            ; Store [F]Mark
  88.     mov    mrklen,di        ; Name Length
  89.     mov    ax,4300h        ; If Attributes
  90.     int    21h            ; NOT Returned
  91.     jc    DoBuf            ; Then NOT FMark
  92.      mov    fmarkf,CX        ; Else Flag as FMark
  93.  
  94. DoBuf:    mov    ah,52h            ; Undocumented
  95.     int    21h            ; Function
  96.     mov    di,ES:[bx-2]        ; obtains
  97.     mov    ES,di            ; MCB of DOS
  98.     inc    di            ; Config.Sys
  99.     mov    si,MCBBUF        ; Initialize Source and
  100.     xor    bx,bx            ; Basic Index Pointers
  101.  
  102. MCBlp:    add    di,ES:[3]        ; Advance so as to
  103.     mov    ES,di            ; Point to MCB and
  104.     inc    di            ; Next Paragraph
  105.     mov    [si+bx+0],es        ; Store MCB
  106.     mov    dx,ES:[1]        ; Get and Store
  107.     mov    [si+bx+2],dx        ; Block Address
  108.     mov    ax,ES:[3]        ; and Block
  109.     mov    [si+bx+4],ax        ; Length
  110.     call    DoFlags            ; Set Appropriate Flags
  111.     add    bx,8            ; Advance to Next and
  112.     cmp    byte ptr ES:[0],"Z"    ; Loop Until Last MCB
  113.     jne    MCBlp
  114.  
  115. ;v3.2    push    DS            ; Restore Extra Segment
  116. ;    pop    ES            ; Register to DATA
  117.     mov    ax,DS            ;restore ES to data        v3.2
  118.     mov    ES,ax
  119.     mov    mcbend,si        ; Initialize MCB buffer end
  120.     add    mcbend,bx        ; Adjust buffer end for length
  121.     mov    ax,mflaga        ; If NO [F]Mark
  122.     or    ax,ax            ; Name Matched
  123.     jz    CkLast            ; Then Try Last
  124.      cmp    ax,pflaga        ; Else If Below Protected
  125.      jc    IsPME            ; Then Protected Error Exit
  126.  
  127. CkLast:    mov    di,si            ; Point to Buffer
  128.     mov    ax,-1            ; Find [F]Mark
  129.     mov    cx,bx            ; for Release
  130.     shr    cx,1            ; In MCB Words
  131.     repne    scasw            ; If None Found Yet
  132.     jne    DoLast            ; Then Assume Last Mark
  133.      jmp    DoMark            ; Else Get [F]Mark Data
  134.  
  135. DoLast:    cmp    word ptr mrklen,0    ; If [F]Mark
  136.     jnz    NoMark            ; Command Name
  137.  
  138.     mov    di,mcbend        ; Or If Scan MCBs
  139.     std                ; backwards finds
  140.     mov    cx,bx            ; NO [F]Mark
  141.     repne    scasb            ; Marked
  142.     cld                ; Then NO [F]Mark
  143.     jne    NoMark            ; Found Error Exit
  144.  
  145.     sub    di,5            ; Else Point to
  146.     mov    bx,di            ; [F]Mark Record
  147.     sub    bx,si            ; With Basic Index
  148.     mov    di,MKPARM        ; Set Destination
  149.     push    si            ; Preserve
  150.     push    DS            ; Source
  151.     mov    DS,[si+bx+2]        ; Point to and
  152.     mov    si,81h            ; Get Command
  153.     call    Ploop            ; [F]Mark Name
  154.     pop    DS            ; Restore
  155.     pop    si            ; Source
  156.     mov    cx,di            ; If NO [F]Mark
  157.     sub    cx,MKPARM        ; Command Length
  158.     jz    ReLast            ; Then Release Mark
  159.  
  160.     mov    di,MKPARM        ; Else Scan
  161.     mov    al,"!"            ;  for "!"
  162.     repne    scasb            ; If Found
  163.     je    IsPME            ; Then Protected Error Exit
  164.     jmp    short NoMark        ; Else Is Named Mark
  165.  
  166. ReLast:    mov    ax,[si+bx+2]        ; Set the [F]Mark
  167.     mov    mflaga,ax        ; PSP Address and
  168.     mov    mrklen,ax        ; use as Length
  169.     mov    word ptr [si+bx+6],-1    ; Flag for Release
  170.     mov    ES,[si+bx+0]        ; Re-Set Registers
  171.     mov    di,[si+bx+2]        ; and Re-Enter MCBs
  172.     add    bx,8            ; Loop after [F]Mark to
  173.     jmp    MCBlp            ; Release subsequent MCBs
  174.  
  175. IsPME:    cmp    flagd,0FFh        ; If NO Display MCBs Flag
  176.     jne    DoPME            ; Then Skip to Message
  177.      call    DoDeBug            ; Else Show MCBs
  178. DoPME:    mov    dx,offset protected$    ; Error Exit with
  179.     mov    byte ptr errlvl,1    ; Error Level 1 and
  180.     jmp    Show            ; Protected [F]Mark Message
  181.  
  182. NoMark:    cmp    flagd,0FFh        ; If NO Display MCBs Flag
  183.     jne    DoNFM            ; Then Skip to Message
  184.      call    DoDeBug            ; Else Show MCBs
  185. DoNFM:    mov    dx,offset notfound    ; Error Exit with
  186.     mov    byte ptr errlvl,2    ; Error Level 2 and
  187.     jmp    short Show        ; Not Found Message
  188.  
  189. DoFErr:    mov    ah,3Eh            ; Close the File
  190.     int    21h            ; Handle If Possible
  191.     mov    dx,offset fileError    ; Reading [F]Mark File
  192.     mov    byte ptr errlvl,3    ; Error Level 3 and
  193.     jmp    short Show        ; Exit without Release
  194.  
  195. DoMark:    mov    dx,di            ; Save Pointer and
  196.     mov    bx,ES:[di+2]        ; Block of [F]Mark
  197. DMloop:    sub    di,8            ; If Down to
  198.     cmp    si,di            ; MCBBUF start
  199.     jnc    IfMark            ; Then Do File or Mark
  200.     mov    ax,ES:[di+2]        ; Else If Block
  201.     mov    cx,ES:[di]        ; Compared to
  202.     inc    cx            ; MCB + 1
  203.     cmp    ax,cx            ; Shows
  204.     jz    DMloop            ; Program
  205.     or    ax,ax            ; Or If Trapped
  206.     jz    DMloop            ; Block Or If
  207.     cmp    ax,bx            ; Less Than [F]Mark
  208.     jc    DMloop            ; Then Continue Look-Back
  209.     mov    byte ptr ES:[di+7],0FFh ; Else Mark Environment
  210.     jmp    short DMloop        ; Loop-Back Until Start
  211.  
  212. IfMark:    mov    di,dx            ; Restore Pointer to [F]Mark
  213.     cmp    word ptr fmarkf,0    ; If NOT File Mark
  214.     jz    IsMark            ; Then is Memory
  215.  
  216.     mov    dx,MKPARM        ; Else Open File
  217.     mov    ax,3D00h        ;  for Read Only
  218.     int    21h            ; If Open Fails
  219.     jc    DoFErr            ; Then File Error Exit
  220.     mov    dx,VECTOR        ; Else Copy Interrupt
  221.     mov    cx,051Ch        ; EGA, ICA, Parent and
  222.     mov    bx,ax            ; EM Handle Count from
  223.     mov    ah,3Fh            ; File Mark file
  224.     int    21h            ; If file Read Fails
  225.     jc    DoFErr            ; Then File Error Exit
  226.      mov    ah,3Eh            ; Else Close the
  227.      int    21h            ; File Handle and
  228.      jmp    short MkExit        ; Check DeBug Flag
  229.  
  230. IsMark:    mov    DS,[di-6]        ; Get Memory data
  231.     mov    si,0120h        ; Copy Mark Interrupts
  232.     mov    cx,051Ch        ; EGA,ICA, Parent and
  233.     mov    di,VECTOR        ; EMS Information
  234.     rep    movsb            ; Into data buffer
  235.     mov    cx,CS            ; Restore            v3.2
  236.     mov    DS,cx            ; Segment            v3.2
  237. MkExit:    cmp    flagd,0FFh        ; If NO Flag
  238.     mov    dx,offset wasfound    ; Then Show
  239.     jne    Show            ; only Result
  240.      call    DoDeBug            ; Else MCBs also
  241. Show:    mov    ah,9            ; Display
  242.     int    21h            ; Message
  243.     mov    si,mcbend        ; Start at the
  244.     sub    si,8            ; UnMark Block
  245.     mov    di,MCBBUF        ; Working Toward
  246.     add    di,16            ; DOS Environment
  247.     mov    dx,[si+2]        ; Get UnMark Address
  248.     mov    ax,[si+4]        ; and Free at UnMark
  249.     cmp    dx,[si-6]        ; Unless Contiguous
  250.     jne    ChkErr            ; UnMark Environment
  251.      inc    ax            ; Don't Include MCB
  252. ChkErr:    cmp    byte ptr errlvl,0    ; If an UnMark Error
  253.     jnz    FreeOk            ; Then Free is Unchanged
  254.  
  255. LookLp:    sub    si,8            ; Look-Back Loop
  256.     mov    cx,[si+2]        ; If Block Address
  257.     cmp    cx,dx            ; IS Same as UnMark
  258.     je    EndChk            ; Then Don't Add
  259.     or    cx,cx            ; Else If NOT Trapped
  260.     jnz    LookCk            ; Then Check If Marked
  261.     cmp    byte ptr [si+15],0    ; Else If Marked Above
  262.     jnz    LookAd            ; Then Add to Free
  263.      jmp    short EndChk        ; Else Don't Add
  264.  
  265. LookCk:    cmp    byte ptr [si+7],0    ; If Block NOT Marked
  266.     jz    EndChk            ; Then Don't Add
  267. LookAd:    add    ax,[si+4]        ; Else Add Length
  268.     inc    ax            ;  and MCB to Free
  269. EndChk:    cmp    di,si            ; Until Just Above
  270.     jc    LookLp            ; DOS Environment
  271.  
  272. FreeOk:    xor    dx,dx            ; Clear Extension
  273.     mov    dl,ah            ; Free RAM Equals
  274.     mov    cl,4            ; Free Paragraphs
  275.     shr    dx,cl            ; Converted to
  276.     shl    ax,cl            ; DD bytes in DX:AX
  277.     mov    bx,offset free$+6    ; Store Free as
  278.     mov    cx,10            ; Decimal Digits
  279. NexDig:    div    cx            ; Store each
  280.     or    dx,30h            ; ASCII digit
  281.     dec    bx            ; Right to Left
  282.     mov    [bx],dl            ; Until
  283.     xor    dx,dx            ; both DX
  284.     or    ax,ax            ; and AX
  285.     jnz    NexDig            ; are 0
  286.  
  287.     mov    ah,9            ; Display
  288.     mov    dx,offset rammsg    ; RAM Bytes Free
  289.     int    21h
  290.     cmp    byte ptr errlvl,0    ; If NO [F]Mark Error
  291.     jz    ChkEMS            ; Then Continue
  292.      jmp    Exit            ; Else Error Exit
  293.  
  294. ChkEMS:    mov    ax,3567h        ; Locate Driver
  295.     int    21h            ; Interrupt
  296.     mov    di,0Ah            ; Address
  297. ;v3.2    lea    si,emsID        ; If Name
  298.     mov    si,offset emsID        ;if name            v3.2
  299.     mov    cx,8            ; 'EMMXXXX0'
  300.     rep    cmpsb            ; Is NOT Found
  301.     mov    ax,CS            ; After Extra Segment        v3.2
  302.     mov    ES,ax            ; Register is Restored        v3.2
  303.     jne    EndEMS            ; Then NO EMS
  304.  
  305. ;v3.2    mov    di,EMSMAP        ; Else Point to
  306. ;v3.2    add    di,100h            ; Next Map Area
  307.     mov    di,EMSMAP+100H        ;else point to next map area    v3.2
  308.     mov    ah,4Dh            ; Get Current
  309.     int    67h            ; Handle Map
  310.     or    ah,ah            ; If Function Fails
  311.     jnz    EndEMS            ; Then EMS Broken
  312.     mov    si,EMSCNT        ; Else If [F]Mark
  313.     lodsw                ; Handle Count Is
  314.     mov    cx,bx            ; Not Less Than
  315.     cmp    ax,bx            ; Current Count
  316.     jnc    EndEMS            ; Then EMS NOT Used
  317.  
  318. EMSHlp:    mov    dx,ES:[di]        ; Else Compare
  319.     cmpsw                ; Maps and Release
  320.     cmpsw                ; Handle(s) NOT in
  321.     je    lpEMSH            ; [F]Mark Map Using
  322.      mov    ah,45h            ; Deallocate Handle
  323.      int    67h            ; EMS Function
  324.      or    ah,ah            ; If Ok AND More
  325. lpEMSH:    loopz    EMSHlp            ; Then Continue
  326.  
  327.     mov    byte ptr errlvl,ah    ; Else EMS Done
  328. EndEMS:    mov    ax,watchf        ; If WATCH
  329.     or    ax,ax            ; NOT Found
  330.     jz    WatchX            ; Then Skip
  331.  
  332.     mov    ES,ax            ; Else Point
  333.     mov    di,218h            ; short of WATCH
  334.     mov    dx,-1            ; Vector Change Area
  335.     mov    ax,mflaga        ; Looking for [F]Mark
  336.     mov    cx,620h
  337. UCloop:    add    di,8            ; If Reach End of
  338.     cmp    di,cx            ; Vector Change Area
  339.     jnc    WatchX            ; Then NO Changes
  340.     cmp    ES:[di],dx        ; Else If NOT PSPid
  341.     jnz    UCloop            ; Or If PSP is NOT
  342.     cmp    ES:[di+2],ax        ; PSP of [F]Mark
  343.     jnz    UCloop            ; Then Keep Looking
  344.  
  345.     mov    dx,di            ; Else Calculate
  346.     sub    dx,220h            ;  and store new
  347.     mov    ES:[104h],dx        ; vpos offset and
  348.     xor    al,al            ; Null-out
  349.     sub    cx,di            ; remaining
  350.     rep    stosb            ; Vector Change Area
  351.     mov    si,VECTOR        ; Copy Interrupt
  352.     mov    cx,200h            ; Vector words
  353.     mov    di,0A20h        ; Into WATCH prevv
  354.     rep    movsw            ; Current Vector Table
  355. WatchX:
  356. ;v3.2    push    CS            ; Restore Extra
  357. ;v3.2    pop    ES            ; Segment Register
  358.     mov    di,CS            ;restore ES            v3.2
  359.     mov    ES,di            ;v3.2
  360.     mov    di,MCBBUF        ; Prepare to Kill File(s)
  361. FileLp:
  362. ;v3.2    push    CS            ; Insure Data Segment
  363. ;v3.2    pop    DS            ; Register in Program
  364.     mov    ax,CS            ;insure DS            v3.2
  365.     mov    DS,ax            ;v3.2
  366.     mov    cx,mcbend        ; Calculate
  367.     sub    cx,di            ; Number of
  368.     shr    cx,1            ; Words to
  369.     mov    ax,-1            ; Scan for Marked
  370.     repne    scasw            ; [F]Mark Blocks
  371.     jne    CheckR            ; Until all Done
  372.  
  373.     mov    DS,ES:[di-6]        ; Point to Mark
  374.     mov    si,81h            ; Command Name
  375.     xor    bx,bx            ; Set Pointer to
  376.     mov    bl,DS:[si-1]        ; Length of Name
  377.     xor    ch,ch            ; Make ASCIIZ and
  378.     mov    cl,DS:[si+bx]        ; Save Previous
  379.     mov    DS:[si+bx],ch        ; Name Command End
  380.     mov    ah,41h            ; Delete
  381.     mov    dx,82h            ; File(s)
  382.     int    21h            ; Restore
  383.     mov    DS:[si+bx],cl        ; Ending
  384.     jmp    short FileLp        ; Loop Until Done
  385.  
  386. CheckR:    cmp    flagr,0            ; If Leave 8259 as is
  387.     jnz    UnMark            ; Then Skip Procedure
  388.      call    Rst8259            ; Else Reset 8259
  389. UnMark:    mov    si,mcbend        ; Work between
  390.     sub    si,8            ; UnMark Program
  391. ;v3.2    mov    bp,MCBBUF        ; and Master
  392. ;v3.2    add    bp,8            ; Environment
  393.     mov    bp,MCBBUF+8        ; and Master Environment    v3.2
  394. Loop49:    sub    si,8            ; If Down to Master
  395.     cmp    si,bp            ; Environment
  396.     je    Result            ; Then Done Releasing
  397.  
  398.     mov    ax,[si]            ; Else If NOT
  399.     inc    ax            ; Marked for
  400.     cmp    byte ptr [si+7],0FFh    ; Release
  401.     jne    Loop49            ; Then Loop
  402.     mov    ES,ax            ; Else If
  403.     mov    ah,49h            ; Released
  404.     int    21h            ; w/o error
  405.     jnc    Loop49            ; Then Continue
  406.  
  407.     mov    byte ptr errlvl,al    ; Else Set Error
  408.     mov    ah,9            ;  and Display
  409.     mov    dx,offset releasErr    ; Error Message
  410.     int    21h
  411. Result:    cmp    byte ptr errlvl,0    ; If NO Error
  412.     jz    SetPSP            ; Then Continue
  413.      int    19h            ; Else ReBoot
  414. SetPSP:
  415. ;v3.2    push    CS            ; Restore Extra
  416. ;v3.2    pop    ES            ; Segment Register
  417.     mov    di,CS            ;restore ES            v3.2
  418.     mov    ES,di            ;v3.2
  419.     mov    di,0Ah            ; Set PSP from
  420. ;v3.2    mov    si,VECTOR        ; Vectors for
  421. ;v3.2    add    si,88h            ; Interrupts
  422.     mov    si,VECTOR+88H        ;vectors for interrupts        v3.2
  423.     mov    cx,6            ; 22h, 23h,
  424.     rep    movsw            ; and 24h
  425.     mov    si,PARENT        ; Get Parent Word
  426.     movsw                ; and Take Command
  427.     xor    di,di
  428.     mov    ES,di            ; Restore
  429.     mov    si,VECTOR        ; Interrupt
  430. ;v3.2    mov    cx,1024            ; Vectors
  431.     mov    cx,1024/2        ; vectors (as words)        v3.2
  432.     cli                ;(probably unneeded)        v3.2
  433. ;v3.2    rep    movsb
  434.     rep    movsw            ;as words            v3.2
  435.     sti
  436.     add    di,0A8h            ; Restore EGA
  437. ;v3.2    mov    cx,8            ; Information
  438. ;v3.2    rep    movsb
  439.     mov    cx,4            ;information (as words)        v3.2
  440.     rep    movsw            ;v3.2
  441.     add    di,40h            ; Restore Inter-
  442.     mov    cx,8            ; Communications
  443.     rep    movsw            ; Area Information
  444.  
  445.     cmp    word ptr stuff_buf,1C0Dh; If Nothing to Stuff
  446.     je    Exit            ; Then Exit
  447.      call    StufKey            ; Else Stuff
  448.  
  449. Exit:    mov    ax,errlvl        ; Set Error Level
  450.     int    21h            ; and Exit to DOS
  451. Main    EndP
  452.  
  453. Ploop    Proc
  454.     lodsb                ; Get a Byte
  455.     cmp    di,MKPARM        ; If Stuffing
  456.     jc    Stuff            ; Then Stuff
  457.     cmp    al,"/"            ; Else If Switch
  458.     je    Parms            ; Then Get Parameter
  459.     cmp    al,"?"            ; Else If Question
  460.     je    DoHelp            ; Then Give Help
  461.     cmp    al,13            ; Else If End Byte
  462.     je    Pexit            ; Then Exit Parsing
  463.     cmp    al,"!"            ; Else If Space or Below
  464.     jc    Ploop            ; Then Ignore Character
  465.     stosb                ; Else Store ID Name
  466.     jmp    short Ploop        ; Until [F]Mark ID ends
  467.  
  468. Parms:    lodsb                ; Get Byte After Switch
  469.     cmp    di,MKPARM        ; If NOT Stuffing
  470.     jnc    ParaQ            ; Then Ready to Check
  471.      pop    di            ; Else Even the Stack
  472. ParaQ:    cmp    al,"?"            ; If Question
  473.     je    DoHelp            ; Then Give Help
  474.  
  475.     and    al,5Fh            ; Else UP-case
  476.     cmp    al,"D"            ; If NOT "D"eBug
  477.     jne    ParaR            ; Then Check "R"eset
  478.      mov    flagd,0FFh        ; Else Set D Flag
  479. ParaR:    cmp    al,"R"            ; If NOT "R"eset 8259
  480.     jne    ParaS            ; Then Check Stuff
  481.      mov    flagr,0FFh        ; Else Set R Flag
  482. ParaS:    cmp    al,"S"            ; If NOT "S"tuff
  483.     jne    Ploop            ; Then Get Next Byte
  484.      push    di            ; Else Preserve Pointer
  485.      mov    di,offset stuff_buf    ; While Storing Stuff
  486.      mov    cx,14            ; Up to 14 bytes plus
  487.      jmp    short Ploop        ; Ending Carriage Return
  488.  
  489. Stuff:    cmp    al,"!"            ; If Space Or Less
  490.     jc    Sexit            ; Or If Another
  491.     cmp    al,"/"            ; Switch While Stuffing
  492.     je    Sexit            ; Then Exit Stuffing
  493.  
  494.     cmp    al,"a"            ; Else Insure
  495.     jc    UCexit            ; Alphabetic
  496.     cmp    al,"z"            ; Characters
  497.     ja    UCexit            ; Converted to
  498.      and    al,5Fh            ; UPPERcase
  499. UCexit:    push    cx            ; Preserve Limit and
  500.     push    di            ; Position in stuff_buf
  501.     mov    cx,NUMCHARS        ; Set Scan Count and
  502.     mov    bx,offset scanc_tbl    ; Indices to Scan Codes
  503.     mov    di,offset ascii_tbl    ; Versus ASCII Codes
  504.     sub    bx,di            ; Adjust Scan Code
  505.     repne    scasb            ; Pointer for Position in
  506.     add    bx,di            ; ASCII Character Table
  507.     mov    ah,[bx-1]        ; Get Scan Code and
  508.     pop    di            ; Restore Pointer and
  509.     pop    cx            ; Stuff Character Counter
  510.     or    ah,ah            ; If Invalid Code
  511.     jz    Sexit            ; Then Exit Stuffing
  512.      stosw                ; Else Store Code/Byte
  513.      loop    Ploop            ; Until End of Stuffing
  514.  
  515. Sexit:    pop    di            ; Even Stack and Back-Up
  516.     dec    si            ; Input In Case of Switch
  517.     cmp    al,"/"            ; If If End With Switch
  518.     je    Ploop            ; Then Resume Parsing
  519.     cmp    al,13            ; Else If End of Input
  520.     je    Pexit            ; Then Exit Normally
  521. DoHelp:    stc                ; Else Set CY for Help
  522.  
  523. Pexit:    ret
  524. Ploop    EndP
  525.  
  526. DoFlags Proc
  527.     push    si            ; Preserve
  528.     push    di            ; Pointers and
  529.     push    ES            ; Segment Register
  530.     mov    bp,di            ; Copy for Comparisons
  531.     sub    dx,di            ; If a Program
  532.     jz    ChkPgm            ; Then Check It
  533.  
  534.     xor    dx,dx            ; Else Zero Flags
  535. ChkRel:    cmp    word ptr mflaga,0    ; If NO [F]Mark Yet
  536.     jz    ExitDF            ; Then NO Release Flag
  537.      mov    dh,0FFh            ; Else Mark for Release
  538. ExitDF:    jmp    short DFexit
  539.  
  540. ChkPgm:    mov    ES,di            ; Look in
  541.     mov    di,62h            ; Program
  542.     mov    cx,7            ; for ID of
  543.     mov    si,offset markID    ; an [F]Mark
  544.     rep    cmpsb
  545.     mov    di,81h            ; If an [F]Mark
  546.     je    ChkMrk            ; Then Check Name
  547.     mov    si,offset mrkmsg+8    ; Else Check for
  548.     mov    di,108h            ; TurboPower
  549.     mov    cx,9            ; "PARAMETER"
  550.     rep    cmpsb
  551.     mov    di,81h            ; If TurboPower
  552.     je    ChkMrk            ; Then Check Name
  553.     mov    cx,11            ; Else If NOT TSR
  554.     mov    si,offset markID+4    ; WATCHER Name
  555.     rep    cmpsb            ; "TSR WATCHER"
  556.     jne    ChkRel            ; Then Check Release
  557.      mov    watchf,bp        ; Else Store Address
  558.      jmp    short ChkRel
  559.  
  560. ChkMrk:    mov    dl,0FFh            ; Flag as [F]Mark
  561.     mov    cl,ES:[di-1]        ; If NO Length
  562.     jcxz    Chk4MF            ; Then NO Protect
  563.  
  564.     push    di            ; Else Save Name
  565.     push    cx            ;  and Length
  566.     mov    al,"!"            ; Scan for
  567.     repne    scasb            ; Protected
  568.     pop    cx            ; If NOT
  569.     pop    di            ; Protected
  570.     jne    Chk4MF            ; Then Check Mark Flag
  571.      mov    pflaga,bp        ; Else Set Protected Flag
  572. Chk4MF:    cmp    word ptr mflaga,0    ; If NO Release [F]Mark
  573.     jz    DoName            ; Then Check This One
  574.      mov    dh,0FFh            ; Else Mark for Release
  575.      jmp    short DFexit
  576.  
  577. DoName:    dec    cx            ; Assume space
  578.     cmp    mrklen,cx        ; If NOT length of
  579.     mov    si,MKPARM        ; Parameter Name
  580.     jne    DFexit            ; Then Check Release
  581.  
  582. FNloop:    inc    di            ; Else Get
  583.     lodsb                ; Next Byte
  584.     cmp    pflaga,bp        ; If Protected [F]Mark
  585.     jz    FNBcmp            ; Then Compare Exact
  586.      or    al,20h            ; Else Insure lower
  587. FNBcmp:    sub    al,ES:[di]        ; If Name Bytes Match
  588.     je    loopFN            ; Then Compare Until
  589.     cmp    pflaga,bp        ; Else If Protected
  590.     jz    DFexit            ; Then MCB Flag Exit
  591.     cmp    al,20h            ; Else If Only Case
  592. loopFN:    loope    FNloop            ; Then Compare Until
  593.     jne    DFexit            ; Fail or Match
  594. Match:    mov    dh,0FFh            ; Mark [F]Mark and
  595.     mov    mflaga,bp        ; Subsequent MCBs
  596.                     ; for Release
  597. DFexit:    pop    ES            ; Restore Segment
  598.     pop    di            ; Destination and
  599.     pop    si            ; Source Pointers
  600.     mov    [si+bx+6],dx        ; Set MCB Flags
  601.     ret
  602. DoFlags EndP
  603.  
  604. DoDeBug Proc
  605.     push    dx            ; Preserve Message
  606.     mov    ah,9            ; Display
  607.     mov    cx,2            ; two sets of
  608.     mov    dx,offset header    ; DeBug Headers
  609. ShoHdr:    int    21h
  610.     loop    ShoHdr
  611.     mov    si,MCBBUF        ; Point to Array
  612. DoMCBs:    mov    cx,2            ; Two Members
  613.     mov    dx,offset crlf        ; per each
  614.     int    21h            ; New Line
  615.  
  616. ShoMCB:    push    cx            ; Preserve Set Count
  617.     mov    bl,[si+1]        ; Get MCB High Byte
  618.     call    ShowVal            ; and Display ASCII
  619.     mov    bl,[si+0]        ; Get MCB Low Byte
  620.     call    ShowVal            ; and Display ASCII
  621.     mov    dl," "            ; Add a Space
  622.     int    21h
  623.     mov    bl,[si+3]        ; Get Block High Byte
  624.     call    ShowVal            ; and Display ASCII
  625.     mov    bl,[si+2]        ; Get Block Low Byte
  626.     call    ShowVal            ; and Display ASCII
  627.     mov    dl," "            ; Add a Space
  628.     int    21h
  629.     mov    bl,[si+5]        ; Get Length High Byte
  630.     call    ShowVal            ; and Display ASCII
  631.  
  632.     mov    bl,[si+4]        ; Get Length Low Byte
  633.     call    ShowVal            ; and Display ASCII
  634.     mov    dl," "            ; Add a Space
  635.     int    21h
  636.     mov    dx,offset watchM    ; If Watch
  637.     mov    ax,watchf        ; PSP Block
  638.     dec    ax            ; minus one
  639.     cmp    ax,[si]            ; Matches MCB
  640.     je    ShoUsr            ; Then is Watch
  641.     mov    dx,offset mrkmsg    ; Else If [F]Mark
  642.     cmp    byte ptr [si+6],0FFh    ; flag is set
  643.     je    ShoUsr            ; Then [F]Mark
  644.     mov    dx,offset pgmmsg    ; Else If Block
  645.     mov    bx,[si+2]        ; is the next
  646.     dec    bx            ; paragraph
  647.     cmp    bx,[si+0]        ; after MCB
  648.     je    ShoUsr            ; Then Program
  649.     mov    dx,offset envmsg    ; Else Environ
  650.     cmp    bx,-1            ; Unless
  651.     jne    ShoUsr            ; Block is
  652.     mov    dx,offset trapmsg    ; Trapped
  653. ShoUsr:    mov    ah,9            ; Display
  654.     int    21h            ; User
  655.     mov    dx,offset trumsg    ; If Marked
  656.     cmp    byte ptr [si+7],0FFh    ; for Release
  657.     je    ShoRel            ; Then True
  658.      mov    dx,offset falmsg    ; Else False
  659. ShoRel:    int    21h            ; Message
  660.     pop    cx            ; Restore Counter
  661.     add    si,8            ; If NOT at
  662.     cmp    si,mcbend        ; End of MCBs
  663.     loopne  ShoMCB            ; Then Continue
  664.     jne    DoMCBs            ; Until All Done
  665.  
  666.     pop    DX            ; Restore Message
  667.     ret
  668. DoDeBug EndP
  669.  
  670. ;v3.2    Now doing calcs in AL (faster)
  671. ShowVal Proc
  672.     mov    cl,4            ; Set Divisor 16
  673.     mov    ah,2            ; for Show Byte
  674.     mov    al,bl            ; Copy the Byte
  675.     and    al,0F0h            ; Isolate High
  676.     shr    al,cl            ; Nibble as
  677.     add    al,30h            ; ASCII
  678.     cmp    al,3Ah            ; If Decimal
  679.     jc    SV1            ; Then Show Dec
  680.      add    al,7            ; Else Show Hex
  681. SV1:    mov    dl,al            ;v3.2
  682.     int    21h
  683.     mov    al,bl            ; Copy the Byte
  684.     and    al,0Fh            ; Isolate Low
  685.     add    al,30h            ; ASCII Nibble
  686.     cmp    al,3Ah            ; If Decimal
  687.     jc    SV2            ; Then Show Dec
  688.      add    al,7            ; Else Show Hex
  689. SV2:    mov    dl,al
  690.     int    21h
  691.     ret
  692. ShowVal EndP
  693.  
  694. StufKey Proc
  695.     mov    ah,1            ; If KeyBoard Buffer
  696.     int    16h            ; is Clear of Keys
  697.     jz    Set_SI            ; Then Ready to Stuff
  698.      xor    ah,ah            ; Else Read Scan Code
  699.      int    16h            ; Code and Character
  700.      jmp    short StufKey        ; Until Buffer Clear
  701.  
  702. Set_SI:    mov    si,offset stuff_buf    ; Point to StufString
  703.     mov    ax,40h            ; Set Segment of
  704.     mov    ES,ax            ; Buffer and its
  705.     mov    ax,ES:[80h]        ; Beginning Word
  706.     mov    di,ax            ; As Pointers to
  707.     sub    di,4            ; Head and Tail
  708.     cli                ; Hold Interrupts
  709.     stosw                ; While Initializing
  710.     mov    bp,di            ; Key Buffer Head, Tail
  711.     stosw                ; and Key Word Contents
  712. SKloop:    lodsw                ; Stuff stuff_buf Stuff
  713.     stosw                ; Into Key Buffer and
  714.     add    word ptr ES:[bp],2    ; Adjust Tail Until
  715.     cmp    ax,1C0Dh        ; Carriage
  716.     jne    SKloop            ; Return
  717.     push    DS            ; Restore Extra
  718.     pop    ES            ; Segment Register
  719.     sti                ; Allow Interrupts
  720.     ret
  721. StufKey EndP
  722.  
  723. Rst8259 Proc  ; RESET THE 8259 INTERRUPT CONTROLLER CHIP - Rick Housh
  724.     push    ES            ; Point Extra Segment to
  725.     mov    ax,-1            ; Machine ID byte at
  726.     mov    ES,ax            ; Offset 14, in ROM BIOS
  727.     mov    al,Byte Ptr ES:[0Eh]    ; Store machine ID byte
  728.     pop    ES            ; PC=0FFh, XT=0FEh, AT=0FCh
  729.     cli                ; Interrupts off
  730.     cmp    al,0FCh            ; If ID Byte = 0FCh
  731.     jz    RstAT            ; Then Reset AT
  732.     cmp    al,0FEh            ; Else If NOT PC/XT
  733.     jc    RstX            ; Then phooey on PC Jr
  734.                     ;  and NON-Compatibles
  735. RstPC:    in    al,21h            ; Else Get and Save
  736.     mov    ah,al            ; Current Interrupt
  737.     mov    al,13h            ; Mask for PC or XT
  738.     out    20h,al
  739.     jmp    short $+2        ; Delay
  740.     mov    al,8            ; Set up main vector number
  741.     out    21h,al
  742.     jmp    short $+2
  743.     mov    al,9
  744.     out    21h,al
  745.     jmp    short $+2
  746.     mov    al,ah            ; Restore mask and reset
  747.     out    21h,al            ; previous interrupt state
  748.     jmp    Short RstX        ; Interrupts back on and exit
  749.  
  750. RstAT:    xor    al,al            ; For AT, turn off any
  751.     out    0F1h,al            ; 80287 math coprocessor
  752.     jmp    short $+2        ; Delay
  753.     in    al,21h            ; Get current interrupt mask
  754.     mov    ah,al            ; and save it
  755.     mov    al,11h
  756.     out    20h,al
  757.     jmp    short $+2
  758.     mov    al,8            ; Set up main vector number
  759.     out    21h,al
  760.     jmp    short $+2
  761.     mov    al,4
  762.     out    21h,al
  763.     jmp    short $+2
  764.     mov    al,1
  765.     out    21h,al
  766.     jmp    short $+2
  767.     mov    al,ah            ; Restore mask, reset
  768.     out    21h,al            ; previous interrupt state
  769.     jmp    short $+2
  770.  
  771. RstSlv:    in    al,0A1h            ; For slave 8259,
  772.     mov    ah,al            ; Get and save current Mask
  773.     mov    al,11h
  774.     out    0A0h,al
  775.     jmp    short $+2        ; Delay
  776.     mov    al,70h
  777.     out    0A1h,al
  778.     jmp    short $+2
  779.     mov    al,2
  780.     out    0A1h,al
  781.     jmp    short $+2
  782.     mov    al,1
  783.     out    0A1h,al
  784.     jmp    short $+2
  785.     mov    al,ah            ; Restore mask, reset
  786.     out    0A1h,al            ; previous interrupt state
  787. RstX:    sti                ; Interrupts back on
  788.     Ret                ; Exit
  789. Rst8259 EndP
  790.  
  791.     align    16
  792. BUFFER  equ    $
  793.  
  794. CSEG    EndS
  795.     End    Main
  796.