From: beeanyew Date: Thu, 3 Jun 2021 09:06:37 +0000 (+0200) Subject: Fix iRTG BlitTemplate add iRTG BlitPattern support X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=86f99314c67c25ac34877d27180217f81e42001e;p=pistorm Fix iRTG BlitTemplate add iRTG BlitPattern support --- diff --git a/platforms/amiga/rtg/irtg_structs.h b/platforms/amiga/rtg/irtg_structs.h index 1b4de36..4ab09c1 100644 --- a/platforms/amiga/rtg/irtg_structs.h +++ b/platforms/amiga/rtg/irtg_structs.h @@ -12,6 +12,7 @@ struct P96Line { uint16_t Xorigin, Yorigin; }; +#pragma pack(2) struct P96Template { uint32_t _p_Memory; uint16_t BytesPerRow; @@ -21,6 +22,7 @@ struct P96Template { uint32_t BgPen; }; +#pragma pack(2) struct P96Pattern { uint32_t _p_Memory; uint16_t XOffset, YOffset; diff --git a/platforms/amiga/rtg/rtg-gfx.c b/platforms/amiga/rtg/rtg-gfx.c index 1d65555..7334854 100644 --- a/platforms/amiga/rtg/rtg-gfx.c +++ b/platforms/amiga/rtg/rtg-gfx.c @@ -260,11 +260,11 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s sptr = get_mapped_data_pointer_by_address(cfg, src_addr); if (!sptr) { if (realtime_graphics_debug) { - printf("BlitTemplate pattern data NOT available in mapped range, source address: $%.8X\n", src_addr); + printf("BlitTemplate data NOT available in mapped range, source address: $%.8X\n", src_addr); } } else { if (realtime_graphics_debug) { - printf("BlitTemplate pattern data available in mapped range at $%.8X\n", src_addr); + printf("BlitTemplate data available in mapped range at $%.8X\n", src_addr); } } @@ -304,8 +304,6 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s return; case DRAWMODE_JAM2: for (uint16_t ys = 0; ys < h; ys++) { - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; - for (int xs = 0; xs < w; xs++) { TEMPLATE_LOOPX; if (w >= 8 && cur_bit == 0x80 && xs < w - 8) { @@ -338,8 +336,6 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s return; case DRAWMODE_COMPLEMENT: for (uint16_t ys = 0; ys < h; ys++) { - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; - for (int xs = 0; xs < w; xs++) { TEMPLATE_LOOPX; if (w >= 8 && cur_bit == 0x80 && xs < w - 8) { @@ -364,7 +360,7 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s } } -void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t src_addr, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t format, uint16_t offset_x, uint16_t offset_y, uint8_t mask, uint8_t draw_mode, uint8_t loop_rows) { +void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t src_addr_, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t format, uint16_t offset_x, uint16_t offset_y, uint8_t mask, uint8_t draw_mode, uint8_t loop_rows) { if (mask) {} uint8_t *dptr = &rtg_mem[rtg_address_adj[1] + (x << format) + (y * pitch)]; @@ -372,6 +368,8 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr uint8_t cur_bit = 0, base_bit = 0, cur_byte = 0; uint8_t invert = (draw_mode & DRAWMODE_INVERSVID); uint16_t tmpl_x = 0; + uint32_t src_addr = src_addr_; + uint32_t src_addr_base = src_addr; draw_mode &= 0x03; @@ -390,28 +388,25 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr }; - if (src_addr >= (PIGFX_RTG_BASE + PIGFX_REG_SIZE)) - sptr = &rtg_mem[src_addr - (PIGFX_RTG_BASE + PIGFX_REG_SIZE)]; - else { - int i = get_mapped_item_by_address(cfg, src_addr); - if (i != -1) { - sptr = &cfg->map_data[i][src_addr - cfg->map_offset[i]]; + sptr = get_mapped_data_pointer_by_address(cfg, src_addr); + if (!sptr) { + if (realtime_graphics_debug) { + printf("BlitPattern data NOT available in mapped range, source address: $%.8X\n", src_addr); + src_addr += (offset_y % loop_rows) * 2; } - else { - printf("BlitPattern: Failed to find mapped range for address %.8X\n", src_addr); - return; + } else { + if (realtime_graphics_debug) { + printf("BlitPattern data available in mapped range at $%.8X\n", src_addr); } + sptr_base = sptr; + sptr += (offset_y % loop_rows) * 2; } - sptr_base = sptr; - sptr += (offset_y % loop_rows) * 2; - switch (draw_mode) { case DRAWMODE_JAM1: for (uint16_t ys = 0; ys < h; ys++) { - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; - for (int xs = 0; xs < w; xs++) { + PATTERN_LOOPX; if (w >= 8 && cur_bit == 0x80 && xs < w - 8) { if (mask == 0xFF || format != RTGFMT_8BIT) { SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format); @@ -437,16 +432,14 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr xs--; cur_bit = 0x80; } - PATTERN_LOOPX; } PATTERN_LOOPY; } return; case DRAWMODE_JAM2: for (uint16_t ys = 0; ys < h; ys++) { - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; - for (int xs = 0; xs < w; xs++) { + PATTERN_LOOPX; if (w >= 8 && cur_bit == 0x80 && xs < w - 8) { if (mask == 0xFF || format != RTGFMT_8BIT) { SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format); @@ -471,16 +464,14 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr xs--; cur_bit = 0x80; } - PATTERN_LOOPX; } PATTERN_LOOPY; } return; case DRAWMODE_COMPLEMENT: for (uint16_t ys = 0; ys < h; ys++) { - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; - for (int xs = 0; xs < w; xs++) { + PATTERN_LOOPX; if (w >= 8 && cur_bit == 0x80 && xs < w - 8) { INVERT_RTG_PIXELS(&dptr[xs << format], format) xs += 7; @@ -496,7 +487,6 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr xs--; cur_bit = 0x80; } - PATTERN_LOOPX; } PATTERN_LOOPY; } diff --git a/platforms/amiga/rtg/rtg.c b/platforms/amiga/rtg/rtg.c index 841e716..0d97b28 100644 --- a/platforms/amiga/rtg/rtg.c +++ b/platforms/amiga/rtg/rtg.c @@ -357,11 +357,12 @@ static void handle_irtg_command(uint32_t cmd) { break; } case RTGCMD_BLITTEMPLATE: { - // A0: BoardInfo *b, A1: RenderInfo *r, A2 Template *t + // A0: BoardInfo *b, A1: RenderInfo *r, A2: Template *t // D0: WORD x, D1: WORD y, D2: WORD w, D3: WORD h // D4: UBYTE mask, D7: RGBFTYPE format - if (!r) + if (!r || !M68KR(M68K_REG_A2)) break; + gdebug("iBlitTemplate begin\n"); uint16_t t_pitch = 0, x_offset = 0; uint32_t src_addr = M68KR(M68K_REG_A2); @@ -373,14 +374,14 @@ static void handle_irtg_command(uint32_t cmd) { t_pitch = be16toh(t->BytesPerRow); fgcol = be32toh(t->FgPen); bgcol = be32toh(t->BgPen); - x_offset = be16toh(t->XOffset); + x_offset = t->XOffset; draw_mode = t->DrawMode; src_addr = be32toh(t->_p_Memory); } else { t_pitch = be16toh(ps_read_16(src_addr + (uint32_t)&t->BytesPerRow)); fgcol = be32toh(ps_read_32(src_addr + (uint32_t)&t->FgPen)); bgcol = be32toh(ps_read_32(src_addr + (uint32_t)&t->BgPen)); - x_offset = be16toh(ps_read_16(src_addr + (uint32_t)&t->XOffset)); + x_offset = ps_read_8(src_addr + (uint32_t)&t->XOffset); draw_mode = ps_read_8(src_addr + (uint32_t)&t->DrawMode); src_addr = be32toh(ps_read_32(src_addr + (uint32_t)&t->_p_Memory)); } @@ -390,6 +391,47 @@ static void handle_irtg_command(uint32_t cmd) { rtg_address_adj[1] = rtg_address[1] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE); rtg_blittemplate(M68KR(M68K_REG_D0), M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D3), src_addr, fgcol, bgcol, CMD_PITCH, t_pitch, RGBF_D7, x_offset, cmd_mask, draw_mode); + gdebug("iBlitTemplate end\n"); + break; + } + case RTGCMD_BLITPATTERN: { + // A0: BoardInfo *b, A1: RenderInfo *r, A2: Pattern *p + // D0: WORD x, D1: WORD y, D2: WORD w, D3: WORD h + // D4: UBYTE mask, D7: RGBFTYPE format + if (!r || !M68KR(M68K_REG_A2)) + break; + gdebug("iBlitPattern begin\n"); + + uint16_t x_offset = 0, y_offset = 0; + uint32_t src_addr = M68KR(M68K_REG_A2); + uint32_t fgcol = 0, bgcol = 0; + uint8_t draw_mode = 0, loop_rows = 0; + + struct P96Pattern *p = (struct P96Pattern *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A2)); + if (p) { + fgcol = be32toh(p->FgPen); + bgcol = be32toh(p->BgPen); + x_offset = be16toh(p->XOffset); + y_offset = be16toh(p->YOffset); + draw_mode = p->DrawMode; + loop_rows = 1 << p->Size; + src_addr = be32toh(p->_p_Memory); + } else { + fgcol = be32toh(ps_read_32(src_addr + (uint32_t)&p->FgPen)); + bgcol = be32toh(ps_read_32(src_addr + (uint32_t)&p->BgPen)); + x_offset = be16toh(ps_read_16(src_addr + (uint32_t)&p->XOffset)); + y_offset = be16toh(ps_read_16(src_addr + (uint32_t)&p->YOffset)); + draw_mode = ps_read_8(src_addr + (uint32_t)&p->DrawMode); + loop_rows = 1 << ps_read_8(src_addr + (uint32_t)&p->Size); + src_addr = be32toh(p->_p_Memory); + } + + cmd_mask = (uint8_t)M68KR(M68K_REG_D4); + rtg_address[1] = be32toh(r->_p_Memory); + rtg_address_adj[1] = rtg_address[1] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE); + + rtg_blitpattern(M68KR(M68K_REG_D0), M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D3), src_addr, fgcol, bgcol, CMD_PITCH, RGBF_D7, x_offset, y_offset, cmd_mask, draw_mode, loop_rows); + gdebug("iBlitPattern end\n"); break; } default: diff --git a/platforms/amiga/rtg/rtg.h b/platforms/amiga/rtg/rtg.h index 5875e14..63decc7 100644 --- a/platforms/amiga/rtg/rtg.h +++ b/platforms/amiga/rtg/rtg.h @@ -44,25 +44,30 @@ void rtg_p2c (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t 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; \ - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; \ + if (sptr) { cur_byte = sptr[tmpl_x]; } \ + else { cur_byte = m68k_read_memory_8(src_addr + tmpl_x); } \ + if (invert) { cur_byte ^= 0xFF; } \ + tmpl_x ^= 0x01; #define PATTERN_LOOPY \ sptr += 2 ; \ - if ((ys + offset_y + 1) % loop_rows == 0) \ - sptr = sptr_base; \ + src_addr += 2; \ + if ((ys + offset_y + 1) % loop_rows == 0) { \ + if (sptr) sptr = sptr_base; \ + src_addr = src_addr_base; \ + } \ tmpl_x = (offset_x / 8) % 2; \ cur_bit = base_bit; \ dptr += pitch; #define TEMPLATE_LOOPX \ if (sptr) { cur_byte = sptr[tmpl_x]; } \ - else { cur_byte = ps_read_8(src_addr + tmpl_x); } \ + else { cur_byte = m68k_read_memory_8(src_addr + tmpl_x); } \ if (invert) { cur_byte ^= 0xFF; } \ tmpl_x++; #define TEMPLATE_LOOPY \ - sptr += t_pitch; \ + if (sptr) sptr += t_pitch; \ src_addr += t_pitch; \ dptr += pitch; \ tmpl_x = offset_x / 8; \ diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c b/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c index ebe9790..9af64be 100644 --- a/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c +++ b/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c @@ -552,7 +552,7 @@ void BlitRectNoMaskComplete (__REGA0(struct BoardInfo *b), __REGA1(struct Render } void BlitTemplate (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Template *t), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format)) { -#ifndef IRTG +#ifndef IRTG if (!r || !t) return; if (w < 1 || h < 1) return; @@ -591,6 +591,7 @@ void BlitTemplate (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), } void BlitPattern (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Pattern *p), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(UBYTE mask), __REGD7(RGBFTYPE format)) { +#ifndef IRTG if (!r || !p) return; if (w < 1 || h < 1) return; @@ -623,6 +624,9 @@ void BlitPattern (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), _ WRITEBYTE(RTG_U82, p->DrawMode); WRITEBYTE(RTG_U83, (1 << p->Size)); WRITESHORT(RTG_COMMAND, RTGCMD_BLITPATTERN); +#else + IWRITECMD(RTGCMD_BLITPATTERN); +#endif } void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format)) { diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card index 0d89952..b837484 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card differ