gbasys
changeset 1:c50064b181c2
stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 04 Mar 2012 07:06:41 +0200 |
parents | 875ef6085efc |
children | e3dc7705ad9c |
files | Makefile samples/fonts/fonts.c src/config.h src/dma.c src/font.c src/font.h src/font_8x16.c src/font_8x8.c src/gbasys.c src/gbasys.h src/gfx.c src/libgba.c src/libgba.h src/libgba_config.h src/syscall.c |
diffstat | 15 files changed, 147 insertions(+), 136 deletions(-) [+] |
line diff
1.1 --- a/Makefile Sun Mar 04 04:04:25 2012 +0200 1.2 +++ b/Makefile Sun Mar 04 07:06:41 2012 +0200 1.3 @@ -4,10 +4,10 @@ 1.4 obj = $(src:.c=.o) 1.5 liba = libgbasys.a 1.6 1.7 -CPP = arm-agb-elf-cpp 1.8 -CC = arm-agb-elf-gcc 1.9 -AS = arm-agb-elf-as 1.10 -AR = arm-agb-elf-ar 1.11 +CPP = arm-eabi-cpp 1.12 +CC = arm-eabi-gcc 1.13 +AS = arm-eabi-as 1.14 +AR = arm-eabi-ar 1.15 1.16 CFLAGS = -pedantic -marm -mcpu=arm7tdmi -Isrc 1.17
2.1 --- a/samples/fonts/fonts.c Sun Mar 04 04:04:25 2012 +0200 2.2 +++ b/samples/fonts/fonts.c Sun Mar 04 07:06:41 2012 +0200 2.3 @@ -1,9 +1,12 @@ 2.4 -#include "libgba.h" 2.5 +#include "gbasys.h" 2.6 2.7 -int main(void) { 2.8 +int main(void) 2.9 +{ 2.10 int i; 2.11 struct font *font; 2.12 2.13 + print_vba("foobar\n"); 2.14 + 2.15 set_video_mode(VMODE_LFB_240x160_16, 1); 2.16 2.17 font = get_font();
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/config.h Sun Mar 04 07:06:41 2012 +0200 3.3 @@ -0,0 +1,30 @@ 3.4 +/* 3.5 +Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 3.6 + 3.7 +This file is part of libgba, a library for GameBoy Advance development. 3.8 + 3.9 +This program is free software; you can redistribute it and/or modify 3.10 +it under the terms of the GNU General Public License as published by 3.11 +the Free Software Foundation; either version 2 of the License, or 3.12 +(at your option) any later version. 3.13 + 3.14 +This program is distributed in the hope that it will be useful, 3.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of 3.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.17 +GNU General Public License for more details. 3.18 + 3.19 +You should have received a copy of the GNU General Public License 3.20 +along with this program; if not, write to the Free Software 3.21 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 3.22 +*/ 3.23 + 3.24 +#ifndef _LIBGBA_CONFIG_H_ 3.25 +#define _LIBGBA_CONFIG_H_ 3.26 + 3.27 +/* compile 8x8 font */ 3.28 +#define CONFIG_FONT_8X8 3.29 + 3.30 +/* compile 8x16 font */ 3.31 +/*#define CONFIG_FONT_8X16*/ 3.32 + 3.33 +#endif /* _LIBGBA_CONFIG_H_ */
4.1 --- a/src/dma.c Sun Mar 04 04:04:25 2012 +0200 4.2 +++ b/src/dma.c Sun Mar 04 07:06:41 2012 +0200 4.3 @@ -1,7 +1,7 @@ 4.4 /* 4.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 4.6 4.7 -This file is part of libgba, a library for GameBoy Advance development. 4.8 +This file is part of gbasys, a library for GameBoy Advance development. 4.9 4.10 This program is free software; you can redistribute it and/or modify 4.11 it under the terms of the GNU General Public License as published by 4.12 @@ -18,11 +18,11 @@ 4.13 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 4.14 */ 4.15 4.16 -#include "libgba_config.h" 4.17 +#include "config.h" 4.18 #include "dma.h" 4.19 4.20 /* DMA Options */ 4.21 -#define DMA_ENABLE 0x80000000 4.22 +#define DMA_ENABLE 0x80000000 4.23 #define DMA_INT_ENABLE 0x40000000 4.24 #define DMA_TIMING_IMMED 0x00000000 4.25 #define DMA_TIMING_VBLANK 0x10000000 4.26 @@ -48,13 +48,15 @@ 4.27 4.28 /* --- perform a copy of words or halfwords using DMA --- */ 4.29 4.30 -void dma_copy32(int channel, void *dst, void *src, int words) { 4.31 +void dma_copy32(int channel, void *dst, void *src, int words) 4.32 +{ 4.33 reg_dma[channel][DMA_SRC] = (unsigned long)src; 4.34 reg_dma[channel][DMA_DST] = (unsigned long)dst; 4.35 reg_dma[channel][DMA_CTRL] = words | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE; 4.36 } 4.37 4.38 -void dma_copy16(int channel, void *dst, void *src, int halfwords) { 4.39 +void dma_copy16(int channel, void *dst, void *src, int halfwords) 4.40 +{ 4.41 reg_dma[channel][DMA_SRC] = (unsigned long)src; 4.42 reg_dma[channel][DMA_DST] = (unsigned long)dst; 4.43 reg_dma[channel][DMA_CTRL] = halfwords | DMA_TIMING_IMMED | DMA_16 | DMA_ENABLE; 4.44 @@ -62,14 +64,16 @@ 4.45 4.46 /* --- fill a buffer with an ammount of words and halfwords using DMA --- */ 4.47 4.48 -void dma_fill32(int channel, void *dst, unsigned long val, int words) { 4.49 +void dma_fill32(int channel, void *dst, unsigned long val, int words) 4.50 +{ 4.51 unsigned long valmem = val; 4.52 reg_dma[channel][DMA_SRC] = (unsigned long)&valmem; 4.53 reg_dma[channel][DMA_DST] = (unsigned long)dst; 4.54 reg_dma[channel][DMA_CTRL] = words | DMA_SRC_FIX | DMA_TIMING_IMMED | DMA_32 | DMA_ENABLE; 4.55 } 4.56 4.57 -void dma_fill16(int channel, void *dst, unsigned short val, int halfwords) { 4.58 +void dma_fill16(int channel, void *dst, unsigned short val, int halfwords) 4.59 +{ 4.60 unsigned short valmem = val; 4.61 reg_dma[channel][DMA_SRC] = (unsigned long)&valmem; 4.62 reg_dma[channel][DMA_DST] = (unsigned long)dst;
5.1 --- a/src/font.c Sun Mar 04 04:04:25 2012 +0200 5.2 +++ b/src/font.c Sun Mar 04 07:06:41 2012 +0200 5.3 @@ -1,7 +1,7 @@ 5.4 /* 5.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 5.6 5.7 -This file is part of libgba, a library for GameBoy Advance development. 5.8 +This file is part of gbasys, a library for GameBoy Advance development. 5.9 5.10 This program is free software; you can redistribute it and/or modify 5.11 it under the terms of the GNU General Public License as published by 5.12 @@ -18,7 +18,7 @@ 5.13 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 5.14 */ 5.15 5.16 -#include "libgba_config.h" 5.17 +#include "config.h" 5.18 #include <stdlib.h> 5.19 #include "font.h" 5.20 #include "gfx.h" 5.21 @@ -97,7 +97,7 @@ 5.22 struct pixel_buffer *glyph; 5.23 5.24 if(!(glyph = get_glyph(c, fg_color, bg_color, pbuf->bpp))) return -1; 5.25 - 5.26 + 5.27 if(pbuf->bpp == 16) { 5.28 int i, j; 5.29 unsigned short *dptr = (unsigned short*)pbuf->pixels + y * pbuf->x + x;
6.1 --- a/src/font.h Sun Mar 04 04:04:25 2012 +0200 6.2 +++ b/src/font.h Sun Mar 04 07:06:41 2012 +0200 6.3 @@ -1,7 +1,7 @@ 6.4 /* 6.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 6.6 6.7 -This file is part of libgba, a library for GameBoy Advance development. 6.8 +This file is part of gbasys, a library for GameBoy Advance development. 6.9 6.10 This program is free software; you can redistribute it and/or modify 6.11 it under the terms of the GNU General Public License as published by 6.12 @@ -20,7 +20,7 @@ 6.13 #ifndef _FONT_H_ 6.14 #define _FONT_H_ 6.15 6.16 -#include "libgba_config.h" 6.17 +#include "config.h" 6.18 6.19 struct pixel_buffer; 6.20
7.1 --- a/src/font_8x16.c Sun Mar 04 04:04:25 2012 +0200 7.2 +++ b/src/font_8x16.c Sun Mar 04 07:06:41 2012 +0200 7.3 @@ -1,7 +1,7 @@ 7.4 /* 7.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 7.6 7.7 -This file is part of libgba, a library for GameBoy Advance development. 7.8 +This file is part of gbasys, a library for GameBoy Advance development. 7.9 7.10 This program is free software; you can redistribute it and/or modify 7.11 it under the terms of the GNU General Public License as published by 7.12 @@ -22,7 +22,7 @@ 7.13 * the Linux 2.6.7 kernel (drivers/video/console/font_8x8.c) 7.14 */ 7.15 7.16 -#include "libgba_config.h" 7.17 +#include "config.h" 7.18 7.19 #ifdef CONFIG_FONT_8X16 7.20
8.1 --- a/src/font_8x8.c Sun Mar 04 04:04:25 2012 +0200 8.2 +++ b/src/font_8x8.c Sun Mar 04 07:06:41 2012 +0200 8.3 @@ -1,7 +1,7 @@ 8.4 /* 8.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 8.6 8.7 -This file is part of libgba, a library for GameBoy Advance development. 8.8 +This file is part of gbasys, a library for GameBoy Advance development. 8.9 8.10 This program is free software; you can redistribute it and/or modify 8.11 it under the terms of the GNU General Public License as published by 8.12 @@ -22,7 +22,7 @@ 8.13 * the Linux 2.6.7 kernel (drivers/video/console/font_8x8.c) 8.14 */ 8.15 8.16 -#include "libgba_config.h" 8.17 +#include "config.h" 8.18 8.19 #ifdef CONFIG_FONT_8X8 8.20
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/src/gbasys.c Sun Mar 04 07:06:41 2012 +0200 9.3 @@ -0,0 +1,34 @@ 9.4 +/* 9.5 +Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 9.6 + 9.7 +This file is part of gbasys, a library for GameBoy Advance development. 9.8 + 9.9 +This program is free software; you can redistribute it and/or modify 9.10 +it under the terms of the GNU General Public License as published by 9.11 +the Free Software Foundation; either version 2 of the License, or 9.12 +(at your option) any later version. 9.13 + 9.14 +This program is distributed in the hope that it will be useful, 9.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of 9.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9.17 +GNU General Public License for more details. 9.18 + 9.19 +You should have received a copy of the GNU General Public License 9.20 +along with this program; if not, write to the Free Software 9.21 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 9.22 +*/ 9.23 + 9.24 +#include "config.h" 9.25 +#include "gbasys.h" 9.26 + 9.27 +void gba_init(void) 9.28 +{ 9.29 + intr_init(); 9.30 + sig_init(); 9.31 + term_init(); 9.32 + 9.33 + enable_key_interrupts(KEY_ALL); 9.34 + set_int(); 9.35 + 9.36 + reset_msec_timer(); 9.37 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/src/gbasys.h Sun Mar 04 07:06:41 2012 +0200 10.3 @@ -0,0 +1,37 @@ 10.4 +/* 10.5 +Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 10.6 + 10.7 +This file is part of libgba, a library for GameBoy Advance development. 10.8 + 10.9 +This program is free software; you can redistribute it and/or modify 10.10 +it under the terms of the GNU General Public License as published by 10.11 +the Free Software Foundation; either version 2 of the License, or 10.12 +(at your option) any later version. 10.13 + 10.14 +This program is distributed in the hope that it will be useful, 10.15 +but WITHOUT ANY WARRANTY; without even the implied warranty of 10.16 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10.17 +GNU General Public License for more details. 10.18 + 10.19 +You should have received a copy of the GNU General Public License 10.20 +along with this program; if not, write to the Free Software 10.21 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 10.22 +*/ 10.23 + 10.24 +#ifndef _LIBGBA_H_ 10.25 +#define _LIBGBA_H_ 10.26 + 10.27 +#include "gfx.h" 10.28 +#include "dma.h" 10.29 +#include "syscall.h" 10.30 +#include "font.h" 10.31 +#include "input.h" 10.32 +#include "intr.h" 10.33 +#include "error.h" 10.34 +#include "signal.h" 10.35 +#include "timer.h" 10.36 +#include "term.h" 10.37 + 10.38 +void gba_init(void); 10.39 + 10.40 +#endif /* _LIBGBA_H_ */
11.1 --- a/src/gfx.c Sun Mar 04 04:04:25 2012 +0200 11.2 +++ b/src/gfx.c Sun Mar 04 07:06:41 2012 +0200 11.3 @@ -1,7 +1,7 @@ 11.4 /* 11.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 11.6 11.7 -This file is part of libgba, a library for GameBoy Advance development. 11.8 +This file is part of gbasys, a library for GameBoy Advance development. 11.9 11.10 This program is free software; you can redistribute it and/or modify 11.11 it under the terms of the GNU General Public License as published by 11.12 @@ -18,7 +18,7 @@ 11.13 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 11.14 */ 11.15 11.16 -#include "libgba_config.h" 11.17 +#include "config.h" 11.18 11.19 #include <stdlib.h> 11.20 #include "gfx.h" 11.21 @@ -70,7 +70,7 @@ 11.22 front_buffer->x = back_buffer->x = xres; 11.23 front_buffer->y = back_buffer->y = yres; 11.24 front_buffer->bpp = back_buffer->bpp = sizeof_pixel * 8; 11.25 - 11.26 + 11.27 if(mode > 3) { 11.28 page_flipping = 1; 11.29 back_buffer->pixels = (void*)0x600a000; 11.30 @@ -84,7 +84,7 @@ 11.31 11.32 void flip(void) { 11.33 static void *tmp; 11.34 - 11.35 + 11.36 if(page_flipping) { 11.37 swap_page(); 11.38 tmp = front_buffer->pixels; 11.39 @@ -121,13 +121,13 @@ 11.40 color |= color << 8; 11.41 sz >>= 1; 11.42 } 11.43 - 11.44 + 11.45 dma_fill16(3, pbuf->pixels, color, sz); 11.46 } 11.47 11.48 void copy_buffer(const struct pixel_buffer *src, struct pixel_buffer *dst) { 11.49 int words; 11.50 - 11.51 + 11.52 if(src->x != dst->x || src->y != dst->y || src->bpp != dst->bpp) return; 11.53 11.54 words = (src->x * src->y) >> (src->bpp == 16 ? 1 : 2); 11.55 @@ -145,21 +145,21 @@ 11.56 ptr += y1 * pbuf->x + x1; 11.57 dx = x2 - x1; 11.58 dy = y2 - y1; 11.59 - 11.60 + 11.61 if(dx >= 0) { 11.62 x_inc = 1; 11.63 } else { 11.64 x_inc = -1; 11.65 dx = -dx; 11.66 } 11.67 - 11.68 + 11.69 if(dy >= 0) { 11.70 y_inc = pbuf->x; 11.71 } else { 11.72 y_inc = -pbuf->x; 11.73 dy = -dy; 11.74 } 11.75 - 11.76 + 11.77 dx2 = dx << 1; 11.78 dy2 = dy << 1; 11.79
12.1 --- a/src/libgba.c Sun Mar 04 04:04:25 2012 +0200 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,33 +0,0 @@ 12.4 -/* 12.5 -Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 12.6 - 12.7 -This file is part of libgba, a library for GameBoy Advance development. 12.8 - 12.9 -This program is free software; you can redistribute it and/or modify 12.10 -it under the terms of the GNU General Public License as published by 12.11 -the Free Software Foundation; either version 2 of the License, or 12.12 -(at your option) any later version. 12.13 - 12.14 -This program is distributed in the hope that it will be useful, 12.15 -but WITHOUT ANY WARRANTY; without even the implied warranty of 12.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12.17 -GNU General Public License for more details. 12.18 - 12.19 -You should have received a copy of the GNU General Public License 12.20 -along with this program; if not, write to the Free Software 12.21 -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 12.22 -*/ 12.23 - 12.24 -#include "libgba_config.h" 12.25 -#include "libgba.h" 12.26 - 12.27 -void gba_init(void) { 12.28 - intr_init(); 12.29 - sig_init(); 12.30 - term_init(); 12.31 - 12.32 - enable_key_interrupts(KEY_ALL); 12.33 - set_int(); 12.34 - 12.35 - reset_msec_timer(); 12.36 -}
13.1 --- a/src/libgba.h Sun Mar 04 04:04:25 2012 +0200 13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 13.3 @@ -1,37 +0,0 @@ 13.4 -/* 13.5 -Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 13.6 - 13.7 -This file is part of libgba, a library for GameBoy Advance development. 13.8 - 13.9 -This program is free software; you can redistribute it and/or modify 13.10 -it under the terms of the GNU General Public License as published by 13.11 -the Free Software Foundation; either version 2 of the License, or 13.12 -(at your option) any later version. 13.13 - 13.14 -This program is distributed in the hope that it will be useful, 13.15 -but WITHOUT ANY WARRANTY; without even the implied warranty of 13.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13.17 -GNU General Public License for more details. 13.18 - 13.19 -You should have received a copy of the GNU General Public License 13.20 -along with this program; if not, write to the Free Software 13.21 -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 13.22 -*/ 13.23 - 13.24 -#ifndef _LIBGBA_H_ 13.25 -#define _LIBGBA_H_ 13.26 - 13.27 -#include "gfx.h" 13.28 -#include "dma.h" 13.29 -#include "syscall.h" 13.30 -#include "font.h" 13.31 -#include "input.h" 13.32 -#include "intr.h" 13.33 -#include "error.h" 13.34 -#include "signal.h" 13.35 -#include "timer.h" 13.36 -#include "term.h" 13.37 - 13.38 -void gba_init(void); 13.39 - 13.40 -#endif /* _LIBGBA_H_ */
14.1 --- a/src/libgba_config.h Sun Mar 04 04:04:25 2012 +0200 14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 14.3 @@ -1,30 +0,0 @@ 14.4 -/* 14.5 -Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 14.6 - 14.7 -This file is part of libgba, a library for GameBoy Advance development. 14.8 - 14.9 -This program is free software; you can redistribute it and/or modify 14.10 -it under the terms of the GNU General Public License as published by 14.11 -the Free Software Foundation; either version 2 of the License, or 14.12 -(at your option) any later version. 14.13 - 14.14 -This program is distributed in the hope that it will be useful, 14.15 -but WITHOUT ANY WARRANTY; without even the implied warranty of 14.16 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14.17 -GNU General Public License for more details. 14.18 - 14.19 -You should have received a copy of the GNU General Public License 14.20 -along with this program; if not, write to the Free Software 14.21 -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14.22 -*/ 14.23 - 14.24 -#ifndef _LIBGBA_CONFIG_H_ 14.25 -#define _LIBGBA_CONFIG_H_ 14.26 - 14.27 -/* compile 8x8 font */ 14.28 -#define CONFIG_FONT_8X8 14.29 - 14.30 -/* compile 8x16 font */ 14.31 -/*#define CONFIG_FONT_8X16*/ 14.32 - 14.33 -#endif /* _LIBGBA_CONFIG_H_ */
15.1 --- a/src/syscall.c Sun Mar 04 04:04:25 2012 +0200 15.2 +++ b/src/syscall.c Sun Mar 04 07:06:41 2012 +0200 15.3 @@ -1,7 +1,7 @@ 15.4 /* 15.5 Copyright 2004 John Tsiombikas <nuclear@siggraph.org> 15.6 15.7 -This file is part of libgba, a library for GameBoy Advance development. 15.8 +This file is part of gbasys, a library for GameBoy Advance development. 15.9 15.10 This program is free software; you can redistribute it and/or modify 15.11 it under the terms of the GNU General Public License as published by 15.12 @@ -18,21 +18,24 @@ 15.13 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15.14 */ 15.15 15.16 -#include "libgba_config.h" 15.17 +#include "config.h" 15.18 15.19 #include <stdio.h> 15.20 #include <stdarg.h> 15.21 #include "syscall.h" 15.22 15.23 -void halt(void) { 15.24 +void halt(void) 15.25 +{ 15.26 __syscall(2); 15.27 } 15.28 15.29 -void stop(void) { 15.30 +void stop(void) 15.31 +{ 15.32 __syscall(3); 15.33 } 15.34 15.35 -void print_vba(const char *str, ...) { 15.36 +void print_vba(const char *str, ...) 15.37 +{ 15.38 char buf[128]; 15.39 va_list arg_list; 15.40