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