// -----------------------------------------------------------
// slide3.c - OUR SECOND GAME: IS COMING
//   raster bars on the border that also bleed into the empty
//   top and bottom of the screen; the middle stays black, so
//   the drop-shadowed big letters remain readable
// -----------------------------------------------------------
#include "defs.h"
#include "common.h"
#include "slides.h"

// ---- data ----
static const char rastbl[64] = {     // raster bar colors (cyclic):
                                     //   red, green, blue, grey ramps
	0x00, 0x00, 0x02, 0x02, 0x08, 0x08, 0x0a, 0x01,
	0x0a, 0x08, 0x08, 0x02, 0x02, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x05, 0x05, 0x0d, 0x0d, 0x07, 0x01,
	0x07, 0x0d, 0x0d, 0x05, 0x05, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x06, 0x06, 0x0e, 0x0e, 0x03, 0x01,
	0x03, 0x0e, 0x0e, 0x06, 0x06, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x0b, 0x0b, 0x0c, 0x0c, 0x0f, 0x01,
	0x0f, 0x0c, 0x0c, 0x0b, 0x0b, 0x00, 0x00, 0x00
};

// ---- variables ----
static char s3phase;                 // raster bar scroll offset

void s3_init(void)
{
	clear_screen();
	print_text( 4, 12, VCOL_WHITE,     "our second game");
	draw_big(    8,  3, VCOL_DARK_GREY, "is coming");   // drop shadow first (+1 row, +1 col)
	draw_big(    7,  2, VCOL_YELLOW,    "is coming");   // then the letters on top of it
	print_text(15,  4, VCOL_WHITE,     "a new point and click adventure");
	print_text(18,  7, VCOL_LT_GREY,   "will be available on steam");
	s3phase = 0;
}

void s3_update(void)
{
	framectr++;
	if (!(framectr & 1))             // bars scroll one step every 2nd frame
		s3phase++;

	// chase the beam: every 4th raster line from RAS_BARTOP down,
	// set the BORDER color from the cyclic 64-entry bar table;
	// above line 74 and from line 210 the screen rows are empty,
	// there the bars run on the background too - in the middle
	// the background stays black so the text remains readable
	char line = RAS_BARTOP;
	for (char x = 0; x < BAR_STEPS; x++)
	{
		char c = rastbl[(x + s3phase) & 63];
		bool mid = line >= 74 && line < 210;
		while (vic.raster != line)
			;
		if (mid)
		{
			vic.color_border = c;        // middle: border only, background back to
			vic.color_back = VCOL_BLACK; //   black (the top zone left its last color)
		}
		else
		{
			vic.color_back = c;          // top/bottom zone: bar color on the
			vic.color_border = c;        //   background too
		}
		line += 4;
	}

	vic.color_border = VCOL_BLACK;   // below the bar area: back to black
	vic.color_back = VCOL_BLACK;

	while (vic.raster != RAS_BOTTOM) // keep the one-call-per-frame contract
		;
}
