# HG changeset patch # User John Tsiombikas # Date 1403407571 -10800 # Node ID 047c61960005f956203b40c7bd3edb1dd9bcf6ab # Parent f77381b127266d4137a20af69f0a42ed7bc5f119 - added bg2 matrix support - changed some stupid const pointers to register addresses to hardcoded compile-time defines diff -r f77381b12726 -r 047c61960005 Makefile --- a/Makefile Tue Sep 04 05:05:50 2012 +0300 +++ b/Makefile Sun Jun 22 06:26:11 2014 +0300 @@ -4,7 +4,7 @@ obj = $(src:.c=.o) liba = libgbasys.a -ARCH = arm-eabi +ARCH = arm-none-eabi CPP = $(ARCH)-cpp CC = $(ARCH)-gcc diff -r f77381b12726 -r 047c61960005 src/gfx.c --- a/src/gfx.c Tue Sep 04 05:05:50 2012 +0300 +++ b/src/gfx.c Sun Jun 22 06:26:11 2014 +0300 @@ -35,8 +35,13 @@ #define BG2_ENABLE 0x400 #define BG3_ENABLE 0x800 -static volatile unsigned short *reg_disp_ctl = (void*)0x4000000; -static volatile unsigned short *reg_vcount = (void*)0x4000006; +#define REG_DISPCTL (*(unsigned short*)0x4000000) +#define REG_VCOUNT (*(unsigned short*)0x4000006) + +#define REG_BG2PA (*(short*)0x4000020) +#define REG_BG2PB (*(short*)0x4000022) +#define REG_BG2PC (*(short*)0x4000024) +#define REG_BG2PD (*(short*)0x4000026) static unsigned short *paladdr = (void*)0x5000000; @@ -49,8 +54,8 @@ struct pixel_buffer *front_buffer = &fbuf; struct pixel_buffer *back_buffer = &bbuf; -#define show_page(n) ((n) ? (*reg_disp_ctl |= FRAME_SEL_BIT) : (*reg_disp_ctl &= ~FRAME_SEL_BIT)) -#define swap_page() (*reg_disp_ctl ^= FRAME_SEL_BIT) +#define show_page(n) ((n) ? (REG_DISPCTL |= FRAME_SEL_BIT) : (REG_DISPCTL &= ~FRAME_SEL_BIT)) +#define swap_page() (REG_DISPCTL ^= FRAME_SEL_BIT) int set_video_mode(int mode, int double_buffering) { if(mode < 3 || mode > 5) return -1; @@ -61,7 +66,7 @@ sizeof_pixel = (mode == 4) ? 1 : 2; - *reg_disp_ctl = mode | BG2_ENABLE; + REG_DISPCTL = mode | BG2_ENABLE; show_page(0); @@ -178,6 +183,19 @@ paladdr[idx] = RGB(r, g, b); } +void set_bg_matrix(int a, int b, int c, int d) +{ + REG_BG2PA = a; + REG_BG2PB = b; + REG_BG2PC = c; + REG_BG2PD = d; +} + +void set_bg_scale(int x, int y) +{ + set_bg_matrix(x, 0, 0, y); +} + void draw_line(int x1, int y1, int x2, int y2, unsigned short col, struct pixel_buffer *pbuf) { int dx, dy, dx2, dy2; int x_inc, y_inc; diff -r f77381b12726 -r 047c61960005 src/gfx.h --- a/src/gfx.h Tue Sep 04 05:05:50 2012 +0300 +++ b/src/gfx.h Sun Jun 22 06:26:11 2014 +0300 @@ -56,6 +56,10 @@ void set_palette(int idx, int r, int g, int b); +/* accepts 8.8 fixed point values */ +void set_bg_matrix(int a, int b, int c, int d); +void set_bg_scale(int x, int y); + #define wait_vsync() while(*((volatile unsigned short*)0x4000006) < front_buffer->y) #define put_pixel(px, py, col, pbuf) ((unsigned short*)(pbuf)->pixels)[(py) * (pbuf)->x + (px)] = col diff -r f77381b12726 -r 047c61960005 src/input.c --- a/src/input.c Tue Sep 04 05:05:50 2012 +0300 +++ b/src/input.c Sun Jun 22 06:26:11 2014 +0300 @@ -20,18 +20,26 @@ #include "input.h" -volatile unsigned short *reg_key_state = (unsigned short*)0x4000130; -volatile unsigned short *reg_key_cntl = (unsigned short*)0x4000132; +#define REG_KEYSTATE (*(unsigned short*)0x4000130) +#define REG_KEYCTL (*(unsigned short*)0x4000132) int get_key_state(int key) { - return ~(*reg_key_state) & key; + int res; + unsigned short prev_mask; + + prev_mask = REG_KEYCTL; + disable_key_interrupts(key); + + res = ~REG_KEYSTATE & key; + REG_KEYCTL = prev_mask; + return res; } void enable_key_interrupts(int keys) { - *reg_key_cntl |= (1 << 14) | keys; + REG_KEYCTL |= (1 << 14) | keys; } void disable_key_interrupts(int keys) { if(keys == KEY_ALL) keys |= (1 << 14); - *reg_key_cntl ^= keys; + REG_KEYCTL ^= keys; } diff -r f77381b12726 -r 047c61960005 src/intr.c --- a/src/intr.c Tue Sep 04 05:05:50 2012 +0300 +++ b/src/intr.c Sun Jun 22 06:26:11 2014 +0300 @@ -23,10 +23,6 @@ #include "gfx.h" -unsigned short *reg_int_master = (unsigned short*)0x04000208; -unsigned short *reg_int_mask = (unsigned short*)0x04000200; -static volatile unsigned short *reg_int = (unsigned short*)0x04000202; - #define MAX_INTR 14 static void (*intr_table[MAX_INTR])(void); @@ -38,10 +34,10 @@ int i; unsigned short irq; char buf[20]; - + clr_int(); - irq = *reg_int & 0x3fff; + irq = REG_INTR & 0x3fff; for(i=0; i