amiga_cyberspace

view src/main.c @ 1:b5d609c7161d

copper
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 26 Jul 2017 08:45:20 +0300
parents e6fd57053627
children b98fa9b135ea
line source
1 #include <stdio.h>
2 #include <proto/exec.h>
3 #include <exec/memory.h>
4 #include "inttypes.h"
5 #include "copper.h"
6 #include "mouse.h"
7 #include "hwregs.h"
9 #define WIDTH 480
10 #define HEIGHT 128
12 #define BPLSIZE (WIDTH / 8 * HEIGHT)
13 #define MAX_HSCROLL (WIDTH - 320)
14 #define HMOD (MAX_HSCROLL / 8)
16 static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon;
18 extern uint32_t backdrop;
20 int init(void);
21 void cleanup(void);
22 void wait_vpos(int x);
23 void wait_vblank(void);
25 int main(void)
26 {
27 int x, y;
29 if(init() == -1) {
30 return 1;
31 }
33 while(!mouse_state(&x, &y)) {
34 wait_vblank();
35 REG32_BPL1PT = (uint32_t)&backdrop;
36 }
38 cleanup();
39 return 0;
40 }
42 int init(void)
43 {
44 int i, x, y, bit;
45 unsigned char *fbptr;
46 unsigned char tmp;
48 Forbid();
50 /* initialize copper */
51 if(init_copper(0, 0) == -1) {
52 return -1;
53 }
55 prev_dmacon = REG_DMACONR;
56 REG_DMACON = CLRBITS(DMA_ALL);
58 prev_intena = REG_INTENAR;
59 REG_INTENA = SETBITS(INTEN_ALL);
61 prev_intreq = REG_INTREQR;
62 prev_adkcon = REG_ADKCONR;
64 REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR;
65 REG_BPLCON1 = 0; /* h-scroll */
66 REG_BPL1MOD = HMOD;
67 REG_BPL2MOD = HMOD;
68 REG_DIWSTART = 0x2981;
69 REG_DIWSTOP = 0x29c1;
70 REG_DDFSTART = 0x38;
71 REG_DDFSTOP = 0xd0;
73 /* populate palette */
74 REG_COLOR0 = 0;
75 REG_COLOR1 = 0xfff;
77 wait_vblank();
78 REG32_BPL1PT = (uint32_t)&backdrop;
80 add_copper(COPPER_VWAIT(40));
81 add_copper(COPPER_MOVE(REGN_COLOR1, 0xf80));
82 add_copper(COPPER_VWAIT(45));
83 add_copper(COPPER_MOVE(REGN_COLOR1, 0xfff));
84 add_copper(COPPER_END);
86 REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER);
87 return 0;
88 }
90 void cleanup(void)
91 {
92 REG_DMACON = CLRBITS(DMA_ALL);
93 REG_DMACON = SETBITS(prev_dmacon);
95 REG_INTREQ = CLRBITS(0x7fff);
96 REG_INTREQ = SETBITS(prev_intreq);
98 REG_ADKCON = CLRBITS(0x7fff);
99 REG_ADKCON = SETBITS(prev_adkcon);
101 REG_INTENA = CLRBITS(INTEN_ALL);
102 REG_INTENA = SETBITS(prev_intena);
104 cleanup_copper();
105 Permit();
106 }
108 void wait_vpos(int x)
109 {
110 x <<= 8;
111 while((REG32_VPOSR & 0x1ff00) < x);
112 }
114 void wait_vblank(void)
115 {
116 wait_vpos(300);
117 }