nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include "copper.h" nuclear@0: #include "hwregs.h" nuclear@0: nuclear@0: uint32_t *copperlist, *copperlist_end; nuclear@0: static uint32_t *copmem, *curlist; nuclear@0: static void *savedlist, *savedview; nuclear@0: static int mode, copmem_size; nuclear@0: nuclear@0: struct GfxBase *GfxBase; nuclear@0: nuclear@0: int init_copper(int maxlist, int nlists) nuclear@0: { nuclear@0: /* save copper list (TODO) */ nuclear@0: if((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0))) { nuclear@0: savedlist = GfxBase->copinit; nuclear@0: savedview = GfxBase->ActiView; nuclear@0: LoadView(0); nuclear@0: WaitTOF(); nuclear@0: WaitTOF(); nuclear@0: nuclear@0: CloseLibrary(GfxBase); nuclear@0: GfxBase = 0; nuclear@0: } nuclear@0: nuclear@0: /* allocate and set new copper lists */ nuclear@0: if(maxlist <= 0) maxlist = 256; nuclear@0: mode = nlists >= COPPER_DOUBLE ? COPPER_DOUBLE : COPPER_SINGLE; nuclear@0: nuclear@0: copmem_size = maxlist * 4 * mode; nuclear@0: if(!(copmem = (uint32_t*)AllocMem(copmem_size, MEMF_CHIP))) { nuclear@0: printf("failed to allocate chip memory for %d copper lists of %d instructions\n", nuclear@0: mode, maxlist); nuclear@0: return -1; nuclear@0: } nuclear@0: nuclear@0: curlist = copperlist = copmem; nuclear@0: *curlist = COPPER_END; nuclear@0: nuclear@0: if(mode == COPPER_DOUBLE) { nuclear@0: copperlist = curlist + maxlist; nuclear@0: *copperlist = COPPER_END; nuclear@0: } nuclear@0: copperlist_end = copperlist; nuclear@0: nuclear@0: REG32_COP1LC = (uint32_t)curlist; nuclear@0: REG_COPJMP1 = 0; /* causes copper to read COP1LC */ nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void cleanup_copper(void) nuclear@0: { nuclear@0: /* restore copper list */ nuclear@0: REG32_COP1LC = (uint32_t)savedlist; nuclear@0: nuclear@0: if((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0))) { nuclear@0: GfxBase->copinit = savedlist; nuclear@0: LoadView(savedview); nuclear@0: WaitTOF(); nuclear@0: WaitTOF(); nuclear@0: CloseLibrary(GfxBase); nuclear@0: GfxBase = 0; nuclear@0: } nuclear@0: nuclear@0: if(copmem) { nuclear@0: FreeMem(copmem, copmem_size); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: void enable_copper(void) nuclear@0: { nuclear@0: REG_DMACON = SETBITS(DMA_COPPER); nuclear@0: } nuclear@0: nuclear@0: void disable_copper(void) nuclear@0: { nuclear@0: REG_DMACON = CLRBITS(DMA_COPPER); nuclear@0: } nuclear@0: nuclear@0: void clear_copper(void) nuclear@0: { nuclear@0: copperlist_end = copperlist; nuclear@0: *copperlist_end = COPPER_END; nuclear@0: } nuclear@0: nuclear@0: void add_copper(uint32_t cmd) nuclear@0: { nuclear@0: *copperlist_end++ = cmd; nuclear@0: } nuclear@0: nuclear@0: void sort_copper(void) nuclear@0: { nuclear@0: /* TODO */ nuclear@0: } nuclear@0: nuclear@0: void swap_copper(void) nuclear@0: { nuclear@0: if(mode == COPPER_DOUBLE) { nuclear@0: uint32_t *tmpptr; nuclear@0: tmpptr = curlist; nuclear@0: curlist = copperlist; nuclear@0: copperlist = copperlist_end = tmpptr; nuclear@0: nuclear@0: REG32_COP1LC = (uint32_t)curlist; nuclear@0: REG_COPJMP1 = 0; nuclear@0: } else { nuclear@0: copperlist_end = curlist; nuclear@0: } nuclear@0: *copperlist_end = COPPER_END; nuclear@0: }