home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / amix / FixAmix.Clock-NTSC / text0000.txt < prev   
Encoding:
Text File  |  2014-05-19  |  5.5 KB  |  163 lines

  1. In article <1992Sep3.092136.3831@ifi.unizh.ch> blatter@ifi.unizh.ch (Martin A. Blatter) writes:
  2. >In article <BtyKEF.6up@oytix.north.de> mike@oytix.north.de (Mike Fleischer) writes:
  3. >>ich wollte meinen Amiga unter UNIX gerne auf NTSC stellen, da ich einen 
  4. >>A2024 habe und die hoehere Bildwiederholfrequenz angenehmer finde.
  5. >>Das klappte auch tadellos, nur, was mir am nexten Tag unangenehm auffiel,
  6. >>war die Tatsache, dass die Uhr in 24 Stunden ca. 10 Minuten nachlief.
  7. >>Ich habe dabei einfach nur den internen Jumper auf dem Motherboard auf
  8. >>NTSC gestellt, sonst nix. Habe ich was vergessen oder falsch gemacht???
  9. >
  10. >Nein, Du hast nix falsch gemacht. Leider ist das ein Bug im Amiga Unix,
  11. >der zwar bekannt ist, aber nie behoben wurde. Wir haben das auf
  12.  
  13. Also ich das Problem auf meinem Unix mit einem mittelpraechtigen Hack 
  14. geloest, der nicht ganz unkritisch ist (siehe Kommentar in der Source), aber
  15. die erwaehnte Race-Condition hat bei mir noch nie zugeschlagen. Da der
  16. Source ziemlich klein ist, haenge ich ihn mal an hier:
  17.  
  18. /*
  19.  * Repair wrong timing set in CIA chip, if running NTSC video on a machine
  20.  * with 50 Hz power frequency.
  21.  *
  22.  * 1.0  91-10-25  M.Wild   first hack
  23.  *
  24.  * Based on /usr/amiga/sys/driver/cl.c. THANKS Commo for providing the 
  25.  * kernel source!
  26.  */
  27.  
  28. #include <sys/types.h>
  29. #include <sys/param.h>
  30. #include <sys/amiga/amiga.h>
  31. #include <sys/mman.h>
  32. #include <signal.h>
  33. #include <fcntl.h>
  34. #include <stdio.h>
  35.  
  36. /* param.h has hibyte/lobyte that don't work */
  37. #undef lobyte
  38. #undef hibyte
  39.  
  40. #define lobyte(x) ((unsigned char)(x))
  41. #define hibyte(x) ((unsigned char)((unsigned)(x)>>8))
  42.  
  43. volatile unsigned char *custom_chips;
  44.  
  45. #define ACIAA ((struct acia *) &custom_chips[0xbfe001 - (long)AHWBOT])
  46.  
  47. /* the following definition copied from /usr/sys/amiga/inc/amigahr.h: */
  48.  
  49. /*
  50.  * 8520 CIA registers.
  51.  */
  52. struct acia {
  53.         unsigned char   pra;            /* Peripheral data register A   */
  54.         unsigned char   cia0[0xFF];
  55.         unsigned char   prb;            /* Peripheral data register B   */
  56.         unsigned char   cia1[0xFF];
  57.         unsigned char   ddra;           /* Data direction register A    */
  58.         unsigned char   cia2[0xFF];
  59.         unsigned char   ddrb;           /* Data direction register B    */
  60.         unsigned char   cia3[0xFF];
  61.         unsigned char   talo;           /* Timer A low register         */
  62.         unsigned char   cia4[0xFF];
  63.         unsigned char   tahi;           /* Timer A high register        */
  64.         unsigned char   cia5[0xFF];
  65.         unsigned char   tblo;           /* Timer B low register         */
  66.         unsigned char   cia6[0xFF];
  67.         unsigned char   tbhi;           /* Timer B high register        */
  68.         unsigned char   cia7[0xFF];
  69.         unsigned char   todl;           /* Time of day low register     */
  70.         unsigned char   cia8[0xFF];
  71.         unsigned char   todm;           /* Time of day middle register  */
  72.         unsigned char   cia9[0xFF];
  73.         unsigned char   todh;           /* Time of day high register    */
  74.         unsigned char   cia10[0xFF];
  75.         unsigned char   cia11[0x100];
  76.         unsigned char   sdr;            /* Serial data register         */
  77.         unsigned char   cia12[0xFF];
  78.         unsigned char   icr;            /* Interrupt control register   */
  79.         unsigned char   cia13[0xFF];
  80.         unsigned char   cra;            /* Control register A           */
  81.         unsigned char   cia14[0xFF];
  82.         unsigned char   crb;            /* Control register B           */
  83.         unsigned char   cia15[0xFF];
  84. };
  85.  
  86. /*
  87.  * open /dev/amiga and map the custom chips (incl CIAs) into user-space.
  88.  */
  89. void
  90. map_custom_chips ()
  91. {
  92.   int fd;
  93.  
  94.   if ((fd = open ("/dev/amiga/", O_RDWR)) < 0)
  95.     {
  96.       perror ("Can't open /dev/amiga");
  97.       exit (1);
  98.     }
  99.  
  100.   custom_chips = (unsigned char *) mmap (0, AHWLEN, PROT_READ|PROT_WRITE, 
  101.                                          MAP_SHARED, fd, AHWBOT);
  102.  
  103.   if (custom_chips == (unsigned char *) -1)
  104.     {
  105.       perror ("Can't mmap /dev/amiga");
  106.       exit (1);
  107.     }
  108.  
  109.   /* we got them ;-)) */
  110. }
  111.  
  112. #ifdef COMMO
  113. #define EHZ             ((hz == 50)?709379:715909)
  114. #define ATICKS          ((EHZ+HZ/2)/HZ)
  115. #else
  116. /* value determined heuristically by correcting above value.. */
  117. #define EHZ             ((hz == 50)?709290:715909)
  118. #define ATICKS          ((EHZ+HZ/2)/HZ)
  119. #endif
  120.  
  121. void
  122. main (int argc, char **argv)
  123. {
  124.   int hz;
  125.  
  126.   if (argc != 2 ||
  127.       ((hz = atoi (argv[1])) != 50 && hz != 60))
  128.     {
  129.       printf ("%s: [50|60]\n", argv[0]);
  130.       exit (1);
  131.     }
  132.  
  133.   map_custom_chips ();
  134.  
  135.   /* this is a critical part of code.. the first line stops the clock. As long
  136.    * as the clock is stopped, no task switching will take place, so we're safe
  137.    * for the next instructions, then at last we restart the timer. I guess 
  138.    * there could be a race condition when trying to stop the clock. If we 
  139.    * lose the CPU in exactly this moment, we'll never get it back, and the 
  140.    * system is stalled. */
  141.   ACIAA->cra = 0;               /* stop the timer */
  142.   ACIAA->talo = lobyte(ATICKS);  /* load it with new values */
  143.   ACIAA->tahi = hibyte(ATICKS); 
  144.   ACIAA->cra = 0x11;            /* and restart it */
  145.  
  146.   exit (0);
  147. }
  148.  
  149.  
  150. Es duerfte klar sein, dass dieses Ding nur von privilegierten Usern
  151. ausgefuehrt werden darf (nur schon wegen der Lese-Berechtigung von /dev/amiga).
  152. Ich hab ein /etc/rc2.d/S91clock File, das mir die Korrektur beim booten
  153. vornimmt:
  154.  
  155. /usr/local/bin/speedy 50
  156.  
  157. -Markus
  158. -- 
  159. Markus M. Wild    -  wild@nessie.cs.id.ethz.ch  |  wild@amiga.physik.unizh.ch 
  160. Vital papers will demonstrate their vitality by spontaneously moving
  161. from where you left them to where you can't find them.
  162.  
  163.