amiga_cyberspace
annotate 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 |
rev | line source |
---|---|
nuclear@0 | 1 #include <stdio.h> |
nuclear@0 | 2 #include <proto/exec.h> |
nuclear@0 | 3 #include <exec/memory.h> |
nuclear@0 | 4 #include "inttypes.h" |
nuclear@0 | 5 #include "mouse.h" |
nuclear@0 | 6 #include "hwregs.h" |
nuclear@0 | 7 |
nuclear@0 | 8 #define WIDTH 480 |
nuclear@0 | 9 #define HEIGHT 128 |
nuclear@0 | 10 |
nuclear@0 | 11 #define BPLSIZE (WIDTH / 8 * HEIGHT) |
nuclear@0 | 12 #define MAX_HSCROLL (WIDTH - 320) |
nuclear@0 | 13 #define HMOD (MAX_HSCROLL / 8) |
nuclear@0 | 14 |
nuclear@0 | 15 static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon; |
nuclear@0 | 16 |
nuclear@0 | 17 extern uint32_t backdrop; |
nuclear@0 | 18 |
nuclear@0 | 19 int init(void); |
nuclear@0 | 20 void cleanup(void); |
nuclear@0 | 21 void wait_vpos(int x); |
nuclear@0 | 22 void wait_vblank(void); |
nuclear@0 | 23 |
nuclear@0 | 24 int main(void) |
nuclear@0 | 25 { |
nuclear@0 | 26 int x, y; |
nuclear@0 | 27 |
nuclear@0 | 28 if(init() == -1) { |
nuclear@0 | 29 return 1; |
nuclear@0 | 30 } |
nuclear@0 | 31 |
nuclear@0 | 32 while(!mouse_state(&x, &y)) { |
nuclear@0 | 33 wait_vblank(); |
nuclear@0 | 34 REG32_BPL1PT = (uint32_t)&backdrop; |
nuclear@0 | 35 } |
nuclear@0 | 36 |
nuclear@0 | 37 cleanup(); |
nuclear@0 | 38 return 0; |
nuclear@0 | 39 } |
nuclear@0 | 40 |
nuclear@0 | 41 int init(void) |
nuclear@0 | 42 { |
nuclear@0 | 43 int i, x, y, bit; |
nuclear@0 | 44 unsigned char *fbptr; |
nuclear@0 | 45 unsigned char tmp; |
nuclear@0 | 46 |
nuclear@0 | 47 Forbid(); |
nuclear@0 | 48 |
nuclear@0 | 49 prev_dmacon = REG_DMACONR; |
nuclear@0 | 50 REG_DMACON = CLRBITS(DMA_ALL); |
nuclear@0 | 51 |
nuclear@0 | 52 prev_intena = REG_INTENAR; |
nuclear@0 | 53 REG_INTENA = SETBITS(INTEN_ALL); |
nuclear@0 | 54 |
nuclear@0 | 55 prev_intreq = REG_INTREQR; |
nuclear@0 | 56 prev_adkcon = REG_ADKCONR; |
nuclear@0 | 57 |
nuclear@0 | 58 REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR; |
nuclear@0 | 59 REG_BPLCON1 = 0; /* h-scroll */ |
nuclear@0 | 60 REG_BPL1MOD = HMOD; |
nuclear@0 | 61 REG_BPL2MOD = HMOD; |
nuclear@0 | 62 REG_DIWSTART = 0x2981; |
nuclear@0 | 63 REG_DIWSTOP = 0x29c1; |
nuclear@0 | 64 REG_DDFSTART = 0x38; |
nuclear@0 | 65 REG_DDFSTOP = 0xd0; |
nuclear@0 | 66 |
nuclear@0 | 67 /* populate palette */ |
nuclear@0 | 68 REG_COLOR0 = 0; |
nuclear@0 | 69 REG_COLOR1 = 0xfff; |
nuclear@0 | 70 |
nuclear@0 | 71 wait_vblank(); |
nuclear@0 | 72 REG32_BPL1PT = (uint32_t)&backdrop; |
nuclear@0 | 73 |
nuclear@0 | 74 REG_DMACON = SETBITS(DMA_BPL | DMA_MASTER); |
nuclear@0 | 75 |
nuclear@0 | 76 return 0; |
nuclear@0 | 77 } |
nuclear@0 | 78 |
nuclear@0 | 79 void cleanup(void) |
nuclear@0 | 80 { |
nuclear@0 | 81 REG_DMACON = CLRBITS(DMA_ALL); |
nuclear@0 | 82 REG_DMACON = SETBITS(prev_dmacon); |
nuclear@0 | 83 |
nuclear@0 | 84 REG_INTREQ = CLRBITS(0x7fff); |
nuclear@0 | 85 REG_INTREQ = SETBITS(prev_intreq); |
nuclear@0 | 86 |
nuclear@0 | 87 REG_ADKCON = CLRBITS(0x7fff); |
nuclear@0 | 88 REG_ADKCON = SETBITS(prev_adkcon); |
nuclear@0 | 89 |
nuclear@0 | 90 REG_INTENA = CLRBITS(INTEN_ALL); |
nuclear@0 | 91 REG_INTENA = SETBITS(prev_intena); |
nuclear@0 | 92 |
nuclear@0 | 93 Permit(); |
nuclear@0 | 94 } |
nuclear@0 | 95 |
nuclear@0 | 96 void wait_vpos(int x) |
nuclear@0 | 97 { |
nuclear@0 | 98 x <<= 8; |
nuclear@0 | 99 while((REG32_VPOSR & 0x1ff00) < x); |
nuclear@0 | 100 } |
nuclear@0 | 101 |
nuclear@0 | 102 void wait_vblank(void) |
nuclear@0 | 103 { |
nuclear@0 | 104 wait_vpos(300); |
nuclear@0 | 105 } |