home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / DOS / UTILITY / DIVERSEN / KWIKHELP / KWIKGRAB.A86 < prev    next >
Text File  |  1994-12-01  |  13KB  |  589 lines

  1. ;----------------------------------------------------------------
  2. ; KWIKGRAB 4 September 1994
  3. ; jtucker@adam.com.au
  4. ; JIM TUCKER 3:800/805
  5.  
  6. ; This saves a screen to a disk file. This code is is for Eric
  7. ; Isaacson's A86V371 assembler released April 1994.
  8. ;----------------------------------------------------------------
  9.  
  10. INCLUDE \ALIB\MACROS.INC
  11.  
  12.         jmp    install
  13. KEY_SCAN    db    34            ;Default hotkey 'G'
  14. KEY_SHIFT    db    12            ;CTRL-ALT
  15. REQUEST        db    0            ;Set by ESC    
  16. BUSY        db    0            ;Set by disk write and video
  17. SWITCH        db    0            ;Tried to unload
  18. HOT_KEY2    db    "G"            ;Here for second load
  19.  
  20. FILENAME    db    'SCREEN00.BIN',0    ;starting name
  21. TRUENAME    db    80 dup 0        ;filled by function 60h
  22. NAME_POS    dw    ?            ;points to last digit of
  23.  
  24. VIDEO_SEG    dw    ?            ;set each time
  25. OLD_INT10    dd    ?            ;trapped but not used
  26. CRITICAL_ERROR    db    0            ;set if we found one
  27. INDOS_FLAG    dd    ?            ;not safe to interrupt
  28. ACTIVE        db    0            ;don't use hotkey
  29. HANDLE        dw    0            ;used by file write
  30.  
  31. ;----------------------------------------------------------------
  32. ; BIOS DISK - This simply sets BUSY while doing disk stuff
  33. ;----------------------------------------------------------------
  34.  
  35. NEW_INT13:    cli                ;just set busy
  36.         inc    cs:busy
  37.         pushf                ;needed for call
  38.         db    09Ah            ;far call opcode
  39. OLD_INT13    dd    ?            ;filled by install
  40.         pushf                ;must preserve CF
  41.         dec    cs:busy            ;done, not busy
  42.         popf
  43.         retf    2            ;keep flags
  44.  
  45. ;----------------------------------------------------------------
  46. ; BIOS VIDEO - Returns CS if called by us else sets BUSY flag
  47. ;----------------------------------------------------------------
  48.  
  49. NEW_INT10:    cli
  50.         inc    cs:busy            ;set doin' sumthin' flag
  51.         cmp    ax,0E07h        ;beeping?
  52.         jne    >l1            ;no
  53.         cmp    bx,'BI'            ;is it us?
  54.         jne    >l1            ;no
  55.         cmp    cx,'NS'            ;doubly sure
  56.         jne    >l1            ;not us
  57.         push    cs            ;yep, really really sure
  58.         pop    bx            ;return segment in BX
  59.         dec    cs:busy            ;not busy
  60.         iret                ;just return to us
  61.  
  62. L1:        pushf                ;call while busy
  63.         call    cs:old_int10
  64.         dec    cs:busy            ;no longer busy
  65.         iret                ;done
  66.  
  67. ;----------------------------------------------------------------
  68. ; BIOS KEYBOARD - Sets a flag if we want to save a screen
  69. ;----------------------------------------------------------------
  70.  
  71. L0:        jmp    exit_09
  72. NEW_INT09:    push    ax,ds
  73.         mov    ds,cs
  74.         cmp    critical_error,0    ;did we have an error
  75.         jne    l0            ;yes, forget it
  76.         cmp    request,1        ;do we have one?
  77.         je    l0            ;yes, doing it
  78.         cmp    busy,0            ;is somebody busy?
  79.         jne    l0            ;yes, forget it
  80.  
  81.         in    al,60h            ;get key code
  82.         cmp    al,key_scan        ;our key?
  83.         jne    l0            ;no, restore flags and exit
  84.         mov    ah,2            ;get shift status
  85.         int    16h
  86.         and    al,key_shift
  87.         cmp    al,key_shift        ;shift down?
  88.         jne    l0            ;no, restore flags and exit
  89.  
  90.         pop    ds,ax            ;as we were
  91.         PUSHALL                ;save everything
  92.         mov    ds,cs
  93.         mov    video_seg,0B800h    ;guess
  94.         mov    ah,0Fh            ;get mode
  95.         int    10h
  96.         cmp    al,7            ;mono?
  97.         jne    >l1            ;no
  98.         mov    video_seg,0B000h    ;bad guess
  99.  
  100. L1:        mov    ax,0002h        ;hide mouse cursor
  101.         int    33h
  102.  
  103.         xor    si,si            ;save screen
  104.         mov    ds,cs:video_seg
  105.         mov    es,cs
  106.         mov    di,OFFSET video_buffer
  107.         mov    cx,2000
  108.         rep    movsw
  109.  
  110.         mov    es,cs:video_seg        ;display squares
  111.         xor    di,di
  112.         mov    ax,07h by 254
  113.         mov    cx,2000
  114.         rep    stosw
  115.  
  116.         mov    ah,0            ;wait a bit
  117.         int    1Ah
  118.         add    dx,9
  119.         mov    bx,dx
  120. L0:        int    1Ah
  121.         cmp    dx,bx
  122.         jne    l0
  123.         mov    ds,cs
  124.         mov    si,OFFSET video_buffer
  125.         mov    es,cs:video_seg
  126.         xor    di,di
  127.         mov    cx,2000
  128.         rep    movsw
  129.  
  130.         xor    si,si            ;restore screen
  131.         mov    ds,cs:video_seg
  132.         mov    es,cs
  133.         mov    di,OFFSET video_buffer
  134.         mov    cx,2000
  135.         rep    movsw
  136.  
  137.         mov    ax,0001h        ;restore moose
  138.         int    33h
  139.  
  140.         mov    cs:request,1        ;set flag for timer
  141.         in    al,61h            ;restore kb
  142.         mov    ah,al
  143.         or    al,80h
  144.         out    61h,al
  145.         mov    al,ah
  146.         out    61h,al
  147.         cli
  148.         mov    al,20h
  149.         out    20h,al
  150.         sti
  151.  
  152.         xor    ax,ax            ;empty buffer
  153.         mov    es,ax
  154.         mov    ax,es:[041Ch]
  155.         mov    es:[041Ah],ax
  156.         POPALL
  157.         iret
  158.  
  159. EXIT_09:    pop    ds,ax
  160.         db    0EAh            ;JMP IMM16
  161. OLD_INT09    dd    ?
  162.  
  163. ;----------------------------------------------------------------
  164. ; BIOS TIMER - Save to disk if request set
  165. ;----------------------------------------------------------------
  166.  
  167. NEW_INT08:    pushf
  168.         db    09Ah            ;call imm16
  169. OLD_INT08    dd    ?
  170.  
  171.         sti
  172.         test    cs:busy            ;can we do it?    
  173.         if nz    jmp exit_08        ;no
  174.         test    cs:request        ;do we want to do it?
  175.         if z    jmp exit_08        ;no
  176.  
  177.         push    bx,ds            ;save these for dx,es
  178.         lds    bx,cs:indos_flag    ;test dos idle    
  179.         cmp    B[bx],0            ;get byte
  180.         pop    ds,bx            ;restore
  181.         if nz    jmp exit_08        ;dos is busy
  182.  
  183.         PUSHF
  184.         PUSHALL
  185. L1:        mov    ds,cs            ;use current segment
  186.         inc    busy            ;so we dont re-enter
  187.         inc    active
  188.         mov    request,0        ;clear the request
  189.  
  190. ; Temporarily trap critical error
  191.  
  192.         mov    ax,3524h        ;set it to ignore
  193.         CALL    NEWDOS
  194.         push    bx,es            ;save old vector
  195.         mov    dx,OFFSET new_int24    ;set our vector
  196.         mov    ax,2524h        ;which does nothing
  197.         CALL    NEWDOS
  198.  
  199. ; Open a file and write the video seg to the disk
  200.  
  201. L10:        mov    ds,cs
  202.         mov    si,name_pos        ;get this ready
  203. L1:        mov    ax,3D00h        ;try to open it
  204.         mov    dx,OFFSET truename    ;includes directory
  205.         CALL    NEWDOS            ;can we open it?
  206.         jc    >l3            ;no, so doesn't exist
  207.  
  208.         mov    bx,ax            ;it exist, close it
  209.         mov    ah,3Eh
  210.         CALL    NEWDOS
  211.  
  212.         inc    B[si]            ;bump the filename number
  213.         cmp    B[si],'9'        ;too big?
  214.         jbe    l1            ;no
  215.         mov    B[si],'0'        ;yes, make it zero
  216.         inc    B[si-1]            ;bump previous digit
  217.         cmp    B[si-1],'9'+1        ;busted 99?
  218.         jne    l1            ;no
  219.         mov    B[si-1],'A'        ;yes make it A
  220.         jmp    l1
  221.  
  222. L3:        mov    ax,3C00h        ;create it
  223.         mov    dx,OFFSET truename
  224.         mov    cx,0
  225.         CALL    NEWDOS
  226.         jc    >l4
  227.  
  228.         mov    bx,ax            ;write the video to it
  229.         mov    ds,cs
  230.         mov    dx,OFFSET video_buffer
  231.         mov    cx,4000
  232.         mov    ah,40h
  233.         CALL    NEWDOS
  234.  
  235.         mov    ah,3Eh            ;close file
  236.         CALL    NEWDOS
  237.  
  238.         mov    ax,0E07h        ;go beep
  239.         int    10h
  240.  
  241.         mov    ds,cs:video_seg
  242.         mov    si,1670            ;save screen bytes
  243.         mov    es,cs
  244.         mov    di,OFFSET store
  245.         mov    cx,8
  246.         rep    movsw
  247.  
  248.         mov    ds,cs            ;write message
  249.         mov    si,OFFSET grab_msg             
  250.         mov    es,cs:video_seg
  251.         mov    di,1670
  252.         mov    cx,8
  253.         rep    movsw
  254.  
  255.         mov    ah,0            ;wait a sec
  256.         int    1Ah
  257.         add    dx,18
  258.         mov    bx,dx
  259. L0:        int    1Ah
  260.         cmp    dx,bx
  261.         jne    l0
  262.  
  263.         mov    ds,cs            ;restore screen
  264.         mov    si,OFFSET store
  265.         mov    es,cs:video_seg
  266.         mov    di,1670
  267.         mov    cx,8
  268.         rep    movsw
  269.  
  270. L4:        dec    busy
  271.         dec    active
  272.  
  273.         pop    ds,dx            ;get back es,bx
  274.         mov    ax,2524h        ;restore critical error
  275.         dosf
  276.  
  277. QUIT_08:    POPALL
  278.         POPF
  279. EXIT_08:    iret
  280.  
  281. NEWDOS:        cli
  282.         int    21h
  283.         sti    
  284.         ret
  285.  
  286. ;----------------------------------------------------------------
  287. ; CRITICAL ERROR - Used while writing
  288. ; This prevents "Abort, Retry Fail..."
  289. ;----------------------------------------------------------------
  290.  
  291. NEW_INT24:    sti                ;interrupts on
  292.         mov    cs:critical_error,1    ;say no more
  293.         iret                ;just return
  294.  
  295. STORE        dw    8 DUP 0
  296. GRAB_MSG    dw    0FFh by ' '
  297.         dw    0FFh by '*'
  298.         dw    0FFh by ' '
  299.         dw    0FFh by 'O'
  300.         dw    0FFh by 'K'
  301.         dw    0FFh by ' '
  302.         dw    0FFh by '*'
  303.         dw    0FFh by ' '
  304.  
  305. EVEN 16
  306. VIDEO_BUFFER    db
  307.  
  308. ;----------------------------------------------------------------
  309. ; This is the start of installation code
  310. ;----------------------------------------------------------------
  311.  
  312. INSTALLED_SEG    dw    0
  313. INSTALL:    mov    dx,sp
  314.         mov    ax,OFFSET video_buffer
  315.         add    ax,100h
  316.         add    ax,4000
  317.         cmp    ax,dx
  318.         jb    >l1
  319.  
  320. L1:        mov    ax,0E07h
  321.         mov    bx,'BI'
  322.         mov    cx,'NS'
  323.         int    10h
  324.         cmp    bx,'BI'
  325.         je    >l1
  326.         mov    installed_seg,bx
  327.         jmp    unload
  328.  
  329. L1:        call    getscan                ;hotkey option
  330.         mov    si,OFFSET filename        ;get truename
  331.         mov    di,OFFSET truename
  332.         mov    ah,60h
  333.         dosf
  334.  
  335.         mov    si,OFFSET truename
  336. L2:        lodsb
  337.         cmp    al,0
  338.         jne    l2
  339.         sub    si,6                ;00 in truename
  340.         mov    name_pos,si            ;save position
  341.  
  342.         mov    si,name_pos        ;get this ready
  343. L1:        mov    ax,3D00h        ;try to open it
  344.         mov    dx,OFFSET truename    ;includes directory
  345.         int    21h
  346.         jc    >l2            ;no, so doesn't exist
  347.  
  348.         mov    bx,ax            ;it exist, close it
  349.         mov    ah,3Eh
  350.         int    21h
  351.  
  352.         inc    B [si]            ;bump the filename number
  353.         cmp    B [si],'9'        ;too big?
  354.         jbe    l1            ;no
  355.         mov    B [si],'0'        ;yes, make it zero
  356.         inc    B [si-1]        ;bump previous digit
  357.         cmp    B [si-1],'9'+1        ;busted 99?
  358.         jne    l1            ;no
  359.         mov    B [si-1],'A'        ;yes make it A
  360.         jmp    l1
  361.  
  362. L2:        mov    ax,3400h            ;get indos location
  363.         dosf
  364.         mov    word ptr indos_flag,  bx
  365.         mov    word ptr indos_flag+2,es
  366.  
  367.         mov    ax,3508h            ;trap INT 8
  368.         dosf
  369.         mov    word ptr old_int08,  bx
  370.          mov    word ptr old_int08+2,es
  371.         mov    ax,2508h
  372.         mov    dx, OFFSET new_int08
  373.         dosf
  374.  
  375.         mov    ax,3509h            ;trap INT 9
  376.         dosf
  377.         mov    word ptr old_int09,  bx
  378.          mov    word ptr old_int09+2,es
  379.         mov    ax,2509h
  380.         mov    dx, OFFSET new_int09
  381.         dosf
  382.  
  383.         mov    ax,3510h            ;trap INT 10
  384.         dosf
  385.         mov    word ptr old_int10,  bx
  386.          mov    word ptr old_int10+2,es
  387.         mov    ax,2510h
  388.         mov    dx, OFFSET new_int10
  389.         dosf
  390.  
  391.         mov    ax,3513h            ;trap INT 13
  392.         dosf
  393.         mov    word ptr old_int13,  bx
  394.          mov    word ptr old_int13+2,es
  395.         mov    ax,2513h
  396.         mov    dx, OFFSET new_int13
  397.         dosf
  398.  
  399.         mov    es,[2Ch]
  400.         mov    ah,49h
  401.         dosf
  402.  
  403.         write    installed
  404.         write    file_mesg
  405.         write    truename
  406.         call    crlf
  407.  
  408.         mov    dx,OFFSET install
  409.         add    dx,4000
  410.         add    dx,15
  411.         shr    dx,4
  412.         mov    ax,3100h
  413.         dosf
  414.  
  415. ALREADY:    mov    dx,OFFSET already_mesg
  416.         mov    ah,9
  417.         dosf
  418.         mov    es,bx
  419.         mov    al,es:hot_key2
  420.         mov    cs:hot_key,al
  421.         write    use_mesg
  422.         badexit
  423.  
  424. MESSAGE:    mov    ah,9
  425.         dosf
  426.         mov    ax,4CFFh
  427.         dosf
  428. @CRLF
  429.  
  430. ALREADY_MESG    db cr,lf,'KWIKGRAB already installed. Use /U to unload'
  431.         db bell,cr,lf,eom
  432.  
  433. INSTALLED    db cr,lf,'KWIKGRAB ■ Release 1994 JIM TUCKER',cr,lf
  434.         db 'Copyright (c) 1994 JIM TUCKER. All rights reserved',cr,lf
  435. USE_MESG    db 'Use <CTRL-ALT-'
  436. HOT_KEY        db 'G'
  437.         db '> to GRAB SCREEN as a binary file',cr,lf,0
  438.  
  439. FILE_MESG    db 'First screen save file is: ',0
  440. MEMORY_MESG    db cr,lf,'Not enough memory here',bell,cr,lf,eom    
  441.  
  442. HELP_MESG    db cr,lf,'KWIKGRAB ■ Release 1994 JIM TUCKER',cr,lf
  443.         db 'Copyright (c) 1994 JIM TUCKER. All rights reserved',cr,lf
  444.         db 'Saves ASCII screen to binary ".BIN" file',cr,lf
  445.         db 'USAGE: KWIKGRAB [/K=Hotkey] | [/Unload]',cr,lf,eom
  446.  
  447. ;----------------------------------------------------------------
  448. ; GETSCAN This gets scan code from the command line
  449. ;----------------------------------------------------------------
  450.  
  451. GETSCAN:    mov    dx,OFFSET help_mesg
  452.         mov    si,81h
  453. L1:        lodsb
  454.         cmp    al,' '
  455.         je    l1
  456.         cmp    al,cr
  457.         je    ret
  458.         cmp    al,'/'
  459.         if ne    jmp message
  460.         lodsb
  461.         call    caps
  462.         cmp    al,'K'
  463.         if ne    jmp message
  464.         lodsb
  465.         cmp    al,'='
  466.         je    >l2
  467.         cmp    al,':'
  468.         if ne    jmp message
  469.  
  470. L2:        lodsb
  471.         call    caps
  472.         cmp    al,' '
  473.         if be    jmp message
  474.  
  475.         mov    di,OFFSET char_string
  476.         mov    cx,string_length
  477.         repne    scasb
  478.         jne    >l3
  479.         add    key_shift,2
  480.  
  481. L3:        mov    hot_key,al
  482.         mov    hot_key2,al
  483.         mov    si,OFFSET scan
  484.         mov    ah,0
  485.         add    si,ax
  486.         lodsb
  487.         mov    key_scan,al
  488.         ret                        
  489. @CAPS        
  490.  
  491. ; Translation table:  ASCII codes into keyboard scan codes
  492.  
  493. SCAN    db    03, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24
  494.     db    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 01, 26, 53, 27, 12
  495.     db    57, 02, 40, 04, 05, 06, 08, 40, 10, 11, 09, 13, 51, 12, 52, 53
  496.     db    11, 02, 03, 04, 05, 06, 07, 08, 09, 10, 39, 39, 51, 13, 52, 53
  497.     db    03, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24
  498.     db    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 26, 43, 27, 07, 12
  499.     db    41, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24
  500.     db    25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 26, 43, 27, 41, 14
  501.  
  502. CHAR_STRING    db '~!@#$%^&*()_+|{}:"<>?'
  503. STRING_LENGTH    EQU $-OFFSET CHAR_STRING    
  504.  
  505. ;----------------------------------------------------------------------
  506. ; UNLOAD
  507. ; This procedure removes KWIKGRAB from memory by replacing the vectors
  508. ; and releasing the memory used for the code and buffer.
  509. ;----------------------------------------------------------------------
  510.  
  511. UNLOAD:        mov    si,81h
  512. L1:        lodsb
  513.         cmp    al,cr
  514.         if e    jmp already
  515.         cmp    al,'/'
  516.         jne    l1
  517.         lodsb
  518.         call    caps
  519.         cmp    al,'U'
  520.         if ne    jmp already
  521.  
  522.         mov    al,08h        ;Check the timer interrupt
  523.         call    check_seg
  524.         mov    al,09h        ;Check keyboard interrupt
  525.         call    check_seg
  526.         mov    al,10h        ;Check the printer interrupt
  527.         call    check_seg
  528.         mov    al,13h        ;Check dos idle interrupt
  529.         call    check_seg
  530.     
  531. ; Here if no interrupts have changed
  532.  
  533. L1:        mov    es,installed_seg
  534.         lds    dx,es:old_int08
  535.         mov    ax,2508h
  536.         dosf
  537.  
  538.         lds    dx,es:old_int09
  539.         mov    ax,2509h
  540.         dosf
  541.  
  542.         lds    dx,es:old_int10
  543.         mov    ax,2510h
  544.         dosf
  545.  
  546.         lds    dx,es:old_int13
  547.         mov    ax,2513h
  548.         dosf
  549.  
  550. L1:        mov    bx,cs
  551.         mov    [es:16h],bx
  552.         mov    [es:0Ch],bx
  553.         mov    W [es:0Ah],OFFSET quit
  554.         mov    ah,50h
  555.         mov    bx,es
  556.         int    21h
  557.         mov    ax,4C00h
  558.         int    21h
  559.  
  560. QUIT:        mov    ds,cs
  561.         mov    dx,OFFSET unload_mesg
  562. QUIT2:        mov    ah,9
  563.         int    21h
  564.         mov    ax,4C00h
  565.         int    21h        ;Exit to dos
  566.  
  567. ; This subroutine checks to see if an interrupt vector points to the
  568.  
  569. CHECK_SEG:    mov    ah,35h        ;Get the vector
  570.         dosf
  571.         mov    ax,es
  572.         cmp    ax,installed_seg
  573.         jne    >l1
  574.         ret
  575.  
  576. L1:        mov    dx,OFFSET cant_unload
  577.         jmp    quit2
  578.  
  579. UNLOAD_MESG    db    cr,lf,'KWIKGRAB unloaded OK',cr,lf,eom    
  580. CANT_UNLOAD    db    cr,lf,'Sorry, cannot unload KWIKGRAB',7,cr,lf,eom
  581.  
  582. ; This makes this file the same size as the installation so it can load high
  583. ; without having to expand
  584.  
  585. PADDING EQU OFFSET INSTALL+4000-$+100H
  586.     DB    PADDING DUP 0
  587. EVEN 16
  588. END
  589.