mirror of
https://github.com/captain-amygdala/pistorm.git
synced 2026-02-09 17:51:17 +00:00
Fix up P2C/P2D, fix 256th color missing in 8bpp modes
This commit is contained in:
@@ -19,7 +19,11 @@ void main()
|
||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||
|
||||
vec4 color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
vec2 bukCoord = vec2(texelColor.r, 0.0);
|
||||
vec2 bukCoord = vec2(texelColor.r, 0.5);
|
||||
|
||||
if (texelColor.r == 1.0) {
|
||||
bukCoord = vec2(0.9999, 0.5);
|
||||
}
|
||||
vec4 colorx = texture2D(texture1, bukCoord);
|
||||
|
||||
gl_FragColor = vec4(colorx.r, colorx.g, colorx.b, 1.0);
|
||||
|
||||
@@ -19,6 +19,8 @@ extern uint16_t rtg_x[8], rtg_y[8];
|
||||
|
||||
extern uint8_t realtime_graphics_debug;
|
||||
|
||||
uint8_t cursor_data[256 * 256];
|
||||
|
||||
void rtg_fillrect_solid(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color, uint16_t pitch, uint16_t format) {
|
||||
uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
|
||||
switch(format) {
|
||||
@@ -748,7 +750,87 @@ void rtg_p2c (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t
|
||||
cur_byte++;
|
||||
cur_byte %= src_line_pitch;
|
||||
}
|
||||
|
||||
}
|
||||
dptr += pitch;
|
||||
if ((line_y + sy + 1) % h)
|
||||
bmp_data += src_line_pitch;
|
||||
else
|
||||
bmp_data = bmp_data_src;
|
||||
cur_bit = base_bit;
|
||||
cur_byte = base_byte;
|
||||
}
|
||||
}
|
||||
|
||||
void rtg_p2d (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src) {
|
||||
uint16_t pitch = rtg_x[3];
|
||||
uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
|
||||
|
||||
uint8_t cur_bit, base_bit, base_byte;
|
||||
uint16_t cur_byte = 0, u8_fg = 0;
|
||||
//uint32_t color_mask = 0xFFFFFFFF;
|
||||
|
||||
uint32_t plane_size = src_line_pitch * h;
|
||||
uint8_t *bmp_data = bmp_data_src;
|
||||
|
||||
cur_bit = base_bit = (0x80 >> (sx % 8));
|
||||
cur_byte = base_byte = ((sx / 8) % src_line_pitch);
|
||||
|
||||
if (realtime_graphics_debug) {
|
||||
printf("P2D: %d,%d - %d,%d (%dx%d) %d, %.2X\n", sx, sy, dx, dy, w, h, planes, layer_mask);
|
||||
printf("Mask: %.2X Minterm: %.2X\n", mask, draw_mode);
|
||||
printf("Pitch: %d Src Pitch: %d (!!!: %.4X)\n", pitch, src_line_pitch, rtg_user[0]);
|
||||
printf("Curbyte: %d Curbit: %d\n", cur_byte, cur_bit);
|
||||
printf("Plane size: %d Total size: %d (%X)\n", plane_size, plane_size * planes, plane_size * planes);
|
||||
printf("Source: %.8X - %.8X\n", rtg_address[1], rtg_address_adj[1]);
|
||||
printf("Target: %.8X - %.8X\n", rtg_address[0], rtg_address_adj[0]);
|
||||
fflush(stdout);
|
||||
|
||||
printf("Grabbing data from RTG memory.\nData:\n");
|
||||
for (int i = 0; i < h; i++) {
|
||||
for (int k = 0; k < planes; k++) {
|
||||
for (int j = 0; j < src_line_pitch; j++) {
|
||||
printf("%.2X", bmp_data_src[j + (i * src_line_pitch) + (plane_size * k)]);
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t *clut = (uint32_t *)bmp_data_src;
|
||||
bmp_data += (256 * 4);
|
||||
bmp_data_src += (256 * 4);
|
||||
|
||||
for (int16_t line_y = 0; line_y < h; line_y++) {
|
||||
for (int16_t x = dx; x < dx + w; x++) {
|
||||
u8_fg = 0;
|
||||
if (draw_mode & 0x01) {
|
||||
DECODE_INVERTED_PLANAR_PIXEL(u8_fg)
|
||||
}
|
||||
else {
|
||||
DECODE_PLANAR_PIXEL(u8_fg)
|
||||
}
|
||||
|
||||
uint32_t fg_color = clut[u8_fg];
|
||||
|
||||
if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
|
||||
switch (rtg_display_format) {
|
||||
case RTGFMT_RBG565:
|
||||
((uint16_t *)dptr)[x] = (fg_color >> 16);
|
||||
break;
|
||||
case RTGFMT_RGB32:
|
||||
((uint32_t *)dptr)[x] = fg_color;
|
||||
break;
|
||||
}
|
||||
goto skip;
|
||||
}
|
||||
|
||||
skip:;
|
||||
if ((cur_bit >>= 1) == 0) {
|
||||
cur_bit = 0x80;
|
||||
cur_byte++;
|
||||
cur_byte %= src_line_pitch;
|
||||
}
|
||||
}
|
||||
dptr += pitch;
|
||||
if ((line_y + sy + 1) % h)
|
||||
|
||||
@@ -40,6 +40,9 @@ struct rtg_shared_data {
|
||||
|
||||
struct rtg_shared_data rtg_share_data;
|
||||
static uint32_t palette[256];
|
||||
static uint32_t cursor_palette[256];
|
||||
|
||||
extern uint8_t cursor_data[256 * 256];
|
||||
|
||||
void rtg_update_screen() {}
|
||||
|
||||
@@ -83,19 +86,15 @@ void *rtgThread(void *args) {
|
||||
uint16_t format = rtg_display_format;
|
||||
uint16_t pitch = rtg_pitch;
|
||||
|
||||
Texture raylib_texture;
|
||||
Texture raylib_clut_texture;
|
||||
Image raylib_fb, raylib_clut;
|
||||
Texture raylib_texture, raylib_cursor_texture;
|
||||
Texture raylib_clut_texture, raylib_cursor_clut_texture;
|
||||
Image raylib_fb, raylib_cursor, raylib_clut, raylib_cursor_clut;
|
||||
|
||||
InitWindow(GetScreenWidth(), GetScreenHeight(), "Pistorm RTG");
|
||||
HideCursor();
|
||||
SetTargetFPS(60);
|
||||
|
||||
Color bef;
|
||||
bef.r = 0;
|
||||
bef.g = 64;
|
||||
bef.b = 128;
|
||||
bef.a = 255;
|
||||
Color bef = { 0, 64, 128, 255 };
|
||||
|
||||
Shader clut_shader = LoadShader(NULL, "platforms/amiga/rtg/clut.shader");
|
||||
Shader swizzle_shader = LoadShader(NULL, "platforms/amiga/rtg/argbswizzle.shader");
|
||||
@@ -107,7 +106,21 @@ void *rtgThread(void *args) {
|
||||
raylib_clut.mipmaps = 1;
|
||||
raylib_clut.data = palette;
|
||||
|
||||
raylib_cursor_clut.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
raylib_cursor_clut.width = 256;
|
||||
raylib_cursor_clut.height = 1;
|
||||
raylib_cursor_clut.mipmaps = 1;
|
||||
raylib_cursor_clut.data = cursor_palette;
|
||||
|
||||
raylib_clut_texture = LoadTextureFromImage(raylib_clut);
|
||||
raylib_cursor_clut_texture = LoadTextureFromImage(raylib_cursor_clut);
|
||||
|
||||
raylib_cursor.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
|
||||
raylib_cursor.width = 256;
|
||||
raylib_cursor.height = 256;
|
||||
raylib_cursor.mipmaps = 1;
|
||||
raylib_cursor.data = cursor_data;
|
||||
raylib_cursor_texture = LoadTextureFromImage(raylib_cursor);
|
||||
|
||||
Rectangle srchax, dsthax;
|
||||
Vector2 originhax;
|
||||
@@ -193,7 +206,12 @@ reinit_raylib:;
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG_RAYLIB_RTG
|
||||
DrawTexture(raylib_clut_texture, 0, 0, RAYWHITE);
|
||||
if (format == RTGFMT_8BIT) {
|
||||
Rectangle srcrect = { 0, 0, 256, 1 };
|
||||
Rectangle dstrect = { 0, 0, 1024, 8 };
|
||||
//DrawTexture(raylib_clut_texture, 0, 0, RAYWHITE);
|
||||
DrawTexturePro(raylib_clut_texture, srcrect, dstrect, originhax, 0.0f, RAYWHITE);
|
||||
}
|
||||
#endif
|
||||
|
||||
DrawFPS(width - 200, 0);
|
||||
|
||||
@@ -302,10 +302,11 @@ static void handle_rtg_command(uint32_t cmd) {
|
||||
break;
|
||||
case RTGCMD_P2C:
|
||||
rtg_p2c(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_u8[1], rtg_u8[2], rtg_u8[0], (rtg_user[0] >> 0x8), rtg_x[4], (uint8_t *)&rtg_mem[rtg_address_adj[1]]);
|
||||
//rtg_p2c_broken(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[3], rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_user[0]);
|
||||
gdebug("Planar2Chunky\n");
|
||||
break;
|
||||
case RTGCMD_P2D:
|
||||
rtg_p2d(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_u8[1], rtg_u8[2], rtg_u8[0], (rtg_user[0] >> 0x8), rtg_x[4], (uint8_t *)&rtg_mem[rtg_address_adj[1]]);
|
||||
gdebug("Planar2Direct\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ void rtg_drawline_solid(int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint
|
||||
void rtg_drawline (int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint16_t len, uint16_t pattern, uint16_t pattern_offset, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t format, uint8_t mask, uint8_t draw_mode);
|
||||
|
||||
void rtg_p2c (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src);
|
||||
void rtg_p2d (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src);
|
||||
|
||||
#define PATTERN_LOOPX \
|
||||
tmpl_x ^= 0x01; \
|
||||
|
||||
@@ -274,7 +274,7 @@ int InitCard(__REGA0(struct BoardInfo* b)) {
|
||||
b->PaletteChipType = PCT_MNT_ZZ9000;
|
||||
b->GraphicsControllerType = GCT_MNT_ZZ9000;
|
||||
|
||||
b->Flags = BIF_INDISPLAYCHAIN | BIF_GRANTDIRECTACCESS;
|
||||
b->Flags = BIF_INDISPLAYCHAIN | BIF_GRANTDIRECTACCESS;// | BIF_HARDWARESPRITE;
|
||||
b->RGBFormats = 1 | 2 | 512 | 1024 | 2048;
|
||||
b->SoftSpriteFlags = 0;
|
||||
b->BitsPerCannon = 8;
|
||||
@@ -318,8 +318,8 @@ int InitCard(__REGA0(struct BoardInfo* b)) {
|
||||
//b->ScrollPlanar = (void *)NULL;
|
||||
//b->UpdatePlanar = (void *)NULL;
|
||||
|
||||
//b->BlitPlanar2Chunky = (void *)BlitPlanar2Chunky;
|
||||
//b->BlitPlanar2Direct = (void *)NULL;
|
||||
b->BlitPlanar2Chunky = (void *)BlitPlanar2Chunky;
|
||||
b->BlitPlanar2Direct = (void *)BlitPlanar2Direct;
|
||||
|
||||
b->FillRect = (void *)FillRect;
|
||||
b->InvertRect = (void *)InvertRect;
|
||||
@@ -510,6 +510,12 @@ void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __RE
|
||||
void InvertRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format)) {
|
||||
if (!r)
|
||||
return;
|
||||
|
||||
if (mask != 0xFF) {
|
||||
b->InvertRectDefault(b, r, x, y, w, h, mask, format);
|
||||
return;
|
||||
}
|
||||
|
||||
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
|
||||
|
||||
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
|
||||
@@ -657,60 +663,6 @@ void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __RE
|
||||
WRITESHORT(RTG_COMMAND, RTGCMD_DRAWLINE);
|
||||
}
|
||||
|
||||
void BlitPlanar2Chunky_Broken (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {
|
||||
if (!r || !b || !bm) return;
|
||||
|
||||
//unsigned long bmp_size = bm->BytesPerRow * bm->Rows;
|
||||
unsigned char planemask_0 = 0, planemask = 0;
|
||||
//unsigned short line_size = (w >> 3) + 2;
|
||||
//unsigned long output_plane_size = line_size * h;
|
||||
unsigned long plane_size = bm->BytesPerRow * bm->Rows;
|
||||
short x_offset = (x >> 3);
|
||||
|
||||
unsigned long dest = CARD_SCRATCH;
|
||||
|
||||
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
|
||||
WRITELONG(RTG_ADDR2, (unsigned long)dest);
|
||||
WRITELONG(RTG_ADDR3, (unsigned long)bm->Planes[0]);
|
||||
|
||||
for (unsigned short i = 0; i < bm->Depth; i++) {
|
||||
if ((unsigned long)bm->Planes[i] == 0xFFFFFFFF) {
|
||||
planemask |= (1 << i);
|
||||
}
|
||||
else if (bm->Planes[i] == NULL) {
|
||||
planemask_0 |= (1 << i);
|
||||
}
|
||||
else {
|
||||
unsigned long bmp_mem = (unsigned long)(bm->Planes[i]) + x_offset + (y * bm->BytesPerRow);
|
||||
unsigned long plane_dest = dest;
|
||||
for (unsigned short y_line = 0; y_line < h; y_line++) {
|
||||
memcpy((unsigned char *)plane_dest, (unsigned char *)bmp_mem, bm->BytesPerRow);
|
||||
plane_dest += bm->BytesPerRow;
|
||||
bmp_mem += bm->BytesPerRow;
|
||||
}
|
||||
}
|
||||
dest += plane_size;
|
||||
}
|
||||
|
||||
WRITESHORT(RTG_X1, x % 0x07);
|
||||
WRITESHORT(RTG_X2, dx);
|
||||
WRITESHORT(RTG_X3, w);
|
||||
WRITESHORT(RTG_Y1, 0);
|
||||
WRITESHORT(RTG_Y2, dy);
|
||||
WRITESHORT(RTG_Y3, h);
|
||||
|
||||
WRITESHORT(RTG_Y4, bm->Rows);
|
||||
WRITESHORT(RTG_X4, r->BytesPerRow);
|
||||
WRITESHORT(RTG_U1, planemask_0 << 8 | planemask);
|
||||
WRITESHORT(RTG_U2, bm->BytesPerRow);
|
||||
|
||||
WRITEBYTE(RTG_U81, mask);
|
||||
WRITEBYTE(RTG_U82, minterm);
|
||||
WRITEBYTE(RTG_U83, bm->Depth);
|
||||
|
||||
WRITESHORT(RTG_COMMAND, RTGCMD_P2C);
|
||||
}
|
||||
|
||||
void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {
|
||||
if (!b || !r)
|
||||
return;
|
||||
@@ -739,8 +691,8 @@ void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm)
|
||||
for (int16_t i = 0; i < bm->Depth; i++) {
|
||||
uint16_t x_offset = (x >> 3);
|
||||
if ((uint32_t)bm->Planes[i] == 0xFFFFFFFF) {
|
||||
//memset((uint8_t*)(((uint32_t)b->memory)+template_addr), 0xFF, output_plane_size);
|
||||
ff_mask |= cur_plane;
|
||||
uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
|
||||
memset(dest, 0xFF, output_plane_size);
|
||||
}
|
||||
else if (bm->Planes[i] != NULL) {
|
||||
uint8_t* bmp_mem = (uint8_t*)bm->Planes[i] + (y * bm->BytesPerRow) + x_offset;
|
||||
@@ -771,6 +723,65 @@ void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm)
|
||||
WRITESHORT(RTG_COMMAND, RTGCMD_P2C);
|
||||
}
|
||||
|
||||
void BlitPlanar2Direct (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bmp), __REGA2(struct RenderInfo *r), __REGA3(struct ColorIndexMapping *clut), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {
|
||||
void BlitPlanar2Direct (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGA3(struct ColorIndexMapping *clut), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {
|
||||
if (!b || !r)
|
||||
return;
|
||||
|
||||
uint32_t plane_size = bm->BytesPerRow * bm->Rows;
|
||||
|
||||
uint32_t template_addr = CARD_SCRATCH;
|
||||
|
||||
uint16_t plane_mask = mask;
|
||||
uint8_t ff_mask = 0x00;
|
||||
uint8_t cur_plane = 0x01;
|
||||
|
||||
uint16_t line_size = (w >> 3) + 2;
|
||||
uint32_t output_plane_size = line_size * h;
|
||||
uint16_t x_offset = (x >> 3);
|
||||
|
||||
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
|
||||
WRITELONG(RTG_ADDR2, template_addr);
|
||||
WRITESHORT(RTG_X4, r->BytesPerRow);
|
||||
WRITESHORT(RTG_X5, line_size);
|
||||
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[r->RGBFormat]);
|
||||
|
||||
WRITEBYTE(RTG_U81, mask);
|
||||
WRITEBYTE(RTG_U82, minterm);
|
||||
|
||||
memcpy((uint8_t*)((uint32_t)template_addr), clut->Colors, (256 << 2));
|
||||
template_addr += (256 << 2);
|
||||
|
||||
for (int16_t i = 0; i < bm->Depth; i++) {
|
||||
uint16_t x_offset = (x >> 3);
|
||||
if ((uint32_t)bm->Planes[i] == 0xFFFFFFFF) {
|
||||
uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
|
||||
memset(dest, 0xFF, output_plane_size);
|
||||
}
|
||||
else if (bm->Planes[i] != NULL) {
|
||||
uint8_t* bmp_mem = (uint8_t*)bm->Planes[i] + (y * bm->BytesPerRow) + x_offset;
|
||||
uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
|
||||
for (int16_t y_line = 0; y_line < h; y_line++) {
|
||||
memcpy(dest, bmp_mem, line_size);
|
||||
dest += line_size;
|
||||
bmp_mem += bm->BytesPerRow;
|
||||
}
|
||||
}
|
||||
else {
|
||||
plane_mask &= (cur_plane ^ 0xFF);
|
||||
}
|
||||
cur_plane <<= 1;
|
||||
template_addr += output_plane_size;
|
||||
}
|
||||
|
||||
WRITESHORT(RTG_X1, (x & 0x07));
|
||||
WRITESHORT(RTG_X2, dx);
|
||||
WRITESHORT(RTG_X3, w);
|
||||
WRITESHORT(RTG_Y1, 0);
|
||||
WRITESHORT(RTG_Y2, dy);
|
||||
WRITESHORT(RTG_Y3, h);
|
||||
|
||||
WRITESHORT(RTG_U1, (plane_mask << 8 | ff_mask));
|
||||
WRITEBYTE(RTG_U83, bm->Depth);
|
||||
|
||||
WRITESHORT(RTG_COMMAND, RTGCMD_P2D);
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user