home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaDemoCD2.iso / ASCII / TEXTE / SCENE / AMIGA / Useful-Amiga / HardwareHacking / KEYWIN95.LHA / ATkeyboard / keyb.asm < prev    next >
Encoding:
Assembly Source File  |  1996-12-31  |  18.0 KB  |  923 lines

  1.     list    p=16c84, r=dec,    n=0
  2.  
  3. cmd_option    equ    0xed
  4. cmd_typematic    equ    0xf3
  5. cmd_default    equ    0xf6
  6. cmd_resend    equ    0xfe
  7. cmd_reset    equ    0xff
  8. rst_warn    equ    0x78
  9. pwr_up        equ    0xfd    ;power up key stream
  10. t_pwr_up    equ    0xfe    ;terminate key stream
  11. no_send        equ    -1    ;do not send to amiga
  12.  
  13.     cblock    1
  14.     tmr0        ;timer
  15.     pc        ;lsb pc
  16.     status
  17.     fsr
  18.     pa        ;port a
  19.     pb        ;port b
  20.     dummy
  21.     eedata
  22.     eeadr
  23.     pclath        ;msb pc latch
  24.     intcon        ;interrupt control reg.
  25.     int_addr    ;interrupt routine addr. 
  26.     trans_addr    ;trans. routine addr. 
  27.     _byte        ;byte to receive/transmit
  28.     save_byte    ;resend byte
  29.     ami_byte    ;byte to transmit -> amiga
  30.     _temp        ;rotation temp storage
  31.     bit_cnt        ;bit counter
  32.     cnt_dwn        ;count down reg.
  33.     parity
  34.     at_s_ret    ;"at realsend routine" return addr.
  35.     x_flag        ;"xtra flag" reg.
  36.     leds        ;at-keyboard leds
  37.     l_byte        ;last received byte
  38.     e0_l_byte    ;last received 0xe0 byte
  39.     tmr_ret        ;timer return addr.
  40.     tmr_ret_pch    ;timer return pc high latch
  41.     tmr_addr    ;delay wait routine addr.
  42.     tmr_pch        ;delay wait routine pc high latch
  43.     tmr_cntdwn    ;0xff cycles in wdt lookalike routine
  44.     tmr_ms        ;remaining cycles in wdt lookalike routine
  45.     endc
  46.  
  47. #define    carry        status,0
  48. #define    zero        status,2
  49. #define    rp0        status,5    ;page select
  50. #define    rd        eecon1,0    ;read eeprom
  51. #define    wr        eecon1,1    ;write eeprom
  52. #define    wren        eecon1,2    ;write eeprom enable
  53. #define    eeif        eecon1,4    ;eeprom write int
  54. #define    rbif        intcon,0    ;pb change int. flag
  55. #define    intf        intcon,1    ;pb,0 int. flag
  56. #define    t0if        intcon,2    ;tmr0 int. flag
  57. #define    rbie        intcon,3
  58. #define    inte        intcon,4
  59. #define    t0ie        intcon,5
  60. #define    eeie        intcon,6
  61. #define    gie        intcon,7    ;global interrupt enable
  62. #define    pch_0        pclath,0
  63. #define    pch_1        pclath,1
  64.  
  65. #define    at_clk_in    pb,0
  66. #define    at_clk_out    pb,1
  67. #define    ami_type    pb,3        ;resetmode switch
  68. #define    at_dat_in    pb,6
  69. #define    at_dat_out    pb,7
  70. #define    ami_dat_out    pa,0
  71. #define    ami_dat_in    pa,1
  72. #define    _kbreset    pa,3
  73. #define    ami_clk        pa,4        ;open drain
  74. #define    par_chk        _byte,7        ;parity check bit
  75. #define    _break        ami_byte,7    ;break bit
  76. #define    c_lock        leds,2        ;caps lock on/off
  77. #define    p_res        x_flag,0    ;pause pressed twice chk
  78. #define    rw_ctrl        x_flag,1    ;reset warning chk bits
  79. #define    rw_lalt        x_flag,2
  80. #define    rw_ralt        x_flag,3
  81. #define    rwarn        x_flag,4    ;reset warning main flag
  82. #define    tmr_tst        x_flag,5    ;longdelay test bit
  83. #define    s_break        x_flag,6    ;"special mission keys" break flag
  84. #define    sync_cd        x_flag,7    ;sync countdown checkbit
  85.  
  86.     org    0        ;reset vector
  87.     movlw    0xff        ;init ports
  88.     movwf    pb
  89.     movwf    pa
  90.     goto    init
  91.  
  92.     org    4        ;interrupt vector
  93.     btfsc    intf        ;pb,0
  94.     goto    at_clk
  95. ;---------------------------------------------------
  96.     bcf    t0if        ;watch dog timer lookalike routine
  97.     decfsz    tmr_cntdwn
  98.     retfie            ;65536us @ 4MHz
  99.  
  100.     btfsc    tmr_tst
  101.     goto    tmr_end
  102.  
  103.     incf    tmr_cntdwn
  104.     bsf    tmr_tst
  105.     movf    tmr_ms,w
  106.     movwf    tmr0
  107.     movf    tmr_pch,w
  108.     movwf    pclath
  109.     movf    tmr_addr,w
  110.     retfie
  111.  
  112. tmr_end    movlw    b'10001111'
  113.     option
  114.     movf    tmr_ret_pch,w
  115.     movwf    pclath
  116.     movf    tmr_ret,w
  117.     return
  118.  
  119. tmr_init
  120.     movwf    tmr_addr    ;save wait routine addr.
  121.     bcf    tmr_tst
  122.     movlw    b'10000111'    ;assign presc. to tmr0, presc. 256
  123.     option
  124.     clrf    tmr0
  125.     movlw    b'10100000'    ;gie,t0ie =enable
  126.     movwf    intcon
  127.     movf    tmr_pch,w
  128.     movwf    pclath
  129.     movf    tmr_addr,w
  130.     return
  131. ;---------------------------------------------------
  132. at_clk    bcf    intf
  133.     movf    int_addr,w    ;get correct int. routine
  134.     movwf    pc
  135. ;---------------------------------------------------
  136. wait    movwf    pc
  137.  
  138. ;========-at get key-===============================
  139. at_get_key
  140.     movlw    at_g0
  141.     movwf    int_addr
  142.     movlw    b'10000010'    ;set at_out
  143.     movwf    pb
  144.     movlw    b'10010000'    ;gie,inte=enable intf=clear
  145. at_g_st    movwf    intcon
  146.     movlw    wait
  147.     goto    wait
  148.  
  149. at_g0    btfsc    at_dat_in    ;chk startbit =0
  150.     goto    at_g_rint    ;if not ,return interrupt
  151.  
  152.     movlw    at_g1
  153.     movwf    int_addr
  154.     movlw    b'01000000'    ;parity chk on bit 6
  155.     movwf    parity
  156.     movlw    8        ;8 databits
  157.     movwf    bit_cnt
  158.     movlw    wait
  159.     retfie
  160.  
  161. at_g1    movf    pb,w
  162.     movwf    _temp
  163.     rlf    _temp
  164.     rlf    _temp
  165.     rrf    _byte
  166.     btfsc    par_chk        ;calc parity
  167.     comf    parity
  168.     decfsz    bit_cnt        ;decrease bit counter
  169.     goto    at_g_rint
  170.  
  171.     movlw    at_par_bit
  172.     movwf    int_addr
  173.     movf    parity,w
  174.     andlw    b'01000000'    ;mask parity bit 6
  175.     movwf    parity
  176. at_g_rint
  177.     movlw    wait
  178.     retfie
  179.  
  180. at_par_bit
  181.     movf    pb,w        ;check if received parity is correct
  182.     andlw    b'01000000'    ;mask parity bit 6
  183.     subwf    parity
  184.     btfsc    zero
  185.     goto    at_stopbit
  186.  
  187.     movlw    at_g_rs        ;clean up stack, before resend
  188.     return
  189.  
  190. at_g_rs    movlw    cmd_resend    ;error, please resend
  191.     call    at_send
  192.     goto    at_get_key
  193.  
  194. at_stopbit
  195.     movlw    at_g3
  196.     movwf    int_addr
  197.  
  198.     movlw    wait
  199.     retfie
  200.  
  201. at_g3    btfss    at_clk_in    ;wait clk hi
  202.     goto    at_g3
  203.     bcf    at_clk_out
  204.     movlw    at_g4
  205. at_g4    return            ;return at_get_key routine
  206. ;========-at send-==================================
  207. at_send    movwf    save_byte    ;if resend
  208. at_resend
  209.     movwf    _byte
  210.     clrf    intcon
  211.     movlw    8
  212.     movwf    bit_cnt
  213.     movlw    1
  214.     movwf    parity
  215.     movlw    at_s
  216.     movwf    int_addr
  217.     movlw    b'10000010'    ;set at_out
  218.     movwf    pb
  219.  
  220. chk_bsy    movf    pb,w        ;check if at= busy
  221.     andlw    b'01000001'    ;mask at_in bits
  222.     sublw    b'01000001'
  223.     btfss    zero
  224.     goto    chk_bsy
  225.  
  226.     movlw    at_s_parity    ;return addr.
  227.     movwf    at_s_ret
  228.     movlw    b'10010000'    ;gie=enable intf=clear inte=enable
  229.     movwf    intcon
  230.     clrf    pclath
  231.     movlw    wait
  232.     bcf    at_dat_out    ;tell the AT-keyb. we want to transmit
  233.     goto    wait
  234.  
  235. at_s_parity            ;parity, stop & ex bits send routine
  236.     movf    parity,w
  237.     iorlw    b'00000110'    ;set stop & ex-bit
  238.     movwf    _byte
  239.     movlw    at_s_ack    ;return addr.
  240.     movwf    at_s_ret
  241.     movlw    3
  242.     movwf    bit_cnt
  243.     movlw    wait
  244.     bsf    gie        ;enable ints.
  245.     goto    wait
  246.  
  247. at_s_ack            ;at send ack. routine
  248.     btfss    at_clk_in    ;test clk=hi
  249.     goto    at_s_ack
  250.     movlw    0xf6        ;short delay
  251.     call    delay
  252.     bcf    at_clk_out    ;ack.
  253.     movlw    0x9c        ;ca:100us
  254.     call    delay
  255.     call    at_get_key    ;get ack. byte
  256.     movf    _byte,w
  257.     sublw    cmd_resend    ;if equal, we'll have to  resend
  258.     btfss    zero
  259.     return
  260.  
  261.     movf    save_byte,w    ;prepare resend
  262.     goto    at_resend
  263.  
  264. at_s    rrf    _byte,w
  265.     rrf    _byte
  266.     movf    _byte,w        ;real send routine
  267.     iorlw    b'00000010'    ;set at_clk_out
  268.     movwf    pb
  269.     btfsc    par_chk
  270.     comf    parity
  271.     decfsz    bit_cnt
  272.     goto    at_s_r
  273.     movf    at_s_ret,w
  274.     return
  275.  
  276. at_s_r    movlw    wait
  277.     retfie
  278.  
  279. ;===================================================
  280. _reset    btfss     ami_type    ;check resetmode
  281.     goto    r_hardreset
  282.  
  283.     bsf    sync_cd
  284.     movlw    10
  285.     movwf    cnt_dwn
  286.     movlw    rst_warn
  287.     call    ami_send
  288.  
  289.     movlw    10
  290.     movwf    cnt_dwn
  291.     bsf    rwarn
  292.     movlw    rst_warn
  293.     call    ami_send
  294.  
  295.     movlw    r_hardreset
  296.     movwf    tmr_ret
  297.     clrf    tmr_ret_pch
  298.     movlw    152        ;10s
  299.     movwf    tmr_cntdwn
  300.     movlw    -151
  301.     movwf    tmr_ms
  302.     clrf    tmr_pch
  303.     movlw    r_sync1        ;wait routine addr.
  304.     call    tmr_init
  305.  
  306. r_sync1    bcf    gie
  307.     btfsc    ami_dat_in    ;wait kdat hi. max 10s
  308.     goto    r_hardreset
  309.     bsf    gie
  310.     movwf    pc
  311.  
  312. r_hardreset
  313.     movlw    1
  314.     movwf    tmr_ret_pch
  315.     movlw    i_1
  316.     movwf    tmr_ret
  317.     movlw    7        ;500ms
  318.     movwf    tmr_cntdwn
  319.     movlw    -161
  320.     movwf    tmr_ms
  321.     bcf    ami_clk        ;hard reset a2000
  322.     clrf    tmr_pch
  323.     bcf    _kbreset    ;hard reset a500/a1200
  324.     movlw    wait
  325.     call    tmr_init
  326.     goto    wait
  327.  
  328. ;---------------------------------------------------
  329. r_sync    movlw    r_hardreset    ;wait kdat lo ack. 250ms
  330.     movwf    tmr_ret
  331.     clrf    tmr_ret_pch
  332.     movlw    3        ;3*65536us
  333.     movwf    tmr_cntdwn
  334.     movlw    -209        ;(2.5*10^5-3*65536)/256=209
  335.     movwf    tmr_ms
  336.     goto    rw_s
  337. ;=======-AmiSync routine-===========================
  338. sync_up    btfss    sync_cd
  339.     goto    sync_up1
  340.     decf    cnt_dwn
  341.     btfsc    zero
  342.     goto    r_hardreset
  343.  
  344. sync_up1
  345.     bcf    ami_dat_out    ;clock out 1:s
  346.     movlw    -20
  347.     call    delay
  348.     bcf    ami_clk
  349.     movlw    -20
  350.     call    delay
  351.     bsf    ami_clk
  352.     movlw    -20
  353.     call    delay
  354.     bsf    ami_dat_out
  355. ;    goto    ami_sync
  356.  
  357. ;---------------------------------------------------
  358. ami_sync
  359.     movlw    sync_up
  360.     movwf    tmr_ret
  361.     clrf    tmr_ret_pch
  362.     movlw    2        ;2*65536us
  363.     movwf    tmr_cntdwn
  364.     movlw    -47        ;remaining (1.43*10^5-2*65536)/256=47
  365.     movwf    tmr_ms
  366. rw_s    movlw    0xff        ;set all ami_outputs
  367.     movwf    pa
  368.     clrf    tmr_pch
  369.     movlw    sync_1        ;wait routine addr.
  370.     call    tmr_init    ;init long delay
  371.  
  372. sync_1    bcf    gie
  373.     btfss    ami_dat_in    ;wait lo ack. 143ms
  374.     goto    sync_2
  375.     bsf    gie
  376.     movwf    pc
  377.  
  378. sync_2    call    tmr_end        ;deinit long delay
  379.  
  380.     btfsc    rwarn
  381.     return
  382.  
  383. sync_3    btfss    ami_dat_in    ;wait ack. end
  384.     goto    sync_3
  385.     return
  386.  
  387.     org    0x100
  388. ;=======-Delay routine-=============================
  389. delay    movwf    tmr0
  390.     movlw    b'10001111'
  391.     option
  392.     bcf    t0ie        ;disable tmr int.
  393.     bcf    t0if
  394. dly    btfss    t0if
  395.     goto    dly
  396.     return
  397.  
  398. ;===================================================
  399. translate
  400.     bsf    pch_0
  401.     bcf    pch_1
  402.     movf    trans_addr,w
  403.     movwf    pc
  404. ;---------------------------------------------------
  405. t_chk    movf    _byte,w
  406.     sublw    0xe1        ;pause
  407.     btfsc    zero
  408.     goto    s_pause
  409.  
  410.     bcf    p_res        ;reset pause flag
  411.  
  412.     movf    _byte,w
  413.     sublw    0xe0        ;arrowkeys etc.
  414.     btfsc    zero
  415.     goto    t_e0
  416.  
  417.     clrf    e0_l_byte
  418.  
  419.     movf    _byte,w
  420.     sublw    0xf0        ;break code
  421.     btfsc    zero
  422.     goto    t_break
  423.  
  424.     bcf    s_break        ;reset "special mission keys" break flag
  425.  
  426.     movf    l_byte,w    ;get rid of repeating chars
  427.     subwf    _byte,w
  428.     btfss    zero
  429.     goto    not_eq
  430.     movlw    no_send
  431.     movwf    ami_byte
  432.     return
  433.  
  434. not_eq    movf    _byte,w
  435.     movwf    l_byte
  436.     goto    table
  437.  
  438. ;---------------------------------------------------
  439. t_break    clrf    l_byte
  440.     bsf    s_break
  441.     movlw    t_b1
  442.     movwf    trans_addr
  443.     movlw    no_send
  444.     movwf    ami_byte
  445.     return
  446.  
  447. t_b1    movlw    t_chk
  448.     movwf    trans_addr
  449.  
  450.     movf    _byte,w
  451.     call    table
  452.     bsf    _break
  453.     return
  454. ;---------------------------------------------------
  455. t_e0    clrf    l_byte
  456.     bcf    s_break
  457.     movlw    t_e01
  458.     movwf    trans_addr
  459.     movlw    no_send
  460.     movwf    ami_byte
  461.     return
  462.  
  463. t_e01    movf    _byte,w
  464.     sublw    0xf0        ;break
  465.     btfsc    zero
  466.     goto    t_e0_b
  467.  
  468.     movlw    t_chk
  469.     movwf    trans_addr
  470.  
  471.     movf    e0_l_byte,w    ;get rid of repeating chars
  472.     subwf    _byte,w
  473.     btfsc    zero
  474.     return
  475.  
  476.     movf    _byte,w
  477.     movwf    e0_l_byte
  478.     goto    e0_table
  479.  
  480. t_e0_b    bsf    s_break
  481.     movlw    t_e0_b1
  482.     movwf    trans_addr
  483.     clrf    e0_l_byte
  484.     return
  485.  
  486. t_e0_b1    movlw    t_chk
  487.     movwf    trans_addr
  488.  
  489.     movf    _byte,w
  490.     call    e0_table
  491.     bsf    _break
  492.     return
  493.  
  494. ;=======-special mission keys-======================
  495.  
  496. s_home    btfsc    s_break
  497.     goto    s_home_b
  498.     movlw    0x61        ;right shift
  499.     call    ami_send
  500.     retlw    0x4f        ;arrow left
  501. s_home_b
  502.     movlw    0x4f+0x80
  503.     call    ami_send
  504.     retlw    0x61+0x80
  505. ;---------------------------------------------------
  506. s_end    btfsc    s_break
  507.     goto    s_end_b
  508.     movlw    0x61        ;right shift
  509.     call    ami_send
  510.     retlw    0x4e        ;arrow right
  511. s_end_b    movlw    0x4e+0x80
  512.     call    ami_send
  513.     retlw    0x61+0x80
  514. ;---------------------------------------------------
  515. s_pageup
  516.     btfsc    s_break
  517.     goto    s_pageup_b
  518.     movlw    0x61        ;right shift
  519.     call    ami_send
  520.     retlw    0x4c        ;arrow up
  521. s_pageup_b
  522.     movlw    0x4c+0x80    ;arrow up + break
  523.     call    ami_send
  524.     retlw    0x61+0x80    ;right shift + break
  525. ;---------------------------------------------------
  526. s_pagedown
  527.     btfsc    s_break
  528.     goto    s_pagedown_b
  529.     movlw    0x61        ;right shift
  530.     call    ami_send
  531.     retlw    0x4d        ;arrow down
  532. s_pagedown_b
  533.     movlw    0x4d+0x80    ;arrow down + break
  534.     call    ami_send
  535.     retlw    0x61+0x80    ;right shift + break
  536. ;---------------------------------------------------
  537. s_c_screen
  538.     btfsc    s_break
  539.     goto    s_c_screen_b
  540.     movlw    0x66        ;left amiga
  541.     call    ami_send
  542.     retlw    0x37        ;m
  543. s_c_screen_b
  544.     movlw    0x37+0x80    ;m + break
  545.     call    ami_send
  546.     retlw    0x66+0x80    ;left amiga + break
  547. ;---------------------------------------------------
  548. s_ctrl    bsf    rw_ctrl
  549.     btfsc    s_break
  550.     bcf    rw_ctrl
  551.     retlw    0x63
  552. ;---------------------------------------------------
  553. s_lamiga
  554.     bsf    rw_lalt
  555.     btfsc    s_break
  556.     bcf    rw_lalt
  557.     retlw    0x66
  558. ;---------------------------------------------------
  559. s_ramiga
  560.     bsf    rw_ralt
  561.     btfsc    s_break
  562.     bcf    rw_ralt
  563.     retlw    0x67
  564. ;---------------------------------------------------
  565. s_caps    btfsc    s_break
  566.     retlw    no_send
  567.  
  568.     clrf    pclath
  569.     movlw    cmd_option
  570.     call    at_send
  571.  
  572.     btfss    c_lock        ;chk capslock= on
  573.     goto    s_c_on
  574.  
  575.     bcf    c_lock        ;capslock off
  576.     movf    leds,w
  577.     call    at_send
  578.     retlw    0x62+0x80    ;capslock + break
  579.  
  580. s_c_on    bsf    c_lock        ;capslock on
  581.     movf    leds,w
  582.     call    at_send
  583.     retlw    0x62        ;capslock
  584. ;---------------------------------------------------
  585. s_pause    clrf    l_byte
  586.     clrf    e0_l_byte
  587.     movlw    s_p1
  588.     movwf    trans_addr
  589.     movlw    7        ;receive 7 more pause bytes,
  590.     movwf    cnt_dwn        ;waste of time don't u think :-)
  591.     movlw    no_send
  592.     movwf    ami_byte
  593.     return
  594.  
  595. s_p1    decfsz    cnt_dwn
  596.     return
  597.  
  598.     btfsc    p_res        ;chk if pause pressed twice
  599.     goto    _reset        ;p_res = hi -> hardreset
  600.  
  601.     bsf    p_res
  602.     movlw    t_chk
  603.     movwf    trans_addr
  604.     return
  605.  
  606. ;===================================================
  607. init    movlw    b'01111101'    ;0=output 1=input
  608.     tris    pb
  609.     movlw    b'11100110'
  610.     tris    pa
  611.     movlw    b'10001111'    ;pull up pb disable,falling edge
  612.     option            ;assign prescaler to wdt, presc. 128
  613.  
  614. ;---------------------------------------------------
  615. at_startup
  616.     movlw    2
  617.     movwf    tmr_ret_pch
  618.     movlw    at_st_ret
  619.     movwf    tmr_ret
  620.     movlw    76        ;wdt 5s
  621.     movwf    tmr_cntdwn
  622.     movlw    -75        ;(5*10^6-76*256²)/256=75
  623.     movwf    tmr_ms
  624.     clrf    tmr_pch
  625.     movlw    wait
  626.     call    tmr_init
  627.  
  628.     movlw    at_g0
  629.     movwf    int_addr
  630.     movlw    b'10110000'    ;gie,t0ie,inte=enable t0if,intf=reset
  631.     call    at_g_st
  632.  
  633. ;---------------------------------------------------
  634. at_st_ret
  635.     bcf    at_clk_out
  636.     movlw    15        ;delay 1s
  637.     movwf    tmr_cntdwn
  638.     movlw    -66        ;(10^6-15*256²)/256=66
  639.     movwf    tmr_ms
  640.     movlw    1
  641.     movwf    tmr_ret_pch
  642.     movlw    i_1
  643.     movwf    tmr_ret
  644.     clrf    tmr_pch
  645.     movlw    wait
  646.     call    tmr_init
  647.     goto    wait
  648. ;---------------------------------------------------
  649.  
  650. i_1    clrf    x_flag        ;init "xtra flag" reg.
  651.     clrf    l_byte        ;init last byte chk
  652.     clrf    e0_l_byte
  653.  
  654.     movlw    cmd_reset    ;at reset
  655.     call    at_send
  656.     call    at_get_key    ;receive 0xaa= bat/selftest complete
  657.  
  658.     movlw    cmd_default
  659.     call    at_send
  660.  
  661.     movlw    cmd_option    ;at option cmd.
  662.     call    at_send
  663.  
  664.     movlw    b'00000100'    ;capslock on
  665.     call    at_send
  666.  
  667.     bsf    sync_cd        ;enable sync-countdown
  668.     movlw    50        ;if sync does not arrive within 50 retries,
  669.     movwf    cnt_dwn        ;then hard reset
  670.     call    sync_up        ;synchronize with amiga
  671.  
  672.     movlw    10
  673.     movwf    cnt_dwn
  674.     movlw    pwr_up        ;power up key stream
  675.     call    ami_send
  676.  
  677.     movlw    10
  678.     movwf    cnt_dwn
  679.     movlw    t_pwr_up    ;terminate key stream
  680.     call    ami_send
  681.     bcf    sync_cd        ;disable sync-countdown
  682.  
  683.     movlw    cmd_option
  684.     call    at_send
  685.  
  686.     clrf    leds        ;all leds off
  687.     clrw
  688.     call    at_send
  689.  
  690.     movlw    t_chk
  691.     movwf    trans_addr    ;init trans_addr
  692.  
  693. ;=======-Main Loop-=================================
  694. loop    clrf    pclath
  695.     call    at_get_key
  696.     call    translate    ;atcode -> amigacode
  697.  
  698.     movf    x_flag,w
  699.     andlw    b'00001110'
  700.     sublw    b'00001110'    ;chk reset warning
  701.     btfsc    zero
  702.     goto    _reset
  703.  
  704.     movf    ami_byte,w
  705.     sublw    no_send        ;0xff = no amisend
  706.     btfsc    zero
  707.     goto    loop
  708.  
  709.     movf    ami_byte,w
  710.     call    ami_send
  711.     goto    loop
  712.  
  713.     org    0x200
  714. ;=======-Amiga Send-================================
  715. ami_send
  716.     clrf    intcon        ;disable all interrupts
  717.     movwf    ami_byte
  718.     rlf    ami_byte,w    ;put bit #7 first
  719.     rlf    ami_byte
  720.     comf    ami_byte    ;& invert, according to rkm hw-ref
  721.     movlw    0xff        ;set ami out
  722.     movwf    pa
  723.     movlw    8        ;8 bits to transmit
  724.     movwf    bit_cnt
  725.  
  726. ami_out    rlf    ami_byte,w
  727.     rlf    ami_byte
  728.     movf    ami_byte,w
  729.     iorlw    b'00011000'    ;set ami_clk & _kbreset
  730.     movwf    pa
  731.     movlw    -20        ;20us
  732.     call    delay
  733.     bcf    ami_clk
  734.     movlw    -20
  735.     call    delay
  736.     bsf    ami_clk
  737.     movlw    -20
  738.     call    delay
  739.     decfsz    bit_cnt
  740.     goto    ami_out
  741.     bsf    ami_dat_out
  742.  
  743.     btfsc    rwarn        ;chk if in resetmode
  744.     goto    r_sync        ;then wait 250ms for ack.
  745.  
  746.     goto    ami_sync    ;wait 143ms for ack.
  747.  
  748.  
  749.     org    0x300
  750. ;======-key lookup table-===========================
  751. e0_table
  752.     addlw    0x70    ;correct the keylookup-table to work with e0xx-codes
  753.  
  754. table    call    tab
  755.     movwf    ami_byte
  756.     return
  757.  
  758. tab    bsf    pch_0
  759.     bsf    pch_1
  760.     addwf    pc
  761.  
  762.     fill (retlw no_send),1
  763.     retlw    0x58        ;f9    =0x01
  764.     fill (retlw no_send),1
  765.     retlw    0x54        ;f5    =0x03
  766.     retlw    0x52        ;f3    =0x04
  767.     retlw    0x50        ;f1    =0x05
  768.     retlw    0x51        ;f2    =0x06
  769.     retlw    0x5b        ;f12    =0x07 -> ]}
  770.     fill (retlw no_send),1
  771.     retlw    0x59        ;f10    =0x09
  772.     retlw    0x57        ;f8    =0x0a
  773.     retlw    0x55        ;f6    =0x0b
  774.     retlw    0x53        ;f4    =0x0c
  775.     retlw    0x42        ;tab    =0x0d
  776.     retlw    0x00        ;`~    =0x0e
  777.     fill (retlw no_send),2
  778.     goto    s_lamiga    ;l alt    =0x11 -> lamiga
  779.     retlw    0x60        ;l shift=0x12
  780.     fill (retlw no_send),1
  781.     retlw    0x64        ;l ctrl    =0x14 -> lalt
  782.     retlw    0x10        ;Q    =0x15
  783.     retlw    0x01        ;1    =0x16
  784.     fill (retlw no_send),3
  785.     retlw    0x31        ;Z    =0x1a
  786.     retlw    0x21        ;S    =0x1b
  787.     retlw    0x20        ;A    =0x1c
  788.     retlw    0x11        ;W    =0x1d
  789.     retlw    0x02        ;2    =0x1e
  790.     fill (retlw no_send),2
  791.     retlw    0x33        ;C    =0x21
  792.     retlw    0x32        ;X    =0x22
  793.     retlw    0x22        ;D    =0x23
  794.     retlw    0x12        ;E    =0x24
  795.     retlw    0x04        ;4    =0x25
  796.     retlw    0x03        ;3    =0x26
  797.     fill (retlw no_send),2
  798.     retlw    0x40        ;space    =0x29
  799.     retlw    0x34        ;V    =0x2a
  800.     retlw    0x23        ;F    =0x2b
  801.     retlw    0x14        ;T    =0x2c
  802.     retlw    0x13        ;R    =0x2d
  803.     retlw    0x05        ;5    =0x2e
  804.     fill (retlw no_send),2
  805.     retlw    0x36        ;N    =0x31
  806.     retlw    0x35        ;B    =0x32
  807.     retlw    0x25        ;H    =0x33
  808.     retlw    0x24        ;G    =0x34
  809.     retlw    0x15        ;Y    =0x35
  810.     retlw    0x06        ;6    =0x36
  811.     fill (retlw no_send),3
  812.     retlw    0x37        ;M    =0x3a
  813.     retlw    0x26        ;J    =0x3b
  814.     retlw    0x16        ;U    =0x3c
  815.     retlw    0x07        ;7    =0x3d
  816.     retlw    0x08        ;8    =0x3e
  817.     fill (retlw no_send),2
  818.     retlw    0x38        ;;,    =0x41
  819.     retlw    0x27        ;K    =0x42
  820.     retlw    0x17        ;I    =0x43
  821.     retlw    0x18        ;O    =0x44
  822.     retlw    0x0a        ;0    =0x45
  823.     retlw    0x09        ;9    =0x46
  824.     fill (retlw no_send),2
  825.     retlw    0x39        ;:.    =0x49
  826.     retlw    0x3a        ;_-    =0x4a
  827.     retlw    0x28        ;L    =0x4b
  828.     retlw    0x29        ;Ö    =0x4c
  829.     retlw    0x19        ;P    =0x4d
  830.     retlw    0x0b        ;+    =0x4e
  831.     fill (retlw no_send),3
  832.     retlw    0x2a        ;Ä    =0x52
  833.     fill (retlw no_send),1
  834.     retlw    0x1a        ;Å    =0x54
  835.     retlw    0x0c        ;=+    =0x55
  836.     fill (retlw no_send),2
  837.     goto    s_ctrl        ;caps l.=0x58 -> ctrl
  838.     retlw    0x61        ;r shift=0x59
  839.     retlw    0x44        ;return    =0x5a
  840.     retlw    0x1b        ;]    =0x5b
  841.     fill (retlw no_send),1
  842.     retlw    0x2b        ;*'    =0x5d
  843.     fill (retlw no_send),3
  844.     retlw    0x30        ;<>    =0x61
  845.     fill (retlw no_send),4
  846.     retlw    0x41        ;bs    =0x66
  847.     fill (retlw no_send),2
  848.     retlw    0x1d        ;kp1    =0x69
  849.     fill (retlw no_send),1
  850.     retlw    0x2d        ;kp4    =0x6b
  851.     retlw    0x3d        ;kp7    =0x6c
  852.     fill (retlw no_send),3
  853.     retlw    0x0f        ;kp0    =0x70
  854.     retlw    0x3c        ;kp.    =0x71
  855.     retlw    0x1e        ;kp2    =0x72
  856.     retlw    0x2e        ;kp5    =0x73
  857.     retlw    0x2f        ;kp6    =0x74
  858.     retlw    0x3e        ;kp8    =0x75
  859.     retlw    0x45        ;esc    =0x76
  860.     retlw    0x5a        ;numlock=0x77
  861.     retlw    0x0d        ;f11    =0x78 -> \|
  862.     retlw    0x5e        ;kp+    =0x79
  863.     retlw    0x1f        ;kp3    =0x7a
  864.     retlw    0x4a        ;kp-    =0x7b
  865.     retlw    0x5d        ;kp*    =0x7c
  866.     retlw    0x3f        ;kp9    =0x7d
  867.     goto    s_caps        ;scrl l.=0x7e -> caps lock
  868.     fill (retlw no_send),2
  869.     goto    s_ramiga    ;r alt    =0x11 -> ramiga
  870.     retlw    no_send        ;l shift=0x12 (numlock x-byte +lshift)
  871.     retlw    0x56        ;f7    =0x83
  872.     retlw    0x65        ;r ctrl    =0x14 -> ralt
  873.     fill (retlw no_send),0x1f-0x14-1
  874.     goto    s_lamiga    ;win95    =0x1f
  875.     fill (retlw no_send),0x27-0x1f-1
  876.     goto    s_ramiga    ;win95    =0x27
  877.     fill (retlw no_send),0x2f-0x27-1
  878.     goto    s_c_screen    ;menu95    =0x2f
  879.     fill (retlw no_send),0x4a-0x2f-1
  880.     retlw    0x5c        ;kp/    =0x4a
  881.     fill (retlw no_send),14
  882.     retlw    no_send        ;r shift=0x59 (useless x-byte)
  883.     retlw    0x43        ;enter    =0x5a
  884.     fill (retlw no_send),14
  885.     goto    s_end        ;end    =0x69
  886.     fill (retlw no_send),1
  887.     retlw    0x4f        ;l arrow=0x6b
  888.     goto    s_home        ;home    =0x6c
  889.     fill (retlw no_send),3
  890.     retlw    0x5f        ;insert    =0x70 -> help
  891.     retlw    0x46        ;delete    =0x71
  892.     retlw    0x4d        ;d arrow=0x72
  893.     fill (retlw no_send),1
  894.     retlw    0x4e        ;r arrow=0x74
  895.     retlw    0x4c        ;u arrow=0x75
  896.     fill (retlw no_send),4
  897.     goto    s_pagedown    ;pagedn    =0x7a
  898.     fill (retlw no_send),1
  899.     goto    s_c_screen    ;print s=0x7c
  900.     goto    s_pageup    ;pageup    =0x7d
  901.  
  902.     end
  903. ;win95        e01f
  904. ;win95        e027
  905. ;menu95        e02f
  906. ;right alt    e011
  907. ;left shift    e012
  908. ;right ctrl    e014
  909. ;keypad div    e04a
  910. ;rshift+nlock    e0f059
  911. ;enter        e05a
  912. ;end        e069
  913. ;left        e06b
  914. ;home        e06c
  915. ;insert        e070
  916. ;delete        e071
  917. ;down        e072
  918. ;right        e074
  919. ;up        e075
  920. ;page down    e07a
  921. ;print screen    e07c
  922. ;page up    e07d
  923.