home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / demos / misc / gettintired.dms / in.adf / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-14  |  12.4 KB  |  528 lines

  1. /* Main program */
  2.  
  3. #include "includes.prl"
  4.  
  5. #include "ptreplay.h"
  6. #include "ptreplay_protos.h"
  7. #include "ptreplay_pragmas.h"
  8.  
  9. #include "common.h"
  10. #include "protos.h"
  11.  
  12. static void disp_fade_in(UWORD *fadeto);
  13. static void disp_fade_out(UWORD *fadeFrom);
  14. static void disp_fade_setpalette(void);
  15. void disp_clear(void);
  16. void disp_swap(void);
  17. void disp_whack(PLANEPTR data, UWORD width, UWORD height, UWORD x, UWORD y, UWORD depth);
  18. void dots_doit(UWORD *pal);
  19. void writer_doit(UBYTE *wrText);
  20. void scroll_doit(void);
  21. PLANEPTR load_getmem(UBYTE *name, ULONG size);
  22. void mandel(PLANEPTR scrMem);
  23. #pragma regcall(mandel(a0))
  24.  
  25. extern struct BitMap theBitMap;
  26. extern struct BitMap theBitMap_3bpl;
  27. extern struct BitMap theBitMap_2bpl;
  28. extern struct BitMap theBitMap_1bpl;
  29. extern struct RastPort theRP;
  30. extern struct RastPort theRP_3bpl;
  31. extern struct RastPort theRP_2bpl;
  32. extern struct RastPort theRP_1bpl;
  33.  
  34. extern struct Custom custom;
  35. extern struct CIA ciaa, ciab;
  36. extern PLANEPTR theRaster, theRaster2;
  37. extern struct Screen *mainScreen;
  38. extern struct DosLibrary *DOSBase;
  39. extern struct GfxBase *GfxBase;
  40. extern struct Library *PTReplayBase;
  41. extern struct ViewPort *mainVP;
  42.  
  43. struct Module *theMod;
  44.  
  45. BOOL swapFlag = FALSE;
  46.  
  47. UWORD incr[16][3];
  48. UWORD col[16][3];
  49.  
  50. UWORD pal1[] =
  51. { 0x000, 0xFFF, 0x15b, 0x000, 0x000, 0x000, 0x000, 0x000,
  52.   0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 };
  53.  
  54. UWORD pal2[] =
  55. { 0x111, 0x223, 0x335, 0x447, 0x559, 0x66b, 0x77d, 0x88f,
  56.   0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 };
  57.  
  58. UWORD pal3[] =
  59. { 0x111, 0x322, 0x533, 0x744, 0x955, 0xb66, 0xd77, 0xf88,
  60.   0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 };
  61.  
  62. UWORD pal4[] =
  63. { 0x111, 0x232, 0x353, 0x474, 0x595, 0x6b6, 0x7d7, 0x8f8,
  64.   0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 };
  65.  
  66. UWORD pal5[] =
  67. { 0x000, 0x0B2, 0x082, 0x061, 0x235, 0x246, 0x357, 0x468,
  68.   0x679, 0x78B, 0x9AC, 0x013, 0x014, 0x225, 0x300, 0x400 };
  69.  
  70. UWORD pal6[] =
  71. { 0x000, 0x111, 0x222, 0x333, 0x444, 0x555, 0x666, 0x777,
  72.   0x888, 0x999, 0xAAA, 0xBBB, 0xCCC, 0xDDD, 0xEEE, 0xFFF };
  73.  
  74. UWORD pal7[] =
  75. { 0x000, 0x00F, 0x00B, 0x007, 0x13F, 0x303, 0x404, 0x050,
  76.   0xFF0, 0x0DD, 0x0AF, 0x07C, 0x00F, 0x70F, 0xC0E, 0xC08 };
  77.  
  78. /***** Global functions *****/
  79.  
  80. /* Main program entry point */
  81. int main(void)
  82. {
  83.   struct Task *myTask;
  84.   BYTE oldPri;
  85.   PLANEPTR pic;
  86.   UBYTE *mod;
  87.  
  88.   srand((ciaa.ciatodmid << 8) | ciaa.ciatodlow);
  89.   /* Open all needed resources */
  90.   if (!init_open_all())
  91.   {
  92.     init_close_all();
  93.     return (10);
  94.   }
  95.  
  96.   myTask = FindTask(NULL);
  97.   oldPri = SetTaskPri(myTask, 127);
  98.   Forbid();
  99.  
  100.   mod = load_getmem((UBYTE *)"module.bin", 95430);
  101.   theMod = PTSetupMod((APTR)mod);
  102.   PTPlay(theMod);
  103.  
  104.   writer_doit((UBYTE *)"#####"
  105.               "      Barking Mad Hedgehogs##"
  106.               "             PRESENTS##");
  107.   disp_clear();
  108.  
  109.   pic = load_getmem((UBYTE *)"logo.bin", 40 * 4 * 256);
  110.   disp_whack(pic, 40, 256, 0, 0, 4);
  111.   disp_fade_in(pal7);
  112.   Delay(350);
  113.   disp_fade_out(pal7);
  114.   disp_clear();
  115.   FreeMem(pic, 40 * 4 * 256);
  116.  
  117.   // writer_doit((UBYTE *)"#####     GETTIN' TIRED OF...?#");
  118.   // disp_clear();
  119.  
  120.   writer_doit((UBYTE *)"#####"
  121.               "  A multitasking/syncing töntro##"
  122.               "        Coded in pure C!!!#");
  123.  
  124.   disp_clear();
  125.   Delay(50);
  126.   dots_doit(pal2);
  127.   Delay(50);
  128.   disp_fade_out(pal2);
  129.   disp_clear();
  130.  
  131.   writer_doit((UBYTE *)"##"
  132.                "         Coding : Picnic##"
  133.                "    Muzak & gfx : Gunrider##"
  134.                " Font and texts : Indian of TriBal##"
  135.                "    Panther gfx : Peter Kürcman#");
  136.   disp_clear();
  137.  
  138.   Delay(50);
  139.   dots_doit(pal3);
  140.   Delay(50);
  141.   disp_fade_out(pal3);
  142.   disp_clear(); 
  143.  
  144.   writer_doit((UBYTE *)"#"
  145.               "       Calculating errors :#" 
  146.           "          Pentium 90 mHz##"
  147.               "   Moral support : A guy and his#" 
  148.               "      oven, the snubbe with a #"
  149.               "     liggunderlag and others..##"
  150.               "  Inteloutside logo supplied by :#"
  151.               "    A Danish guy with an A600..#");
  152.   disp_clear();
  153.  
  154.   Delay(50);
  155.   dots_doit(pal4);
  156.   Delay(50);
  157.   disp_fade_out(pal4);
  158.   disp_clear();
  159.  
  160.   /* LoadRGB4(mainVP, pal3, 16);
  161.   mandel(theRaster);
  162.   Delay(100);
  163.   disp_clear(); */
  164.   
  165.   disp_clear();
  166.   Delay(50);
  167.   scroll_doit();
  168.  
  169.   disp_clear();
  170.   Delay(50);
  171.   writer_doit((UBYTE *)"##"
  172.           "Q: According to Intel, the Pentium#"
  173.               "conforms to the IEEE standards 754#"
  174.               "and 854 for floating point#"
  175.               "arithmetic. If you fly in aircraft#"
  176.               "designed using a Pentium, what is#" 
  177.               "the correct pronunciation of#"
  178.               "'IEEE'?##"
  179.               "A: [Aaaaaaaiiiiiiiiieeeeeeeeeeeee]#");
  180.  
  181.   disp_clear();
  182.   Delay(50);
  183.  
  184.   pic = load_getmem((UBYTE *)"outside.bin", 34 * 210 * 4);
  185.   disp_whack(pic, 34, 210, 4, 18, 4);
  186.   disp_fade_in(pal6);
  187.   Delay(1000);
  188.   disp_fade_out(pal6);
  189.   disp_clear();
  190.   FreeMem(pic, 34 * 120 * 4);
  191.  
  192.   PTStop(theMod);
  193.   PTFreeMod(theMod);
  194.   FreeMem(mod, 95430);
  195.  
  196.   Permit();
  197.   SetTaskPri(myTask, oldPri);
  198.   
  199.   /* Close opened resources */
  200.   init_close_all();
  201.   return (0);
  202. }
  203.  
  204. /*********** FADER ***************/
  205.  
  206. /* Fade palette from all black to specified colors */
  207. static void disp_fade_in(UWORD *fadeto)
  208. {
  209.   SHORT i, p;
  210.   
  211.  
  212.   for (i = 0; i < 3; i ++)
  213.     for (p = 0; p < 16; p ++)
  214.       col[p][i] = 0;
  215.  
  216.   for (i = 0; i < 16; i ++)
  217.   {
  218.     incr[i][0] = ((fadeto[i] << 4) & 0xf000) / 15;
  219.     incr[i][1] = ((fadeto[i] << 8) & 0xf000) / 15;
  220.     incr[i][2] = ((fadeto[i] << 12) & 0xf000) / 15;
  221.   }
  222.  
  223.   disp_fade_setpalette();
  224.   for (i = 1; i < 16; i ++)
  225.   {
  226.     for (p = 0; p < 16; p ++)
  227.     {
  228.       col[p][0] += incr[p][0];
  229.       col[p][1] += incr[p][1];
  230.       col[p][2] += incr[p][2];
  231.     }
  232.     WaitTOF();
  233.     WaitTOF();
  234.     WaitTOF();
  235.     disp_fade_setpalette();
  236.   }
  237.   WaitTOF();
  238.   WaitTOF();
  239.   WaitTOF();
  240.   LoadRGB4(mainVP, fadeto, 16);
  241. }
  242.  
  243. /* Fade palette from colors to all black */
  244. static void disp_fade_out(UWORD *fadeFrom)
  245. {
  246.   UWORD i, p;
  247.  
  248.   for (i = 0; i < 16; i ++)
  249.   {
  250.     col[i][0] = (fadeFrom[i] & 0x0f00) << 4;
  251.     col[i][1] = (fadeFrom[i] & 0x00f0) << 8;
  252.     col[i][2] = (fadeFrom[i] & 0x000f) << 12;
  253.     incr[i][0] = col[i][0] / 15;
  254.     incr[i][1] = col[i][1] / 15;
  255.     incr[i][2] = col[i][2] / 15;
  256.   }
  257.  
  258.   for (i = 1; i < 16; i ++)
  259.   {
  260.     for (p = 0; p < 16; p ++)
  261.     {
  262.       col[p][0] -= incr[p][0];
  263.       col[p][1] -= incr[p][1];
  264.       col[p][2] -= incr[p][2];
  265.     }
  266.     WaitTOF();
  267.     WaitTOF();
  268.     WaitTOF();
  269.     disp_fade_setpalette();
  270.   }
  271.   WaitTOF();
  272.   WaitTOF();
  273.   WaitTOF();
  274.   for (i = 0; i < 16; i ++)
  275.     SetRGB4(mainVP, i, 0, 0, 0);
  276. }
  277.  
  278. /* Set palette registers to currents colors while fading */
  279. static void disp_fade_setpalette(void)
  280. {
  281.   UWORD i, temp, pal[16];
  282.  
  283.   for (i = 0; i < 16; i ++)
  284.   {
  285.     pal[i] = (col[i][0] & 0xf000) >> 4;
  286.     temp = (col[i][1] & 0xf000) >> 8;
  287.     pal[i] |= temp;
  288.     temp = (col[i][2] & 0xf000) >> 12;
  289.     pal[i] |= temp;
  290.   }
  291.   LoadRGB4(mainVP, pal, 16);
  292. }
  293.  
  294. /***************** DISPLAY SUPPORT ********************/
  295.  
  296. void disp_clear(void)
  297. {
  298.   SetRast(&theRP, 0);
  299. }
  300.  
  301. void disp_swap(void)
  302. {
  303.   UWORD i;
  304.   PLANEPTR temp;
  305.  
  306.   if (swapFlag)
  307.     temp = theRaster;
  308.   else
  309.     temp = theRaster;
  310.   swapFlag = !swapFlag;
  311.  
  312.   for(i = 0; i < 4; i ++)
  313.   {
  314.     mainVP->RasInfo->BitMap->Planes[i] = temp;
  315.     theBitMap.Planes[i] = temp;
  316.     theBitMap_3bpl.Planes[i] = temp;
  317.     theBitMap_2bpl.Planes[i] = temp;
  318.     theBitMap_1bpl.Planes[i] = temp;
  319.     temp += (48 * 256);
  320.   }
  321.   MakeVPort(GfxBase->ActiView, mainVP);
  322.   MrgCop(GfxBase->ActiView);
  323.   LoadView(GfxBase->ActiView);
  324. }
  325.  
  326. void disp_whack(PLANEPTR data, UWORD width, UWORD height, UWORD x, UWORD y, UWORD depth)
  327. {
  328.   PLANEPTR src, dest;
  329.   UWORD i, j, k;
  330.  
  331.   src = data;
  332.   for (k = 0; k < depth; k ++)
  333.   {
  334.     dest = theBitMap.Planes[k] + 48 * y + x;
  335.     for (i = 0; i < height; i ++)
  336.     {
  337.       for (j = 0; j < width; j ++)
  338.       {
  339.         *dest ++ = *src ++;
  340.       }
  341.       dest += (48 - width);
  342.     }
  343.   }
  344. }
  345.  
  346. /***************** SHADEDOTS ********************/
  347.  
  348. void dots_doit(UWORD *pal)
  349. {
  350.   WORD x[20], y[20];
  351.   WORD i, j, h, c;
  352.  
  353.   LoadRGB4(mainVP, pal, 16);
  354.   for (i = 0; i < 20; i ++)
  355.   {
  356.     x[i] = rand() % 320;
  357.     y[i] = rand() % 256;
  358.   }
  359.  
  360.   for (j = 0; j < 1500; j ++)
  361.   {
  362.     for (i = 0; i < 15; i ++)
  363.     {
  364.       h = rand() % 6;
  365.       switch (h)
  366.       {
  367.         case 0:
  368.           x[i] ++;
  369.           break;
  370.  
  371.         case 1:
  372.         case 4:
  373.           x[i] --;
  374.           break;
  375.  
  376.         case 2:
  377.         case 5:
  378.           y[i] ++;
  379.           break;
  380.  
  381.         case 3:
  382.           y[i] --;
  383.           break;
  384.       }
  385.       if (x[i] > 319) x[i] -= 320;
  386.       if (x[i] < 0) x[i] += 320;
  387.       if (y[i] > 255) y[i] -= 256;
  388.       if (y[i] < 0) y[i] += 256;
  389.  
  390.       c = ReadPixel(&theRP_3bpl, x[i], y[i]);
  391.       c += 1; /* ((rand() % 2) << 1) - 1; */
  392.       if (c > 7) c = 2;
  393.       SetAPen(&theRP_3bpl, c);
  394.       WritePixel(&theRP_3bpl, x[i], y[i]);
  395.     }
  396.   }
  397. }
  398.  
  399. /**************** WRITER *******************/
  400.  
  401. void writer_doit(UBYTE *wrText)
  402. {
  403.   UBYTE *currChar;
  404.   UWORD x = 0, y = 30;
  405.  
  406.   currChar = wrText;
  407.   SetDrMd(&theRP_2bpl, JAM1);
  408.   while(*currChar)
  409.   {
  410.     while(*currChar != '#')
  411.     {
  412.       SetAPen(&theRP_2bpl, 2);
  413.       Move(&theRP_2bpl, x + 2, y + 2);
  414.       Text(&theRP_2bpl, currChar, 1);
  415.       SetAPen(&theRP_2bpl, 1);
  416.       Move(&theRP_2bpl, x, y);
  417.       Text(&theRP_2bpl, currChar, 1);
  418.       x += TextLength(&theRP_2bpl, currChar, 1);
  419.       currChar ++;
  420.     }
  421.     currChar ++;
  422.     y += 17;
  423.     x = 0;
  424.   }
  425.   disp_fade_in(pal1);
  426.   Delay(400);
  427.   disp_fade_out(pal1);
  428. }
  429.  
  430. /**************** SCROLLTEXT *********************/
  431.  
  432. void scroll_doit(void)
  433. {
  434.   PLANEPTR font, pic;
  435.   UBYTE *currChar;
  436.   static struct BitMap fontMap;
  437.   static UWORD offs[] =
  438.   { 192, 192, 192, 192, 192, 192, 192, 192,
  439.     192, 192, 192, 192, 192, 192, 192, 192,
  440.     192, 192, 192, 192, 192, 192, 192, 192,
  441.     192, 192, 192, 192, 192, 192, 192, 192,
  442.     192, 192, 192, 192, 192, 192, 192, 192,
  443.     192, 192, 192, 192, 192, 192, 192, 192,
  444.     192, 192, 192, 192, 192, 192, 192, 192,
  445.     192, 192, 192, 192, 192, 192, 192, 192,
  446.     192, 192, 128, 192, 192, 192, 192, 192,
  447.     192, 192, 192, 192, 192, 192, 64, 192,
  448.     288, 144, 256, 192, 192, 192, 192, 192,
  449.     32, 192, 192, 192, 224, 96, 192, 192,
  450.     256, 96, 0, 144, 32, 144, 64, 144,
  451.     96, 144, 128, 144, 160, 144, 192, 144,
  452.     224, 144, 256, 144, 96, 192, 0, 192,
  453.     192, 192, 192, 192, 192, 192, 160, 192,
  454.     192, 192, 0, 0, 32, 0, 64, 0,
  455.     96, 0, 128, 0, 160, 0, 192, 0,
  456.     224, 0, 256, 0, 0, 48, 32, 48,
  457.     64, 48, 96, 48, 128, 48, 160, 48,
  458.     192, 48, 224, 48, 256, 48, 0, 96,
  459.     32, 96, 64, 96, 96, 96, 224, 192,
  460.     128, 96, 160, 96, 192, 96, 192, 192,
  461.     192, 192, 192, 192, 192, 192, 192, 192,
  462.     192, 192, 0, 0, 32, 0, 64, 0,
  463.     96, 0, 128, 0, 160, 0, 192, 0,
  464.     224, 0, 256, 0, 0, 48, 32, 48,
  465.     64, 48, 96, 48, 128, 48, 160, 48,
  466.     192, 48, 224, 48, 256, 48, 0, 96,
  467.     32, 96, 64, 96, 96, 96, 224, 192,
  468.     128, 96, 160, 96, 192, 96, 192, 192,
  469.     192, 192, 192, 192, 192, 192, 192, 192 };
  470.   static UBYTE scrText[] = "welcome to the little scrollthingy... "
  471.   "first the serious stuff :       "
  472.   "q: what's another name for the 'intel inside' sticker they put on pentiums?          "
  473.   "a: the warning label.         "
  474.   "now we'll greet some people:       tcc, chaos pm, lcg, exceed, inventors of coca cola, "
  475.   "the staff at this great party, kyrcman's microwave oven (and the man ;), " 
  476.   "motorola inc. (wod else ;) and the snubbe...   stay tuned for more pentium fun...                      ";
  477.  
  478.   font = load_getmem((UBYTE *)"scrollfont.bin", 80 * 256);
  479.   InitBitMap(&fontMap, 2, 320, 256);
  480.   fontMap.Planes[0] = font;
  481.   fontMap.Planes[1] = font + 40 * 256;
  482.   pic = load_getmem((UBYTE *)"panther.bin", 34 * 167 * 4);
  483.   disp_whack(pic, 34, 167, 4, 20, 4);
  484.   currChar = scrText;
  485.  
  486.   disp_fade_in(pal5);
  487.   Delay(100);
  488.   
  489.   while (*currChar)
  490.   {
  491.     BltBitMap(&fontMap, offs[(*currChar) << 1], offs[((*currChar) << 1) + 1],
  492.     &theBitMap_2bpl, 320, 208, 32, 48, 0xc0, 0xff, NULL);
  493.     currChar ++;
  494.  
  495.     WaitTOF();
  496.     ScrollRaster(&theRP_2bpl, 8, 0, 0, 208, 383, 255);
  497.     WaitTOF();
  498.     ScrollRaster(&theRP_2bpl, 8, 0, 0, 208, 383, 255);
  499.     WaitTOF();
  500.     ScrollRaster(&theRP_2bpl, 8, 0, 0, 208, 383, 255);
  501.     WaitTOF();
  502.     ScrollRaster(&theRP_2bpl, 8, 0, 0, 208, 383, 255);
  503.   }
  504.  
  505.   disp_fade_out(pal5);  
  506.   FreeMem(font, 80 * 256);
  507.   FreeMem(pic, 34 * 167 * 4);
  508. }
  509.  
  510. /*************** LOADER *********************/
  511.  
  512. PLANEPTR load_getmem(UBYTE *name, ULONG size)
  513. {
  514.   BPTR fileHandle;
  515.   PLANEPTR mem;
  516.  
  517.   if (!(fileHandle = Open(name, MODE_OLDFILE)))
  518.     return (NULL);
  519.  
  520.   if (!(mem = AllocMem(size, MEMF_CHIP)))
  521.     return (NULL);
  522.  
  523.   Read(fileHandle, mem, size);
  524.   Close(fileHandle);
  525.  
  526.   return (mem);
  527. }
  528.