View Single Post
Old 12 October 2019, 13:10   #38
Spec-Chum
Registered User
 
Join Date: Dec 2016
Location: England
Posts: 87
Awesome work.

Had a quick play and converted my asm takeover code to C and it worked

One snag, however, I couldn't figure out how to put the copperlist array into chip mem? I tried
Code:
__chip
but it didn't work. Using attributes didn't work either as it just says they're disabled.

Any idea how to specify something needs to be in chip mem?

Here's the full code, it kinda just draws a flag, but I'm quite a noob, so this probably isn't the best way of doing it lol

Code:
#include "support/gcc8_c_support.h"
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <graphics/gfxbase.h>
#include <graphics/view.h>
#include <exec/execbase.h>
#include <hardware/Custom.h>
#include <hardware/intbits.h>

struct ExecBase *SysBase;
struct GfxBase *GfxBase;
volatile struct Custom *Custom;

struct View *OldView;
static UWORD oldInt;
static UWORD oldDMA;

APTR cl;

// Copperlist (FIXME: This should be in chipmem)
static UWORD copperlist[] = 
{
	    0x0100, 0x0200,		// don't need any Bitplanes
        0x0180, 0x0f00,		// Colour00 = red
        0x8001, 0xff00,     // wait until VPos = 0x80
        0x0180, 0x0fff,     // Colour00 = white
        0xd001, 0xff00,		// wait until VPos 0xd0
        0x0180, 0x000f, 	// Colour00 = blue
		0xffff, 0xfffe		// end list
};

int main()
{
	SysBase = *((struct ExecBase**)4UL);
	Custom = (struct Custom*)0xdff000;

	GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0);

	// put copperlist in chip mem (FIXME: must be a way to put copperlist[] there?)
	cl = AllocMem(sizeof(copperlist), MEMF_CHIP);
	CopyMem(copperlist, cl, sizeof(copperlist));

	// Save original view
	OldView = GfxBase->ActiView;

	// Set clean view
	LoadView(0);
	WaitTOF();
	WaitTOF();

	// Save interrupts and DMA
	oldDMA = Custom->intenar;
	oldInt = Custom->dmaconr;

	// disable all interrupts
	Custom->intena = 0x7fff;

	// disable all DMA
	Custom->dmacon = 0x7fff;

	// set cl1 to our copper
	Custom->cop1lc = (ULONG)cl;
	
	// enable selected DMA
	Custom->dmacon = 0x8280;	// No Blitter or sprites, only copper

	// loop until mouse clicked
	while(((*(volatile UBYTE*)0xbfe001) & 64))
	{

	}

	// restore interrupts and DMA
	Custom->dmaconr = oldDMA | 0x8000;
	Custom->intenar = oldInt | 0x8000;

	// restore orginal copper
	Custom->cop1lc = (ULONG)GfxBase->copinit;

	// restore old view
	LoadView(OldView);
	WaitTOF();
	WaitTOF();

	// free copperlist memory
	FreeMem(cl, sizeof(copperlist));

	CloseLibrary((struct Library*)GfxBase);

	return 0;
}
Spec-Chum is offline  
 
Page generated in 0.04242 seconds with 11 queries