amiga_cyberspace

view src/main.c @ 0:e6fd57053627

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Jul 2017 08:17:34 +0300
parents
children b5d609c7161d
line source
1 #include <stdio.h>
2 #include <proto/exec.h>
3 #include <exec/memory.h>
4 #include "inttypes.h"
5 #include "mouse.h"
6 #include "hwregs.h"
8 #define WIDTH 480
9 #define HEIGHT 128
11 #define BPLSIZE (WIDTH / 8 * HEIGHT)
12 #define MAX_HSCROLL (WIDTH - 320)
13 #define HMOD (MAX_HSCROLL / 8)
15 static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon;
17 extern uint32_t backdrop;
19 int init(void);
20 void cleanup(void);
21 void wait_vpos(int x);
22 void wait_vblank(void);
24 int main(void)
25 {
26 int x, y;
28 if(init() == -1) {
29 return 1;
30 }
32 while(!mouse_state(&x, &y)) {
33 wait_vblank();
34 REG32_BPL1PT = (uint32_t)&backdrop;
35 }
37 cleanup();
38 return 0;
39 }
41 int init(void)
42 {
43 int i, x, y, bit;
44 unsigned char *fbptr;
45 unsigned char tmp;
47 Forbid();
49 prev_dmacon = REG_DMACONR;
50 REG_DMACON = CLRBITS(DMA_ALL);
52 prev_intena = REG_INTENAR;
53 REG_INTENA = SETBITS(INTEN_ALL);
55 prev_intreq = REG_INTREQR;
56 prev_adkcon = REG_ADKCONR;
58 REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR;
59 REG_BPLCON1 = 0; /* h-scroll */
60 REG_BPL1MOD = HMOD;
61 REG_BPL2MOD = HMOD;
62 REG_DIWSTART = 0x2981;
63 REG_DIWSTOP = 0x29c1;
64 REG_DDFSTART = 0x38;
65 REG_DDFSTOP = 0xd0;
67 /* populate palette */
68 REG_COLOR0 = 0;
69 REG_COLOR1 = 0xfff;
71 wait_vblank();
72 REG32_BPL1PT = (uint32_t)&backdrop;
74 REG_DMACON = SETBITS(DMA_BPL | DMA_MASTER);
76 return 0;
77 }
79 void cleanup(void)
80 {
81 REG_DMACON = CLRBITS(DMA_ALL);
82 REG_DMACON = SETBITS(prev_dmacon);
84 REG_INTREQ = CLRBITS(0x7fff);
85 REG_INTREQ = SETBITS(prev_intreq);
87 REG_ADKCON = CLRBITS(0x7fff);
88 REG_ADKCON = SETBITS(prev_adkcon);
90 REG_INTENA = CLRBITS(INTEN_ALL);
91 REG_INTENA = SETBITS(prev_intena);
93 Permit();
94 }
96 void wait_vpos(int x)
97 {
98 x <<= 8;
99 while((REG32_VPOSR & 0x1ff00) < x);
100 }
102 void wait_vblank(void)
103 {
104 wait_vpos(300);
105 }