amiga_cyberspace

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main.c	Tue Jul 25 08:17:34 2017 +0300
     1.3 @@ -0,0 +1,105 @@
     1.4 +#include <stdio.h>
     1.5 +#include <proto/exec.h>
     1.6 +#include <exec/memory.h>
     1.7 +#include "inttypes.h"
     1.8 +#include "mouse.h"
     1.9 +#include "hwregs.h"
    1.10 +
    1.11 +#define WIDTH	480
    1.12 +#define HEIGHT	128
    1.13 +
    1.14 +#define BPLSIZE		(WIDTH / 8 * HEIGHT)
    1.15 +#define MAX_HSCROLL	(WIDTH - 320)
    1.16 +#define HMOD		(MAX_HSCROLL / 8)
    1.17 +
    1.18 +static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon;
    1.19 +
    1.20 +extern uint32_t backdrop;
    1.21 +
    1.22 +int init(void);
    1.23 +void cleanup(void);
    1.24 +void wait_vpos(int x);
    1.25 +void wait_vblank(void);
    1.26 +
    1.27 +int main(void)
    1.28 +{
    1.29 +	int x, y;
    1.30 +
    1.31 +	if(init() == -1) {
    1.32 +		return 1;
    1.33 +	}
    1.34 +
    1.35 +	while(!mouse_state(&x, &y)) {
    1.36 +		wait_vblank();
    1.37 +		REG32_BPL1PT = (uint32_t)&backdrop;
    1.38 +	}
    1.39 +
    1.40 +	cleanup();
    1.41 +	return 0;
    1.42 +}
    1.43 +
    1.44 +int init(void)
    1.45 +{
    1.46 +	int i, x, y, bit;
    1.47 +	unsigned char *fbptr;
    1.48 +	unsigned char tmp;
    1.49 +
    1.50 +	Forbid();
    1.51 +
    1.52 +	prev_dmacon = REG_DMACONR;
    1.53 +	REG_DMACON = CLRBITS(DMA_ALL);
    1.54 +
    1.55 +	prev_intena = REG_INTENAR;
    1.56 +	REG_INTENA = SETBITS(INTEN_ALL);
    1.57 +
    1.58 +	prev_intreq = REG_INTREQR;
    1.59 +	prev_adkcon = REG_ADKCONR;
    1.60 +
    1.61 +	REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR;
    1.62 +	REG_BPLCON1 = 0;	/* h-scroll */
    1.63 +	REG_BPL1MOD = HMOD;
    1.64 +	REG_BPL2MOD = HMOD;
    1.65 +	REG_DIWSTART = 0x2981;
    1.66 +	REG_DIWSTOP = 0x29c1;
    1.67 +	REG_DDFSTART = 0x38;
    1.68 +	REG_DDFSTOP = 0xd0;
    1.69 +
    1.70 +	/* populate palette */
    1.71 +	REG_COLOR0 = 0;
    1.72 +	REG_COLOR1 = 0xfff;
    1.73 +
    1.74 +	wait_vblank();
    1.75 +	REG32_BPL1PT = (uint32_t)&backdrop;
    1.76 +
    1.77 +	REG_DMACON = SETBITS(DMA_BPL | DMA_MASTER);
    1.78 +
    1.79 +	return 0;
    1.80 +}
    1.81 +
    1.82 +void cleanup(void)
    1.83 +{
    1.84 +	REG_DMACON = CLRBITS(DMA_ALL);
    1.85 +	REG_DMACON = SETBITS(prev_dmacon);
    1.86 +
    1.87 +	REG_INTREQ = CLRBITS(0x7fff);
    1.88 +	REG_INTREQ = SETBITS(prev_intreq);
    1.89 +
    1.90 +	REG_ADKCON = CLRBITS(0x7fff);
    1.91 +	REG_ADKCON = SETBITS(prev_adkcon);
    1.92 +
    1.93 +	REG_INTENA = CLRBITS(INTEN_ALL);
    1.94 +	REG_INTENA = SETBITS(prev_intena);
    1.95 +
    1.96 +	Permit();
    1.97 +}
    1.98 +
    1.99 +void wait_vpos(int x)
   1.100 +{
   1.101 +	x <<= 8;
   1.102 +	while((REG32_VPOSR & 0x1ff00) < x);
   1.103 +}
   1.104 +
   1.105 +void wait_vblank(void)
   1.106 +{
   1.107 +	wait_vpos(300);
   1.108 +}