Skip to content

Commit

Permalink
First merge of Nick Kovac's plzpart code
Browse files Browse the repository at this point in the history
This merges an adapted version of Nick Kovac's javascript plzpart code,
which went from assembly to C to javascript and back to C. This merge
is still untested and certainly contains errors.

TODO: render the plasma to a texture so we can use it in GL.

Signed-off-by: Claudio Matsuoka <[email protected]>
  • Loading branch information
cmatsuoka committed Jan 19, 2014
1 parent 385fd2b commit 0349c63
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 1,089 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ visu/c/u2a
visu/c/u2e
tags
*.mp4
*~
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include glenz/Makefile
include tunneli/Makefile
include techno/Makefile
include lens/Makefile
#include plzpart/Makefile
include plzpart/Makefile
include dots/Makefile
include water/Makefile

Expand Down
6 changes: 3 additions & 3 deletions plzpart/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PLZPART_OBJS = plz.o plza.o plzfill.o copper.o asmyt.o psini.o tweak.o \
vect.o main.o sinit.o spline.o
PLZPART_OBJS = plz.o plza.o plzfill.o copper.o asmyt.o tweak.o \
vect.o main.o sinit.o spline.o vga.o

PLZPART_PATH = plzpart

Expand All @@ -16,6 +16,6 @@ default-plzpart:
plzpart-all: $(PLZPART_PATH)/$(PLZPART_BIN)

$(PLZPART_PATH)/$(PLZPART_BIN): $(PLZPART_PATH_OBJS)
$(LD) -o $@ $(LDFLAGS) $(PLZPART_PATH_OBJS) $(LIBS) -lSOIL
$(LD) -o $@ $(LDFLAGS) $(PLZPART_PATH_OBJS) $(LIBS)

plz.c: tweak.h ptau.pre
92 changes: 88 additions & 4 deletions plzpart/asmyt.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,110 @@
#include "common.h"

static uint16_t selfmod[5 * 84];
extern char *psini;

#define PSINI_OFFSET 0
#define LSINI4_OFFSET 16384
#define LSINI16_OFFSET (16384 + 2 * 8192)


int plzline(int y, int vseg)
{
// vseg represented a segment, so multiply by sixteen (shift left by 4)
// to convert into an offset.
int nVgaYOffset = vseg << 4;

int cccTable[] = {
3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 19, 18,
17, 16, 23, 22, 21, 20, 27, 26, 25, 24, 31, 30, 29, 28, 35,
34, 33, 32, 39, 38, 37, 36, 43, 42, 41, 40, 47, 46, 45, 44,
51, 50, 49, 48, 55, 54, 53, 52, 59, 58, 57, 56, 63, 62, 61,
60, 67, 66, 65, 64, 71, 70, 69, 68, 75, 74, 73, 72, 79, 78,
77, 76, 83, 82, 81, 80
};

int ah = 0;
int al = 0;
int eax = 0;
int i;

for (i = 0; i < 84; i++) {
int ccc = cccTable[i];

if ((ccc & 1) == 1) {
uint16_t offs;
int bx = 0;

offs = (y * 2) + selfmod[2 * 84 + ccc];
bx = *(short *)&psini[offs];

offs = bx + selfmod[1 * 84 + ccc];
ah = psini[offs];

offs = (y * 2) + selfmod[4 * 84 + ccc];
bx = *(short *)&psini[offs];

offs = bx + (y * 2) + selfmod[3 * 84 + ccc];
ah += psini[offs];
ah &= 0xFF;
} else {
uint16_t offs;
int bx = 0;

offs = (y * 2) + selfmod[2 * 84 + ccc];
bx = *(short *)&psini[offs];

offs = bx + selfmod[1 * 84 + ccc];
al = psini[offs];

offs = (y * 2) + selfmod[4 * 84 + ccc];
bx = *(short *)&psini[offs];

offs = bx + (y * 2) + selfmod[3 * 84 + ccc];
al += psini[offs];
al &= 0xFF;
}

if ((ccc & 3) == 2) {
eax = (ah << 8) | (al << 0);
eax <<= 16;
}

if ((ccc & 3) == 0) {
eax |= (ah << 8) | (al << 0);
vga_write32(nVgaYOffset + ccc, eax);
}
}

return 0;
}


int setplzparas(int c1, int c2, int c3, int c4)
{
int ccc;

for (ccc = 0; ccc < 84; ccc++) {
//c1 + psini[ccc * 8];
uint16_t lc1, lc2, lc3, lc4;

lc1 = c1 + PSINI_OFFSET + (ccc * 8);
selfmod[1 * 84 + ccc] = lc1;

lc2 = (c2 * 2) + LSINI16_OFFSET - (ccc * 8) + (80 * 8);
selfmod[2 * 84 + ccc] = lc2;

lc3 = c3 + PSINI_OFFSET - (ccc * 4) + (80 * 4);
selfmod[3 * 84 + ccc] = lc3;

lc4 = (c4 * 2) + LSINI4_OFFSET + (ccc * 32);
selfmod[4 * 84 + ccc] = lc4;
}

return 0;
}



int set_plzstart(int y)
{
vga_set_line_compare(y);

return 0;
}
25 changes: 25 additions & 0 deletions plzpart/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#include <stdint.h>


uint16_t psini_read16(int);
uint8_t psini_read8(int);
void psini_write16(int, uint16_t);
void psini_write8(int, uint8_t);

void vga_select_bitplanes_02(void);
void vga_select_bitplanes_13(void);
void vga_select_bitplanes_0123(void);
void vga_write32(int, int);
void vga_set_line_compare(int);
void vga_set_palette_entry(int, int, int, int);
void vga_show_framebuffer(void);
void vga_set_hscroll_offset(int);
void vga_upload_palette(uint8_t *);

void initvect(void);

int init_copper(void);
int close_copper(void);
void copper1(void);
void copper2(void);
202 changes: 197 additions & 5 deletions plzpart/copper.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include <math.h>
#include "common.h"

int frame_count = 0;
int cop_drop = 0;
Expand All @@ -8,19 +9,210 @@ int cop_start = 0;
int cop_scrl = 0;
int cop_plz = 1;

int close_copper()
static int dtau[65];

uint8_t fadepal[768 * 2];
char *cop_fadepal;

extern int l1, l2, l3, l4;
extern int k1, k2, k3, k4;
extern int il1, il2, il3, il4;
extern int ik1, ik2, ik3, ik4;
extern int ttptr;

extern char *pals;


int init_copper()
{
int ccc;

for (ccc = 0; ccc < 65; ccc++) {
dtau[ccc] = floor(1.0 * ccc * ccc / 4 * 43 / 128 + 60);
}

return 0;
}

int init_copper()
int close_copper()
{
return 0;
}

void pompota()
{

// [NK 18/1/2014] Disable this for now, as it looks a bit jittery.
return;

#if 0
// [nk] This function toggles the horizontal split point every frame
// [nk] between line 60 and 61, along with the horizontal offset.
// [nk] (since set_plzstart == 60, it's splitting at the top of the plasma)
vga_set_line_compare(60);
cop_scrl = 4;

pompi++;

if ((pompi & 1) != 0)
{
// [NK 12/1/2014] Moving the starting line up and down each alternate frame
// [NK 12/1/2014] doesn't look good in windowed mode.
// [NK 13/1/2014] Seems to work okay in fullscreen mode though.
//vga_set_line_compare(61);
cop_scrl = 0;
}
#endif
}

void moveplz()
{
k1 += -3;
k1 &= 4095;
k2 += -2;
k2 &= 4095;
k3 += 1;
k3 &= 4095;
k4 += 2;
k4 &= 4095;
l1 += -1;
l1 &= 4095;
l2 += -2;
l2 &= 4095;
l3 += 2;
l3 &= 4095;
l4 += 3;
l4 &= 4095;
}

void initpparas()
{
l1 = il1;
l2 = il2;
l3 = il3;
l4 = il4;

unsigned char fadepal[768 * 2];
k1 = ik1;
k2 = ik2;
k3 = ik3;
k4 = ik4;
}

void do_drop()
{
cop_drop++;

int cop_fadepal = 0;
if (cop_drop <= 64) {
vga_set_line_compare(dtau[cop_drop]);
} else {
//@@over

int bShouldFade = 0;

// [NK 18/1/2014] Hack for looping back to the first plasma.
if ((cop_drop == 65) && (ttptr == 0)) {
cop_drop = 128;
}

if (cop_drop >= 256) {
} else if (cop_drop >= 128) {
bShouldFade = 1;
} else if (cop_drop > 96) {
} else /*if (cop_drop > 64) */{
bShouldFade = 1;
}

if (bShouldFade) {
// [NK 15/1/2014] cop_pal always points to fadepal, so just upload fadepal.
//cop_pal = fadepal;
do_pal = 1;

if (cop_drop == 65) {
vga_set_line_compare(400);
initpparas();
} else {
int i, ccc;
int cop_fadepal_idx = 0;
int fadepal_idx = 0;

vga_set_line_compare(60);

// [NK 9/1/2014] I think it's using 8.8 fixed point numbers to fade the palette.

for (i = 0; i < (768 / 16); i++) {
for (ccc = 0; ccc < 16; ccc++) {
// var al = cop_fadepal_ReadByte(cop_fadepal_idx + (ccc * 2));
// al &= 0xFF;
// var ah = cop_fadepal_ReadByte(cop_fadepal_idx + (ccc * 2) + 1);
// ah &= 0xFF;
// [NK 17/1/2014] Read cop_fadepal as words, rather than bytes,
// [NK 17/1/2014] to avoid endian issues.
int ax = *(short *)&cop_fadepal[cop_fadepal_idx + (ccc * 2)];
int al = ax & 0xFF;
int ah = (ax >> 8) & 0xFF;

int nOldValue = fadepal[fadepal_idx + ccc + 768] & 0xff;

int t = fadepal[fadepal_idx + ccc + 768];
t &= 0xFF;
t += al;
t &= 0xFF;
fadepal[fadepal_idx + ccc + 768] = t;

int nNewValue = fadepal[fadepal_idx + ccc + 768];
nNewValue &= 0xFF;

int carry = 0;

if (nNewValue < nOldValue) {
carry = 1;
}

t = fadepal[fadepal_idx + ccc];
t &= 0xFF;
t += ah + carry;
t &= 0xFF;
fadepal[fadepal_idx + ccc] = t;
}

cop_fadepal_idx += 32;
fadepal_idx += 16;
}
}
} else {
cop_drop = 0;
}
}
}

// [nk] just before retrace
void copper1()
{
// There is also assembly code to set the first pixel of
// display memory here, but it may not be necessary.

vga_set_hscroll_offset(cop_scrl);
}

// [nk] in retrace
void copper2()
{
// [nk] Don't think this is used.
frame_count++;

if (do_pal != 0) {
do_pal = 0;
// [NK 15/1/2014] cop_pal always points to fadepal, so just upload fadepal.
//vga_upload_palette(cop_pal);
vga_upload_palette(fadepal);
}

pompota();
moveplz();

if (cop_drop != 0)
{
do_drop();
}
}

Loading

0 comments on commit 0349c63

Please sign in to comment.