gbasys
changeset 8:047c61960005
- added bg2 matrix support
- changed some stupid const pointers to register addresses to hardcoded compile-time defines
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Jun 2014 06:26:11 +0300 |
parents | f77381b12726 |
children | 85f219fcdc82 |
files | Makefile src/gfx.c src/gfx.h src/input.c src/intr.c src/intr.h |
diffstat | 6 files changed, 51 insertions(+), 24 deletions(-) [+] |
line diff
1.1 --- a/Makefile Tue Sep 04 05:05:50 2012 +0300 1.2 +++ b/Makefile Sun Jun 22 06:26:11 2014 +0300 1.3 @@ -4,7 +4,7 @@ 1.4 obj = $(src:.c=.o) 1.5 liba = libgbasys.a 1.6 1.7 -ARCH = arm-eabi 1.8 +ARCH = arm-none-eabi 1.9 1.10 CPP = $(ARCH)-cpp 1.11 CC = $(ARCH)-gcc
2.1 --- a/src/gfx.c Tue Sep 04 05:05:50 2012 +0300 2.2 +++ b/src/gfx.c Sun Jun 22 06:26:11 2014 +0300 2.3 @@ -35,8 +35,13 @@ 2.4 #define BG2_ENABLE 0x400 2.5 #define BG3_ENABLE 0x800 2.6 2.7 -static volatile unsigned short *reg_disp_ctl = (void*)0x4000000; 2.8 -static volatile unsigned short *reg_vcount = (void*)0x4000006; 2.9 +#define REG_DISPCTL (*(unsigned short*)0x4000000) 2.10 +#define REG_VCOUNT (*(unsigned short*)0x4000006) 2.11 + 2.12 +#define REG_BG2PA (*(short*)0x4000020) 2.13 +#define REG_BG2PB (*(short*)0x4000022) 2.14 +#define REG_BG2PC (*(short*)0x4000024) 2.15 +#define REG_BG2PD (*(short*)0x4000026) 2.16 2.17 static unsigned short *paladdr = (void*)0x5000000; 2.18 2.19 @@ -49,8 +54,8 @@ 2.20 struct pixel_buffer *front_buffer = &fbuf; 2.21 struct pixel_buffer *back_buffer = &bbuf; 2.22 2.23 -#define show_page(n) ((n) ? (*reg_disp_ctl |= FRAME_SEL_BIT) : (*reg_disp_ctl &= ~FRAME_SEL_BIT)) 2.24 -#define swap_page() (*reg_disp_ctl ^= FRAME_SEL_BIT) 2.25 +#define show_page(n) ((n) ? (REG_DISPCTL |= FRAME_SEL_BIT) : (REG_DISPCTL &= ~FRAME_SEL_BIT)) 2.26 +#define swap_page() (REG_DISPCTL ^= FRAME_SEL_BIT) 2.27 2.28 int set_video_mode(int mode, int double_buffering) { 2.29 if(mode < 3 || mode > 5) return -1; 2.30 @@ -61,7 +66,7 @@ 2.31 2.32 sizeof_pixel = (mode == 4) ? 1 : 2; 2.33 2.34 - *reg_disp_ctl = mode | BG2_ENABLE; 2.35 + REG_DISPCTL = mode | BG2_ENABLE; 2.36 2.37 show_page(0); 2.38 2.39 @@ -178,6 +183,19 @@ 2.40 paladdr[idx] = RGB(r, g, b); 2.41 } 2.42 2.43 +void set_bg_matrix(int a, int b, int c, int d) 2.44 +{ 2.45 + REG_BG2PA = a; 2.46 + REG_BG2PB = b; 2.47 + REG_BG2PC = c; 2.48 + REG_BG2PD = d; 2.49 +} 2.50 + 2.51 +void set_bg_scale(int x, int y) 2.52 +{ 2.53 + set_bg_matrix(x, 0, 0, y); 2.54 +} 2.55 + 2.56 void draw_line(int x1, int y1, int x2, int y2, unsigned short col, struct pixel_buffer *pbuf) { 2.57 int dx, dy, dx2, dy2; 2.58 int x_inc, y_inc;
3.1 --- a/src/gfx.h Tue Sep 04 05:05:50 2012 +0300 3.2 +++ b/src/gfx.h Sun Jun 22 06:26:11 2014 +0300 3.3 @@ -56,6 +56,10 @@ 3.4 3.5 void set_palette(int idx, int r, int g, int b); 3.6 3.7 +/* accepts 8.8 fixed point values */ 3.8 +void set_bg_matrix(int a, int b, int c, int d); 3.9 +void set_bg_scale(int x, int y); 3.10 + 3.11 #define wait_vsync() while(*((volatile unsigned short*)0x4000006) < front_buffer->y) 3.12 3.13 #define put_pixel(px, py, col, pbuf) ((unsigned short*)(pbuf)->pixels)[(py) * (pbuf)->x + (px)] = col
4.1 --- a/src/input.c Tue Sep 04 05:05:50 2012 +0300 4.2 +++ b/src/input.c Sun Jun 22 06:26:11 2014 +0300 4.3 @@ -20,18 +20,26 @@ 4.4 4.5 #include "input.h" 4.6 4.7 -volatile unsigned short *reg_key_state = (unsigned short*)0x4000130; 4.8 -volatile unsigned short *reg_key_cntl = (unsigned short*)0x4000132; 4.9 +#define REG_KEYSTATE (*(unsigned short*)0x4000130) 4.10 +#define REG_KEYCTL (*(unsigned short*)0x4000132) 4.11 4.12 int get_key_state(int key) { 4.13 - return ~(*reg_key_state) & key; 4.14 + int res; 4.15 + unsigned short prev_mask; 4.16 + 4.17 + prev_mask = REG_KEYCTL; 4.18 + disable_key_interrupts(key); 4.19 + 4.20 + res = ~REG_KEYSTATE & key; 4.21 + REG_KEYCTL = prev_mask; 4.22 + return res; 4.23 } 4.24 4.25 void enable_key_interrupts(int keys) { 4.26 - *reg_key_cntl |= (1 << 14) | keys; 4.27 + REG_KEYCTL |= (1 << 14) | keys; 4.28 } 4.29 4.30 void disable_key_interrupts(int keys) { 4.31 if(keys == KEY_ALL) keys |= (1 << 14); 4.32 - *reg_key_cntl ^= keys; 4.33 + REG_KEYCTL ^= keys; 4.34 }
5.1 --- a/src/intr.c Tue Sep 04 05:05:50 2012 +0300 5.2 +++ b/src/intr.c Sun Jun 22 06:26:11 2014 +0300 5.3 @@ -23,10 +23,6 @@ 5.4 5.5 #include "gfx.h" 5.6 5.7 -unsigned short *reg_int_master = (unsigned short*)0x04000208; 5.8 -unsigned short *reg_int_mask = (unsigned short*)0x04000200; 5.9 -static volatile unsigned short *reg_int = (unsigned short*)0x04000202; 5.10 - 5.11 #define MAX_INTR 14 5.12 static void (*intr_table[MAX_INTR])(void); 5.13 5.14 @@ -38,10 +34,10 @@ 5.15 int i; 5.16 unsigned short irq; 5.17 char buf[20]; 5.18 - 5.19 + 5.20 clr_int(); 5.21 5.22 - irq = *reg_int & 0x3fff; 5.23 + irq = REG_INTR & 0x3fff; 5.24 5.25 for(i=0; i<MAX_INTR; i++) { 5.26 unsigned short irq_bit = (1 << i); 5.27 @@ -50,7 +46,7 @@ 5.28 } 5.29 } 5.30 5.31 - *reg_int = irq; 5.32 + REG_INTR = irq; 5.33 5.34 set_int(); 5.35 }
6.1 --- a/src/intr.h Tue Sep 04 05:05:50 2012 +0300 6.2 +++ b/src/intr.h Sun Jun 22 06:26:11 2014 +0300 6.3 @@ -39,20 +39,21 @@ 6.4 INTR_GPAK 6.5 }; 6.6 6.7 -extern unsigned short *reg_int_master; 6.8 -extern unsigned short *reg_int_mask; 6.9 +#define REG_INTR_MASTER (*(unsigned short*)0x4000208) 6.10 +#define REG_INTR_MASK (*(unsigned short*)0x4000200) 6.11 +#define REG_INTR (*(unsigned short*)0x4000202) 6.12 6.13 void intr_init(void); 6.14 6.15 /* set/clear interrupts */ 6.16 -#define set_int() do {*reg_int_master = 1;} while(0) 6.17 -#define clr_int() do {*reg_int_master = 0;} while(0) 6.18 +#define set_int() do {REG_INTR_MASTER = 1;} while(0) 6.19 +#define clr_int() do {REG_INTR_MASTER = 0;} while(0) 6.20 6.21 /* set an interrupt handler */ 6.22 void interrupt(int intr, void (*handler)(void)); 6.23 6.24 /* mask/unmask an interrupt */ 6.25 -#define mask(intr) do {*reg_int_mask ^= 1 << (intr);} while(0) 6.26 -#define unmask(intr) do {*reg_int_mask |= 1 << (intr);} while(0) 6.27 +#define mask(intr) do {REG_INTR_MASK ^= 1 << (intr);} while(0) 6.28 +#define unmask(intr) do {REG_INTR_MASK |= 1 << (intr);} while(0) 6.29 6.30 #endif /* _INTR_H_ */