home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / info / ibmkeybd.lzh / a51.c next >
C/C++ Source or Header  |  1990-03-27  |  152KB  |  4,903 lines

  1. #include "a51.h"
  2. void convert();
  3. void hexs();
  4.  
  5. void cleanexit(t)
  6. char t[80];
  7. {
  8.     int x;
  9.     LINK tl;
  10.         tl=tag_list;
  11.         x=0;
  12.         hexsflag=0;
  13.         while (tl!=(LINK) NULL)
  14.         {
  15.             if (x==0) fprintf(f_lst,"\n");
  16.             else fprintf(f_lst,"\t");
  17.             hexs(tl->value);
  18.             fprintf(f_lst,"%s\t%s",tl->tag,hexstr);
  19.             tl=tl->next;
  20.         }
  21.         fprintf(f_lst,"\n\n");
  22.         fclose(f_lst);
  23.     printf("****%d\t%s\n",line,buffer);
  24.     printf("ERROR:%s\n",t);
  25.     exit();
  26. }
  27.  
  28. void warn(t)
  29. char t[80];
  30. {
  31.     printf("++++%d\t%s\n",line,buffer);
  32.     printf("WARNING:%s\n",t);
  33.     return;
  34. }
  35.  
  36. void strnullcpy(t,u,n)
  37. char t[80];
  38. char u[80];
  39. int n;
  40. {
  41.     strncpy(t,u,n);
  42.     t[n]='\0';
  43.     return;
  44. }
  45.  
  46. void hack(n)
  47. int n;
  48. {
  49.     int x;
  50.     for (x=0;x<=80;x++)
  51.         s[x]=s[x+n];
  52.     pos-=n;
  53.     return;
  54. }
  55.  
  56. char hexc(n)
  57. int n;
  58. {
  59.     if ((n+=48)>57) n+=7;
  60.     return((char) n);
  61. }
  62.  
  63. void hexs(l)
  64. long l;
  65. {
  66.     long m;
  67.     char t[7];
  68.     m=l;
  69.     t[0]=hexc(m/1048576);
  70.     m%=1048576;
  71.     t[1]=hexc(m/65536);
  72.     m%=65536;
  73.     t[2]=hexc(m/4096);
  74.     m%=4096;
  75.     t[3]=hexc(m/256);
  76.     m%=256;
  77.     t[4]=hexc(m/16);
  78.     m%=16;
  79.     t[5]=hexc(m);
  80.     t[6]='\0';
  81.     if (l>65535) {strcpy(hexstr,t);return;}
  82.     if ((l>255)||(hexsflag==1)) {strcpy(hexstr,&t[2]);return;}
  83.     strcpy(hexstr,&t[4]);
  84.     return;
  85. }
  86.  
  87. void showcode()
  88. {
  89.     int x,y;
  90.     int flag;
  91.     char filename[80];
  92.     char longstr[80];
  93.     strcpy(filename,basename);
  94.     f_hex=fopen(strcat(filename,".hex"),"w");
  95.     if (f_hex==(FILE *) NULL)
  96.         {
  97.         printf("Could not open file.hex for write.");
  98.         return;
  99.         }
  100.     for (x=0;x<32767-16;x+=16)
  101.     {
  102.         flag=0;
  103.         for (y=0;y<=15;y++)
  104.             if (mem[x+y]!=0) flag=1;
  105.         if (flag==1)
  106.         {
  107.             hexsflag=1;
  108.             hexs(x);
  109.             hexsflag=0;
  110.             strcpy(longstr,hexstr);
  111.             strcat(longstr,":    ");
  112.             for (y=0;y<=15;y++)
  113.             {
  114.                 hexs(mem[x+y]);
  115.                 strcat(longstr,hexstr);
  116.                 strcat(longstr," ");
  117.                 if (y==7) strcat(longstr," ");
  118.             }
  119.             fprintf(f_hex,"%s\n",longstr);
  120.         }
  121.     }
  122.     fclose(f_hex);
  123.     return;
  124. }    
  125.  
  126. void codeit(t)
  127. char t[80];
  128. {
  129.     char sht[3];
  130.     char tdup[80];
  131.     char buf[80];
  132.     char tdup2[80];
  133.     int ad,x,y;
  134.     strcpy(tdup,t);    
  135.     if (pass==1) return;
  136.     hexsflag=1;
  137.     hexs(addr);
  138.     hexsflag=0;
  139.     sht[2]='\0';
  140.     strcpy(buf,buffer);
  141.     if (strlen(buffer)>50) strnullcpy(buf,buffer,50);
  142.     strcpy(tdup2,tdup);
  143.     if (strlen(tdup)>6) strnullcpy(tdup2,tdup,6);
  144.     fprintf(f_lst,"%5d %4s  %6s   %s\n",line,hexstr,tdup2,buf);
  145.     
  146.     if (tdup[0]!=' ')
  147.     {
  148.         ad=addr;
  149.         for (x=0;x<strlen(tdup);x+=2)
  150.         {
  151.             y=tdup[x]-48;
  152.             if (y>9) y-=7;
  153.             value=y*16;
  154.             y=tdup[x+1]-48;
  155.             if (y>9) y-=7;
  156.             value+=y;    
  157.             mem[ad++]=value;
  158.         }
  159.     }
  160.     return;
  161. }
  162.  
  163. int tag_defined(t)
  164. char t[80];
  165. {
  166.     LINK    list;
  167.     list=tag_list;
  168.     while (list!=(LINK) NULL)
  169.     {
  170.         if (strcmp(t,list->tag)==0)
  171.             return(1);
  172.         list=list->next;
  173.     }
  174.     return(0);
  175.     
  176. void add_tag(val) 
  177. int val;
  178. {
  179.     LINK    list;
  180.     list=tag_list;
  181.     if (list!=(LINK) NULL)
  182.         while (list->next!=(LINK) NULL)
  183.             list=list->next;
  184.     if (list==(LINK) NULL)
  185.     {
  186.         tag_list=(LINK) malloc(sizeof(ELEM));
  187.         strcpy(tag_list->tag,name);
  188.         tag_list->value=val;
  189.         tag_list->next=(LINK) NULL;
  190.     }
  191.     else
  192.     {
  193.         list->next=(LINK) malloc(sizeof(ELEM));
  194.         strcpy(list->next->tag,name);
  195.         list->next->value=val;
  196.         list->next->next=(LINK) NULL;
  197.     }
  198.     return;
  199.  
  200. int validtag(t)
  201. char t[80];
  202. {
  203.     int x;
  204.     for (x=0;x<strlen(t);x++)
  205.     {
  206.         if ((
  207.         ((s[x]>='A')&&(s[x]<='Z'))||
  208.         ((s[x]>='0')&&(s[x]<='9'))||
  209.         (s[x]=='_')
  210.         )==0)
  211.             return(0);
  212.     }
  213.     return(1);
  214. }
  215.         
  216. void gettag(x)
  217. int x;
  218. {
  219.     strnullcpy(name,s,x);
  220.     if (validtag(name)==0)
  221.         cleanexit("Tag contains extranneous characters.");
  222.     if (pass==1)
  223.     {
  224.         if (tag_defined(name)) cleanexit("Tag already defined.");
  225.         add_tag(addr);
  226.     }
  227.     hack(x+1);
  228.     return;
  229. }
  230.  
  231. int testbase(b,c)
  232. int b;
  233. char c;
  234. {
  235.     int n;
  236.     n=((int) c)-48;
  237.  if (n<0) return(-1);
  238.     if ((n>9)&&(n<17)) return(-1);
  239.     if (n>9) n-=7;
  240.     if (n>(b-1)) return(-1);
  241.     return(n);
  242. }
  243.  
  244. void convert(base)
  245. int base;
  246. {
  247.     int x;
  248.     value=0;
  249.     while ((x=testbase(base,s[0]))>=0)
  250.     {
  251.         hack(1);
  252.         value*=base;
  253.         value+=x;
  254.     }
  255.     return;
  256. }
  257.  
  258. int lookup()
  259. {
  260.     LINK    list;
  261.     list=tag_list;
  262.     while (list!=(LINK) NULL)
  263.     {
  264.         if (strcmp(list->tag,name)==0) return(list->value);
  265.         list=list->next;
  266.     }
  267.     cleanexit("Lookup on identifier failed.");
  268. }
  269.  
  270. int regist(t)
  271. char t[80];
  272. {
  273.     if (strcmp(t,"AB")==0) return(18);
  274.     if (strcmp(t,"A")==0) return(1);
  275.     if (strcmp(t,"DPTR")==0) return(4);
  276.     if (t[0]=='R')
  277.         if (((t[1]>='0')&&(t[1]<='7'))&&(t[2]=='\0'))
  278.             return( ((int) t[1]) -38);
  279.     if (strcmp(t,"C")==0) return(3);
  280.     if (strcmp(t,"@DPTR")==0) return(5);
  281.     if (strcmp(t,"@R0")==0) return(8);
  282.     if (strcmp(t,"@R1")==0) return(9);
  283.     return(0);
  284. }
  285.  
  286. int getexp()
  287. {
  288.     int flag,x;
  289.     value=0;
  290.     flag=0;
  291.     if (s[0]=='#')
  292.     {
  293.         hack(1);
  294.         flag=1;
  295.     }
  296.     if (strncmp(s,"H'",2)==0)
  297.     {
  298.         hack(2);
  299.         convert(16,s);
  300.         return(7-flag);
  301.     }
  302.     if (strncmp(s,"B'",2)==0)
  303.     {
  304.         hack(2);
  305.         convert(2,s);
  306.         return(7-flag);
  307.     }
  308.     x=0;
  309.     if (testbase(10,s[0])>=0)
  310.     {
  311.         while(testbase(16,s[x])>=0) x++;
  312.         if (s[x]=='H') {convert(16,s);hack(1);return(7-flag);}
  313.         if (s[x-1]=='B') {convert(2,s);hack(1); return(7-flag);}
  314.         convert(10,s); return(7-flag);
  315.     }
  316.     if (s[0]=='\'')
  317.     {
  318.         hack(1);
  319.         if (s[1]!='\'') cleanexit("Need another single quote.");
  320.         value=(int) s[0];
  321.         hack(2);
  322.         if (flag==0)
  323.         {
  324.             warn("Character constants not advisable here.");
  325.             return(7);
  326.         }
  327.         return(6);
  328.     }
  329.     x=0;
  330.     while (
  331.     (s[0]!=',')&&
  332.     (s[0]!='\0')&&
  333.     (s[0]!='+')&&
  334.     (s[0]!='*')&&
  335.     (s[0]!='-')&&
  336.     (s[0]!=';')&&
  337.     (s[0]!=' ')
  338.     )
  339.     {
  340.         name[x++]=s[0];
  341.         hack(1);
  342.     }
  343.     name[x]='\0';
  344.     while (s[0]==' ') hack(1);
  345.     x=regist(name);
  346.     if (x>0) return(x);
  347.     if (tag_defined(name)==0)
  348.     {
  349.         if (pass==1) {value=0;return(7-flag);}
  350.         cleanexit("Need to define this expression.");
  351.     }
  352.     value=lookup();
  353.     return(7-flag);
  354. }
  355.         
  356. int getbyte()
  357. {
  358.     int v,x,firstx;
  359.     char c;
  360.     x=getexp();    
  361.     v=value;
  362.     firstx=x;
  363.     while ((s[0]=='+')||(s[0]=='-')||(s[0]=='*'))
  364.     {
  365.         c=s[0];
  366.         hack(1);
  367.         x=getexp();
  368.         if (x!=firstx) cleanexit("Expression types must match.");
  369.         switch(c) {
  370.             case '+':
  371.                 v+=value;
  372.                 break;
  373.             case '-':
  374.                 v-=value;
  375.                 break;
  376.             case '*':
  377.                 v*=value;
  378.                 break;
  379.             default:
  380.                 break;
  381.             }
  382.     }
  383.     realvalue=v;
  384.     value=v;
  385.     if (value<-65536) cleanexit("Value out of range.");
  386.     if (value<-128) value+=65536;
  387.     if (value<0) value+=256;
  388.     if (value>65535) cleanexit("Value out of range.");
  389.     return(x);
  390. }
  391.  
  392. void equate()
  393. {
  394.     char left[80];
  395.     int x;
  396.     hack(5);
  397.     x=0;
  398.     while ((s[x]!=',')&&(s[x]!='\0')) x++;
  399.     if (s[x]!=',') cleanexit("Equate needs a comma.");
  400.     strnullcpy(left,s,x);
  401.     if (regist(left)>0) cleanexit("Cannot use registers in equate.");
  402.     hack(x+1);
  403.     codeit("  ->");
  404.     if (pass==2)
  405.     {
  406.         x=getbyte();
  407.         return;
  408.     }
  409.     if (tag_defined(left)==1)
  410.         cleanexit("Identifier already defined.");
  411.     if (getbyte()!=7) cleanexit("Value must be a byte/word.");
  412.     strcpy(name,left);
  413.     add_tag(value);
  414.     return;
  415. }
  416.  
  417. void origin()
  418. {
  419.     hack(5);
  420.     if (getbyte()!=7) cleanexit("Must be byte/word.");
  421.     if (pass==2) codeit("  ->");
  422.     addr=value;
  423.     return;
  424. }
  425.  
  426. void defbyte()
  427. {
  428.     hack(4);
  429.     if (getbyte()!=7) cleanexit("Must be byte.");
  430.     if (value>255) cleanexit("Byte value out of range.");
  431.     if (pass==2)
  432.     {
  433.         hexs(value);
  434.         codeit(hexstr);
  435.     }
  436.     addr+=1;
  437.     return;
  438. }
  439.  
  440. void defword()
  441. {
  442.     hack(4);
  443.     if (getbyte()!=7) cleanexit("Must be word.");
  444.     if (pass==2)
  445.     {
  446.         hexsflag=1;
  447.         hexs(value);
  448.         hexsflag=0;
  449.         codeit(hexstr);
  450.     }
  451.     addr+=2;
  452.     return;
  453. }
  454.  
  455. void defmsg()
  456. {
  457.     char t[80];
  458.     int x;
  459.     hack(4);
  460.     if (s[0]!='\'')
  461.         cleanexit("Must start with single quote.");
  462.     hack(1);
  463.     t[0]='\0';
  464.     for (x=0;x<=pos;x++)
  465.     {
  466.         if (s[x]=='\'')
  467.         {
  468.             if (pass==2) codeit(t);
  469.             addr+=x;
  470.             hack(x+1);
  471.             return;
  472.         }
  473.         if (pass==2)
  474.         {
  475.             hexs(s[x]);
  476.             strcat(t,hexstr);
  477.         }
  478.     }
  479.     cleanexit("Must end with single quote.");
  480. }
  481.  
  482. void reserve()
  483. {
  484.     hack(4);
  485.     if (getbyte()!=7) cleanexit("Must be byte/word.");
  486.     if (pass==2) codeit("  ->");
  487.     addr+=value;
  488.     return;
  489. }
  490.  
  491. void endassm()
  492. {
  493.     hack(4);
  494.     return;
  495. }
  496.  
  497. void getdirec()
  498. {
  499.     if (strncmp(s,".EQU",4)==0) {equate();return;}
  500.     if (strncmp(s,".ORG",4)==0) {origin();return;}
  501.     if (strncmp(s,".DB",3)==0) {defbyte();return;}
  502.     if (strncmp(s,".DW",3)==0) {defword();return;}
  503.     if (strncmp(s,".DM",3)==0) {defmsg();return;}
  504.     if (strncmp(s,".RS",3)==0) {reserve();return;}
  505.     if (strncmp(s,".END",3)==0) {endassm();return;}
  506.     cleanexit("Compiler directive not understood.");
  507. }
  508.  
  509. void get2()
  510. {
  511.     mi=1;
  512.     lop=getbyte();
  513.     lval=value;
  514.     if ((lop==6)||(lop==7)) mi++;
  515.     if (lval>255) cleanexit("Left operator value > 255.");
  516.     if (s[0]!=',')
  517.         cleanexit("This statement needs two operands.");
  518.     hack(1);
  519.     rop=getbyte();
  520.     rval=value;
  521.     if ((rop==6)||(rop==7)) mi++;
  522.     if (rval>255) cleanexit("Right operator value > 255.");
  523.     return;
  524. }
  525.  
  526. void get1()
  527. {
  528.     mi=1;
  529.     lop=getbyte();
  530.     lval=value;
  531.     if ((lop==6)||(lop==7)) mi++;
  532.     if (lval>255) cleanexit("Operator value > 255.");
  533.     return;
  534. }
  535.  
  536. void addr11()
  537. {
  538.     lop=getbyte();
  539.     if (lop!=7) cleanexit("Operand must be an address.");
  540.     if (pass==1) {value=0;return;}
  541.     if ((value&63488)!=(addr&63488))
  542.         cleanexit("11 bit address out of range.");
  543.     value&=2047;
  544.     return;
  545. }
  546.  
  547. void addr16()
  548. {
  549.     lop=getbyte();
  550.     if (lop!=7) cleanexit("Operand must be an address.");
  551.     return;
  552. }
  553.  
  554. void data16()
  555. {
  556.     lop=getbyte();
  557.     if (lop!=6) cleanexit("Operand must be data.");
  558.     return;
  559. }
  560.  
  561. int getrel()
  562. {
  563.     int x,r;
  564.     x=getbyte();
  565.     if (x!=7) cleanexit("Operand must be an address.");
  566.     if (pass==1) {return(0);} 
  567.     r=realvalue-(addr+mi);
  568.     if (r<-128) cleanexit("Relative offset < -128.");
  569.     if (r>127) cleanexit("Relative offset > 127.");
  570.     if (r<0) r+=256;
  571.     return(r);
  572. }
  573.  
  574.  
  575. void ljmp()
  576. {
  577.     hack(5);
  578.     addr16();
  579.     hexs(02*65536+value);
  580.     codeit(hexstr);
  581.     addr+=3;
  582. }
  583.  
  584. void form0(n)
  585. int n;
  586. {
  587.     mi=2;
  588.     hexs(n*256+getrel());
  589.     codeit(hexstr);
  590.     addr+=mi;
  591. }
  592.  
  593. void sjmp()
  594. {
  595.     hack(5);
  596.     form0(128);
  597. }
  598.  
  599. jc()
  600. {
  601.     hack(3);
  602.     form0(64);
  603. }
  604.  
  605. jnc()
  606. {
  607.     hack(4);
  608.     form0(80);
  609. }
  610.  
  611. void form1(n)
  612. int n;
  613. {
  614.     get1();
  615.     mi++;
  616.     if (lop!=7) cleanexit("Left operand must be bit address.");
  617.     if (s[0]!=',') cleanexit("This command needs two operands.");
  618.     hack(1);
  619.     hexs(n*65536+lval*256+getrel());
  620.     codeit(hexstr);
  621.     addr+=mi;
  622. }
  623.  
  624. void jb()
  625. {
  626.     hack(3);
  627.     form1(32);
  628. }
  629.  
  630. void jnb()
  631. {
  632.     hack(4);
  633.     form1(48);
  634. }
  635.  
  636. void jbc()
  637. {
  638.     hack(4);
  639.     form1(16);
  640. }
  641.     
  642. void form2(n)
  643. int n;
  644. {
  645.     int x,y;
  646.     addr11();
  647.     x=(value/256)<<5;
  648.     x+=n;
  649.     y=(value%256);
  650.     hexs(x*256+y);
  651.     codeit(hexstr);
  652.     addr+=2;
  653. }
  654.  
  655. void ajmp()
  656. {
  657.     hack(5);
  658.     form2(1);
  659.     }
  660.  
  661. void acall()
  662. {
  663.     hack(6);
  664.     form2(17);
  665. }
  666.  
  667. void lcall()
  668. {
  669.     hack(6);
  670.     addr16();
  671.     hexs(18*65536+value);
  672.     codeit(hexstr);
  673.     addr+=3;
  674. }
  675.  
  676. void jz()
  677. {
  678.     hack(3);
  679.     form0(96);
  680. }
  681.  
  682. void jnz()
  683. {
  684.     hack(4);
  685.     form0(112);
  686. }
  687.  
  688. void djnz()
  689. {
  690.     hack(5);
  691.     get1();
  692.     if (s[0]!=',') cleanexit("This statement needs two operands.");
  693.     hack(1);
  694.     mi++;
  695.     if (lop==7)
  696.     {
  697.         hexs(213*65536+lval*256+getrel());
  698.         codeit(hexstr);
  699.         addr+=mi;
  700.         return;
  701.     }
  702.     if ((lop>=10)&&(lop<=17))
  703.     {
  704.         hexs((216-10+lop)*256+getrel());
  705.         codeit(hexstr);
  706.         addr+=mi;
  707.         return;
  708.     }
  709.     cleanexit("Left operand must be a direct addr or Rn.");
  710. }
  711.  
  712. void cjne()
  713. {
  714.     hack(5);
  715.     get2();
  716.     if (s[0]!=',') cleanexit("This statement needs 3 operands.");
  717.     hack(1);
  718.     mi++;
  719.     if (lop==1)
  720.     {
  721.         if (rop==6)
  722.         {
  723.             hexs(180*65536+rval*256+getrel());
  724.             codeit(hexstr);
  725.             addr+=mi;
  726.             return;
  727.         }
  728.         if (rop==7)
  729.         {
  730.             hexs(181*65536+rval*256+getrel());
  731.             codeit(hexstr);
  732.             addr+=mi;
  733.             return;
  734.         }
  735.         cleanexit("Middle operand must be # or $.");
  736.     }
  737.     if ((lop>=8)&&(lop<=17))
  738.     {
  739.         if (rop!=6) cleanexit("Middle operand must be #.");
  740.         hexs((182-8+lop)*65536+rval*256+getrel());
  741.         codeit(hexstr);
  742.         addr+=mi;
  743.         return;
  744.     }
  745.     cleanexit("Left operand must be A,@Ri, or Rn.");
  746. }
  747.  
  748. void movdptr()
  749. {
  750.     hack(8);
  751.     if (s[0]!=',') cleanexit("Comma needed.");
  752.     hack(1);
  753.     data16();
  754.     hexs(144*65536+value);
  755.     codeit(hexstr);
  756.     addr+=3;
  757.     return;
  758. }
  759.  
  760. void form4(n)
  761. int n;
  762. {
  763.     get2();
  764.     if (lop!=1) cleanexit("Left operand must be A.");
  765.     if ((rop>=6)&&(rop<=17))
  766.     {
  767.         hexs(n-6+rop);
  768.         if ((rop==6)||(rop==7))
  769.         {
  770.             hexs((n-6+rop)*256+rval);
  771.         }
  772.         codeit(hexstr);
  773.         addr+=mi;
  774.         return;
  775.     }
  776.     cleanexit("Right operand must be #,$,@Ri, or Rn.");
  777. }
  778.  
  779. void addc()
  780. {
  781.     hack(5);
  782.     form4(52);
  783. }
  784.  
  785. void add()
  786. {
  787.     hack(4);
  788.     form4(36);
  789. }
  790.  
  791. void subb()
  792. {
  793.     hack(5);
  794.     form4(148);
  795. }
  796.  
  797. void inc()
  798. {
  799.     hack(4);
  800.     get1();
  801.     if (lop==1) lop=6;
  802.     if ((lop>=6)&&(lop<=17))
  803.     {
  804.         hexs(4-6+lop);
  805.         if (lop==7)
  806.             hexs((4-6+lop)*256+lval);
  807.         codeit(hexstr);
  808.         addr+=mi;
  809.         return;
  810.     }
  811.     if (lop==4)
  812.     {
  813.         hexs(163);
  814.         codeit(hexstr);
  815.         addr+=mi;
  816.         return;
  817.     }
  818.     cleanexit("Operand must be A,$,@Ri, Rn, or DPTR.");
  819. }
  820.  
  821. void dec()
  822. {
  823.     hack(4);
  824.     get1();
  825.     if (lop==1) lop=6;
  826.     if ((lop>=6)&&(lop<=17))
  827.     {
  828.         hexs(20-6+lop);
  829.         if (lop==7)
  830.             hexs((20-6+lop)*256+lval);
  831.         codeit(hexstr);
  832.         addr+=mi;
  833.         return;
  834.     }
  835.     cleanexit("Operand must be A,$,@Ri, or Rn.");
  836. }
  837.  
  838. void mul()
  839. {
  840.     hack(4);
  841.     get1();
  842.     if (lop!=18) cleanexit("Operand must be AB.");
  843.     hexs(164);
  844.     codeit(hexstr);
  845.     addr++;
  846. }
  847.  
  848. void div()
  849. {
  850.     hack(4);
  851.     get1();
  852.     if (lop!=18) cleanexit("Operand must be AB.");
  853.     hexs(132);
  854.     codeit(hexstr);
  855.     addr++;
  856. }
  857.  
  858. void da()
  859. {
  860.     hack(3);
  861.     get1();
  862.     if (lop!=1) cleanexit("Operand must be A.");
  863.     hexs(212);
  864.     codeit(hexstr);
  865.     addr++;
  866. }
  867.  
  868. void form5(n,m,o,p)
  869. int n;
  870. int m;
  871. int o;
  872. int p;
  873. {
  874.     get2();
  875.     if (lop==1)
  876.     {
  877.         if ((rop>=6)&&(rop<=17))
  878.         {
  879.             hexs(n-8+rop);
  880.             if ((rop==6)||(rop==7))
  881.                 hexs((m-6+rop)*256+rval);
  882.             codeit(hexstr);
  883.             addr+=mi;
  884.             return;
  885.         }
  886.         cleanexit("Right OP must be #,$,@Ri, or Rn.");
  887.     }
  888.     if (lop==7)
  889.     {
  890.         if (rop==1)
  891.         {
  892.             hexs(o*256+lval);
  893.             codeit(hexstr);
  894.             addr+=mi;
  895.             return;
  896.         }
  897.         if (rop==6)
  898.         {
  899.             hexs((o+1)*65536+lval*256+rval);
  900.             codeit(hexstr);
  901.             addr+=mi;
  902.             return;
  903.         }
  904.         cleanexit("Right operand must be A or #.");
  905.     }
  906.     if (lop==3)
  907.     {
  908.         if (rop==7)
  909.         {
  910.             hexs(p*256+rval);
  911.             codeit(hexstr);
  912.             addr+=mi;
  913.             return;
  914.         }
  915.         cleanexit("Right operand must be bit address.");
  916.     }
  917.     cleanexit("Left operand must be A, C, or $.");
  918. }
  919.  
  920. void orl()
  921. {
  922.     hack(4);
  923.     form5(70,68,66,114);
  924. }
  925.  
  926. void anl()
  927. {
  928.     hack(4);
  929.     form5(86,84,82,130);
  930. }
  931.  
  932. void xrl()
  933. {
  934.     hack(4);
  935.     get2();
  936.     if (lop==1)
  937.     {
  938.         if ((rop>=6)&&(rop<=17))
  939.         {
  940.             hexs(100-6+rop);
  941.             if ((rop==6)||(rop==7))
  942.                 hexs((100-6+rop)*256+rval);
  943.             codeit(hexstr);
  944.             addr+=mi;
  945.             return;
  946.         }
  947.         cleanexit("Right OP must be #,$,@Ri, or Rn.");
  948.     }
  949.     if (lop==7)
  950.     {
  951.         if (rop==1)
  952.         {
  953.             hexs(98*256+lval);
  954.             codeit(hexstr);
  955.             addr+=mi;
  956.             return;
  957.         }
  958.         if (rop==6)
  959.         {
  960.             hexs(99*65536+lval*256+rval);
  961.             codeit(hexstr);
  962.             addr+=mi;
  963.             return;
  964.         }
  965.         cleanexit("Right operand must be A or #.");
  966.     }
  967.     cleanexit("Left operand must be A or $.");
  968. }
  969.  
  970. void form6(n,m,o)
  971. int m,n,o;
  972. {
  973.     get1();
  974.     if (lop==1)
  975.     {
  976.         hexs(n);
  977.         codeit(hexstr);
  978.         addr++;
  979.         return;
  980.     }
  981.     if (lop==3)
  982.     {
  983.         hexs(m);
  984.         codeit(hexstr);
  985.         addr++;
  986.         return;
  987.     }
  988.     if (lop==7)
  989.     {
  990.         hexs(o*256+lval);
  991.         codeit(hexstr);
  992.         addr+=2;
  993.         return;
  994.     }
  995.     cleanexit("Operand must be A, C, or $.");
  996. }
  997.  
  998. void clr()
  999. {
  1000.     hack(4);
  1001.     form6(228,195,194);
  1002. }
  1003.  
  1004. void cpl()
  1005. {
  1006.     hack(4);
  1007.     form6(244,179,178);
  1008. }
  1009.  
  1010. void setb()
  1011. {
  1012.     hack(5);
  1013.     get1();
  1014.     if (lop==3)
  1015.     {
  1016.         hexs(211);
  1017.         codeit(hexstr);
  1018.         addr++;
  1019.         return;
  1020.     }
  1021.     if (lop==7)
  1022.     {
  1023.         hexs(210*256+lval);
  1024.         codeit(hexstr);
  1025.         addr+=2;
  1026.         return;
  1027.     }
  1028.     cleanexit("Operand must be C or $.");
  1029. }
  1030.  
  1031. void form7(n)
  1032. int n;
  1033. {
  1034.     get1();
  1035.     if (lop!=1) cleanexit("Operand must be A.");
  1036.     hexs(n);
  1037.     codeit(hexstr);
  1038.     addr++;
  1039. }
  1040.  
  1041. void rl()
  1042. {
  1043.     hack(3);
  1044.     form7(35);
  1045. }
  1046.  
  1047. void rlc()
  1048. {
  1049.     hack(4);
  1050.     form7(51);
  1051. }
  1052.  
  1053. void rr()
  1054. {
  1055.     hack(3);
  1056.     form7(3);
  1057. }
  1058.  
  1059. void rrc()
  1060. {
  1061.     hack(4);
  1062.     form7(19);
  1063. }
  1064.  
  1065. void swap()
  1066. {
  1067.     hack(5);
  1068.     form7(196);
  1069. }
  1070.  
  1071. void mov()
  1072. {
  1073.     hack(4);
  1074.     get2();
  1075.     if (lop==1)
  1076.     {
  1077.         if ((rop>=7)&&(rop<=17))
  1078.         {
  1079.             hexs(229-7+rop);
  1080.             if (rop==7)
  1081.                 hexs(229*256+rval);
  1082.             codeit(hexstr);
  1083.             addr+=mi;
  1084.             return;
  1085.         }
  1086.         if (rop==6)
  1087.         {
  1088.             hexs(116*256+rval);
  1089.             codeit(hexstr);
  1090.             addr+=mi;
  1091.             return;
  1092.         }
  1093.         cleanexit("Right operand must be #,$,@Ri, or Rn.");
  1094.     }
  1095.     if ((lop>=8)&&(lop<=17))
  1096.     {
  1097.         if (rop==1)
  1098.         {
  1099.             hexs(245-8+lop);
  1100.             if (lop==7)
  1101.                 hexs((245-8+lop)*256+rval);
  1102.             codeit(hexstr);
  1103.             addr+=mi;
  1104.             return;
  1105.         }
  1106.         if (rop==7)
  1107.         {
  1108.             hexs((166-8+lop)*256+rval);
  1109.             codeit(hexstr);
  1110.             addr+=mi;
  1111.             return;
  1112.         }
  1113.         if (rop==6)
  1114.         {
  1115.             hexs((118-8+lop)*256+rval);
  1116.             codeit(hexstr);
  1117.             addr+=mi;
  1118.             return;
  1119.         }
  1120.         cleanexit("Right operand must be A,#, or $.");
  1121.     }
  1122.     if (lop==7)
  1123.     {
  1124.         if ((rop>=7)&&(rop<=17))
  1125.         {
  1126.             hexs((133-7+rop)*256+lval);
  1127.             if (rop==7)
  1128.                 hexs(133*65536+lval*256+rval);
  1129.             codeit(hexstr);
  1130.             addr+=mi;
  1131.             return;
  1132.         }
  1133.         if (rop==6)
  1134.         {
  1135.             hexs(117*65536+lval*256+rval);
  1136.             codeit(hexstr);
  1137.             addr+=mi;
  1138.             return;
  1139.         }
  1140.         if (rop==3)
  1141.         {
  1142.             hexs(146*256+lval);
  1143.             codeit(hexstr);
  1144.             addr+=mi;
  1145.             return;
  1146.         }
  1147.         if (rop==1)
  1148.         {
  1149.             hexs(245*256+lval);
  1150.             codeit(hexstr);
  1151.             addr+=mi;
  1152.             return;
  1153.         }
  1154.         cleanexit("Right operand must be #,$, @Ri, or Rn.");
  1155.     }
  1156.     if (lop==3)
  1157.     {
  1158.         if (rop!=7) cleanexit("Right operand must be bit addr.");
  1159.         hexs(162*256+rval);
  1160.         codeit(hexstr);
  1161.         addr+=mi;
  1162.         return;
  1163.     }
  1164.     cleanexit("Left operand must be A,$, or C.");
  1165. }
  1166.  
  1167. void movx()
  1168. {
  1169.     hack(5);
  1170.     get2();
  1171.     if (lop==1)
  1172.     {
  1173.         if (rop==5)
  1174.         {
  1175.             hexs(224);
  1176.             codeit(hexstr);
  1177.             addr++;
  1178.             return;
  1179.         }
  1180.         if (rop==8)
  1181.         {
  1182.             hexs(226);
  1183.             codeit(hexstr);
  1184.             addr++;
  1185.             return;
  1186.         }
  1187.         if (rop==9)
  1188.         {
  1189.             hexs(227);
  1190.             codeit(hexstr);
  1191.             addr++;
  1192.             return;
  1193.         }
  1194.         cleanexit("Right operand must be @Ri, or @DPTR.");
  1195.     }
  1196.     if (lop==5)
  1197.     {
  1198.         if (rop!=1) cleanexit("Right OP must be A.");
  1199.         hexs(240);
  1200.         codeit(hexstr);
  1201.         addr++;
  1202.         return;
  1203.     }
  1204.     if (lop==8)
  1205.     {
  1206.         if (rop!=1) cleanexit("Right OP must be A.");
  1207.         hexs(242);
  1208.         codeit(hexstr);
  1209.         addr++;
  1210.         return;
  1211.     }
  1212.     if (lop==9)
  1213.     {
  1214.         if (rop!=1) cleanexit("Right OP must be A.");
  1215.         hexs(243);
  1216.         codeit(hexstr);
  1217.         addr++;
  1218.         return;
  1219.     }
  1220.     cleanexit("Left operand must be A,@Ri, or @DPTR.");
  1221. }
  1222.  
  1223. void pop()
  1224. {
  1225.     hack(4);
  1226.     get1();
  1227.     if (lop!=7) cleanexit("Operand must be direct byte.");
  1228.     hexs(208*256+lval);
  1229.     codeit(hexstr);
  1230.     addr+=mi;
  1231. }
  1232.  
  1233. void push()
  1234. {
  1235.     hack(5);
  1236.     get1();
  1237.     if (lop!=7) cleanexit("Operand must be direct byte.");
  1238.     hexs(192*256+lval);
  1239.     codeit(hexstr);
  1240.     addr+=mi;
  1241. }
  1242.  
  1243. void form8(n)
  1244. int n;
  1245. {
  1246.     hexs(n);
  1247.     codeit(hexstr);
  1248.     addr++;
  1249.     return;
  1250. }
  1251.  
  1252. void ret()
  1253. {
  1254.     hack(3);
  1255.     form8(34);
  1256. }
  1257.  
  1258. void reti()
  1259. {
  1260.     hack(4);
  1261.     form8(50);
  1262. }
  1263.  
  1264. void nop()
  1265. {
  1266.     hack(3);
  1267.     form8(0);
  1268. }
  1269.  
  1270. void xch()
  1271. {
  1272.     hack(4);
  1273.     get2();
  1274.     if (lop!=1) cleanexit("Left operand must be A.");
  1275.     if ((rop>=7)&&(rop<=17))
  1276.     {
  1277.         hexs(197-7+rop);
  1278.         if (rop==7) hexs((197-7+rop)*256+rval);
  1279.         codeit(hexstr);
  1280.         addr+=mi;
  1281.         return;
  1282.     }
  1283.     cleanexit("Right operand must be $,@Ri, or Rn.");
  1284. }
  1285.  
  1286. void xchd()
  1287. {
  1288.     hack(5);
  1289.     get2();
  1290.     if (lop!=1) cleanexit("Left operand must be A.");
  1291.     if ((rop>=8)&&(rop<=17))
  1292.     {
  1293.         hexs(214-8+rop);
  1294.         codeit(hexstr);
  1295.         addr++;
  1296.         return;
  1297.     }
  1298.     cleanexit("Right operand must be @Ri.");
  1299. }
  1300.  
  1301. void movcadptr()
  1302. {
  1303.     hack(14);
  1304.     hexs(147);
  1305.     codeit(hexstr);
  1306.     addr++;
  1307. }
  1308.  
  1309. void movcapc()
  1310. {
  1311.     hack(12);
  1312.     hexs(131);
  1313.     codeit(hexstr);
  1314.     addr++;
  1315. }
  1316.  
  1317. void jmpadptr()
  1318. {
  1319.     hack(11);
  1320.     hexs(115);
  1321.     codeit(hexstr);
  1322.     addr++;
  1323. }
  1324.  
  1325. void opcode()
  1326. {
  1327.     if (strncmp(s,"ADDC ",5)==0) {addc();return;}
  1328.     if (strncmp(s,"ADD ",4)==0) {add();return;}
  1329.     if (strncmp(s,"SUBB ",5)==0) {subb();return;}
  1330.     if (strncmp(s,"INC ",4)==0) {inc();return;}
  1331.     if (strncmp(s,"DEC ",4)==0) {dec();return;}
  1332.     if (strncmp(s,"MUL ",4)==0) {mul();return;}
  1333.     if (strncmp(s,"DIV ",4)==0) {div();return;}
  1334.     if (strncmp(s,"DA ",3)==0) {da();return;}
  1335.     if (strncmp(s,"ANL ",4)==0) {anl();return;}
  1336.     if (strncmp(s,"ORL ",4)==0) {orl();return;}
  1337.     if (strncmp(s,"XRL ",4)==0) {xrl();return;}
  1338.     if (strncmp(s,"CPL ",4)==0) {cpl();return;}
  1339.     if (strncmp(s,"RLC ",4)==0) {rlc();return;}
  1340.     if (strncmp(s,"RR ",3)==0) {rr();return;}
  1341.     if (strncmp(s,"RRC ",4)==0) {rrc();return;}
  1342.     if (strncmp(s,"RL ",3)==0) {rl();return;}
  1343.     if (strncmp(s,"SWAP ",5)==0) {swap();return;}
  1344.     if (strncmp(s,"MOVX ",5)==0) {movx();return;}
  1345.     if (strncmp(s,"MOV DPTR",8)==0) {movdptr();return;}
  1346.     if (strncmp(s,"MOVC A,@A+DPTR",14)==0) {movcadptr();return;}
  1347.     if (strncmp(s,"MOVC A,@A+PC",12)==0) {movcapc();return;}
  1348.     if (strncmp(s,"JMP @A+DPTR",11)==0) {jmpadptr();return;}
  1349.     if (strncmp(s,"MOV ",4)==0) {mov();return;}
  1350.     if (strncmp(s,"PUSH ",5)==0) {push();return;}
  1351.     if (strncmp(s,"POP ",4)==0) {pop();return;}
  1352.     if (strncmp(s,"XCHD ",5)==0) {xchd();return;}
  1353.     if (strncmp(s,"XCH ",4)==0) {xch();return;}
  1354.     if (strncmp(s,"CLR ",4)==0) {clr();return;}
  1355.     if (strncmp(s,"SETB ",5)==0) {setb();return;}
  1356.     if (strncmp(s,"JC ",3)==0) {jc();return;}
  1357.     if (strncmp(s,"JNC ",4)==0) {jnc();return;}
  1358.     if (strncmp(s,"JNB ",4)==0) {jnb();return;}
  1359.     if (strncmp(s,"JBC ",4)==0) {jbc();return;}
  1360.     if (strncmp(s,"JB ",3)==0) {jb();return;}
  1361.     if (strncmp(s,"ACALL ",6)==0) {acall();return;}
  1362.     if (strncmp(s,"LCALL ",6)==0) {lcall();return;}
  1363.     if (strncmp(s,"RETI",4)==0) {reti();return;}
  1364.     if (strncmp(s,"RET",3)==0) {ret();return;}
  1365.     if (strncmp(s,"SJMP ",5)==0) {sjmp();return;}
  1366.     if (strncmp(s,"LJMP ",5)==0) {ljmp();return;}
  1367.     if (strncmp(s,"AJMP ",5)==0) {ajmp();return;}
  1368.     if (strncmp(s,"JZ ",3)==0) {jz();return;}
  1369.     if (strncmp(s,"JNZ ",4)==0) {jnz();return;}
  1370.     if (strncmp(s,"CJNE ",5)==0) {cjne();return;}
  1371.     if (strncmp(s,"DJNZ ",5)==0) {djnz();return;}
  1372.     if (strncmp(s,"NOP",3)==0) {nop();return;}
  1373.     if ((s[0]>32)&&(s[0]<127)) 
  1374.         warn("Syntax Error.");
  1375.     return;
  1376. }
  1377.  
  1378. void assemble()
  1379. {
  1380.     int x,y;
  1381.     while (s[0]==' ') hack(1);
  1382.     if (s[0]==';') {codeit("  **"); return;}
  1383.     y=(-1); x=0;
  1384.     do
  1385.     {
  1386.         if (s[x]==';')        
  1387.             y=x;
  1388.         x++;
  1389.     } while ((x<=pos)&&(y<0));
  1390.     if (y>=0)
  1391.     {
  1392.         s[y]='\0';
  1393.         pos=y;
  1394.     }
  1395.  
  1396.     while (s[0]==':')
  1397.     {
  1398.     warn (": at beginning of line.");
  1399.     hack(1);
  1400.     }
  1401.     
  1402.     for (x=0;x<=pos;x++)
  1403.         if (s[x]==':')
  1404.         {
  1405.             if (pass==1) gettag(x);
  1406.             else hack(x+1);
  1407.             while (s[0]==' ') hack(1);
  1408.             if (s[0]=='\0') codeit(" --]");
  1409.         }
  1410.     while (s[0]==' ') hack(1);    
  1411.     if (s[0]=='.') {getdirec();return;}
  1412.     opcode();
  1413.     return;
  1414. }
  1415.  
  1416. int getline()
  1417. {
  1418.     int x;
  1419.     x=0;
  1420.     while ((c=fgetc(f))<32)
  1421.     {
  1422.         if (c=='\n')
  1423.              {strcpy(buffer,"    ");line++;codeit("     ");}
  1424.         if (c==EOF) return(-1);
  1425.     }
  1426.     buffer[x++]=c;
  1427.     while ((c=fgetc(f))!='\n')
  1428.         buffer[x++]=c;
  1429.     buffer[x]='\0';
  1430.     return(x);
  1431. }
  1432.  
  1433. void main(argc,argv)
  1434. int argc;
  1435. char *argv[];
  1436. {
  1437.     int n,x,y,last,white;
  1438.     char filename[80];
  1439.     LINK tl;
  1440.     tag_list=(LINK) NULL;
  1441.     printf("8051 assembler by Eric Rudolph, 1991. Version 1.\n");
  1442.     strcpy(basename,argv[1]);
  1443.     strcpy(filename,basename);
  1444.     f=fopen("a51.equ","r");
  1445.     if (f==(FILE *) NULL)
  1446.         printf("Could not find asm.equ file.\n");
  1447.     else
  1448.         do
  1449.         {
  1450.             fscanf(f,"%s",name);
  1451.             fscanf(f,"%d",&value);
  1452.             if (value>0) add_tag(value);
  1453.         } while (value>0);
  1454.     for (x=0;x<32767;x++)
  1455.         mem[x]=0;
  1456.     
  1457.     f=fopen(filename,"r");
  1458.     hexsflag=0;
  1459.     if (f!=(FILE *) NULL)
  1460.     {
  1461.         printf("PASS1\n");
  1462.         addr=0;pass=1;line=0;
  1463.         do
  1464.         {
  1465.             n=getline();
  1466.             if (n>0)
  1467.             {
  1468.                 line++;
  1469.                 y=0;
  1470.                 last=1;
  1471.                 for (x=0;x<=n;x++)
  1472.                 {
  1473.                     white=0;
  1474. if ((buffer[x]==' ')||(buffer[x]=='\t'))
  1475.     white=1;
  1476. if ((white==1)&&(last==0))
  1477.     s[y++]=' ';
  1478. if (white==0)
  1479. {
  1480.     s[y]=buffer[x];
  1481.     if ((buffer[x]>='a')&&(buffer[x]<='z')) s[y]-=32;
  1482.     y++;
  1483. }
  1484.                     last=white;
  1485.                 }
  1486.                 pos=strlen(s);
  1487.                 if (s[pos-1]==' ') {s[pos-1]='\0';pos--;}
  1488.                 assemble();
  1489.             }
  1490.         } while (n>=1);
  1491.         fclose(f);
  1492.         printf("PASS2\n");
  1493.         f=fopen(filename,"r");
  1494.         strcat(filename,".lst");
  1495.         f_lst=fopen(filename,"w");
  1496.         if (f_lst==(FILE *) NULL) cleanexit("Can't open .lst for write.");
  1497.         addr=0;pass=2;line=0;
  1498.         do
  1499.         {
  1500.             n=getline();
  1501.             if (n>0)
  1502.                 {
  1503.                 line++;
  1504.                 y=0;
  1505.                 last=1;
  1506.                 for (x=0;x<=n;x++)
  1507.                 {
  1508.                     white=0;
  1509. if ((buffer[x]==' ')||(buffer[x]=='\t'))
  1510.     white=1;
  1511. if ((white==1)&&(last==0))
  1512.     s[y++]=' ';
  1513. if (white==0)
  1514. {
  1515.     s[y]=buffer[x];
  1516.     if ((buffer[x]>='a')&&(buffer[x]<='z')) s[y]-=32;
  1517.     y++;
  1518. }
  1519.                     last=white;
  1520.                 }
  1521.                 pos=strlen(s);
  1522.                 if (s[pos-1]==' ') {s[pos-1]='\0';pos--;}
  1523.                 assemble();
  1524.             }
  1525.         } while (n>=1);
  1526.         fprintf(f_lst,"=============================\n");
  1527.         tl=tag_list;
  1528.         x=0;
  1529.         hexsflag=0;
  1530.         while (tl!=(LINK) NULL)
  1531.         {
  1532.             if (x==0) fprintf(f_lst,"\n");
  1533.             else fprintf(f_lst,"\t");
  1534.             hexs(tl->value);
  1535.             fprintf(f_lst,"%s\t%s",tl->tag,hexstr);
  1536.             tl=tl->next;
  1537.         }
  1538.         fprintf(f_lst,"\n\n");
  1539.         fclose(f_lst);
  1540.         showcode();
  1541.         printf("END OF ASSEMBLY.\n");
  1542.     }
  1543.     else 
  1544.         printf("No such file.\n");
  1545.     
  1546. }
  1547.  
  1548. @\Rogue\Monster\
  1549. else
  1550.   echo "shar: Will not over write a51.c"
  1551. fi
  1552. if `test ! -s a51.doc`
  1553. then
  1554. echo "x - a51.doc"
  1555. cat > a51.doc << '@\Rogue\Monster\'
  1556. This is an 8031/8051 assembler.
  1557.  
  1558. This assembler is a simple one, I think. It includes little error checking
  1559. but it does work on programs that are correctly written. It will bomb out
  1560. of assembling on any error. Usually when compling programs anyhow, the
  1561. rest of the errors are useless anyhow. It is not "case sensative".
  1562.  
  1563. This assembler has several directives:
  1564.  
  1565.     .org exp    ;start address at exp.
  1566.     .equ exp,exp    ;equate left expression to right one.
  1567.     .db exp        ;define byte of expression
  1568.     .dw exp        ;define word.
  1569.     .rs exp        ;reserve exp bytes of space
  1570.     .dm exp        ;define message. Put in single quotes.
  1571.     .end exp    ;end assembly. Start address=exp
  1572.  
  1573. "exp" is either a string constant or a number, or a math function of both.
  1574. Either way, the resulting expression must be a constant. I.e. No registers.
  1575. Is that clear? (I am not good at documentation!) 
  1576.  
  1577. string names, called "tags" can be up to 80 characters in length, but each
  1578. line can ONLY be 80 characters long, so it's probably best to make them a
  1579. little shorter than 80.
  1580.  
  1581. This compiler supports addition, subtraction, and multiplication of 
  1582. constants. Plus, any character within single quotes will be treated as the
  1583. ASCII decimal equivalent. I.e. 'A'=65.
  1584.  
  1585. numerical constants can be specified in one of three ways, not including the
  1586. character constant. Decimal, Hexidecimal, and Binary are all supported.
  1587. Both H'xxx and 0xxxH and B'xxx and 0xxxB are supported. My favorite is 0xxxH.
  1588. If the trailing H is used in hexidecimal format, like most compilers, if the
  1589. first number is a alphabet character (A-F) it must be preceded with a 0.
  1590.  
  1591. The full 8051 instruction set it translated in this assembler EXCEPT for
  1592. 1. ANL c,/bit and 2. ORL c,/bit. Oh well!
  1593.  
  1594. To use this assembler, first compile it with "cc a51.c -o a51"
  1595. The compiler must be able to handle arrays of 32k long. With this capability,
  1596. you can have programs with an ADDRESS SPACE OF 0-8000 HEX! Addresses
  1597. farther than this will cause the program to BOMB. If your compiler can
  1598. handle it, change the array bounds in a51.h to 64k and all limiting
  1599. references to 32k in the program to 64k. I can't imagine a 32k program on
  1600. the 8051 myself...
  1601.  
  1602. To use the program, type "a51 filename" The assembler will generate two
  1603. files, a filename.lst file and a filename.hex file. 
  1604.     The .lst file will contain a listing of your program with the code
  1605. beside it followed by a table of tags that were defined.
  1606.     The .hex file will contain all the object code that is in your program
  1607. but no checksums, since I don't know how to do that. (any ideas?)
  1608.  
  1609. To make life easy, the assembler comes with an additional file, "a51.equ"
  1610. that has predefined tags with thier values. This file must end with a negative
  1611. number as a delimiter. Feel free to add your own equates if you want. It will
  1612. work the same.
  1613.  
  1614. Negative numbers are treated as two's complement. Always. If the number is
  1615. negative and greater than -256, it is treated as a byte.
  1616. If the number is negative and less than -255 (like -256) it is treated as
  1617. a word. Remember this! It's probably best not even to use negative 
  1618. constants. Figure them out yourself and compliment them. Just to make sure,
  1619. check the code listing and see if it's right.
  1620.  
  1621. rem statements are preceded by semicolons. 
  1622.  
  1623. Example programs foo and foo2 are included to show a couple of the features.
  1624.  
  1625. Questions? Complaints? Bugs?
  1626.  
  1627. rudolpe@jacobs.cs.orst.edu (503-745-7466)
  1628.  
  1629. @\Rogue\Monster\
  1630. else
  1631.   echo "shar: Will not over write a51.doc"
  1632. fi
  1633. if `test ! -s a51.equ`
  1634. then
  1635. echo "x - a51.equ"
  1636. cat > a51.equ << '@\Rogue\Monster\'
  1637. ACC
  1638. 224
  1639. ACC.0
  1640. 224
  1641. ACC.1
  1642. 225
  1643. ACC.2
  1644. 226
  1645. ACC.3
  1646. 227
  1647. ACC.4
  1648. 228
  1649. ACC.5
  1650. 229
  1651. ACC.6
  1652. 230
  1653. ACC.7
  1654. 231
  1655. B
  1656. 240
  1657. B.0
  1658. 240
  1659. B.1
  1660. 241
  1661. B.2
  1662. 242
  1663. B.3
  1664. 243
  1665. B.4
  1666. 244
  1667. B.5
  1668. 245
  1669. B.6
  1670. 246
  1671. B.7
  1672. 247
  1673. PSW
  1674. 208
  1675. PSW.0
  1676. 208
  1677. PSW.1
  1678. 209
  1679. PSW.2
  1680. 210
  1681. PSW.3
  1682. 211
  1683. PSW.4
  1684. 212
  1685. PSW.5
  1686. 213
  1687. PSW.6
  1688. 214
  1689. PSW.7
  1690. 215
  1691. P0
  1692. 128
  1693. P0.0
  1694. 128
  1695. P0.1
  1696. 129
  1697. P0.2
  1698. 130
  1699. P0.3
  1700. 131
  1701. P0.4
  1702. 132
  1703. P0.5
  1704. 133
  1705. P0.6
  1706. 134
  1707. P0.7
  1708. 135
  1709. TCON
  1710. 136
  1711. TCON.0
  1712. 136
  1713. TCON.1
  1714. 137
  1715. TCON.2
  1716. 138
  1717. TCON.3
  1718. 139
  1719. TCON.4
  1720. 140
  1721. TCON.5
  1722. 141
  1723. TCON.6
  1724. 142
  1725. TCON.7
  1726. 143
  1727. P1
  1728. 144
  1729. P1.0
  1730. 144
  1731. P1.1
  1732. 145
  1733. P1.2
  1734. 146
  1735. P1.3
  1736. 147
  1737. P1.4
  1738. 148
  1739. P1.5
  1740. 149
  1741. P1.6
  1742. 150
  1743. P1.7
  1744. 151
  1745. SCON
  1746. 152
  1747. SCON.0
  1748. 152
  1749. SCON.1
  1750. 153
  1751. SCON.2
  1752. 154
  1753. SCON.3
  1754. 155
  1755. SCON.4
  1756. 156
  1757. SCON.5
  1758. 157
  1759. SCON.6
  1760. 158
  1761. SCON.7
  1762. 159
  1763. P2
  1764. 160
  1765. P2.0
  1766. 160
  1767. P2.1
  1768. 161
  1769. P2.2
  1770. 162
  1771. P2.3
  1772. 163
  1773. P2.4
  1774. 164
  1775. P2.5
  1776. 165
  1777. P2.6
  1778. 166
  1779. P2.7
  1780. 167
  1781. IE
  1782. 168
  1783. IE.0
  1784. 168
  1785. IE.1
  1786. 169
  1787. IE.2
  1788. 170
  1789. IE.3
  1790. 171
  1791. IE.4
  1792. 172
  1793. IE.5
  1794. 173
  1795. IE.6
  1796. 174
  1797. IE.7
  1798. 175
  1799. P3
  1800. 176
  1801. P3.0
  1802. 176
  1803. P3.1
  1804. 177
  1805. P3.2
  1806. 178
  1807. P3.3
  1808. 179
  1809. P3.4
  1810. 180
  1811. P3.5
  1812. 181
  1813. P3.6
  1814. 182
  1815. P3.7
  1816. 183
  1817. SBUF
  1818. 153
  1819. TMOD
  1820. 137
  1821. TL0
  1822. 138
  1823. TL1
  1824. 139
  1825. TH0
  1826. 140
  1827. TH1
  1828. 141
  1829. SP
  1830. 129
  1831. DPL
  1832. 130
  1833. DPH
  1834. 131
  1835. PCON
  1836. 135
  1837. P
  1838. 208
  1839. OV
  1840. 210
  1841. RS0
  1842. 211
  1843. RS1
  1844. 212
  1845. F0
  1846. 213
  1847. AC
  1848. 214
  1849. CY
  1850. 215
  1851. EA
  1852. 175
  1853. ES
  1854. 172
  1855. ET1
  1856. 171
  1857. EX1
  1858. 170
  1859. ET0
  1860. 169
  1861. EX0
  1862. 168
  1863. PS
  1864. 188
  1865. PT1
  1866. 187
  1867. PX1
  1868. 186
  1869. PT0
  1870. 185
  1871. PX0
  1872. 184
  1873. TF1
  1874. 143
  1875. TR1
  1876. 142
  1877. TF0
  1878. 141
  1879. TR0
  1880. 140
  1881. IE1
  1882. 139
  1883. IT1
  1884. 138
  1885. IE0
  1886. 137
  1887. IT0
  1888. 136
  1889. SM0
  1890. 159
  1891. SM1
  1892. 158
  1893. SM2
  1894. 157
  1895. REN
  1896. 156
  1897. TB8
  1898. 155
  1899. RB8
  1900. 154
  1901. TI
  1902. 153
  1903. RI
  1904. 152
  1905. INT0
  1906. 178
  1907. INT1
  1908. 179
  1909. IP
  1910. 184
  1911. IP.0
  1912. 184
  1913. IP.1
  1914. 185
  1915. IP.2
  1916. 186
  1917. IP.3
  1918. 187
  1919. IP.4
  1920. 188
  1921. IP.5
  1922. 189
  1923. RXD
  1924. 176
  1925. TXD
  1926. 177
  1927. END
  1928. -1
  1929.  
  1930. @\Rogue\Monster\
  1931. else
  1932.   echo "shar: Will not over write a51.equ"
  1933. fi
  1934. if `test ! -s a51.h`
  1935. then
  1936. echo "x - a51.h"
  1937. cat > a51.h << '@\Rogue\Monster\'
  1938. #include <stdio.h>
  1939. #include <string.h>
  1940.  
  1941. short        mem[32768];
  1942. char        s[80];
  1943. char        buffer[80];
  1944. char        hexstr[7];
  1945. char        name[80];
  1946. char        left[80];
  1947. char        basename[80];
  1948. char        c;
  1949. int        addr,line,lval,mi,pass,pos,rval,realvalue,value;
  1950. int        lop,rel,rop,ln,hexsflag;
  1951. FILE         *f,*f_lst,*f_hex;
  1952. struct        taglist {
  1953.     char    tag[80];
  1954.     int    value;
  1955.     struct    taglist *next;
  1956.     };
  1957. struct taglist    *tag_list;
  1958. typedef    struct taglist ELEM;
  1959. typedef    ELEM *LINK;
  1960.  
  1961. @\Rogue\Monster\
  1962. else
  1963.   echo "shar: Will not over write a51.h"
  1964. fi
  1965. if `test ! -s foo`
  1966. then
  1967. echo "x - foo"
  1968. cat > foo << '@\Rogue\Monster\'
  1969. nop
  1970. ajmp 100h
  1971. ljmp 100h
  1972. rr a
  1973. inc a
  1974. inc 40h
  1975. inc r0
  1976. inc r1
  1977. inc r2
  1978. inc r3
  1979. inc r4
  1980. inc r5
  1981. inc r6
  1982. inc r7
  1983. jbc 20h,77h
  1984. acall 0
  1985. lcall 4220h
  1986. rrc a
  1987. dec a
  1988. dec 40h
  1989. dec @r0
  1990. dec @r1
  1991. dec r0
  1992. dec r1
  1993. dec r2
  1994. dec r3
  1995. dec r4
  1996. dec r5
  1997. dec r6
  1998. dec r7
  1999. jb 10h,77h
  2000. ret
  2001. rl a
  2002. add a,#1
  2003. add a,20h
  2004. add a,@r0
  2005. add a,@r1
  2006. add a,r0
  2007. add a,r1
  2008. add a,r2
  2009. add a,r3
  2010. add a,r4
  2011. add a,r5
  2012. add a,r6
  2013. add a,r7
  2014. jnb 10h,77h
  2015. reti
  2016. rlc a
  2017. addc a,#1
  2018. addc a,20h
  2019. addc a,@r0
  2020. addc a,@r1
  2021. addc a,r0
  2022. addc a,r1
  2023. addc a,r2
  2024. addc a,r3
  2025. addc a,r4
  2026. addc a,r5
  2027. addc a,r6
  2028. addc a,r7
  2029. jc 77h
  2030. orl 20h,a
  2031. orl 20h,#1
  2032. orl a,#1
  2033. orl a,20h
  2034. orl a,@r0
  2035. orl a,@r1
  2036. orl a,r0
  2037. orl a,r1
  2038. orl a,r2
  2039. orl a,r3
  2040. orl a,r4
  2041. orl a,r5
  2042. orl a,r6
  2043. orl a,r7
  2044. jnc 77h
  2045. anl 20h,a
  2046. anl 20h,#1
  2047. anl a,#1
  2048. anl a,20h
  2049. anl a,@r0
  2050. anl a,@r1
  2051. anl a,r0
  2052. anl a,r1
  2053. anl a,r2
  2054. anl a,r3
  2055. anl a,r4
  2056. anl a,r5
  2057. anl a,r6
  2058. anl a,r7
  2059. jz 77h
  2060. xrl 20h,a
  2061. xrl 20h,#1
  2062. xrl a,#1
  2063. xrl a,20h
  2064. xrl a,@r0
  2065. xrl a,@r1
  2066. xrl a,r0
  2067. xrl a,r1
  2068. xrl a,r2
  2069. xrl a,r3
  2070. xrl a,r4
  2071. xrl a,r5
  2072. xrl a,r6
  2073. xrl a,r7
  2074. jnz 77h
  2075. orl c,10h
  2076. jmp @a+dptr
  2077. mov a,#1
  2078. mov 20h,#1
  2079. mov @r0,#1
  2080. mov @r1,#1
  2081. mov r0,#1
  2082. mov r1,#1
  2083. mov r2,#1
  2084. mov r3,#1
  2085. mov r4,#1
  2086. mov r5,#1
  2087. mov r6,#1
  2088. mov r7,#1
  2089. sjmp 77h
  2090. anl c,77h
  2091. movc a,@a+pc
  2092. div ab
  2093. mov 20h,21h
  2094. mov 20h,@r0
  2095. mov 20h,@r1
  2096. mov 20h,r0
  2097. mov 20h,r1
  2098. mov 20h,r2
  2099. mov 20h,r3
  2100. mov 20h,r4
  2101. mov 20h,r5
  2102. mov 20h,r6
  2103. mov 20h,r7
  2104. mov dptr,#2123h
  2105. mov 77h,c
  2106. movc a,@a+dptr
  2107. subb a,#1
  2108. subb a,20h
  2109. subb a,@r0
  2110. subb a,@r1
  2111. subb a,r0
  2112. subb a,r1
  2113. subb a,r2
  2114. subb a,r3
  2115. subb a,r4
  2116. subb a,r5
  2117. subb a,r6
  2118. subb a,r7
  2119. mov c,77h
  2120. inc dptr
  2121. mul ab
  2122. mov @r0,20h
  2123. mov @r1,20h
  2124. mov r0,20h
  2125. mov r1,20h
  2126. mov r2,20h
  2127. mov r3,20h
  2128. mov r4,20h
  2129. mov r5,20h
  2130. mov r6,20h
  2131. mov r7,20h
  2132. cpl 77h
  2133. cpl c
  2134. cjne a,#1,loo
  2135. cjne a,20h,loo
  2136. cjne @r0,#1,loo
  2137. cjne @r1,#1,loo
  2138. cjne r0,#1,loo
  2139. cjne r1,#1,loo 
  2140. cjne r2,#1,loo 
  2141. cjne r3,#1,loo 
  2142. cjne r4,#1,loo 
  2143. cjne r5,#1,loo 
  2144. cjne r6,#1,loo 
  2145. cjne r7,#1,loo 
  2146. loo:
  2147. push 40h
  2148. clr 77h
  2149. clr c
  2150. swap a
  2151. xch a,20h
  2152. xch a,@r0
  2153. xch a,@r1
  2154. xch a,r0
  2155. xch a,r1
  2156. xch a,r2
  2157. xch a,r3
  2158. xch a,r4
  2159. xch a,r5
  2160. xch a,r6
  2161. xch a,r7
  2162. pop 40h
  2163. setb 77h
  2164. setb c
  2165. da a
  2166. djnz 40h,loo 
  2167. xchd a,@r0
  2168. xchd a,@r1
  2169. loop:
  2170. djnz r0,loop
  2171. djnz r1,loop
  2172. djnz r2,loop
  2173. djnz r3,loop
  2174. djnz r4,loop
  2175. djnz r5,loop
  2176. djnz r6,loop
  2177. djnz r7,loop
  2178. movx a,@dptr
  2179. movx a,@r0
  2180. movx a,@r1
  2181. clr a
  2182. mov a,20h
  2183. mov a,@r0
  2184. mov a,@r1
  2185. mov a,r0
  2186. mov a,r1
  2187. mov a,r2
  2188. mov a,r3
  2189. mov a,r4
  2190. mov a,r5
  2191. mov a,r6
  2192. mov a,r7
  2193. movx @dptr,a
  2194. movx @r0,a
  2195. movx @r1,a
  2196. cpl a
  2197. mov @r0,a
  2198. mov @r1,a
  2199. mov r0,a
  2200. mov r1,a
  2201. mov r2,a
  2202. mov r3,a
  2203. mov r4,a
  2204. mov r5,a
  2205. mov r6,a
  2206. mov r7,a
  2207.  
  2208.  
  2209.  
  2210.  
  2211. @\Rogue\Monster\
  2212. else
  2213.   echo "shar: Will not over write foo"
  2214. fi
  2215. if `test ! -s foo2`
  2216. then
  2217. echo "x - foo2"
  2218. cat > foo2 << '@\Rogue\Monster\'
  2219. mov a,#'A'
  2220. .dw 2000h
  2221.  
  2222.  
  2223. .db 24h+111b+'a'
  2224. .db 1111b
  2225. .dm 'hello'
  2226. .equ apple_soft,45h
  2227. .db apple_soft
  2228. .end
  2229.  
  2230. @\Rogue\Monster\
  2231. else
  2232.   echo "shar: Will not over write foo2"
  2233. fi
  2234. if `test ! -s key.asm`
  2235. then
  2236. echo "x - key.asm"
  2237. cat > key.asm << '@\Rogue\Monster\'
  2238. ;* these port equates are explained below. Relocate them to any of
  2239. ;* Port1, pins 0-7 or Port3, pins 0-7, except Port3, pins2 and 3
  2240. ;* because these are the external interrupts.
  2241. ;* it doesn't matter as long as you equate the right pin to the right
  2242. ;* signal.
  2243.  
  2244.         .equ    Kclk,p1.0
  2245.         .equ    Kdat,p1.1
  2246.         .equ    Aclk,p1.3
  2247.         .equ    Adat,p1.4
  2248.         .equ    Areset,p1.5
  2249.         .equ    Kswitch,p1.7
  2250.  
  2251.         .org    0000h
  2252. init:   ljmp    start
  2253.         .org    0003h
  2254.         ljmp    resetint
  2255.         .org    001bh
  2256.         ljmp    timer1int
  2257.  
  2258. ;**************************************************
  2259. ;*
  2260. ;*
  2261. ;* Equates Descriptions:
  2262. ;* 
  2263. ;*      Aclk is the line to the Amiga keyboard clock in. (P1.3)
  2264. ;*      Adat is the line to the Amiga keyboard data in. (P1.4)
  2265. ;*      Areset is the Amiga Reset line (P1.5) (for the A500)
  2266. ;*      Kclk is the line to the Keyboard clock out (P1.0)
  2267. ;*      Kdat is the line to the Keyboard data out (P1.1)
  2268. ;*      Kstyle is bit defining whether or not the keyboard
  2269. ;*        is AT or XT. if AT, Kstyle=1
  2270. ;*
  2271. ;*      Oldchar is the last character typed to go to the Amiga.
  2272. ;* This is used to tell if the Capslock was Pressed and 
  2273. ;* Released without pressing any other keys. If this was done, 
  2274. ;* then it is a "Caps Lock" otherwise, the Caps key functions
  2275. ;* as the Control Key because of the keyboard remapping.
  2276. ;*
  2277. ;*      Capbit is the flag which tells whether the Caps Lock
  2278. ;* should be down or up.
  2279. ;*      Capdown is the flag which tells whether the Caps Lock 
  2280. ;* KEY is presently down or up. The difference between Capdown 
  2281. ;* and Capbit is that Capdown relates to the KEY. Capbit toggles 
  2282. ;* once for every "press and release" of the Cap Lock Key. 
  2283. ;* Press and release Cap Lock Key, and Capbit goes low.....
  2284. ;* Press and release it again, and Capbit goes high....
  2285. ;*      Cntldown is the flag which is set and reset when you 
  2286. ;* press Cap Lock and then another key. Then, Cap Lock Key 
  2287. ;* functions as the Control Key.
  2288. ;* LAMIGA,RAMIGA,and CONTROL are all flags that tell if those 
  2289. ;* keys are being held down. When all three are, the computer
  2290. ;* will reset.
  2291. ;*
  2292. ;* ATparity is the 10th bit that the AT keyboard transmits. It 
  2293. ;* is SET if the number of DATA bits set is EVEN. Otherwise, its
  2294. ;* CLEARED.
  2295. ;*
  2296. ;**************************************************
  2297.  
  2298.         ;bit memory locations:
  2299.  
  2300.         .equ    Capbit,42h
  2301.         .equ    Capdown,43h
  2302.         .equ    Ctrldown,44h
  2303.         .equ    CONTROL,45h
  2304.         .equ    LAMIGA,46h
  2305.         .equ    RAMIGA,47h
  2306.         .equ    ATparity,48h
  2307.         .equ    Make,49h
  2308.         .equ    XT7bit,4ah
  2309.         .equ    Kstyle,4bh
  2310.  
  2311.         ;byte memory locations:
  2312.  
  2313.         .equ    Charbad,50h
  2314.         .equ    Oldchar,51h
  2315.         .equ    Amigachar,52h
  2316.  
  2317.         .org    0200h
  2318.  
  2319. start:  mov     tmod,#11h       ;two 16 bit timers
  2320.         mov     tcon,#05h    ;edge triggered interrupt.
  2321.         mov     ie,#00h         ;clear all interrupts
  2322.         setb    ea
  2323.         setb    et1             ;enable timer 1
  2324.         setb    ex0             ;enable external 0
  2325.         setb    int0            ;make sure it's high
  2326.         setb    pt0        ;timer 0 has high priority
  2327.         mov     sp,#30h         ;stack somewhere safe.
  2328.  
  2329. ; set the ports for input
  2330.         mov     p1,#255         ;set port1 for read
  2331.         clr     tr1             ;make sure timers are in
  2332.         clr     tf1             ;reset state.
  2333.         clr     tr0
  2334.         clr     tf0
  2335.  
  2336. ; clear out the miscellaneous flags.
  2337.         clr     Capdown         ;Caps is up...
  2338.         clr     Ctrldown        ;Control is up
  2339.         clr     Capbit          ;Caps light is off.
  2340.         setb    CONTROL         ;all reset keys are UP
  2341.         setb    LAMIGA
  2342.         setb    RAMIGA
  2343.  
  2344. ;**** sync the controller with the Amiga. clock out
  2345. ;**** ones until we receive a handshake...
  2346. sync:
  2347.         mov     tl1,#0          ;set up timer for 143ms
  2348.         mov     th1,#0
  2349.         mov     r1,#2
  2350.         setb     tr1
  2351. sync2:
  2352.         jb      Adat,sync2      ;wait for handshake
  2353. sync3:
  2354.         jnb     Adat,sync3      ;wait for end of handshake
  2355.         clr     tr1
  2356.  
  2357. ;**** transmit power up key stream and end key stream.
  2358.         mov     a,#0FDh
  2359.         acall   actualtransmit
  2360.         mov     a,#0FEh
  2361.         acall   actualtransmit
  2362.  
  2363. ;**** test for XT keyboard, if Kswitch is low, automatically
  2364. ;**** jump to XT mode.
  2365. ;**** otherwise, test to see if Kdat is low and stays there.
  2366. ;**** If so, it's in XT mode.                                
  2367.  
  2368.         jnb     Kswitch,XTPowerup 
  2369.         jb      Kdat,ATPowerup
  2370.         mov     th0,#0
  2371.         mov     tl0,#0
  2372.         clr     tf0
  2373.         setb    tr0
  2374. XTtest: jb      tf0,XTPowerup   ;timer ran out. XT mode.
  2375.         jnb     Kdat,XTtest     ;data is low, but for how long?
  2376.         clr     tr0
  2377.         clr     tf0
  2378.         sjmp    ATPowerup
  2379. XTPowerup:
  2380.         clr     Kstyle          ;XT flag.
  2381.         clr     tf0
  2382.         clr     Kclk            ;Clock low=Reset for the XT.
  2383. XTreset:
  2384.         jnb     tf0,XTreset
  2385.         setb    Kclk
  2386.         clr     tr0
  2387.         clr     tf0
  2388. ll:     acall   XTgetkey        ;(Should be AA)
  2389.         ljmp    XTstyle
  2390.  
  2391. ;**** sync up the AT and go with it!
  2392.  
  2393. ATPowerup:
  2394.         setb    Kstyle
  2395.         mov     a,#0ffh         ;RESET
  2396.         acall   SendtoAT
  2397.         mov     a,#0f6h         ;DEFAULT
  2398.         acall   SendtoAT
  2399.         mov     a,#0edh         ;NEXT DATA is FOR LIGHTS
  2400.         acall   SendtoAT
  2401.         mov     a,#2            ;NUMLOCK ON?
  2402.         acall   SendtoAT
  2403.         mov     a,#0f4h         ;CLEAR BUFFER
  2404.         acall   SendtoAT
  2405.         ljmp    ATstyle         ;go and parse AT keyboard
  2406.  
  2407. ;***********************************************
  2408. ;* ATgetkey
  2409. ;* ATgetkey
  2410. ;* ATgetkey
  2411. ;*
  2412. ;* ATgetkey looks at the keyboard and waits for a key to be
  2413. ;* pressed. ATinkey is the actual routine that watched the logic
  2414. ;* levels of Kdat and Kclk. IF the character's parity is not 
  2415. ;* what it is supposed to be, then the routine will attempt to
  2416. ;* tell the keyboard to resend.
  2417. ;*
  2418. ;* When exiting from this routine, Kclock is pulled low to hold 
  2419. ;* off any more transmissions. You must restore it to 5 volts to
  2420. ;* receive any more characters later.
  2421. ;*
  2422. ;*
  2423.  
  2424. ATgetkey:
  2425.         mov     r0,#11          ;number of bits
  2426.         setb    Kclk
  2427. ATwaitC0:         
  2428.         jb      Kclk,ATwaitC0   ;wait for a clock pulse
  2429.         dec     r0              ;decrement clock bit counter
  2430.         cjne    r0,#10,ATnstart ;test for startbit
  2431.         sjmp    ATwait  
  2432. ATnstart:
  2433.         cjne    r0,#0,ATnstop   ;check for stopbit      
  2434. ATwaitC1:
  2435.         jnb     Kclk,ATwaitC1   ;wait for clock to go high                     
  2436.         clr     Kclk            ;hold off more data
  2437.         mov     r0,#20          ;small delay
  2438. pause:  djnz    r0,pause
  2439. ;**** now we check to see if the parity between
  2440. ;**** Bit register P (which is set if Parity of Acc is odd)
  2441. ;**** is compared to the received Parity Bit.
  2442.         jb      p,parityodd     ;test if parity of DATA is odd
  2443. parityeven:
  2444.         jnb     ATparity,ATerror
  2445.         ret                     ;Okay to return. A=valid
  2446. parityodd:
  2447.         jb      ATparity,ATerror
  2448.         ret                     ;Okay to return. A=valid
  2449. ATerror:
  2450.         mov     a,#0feh         ;RESEND character
  2451.         acall   SendtoAT
  2452.         sjmp    ATgetkey        ;now return to caller
  2453. ATnstop:
  2454.         cjne    r0,#1,ATdatab   ;check for paritybit
  2455.         mov     c,Kdat          ;error checking! (AT only)
  2456.         mov     ATparity,c
  2457.         sjmp    ATwait          ;
  2458. ATdatab: 
  2459.         mov     c,Kdat          ;get data bit
  2460.         rrc     a               ;shift it into accumulator
  2461. ATwait: jnb     Kclk,ATwait     ;wait for clock line to go low
  2462.         sjmp    ATwaitC0        ;get another bit
  2463.  
  2464.  
  2465. ;**************************************************
  2466. ;* AT-STYLE
  2467. ;*
  2468. ;*     This waits for a keycode or two from the IBM and then calls
  2469. ;* the appropriate transmit subroutine. The IBM keyboard sends 
  2470. ;* out special codes in front of and behind some scancodes. This
  2471. ;* routine will chop them out before doing a lookup on the 
  2472. ;* code to see what to send to the AMIGA. The scancodes between 
  2473. ;* the IBM and the AMIGA are of course, not the same!
  2474. ;*
  2475. ;**************************************************
  2476.  
  2477. ATstyle:
  2478.         acall   ATgetkey          ;get one scancode.
  2479.         cjne    a,#0e1h,ATnE1
  2480.         acall   ATgetkey          ;(should be 14)
  2481.         acall   ATgetkey          ;(should be 77)
  2482.         acall   ATgetkey          ;(should be E1)
  2483.         acall   ATgetkey          ;(should be F0)
  2484.         acall   ATgetkey          ;(should be 14)
  2485.         acall   ATgetkey          ;(should be F0)
  2486.         acall   ATgetkey          ;(should be 77)
  2487.         sjmp    ATstyle
  2488. ;PAUSE was pressed. Just ignore it.
  2489. ATnE1:
  2490.         mov     dptr,#ATtb1
  2491.         cjne    a,#0e0h,ATnE0
  2492.         mov     dptr,#ATtb2
  2493.         acall   ATgetkey
  2494.         cjne    a,#0f0h,ATnE0F0
  2495.         acall   ATgetkey
  2496.         cjne    a,#12h,ATnEF12
  2497.         ljmp    ATstyle         ;(E0F012....ignore it)
  2498. ATnEF12:
  2499.         cjne    a,#59h,ATup     ;(E0F0mk)
  2500.         ljmp    ATstyle         ;(E0F059....ignore it)
  2501. ATnE0F0:
  2502.         cjne    a,#12h,ATnE012
  2503.         ljmp    ATstyle         ;(E012....ignore it)
  2504. ATnE012:
  2505.         cjne    a,#59h,ATdown   ;(E0mk)
  2506.         ljmp    ATstyle         ;(E059....ignore it)
  2507. ATnE0:
  2508.         cjne    a,#0f0h,ATdown  ;(mk)
  2509.         acall   ATgetkey
  2510.         sjmp    ATup            ;(F0mk....normal key break)
  2511.  
  2512. ;**************************************************
  2513. ;* ATdown and the rest here call a lookup table to change
  2514. ;* the AT scancodes into AMIGA scancodes. In the "down"
  2515. ;* routine, the "make" bit is asserted. In the "up" routine
  2516. ;* it is de-asserted.
  2517. ;**************************************************
  2518. ATdown:
  2519.         movc    a,@a+dptr       ;indexed into table
  2520.         clr     acc.7           ;clear make/break bit
  2521.         acall   transmit        ;transmit it
  2522.         ljmp    ATstyle
  2523. ATup:
  2524.         movc    a,@a+dptr
  2525.         setb    acc.7           ;set make/break bit
  2526.         acall   transmit        ;transmit it
  2527.         ljmp    ATstyle
  2528.  
  2529. ;**************************************************
  2530. ;* SendtoAT is the subroutine that sends special codes
  2531. ;* to the keyboard from the controller. Codes include
  2532. ;* the command to reset (FF) or the command to change
  2533. ;* the lights (ED). It is advisable to keep the timing
  2534. ;* very close to how I have it done in this routine.
  2535. ;**************************************************
  2536.  
  2537. SendtoAT:
  2538.         setb    Kclk
  2539.         clr     Kdat
  2540.         mov     r0,#8
  2541. Send4:  jb      Kclk,Send4      ;data bit
  2542.         mov     c,acc.0
  2543.         mov     Kdat,c
  2544.         rr      a 
  2545. Send5:  jnb     Kclk,Send5      ;data bit
  2546.         dec     r0
  2547.         cjne    r0,#0,Send4
  2548.         mov     c,p
  2549.         cpl     c
  2550. Send6:  jb      Kclk,Send6      ;parity bit
  2551.         mov     Kdat,c
  2552. Send7:  jnb     Kclk,Send7      ;parity bit
  2553. Send77: jb      Kclk,Send77     ;stop bit
  2554.         setb    Kdat
  2555. Send78: jnb     Kclk,Send78     ;stop bit
  2556. Send79: jb      Kclk,Send79
  2557. Send7a: jnb     Kclk,Send7a
  2558.         mov     r0,#8           ;small delay
  2559. Send8:  djnz    r0,Send8
  2560.         clr     Kclk            ;drive clock low
  2561.         mov     r0,#20          ;long delay
  2562. Send9:  djnz    r0,Send9
  2563.         setb    Kclk
  2564.         acall   ATgetkey        ;should check if response isbad.
  2565.         ret                     ;who cares if it is? not me!
  2566.  
  2567. XTgetkey:
  2568.         setb    Kdat            ;let data flow!
  2569.         mov     r0,#8
  2570. XTw1:   jb      Kclk,XTw1       ;start bit1
  2571. XTw2:   jnb     Kclk,XTw2       ;start bit1
  2572. XTw3:   jb      Kclk,XTw3       ;start bit2
  2573. XTw4:   jnb     Kclk,XTw4       ;start bit2
  2574. XTw5:   jb      Kclk,XTw5       ;data bit
  2575.         mov     c,Kdat
  2576.         rrc     a
  2577. XTw6:   jnb     Kclk,XTw6       ;data bit
  2578.         djnz    r0,XTw5
  2579.         clr     Kdat            ;hold off data
  2580.         ret
  2581.  
  2582. XTstyle:
  2583.         acall   XTgetkey
  2584.         cjne    a,#0e1h,XTnE1
  2585.         acall   XTgetkey        ;(should be 1d)
  2586.         acall   XTgetkey        ;(should be 45)
  2587.         acall   XTgetkey        ;(should be e1)
  2588.         acall   XTgetkey        ;(should be 9d)
  2589.         acall   XTgetkey        ;(should be c5)
  2590.         sjmp    XTstyle
  2591. XTnE1:
  2592.         cjne    a,#0e0h,XTnE0
  2593.         acall   XTgetkey
  2594.         cjne    a,#0aah,XTnAA
  2595.         sjmp    XTstyle
  2596. XTnAA:
  2597.         cjne    a,#2ah,XTn2A
  2598.         sjmp    XTstyle
  2599. XTn2A:
  2600.         cjne    a,#0b6h,XTnB6
  2601.         sjmp    XTstyle
  2602. XTnB6:
  2603.         cjne    a,#36h,XTn36
  2604.         sjmp    XTstyle
  2605. XTn36:
  2606.         mov     dptr,#XTtb2
  2607. XTlookup:
  2608.         mov     c,acc.7         ;(1=break)
  2609.         mov     XT7bit,c
  2610.         clr     acc.7
  2611.         movc    a,@a+dptr
  2612.         mov     c,XT7bit
  2613.         mov     acc.7,c
  2614.         acall   transmit
  2615.         ljmp    XTstyle
  2616. XTnE0:
  2617.         mov     dptr,#XTtb1
  2618.         sjmp    XTlookup
  2619.  
  2620. ;**************************************************
  2621. ;*
  2622. ;* TRANSMIT first does some checking to take out repeating
  2623. ;* keys and does the conversion on the Caps Lock Key and
  2624. ;* then calls Actualtransmit.
  2625. ;*
  2626. ;**************************************************
  2627.  
  2628. dontrans:                       ;jumps back if key is already
  2629.         pop     acc             ;held down.
  2630.         ret
  2631. transmit:
  2632.         cjne    a,Oldchar,transok
  2633.         ret
  2634. transok:
  2635.         cjne    a,#62h,transok2 ;jump if not CapsLock=down
  2636.         mov     Oldchar,a
  2637.         setb    Capdown         ;set the flags for later
  2638.         ret
  2639. transok2:                       
  2640.         cjne    a,#0e2h,transok3;jump if not CapsLock=up
  2641.         mov     a,Oldchar       ;see if Caps was just down
  2642.         jnb     Kstyle,XTcap    ;if XT, skip control feature.
  2643.         cjne    a,#62h,transok4 ;if not, then it was a control
  2644. XTcap:
  2645.         clr     Capdown         ;clear flag
  2646.         cpl     Capbit          ;toggle down/up-ness of Caplock
  2647.         mov     a,#62h
  2648.         mov     c,Capbit
  2649.         cpl     c
  2650.         mov     acc.7,c
  2651.         acall   actualtransmit  ;(Caps to Amiga!)
  2652.         jnb     Kstyle,skiplights ;(don't do lights if XT)
  2653.         mov     a,#0edh         ;set lights on next byte.
  2654.         acall   SendtoAT
  2655.         mov     a,#2            ;numlock on
  2656.         mov     c,Capbit
  2657.         mov     acc.2,c
  2658.         acall   SendtoAT        ;maybe capslock light
  2659. skiplights: 
  2660.         ret           
  2661. transok4:
  2662.         clr     CtrlDown        ;This sends out a Control Up.
  2663.         clr     Capdown         ;Caps lock is done functioning as Ctl
  2664.         mov     a,#63h          ;Control Key
  2665.         setb    acc.7           ;break bit set.
  2666.         acall   actualtransmit  ;send to Amiga.
  2667.         ret
  2668. transok3:
  2669.         mov     Oldchar,a
  2670.         jnb     Kstyle,noControl
  2671.         jnb     Capdown,noControl
  2672.         jb      CtrlDown,noControl
  2673.         setb    CtrlDown        ;Caps lock is beginning to function
  2674.         mov     a,#63h          ;as the Control Key.
  2675.         acall   actualtransmit  ;send Control Down to Amiga
  2676.         mov     a,Oldchar       ;now send the actual key
  2677.  
  2678. noControl:                      ;its not a controlled key
  2679.         mov     c,acc.7         ;c=make/break bit
  2680.         mov     Make,c          ;will be set if key up
  2681.         clr     acc.7           ;test for key only. NO make/break
  2682.         cjne    a,#0eh,noMup    ;special key mouse up
  2683.         jnb     Make,kmupdown
  2684. kmupup:
  2685.         mov     a,#0cch         ;cursor up break
  2686.         acall   actualtransmit
  2687.         acall   Smalldelay
  2688.         mov     a,#0e7h         ;right amiga break
  2689.         acall   actualtransmit
  2690.         ret
  2691. kmupdown:
  2692.         mov     a,#67h          ;amiga make
  2693.         acall   actualtransmit
  2694.         acall   Smalldelay
  2695.         mov     a,#4ch          ;cursor up make
  2696.         acall   actualtransmit
  2697.         ret
  2698. noMup:
  2699.         cjne    a,#1ch,noMdown  ;special key mouse down
  2700.         jnb     Make,kmdowndown
  2701. kmdownup:
  2702.         mov     a,#0cdh         ;cursor down break
  2703.         acall   actualtransmit
  2704.         mov     a,#0e7h         ;amiga break
  2705.         acall   Smalldelay
  2706.         acall   actualtransmit
  2707.         ret
  2708. kmdowndown:
  2709.         mov     a,#67h          ;amiga make
  2710.         acall   actualtransmit
  2711.         acall   Smalldelay      ;cursor down make
  2712.         mov     a,#4dh
  2713.         acall   actualtransmit
  2714.         ret
  2715. noMdown:
  2716.         cjne    a,#2ch,noMleft  ;special key mouse left
  2717.         jnb     Make,kmleftdown
  2718. kmleftup:
  2719.         mov     a,#0cfh         ;cursor left break
  2720.         acall   actualtransmit
  2721.         acall   Smalldelay      ;amiga break
  2722.         mov     a,#0e7h
  2723.         acall   actualtransmit
  2724.         ret
  2725. kmleftdown:
  2726.         mov     a,#67h          ;amiga make
  2727.         acall   actualtransmit
  2728.         acall   Smalldelay
  2729.         mov     a,#4fh          ;cursor left make
  2730.         acall   actualtransmit
  2731.         ret
  2732. noMleft:                        ;special key mouse right
  2733.         cjne    a,#47h,notspecial
  2734.         jnb     Make,kmrhtdown
  2735. kmrhtup:
  2736.         mov     a,#0ceh         ;cursor right break
  2737.         acall   actualtransmit
  2738.         acall   Smalldelay
  2739.         mov     a,#0e7h         ;amiga break
  2740.         acall   actualtransmit
  2741.         ret
  2742. kmrhtdown:
  2743.         mov     a,#67h          ;amiga make
  2744.         acall   actualtransmit
  2745.         acall   Smalldelay
  2746.         mov     a,#04eh         ;cursor right make
  2747.         acall   actualtransmit
  2748.         ret
  2749. Smalldelay:
  2750.         mov     th0,#0
  2751.         mov     tl0,#0
  2752.         clr     tf0
  2753.         setb    tr0
  2754. small1: jnb     tf0,small1
  2755.         clr     tf0
  2756.         clr     tr0
  2757.         ret
  2758. notspecial:
  2759.         mov     a,Oldchar
  2760.         acall   actualtransmit  ;transmit the keycode
  2761.         mov     a,Oldchar       ;get back same keycode, in A.
  2762.         mov     c,acc.7         ;put make/break bit in Make
  2763.         mov     Make,c
  2764.         clr     acc.7           ;start testing for reset keys
  2765.         cjne    a,#63h,nrset1   ;held down
  2766.         mov     c,Make
  2767.         mov     CONTROL,c
  2768.         sjmp    trset
  2769. nrset1: cjne    a,#66h,nrset2
  2770.         mov     c,Make
  2771.         mov     LAMIGA,c
  2772.         sjmp    trset
  2773. nrset2: cjne    a,#67h,trset
  2774.         mov     c,Make
  2775.         mov     RAMIGA,c
  2776. trset:  jnb     CONTROL,maybefree       ;if bit set, this key is up
  2777.         jb      CtrlDown,maybefree      ;if bit set, this key is down
  2778.         sjmp    free
  2779. maybefree:
  2780.         jb      LAMIGA,free     ;ditto
  2781.         jb      RAMIGA,free     ;ditto
  2782.         sjmp    resetwarn       ;OOPS! They are all down!
  2783. free:   ret
  2784. dummy:
  2785.         reti
  2786. resetint:
  2787.         acall   dummy
  2788. resetwarn:
  2789.         clr     tf0             
  2790.         mov     a,78h
  2791.         mov     r1,#2           ;set up timer 0 watchdog
  2792.         mov     tl0,#0
  2793.         mov     th0,#0
  2794.         cpl     a               ;invert, don't know why.
  2795.         mov     r0,#8
  2796. wr1:
  2797.         rl      a
  2798.         mov     c,acc.7
  2799.         mov     Adat,c
  2800.         mov     b,#8
  2801. wr2:
  2802.         djnz    b,wr2             ; transmit it.
  2803.         clr     Aclk
  2804.         mov     b,#8
  2805. wr3:
  2806.         djnz    b,wr3
  2807.         setb    Aclk
  2808.         mov     b,#10
  2809. wr4:
  2810.         djnz    b,wr4
  2811.         djnz    r0,wr1
  2812.         setb    Adat
  2813.         setb    tr0             ;start watchdog
  2814. wr5:
  2815.         jnb     Adat,caught1
  2816.         jnb     tf0,wr5
  2817.         clr     tf0
  2818.         djnz    r1,wr5
  2819.         sjmp    Hardreset
  2820. caught1:
  2821.         clr     tr0
  2822.         clr     tf0
  2823.         mov     a,78h
  2824.         mov     r1,#4
  2825.         mov     tl0,#0
  2826.         mov     th0,#0
  2827.         cpl     a    
  2828.         mov     r0,#8
  2829. wr11:
  2830.         rl      a
  2831.         mov     c,acc.7
  2832.         mov     Adat,c
  2833.         mov     b,#8
  2834. wr22:
  2835.         djnz    b,wr22   
  2836.         clr     Aclk
  2837.         mov     b,#8
  2838. wr33:
  2839.         djnz    b,wr33
  2840.         setb    Aclk
  2841.         mov     b,#10
  2842. wr44:
  2843.         djnz    b,wr44
  2844.         djnz    r0,wr11
  2845.         setb    Adat
  2846.         setb    tr0             ;start watchdog
  2847. wr55:
  2848.         jnb     Adat,caught2
  2849.         jnb     tf0,wr55
  2850.         clr     tf0
  2851.         djnz    r1,wr55
  2852.         sjmp    Hardreset
  2853. caught2:
  2854. hold:   jnb     Adat,hold
  2855. Hardreset:
  2856.         clr     tr0
  2857.         clr     tf0
  2858.         clr     Areset
  2859.         clr     Aclk            ;clear both lines for A500/A1000
  2860.         mov     r1,#15          ;clock should go low for over 500ms
  2861.         mov     th0,#0          ;timer 1 will overflow repeatedly
  2862.         mov     tl0,#0
  2863.         setb    tr0
  2864. hsloop:
  2865.         jnb     tf0,hsloop      ;wait for overflow flag
  2866.         clr     tf0             ;clear it again
  2867.         djnz    r1,hsloop
  2868.         clr     tf0
  2869.         clr     tr0             ;stop the timer
  2870.         ljmp    start
  2871.  
  2872. ;**************************************************
  2873. ;* 
  2874. ;* ActualTransmit sends the character out to the Amiga and waits
  2875. ;* for an acknowledge handshake. If it does not receive one in
  2876. ;* 143 ms, then it clocks out 1's on the data line until it 
  2877. ;* receives the acknowledge. If the Amiga is not connected up, 
  2878. ;* then it will hang here. The handshake is that the AMIGA 
  2879. ;* drives the clock line low.
  2880. ;*
  2881. ;*      The loops with register B are for timing delays. 
  2882. ;* There should be about 20usec between when the Data line is 
  2883. ;* set, the Clock line is driven low, and the Clock line
  2884. ;* is driven high.
  2885. ;*
  2886. ;**************************************************
  2887.  
  2888. actualtransmit:
  2889.         mov     Amigachar,a     ;set the character to transmit
  2890.  
  2891.         mov     r0,#05          ;do a small delay
  2892. dly:
  2893.         mov     b,#0
  2894. delay:  djnz    b,delay
  2895.         djnz    r0,dly
  2896.  
  2897. actual2:
  2898.         mov     a,Amigachar     ;restore it
  2899.         clr     Charbad         ;character is not bad yet
  2900.         mov     r1,#2           ;set up timer 0 watchdog
  2901.         mov     tl1,#0
  2902.         mov     th1,#0
  2903.         cpl     a               ;invert, don't know why.
  2904.         mov     r0,#8
  2905. f:      rl      a
  2906.         mov     c,acc.7
  2907.         mov     Adat,c
  2908.         mov     b,#8
  2909. g:      djnz    b,g             ; transmit it.
  2910.         clr     Aclk
  2911.         mov     b,#8
  2912. h:      djnz    b,h
  2913.         setb    Aclk
  2914.         mov     b,#10
  2915. i:      djnz    b,i
  2916.         djnz    r0,f
  2917.         setb    Adat
  2918.         setb    tr1             ;start watchdog
  2919. waitshake:
  2920.         jb      Adat,waitshake
  2921.         clr     tr1             ;stop watchdog
  2922. gotit:  jnb     Adat,gotit
  2923.         ret
  2924.  
  2925. timer1int:
  2926.         djnz    r1,t3           ;we wait for 143 ms.
  2927.         mov     r1,#2           
  2928.         setb    Charbad         ;flag to resend the character
  2929.         clr     Adat            ;1 on the data line
  2930.         mov     b,#8
  2931. tt1:    djnz    b,tt1           ;wait for it
  2932.         clr     Aclk            ;clock asserted
  2933.         mov     b,#8            ;sync up the controller to the
  2934. tt2:    djnz    b,tt2           ;amiga
  2935.         setb    Aclk
  2936.         mov     b,#10
  2937. tt3:    djnz    b,tt3
  2938.         setb    Adat
  2939. t3:     reti                    ;return and send again.
  2940.  
  2941. ATtb1: 
  2942.         .db     0               
  2943.         .db     58h             ;F9
  2944.         .db     0               
  2945.         .db     54h             ;F5
  2946.         .db     52h             ;F3
  2947.         .db     50h             ;F1
  2948.         .db     51h             ;F2
  2949.         .db     5bh             ;F12=right parenthesis
  2950.         .db     0
  2951.         .db     59h             ;F10
  2952.         .db     57h             ;F8
  2953.         .db     55h             ;F6
  2954.         .db     53h             ;F4
  2955.         .db     42h             ;TAB
  2956.         .db     00h             ;~
  2957.         .db     0
  2958.  
  2959.         .db     0
  2960.         .db     64h             ;Left ALT
  2961.         .db     60h             ;Left SHIFT
  2962.         .db     0
  2963.         .db     66h             ;Left Ctrl=Left AMIGA
  2964.         .db     10h             ;Q
  2965.         .db     01h             ;1
  2966.         .db     0
  2967.         .db     0
  2968.         .db     0
  2969.         .db     31h             ;Z
  2970.         .db     21h             ;S
  2971.         .db     20h             ;A
  2972.         .db     11h             ;W
  2973.         .db     02h             ;2
  2974.         .db     0
  2975.  
  2976.         .db     0
  2977.         .db     33h             ;C
  2978.         .db     32h             ;X
  2979.         .db     22h             ;D
  2980.         .db     12h             ;E
  2981.         .db     04h             ;4
  2982.         .db     03h             ;3
  2983.         .db     0
  2984.         .db     0
  2985.         .db     40h             ;SPACE
  2986.         .db     34h             ;V
  2987.         .db     23h             ;F
  2988.         .db     14h             ;T
  2989.         .db     13h             ;R
  2990.         .db     05h             ;5
  2991.         .db     0
  2992.  
  2993.         .db     0
  2994.         .db     36h             ;N
  2995.         .db     35h             ;B
  2996.         .db     25h             ;H
  2997.         .db     24h             ;G
  2998.         .db     15h             ;Y
  2999.         .db     06h             ;6
  3000.         .db     0
  3001.         .db     0
  3002.         .db     0
  3003.         .db     37h             ;M
  3004.         .db     26h             ;J
  3005.         .db     16h             ;U
  3006.         .db     07h             ;7
  3007.         .db     08h             ;8
  3008.         .db     0
  3009.  
  3010.         .db     0
  3011.         .db     38h             ;<
  3012.         .db     27h             ;K
  3013.         .db     17h             ;I
  3014.         .db     18h             ;O
  3015.         .db     0Ah             ;0
  3016.         .db     09h             ;9
  3017.         .db     0
  3018.         .db     0
  3019.         .db     39h             ;>
  3020.         .db     3ah             ;/
  3021.         .db     28h             ;L
  3022.         .db     29h             ; ';'
  3023.         .db     19h             ;P
  3024.         .db     0bh             ;-
  3025.         .db     0
  3026.  
  3027.         .db     0
  3028.         .db     0
  3029.         .db     2ah             ;'
  3030.         .db     0
  3031.         .db     1ah             ;[
  3032.         .db     0ch             ;=
  3033.         .db     0
  3034.         .db     0
  3035.         .db     62h             ;CAPS LOCK?
  3036.         .db     61h             ;Right SHIFT
  3037.         .db     44h             ;RETURN
  3038.         .db     1bh             ;]
  3039.         .db     0
  3040.         .db     0dh             ;\
  3041.         .db     0
  3042.         .db     0
  3043.  
  3044.         .rs     6
  3045.         .db     41h             ;Back SPACE
  3046.         .db     0
  3047.         .db     0
  3048.         .db     1dh             ;1 keypad
  3049.         .db     0
  3050.         .db     2dh             ;4 keypad
  3051.         .db     3dh             ;7 keypad
  3052.         .db     0
  3053.         .db     0
  3054.         .db     0
  3055.  
  3056.         .db     0fh             ;0 keypad
  3057.         .db     3ch             ;dot keypad
  3058.         .db     1eh             ;2 keypad
  3059.         .db     2eh             ;5 keypad
  3060.         .db     2fh             ;6 keypad
  3061.         .db     3eh             ;8 keypad
  3062.         .db     45h             ;ESCAPE!
  3063.         .db     63h             ;Number Lock=CTRL
  3064.         .db     5ah             ;F11=( keypad
  3065.         .db     5eh             ;+ keypad
  3066.         .db     1fh             ;3 keypad
  3067.         .db     4ah             ;- keypad
  3068.         .db     5dh             ;* keypad
  3069.         .db     3fh             ;9 keypad
  3070.         .db     67h             ;scroll Lock=Right AMIGA
  3071.         .db     0
  3072. ATtb2:
  3073.         .rs     3
  3074.         .db     56h             ;F7
  3075.         .db     66h             ;print screen=Left Amiga
  3076.         .rs     11
  3077.  
  3078.         .db     0
  3079.         .db     65h             ;Right ALT
  3080.         .db     0
  3081.         .db     0
  3082.         .db     67h             ;Right CTL=RIGHT AMIGA
  3083.         .rs     11
  3084.  
  3085.         .rs     10h
  3086.         
  3087.         .rs     10h
  3088.  
  3089.         .rs     10
  3090.         .db     5ch             ;/key, supposedly
  3091.         .rs     5
  3092.  
  3093.         .rs     10
  3094.         .db     43h             ;Numeric Enter
  3095.         .rs     5
  3096.  
  3097.         .rs     9
  3098.         .db     1ch             ;End=Mouse down
  3099.         .db     0
  3100.         .db     4fh             ;Cursor Left
  3101.         .db     0eh             ;Home=Mouse up
  3102.         .db     0
  3103.         .db     0
  3104.         .db     63h             ;MACRO key=control
  3105.  
  3106.         .db     2ch             ;Insert=Mouse Left
  3107.         .db     46h             ;Delete
  3108.         .db     4dh             ;Cursor Down
  3109.         .db     0
  3110.         .db     4eh             ;Cursor Right
  3111.         .db     4ch             ;Cursor Up
  3112.         .rs     4
  3113.         .db     5fh             ;Page Down=Help
  3114.         .db     0
  3115.         .db     66h             ;print screen=LEFT AMIGA
  3116.         .db     47h             ;Page up=mouse right
  3117.         .db     40h             ;Break=Space?
  3118.         .db     0
  3119. XTtb1:
  3120.         .db     0
  3121.         .db     45h             ;esc
  3122.         .db     01h             ;1
  3123.         .db     02h             ;2
  3124.         .db     03h             ;3
  3125.         .db     04h             ;4
  3126.         .db     05h             ;5
  3127.         .db     06h             ;6
  3128.         .db     07h             ;7
  3129.         .db     08h             ;8
  3130.         .db     09h             ;9
  3131.         .db     0ah             ;0
  3132.         .db     0bh             ;-
  3133.         .db     0ch             ;=
  3134.         .db     41h             ;Backspace
  3135.         .db     42h             ;Tab
  3136.  
  3137.         .db     10h             ;Q
  3138.         .db     11h             ;W
  3139.         .db     12h             ;E
  3140.         .db     13h             ;R
  3141.         .db     14h             ;T
  3142.         .db     15h             ;Y
  3143.         .db     16h             ;U
  3144.         .db     17h             ;I
  3145.         .db     18h             ;O
  3146.         .db     19h             ;P
  3147.         .db     1Ah             ;[
  3148.         .db     1Bh             ;]
  3149.         .db     44h             ;ENTER
  3150.         .db     66h             ;L.CTL=LEFT AMIGA
  3151.         .db     20h             ;A
  3152.         .db     21h             ;S
  3153.  
  3154.         .db     22h             ;D
  3155.         .db     23h             ;F
  3156.         .db     24h             ;G
  3157.         .db     25h             ;H
  3158.         .db     26h             ;J
  3159.         .db     27h             ;K
  3160.         .db     28h             ;L
  3161.         .db     29h             ;';'
  3162.         .db     2Ah             ;'
  3163.         .db     00h             ;~
  3164.         .db     60h             ;Left Shift
  3165.         .db     0dh             ;\
  3166.         .db     31h             ;Z
  3167.         .db     32h             ;X
  3168.         .db     33h             ;C
  3169.         .db     34h             ;V
  3170.  
  3171.         .db     35h             ;B
  3172.         .db     36h             ;N
  3173.         .db     37h             ;M
  3174.         .db     38h             ;<
  3175.         .db     39h             ;>
  3176.         .db     3Ah             ;/
  3177.         .db     61h             ;Right Shift
  3178.         .db     5dh             ;Numeric *
  3179.         .db     64h             ;Left Alt
  3180.         .db     40h             ;space
  3181.         .db     62h             ;CapsLock
  3182.         .db     50h             ;F1
  3183.         .db     51h             ;F2
  3184.         .db     52h             ;F3
  3185.         .db     53h             ;F4
  3186.         .db     54h             ;F5
  3187.  
  3188.         .db     55h             ;F6
  3189.         .db     56h             ;F7
  3190.         .db     57h             ;F8
  3191.         .db     58h             ;F9
  3192.         .db     59h             ;F10
  3193.         .db     63h             ;Number Lock=Control
  3194.         .db     67h             ;Scroll Lock=Right Amiga
  3195.         .db     3dh             ;Numeric 7
  3196.         .db     3eh             ;* 8
  3197.         .db     3fh             ;* 9
  3198.         .db     4ah             ;* -
  3199.         .db     2dh             ;* 4
  3200.         .db     2eh             ;* 5
  3201.         .db     2fh             ;* 6
  3202.         .db     5eh             ;* +
  3203.         .db     1dh             ;* 1
  3204.  
  3205.         .db     1eh             ;* 2
  3206.         .db     1fh             ;* 3
  3207.         .db     0fh             ;* 0
  3208.         .db     3ch             ;* .
  3209.         .db     63h             ;print screen=CONTROL
  3210.         .db     0
  3211.         .db     0
  3212.         .db     5ah             ;F11=Numeric (
  3213.         .db     5bh             ;F12=Numeric )
  3214.         .rs     7
  3215.  
  3216.         .rs     10h
  3217.  
  3218.         .rs     10h
  3219. XTtb2:
  3220.         .rs     10h
  3221.  
  3222.         .rs     12
  3223.         .db     43h             ;Numeric Enter
  3224.         .db     67h             ;Right Control=RIGHT AMIGA
  3225.         .rs     2
  3226.  
  3227.         .rs     10h
  3228.         
  3229.         .rs     5
  3230.         .db     5ch             ;Numeric /key
  3231.         .db     0
  3232.         .db     66h             ;Print Screeen=Left Amiga
  3233.         .db     65h             ;Right Alt
  3234.         .rs     7
  3235.  
  3236.         .rs     6
  3237.         .db     5fh             ;BREAK=HELP!
  3238.         .db     0eh             ;Home=MOUSE UP
  3239.         .db     4ch             ;cursor up
  3240.         .db     47h             ;pageup=mouse right
  3241.         .db     0
  3242.         .db     4fh             ;cursor left
  3243.         .db     0
  3244.         .db     4eh             ;cursor right
  3245.         .db     0
  3246.         .db     1ch             ;End=mouse down
  3247.  
  3248.         .db     4dh             ;cursor down
  3249.         .db     5fh             ;page down=HELP!
  3250.         .db     2ch             ;insert=mouse left
  3251.         .db     46h             ;delete
  3252.         .rs     12
  3253.        
  3254.         .rs     15
  3255.         .db     63h             ;Macro=control
  3256.  
  3257.         .rs     10h
  3258.  
  3259.         .end    0
  3260.  
  3261. @\Rogue\Monster\
  3262. else
  3263.   echo "shar: Will not over write key.asm"
  3264. fi
  3265. if `test ! -s key.asm.hex`
  3266. then
  3267. echo "x - key.asm.hex"
  3268. cat > key.asm.hex << '@\Rogue\Monster\'
  3269. 0000:    02 02 00 02 04 D0 00 00  00 00 00 00 00 00 00 00 
  3270. 0010:    00 00 00 00 00 00 00 00  00 00 00 02 05 B4 00 00 
  3271. 0200:    75 89 11 75 88 05 75 A8  00 D2 AF D2 AB D2 A8 D2 
  3272. 0210:    B2 D2 B9 75 81 30 75 90  FF C2 8E C2 8F C2 8C C2 
  3273. 0220:    8D C2 43 C2 44 C2 42 D2  45 D2 46 D2 47 75 8B 00 
  3274. 0230:    75 8D 00 79 02 D2 8E 20  94 FD 30 94 FD C2 8E 74 
  3275. 0240:    FD B1 6F 74 FE B1 6F 30  97 19 20 91 2A 75 8C 00 
  3276. 0250:    75 8A 00 C2 8D D2 8C 20  8D 09 30 91 FA C2 8C C2 
  3277. 0260:    8D 80 14 C2 4B C2 8D C2  90 30 8D FD D2 90 C2 8C 
  3278. 0270:    C2 8D 71 5C 02 03 7A D2  4B 74 FF 71 1F 74 F6 71 
  3279. 0280:    1F 74 ED 71 1F 74 02 71  1F 74 F4 71 1F 02 02 CB 
  3280. 0290:    78 0B D2 90 20 90 FD 18  B8 0A 02 80 29 B8 00 1A 
  3281. 02A0:    30 90 FD C2 90 78 14 D8  FE 20 D0 04 30 48 05 22 
  3282. 02B0:    20 48 01 22 74 FE 71 1F  80 D6 B8 01 06 A2 91 92 
  3283. 02C0:    48 80 03 A2 91 13 30 90  FD 80 C9 51 90 B4 E1 10 
  3284. 02D0:    51 90 51 90 51 90 51 90  51 90 51 90 51 90 80 EB 
  3285. 02E0:    90 05 D5 B4 E0 22 90 06  55 51 90 B4 F0 0E 51 90 
  3286. 02F0:    B4 12 03 02 02 CB B4 59  1E 02 02 CB B4 12 03 02 
  3287. 0300:    02 CB B4 59 0A 02 02 CB  B4 F0 04 51 90 80 08 93 
  3288. 0310:    C2 E7 71 BF 02 02 CB 93  D2 E7 71 BF 02 02 CB D2 
  3289. 0320:    90 C2 91 78 08 20 90 FD  A2 E0 92 91 03 30 90 FD 
  3290. 0330:    18 B8 00 F1 A2 D0 B3 20  90 FD 92 91 30 90 FD 20 
  3291. 0340:    90 FD D2 91 30 90 FD 20  90 FD 30 90 FD 78 08 D8 
  3292. 0350:    FE C2 90 78 14 D8 FE D2  90 51 90 22 D2 91 78 08 
  3293. 0360:    20 90 FD 30 90 FD 20 90  FD 30 90 FD 20 90 FD A2 
  3294. 0370:    91 13 30 90 FD D8 F5 C2  91 22 71 5C B4 E1 0C 71 
  3295. 0380:    5C 71 5C 71 5C 71 5C 71  5C 80 EF B4 E0 29 71 5C 
  3296. 0390:    B4 AA 02 80 E5 B4 2A 02  80 E0 B4 B6 02 80 DB B4 
  3297. 03A0:    36 02 80 D6 90 07 55 A2  E7 92 4A C2 E7 93 A2 4A 
  3298. 03B0:    92 E7 71 BF 02 03 7A 90  06 D5 80 EB D0 E0 22 B5 
  3299. 03C0:    51 01 22 B4 62 05 F5 51  D2 43 22 B4 E2 30 E5 51 
  3300. 03D0:    30 4B 03 B4 62 1D C2 43  B2 42 74 62 A2 42 B3 92 
  3301. 03E0:    E7 B1 6F 30 4B 0C 74 ED  71 1F 74 02 A2 42 92 E2 
  3302. 03F0:    71 1F 22 C2 44 C2 43 74  63 D2 E7 B1 6F 22 F5 51 
  3303. 0400:    30 4B 0E 30 43 0B 20 44  08 D2 44 74 63 B1 6F E5 
  3304. 0410:    51 A2 E7 92 49 C2 E7 B4  0E 19 30 49 0B 74 CC B1 
  3305. 0420:    6F 91 87 74 E7 B1 6F 22  74 67 B1 6F 91 87 74 4C 
  3306. 0430:    B1 6F 22 B4 1C 19 30 49  0B 74 CD B1 6F 74 E7 91 
  3307. 0440:    87 B1 6F 22 74 67 B1 6F  91 87 74 4D B1 6F 22 B4 
  3308. 0450:    2C 19 30 49 0B 74 CF B1  6F 91 87 74 E7 B1 6F 22 
  3309. 0460:    74 67 B1 6F 91 87 74 4F  B1 6F 22 B4 47 2B 30 49 
  3310. 0470:    0B 74 CE B1 6F 91 87 74  E7 B1 6F 22 74 67 B1 6F 
  3311. 0480:    91 87 74 4E B1 6F 22 75  8C 00 75 8A 00 C2 8D D2 
  3312. 0490:    8C 30 8D FD C2 8D C2 8C  22 E5 51 B1 6F E5 51 A2 
  3313. 04A0:    E7 92 49 C2 E7 B4 63 06  A2 49 92 45 80 10 B4 66 
  3314. 04B0:    06 A2 49 92 46 80 07 B4  67 04 A2 49 92 47 30 45 
  3315. 04C0:    05 20 44 02 80 08 20 46  05 20 47 02 80 04 22 32 
  3316. 04D0:    91 CF C2 8D E5 78 79 02  75 8A 00 75 8C 00 F4 78 
  3317. 04E0:    08 23 A2 E7 92 94 75 F0  08 D5 F0 FD C2 93 75 F0 
  3318. 04F0:    08 D5 F0 FD D2 93 75 F0  0A D5 F0 FD D8 E3 D2 94 
  3319. 0500:    D2 8C 30 94 09 30 8D FA  C2 8D D9 F6 80 41 C2 8C 
  3320. 0510:    C2 8D E5 78 79 04 75 8A  00 75 8C 00 F4 78 08 23 
  3321. 0520:    A2 E7 92 94 75 F0 08 D5  F0 FD C2 93 75 F0 08 D5 
  3322. 0530:    F0 FD D2 93 75 F0 0A D5  F0 FD D8 E3 D2 94 D2 8C 
  3323. 0540:    30 94 09 30 8D FA C2 8D  D9 F6 80 03 30 94 FD C2 
  3324. 0550:    8C C2 8D C2 95 C2 93 79  0F 75 8C 00 75 8A 00 D2 
  3325. 0560:    8C 30 8D FD C2 8D D9 F9  C2 8D C2 8C 02 02 00 F5 
  3326. 0570:    52 78 05 75 F0 00 D5 F0  FD D8 F8 E5 52 C2 50 79 
  3327. 0580:    02 75 8B 00 75 8D 00 F4  78 08 23 A2 E7 92 94 75 
  3328. 0590:    F0 08 D5 F0 FD C2 93 75  F0 08 D5 F0 FD D2 93 75 
  3329. 05A0:    F0 0A D5 F0 FD D8 E3 D2  94 D2 8E 20 94 FD C2 8E 
  3330. 05B0:    30 94 FD 22 D9 1E 79 02  D2 50 C2 94 75 F0 08 D5 
  3331. 05C0:    F0 FD C2 93 75 F0 08 D5  F0 FD D2 93 75 F0 0A D5 
  3332. 05D0:    F0 FD D2 94 32 00 58 00  54 52 50 51 5B 00 59 57 
  3333. 05E0:    55 53 42 00 00 00 64 60  00 66 10 01 00 00 00 31 
  3334. 05F0:    21 20 11 02 00 00 33 32  22 12 04 03 00 00 40 34 
  3335. 0600:    23 14 13 05 00 00 36 35  25 24 15 06 00 00 00 37 
  3336. 0610:    26 16 07 08 00 00 38 27  17 18 0A 09 00 00 39 3A 
  3337. 0620:    28 29 19 0B 00 00 00 2A  00 1A 0C 00 00 62 61 44 
  3338. 0630:    1B 00 0D 00 00 00 00 00  00 00 00 41 00 00 1D 00 
  3339. 0640:    2D 3D 00 00 00 0F 3C 1E  2E 2F 3E 45 63 5A 5E 1F 
  3340. 0650:    4A 5D 3F 67 00 00 00 00  56 66 00 00 00 00 00 00 
  3341. 0660:    00 00 00 00 00 00 65 00  00 67 00 00 00 00 00 00 
  3342. 0690:    00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 5C 
  3343. 06A0:    00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 43 
  3344. 06B0:    00 00 00 00 00 00 00 00  00 00 00 00 00 00 1C 00 
  3345. 06C0:    4F 0E 00 00 63 2C 46 4D  00 4E 4C 00 00 00 00 5F 
  3346. 06D0:    00 66 47 40 00 00 45 01  02 03 04 05 06 07 08 09 
  3347. 06E0:    0A 0B 0C 41 42 10 11 12  13 14 15 16 17 18 19 1A 
  3348. 06F0:    1B 44 66 20 21 22 23 24  25 26 27 28 29 2A 00 60 
  3349. 0700:    0D 31 32 33 34 35 36 37  38 39 3A 61 5D 64 40 62 
  3350. 0710:    50 51 52 53 54 55 56 57  58 59 63 67 3D 3E 3F 4A 
  3351. 0720:    2D 2E 2F 5E 1D 1E 1F 0F  3C 63 00 00 5A 5B 00 00 
  3352. 0770:    00 43 67 00 00 00 00 00  00 00 00 00 00 00 00 00 
  3353. 0780:    00 00 00 00 00 00 00 00  00 00 5C 00 66 65 00 00 
  3354. 0790:    00 00 00 00 00 00 00 00  00 00 00 5F 0E 4C 47 00 
  3355. 07A0:    4F 00 4E 00 1C 4D 5F 2C  46 00 00 00 00 00 00 00 
  3356. 07C0:    00 00 00 00 63 00 00 00  00 00 00 00 00 00 00 00 
  3357. @\Rogue\Monster\
  3358. else
  3359.   echo "shar: Will not over write key.asm.hex"
  3360. fi
  3361. if `test ! -s key.list`
  3362. then
  3363. echo "x - key.list"
  3364. cat > key.list << '@\Rogue\Monster\'
  3365. 000001 0000                  ;* these equates are explained below. Relocate them to any of
  3366. 000002 0000                  ;* Port1, pins 0-7 or Port3, pins 0-7, except Port3, pins2 and 3
  3367. 000003 0000                  ;* because these are the external interrupts.
  3368. 000004 0000                  
  3369. 000005 0090                          .equ    Kclk,p1.0
  3370. 000006 0091                          .equ    Kdat,p1.1
  3371. 000007 0092                          .equ    Kreset,p1.2 
  3372. 000008 0093                          .equ    Aclk,p1.3
  3373. 000009 0094                          .equ    Adat,p1.4
  3374. 000010 0095                          .equ    Areset,p1.5
  3375. 000011 0097                          .equ    Kswitch,p1.7
  3376. 000012 0000                  
  3377. 000013 0000                          .org    0000h
  3378. 000014 0000 020200           init:   ljmp    start
  3379. 000015 0003                          .org    0003h
  3380. 000016 0003 0204D0                   ljmp    resetint
  3381. 000017 001B                          .org    001bh
  3382. 000018 001B 0205B4                   ljmp    timer1int
  3383. 000019 001E                  
  3384. 000020 001E                  ;**************************************************
  3385. 000021 001E                  ;*
  3386. 000022 001E                  ;*
  3387. 000023 001E                  ;* Equates Descriptions:
  3388. 000024 001E                  ;* 
  3389. 000025 001E                  ;*    Watch1 is a flag which tells the IBM keycode parser that
  3390. 000026 001E                  ;* some extranneous codes are to come across the lines. In 
  3391. 000027 001E                  ;* particular, these codes will be either E0 4A or E0 59. The 
  3392. 000028 001E                  ;* parser should ignore them.
  3393. 000029 001E                  ;*      Watch2 is also the same type of flag as Watch1. It
  3394. 000030 001E                  ;* tells the parser that E0 12 59 will follow and to ignore it.
  3395. 000031 001E                  ;*
  3396. 000032 001E                  ;*      Aclk is the line to the Amiga keyboard clock in. (P1.3)
  3397. 000033 001E                  ;*      Adat is the line to the Amiga keyboard data in. (P1.4)
  3398. 000034 001E                  ;*      Areset is the Amiga Reset line (P1.5)
  3399. 000035 001E                  ;*      Kclk is the line to the Keyboard clock out (P1.0)
  3400. 000036 001E                  ;*      Kdat is the line to the Keyboard data out (P1.1)
  3401. 000037 001E                  ;*      Kreset is the Keyboard Reset line (P1.2)
  3402. 000038 001E                  ;*      Kstyle is bit defining whether or not the keyboard
  3403. 000039 001E                  ;*        is AT or XT. if AT, Kstyle=1
  3404. 000040 001E                  ;*
  3405. 000041 001E                  ;*      Oldchar is the last character typed to go to the Amiga.
  3406. 000042 001E                  ;* This is used to tell if the Capslock was Pressed and 
  3407. 000043 001E                  ;* Released without pressing any other keys. If this was done, 
  3408. 000044 001E                  ;* then it is a "Caps Lock" otherwise, the Caps key functions
  3409. 000045 001E                  ;* as the Control Key because of the keyboard remapping.
  3410. 000046 001E                  ;*
  3411. 000047 001E                  ;*      Capbit is the flag which tells whether the Caps Lock
  3412. 000048 001E                  ;* should be down or up.
  3413. 000049 001E                  ;*      Capdown is the flag which tells whether the Caps Lock 
  3414. 000050 001E                  ;* KEY is presently down or up. The difference between Capdown 
  3415. 000051 001E                  ;* and Capbit is that Capdown relates to the KEY. Capbit toggles 
  3416. 000052 001E                  ;* once for every "press and release" of the Cap Lock Key. 
  3417. 000053 001E                  ;* Press and release Cap Lock Key, and Capbit goes low.....
  3418. 000054 001E                  ;* Press and release it again, and Capbit goes high....
  3419. 000055 001E                  ;*      Cntldown is the flag which is set and reset when you 
  3420. 000056 001E                  ;* press Cap Lock and then another key. Then, Cap Lock Key 
  3421. 000057 001E                  ;* functions as the Control Key.
  3422. 000058 001E                  ;* LAMIGA,RAMIGA,and CONTROL are all flags that tell if those 
  3423. 000059 001E                  ;* keys are being held down. When all three are, the computer
  3424. 000060 001E                  ;* will reset.
  3425. 000061 001E                  ;*
  3426. 000062 001E                  ;* ATparity is the 10th bit that the AT keyboard transmits. It 
  3427. 000063 001E                  ;* is SET if the number of DATA bits set is EVEN. Otherwise, its
  3428. 000064 001E                  ;* CLEARED.
  3429. 000065 001E                  ;*
  3430. 000066 001E                  ;**************************************************
  3431. 000067 001E                  
  3432. 000068 001E                          ;bit memory locations:
  3433. 000069 001E                  
  3434. 000070 0042                          .equ    Capbit,42h
  3435. 000071 0043                          .equ    Capdown,43h
  3436. 000072 0044                          .equ    Ctrldown,44h
  3437. 000073 0045                          .equ    CONTROL,45h
  3438. 000074 0046                          .equ    LAMIGA,46h
  3439. 000075 0047                          .equ    RAMIGA,47h
  3440. 000076 0048                          .equ    ATparity,48h
  3441. 000077 0049                          .equ    Make,49h
  3442. 000078 004A                          .equ    XT7bit,4ah
  3443. 000079 004B                          .equ    Kstyle,4bh
  3444. 000080 001E                  
  3445. 000081 001E                          ;byte memory locations:
  3446. 000082 001E                  
  3447. 000083 0050                          .equ    Charbad,50h
  3448. 000084 0051                          .equ    Oldchar,51h
  3449. 000085 0052                          .equ    Amigachar,52h
  3450. 000086 001E                  
  3451. 000087 0200                          .org    0200h
  3452. 000088 0200                  
  3453. 000089 0200 758911           start:  mov     tmod,#11h       ;two 16 bit timers
  3454. 000090 0203 758805                   mov     tcon,#05h
  3455. 000091 0206 75A800                   mov     ie,#00h         ;clear all interrupts
  3456. 000092 0209 D2AF                     setb    ea
  3457. 000093 020B D2AB                     setb    et1             ;enable timer 1
  3458. 000094 020D D2A8                     setb    ex0             ;enable external 0
  3459. 000095 020F D2B2                     setb    int0            ;make sure it's high
  3460. 000096 0211 D2B9                     setb    pt0
  3461. 000097 0213 758130                   mov     sp,#30h         ;stack somewhere safe.
  3462. 000098 0216                  
  3463. 000099 0216                  ; set the ports for input
  3464. 000100 0216 7590FF                   mov     p1,#255         ;set port1 for read
  3465. 000101 0219 C28E                     clr     tr1             ;make sure timers are in
  3466. 000102 021B C28F                     clr     tf1             ;reset state.
  3467. 000103 021D C28C                     clr     tr0
  3468. 000104 021F C28D                     clr     tf0
  3469. 000105 0221                  
  3470. 000106 0221                  ; clear out the miscellaneous flags.
  3471. 000107 0221 C243                     clr     Capdown         ;Caps is up...
  3472. 000108 0223 C244                     clr     Ctrldown        ;Control is up
  3473. 000109 0225 C242                     clr     Capbit          ;Caps light is off.
  3474. 000110 0227 D245                     setb    CONTROL         ;all reset keys are UP
  3475. 000111 0229 D246                     setb    LAMIGA
  3476. 000112 022B D247                     setb    RAMIGA
  3477. 000113 022D                  
  3478. 000114 022D                  ;**** sync the controller with the Amiga. clock out
  3479. 000115 022D                  ;**** ones until we receive a handshake...
  3480. 000116 022D                  sync:
  3481. 000117 022D 758B00                   mov     tl1,#0          ;set up timer for 143ms
  3482. 000118 0230 758D00                   mov     th1,#0
  3483. 000119 0233 7902                     mov     r1,#2
  3484. 000120 0235 D28E                     setb     tr1
  3485. 000121 0237                  sync2:
  3486. 000122 0237 2094FD                   jb      Adat,sync2      ;wait for handshake
  3487. 000123 023A                  sync3:
  3488. 000124 023A 3094FD                   jnb     Adat,sync3      ;wait for end of handshake
  3489. 000125 023D C28E                     clr     tr1
  3490. 000126 023F                  
  3491. 000127 023F                  ;**** transmit power up key stream and end key stream.
  3492. 000128 023F 74FD                     mov     a,#0FDh
  3493. 000129 0241 B16F                     acall   actualtransmit
  3494. 000130 0243 74FE                     mov     a,#0FEh
  3495. 000131 0245 B16F                     acall   actualtransmit
  3496. 000132 0247                  
  3497. 000133 0247                  ;**** test for XT keyboard, if Kswitch is low, automatically
  3498. 000134 0247                  ;**** jump to XT mode.
  3499. 000135 0247                  ;**** otherwise, test to see if Kdat is low and stays there.
  3500. 000136 0247                  ;**** If so, it's in XT mode.                                
  3501. 000137 0247 309719                   jnb     Kswitch,XTPowerup 
  3502. 000138 024A 20912A                   jb      Kdat,ATPowerup
  3503. 000139 024D 758C00                   mov     th0,#0
  3504. 000140 0250 758A00                   mov     tl0,#0
  3505. 000141 0253 C28D                     clr     tf0
  3506. 000142 0255 D28C                     setb    tr0
  3507. 000143 0257 208D09           XTtest: jb      tf0,XTPowerup   ;timer ran out. XT mode.
  3508. 000144 025A 3091FA                   jnb     Kdat,XTtest     ;data is low, but for how long?
  3509. 000145 025D C28C                     clr     tr0
  3510. 000146 025F C28D                     clr     tf0
  3511. 000147 0261 8014                     sjmp    ATPowerup
  3512. 000148 0263                  XTPowerup:
  3513. 000149 0263 C24B                     clr     Kstyle          ;XT flag.
  3514. 000150 0265 C28D                     clr     tf0
  3515. 000151 0267 C290                     clr     Kclk            ;Clock low=Reset for the XT.
  3516. 000152 0269                  XTreset:
  3517. 000153 0269 308DFD                   jnb     tf0,XTreset
  3518. 000154 026C D290                     setb    Kclk
  3519. 000155 026E C28C                     clr     tr0
  3520. 000156 0270 C28D                     clr     tf0
  3521. 000157 0272 715C             ll:     acall   XTgetkey        ;(Should be AA)
  3522. 000158 0274 02037A                   ljmp    XTstyle
  3523. 000159 0277                  
  3524. 000160 0277                  ;**** sync up the AT and go with it!
  3525. 000161 0277                  
  3526. 000162 0277                  ATPowerup:
  3527. 000163 0277 D24B                     setb    Kstyle
  3528. 000164 0279 74FF                     mov     a,#0ffh         ;RESET
  3529. 000165 027B 711F                     acall   SendtoAT
  3530. 000166 027D 74F6                     mov     a,#0f6h         ;DEFAULT
  3531. 000167 027F 711F                     acall   SendtoAT
  3532. 000168 0281 74ED                     mov     a,#0edh         ;NEXT DATA is FOR LIGHTS
  3533. 000169 0283 711F                     acall   SendtoAT
  3534. 000170 0285 7402                     mov     a,#2            ;NUMLOCK ON?
  3535. 000171 0287 711F                     acall   SendtoAT
  3536. 000172 0289 74F4                     mov     a,#0f4h         ;CLEAR BUFFER
  3537. 000173 028B 711F                     acall   SendtoAT
  3538. 000174 028D 0202CB                   ljmp    ATstyle         ;go and parse AT keyboard
  3539. 000175 0290                  
  3540. 000176 0290                  ;***********************************************
  3541. 000177 0290                  ;* ATgetkey
  3542. 000178 0290                  ;* ATgetkey
  3543. 000179 0290                  ;* ATgetkey
  3544. 000180 0290                  ;*
  3545. 000181 0290                  ;* ATgetkey looks at the keyboard and waits for a key to be
  3546. 000182 0290                  ;* pressed. ATinkey is the actual routine that watched the logic
  3547. 000183 0290                  ;* levels of Kdat and Kclk. IF the character's parity is not 
  3548. 000184 0290                  ;* what it is supposed to be, then the routine will attempt to
  3549. 000185 0290                  ;* tell the keyboard to resend.
  3550. 000186 0290                  ;*
  3551. 000187 0290                  ;* When exiting from this routine, Kclock is pulled low to hold 
  3552. 000188 0290                  ;* off any more transmissions. You must restore it to 5 volts to
  3553. 000189 0290                  ;* receive any more characters later.
  3554. 000190 0290                  ;*
  3555. 000191 0290                  ;*
  3556. 000192 0290                  
  3557. 000193 0290                  ATgetkey:
  3558. 000194 0290 780B                     mov     r0,#11          ;number of bits
  3559. 000195 0292 D290                     setb    Kclk
  3560. 000196 0294                  ATwaitC0:         
  3561. 000197 0294 2090FD                   jb      Kclk,ATwaitC0   ;wait for a clock pulse
  3562. 000198 0297 18                       dec     r0              ;decrement clock bit counter
  3563. 000199 0298 B80A02                   cjne    r0,#10,ATnstart ;test for startbit
  3564. 000200 029B 8029                     sjmp    ATwait  
  3565. 000201 029D                  ATnstart:
  3566. 000202 029D B8001A                   cjne    r0,#0,ATnstop   ;check for stopbit      
  3567. 000203 02A0                  ATwaitC1:
  3568. 000204 02A0 3090FD                   jnb     Kclk,ATwaitC1   ;wait for clock to go high                     
  3569. 000205 02A3 C290                     clr     Kclk            ;hold off more data
  3570. 000206 02A5 7814                     mov     r0,#20          ;small delay
  3571. 000207 02A7 D8FE             pause:  djnz    r0,pause
  3572. 000208 02A9                  ;**** now we check to see if the parity between
  3573. 000209 02A9                  ;**** Bit register P (which is set if Parity of Acc is odd)
  3574. 000210 02A9                  ;**** is compared to the received Parity Bit.
  3575. 000211 02A9 20D004                   jb      p,parityodd     ;test if parity of DATA is odd
  3576. 000212 02AC                  parityeven:
  3577. 000213 02AC 304805                   jnb     ATparity,ATerror
  3578. 000214 02AF 22                       ret                     ;Okay to return. A=valid
  3579. 000215 02B0                  parityodd:
  3580. 000216 02B0 204801                   jb      ATparity,ATerror
  3581. 000217 02B3 22                       ret                     ;Okay to return. A=valid
  3582. 000218 02B4                  ATerror:
  3583. 000219 02B4 74FE                     mov     a,#0feh         ;RESEND character
  3584. 000220 02B6 711F                     acall   SendtoAT
  3585. 000221 02B8 80D6                     sjmp    ATgetkey        ;now return to caller
  3586. 000222 02BA                  ATnstop:
  3587. 000223 02BA B80106                   cjne    r0,#1,ATdatab   ;check for paritybit
  3588. 000224 02BD A291                     mov     c,Kdat          ;error checking! (AT only)
  3589. 000225 02BF 9248                     mov     ATparity,c
  3590. 000226 02C1 8003                     sjmp    ATwait          ;
  3591. 000227 02C3                  ATdatab: 
  3592. 000228 02C3 A291                     mov     c,Kdat          ;get data bit
  3593. 000229 02C5 13                       rrc     a               ;shift it into accumulator
  3594. 000230 02C6 3090FD           ATwait: jnb     Kclk,ATwait     ;wait for clock line to go low
  3595. 000231 02C9 80C9                     sjmp    ATwaitC0        ;get another bit
  3596. 000232 02CB                  
  3597. 000233 02CB                  
  3598. 000234 02CB                  ;**************************************************
  3599. 000235 02CB                  ;* AT-STYLE
  3600. 000236 02CB                  ;*
  3601. 000237 02CB                  ;*     This waits for a keycode or two from the IBM and then calls
  3602. 000238 02CB                  ;* the appropriate transmit subroutine. The IBM keyboard sends 
  3603. 000239 02CB                  ;* out special codes in front of and behind some scancodes. This
  3604. 000240 02CB                  ;* routine will chop them out before doing a lookup on the 
  3605. 000241 02CB                  ;* code to see what to send to the AMIGA. The scancodes between 
  3606. 000242 02CB                  ;* the IBM and the AMIGA are of course, not the same!
  3607. 000243 02CB                  ;*
  3608. 000244 02CB                  ;**************************************************
  3609. 000245 02CB                  
  3610. 000246 02CB                  ATstyle:
  3611. 000247 02CB 5190                     acall   ATgetkey          ;get one scancode.
  3612. 000248 02CD B4E110                   cjne    a,#0e1h,ATnE1
  3613. 000249 02D0 5190                     acall   ATgetkey          ;(should be 14)
  3614. 000250 02D2 5190                     acall   ATgetkey          ;(should be 77)
  3615. 000251 02D4 5190                     acall   ATgetkey          ;(should be E1)
  3616. 000252 02D6 5190                     acall   ATgetkey          ;(should be F0)
  3617. 000253 02D8 5190                     acall   ATgetkey          ;(should be 14)
  3618. 000254 02DA 5190                     acall   ATgetkey          ;(should be F0)
  3619. 000255 02DC 5190                     acall   ATgetkey          ;(should be 77)
  3620. 000256 02DE 80EB                     sjmp    ATstyle
  3621. 000257 02E0                  ;PAUSE was pressed. Just ignore it.
  3622. 000258 02E0                  ATnE1:
  3623. 000259 02E0 9005D5                   mov     dptr,#ATtb1
  3624. 000260 02E3 B4E022                   cjne    a,#0e0h,ATnE0
  3625. 000261 02E6 900655                   mov     dptr,#ATtb2
  3626. 000262 02E9 5190                     acall   ATgetkey
  3627. 000263 02EB B4F00E                   cjne    a,#0f0h,ATnE0F0
  3628. 000264 02EE 5190                     acall   ATgetkey
  3629. 000265 02F0 B41203                   cjne    a,#12h,ATnEF12
  3630. 000266 02F3 0202CB                   ljmp    ATstyle         ;(E0F012....ignore it)
  3631. 000267 02F6                  ATnEF12:
  3632. 000268 02F6 B4591E                   cjne    a,#59h,ATup     ;(E0F0mk)
  3633. 000269 02F9 0202CB                   ljmp    ATstyle         ;(E0F059....ignore it)
  3634. 000270 02FC                  ATnE0F0:
  3635. 000271 02FC B41203                   cjne    a,#12h,ATnE012
  3636. 000272 02FF 0202CB                   ljmp    ATstyle         ;(E012....ignore it)
  3637. 000273 0302                  ATnE012:
  3638. 000274 0302 B4590A                   cjne    a,#59h,ATdown   ;(E0mk)
  3639. 000275 0305 0202CB                   ljmp    ATstyle         ;(E059....ignore it)
  3640. 000276 0308                  ATnE0:
  3641. 000277 0308 B4F004                   cjne    a,#0f0h,ATdown  ;(mk)
  3642. 000278 030B 5190                     acall   ATgetkey
  3643. 000279 030D 8008                     sjmp    ATup            ;(F0mk....normal key break)
  3644. 000280 030F                  
  3645. 000281 030F                  ;**************************************************
  3646. 000282 030F                  ;* ATdown and the rest here call a lookup table to change
  3647. 000283 030F                  ;* the AT scancodes into AMIGA scancodes. In the "down"
  3648. 000284 030F                  ;* routine, the "make" bit is asserted. In the "up" routine
  3649. 000285 030F                  ;* it is de-asserted.
  3650. 000286 030F                  ;**************************************************
  3651. 000287 030F                  ATdown:
  3652. 000288 030F 93                       movc    a,@a+dptr       ;indexed into table
  3653. 000289 0310 C2E7                     clr     acc.7           ;clear make/break bit
  3654. 000290 0312 71BF                     acall   transmit        ;transmit it
  3655. 000291 0314 0202CB                   ljmp    ATstyle
  3656. 000292 0317                  ATup:
  3657. 000293 0317 93                       movc    a,@a+dptr
  3658. 000294 0318 D2E7                     setb    acc.7           ;set make/break bit
  3659. 000295 031A 71BF                     acall   transmit        ;transmit it
  3660. 000296 031C 0202CB                   ljmp    ATstyle
  3661. 000297 031F                  
  3662. 000298 031F                  ;**************************************************
  3663. 000299 031F                  ;* SendtoAT is the subroutine that sends special codes
  3664. 000300 031F                  ;* to the keyboard from the controller. Codes include
  3665. 000301 031F                  ;* the command to reset (FF) or the command to change
  3666. 000302 031F                  ;* the lights (ED). It is advisable to keep the timing
  3667. 000303 031F                  ;* very close to how I have it done in this routine.
  3668. 000304 031F                  ;**************************************************
  3669. 000305 031F                  
  3670. 000306 031F                  SendtoAT:
  3671. 000307 031F D290                     setb    Kclk
  3672. 000308 0321 C291                     clr     Kdat
  3673. 000309 0323 7808                     mov     r0,#8
  3674. 000310 0325 2090FD           Send4:  jb      Kclk,Send4      ;data bit
  3675. 000311 0328 A2E0                     mov     c,acc.0
  3676. 000312 032A 9291                     mov     Kdat,c
  3677. 000313 032C 03                       rr      a 
  3678. 000314 032D 3090FD           Send5:  jnb     Kclk,Send5      ;data bit
  3679. 000315 0330 18                       dec     r0
  3680. 000316 0331 B800F1                   cjne    r0,#0,Send4
  3681. 000317 0334 A2D0                     mov     c,p
  3682. 000318 0336 B3                       cpl     c
  3683. 000319 0337 2090FD           Send6:  jb      Kclk,Send6      ;parity bit
  3684. 000320 033A 9291                     mov     Kdat,c
  3685. 000321 033C 3090FD           Send7:  jnb     Kclk,Send7      ;parity bit
  3686. 000322 033F 2090FD           Send77: jb      Kclk,Send77     ;stop bit
  3687. 000323 0342 D291                     setb    Kdat
  3688. 000324 0344 3090FD           Send78: jnb     Kclk,Send78     ;stop bit
  3689. 000325 0347 2090FD           Send79: jb      Kclk,Send79
  3690. 000326 034A 3090FD           Send7a: jnb     Kclk,Send7a
  3691. 000327 034D 7808                     mov     r0,#8           ;small delay
  3692. 000328 034F D8FE             Send8:  djnz    r0,Send8
  3693. 000329 0351 C290                     clr     Kclk            ;drive clock low
  3694. 000330 0353 7814                     mov     r0,#20          ;long delay
  3695. 000331 0355 D8FE             Send9:  djnz    r0,Send9
  3696. 000332 0357 D290                     setb    Kclk
  3697. 000333 0359 5190                     acall   ATgetkey        ;should check if response isbad.
  3698. 000334 035B 22                       ret                     ;who cares if it is? not me!
  3699. 000335 035C                  
  3700. 000336 035C                  XTgetkey:
  3701. 000337 035C D291                     setb    Kdat            ;let data flow!
  3702. 000338 035E 7808                     mov     r0,#8
  3703. 000339 0360 2090FD           XTw1:   jb      Kclk,XTw1       ;start bit1
  3704. 000340 0363 3090FD           XTw2:   jnb     Kclk,XTw2       ;start bit1
  3705. 000341 0366 2090FD           XTw3:   jb      Kclk,XTw3       ;start bit2
  3706. 000342 0369 3090FD           XTw4:   jnb     Kclk,XTw4       ;start bit2
  3707. 000343 036C 2090FD           XTw5:   jb      Kclk,XTw5       ;data bit
  3708. 000344 036F A291                     mov     c,Kdat
  3709. 000345 0371 13                       rrc     a
  3710. 000346 0372 3090FD           XTw6:   jnb     Kclk,XTw6       ;data bit
  3711. 000347 0375 D8F5                     djnz    r0,XTw5
  3712. 000348 0377 C291                     clr     Kdat            ;hold off data
  3713. 000349 0379 22                       ret
  3714. 000350 037A                  
  3715. 000351 037A                  XTstyle:
  3716. 000352 037A 715C                     acall   XTgetkey
  3717. 000353 037C B4E10C                   cjne    a,#0e1h,XTnE1
  3718. 000354 037F 715C                     acall   XTgetkey        ;(should be 1d)
  3719. 000355 0381 715C                     acall   XTgetkey        ;(should be 45)
  3720. 000356 0383 715C                     acall   XTgetkey        ;(should be e1)
  3721. 000357 0385 715C                     acall   XTgetkey        ;(should be 9d)
  3722. 000358 0387 715C                     acall   XTgetkey        ;(should be c5)
  3723. 000359 0389 80EF                     sjmp    XTstyle
  3724. 000360 038B                  XTnE1:
  3725. 000361 038B B4E029                   cjne    a,#0e0h,XTnE0
  3726. 000362 038E 715C                     acall   XTgetkey
  3727. 000363 0390 B4AA02                   cjne    a,#0aah,XTnAA
  3728. 000364 0393 80E5                     sjmp    XTstyle
  3729. 000365 0395                  XTnAA:
  3730. 000366 0395 B42A02                   cjne    a,#2ah,XTn2A
  3731. 000367 0398 80E0                     sjmp    XTstyle
  3732. 000368 039A                  XTn2A:
  3733. 000369 039A B4B602                   cjne    a,#0b6h,XTnB6
  3734. 000370 039D 80DB                     sjmp    XTstyle
  3735. 000371 039F                  XTnB6:
  3736. 000372 039F B43602                   cjne    a,#36h,XTn36
  3737. 000373 03A2 80D6                     sjmp    XTstyle
  3738. 000374 03A4                  XTn36:
  3739. 000375 03A4 900755                   mov     dptr,#XTtb2
  3740. 000376 03A7                  XTlookup:
  3741. 000377 03A7 A2E7                     mov     c,acc.7         ;(1=break)
  3742. 000378 03A9 924A                     mov     XT7bit,c
  3743. 000379 03AB C2E7                     clr     acc.7
  3744. 000380 03AD 93                       movc    a,@a+dptr
  3745. 000381 03AE A24A                     mov     c,XT7bit
  3746. 000382 03B0 92E7                     mov     acc.7,c
  3747. 000383 03B2 71BF                     acall   transmit
  3748. 000384 03B4 02037A                   ljmp    XTstyle
  3749. 000385 03B7                  XTnE0:
  3750. 000386 03B7 9006D5                   mov     dptr,#XTtb1
  3751. 000387 03BA 80EB                     sjmp    XTlookup
  3752. 000388 03BC                  
  3753. 000389 03BC                  ;**************************************************
  3754. 000390 03BC                  ;*
  3755. 000391 03BC                  ;* TRANSMIT first does some checking to take out repeating
  3756. 000392 03BC                  ;* keys and does the conversion on the Caps Lock Key and
  3757. 000393 03BC                  ;* then calls Actualtransmit.
  3758. 000394 03BC                  ;*
  3759. 000395 03BC                  ;**************************************************
  3760. 000396 03BC                  
  3761. 000397 03BC                  dontrans:                       ;jumps back if key is already
  3762. 000398 03BC D0E0                     pop     acc             ;held down.
  3763. 000399 03BE 22                       ret
  3764. 000400 03BF                  transmit:
  3765. 000401 03BF B55101                   cjne    a,Oldchar,transok
  3766. 000402 03C2 22                       ret
  3767. 000403 03C3                  transok:
  3768. 000404 03C3 B46205                   cjne    a,#62h,transok2 ;jump if not CapsLock=down
  3769. 000405 03C6 F551                     mov     Oldchar,a
  3770. 000406 03C8 D243                     setb    Capdown         ;set the flags for later
  3771. 000407 03CA 22                       ret
  3772. 000408 03CB                  transok2:                       
  3773. 000409 03CB B4E230                   cjne    a,#0e2h,transok3;jump if not CapsLock=up
  3774. 000410 03CE E551                     mov     a,Oldchar       ;see if Caps was just down
  3775. 000411 03D0 304B03                   jnb     Kstyle,XTcap    ;if XT, skip control feature.
  3776. 000412 03D3 B4621D                   cjne    a,#62h,transok4 ;if not, then it was a control
  3777. 000413 03D6                  XTcap:
  3778. 000414 03D6 C243                     clr     Capdown         ;clear flag
  3779. 000415 03D8 B242                     cpl     Capbit          ;toggle down/up-ness of Caplock
  3780. 000416 03DA 7462                     mov     a,#62h
  3781. 000417 03DC A242                     mov     c,Capbit
  3782. 000418 03DE B3                       cpl     c
  3783. 000419 03DF 92E7                     mov     acc.7,c
  3784. 000420 03E1 B16F                     acall   actualtransmit  ;(Caps to Amiga!)
  3785. 000421 03E3 304B0C                   jnb     Kstyle,skiplights ;(don't do lights if XT)
  3786. 000422 03E6 74ED                     mov     a,#0edh         ;set lights on next byte.
  3787. 000423 03E8 711F                     acall   SendtoAT
  3788. 000424 03EA 7402                     mov     a,#2            ;numlock on
  3789. 000425 03EC A242                     mov     c,Capbit
  3790. 000426 03EE 92E2                     mov     acc.2,c
  3791. 000427 03F0 711F                     acall   SendtoAT        ;maybe capslock light
  3792. 000428 03F2                  skiplights: 
  3793. 000429 03F2 22                       ret           
  3794. 000430 03F3                  transok4:
  3795. 000431 03F3 C244                     clr     CtrlDown        ;This sends out a Control Up.
  3796. 000432 03F5 C243                     clr     Capdown         ;Caps lock is done functioning as Ctl
  3797. 000433 03F7 7463                     mov     a,#63h          ;Control Key
  3798. 000434 03F9 D2E7                     setb    acc.7           ;break bit set.
  3799. 000435 03FB B16F                     acall   actualtransmit  ;send to Amiga.
  3800. 000436 03FD 22                       ret
  3801. 000437 03FE                  transok3:
  3802. 000438 03FE F551                     mov     Oldchar,a
  3803. 000439 0400 304B0E                   jnb     Kstyle,noControl
  3804. 000440 0403 30430B                   jnb     Capdown,noControl
  3805. 000441 0406 204408                   jb      CtrlDown,noControl
  3806. 000442 0409 D244                     setb    CtrlDown        ;Caps lock is beginning to function
  3807. 000443 040B 7463                     mov     a,#63h          ;as the Control Key.
  3808. 000444 040D B16F                     acall   actualtransmit  ;send Control Down to Amiga
  3809. 000445 040F E551                     mov     a,Oldchar       ;now send the actual key
  3810. 000446 0411                  
  3811. 000447 0411                  noControl:                      ;its not a controlled key
  3812. 000448 0411 A2E7                     mov     c,acc.7         ;c=make/break bit
  3813. 000449 0413 9249                     mov     Make,c          ;will be set if key up
  3814. 000450 0415 C2E7                     clr     acc.7           ;test for key only. NO make/break
  3815. 000451 0417 B40E19                   cjne    a,#0eh,noMup    ;special key mouse up
  3816. 000452 041A 30490B                   jnb     Make,kmupdown
  3817. 000453 041D                  kmupup:
  3818. 000454 041D 74CC                     mov     a,#0cch         ;cursor up break
  3819. 000455 041F B16F                     acall   actualtransmit
  3820. 000456 0421 9187                     acall   Smalldelay
  3821. 000457 0423 74E7                     mov     a,#0e7h         ;right amiga break
  3822. 000458 0425 B16F                     acall   actualtransmit
  3823. 000459 0427 22                       ret
  3824. 000460 0428                  kmupdown:
  3825. 000461 0428 7467                     mov     a,#67h          ;amiga make
  3826. 000462 042A B16F                     acall   actualtransmit
  3827. 000463 042C 9187                     acall   Smalldelay
  3828. 000464 042E 744C                     mov     a,#4ch          ;cursor up make
  3829. 000465 0430 B16F                     acall   actualtransmit
  3830. 000466 0432 22                       ret
  3831. 000467 0433                  noMup:
  3832. 000468 0433 B41C19                   cjne    a,#1ch,noMdown  ;special key mouse down
  3833. 000469 0436 30490B                   jnb     Make,kmdowndown
  3834. 000470 0439                  kmdownup:
  3835. 000471 0439 74CD                     mov     a,#0cdh         ;cursor down break
  3836. 000472 043B B16F                     acall   actualtransmit
  3837. 000473 043D 74E7                     mov     a,#0e7h         ;amiga break
  3838. 000474 043F 9187                     acall   Smalldelay
  3839. 000475 0441 B16F                     acall   actualtransmit
  3840. 000476 0443 22                       ret
  3841. 000477 0444                  kmdowndown:
  3842. 000478 0444 7467                     mov     a,#67h          ;amiga make
  3843. 000479 0446 B16F                     acall   actualtransmit
  3844. 000480 0448 9187                     acall   Smalldelay      ;cursor down make
  3845. 000481 044A 744D                     mov     a,#4dh
  3846. 000482 044C B16F                     acall   actualtransmit
  3847. 000483 044E 22                       ret
  3848. 000484 044F                  noMdown:
  3849. 000485 044F B42C19                   cjne    a,#2ch,noMleft  ;special key mouse left
  3850. 000486 0452 30490B                   jnb     Make,kmleftdown
  3851. 000487 0455                  kmleftup:
  3852. 000488 0455 74CF                     mov     a,#0cfh         ;cursor left break
  3853. 000489 0457 B16F                     acall   actualtransmit
  3854. 000490 0459 9187                     acall   Smalldelay      ;amiga break
  3855. 000491 045B 74E7                     mov     a,#0e7h
  3856. 000492 045D B16F                     acall   actualtransmit
  3857. 000493 045F 22                       ret
  3858. 000494 0460                  kmleftdown:
  3859. 000495 0460 7467                     mov     a,#67h          ;amiga make
  3860. 000496 0462 B16F                     acall   actualtransmit
  3861. 000497 0464 9187                     acall   Smalldelay
  3862. 000498 0466 744F                     mov     a,#4fh          ;cursor left make
  3863. 000499 0468 B16F                     acall   actualtransmit
  3864. 000500 046A 22                       ret
  3865. 000501 046B                  noMleft:                        ;special key mouse right
  3866. 000502 046B B4472B                   cjne    a,#47h,notspecial
  3867. 000503 046E 30490B                   jnb     Make,kmrhtdown
  3868. 000504 0471                  kmrhtup:
  3869. 000505 0471 74CE                     mov     a,#0ceh         ;cursor right break
  3870. 000506 0473 B16F                     acall   actualtransmit
  3871. 000507 0475 9187                     acall   Smalldelay
  3872. 000508 0477 74E7                     mov     a,#0e7h         ;amiga break
  3873. 000509 0479 B16F                     acall   actualtransmit
  3874. 000510 047B 22                       ret
  3875. 000511 047C                  kmrhtdown:
  3876. 000512 047C 7467                     mov     a,#67h          ;amiga make
  3877. 000513 047E B16F                     acall   actualtransmit
  3878. 000514 0480 9187                     acall   Smalldelay
  3879. 000515 0482 744E                     mov     a,#04eh         ;cursor right make
  3880. 000516 0484 B16F                     acall   actualtransmit
  3881. 000517 0486 22                       ret
  3882. 000518 0487                  Smalldelay:
  3883. 000519 0487 758C00                   mov     th0,#0
  3884. 000520 048A 758A00                   mov     tl0,#0
  3885. 000521 048D C28D                     clr     tf0
  3886. 000522 048F D28C                     setb    tr0
  3887. 000523 0491 308DFD           small1: jnb     tf0,small1
  3888. 000524 0494 C28D                     clr     tf0
  3889. 000525 0496 C28C                     clr     tr0
  3890. 000526 0498 22                       ret
  3891. 000527 0499                  notspecial:
  3892. 000528 0499 E551                     mov     a,Oldchar
  3893. 000529 049B B16F                     acall   actualtransmit  ;transmit the keycode
  3894. 000530 049D E551                     mov     a,Oldchar       ;get back same keycode, in A.
  3895. 000531 049F A2E7                     mov     c,acc.7         ;put make/break bit in Make
  3896. 000532 04A1 9249                     mov     Make,c
  3897. 000533 04A3 C2E7                     clr     acc.7           ;start testing for reset keys
  3898. 000534 04A5 B46306                   cjne    a,#63h,nrset1   ;held down
  3899. 000535 04A8 A249                     mov     c,Make
  3900. 000536 04AA 9245                     mov     CONTROL,c
  3901. 000537 04AC 8010                     sjmp    trset
  3902. 000538 04AE B46606           nrset1: cjne    a,#66h,nrset2
  3903. 000539 04B1 A249                     mov     c,Make
  3904. 000540 04B3 9246                     mov     LAMIGA,c
  3905. 000541 04B5 8007                     sjmp    trset
  3906. 000542 04B7 B46704           nrset2: cjne    a,#67h,trset
  3907. 000543 04BA A249                     mov     c,Make
  3908. 000544 04BC 9247                     mov     RAMIGA,c
  3909. 000545 04BE 304505           trset:  jnb     CONTROL,maybefree       ;if bit set, this key is up
  3910. 000546 04C1 204402                   jb      CtrlDown,maybefree      ;if bit set, this key is down
  3911. 000547 04C4 8008                     sjmp    free
  3912. 000548 04C6                  maybefree:
  3913. 000549 04C6 204605                   jb      LAMIGA,free     ;ditto
  3914. 000550 04C9 204702                   jb      RAMIGA,free     ;ditto
  3915. 000551 04CC 8004                     sjmp    resetwarn       ;OOPS! They are all down!
  3916. 000552 04CE 22               free:   ret
  3917. 000553 04CF                  dummy:
  3918. 000554 04CF 32                       reti
  3919. 000555 04D0                  resetint:
  3920. 000556 04D0 91CF                     acall   dummy
  3921. 000557 04D2                  resetwarn:
  3922. 000558 04D2 C28D                     clr     tf0             
  3923. 000559 04D4 E578                     mov     a,78h
  3924. 000560 04D6 7902                     mov     r1,#2           ;set up timer 0 watchdog
  3925. 000561 04D8 758A00                   mov     tl0,#0
  3926. 000562 04DB 758C00                   mov     th0,#0
  3927. 000563 04DE F4                       cpl     a               ;invert, don't know why.
  3928. 000564 04DF 7808                     mov     r0,#8
  3929. 000565 04E1                  wr1:
  3930. 000566 04E1 23                       rl      a
  3931. 000567 04E2 A2E7                     mov     c,acc.7
  3932. 000568 04E4 9294                     mov     Adat,c
  3933. 000569 04E6 75F008                   mov     b,#8
  3934. 000570 04E9                  wr2:
  3935. 000571 04E9 D5F0FD                   djnz    b,wr2             ; transmit it.
  3936. 000572 04EC C293                     clr     Aclk
  3937. 000573 04EE 75F008                   mov     b,#8
  3938. 000574 04F1                  wr3:
  3939. 000575 04F1 D5F0FD                   djnz    b,wr3
  3940. 000576 04F4 D293                     setb    Aclk
  3941. 000577 04F6 75F00A                   mov     b,#10
  3942. 000578 04F9                  wr4:
  3943. 000579 04F9 D5F0FD                   djnz    b,wr4
  3944. 000580 04FC D8E3                     djnz    r0,wr1
  3945. 000581 04FE D294                     setb    Adat
  3946. 000582 0500 D28C                     setb    tr0             ;start watchdog
  3947. 000583 0502                  wr5:
  3948. 000584 0502 309409                   jnb     Adat,caught1
  3949. 000585 0505 308DFA                   jnb     tf0,wr5
  3950. 000586 0508 C28D                     clr     tf0
  3951. 000587 050A D9F6                     djnz    r1,wr5
  3952. 000588 050C 8041                     sjmp    Hardreset
  3953. 000589 050E                  caught1:
  3954. 000590 050E C28C                     clr     tr0
  3955. 000591 0510 C28D                     clr     tf0
  3956. 000592 0512 E578                     mov     a,78h
  3957. 000593 0514 7904                     mov     r1,#4
  3958. 000594 0516 758A00                   mov     tl0,#0
  3959. 000595 0519 758C00                   mov     th0,#0
  3960. 000596 051C F4                       cpl     a    
  3961. 000597 051D 7808                     mov     r0,#8
  3962. 000598 051F                  wr11:
  3963. 000599 051F 23                       rl      a
  3964. 000600 0520 A2E7                     mov     c,acc.7
  3965. 000601 0522 9294                     mov     Adat,c
  3966. 000602 0524 75F008                   mov     b,#8
  3967. 000603 0527                  wr22:
  3968. 000604 0527 D5F0FD                   djnz    b,wr22   
  3969. 000605 052A C293                     clr     Aclk
  3970. 000606 052C 75F008                   mov     b,#8
  3971. 000607 052F                  wr33:
  3972. 000608 052F D5F0FD                   djnz    b,wr33
  3973. 000609 0532 D293                     setb    Aclk
  3974. 000610 0534 75F00A                   mov     b,#10
  3975. 000611 0537                  wr44:
  3976. 000612 0537 D5F0FD                   djnz    b,wr44
  3977. 000613 053A D8E3                     djnz    r0,wr11
  3978. 000614 053C D294                     setb    Adat
  3979. 000615 053E D28C                     setb    tr0             ;start watchdog
  3980. 000616 0540                  wr55:
  3981. 000617 0540 309409                   jnb     Adat,caught2
  3982. 000618 0543 308DFA                   jnb     tf0,wr55
  3983. 000619 0546 C28D                     clr     tf0
  3984. 000620 0548 D9F6                     djnz    r1,wr55
  3985. 000621 054A 8003                     sjmp    Hardreset
  3986. 000622 054C                  caught2:
  3987. 000623 054C 3094FD           hold:   jnb     Adat,hold
  3988. 000624 054F                  Hardreset:
  3989. 000625 054F C28C                     clr     tr0
  3990. 000626 0551 C28D                     clr     tf0
  3991. 000627 0553 C295                     clr     Areset
  3992. 000628 0555 C293                     clr     Aclk            ;clear both lines for A500/A1000
  3993. 000629 0557 790F                     mov     r1,#15          ;clock should go low for over 500ms
  3994. 000630 0559 758C00                   mov     th0,#0          ;timer 1 will overflow repeatedly
  3995. 000631 055C 758A00                   mov     tl0,#0
  3996. 000632 055F D28C                     setb    tr0
  3997. 000633 0561                  hsloop:
  3998. 000634 0561 308DFD                   jnb     tf0,hsloop      ;wait for overflow flag
  3999. 000635 0564 C28D                     clr     tf0             ;clear it again
  4000. 000636 0566 D9F9                     djnz    r1,hsloop
  4001. 000637 0568 C28D                     clr     tf0
  4002. 000638 056A C28C                     clr     tr0             ;stop the timer
  4003. 000639 056C 020200                   ljmp    start
  4004. 000640 056F                   
  4005. 000641 056F                  ;**************************************************
  4006. 000642 056F                  ;* 
  4007. 000643 056F                  ;* ActualTransmit sends the character out to the Amiga and waits
  4008. 000644 056F                  ;* for an acknowledge handshake. If it does not receive one in
  4009. 000645 056F                  ;* 143 ms, then it clocks out 1's on the data line until it 
  4010. 000646 056F                  ;* receives the acknowledge. If the Amiga is not connected up, 
  4011. 000647 056F                  ;* then it will hang here. The handshake is that the AMIGA 
  4012. 000648 056F                  ;* drives the clock line low.
  4013. 000649 056F                  ;*
  4014. 000650 056F                  ;*      The loops with register B are for timing delays. 
  4015. 000651 056F                  ;* There should be about 20usec between when the Data line is 
  4016. 000652 056F                  ;* set, the Clock line is driven low, and the Clock line
  4017. 000653 056F                  ;* is driven high.
  4018. 000654 056F                  ;*
  4019. 000655 056F                  ;**************************************************
  4020. 000656 056F                  
  4021. 000657 056F                  actualtransmit:
  4022. 000658 056F F552                     mov     Amigachar,a     ;set the character to transmit
  4023. 000659 0571                  
  4024. 000660 0571 7805                     mov     r0,#05          ;do a small delay
  4025. 000661 0573                  dly:
  4026. 000662 0573 75F000                   mov     b,#0
  4027. 000663 0576 D5F0FD           delay:  djnz    b,delay
  4028. 000664 0579 D8F8                     djnz    r0,dly
  4029. 000665 057B                  
  4030. 000666 057B                  actual2:
  4031. 000667 057B E552                     mov     a,Amigachar     ;restore it
  4032. 000668 057D C250                     clr     Charbad         ;character is not bad yet
  4033. 000669 057F 7902                     mov     r1,#2           ;set up timer 0 watchdog
  4034. 000670 0581 758B00                   mov     tl1,#0
  4035. 000671 0584 758D00                   mov     th1,#0
  4036. 000672 0587 F4                       cpl     a               ;invert, don't know why.
  4037. 000673 0588 7808                     mov     r0,#8
  4038. 000674 058A 23               f:      rl      a
  4039. 000675 058B A2E7                     mov     c,acc.7
  4040. 000676 058D 9294                     mov     Adat,c
  4041. 000677 058F 75F008                   mov     b,#8
  4042. 000678 0592 D5F0FD           g:      djnz    b,g             ; transmit it.
  4043. 000679 0595 C293                     clr     Aclk
  4044. 000680 0597 75F008                   mov     b,#8
  4045. 000681 059A D5F0FD           h:      djnz    b,h
  4046. 000682 059D D293                     setb    Aclk
  4047. 000683 059F 75F00A                   mov     b,#10
  4048. 000684 05A2 D5F0FD           i:      djnz    b,i
  4049. 000685 05A5 D8E3                     djnz    r0,f
  4050. 000686 05A7 D294                     setb    Adat
  4051. 000687 05A9 D28E                     setb    tr1             ;start watchdog
  4052. 000688 05AB                  waitshake:
  4053. 000689 05AB 2094FD                   jb      Adat,waitshake
  4054. 000690 05AE C28E                     clr     tr1             ;stop watchdog
  4055. 000691 05B0 3094FD           gotit:  jnb     Adat,gotit
  4056. 000692 05B3 22                       ret
  4057. 000693 05B4                  
  4058. 000694 05B4                  timer1int:
  4059. 000695 05B4 D91E                     djnz    r1,t3           ;we wait for 143 ms.
  4060. 000696 05B6 7902                     mov     r1,#2           
  4061. 000697 05B8 D250                     setb    Charbad         ;flag to resend the character
  4062. 000698 05BA C294                     clr     Adat            ;1 on the data line
  4063. 000699 05BC 75F008                   mov     b,#8
  4064. 000700 05BF D5F0FD           tt1:    djnz    b,tt1           ;wait for it
  4065. 000701 05C2 C293                     clr     Aclk            ;clock asserted
  4066. 000702 05C4 75F008                   mov     b,#8            ;sync up the controller to the
  4067. 000703 05C7 D5F0FD           tt2:    djnz    b,tt2           ;amiga
  4068. 000704 05CA D293                     setb    Aclk
  4069. 000705 05CC 75F00A                   mov     b,#10
  4070. 000706 05CF D5F0FD           tt3:    djnz    b,tt3
  4071. 000707 05D2 D294                     setb    Adat
  4072. 000708 05D4 32               t3:     reti                    ;return and send again.
  4073. 000709 05D5                  
  4074. 000710 05D5                  ATtb1: 
  4075. 000711 05D5 00                       .db     0               
  4076. 000712 05D6 58                       .db     58h             ;F9
  4077. 000713 05D7 00                       .db     0               
  4078. 000714 05D8 54                       .db     54h             ;F5
  4079. 000715 05D9 52                       .db     52h             ;F3
  4080. 000716 05DA 50                       .db     50h             ;F1
  4081. 000717 05DB 51                       .db     51h             ;F2
  4082. 000718 05DC 5B                       .db     5bh             ;F12=right parenthesis
  4083. 000719 05DD 00                       .db     0
  4084. 000720 05DE 59                       .db     59h             ;F10
  4085. 000721 05DF 57                       .db     57h             ;F8
  4086. 000722 05E0 55                       .db     55h             ;F6
  4087. 000723 05E1 53                       .db     53h             ;F4
  4088. 000724 05E2 42                       .db     42h             ;TAB
  4089. 000725 05E3 00                       .db     00h             ;~
  4090. 000726 05E4 00                       .db     0
  4091. 000727 05E5                  
  4092. 000728 05E5 00                       .db     0
  4093. 000729 05E6 64                       .db     64h             ;Left ALT
  4094. 000730 05E7 60                       .db     60h             ;Left SHIFT
  4095. 000731 05E8 00                       .db     0
  4096. 000732 05E9 66                       .db     66h             ;Left Ctrl=Left AMIGA
  4097. 000733 05EA 10                       .db     10h             ;Q
  4098. 000734 05EB 01                       .db     01h             ;1
  4099. 000735 05EC 00                       .db     0
  4100. 000736 05ED 00                       .db     0
  4101. 000737 05EE 00                       .db     0
  4102. 000738 05EF 31                       .db     31h             ;Z
  4103. 000739 05F0 21                       .db     21h             ;S
  4104. 000740 05F1 20                       .db     20h             ;A
  4105. 000741 05F2 11                       .db     11h             ;W
  4106. 000742 05F3 02                       .db     02h             ;2
  4107. 000743 05F4 00                       .db     0
  4108. 000744 05F5                  
  4109. 000745 05F5 00                       .db     0
  4110. 000746 05F6 33                       .db     33h             ;C
  4111. 000747 05F7 32                       .db     32h             ;X
  4112. 000748 05F8 22                       .db     22h             ;D
  4113. 000749 05F9 12                       .db     12h             ;E
  4114. 000750 05FA 04                       .db     04h             ;4
  4115. 000751 05FB 03                       .db     03h             ;3
  4116. 000752 05FC 00                       .db     0
  4117. 000753 05FD 00                       .db     0
  4118. 000754 05FE 40                       .db     40h             ;SPACE
  4119. 000755 05FF 34                       .db     34h             ;V
  4120. 000756 0600 23                       .db     23h             ;F
  4121. 000757 0601 14                       .db     14h             ;T
  4122. 000758 0602 13                       .db     13h             ;R
  4123. 000759 0603 05                       .db     05h             ;5
  4124. 000760 0604 00                       .db     0
  4125. 000761 0605                  
  4126. 000762 0605 00                       .db     0
  4127. 000763 0606 36                       .db     36h             ;N
  4128. 000764 0607 35                       .db     35h             ;B
  4129. 000765 0608 25                       .db     25h             ;H
  4130. 000766 0609 24                       .db     24h             ;G
  4131. 000767 060A 15                       .db     15h             ;Y
  4132. 000768 060B 06                       .db     06h             ;6
  4133. 000769 060C 00                       .db     0
  4134. 000770 060D 00                       .db     0
  4135. 000771 060E 00                       .db     0
  4136. 000772 060F 37                       .db     37h             ;M
  4137. 000773 0610 26                       .db     26h             ;J
  4138. 000774 0611 16                       .db     16h             ;U
  4139. 000775 0612 07                       .db     07h             ;7
  4140. 000776 0613 08                       .db     08h             ;8
  4141. 000777 0614 00                       .db     0
  4142. 000778 0615                  
  4143. 000779 0615 00                       .db     0
  4144. 000780 0616 38                       .db     38h             ;<
  4145. 000781 0617 27                       .db     27h             ;K
  4146. 000782 0618 17                       .db     17h             ;I
  4147. 000783 0619 18                       .db     18h             ;O
  4148. 000784 061A 0A                       .db     0Ah             ;0
  4149. 000785 061B 09                       .db     09h             ;9
  4150. 000786 061C 00                       .db     0
  4151. 000787 061D 00                       .db     0
  4152. 000788 061E 39                       .db     39h             ;>
  4153. 000789 061F 3A                       .db     3ah             ;/
  4154. 000790 0620 28                       .db     28h             ;L
  4155. 000791 0621 29                       .db     29h             ; ';'
  4156. 000792 0622 19                       .db     19h             ;P
  4157. 000793 0623 0B                       .db     0bh             ;-
  4158. 000794 0624 00                       .db     0
  4159. 000795 0625                  
  4160. 000796 0625 00                       .db     0
  4161. 000797 0626 00                       .db     0
  4162. 000798 0627 2A                       .db     2ah             ;'
  4163. 000799 0628 00                       .db     0
  4164. 000800 0629 1A                       .db     1ah             ;[
  4165. 000801 062A 0C                       .db     0ch             ;=
  4166. 000802 062B 00                       .db     0
  4167. 000803 062C 00                       .db     0
  4168. 000804 062D 62                       .db     62h             ;CAPS LOCK?
  4169. 000805 062E 61                       .db     61h             ;Right SHIFT
  4170. 000806 062F 44                       .db     44h             ;RETURN
  4171. 000807 0630 1B                       .db     1bh             ;]
  4172. 000808 0631 00                       .db     0
  4173. 000809 0632 0D                       .db     0dh             ;\
  4174. 000810 0633 00                       .db     0
  4175. 000811 0634 00                       .db     0
  4176. 000812 0635                  
  4177. 000813 0635                          .rs     6
  4178. 000814 063B 41                       .db     41h             ;Back SPACE
  4179. 000815 063C 00                       .db     0
  4180. 000816 063D 00                       .db     0
  4181. 000817 063E 1D                       .db     1dh             ;1 keypad
  4182. 000818 063F 00                       .db     0
  4183. 000819 0640 2D                       .db     2dh             ;4 keypad
  4184. 000820 0641 3D                       .db     3dh             ;7 keypad
  4185. 000821 0642 00                       .db     0
  4186. 000822 0643 00                       .db     0
  4187. 000823 0644 00                       .db     0
  4188. 000824 0645                  
  4189. 000825 0645 0F                       .db     0fh             ;0 keypad
  4190. 000826 0646 3C                       .db     3ch             ;dot keypad
  4191. 000827 0647 1E                       .db     1eh             ;2 keypad
  4192. 000828 0648 2E                       .db     2eh             ;5 keypad
  4193. 000829 0649 2F                       .db     2fh             ;6 keypad
  4194. 000830 064A 3E                       .db     3eh             ;8 keypad
  4195. 000831 064B 45                       .db     45h             ;ESCAPE!
  4196. 000832 064C 63                       .db     63h             ;Number Lock=CTRL
  4197. 000833 064D 5A                       .db     5ah             ;F11=( keypad
  4198. 000834 064E 5E                       .db     5eh             ;+ keypad
  4199. 000835 064F 1F                       .db     1fh             ;3 keypad
  4200. 000836 0650 4A                       .db     4ah             ;- keypad
  4201. 000837 0651 5D                       .db     5dh             ;* keypad
  4202. 000838 0652 3F                       .db     3fh             ;9 keypad
  4203. 000839 0653 67                       .db     67h             ;scroll Lock=Right AMIGA
  4204. 000840 0654 00                       .db     0
  4205. 000841 0655                  ATtb2:
  4206. 000842 0655                          .rs     3
  4207. 000843 0658 56                       .db     56h             ;F7
  4208. 000844 0659 66                       .db     66h             ;print screen=Left Amiga
  4209. 000845 065A                          .rs     11
  4210. 000846 0665                  
  4211. 000847 0665 00                       .db     0
  4212. 000848 0666 65                       .db     65h             ;Right ALT
  4213. 000849 0667 00                       .db     0
  4214. 000850 0668 00                       .db     0
  4215. 000851 0669 67                       .db     67h             ;Right CTL=RIGHT AMIGA
  4216. 000852 066A                          .rs     11
  4217. 000853 0675                  
  4218. 000854 0675                          .rs     10h
  4219. 000855 0685                          
  4220. 000856 0685                          .rs     10h
  4221. 000857 0695                  
  4222. 000858 0695                          .rs     10
  4223. 000859 069F 5C                       .db     5ch             ;/key, supposedly
  4224. 000860 06A0                          .rs     5
  4225. 000861 06A5                  
  4226. 000862 06A5                          .rs     10
  4227. 000863 06AF 43                       .db     43h             ;Numeric Enter
  4228. 000864 06B0                          .rs     5
  4229. 000865 06B5                  
  4230. 000866 06B5                          .rs     9
  4231. 000867 06BE 1C                       .db     1ch             ;End=Mouse down
  4232. 000868 06BF 00                       .db     0
  4233. 000869 06C0 4F                       .db     4fh             ;Cursor Left
  4234. 000870 06C1 0E                       .db     0eh             ;Home=Mouse up
  4235. 000871 06C2 00                       .db     0
  4236. 000872 06C3 00                       .db     0
  4237. 000873 06C4 63                       .db     63h             ;MACRO key=control
  4238. 000874 06C5                  
  4239. 000875 06C5 2C                       .db     2ch             ;Insert=Mouse Left
  4240. 000876 06C6 46                       .db     46h             ;Delete
  4241. 000877 06C7 4D                       .db     4dh             ;Cursor Down
  4242. 000878 06C8 00                       .db     0
  4243. 000879 06C9 4E                       .db     4eh             ;Cursor Right
  4244. 000880 06CA 4C                       .db     4ch             ;Cursor Up
  4245. 000881 06CB                          .rs     4
  4246. 000882 06CF 5F                       .db     5fh             ;Page Down=Help
  4247. 000883 06D0 00                       .db     0
  4248. 000884 06D1 66                       .db     66h             ;print screen=LEFT AMIGA
  4249. 000885 06D2 47                       .db     47h             ;Page up=mouse right
  4250. 000886 06D3 40                       .db     40h             ;Break=Space?
  4251. 000887 06D4 00                       .db     0
  4252. 000888 06D5                  XTtb1:
  4253. 000889 06D5 00                       .db     0
  4254. 000890 06D6 45                       .db     45h             ;esc
  4255. 000891 06D7 01                       .db     01h             ;1
  4256. 000892 06D8 02                       .db     02h             ;2
  4257. 000893 06D9 03                       .db     03h             ;3
  4258. 000894 06DA 04                       .db     04h             ;4
  4259. 000895 06DB 05                       .db     05h             ;5
  4260. 000896 06DC 06                       .db     06h             ;6
  4261. 000897 06DD 07                       .db     07h             ;7
  4262. 000898 06DE 08                       .db     08h             ;8
  4263. 000899 06DF 09                       .db     09h             ;9
  4264. 000900 06E0 0A                       .db     0ah             ;0
  4265. 000901 06E1 0B                       .db     0bh             ;-
  4266. 000902 06E2 0C                       .db     0ch             ;=
  4267. 000903 06E3 41                       .db     41h             ;Backspace
  4268. 000904 06E4 42                       .db     42h             ;Tab
  4269. 000905 06E5                  
  4270. 000906 06E5 10                       .db     10h             ;Q
  4271. 000907 06E6 11                       .db     11h             ;W
  4272. 000908 06E7 12                       .db     12h             ;E
  4273. 000909 06E8 13                       .db     13h             ;R
  4274. 000910 06E9 14                       .db     14h             ;T
  4275. 000911 06EA 15                       .db     15h             ;Y
  4276. 000912 06EB 16                       .db     16h             ;U
  4277. 000913 06EC 17                       .db     17h             ;I
  4278. 000914 06ED 18                       .db     18h             ;O
  4279. 000915 06EE 19                       .db     19h             ;P
  4280. 000916 06EF 1A                       .db     1Ah             ;[
  4281. 000917 06F0 1B                       .db     1Bh             ;]
  4282. 000918 06F1 44                       .db     44h             ;ENTER
  4283. 000919 06F2 66                       .db     66h             ;L.CTL=LEFT AMIGA
  4284. 000920 06F3 20                       .db     20h             ;A
  4285. 000921 06F4 21                       .db     21h             ;S
  4286. 000922 06F5                  
  4287. 000923 06F5 22                       .db     22h             ;D
  4288. 000924 06F6 23                       .db     23h             ;F
  4289. 000925 06F7 24                       .db     24h             ;G
  4290. 000926 06F8 25                       .db     25h             ;H
  4291. 000927 06F9 26                       .db     26h             ;J
  4292. 000928 06FA 27                       .db     27h             ;K
  4293. 000929 06FB 28                       .db     28h             ;L
  4294. 000930 06FC 29                       .db     29h             ;';'
  4295. 000931 06FD 2A                       .db     2Ah             ;'
  4296. 000932 06FE 00                       .db     00h             ;~
  4297. 000933 06FF 60                       .db     60h             ;Left Shift
  4298. 000934 0700 0D                       .db     0dh             ;\
  4299. 000935 0701 31                       .db     31h             ;Z
  4300. 000936 0702 32                       .db     32h             ;X
  4301. 000937 0703 33                       .db     33h             ;C
  4302. 000938 0704 34                       .db     34h             ;V
  4303. 000939 0705                  
  4304. 000940 0705 35                       .db     35h             ;B
  4305. 000941 0706 36                       .db     36h             ;N
  4306. 000942 0707 37                       .db     37h             ;M
  4307. 000943 0708 38                       .db     38h             ;<
  4308. 000944 0709 39                       .db     39h             ;>
  4309. 000945 070A 3A                       .db     3Ah             ;/
  4310. 000946 070B 61                       .db     61h             ;Right Shift
  4311. 000947 070C 5D                       .db     5dh             ;Numeric *
  4312. 000948 070D 64                       .db     64h             ;Left Alt
  4313. 000949 070E 40                       .db     40h             ;space
  4314. 000950 070F 62                       .db     62h             ;CapsLock
  4315. 000951 0710 50                       .db     50h             ;F1
  4316. 000952 0711 51                       .db     51h             ;F2
  4317. 000953 0712 52                       .db     52h             ;F3
  4318. 000954 0713 53                       .db     53h             ;F4
  4319. 000955 0714 54                       .db     54h             ;F5
  4320. 000956 0715                  
  4321. 000957 0715 55                       .db     55h             ;F6
  4322. 000958 0716 56                       .db     56h             ;F7
  4323. 000959 0717 57                       .db     57h             ;F8
  4324. 000960 0718 58                       .db     58h             ;F9
  4325. 000961 0719 59                       .db     59h             ;F10
  4326. 000962 071A 63                       .db     63h             ;Number Lock=Control
  4327. 000963 071B 67                       .db     67h             ;Scroll Lock=Right Amiga
  4328. 000964 071C 3D                       .db     3dh             ;Numeric 7
  4329. 000965 071D 3E                       .db     3eh             ;* 8
  4330. 000966 071E 3F                       .db     3fh             ;* 9
  4331. 000967 071F 4A                       .db     4ah             ;* -
  4332. 000968 0720 2D                       .db     2dh             ;* 4
  4333. 000969 0721 2E                       .db     2eh             ;* 5
  4334. 000970 0722 2F                       .db     2fh             ;* 6
  4335. 000971 0723 5E                       .db     5eh             ;* +
  4336. 000972 0724 1D                       .db     1dh             ;* 1
  4337. 000973 0725                  
  4338. 000974 0725 1E                       .db     1eh             ;* 2
  4339. 000975 0726 1F                       .db     1fh             ;* 3
  4340. 000976 0727 0F                       .db     0fh             ;* 0
  4341. 000977 0728 3C                       .db     3ch             ;* .
  4342. 000978 0729 63                       .db     63h             ;print screen=CONTROL
  4343. 000979 072A 00                       .db     0
  4344. 000980 072B 00                       .db     0
  4345. 000981 072C 5A                       .db     5ah             ;F11=Numeric (
  4346. 000982 072D 5B                       .db     5bh             ;F12=Numeric )
  4347. 000983 072E                          .rs     7
  4348. 000984 0735                  
  4349. 000985 0735                          .rs     10h
  4350. 000986 0745                  
  4351. 000987 0745                          .rs     10h
  4352. 000988 0755                  XTtb2:
  4353. 000989 0755                          .rs     10h
  4354. 000990 0765                  
  4355. 000991 0765                          .rs     12
  4356. 000992 0771 43                       .db     43h             ;Numeric Enter
  4357. 000993 0772 67                       .db     67h             ;Right Control=RIGHT AMIGA
  4358. 000994 0773                          .rs     2
  4359. 000995 0775                  
  4360. 000996 0775                          .rs     10h
  4361. 000997 0785                          
  4362. 000998 0785                          .rs     5
  4363. 000999 078A 5C                       .db     5ch             ;Numeric /key
  4364. 001000 078B 00                       .db     0
  4365. 001001 078C 66                       .db     66h             ;Print Screeen=Left Amiga
  4366. 001002 078D 65                       .db     65h             ;Right Alt
  4367. 001003 078E                          .rs     7
  4368. 001004 0795                  
  4369. 001005 0795                          .rs     6
  4370. 001006 079B 5F                       .db     5fh             ;BREAK=HELP!
  4371. 001007 079C 0E                       .db     0eh             ;Home=MOUSE UP
  4372. 001008 079D 4C                       .db     4ch             ;cursor up
  4373. 001009 079E 47                       .db     47h             ;pageup=mouse right
  4374. 001010 079F 00                       .db     0
  4375. 001011 07A0 4F                       .db     4fh             ;cursor left
  4376. 001012 07A1 00                       .db     0
  4377. 001013 07A2 4E                       .db     4eh             ;cursor right
  4378. 001014 07A3 00                       .db     0
  4379. 001015 07A4 1C                       .db     1ch             ;End=mouse down
  4380. 001016 07A5                  
  4381. 001017 07A5 4D                       .db     4dh             ;cursor down
  4382. 001018 07A6 5F                       .db     5fh             ;page down=HELP!
  4383. 001019 07A7 2C                       .db     2ch             ;insert=mouse left
  4384. 001020 07A8 46                       .db     46h             ;delete
  4385. 001021 07A9                          .rs     12
  4386. 001022 07B5                         
  4387. 001023 07B5                          .rs     15
  4388. 001024 07C4 63                       .db     63h             ;Macro=control
  4389. 001025 07C5                  
  4390. 001026 07C5                          .rs     10h
  4391. 001027 07D5                  
  4392. 001028 07D5                          .end    0
  4393.  
  4394. AC      =00D6  ET2     =00AD  P0.0    =0080  RXD     =00B0  TMOD    =0089  
  4395. ACC     =00E0  EX0     =00A8  P0.1    =0081  SBUF    =0099  TR0     =008C  
  4396. ACC.0   =00E0  EX1     =00AA  P0.2    =0082  SCON    =0098  TR1     =008E  
  4397. ACC.1   =00E1  EXEN2   =00CB  P0.3    =0083  SCON.0  =0098  TR2     =00CA  
  4398. ACC.2   =00E2  EXF2    =00CE  P0.4    =0084  SCON.1  =0099  TRANSMIT=03BF  
  4399. ACC.3   =00E3  F       =058A  P0.5    =0085  SCON.2  =009A  TRANSOK =03C3  
  4400. ACC.4   =00E4  F0      =00D5  P0.6    =0086  SCON.3  =009B  TRANSOK2=03CB  
  4401. ACC.5   =00E5  FREE    =04CE  P0.7    =0087  SCON.4  =009C  TRANSOK3=03FE  
  4402. ACC.6   =00E6  G       =0592  P1      =0090  SCON.5  =009D  TRANSOK4=03F3  
  4403. ACC.7   =00E7  GOTIT   =05B0  P1.0    =0090  SCON.6  =009E  TRSET   =04BE  
  4404. ACLK    =0093  H       =059A  P1.1    =0091  SCON.7  =009F  TT1     =05BF  
  4405. ACTUAL2 =057B  HARDRESE=054F  P1.2    =0092  SEND4   =0325  TT2     =05C7  
  4406. ACTUALTR=056F  HOLD    =054C  P1.3    =0093  SEND5   =032D  TT3     =05CF  
  4407. ADAT    =0094  HSLOOP  =0561  P1.4    =0094  SEND6   =0337  TXD     =00B1  
  4408. AMIGACHA=0052  I       =05A2  P1.5    =0095  SEND7   =033C  WAITSHAK=05AB  
  4409. ARESET  =0095  IE      =00A8  P1.6    =0096  SEND77  =033F  WR1     =04E1  
  4410. ATDATAB =02C3  IE.0    =00A8  P1.7    =0097  SEND78  =0344  WR11    =051F  
  4411. ATDOWN  =030F  IE.1    =00A9  P2      =00A0  SEND79  =0347  WR2     =04E9  
  4412. ATERROR =02B4  IE.2    =00AA  P2.0    =00A0  SEND7A  =034A  WR22    =0527  
  4413. ATGETKEY=0290  IE.3    =00AB  P2.1    =00A1  SEND8   =034F  WR3     =04F1  
  4414. ATNE0   =0308  IE.4    =00AC  P2.2    =00A2  SEND9   =0355  WR33    =052F  
  4415. ATNE012 =0302  IE.5    =00AD  P2.3    =00A3  SENDTOAT=031F  WR4     =04F9  
  4416. ATNE0F0 =02FC  IE.7    =00AF  P2.4    =00A4  SKIPLIGH=03F2  WR44    =0537  
  4417. ATNE1   =02E0  IE0     =0089  P2.5    =00A5  SM0     =009F  WR5     =0502  
  4418. ATNEF12 =02F6  IE1     =008B  P2.6    =00A6  SM1     =009E  WR55    =0540  
  4419. ATNSTART=029D  INIT    =0000  P2.7    =00A7  SM2     =009D  XT7BIT  =004A  
  4420. ATNSTOP =02BA  INT0    =00B2  P3      =00B0  SMALL1  =0491  XTCAP   =03D6  
  4421. ATPARITY=0048  INT1    =00B3  P3.0    =00B0  SMALLDEL=0487  XTGETKEY=035C  
  4422. ATPOWERU=0277  IP      =00B8  P3.1    =00B1  SP      =0081  XTLOOKUP=03A7  
  4423. ATSTYLE =02CB  IP.0    =00B8  P3.2    =00B2  START   =0200  XTN2A   =039A  
  4424. ATTB1   =05D5  IP.1    =00B9  P3.3    =00B3  SYNC    =022D  XTN36   =03A4  
  4425. ATTB2   =0655  IP.2    =00BA  P3.4    =00B4  SYNC2   =0237  XTNAA   =0395  
  4426. ATUP    =0317  IP.3    =00BB  P3.5    =00B5  SYNC3   =023A  XTNB6   =039F  
  4427. ATWAIT  =02C6  IP.4    =00BC  P3.6    =00B6  T2CON   =00C8  XTNE0   =03B7  
  4428. ATWAITC0=0294  IP.5    =00BD  P3.7    =00B7  T2CON.0 =00C8  XTNE1   =038B  
  4429. ATWAITC1=02A0  IT0     =0088  PARITYEV=02AC  T2CON.1 =00C9  XTPOWERU=0263  
  4430. B       =00F0  IT1     =008A  PARITYOD=02B0  T2CON.2 =00CA  XTRESET =0269  
  4431. B.0     =00F0  KCLK    =0090  PAUSE   =02A7  T2CON.3 =00CB  XTSTYLE =037A  
  4432. B.1     =00F1  KDAT    =0091  PCON    =0087  T2CON.4 =00CC  XTTB1   =06D5  
  4433. B.2     =00F2  KMDOWNDO=0444  PS      =00BC  T2CON.5 =00CD  XTTB2   =0755  
  4434. B.3     =00F3  KMDOWNUP=0439  PSW     =00D0  T2CON.6 =00CE  XTTEST  =0257  
  4435. B.4     =00F4  KMLEFTDO=0460  PSW.0   =00D0  T2CON.7 =00CF  XTW1    =0360  
  4436. B.5     =00F5  KMLEFTUP=0455  PSW.1   =00D1  T3      =05D4  XTW2    =0363  
  4437. B.6     =00F6  KMRHTDOW=047C  PSW.2   =00D2  TB8     =009B  XTW3    =0366  
  4438. B.7     =00F7  KMRHTUP =0471  PSW.3   =00D3  TCLK    =00CC  XTW4    =0369  
  4439. CAPBIT  =0042  KMUPDOWN=0428  PSW.4   =00D4  TCON    =0088  XTW5    =036C  
  4440. CAPDOWN =0043  KMUPUP  =041D  PSW.5   =00D5  TCON.0  =0088  XTW6    =0372  
  4441. CAUGHT1 =050E  KRESET  =0092  PSW.6   =00D6  TCON.1  =0089  
  4442. CAUGHT2 =054C  KSTYLE  =004B  PSW.7   =00D7  TCON.2  =008A  
  4443. CHARBAD =0050  KSWITCH =0097  PT0     =00B9  TCON.3  =008B  
  4444. CONTROL =0045  LAMIGA  =0046  PT1     =00BB  TCON.4  =008C  
  4445. CPRL2   =00C8  LL      =0272  PT2     =00BD  TCON.5  =008D  
  4446. CT2     =00C9  MAKE    =0049  PX0     =00B8  TCON.6  =008E  
  4447. CTRLDOWN=0044  MAYBEFRE=04C6  PX1     =00BA  TCON.7  =008F  
  4448. CY      =00D7  NOCONTRO=0411  RAMIGA  =0047  TF0     =008D  
  4449. DELAY   =0576  NOMDOWN =044F  RB8     =009A  TF1     =008F  
  4450. DLY     =0573  NOMLEFT =046B  RCAP2H  =00CB  TF2     =00CF  
  4451. DONTRANS=03BC  NOMUP   =0433  RCAP2L  =00CA  TH0     =008C  
  4452. DPH     =0083  NOTSPECI=0499  RCLK    =00CD  TH1     =008D  
  4453. DPL     =0082  NRSET1  =04AE  REN     =009C  TH2     =00CD  
  4454. DUMMY   =04CF  NRSET2  =04B7  RESETINT=04D0  TI      =0099  
  4455. EA      =00AF  OLDCHAR =0051  RESETWAR=04D2  TIMER1IN=05B4  
  4456. ES      =00AC  OV      =00D2  RI      =0098  TL0     =008A  
  4457. ET0     =00A9  P       =00D0  RS0     =00D3  TL1     =008B  
  4458. ET1     =00AB  P0      =0080  RS1     =00D4  TL2     =00CC  
  4459. @\Rogue\Monster\
  4460. else
  4461.   echo "shar: Will not over write key.list"
  4462. fi
  4463. if `test ! -s key.obj`
  4464. then
  4465. echo "x - key.obj"
  4466. cat > key.obj << '@\Rogue\Monster\'
  4467. :03000000020200F9
  4468. :030003000204D024
  4469. :03001B000205B427
  4470. :1002000075891175880575A800D2AFD2ABD2A8D276
  4471. :10021000B2D2B97581307590FFC28EC28FC28CC2C6
  4472. :100220008DC243C244C242D245D246D247758B00EA
  4473. :10023000758D007902D28E2094FD3094FDC28E74AB
  4474. :10024000FDB16F74FEB16F30971920912A758C0043
  4475. :10025000758A00C28DD28C208D093091FAC28CC271
  4476. :100260008D8014C24BC28DC290308DFDD290C28C55
  4477. :10027000C28D715C02037AD24B74FF711F74F671E8
  4478. :100280001F74ED711F7402711F74F4711F0202CB91
  4479. :10029000780BD2902090FD18B80A028029B8001A75
  4480. :1002A0003090FDC2907814D8FE20D004304805224A
  4481. :1002B0002048012274FE711F80D6B80106A29192D7
  4482. :1002C000488003A291133090FD80C95190B4E11091
  4483. :1002D000519051905190519051905190519080EB8C
  4484. :1002E0009005D5B4E0229006555190B4F00E51908F
  4485. :1002F000B412030202CBB4591E0202CBB4120302A1
  4486. :1003000002CBB4590A0202CBB4F004519080089396
  4487. :10031000C2E771BF0202CB93D2E771BF0202CBD218
  4488. :1003200090C29178082090FDA2E09291033090FD58
  4489. :1003300018B800F1A2D0B32090FD92913090FD202A
  4490. :1003400090FDD2913090FD2090FD3090FD7808D83E
  4491. :10035000FEC2907814D8FED290519022D2917808A3
  4492. :100360002090FD3090FD2090FD3090FD2090FDA26A
  4493. :1003700091133090FDD8F5C29122715CB4E10C71FB
  4494. :100380005C715C715C715C715C80EFB4E029715CE4
  4495. :10039000B4AA0280E5B42A0280E0B4B60280DBB4DD
  4496. :1003A000360280D6900755A2E7924AC2E793A24A46
  4497. :1003B00092E771BF02037A9006D580EBD0E022B5B8
  4498. :1003C000510122B46205F551D24322B4E230E55125
  4499. :1003D000304B03B4621DC243B2427462A242B39274
  4500. :1003E000E7B16F304B0C74ED711F7402A24292E2C0
  4501. :1003F000711F22C244C2437463D2E7B16F22F55128
  4502. :10040000304B0E30430B204408D2447463B16FE587
  4503. :1004100051A2E79249C2E7B40E1930490B74CCB12E
  4504. :100420006F918774E7B16F227467B16F9187744CD5
  4505. :10043000B16F22B41C1930490B74CDB16F74E791C0
  4506. :1004400087B16F227467B16F9187744DB16F22B419
  4507. :100450002C1930490B74CFB16F918774E7B16F22BB
  4508. :100460007467B16F9187744FB16F22B4472B3049D5
  4509. :100470000B74CEB16F918774E7B16F227467B16F5F
  4510. :100480009187744EB16F22758C00758A00C28DD22F
  4511. :100490008C308DFDC28DC28C22E551B16FE551A229
  4512. :1004A000E79249C2E7B46306A24992458010B46658
  4513. :1004B00006A24992468007B46704A2499247304594
  4514. :1004C000052044028008204605204702800422328D
  4515. :1004D00091CFC28DE5787902758A00758C00F47829
  4516. :1004E0000823A2E7929475F008D5F0FDC29375F049
  4517. :1004F00008D5F0FDD29375F00AD5F0FDD8E3D2947B
  4518. :10050000D28C309409308DFAC28DD9F68041C28CDC
  4519. :10051000C28DE5787904758A00758C00F47808231B
  4520. :10052000A2E7929475F008D5F0FDC29375F008D556
  4521. :10053000F0FDD29375F00AD5F0FDD8E3D294D28CB9
  4522. :10054000309409308DFAC28DD9F680033094FDC203
  4523. :100550008CC28DC295C293790F758C00758A00D2BA
  4524. :100560008C308DFDC28DD9F9C28DC28C020200F58E
  4525. :1005700052780575F000D5F0FDD8F8E552C25079F3
  4526. :1005800002758B00758D00F4780823A2E7929475AC
  4527. :10059000F008D5F0FDC29375F008D5F0FDD2937543
  4528. :1005A000F00AD5F0FDD8E3D294D28E2094FDC28E0D
  4529. :1005B0003094FD22D91E7902D250C29475F008D52C
  4530. :1005C000F0FDC29375F008D5F0FDD29375F00AD511
  4531. :1005D000F0FDD29432005800545250515B005957EC
  4532. :1005E00055534200000064600066100100000031B5
  4533. :1005F0002120110200003332221204030000403493
  4534. :100600002314130500003635252415060000003795
  4535. :10061000261607080000382717180A090000393A7B
  4536. :100620002829190B0000002A001A0C0000626144FE
  4537. :050630001B000D00009D
  4538. :10063B004100001D002D3D0000000F3C1E2E2F3EE3
  4539. :0A064B0045635A5E1F4A5D3F6700D9
  4540. :020658005666E4
  4541. :050665000065000067C4
  4542. :01069F005CFE
  4543. :0106AF004307
  4544. :0D06BE001C004F0E0000632C464D004E4CFA
  4545. :1006CF005F00664740000045010203040506070866
  4546. :1006DF00090A0B0C41421011121314151617181991
  4547. :1006EF001A1B4466202122232425262728292A0085
  4548. :1006FF00600D3132333435363738393A615D644005
  4549. :10070F00625051525354555657585963673D3E3FA7
  4550. :0F071F004A2D2E2F5E1D1E1F0F3C6300005A5BDC
  4551. :020771004367DC
  4552. :04078A005C00666544
  4553. :0E079B005F0E4C47004F004E001C4D5F2C4679
  4554. :0107C40063D1
  4555. :00000001FF
  4556. @\Rogue\Monster\
  4557. else
  4558.   echo "shar: Will not over write key.obj"
  4559. fi
  4560. if `test ! -s keydoc`
  4561. then
  4562. echo "x - keydoc"
  4563. cat > keydoc << '@\Rogue\Monster\'
  4564. IBM Keyboard Interfact Project, by ERic Rudolph, 1991.
  4565. No Copyright Whatsoever, but I would like credit where it's due.
  4566.  
  4567. This is documentation for the circuit I built which converts the information
  4568. put out by an XT or AT keyboard to that which can be recognized by an Amiga.
  4569.  
  4570. The circuit itself is a simple 8051 with an address latch and an Eprom.
  4571. It is inserted between the keyboard and the Amiga and sends data in both
  4572. directions to the Keyboard and the Amiga. 
  4573.  
  4574. Parts count could be reduced by using an 8751 which contains a 4k internal
  4575. Eprom. Seeing as how I don't know how to program them yet, I will stick to
  4576. the above design, but I am sure it's not hard to do. :-\
  4577.  
  4578. Full Parts List:
  4579. ================
  4580. 1) Intel 8031/8051, preferrably low power
  4581. 2) 74373 address latch
  4582. 3) 2732 Eprom
  4583. 4) 11.059 MHZ crystal
  4584. 5) 2 30pf caps
  4585. 6) 1 10k resistor, 1/4 watt
  4586. 7) 1 10uF electolytic cap
  4587. 8) 2 momentary pushbutton switches. Neither is really needed.
  4588. 10) connectors to the Amiga and the IBM
  4589.  
  4590. The total cost for these parts come to about $18.00 minus box and breadboard.
  4591. It certainly would be cheaper to use some used components. 
  4592.  
  4593. Wiring List:
  4594. ============
  4595. INTEL 8031/8051:
  4596. Port1, pins 1-8 can be connected in any manner whatsoever,
  4597. so long as you change the source code. You can relocate
  4598. the lines to the Keyboard and the Amiga wherever suitable.
  4599. If you understand the 8051 or read the 8051 manual, it will make more
  4600. sense.
  4601.     pin    to
  4602.     ===    ==
  4603.     1(p1.0)    Keyboard Clock. Female 5-pin, pin #1
  4604.     2    Keyboard Data, Female 5-pin, pin #2
  4605.     3     
  4606.     4    Amiga Clock
  4607.     5    Amiga Data
  4608.     6    Amiga Reset
  4609.     7
  4610.     8(p1.7)    XT/AT pin. Tie low to always convert an XT keyboard.
  4611.         For Auto detect, leave pin unconnected.
  4612.     9(reset) to - side of 10uF cap & 10k resistor & pushbutton switch
  4613.         only if you want a manual CIRCUIT reset switch.
  4614.     10(p3.0)
  4615.     11
  4616.     12(int0)  pushbutton switch2
  4617.     13-16
  4618.     17(p3.7)
  4619.     18    clock crystal & 30pf cap1
  4620.     19    clock crystal(other pin) & 30pf cap2
  4621.     20     Ground
  4622.     21(a8)    Eprom Addr8, 2732 pin#23
  4623.     22     Eprom Addr9, 2732 pin#22
  4624.     23     Eprom Addr10, 2732 pin#19
  4625.     24(a11)    Eprom Addr11, 2732 pin#21
  4626.     25-28
  4627.     29    Eprom Read, 2732 pin#20
  4628.     30    373 Gate, pin# 11
  4629.     31     Ground
  4630.     32(ad7)    373 D7, pin#13 & Eprom Data7, pin#17
  4631.     33    373 D6, pin#14 & Eprom Data6, pin#16
  4632.     34    373 D5, pin#8 & Eprom Data5, pin#15
  4633.     35    373 D4, pin#7 & Eprom Data4, pin#14
  4634.     36    373 D3, pin#4 & Eprom Data3, pin#13
  4635.     37    373 D2, pin#3 & Eprom Data2, pin#11
  4636.     38    373 D1, pin#17 & Eprom Data1, pin#10
  4637.     39(ad0)    373 D0, pin#18 & Eprom Data0, pin#9
  4638.     40    +5 Volts
  4639. 74373:
  4640.     1    Ground
  4641.     2    Eprom Addr2, pin#6
  4642.     3    done
  4643.     4    done
  4644.     5    Eprom Addr3, pin#5
  4645.     6    Eprom Addr4, pin#4    
  4646.     7    done
  4647.     8    done
  4648.     9    Eprom Addr5, pin#3    
  4649.     10    Ground
  4650.     11    done
  4651.     12    Eprom Addr7, pin#1
  4652.     13    done
  4653.     14    done
  4654.     15    Eprom Addr6, pin#2
  4655.     16    Eprom Addr1, pin#7
  4656.     17    done
  4657.     18    done
  4658.     19    Eprom Addr0, pin#8
  4659.     20    +5 volts
  4660. 2732 Prom:
  4661.     1-11    done
  4662.     12    Ground
  4663.     13-17    done
  4664.     18    Ground (chip enable. Doesn't save power very much)
  4665.     19-23    done
  4666.     24    +5 volts
  4667. crystal:
  4668.     connected between 8051 pins 18 and 19
  4669. 30pf cap1:
  4670.     connected between a lead of cystal and ground
  4671. 30pf cap2:
  4672.     connected between other lead of crystal and ground
  4673. 10uF Electrolytic Cap:
  4674.     minus end to 8051 pin9, + end to +5 volts.
  4675. 10k resistor:
  4676.     tied between ground and 8051 pin 9
  4677. VVV reset pushbutton switch. This is not absolutely necessary.
  4678. Pushbutton Switch1:
  4679.     tied between 8051 pin9 and +5 volts
  4680. VVV only use if you want a one-button hard reset.
  4681. Pushbutton Switch2: (amiga reset switch)
  4682.     tied between 8051 pin12 (int0) and ground
  4683. 5-pin Female IBM connector:
  4684.     Connect plus voltage pin to +5 volts
  4685.     Connect ground pin to ground
  4686.     connect clock and data as in above
  4687. (pin1=clock, pin2=data, pin3=NC, pin4=ground, pin5=+5v)
  4688. (as you face the back of the 5-pin female din, with the notch pointing up,
  4689. the pin order from left to right is 1,4,2,5,3)
  4690.  
  4691. Amiga Connector: each of the amiga connectors for the 500/1000/2000 will 
  4692.     be different.
  4693. On the Amiga 1000, the keyboard connects by means of a telephone
  4694.     HANDSET connector with a regular phone handset cord. The pins
  4695.     from left to right on the back of the Amiga 1000 are +5,clock,data,GND.
  4696.     If you make this circuit yourself, I suggest purchasing a little jack
  4697.     from the local telephone repairman. They are fairly standard jacks
  4698.     I believe. Connect red on the jack to +5,white to clock,greeen to
  4699.     data, black to ground. (On the circuit board, that is...)
  4700.     Clock and Data are wherever you locate them in the source code.
  4701.     As it stands, Amiga Clock is on pin 3 of the 8051, and Data is
  4702.     on pin 4.
  4703.  
  4704. For the Amiga 500, there is a 8 pin straight line on the mother board.
  4705. These pins from left to right are
  4706. 1. Data
  4707. 2. Clock
  4708. 3. Reset
  4709. 4.+5
  4710. 5 Not connected. (Key)
  4711. 6.Ground
  4712. 7. Status (not used)
  4713. 8. Disk Light (not used)
  4714.  
  4715. Make yourself a special adaptor that connects your amiga to the circuit.
  4716. You WILL need to connect the reset line if you want to soft reset from
  4717. the keyboard. The A500 only resets by having the Reset line driven low.
  4718.  
  4719. It says in my hardware manual here that The connector TO the keyboard
  4720. goes as follows:
  4721. 1: Clock
  4722. 2: Data
  4723. 3: Not connected.
  4724. 4: Ground
  4725. 5: +5 volts.
  4726. I imagine it's just like the AT connector, but it's a shame they don't use
  4727. the same data signals!
  4728.  
  4729.  
  4730.  
  4731. VERY IMPORTANT:!!!! The cord from the Amiga to the Converter must be
  4732. very very short and have very low resistance for this circuit to run on it's
  4733. own power. Do NOT use a long handset cord, it will load down the power lines.
  4734. IT's made of ribbon copper wound around some white stuff and it conducts poorly
  4735. on purpose. I used a hackup phone handset cord that is only about 3 inches
  4736. long. That works fine. You may need to get a phone repairman to make the
  4737. little cord special. He can do it, I know. It's a common thing. It shouldn't
  4738. be expensive. The one he made for me cost 1$.
  4739.  
  4740. That's it!
  4741. ====================================================================
  4742. A little background on the IBM AT keyboard:
  4743. The keyboard I used for this circuit was a BTC 5339sx. It costs about $40
  4744. Lucky Computers, 1-800-348-5825. I have also tested the circuit on a 
  4745. standard PC keyboard, and an HP Vectra AT keyboard.
  4746.  
  4747. The AT keyboard DIN connector has 5 pins. Pin 3 is called Reset, but it's
  4748. reserved, so we can't use it. Forget it exists on the AT keyboard. They just
  4749. charge you money for it. (joke) Open collectors drive the clock and data pins,
  4750. so when they are not driven low, they float at 5 volts.
  4751.  
  4752. The keyboard transmits data by bits, each synchonous somehow with the clock
  4753. line. They keyboard when clocking in or out data, always runs the clock.
  4754. The controller can drive the clock line, but not with reference to data.
  4755.     When the Keyboard sends data, it first sets the data, then drives
  4756. clock low, then high, and then changes the data to the next value.
  4757.     The AT uses 11 bits for a transmission, 1 start bit (0), 8 data
  4758. bits, 1 parity bit-set if the number of 1's in the data bits is even, and
  4759. a stop bit (1). When the keyboard sends it's last bit, the stop bit, the
  4760. controller must drive clock line low as a handshake and to tell the 
  4761. keyboard not to send until clock goes high again.
  4762.     Theoretically, the controller could interrupt the sending of the
  4763. bits, but I consider this unnecessary, and don't bother with it.
  4764. When the computer needs to send a command to the keyboard, it sets clock
  4765. line high and the data line low. When the keyboard sees this, it will
  4766. start clocking pulsed on the data line. 
  4767. Then, the controller must look for the clock line going low, set the data
  4768. bit, wait for the clock to go high, then wait for the clock to go low
  4769. again, and then change the bit. Thus, it changes the data in the middle
  4770. of the clock low pulse. When the keyboard has received it's 10th bit,
  4771. it will drive the data line low while at the same time clocking out
  4772. an extra clock low pulse. Then, it expects a handshake of the clock line
  4773. low from the controller.
  4774.                     0       1       2   |   7       P     stop    extra
  4775. Clock:------------\___/---\___/---\___/---\___/---\___/---\___/---\___/end
  4776.  
  4777. Data:-------\_______00000001111111122222|6677777777PPPPPPPP1111xxxxxxxx_____
  4778.  
  4779. Notice there is NO start bit when the controller sends data to the Keyboard.
  4780.  
  4781. Special Commands the Keyboard can Send to the Controller:
  4782. -----------------------------------------------------------
  4783. 00     Keyboard buffer overflowed
  4784. AA     Selftest passed
  4785. FA    The command sent was received correctly
  4786. FE    The command sent was received poorly. Please resend.
  4787.  
  4788. Special Commands the Controller can Send to the Keyboard:
  4789. -----------------------------------------------------------
  4790. ED    Set the LEDs according to next byte I send
  4791.     bit 0=Scroll lock 1=on
  4792.     bit 1=Num lock
  4793.     bit 2=Caps lock
  4794.     bits 3-7 must be 0
  4795. F4    clear the key buffer and start scanning
  4796. F6    restore default values
  4797. FE    retransmit last character, please
  4798. FF    Reset, you stupid keyboard!
  4799.  
  4800. Whew! That about raps it up for the AT keybard! Enough said, right?
  4801.  
  4802.  
  4803. XT keyboards transmit much the same way except they only use 10 bits.
  4804. Two start bits (both high) and 8 data bits, transmitted in order 0-1-2...-7
  4805. The last bit is a make/break bit which is 1 to signify a break.
  4806.  
  4807. The XT can have no commands sent to it. The way to reset it is to drive
  4808. the Clock line low for some longish period of time. The keyboard will not
  4809. send data (it will hold off) if the data line is being held low by an
  4810. external source (the controller)
  4811.  
  4812. AMIGA SIDE=========================================
  4813.  
  4814. Now I bet you are all wondering which keys are mapped to which keys.
  4815. I am using the 101 AT keyboard.
  4816.  
  4817. AT            Amiga
  4818. ==            =====
  4819.  
  4820. Left Ctrl        Left Amiga
  4821. Right Ctrl        Right Amiga
  4822. F11            Numeric Keypad (
  4823. F12            Numeric Keypad ) (doesn't work on A1000's)
  4824. Capslock        Control (IF used in conjunction with another key)
  4825. Delete            Delete
  4826. Page Down        Help
  4827. PrintScreen        Left Amiga
  4828. ScrollLock        Right Amiga
  4829. NumLock            Control
  4830. (the above three keys mapped for easy one-hand reset)
  4831. Insert            Amiga+Left Cursor
  4832. Home            Amiga+Up Cursor
  4833. End            Amiga+Down Cursor
  4834. PageUp            Amiga+Right Cursor
  4835. (the above keys mapped for easy mouse pointer control in workbench.)
  4836.  
  4837. The BTC keyboard I used also included a Macro key (conveniently) that
  4838. is mapped as a control key.
  4839.  
  4840.  
  4841. All other keys are mapped exactly the same.
  4842.  
  4843. Since the Control Keys on the AT are mapped to the Amiga keys,
  4844. I made a little routine that defines the Capslock Key to work as
  4845. Control if you hold it down first, then type the other key.
  4846. Just use it as you would an ordinary Control key.
  4847. This only works for the AT, not the XT since I can't control the lights
  4848. on the XT.
  4849.  
  4850. The explanation for how the Amiga Keyboard works is provided in the
  4851. Hardware Reference Manual. I will not repeat this info here, for fear of
  4852. copyright infringements and because the manual is cheap and a valuable
  4853. must for anyone who indulges in this kind of thing.
  4854.  
  4855.  
  4856. <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  4857.  
  4858. SOFTWARE:
  4859.  
  4860. I have included the source and the machine code for the software that
  4861. runs this circuit. The timing loops are pretty stringent so if you want to
  4862. change things, better have a logic analyzer on hand!
  4863.  
  4864. I am also going to include a simple 8051 code assembler for those who don't
  4865. like to hand-code. If you keep your programs neatly written, it should 
  4866. assemble fine.
  4867.  
  4868. Documentation is within the program listing. It's not too hard to follow if
  4869. you know what you are doing.
  4870.  
  4871. Feel free to change anything you want, but before you redistribute it,
  4872. please tell me of the changes. Make it known within the program that you
  4873. have made changes.
  4874.  
  4875. The circuit, once built, should never have to be removed once plugged into
  4876. your computer. It should Auto Detect which style keyboard is hooked up
  4877. if the XT/AT pin (now coded as Port 1.7 (pin 8)) is not tied low.
  4878. IF for some reason the circuit does not start up fine, you may need
  4879. a reset CIRCUIT switch. This is different than the reset Computer
  4880. switch. This switch SHOULD restart the circuit and make it sync
  4881. up to the computer and the keyboard.
  4882.  
  4883. I will sell anybody any number of the parts needed, from circuit board
  4884. to telephone connectors to the whole thing.
  4885.  
  4886. Circuit board alone: 5$
  4887. Telephone connector: 1.50$
  4888. Whole thing minus case:25$ plus shipping.
  4889. Full documentation: 1$ plus postage.
  4890.  
  4891. Any questions? Be glad to answer em!
  4892. Email address: rudolpe@jacobs.cs.orst.edu
  4893. Phone # 503-745-7466 (Oregon)
  4894.  
  4895. @\Rogue\Monster\
  4896. else
  4897.   echo "shar: Will not over write keydoc"
  4898. fi
  4899. # to concatenate archives, remove anything after this line
  4900. exit 0
  4901.