iRTG initial implementation

Reworked PiGFX .card driver to build using m68k-amigaos-gcc instead of VBCC
Add some iRTG accelerated functionality to rtg.c
Move rtg_enums.h to match other Amiga driver build setups
pigfx020i.card must be used to enable iRTG usage
This commit is contained in:
beeanyew
2021-06-02 16:10:23 +02:00
parent 257996ca05
commit b1a449ddbf
14 changed files with 1432 additions and 939 deletions

View File

@@ -0,0 +1,299 @@
struct P96Line {
int16_t X, Y;
uint16_t Length;
int16_t dX, dY;
int16_t sDelta, lDelta, twoSDminusLD;
uint16_t LinePtrn;
uint16_t PatternShift;
uint32_t FgPen, BgPen;
uint16_t Horizontal;
uint8_t DrawMode;
int8_t pad;
uint16_t Xorigin, Yorigin;
};
struct MinNode_placeholder {
uint32_t _p_mln_Succ;
uint32_t _p_mln_Pred;
};
#pragma pack(2)
struct Node_placeholder {
uint32_t _p_ln_Succ;
uint32_t _p_ln_Pred;
uint8_t shit[2];
uint32_t _p_ln_Name;
};
struct MinList_placeholder {
uint32_t _p_mlh_Head;
uint32_t _p_mlh_Tail;
uint32_t _p_mlh_TailPred;
};
struct List_placeholder {
uint32_t _p_lh_Head;
uint32_t _p_lh_Tail;
uint32_t _p_lh_TailPred;
uint8_t lh_Type;
uint8_t l_pad;
};
struct SemaphoreRequest_placeholder {
struct MinNode_placeholder sr_Link;
uint32_t _p_sr_Waiter;
};
struct SignalSemaphore_placeholder {
struct Node_placeholder ss_Link;
int16_t ss_NestCount;
struct MinList_placeholder ss_WaitQueue;
struct SemaphoreRequest_placeholder ss_MultipleLink;
uint32_t _p_ss_Owner;
int16_t ss_QueueCount;
};
struct Interrupt_placeholder {
struct Node_placeholder is_Node;
uint32_t _p_is_Data;
uint32_t _p_is_Code;
};
struct MsgPort_placeholder {
struct Node_placeholder mp_Node;
uint8_t mp_Flags;
uint8_t mp_SigBit;
uint32_t _p_mp_SigTask;
struct List_placeholder mp_MsgList;
};
struct Rectangle {
int16_t MinX,MinY;
int16_t MaxX,MaxY;
};
struct CLUTEntry {
uint8_t Red;
uint8_t Green;
uint8_t Blue;
};
struct timeval_placeholder {
uint32_t tv_secs;
uint32_t tv_micro;
};
#define MAXMODES 5
struct ModeInfo_placeholder {
struct Node_placeholder Node;
int16_t OpenCount;
uint32_t Active;
uint16_t Width;
uint16_t Height;
uint8_t Depth;
uint8_t Flags;
uint16_t HorTotal;
uint16_t HorBlankSize;
uint16_t HorSyncStart;
uint16_t HorSyncSize;
uint8_t HorSyncSkew;
uint8_t HorEnableSkew;
uint16_t VerTotal;
uint16_t VerBlankSize;
uint16_t VerSyncStart;
uint16_t VerSyncSize;
union {
uint8_t Clock;
uint8_t Numerator;
} pll1;
union {
uint8_t ClockDivide;
uint8_t Denominator;
} pll2;
uint32_t PixelClock;
};
struct P96RenderInfo {
uint32_t _p_Memory;
int16_t BytesPerRow;
int16_t pad;
uint32_t RGBFormat;
};
struct P96BoardInfo{
uint32_t _p_RegisterBase, _p_MemoryBase, _p_MemoryIOBase;
uint32_t MemorySize;
uint32_t _p_BoardName;
int8_t VBIName[32];
uint32_t _p_CardBase;
uint32_t _p_ChipBase;
uint32_t _p_ExecBase;
uint32_t _p_UtilBase;
struct Interrupt_placeholder HardInterrupt;
struct Interrupt_placeholder SoftInterrupt;
struct SignalSemaphore_placeholder BoardLock;
struct MinList_placeholder ResolutionsList;
uint32_t BoardType;
uint32_t PaletteChipType;
uint32_t GraphicsControllerType;
uint16_t MoniSwitch;
uint16_t BitsPerCannon;
uint32_t Flags;
uint16_t SoftSpriteFlags;
uint16_t ChipFlags;
uint32_t CardFlags;
uint16_t BoardNum;
uint16_t RGBFormats;
uint16_t MaxHorValue[MAXMODES];
uint16_t MaxVerValue[MAXMODES];
uint16_t MaxHorResolution[MAXMODES];
uint16_t MaxVerResolution[MAXMODES];
uint32_t MaxMemorySize, MaxChunkSize;
uint32_t MemoryClock;
uint32_t PixelClockCount[MAXMODES];
uint32_t _p_AllocCardMem;
uint32_t _p_FreeCardMem;
uint32_t _p_SetSwitch;
uint32_t _p_SetColorArray;
uint32_t _p_SetDAC;
uint32_t _p_SetGC;
uint32_t _p_SetPanning;
uint32_t _p_CalculateBytesPerRow;
uint32_t _p_CalculateMemory;
uint32_t _p_GetCompatibleFormats;
uint32_t _p_SetDisplay;
uint32_t _p_ResolvePixelClock;
uint32_t _p_GetPixelClock;
uint32_t _p_SetClock;
uint32_t _p_SetMemoryMode;
uint32_t _p_SetWriteMask;
uint32_t _p_SetClearMask;
uint32_t _p_SetReadPlane;
uint32_t _p_WaitVerticalSync;
uint32_t _p_SetInterrupt;
uint32_t _p_WaitBlitter;
uint32_t _p_ScrollPlanar;
uint32_t _p_ScrollPlanarDefault;
uint32_t _p_UpdatePlanar;
uint32_t _p_UpdatePlanarDefault;
uint32_t _p_BlitPlanar2Chunky;
uint32_t _p_BlitPlanar2ChunkyDefault;
uint32_t _p_FillRect;
uint32_t _p_FillRectDefault;
uint32_t _p_InvertRect;
uint32_t _p_InvertRectDefault;
uint32_t _p_BlitRect;
uint32_t _p_BlitRectDefault;
uint32_t _p_BlitTemplate;
uint32_t _p_BlitTemplateDefault;
uint32_t _p_BlitPattern;
uint32_t _p_BlitPatternDefault;
uint32_t _p_DrawLine;
uint32_t _p_DrawLineDefault;
uint32_t _p_BlitRectNoMaskComplete;
uint32_t _p_BlitRectNoMaskCompleteDefault;
uint32_t _p_BlitPlanar2Direct;
uint32_t _p_BlitPlanar2DirectDefault;
uint32_t _p_EnableSoftSprite;
uint32_t _p_EnableSoftSpriteDefault;
uint32_t _p_AllocCardMemAbs;
uint32_t _p_SetSplitPosition;
uint32_t _p_ReInitMemory;
uint32_t _p_Reserved2Default;
uint32_t _p_Reserved3;
uint32_t _p_Reserved3Default;
uint32_t _p_WriteYUVRect;
uint32_t _p_WriteYUVRectDefault;
uint32_t _p_GetVSyncState;
uint32_t _p_GetVBeamPos;
uint32_t _p_SetDPMSLevel;
uint32_t _p_ResetChip;
uint32_t _p_GetFeatureAttrs;
uint32_t _p_AllocBitMap;
uint32_t _p_FreeBitMap;
uint32_t _p_GetBitMapAttr;
uint32_t _p_SetSprite;
uint32_t _p_SetSpritePosition;
uint32_t _p_SetSpriteImage;
uint32_t _p_SetSpriteColor;
uint32_t _p_CreateFeature;
uint32_t _p_SetFeatureAttrs;
uint32_t _p_DeleteFeature;
struct MinList_placeholder SpecialFeatures;
uint32_t _p_ModeInfo;
uint32_t RGBFormat;
int16_t XOffset;
int16_t YOffset;
uint8_t Depth;
uint8_t ClearMask;
uint16_t Border;
uint32_t Mask;
uint8_t CLUT[256 * 3];
uint32_t _p_ViewPort;
uint32_t _p_VisibleBitMap;
uint32_t _p_BitMapExtra;
struct MinList_placeholder BitMapList;
struct MinList_placeholder MemList;
int16_t MouseX;
int16_t MouseY;
uint8_t MouseWidth;
uint8_t MouseHeight;
uint8_t MouseXOffset;
uint8_t MouseYOffset;
uint32_t _p_MouseImage;
uint8_t MousePens[4];
struct Rectangle MouseRect;
uint32_t _p_MouseChunky;
uint32_t _p_MouseRendered;
uint32_t _p_MouseSaveBuffer;
uint32_t ChipData[16];
uint32_t CardData[16];
uint32_t _p_MemorySpaceBase;
uint32_t MemorySpaceSize;
uint32_t _p_DoubleBufferList;
struct timeval_placeholder SyncTime;
uint32_t SyncPeriod;
struct MsgPort_placeholder SoftVBlankPort;
struct MinList_placeholder WaitQ;
int32_t EssentialFormats;
uint32_t _p_MouseImageBuffer;
uint32_t _p_backViewPort;
uint32_t _p_backBitMap;
uint32_t _p_backExtra;
int16_t YSplit;
uint32_t MaxPlanarMemory;
uint32_t MaxBMWidth;
uint32_t MaxBMHeight;
};

View File

@@ -17,6 +17,9 @@ extern uint16_t rtg_display_format;
extern uint16_t rtg_user[8];
extern uint16_t rtg_x[8], rtg_y[8];
extern uint32_t framebuffer_addr;
extern uint32_t framebuffer_addr_adj;
extern uint8_t realtime_graphics_debug;
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) {
@@ -56,7 +59,7 @@ void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color
for (int ys = 0; ys < h; ys++) {
for (int xs = 0; xs < w; xs++) {
SET_RTG_PIXEL_MASK(&dptr[xs], (color & 0xFF), format);
SET_RTG_PIXEL_MASK(&dptr[xs << format], (color & 0xFF), format);
}
dptr += pitch;
}

View File

@@ -179,6 +179,9 @@ reinit_raylib:;
} else if (GetScreenHeight() == 1080) {
dstscale.width = 1440;
dstscale.height = 1080;
} else if (GetScreenHeight() == 1200) {
dstscale.width = 1600;
dstscale.height = 1200;
}
} else {
while (dstscale.height + height <= GetScreenHeight()) {

View File

@@ -6,9 +6,12 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "irtg_structs.h"
#include "config_file/config_file.h"
#include "rtg.h"
#include "m68k.h"
uint8_t rtg_u8[4];
uint16_t rtg_x[8], rtg_y[8];
uint16_t rtg_user[8];
@@ -30,28 +33,34 @@ uint32_t framebuffer_addr = 0;
uint32_t framebuffer_addr_adj = 0;
static void handle_rtg_command(uint32_t cmd);
//static struct timespec f1, f2;
static void handle_irtg_command(uint32_t cmd);
uint8_t realtime_graphics_debug = 0;
extern int cpu_emulation_running;
extern struct emulator_config *cfg;
extern uint8_t rtg_on;
/*
static const char *op_type_names[OP_TYPE_NUM] = {
//#define DEBUG_RTG
#ifdef DEBUG_RTG
/*static const char *op_type_names[OP_TYPE_NUM] = {
"BYTE",
"WORD",
"LONGWORD",
"MEM",
};
};*/
static const char *rtg_format_names[RTGFMT_NUM] = {
/*static const char *rtg_format_names[RTGFMT_NUM] = {
"8BPP CLUT",
"16BPP RGB (565)",
"32BPP RGB (RGBA)",
"15BPP RGB (555)",
};
*/
};*/
#define DEBUG printf
#else
#define DEBUG(...)
#endif
int init_rtg_data(struct emulator_config *cfg_) {
rtg_mem = calloc(1, 40 * SIZE_MEGA);
if (!rtg_mem) {
@@ -142,8 +151,9 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
return;
}
}
}
else {
} else if (address == RTG_DEBUGME) {
printf("RTG DEBUGME WRITE: %d.\n", value);
} else {
switch (mode) {
case OP_TYPE_BYTE:
switch (address) {
@@ -171,6 +181,9 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
case RTG_COMMAND:
handle_rtg_command(value);
break;
case IRTG_COMMAND:
handle_irtg_command(value);
break;
}
break;
case OP_TYPE_LONGWORD:
@@ -196,6 +209,157 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
}
#define gdebug(a) if (realtime_graphics_debug) { printf(a); m68k_end_timeslice(); cpu_emulation_running = 0; }
#define M68KR(a) m68k_get_reg(NULL, a)
#define RGBF_D7 rgbf_to_rtg[M68KR(M68K_REG_D7)]
#define CMD_PITCH be16toh(r->BytesPerRow)
static struct P96RenderInfo *r;
static struct P96BoardInfo *b;
static struct P96Line *ln;
static uint8_t cmd_mask;
static void handle_irtg_command(uint32_t cmd) {
b = (struct P96BoardInfo *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A0));
r = (struct P96RenderInfo *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A1));
switch (cmd) {
case RTGCMD_SETPAN: {
// A0: struct BoardInfo *b, A1: UBYTE *addr, D0 UWORD width, D1: WORD x_offset, D2: WORD y_offset, D7: RGBFTYPE format
#ifdef DEBUG_RTG
if (realtime_graphics_debug) {
printf("iSetPanning begin\n");
printf("IRTGCmd SetPanning\n");
printf("IRTGCmd x: %d y: %d w: %d (%d)\n", M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D0) << RGBF_D7, M68KR(M68K_REG_D0));
printf("BoardInfo: %.8X Addr: %.8X\n", M68KR(M68K_REG_A0), M68KR(M68K_REG_A1));
printf("BoardInfo Xoffs: %d Yoffs: %d\n", be16toh(b->XOffset), be16toh(b->YOffset));
}
#endif
if (!b) break;
b->XOffset = (int16_t)htobe16(M68KR(M68K_REG_D1));
b->YOffset = (int16_t)htobe16(M68KR(M68K_REG_D2));
rtg_offset_x = M68KR(M68K_REG_D1);
rtg_offset_y = M68KR(M68K_REG_D2);
rtg_pitch = (M68KR(M68K_REG_D0) << RGBF_D7);
framebuffer_addr = M68KR(M68K_REG_A1) - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << RGBF_D7) + (rtg_offset_y * rtg_pitch);
#ifdef DEBUG_RTG
if (realtime_graphics_debug) {
printf("RTG OffsetX/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
printf("RTG Pitch: %d\n", rtg_pitch);
printf("RTG FBAddr/Adj: %.8X (%.8X)/%.8X\n", framebuffer_addr, M68KR(M68K_REG_A1), framebuffer_addr_adj);
printf("iSetPanning End\n");
}
#endif
break;
}
case RTGCMD_DRAWLINE: {
// A0: struct BoardInfo *b, A1: RenderInfo *r A2: struct Line *l, D0: UBYTE mask, D7: RGBFTYPE format
gdebug("iDrawLine begin\n");
ln = (struct P96Line *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A2));
if (!ln || !r) break;
cmd_mask = (uint8_t)M68KR(M68K_REG_D0);
rtg_address_adj[0] = be32toh(r->_p_Memory) - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
if (cmd_mask == 0xFF && be16toh(ln->LinePtrn) == 0xFFFF) {
rtg_drawline_solid(be16toh(ln->X), be16toh(ln->Y), be16toh(ln->dX), be16toh(ln->dY),
be16toh(ln->Length), be32toh(ln->FgPen), CMD_PITCH, RGBF_D7);
} else {
rtg_drawline(be16toh(ln->X), be16toh(ln->Y), be16toh(ln->dX), be16toh(ln->dY),
be16toh(ln->Length), be16toh(ln->LinePtrn), be16toh(ln->PatternShift),
be32toh(ln->FgPen), be32toh(ln->BgPen), CMD_PITCH,
RGBF_D7, cmd_mask, ln->DrawMode);
}
gdebug("iDrawLine end\n");
break;
}
case RTGCMD_FILLRECT: {
// A0: BoardInfo *b, A1: RenderInfo *r
// D0 WORD x, D1: WORD y, D2: WORD w, D3: WORD h
// D4: ULONG color, D5: UBYTE mask, D7: RGBFTYPE format
gdebug("iFillRect begin\n");
#ifdef DEBUG_RTG
if (realtime_graphics_debug) {
DEBUG("X1/X2: %d/%d-> X2/Y2: %d/%d\n", (int16_t)M68KR(M68K_REG_D0), (int16_t)M68KR(M68K_REG_D1), (int16_t)M68KR(M68K_REG_D2), (int16_t)M68KR(M68K_REG_D3));
DEBUG("R: %.8X B: %.8X\n", M68KR(M68K_REG_A0), M68KR(M68K_REG_A1));
}
#endif
if (!b || !r) break;
cmd_mask = (uint8_t)M68KR(M68K_REG_D5);
rtg_address_adj[0] = be32toh(r->_p_Memory) - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
if (cmd_mask == 0xFF) {
rtg_fillrect_solid((int16_t)M68KR(M68K_REG_D0), (int16_t)M68KR(M68K_REG_D1), (int16_t)M68KR(M68K_REG_D2), (int16_t)M68KR(M68K_REG_D3),
M68KR(M68K_REG_D4), CMD_PITCH, RGBF_D7);
} else {
rtg_fillrect((int16_t)M68KR(M68K_REG_D0), (int16_t)M68KR(M68K_REG_D1), (int16_t)M68KR(M68K_REG_D2), (int16_t)M68KR(M68K_REG_D3),
M68KR(M68K_REG_D4), CMD_PITCH, RGBF_D7, cmd_mask);
}
gdebug("iFillRect end\n");
break;
}
case RTGCMD_INVERTRECT: {
// A0: BoardInfo *b, A1: RenderInfo *r
// D0 WORD x, D1: WORD y, D2: WORD w, D3: WORD h
// D4: UBYTE mask, D7: RGBFTYPE format
gdebug("iInvertRect begin\n");
if (!b || !r) break;
cmd_mask = (uint8_t)M68KR(M68K_REG_D4);
rtg_address_adj[0] = be32toh(r->_p_Memory) - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
rtg_invertrect((int16_t)M68KR(M68K_REG_D0), (int16_t)M68KR(M68K_REG_D1), (int16_t)M68KR(M68K_REG_D2), (int16_t)M68KR(M68K_REG_D3), CMD_PITCH, RGBF_D7, cmd_mask);
gdebug("iInvertRect end\n");
break;
}
case RTGCMD_BLITRECT: {
// A0: BoardInfo *b, A1: RenderInfo *r)
// D0: WORD x, D1: WORD y, D2: WORD dx, D3: WORD dy, D4: WORD w, D5: WORD h,
// D6: UBYTE mask, D7: RGBFTYPE format
gdebug("iBlitRect begin\n");
cmd_mask = (uint8_t)M68KR(M68K_REG_D6);
rtg_address_adj[0] = be32toh(r->_p_Memory) - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
if (cmd_mask == 0xFF) {
rtg_blitrect_solid(M68KR(M68K_REG_D0), M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D3), M68KR(M68K_REG_D4), M68KR(M68K_REG_D5), CMD_PITCH, RGBF_D7);
} else {
rtg_blitrect(M68KR(M68K_REG_D0), M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D3), M68KR(M68K_REG_D4), M68KR(M68K_REG_D5), CMD_PITCH, RGBF_D7, cmd_mask);
}
gdebug("iBlitRect end\n");
break;
}
case RTGCMD_BLITRECT_NOMASK_COMPLETE: {
// A0: BoardInfo *b, A1: RenderInfo *rs, A2: RenderInfo *rt,
// D0: WORD x, D1: WORD y, D2: WORD dx, D3: WORD dy, D4: WORD w, D5: WORD h,
// D6: UBYTE minterm, D7: RGBFTYPE format
gdebug("iBlitRectNoMaskComplete begin\n");
uint8_t minterm = (uint8_t)M68KR(M68K_REG_D6);
struct P96RenderInfo *rt = (struct P96RenderInfo *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A2));
uint32_t src_addr = be32toh(r->_p_Memory);
uint32_t dst_addr = be32toh(rt->_p_Memory);
rtg_blitrect_nomask_complete(M68KR(M68K_REG_D0), M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D3), M68KR(M68K_REG_D4), M68KR(M68K_REG_D5),
CMD_PITCH, be16toh(rt->BytesPerRow), src_addr, dst_addr, RGBF_D7, minterm);
gdebug("iBlitRectNoMaskComplete end\n");
break;
}
default:
printf("[!!!IRTG] Unnkonw/unhandled iRTG command %d.\n", cmd);
break;
}
}
static void handle_rtg_command(uint32_t cmd) {
//printf("Handling RTG command %d (%.8X)\n", cmd, cmd);
@@ -225,10 +389,6 @@ static void handle_rtg_command(uint32_t cmd) {
rtg_pitch = (rtg_x[0] << rtg_display_format);
framebuffer_addr = rtg_address[0] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
//printf("Set panning to $%.8X (%.8X)\n", framebuffer_addr, rtg_address[0]);
//printf("(Panned: $%.8X)\n", framebuffer_addr_adj);
//printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
//printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
break;
case RTGCMD_SETCLUT: {
//printf("Command: SetCLUT.\n");
@@ -295,7 +455,7 @@ static void handle_rtg_command(uint32_t cmd) {
if (rtg_u8[0] == 0xFF && rtg_y[2] == 0xFFFF)
rtg_drawline_solid(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_rgb[0], rtg_x[3], rtg_format);
else
rtg_drawline(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[4], rtg_rgb[0], rtg_rgb[1], rtg_x[3], rtg_format, rtg_u8[0], rtg_u8[1]);
rtg_drawline(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[4], rtg_rgb[0], rtg_rgb[1], rtg_x[3], rtg_format, rtg_u8[0], rtg_u8[1]);
gdebug("DrawLine\n");
break;
case RTGCMD_P2C:

View File

@@ -9,7 +9,7 @@
#define CARD_OFFSET 0
#include "rtg_driver_amiga/rtg_enums.h"
#include "rtg_enums.h"
void rtg_write(uint32_t address, uint32_t value, uint8_t mode);
unsigned int rtg_read(uint32_t address, uint8_t mode);

View File

@@ -1,2 +0,0 @@
vc +aos68k -nostdlib -I$VBCC/targets/m68k-amigaos/include -c99 -O2 -o pigfx020.card pigfx.c -ldebug -lamiga -cpu=68020
vc +aos68k -nostdlib -I$VBCC/targets/m68k-amigaos/include -c99 -O2 -o pigfx030.card pigfx.c -ldebug -lamiga -cpu=68030

View File

@@ -1,2 +1,3 @@
vc +aos68k -nostdlib -I$VBCC/targets/m68k-amigaos/include -c99 -O2 -o pigfx020.card pigfx.c -ldebug -lamiga -cpu=68020
vc +aos68k -nostdlib -I$VBCC/targets/m68k-amigaos/include -c99 -O2 -o pigfx030.card pigfx.c -ldebug -lamiga -cpu=68030
m68k-amigaos-gcc pigfx-2.c -m68020 -O2 -o pigfx020.card -noixemul -Wall -Wextra -Wno-unused-parameter -fomit-frame-pointer -nostartfiles -lamiga
m68k-amigaos-gcc pigfx-2.c -m68030 -O2 -o pigfx030.card -noixemul -Wall -Wextra -Wno-unused-parameter -fomit-frame-pointer -nostartfiles -lamiga
m68k-amigaos-gcc pigfx-2.c -m68020 -O2 -o pigfx020i.card -noixemul -Wall -Wextra -Wno-unused-parameter -fomit-frame-pointer -nostartfiles -lamiga -DIRTG

View File

@@ -0,0 +1,841 @@
// SPDX-License-Identifier: MIT
// PiStorm RTG driver, VBCC edition.
// Based in part on the ZZ9000 RTG driver.
#include <proto/exec.h>
#include <proto/expansion.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <exec/execbase.h>
#include <exec/resident.h>
#include <exec/initializers.h>
#include <clib/debug_protos.h>
#include <string.h>
#include <stdint.h>
#include "boardinfo.h"
#include "../rtg_enums.h"
#define STR(s) #s
#define XSTR(s) STR(s)
#define CHECKRTG *((unsigned short *)(CARD_OFFSET))
#define CARD_OFFSET 0x70000000
#define IRTGCMD_OFFSET 0x70000060
#define CARD_REGSIZE 0x00010000
#define CARD_MEMSIZE 0x02000000 // 32MB "VRAM"
#define CARD_SCRATCH 0x72010000
#define WRITESHORT(cmd, val) *(unsigned short *)((unsigned long)(CARD_OFFSET+cmd)) = val;
#define WRITELONG(cmd, val) *(unsigned long *)((unsigned long)(CARD_OFFSET+cmd)) = val;
#define WRITEBYTE(cmd, val) *(unsigned char *)((unsigned long)(CARD_OFFSET+cmd)) = val;
#define READSHORT(cmd, var) var = *(volatile unsigned short *)(CARD_OFFSET + cmd);
#define READLONG(cmd, var) var = *(volatile unsigned long *)(CARD_OFFSET + cmd);
#define RTG_DEBUGME(val) *(volatile unsigned long *)((unsigned long)(CARD_OFFSET+RTG_DEBUGME)) = val;
//#define RTG_DEBUGME(...)
#define IWRITECMD(val) *(volatile unsigned short *)(IRTGCMD_OFFSET) = val;
#define CHIP_RAM_SIZE 0x00200000 // Chip RAM offset, 2MB
struct GFXBase {
struct Library libNode;
BPTR segList;
struct ExecBase* sysBase;
struct ExpansionBase* expansionBase;
};
#define __saveds__
#define kprintf(...)
struct ExecBase *SysBase;
int FindCard(__REGA0(struct BoardInfo* b));
int InitCard(__REGA0(struct BoardInfo* b));
void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border));
void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num));
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format));
UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format));
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format));
ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format));
ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format));
void SetClock (__REGA0(struct BoardInfo *b));
void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane));
void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle));
void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format));
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));
void BlitRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE mask), __REGD7(RGBFTYPE format));
void BlitRectNoMaskComplete (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *rs), __REGA2(struct RenderInfo *rt), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE minterm), __REGD7(RGBFTYPE format));
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));
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));
void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format));
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));
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 SetSprite (__REGA0(struct BoardInfo *b), __REGD0(BOOL what), __REGD7(RGBFTYPE format));
void SetSpritePosition (__REGA0(struct BoardInfo *b), __REGD0(WORD x), __REGD1(WORD y), __REGD7(RGBFTYPE format));
void SetSpriteImage (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
void SetSpriteColor (__REGA0(struct BoardInfo *b), __REGD0(UBYTE idx), __REGD1(UBYTE R), __REGD2(UBYTE G), __REGD3(UBYTE B), __REGD7(RGBFTYPE format));
#define DEVICE_VERSION 43
#define DEVICE_REVISION 20
#define DEVICE_PRIORITY 0
#define DEVICE_ID_STRING "PiGFX " XSTR(DEVICE_VERSION) "." XSTR(DEVICE_REVISION) " " DEVICE_DATE
#define DEVICE_NAME "pigfx.card"
#define DEVICE_DATE "(29 May 2021)"
int __attribute__((no_reorder)) _start()
{
return -1;
}
asm("romtag: \n"
" dc.w "XSTR(RTC_MATCHWORD)" \n"
" dc.l romtag \n"
" dc.l endcode \n"
" dc.b "XSTR(RTF_AUTOINIT)" \n"
" dc.b "XSTR(DEVICE_VERSION)" \n"
" dc.b "XSTR(NT_LIBRARY)" \n"
" dc.b "XSTR(DEVICE_PRIORITY)" \n"
" dc.l _device_name \n"
" dc.l _device_id_string \n"
" dc.l _auto_init_tables \n"
"endcode: \n");
char device_name[] = DEVICE_NAME;
char device_id_string[] = DEVICE_ID_STRING;
__saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase));
BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase));
BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb));
ULONG ExtFuncLib(void);
__saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
__REGA0(BPTR seglist),
__REGD0(struct GFXBase *exb));
#define CLOCK_HZ 100000000
static struct GFXBase *_gfxbase;
const char *gfxname = "PiStorm RTG";
char dummies[128];
__saveds struct GFXBase* __attribute__((used)) InitLib(__REGA6(struct ExecBase *sysbase),
__REGA0(BPTR seglist),
__REGD0(struct GFXBase *exb))
{
_gfxbase = exb;
SysBase = *(struct ExecBase **)4L;
return _gfxbase;
}
__saveds struct GFXBase* __attribute__((used)) OpenLib(__REGA6(struct GFXBase *gfxbase))
{
gfxbase->libNode.lib_OpenCnt++;
gfxbase->libNode.lib_Flags &= ~LIBF_DELEXP;
return gfxbase;
}
BPTR __saveds __attribute__((used)) CloseLib(__REGA6(struct GFXBase *gfxbase))
{
gfxbase->libNode.lib_OpenCnt--;
if (!gfxbase->libNode.lib_OpenCnt) {
if (gfxbase->libNode.lib_Flags & LIBF_DELEXP) {
return (ExpungeLib(gfxbase));
}
}
return 0;
}
BPTR __saveds __attribute__((used)) ExpungeLib(__REGA6(struct GFXBase *exb))
{
BPTR seglist;
struct ExecBase *SysBase = *(struct ExecBase **)4L;
if(!exb->libNode.lib_OpenCnt) {
ULONG negsize, possize, fullsize;
UBYTE *negptr = (UBYTE *)exb;
seglist = exb->segList;
Remove((struct Node *)exb);
negsize = exb->libNode.lib_NegSize;
possize = exb->libNode.lib_PosSize;
fullsize = negsize + possize;
negptr -= negsize;
FreeMem(negptr, fullsize);
return(seglist);
}
exb->libNode.lib_Flags |= LIBF_DELEXP;
return 0;
}
ULONG ExtFuncLib(void)
{
return 0;
}
#define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary((STRPTR)b,0L))==NULL) { \
kprintf((STRPTR)"Failed to load %s.\n", b); \
return 0; \
} \
int __attribute__((used)) FindCard(__REGA0(struct BoardInfo* b)) {
uint16_t card_check = CHECKRTG;
if (card_check != 0xFFCF) {
// RTG not enabled
return 0;
}
struct ExpansionBase *ExpansionBase = NULL;
struct DOSBase *DOSBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;
LOADLIB(ExpansionBase, "expansion.library");
LOADLIB(DOSBase, "dos.library");
LOADLIB(IntuitionBase, "intuition.library");
b->MemorySize = CARD_MEMSIZE;
b->RegisterBase = (void *)CARD_OFFSET;
b->MemoryBase = (void *)(CARD_OFFSET + CARD_REGSIZE);
return 1;
}
#define HWSPRITE 1
#define VGASPLIT (1 << 6)
#define FLICKERFIXER (1 << 12)
#define INDISPLAYCHAIN (1 << 20)
#define DIRECTACCESS (1 << 26)
int __attribute__((used)) InitCard(__REGA0(struct BoardInfo* b)) {
int i;
kprintf("Wueh! %ld\n", sizeof(BOOL));
b->CardBase = (struct CardBase *)_gfxbase;
b->ExecBase = SysBase;
b->BoardName = "PiStorm RTG";
b->BoardType = BT_MNT_ZZ9000;
b->PaletteChipType = PCT_MNT_ZZ9000;
b->GraphicsControllerType = GCT_MNT_ZZ9000;
b->Flags = BIF_INDISPLAYCHAIN | BIF_GRANTDIRECTACCESS | BIF_HARDWARESPRITE | BIF_FLICKERFIXER;
b->RGBFormats = 1 | 2 | 512 | 1024 | 2048;
b->SoftSpriteFlags = 0;
b->BitsPerCannon = 8;
for(i = 0; i < MAXMODES; i++) {
b->MaxHorValue[i] = 8192;
b->MaxVerValue[i] = 8192;
b->MaxHorResolution[i] = 8192;
b->MaxVerResolution[i] = 8192;
b->PixelClockCount[i] = 1;
}
b->MemoryClock = CLOCK_HZ;
//b->AllocCardMem = (void *)NULL;
//b->FreeCardMem = (void *)NULL;
b->SetSwitch = (void *)SetSwitch;
b->SetColorArray = (void *)SetColorArray;
b->SetDAC = (void *)SetDAC;
b->SetGC = (void *)SetGC;
b->SetPanning = (void *)SetPanning;
b->CalculateBytesPerRow = (void *)CalculateBytesPerRow;
b->CalculateMemory = (void *)CalculateMemory;
b->GetCompatibleFormats = (void *)GetCompatibleFormats;
b->SetDisplay = (void *)SetDisplay;
b->ResolvePixelClock = (void *)ResolvePixelClock;
b->GetPixelClock = (void *)GetPixelClock;
b->SetClock = (void *)SetClock;
b->SetMemoryMode = (void *)SetMemoryMode;
b->SetWriteMask = (void *)SetWriteMask;
b->SetClearMask = (void *)SetClearMask;
b->SetReadPlane = (void *)SetReadPlane;
b->WaitVerticalSync = (void *)WaitVerticalSync;
//b->SetInterrupt = (void *)NULL;
//b->WaitBlitter = (void *)NULL;
//b->ScrollPlanar = (void *)NULL;
//b->UpdatePlanar = (void *)NULL;
b->BlitPlanar2Chunky = (void *)BlitPlanar2Chunky;
b->BlitPlanar2Direct = (void *)BlitPlanar2Direct;
b->FillRect = (void *)FillRect;
b->InvertRect = (void *)InvertRect;
b->BlitRect = (void *)BlitRect;
b->BlitTemplate = (void *)BlitTemplate;
b->BlitPattern = (void *)BlitPattern;
b->DrawLine = (void *)DrawLine;
b->BlitRectNoMaskComplete = (void *)BlitRectNoMaskComplete;
//b->EnableSoftSprite = (void *)NULL;
//b->AllocCardMemAbs = (void *)NULL;
//b->SetSplitPosition = (void *)NULL;
//b->ReInitMemory = (void *)NULL;
//b->WriteYUVRect = (void *)NULL;
//b->GetVSyncState = (void *)NULL;
//b->GetVBeamPos = (void *)NULL;
//b->SetDPMSLevel = (void *)NULL;
//b->ResetChip = (void *)NULL;
//b->GetFeatureAttrs = (void *)NULL;
//b->AllocBitMap = (void *)NULL;
//b->FreeBitMap = (void *)NULL;
//b->GetBitMapAttr = (void *)NULL;
b->SetSprite = (void *)SetSprite;
b->SetSpritePosition = (void *)SetSpritePosition;
b->SetSpriteImage = (void *)SetSpriteImage;
b->SetSpriteColor = (void *)SetSpriteColor;
//b->CreateFeature = (void *)NULL;
//b->SetFeatureAttrs = (void *)NULL;
//b->DeleteFeature = (void *)NULL;
return 1;
}
void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
// Used to set the color format of the video card's RAMDAC.
// This needs no handling, since the PiStorm doesn't really have a RAMDAC or a video card chipset.
}
void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border)) {
b->ModeInfo = mode_info;
// Send width, height and format to the RaspberryPi Targetable Graphics.
WRITESHORT(RTG_X1, mode_info->Width);
WRITESHORT(RTG_Y1, mode_info->Height);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[b->RGBFormat]);
WRITESHORT(RTG_COMMAND, RTGCMD_SETGC);
}
int setswitch = -1;
UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
if (setswitch != enabled) {
setswitch = enabled;
}
WRITEBYTE(RTG_U81, setswitch);
WRITESHORT(RTG_X1, setswitch);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSWITCH);
return 1 - enabled;
}
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format)) {
// Set the panning offset, or the offset used for the current display area on the Pi.
// The address needs to have CARD_BASE subtracted from it to be used as an offset on the Pi side.
#ifndef IRTG
if (!b)
return;
b->XOffset = x_offset;
b->YOffset = y_offset;
WRITELONG(RTG_ADDR1, (unsigned long)addr);
WRITESHORT(RTG_X1, width);
WRITESHORT(RTG_X2, b->XOffset);
WRITESHORT(RTG_Y2, b->YOffset);
WRITESHORT(RTG_COMMAND, RTGCMD_SETPAN);
#else
IWRITECMD(RTGCMD_SETPAN);
#endif
}
void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num)) {
// Sets the color components of X color components for 8-bit paletted display modes.
if (!b->CLUT)
return;
int j = start + num;
for(int i = start; i < j; i++) {
//WRITEBYTE(RTG_U82, (unsigned char)b->CLUT[i].Red);
//WRITEBYTE(RTG_U83, (unsigned char)b->CLUT[i].Green);
//WRITEBYTE(RTG_U84, (unsigned char)b->CLUT[i].Blue);
unsigned long xrgb = 0 | (b->CLUT[i].Red << 16) | (b->CLUT[i].Green << 8) | (b->CLUT[i].Blue);
WRITEBYTE(RTG_U81, (unsigned char)i);
WRITELONG(RTG_RGB1, xrgb);
WRITESHORT(RTG_COMMAND, RTGCMD_SETCLUT);
}
}
UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format)) {
if (!b)
return 0;
UWORD pitch = width;
switch(format) {
default:
return pitch;
case 0x05: case 0x0A: case 0x0B: case 0x0D:
return (width * 2);
case 0x08: case 0x09:
return (width * 4);
}
}
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format)) {
/*if (!b)
return (APTR)addr;
if (addr > (unsigned int)b->MemoryBase && addr < (((unsigned int)b->MemoryBase) + b->MemorySize)) {
addr = ((addr + 0x1000) & 0xFFFFF000);
}*/
return (APTR)addr;
}
ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
// It is of course compatible with all the formats ever.
return 0xFFFFFFFF;
}
//static int display_enabled = 0;
UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
// Enables or disables the display.
WRITEBYTE(RTG_U82, (unsigned char)enabled);
WRITESHORT(RTG_COMMAND, RTGCMD_SETDISPLAY);
return 1;
}
LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format)) {
mode_info->PixelClock = CLOCK_HZ;
mode_info->pll1.Clock = 0;
mode_info->pll2.ClockDivide = 1;
return 0;
}
ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format)) {
// Just return 100MHz.
return CLOCK_HZ;
}
// None of these five really have to do anything.
void SetClock (__REGA0(struct BoardInfo *b)) {
}
void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
}
void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
}
void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
}
void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)) {
}
void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) {
// I don't know why this one has a bool in D0, but it isn't used for anything.
}
void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format)) {
#ifndef IRTG
if (!r)
return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITELONG(RTG_RGB1, color);
WRITESHORT(RTG_X3, r->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITESHORT(RTG_COMMAND, RTGCMD_FILLRECT);
#else
IWRITECMD(RTGCMD_FILLRECT);
#endif
}
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)) {
#ifndef IRTG
if (!r)
return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITESHORT(RTG_X3, r->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITESHORT(RTG_COMMAND, RTGCMD_INVERTRECT);
#else
IWRITECMD(RTGCMD_INVERTRECT);
#endif
}
void BlitRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE mask), __REGD7(RGBFTYPE format)) {
#ifndef IRTG
if (!r)
return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, dx);
WRITESHORT(RTG_X3, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, dy);
WRITESHORT(RTG_Y3, h);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT);
#else
IWRITECMD(RTGCMD_BLITRECT);
#endif
}
void BlitRectNoMaskComplete (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *rs), __REGA2(struct RenderInfo *rt), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE minterm), __REGD7(RGBFTYPE format)) {
#ifndef IRTG
if (!rs || !rt)
return;
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITELONG(RTG_ADDR1, (unsigned long)rs->Memory);
WRITELONG(RTG_ADDR2, (unsigned long)rt->Memory);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, dx);
WRITESHORT(RTG_X3, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, dy);
WRITESHORT(RTG_Y3, h);
WRITESHORT(RTG_X4, rs->BytesPerRow);
WRITESHORT(RTG_X5, rt->BytesPerRow);
WRITEBYTE(RTG_U81, minterm);
WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT_NOMASK_COMPLETE);
#else
IWRITECMD(RTGCMD_BLITRECT_NOMASK_COMPLETE);
#endif
}
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)) {
if (!r || !t) return;
if (w < 1 || h < 1) return;
WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_X3, t->XOffset);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITESHORT(RTG_Y3, 0);
if ((unsigned long)t->Memory > CHIP_RAM_SIZE) {
WRITELONG(RTG_ADDR1, (unsigned long)t->Memory);
}
else {
unsigned long dest = CARD_SCRATCH;
memcpy((unsigned char *)dest, t->Memory, (t->BytesPerRow * h));
WRITELONG(RTG_ADDR1, (unsigned long)dest);
WRITELONG(RTG_ADDR3, (unsigned long)t->Memory);
}
WRITELONG(RTG_RGB1, t->FgPen);
WRITELONG(RTG_RGB2, t->BgPen);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITESHORT(RTG_X5, t->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITEBYTE(RTG_U82, t->DrawMode);
WRITESHORT(RTG_COMMAND, RTGCMD_BLITTEMPLATE);
}
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)) {
if (!r || !p) return;
if (w < 1 || h < 1) return;
WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_X3, p->XOffset);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITESHORT(RTG_Y3, p->YOffset);
if ((unsigned long)p->Memory > CHIP_RAM_SIZE) {
WRITELONG(RTG_ADDR1, (unsigned long)p->Memory);
}
else {
unsigned long dest = CARD_SCRATCH;
memcpy((unsigned char *)dest, p->Memory, (2 * (1 << p->Size)));
WRITELONG(RTG_ADDR1, (unsigned long)dest);
}
WRITELONG(RTG_RGB1, p->FgPen);
WRITELONG(RTG_RGB2, p->BgPen);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITESHORT(RTG_X5, (1 << p->Size));
WRITEBYTE(RTG_U81, mask);
WRITEBYTE(RTG_U82, p->DrawMode);
WRITEBYTE(RTG_U83, (1 << p->Size));
WRITESHORT(RTG_COMMAND, RTGCMD_BLITPATTERN);
}
void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format)) {
#ifndef IRTG
if (!r || !b) return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITELONG(RTG_RGB1, l->FgPen);
WRITELONG(RTG_RGB2, l->BgPen);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, l->X);
WRITESHORT(RTG_X2, l->dX);
WRITESHORT(RTG_Y1, l->Y);
WRITESHORT(RTG_Y2, l->dY);
WRITESHORT(RTG_X3, l->Length);
WRITESHORT(RTG_Y3, l->LinePtrn);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITESHORT(RTG_X5, l->PatternShift);
WRITEBYTE(RTG_U81, mask);
WRITEBYTE(RTG_U82, l->DrawMode);
WRITEBYTE(RTG_U83, l->pad);
WRITESHORT(RTG_COMMAND, RTGCMD_DRAWLINE);
#else
IWRITECMD(RTGCMD_DRAWLINE);
#endif
}
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;
//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);
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_P2C);
}
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);
}
void SetSprite (__REGA0(struct BoardInfo *b), __REGD0(BOOL what), __REGD7(RGBFTYPE format)) {
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITE);
}
void SetSpritePosition (__REGA0(struct BoardInfo *b), __REGD0(WORD x), __REGD1(WORD y), __REGD7(RGBFTYPE format)) {
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITEPOS);
}
void SetSpriteImage (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
WRITESHORT(RTG_X1, b->XOffset);
WRITESHORT(RTG_Y1, b->YOffset);
WRITEBYTE(RTG_U81, b->MouseWidth);
WRITEBYTE(RTG_U82, b->MouseHeight);
uint8_t* dest = (uint8_t*)((uint32_t)CARD_SCRATCH);
uint8_t* src = (uint8_t *)b->MouseImage;
uint16_t data_size = ((b->MouseWidth >> 3) * 2) * (b->MouseHeight);
if (b->MouseWidth > 16) src += 8;
else src += 4;
memcpy(dest, src, data_size);
WRITELONG(RTG_ADDR2, CARD_SCRATCH);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITEIMAGE);
}
void SetSpriteColor (__REGA0(struct BoardInfo *b), __REGD0(UBYTE idx), __REGD1(UBYTE R), __REGD2(UBYTE G), __REGD3(UBYTE B), __REGD7(RGBFTYPE format)) {
WRITEBYTE(RTG_U81, R);
WRITEBYTE(RTG_U82, G);
WRITEBYTE(RTG_U83, B);
WRITEBYTE(RTG_U84, idx);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITECOLOR);
}
static uint32_t device_vectors[] = {
(uint32_t)OpenLib,
(uint32_t)CloseLib,
(uint32_t)ExpungeLib,
0,
(uint32_t)FindCard,
(uint32_t)InitCard,
-1
};
struct InitTable
{
ULONG LibBaseSize;
APTR FunctionTable;
APTR DataTable;
APTR InitLibTable;
};
const uint32_t auto_init_tables[4] = {
sizeof(struct Library),
(uint32_t)device_vectors,
0,
(uint32_t)InitLib,
};

View File

@@ -1,833 +0,0 @@
// SPDX-License-Identifier: MIT
// PiStorm RTG driver, VBCC edition.
// Based in part on the ZZ9000 RTG driver.
#include <proto/exec.h>
#include <proto/expansion.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <exec/execbase.h>
#include <exec/resident.h>
#include <exec/initializers.h>
#include <clib/debug_protos.h>
#include <string.h>
#include <stdint.h>
#include "boardinfo.h"
#include "rtg_enums.h"
#define WRITESHORT(cmd, val) *(unsigned short *)((unsigned long)(b->RegisterBase)+cmd) = val;
#define WRITELONG(cmd, val) *(unsigned long *)((unsigned long)(b->RegisterBase)+cmd) = val;
#define WRITEBYTE(cmd, val) *(unsigned char *)((unsigned long)(b->RegisterBase)+cmd) = val;
#define CHECKRTG *((unsigned short *)(CARD_OFFSET))
#define CARD_OFFSET 0x70000000
#define CARD_REGSIZE 0x00010000
#define CARD_MEMSIZE 0x02000000 // 32MB "VRAM"
#define CARD_SCRATCH 0x72010000
#define CHIP_RAM_SIZE 0x00200000 // Chip RAM offset, 2MB
const unsigned short rgbf_to_rtg[16] = {
RTGFMT_8BIT, // 0x00
RTGFMT_8BIT, // 0x01
0, // 0x02
0, // 0x03
0, // 0x04
RTGFMT_RGB555, // 0x05
0, // 0x06
0, // 0x07
RTGFMT_RGB32, // 0x08
RTGFMT_RGB32, // 0x09
RTGFMT_RBG565, // 0x0A
RTGFMT_RGB555, // 0x0B
0, // 0x0C
RTGFMT_RGB555, // 0x0D
0, // 0x0E
0, // 0x0F
};
struct GFXBase {
struct Library libNode;
BPTR segList;
struct ExecBase* sysBase;
struct ExpansionBase* expansionBase;
};
int FindCard(__REGA0(struct BoardInfo* b));
int InitCard(__REGA0(struct BoardInfo* b));
void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border));
void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num));
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format));
UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format));
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format));
ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format));
ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format));
void SetClock (__REGA0(struct BoardInfo *b));
void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane));
void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle));
void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format));
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));
void BlitRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE mask), __REGD7(RGBFTYPE format));
void BlitRectNoMaskComplete (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *rs), __REGA2(struct RenderInfo *rt), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE minterm), __REGD7(RGBFTYPE format));
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));
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));
void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format));
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));
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 SetSprite (__REGA0(struct BoardInfo *b), __REGD0(BOOL what), __REGD7(RGBFTYPE format));
void SetSpritePosition (__REGA0(struct BoardInfo *b), __REGD0(WORD x), __REGD1(WORD y), __REGD7(RGBFTYPE format));
void SetSpriteImage (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
void SetSpriteColor (__REGA0(struct BoardInfo *b), __REGD0(UBYTE idx), __REGD1(UBYTE R), __REGD2(UBYTE G), __REGD3(UBYTE B), __REGD7(RGBFTYPE format));
static ULONG LibStart(void) {
return(-1);
}
static const char LibraryName[] = "PiRTG.card";
static const char LibraryID[] = "$VER: PiRTG.card 0.01\r\n";
__saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase));
BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase));
BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb));
ULONG ExtFuncLib(void);
__saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
__REGA0(BPTR seglist),
__REGD0(struct GFXBase *exb));
static const APTR FuncTab[] = {
(APTR)OpenLib,
(APTR)CloseLib,
(APTR)ExpungeLib,
(APTR)ExtFuncLib,
(APTR)FindCard,
(APTR)InitCard,
(APTR)((LONG)-1)
};
struct InitTable
{
ULONG LibBaseSize;
APTR FunctionTable;
APTR DataTable;
APTR InitLibTable;
};
static struct InitTable InitTab = {
(ULONG) sizeof(struct GFXBase),
(APTR) FuncTab,
(APTR) NULL,
(APTR) InitLib
};
static const struct Resident ROMTag = {
RTC_MATCHWORD,
&ROMTag,
&ROMTag + 1,
RTF_AUTOINIT,
83,
NT_LIBRARY,
0,
(char *)LibraryName,
(char *)LibraryID,
(APTR)&InitTab
};
#define CLOCK_HZ 100000000
static struct GFXBase *_gfxbase;
const char *gfxname = "PiStorm RTG";
char dummies[128];
__saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
__REGA0(BPTR seglist),
__REGD0(struct GFXBase *exb))
{
_gfxbase = exb;
return _gfxbase;
}
__saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase))
{
gfxbase->libNode.lib_OpenCnt++;
gfxbase->libNode.lib_Flags &= ~LIBF_DELEXP;
return gfxbase;
}
BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase))
{
gfxbase->libNode.lib_OpenCnt--;
if (!gfxbase->libNode.lib_OpenCnt) {
if (gfxbase->libNode.lib_Flags & LIBF_DELEXP) {
return (ExpungeLib(gfxbase));
}
}
return 0;
}
BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb))
{
BPTR seglist;
struct ExecBase *SysBase = *(struct ExecBase **)4L;
if(!exb->libNode.lib_OpenCnt) {
ULONG negsize, possize, fullsize;
UBYTE *negptr = (UBYTE *)exb;
seglist = exb->segList;
Remove((struct Node *)exb);
negsize = exb->libNode.lib_NegSize;
possize = exb->libNode.lib_PosSize;
fullsize = negsize + possize;
negptr -= negsize;
FreeMem(negptr, fullsize);
return(seglist);
}
exb->libNode.lib_Flags |= LIBF_DELEXP;
return 0;
}
ULONG ExtFuncLib(void)
{
return 0;
}
static LONG zorro_version = 0;
static struct GFXData *gfxdata;
//MNTZZ9KRegs* registers;
#define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary(b,0L))==NULL) { \
KPrintF("Failed to load %s.\n", b); \
return 0; \
} \
static BYTE card_already_found;
static BYTE card_initialized;
int FindCard(__REGA0(struct BoardInfo* b)) {
//if (card_already_found)
// return 1;
uint16_t card_check = CHECKRTG;
if (card_check != 0xFFCF) {
// RTG not enabled
return 0;
}
struct ConfigDev* cd = NULL;
struct ExpansionBase *ExpansionBase = NULL;
struct DOSBase *DOSBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;
struct ExecBase *SysBase = *(struct ExecBase **)4L;
LOADLIB(ExpansionBase, "expansion.library");
LOADLIB(DOSBase, "dos.library");
LOADLIB(IntuitionBase, "intuition.library");
b->MemorySize = CARD_MEMSIZE;
b->RegisterBase = (void *)CARD_OFFSET;
b->MemoryBase = (void *)(CARD_OFFSET + CARD_REGSIZE);
return 1;
}
#define HWSPRITE 1
#define VGASPLIT (1 << 6)
#define FLICKERFIXER (1 << 12)
#define INDISPLAYCHAIN (1 << 20)
#define DIRECTACCESS (1 << 26)
int InitCard(__REGA0(struct BoardInfo* b)) {
//if (!card_initialized)
// card_initialized = 1;
// else
//return 1;
int max, i;
struct ExecBase *SysBase = *(struct ExecBase **)4L;
b->CardBase = (struct CardBase *)_gfxbase;
b->ExecBase = SysBase;
b->BoardName = "PiStorm RTG";
b->BoardType = BT_MNT_ZZ9000;
b->PaletteChipType = PCT_MNT_ZZ9000;
b->GraphicsControllerType = GCT_MNT_ZZ9000;
b->Flags = BIF_INDISPLAYCHAIN | BIF_GRANTDIRECTACCESS | BIF_HARDWARESPRITE;
b->RGBFormats = 1 | 2 | 512 | 1024 | 2048;
b->SoftSpriteFlags = 0;
b->BitsPerCannon = 8;
for(i = 0; i < MAXMODES; i++) {
b->MaxHorValue[i] = 8192;
b->MaxVerValue[i] = 8192;
b->MaxHorResolution[i] = 8192;
b->MaxVerResolution[i] = 8192;
b->PixelClockCount[i] = 1;
}
b->MemoryClock = CLOCK_HZ;
//b->AllocCardMem = (void *)NULL;
//b->FreeCardMem = (void *)NULL;
b->SetSwitch = (void *)SetSwitch;
b->SetColorArray = (void *)SetColorArray;
b->SetDAC = (void *)SetDAC;
b->SetGC = (void *)SetGC;
b->SetPanning = (void *)SetPanning;
b->CalculateBytesPerRow = (void *)CalculateBytesPerRow;
b->CalculateMemory = (void *)CalculateMemory;
b->GetCompatibleFormats = (void *)GetCompatibleFormats;
b->SetDisplay = (void *)SetDisplay;
b->ResolvePixelClock = (void *)ResolvePixelClock;
b->GetPixelClock = (void *)GetPixelClock;
b->SetClock = (void *)SetClock;
b->SetMemoryMode = (void *)SetMemoryMode;
b->SetWriteMask = (void *)SetWriteMask;
b->SetClearMask = (void *)SetClearMask;
b->SetReadPlane = (void *)SetReadPlane;
b->WaitVerticalSync = (void *)WaitVerticalSync;
//b->SetInterrupt = (void *)NULL;
//b->WaitBlitter = (void *)NULL;
//b->ScrollPlanar = (void *)NULL;
//b->UpdatePlanar = (void *)NULL;
b->BlitPlanar2Chunky = (void *)BlitPlanar2Chunky;
b->BlitPlanar2Direct = (void *)BlitPlanar2Direct;
b->FillRect = (void *)FillRect;
b->InvertRect = (void *)InvertRect;
b->BlitRect = (void *)BlitRect;
b->BlitTemplate = (void *)BlitTemplate;
b->BlitPattern = (void *)BlitPattern;
b->DrawLine = (void *)DrawLine;
b->BlitRectNoMaskComplete = (void *)BlitRectNoMaskComplete;
//b->EnableSoftSprite = (void *)NULL;
//b->AllocCardMemAbs = (void *)NULL;
//b->SetSplitPosition = (void *)NULL;
//b->ReInitMemory = (void *)NULL;
//b->WriteYUVRect = (void *)NULL;
//b->GetVSyncState = (void *)NULL;
//b->GetVBeamPos = (void *)NULL;
//b->SetDPMSLevel = (void *)NULL;
//b->ResetChip = (void *)NULL;
//b->GetFeatureAttrs = (void *)NULL;
//b->AllocBitMap = (void *)NULL;
//b->FreeBitMap = (void *)NULL;
//b->GetBitMapAttr = (void *)NULL;
b->SetSprite = (void *)SetSprite;
b->SetSpritePosition = (void *)SetSpritePosition;
b->SetSpriteImage = (void *)SetSpriteImage;
b->SetSpriteColor = (void *)SetSpriteColor;
//b->CreateFeature = (void *)NULL;
//b->SetFeatureAttrs = (void *)NULL;
//b->DeleteFeature = (void *)NULL;
return 1;
}
void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
// Used to set the color format of the video card's RAMDAC.
// This needs no handling, since the PiStorm doesn't really have a RAMDAC or a video card chipset.
}
void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border)) {
b->ModeInfo = mode_info;
// Send width, height and format to the RaspberryPi Targetable Graphics.
WRITESHORT(RTG_X1, mode_info->Width);
WRITESHORT(RTG_Y1, mode_info->Height);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[b->RGBFormat]);
WRITESHORT(RTG_COMMAND, RTGCMD_SETGC);
}
int setswitch = -1;
UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
if (setswitch != enabled) {
setswitch = enabled;
}
WRITEBYTE(RTG_U81, setswitch);
WRITESHORT(RTG_X1, setswitch);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSWITCH);
return 1 - enabled;
}
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format)) {
// Set the panning offset, or the offset used for the current display area on the Pi.
// The address needs to have CARD_BASE subtracted from it to be used as an offset on the Pi side.
if (!b)
return;
b->XOffset = x_offset;
b->YOffset = y_offset;
WRITELONG(RTG_ADDR1, (unsigned long)addr);
WRITESHORT(RTG_X1, width);
WRITESHORT(RTG_X2, b->XOffset);
WRITESHORT(RTG_Y2, b->YOffset);
WRITESHORT(RTG_COMMAND, RTGCMD_SETPAN);
}
void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num)) {
// Sets the color components of X color components for 8-bit paletted display modes.
if (!b->CLUT)
return;
int j = start + num;
for(int i = start; i < j; i++) {
//WRITEBYTE(RTG_U82, (unsigned char)b->CLUT[i].Red);
//WRITEBYTE(RTG_U83, (unsigned char)b->CLUT[i].Green);
//WRITEBYTE(RTG_U84, (unsigned char)b->CLUT[i].Blue);
unsigned long xrgb = 0 | (b->CLUT[i].Red << 16) | (b->CLUT[i].Green << 8) | (b->CLUT[i].Blue);
WRITEBYTE(RTG_U81, (unsigned char)i);
WRITELONG(RTG_RGB1, xrgb);
WRITESHORT(RTG_COMMAND, RTGCMD_SETCLUT);
}
}
UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format)) {
if (!b)
return 0;
UWORD pitch = width;
switch(format) {
default:
return pitch;
case 0x05: case 0x0A: case 0x0B: case 0x0D:
return (width * 2);
case 0x08: case 0x09:
return (width * 4);
}
}
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format)) {
/*if (!b)
return (APTR)addr;
if (addr > (unsigned int)b->MemoryBase && addr < (((unsigned int)b->MemoryBase) + b->MemorySize)) {
addr = ((addr + 0x1000) & 0xFFFFF000);
}*/
return (APTR)addr;
}
ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
// It is of course compatible with all the formats ever.
return 0xFFFFFFFF;
}
static int display_enabled = 0;
UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
// Enables or disables the display.
WRITEBYTE(RTG_U82, (unsigned char)enabled);
WRITESHORT(RTG_COMMAND, RTGCMD_SETDISPLAY);
return 1;
}
LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format)) {
mode_info->PixelClock = CLOCK_HZ;
mode_info->pll1.Clock = 0;
mode_info->pll2.ClockDivide = 1;
return 0;
}
ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format)) {
// Just return 100MHz.
return CLOCK_HZ;
}
// None of these five really have to do anything.
void SetClock (__REGA0(struct BoardInfo *b)) {
}
void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
}
void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
}
void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
}
void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)) {
}
void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) {
// I don't know why this one has a bool in D0, but it isn't used for anything.
}
void FillRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD w), __REGD3(WORD h), __REGD4(ULONG color), __REGD5(UBYTE mask), __REGD7(RGBFTYPE format)) {
if (!r)
return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITELONG(RTG_RGB1, color);
WRITESHORT(RTG_X3, r->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITESHORT(RTG_COMMAND, RTGCMD_FILLRECT);
}
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]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITESHORT(RTG_X3, r->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITESHORT(RTG_COMMAND, RTGCMD_INVERTRECT);
}
void BlitRect (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE mask), __REGD7(RGBFTYPE format)) {
if (!r)
return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, dx);
WRITESHORT(RTG_X3, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, dy);
WRITESHORT(RTG_Y3, h);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT);
}
void BlitRectNoMaskComplete (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *rs), __REGA2(struct RenderInfo *rt), __REGD0(WORD x), __REGD1(WORD y), __REGD2(WORD dx), __REGD3(WORD dy), __REGD4(WORD w), __REGD5(WORD h), __REGD6(UBYTE minterm), __REGD7(RGBFTYPE format)) {
if (!rs || !rt)
return;
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITELONG(RTG_ADDR1, (unsigned long)rs->Memory);
WRITELONG(RTG_ADDR2, (unsigned long)rt->Memory);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, dx);
WRITESHORT(RTG_X3, w);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, dy);
WRITESHORT(RTG_Y3, h);
WRITESHORT(RTG_X4, rs->BytesPerRow);
WRITESHORT(RTG_X5, rt->BytesPerRow);
WRITEBYTE(RTG_U81, minterm);
WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT_NOMASK_COMPLETE);
}
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)) {
if (!r || !t) return;
if (w < 1 || h < 1) return;
WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_X3, t->XOffset);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITESHORT(RTG_Y3, 0);
if ((unsigned long)t->Memory > CHIP_RAM_SIZE) {
WRITELONG(RTG_ADDR1, (unsigned long)t->Memory);
}
else {
unsigned long dest = CARD_SCRATCH;
memcpy((unsigned char *)dest, t->Memory, (t->BytesPerRow * h));
WRITELONG(RTG_ADDR1, (unsigned long)dest);
WRITELONG(RTG_ADDR3, (unsigned long)t->Memory);
}
WRITELONG(RTG_RGB1, t->FgPen);
WRITELONG(RTG_RGB2, t->BgPen);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITESHORT(RTG_X5, t->BytesPerRow);
WRITEBYTE(RTG_U81, mask);
WRITEBYTE(RTG_U82, t->DrawMode);
WRITESHORT(RTG_COMMAND, RTGCMD_BLITTEMPLATE);
}
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)) {
if (!r || !p) return;
if (w < 1 || h < 1) return;
WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_X2, w);
WRITESHORT(RTG_X3, p->XOffset);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_Y2, h);
WRITESHORT(RTG_Y3, p->YOffset);
if ((unsigned long)p->Memory > CHIP_RAM_SIZE) {
WRITELONG(RTG_ADDR1, (unsigned long)p->Memory);
}
else {
unsigned long dest = CARD_SCRATCH;
memcpy((unsigned char *)dest, p->Memory, (2 * (1 << p->Size)));
WRITELONG(RTG_ADDR1, (unsigned long)dest);
}
WRITELONG(RTG_RGB1, p->FgPen);
WRITELONG(RTG_RGB2, p->BgPen);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITESHORT(RTG_X5, (1 << p->Size));
WRITEBYTE(RTG_U81, mask);
WRITEBYTE(RTG_U82, p->DrawMode);
WRITEBYTE(RTG_U83, (1 << p->Size));
WRITESHORT(RTG_COMMAND, RTGCMD_BLITPATTERN);
}
void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format)) {
if (!r || !b) return;
WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
WRITELONG(RTG_RGB1, l->FgPen);
WRITELONG(RTG_RGB2, l->BgPen);
WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
WRITESHORT(RTG_X1, l->X);
WRITESHORT(RTG_X2, l->dX);
WRITESHORT(RTG_Y1, l->Y);
WRITESHORT(RTG_Y2, l->dY);
WRITESHORT(RTG_X3, l->Length);
WRITESHORT(RTG_Y3, l->LinePtrn);
WRITESHORT(RTG_X4, r->BytesPerRow);
WRITESHORT(RTG_X5, l->PatternShift);
WRITEBYTE(RTG_U81, mask);
WRITEBYTE(RTG_U82, l->DrawMode);
WRITEBYTE(RTG_U83, l->pad);
WRITESHORT(RTG_COMMAND, RTGCMD_DRAWLINE);
}
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;
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);
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_P2C);
}
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);
}
void SetSprite (__REGA0(struct BoardInfo *b), __REGD0(BOOL what), __REGD7(RGBFTYPE format)) {
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITE);
}
void SetSpritePosition (__REGA0(struct BoardInfo *b), __REGD0(WORD x), __REGD1(WORD y), __REGD7(RGBFTYPE format)) {
WRITESHORT(RTG_X1, x);
WRITESHORT(RTG_Y1, y);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITEPOS);
}
void SetSpriteImage (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
WRITESHORT(RTG_X1, b->XOffset);
WRITESHORT(RTG_Y1, b->YOffset);
WRITEBYTE(RTG_U81, b->MouseWidth);
WRITEBYTE(RTG_U82, b->MouseHeight);
uint8_t* dest = (uint8_t*)((uint32_t)CARD_SCRATCH);
uint8_t* src = (uint8_t *)b->MouseImage;
uint16_t data_size = ((b->MouseWidth >> 3) * 2) * (b->MouseHeight);
if (b->MouseWidth > 16) src += 8;
else src += 4;
memcpy(dest, src, data_size);
WRITELONG(RTG_ADDR2, CARD_SCRATCH);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITEIMAGE);
}
void SetSpriteColor (__REGA0(struct BoardInfo *b), __REGD0(UBYTE idx), __REGD1(UBYTE R), __REGD2(UBYTE G), __REGD3(UBYTE B), __REGD7(RGBFTYPE format)) {
WRITEBYTE(RTG_U81, R);
WRITEBYTE(RTG_U82, G);
WRITEBYTE(RTG_U83, B);
WRITEBYTE(RTG_U84, idx);
WRITESHORT(RTG_COMMAND, RTGCMD_SETSPRITECOLOR);
}

Binary file not shown.

View File

@@ -1,86 +0,0 @@
// SPDX-License-Identifier: MIT
// "Register" offsets for sending data to the RTG.
enum pi_regs {
RTG_COMMAND = 0x00,
RTG_X1 = 0x02,
RTG_X2 = 0x04,
RTG_X3 = 0x06,
RTG_Y1 = 0x08,
RTG_Y2 = 0x0A,
RTG_Y3 = 0x0C,
RTG_FORMAT = 0x0E,
RTG_RGB1 = 0x10,
RTG_RGB2 = 0x14,
RTG_ADDR1 = 0x18,
RTG_ADDR2 = 0x1C,
RTG_U81 = 0x20,
RTG_U82 = 0x21,
RTG_U83 = 0x22,
RTG_U84 = 0x23,
RTG_X4 = 0x24,
RTG_X5 = 0x26,
RTG_Y4 = 0x28,
RTG_Y5 = 0x2A,
RTG_U1 = 0x2C,
RTG_U2 = 0x2E,
RTG_ADDR3 = 0x30,
RTG_ADDR4 = 0x34,
};
enum rtg_cmds {
RTGCMD_SETGC,
RTGCMD_SETPAN,
RTGCMD_SETCLUT,
RTGCMD_ENABLE,
RTGCMD_SETDISPLAY,
RTGCMD_SETSWITCH,
RTGCMD_FILLRECT,
RTGCMD_BLITRECT,
RTGCMD_BLITRECT_NOMASK_COMPLETE,
RTGCMD_BLITPATTERN,
RTGCMD_BLITTEMPLATE,
RTGCMD_INVERTRECT,
RTGCMD_DRAWLINE,
RTGCMD_P2C,
RTGCMD_P2D,
RTGCMD_SETSPRITE,
RTGCMD_SETSPRITEPOS,
RTGCMD_SETSPRITECOLOR,
RTGCMD_SETSPRITEIMAGE,
RTGCMD_DEBUGME,
};
enum rtg_formats {
RTGFMT_8BIT,
RTGFMT_RBG565,
RTGFMT_RGB32,
RTGFMT_RGB555,
RTGFMT_NUM,
};
enum gfx_minterm_modes {
MINTERM_FALSE,
MINTERM_NOR,
MINTERM_ONLYDST,
MINTERM_NOTSRC,
MINTERM_ONLYSRC,
MINTERM_INVERT,
MINTERM_EOR,
MINTERM_NAND,
MINTERM_AND,
MINTERM_NEOR,
MINTERM_DST,
MINTERM_NOTONLYSRC,
MINTERM_SRC,
MINTERM_NOTONLYDST,
MINTERM_OR,
MINTERM_TRUE,
};
enum gfx_draw_modes {
DRAWMODE_JAM1 = 0,
DRAWMODE_JAM2 = 1,
DRAWMODE_COMPLEMENT = 2,
DRAWMODE_INVERSVID = 4,
};

View File

@@ -0,0 +1,107 @@
// SPDX-License-Identifier: MIT
// "Register" offsets for sending data to the RTG.
enum pi_regs {
RTG_COMMAND = 0x00,
RTG_X1 = 0x02,
RTG_X2 = 0x04,
RTG_X3 = 0x06,
RTG_Y1 = 0x08,
RTG_Y2 = 0x0A,
RTG_Y3 = 0x0C,
RTG_FORMAT = 0x0E,
RTG_RGB1 = 0x10,
RTG_RGB2 = 0x14,
RTG_ADDR1 = 0x18,
RTG_ADDR2 = 0x1C,
RTG_U81 = 0x20,
RTG_U82 = 0x21,
RTG_U83 = 0x22,
RTG_U84 = 0x23,
RTG_X4 = 0x24,
RTG_X5 = 0x26,
RTG_Y4 = 0x28,
RTG_Y5 = 0x2A,
RTG_U1 = 0x2C,
RTG_U2 = 0x2E,
RTG_ADDR3 = 0x30,
RTG_ADDR4 = 0x34,
RTG_DEBUGME = 0x50,
IRTG_COMMAND = 0x60,
};
enum rtg_cmds {
RTGCMD_SETGC,
RTGCMD_SETPAN,
RTGCMD_SETCLUT,
RTGCMD_ENABLE,
RTGCMD_SETDISPLAY,
RTGCMD_SETSWITCH,
RTGCMD_FILLRECT,
RTGCMD_BLITRECT,
RTGCMD_BLITRECT_NOMASK_COMPLETE,
RTGCMD_BLITPATTERN,
RTGCMD_BLITTEMPLATE,
RTGCMD_INVERTRECT,
RTGCMD_DRAWLINE,
RTGCMD_P2C,
RTGCMD_P2D,
RTGCMD_SETSPRITE,
RTGCMD_SETSPRITEPOS,
RTGCMD_SETSPRITECOLOR,
RTGCMD_SETSPRITEIMAGE,
RTGCMD_DEBUGME,
};
enum rtg_formats {
RTGFMT_8BIT,
RTGFMT_RBG565,
RTGFMT_RGB32,
RTGFMT_RGB555,
RTGFMT_NUM,
};
enum gfx_minterm_modes {
MINTERM_FALSE,
MINTERM_NOR,
MINTERM_ONLYDST,
MINTERM_NOTSRC,
MINTERM_ONLYSRC,
MINTERM_INVERT,
MINTERM_EOR,
MINTERM_NAND,
MINTERM_AND,
MINTERM_NEOR,
MINTERM_DST,
MINTERM_NOTONLYSRC,
MINTERM_SRC,
MINTERM_NOTONLYDST,
MINTERM_OR,
MINTERM_TRUE,
};
enum gfx_draw_modes {
DRAWMODE_JAM1 = 0,
DRAWMODE_JAM2 = 1,
DRAWMODE_COMPLEMENT = 2,
DRAWMODE_INVERSVID = 4,
};
static const unsigned short rgbf_to_rtg[16] = {
RTGFMT_8BIT, // 0x00
RTGFMT_8BIT, // 0x01
0, // 0x02
0, // 0x03
0, // 0x04
RTGFMT_RGB555, // 0x05
0, // 0x06
0, // 0x07
RTGFMT_RGB32, // 0x08
RTGFMT_RGB32, // 0x09
RTGFMT_RBG565, // 0x0A
RTGFMT_RGB555, // 0x0B
0, // 0x0C
RTGFMT_RGB555, // 0x0D
0, // 0x0E
0, // 0x0F
};