home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / TOXIC_14.ARJ / toxic_14 / TOXIC_14.D_2 / LEONARD / LEO_ST.ZIP / ST_PC / SYSTEM / STS.C < prev   
C/C++ Source or Header  |  1996-04-07  |  9KB  |  480 lines

  1.  
  2. /********************************************************
  3.  *                            *
  4.  *                            *
  5.  *    SEND. Envoie d'un fichier binaire par port    *
  6.  *    paralelle, protocole "LEO".            *
  7.  *    Version PC->ST 4bits.                *
  8.  *    WATCOM 16bits.                    *
  9.  *                            *
  10.  *    (C)oderight OXYGENE 1995 by léo.        *
  11.  *                            *
  12.  *                            *
  13.  ********************************************************/
  14.  
  15.  
  16.  
  17. /***************************************************************************
  18.  
  19.     Le programme utilise le protocole BI-Directionnel STE<->PC by Leonard
  20.  
  21.     Voici donc le cablage à la mord moi le noeud que j'ai trouvé le plus
  22.     adapté à la liaison...
  23.  
  24.     (Le port paralelle du ST n'étant retournable qu'en tout ou rien, on
  25.     recoit les données en 8 bits par le port joystick numérique du STE !)
  26.  
  27.  
  28.  
  29.  
  30.  
  31.   1) Description du protocole.
  32.  
  33.  
  34. Le cable doit donc comporter deux prises 15broches à trois rangées pour etre
  35. connectées aux 2 ports joystick numérique STE.
  36.  
  37. Le STROBE du PC a été mappé sur la broche UP du port 2 (bit 15) pour pouvoir
  38. faire le wait de synchro avec un:
  39.  
  40. .wait:    move.w    (a0),d0
  41.     bmi.s    .wait
  42.     move.b    d0,(a1)+
  43.  
  44. Comme D0-D7 sont mappées sur les 8bits de poids faible, on a tout de suite
  45. la donnée 8bits dans l'octet faible de D0.
  46.  
  47.  
  48. Pour envoyer sur ST, on evoie en paquets de 4bits (Le port PC n'étant pas
  49. retournable ou ne peut rien recevoir par D0-D7). On utilise D7 du ST comme
  50. bit de strobe. (Plus rapide à programmer que de passer par le PSG Yamaha).
  51.  
  52.  
  53. Comme toutes ces liaisons sont faites en SYNCHRO, il faut toujours se demerder
  54. pour que la machine qui RECOIT SOIT PLUS RAPIDE QUE CELLE QUI ENVOIE.
  55. Pour que la laison boost il faut simplement faire la routine de reception la
  56. plus rapide possible sur ST et s'arranger à régler au mieux la vitesse sur PC.
  57.  
  58. PROBLEMES:
  59.     Des problèmes de rebond lors de changements d'états sur les ports
  60. joystick numériques font que j'ai été obligé de doubler le test du bit de strobe
  61. sur ST pour que cela fonctionne:
  62.  
  63.  
  64. .wait:    move.w    (a0),d0
  65.     bmi.s    .wait
  66.     move.w    (a0),d0
  67.     bmi.s    .wait
  68.     move.b    d0,(a1)+
  69.  
  70.  
  71.  Voila, le port STE se lit en .W à l'adresse: $00FF9202
  72.  
  73.  
  74.  
  75.                             Leonard, OXYGENE.
  76.  
  77.  
  78.  
  79.  
  80.   2) Description du cable:
  81.  
  82.  
  83.  
  84.     ST            PC
  85.  
  86.  
  87.                  Port paralelle.
  88.  
  89.  
  90. Port Joystick STE 1   םגגגגגגגג 1  STROBE
  91.                       ø
  92.         4 <גגגגגגגגגגגדגגגגגגגג 2  D0
  93.         3 <גגגגגגגגגגגדגגגגגגגג 3  D1
  94.         2 <גגגגגגגגגגגדגגגגגגגג 4  D2
  95.         1 <גגגגגגגגגגגדגגגגגגגג 5  D3
  96.                       ø
  97.     GND 9 גגגגגגגגגגגגדגגגגגגגג 19 GND
  98.                       ø
  99.                       ø  םגגגגג 6  D4
  100.                       ø  øםגגגג 7  D5
  101.                       ø  øøםגגג 8  D6
  102. Port Joystick STE 2   ø  øøøםגג 9  D7
  103.                       ø  øøøø
  104.         4 <גגגגגגגגגגגדגגךøøø
  105.         3 <גגגגגגגגגגגדגגגךøø
  106.         2 <גגגגגגגגגגגדגגגגךø
  107.         1 <גגגגגגגגגגגדגגגגגך
  108.                       ø
  109.    UP2 11 <גגגגגגגגגגגך
  110.  
  111.    GND 19 גגגגגגגגגגגגגגגגגגגגג 25 GND
  112.  
  113.  
  114.  
  115.  Port Paralelle ST
  116.  
  117.     D0  2 גגגגגגגגגגגגגגגגגגגג> 15 ERROR
  118.     D1  3 גגגגגגגגגגגגגגגגגגגג> 13 SLCT (Printer OnLine (Selected))
  119.     D2  4 גגגגגגגגגגגגגגגגגגגג> 12 PE (Paper Error)
  120.     D3  5 גגגגגגגגגגגגגגגגגגגג> 10 ACK (Acknowledge, Printer Ready)
  121.  
  122.     D7  9 גגגגגגגגגגגגגגגגגגגג> 11 BUSY
  123.  
  124.  
  125.  
  126.        25 גגגגגגגגגגגגגגגגגגגגג 20 GND
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. ****************************************************************************/
  134.  
  135.  
  136. // includes.
  137. #include <stdio.h>
  138. #include <stdlib.h>
  139. #include <stddef.h>
  140. #include <conio.h>
  141. #include <time.h>
  142. #include <string.h>
  143.  
  144. typedef    unsigned long    UD;
  145. typedef    long        SD;
  146. typedef unsigned short    UW;
  147. typedef short        SW;
  148. typedef unsigned char    UB;
  149. typedef char        SB;
  150.  
  151.  
  152. #define    BLOCK_SIZE    (2048)        // Si modif, a changer aussi sur le ST !
  153. #define DEFAULT_WAIT    (200)
  154.  
  155. #define    LOAD_ONLY        0
  156. #define    LOAD_AND_RUN    1
  157. #define    BLOCK_RUN        2
  158. #define    BLOCK_SAVE        3
  159. #define    FILE_COPY        4
  160.  
  161.  
  162. #define    BLOCK_INFO_SIZE    32
  163.  
  164. UD    binaryAd;
  165. UW    binaryMode=LOAD_ONLY;
  166. UB    buffer[BLOCK_SIZE];
  167. UB    info_block[BLOCK_INFO_SIZE];
  168. UD    tempo;
  169. char    fileName[_MAX_PATH];
  170.  
  171. static char tmpDrive[_MAX_DRIVE];
  172. static char tmpDir[_MAX_DIR];
  173. static char tmpFname[_MAX_FNAME];
  174. static char tmpExt[_MAX_EXT];
  175.  
  176. /********************************************************************
  177.             SECTION CODE
  178.  ********************************************************************/
  179.  
  180.  
  181.  
  182. UD    file_size(FILE *handle)
  183.  {
  184.  UD    size,pos;
  185.  
  186.     pos=ftell(handle);
  187.     fseek(handle,0,SEEK_END);
  188.     size=ftell(handle);
  189.     fseek(handle,pos,SEEK_SET);
  190.     return size;
  191. }
  192.  
  193.  
  194.  
  195. UW    calc_check(FILE *in,UD size)
  196.  {
  197.  UD    i;
  198.  UW    check;
  199.  
  200.  
  201.     printf("Calculating checksum:");
  202.     fflush(stdout);
  203.     check=0;
  204.     for (i=0;i<size;i++) check+=(UB)fgetc(in);
  205.     printf("$%4X\n",check);
  206.     fseek(in,0,SEEK_SET);
  207.     return check;
  208.  }
  209.  
  210.  
  211. void    wait(register int t)
  212.  {
  213.  
  214.     do
  215.     {
  216.     }
  217.     while (--t);
  218.  
  219.  }
  220.  
  221.  
  222.  
  223. void    paral_send(UB *ptr,register unsigned int size,int timing)
  224.  {
  225.  register int    strobe;
  226.  register UB    data;
  227.  
  228.  
  229.  // Version Send 8 bits par ports joystick STE.
  230.     strobe=0;
  231.     do
  232.     {
  233.       data=*ptr++;
  234.       outp(0x378,(data));
  235.       strobe^=1;
  236.       outp(0x37a,strobe);
  237.       wait(timing);
  238.     }
  239.     while (--size);
  240.  
  241.  }
  242.  
  243.  
  244.  
  245.  
  246. void    send_file(char *name)
  247.  {
  248.  FILE    *in;
  249.  SD    size;
  250.  UD    orgsize;
  251.  int    sload;
  252.  UW    check;
  253.  clock_t    t1,t2;
  254.  float    t3;
  255.  static char tmpName[_MAX_PATH];
  256.  
  257.  
  258.  
  259.     if ((binaryMode==BLOCK_RUN) || (binaryMode==BLOCK_SAVE))
  260.     {
  261.  
  262.         info_block[10]=(binaryMode>>8)&255;
  263.         info_block[11]=(binaryMode)&255;
  264.         paral_send(info_block,BLOCK_INFO_SIZE,2048);
  265.  
  266.         printf("Command send.\n");
  267.  
  268.         return;
  269.     }
  270.  
  271.  
  272.     in=fopen(name,"rb");
  273.     if (!in)
  274.     {
  275.       printf("Unable to open %s\n",name);
  276.       exit(1);
  277.     }
  278.  
  279.     orgsize=file_size(in);
  280.     size=orgsize;
  281.     check=calc_check(in,size);
  282.  
  283.     // Poke la taille a transferer.
  284.     info_block[0]=((size)>>24)&255;
  285.     info_block[1]=((size)>>16)&255;
  286.     info_block[2]=((size)>>8)&255;
  287.     info_block[3]=((size))&255;
  288.  
  289.     info_block[4]=(check>>8)&255;
  290.     info_block[5]=(check)&255;
  291.  
  292.     info_block[6]=((binaryAd)>>24)&255;
  293.     info_block[7]=((binaryAd)>>16)&255;
  294.     info_block[8]=((binaryAd)>>8)&255;
  295.     info_block[9]=((binaryAd))&255;
  296.  
  297.     info_block[10]=(binaryMode>>8)&255;
  298.     info_block[11]=(binaryMode)&255;
  299.  
  300.  
  301.     _splitpath(name,NULL,NULL,tmpFname,tmpExt);
  302.     _makepath(tmpName,NULL,NULL,tmpFname,tmpExt);
  303.     strcpy(info_block+16,tmpName);
  304.  
  305.     paral_send(info_block,BLOCK_INFO_SIZE,2048);
  306.  
  307.  
  308.  
  309.     printf("Sending %ld bytes...\n",size);
  310.  
  311.     // Wait 1 sec.
  312.     t1=clock();
  313.     while (clock()<(t1+CLOCKS_PER_SEC));
  314.  
  315.     t1=clock();
  316.  
  317.     while (size>0)
  318.     {
  319.       if (size>=BLOCK_SIZE) sload=BLOCK_SIZE;
  320.       else sload=size;
  321.       memset(buffer,0,BLOCK_SIZE);
  322.       fread(buffer,1,sload,in);
  323.       //putchar('*');
  324.       fputc('*',stdout);
  325.       paral_send(buffer,BLOCK_SIZE,tempo);
  326.       size-=sload;
  327.     }
  328.  
  329.     printf("\n");
  330.  
  331.     memset(buffer,0,BLOCK_SIZE);
  332.     paral_send(buffer,BLOCK_SIZE,tempo);
  333.  
  334.  
  335.     outp(0x378,0);        // Data clear.
  336.     outp(0x37a,0);        // Strobe clear.
  337.  
  338.  
  339.     t2=clock();
  340.     t3=t2-t1;
  341.     t3/=CLOCKS_PER_SEC;
  342.  
  343.     printf("Sending %ldbytes in %.02f seconds.\n",orgsize,t3);
  344.     printf("(Rate: %3.02f bytes/sec.)\n",((float)orgsize/t3));
  345.  
  346.  
  347.  
  348.  }
  349.  
  350.  
  351. void    usage(void)
  352.  {
  353.  
  354.  
  355.  
  356.         printf(    "Usage: STS <command> [pc_file_name] [-options]\n\n"
  357.                 "command:\n"
  358.                 "\td.......: Download \"pc_file_name\" in ST-Memory.\n"
  359.                 "\tr.......: Run \"pc_file_name\" in ST-Memory.\n"
  360.                 "\ts.......: Save block \"BLOCK.BIN\" on ST-Disk.\n"
  361.                 "\tg.......: GO: run block.\n"
  362.                 "\tc.......: file Copy.\n"
  363.                 "\n"
  364.                 "options:\n"
  365.                 "\t-a0xADR...: Specify ST-RAM adress.\n"
  366.                 );
  367.  
  368.         exit(1);
  369.  }
  370.  
  371.  
  372.  
  373. void    CheckArgs(int argc,char **argv)
  374.  {
  375.  int    n=0;
  376.  int    i;
  377.  char    c;
  378.  
  379.  
  380.         binaryAd = 0x8000;
  381.  
  382.         for (i=1;i<argc;i++)
  383.         {
  384.             c=toupper(*argv[i]);
  385.             if ((c=='-') || (c=='/'))
  386.             {
  387.                 c=argv[i][1];
  388.                 c=toupper(c);
  389.                 switch (c)
  390.                 {
  391.                     case '?':
  392.                     case 'H':
  393.                         Usage();
  394.                         break;
  395.                     case 'A':
  396.                         sscanf(&argv[i][2],"%lx",&binaryAd);
  397.                         if (!binaryAd)
  398.                         {
  399.                             printf("Wrong adress value.\n");
  400.                             usage();
  401.                         }
  402.                         break;
  403.                     default:
  404.                         printf("%s:Unknow option.\n\n",argv[i]);
  405.                         Usage();
  406.                         break;
  407.                 }
  408.             }
  409.             else
  410.             {
  411.                 n++;
  412.                 switch (n)
  413.                 {
  414.                     case 1:
  415.                         switch (c)
  416.                         {
  417.                             case 'D':
  418.                                 binaryMode=LOAD_ONLY;
  419.                                 break;
  420.                             case 'R':
  421.                                 binaryMode=LOAD_AND_RUN;
  422.                                 break;
  423.                             case 'S':
  424.                                 binaryMode=BLOCK_SAVE;
  425.                                 break;
  426.                             case 'G':
  427.                                 binaryMode=BLOCK_RUN;
  428.                                 break;
  429.                             case 'C':
  430.                                 binaryMode=FILE_COPY;
  431.                                 break;
  432.                             default:
  433.                                 printf("%s:Unknow command.\n\n",argv[i]);
  434.                                 usage();
  435.                         }
  436.                     case 2:
  437.                         strcpy(fileName,argv[i]);
  438.                         break;
  439.                     default:
  440.                         printf("TOO much args.\n");
  441.                         Usage();
  442.                 }
  443.             }
  444.         }
  445.  
  446.         if ((binaryMode==LOAD_ONLY) || (binaryMode==LOAD_AND_RUN) || (binaryMode==FILE_COPY))
  447.         {
  448.             if (n!=2) Usage();
  449.         }
  450.         else
  451.         {
  452.             if (n!=1) Usage();
  453.         }
  454.  
  455.  }
  456.  
  457.  
  458. void    main(int argc,char **argv)
  459.  {
  460.  
  461.         printf(    "FAST Atari SEND-Command tool.\n"
  462.                 "Version 16Bits.\n"
  463.                 "(C)OXYGENE 1995 by Leonard.\n\n");
  464.  
  465.         CheckArgs(argc,argv);
  466.  
  467.         tempo=DEFAULT_WAIT;
  468.  
  469.         printf("Tempo assumed: %ld\n",tempo);
  470.  
  471.         printf("Adress assumed:$%lx\n",binaryAd);
  472.  
  473.         send_file(fileName);
  474.  
  475.  }
  476.  
  477.  
  478.  
  479.  
  480.