home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Src / sources / whdload / keyboard.s < prev    next >
Text File  |  2000-08-07  |  3KB  |  144 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    keyboard.s
  3. ;  :Contents.    routine to setup an keyboard handler
  4. ;  :Version.    $Id: keyboard.s 1.6 2000/01/23 21:10:55 jah Exp $
  5. ;  :History.    30.08.97 extracted from some slave sources
  6. ;        17.11.97 _keyexit2 added
  7. ;        23.12.98 _key_help added
  8. ;        07.10.99 some cosmetic changes, documentation improved
  9. ;        24.10.99 _keycode added
  10. ;  :Requires.    _keydebug    byte variable containing rawkey code
  11. ;        _keyexit    byte variable containing rawkey code
  12. ;  :Optional.    _keyexit2    byte variable containing rawkey code
  13. ;        _key_help    function to execute on help pressed
  14. ;        _debug        function to quit with debug
  15. ;        _exit        function to quit
  16. ;        _keycode
  17. ;  :Copyright.    Public Domain
  18. ;  :Language.    68000 Assembler
  19. ;  :Translator.    Barfly 2.9
  20. ;  :To Do.
  21. ;---------------------------------------------------------------------------*
  22. ; this routine setups a keyboard handler, realizing quit and quit-with-debug
  23. ; feature by pressing the appropriate key. the following variables must be
  24. ; defined:
  25. ;    _keyexit
  26. ;    _keydebug
  27. ; the labels should refer to the Slave structure, so user definable quit- and
  28. ; debug-key will be supported
  29. ;
  30. ; the optional variable:
  31. ;    _keyexit2
  32. ; can be used to specify a second quit-key, if a quit by two different keys
  33. ; should be supported
  34. ;
  35. ; the optional function:
  36. ;    _key_help
  37. ; will be called when the 'help' key is pressed, the fuction must return via
  38. ; 'rts' and must not change any registers
  39. ;
  40. ; the optional variable:
  41. ;     _keycode
  42. ; will be filled with the last rawkeycode
  43. ;
  44. ; IN:    -
  45. ; OUT:    -
  46.  
  47. _SetupKeyboard
  48.     ;set the interrupt vector
  49.         pea    (.int,pc)
  50.         move.l    (a7)+,($68)
  51.     ;allow interrupts from the keyboard
  52.         move.b    #CIAICRF_SETCLR|CIAICRF_SP,(ciaicr+_ciaa)
  53.     ;clear all ciaa-interrupts
  54.         tst.b    (ciaicr+_ciaa)
  55.     ;set input mode
  56.         and.b    #~(CIACRAF_SPMODE),(ciacra+_ciaa)
  57.     ;clear ports interrupt
  58.         move.w    #INTF_PORTS,(intreq+_custom)
  59.     ;allow ports interrupt
  60.         move.w    #INTF_SETCLR|INTF_INTEN|INTF_PORTS,(intena+_custom)
  61.         rts
  62.  
  63. .int        movem.l    d0-d1/a1,-(a7)
  64.         lea    (_ciaa),a1
  65.     ;check if keyboard has caused interrupt
  66.         btst    #CIAICRB_SP,(ciaicr,a1)
  67.         beq    .end
  68.     ;read keycode
  69.         move.b    (ciasdr,a1),d0
  70.     ;set output to low and output mode (handshake)
  71.         clr.b    (ciasdr,a1)
  72.         or.b    #CIACRAF_SPMODE,(ciacra,a1)
  73.     ;calculate rawkeycode
  74.         not.b    d0
  75.         ror.b    #1,d0
  76.  
  77.         cmp.b    (_keydebug,pc),d0
  78.         bne    .1
  79.         movem.l    (a7)+,d0-d1/a1
  80.         move.w    (a7),(6,a7)            ;sr
  81.         move.l    (2,a7),(a7)            ;pc
  82.         clr.w    (4,a7)                ;ext.l sr
  83.     IFD _debug
  84.         bra    _debug
  85.     ELSE
  86.         bra    .debug
  87.     ENDC
  88.  
  89. .1        cmp.b    (_keyexit,pc),d0
  90.     IFD _exit
  91.         beq    _exit
  92.     ELSE
  93.         beq    .exit
  94.     ENDC
  95.  
  96.     IFD _keyexit2
  97.         cmp.b    (_keyexit2,pc),d0
  98.     IFD _exit
  99.         beq    _exit
  100.     ELSE
  101.         beq    .exit
  102.     ENDC
  103.     ENDC
  104.  
  105.     IFD _key_help
  106.         cmp.b    #$5f,d0
  107.         bne    .2
  108.         bsr    _key_help
  109. .2
  110.     ENDC
  111.  
  112.     IFD _keycode
  113.         move.l    a0,-(a7)
  114.         lea    (_keycode,pc),a0
  115.         move.b    d0,(a0)
  116.         move.l    (a7)+,a0
  117.     ENDC
  118.  
  119.     ;better would be to use the cia-timer to wait, but we arn't know if
  120.     ;they are otherwise used, so using the rasterbeam
  121.     ;required minimum waiting is 75 µs, one rasterline is 63.5 µs
  122.     ;a loop of 3 results in min=127µs max=190.5µs
  123.         moveq    #3-1,d1
  124. .wait1        move.b    (_custom+vhposr),d0
  125. .wait2        cmp.b    (_custom+vhposr),d0
  126.         beq    .wait2
  127.         dbf    d1,.wait1
  128.  
  129.     ;set input mode
  130.         and.b    #~(CIACRAF_SPMODE),(ciacra,a1)
  131. .end        move.w    #INTF_PORTS,(intreq+_custom)
  132.         movem.l    (a7)+,d0-d1/a1
  133.         rte
  134.  
  135.     IFND _exit
  136. .debug        pea    TDREASON_DEBUG.w
  137. .quit        move.l    (_resload,pc),-(a7)
  138.         addq.l    #resload_Abort,(a7)
  139.         rts
  140. .exit        pea    TDREASON_OK.w
  141.         bra    .quit
  142.     ENDC
  143.  
  144.