fix libraw2crtc

see http://pulkomandy.tk/projects/GrafX2/ticket/83
This commit is contained in:
Thomas Bernard 2018-06-25 23:47:31 +02:00
parent e381177970
commit de9d6b66d7

View File

@ -31,14 +31,16 @@ unsigned short addrCalc(unsigned char vcc, unsigned char rcc, unsigned char hcc,
unsigned char mode0interlace(T_IO_Context * context, unsigned char x, unsigned char y)
{
// bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
// p0b0 p1b0 p0b2 p1b2 p0b1 p1b1 p0b3 p1b3
unsigned char mode0pixel[] = {0, 64, 4, 68, 16, 80, 20, 84, 1, 65, 5, 69, 17, 81, 21, 85};
return mode0pixel[Get_pixel(context,x,y)] << 1 | mode0pixel[Get_pixel(context,x+1,y)];
return mode0pixel[Get_pixel(context,x,y) & 0xf] << 1 | mode0pixel[Get_pixel(context,x+1,y) & 0xf];
}
unsigned char mode1interlace(T_IO_Context * context, unsigned char x, unsigned char y)
{
unsigned char mode1pixel[] = {0, 16, 1, 17};
return mode1pixel[Get_pixel(context,x,y)] << 3 | mode1pixel[Get_pixel(context,x+1,y)] << 2 | mode1pixel[Get_pixel(context,x+2,y)] << 1 | mode1pixel[Get_pixel(context,x+3,y)];
return mode1pixel[Get_pixel(context,x,y) & 3] << 3 | mode1pixel[Get_pixel(context,x+1,y) & 3] << 2 | mode1pixel[Get_pixel(context,x+2,y) & 3] << 1 | mode1pixel[Get_pixel(context,x+3,y) & 3];
}
unsigned char mode2interlace(T_IO_Context * context, unsigned char x, unsigned char y)
@ -52,11 +54,9 @@ unsigned char mode2interlace(T_IO_Context * context, unsigned char x, unsigned c
unsigned char mode3interlace(T_IO_Context * context, unsigned char x, unsigned char y)
{
unsigned char mode3pixel[] = {0, 16, 1, 17};
return mode3pixel[Get_pixel(context, x,y)] << 3 | mode3pixel[Get_pixel(context,x+1,y)] << 2;
return mode3pixel[Get_pixel(context, x,y) & 3] << 3 | mode3pixel[Get_pixel(context,x+1,y) & 3] << 2;
}
unsigned char (*ptrMode)(T_IO_Context * context, unsigned char x, unsigned char y);
unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char r9, unsigned long *outSize, unsigned char *r1, unsigned char r12, unsigned char r13)
{
unsigned char *outBuffer;
@ -66,11 +66,8 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char
unsigned char minAddrIsDefined = 0;
unsigned short maxAddr = 0;
int y,x;
int i, y,x;
unsigned char r6;
unsigned short i;
unsigned char *ptrTmp;
unsigned char *ptrOut;
unsigned char vcc;
unsigned char rcc;
unsigned char hcc;
@ -78,7 +75,9 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char
int width = context->Width;
int height = context->Height;
unsigned char (*ptrMode)(T_IO_Context * context, unsigned char x, unsigned char y);
switch(mode)
{
case 0:
@ -111,14 +110,14 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char
}
}
tmpBuffer = (unsigned char*)malloc(0xFFFF);
tmpBuffer = (unsigned char*)malloc(0x10000);
if (tmpBuffer == NULL)
{
fprintf(stderr, "failed to allocate tmpBuffer\n");
exit(4);
}
allocationBuffer = (unsigned char*)malloc(0xFFFF);
allocationBuffer = (unsigned char*)malloc(0x10000);
if(allocationBuffer == NULL)
{
fprintf(stderr, "failed to allocate allocationBuffer\n");
@ -136,16 +135,18 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char
{
for(cclk = 0; cclk < 2; cclk++)
{
unsigned short addr;
x = (hcc << 1 | cclk);
y = vcc*(r9+1) + rcc;
*(tmpBuffer + addrCalc(vcc, rcc, hcc, cclk, *r1, r12, r13)) = (*ptrMode)(context,x,y);
*(allocationBuffer + addrCalc(vcc, rcc, hcc, cclk, *r1, r12, r13)) += 1;
addr = addrCalc(vcc, rcc, hcc, cclk, *r1, r12, r13);
tmpBuffer[addr] = (*ptrMode)(context,x,y);
allocationBuffer[addr] += 1;
}
}
}
}
for(i = 0; i < 0xFFFF; i++)
for(i = 0; i < 0x10000; i++)
{
if(*(allocationBuffer + i) > 1)
{
@ -154,11 +155,11 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char
if(*(allocationBuffer + i) > 0)
{
maxAddr = i;
}
if((*(allocationBuffer + i) == 1) && (minAddrIsDefined == 0))
{
minAddr = i;
minAddrIsDefined = 1;
if(minAddrIsDefined == 0)
{
minAddr = i;
minAddrIsDefined = 1;
}
}
}
@ -171,13 +172,7 @@ unsigned char *raw2crtc(T_IO_Context *context, unsigned char mode, unsigned char
exit(4);
}
ptrTmp = tmpBuffer + minAddr;
ptrOut = outBuffer;
for(i = minAddr; i <= maxAddr; i++)
{
*(ptrOut++) = *(ptrTmp++);
}
memcpy(outBuffer, tmpBuffer + minAddr, *outSize);
free(tmpBuffer);
tmpBuffer = NULL;