]> git.sesse.net Git - pistorm/blob - platforms/amiga/rtg/rtg_driver_amiga/pigfx.c
2cb4877c251fac489f19bc004289f85103dced35
[pistorm] / platforms / amiga / rtg / rtg_driver_amiga / pigfx.c
1 // PiStorm RTG driver, VBCC edition.
2 // Based in part on the ZZ9000 RTG driver.
3
4 #include <proto/exec.h>
5 #include <proto/expansion.h>
6 #include <proto/dos.h>
7 #include <proto/intuition.h>
8 #include <exec/types.h>
9 #include <exec/memory.h>
10 #include <exec/libraries.h>
11 #include <exec/execbase.h>
12 #include <exec/resident.h>
13 #include <exec/initializers.h>
14 #include <clib/debug_protos.h>
15 #include <string.h>
16 #include <stdio.h>
17 #include "boardinfo.h"
18 #include "rtg_enums.h"
19
20 #define WRITESHORT(cmd, val) *(unsigned short *)((unsigned long)(b->RegisterBase)+cmd) = val;
21 #define WRITELONG(cmd, val) *(unsigned long *)((unsigned long)(b->RegisterBase)+cmd) = val;
22 #define WRITEBYTE(cmd, val) *(unsigned char *)((unsigned long)(b->RegisterBase)+cmd) = val;
23
24 #define CARD_OFFSET  0x70000000
25 #define CARD_REGSIZE 0x00010000
26 // 32MB "VRAM"
27 #define CARD_MEMSIZE 0x02000000
28 #define CHIP_RAM_SIZE 0x200000
29
30 const unsigned short rgbf_to_rtg[16] = {
31   RTGFMT_8BIT,      // 0x00
32   RTGFMT_8BIT,      // 0x01
33   0,                // 0x02
34   0,                // 0x03
35   0,                // 0x04
36   RTGFMT_RGB555,    // 0x05
37   0,                // 0x06
38   0,                // 0x07
39   RTGFMT_RGB32,     // 0x08
40   RTGFMT_RGB32,     // 0x09
41   RTGFMT_RBG565,    // 0x0A
42   RTGFMT_RGB555,    // 0x0B
43   0,                // 0x0C
44   RTGFMT_RGB555,    // 0x0D
45   0,                // 0x0E
46   0,                // 0x0F
47 };
48
49 struct GFXBase {
50   struct Library libNode;
51   BPTR segList;
52   struct ExecBase* sysBase;
53   struct ExpansionBase* expansionBase;
54 };
55
56 int FindCard(__REGA0(struct BoardInfo* b));
57 int InitCard(__REGA0(struct BoardInfo* b));
58
59 void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
60 void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border));
61 void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num));
62 void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format));
63 UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
64 UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
65
66 UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format));
67 APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format));
68 ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
69
70 LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format));
71 ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format));
72 void SetClock (__REGA0(struct BoardInfo *b));
73
74 void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format));
75 void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
76 void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask));
77 void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane));
78
79 void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle));
80
81 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));
82 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));
83 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));
84 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));
85 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));
86
87 static ULONG LibStart(void) {
88   return(-1);
89 }
90
91 static const char LibraryName[] = "PiRTG.card";
92 static const char LibraryID[]   = "$VER: PiRTG.card 0.01\r\n";
93
94 __saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase));
95 BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase));
96 BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb));
97 ULONG ExtFuncLib(void);
98 __saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
99                                  __REGA0(BPTR seglist),
100                                  __REGD0(struct GFXBase *exb));
101
102 static const APTR FuncTab[] = {
103   (APTR)OpenLib,
104   (APTR)CloseLib,
105   (APTR)ExpungeLib,
106   (APTR)ExtFuncLib,
107
108   (APTR)FindCard,
109   (APTR)InitCard,
110   (APTR)((LONG)-1)
111 };
112
113 struct InitTable
114 {
115   ULONG LibBaseSize;
116   APTR  FunctionTable;
117   APTR  DataTable;
118   APTR  InitLibTable;
119 };
120
121 static struct InitTable InitTab = {
122   (ULONG) sizeof(struct GFXBase),
123   (APTR) FuncTab,
124   (APTR) NULL,
125   (APTR) InitLib
126 };
127
128 static const struct Resident ROMTag = {
129         RTC_MATCHWORD,
130   &ROMTag,
131   &ROMTag + 1,
132   RTF_AUTOINIT,
133         83,
134   NT_LIBRARY,
135   0,
136   (char *)LibraryName,
137   (char *)LibraryID,
138   (APTR)&InitTab
139 };
140
141 #define CLOCK_HZ 100000000
142
143 static struct GFXBase *_gfxbase;
144 const char *gfxname = "PiStorm RTG";
145 char dummies[128];
146
147 __saveds struct GFXBase* InitLib(__REGA6(struct ExecBase *sysbase),
148                                           __REGA0(BPTR seglist),
149                                           __REGD0(struct GFXBase *exb))
150 {
151   _gfxbase = exb;
152   return _gfxbase;
153 }
154
155 __saveds struct GFXBase* OpenLib(__REGA6(struct GFXBase *gfxbase))
156 {
157   gfxbase->libNode.lib_OpenCnt++;
158   gfxbase->libNode.lib_Flags &= ~LIBF_DELEXP;
159
160   return gfxbase;
161 }
162
163 BPTR __saveds CloseLib(__REGA6(struct GFXBase *gfxbase))
164 {
165   gfxbase->libNode.lib_OpenCnt--;
166
167   if (!gfxbase->libNode.lib_OpenCnt) {
168     if (gfxbase->libNode.lib_Flags & LIBF_DELEXP) {
169       return (ExpungeLib(gfxbase));
170     }
171   }
172   return 0;
173 }
174
175 BPTR __saveds ExpungeLib(__REGA6(struct GFXBase *exb))
176 {
177   BPTR seglist;
178   struct ExecBase *SysBase = *(struct ExecBase **)4L;
179
180   if(!exb->libNode.lib_OpenCnt) {
181     ULONG negsize, possize, fullsize;
182     UBYTE *negptr = (UBYTE *)exb;
183
184     seglist = exb->segList;
185
186     Remove((struct Node *)exb);
187
188     negsize  = exb->libNode.lib_NegSize;
189     possize  = exb->libNode.lib_PosSize;
190     fullsize = negsize + possize;
191     negptr  -= negsize;
192
193     FreeMem(negptr, fullsize);
194     return(seglist);
195   }
196
197   exb->libNode.lib_Flags |= LIBF_DELEXP;
198   return 0;
199 }
200
201 ULONG ExtFuncLib(void)
202 {
203   return 0;
204 }
205
206 static LONG zorro_version = 0;
207
208 static struct GFXData *gfxdata;
209 //MNTZZ9KRegs* registers;
210
211 #define LOADLIB(a, b) if ((a = (struct a*)OpenLibrary(b,0L))==NULL) { \
212     KPrintF("Failed to load %s.\n", b); \
213     return 0; \
214   } \
215
216 static BYTE card_already_found;
217 static BYTE card_initialized;
218
219 int FindCard(__REGA0(struct BoardInfo* b)) {
220   //if (card_already_found)
221 //    return 1;
222   struct ConfigDev* cd = NULL;
223   struct ExpansionBase *ExpansionBase = NULL;
224   struct DOSBase *DOSBase = NULL;
225   struct IntuitionBase *IntuitionBase = NULL;
226   struct ExecBase *SysBase = *(struct ExecBase **)4L;
227
228   LOADLIB(ExpansionBase, "expansion.library");
229   LOADLIB(DOSBase, "dos.library");
230   LOADLIB(IntuitionBase, "intuition.library");
231
232   b->MemorySize = CARD_MEMSIZE;
233   b->RegisterBase = (void *)CARD_OFFSET;
234   b->MemoryBase = (void *)(CARD_OFFSET + CARD_REGSIZE);
235
236   return 1;
237 }
238
239 #define HWSPRITE 1
240 #define VGASPLIT (1 << 6)
241 #define FLICKERFIXER (1 << 12)
242 #define INDISPLAYCHAIN (1 << 20)
243 #define DIRECTACCESS (1 << 26)
244
245 int InitCard(__REGA0(struct BoardInfo* b)) {
246   //if (!card_initialized)
247 //    card_initialized = 1;
248 //  else
249     //return 1;
250
251   int max, i;
252   struct ExecBase *SysBase = *(struct ExecBase **)4L;
253
254   b->CardBase = (struct CardBase *)_gfxbase;
255   b->ExecBase = SysBase;
256   b->BoardName = "PiStorm RTG";
257   b->BoardType = BT_MNT_ZZ9000;
258   b->PaletteChipType = PCT_MNT_ZZ9000;
259   b->GraphicsControllerType = GCT_MNT_ZZ9000;
260
261   b->Flags = BIF_INDISPLAYCHAIN | BIF_GRANTDIRECTACCESS;
262   b->RGBFormats = 1 | 2 | 512 | 1024 | 2048;
263   b->SoftSpriteFlags = 0;
264   b->BitsPerCannon = 8;
265
266   for(i = 0; i < MAXMODES; i++) {
267     b->MaxHorValue[i] = 1920;
268     b->MaxVerValue[i] = 1080;
269     b->MaxHorResolution[i] = 1920;
270     b->MaxVerResolution[i] = 1080;
271     b->PixelClockCount[i] = 1;
272   }
273
274   b->MemoryClock = CLOCK_HZ;
275
276   //b->AllocCardMem = (void *)NULL;
277   //b->FreeCardMem = (void *)NULL;
278   b->SetSwitch = (void *)SetSwitch;
279   b->SetColorArray = (void *)SetColorArray;
280   b->SetDAC = (void *)SetDAC;
281   b->SetGC = (void *)SetGC;
282   b->SetPanning = (void *)SetPanning;
283   b->CalculateBytesPerRow = (void *)CalculateBytesPerRow;
284   b->CalculateMemory = (void *)CalculateMemory;
285   b->GetCompatibleFormats = (void *)GetCompatibleFormats;
286   b->SetDisplay = (void *)SetDisplay;
287
288   b->ResolvePixelClock = (void *)ResolvePixelClock;
289   b->GetPixelClock = (void *)GetPixelClock;
290   b->SetClock = (void *)SetClock;
291
292   b->SetMemoryMode = (void *)SetMemoryMode;
293   b->SetWriteMask = (void *)SetWriteMask;
294   b->SetClearMask = (void *)SetClearMask;
295   b->SetReadPlane = (void *)SetReadPlane;
296
297   b->WaitVerticalSync = (void *)WaitVerticalSync;
298   //b->SetInterrupt = (void *)NULL;
299
300   //b->WaitBlitter = (void *)NULL;
301
302   //b->ScrollPlanar = (void *)NULL;
303   //b->UpdatePlanar = (void *)NULL;
304
305   //b->BlitPlanar2Chunky = (void *)NULL;
306   //b->BlitPlanar2Direct = (void *)NULL;
307
308   b->FillRect = (void *)FillRect;
309   //b->InvertRect = (void *)NULL;
310   b->BlitRect = (void *)BlitRect;
311   b->BlitTemplate = (void *)BlitTemplate;
312   b->BlitPattern = (void *)BlitPattern;
313   //b->DrawLine = (void *)NULL;
314   b->BlitRectNoMaskComplete = (void *)BlitRectNoMaskComplete;
315   //b->EnableSoftSprite = (void *)NULL;
316
317   //b->AllocCardMemAbs = (void *)NULL;
318   //b->SetSplitPosition = (void *)NULL;
319   //b->ReInitMemory = (void *)NULL;
320   //b->WriteYUVRect = (void *)NULL;
321   //b->GetVSyncState = (void *)NULL;
322   //b->GetVBeamPos = (void *)NULL;
323   //b->SetDPMSLevel = (void *)NULL;
324   //b->ResetChip = (void *)NULL;
325   //b->GetFeatureAttrs = (void *)NULL;
326   //b->AllocBitMap = (void *)NULL;
327   //b->FreeBitMap = (void *)NULL;
328   //b->GetBitMapAttr = (void *)NULL;
329
330   //b->SetSprite = (void *)NULL;
331   //b->SetSpritePosition = (void *)NULL;
332   //b->SetSpriteImage = (void *)NULL;
333   //b->SetSpriteColor = (void *)NULL;
334
335   //b->CreateFeature = (void *)NULL;
336   //b->SetFeatureAttrs = (void *)NULL;
337   //b->DeleteFeature = (void *)NULL;
338
339   return 1;
340 }
341
342 void SetDAC (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
343   // Used to set the color format of the video card's RAMDAC.
344   // This needs no handling, since the PiStorm doesn't really have a RAMDAC or a video card chipset.
345 }
346
347 void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border)) {
348   b->ModeInfo = mode_info;
349   // Send width, height and format to the RaspberryPi Targetable Graphics.
350   WRITESHORT(RTG_X1, mode_info->Width);
351   WRITESHORT(RTG_Y1, mode_info->Height);
352   WRITESHORT(RTG_FORMAT, rgbf_to_rtg[b->RGBFormat]);
353   WRITESHORT(RTG_COMMAND, RTGCMD_SETGC);
354 }
355
356 int setswitch = -1;
357 UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
358   if (setswitch != enabled) {
359     setswitch = enabled;
360   }
361   
362   WRITEBYTE(RTG_U81, setswitch);
363   WRITESHORT(RTG_X1, setswitch);
364   WRITESHORT(RTG_COMMAND, RTGCMD_SETSWITCH);
365
366   return 1 - enabled;
367 }
368
369 void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format)) {
370   // Set the panning offset, or the offset used for the current display area on the Pi.
371   // The address needs to have CARD_BASE subtracted from it to be used as an offset on the Pi side.
372   if (!b)
373     return;
374
375   b->XOffset = x_offset;
376   b->YOffset = y_offset;
377
378   WRITELONG(RTG_ADDR1, (unsigned long)addr);
379   WRITESHORT(RTG_X1, width);
380   WRITESHORT(RTG_X2, b->XOffset);
381   WRITESHORT(RTG_Y2, b->YOffset);
382   WRITESHORT(RTG_COMMAND, RTGCMD_SETPAN);
383 }
384
385 void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num)) {
386   // Sets the color components of X color components for 8-bit paletted display modes.
387   if (!b->CLUT)
388     return;
389   
390   int j = start + num;
391   
392   for(int i = start; i < j; i++) {
393     //WRITEBYTE(RTG_U82, (unsigned char)b->CLUT[i].Red);
394     //WRITEBYTE(RTG_U83, (unsigned char)b->CLUT[i].Green);
395     //WRITEBYTE(RTG_U84, (unsigned char)b->CLUT[i].Blue);
396     unsigned long xrgb = 0 | (b->CLUT[i].Red << 16) | (b->CLUT[i].Green << 8) | (b->CLUT[i].Blue);
397     WRITEBYTE(RTG_U81, (unsigned char)i);
398     WRITELONG(RTG_RGB1, xrgb);
399     WRITESHORT(RTG_COMMAND, RTGCMD_SETCLUT);
400   }
401 }
402
403 UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format)) {
404   if (!b)
405     return 0;
406
407   UWORD pitch = width;
408
409   switch(format) {
410     default:
411       return pitch;
412     case 0x05: case 0x0A: case 0x0B: case 0x0D:
413       return (width * 2);
414     case 0x08: case 0x09:
415       return (width * 4);
416   }
417 }
418
419 APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned long addr), __REGD7(RGBFTYPE format)) {
420   /*if (!b)
421     return (APTR)addr;
422
423   if (addr > (unsigned int)b->MemoryBase && addr < (((unsigned int)b->MemoryBase) + b->MemorySize)) {
424     addr = ((addr + 0x1000) & 0xFFFFF000);
425   }*/
426
427   return (APTR)addr;
428 }
429
430 ULONG GetCompatibleFormats (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
431   // It is of course compatible with all the formats ever.
432   return 0xFFFFFFFF;
433 }
434
435 static int display_enabled = 0;
436 UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
437   // Enables or disables the display.
438   WRITEBYTE(RTG_U82, (unsigned char)enabled);
439   WRITESHORT(RTG_COMMAND, RTGCMD_SETDISPLAY);
440
441   return 1;
442 }
443
444 LONG ResolvePixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG pixel_clock), __REGD7(RGBFTYPE format)) {
445   mode_info->PixelClock = CLOCK_HZ;
446   mode_info->pll1.Clock = 0;
447   mode_info->pll2.ClockDivide = 1;
448
449   return 0;
450 }
451
452 ULONG GetPixelClock (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(ULONG index), __REGD7(RGBFTYPE format)) {
453   // Just return 100MHz.
454   return CLOCK_HZ;
455 }
456
457 // None of these five really have to do anything.
458 void SetClock (__REGA0(struct BoardInfo *b)) {
459 }
460
461 void SetMemoryMode (__REGA0(struct BoardInfo *b), __REGD7(RGBFTYPE format)) {
462 }
463
464 void SetWriteMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
465 }
466
467 void SetClearMask (__REGA0(struct BoardInfo *b), __REGD0(UBYTE mask)) {
468 }
469
470 void SetReadPlane (__REGA0(struct BoardInfo *b), __REGD0(UBYTE plane)) {
471 }
472
473 void WaitVerticalSync (__REGA0(struct BoardInfo *b), __REGD0(BOOL toggle)) {
474   // I don't know why this one has a bool in D0, but it isn't used for anything.
475 }
476
477 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)) {
478   if (!r)
479     return;
480   if (mask != 0xFF) {
481     b->FillRectDefault(b, r, x, y, w, h, color, mask, format);
482     return;
483   }
484
485   WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
486   
487   WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
488   WRITESHORT(RTG_X1, x);
489   WRITESHORT(RTG_X2, w);
490   WRITESHORT(RTG_Y1, y);
491   WRITESHORT(RTG_Y2, h);
492   WRITELONG(RTG_RGB1, color);
493   WRITESHORT(RTG_X3, r->BytesPerRow);
494   WRITESHORT(RTG_COMMAND, RTGCMD_FILLRECT);
495 }
496
497 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)) {
498   if (!r)
499     return;
500   if (mask != 0xFF) {
501     b->BlitRectDefault(b, r, x, y, dx, dy, w, h, mask, format);
502     return;
503   }
504
505   WRITELONG(RTG_ADDR1, (unsigned long)r->Memory);
506
507   WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
508   WRITESHORT(RTG_X1, x);
509   WRITESHORT(RTG_X2, dx);
510   WRITESHORT(RTG_X3, w);
511   WRITESHORT(RTG_Y1, y);
512   WRITESHORT(RTG_Y2, dy);
513   WRITESHORT(RTG_Y3, h);
514   WRITESHORT(RTG_X4, r->BytesPerRow);
515   WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT);
516 }
517
518 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)) {
519   if (!rs || !rt)
520     return;
521   if (minterm != MINTERM_SRC) {
522     b->BlitRectNoMaskCompleteDefault(b, rs, rt, x, y, dx, dy, w, h, minterm, format);
523     return;
524   }
525
526   WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
527   WRITELONG(RTG_ADDR1, (unsigned long)rs->Memory);
528   WRITELONG(RTG_ADDR2, (unsigned long)rt->Memory);
529   WRITESHORT(RTG_X1, x);
530   WRITESHORT(RTG_X2, dx);
531   WRITESHORT(RTG_X3, w);
532   WRITESHORT(RTG_Y1, y);
533   WRITESHORT(RTG_Y2, dy);
534   WRITESHORT(RTG_Y3, h);
535   WRITESHORT(RTG_X4, rs->BytesPerRow);
536   WRITESHORT(RTG_X5, rt->BytesPerRow);
537   WRITEBYTE(RTG_U81, minterm);
538   WRITESHORT(RTG_COMMAND, RTGCMD_BLITRECT_NOMASK_COMPLETE);
539 }
540
541 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)) {
542   if (!r || !t) return;
543   if (w < 1 || h < 1) return;
544
545   if (mask != 0xFF) {
546     b->BlitTemplateDefault(b, r, t, x, y, w, h, mask, format);
547     return;
548   }
549
550   WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
551
552   WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
553   WRITESHORT(RTG_X1, x);
554   WRITESHORT(RTG_X2, w);
555   WRITESHORT(RTG_X3, t->XOffset);
556   WRITESHORT(RTG_Y1, y);
557   WRITESHORT(RTG_Y2, h);
558   WRITESHORT(RTG_Y3, 0);
559
560   if ((unsigned long)t->Memory > CHIP_RAM_SIZE) {
561     WRITELONG(RTG_ADDR1, (unsigned long)t->Memory);
562   }
563   else {
564     UBYTE *dest = (UBYTE *)((unsigned long)(CARD_OFFSET + CARD_REGSIZE + CARD_MEMSIZE) - 0x1000 - (t->BytesPerRow * h));
565     memcpy(dest, t->Memory, (t->BytesPerRow * h));
566     WRITELONG(RTG_ADDR1, (unsigned long)dest);
567   }
568
569   WRITELONG(RTG_RGB1, t->FgPen);
570   WRITELONG(RTG_RGB2, t->BgPen);
571
572   WRITESHORT(RTG_X4, r->BytesPerRow);
573   WRITESHORT(RTG_X5, t->BytesPerRow);
574
575   WRITEBYTE(RTG_U81, mask);
576   WRITEBYTE(RTG_U82, t->DrawMode);
577   WRITESHORT(RTG_COMMAND, RTGCMD_BLITTEMPLATE);
578 }
579
580 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)) {
581   if (!r || !p) return;
582   if (w < 1 || h < 1) return;
583
584   if (mask != 0xFF) {
585     b->BlitPatternDefault(b, r, p, x, y, w, h, mask, format);
586     return;
587   }
588
589   WRITELONG(RTG_ADDR2, (unsigned long)r->Memory);
590
591   WRITESHORT(RTG_FORMAT, rgbf_to_rtg[format]);
592   WRITESHORT(RTG_X1, x);
593   WRITESHORT(RTG_X2, w);
594   WRITESHORT(RTG_X3, p->XOffset);
595   WRITESHORT(RTG_Y1, y);
596   WRITESHORT(RTG_Y2, h);
597   WRITESHORT(RTG_Y3, p->YOffset);
598
599   if ((unsigned long)p->Memory > CHIP_RAM_SIZE) {
600     WRITELONG(RTG_ADDR1, (unsigned long)p->Memory);
601   }
602   else {
603     UBYTE *dest = (UBYTE *)((unsigned long)(CARD_OFFSET + CARD_REGSIZE + CARD_MEMSIZE) - 0x1000 - (2 * (1 << p->Size)));
604     memcpy(dest, p->Memory, (2 * (1 << p->Size)));
605     WRITELONG(RTG_ADDR1, (unsigned long)dest);
606   }
607
608   WRITELONG(RTG_RGB1, p->FgPen);
609   WRITELONG(RTG_RGB2, p->BgPen);
610
611   WRITESHORT(RTG_X4, r->BytesPerRow);
612   WRITESHORT(RTG_X5, (1 << p->Size));
613
614   WRITEBYTE(RTG_U81, mask);
615   WRITEBYTE(RTG_U82, p->DrawMode);
616   WRITEBYTE(RTG_U83, (1 << p->Size));
617   WRITESHORT(RTG_COMMAND, RTGCMD_BLITPATTERN);
618 }