home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / amix / FixAmix.Clock-NTSC < prev    next >
Internet Message Format  |  2014-05-19  |  6KB

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