home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog-asm / assemtls.lzh / ASSEMTOOLS / ASOURCE / KEY.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-08-16  |  9.4 KB  |  366 lines

  1. ;
  2. ; ### Function key redefining program by JM v 1.02 ###
  3. ;
  4. ; - Created 890126 by JM -
  5. ;
  6. ;
  7. ; This program changes the default function key values set by the FKey
  8. ; program.
  9. ;
  10. ;
  11. ;
  12. ;
  13. ; Bugs: yet unknown
  14. ;
  15. ;
  16. ; Edited:
  17. ;
  18. ; - 890126 by JM -> v0.01    - uh-huh
  19. ; - 890126 by JM -> v0.02    - should work.
  20. ; - 890126 by JM -> v0.03    - well, try to learn the difference betw.
  21. ;                  a0 and d0 - that will save you from many
  22. ;                  troubles.
  23. ; - 890126 by JM -> v0.04    - ctrl key capability added.
  24. ; - 890127 by JM -> v0.10    - comments improved.
  25. ; - 890127 by JM -> v0.11    - alt and shft+alt support added (needed with
  26. ;                  some national keymaps to get a #).
  27. ; - 890127 by JM -> v0.12    - key ? can be used to list the current
  28. ;                  definitions.
  29. ; - 890127 by JM -> v1.0    - MESSAGE added.
  30. ; - 890311 by JM -> v1.01    - two branches converted to .s.
  31. ; - 890513 by JM -> v1.02    - Now makes the fkey string empty if necessary.
  32. ;
  33. ;
  34.  
  35.  
  36.  
  37.         include    "exec.xref"
  38.         include    "dos.xref"
  39.         include    "console.xref"
  40.         include    "JMPLibs.i"
  41.         include    "relative.i"
  42.         include    "com.i"
  43.         include    "string.i"
  44.         include    "numeric.i"
  45.         include    "exec/types.i"
  46.         include    "exec/nodes.i"
  47.         include    "exec/lists.i"
  48.         include    "exec/ports.i"
  49.         include    "exec/memory.i"
  50.         include    "exec/devices.i"
  51.         include    "exec/io.i"
  52.         include    "exec/tasks.i"
  53.         include    "devices/input.i"
  54.         include    "devices/inputevent.i"
  55.  
  56.  
  57. strcpy        macro    * a0,a1
  58. strcpy\@    move.b    (\1)+,(\2)+
  59.         bne.s    strcpy\@
  60.         endm
  61.  
  62.  
  63. RELATIVE    equ    1
  64.  
  65.         .var            allocates variables from stack
  66.         dl    _DosBase     using LINK a4,#-size
  67.         dl    _ConsoleDeviceBase
  68.         dl    cmdlin
  69.         dl    cderror
  70.         dl    ioreq
  71.         dl    ievent
  72.         dl    globport
  73.         dl    buffer
  74.  
  75.  
  76. start        .begin                this turns to LINK a4,#-NN
  77.         move.l    a0,cmdlin(a4)
  78.         clr.b    -1(a0,d0.w)        add NULL to the end of cmd line
  79.         moveq.l    #-1,d0
  80.         move.l    d0,cderror(a4)        set variables to known values
  81.         clr.l    _DosBase(a4)
  82.         clr.l    _ConsoleDeviceBase(a4)
  83.         lea    IORequest,a0        get addr if IORequest struct
  84.         move.l    a0,ioreq(a4)
  85.         lea    IEvent,a0        get addr of InputEvent struct
  86.         move.l    a0,ievent(a4)
  87.  
  88.         openlib    Dos,cleanup        open dos.library
  89.         bsr    getconsbase        open console.device
  90.         bcs.s    cleanup_i
  91.  
  92.         lea    portname(pc),a1        test if port already exists
  93.         lib    Exec,FindPort
  94.         move.l    d0,globport(a4)        save port address
  95.         beq.s    install_first
  96.  
  97.         move.l    cmdlin(a4),a0        check if LIST command
  98.         cmp.b    #'?',(a0)
  99.         bne.s    define
  100.  
  101.         lea    MESSAGE(pc),a0
  102.         printa    a0
  103.         bsr    listdef            list definitions
  104. cleanup_i    bra.s    cleanup
  105.  
  106. define        bsr.s    setdef            re-define a fkey
  107.         bra.s    cleanup
  108.  
  109. install_first    lea    INSTALLREQ(pc),a0    request the user to run fkey
  110.         printa    a0
  111.  
  112. cleanup        bsr    closeconsole        close console.device
  113.         closlib    Dos            close dos.library
  114.         moveq.l    #0,d0
  115.         .end                UNLK and RTS
  116.  
  117.  
  118.  
  119.  
  120.  
  121. *************************************************************************
  122. *                                    *
  123. * Set definitions                            *
  124. * Command line parsing is very simple.  The command name must be    *
  125. * followed by one space and the function key number 1...20.        *
  126. * After the number one space is needed.  The rest of the command line    *
  127. * is interpreted as the string for the function key.            *
  128. *                                    *
  129. *************************************************************************
  130.  
  131. setdef        move.l    cmdlin(a4),a0        get fkey number
  132.         numlib    get10             (gets a number in d0)
  133.         bcs.s    setdef_e1        -> illegal number
  134.         subq.l    #1,d0
  135.         blt.s    setdef_e1        check if legal number
  136.         cmp.l    #19,d0
  137.         bgt.s    setdef_e1
  138.  
  139.         move.l    globport(a4),a1        get messageport address
  140.         move.l    MP_SIZE(a1),a1        pointer to fkey strings
  141.         asl.w    #6,d0            multiply by 64
  142.         add.w    d0,a1            add index to pointer
  143.  
  144.         tst.b    (a0)            see if there is no string
  145.         beq.s    setdef_ok        -> make the fkey empty
  146.         cmpi.b    #' ',(a0)+        must be num<spc>string
  147.         bne.s    setdef_e1
  148.  
  149.         moveq.l    #31,d2            counter
  150. setloop1    move.b    (a0)+,d0        get a char to convert
  151.         beq.s    setdef_ok        null -> end of string
  152.         moveq.l    #'^',d1
  153.         cmp.b    d1,d0            if ^ -> ctrl code
  154.         bne.s    setloop2
  155.         move.b    (a0)+,d0        actual ctrl char
  156.         beq.s    setdef_ok
  157.         cmp.b    d1,d0            ^^ converted to ^
  158.         beq.s    setloop2
  159.         and.w    #31,d0            convert to ctrl code
  160. setloop2    bsr.s    give_me_raw
  161.         bcs.s    setdef_e2        -> code unknown
  162.         move.b    d0,(a1)+        set raw key code
  163.         move.b    d1,31(a1)        set qualifier
  164.         dbf    d2,setloop1
  165.         lea    STRLONG(pc),a0
  166. setdef_e    printa    a0            print error message
  167.         rts
  168. setdef_ok    move.b    #-1,(a1)        end mark
  169.         rts
  170.  
  171. setdef_e1    lea    ILLNUM(pc),a0        error messages
  172.         bra.s    setdef_e
  173. setdef_e2    lea    ILLCODE(pc),a0
  174.         bra.s    setdef_e
  175.  
  176.  
  177.  
  178.  
  179. *************************************************************************
  180. *                                    *
  181. * Vanilla-to-Rawkey conversion routine.  Doesn't handle dead keys,    *
  182. * however.                                *
  183. * The routine first sets the qualifier value to zero and tries all    *
  184. * raw key codes $0...$7f with RawKeyConvert() to find the correct    *
  185. * raw key code.  If it fails it then tries all raw key codes with    *
  186. * different qualifier combinations as specified in the qtab.        *
  187. * If it still fails an error is    returned to the caller.            *
  188. *                                    *
  189. * This routine is very slow because it may need to call RawKeyConvert()    *
  190. * thousands of times.  However, this way we don't have to include a    *
  191. * conversion table with the program code AND the program uses the    *
  192. * keymap currently selected when doing the conversions.            *
  193. *                                    *
  194. * Inputs:  d0=vanillakey                        *
  195. * Outputs: d0=rawkeycode; d1=qualifier; if (error) -> .C=1        *
  196. *                                    *
  197. *************************************************************************
  198.  
  199. give_me_raw    push    d2-d4/a0-a3/a5/a6
  200.         move.b    d0,d4            original vanilla code
  201.         move.l    ievent(a4),a3        InputEvent structure
  202.         lea    buffer(a4),a5        buffer for vanilla code
  203.         clr.l    ie_NextEvent(a3)
  204.         move.b    #IECLASS_RAWKEY,ie_Class(a3)
  205.         clr.b    ie_SubClass(a3)
  206.         clr.l    ie_EventAddress(a3)
  207.  
  208.         moveq.l    #0,d2            index to qualifier table
  209. gmrlp1        moveq.l    #0,d3            raw key code
  210. gmrlp2        move.w    d3,ie_Code(a3)
  211.         move.w    qtab(pc,d2.w),ie_Qualifier(a3)
  212.         clr.w    (a5)            clear buffer
  213.         move.l    a3,a0            InputEvent*
  214.         move.l    a5,a1            buffer*
  215.         moveq.l    #1,d1            length
  216.         sub.l    a2,a2            use default keymap
  217.         lib    ConsoleDevice,RawKeyConvert
  218.         cmp.b    (a5),d4            check if vanilla found
  219.         beq.s    give_me_raw_ok
  220.         addq.b    #1,d3
  221.         bpl.s    gmrlp2            check all raw codes
  222.         addq.w    #2,d2            try the next qualifier
  223.         move.w    qtab(pc,d2.w),d0    last one?
  224.         bpl.s    gmrlp1
  225.  
  226. give_me_raw_e    setc                flag: code unknown
  227.         pull    d2-d4/a0-a3/a5/a6
  228.         rts
  229.  
  230. *Known qualifiers:
  231. qtab        dc.w    0,1,8,16,17,-1    none,lshift,ctrl,lalt,shft+lalt,end
  232.  
  233. give_me_raw_ok    move.l    d3,d0            raw key code
  234.         move.w    qtab(pc,d2.w),d1    qualifier
  235.         pull    d2-d4/a0-a3/a5/a6
  236.         clrc                flag: code found
  237.         rts
  238.  
  239.  
  240.  
  241. *************************************************************************
  242. *                                    *
  243. * Routine to list the current function key definitions.            *
  244. *                                    *
  245. *************************************************************************
  246.  
  247. listdef        move.l    globport(a4),a5        get messageport address
  248.         move.l    MP_SIZE(a5),a5        pointer to fkey strings
  249.         move.l    ievent(a4),a3        InputEvent structure
  250.  
  251.         clr.l    ie_NextEvent(a3)
  252.         move.b    #IECLASS_RAWKEY,ie_Class(a3)
  253.         clr.b    ie_SubClass(a3)
  254.         clr.l    ie_EventAddress(a3)
  255.  
  256.         moveq.l    #0,d2            index to qualifier table
  257.         move.l    #outbuffer,d5        output buffer
  258. listlp1        move.l    d5,a0
  259.         lea    64(a5),a1        addr of next fkey string
  260.         move.l    a1,d4
  261.         move.l    d2,d0
  262.         addq.l    #1,d0
  263.         numlib    sput10
  264.         move.l    a0,a2
  265.         move.b    #' ',(a2)+
  266. listlp2        moveq.l    #0,d0
  267.         move.b    (a5)+,d0
  268.         bmi.s    list_k_ok        -> end of string
  269.         move.w    d0,ie_Code(a3)
  270.         move.b    31(a5),d0
  271.         move.w    d0,ie_Qualifier(a3)
  272.         move.l    a3,a0            InputEvent*
  273.         move.l    a2,a1            buffer*
  274.         moveq.l    #1,d1            length
  275.         move.l    a2,d3
  276.         sub.l    a2,a2            use default keymap
  277.         lib    ConsoleDevice,RawKeyConvert
  278.         move.l    d3,a2
  279.         addq.l    #1,a2
  280.         bra.s    listlp2
  281. list_k_ok    move.b    #10,(a2)+        add LF
  282.         clr.b    (a2)            add NULL
  283.         printa    d5
  284.         move.l    d4,a5
  285.         addq.l    #1,d2
  286.         cmp.w    #20,d2
  287.         blo.s    listlp1
  288.         rts
  289.  
  290.  
  291. *************************************************************************
  292. *                                    *
  293. * Routines to open and close console.device.                *
  294. * getconsbase also sets the console.library pointer.            *
  295. *                                    *
  296. *************************************************************************
  297.  
  298. getconsbase    lea    consname(pc),a0        open console and get lib.base
  299.         moveq    #-1,d0            unit
  300.         move.l    ioreq(a4),a1        iorequest
  301.         moveq    #0,d1            flags
  302.         lib    Exec,OpenDevice
  303.         move.l    d0,cderror(a4)
  304.         bne.s    getcons_e
  305.         move.l    ioreq(a4),a0        ioreq
  306.         move.l    IO_DEVICE(a0),_ConsoleDeviceBase(a4)
  307.         beq.s    getcons_e
  308.         clrc
  309.         rts
  310. getcons_e    setc
  311.         rts
  312.  
  313.  
  314. closeconsole    move.l    cderror(a4),d0        close console.device
  315.         bne.s    closecons_ok
  316.         move.l    ioreq(a4),a1
  317.         lib    Exec,CloseDevice
  318. closecons_ok    rts
  319.  
  320.  
  321.         numlib                ;contains get10 subroutine
  322.                         ;(gets a base-10 number into
  323.                         ; d0 from (a0))
  324.  
  325.  
  326. *************************************************************************
  327. *                                    *
  328. * ASCII strings                                *
  329. *                                    *
  330. *************************************************************************
  331.  
  332. consname    dc.b    'console.device',0
  333. portname    dc.b    'FKeyPort',0
  334. INSTALLREQ    dc.b    'Install FKeys first',10,0
  335. ILLNUM        dc.b    'Illegal function key number',10,0
  336. ILLCODE        dc.b    'Illegal character',10,0
  337. STRLONG        dc.b    'String too long',10,0
  338. MESSAGE        dc.b    'KEY 1.02 by Supervisor Software 1989',10,0
  339.  
  340.  
  341.  
  342. *************************************************************************
  343. *                                    *
  344. * Library names (only dos.library used in this program).        *
  345. *                                    *
  346. *************************************************************************
  347.  
  348.         libnames
  349.  
  350.  
  351.  
  352. *************************************************************************
  353. *                                    *
  354. * Structures defined in bss chunk to make the program file smaller.    *
  355. *                                    *
  356. *************************************************************************
  357.  
  358.         section    struct,bss
  359.  
  360. IORequest    ds.b    IO_SIZE            struct IOStdReq
  361. IEvent        ds.b    ie_SIZEOF        struct InputEvent
  362. outbuffer    ds.b    64            buffer for LIST command
  363.  
  364.         end
  365.  
  366.