View Single Post
Old 18 October 2019, 00:23   #4
Spec-Chum
Registered User

 
Join Date: Dec 2016
Location: England
Posts: 86
Quote:
Originally Posted by mcgeezer View Post
(although I've never written any C before).
I really doubt a man of your skill will have much issues mate, if I'm honest.

C can be made very asm like, indeed that was what it was designed for, as an almost 1 to 1 correlation with asm.

As an example I've decided to code Scoopex's tutorials into C, so I'm not just copying and pasting. Here's tut4. You can most probably guess the code this produces, as it's virtually identical to Photon's source.

Code:
#include <exec/types.h>

#define VPOSR 0xdff004
#define VHPOSR 0xdff006
#define INTENAR 0xdff01c
#define INTENA 0xdff09a
#define COLOR00 0xdff180
#define CIAPRAA 0xbfe001

int main()
{
	volatile UBYTE *vhposr = (UBYTE *)VHPOSR;
	volatile UBYTE *vposr_lo = (UBYTE *)VPOSR + 1;	// point to low byte
	UWORD *color00 = (UWORD *)COLOR00;
	UWORD *intena = (UWORD *)INTENA;

	// line starting position
	UBYTE yPos = 0xac;

	// line direction
	BYTE yDir = 1;

	// save interrupts
	UWORD oldInt = *(UWORD *)INTENAR;

	// disable all interrupts
	*intena = 0x7fff;

	// do main loop until mouse pressed
	while(*(volatile UBYTE *)CIAPRAA & 64)
	{
		// wait for start of frame
		if((*vposr_lo & 1) == 0 && *vhposr == 0x2c)
		{
			*color00 = 0;	// bg black

			// update line y position
			yPos += yDir;

			// bounce line
			if(yPos > 0xf0 || yPos < 0x40)
			{
				yDir = -yDir;
			}

			// do literally nothing until we reach yPos
			while(*vhposr != yPos)
			{}
			*color00 = 0xfff;	// bg white

			// now do nothing until we're not on yPos
			while(*vhposr == yPos)
			{}
			*color00 = 0x116;	// bg blue
		}
	}

	// restore interrupts
	*intena = oldInt | 0xc000;	
	
    return 0;
}
On the other side of the coin, you can use the headers to (to some) make your life a little easier, here's my asm takeover code I converted to C:

Code:
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <exec/execbase.h>
#include <hardware/cia.h>
#include <hardware/custom.h>
#include <graphics/gfxbase.h>

extern struct GfxBase *GfxBase;
extern struct Custom custom;
extern struct CIA ciaa;

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

__chip UWORD copperlist[] =
{
        0x0106, 0x0000,     // AGA - BPLCON3
        0x01fc, 0x0000,     // AGA - Slow FMODE

    	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()
{
	// Save original view
	OldView = GfxBase->ActiView;

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

	// Save interrupts and DMA
	oldInt = custom.intenar;
	oldDMA = custom.dmaconr;

	// disable all interrupts
	custom.intena = 0x7fff;

	// disable all DMA
	custom.dmacon = 0x7fff;

	// set cl1 to our copper
	custom.cop1lc = (ULONG)copperlist;
	
	// enable selected DMA
	custom.dmacon = 0x8280;	// No Blitter or sprites, only copper

	// loop until mouse clicked
	while(ciaa.ciapra & CIAF_GAMEPORT0)
	{
		// do nothing
	}

	// restore interrupts and DMA
	custom.dmacon = oldDMA | 0x8000;
	custom.intena = oldInt | 0x8000;

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

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

	return 0;
}

Last edited by Spec-Chum; 18 October 2019 at 00:41.
Spec-Chum is offline  
 
Page generated in 0.04536 seconds with 11 queries