home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / keyboard / keyutils.arc / SETKEY.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-09-05  |  4.5 KB  |  102 lines

  1. comment |
  2.  
  3.        Program name:  Setkey.asm
  4.  
  5.        Author:  Terry N. Bezue
  6.  
  7.        Date:  10/17/87
  8.  
  9.        Language:  Microsoft Macro Assembler 4.0
  10.  
  11.        Purpose:  Define function keys 1-40 by user input
  12.  
  13.        Requirements:  ANSI.SYS must be installed to work correctly
  14.  
  15.        Recompile insturctions:
  16.                masm setkey;
  17.                link setkey;
  18.                exe2bin setkey setkey.com
  19.                del setkey.exe
  20.  
  21.        |
  22. ;      Macro to print data at address
  23. print  macro   address
  24.        lea     dx,address
  25.        mov     ah,9
  26.        int     21h
  27.        endm
  28. code           segment byte
  29.                assume  cs:code,ds:code,ss:code,es:code
  30.                org     80h
  31. nbytes         label   byte
  32.                org     82h
  33. input          label   byte
  34.                org     100h            ; COM format
  35. setkey:        jmp     short start
  36. first          db      27,'[0;$'
  37. key            db      0,0,0,';"$'
  38. last           db      '";13p$'
  39. errmsg         db      7,'Invalid parameters in input$'
  40.  
  41. start:         xor     dh,dh           ; zero dh
  42.                mov     bx,10           ; convert to key code
  43.                mov     cl,nbytes       ; Get # of bytes entered
  44.                xor     ch,ch           ; zero ch
  45.                dec     cx              ; skip first blank char
  46.                cmp     cl,0            ; more chars entered
  47.                jg      parse           ; yes, process line
  48.                jmp     error           ; no, error
  49. parse:         lea     di,input        ; get address of input
  50.                mov     al,' '          ; find first
  51.                repe    scasb           ;   non blank char
  52.                jz      error           ; if all blank, error
  53.                dec     di              ; adjust di
  54.                inc     cx              ;  ... and cx
  55.                xor     ax,ax           ; zero ax
  56. get_key:       mov     dl,[di]         ; get char
  57.                cmp     dl,' '          ; is it a blank
  58.                jz      ck_key          ; if so, check for vadility
  59.                cmp     dl,'0'          ; is it zero
  60.                jb      error           ; if less, error
  61.                cmp     dl,'9'          ; is it a nine
  62.                ja      error           ; if greater,error
  63.                sub     dl,'0'          ; make hex
  64.                mul     bl              ; mul old number by 10
  65.                add     ax,dx           ; add next digit
  66.                inc     di              ; point to next char
  67.                loop    get_key         ; do next digit
  68. ck_key:        cmp     ax,0            ; key must be between 1 and 40
  69.                jle     error           ; if less than 1, error
  70.                cmp     ax,10           ; was it a 10
  71.                jle     adj_main        ; if so, adjust for main fkeys
  72.                cmp     ax,40           ; greater than 40
  73.                jg      error           ; if so, error
  74.                add     ax,15           ;   adjust for extended keys
  75. adj_main:      add     ax,58           ; adjust fo main fkeys
  76.                lea     si,key+2        ; get key address
  77.                push    cx              ; save remaining byte count
  78.                mov     cx,3            ; will be at 3 digits in key
  79. put_digit:     xor     dx,dx           ; zero in dx
  80.                div     bx              ; divide by ten
  81.                add     dl,'0'          ; convert to ascii
  82.                mov     [si],dl         ; store it
  83.                dec     si              ; next digit
  84.                loop    put_digit       ; do next digit
  85.                pop     cx              ; get remaining byte count back
  86.                dec     cx              ; skip blank char
  87.                cmp     cx,0            ; error if no more
  88.                jle     error
  89.                inc     di              ; adjust di
  90.                print   first           ; print setup part
  91.                print   key             ; print converted key number
  92.                mov     si,di           ; address of string in si
  93.                add     si,cx           ; point to end of string
  94.                mov     byte ptr [si],'$' ; put end of string char
  95.                print   [di]            ; print string starting at di
  96.                print   last            ; print last part
  97.                jmp     short done      ; we're done
  98. error:         print   errmsg           ; print error message
  99. done:          int     20h             ; terminate
  100. code           ends
  101.                end     setkey
  102.