mirror of
https://github.com/cc65/cc65.git
synced 2024-06-28 19:29:53 +00:00
Fix shaped bugs
git-svn-id: svn://svn.cc65.org/cc65/trunk@5933 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
e04f1d8cb0
commit
7e75e29812
|
@ -144,46 +144,13 @@ static void AssembleByte(unsigned bits, char val)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
val <<= 8 - bits;
|
/* handle end of line for literal */
|
||||||
|
if (bits == 7) {
|
||||||
do {
|
|
||||||
byte <<= 1;
|
|
||||||
|
|
||||||
if (val & 0x80)
|
|
||||||
++byte;
|
|
||||||
|
|
||||||
if (!(--bit_counter)) {
|
|
||||||
OutBuffer[OutIndex++] = byte;
|
|
||||||
if (!OutIndex) {
|
|
||||||
Error ("Sprite is too large for the Lynx");
|
|
||||||
}
|
|
||||||
byte = 0;
|
|
||||||
bit_counter = 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
val <<= 1;
|
|
||||||
|
|
||||||
} while (--bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void AssembleByteLiteral(unsigned bits, char val)
|
|
||||||
{
|
|
||||||
static char bit_counter = 8, byte = 0;
|
|
||||||
|
|
||||||
/* initialize */
|
|
||||||
if (!bits) {
|
|
||||||
OutIndex = 0;
|
|
||||||
bit_counter = 8;
|
|
||||||
byte = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* handle end of line */
|
|
||||||
if (bits == 8) {
|
|
||||||
if (bit_counter != 8) {
|
if (bit_counter != 8) {
|
||||||
byte <<= bit_counter;
|
byte <<= bit_counter;
|
||||||
OutBuffer[OutIndex++] = byte;
|
OutBuffer[OutIndex++] = byte;
|
||||||
if (!OutIndex) {
|
if (!OutIndex) {
|
||||||
Error ("Sprite is too large for the Lynx");
|
Error ("ASprite is too large for the Lynx");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -266,20 +233,19 @@ static void encodeSprite(StrBuf *D, enum Mode M, char ColorBits, char ColorMask,
|
||||||
unsigned char differ[16];
|
unsigned char differ[16];
|
||||||
unsigned char *d_ptr;
|
unsigned char *d_ptr;
|
||||||
|
|
||||||
|
AssembleByte(0, 0);
|
||||||
switch (M) {
|
switch (M) {
|
||||||
case smAuto:
|
case smAuto:
|
||||||
case smLiteral:
|
case smLiteral:
|
||||||
AssembleByteLiteral(0, 0);
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
/* Fetch next pixel index into pixel buffer */
|
/* Fetch next pixel index into pixel buffer */
|
||||||
AssembleByteLiteral(ColorBits, LineBuffer[i] & ColorMask);
|
AssembleByte(ColorBits, LineBuffer[i] & ColorMask);
|
||||||
}
|
}
|
||||||
AssembleByteLiteral(8, 0);
|
AssembleByte(7, 0);
|
||||||
/* Write the buffer to file */
|
/* Write the buffer to file */
|
||||||
WriteOutBuffer(D);
|
WriteOutBuffer(D);
|
||||||
break;
|
break;
|
||||||
case smPacked:
|
case smPacked:
|
||||||
AssembleByte(0, 0);
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (len) {
|
while (len) {
|
||||||
if (ChoosePackagingMode(len, i, LineBuffer)) {
|
if (ChoosePackagingMode(len, i, LineBuffer)) {
|
||||||
|
@ -325,53 +291,54 @@ static void encodeSprite(StrBuf *D, enum Mode M, char ColorBits, char ColorMask,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case smShaped:
|
case smShaped:
|
||||||
if (LastOpaquePixel >= 0 && LastOpaquePixel < len) {
|
if (LastOpaquePixel > -1) {
|
||||||
len = LastOpaquePixel;
|
if (LastOpaquePixel < len - 1) {
|
||||||
}
|
len = LastOpaquePixel + 1;
|
||||||
AssembleByte(0, 0);
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
while (len) {
|
while (len) {
|
||||||
if (ChoosePackagingMode(len, i, LineBuffer)) {
|
if (ChoosePackagingMode(len, i, LineBuffer)) {
|
||||||
/* Make runlength packet */
|
/* Make runlength packet */
|
||||||
V = LineBuffer[i];
|
V = LineBuffer[i];
|
||||||
++i;
|
|
||||||
--len;
|
|
||||||
count = 0;
|
|
||||||
do {
|
|
||||||
++count;
|
|
||||||
++i;
|
++i;
|
||||||
--len;
|
--len;
|
||||||
} while (V == LineBuffer[i] && len && count != 15);
|
count = 0;
|
||||||
|
do {
|
||||||
|
++count;
|
||||||
|
++i;
|
||||||
|
--len;
|
||||||
|
} while (V == LineBuffer[i] && len && count != 15);
|
||||||
|
|
||||||
AssembleByte(5, count);
|
AssembleByte(5, count);
|
||||||
AssembleByte(ColorBits, V);
|
AssembleByte(ColorBits, V);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Make packed literal packet */
|
/* Make packed literal packet */
|
||||||
d_ptr = differ;
|
d_ptr = differ;
|
||||||
V = LineBuffer[i++];
|
|
||||||
*d_ptr++ = V;
|
|
||||||
--len;
|
|
||||||
count = 0;
|
|
||||||
while (ChoosePackagingMode(len, i, LineBuffer) == 0 && len && count != 15) {
|
|
||||||
V = LineBuffer[i++];
|
V = LineBuffer[i++];
|
||||||
*d_ptr++ = V;
|
*d_ptr++ = V;
|
||||||
++count;
|
|
||||||
--len;
|
--len;
|
||||||
|
count = 0;
|
||||||
|
while (ChoosePackagingMode(len, i, LineBuffer) == 0 && len && count != 15) {
|
||||||
|
V = LineBuffer[i++];
|
||||||
|
*d_ptr++ = V;
|
||||||
|
++count;
|
||||||
|
--len;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssembleByte(5, count | 0x10);
|
||||||
|
d_ptr = differ;
|
||||||
|
do {
|
||||||
|
AssembleByte(ColorBits, *d_ptr++);
|
||||||
|
} while (--count >= 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssembleByte(5, count | 0x10);
|
|
||||||
d_ptr = differ;
|
|
||||||
do {
|
|
||||||
AssembleByte(ColorBits, *d_ptr++);
|
|
||||||
} while (--count >= 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
AssembleByte(5, 0);
|
||||||
|
AssembleByte(8, 0);
|
||||||
|
/* Write the buffer to file */
|
||||||
|
WriteOutBuffer(D);
|
||||||
}
|
}
|
||||||
AssembleByte(5, 0);
|
|
||||||
AssembleByte(8, 0);
|
|
||||||
/* Write the buffer to file */
|
|
||||||
WriteOutBuffer(D);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user