Advertisement
Guest User

Untitled

a guest
Sep 13th, 2014
1,638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pic 16 38.97 KB | None | 0 0
  1. ;KEY.ASM
  2. ;   IBM keyboard to Amiga Converter
  3. ;
  4. ;
  5.         list p=16f628a, f=inhx8m  ;Enter device name
  6.         include "p16f628a.inc"
  7.         __CONFIG _MCLRE_ON & _WDT_OFF & _INTOSC_OSC_NOCLKOUT & _LVP_OFF & _PWRTE_ON & _CP_OFF & _BOREN_OFF
  8.  
  9. #DEFINE PAGE0   bcf     STATUS,RP0          
  10. #DEFINE PAGE1   bsf     STATUS,RP0          
  11.    
  12. ;
  13. ;------------------------------------------------------
  14. ;Please define ScratchPadRam here:
  15. ;If you are using PIC16C5X define "ScratchPadRam equ 0x10"
  16. ;else define "ScratchPadRam equ 0x20"
  17. ;-------------------------------------------------------
  18. ;
  19. ScrollLock  equ     0x0
  20. NumLock     equ     0x1
  21. CapsLock    equ     0x2
  22. Kclk        equ     0x1
  23. Kdat        equ     0x0
  24. Aclk        equ     0x4
  25. Adat        equ     0x3
  26. Arst        equ     0x2
  27. Ctrlbit     equ     0x0
  28. RAmigabit   equ     0x1
  29. LAmigabit   equ     0x2
  30. Keytype     equ     0x0
  31. Resetype    equ     0x1
  32. ;
  33. ;
  34. ScratchPadRam   equ     0x20
  35. ;
  36. Capbit      equ     ScratchPadRam+0x0
  37. Capdown     equ     ScratchPadRam+0x1
  38. CtrlDown    equ     ScratchPadRam+0x2
  39. RESET       equ     ScratchPadRam+0x3
  40. Lights      equ     ScratchPadRam+0x4
  41. Count3      equ     ScratchPadRam+0x5
  42. ATparity    equ     ScratchPadRam+0x6
  43. Make        equ     ScratchPadRam+0x7
  44. Charbad     equ     ScratchPadRam+0x8
  45. Oldchar     equ     ScratchPadRam+0x9
  46. Amigachar   equ     ScratchPadRam+0xA
  47. Count1      equ     ScratchPadRam+0xB
  48. Count2      equ     ScratchPadRam+0xC
  49. ATchar      equ     ScratchPadRam+0xD
  50. tableoffset equ     ScratchPadRam+0xE
  51. AltConfig   equ     ScratchPadRam+0xF
  52. Savechar    equ     ScratchPadRam+0x10
  53. returnvalue equ     ScratchPadRam+0x11
  54. eeaddress   equ     ScratchPadRam+0x12
  55. eedata      equ     ScratchPadRam+0x13
  56. win95       equ     ScratchPadRam+0x14
  57. Savechar2   equ     ScratchPadRam+0x15
  58. ;
  59. ;        
  60.         org     0x0
  61.         goto    start
  62.  
  63. ATtb1
  64.         movwf       PCL                  
  65.         retlw       0x4F            ;F9
  66.         retlw       0x0              
  67.         retlw       0x57            ;F5
  68.         retlw       0x5B            ;F3
  69.         retlw       0x5F            ;F1
  70.         retlw       0x5D            ;F2
  71.         retlw       0x41            ;F12=help
  72.         retlw       0x0
  73.         retlw       0x4D            ;F10
  74.         retlw       0x51            ;F8
  75.         retlw       0x55            ;F6
  76.         retlw       0x59            ;F4
  77.         retlw       0x7B            ;TAB
  78.         retlw       0xFF            ;~
  79.         retlw       0x0
  80.  
  81.         retlw       0x0
  82.         retlw       0x37            ;Left ALT
  83.         retlw       0x3F            ;Left SHIFT
  84.         retlw       0x0
  85.         goto    lctrl               ;Left Ctrl
  86.         retlw       0xDF            ;Q
  87.         retlw       0xFD            ;1
  88.         retlw       0x0
  89.         retlw       0x0
  90.         retlw       0x0
  91.         retlw       0x9D            ;Z
  92.         retlw       0xBD            ;S
  93.         retlw       0xBF            ;A
  94.         retlw       0xDD            ;W
  95.         retlw       0xFB            ;2
  96.         retlw       0x0
  97.  
  98.         retlw       0x0
  99.         retlw       0x99            ;C
  100.         retlw       0x9B            ;X
  101.         retlw       0xBB            ;D
  102.         retlw       0xDB            ;E
  103.         retlw       0xF7            ;4
  104.         retlw       0xF9            ;3
  105.         retlw       0x0
  106.         retlw       0x0
  107.         retlw       0x7F            ;SPACE
  108.         retlw       0x97            ;V
  109.         retlw       0xB9            ;F
  110.         retlw       0xD7            ;T
  111.         retlw       0xD9            ;R
  112.         retlw       0xF5            ;5
  113.         retlw       0x0
  114.  
  115.         retlw       0x0
  116.         retlw       0x93            ;N
  117.         retlw       0x95            ;B
  118.         retlw       0xB5            ;H
  119.         retlw       0xB7            ;G
  120.         retlw       0xD5            ;Y
  121.         retlw       0xF3            ;6
  122.         retlw       0x0
  123.         retlw       0x0
  124.         retlw       0x0
  125.         retlw       0x91            ;M
  126.         retlw       0xB3            ;J
  127.         retlw       0xD3            ;U
  128.         retlw       0xF1            ;7
  129.         retlw       0xEF            ;8
  130.         retlw       0x0
  131.  
  132.         retlw       0x0
  133.         retlw       0x8F            ;<
  134.         retlw       0xB1            ;K
  135.         retlw       0xD1            ;I
  136.         retlw       0xCF            ;O
  137.         retlw       0xEB            ;0
  138.         retlw       0xED            ;9
  139.         retlw       0x0
  140.         retlw       0x0
  141.         retlw       0x8D            ;>
  142.         retlw       0x8B            ;/
  143.         retlw       0xAF            ;L
  144.         retlw       0xAD            ; ';'
  145.         retlw       0xCD            ;P
  146.         retlw       0xE9            ;-
  147.         retlw       0x0
  148.  
  149.         retlw       0x0
  150.         retlw       0x0
  151.         retlw       0xAB            ;@
  152.         retlw       0x0
  153.         retlw       0xCB            ;[
  154.         retlw       0xE7            ;=
  155.         retlw       0x0
  156.         retlw       0x0
  157.         retlw       0x3B            ;CAPS LOCK?
  158.         retlw       0x3D            ;Right SHIFT
  159.         retlw       0x77            ;RETURN
  160.         retlw       0xC9            ;]
  161.         retlw       0x0
  162.         retlw       0xA9            ;#=right foreign key
  163.         retlw       0x0
  164.         retlw       0x0
  165.  
  166.         retlw       0x0
  167.         retlw       0x9F            ;\ (next to left shift on AT keyboard)
  168.         retlw       0x0
  169.         retlw       0x0
  170.         retlw       0x0
  171.         retlw       0x0
  172.         retlw       0x7D            ;Back SPACE
  173.         retlw       0x0
  174.         retlw       0x0
  175.         retlw       0xC5            ;1 keypad
  176.         retlw       0x0
  177.         retlw       0xA5            ;4 keypad
  178.         retlw       0x85            ;7 keypad
  179.         retlw       0x0
  180.         retlw       0x0
  181.         retlw       0x0
  182.  
  183.         retlw       0xE1            ;0 keypad
  184.         retlw       0x87            ;dot keypad
  185.         retlw       0xC3            ;2 keypad
  186.         retlw       0xA3            ;5 keypad
  187.         retlw       0xA1            ;6 keypad
  188.         retlw       0x83            ;8 keypad
  189.         retlw       0x75            ;ESCAPE!
  190.         retlw       0x4B            ;Number Lock=( keypad  
  191.         retlw       0xE5            ;F11=\
  192.         retlw       0x43            ;+ keypad
  193.         retlw       0xC1            ;3 keypad
  194.         retlw       0x6B            ;- keypad
  195.         retlw       0x45            ;* keypad
  196.         retlw       0x81            ;9 keypad
  197.         retlw       0x49            ;scroll Lock=) keypad
  198.         retlw       0x0
  199.  
  200. ATtb2:
  201.         retlw       0x0
  202.         retlw       0x0
  203.         retlw       0x0
  204.         retlw       0x53            ;F7
  205.         goto    prtscreen           ;print screen=R Amiga P  
  206.         retlw       0x0
  207.         retlw       0x0
  208.         retlw       0x0
  209.         retlw       0x0
  210.         retlw       0x0
  211.         retlw       0x0
  212.         retlw       0x0
  213.         retlw       0x0
  214.         retlw       0x0
  215.         retlw       0x0
  216.         retlw       0x0
  217.  
  218.         retlw       0x0
  219.         retlw       0x35            ;Right ALT
  220.         retlw       0x0
  221.         retlw       0x0
  222.         goto    rctrl               ;Right CTL
  223.         retlw       0x0
  224.         retlw       0x0
  225.         retlw       0x0
  226.         retlw       0x0
  227.         retlw       0x0
  228.         retlw       0x0
  229.         retlw       0x0
  230.         retlw       0x0
  231.         retlw       0x0
  232.         retlw       0x0
  233.         retlw       0x33            ;Left Win=Left Amiga
  234.  
  235.         retlw       0x0
  236.         retlw       0x0
  237.         retlw       0x0
  238.         retlw       0x0
  239.         retlw       0x0
  240.         retlw       0x0
  241.         retlw       0x0
  242.         retlw       0x31            ;Right Win=Right Amiga
  243.         retlw       0x0
  244.         retlw       0x0
  245.         retlw       0x0
  246.         retlw       0x0
  247.         retlw       0x0
  248.         retlw       0x0
  249.         retlw       0x0
  250.         goto    swapscreen          ;Menu Key=L-Amiga M
  251.        
  252.         retlw       0x0
  253.         retlw       0x0
  254.         retlw       0x0
  255.         retlw       0x0
  256.         retlw       0x0
  257.         retlw       0x0
  258.         retlw       0x0
  259.         retlw       0x0
  260.         retlw       0x0
  261.         retlw       0x0
  262.         retlw       0x0
  263.         retlw       0x0
  264.         retlw       0x0
  265.         retlw       0x0
  266.         retlw       0x0
  267.         retlw       0x0
  268.  
  269.         retlw       0x0
  270.         retlw       0x0
  271.         retlw       0x0
  272.         retlw       0x0
  273.         retlw       0x0
  274.         retlw       0x0
  275.         retlw       0x0
  276.         retlw       0x0
  277.         retlw       0x0
  278.         retlw       0x0
  279.         retlw       0x8B            ;/key, supposedly
  280.         retlw       0x0
  281.         retlw       0x0
  282.         retlw       0x0
  283.         retlw       0x0
  284.         retlw       0x0
  285.  
  286.         retlw       0x0
  287.         retlw       0x0
  288.         retlw       0x0
  289.         retlw       0x0
  290.         retlw       0x0
  291.         retlw       0x0
  292.         retlw       0x0
  293.         retlw       0x0
  294.         retlw       0x0
  295.         retlw       0x0
  296.         retlw       0x79            ;Numeric Enter
  297.         retlw       0x0
  298.         retlw       0x0
  299.         retlw       0x0
  300.         retlw       0x0
  301.         retlw       0x0
  302.  
  303.         retlw       0x0
  304.         retlw       0x0
  305.         retlw       0x0
  306.         retlw       0x0
  307.         retlw       0x0
  308.         retlw       0x0
  309.         retlw       0x0
  310.         retlw       0x0
  311.         retlw       0x0
  312.         goto    endkey              ;End=Shift right-cursor  
  313.         retlw       0x0
  314.         retlw       0x61            ;Cursor Left
  315.         goto    home                ;Home=Shift left-cursor  
  316.         retlw       0x0
  317.         retlw       0x0
  318.         retlw       0x63            ;MACRO key=control
  319.  
  320.         goto    insert              ;Insert=Right Amiga 7
  321.         retlw       0x73            ;Delete
  322.         retlw       0x65            ;Cursor Down
  323.         retlw       0x0
  324.         retlw       0x63            ;Cursor Right
  325.         retlw       0x67            ;Cursor Up
  326.         retlw       0x0
  327.         retlw       0x0
  328.         retlw       0x0
  329.         retlw       0x0
  330.         goto    pagedown            ;Page Down=Shift down-cursor
  331.         retlw       0x0
  332.         goto    prtscreen           ;print screen=Right Amiga P
  333.         goto    pageup              ;Page up=Shift up-cursor
  334.         goto    break               ;Break=Ctrl-C
  335. ;        retlw       0x0
  336.  
  337.  
  338.  
  339. ; *** Left Control key ***
  340. lctrl
  341.         btfsc   win95,0x0
  342.         retlw   0x39                ; ctrl
  343.         retlw   0x33                ; left Amiga
  344.  
  345. ; *** Right Control key ***
  346. rctrl
  347.         btfsc   win95,0x0
  348.         retlw   0x39                ; ctrl
  349.         retlw   0x31                ; right Amiga
  350.        
  351.  
  352. ; *** Menu = Left Amiga-M ***
  353. swapscreen
  354.         movlw   0x33                ; Left Amiga pressed
  355.         call    actualtransmit
  356.         movlw   0x91                ; M pressed & released
  357.         call    sendmessage
  358.         movlw   0x32                ; Left Amiga released
  359.         call    actualtransmit
  360.         retlw   0x0          
  361.  
  362.  
  363. ; *** Prt Scrn Key = Right Amiga-P ***
  364. prtscreen
  365.         movlw   0x31                ; Right Amiga pressed
  366.         call    actualtransmit
  367.         movlw   0xCD                ; P pressed & released
  368.         call    sendmessage
  369.         movlw   0x30                ; Right Amiga released
  370.         call    actualtransmit
  371.         retlw   0x0          
  372.  
  373.  
  374.  
  375. ; *** End Key = Shift right-cursor ***
  376. endkey
  377.         movlw   0x3D                ; Right shift pressed
  378.         call    actualtransmit
  379.         movlw   0x63                ; right-cursor pressed & released
  380.         call    sendmessage
  381.         movlw   0x3C                ; Right shift released
  382.         call    actualtransmit
  383.         retlw   0x0          
  384.  
  385.  
  386.  
  387. ; *** Home Key = Shift left-cursor ***
  388. home
  389.         movlw   0x3D                ; Right shift pressed
  390.         call    actualtransmit
  391.         movlw   0x61                ; left-cursor pressed & released
  392.         call    sendmessage
  393.         movlw   0x3C                ; Right shift released
  394.         call    actualtransmit
  395.         retlw   0x0          
  396.  
  397.  
  398.  
  399. ; *** PageDown Key = Shift down-cursor ***
  400. pagedown
  401.         movlw   0x3D                ; Right shift pressed
  402.         call    actualtransmit
  403.         movlw   0x65                ; down-cursor pressed & released
  404.         call    sendmessage
  405.         movlw   0x3C                ; Right shift released
  406.         call    actualtransmit
  407.         retlw   0x0          
  408.  
  409.  
  410.  
  411. ; *** Pageup Key = Shift up-cursor ***
  412. pageup
  413.         movlw   0x3D                ; Right shift pressed
  414.         call    actualtransmit
  415.         movlw   0x67                ; up-cursor pressed & released
  416.         call    sendmessage
  417.         movlw   0x3C                ; Right shift released
  418.         call    actualtransmit
  419.         retlw   0x0          
  420.  
  421.  
  422.  
  423. ; *** Insert Key = Right Amiga 7 ***
  424. insert
  425.         movlw   0x31                ; Right Amiga pressed
  426.         call    actualtransmit
  427.         movlw   0xF1                ; 7 pressed & released
  428.         call    sendmessage
  429.         movlw   0x30                ; Right Amiga released
  430.         call    actualtransmit
  431.         retlw   0x0          
  432.  
  433.  
  434.  
  435. ; *** Break Key = Ctrl-C ***
  436. break
  437.         movlw   0x39                ; Ctrl pressed
  438.         call    actualtransmit
  439.         movlw   0x99                ; C pressed & released
  440.         call    sendmessage
  441.         movlw   0x38                ; Ctrl released
  442.         call    actualtransmit
  443.         retlw   0x0          
  444.  
  445.  
  446.  
  447. ; *** Wait a long time ***
  448. longdelay
  449.         movwf   Count1
  450. dly
  451.         call    fixeddelay
  452.         decfsz  Count1,F
  453.         goto    dly
  454.         return
  455. ;
  456. ; *** Wait a short while ***
  457. fixeddelay
  458.         movlw   0xFF
  459. smalldelay
  460.         movwf   Count2
  461. delay
  462.         decfsz  Count2,F
  463.         goto    delay
  464.         return
  465.  
  466.  
  467.  
  468.  
  469. ; *** Send character to Amiga and wait for handshake ***
  470. amigatransmit
  471.         movwf   Amigachar
  472.         subwf   Oldchar,W
  473.         btfsc   STATUS,Z            ; skip if not equal
  474.         return                      ; ignore it
  475.        
  476.         movlw   0x33                ; LAmiga pressed
  477.         subwf   Amigachar,W
  478.         btfsc   STATUS,Z            ; skip if not equal
  479.         bcf     RESET,LAmigabit
  480.         movlw   0x32                ; LAmiga released
  481.         subwf   Amigachar,W
  482.         btfsc   STATUS,Z            ; skip if not equal
  483.         bsf     RESET,LAmigabit
  484.                
  485.         movlw   0x31                ; RAmiga pressed
  486.         subwf   Amigachar,W
  487.         btfsc   STATUS,Z            ; skip if not equal
  488.         bcf     RESET,RAmigabit
  489.         movlw   0x30                ; RAmiga released
  490.         subwf   Amigachar,W
  491.         btfsc   STATUS,Z            ; skip if not equal
  492.         bsf     RESET,RAmigabit
  493.                
  494.         movlw   0x3B                ; jump if not Capslock down
  495.         subwf   Amigachar,W
  496.         btfss   STATUS,Z            ; skip if equal
  497.         goto    transok2            ; ignore it
  498.         bcf     RESET,Ctrlbit
  499.         movf    Amigachar,W
  500.         movwf   Oldchar
  501.         movlw   0xFF
  502.         movwf   Capdown             ; set flags for later
  503.         return
  504. transok2
  505.         movlw   0x3A                ; jump if not Capslock up
  506.         subwf   Amigachar,W
  507.         btfss   STATUS,Z            ; skip if equal
  508.         goto    transok3            ; ignore it
  509.  
  510.         bsf     RESET,Ctrlbit
  511.         movlw   0x3B                ; see if Capslock was just down
  512.         subwf   Oldchar,W           ;
  513.         btfss   STATUS,Z            ; skip if equal
  514.         goto    transok4            ; use as Ctrl key
  515.         clrf    Capdown             ; clear flag
  516.         comf    Capbit,F            ; toggle down/upness of caplock
  517.         movlw   0x3B                ; send Capslock down
  518.         btfss   Capbit,0x0
  519.         andlw   0xFE
  520.         call    actualtransmit
  521. ; send lights to AT
  522.         movlw   0xED                ; Next data is for lights
  523.         call    SendtoAT
  524.         bsf     Lights,CapsLock     ; Capslock on
  525.         btfss   Capbit,0x0
  526.         bcf     Lights,CapsLock     ; Capslock off
  527.         movf    Lights,W
  528.         call    SendtoAT
  529.         return
  530. transok4
  531.         btfsc   win95,0x0
  532.         return
  533.         clrf    CtrlDown
  534.         clrf    Capdown             ; Capslock has finished acting as ctrl
  535.         movlw   0x38                ; send Ctrl up
  536.         call    actualtransmit
  537.         return
  538. transok3
  539.         movf    Amigachar,W
  540.         movwf   Savechar2
  541.         movwf   Oldchar
  542.         movf    Capdown,F           ; Capslock down?
  543.         btfsc   STATUS,Z            ; skip if non-zero i.e caps pressed
  544.         goto    nocontrol           ; ignore it
  545.         btfsc   win95,0x0
  546.         goto    nocontrol           ; ignore it
  547.         movf    CtrlDown,F
  548.         btfss   STATUS,Z            ; skip if zero i.e caps pressed
  549.         goto    nocontrol           ; ignore it
  550.         movlw   0xFF
  551.         movwf   CtrlDown            ; Caps lock is now Ctrl key
  552.         movlw   0x39                ; send Ctrl down
  553.         call    actualtransmit
  554.         movf    Savechar2,W
  555.         goto    actualtransmit
  556. nocontrol
  557.         movf    Amigachar,W
  558.         andlw   0xFE
  559.         sublw   0x44                ; * (Numkey) released
  560.         btfss   STATUS,Z            ; skip if equal
  561.         clrf    AltConfig
  562.         incf    AltConfig,F
  563.  
  564.         movlw   0x28                ; 20 th time?
  565.         subwf   AltConfig,W
  566.         btfsc   STATUS,Z            ; skip if not equal
  567.         call    settings
  568.  
  569.  
  570.         movf    Amigachar,W
  571.  
  572. actualtransmit
  573.         movwf   Amigachar
  574.  
  575.         movlw   .5           ; do a 5x256 delay
  576.         call    longdelay
  577. actual2
  578.         movlw   .8
  579.         movwf   Count1
  580.         clrf    Charbad
  581. f
  582.         btfsc   Amigachar,0x7       ; IF bit7=1 THEN Adat=1
  583.         bsf     PORTA,Adat
  584.         btfss   Amigachar,0x7       ; IF bit7=0 THEN Adat=0
  585.         bcf     PORTA,Adat
  586.         movlw   .8
  587.         call    smalldelay          ; Allow Adat logic to settle
  588.         bcf     PORTA,Aclk          ; transmit
  589.         movlw   .8
  590.         call    smalldelay          ; Allow Aclk logic to settle
  591.         bsf     PORTA,Aclk          ; reset Aclk=1
  592.         movlw   .10
  593.         call    smalldelay          ; Allow Aclk logic to settle
  594.         rlf     Amigachar,F
  595.         decfsz  Count1,F            ; Transmit next bit?
  596.         goto    f
  597.  
  598.         movlw   0xF
  599.         movwf   Count1
  600.         movlw   0xFF
  601.         movwf   Count1
  602.         movwf   Count2
  603.  
  604.         PAGE1          
  605.         bsf     TRISA,Adat          ; Read acknowledge signal
  606.         PAGE0          
  607. ack
  608.         decf    Count1,F
  609.         btfsc   STATUS,Z
  610.         decf    Count2,F
  611.         movf    Count2,W            ; Count2=0?
  612.         btfsc   STATUS,Z
  613.         goto    syncup              ; no handshake
  614.         btfsc   PORTA,Adat         ; wait for handshake from amiga
  615.         goto    ack
  616. ready
  617.         btfss   PORTA,Adat          ; wait for handshake to finish
  618.         goto    ready
  619.  
  620.         bsf     PORTA,Adat          ; reset Adat=1
  621.         PAGE1          
  622.         bcf     TRISA,Adat          ; Return to output mode
  623.         PAGE0          
  624.         return
  625. syncup
  626.         bcf     PORTA,Aclk          ; send another clock pulse
  627.         movlw   .8
  628.         call    smalldelay          ; Allow Aclk logic to settle
  629.         bsf     PORTA,Aclk          ; reset Aclk=1
  630.         movlw   0xFF
  631.         movwf   Count1
  632.         movwf   Count2
  633.         decf    Count3,F
  634.         btfsc   STATUS,Z
  635.         return
  636.         goto    ack                 ; wait for acknowledge again
  637.  
  638.  
  639.  
  640. ; *** Send character to AT keyboard and wait for handshake ***
  641. SendtoAT
  642.         movwf   Charbad
  643. resend
  644.         movf    Charbad,W
  645.         movwf   ATchar
  646.         clrf    ATparity
  647.         bsf     PORTB,Kclk          ; Kclk=1 get keyboards attention
  648.         nop
  649.         bcf     PORTB,Kdat          ; Kdat=0 get keyboards attention
  650.         PAGE1          
  651.         bcf     TRISB,Kclk          ; Kclk is in output mode
  652.         nop
  653.         bcf     TRISB,Kdat          ; Kdat is in output mode
  654.         PAGE0          
  655.         movlw   .8
  656.         movwf   Count1
  657.         PAGE1          
  658.         bsf     TRISB,Kclk          ; Kclk is in input mode
  659.         PAGE0          
  660. Send4   btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  661.         goto    Send4
  662.         btfsc   ATchar,0x0          ; IF bit0=1 THEN Kdat=1
  663.         bsf     PORTB,Kdat
  664.         btfss   ATchar,0x0          ; IF bit0=0 THEN Kdat=0
  665.         bcf     PORTB,Kdat
  666.         rrf     ATchar,F            ; next bit
  667.         btfsc   STATUS,C            ; test parity of bit shifted out
  668.         incf    ATparity,F
  669. Send5   btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  670.         goto    Send5                
  671.         decfsz  Count1,F
  672.         goto    Send4
  673. Send6   btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  674.         goto    Send6
  675.         btfsc   ATparity,0x0        ; IF bit0=odd THEN Kdat=0 (odd parity)
  676.         bcf     PORTB,Kdat
  677.         btfss   ATparity,0x0        ; IF bit0=even THEN Kdat=1 (odd parity)
  678.         bsf     PORTB,Kdat
  679. Send7   btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  680.         goto    Send7
  681. Send77  btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  682.         goto    Send77
  683.         bsf     PORTB,Kdat          ; stop bit
  684. Send78  btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  685.         goto    Send78
  686.         PAGE1          
  687.         bsf     TRISB,Kdat          ; reset Kdat back to input mode
  688.         PAGE0          
  689. Send79  btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  690.         goto    Send79
  691. Send7a  btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  692.         goto    Send7a
  693.         movlw   .8
  694.         call    smalldelay          ; Allow Kclk logic to settle
  695.         bcf     PORTB,Kclk          ; Kclk=0 Send handshake
  696.         PAGE1          
  697.         bcf     TRISB,Kclk          ; Kclk is in output mode
  698.         PAGE0          
  699.         movlw   .20
  700.         call    smalldelay          ; Allow keyboard chance
  701.         call    ATgetkey
  702.         movlw   0xFA                ; Was transmission ok
  703.         subwf   ATchar,W
  704.         btfss   STATUS,Z            ; skip if good
  705.         goto    resend
  706.         return
  707.        
  708.  
  709.  
  710.  
  711. ; *** Waits for keyboard to send code ***
  712. ATgetkey
  713.         clrf    ATchar
  714.         bsf     PORTB,Kclk          ; Kclk=1 Allow keyboard to talk
  715.         PAGE1
  716.         bsf     TRISB,Kclk          ; Kclk is in input mode
  717.         PAGE0
  718. skip1st btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  719.         goto    skip1st
  720. skippy  btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  721.         goto    skippy
  722.         movlw   .8
  723.         movwf   Count1
  724. ATwait0
  725.         btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  726.         goto    ATwait0
  727.         rrf     ATchar,F
  728.         btfsc   PORTB,Kdat
  729.         bsf     ATchar,0x7
  730.         btfss   PORTB,Kdat
  731.         bcf     ATchar,0x7
  732. ATwait1 btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  733.         goto    ATwait1
  734.         decfsz  Count1,F
  735.         goto    ATwait0             ; get all 8 bits of data
  736. parity0 btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  737.         goto    parity0
  738. parity1 btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  739.         goto    parity1
  740. stop0   btfsc   PORTB,Kclk          ; wait for keyboard to make Kclk=0
  741.         goto    stop0
  742. stop1   btfss   PORTB,Kclk          ; wait for keyboard to make Kclk=1
  743.         goto    stop1
  744.         bcf     PORTB,Kclk          ; Kclk=0 Send handshake
  745.         PAGE1
  746.         bcf     TRISB,Kclk          ; Kclk is in output mode
  747.         PAGE0
  748.         movlw   .20
  749.         call    smalldelay          ; Allow keyboard chance to recieve
  750.         return
  751.  
  752.  
  753.  
  754.  
  755.  
  756. ; *** Flash Light ***
  757. flash
  758.         movwf   Lights
  759.         movlw   0xED                ; Next data is for lights
  760.         call    SendtoAT
  761.         movf    Lights,W            ; Flash lights
  762.         call    SendtoAT
  763.         movlw   0x25
  764.         call    longdelay    
  765.         movlw   0xED                ; Next data is for lights
  766.         call    SendtoAT
  767.         movlw   0x0                 ; Clear Lights
  768.         call    SendtoAT
  769.         movlw   0x25
  770.         call    longdelay    
  771.         return
  772.  
  773.  
  774.  
  775. ; *** Performs reset on Amiga ***
  776. reset
  777.         movlw   Resetype
  778.         call    readdata
  779.         sublw   0x1                
  780.         btfsc   STATUS,Z            ; skip if not equal
  781.         goto    kill                ; jump if fast reset
  782.         movlw   0x0F                ; Tell amiga we are going to reset it
  783.         call    actualtransmit
  784.  
  785.         movlw   0x8
  786.         movwf   Count3
  787. strobe  movlw   0x1
  788.         call    flash
  789.         movlw   0x2
  790.         call    flash
  791.         movlw   0x4
  792.         call    flash
  793.         decfsz  Count3,F
  794.         goto    strobe
  795. kill
  796.         movlw   0x70
  797.         call    longdelay    
  798.         bcf     PORTB,Arst          ; Arst=0 Send reset
  799.         PAGE1
  800.         bcf     TRISB,Arst          ; Arst is in output mode
  801.         PAGE0
  802.         movlw   0xFF
  803.         call    longdelay           ; Wait for Amiga to reset
  804.         goto    start2
  805.  
  806.  
  807.  
  808.  
  809. start
  810.  
  811. ; *** Allow time for HardDrive to spin upto speed ***
  812. SpinUp
  813.         bcf     PORTB,Arst          ; Arst=0 Send reset
  814.         PAGE1
  815.         bcf     TRISB,Arst          ; Arst is in output mode
  816.         PAGE0
  817.         movlw   0x30
  818.         movwf   Count3
  819. waitHD
  820.         movlw   0xFF
  821.         call    longdelay           ; Wait for drive to wake up
  822.         decfsz  Count3,F
  823.         goto    waitHD
  824.  
  825. start2
  826. ; *** Setup ports ***
  827.         bsf     PORTA,Aclk          ; transmit
  828.         nop
  829.         bsf     PORTA,Adat
  830.         PAGE1          
  831.         movlw   0x7
  832.         movwf   TRISA
  833.         movlw   0xFF
  834.         movwf   TRISB
  835.         PAGE0          
  836.  
  837.  
  838. ; *** Clear out miscellaneous flags ***
  839.         clrf    Capdown
  840.         clrf    CtrlDown
  841.         clrf    Capbit
  842.         clrf    Oldchar
  843.         clrf    AltConfig
  844.         movlw   0x7
  845.         movwf   RESET
  846.  
  847. ; *** See what sort of keyboard is attached ***
  848.         clrf    win95
  849.         movlw   Keytype
  850.         call    readdata
  851.         sublw   0x2                
  852.         btfsc   STATUS,Z            ; skip if not equal
  853.         comf    win95               ; win95=true or false
  854.  
  855. ; *** Wait for AT keyboard to power up ***
  856. waitAT
  857.         btfss   PORTB,Kdat         ; wait for AT keyboard
  858.         goto    waitAT
  859.        
  860. ; *** Reset AT keyboard ***
  861. ;        movlw   0xFF            ; Reset
  862. ;        call    SendtoAT
  863.         movlw   0xF6            ; Default
  864.         call    SendtoAT
  865.         movlw   0x7
  866.         call    flash
  867.         movlw   0xED            ; Next data is for lights
  868.         call    SendtoAT
  869.         movlw   0x2
  870.         movwf   Lights
  871.         call    SendtoAT
  872.         movlw   0xF4            ; Clear buffer
  873.         call    SendtoAT
  874.  
  875.  
  876. ATstyle
  877.         movf    RESET,F
  878.         btfsc   STATUS,Z
  879.         goto    reset
  880.         call    ATgetkey
  881.         movlw   0xE1
  882.         subwf   ATchar,W
  883.         btfss   STATUS,Z            ; skip if equal
  884.         goto    ATnE1        
  885.         call    ATgetkey            ; should be $14
  886.         call    ATgetkey            ; should be $77
  887.         call    ATgetkey            ; should be $E1
  888.         call    ATgetkey            ; should be $F0
  889.         call    ATgetkey            ; should be $14
  890.         call    ATgetkey            ; should be $F0
  891.         call    ATgetkey            ; should be $77
  892.         goto    ATstyle
  893. ATnE1
  894.         clrf    tableoffset
  895.         movlw   0xE0
  896.         subwf   ATchar,W
  897.         btfss   STATUS,Z            ; skip if equal
  898.         goto    ATnE0        
  899.         movlw   0x80
  900.         movwf   tableoffset
  901.         call    ATgetkey
  902.         movlw   0xF0
  903.         subwf   ATchar,W
  904.         btfss   STATUS,Z            ; skip if equal
  905.         goto    ATnE0F0        
  906.         call    ATgetkey
  907.         movlw   0x12
  908.         subwf   ATchar,W
  909.         btfsc   STATUS,Z            ; skip if not equal
  910.         goto    ATstyle             ; E0F012 ignore it
  911. ATnEF12
  912.         movlw   0x59
  913.         subwf   ATchar,W
  914.         btfss   STATUS,Z            ; skip if equal
  915.         goto    ATup        
  916.         goto    ATstyle             ; E0F059 ignore it
  917. ATnE0F0
  918.         movlw   0x12
  919.         subwf   ATchar,W
  920.         btfsc   STATUS,Z            ; skip if not equal
  921.         goto    ATstyle             ; E012 ignore it
  922. ATnE012
  923.         movlw   0x59
  924.         subwf   ATchar,W
  925.         btfss   STATUS,Z            ; skip if equal
  926.         goto    ATdown        
  927.         goto    ATstyle             ; E059 ignore it
  928. ATnE0
  929.         movlw   0xF0
  930.         subwf   ATchar,W
  931.         btfss   STATUS,Z            ; skip if equal
  932.         goto    ATdown        
  933.         call    ATgetkey
  934.         goto    ATup                ; F0= key released
  935. ATdown        
  936.         incf    ATchar,W
  937.         addwf   tableoffset,W
  938.         call    ATtb1
  939.         addlw   0x0                 ; test W
  940.         btfss   STATUS,Z
  941.         call    amigatransmit
  942.         goto    ATstyle
  943. ATup        
  944.         incf    ATchar,W
  945.         addwf   tableoffset,W
  946.         movwf   tableoffset
  947.  
  948.         movlw   0xAF+1              ; menu key
  949.         subwf   tableoffset,W
  950.         btfsc   STATUS,Z            ; skip if not equal
  951.         goto    ATstyle             ; ignore it
  952.  
  953.         movlw   0x84+1              ; PrtScrn
  954.         subwf   tableoffset,W
  955.         btfsc   STATUS,Z            ; skip if not equal
  956.         goto    ATstyle             ; ignore it
  957.  
  958.         movlw   0xE9+1              ; End
  959.         subwf   tableoffset,W
  960.         btfsc   STATUS,Z            ; skip if not equal
  961.         goto    ATstyle             ; ignore it
  962.  
  963.         movlw   0xEC+1              ; Home
  964.         subwf   tableoffset,W
  965.         btfsc   STATUS,Z            ; skip if not equal
  966.         goto    ATstyle             ; ignore it
  967.  
  968.         movlw   0xF0+1              ; Insert
  969.         subwf   tableoffset,W
  970.         btfsc   STATUS,Z            ; skip if not equal
  971.         goto    ATstyle             ; ignore it
  972.  
  973.         movlw   0xFA+1              ; PageDown
  974.         subwf   tableoffset,W
  975.         btfsc   STATUS,Z            ; skip if not equal
  976.         goto    ATstyle             ; ignore it
  977.  
  978.         movlw   0xFC+1              ; PrtScrn
  979.         subwf   tableoffset,W
  980.         btfsc   STATUS,Z            ; skip if not equal
  981.         goto    ATstyle             ; ignore it
  982.  
  983.         movlw   0xFD+1              ; PageUp
  984.         subwf   tableoffset,W
  985.         btfsc   STATUS,Z            ; skip if not equal
  986.         goto    ATstyle             ; ignore it
  987.  
  988.         movlw   0xFE+1              ; Break
  989.         subwf   tableoffset,W
  990.         btfsc   STATUS,Z            ; skip if not equal
  991.         goto    ATstyle             ; ignore it
  992.  
  993.         movf    tableoffset,W
  994.         call    ATtb1
  995.         andlw   0xFE                ; clear bit 0
  996.         call    amigatransmit
  997.         goto    ATstyle
  998.        
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012. ; *** Change configuration ***
  1013. settings
  1014.         clrf    eeaddress
  1015.         movlw   0x3B                ; CAPSLOCK ON
  1016.         call    actualtransmit
  1017.        
  1018.         call    say_select          ; Select Type of
  1019.         call    say_key             ; key
  1020.         movlw   0x95                ; b
  1021.         call    sendmessage
  1022.         movlw   0xCF                ; o
  1023.         call    sendmessage
  1024.         movlw   0xBF                ; a
  1025.         call    sendmessage
  1026.         movlw   0xD9                ; r
  1027.         call    sendmessage
  1028.         movlw   0xBB                ; d
  1029.         call    sendmessage
  1030.         call    say_option1         ; 1=
  1031.         call    say_uk10            ; uk 10
  1032.         movlw   0xFB                ; 2
  1033.         call    sendmessage
  1034.         movlw   0x7F                ; space
  1035.         call    sendmessage
  1036.         call    say_key             ; key
  1037.         call    say_option2         ; 2=
  1038.         call    say_uk10            ; uk 10
  1039.         movlw   0xF5                ; 5
  1040.         call    sendmessage
  1041.         movlw   0x7F                ; space
  1042.         call    sendmessage
  1043.         call    say_key             ; key
  1044.         movlw   0x7F                ; space
  1045.         call    sendmessage
  1046.         movlw   0xDD                ; w
  1047.         call    sendmessage
  1048.         movlw   0xD1                ; i
  1049.         call    sendmessage
  1050.         movlw   0x93                ; n
  1051.         call    sendmessage
  1052.         movlw   0xED                ; 9
  1053.         call    sendmessage
  1054.         movlw   0xF5                ; 5
  1055.         call    sendmessage
  1056.         movlw   0x77                ; return
  1057.         call    sendmessage
  1058.         call    getselection
  1059.         movwf   eedata
  1060.         movf    eedata,W
  1061.         btfsc   STATUS,Z            ; skip if not zero
  1062.         goto    settings              ; bad choice, try again
  1063.         call    writedata        
  1064.         call    say_ok
  1065.         clrf    win95
  1066.         movlw   Keytype
  1067.         call    readdata
  1068.         sublw   0x2                
  1069.         btfsc   STATUS,Z            ; skip if not equal
  1070.         comf    win95               ; win95=true or false
  1071.  
  1072.         incf    eeaddress
  1073. askreset
  1074.         call    say_select          ; Select Type of
  1075.         call    say_reset           ; reset
  1076.         call    say_option1         ; 1=
  1077.         movlw   0xB9                ; f
  1078.         call    sendmessage
  1079.         movlw   0xBF                ; a
  1080.         call    sendmessage
  1081.         movlw   0xBD                ; s
  1082.         call    sendmessage
  1083.         movlw   0xD7                ; t
  1084.         call    sendmessage
  1085.         movlw   0x7F                ; space
  1086.         call    sendmessage
  1087.         call    say_reset           ; reset
  1088.         call    say_option2         ; 2=
  1089.         movlw   0xBD                ; s
  1090.         call    sendmessage
  1091.         movlw   0xAF                ; l
  1092.         call    sendmessage
  1093.         movlw   0xCF                ; o
  1094.         call    sendmessage
  1095.         movlw   0xDD                ; w
  1096.         call    sendmessage
  1097.         movlw   0x7F                ; space
  1098.         call    sendmessage
  1099.         call    say_reset           ; reset
  1100.         movlw   0x77                ; return
  1101.         call    sendmessage
  1102.  
  1103.         call    getselection
  1104.         movwf   eedata
  1105.         movf    eedata,W
  1106.         btfsc   STATUS,Z            ; skip if not zero
  1107.         goto    askreset            ; bad choice, try again
  1108.         call    writedata        
  1109.         call    say_ok
  1110.  
  1111.         clrf    AltConfig
  1112.         movlw   0x7E                ; space up
  1113.         movf    Capdown,F           ; Capslock down?
  1114.         btfsc   STATUS,Z            ; skip if non-zero i.e caps pressed
  1115.         movlw   0x3A                ; Caps up
  1116.         movwf   Amigachar
  1117.         return
  1118.        
  1119. say_select
  1120.         movlw   0x77                ; return x2
  1121.         call    sendmessage
  1122.         call    sendmessage
  1123.         movlw   0xBD                ; s
  1124.         call    sendmessage
  1125.         movlw   0xDB                ; e
  1126.         call    sendmessage
  1127.         movlw   0xAF                ; l
  1128.         call    sendmessage
  1129.         movlw   0xDB                ; e
  1130.         call    sendmessage
  1131.         movlw   0x99                ; c
  1132.         call    sendmessage
  1133.         movlw   0xD7                ; t
  1134.         call    sendmessage
  1135.         movlw   0x7F                ; space
  1136.         call    sendmessage
  1137.         movlw   0xD7                ; t
  1138.         call    sendmessage
  1139.         movlw   0xD5                ; y
  1140.         call    sendmessage
  1141.         movlw   0xCD                ; p
  1142.         call    sendmessage
  1143.         movlw   0xDB                ; e
  1144.         call    sendmessage
  1145.         movlw   0x7F                ; space
  1146.         call    sendmessage
  1147.         movlw   0xCF                ; o
  1148.         call    sendmessage
  1149.         movlw   0xB9                ; f
  1150.         call    sendmessage
  1151.         movlw   0x7F                ; space
  1152.         call    sendmessage
  1153.         return
  1154.  
  1155. say_key
  1156.         movlw   0xB1                ; k
  1157.         call    sendmessage
  1158.         movlw   0xDB                ; e
  1159.         call    sendmessage
  1160.         movlw   0xD5                ; y
  1161.         call    sendmessage
  1162.         return
  1163.  
  1164. say_option1
  1165.        movlw   0x77                ; return x2
  1166.         call    sendmessage
  1167.         call    sendmessage
  1168.         movlw   0xFD                ; 1
  1169.         call    sendmessage
  1170.         movlw   0xE7                ; =
  1171.         call    sendmessage
  1172.         movlw   0x7F                ; space
  1173.         call    sendmessage
  1174.         return
  1175.  
  1176. say_option2
  1177.         movlw   0x77                ; return
  1178.         call    sendmessage
  1179.         movlw   0xFB                ; 2
  1180.         call    sendmessage
  1181.         movlw   0xE7                ; =
  1182.         call    sendmessage
  1183.         movlw   0x7F                ; space
  1184.         call    sendmessage
  1185.         return
  1186.  
  1187. say_uk10
  1188.         movlw   0xD3                ; u
  1189.         call    sendmessage
  1190.         movlw   0xB1                ; k
  1191.         call    sendmessage
  1192.         movlw   0x7F                ; space
  1193.         call    sendmessage
  1194.         movlw   0xFD                ; 1
  1195.         call    sendmessage
  1196.         movlw   0xEB                ; 0
  1197.         call    sendmessage
  1198.         return
  1199.  
  1200. say_ok
  1201.         movlw   0xCF                ; o
  1202.         call    sendmessage
  1203.         movlw   0xB1                ; k
  1204.         call    sendmessage
  1205.         movlw   0x77                ; return
  1206.         call    sendmessage
  1207.         return
  1208.  
  1209. say_reset
  1210.         movlw   0xD9                ; r
  1211.         call    sendmessage
  1212.         movlw   0xDB                ; e
  1213.         call    sendmessage
  1214.         movlw   0xBD                ; s
  1215.         call    sendmessage
  1216.         movlw   0xDB                ; e
  1217.         call    sendmessage
  1218.         movlw   0xD7                ; t
  1219.         call    sendmessage
  1220.         return
  1221.  
  1222.  
  1223. sendmessage
  1224.         movwf   Savechar
  1225.         call    actualtransmit
  1226.         movf    Savechar,W
  1227.         andlw   0xFE
  1228.         call    actualtransmit
  1229.         movf    Savechar,W
  1230.         return        
  1231.  
  1232. getselection
  1233.         call    ATgetkey
  1234.         call    ATgetkey
  1235.         call    ATgetkey
  1236.         movlw   0x16                ; was key 1 pressed and released
  1237.         subwf   ATchar,W
  1238.         btfsc   STATUS,Z            ; skip if not equal
  1239.         retlw   0x1    
  1240.         movlw   0x1E                ; was key 2 pressed and released
  1241.         subwf   ATchar,W
  1242.         btfsc   STATUS,Z            ; skip if not equal
  1243.         retlw   0x2        
  1244.         retlw   0x0
  1245.  
  1246. writedata
  1247.         movf    eeaddress,W
  1248.         movwf   EEADR
  1249.         movf    eedata,W
  1250.         movwf   EEDATA
  1251.         PAGE1
  1252.         bsf     EECON1,WREN         ; EEPROM write enable
  1253.         movlw   0x55
  1254.         movwf   EECON2
  1255.         movlw   0xAA
  1256.         movwf   EECON2
  1257.         bsf     EECON1,WR
  1258. wait_write
  1259.         btfss   EECON1,EEIF         ; wait for write to finish
  1260.         goto    wait_write
  1261.         clrf    EECON1              ; EEPROM write disable & int accept
  1262.         PAGE0
  1263.         return
  1264.  
  1265.  
  1266. readdata
  1267.         movwf   EEADR
  1268.         PAGE1
  1269.         bsf     EECON1,RD           ; EEPROM read
  1270.         PAGE0
  1271.         movf    EEDATA,W
  1272.         return
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement