home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / IYONIX / MANICMINER / SOURCE.ZIP / manicminer-1.6.3 / c / titles < prev    next >
Encoding:
Text File  |  2000-12-10  |  12.9 KB  |  577 lines

  1. #include "manic.h"
  2. #include "functions.h"
  3. #include "gfxdata/gfxdata.h"
  4. #include "gfxlibs/keyboard.h"
  5. #include "miscdata/misc.h"
  6. #include "gfxlibs/gfx.h"
  7. #include "sndlibs/snd.h"
  8. #include <string.h>
  9.  
  10. static void ClearPiano (void);
  11. static void DoPiano (void);
  12. static void DoPrefs (void);
  13. static void DoPrefsExtra (void);
  14. static void DoPrefsPage (void);
  15. static void DoTitleScroll (void);
  16. static void DrawScroll (void);
  17. static void DrawTPlate2 (void);
  18. static void DoTPlate (void);
  19. static void DrawWilly4 (BYTE block);
  20. static void FillPixelBuff (void);
  21. static void PrefsUpdate (void);
  22. static void PrintPrefs (void);
  23. static void SetupPrefs (void);
  24. static void TitleSetup (void);
  25. static void TitleSetupExtra (void);
  26. static void UpdatePianoKeys (int);
  27. static void UpdateScrollBuffer (void);
  28.  
  29. #ifdef __riscos
  30. # define PREFx 10
  31. #else
  32. # define PREFx 15
  33. #endif
  34.  
  35. static struct
  36. {
  37.   BYTE m, c, p;
  38.   BYTE h[4];
  39. }
  40. PREFS;
  41.  
  42. static struct
  43. {
  44.   unsigned long khit;
  45.   WORD c;
  46.   BYTE bodge1, bodge2, bodgep, bodgep2;
  47. }
  48. PIANO =
  49. { 0 };
  50.  
  51. static BYTE SCROLLbuff[34];
  52. static WORD SCROLLpos;
  53. static BYTE PIXELbuff[264 * 8];
  54. static WORD PIXELoff;
  55.  
  56. void
  57. Titles (void)
  58. {
  59.   switch (TITLEm) {
  60.   case 0:
  61.     TitleSetup ();
  62.     break;
  63.   case 1:
  64.     DoPiano ();
  65.     break;
  66.   case 2:
  67.     ClearPiano ();
  68.     break;
  69.   case 3:
  70.     DoTitleScroll ();
  71.     break;
  72.   case 4:
  73.     DoPrefs ();
  74.     break;
  75.   }
  76. }
  77.  
  78. /* ////////////////////////////////////////////////////////////
  79. //    Setup Tiltes
  80. //////////////////////////////////////////////////////////// */
  81. static void
  82. TitleSetup (void)
  83. {
  84.   memcpy (PALover, PALmain, sizeof (PALover));
  85.  
  86.   TITLEwf = 2;
  87.   TITLEwp = 0;
  88.   SCROLLpos = 0;
  89.   PIXELoff = 0;
  90.  
  91.   UpdateScrollBuffer ();
  92.   FillPixelBuff ();
  93.  
  94.   TITLEm = 1;
  95.   PREFS.c = 128;
  96.   PREFS.p = 0;
  97.  
  98.   mm_snd_playmod (0x0d);
  99.   mm_snd_unmute ();
  100.  
  101.   TitleSetupExtra ();
  102.   mm_gfx_palset (PALblack);
  103.   mm_gfx_flush ();
  104.   mm_gfx_palset (PALmain);
  105. }
  106.  
  107. /* ////////////////////////////////////////////////////////////
  108. //    Setup Extra Bits
  109. //////////////////////////////////////////////////////////// */
  110. static void
  111. TitleSetupExtra (void)
  112. {
  113.   int l;
  114.  
  115.   mm_gfx_cls (240);
  116.  
  117.   PAPER = 0;
  118.   mm_gfx_fillbox (0, 0, 256, 192, PAPER);
  119.   DrawFinal ();
  120.   PlotXY (152, 40, GFXfill, 16, 24);
  121.   PlotXY (176, 40, GFXfill + 384, 72, 24);
  122.  
  123.   SUN.m = 1;
  124.   SUN.y = 32;
  125.   SUN.h = 16;
  126.   DoSun ();
  127.  
  128.   PlotXY (0, 64, GFXpiano, 256, 64);
  129.   DrawWilly4 (TITLEwf);
  130.  
  131.   DrawTPlate2 ();
  132.   DrawAirBG ();
  133.  
  134.   INK = 122;
  135.   l = strlen (LEVELSNAME);
  136.   FontPrintSmall (27, 28, "Level set:");
  137.   FontPrint (16 - strlen (LEVELSNAME) / 2 + 127 * (l & 1), 22, LEVELSNAME);
  138.  
  139.   PIANO.c = 0;
  140.   PIANO.khit = 0;
  141.   UpdatePianoKeys (0);
  142. }
  143.  
  144. /* ////////////////////////////////////////////////////////////
  145. //    Play The Piano
  146. //////////////////////////////////////////////////////////// */
  147. static void
  148. DoPiano (void)
  149. {
  150.   if (mm_snd_getmodpos () == 0x11 ) {
  151.     TITLEm = 2;
  152.     mm_snd_stopmod ();
  153.   }
  154.  
  155.   UpdatePianoKeys (1);
  156.   mm_gfx_flush ();
  157.  
  158.   if (mm_keyb_pressed (KEYB_F1)) {
  159.     TITLEm = 4;
  160.     PREFS.m = 0;
  161.     mm_snd_stopmod ();
  162.   }
  163.   if (mm_keyb_pressed (KEYB_ENTER)) {
  164.     TITLEm = 0;
  165.     DEMOm = 0;
  166.     MODE = 2;
  167.     mm_snd_stopmod ();
  168.   }
  169.   DoTPlate ();
  170. }
  171.  
  172. /* ////////////////////////////////////////////////////////////
  173. //    Draw Piano Key
  174. //////////////////////////////////////////////////////////// */
  175. static void
  176. DrawKey (int xpos, int ypos, BYTE block)
  177. {
  178.   PlotXY (xpos * 8, ypos * 8, GFXpkeys + block * 128, 8, 16);
  179. }
  180.  
  181. /* ////////////////////////////////////////////////////////////
  182. //    Update Piano Keys
  183. //////////////////////////////////////////////////////////// */
  184. static void
  185. UpdatePianoKeys (int play)
  186. {
  187.   static const BYTE keytype[] = {
  188.     0, 1, 2,
  189.     0, 1, 2, 0, 1, 1, 2,
  190.     0, 1, 2, 0, 1, 1, 2,
  191.     0, 1, 2, 0, 1, 1, 2,
  192.     0, 1, 2, 0, 1, 1, 2,
  193.     3
  194.   };
  195.   int i;
  196.   unsigned long newkhit = play ? mm_snd_hitpianokeys () : 0;
  197.  
  198.   for (i = 31; i >= 0; --i)
  199.     if ((newkhit ^ PIANO.khit) & 1 << i)
  200.       DrawKey (i, 14, keytype[i] + ((newkhit & 1 << i) ? 4 : 0));
  201.   PIANO.khit = newkhit;
  202. }
  203.  
  204. /* ////////////////////////////////////////////////////////////
  205. //    Clear Piano
  206. //////////////////////////////////////////////////////////// */
  207. static void
  208. ClearPiano (void)
  209. {
  210.   PIANO.khit = 0;
  211.  
  212.   UpdatePianoKeys (0);
  213.   mm_gfx_flush ();
  214.  
  215.   TITLEm = 3;
  216.   SCROLLpos = 0;
  217. }
  218.  
  219. /* ////////////////////////////////////////////////////////////
  220. //    Do Title Scroll
  221. //////////////////////////////////////////////////////////// */
  222. static void
  223. DoTitleScroll (void)
  224. {
  225.   mm_gfx_flush ();
  226.  
  227.   if (++TITLEwp == 16) {
  228.     TITLEwp = 0;
  229.     TITLEwf = (TITLEwf + 2) & 7;
  230.   }
  231.   DrawWilly4 (TITLEwf + 4);
  232.   DrawScroll ();
  233.  
  234.   if (++PIXELoff == 8) {
  235.     PIXELoff = 0;
  236.     if (++SCROLLpos == strlen (SCROLLtext) - 32) {
  237.       TITLEm = 0;
  238.       DEMOm = 0;
  239.       MODE = 1;
  240.  
  241.       mm_snd_playmod (MUSICtype ? 9 : 0);
  242.     }
  243.     else {
  244.       UpdateScrollBuffer ();
  245.       FillPixelBuff ();
  246.     }
  247.   }
  248.  
  249.   if (mm_keyb_pressed (KEYB_F1)) {
  250.     TITLEm = 4;
  251.     PREFS.m = 0;
  252.   }
  253.   if (mm_keyb_pressed (KEYB_ENTER)) {
  254.     TITLEm = 0;
  255.     DEMOm = 0;
  256.     MODE = 2;
  257.   }
  258.  
  259.   DoTPlate ();
  260. }
  261.  
  262. /* ////////////////////////////////////////////////////////////
  263. //    Update Scroll Buffer
  264. //////////////////////////////////////////////////////////// */
  265. static void
  266. UpdateScrollBuffer (void)
  267. {
  268.   memcpy (SCROLLbuff, SCROLLtext + SCROLLpos, 33);
  269. }
  270.  
  271. /* ////////////////////////////////////////////////////////////
  272. //    Fill Pixel buffer with text
  273. //////////////////////////////////////////////////////////// */
  274. static void
  275. FillPixelBuff (void)
  276. {
  277.   int i, x, y, dx = 0, dy = 0;
  278.  
  279.   for (i = 0; i < 33; i++) {
  280.     WORD alpha = (WORD) SCROLLbuff[i] - 32;
  281.     BYTE *font = fontb + alpha * 8;
  282.     BYTE *alias = GFXfant + alpha * 8;
  283.  
  284.     for (y = 0; y < 8; y++) {
  285.       for (x = 0; x < 8; x++)
  286.     PIXELbuff[((dy + y) * 264) + dx + x] = (*font & 1 << x) ? 102 :
  287.                            (*alias & 1 << x) ? 107 :
  288.                            PAPER;
  289.       font++;
  290.       alias++;
  291.     }
  292.     dx += 8;
  293.   }
  294. }
  295.  
  296. /* ////////////////////////////////////////////////////////////
  297. //    Draw Scroll
  298. //////////////////////////////////////////////////////////// */
  299. static void
  300. DrawScroll (void)
  301. {
  302.   int y;
  303.   for (y = 0; y < 8; y++)
  304.     PlotXY (0, 152 + y, PIXELbuff + y * 264 + PIXELoff, 256, 1);
  305. }
  306.  
  307. /* ////////////////////////////////////////////////////////////
  308. //    Draw Level Title Plate
  309. //////////////////////////////////////////////////////////// */
  310. static void
  311. DrawTPlate2 (void)
  312. {
  313.   static const char *const o[] = {
  314.     "\x7F" "1997 Andy Noble",
  315.     "\x7F" "1998, 2000 Darren Salt",
  316.     "\x7F" "2000 Stuart Brady"
  317.   };
  318.   int l = strlen (o[PREFS.p]);
  319.   PlotXY (0, 128, GFXtplate, 256, 8);
  320.   FontPrint2 (16 - l / 2 + 127 * (l & 1), 16, o[PREFS.p]);
  321. }
  322.  
  323. static void
  324. DoTPlate (void)
  325. {
  326.   if (--PREFS.c)
  327.     return;
  328.   PREFS.c = 128;
  329.   PREFS.p = (PREFS.p + 1) % 3;
  330.   DrawTPlate2 ();
  331. }
  332.  
  333. /* ////////////////////////////////////////////////////////////
  334. //    Draw Willy
  335. //////////////////////////////////////////////////////////// */
  336. static void
  337. DrawWilly4 (BYTE block)
  338. {
  339.   Plot16ink (232, 72, GFXwilly + 256 * block, 0, 39);
  340. }
  341.  
  342. /* ////////////////////////////////////////////////////////////
  343. //    Preferences Screen
  344. //////////////////////////////////////////////////////////// */
  345. static void
  346. DoPrefs (void)
  347. {
  348.   switch (PREFS.m) {
  349.   case 0:
  350.     SetupPrefs ();
  351.     break;
  352.   case 1:
  353.     PrefsUpdate ();
  354.     break;
  355.   }
  356. }
  357.  
  358. /* ////////////////////////////////////////////////////////////
  359. //    Setup Prefs
  360. //////////////////////////////////////////////////////////// */
  361. static void
  362. SetupPrefs (void)
  363. {
  364.   memcpy (PALover, PALmain, sizeof (PALover));
  365.  
  366.   DoPrefsExtra ();
  367.   mm_gfx_flush ();
  368.   mm_gfx_palset (PALover);
  369.  
  370.   PREFS.h[0] = PREFS.h[1] = PREFS.h[2] = 0;
  371.   PREFS.m = 1;
  372.   PREFS.c = 100;
  373.   PREFS.p = 0;
  374.  
  375.   mm_snd_playmod (0x12);
  376. }
  377.  
  378. /* ////////////////////////////////////////////////////////////
  379. //    Prefs Screen Setup
  380. //////////////////////////////////////////////////////////// */
  381. static void
  382. DoPrefsExtra (void)
  383. {
  384.   int x, y, i;
  385.  
  386.   i = 240;
  387.  
  388.   mm_gfx_cls (0);
  389.  
  390.   for (x = 0; x < 31; x++) {
  391.     PAPER = i++;
  392.     if (i > 254)
  393.       i = 240;
  394.     FontPrint (x, 0, " ");
  395.   }
  396.  
  397.   for (y = 0; y < 23; y++) {
  398.     PAPER = i++;
  399.     if (i > 254)
  400.       i = 240;
  401.     FontPrint (31, y, " ");
  402.   }
  403.  
  404.   for (x = 31; x; x--) {
  405.     PAPER = i++;
  406.     if (i > 254)
  407.       i = 240;
  408.     FontPrint (x, 23, " ");
  409.   }
  410.  
  411.   for (y = 23; y; y--) {
  412.     PAPER = i++;
  413.     if (i > 254)
  414.       i = 240;
  415.     FontPrint (0, y, " ");
  416.   }
  417.  
  418.   PAPER = 0;
  419.   INK = 7;
  420.   FontPrintSmall (24, 2, "`fManic Miner PC");
  421.   FontPrintSmall (23, 3, "`g(C)`e1997 `gAndy Noble");
  422.   FontPrintSmall (10, 4, "`gBased on an original game by `eMatthew Smith`g.");
  423.   FontPrintSmall ( 7, 5, "`g(C) `e1983 `fBUG-BYTE`g Ltd. And `fSoftware Projects`g Ltd.");
  424.  
  425.   DoPrefsPage ();
  426.  
  427. #ifdef __riscos
  428.   FontPrintSmall (PREFx, 27, "`f    F2           F3         F4        F5");
  429.   FontPrintSmall (PREFx, 28, "`bGame Speed  Pause music?  Melody  Resolution");
  430. #else
  431.   FontPrintSmall (PREFx, 27, "`f    F2           F3         F4");
  432.   FontPrintSmall (PREFx, 28, "`bGame Speed  Pause music?  Melody");
  433. #endif
  434.  
  435.   PrintPrefs ();
  436. }
  437.  
  438. typedef struct
  439. {
  440.   coords_t pos;
  441.   const char *text;
  442. }
  443. text_t;
  444.  
  445. static void
  446. DoPrefsPage (void)
  447. {
  448.   static const text_t One[] = {
  449.     {{18,  6}, "`g(C) `e1997 `fAlchemist Research`g."},
  450.     {{ 7,  8}, "`dProgramming`g, `dGraphics`e................`fAndy Noble`e."},
  451.     {{ 7,  9}, "`dMUSIC ARRANGED BY`e.................`fMatt Simmonds`e."},
  452.     {{ 7, 10}, "`dExtra Levels`e.................`fLee `d'`gBLOOD!`d' `fTonks`e."},
  453.     {{ 7, 11}, "`dTesting and Ideas`e.................`fEwan Christie`e."},
  454.     {{ 3, 13}, "`dI would just like to say ThankYou to the following people"},
  455.     {{ 3, 15}, "`fSahara Surfers`d..............`eFor MIDAS Digital Audio System"},
  456.     {{ 3, 17}, "`fTyrone L. Cartwright`d............`eFor help with the bad guys"},
  457.     {{ 3, 19}, "`fDavid H. Tolley`d.................`eFor the constant slaggings"},
  458.     {{ 3, 20}, "`fGerton Lunter`d........................`eFor the excellent Z80"},
  459.     {{ 3, 21}, "`fJames McKay`d.................`eFor the equally excellent X128"},
  460.     {{ 5, 22}, "`cEverybody who e-mailed me with words of encouragement."},
  461.     {{13, 24}, "`fAnd all the Guys on COMP.SYS.SINCLAIR"},
  462.     {{ 4, 25}, "`eWho keep me informed and amused about all things Speccy."},
  463.     {{0}}
  464.   };
  465.  
  466.   static const text_t Two[] = {
  467.     {{18,  6}, "`g(C) `e1998, 2000 `fDarren Salt`g."},
  468.     {{21,  7}, "`g(C) `e2000 `fStuart Brady`g."},
  469.     {{ 7,  9}, "`dLinux port`e...........................`fStuart Brady`e."},
  470.     {{ 7, 10}, "`dAdditional programming`c and"},
  471.     {{ 7, 11}, "`dRISC OS port`e..........................`fDarren Salt`e."},
  472.     {{ 7, 13}, "`dRISC OS 16-bit sound support`e....`fAndre' Timmermans`e."},
  473.     {{ 7, 15}, "`dTesting, testing, testing`e..........`fRichard Hallas`e."},
  474.     {{ 5, 17}, "`dWe'd just like to say ThankYou to the following people"},
  475.     {{ 4, 19}, "`fAll who have contributed to`d......................`eAllegro"},
  476.     {{ 4, 20}, "`cand`d..`eany other libraries which may be used in this build"},
  477.     {{19, 22}, "`ghttp://www.retrospec.co.uk/"},
  478.     {{11, 24}, "`fYou haven't played the original version...?"},
  479.     {{ 8, 25}, "`eThen visit `ghttp://www.void.jump.org/`e immediately!"},
  480.     {{0}}
  481.   };
  482.  
  483.   static const text_t *const Page[] = { One, Two };
  484.   int i = 0;
  485.  
  486.   PAPER = 0;
  487.   INK = 7;
  488.   PlotXYback (8, 36, 0, 240, 120);
  489.  
  490.   do {
  491.     FontPrintSmall (Page[PREFS.p][i].pos.x, Page[PREFS.p][i].pos.y,
  492.             Page[PREFS.p][i].text);
  493.   } while (Page[PREFS.p][++i].text);
  494. }
  495.  
  496. /* ////////////////////////////////////////////////////////////
  497. //    Update setup screen
  498. //////////////////////////////////////////////////////////// */
  499. static void
  500. PrefsUpdate (void)
  501. {
  502.   RotPal ();
  503.   mm_gfx_flush ();
  504.   mm_gfx_palset (PALover);
  505.  
  506.   if (!--PREFS.c) {
  507.     PREFS.p = (PREFS.p + 1) % 2;
  508.     DoPrefsPage ();
  509.   }
  510.  
  511.   if (mm_keyb_pressed (KEYB_F2)) {
  512.     if (!PREFS.h[0]) {
  513.       SPEED = (SPEED + 1) % 5;
  514.       PREFS.h[0] = 1;
  515.     }
  516.   } else
  517.     PREFS.h[0] = 0;
  518.  
  519.   if (mm_keyb_pressed (KEYB_F3)) {
  520.     if (!PREFS.h[1]) {
  521.       PAUSEtype=!PAUSEtype;
  522.       PREFS.h[1] = 1;
  523.     }
  524.   } else
  525.     PREFS.h[1] = 0;
  526.  
  527.   if (mm_keyb_pressed (KEYB_F4)) {
  528.     if (!PREFS.h[2]) {
  529.       MUSICtype ^= 1;
  530.       PREFS.h[2] = 1;
  531.     }
  532.   } else
  533.     PREFS.h[2] = 0;
  534.  
  535. #ifdef __riscos
  536.  if (mm_keyb_pressed (KEYB_F5)) {
  537.     if (!PREFS.h[3]) {
  538.       VidMode = !VidMode;
  539.       PREFS.h[3] = 1;
  540.       if (hires_ok) {
  541.     SelMode (VidMode);
  542.     mm_gfx_palset (PALover);
  543.     DoPrefsExtra();
  544.       }
  545.     }
  546.   } else
  547.     PREFS.h[3]=0;
  548. #endif
  549.  
  550.   if (mm_keyb_pressed (KEYB_ESC)) {
  551.     MODE = 0;
  552.     TITLEm = 0;
  553.     mm_snd_stopmod ();
  554.   }
  555.  
  556.   PrintPrefs ();
  557. }
  558.  
  559. /* ////////////////////////////////////////////////////////////
  560. //    Display preferences
  561. //////////////////////////////////////////////////////////// */
  562. static void
  563. PrintPrefs (void)
  564. {
  565.   static const char speed[][12] =
  566.   {"`a SILLY! ", "`c  HARD  ", "`d  1997  ", "`gORIGINAL", "`e BORING "};
  567.  
  568.   FontPrintSmall (PREFx + 1, 29, speed[SPEED]);
  569.   FontPrintSmall (PREFx + 16, 29, PAUSEtype ? "`gYES" : "`e NO");
  570.   FontPrintSmall (PREFx + 25, 29, MUSICtype ? "`gORIGINAL" : "`d  1997  ");
  571. #ifdef __riscos
  572.   FontPrintSmall (PREFx + 34, 29,
  573.           VidMode ? (hires_ok ? "`d  HI RES  " : "`cHI RES N/A") :
  574.           "`g  LO RES  ");
  575. #endif
  576. }
  577.