home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / nieuûytki / pckeybhack / onlyat.asm < prev    next >
Assembly Source File  |  1996-06-16  |  33KB  |  1,079 lines

  1. ;* these port equates are explained below. Relocate them to any of
  2. ;* Port1, pins 0-7 or Port3, pins 0-7, except Port3, pins2 and 3
  3. ;* because these are the external interrupts.
  4. ;* it doesn't matter as long as you equate the right pin to the right
  5. ;* signal.
  6.  
  7.         .equ    Kclk,p1.0
  8.         .equ    Kdat,p1.1
  9.         .equ    Aclk,p1.3
  10.         .equ    Adat,p1.4
  11.         .equ    Areset,p1.5
  12.         .equ    switch95,p1.6
  13.         .equ    switchMap,p1.7
  14.         .equ    usFlag,p1.2
  15.  
  16.         .org    0000h
  17.  
  18. init:   setb    ColdBoot
  19.         ljmp    start
  20.         .org    001bh
  21.         ljmp    timer1int
  22.  
  23. ;**************************************************
  24. ;*
  25. ;*
  26. ;* Equates Descriptions:
  27. ;*
  28. ;*      Aclk is the line to the Amiga keyboard clock in. (P1.3)
  29. ;*      Adat is the line to the Amiga keyboard data in. (P1.4)
  30. ;*      Areset is the Amiga Reset line (P1.5)
  31. ;*      Kclk is the line to the Keyboard clock out (P1.0)
  32. ;*      Kdat is the line to the Keyboard data out (P1.1)
  33. ;*        switch95 is the input signal to toggle between 102 and
  34. ;*                the 105 AT mapping.
  35. ;*        switchMap is the input signal to toggle between mapping
  36. ;*                the xtra keys and  sending rawkey codes
  37. ;*
  38. ;*      Oldchar is the last character typed to go to the Amiga.
  39. ;* This is used to tell if the Capslock was Pressed and 
  40. ;* Released without pressing any other keys. If this was done, 
  41. ;* then it is a "Caps Lock" otherwise, the Caps key functions
  42. ;* as the Control Key because of the keyboard remapping.
  43. ;*
  44. ;*      Capbit is the flag which tells whether the Caps Lock
  45. ;* should be down or up.
  46. ;*      Capdown is the flag which tells whether the Caps Lock 
  47. ;* KEY is presently down or up. The difference between Capdown 
  48. ;* and Capbit is that Capdown relates to the KEY. Capbit toggles 
  49. ;* once for every "press and release" of the Cap Lock Key. 
  50. ;* Press and release Cap Lock Key, and Capbit goes low.....
  51. ;* Press and release it again, and Capbit goes high....
  52. ;*      Cntldown is the flag which is set and reset when you 
  53. ;* press Cap Lock and then another key. Then, Cap Lock Key 
  54. ;* functions as the Control Key.
  55. ;* LAMIGA,RAMIGA,and CONTROL are all flags that tell if those 
  56. ;* keys are being held down. When all three are, the computer
  57. ;* will reset.
  58. ;*
  59. ;* ATparity is the 10th bit that the AT keyboard transmits. It 
  60. ;* is SET if the number of DATA bits set is EVEN. Otherwise, its
  61. ;* CLEARED.
  62. ;*
  63. ;**************************************************
  64.  
  65.         ;bit memory locations:
  66.  
  67.         .equ    Capbit,42h
  68.         .equ    Capdown,43h
  69.         .equ    Ctrldown,44h
  70.         .equ    CONTROL,45h
  71.         .equ    LAMIGA,46h
  72.         .equ    RAMIGA,47h
  73.         .equ    ATparity,48h
  74.         .equ    Make,49h
  75.          .equ    ColdBoot,50h
  76.  
  77.         ;byte memory locations:
  78.  
  79.         .equ    Charbad,50h
  80.         .equ    Oldchar,51h
  81.         .equ    Amigachar,52h
  82.         .equ    tempo,53h
  83.         .equ    mkey,54h
  84.         .equ    scrollKey,55h
  85.  
  86.         .org    0200h
  87.  
  88. start:  mov     tmod,#11h       ;two 16 bit timers
  89.         mov     ie,#00h         ;clear all interrupts
  90.         setb    ea              ;allow interrupt
  91.         setb    et1             ;enable timer 1 interrupt
  92.         setb    pt0                ;timer 0 has high priority
  93.         mov     sp,#30h         ;stack somewhere safe.
  94.  
  95. ; set the ports for input
  96.         mov     p1,#255         ;set port1 for read
  97.         mov     p3,#255         ;set port 3 for read
  98.         clr     tr1             ;make sure timers are in
  99.         clr     tf1             ;reset state.
  100.         clr     tr0
  101.         clr     tf0
  102.  
  103. ; clear out the miscellaneous flags.
  104.         clr     Capdown         ;Caps is up...
  105.         clr     Ctrldown        ;Control is up
  106.         clr     Capbit          ;Caps light is off.
  107.         setb    CONTROL         ;all reset keys are UP
  108.         setb    LAMIGA
  109.         setb    RAMIGA
  110.  
  111. ;**** sync the controller with the Amiga. clock out
  112. ;**** ones until we receive a handshake...
  113. sync:
  114.         mov     tl1,#0          ;set up timer for 143ms
  115.         mov     th1,#0
  116.         mov     r1,#2
  117.         setb    tr1
  118. sync2:
  119.         jb      Adat,sync2      ;wait for handshake
  120. sync3:
  121.         jnb     Adat,sync3      ;wait for end of handshake
  122.         clr     tr1
  123.  
  124. ;**** transmit power up key stream and end key stream.
  125.         mov     a,#0FDh
  126.         acall   actualtransmit
  127.         mov     a,#0FEh
  128.         acall   actualtransmit
  129.  
  130. ;**** sync up the AT and go with it!
  131.  
  132. ATPowerup:
  133.         mov     a,#0ffh         ;RESET
  134.         acall   SendtoAT
  135.         mov     a,#0f6h         ;DEFAULT
  136.         acall   SendtoAT
  137.         mov     a,#0edh         ;NEXT DATA is FOR LIGHTS
  138.         acall   SendtoAT
  139.         mov     a,#2            ;NUMLOCK ON?
  140.         acall   SendtoAT
  141.         mov     a,#0f4h         ;CLEAR BUFFER
  142.         acall   SendtoAT
  143.  
  144. ;***************************************************
  145. ;*  If some pin of P3 are low perform a
  146. ;*    Reset after a delay for slow hard drive spin up
  147. ;*
  148. ;***************************************************
  149.  
  150.         jnb     ColdBoot,noCold      ;first boot ?
  151.         clr     ColdBoot
  152.  
  153.         mov     a,p3
  154.         cjne    a,#255,slowSpinUp   ;any low level on P3
  155.         ljmp    ATstyle
  156.  
  157. slowSpinUp:
  158.         clr     tr0
  159.         clr     tf0
  160.         cpl     a
  161.         mov     tempo,a
  162.         mov     r1,tempo    ;approximatly  (r1) * 72ms
  163.         mov     th0,#0      ;timer 0 will overflow repeatedly
  164.         mov     tl0,#0
  165.         setb    tr0         ; start timer 0
  166. waitReset:
  167.         jnb     tf0,waitReset   ;wait for overflow flag
  168.         clr     tf0             ;clear it again
  169.         djnz    r1,waitReset
  170.         clr     tf0
  171.         clr     tr0             ;stop the timer
  172.         ljmp    resetwarn
  173.  
  174. noCold:
  175.         ljmp    ATstyle         ;go and parse AT keyboard
  176.  
  177. ;***********************************************
  178. ;* ATgetkey
  179. ;* ATgetkey
  180. ;* ATgetkey
  181. ;*
  182. ;* ATgetkey looks at the keyboard and waits for a key to be
  183. ;* pressed. ATinkey is the actual routine that watched the logic
  184. ;* levels of Kdat and Kclk. IF the character's parity is not
  185. ;* what it is supposed to be, then the routine will attempt to
  186. ;* tell the keyboard to resend.
  187. ;*
  188. ;* When exiting from this routine, Kclock is pulled low to hold
  189. ;* off any more transmissions. You must restore it to 5 volts to
  190. ;* receive any more characters later.
  191. ;*
  192. ;*
  193.  
  194. ATgetkey:
  195.         mov     r0,#11          ;number of bits
  196.         setb    Kclk
  197. ATwaitC0:
  198.         jb      Kclk,ATwaitC0   ;wait for a clock pulse
  199.         dec     r0              ;decrement clock bit counter
  200.         cjne    r0,#10,ATnstart ;test for startbit
  201.         sjmp    ATwait
  202. ATnstart:
  203.         cjne    r0,#0,ATnstop   ;check for stopbit
  204. ATwaitC1:
  205.         jnb     Kclk,ATwaitC1   ;wait for clock to go high
  206.         clr     Kclk            ;hold off more data
  207.         mov     r0,#20          ;small delay
  208. pause:  djnz    r0,pause
  209. ;**** now we check to see if the parity between
  210. ;**** Bit register P (which is set if Parity of Acc is odd)
  211. ;**** is compared to the received Parity Bit.
  212.         jb      p,parityodd     ;test if parity of DATA is odd
  213. parityeven:
  214.         jnb     ATparity,ATerror
  215.         ret                     ;Okay to return. A=valid
  216. parityodd:
  217.         jb      ATparity,ATerror
  218.         ret                     ;Okay to return. A=valid
  219. ATerror:
  220.         mov     a,#0feh         ;RESEND character
  221.         acall   SendtoAT
  222.         sjmp    ATgetkey        ;now return to caller
  223. ATnstop:
  224.         cjne    r0,#1,ATdatab   ;check for paritybit
  225.         mov     c,Kdat          ;error checking! (AT only)
  226.         mov     ATparity,c
  227.         sjmp    ATwait          ;
  228. ATdatab: 
  229.         mov     c,Kdat          ;get data bit
  230.         rrc     a               ;shift it into accumulator
  231. ATwait: jnb     Kclk,ATwait     ;wait for clock line to go low
  232.         sjmp    ATwaitC0        ;get another bit
  233.  
  234.  
  235. ;**************************************************
  236. ;* AT-STYLE
  237. ;*
  238. ;*     This waits for a keycode or two from the IBM and then calls
  239. ;* the appropriate transmit subroutine. The IBM keyboard sends 
  240. ;* out special codes in front of and behind some scancodes. This
  241. ;* routine will chop them out before doing a lookup on the
  242. ;* code to see what to send to the AMIGA. The scancodes between 
  243. ;* the IBM and the AMIGA are of course, not the same!
  244. ;*
  245. ;**************************************************
  246.  
  247. ATstyle:
  248.         acall   ATgetkey          ;get one scancode.
  249.         cjne    a,#0e1h,ATnE1
  250.         acall   ATgetkey          ;(should be 14)
  251.         acall   ATgetkey          ;(should be 77)
  252.         acall   ATgetkey          ;(should be E1)
  253.         acall   ATgetkey          ;(should be F0)
  254.         acall   ATgetkey          ;(should be 14)
  255.         acall   ATgetkey          ;(should be F0)
  256.         acall   ATgetkey          ;(should be 77)
  257.         sjmp    ATstyle
  258. ;PAUSE was pressed. Just ignore it.
  259. ATnE1:
  260.         mov     dptr,#ATtb1
  261.         cjne    a,#0e0h,ATnE0
  262.         mov     dptr,#ATtb2
  263.         acall   ATgetkey
  264.         cjne    a,#0f0h,ATnE0F0
  265.         acall   ATgetkey
  266.         cjne    a,#12h,ATnEF12
  267.         ljmp    ATstyle         ;(E0F012....ignore it)
  268. ATnEF12:
  269.         cjne    a,#59h,ATup     ;(E0F0mk)
  270.         ljmp    ATstyle         ;(E0F059....ignore it)
  271. ATnE0F0:
  272.         cjne    a,#12h,ATnE012
  273.         ljmp    ATstyle         ;(E012....ignore it)
  274. ATnE012:
  275.         cjne    a,#59h,ATdown   ;(E0mk)
  276.         ljmp    ATstyle         ;(E059....ignore it)
  277. ATnE0:
  278.         cjne    a,#0f0h,ATdown  ;(mk)
  279.         acall   ATgetkey
  280.         sjmp    ATup            ;(F0mk....normal key break)
  281.  
  282. ;**************************************************
  283. ;* ATdown and the rest here call a lookup table to change
  284. ;* the AT scancodes into AMIGA scancodes. In the "down"
  285. ;* routine, the "make" bit is asserted. In the "up" routine
  286. ;* it is de-asserted.
  287. ;**************************************************
  288. ATdown:
  289.         movc    a,@a+dptr       ;indexed into table
  290.         clr     acc.7           ;clear make/break bit
  291.         acall   transmit        ;transmit it
  292.         ljmp    ATstyle
  293. ATup:
  294.         movc    a,@a+dptr
  295.         setb    acc.7           ;set make/break bit
  296.         acall   transmit        ;transmit it
  297.         ljmp    ATstyle
  298.  
  299. ;**************************************************
  300. ;* SendtoAT is the subroutine that sends special codes
  301. ;* to the keyboard from the controller. Codes include
  302. ;* the command to reset (FF) or the command to change
  303. ;* the lights (ED). It is advisable to keep the timing
  304. ;* very close to how I have it done in this routine.
  305. ;**************************************************
  306.  
  307. SendtoAT:
  308.         setb    Kclk
  309.         clr     Kdat
  310.         mov     r0,#8
  311. Send4:  jb      Kclk,Send4      ;data bit
  312.         mov     c,acc.0
  313.         mov     Kdat,c
  314.         rr      a 
  315. Send5:  jnb     Kclk,Send5      ;data bit
  316.         dec     r0
  317.         cjne    r0,#0,Send4
  318.         mov     c,p
  319.         cpl     c
  320. Send6:  jb      Kclk,Send6      ;parity bit
  321.         mov     Kdat,c
  322. Send7:  jnb     Kclk,Send7      ;parity bit
  323. Send77: jb      Kclk,Send77     ;stop bit
  324.         setb    Kdat
  325. Send78: jnb     Kclk,Send78     ;stop bit
  326. Send79: jb      Kclk,Send79
  327. Send7a: jnb     Kclk,Send7a
  328.         mov     r0,#8           ;small delay
  329. Send8:  djnz    r0,Send8
  330.         clr     Kclk            ;drive clock low
  331.         mov     r0,#20          ;long delay
  332. Send9:  djnz    r0,Send9
  333.         setb    Kclk
  334.         acall   ATgetkey        ;should check if response isbad.
  335.         ret                     ;who cares if it is? not me!
  336.  
  337. ;**************************************************
  338. ;*
  339. ;* TRANSMIT first does some checking to take out repeating
  340. ;* keys and does the conversion on the Caps Lock Key and
  341. ;* then calls Actualtransmit.
  342. ;*
  343. ;**************************************************
  344.  
  345. dontrans:                       ;jumps back if key is already
  346.         pop     acc             ;held down.
  347.         ret
  348. transmit:
  349.         cjne    a,Oldchar,transok
  350.         ret
  351. transok:
  352.         cjne    a,#62h,transok2 ;jump if not CapsLock=down
  353.         mov     Oldchar,a
  354.         setb    Capdown         ;set the flags for later
  355.         ret
  356. transok2:                       
  357.         cjne    a,#0e2h,transok3;jump if not CapsLock=up
  358.         mov     a,Oldchar       ;see if Caps was just down
  359.         cjne    a,#62h,transok4 ;if not, then it was a control
  360. XTcap:
  361.         clr     Capdown         ;clear flag
  362.         cpl     Capbit          ;toggle down/up-ness of Caplock
  363.         mov     a,#62h
  364.         mov     c,Capbit
  365.         cpl     c
  366.         mov     acc.7,c
  367.         acall   actualtransmit  ;(Caps to Amiga!)
  368.         mov     a,#0edh         ;set lights on next byte.
  369.         acall   SendtoAT
  370.         mov     a,#2            ;numlock on
  371.         mov     c,Capbit
  372.         mov     acc.2,c
  373.         acall   SendtoAT        ;maybe capslock light
  374. skiplights: 
  375.         ret           
  376. transok4:
  377.         clr     CtrlDown        ;This sends out a Control Up.
  378.         clr     Capdown         ;Caps lock is done functioning as Ctl
  379.         mov     a,#63h          ;Control Key
  380.         setb    acc.7           ;break bit set.
  381.         acall   actualtransmit  ;send to Amiga.
  382.         ret
  383. transok3:
  384.         mov     Oldchar,a
  385.         jnb     Capdown,noControl
  386.         jb      CtrlDown,noControl
  387.         setb    CtrlDown        ;Caps lock is beginning to function
  388.         mov     a,#63h          ;as the Control Key.
  389.         acall   actualtransmit  ;send Control Down to Amiga
  390.         mov     a,Oldchar       ;now send the actual key
  391.  
  392. noControl:                      ;its not a controlled key
  393.         mov     c,acc.7         ;c=make/break bit
  394.         mov     Make,c          ;will be set if key up
  395.         clr     acc.7           ;test for key only. NO make/break
  396.  
  397. ;************************************
  398. ; begin special key test
  399.  
  400.         jb      switchMap,noRaw ;jump if switchMap
  401.         ljmp    amigaKey
  402.  
  403. noRaw:
  404.         mov     mKey,#29h
  405.         jb      usFlag,frenchM  ;american or french 'm' ? 
  406.         mov     mKey,#37h
  407. frenchM:
  408.         mov     r3,mKey
  409.         mov     scrollKey,r3    ;prepare the mapping of scrollLock
  410.         jb      switch95,suite  ;jump if switch95 is high
  411.         mov     scrollKey,#18h
  412. suite:
  413.  
  414. ;************************************
  415. ; HOME -> control cursor up
  416. ;************************************
  417.  
  418.         cjne    a,#75h,noHome    ;home ?
  419.         jnb     Make,homedown
  420. homeup:
  421.         mov     a,#0cch         ;cursor up break
  422.         acall   actualtransmit
  423.         acall   Smalldelay
  424.         mov     a,#0e3h         ;right control break (cdc 27-5-96))
  425.         acall   actualtransmit
  426.         ret
  427. homedown:
  428.         mov     a,#63h          ;control make
  429.         acall   actualtransmit
  430.         acall   Smalldelay
  431.         mov     a,#4ch          ;cursor up make
  432.         acall   actualtransmit
  433.         ret
  434. noHome:
  435.  
  436. ;*************************************
  437. ; END -> control cursor down 
  438. ;*************************************
  439.  
  440.         cjne    a,#76h,noEnd  ; end ?
  441.         jnb     Make,enddown
  442. endup:
  443.         mov     a,#0cdh         ;cursor down break
  444.         acall   actualtransmit
  445.         mov     a,#0e3h         ;control break
  446.         acall   Smalldelay
  447.         acall   actualtransmit
  448.         ret
  449. enddown:
  450.         mov     a,#63h          ;control make
  451.         acall   actualtransmit
  452.         acall   Smalldelay      ;cursor down make
  453.         mov     a,#4dh
  454.         acall   actualtransmit
  455.         ret
  456. noEnd:                        
  457.  
  458. ;******************************************
  459. ; Page Up -> Rshift cursor up 
  460. ;******************************************
  461.  
  462.         cjne    a,#77h,noPageUp    ; pageUp ?
  463.         jnb     Make,pageUpdown
  464. pageUpup:
  465.         mov     a,#0cch         ;cursor up break
  466.         acall   actualtransmit
  467.         acall   Smalldelay
  468.         mov     a,#0e1h         ;Rshift break
  469.         acall   actualtransmit
  470.         ret
  471. pageUpdown:
  472.         mov     a,#61h          ;Rshift make
  473.         acall   actualtransmit
  474.         acall   Smalldelay
  475.         mov     a,#04ch         ;cursor up make
  476.         acall   actualtransmit
  477.         ret
  478. noPageUp:
  479.  
  480. ;******************************************
  481. ; Page Down -> Rshift cursor down
  482. ;******************************************
  483.  
  484.         cjne    a,#78h,noPageDown  ;PageDow key ?
  485.         jnb     Make,pageDowndown
  486. pageDownup:
  487.         mov     a,#0cdh         ;cursor down break
  488.         acall   actualtransmit
  489.         acall   Smalldelay      
  490.         mov     a,#0e1h            ;Rshift break
  491.         acall   actualtransmit
  492.         ret
  493. pageDowndown:
  494.         mov     a,#61h          ;Rshift make
  495.         acall   actualtransmit
  496.         acall   Smalldelay
  497.         mov     a,#4dh          ;cursor down make
  498.         acall   actualtransmit
  499.         ret
  500. noPageDown:
  501.  
  502. ;************************************
  503. ; F12 -> right Amiga d
  504. ;************************************
  505.  
  506.         cjne    a,#7ah,noF12    ; F12 ?
  507.         jnb     Make,F12down
  508. F12up:
  509.         mov     a,#0a2h         ;'d' break
  510.         acall   actualtransmit
  511.         acall   Smalldelay
  512.         mov     a,#0e7h         ;right Amiga break
  513.         acall   actualtransmit
  514.         ret
  515. F12down:
  516.         mov     a,#67h          ;right Amiga  make
  517.         acall   actualtransmit
  518.         acall   Smalldelay
  519.         mov     a,#22h          ;'d' make
  520.         acall   actualtransmit
  521.         ret
  522. noF12:
  523.  
  524. ;************************************
  525. ; PrintScreen -> right Amiga /
  526. ;************************************
  527.  
  528.         cjne    a,#7bh,noPscreen    ; printScreen ?
  529.         jnb     Make,pscreendown
  530. pscreenup:
  531.         mov     a,#0dch         ;'/' break
  532.         acall   actualtransmit
  533.         acall   Smalldelay
  534.         mov     a,#0e7h         ;right Amiga break
  535.         acall   actualtransmit
  536.         ret
  537. pscreendown:
  538.         mov     a,#67h          ;right Amiga  make
  539.         acall   actualtransmit
  540.         acall   Smalldelay
  541.         mov     a,#5ch          ;'/' make
  542.         acall   actualtransmit
  543.         ret
  544. noPscreen:
  545.  
  546. ;************************************
  547. ; ScrollLock -> left Amiga m or o
  548. ;************************************
  549.  
  550.         cjne    a,#7ch,noScroll    ; ScrollLock ?
  551.         jnb     Make,scrolldown
  552. scrollup:
  553.         mov     a,scrollKey         ;key  break
  554.         add        a,#80h
  555.         acall   actualtransmit
  556.         acall   Smalldelay
  557.         mov     a,#0e6h         ;left Amiga break
  558.         acall   actualtransmit
  559.         ret
  560. scrolldown:
  561.         mov     a,#66h          ;left Amiga  make
  562.         acall   actualtransmit
  563.         acall   Smalldelay
  564.         mov     a,scrollKey     ;key  make
  565.         acall   actualtransmit
  566.         ret
  567. noScroll:
  568.  
  569. ;************************************
  570. ; F11 -> \ the missing key !!
  571. ;************************************
  572.  
  573.         cjne    a,#79h,noF11    ; F11 ?
  574.         jnb     Make,F11down
  575. F11up:
  576.         mov        Oldchar,#8dh    ; '\' break
  577.         sjmp    noF11
  578. F11down:
  579.         mov     Oldchar,#0dh    ; '\' make
  580.         ljmp    endSpecial    ;
  581. noF11:
  582.  
  583.  
  584. amigaKey:
  585.         jnb     switch95,Keyboard95        ; jump if switch95 is low (mean 95 style keyboard)
  586.  
  587. ;******************************************
  588. ; Left Control ->  Left Amiga
  589. ;******************************************
  590.  
  591.         cjne    a,#70h,noLctrl  ; left control ?
  592.         jnb     Make,lctrldown
  593. lctrlup:
  594.         mov        Oldchar,#0e6h    ; left amiga break
  595.         sjmp    noLctrl
  596. lctrldown:
  597.         mov     Oldchar,#66h    ; left amiga make
  598.         ljmp    endSpecial    ;
  599.  
  600. ;******************************************
  601. ; Right Control ->  Right Amiga
  602. ;******************************************
  603.  
  604. noLctrl:
  605.         cjne    a,#71h,endSpecial  ;right control key ?
  606.         jnb     Make,rctrldown
  607. rctrlup:
  608.         mov        Oldchar,#0e7h    ; right amiga break
  609.         sjmp    endSpecial
  610. rctrldown:
  611.         mov     Oldchar,#67h    ; right amiga make
  612.         ljmp    endSpecial    ;
  613.  
  614.  
  615. ; begin 95 style keyboard special test
  616.  
  617. Keyboard95:        
  618.  
  619. ;************************************
  620. ; windos menu -> Left Amiga m 
  621. ;************************************
  622.  
  623.         cjne    a,#74h,noWinMenu    ; windos menu key ?
  624.         jnb     Make,winMenuDown
  625. winMenuUp:
  626.         mov     a,mKey         ; 'm' break
  627.         add        a,#80h
  628.         acall   actualtransmit
  629.         acall   Smalldelay
  630.         mov     a,#0e6h         ; left Amiga break
  631.         acall   actualtransmit
  632.         ret
  633. winMenuDown:
  634.         mov     a,#66h          ; left Amiga make
  635.         acall   actualtransmit
  636.         acall   Smalldelay
  637.         mov     a,mKey          ; 'm' make
  638.         acall   actualtransmit
  639.         ret
  640. noWinMenu:
  641.  
  642. ;******************************************
  643. ; Left Control ->  Control
  644. ;******************************************
  645.  
  646.         cjne    a,#70h,noLctrl95  ; left control ?
  647.         jnb     Make,lctrldown95
  648. lctrlup95:
  649.         mov        Oldchar,#0e3h    ; control break
  650.         sjmp    noLctrl95
  651. lctrldown95:
  652.         mov     Oldchar,#63h    ; control make
  653.         sjmp    endSpecial    ;
  654. noLctrl95:
  655.  
  656. ;******************************************
  657. ; Right Control ->  Control
  658. ;******************************************
  659.  
  660.         cjne    a,#71h,noRctrl95  ;right control ?
  661.         jnb     Make,rctrldown95
  662. rctrlup95:
  663.         mov        Oldchar,#0e3h    ; control break
  664.         sjmp    endSpecial
  665. rctrldown95:
  666.         mov     Oldchar,#63h    ; control make
  667.         sjmp    endSpecial    ;
  668. noRctrl95:
  669.  
  670. ;******************************************
  671. ; Left windows key ->  Left Amiga
  672. ;******************************************
  673.  
  674.         cjne    a,#72h,noLwin  ; left windows key ?
  675.         jnb     Make,lwindown
  676. lwinup:
  677.         mov        Oldchar,#0e6h    ; left amiga break
  678.         sjmp    noLwin
  679. lwindown:
  680.         mov     Oldchar,#66h    ; left amiga make
  681.         sjmp    endSpecial    ;
  682. noLwin:
  683.  
  684. ;******************************************
  685. ; Right windos key ->  Right Amiga
  686. ;******************************************
  687.  
  688.         cjne    a,#73h,endSpecial      ; right windows key ?
  689.         jnb     Make,rwindown
  690. rwinup:
  691.         mov        Oldchar,#0e7h    ; right amiga break
  692.         sjmp    endSpecial
  693. rwindown:
  694.         mov     Oldchar,#67h    ; right amiga make
  695.         sjmp    endSpecial
  696.  
  697.  
  698. ; ************************
  699. Smalldelay:
  700.         mov     th0,#0
  701.         mov     tl0,#0
  702.         clr     tf0
  703.         setb    tr0
  704. small1: jnb     tf0,small1
  705.         clr     tf0
  706.         clr     tr0
  707.         ret
  708. ; ************************
  709.  
  710. endSpecial:
  711.         mov     a,Oldchar
  712.         acall   actualtransmit  ;transmit the keycode
  713.         mov     a,Oldchar       ;get back same keycode, in A.
  714.         mov     c,acc.7         ;put make/break bit in Make
  715.         mov     Make,c
  716.         clr     acc.7           ;start testing for reset keys
  717.  
  718.         cjne    a,#63h,nrset1   ;held down
  719.         mov     c,Make
  720.         mov     CONTROL,c
  721.         sjmp    trset
  722. nrset1: cjne    a,#66h,nrset2
  723.         mov     c,Make
  724.         mov     LAMIGA,c
  725.         sjmp    trset
  726. nrset2: cjne    a,#67h,trset
  727.         mov     c,Make
  728.         mov     RAMIGA,c
  729. trset:  jnb     CONTROL,maybefree       ;if bit set, this key is up
  730.         jb      CtrlDown,maybefree      ;if bit set, this key is down
  731.         sjmp    free
  732. maybefree:
  733.         jb      LAMIGA,free     ;ditto
  734.         jb      RAMIGA,free     ;ditto
  735.         sjmp    resetwarn       ;OOPS! They are all down!
  736. free:   ret
  737.  
  738.  
  739. resetwarn:
  740.         clr     tf0             
  741.         mov     a,78h
  742.         mov     r1,#2           ;set up timer 0 watchdog
  743.         mov     tl0,#0
  744.         mov     th0,#0
  745.         cpl     a               ;invert, don't know why.
  746.         mov     r0,#8
  747. wr1:
  748.         rl      a
  749.         mov     c,acc.7
  750.         mov     Adat,c
  751.         mov     b,#8
  752. wr2:
  753.         djnz    b,wr2             ; transmit it.
  754.         clr     Aclk
  755.         mov     b,#8
  756. wr3:
  757.         djnz    b,wr3
  758.         setb    Aclk
  759.         mov     b,#10
  760. wr4:
  761.         djnz    b,wr4
  762.         djnz    r0,wr1
  763.         setb    Adat
  764.         setb    tr0             ;start watchdog
  765. wr5:
  766.         jnb     Adat,caught1
  767.         jnb     tf0,wr5
  768.         clr     tf0
  769.         djnz    r1,wr5
  770.         sjmp    Hardreset
  771. caught1:
  772.         clr     tr0
  773.         clr     tf0
  774.         mov     a,78h
  775.         mov     r1,#4
  776.         mov     tl0,#0
  777.         mov     th0,#0
  778.         cpl     a    
  779.         mov     r0,#8
  780. wr11:
  781.         rl      a
  782.         mov     c,acc.7
  783.         mov     Adat,c
  784.         mov     b,#8
  785. wr22:
  786.         djnz    b,wr22   
  787.         clr     Aclk
  788.         mov     b,#8
  789. wr33:
  790.         djnz    b,wr33
  791.         setb    Aclk
  792.         mov     b,#10
  793. wr44:
  794.         djnz    b,wr44
  795.         djnz    r0,wr11
  796.         setb    Adat
  797.         setb    tr0             ;start watchdog
  798. wr55:
  799.         jnb     Adat,caught2
  800.         jnb     tf0,wr55
  801.         clr     tf0
  802.         djnz    r1,wr55
  803.         sjmp    Hardreset
  804. caught2:
  805. hold:   jnb     Adat,hold
  806. Hardreset:
  807.         clr     tr0
  808.         clr     tf0
  809.         clr     Areset
  810.         clr     Aclk            ;clear both lines
  811.         mov     r1,#15          ;clock should go low for over 500ms
  812.         mov     th0,#0          ;timer 1 will overflow repeatedly
  813.         mov     tl0,#0
  814.         setb    tr0
  815. hsloop:
  816.         jnb     tf0,hsloop      ;wait for overflow flag
  817.         clr     tf0             ;clear it again
  818.         djnz    r1,hsloop
  819.         clr     tf0
  820.         clr     tr0             ;stop the timer
  821.         ljmp    start
  822.  
  823. ;**************************************************
  824. ;*
  825. ;* ActualTransmit sends the character out to the Amiga and waits
  826. ;* for an acknowledge handshake. If it does not receive one in
  827. ;* 143 ms, then it clocks out 1's on the data line until it
  828. ;* receives the acknowledge. If the Amiga is not connected up,
  829. ;* then it will hang here. The handshake is that the AMIGA
  830. ;* drives the clock line low.
  831. ;*
  832. ;*      The loops with register B are for timing delays.
  833. ;* There should be about 20usec between when the Data line is 
  834. ;* set, the Clock line is driven low, and the Clock line
  835. ;* is driven high.
  836. ;*
  837. ;**************************************************
  838.  
  839. actualtransmit:
  840.         mov     Amigachar,a     ;set the character to transmit
  841.  
  842.         mov     r0,#05          ;do a small delay
  843. dly:
  844.         mov     b,#0
  845. delay:  djnz    b,delay
  846.         djnz    r0,dly
  847.  
  848. actual2:
  849.         mov     a,Amigachar     ;restore it
  850.         clr     Charbad         ;character is not bad yet
  851.         mov     r1,#2           ;set up timer 0 watchdog
  852.         mov     tl1,#0
  853.         mov     th1,#0
  854.         cpl     a               ;invert, don't know why.
  855.         mov     r0,#8
  856. f:      rl      a
  857.         mov     c,acc.7
  858.         mov     Adat,c
  859.         mov     b,#8
  860. g:      djnz    b,g             ; transmit it.
  861.         clr     Aclk
  862.         mov     b,#8
  863. h:      djnz    b,h
  864.         setb    Aclk
  865.         mov     b,#10
  866. i:      djnz    b,i
  867.         djnz    r0,f
  868.         setb    Adat
  869.         setb    tr1             ;start watchdog
  870. waitshake:
  871.         jb      Adat,waitshake
  872.         clr     tr1             ;stop watchdog
  873. gotit:  jnb     Adat,gotit
  874.         ret
  875.  
  876. timer1int:
  877.         djnz    r1,t3           ;we wait for 143 ms.
  878.         mov     r1,#2           
  879.         setb    Charbad         ;flag to resend the character
  880.         clr     Adat            ;1 on the data line
  881.         mov     b,#8
  882. tt1:    djnz    b,tt1           ;wait for it
  883.         clr     Aclk            ;clock asserted
  884.         mov     b,#8            ;sync up the controller to the
  885. tt2:    djnz    b,tt2           ;amiga
  886.         setb    Aclk
  887.         mov     b,#10
  888. tt3:    djnz    b,tt3
  889.         setb    Adat
  890. t3:     reti                    ;return and send again.
  891.  
  892. ATtb1: 
  893.         .db     0               
  894.         .db     58h             ;F9
  895.         .db     0               
  896.         .db     54h             ;F5
  897.         .db     52h             ;F3
  898.         .db     50h             ;F1
  899.         .db     51h             ;F2
  900.         .db     7ah             ;F12= raw 7a (charles)
  901.         .db     0
  902.         .db     59h             ;F10
  903.         .db     57h             ;F8
  904.         .db     55h             ;F6
  905.         .db     53h             ;F4
  906.         .db     42h             ;TAB
  907.         .db     00h             ;~
  908.         .db     0
  909.  
  910.         .db     0
  911.         .db     64h             ;Left ALT
  912.         .db     60h             ;Left SHIFT
  913.         .db     0
  914.         .db     70h             ;Left Ctrl = raw 70
  915.         .db     10h             ;Q
  916.         .db     01h             ;1
  917.         .db     0
  918.         .db     0
  919.         .db     0
  920.         .db     31h             ;Z
  921.         .db     21h             ;S
  922.         .db     20h             ;A
  923.         .db     11h             ;W
  924.         .db     02h             ;2
  925.         .db     0
  926.  
  927.         .db     0
  928.         .db     33h             ;C
  929.         .db     32h             ;X
  930.         .db     22h             ;D
  931.         .db     12h             ;E
  932.         .db     04h             ;4
  933.         .db     03h             ;3
  934.         .db     0
  935.         .db     0
  936.         .db     40h             ;SPACE
  937.         .db     34h             ;V
  938.         .db     23h             ;F
  939.         .db     14h             ;T
  940.         .db     13h             ;R
  941.         .db     05h             ;5
  942.         .db     0
  943.  
  944.         .db     0
  945.         .db     36h             ;N
  946.         .db     35h             ;B
  947.         .db     25h             ;H
  948.         .db     24h             ;G
  949.         .db     15h             ;Y
  950.         .db     06h             ;6
  951.         .db     0
  952.         .db     0
  953.         .db     0
  954.         .db     37h             ;M
  955.         .db     26h             ;J
  956.         .db     16h             ;U
  957.         .db     07h             ;7
  958.         .db     08h             ;8
  959.         .db     0
  960.  
  961.         .db     0
  962.         .db     38h             ;<
  963.         .db     27h             ;K
  964.         .db     17h             ;I
  965.         .db     18h             ;O
  966.         .db     0Ah             ;0
  967.         .db     09h             ;9
  968.         .db     0
  969.         .db     0
  970.         .db     39h             ;>
  971.         .db     3ah             ;/
  972.         .db     28h             ;L
  973.         .db     29h             ; ';'
  974.         .db     19h             ;P
  975.         .db     0bh             ;-
  976.         .db     0
  977.  
  978.         .db     0
  979.         .db     0
  980.         .db     2ah             ;'
  981.         .db     0
  982.         .db     1ah             ;[
  983.         .db     0ch             ;=
  984.         .db     0
  985.         .db     0
  986.         .db     62h             ;CAPS LOCK?
  987.         .db     61h             ;Right SHIFT
  988.         .db     44h             ;RETURN
  989.         .db     1bh             ;]
  990.         .db     0
  991.         .db     2bh             ; µ ( put 2b instead d, Charles)
  992.         .db     0
  993.         .db     0
  994.         .db        0
  995.         .db        30h                ; < (add by Charles Da Costa)
  996.  
  997.         .rs     4
  998.         .db     41h             ;Back SPACE
  999.         .db     0
  1000.         .db     0
  1001.         .db     1dh             ;1 keypad
  1002.         .db     0
  1003.         .db     2dh             ;4 keypad
  1004.         .db     3dh             ;7 keypad
  1005.         .db     0
  1006.         .db     0
  1007.         .db     0
  1008.  
  1009.         .db     0fh             ;0 keypad
  1010.         .db     3ch             ;dot keypad
  1011.         .db     1eh             ;2 keypad
  1012.         .db     2eh             ;5 keypad
  1013.         .db     2fh             ;6 keypad
  1014.         .db     3eh             ;8 keypad
  1015.         .db     45h             ;ESCAPE!
  1016.         .db     5ah             ;Number Lock=( (Charles)
  1017.         .db     79h             ;F11 = raw 79  (Charles)
  1018.         .db     5eh             ;+ keypad
  1019.         .db     1fh             ;3 keypad
  1020.         .db     4ah             ;- keypad
  1021.         .db     5dh             ;* keypad
  1022.         .db     3fh             ;9 keypad
  1023.         .db     7ch             ;scroll Lock raw 7c (Charles)
  1024.         .db     0
  1025. ATtb2:
  1026.         .rs     3
  1027.         .db     56h             ;F7
  1028.         .db     7bh             ;print screen raw 7b (charles)
  1029.         .rs     11
  1030. ;10
  1031.         .db     0
  1032.         .db     65h             ;Right ALT
  1033.         .db     0
  1034.         .db     0
  1035.         .db     71h             ;Right CTL = raw 71 (charles)
  1036.         .rs        10
  1037.         .db        72h                ;win95g = raw 72 (charles)
  1038. ;20
  1039.         .rs     7
  1040.         .db        73h                ;win95d = raw 73 (charles)
  1041.         .rs        7
  1042.         .db        74h                ;menu95 = raw 74 (charles)
  1043.  
  1044. ;30        
  1045.         .rs     10h
  1046.  
  1047.         .rs     10
  1048.         .db     5ch             ;/key, supposedly
  1049.         .rs     5
  1050.  
  1051.         .rs     10
  1052.         .db     43h             ;Numeric Enter
  1053.         .rs     5
  1054.  
  1055.         .rs     9
  1056.         .db     76h             ;End=control down (Charles 27-5-96)
  1057.         .db     0
  1058.         .db     4fh             ;Cursor Left
  1059.         .db     75h             ;Home=control up (Charles 27-5-96)
  1060.         .db     0
  1061.         .db     0
  1062.         .db     63h             ;MACRO key=control
  1063.  
  1064.         .db     5fh             ;Insert=help (Charles 27-5-96)
  1065.         .db     46h             ;Delete
  1066.         .db     4dh             ;Cursor Down
  1067.         .db     0
  1068.         .db     4eh             ;Cursor Right
  1069.         .db     4ch             ;Cursor Up
  1070.         .rs     4
  1071.         .db     78h             ;Page Down=shift down (Charles 27-5-96)
  1072.         .db     0
  1073.         .db     7bh             ;print screen = raw 7b
  1074.         .db     77h             ;Page up=shift up (Charles 27-5-96)
  1075.         .db     40h             ;Break=Space?
  1076.         .db     0
  1077.  
  1078.         .end    0
  1079.