Skip to content

Commit

Permalink
Rework palette code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Feliks committed Nov 4, 2023
1 parent 1f13efb commit 5aff719
Showing 1 changed file with 72 additions and 75 deletions.
147 changes: 72 additions & 75 deletions gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "globals.h"

unsigned char paleta_r[256], paleta_g[256], paleta_b[256];
unsigned char palette[768];


void tryb_graf()
Expand Down Expand Up @@ -40,12 +40,36 @@ void czysc_bufor()

void retrace()
{
while (!(inp(0x03da) & 8))
while (!(inportb(0x03da) & 8))
;
while ((inp(0x03da) & 8))
while ((inportb(0x03da) & 8))
;
}

void set_palette(unsigned char* my_pal)
{
int i;

outportb(0x03c8, 0);

for (i = 0; i < 768; i++) {
outportb(0x03c9, my_pal[i]);
}
}

void dump_palette(unsigned char* my_pal)
{
int i;

outportb(0x03c7, 0);

for (i = 0; i < 768; i++) {
my_pal[i] = inportb(0x03c9);
}
}

// end of low-level code

void pasek(int x, int y, unsigned char kolor)
{
int i;
Expand Down Expand Up @@ -80,110 +104,83 @@ void draw_sprite(unsigned char* sprite, int x, int y, int width, int height, uns
}
}

void paleta_inicjuj(void)
void save_pal(void)
{
int i;

outportb(0x03c8, 100);

for (i = 0; i < 64; i++) {
outportb(0x03c9, 0);
outportb(0x03c9, 0);
outportb(0x03c9, i);
}
for (i = 0; i < 64; i++) {
outportb(0x03c9, i);
outportb(0x03c9, 0);
outportb(0x03c9, 0);
}
dump_palette(palette);
}


void save_pal(void)
void renew_pal(void)
{
int i;

outp(0x03c7, 0);

for (i = 0; i < 256; i++) {
paleta_r[i] = inp(0x03c9);
paleta_g[i] = inp(0x03c9);
paleta_b[i] = inp(0x03c9);
}
set_palette(palette);
}

void renew_pal(void)
void paleta_inicjuj(void)
{
int i;
unsigned char my_pal[768], *ptr;

outp(0x03c8, 0);
dump_palette(my_pal);
ptr = my_pal + 100 * 3;

for (i = 0; i < 256; i++) {
outp(0x03c9, paleta_r[i]);
outp(0x03c9, paleta_g[i]);
outp(0x03c9, paleta_b[i]);
for (i = 0; i < 64; i++) {
*(ptr++) = 0;
*(ptr++) = 0;
*(ptr++) = i;
}
for (i = 0; i < 64; i++) {
*(ptr++) = i;
*(ptr++) = 0;
*(ptr++) = 0;
}

set_palette(my_pal);
}

void flash(void)
{
int i, j;
unsigned char r, g, b;
unsigned char my_pal[768], dest_pal[768], *srcp, *destp;

outp(0x03c8, 0);
for (i = 0; i < 768; i++) {
outp(0x03c9, 63);
}
dump_palette(dest_pal);

memset(my_pal, 63, 768);
set_palette(my_pal);

for (i = 0; i < 64; i++) {
for (j = 0; j < 256; j++) {
outp(0x03c7, j);
r = inp(0x03c9);
g = inp(0x03c9);
b = inp(0x03c9);

if (r > paleta_r[j])
r--;
if (g > paleta_g[j])
g--;
if (b > paleta_b[j])
b--;

outp(0x03c8, j);
outp(0x03c9, r);
outp(0x03c9, g);
outp(0x03c9, b);
srcp = my_pal;
destp = dest_pal;

for (j = 0; j < 768; j++) {
if ((*srcp) > (*destp)) {
(*srcp)--;
}
srcp++;
destp++;
}

set_palette(my_pal);
retrace();
}
}

void fade_down(void)
{
int i, j;
unsigned char r, g, b;
unsigned char my_pal[768], *srcp;

dump_palette(my_pal);

for (j = 0; j < 64; j++) {
for (i = 0; i < 256; i++) {
outp(0x03c7, i);
r = inp(0x03c9);
g = inp(0x03c9);
b = inp(0x03c9);

if (r > 0)
r--;
if (g > 0)
g--;
if (b > 0)
b--;

outp(0x03c8, i);
outp(0x03c9, r);
outp(0x03c9, g);
outp(0x03c9, b);

srcp = my_pal;
for (j = 0; j < 768; j++) {
if ((*srcp) > 0) {
(*srcp)--;
}
srcp++;
}

set_palette(my_pal);
retrace();
}
}

0 comments on commit 5aff719

Please sign in to comment.