amiga_imgv

diff src/amiga/copper.c @ 0:a4788c959918

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 25 Oct 2017 19:34:53 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/amiga/copper.c	Wed Oct 25 19:34:53 2017 +0300
     1.3 @@ -0,0 +1,113 @@
     1.4 +#include <stdio.h>
     1.5 +#include <exec/memory.h>
     1.6 +#include <exec/libraries.h>
     1.7 +#include <graphics/gfxbase.h>
     1.8 +#include "copper.h"
     1.9 +#include "hwregs.h"
    1.10 +
    1.11 +uint32_t *copperlist, *copperlist_end;
    1.12 +static uint32_t *copmem, *curlist;
    1.13 +static void *savedlist, *savedview;
    1.14 +static int mode, copmem_size;
    1.15 +
    1.16 +struct GfxBase *GfxBase;
    1.17 +
    1.18 +int init_copper(int maxlist, int nlists)
    1.19 +{
    1.20 +	/* save copper list (TODO) */
    1.21 +	if((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0))) {
    1.22 +		savedlist = GfxBase->copinit;
    1.23 +		savedview = GfxBase->ActiView;
    1.24 +		LoadView(0);
    1.25 +		WaitTOF();
    1.26 +		WaitTOF();
    1.27 +
    1.28 +		CloseLibrary(GfxBase);
    1.29 +		GfxBase = 0;
    1.30 +	}
    1.31 +
    1.32 +	/* allocate and set new copper lists */
    1.33 +	if(maxlist <= 0) maxlist = 256;
    1.34 +	mode = nlists >= COPPER_DOUBLE ? COPPER_DOUBLE : COPPER_SINGLE;
    1.35 +
    1.36 +	copmem_size = maxlist * 4 * mode;
    1.37 +	if(!(copmem = (uint32_t*)AllocMem(copmem_size, MEMF_CHIP))) {
    1.38 +		printf("failed to allocate chip memory for %d copper lists of %d instructions\n",
    1.39 +				mode, maxlist);
    1.40 +		return -1;
    1.41 +	}
    1.42 +
    1.43 +	curlist = copperlist = copmem;
    1.44 +	*curlist = COPPER_END;
    1.45 +
    1.46 +	if(mode == COPPER_DOUBLE) {
    1.47 +		copperlist = curlist + maxlist;
    1.48 +		*copperlist = COPPER_END;
    1.49 +	}
    1.50 +	copperlist_end = copperlist;
    1.51 +
    1.52 +	REG32_COP1LC = (uint32_t)curlist;
    1.53 +	REG_COPJMP1 = 0;	/* causes copper to read COP1LC */
    1.54 +	return 0;
    1.55 +}
    1.56 +
    1.57 +void cleanup_copper(void)
    1.58 +{
    1.59 +	/* restore copper list */
    1.60 +	REG32_COP1LC = (uint32_t)savedlist;
    1.61 +
    1.62 +	if((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0))) {
    1.63 +		GfxBase->copinit = savedlist;
    1.64 +		LoadView(savedview);
    1.65 +		WaitTOF();
    1.66 +		WaitTOF();
    1.67 +		CloseLibrary(GfxBase);
    1.68 +		GfxBase = 0;
    1.69 +	}
    1.70 +
    1.71 +	if(copmem) {
    1.72 +		FreeMem(copmem, copmem_size);
    1.73 +	}
    1.74 +}
    1.75 +
    1.76 +void enable_copper(void)
    1.77 +{
    1.78 +	REG_DMACON = SETBITS(DMA_COPPER);
    1.79 +}
    1.80 +
    1.81 +void disable_copper(void)
    1.82 +{
    1.83 +	REG_DMACON = CLRBITS(DMA_COPPER);
    1.84 +}
    1.85 +
    1.86 +void clear_copper(void)
    1.87 +{
    1.88 +	copperlist_end = copperlist;
    1.89 +	*copperlist_end = COPPER_END;
    1.90 +}
    1.91 +
    1.92 +void add_copper(uint32_t cmd)
    1.93 +{
    1.94 +	*copperlist_end++ = cmd;
    1.95 +}
    1.96 +
    1.97 +void sort_copper(void)
    1.98 +{
    1.99 +	/* TODO */
   1.100 +}
   1.101 +
   1.102 +void swap_copper(void)
   1.103 +{
   1.104 +	if(mode == COPPER_DOUBLE) {
   1.105 +		uint32_t *tmpptr;
   1.106 +		tmpptr = curlist;
   1.107 +		curlist = copperlist;
   1.108 +		copperlist = copperlist_end = tmpptr;
   1.109 +
   1.110 +		REG32_COP1LC = (uint32_t)curlist;
   1.111 +		REG_COPJMP1 = 0;
   1.112 +	} else {
   1.113 +		copperlist_end = curlist;
   1.114 +	}
   1.115 +	*copperlist_end = COPPER_END;
   1.116 +}