amiga_imgv

view src/amiga/copper.c @ 9:01bd8bbc46d4

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Oct 2017 21:56:28 +0200
parents
children
line source
1 #include <stdio.h>
2 #include <exec/memory.h>
3 #include <exec/libraries.h>
4 #include <graphics/gfxbase.h>
5 #include "copper.h"
6 #include "hwregs.h"
8 uint32_t *copperlist, *copperlist_end;
9 static uint32_t *copmem, *curlist;
10 static void *savedlist, *savedview;
11 static int mode, copmem_size;
13 struct GfxBase *GfxBase;
15 int init_copper(int maxlist, int nlists)
16 {
17 /* save copper list (TODO) */
18 if((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0))) {
19 savedlist = GfxBase->copinit;
20 savedview = GfxBase->ActiView;
21 LoadView(0);
22 WaitTOF();
23 WaitTOF();
25 CloseLibrary(GfxBase);
26 GfxBase = 0;
27 }
29 /* allocate and set new copper lists */
30 if(maxlist <= 0) maxlist = 256;
31 mode = nlists >= COPPER_DOUBLE ? COPPER_DOUBLE : COPPER_SINGLE;
33 copmem_size = maxlist * 4 * mode;
34 if(!(copmem = (uint32_t*)AllocMem(copmem_size, MEMF_CHIP))) {
35 printf("failed to allocate chip memory for %d copper lists of %d instructions\n",
36 mode, maxlist);
37 return -1;
38 }
40 curlist = copperlist = copmem;
41 *curlist = COPPER_END;
43 if(mode == COPPER_DOUBLE) {
44 copperlist = curlist + maxlist;
45 *copperlist = COPPER_END;
46 }
47 copperlist_end = copperlist;
49 REG32_COP1LC = (uint32_t)curlist;
50 REG_COPJMP1 = 0; /* causes copper to read COP1LC */
51 return 0;
52 }
54 void cleanup_copper(void)
55 {
56 /* restore copper list */
57 REG32_COP1LC = (uint32_t)savedlist;
59 if((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0))) {
60 GfxBase->copinit = savedlist;
61 LoadView(savedview);
62 WaitTOF();
63 WaitTOF();
64 CloseLibrary(GfxBase);
65 GfxBase = 0;
66 }
68 if(copmem) {
69 FreeMem(copmem, copmem_size);
70 }
71 }
73 void enable_copper(void)
74 {
75 REG_DMACON = SETBITS(DMA_COPPER);
76 }
78 void disable_copper(void)
79 {
80 REG_DMACON = CLRBITS(DMA_COPPER);
81 }
83 void clear_copper(void)
84 {
85 copperlist_end = copperlist;
86 *copperlist_end = COPPER_END;
87 }
89 void add_copper(uint32_t cmd)
90 {
91 *copperlist_end++ = cmd;
92 }
94 void sort_copper(void)
95 {
96 /* TODO */
97 }
99 void swap_copper(void)
100 {
101 if(mode == COPPER_DOUBLE) {
102 uint32_t *tmpptr;
103 tmpptr = curlist;
104 curlist = copperlist;
105 copperlist = copperlist_end = tmpptr;
107 REG32_COP1LC = (uint32_t)curlist;
108 REG_COPJMP1 = 0;
109 } else {
110 copperlist_end = curlist;
111 }
112 *copperlist_end = COPPER_END;
113 }