From: beeanyew Date: Thu, 3 Jun 2021 06:35:38 +0000 (+0200) Subject: Add iRTG implementation for BlitTemplate, clean up BlitTemplate RTG code X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=46520d9b224c013f38d3eb09854440754b014dc6;p=pistorm Add iRTG implementation for BlitTemplate, clean up BlitTemplate RTG code --- diff --git a/platforms/amiga/rtg/irtg_structs.h b/platforms/amiga/rtg/irtg_structs.h index 3fd3e9b..1b4de36 100644 --- a/platforms/amiga/rtg/irtg_structs.h +++ b/platforms/amiga/rtg/irtg_structs.h @@ -12,6 +12,23 @@ struct P96Line { uint16_t Xorigin, Yorigin; }; +struct P96Template { + uint32_t _p_Memory; + uint16_t BytesPerRow; + uint8_t XOffset; + uint8_t DrawMode; + uint32_t FgPen; + uint32_t BgPen; +}; + +struct P96Pattern { + uint32_t _p_Memory; + uint16_t XOffset, YOffset; + uint32_t FgPen, BgPen; + uint8_t Size; // Width: 16, Height: (1<= (PIGFX_RTG_BASE + PIGFX_REG_SIZE)) { - sptr = &rtg_mem[src_addr - (PIGFX_RTG_BASE + PIGFX_REG_SIZE)]; + sptr = get_mapped_data_pointer_by_address(cfg, src_addr); + if (!sptr) { if (realtime_graphics_debug) { - printf("Origin: %.8X\n", rtg_address[2]); - printf("Grabbing data from RTG memory.\nData:\n"); - for (int i = 0; i < h; i++) { - for (int j = 0; j < t_pitch; j++) { - printf("%.2X", sptr[j + (i * t_pitch)]); - } - printf("\n"); - } -#ifndef FAKESTORM - printf("Data available at origin:\n"); - for (int i = 0; i < h; i++) { - for (int j = 0; j < w; j++) { - printf("%.2X", read8(rtg_address[2] + j + (i * t_pitch))); - } - printf("\n"); - } -#endif + printf("BlitTemplate pattern data NOT available in mapped range, source address: $%.8X\n", src_addr); } - } - 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]]; - if (realtime_graphics_debug) { - printf("Grabbing data from maping %d - offset %.8lX\nData:\n", i, src_addr - cfg->map_offset[i]); - for (int i = 0; i < h; i++) { - for (int j = 0; j < t_pitch; j++) { - printf("%.2X", sptr[j + (i * t_pitch)]); - } - printf("\n"); - } - } - } - else { - printf("BlitTemplate: Failed to find mapped range for address %.8X\n", src_addr); - return; + } else { + if (realtime_graphics_debug) { + printf("BlitTemplate pattern data available in mapped range at $%.8X\n", src_addr); } } 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++) { + TEMPLATE_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); @@ -332,7 +298,6 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s xs--; cur_bit = 0x80; } - TEMPLATE_LOOPX; } TEMPLATE_LOOPY; } @@ -342,6 +307,7 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s 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) { if (mask == 0xFF || format != RTGFMT_8BIT) { SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format); @@ -366,7 +332,6 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s xs--; cur_bit = 0x80; } - TEMPLATE_LOOPX; } TEMPLATE_LOOPY; } @@ -376,6 +341,7 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s 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) { INVERT_RTG_PIXELS(&dptr[xs << format], format) xs += 7; @@ -391,7 +357,6 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s xs--; cur_bit = 0x80; } - TEMPLATE_LOOPX; } TEMPLATE_LOOPY; } diff --git a/platforms/amiga/rtg/rtg.c b/platforms/amiga/rtg/rtg.c index 45d8e57..841e716 100644 --- a/platforms/amiga/rtg/rtg.c +++ b/platforms/amiga/rtg/rtg.c @@ -8,6 +8,7 @@ #include #include "irtg_structs.h" #include "config_file/config_file.h" +#include "gpio/ps_protocol.h" #include "rtg.h" #include "m68k.h" @@ -355,6 +356,42 @@ static void handle_irtg_command(uint32_t cmd) { gdebug("iBlitRectNoMaskComplete end\n"); break; } + case RTGCMD_BLITTEMPLATE: { + // 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) + break; + + uint16_t t_pitch = 0, x_offset = 0; + uint32_t src_addr = M68KR(M68K_REG_A2); + uint32_t fgcol = 0, bgcol = 0; + uint8_t draw_mode = 0; + + struct P96Template *t = (struct P96Template *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A2)); + if (t) { + t_pitch = be16toh(t->BytesPerRow); + fgcol = be32toh(t->FgPen); + bgcol = be32toh(t->BgPen); + x_offset = be16toh(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)); + draw_mode = ps_read_8(src_addr + (uint32_t)&t->DrawMode); + src_addr = be32toh(ps_read_32(src_addr + (uint32_t)&t->_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_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); + break; + } default: printf("[!!!IRTG] Unnkonw/unhandled iRTG command %d.\n", cmd); break; diff --git a/platforms/amiga/rtg/rtg.h b/platforms/amiga/rtg/rtg.h index 51ef2b9..5875e14 100644 --- a/platforms/amiga/rtg/rtg.h +++ b/platforms/amiga/rtg/rtg.h @@ -56,11 +56,14 @@ void rtg_p2d (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t dptr += pitch; #define TEMPLATE_LOOPX \ - tmpl_x++; \ - cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x]; \ + if (sptr) { cur_byte = sptr[tmpl_x]; } \ + else { cur_byte = ps_read_8(src_addr + tmpl_x); } \ + if (invert) { cur_byte ^= 0xFF; } \ + tmpl_x++; #define TEMPLATE_LOOPY \ sptr += t_pitch; \ + src_addr += t_pitch; \ dptr += pitch; \ tmpl_x = offset_x / 8; \ cur_bit = base_bit; diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c b/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c index 996dffd..ebe9790 100644 --- a/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c +++ b/platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c @@ -552,6 +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 if (!r || !t) return; if (w < 1 || h < 1) return; @@ -584,6 +585,9 @@ void BlitTemplate (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), WRITEBYTE(RTG_U81, mask); WRITEBYTE(RTG_U82, t->DrawMode); WRITESHORT(RTG_COMMAND, RTGCMD_BLITTEMPLATE); +#else + IWRITECMD(RTGCMD_BLITTEMPLATE); +#endif } 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)) { diff --git a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card index d5f5d5d..0d89952 100644 Binary files a/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card and b/platforms/amiga/rtg/rtg_driver_amiga/pigfx020i.card differ