1 // SPDX-License-Identifier: MIT
3 // PiStorm RTG driver, VBCC edition.
4 // Based in part on the ZZ9000 RTG driver.
6 #include <proto/exec.h>
7 #include <proto/expansion.h>
9 #include <proto/intuition.h>
10 #include <exec/types.h>
11 #include <exec/memory.h>
12 #include <exec/libraries.h>
13 #include <exec/execbase.h>
14 #include <exec/resident.h>
15 #include <exec/initializers.h>
16 #include <clib/debug_protos.h>
19 #include "boardinfo.h"
20 #include "rtg_enums.h"
22 #define WRITESHORT(cmd, val) *(unsigned short *)((unsigned long)(b->RegisterBase)+cmd) = val;
23 #define WRITELONG(cmd, val) *(unsigned long *)((unsigned long)(b->RegisterBase)+cmd) = val;
24 #define WRITEBYTE(cmd, val) *(unsigned char *)((unsigned long)(b->RegisterBase)+cmd) = val;
26 #define CHECKRTG *((unsigned short *)(CARD_OFFSET))
28 #define CARD_OFFSET 0x70000000
29 #define CARD_REGSIZE 0x00010000
30 #define CARD_MEMSIZE 0x02000000 // 32MB "VRAM"
31 #define CARD_SCRATCH 0x72010000
33 #define CHIP_RAM_SIZE 0x00200000 // Chip RAM offset, 2MB
35 const unsigned short rgbf_to_rtg[16] = {
41 RTGFMT_RGB555, // 0x05
46 RTGFMT_RBG565, // 0x0A
47 RTGFMT_RGB555, // 0x0B
49 RTGFMT_RGB555, // 0x0D
55 struct Library libNode;
57 struct ExecBase* sysBase;
58 struct ExpansionBase* expansionBase;
61 int FindCard(__REGA0(struct BoardInfo* b));
62 int InitCard(__REGA0(struct BoardInfo* b));
64 void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
65 void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border));
66 void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num));
67 void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format));
68 UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
69 UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
71 UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format));
72 APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format));
73 ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
75 LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format));
76 ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format));
77 void SetClock (__REGA0(struct BoardInfo *b));
79 void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
80 void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
81 void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
82 void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane));
84 void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle));
86 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));
87 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));
88 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));
89 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));
90 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));
91 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));
92 void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format));
94 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));
95 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));
97 static ULONG LibStart(void) {
101 static const char LibraryName[] = "PiRTG.card";
102 static const char LibraryID[] = "$VER: PiRTG.card 0.01\r\n";
104 __saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase));
105 BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase));
106 BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb));
107 ULONG ExtFuncLib(void);
108 __saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
109 __REGA0(BPTR seglist),
110 __REGD0(struct GFXBase *exb));
112 static const APTR FuncTab[] = {
131 static struct InitTable InitTab = {
132 (ULONG) sizeof(struct GFXBase),
138 static const struct Resident ROMTag = {
151 #define CLOCK_HZ 100000000
153 static struct GFXBase *_gfxbase;
154 const char *gfxname = "PiStorm RTG";
157 __saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
158 __REGA0(BPTR seglist),
159 __REGD0(struct GFXBase *exb))
165 __saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase))
167 gfxbase->libNode.lib_OpenCnt++;
168 gfxbase->libNode.lib_Flags &= ~LIBF_DELEXP;
173 BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase))
175 gfxbase->libNode.lib_OpenCnt--;
177 if (!gfxbase->libNode.lib_OpenCnt) {
178 if (gfxbase->libNode.lib_Flags & LIBF_DELEXP) {
179 return (ExpungeLib(gfxbase));
185 BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb))
188 struct ExecBase *SysBase = *(struct ExecBase **)4L;
190 if(!exb->libNode.lib_OpenCnt) {
191 ULONG negsize, possize, fullsize;
192 UBYTE *negptr = (UBYTE *)exb;
194 seglist = exb->segList;
196 Remove((struct Node *)exb);
198 negsize = exb->libNode.lib_NegSize;
199 possize = exb->libNode.lib_PosSize;
200 fullsize = negsize + possize;
203 FreeMem(negptr, fullsize);
207 exb->libNode.lib_Flags |= LIBF_DELEXP;
211 ULONG ExtFuncLib(void)
216 static LONG zorro_version = 0;
218 static struct GFXData *gfxdata;
219 //MNTZZ9KRegs* registers;
221 #define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary(b,0L))==NULL) { \
222 KPrintF("Failed to load %s.\n", b); \
226 static BYTE card_already_found;
227 static BYTE card_initialized;
229 int FindCard(__REGA0(struct BoardInfo* b)) {
230 //if (card_already_found)
232 uint16_t card_check = CHECKRTG;
233 if (card_check != 0xFFCF) {
238 struct ConfigDev* cd = NULL;
239 struct ExpansionBase *ExpansionBase = NULL;
240 struct DOSBase *DOSBase = NULL;
241 struct IntuitionBase *IntuitionBase = NULL;
242 struct ExecBase *SysBase = *(struct ExecBase **)4L;
244 LOADLIB(ExpansionBase, "expansion.library");
245 LOADLIB(DOSBase, "dos.library");
246 LOADLIB(IntuitionBase, "intuition.library");
248 b->MemorySize = CARD_MEMSIZE;
249 b->RegisterBase = (void *)CARD_OFFSET;
250 b->MemoryBase = (void *)(CARD_OFFSET + CARD_REGSIZE);
256 #define VGASPLIT (1 << 6)
257 #define FLICKERFIXER (1 << 12)
258 #define INDISPLAYCHAIN (1 << 20)
259 #define DIRECTACCESS (1 << 26)
261 int InitCard(__REGA0(struct BoardInfo* b)) {
262 //if (!card_initialized)
263 // card_initialized = 1;
268 struct ExecBase *SysBase = *(struct ExecBase **)4L;
270 b->CardBase = (struct CardBase *)_gfxbase;
271 b->ExecBase = SysBase;
272 b->BoardName = "PiStorm RTG";
273 b->BoardType = BT_MNT_ZZ9000;
274 b->PaletteChipType = PCT_MNT_ZZ9000;
275 b->GraphicsControllerType = GCT_MNT_ZZ9000;
277 b->Flags = BIF_INDISPLAYCHAIN | BIF_GRANTDIRECTACCESS;// | BIF_HARDWARESPRITE;
278 b->RGBFormats = 1 | 2 | 512 | 1024 | 2048;
279 b->SoftSpriteFlags = 0;
280 b->BitsPerCannon = 8;
282 for(i = 0; i < MAXMODES; i++) {
283 b->MaxHorValue[i] = 8192;
284 b->MaxVerValue[i] = 8192;
285 b->MaxHorResolution[i] = 8192;
286 b->MaxVerResolution[i] = 8192;
287 b->PixelClockCount[i] = 1;
290 b->MemoryClock = CLOCK_HZ;
292 //b->AllocCardMem = (void *)NULL;
293 //b->FreeCardMem = (void *)NULL;
294 b->SetSwitch = (void *)SetSwitch;
295 b->SetColorArray = (void *)SetColorArray;
296 b->SetDAC = (void *)SetDAC;
297 b->SetGC = (void *)SetGC;
298 b->SetPanning = (void *)SetPanning;
299 b->CalculateBytesPerRow = (void *)CalculateBytesPerRow;
300 b->CalculateMemory = (void *)CalculateMemory;
301 b->GetCompatibleFormats = (void *)GetCompatibleFormats;
302 b->SetDisplay = (void *)SetDisplay;
304 b->ResolvePixelClock = (void *)ResolvePixelClock;
305 b->GetPixelClock = (void *)GetPixelClock;
306 b->SetClock = (void *)SetClock;
308 b->SetMemoryMode = (void *)SetMemoryMode;
309 b->SetWriteMask = (void *)SetWriteMask;
310 b->SetClearMask = (void *)SetClearMask;
311 b->SetReadPlane = (void *)SetReadPlane;
313 b->WaitVerticalSync = (void *)WaitVerticalSync;
314 //b->SetInterrupt = (void *)NULL;
316 //b->WaitBlitter = (void *)NULL;
318 //b->ScrollPlanar = (void *)NULL;
319 //b->UpdatePlanar = (void *)NULL;
321 b->BlitPlanar2Chunky = (void *)BlitPlanar2Chunky;
322 b->BlitPlanar2Direct = (void *)BlitPlanar2Direct;
324 b->FillRect = (void *)FillRect;
325 b->InvertRect = (void *)InvertRect;
326 b->BlitRect = (void *)BlitRect;
327 b->BlitTemplate = (void *)BlitTemplate;
328 b->BlitPattern = (void *)BlitPattern;
329 b->DrawLine = (void *)DrawLine;
330 b->BlitRectNoMaskComplete = (void *)BlitRectNoMaskComplete;
331 //b->EnableSoftSprite = (void *)NULL;
333 //b->AllocCardMemAbs = (void *)NULL;
334 //b->SetSplitPosition = (void *)NULL;
335 //b->ReInitMemory = (void *)NULL;
336 //b->WriteYUVRect = (void *)NULL;
337 //b->GetVSyncState = (void *)NULL;
338 //b->GetVBeamPos = (void *)NULL;
339 //b->SetDPMSLevel = (void *)NULL;
340 //b->ResetChip = (void *)NULL;
341 //b->GetFeatureAttrs = (void *)NULL;
342 //b->AllocBitMap = (void *)NULL;
343 //b->FreeBitMap = (void *)NULL;
344 //b->GetBitMapAttr = (void *)NULL;
346 //b->SetSprite = (void *)NULL;
347 //b->SetSpritePosition = (void *)NULL;
348 //b->SetSpriteImage = (void *)NULL;
349 //b->SetSpriteColor = (void *)NULL;
351 //b->CreateFeature = (void *)NULL;
352 //b->SetFeatureAttrs = (void *)NULL;
353 //b->DeleteFeature = (void *)NULL;
358 void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
359 // Used to set the color format of the video card's RAMDAC.
360 // This needs no handling, since the PiStorm doesn't really have a RAMDAC or a video card chipset.
363 void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border)) {
364 b->ModeInfo = mode_info;
365 // Send width, height and format to the RaspberryPi Targetable Graphics.
366 WRITESHORT(RTG_X1, mode_info->Width);
367 WRITESHORT(RTG_Y1, mode_info->Height);
368 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[b->RGBFormat]);
369 WRITESHORT(RTG_COMMAND, RTGCMD_SETGC);
373 UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
374 if (setswitch != enabled) {
378 WRITEBYTE(RTG_U81, setswitch);
379 WRITESHORT(RTG_X1, setswitch);
380 WRITESHORT(RTG_COMMAND, RTGCMD_SETSWITCH);
385 void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format)) {
386 // Set the panning offset, or the offset used for the current display area on the Pi.
387 // The address needs to have CARD_BASE subtracted from it to be used as an offset on the Pi side.
391 b->XOffset = x_offset;
392 b->YOffset = y_offset;
394 WRITELONG(RTG_ADDR1, (unsigned long)addr);
395 WRITESHORT(RTG_X1, width);
396 WRITESHORT(RTG_X2, b->XOffset);
397 WRITESHORT(RTG_Y2, b->YOffset);
398 WRITESHORT(RTG_COMMAND, RTGCMD_SETPAN);
401 void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num)) {
402 // Sets the color components of X color components for 8-bit paletted display modes.
408 for(int i = start; i < j; i++) {
409 //WRITEBYTE(RTG_U82, (unsigned char)b->CLUT[i].Red);
410 //WRITEBYTE(RTG_U83, (unsigned char)b->CLUT[i].Green);
411 //WRITEBYTE(RTG_U84, (unsigned char)b->CLUT[i].Blue);
412 unsigned long xrgb = 0 | (b->CLUT[i].Red << 16) | (b->CLUT[i].Green << 8) | (b->CLUT[i].Blue);
413 WRITEBYTE(RTG_U81, (unsigned char)i);
414 WRITELONG(RTG_RGB1, xrgb);
415 WRITESHORT(RTG_COMMAND, RTGCMD_SETCLUT);
419 UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format)) {
428 case 0x05: case 0x0A: case 0x0B: case 0x0D:
430 case 0x08: case 0x09:
435 APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format)) {
439 if (addr > (unsigned int)b->MemoryBase && addr < (((unsigned int)b->MemoryBase) + b->MemorySize)) {
440 addr = ((addr + 0x1000) & 0xFFFFF000);
446 ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
447 // It is of course compatible with all the formats ever.
451 static int display_enabled = 0;
452 UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
453 // Enables or disables the display.
454 WRITEBYTE(RTG_U82, (unsigned char)enabled);
455 WRITESHORT(RTG_COMMAND, RTGCMD_SETDISPLAY);
460 LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format)) {
461 mode_info->PixelClock = CLOCK_HZ;
462 mode_info->pll1.Clock = 0;
463 mode_info->pll2.ClockDivide = 1;
468 ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format)) {
469 // Just return 100MHz.
473 // None of these five really have to do anything.
474 void SetClock (__REGA0(struct BoardInfo *b)) {
477 void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
480 void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
483 void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
486 void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)) {
489 void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) {
490 // I don't know why this one has a bool in D0, but it isn't used for anything.
493 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)) {
497 WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
499 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
500 WRITESHORT(RTG_X1, x);
501 WRITESHORT(RTG_X2, w);
502 WRITESHORT(RTG_Y1, y);
503 WRITESHORT(RTG_Y2, h);
504 WRITELONG(RTG_RGB1, color);
505 WRITESHORT(RTG_X3, r->BytesPerRow);
506 WRITEBYTE(RTG_U81, mask);
507 WRITESHORT(RTG_COMMAND, RTGCMD_FILLRECT);
510 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)) {
515 b->InvertRectDefault(b, r, x, y, w, h, mask, format);
519 WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
521 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
522 WRITESHORT(RTG_X1, x);
523 WRITESHORT(RTG_X2, w);
524 WRITESHORT(RTG_Y1, y);
525 WRITESHORT(RTG_Y2, h);
526 WRITESHORT(RTG_X3, r->BytesPerRow);
527 WRITEBYTE(RTG_U81, mask);
528 WRITESHORT(RTG_COMMAND, RTGCMD_INVERTRECT);
531 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)) {
535 WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
537 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
538 WRITESHORT(RTG_X1, x);
539 WRITESHORT(RTG_X2, dx);
540 WRITESHORT(RTG_X3, w);
541 WRITESHORT(RTG_Y1, y);
542 WRITESHORT(RTG_Y2, dy);
543 WRITESHORT(RTG_Y3, h);
544 WRITESHORT(RTG_X4, r->BytesPerRow);
545 WRITEBYTE(RTG_U81, mask);
546 WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT);
549 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)) {
553 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
554 WRITELONG(RTG_ADDR1, (unsigned long)rs->Memory);
555 WRITELONG(RTG_ADDR2, (unsigned long)rt->Memory);
556 WRITESHORT(RTG_X1, x);
557 WRITESHORT(RTG_X2, dx);
558 WRITESHORT(RTG_X3, w);
559 WRITESHORT(RTG_Y1, y);
560 WRITESHORT(RTG_Y2, dy);
561 WRITESHORT(RTG_Y3, h);
562 WRITESHORT(RTG_X4, rs->BytesPerRow);
563 WRITESHORT(RTG_X5, rt->BytesPerRow);
564 WRITEBYTE(RTG_U81, minterm);
565 WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT_NOMASK_COMPLETE);
568 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)) {
569 if (!r || !t) return;
570 if (w < 1 || h < 1) return;
572 WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
574 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
575 WRITESHORT(RTG_X1, x);
576 WRITESHORT(RTG_X2, w);
577 WRITESHORT(RTG_X3, t->XOffset);
578 WRITESHORT(RTG_Y1, y);
579 WRITESHORT(RTG_Y2, h);
580 WRITESHORT(RTG_Y3, 0);
582 if ((unsigned long)t->Memory > CHIP_RAM_SIZE) {
583 WRITELONG(RTG_ADDR1, (unsigned long)t->Memory);
586 unsigned long dest = CARD_SCRATCH;
587 memcpy((unsigned char *)dest, t->Memory, (t->BytesPerRow * h));
588 WRITELONG(RTG_ADDR1, (unsigned long)dest);
589 WRITELONG(RTG_ADDR3, (unsigned long)t->Memory);
592 WRITELONG(RTG_RGB1, t->FgPen);
593 WRITELONG(RTG_RGB2, t->BgPen);
595 WRITESHORT(RTG_X4, r->BytesPerRow);
596 WRITESHORT(RTG_X5, t->BytesPerRow);
598 WRITEBYTE(RTG_U81, mask);
599 WRITEBYTE(RTG_U82, t->DrawMode);
600 WRITESHORT(RTG_COMMAND, RTGCMD_BLITTEMPLATE);
603 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)) {
604 if (!r || !p) return;
605 if (w < 1 || h < 1) return;
607 WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
609 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
610 WRITESHORT(RTG_X1, x);
611 WRITESHORT(RTG_X2, w);
612 WRITESHORT(RTG_X3, p->XOffset);
613 WRITESHORT(RTG_Y1, y);
614 WRITESHORT(RTG_Y2, h);
615 WRITESHORT(RTG_Y3, p->YOffset);
617 if ((unsigned long)p->Memory > CHIP_RAM_SIZE) {
618 WRITELONG(RTG_ADDR1, (unsigned long)p->Memory);
621 unsigned long dest = CARD_SCRATCH;
622 memcpy((unsigned char *)dest, p->Memory, (2 * (1 << p->Size)));
623 WRITELONG(RTG_ADDR1, (unsigned long)dest);
626 WRITELONG(RTG_RGB1, p->FgPen);
627 WRITELONG(RTG_RGB2, p->BgPen);
629 WRITESHORT(RTG_X4, r->BytesPerRow);
630 WRITESHORT(RTG_X5, (1 << p->Size));
632 WRITEBYTE(RTG_U81, mask);
633 WRITEBYTE(RTG_U82, p->DrawMode);
634 WRITEBYTE(RTG_U83, (1 << p->Size));
635 WRITESHORT(RTG_COMMAND, RTGCMD_BLITPATTERN);
638 void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __REGA2(struct Line *l), __REGD0(UBYTE mask), __REGD7(RGBFTYPE format)) {
639 if (!r || !b) return;
641 WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
643 WRITELONG(RTG_RGB1, l->FgPen);
644 WRITELONG(RTG_RGB2, l->BgPen);
646 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
648 WRITESHORT(RTG_X1, l->X);
649 WRITESHORT(RTG_X2, l->dX);
650 WRITESHORT(RTG_Y1, l->Y);
651 WRITESHORT(RTG_Y2, l->dY);
653 WRITESHORT(RTG_X3, l->Length);
654 WRITESHORT(RTG_Y3, l->LinePtrn);
656 WRITESHORT(RTG_X4, r->BytesPerRow);
657 WRITESHORT(RTG_X5, l->PatternShift);
659 WRITEBYTE(RTG_U81, mask);
660 WRITEBYTE(RTG_U82, l->DrawMode);
661 WRITEBYTE(RTG_U83, l->pad);
663 WRITESHORT(RTG_COMMAND, RTGCMD_DRAWLINE);
666 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)) {
670 uint32_t plane_size = bm->BytesPerRow * bm->Rows;
672 uint32_t template_addr = CARD_SCRATCH;
674 uint16_t plane_mask = mask;
675 uint8_t ff_mask = 0x00;
676 uint8_t cur_plane = 0x01;
678 uint16_t line_size = (w >> 3) + 2;
679 uint32_t output_plane_size = line_size * h;
680 uint16_t x_offset = (x >> 3);
682 WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
683 WRITELONG(RTG_ADDR2, template_addr);
684 WRITESHORT(RTG_X4, r->BytesPerRow);
685 WRITESHORT(RTG_X5, line_size);
686 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[r->RGBFormat]);
688 WRITEBYTE(RTG_U81, mask);
689 WRITEBYTE(RTG_U82, minterm);
691 for (int16_t i = 0; i < bm->Depth; i++) {
692 uint16_t x_offset = (x >> 3);
693 if ((uint32_t)bm->Planes[i] == 0xFFFFFFFF) {
694 uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
695 memset(dest, 0xFF, output_plane_size);
697 else if (bm->Planes[i] != NULL) {
698 uint8_t* bmp_mem = (uint8_t*)bm->Planes[i] + (y * bm->BytesPerRow) + x_offset;
699 uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
700 for (int16_t y_line = 0; y_line < h; y_line++) {
701 memcpy(dest, bmp_mem, line_size);
703 bmp_mem += bm->BytesPerRow;
707 plane_mask &= (cur_plane ^ 0xFF);
710 template_addr += output_plane_size;
713 WRITESHORT(RTG_X1, (x & 0x07));
714 WRITESHORT(RTG_X2, dx);
715 WRITESHORT(RTG_X3, w);
716 WRITESHORT(RTG_Y1, 0);
717 WRITESHORT(RTG_Y2, dy);
718 WRITESHORT(RTG_Y3, h);
720 WRITESHORT(RTG_U1, (plane_mask << 8 | ff_mask));
721 WRITEBYTE(RTG_U83, bm->Depth);
723 WRITESHORT(RTG_COMMAND, RTGCMD_P2C);
726 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)) {
730 uint32_t plane_size = bm->BytesPerRow * bm->Rows;
732 uint32_t template_addr = CARD_SCRATCH;
734 uint16_t plane_mask = mask;
735 uint8_t ff_mask = 0x00;
736 uint8_t cur_plane = 0x01;
738 uint16_t line_size = (w >> 3) + 2;
739 uint32_t output_plane_size = line_size * h;
740 uint16_t x_offset = (x >> 3);
742 WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
743 WRITELONG(RTG_ADDR2, template_addr);
744 WRITESHORT(RTG_X4, r->BytesPerRow);
745 WRITESHORT(RTG_X5, line_size);
746 WRITESHORT(RTG_FORMAT, rgbf_to_rtg[r->RGBFormat]);
748 WRITEBYTE(RTG_U81, mask);
749 WRITEBYTE(RTG_U82, minterm);
751 memcpy((uint8_t*)((uint32_t)template_addr), clut->Colors, (256 << 2));
752 template_addr += (256 << 2);
754 for (int16_t i = 0; i < bm->Depth; i++) {
755 uint16_t x_offset = (x >> 3);
756 if ((uint32_t)bm->Planes[i] == 0xFFFFFFFF) {
757 uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
758 memset(dest, 0xFF, output_plane_size);
760 else if (bm->Planes[i] != NULL) {
761 uint8_t* bmp_mem = (uint8_t*)bm->Planes[i] + (y * bm->BytesPerRow) + x_offset;
762 uint8_t* dest = (uint8_t*)((uint32_t)template_addr);
763 for (int16_t y_line = 0; y_line < h; y_line++) {
764 memcpy(dest, bmp_mem, line_size);
766 bmp_mem += bm->BytesPerRow;
770 plane_mask &= (cur_plane ^ 0xFF);
773 template_addr += output_plane_size;
776 WRITESHORT(RTG_X1, (x & 0x07));
777 WRITESHORT(RTG_X2, dx);
778 WRITESHORT(RTG_X3, w);
779 WRITESHORT(RTG_Y1, 0);
780 WRITESHORT(RTG_Y2, dy);
781 WRITESHORT(RTG_Y3, h);
783 WRITESHORT(RTG_U1, (plane_mask << 8 | ff_mask));
784 WRITEBYTE(RTG_U83, bm->Depth);
786 WRITESHORT(RTG_COMMAND, RTGCMD_P2D);