]> git.sur5r.net Git - cc65/blobdiff - samples/nachtm.c
Since we have now builtin search paths, we need to be able to forget them,
[cc65] / samples / nachtm.c
index 9663b3df665a29119c8fa1d8da801f2c590f99c6..6c78ebcb2c9a5c3feebc6e98e1953126a20b8489 100644 (file)
@@ -13,6 +13,7 @@
 
 
 #include <stdio.h>
+#include <string.h>
 #include <time.h>
 #include <conio.h>
 #include <cbm.h>
@@ -41,7 +42,7 @@
 
 
 
-static int Voice1 [] = {
+static unsigned Voice1 [] = {
     0x5708,0x8004,0x5204,0x5708,0x8004,0x5204,0x5704,0x5204,0x5704,0x5B04,
     0x6208,0x8008,0x6008,0x8004,0x5904,0x6008,0x8004,0x5904,0x6004,0x5904,
     0x5604,0x5904,0x5208,0x8008,0x5704,0x8004,0x570C,0x5B01,0x5B01,0x5B01,
@@ -395,7 +396,7 @@ static int Voice1 [] = {
     0x0000
 };
 
-static int Voice2 [] = {
+static unsigned Voice2 [] = {
     0x4708,0x8004,0x4204,0x4708,0x8004,0x4204,0x4704,0x4204,0x4704,0x4B04,
     0x5208,0x8008,0x5008,0x8004,0x4904,0x5008,0x8004,0x4904,0x5004,0x4904,
     0x4604,0x4904,0x4208,0x8008,0x4704,0x4704,0x4704,0x4704,0x4704,0x4704,
@@ -615,7 +616,7 @@ static int Voice2 [] = {
     0x0000
 };
 
-static int Voice3 [] = {
+static unsigned Voice3 [] = {
     0x3708,0x8004,0x3204,0x3708,0x8004,0x3204,0x3704,0x3204,0x3704,0x3B04,
     0x3208,0x8008,0x4008,0x8004,0x3904,0x4008,0x8004,0x3904,0x4004,0x3904,
     0x3604,0x4904,0x4208,0x8008,0x3704,0x3704,0x3704,0x3704,0x3704,0x3704,
@@ -857,16 +858,7 @@ static int Voice3 [] = {
 
 
 
-/* Screen sizes */
-#ifdef __CBM610__
-#  define MAX_X        80
-#else
-#  define MAX_X 40
-#endif
-
-
-
-#ifdef __C64__
+#if defined(__C64__) || defined(__CBM510__)
 static unsigned long FreqTab [12] = {
 #ifndef NTSC
     /* PAL */
@@ -878,16 +870,12 @@ static unsigned long FreqTab [12] = {
     0x00BDAD, 0x00C8F4, 0x00D4E6, 0x00E18F, 0x00EEF9, 0x00FD2F,
 #endif
 };
-#endif
-
-#ifdef __C128__
+#elif defined(__C128__)
 static unsigned long FreqTab [12] = {
     0x00892B, 0x009153, 0x0099F7, 0x00A31E, 0x00ACD2, 0x00B718,
     0x00C1FD, 0x00CD85, 0x00D9BD, 0x00E6B0, 0x00F467, 0x0102F0,
 };
-#endif
-
-#ifdef __CBM610__
+#elif defined(__CBM610__)
 static unsigned long FreqTab [12] = {
     0x004495, 0x0048AA, 0x004CFB, 0x00518F, 0x005669, 0x005B8C,
     0x0060FE, 0x0066C3, 0x006CDE, 0x007358, 0x007A34, 0x008178,
@@ -901,7 +889,7 @@ typedef struct {
     unsigned char      Trigger;        /* Trigger value */
     unsigned char      Ticks;          /* Ticks for this tone */
     unsigned           Freq;           /* Actual frequency value */
-    int*               Data;           /* Pointer to data */
+    unsigned*                  Data;           /* Pointer to data */
     struct __sid_voice*        Voice;          /* Pointer to sid registers */
 } VoiceCtrl;
 
@@ -921,6 +909,9 @@ static VoiceCtrl* V [3] = {
     &V1, &V2, &V3
 };
 
+/* Screen dimensions */
+static unsigned char XSize, YSize;
+
 /* Variable that contains the time of the next clock tick to play a note */
 static unsigned char NextClock;
 
@@ -938,7 +929,7 @@ static unsigned char Done;
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                  Code                                    */
 /*****************************************************************************/
 
 
@@ -947,7 +938,7 @@ static void MakeTeeLine (unsigned char Y)
 /* Make a divider line */
 {
     cputcxy (0, Y, CH_LTEE);
-    chline (MAX_X - 2);
+    chline (XSize - 2);
     cputc (CH_RTEE);
 }
 
@@ -957,27 +948,27 @@ static void MakeNiceScreen (void)
 /* Make a nice screen */
 {
     typedef struct {
-       unsigned char   X;
        unsigned char   Y;
        char*           Msg;
     } TextDesc;
     static TextDesc Text [] = {
-               {  (MAX_X / 2) - 11,  2, "Wolfgang Amadeus Mozart"      },
-        {  (MAX_X / 2) - 12,  4, "\"Eine kleine Nachtmusik\""  },
-               {  (MAX_X / 2) -  4,  5, "(KV 525)"                     },
-        {  (MAX_X / 2) - 14,  9, "Ported to the SID in 1987 by" },
-               {  (MAX_X / 2) - 10, 11, "Joachim von Bassewitz"        },
-               {  (MAX_X / 2) - 13, 12, "(joachim@von-bassewitz.de)"   },
-               {  (MAX_X / 2) -  1, 13, "and"                          },
-               {  (MAX_X / 2) - 10, 14, "Ullrich von Bassewitz"        },
-        {  (MAX_X / 2) - 13, 15, "(ullrich@von-bassewitz.de)"  },
-               {  (MAX_X / 2) -  9, 18, "C Implementation by"          },
-               {  (MAX_X / 2) - 10, 19, "Ullrich von Bassewitz"        },
-        {  (MAX_X / 2) - 11, 23, "Press any key to quit..."    },
+               {   2, "Wolfgang Amadeus Mozart"        },
+        {   4, "\"Eine kleine Nachtmusik\""    },
+               {   5, "(KV 525)"                       },
+        {   9, "Ported to the SID in 1987 by" },
+               {  11, "Joachim von Bassewitz"          },
+               {  12, "(joachim@von-bassewitz.de)"     },
+               {  13, "and"                            },
+               {  14, "Ullrich von Bassewitz"          },
+        {  15, "(ullrich@von-bassewitz.de)"    },
+               {  18, "C Implementation by"            },
+               {  19, "Ullrich von Bassewitz"          },
+        {  23, "Press any key to quit..."      },
     };
 
-    TextDesc* T;
+    register const TextDesc* T;
     unsigned char I;
+    unsigned char X;
 
     /* Clear the screen hide the cursor, set colors */
 #ifdef __CBM610__
@@ -992,7 +983,7 @@ static void MakeNiceScreen (void)
 
     /* Top line */
     cputcxy (0, 0, CH_ULCORNER);
-    chline (MAX_X - 2);
+    chline (XSize - 2);
     cputc (CH_URCORNER);
 
     /* Left line */
@@ -1000,11 +991,11 @@ static void MakeNiceScreen (void)
 
     /* Bottom line */
     cputc (CH_LLCORNER);
-    chline (MAX_X - 2);
+    chline (XSize - 2);
     cputc (CH_LRCORNER);
 
     /* Right line */
-    cvlinexy (MAX_X - 1, 1, 23);
+    cvlinexy (XSize - 1, 1, 23);
 
     /* Several divider lines */
     MakeTeeLine (7);
@@ -1012,8 +1003,9 @@ static void MakeNiceScreen (void)
 
     /* Write something into the frame */
     for (I = 0, T = Text; I < sizeof (Text) / sizeof (Text [0]); ++I) {
-       cputsxy (T->X, T->Y, T->Msg);
-       ++T;
+        X = (XSize - strlen (T->Msg)) / 2;
+       cputsxy (X, T->Y, T->Msg);
+       ++T;
     }
 }
 
@@ -1045,10 +1037,10 @@ static void DisplayTime (void)
 
 
 
-/* On the 610, the SID is in another bank (the system bank), so we cannot
+/* On the 510/610, the SID is in another bank (the system bank), so we cannot
  * just write to the memory space.
  */
-#ifdef __CBM610__
+#if defined(__CBM510__) || defined(__CBM610__)
 #  define outb(addr,val)       pokebsys ((unsigned)(addr), val)
 #  define outw(addr,val)       pokewsys ((unsigned)(addr), val)
 #else
@@ -1063,13 +1055,16 @@ int main (void)
     unsigned char       I;
     unsigned char       Tone;
     unsigned char       Octave;
-    unsigned           Val;
+    unsigned           Val;
     struct __sid_voice*        Voice;
-    VoiceCtrl*         VC;
+    register VoiceCtrl*        VC;
 
     /* Initialize the debugger */
     DbgInit (0);
 
+    /* Get the screen dimensions */
+    screensize (&XSize, &YSize);
+
     /* Make a nice screen */
     MakeNiceScreen ();