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

197 lines
4.2 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "display/display.h"
#include "screen.h"
void blitter(int id)
{
int i, j;
int w = displays[id].regs[12];
int h = displays[id].regs[13];
int sy = displays[id].regs[9], sx = displays[id].regs[8];
int dy = displays[id].regs[11], dx = displays[id].regs[10];
if ((id <0) && (id >= MAX_DISPLAY))
return;
if (screens[id] == NULL)
return;
if (displays[id].regs[7] == 0)
return;
if (w > (80 - dx))
w = 80 - dx;
if (h > (50 - dy))
h = 50 - dy;
if ((w < 0) || (h < 0))
{
displays[id].regs[7] = 0;
return;
}
switch (displays[id].regs[7])
{
case 1:
for (j = 0; j < h; j++)
for (i = 0; i < w; i++)
if (((j + dy) < 50) && ((i + dx) < 80))
{
screens[id]->chars.rowcol[j + dy][i + dx] = displays[id].regs[8];
if (screens[id]->type)
screens[id]->attributes.rowcol[j + dy][i + dx] = displays[id].regs[9];
}
displays[id].regs[7] = 0;
return;
case 2:
for (j = 0; j < h; j++)
for (i = 0; i < w; i++)
if (((j + dy) < 50) && ((i + dx) < 80))
screens[id]->chars.rowcol[j + dy][i + dx] ^= 0x80;
displays[id].regs[7] = 0;
return;
}
if (w > (80 - sx))
w = 80 - sx;
if (h > (50 - sy))
h = 50 - sy;
if ((w < 0) || (h < 0))
{
displays[id].regs[7] = 0;
return;
}
if (displays[id].regs[7] == 3)
{
for (j = 0; j < h; j++)
{
for (i = 0; i < w; i++)
{
if (((j + sy) < 50) && ((i + sx) < 80) && ((j + dy) < 50) && ((i + dx) < 80))
{
screens[id]->chars.rowcol[j + dy][i + dx] = screens[id]->chars.rowcol[j + sy][i + sx];
if (screens[id]->type)
screens[id]->attributes.rowcol[j + dy][i + dx] = screens[id]->attributes.rowcol[j + sy][i + sx];
}
}
}
displays[id].regs[7] = 0;
}
}
void init_displays()
{
memset(&displays,0x00,sizeof(displays));
}
void reset_display(int id)
{
if ((id >=0) && (id < MAX_DISPLAY))
{
if (screens[id] != NULL)
{
displays[id].regs[3] = 2;
displays[id].regs[4] = 0;
displays[id].regs[5] = 0;
displays[id].regs[6] = 0;
memset(screens[id]->chars.linear,0x20,SCR_SIZE);
scrattrfill(id, 0xbd);
}
}
}
void disp_store(int id, int ptr, unsigned char value)
{
if ((id >=0) && (id < MAX_DISPLAY))
{
if (screens[id] != NULL)
{
if (ptr < 16)
{
if ((ptr == 0x04) || (ptr == 0x05))
{
displays[id].regs[ptr] = value & 0x0f;
}
else if (ptr != 0x06)
{
displays[id].regs[ptr] = value;
if (ptr == 0x01) screens[id]->cx = value;
if (ptr == 0x02) screens[id]->cy = value;
if (ptr == 0x03) screens[id]->blink = value;
}
}
else if ((ptr >= 0x10) && (ptr < 0x60))
{
if (displays[id].regs[0] < 50)
screens[id]->chars.rowcol[displays[id].regs[0]][ptr - 0x10] = value;
}
else if ((screens[id]->type == 1) && (ptr >= 0x60) && (ptr < 0xb0))
{
if (displays[id].regs[0] < 50)
screens[id]->attributes.rowcol[displays[id].regs[0]][ptr - 0x60] = value;
}
}
}
}
unsigned char disp_load(int id, int ptr)
{
if ((id >=0) && (id < MAX_DISPLAY))
{
if (screens[id] != NULL)
{
if (ptr < 16)
{
if (ptr == 0x06)
return displays[id].kbbuf[displays[id].regs[4]];
return displays[id].regs[ptr];
}
else if ((ptr >= 0x10) && (ptr < 0x60))
{
if (displays[id].regs[0] < 50)
return screens[id]->chars.rowcol[displays[id].regs[0]][ptr - 0x10];
}
else if ((screens[id]->type == 1) && (ptr >= 0x60) && (ptr < 0xb0))
{
if (displays[id].regs[0] < 50)
return screens[id]->attributes.rowcol[displays[id].regs[0]][ptr - 0x60];
}
else if (ptr == 0xff)
return screens[id]->type;
}
}
return 0;
}
unsigned char disp_key(int id, unsigned char ch)
{
int np;
if ((id >=0) && (id < MAX_DISPLAY))
{
if (screens[id] != NULL)
{
np = (displays[id].regs[5] + 1) & 0x0f;
if (np != displays[id].regs[4])
{
displays[id].kbbuf[displays[id].regs[5] & 0x0f] = ch;
displays[id].regs[5] = np;
displays[id].regs[6] = displays[id].kbbuf[displays[id].regs[4] & 0x0f];
}
}
}
}