Port of cosmo-engine to TempleOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.2 KiB

CBGR48 orig_palette;
//GrPaletteGet(&orig_palette);
I64 next_pal_colour = 0;
U8 palette_anim_type = 0;
I64 palette_index = 0;
I64 palette_2E1EE = 0;
U8 ega_palette[64][3]=
{
{0x00,0x00,0x00}, {0x00,0x00,0xaa}, {0x00,0xaa,0x00}, {0x00,0xaa,0xaa}, {0xaa,0x00,0x00}, {0xaa,0x00,0xaa}, {0xaa,0x55,0x00}, {0xaa,0xaa,0xaa},
{0x00,0x00,0x00}, {0x00,0x00,0xaa}, {0x00,0xaa,0x00}, {0x00,0xaa,0xaa}, {0xaa,0x00,0x00}, {0xaa,0x00,0xaa}, {0xaa,0x55,0x00}, {0xaa,0xaa,0xaa},
{0x55,0x55,0x55}, {0x55,0x55,0xff}, {0x55,0xff,0x55}, {0x55,0xff,0xff}, {0xff,0x55,0x55}, {0xff,0x55,0xff}, {0xff,0xff,0x55}, {0xff,0xff,0xff},
{0x55,0x55,0x55}, {0x55,0x55,0xff}, {0x55,0xff,0x55}, {0x55,0xff,0xff}, {0xff,0x55,0x55}, {0xff,0x55,0xff}, {0xff,0xff,0x55}, {0xff,0xff,0xff},
{0x00,0x00,0x00}, {0x00,0x00,0xaa}, {0x00,0xaa,0x00}, {0x00,0xaa,0xaa}, {0xaa,0x00,0x00}, {0xaa,0x00,0xaa}, {0xaa,0x55,0x00}, {0xaa,0xaa,0xaa},
{0x00,0x00,0x00}, {0x00,0x00,0xaa}, {0x00,0xaa,0x00}, {0x00,0xaa,0xaa}, {0xaa,0x00,0x00}, {0xaa,0x00,0xaa}, {0xaa,0x55,0x00}, {0xaa,0xaa,0xaa},
{0x55,0x55,0x55}, {0x55,0x55,0xff}, {0x55,0xff,0x55}, {0x55,0xff,0xff}, {0xff,0x55,0x55}, {0xff,0x55,0xff}, {0xff,0xff,0x55}, {0xff,0xff,0xff},
{0x55,0x55,0x55}, {0x55,0x55,0xff}, {0x55,0xff,0x55}, {0x55,0xff,0xff}, {0xff,0x55,0x55}, {0xff,0x55,0xff}, {0xff,0xff,0x55}, {0xff,0xff,0xff}
};
U8 palette_anim_type_1_tbl[52] =
{
0x04, 0x04, 0x0C, 0x0C, 0x0E, 0x0E, 0x0F, 0x0F, 0x0E, 0x0E,
0x0C, 0x0C, 0xFF, 0x00, 0x00, 0x04, 0x04, 0x0C, 0x04, 0x04,
0x00, 0x00, 0x02, 0x02, 0x0A, 0x02, 0x02, 0x00, 0x00, 0x01,
0x01, 0x09, 0x01, 0x01, 0xFF, 0x00, 0x00, 0x08, 0x07, 0x0F,
0x07, 0x08, 0xFF, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x04,
0x0D, 0xFF
};
U8 palette_anim_type_2_tbl[22] =
{
0x00, 0x00, 0x04, 0x04, 0x0C, 0x04, 0x04, 0x00, 0x00, 0x02,
0x02, 0x0A, 0x02, 0x02, 0x00, 0x00, 0x01, 0x01, 0x09, 0x01,
0x01, 0xFF
};
U8 palette_anim_type_3_tbl[8] =
{
0x00, 0x00, 0x08, 0x07, 0x0F, 0x07, 0x08, 0xFF
};
U8 palette_anim_type_4_tbl[9] =
{
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x04, 0x0D, 0xFF
};
CBGR48 get_ega_color(U8 ega)
{
CBGR48 c;
// c.r = 85 * (((ega >> 1) & 2) + ((ega >> 5) & 1));
// c.g = 85 * (( ega & 2) + ((ega >> 4) & 1));
// c.b = 85 * (((ega << 1) & 2) + ((ega >> 3) & 1));
c.b.u8[0] = ega_palette[ega][2];
c.b.u8[1] = ega_palette[ega][2];
c.g.u8[0] = ega_palette[ega][1];
c.g.u8[1] = ega_palette[ega][1];
c.r.u8[0] = ega_palette[ega][0];
c.r.u8[1] = ega_palette[ega][0];
return c;
}
U0 set_palette_color(I64 pal_reg, I64 ega)
{
GrPaletteColorSet(pal_reg, get_ega_color(ega));
}
U0 palette_cycle_reg_5_from_tbl(U8 *palette_cycle_tbl_ptr)
{
palette_index++;
//FIXME need to hook up palette_2E1EE into this logic.
if (palette_cycle_tbl_ptr[palette_index] == 0xff)
{
palette_index = 0;
}
if (palette_cycle_tbl_ptr[palette_index] >= 8)
{
set_palette_color(5, (palette_cycle_tbl_ptr[palette_index] + 8));
}
else
{
set_palette_color(5, palette_cycle_tbl_ptr[palette_index]);
}
return;
}
U0 update_palette_anim()
{
switch (palette_anim_type - 1)
{
case 0:
if (next_pal_colour == 2)
{
next_pal_colour = 0;
set_palette_color(5, 0x10);
return;
}
if (next_pal_colour == 1)
{
next_pal_colour = 2;
set_palette_color(5, 7);
return;
}
if (cosmo_rand() >= 0x5dc)
{
set_palette_color(5, 0);
next_pal_colour = 0;
}
else
{
set_palette_color(5, 0x17);
play_sfx(0x3c);
next_pal_colour = 1;
}
break;
case 1:
palette_cycle_reg_5_from_tbl(palette_anim_type_1_tbl);
break;
case 2:
palette_cycle_reg_5_from_tbl(palette_anim_type_2_tbl);
break;
case 3:
palette_cycle_reg_5_from_tbl(palette_anim_type_3_tbl);
break;
case 4:
palette_cycle_reg_5_from_tbl(palette_anim_type_4_tbl);
break;
}
return;
}