brought the code over from the amiga test
[lugburz] / src / amiga / copper.c
1 #include "copper.h"
2 #include "hwregs.h"
3
4 uint32_t *copperlist, *copperlist_end;
5 static uint32_t *copmem, *curlist;
6 static int mode, copmem_size;
7
8 extern uint32_t **_mem_start;
9
10 int init_copper(uint32_t *cmem, int maxlist, int nlists)
11 {
12         /* allocate and set new copper lists */
13         if(maxlist <= 0) maxlist = 256;
14         mode = nlists >= COPPER_DOUBLE ? COPPER_DOUBLE : COPPER_SINGLE;
15
16         copmem_size = maxlist * 4 * mode;
17         copmem = cmem ? cmem : *_mem_start;
18
19         curlist = copperlist = copmem;
20         *curlist = COPPER_END;
21
22         if(mode == COPPER_DOUBLE) {
23                 copperlist = curlist + maxlist;
24                 *copperlist = COPPER_END;
25         }
26         copperlist_end = copperlist;
27
28         REG32_COP1LC = (uint32_t)curlist;
29         REG_COPJMP1 = 0;        /* causes copper to read COP1LC */
30         return 0;
31 }
32
33 void cleanup_copper(void)
34 {
35 }
36
37 void enable_copper(void)
38 {
39         REG_DMACON = SETBITS(DMA_COPPER);
40 }
41
42 void disable_copper(void)
43 {
44         REG_DMACON = CLRBITS(DMA_COPPER);
45 }
46
47 void clear_copper(void)
48 {
49         copperlist_end = copperlist;
50         *copperlist_end = COPPER_END;
51 }
52
53 void add_copper(uint32_t cmd)
54 {
55         *copperlist_end++ = cmd;
56 }
57
58 void sort_copper(void)
59 {
60         /* TODO */
61 }
62
63 void swap_copper(void)
64 {
65         if(mode == COPPER_DOUBLE) {
66                 uint32_t *tmpptr;
67                 tmpptr = curlist;
68                 curlist = copperlist;
69                 copperlist = copperlist_end = tmpptr;
70
71                 REG32_COP1LC = (uint32_t)curlist;
72                 REG_COPJMP1 = 0;
73         } else {
74                 copperlist_end = curlist;
75         }
76         *copperlist_end = COPPER_END;
77 }