home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume02 / numlock < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  7.4 KB

  1. From mipos3!intelca!oliveb!ames!husc6!necntc!ncoast!allbery Sat Jan 23 19:38:07 PST 1988
  2. Article 262 of comp.sources.misc:
  3. Path: td2cad!mipos3!intelca!oliveb!ames!husc6!necntc!ncoast!allbery
  4. From: pozar@hoptoad.UUCP (Tim Pozar)
  5. Newsgroups: comp.sources.misc
  6. Subject: v02i013: Numlock code for IBM-PCs and the like.
  7. Message-ID: <7106@ncoast.UUCP>
  8. Date: 20 Jan 88 01:14:29 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Organization: Syncstream/Widget Systems (San Francisco)
  11. Lines: 318
  12. Approved: allbery@ncoast.UUCP
  13. X-Archive: comp.sources.misc/8801/13
  14. Comp.sources.misc: Volume 2, Issue 13
  15. Submitted-By: Tim Pozar <pozar@hoptoad.UUCP>
  16. Archive-Name: numlock
  17.  
  18. Comp.sources.misc: Volume 2, Issue 13
  19. Submitted-By: Tim Pozar <pozar@hoptoad.UUCP>
  20. Archive-Name: numlock
  21.  
  22. [Stop fidgeting, folks:  assembler isn't uuencoded, even though it may look
  23. like it!  ;-)  ++bsa]
  24.  
  25.     I would hope that this is the 'catch-all' source newsgroup.
  26. I didn't see a newsgroup called comp.sources.ibm.pc.  Pardon me
  27. if there is one out there and I just didn't find it on this
  28. machine.
  29.     I have had several requests for this hack.  It's pretty
  30. simple but it does the job.  I compiled it on MASM 4.0.  The
  31. code is pretty straight forward.  I'm not doing anything really
  32. wierd.
  33. ---
  34.  
  35. page 55,132
  36. title TOGKEY -- Toggles the Insert, Caps, Num, Scroll, or Suspend (Hold) key.
  37.  
  38. ;
  39. FALSE    EQU    0
  40. TRUE    EQU    NOT FALSE
  41. vn    equ    "1"    ;version number
  42. rn    equ    "0"    ;revision number
  43. ;
  44. data    segment at 40h
  45. ;
  46. foo        db    16h dup(?)
  47. ;
  48. kb_flag        dw    ?    ;Keyboard Status 
  49. ;
  50. INS_STATE    EQU     8000H
  51. CAPS_STATE    EQU     4000H
  52. NUM_STATE    EQU     2000H
  53. SCROLL_STATE    EQU     1000H
  54. ALT_SHIFT    EQU     0800H
  55. CTL_SHIFT    EQU     0400H
  56. LEFT_SHIFT    EQU     0200H
  57. RIGHT_SHIFT    EQU     0100H
  58. ;
  59. kb_flage_1     db    ?        ;Second byte of Keyboard Status
  60. ;
  61. INS_SHIFT    EQU    80H
  62. CAPS_SHIFT    EQU    40H
  63. NUM_SHIFT    EQU    20H
  64. SCROLL_SHIFT    EQU    10H
  65. HOLD_STATE    EQU    08H
  66.     ;
  67. data ends
  68.  
  69. ;
  70. ;       MISCELLANEOUS EQUATES
  71. ;
  72. CR      EQU     0dh
  73. LF      EQU     0ah
  74. eom    equ    0    ;End of string char (did you think I was going to
  75.             ;use '$' ?!!!)
  76. DosCall EQU     21h    ;INTERUPT NUMBER FOR DOS CALL  
  77. ;
  78. prognam    segment    public
  79.     ;
  80. ;
  81.     assume    cs:prognam,ds:prognam,ss:prognam
  82.     org    80h
  83. psiz    db    ?
  84. pstng    db    ?
  85.     org     100h
  86.             ;
  87. start:    jmp    intial
  88.     db    cr,lf,"TOGKEY ver:",vn,".",rn
  89.     db    cr,lf,"Copyright 1988 by Timothy M. Pozar"
  90.     db    cr,lf,"Please don't rip me off!!",cr,lf,1ah    ;ends with a ^Z
  91.     db    57h,08h,20h,32h,20h    ;ser
  92.     ;
  93. intial:    mov    ax,cs
  94.     mov    ds,ax
  95.     mov    ss,ax
  96.     mov     sp,offset stack    
  97.     ;
  98. begin:                ;beginning of programme
  99.     mov    al,psiz        ;how many char are on the command line
  100.     mov    switch_num,al
  101.     cmp    al,0
  102.     jz    help        ;if there is none, display help msg
  103.     cmp    al,1
  104.     jnz    nohelp        ;if there is just one, display help msg
  105.                 ;else skip over and start parsing
  106. help:
  107.     mov    dx,offset signon_msg
  108.     call     pstring
  109.     jmp    done
  110. nohelp:
  111.     sub    cx,cx    
  112.     mov    cl,switch_num
  113.     mov    si,offset pstng    ;start of command string
  114.     cld
  115.     ;
  116. lp1:    
  117.     lodsb
  118.     cmp    al,switch_char1
  119.     jz    tswtch
  120.     cmp    al,switch_char2
  121.     jz    tswtch
  122.     jmp    lpend
  123. tswtch:    push    ax
  124.     mov    ax,TRUE
  125.     mov    switch_rcv,ax
  126.     pop    ax
  127.     dec    cx        ;test for what switch char is there
  128.     lodsb
  129. ;
  130. tog_ins1:
  131.     cmp    al,"i"
  132.     jz    tog_ins2
  133.     cmp    al,"I"
  134.     jnz    tog_cap1
  135. tog_ins2:            ;set insert flag to true
  136.     mov    ax,TRUE
  137.     mov    insert_flg,ax
  138.     jmp    lpend
  139. ;
  140. tog_cap1:
  141.     cmp    al,"c"        ;set caps flag to true
  142.     jz    tog_cap2
  143.     cmp    al,"C"
  144.     jnz    tog_num1
  145. tog_cap2:
  146.     mov    ax,TRUE
  147.     mov    caps_flg,ax
  148.     jmp    lpend
  149. ;
  150. tog_num1:
  151.     cmp    al,"n"        ;set numlock flag to true
  152.     jz    tog_num2
  153.     cmp    al,"N"
  154.     jnz    tog_scroll1
  155. tog_num2:
  156.     mov    ax,TRUE
  157.     mov    num_flg,ax
  158.     jmp    lpend
  159. ;
  160. tog_scroll1:
  161.     cmp    al,"s"        ;set scroll flag to true
  162.     jz    tog_scroll2
  163.     cmp    al,"S"
  164.     jnz    defalt
  165. tog_scroll2:
  166.     mov    ax,TRUE
  167.     mov    scroll_flg,ax
  168.     jmp    lpend
  169.  
  170. defalt:
  171.             ;Did not reconize this char as a valid command.
  172.     push    ax
  173.     mov    dx,offset duh_msg
  174.     call    pstring
  175.     pop    ax
  176.     call    pchar
  177.     mov     al,'.'
  178.     call    pchar
  179.     jmp    done
  180.  
  181. lpend:    loop    lp1
  182.     ;
  183. lpfin:
  184.     mov    ax,switch_rcv        ;did we get a valid switch char some
  185.     cmp    ax,TRUE            ;where in there?
  186.     jz    main
  187.     mov    dx,offset no_swtch_msg    ;if not, bomb out 
  188.     call    pstring
  189.     jmp    done
  190. ;
  191. ;       M A I N
  192. ;
  193. main:
  194.     ;
  195. flip_cap:
  196.     mov    ax,caps_flg
  197.     cmp    ax,true
  198.     jnz    flip_ins
  199.     mov    dx,offset capsmsg
  200.     call    pstring
  201.     mov    cx,CAPS_STATE
  202.     call    modkeyb
  203.     ;
  204. flip_ins:
  205.     mov    ax,insert_flg
  206.     cmp    ax,true
  207.     jnz    flip_num
  208.     mov    dx,offset insmsg
  209.     call    pstring
  210.     mov    cx,INS_STATE
  211.     call    modkeyb
  212.     ;
  213. flip_num:
  214.     mov    ax,num_flg
  215.     cmp    ax,true
  216.     jnz    flip_scroll
  217.     mov    dx,offset nummsg
  218.     call    pstring
  219.     mov    cx,NUM_STATE
  220.     call    modkeyb
  221.     ;
  222. flip_scroll:
  223.     mov    ax,scroll_flg
  224.     cmp    ax,true
  225.     jnz    done
  226.     mov    dx,offset scrollmsg
  227.     call    pstring
  228.     mov    cx,SCROLL_STATE
  229.     call    modkeyb
  230.     ;
  231.  
  232. done:
  233.     mov    dx,offset newline
  234.     call     pstring
  235.     mov    ah,4ch
  236.     int    DosCall        ; That's all Folks !
  237.     ;
  238.  
  239. modkeyb    proc    near
  240.     push    ds
  241.     mov    ax,data
  242.     mov    ds,ax
  243.     mov    bx,offset kb_flag
  244.     xor    [bx],cx
  245.     pop    ds
  246.     ret
  247. modkeyb endp
  248.  
  249. pstring    proc    near
  250.     ;SAMPLE CALL TO PSTRING
  251.     ;mov    dx,offset anounc ;point to address of message "anounc"
  252.     ;call     pstring        ;display anounc
  253.     ;
  254.     mov    bx,dx
  255. pmore:    mov    al,[bx]
  256.     cmp    al,eom
  257.     jz    pfin
  258.     call    pchar
  259.     inc    bx
  260.     jmp    pmore
  261. pfin:    ret
  262.     ;
  263. pstring    endp
  264. ;
  265. pchar    proc    near
  266.     ;sends one char to the console
  267.     mov    ah,2
  268.     mov    dl,al
  269.     int    DosCall
  270.     ret
  271.     ;
  272. pchar    endp
  273.  
  274.  
  275. ;ZEE DATA AREA --
  276. ;
  277. ;Messages
  278. ;
  279. no_swtch_msg db    cr,lf,"  Did not find the current switch character on the command"
  280.     db    cr,lf,"  line.  Please use either '/' or '-'."
  281.     db      eom
  282. duh_msg db    cr,lf,"  Did not reconize the command line switch character "
  283.     db      eom
  284. newline db    cr,lf,eom
  285. capsmsg    db    cr,lf,"  Changeing state of the CapsLock key.",eom
  286. insmsg    db    cr,lf,"  Changeing state of the Insert key.",eom
  287. nummsg    db    cr,lf,"  Changeing state of the NumLock key.",eom
  288. scrollmsg db    cr,lf,"  Changeing state of the ScrollLock key.",eom
  289.     ;
  290. signon_msg db    cr,lf,"TOGKEY ver:",vn,".",rn," 8.Jan.88"
  291.     db    cr,lf,"  Copyright (c)1988 T. M. Pozar"
  292.     db    cr,lf,"  Voice (415) 788-2022 / Data  (415) 391-2657"
  293.     db    cr,lf,"  Use limited to private (non-commercial) only.  Commercial use, by the "
  294.     db      cr,lf,"  written permission of the author only."
  295.     db    cr,lf," "
  296.     db    cr,lf,"  TOGKEY will toggle the state of a paticular key, such as the CapsLock, or"
  297.     db    cr,lf,"  Insert keys.  In order to toggle those keys the associated command line"
  298.     db      cr,lf,"  switch must be specified.  For example:"
  299.     db    cr,lf,"     A>togkey -N -C <return>"
  300.     db    cr,lf," "
  301.     db    cr,lf,"  In this example we have told the programme to toggle the state of the"
  302.     db    cr,lf,"  NumLock and CapsLock keys.  (See below for the switch settings.)  This"
  303.     db    cr,lf,"  will not change the lights on the keyboard, it will only change the state"
  304.     db    cr,lf,"  table in memory."
  305.     db    cr,lf," "
  306.     db    cr,lf,"Switch Settings...  (Should be preceded by '-' or '/')"
  307.     db    cr,lf,"  C = CapsShift (or CapsLock)"
  308.     db    cr,lf,"  I = Insert"
  309.     db    cr,lf,"  N = NumShift (or NumLock)"
  310.     db    cr,lf,"  S = ScrollShift"
  311.     db    eom
  312.     ;
  313. ;
  314. ;
  315. switch_num    db    0
  316. switch_char1    db    "-"
  317. switch_char2    db    "/"
  318. switch_rcv    dw    FALSE        ;TRUE = got a valid switch char on command line
  319. caps_flg    dw    FALSE        ;TRUE = toggle caps lock state
  320. insert_flg    dw    FALSE        ;TRUE = toggle insert state
  321. num_flg        dw    FALSE        ;TRUE = toggle num lock state
  322. scroll_flg    dw    FALSE        ;TRUE = toggle scroll lock state
  323.     ;
  324.          db    10 dup ('stack   ')    ;room for stack
  325. stack    label     byte        ;top of stack
  326. prognam    ends
  327.     end start
  328.  
  329. -- 
  330. =======================================================================
  331. | ...sun!hoptoad!\                                     Tim Pozar      |
  332. |                 >fidogate!pozar               Fido:  1:125/406      |
  333. |  ...lll-winken!/                            PaBell:  (415) 788-3904 |
  334. |         USNail:  KKSF  77 Maiden Lane  San Francisco CA 94108       |
  335. =======================================================================
  336.  
  337.  
  338.