| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
|
| 14 |
#include "common.h" |
| 15 |
#include "glk.h" |
| 16 |
#include "graphics.h" |
| 17 |
|
| 18 |
extern int at_last_line; |
| 19 |
|
| 20 |
int ycount = 0; |
| 21 |
int skipy = 1; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
static void DrawDOSPixels(int pattern) |
| 26 |
{ |
| 27 |
int pix1, pix2, pix3, pix4; |
| 28 |
|
| 29 |
pix1 = (pattern & 0xc0) >> 6; |
| 30 |
pix2 = (pattern & 0x30) >> 4; |
| 31 |
pix3 = (pattern & 0x0c) >> 2; |
| 32 |
pix4 = (pattern & 0x03); |
| 33 |
|
| 34 |
if (!skipy) { |
| 35 |
PutDoublePixel(x, y, pix1); |
| 36 |
x += 2; |
| 37 |
PutDoublePixel(x, y, pix2); |
| 38 |
x += 2; |
| 39 |
PutDoublePixel(x, y, pix3); |
| 40 |
x += 2; |
| 41 |
PutDoublePixel(x, y, pix4); |
| 42 |
x += 2; |
| 43 |
} else { |
| 44 |
PutPixel(x, y, pix1); |
| 45 |
x++; |
| 46 |
PutPixel(x, y, pix2); |
| 47 |
x++; |
| 48 |
PutPixel(x, y, pix3); |
| 49 |
x++; |
| 50 |
PutPixel(x, y, pix4); |
| 51 |
x++; |
| 52 |
} |
| 53 |
|
| 54 |
if (x >= xlen + xoff) { |
| 55 |
y += 2; |
| 56 |
x = xoff; |
| 57 |
ycount++; |
| 58 |
} |
| 59 |
|
| 60 |
if (ycount > ylen) { |
| 61 |
y = yoff + 1; |
| 62 |
at_last_line++; |
| 63 |
ycount = 0; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
int DrawDOSImageFromData(uint8_t *ptr, size_t datasize) |
| 68 |
{ |
| 69 |
x = 0; |
| 70 |
y = 0; |
| 71 |
at_last_line = 0; |
| 72 |
|
| 73 |
xlen = 0; |
| 74 |
ylen = 0; |
| 75 |
xoff = 0; |
| 76 |
yoff = 0; |
| 77 |
ycount = 0; |
| 78 |
skipy = 1; |
| 79 |
|
| 80 |
int work; |
| 81 |
int c; |
| 82 |
int i; |
| 83 |
int rawoffset; |
| 84 |
|
| 85 |
RGB black = { 0,0,0 }; |
| 86 |
RGB magenta = { 255,0,255 }; |
| 87 |
RGB cyan = { 0,255,255 }; |
| 88 |
RGB white = { 255,255,255 }; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
SetColor(0, &black); |
| 93 |
SetColor(1, &cyan); |
| 94 |
SetColor(2, &magenta); |
| 95 |
SetColor(3, &white); |
| 96 |
|
| 97 |
if (ptr == NULL) { |
| 98 |
fprintf(stderr, "DrawMSDOSImageFromData: ptr == NULL\n"); |
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
uint8_t *origptr = ptr; |
| 103 |
|
| 104 |
|
| 105 |
ptr = origptr + 0x05; |
| 106 |
work = *ptr++; |
| 107 |
int imagesize = work + (*ptr * 256); |
| 108 |
|
| 109 |
|
| 110 |
ptr = origptr + 0x0d; |
| 111 |
work = *ptr++; |
| 112 |
if (work == 0xff) |
| 113 |
skipy = 0; |
| 114 |
|
| 115 |
|
| 116 |
ptr = origptr + 0x0f; |
| 117 |
work = *ptr++; |
| 118 |
rawoffset = work + (*ptr * 256); |
| 119 |
xoff = ((rawoffset % 80) * 4) - 24; |
| 120 |
yoff = rawoffset / 40; |
| 121 |
yoff -= (yoff & 1); |
| 122 |
x = xoff; |
| 123 |
y = yoff; |
| 124 |
|
| 125 |
|
| 126 |
ptr = origptr + 0x11; |
| 127 |
work = *ptr++; |
| 128 |
ylen = work + (*ptr * 256); |
| 129 |
ylen -= rawoffset; |
| 130 |
ylen /= 80; |
| 131 |
|
| 132 |
|
| 133 |
ptr = origptr + 0x13; |
| 134 |
xlen = *ptr * 4; |
| 135 |
|
| 136 |
ptr = origptr + 0x17; |
| 137 |
while (ptr - origptr < imagesize) { |
| 138 |
|
| 139 |
c = *ptr++; |
| 140 |
|
| 141 |
if ((c & 0x80) == 0x80) { |
| 142 |
work = *ptr++; |
| 143 |
c &= 0x7f; |
| 144 |
for (i = 0; i <= c; i++) { |
| 145 |
DrawDOSPixels(work); |
| 146 |
} |
| 147 |
} else { |
| 148 |
|
| 149 |
for (i = 0; i <= c; i++) { |
| 150 |
work = *ptr++; |
| 151 |
DrawDOSPixels(work); |
| 152 |
} |
| 153 |
} |
| 154 |
if (at_last_line > 1) |
| 155 |
break; |
| 156 |
} |
| 157 |
return 1; |
| 158 |
} |