Angband
Data Structures | Macros | Typedefs | Functions | Variables
main-nds.c File Reference

Main file for playing on the Nintendo DS. More...

#include <nds.h>
#include <fat.h>
#include "angband.h"
#include "buildid.h"
#include "main.h"
#include "init.h"
#include "ui-prefs.h"
#include "savefile.h"
#include "nds/ds_errfont.h"
#include "nds/ds_main.h"

Data Structures

struct  term_data
 

Macros

#define NDS_BUTTON_FILE   "buttons.dat"
 
#define NDS_MAPPABLE_MASK   (KEY_A | KEY_B | KEY_X | KEY_Y | KEY_START | KEY_SELECT)
 
#define NDS_MODIFIER_MASK   (KEY_L | KEY_R)
 
#define NDS_BUTTON_MASK   (NDS_MAPPABLE_MASK | NDS_MODIFIER_MASK)
 
#define NDS_NUM_MAPPABLE   6 /* A, B, X, Y, Select, Start */
 
#define NDS_NUM_MODIFIER   2 /* R, L */
 
#define NDS_CMD_LENGTH   16 /* max. 15 keys/button + null terminator */
 
#define total_tiles_used   512 /*hack, guess */
 
#define DEF_TILE_WIDTH   8
 
#define DEF_TILE_HEIGHT   8
 
#define DEF_TILE_FILE   "/angband/lib/xtra/graf/8x8.bmp"
 
#define DEF_TILES_PER_ROW   32
 
#define c1(a, i)   (RGB15((a[i]>>3),(a[i+1]>>3),(a[i+2]>>3)))
 
#define c2(a, i)   (RGB15((a[i+2]>>3),(a[i+1]>>3),(a[i]>>3)))
 
#define TILE_BUFFER_SIZE   (TILE_WIDTH*TILE_HEIGHT*(total_tiles_used+1)*2)
 
#define MAX_TERM_DATA   1
 
#define NUM_FILES   3
 
#define h   TILE_HEIGHT
 
#define w   TILE_WIDTH
 
#define bmpxy2off(x, y)   (((y-(y%h))*iw+(y%h))*w + x*h)
 

Typedefs

typedef struct term_data term_data
 

Functions

s16 nds_buttons_to_btnid (u16 kd, u16 kh)
 
static void Term_init_nds (term *t)
 
static void Term_nuke_nds (term *t)
 
static void pixel_to_square (int *const x, int *const y, const int ox, const int oy)
 
static void handle_touch (int x, int y, int button, bool press)
 
u16b kbd_mod_code (u16 ret)
 
void kbd_set_color_from_pos (u16b r, u16b k, byte color)
 
void kbd_set_color_from_code (u16b code, byte color)
 
void kbd_set_map ()
 
u16b kbd_xy2key (byte x, byte y)
 
void kbd_dotoggle (bool *flag, int how)
 
void kbd_togglemod (int which, int how)
 
byte kbd_vblank ()
 
void nds_check_buttons (u16b kd, u16b kh)
 
bool has_event ()
 
u16b get_event ()
 
void put_key_event (byte c)
 
void put_mouse_event (byte x, byte y)
 
void do_vblank ()
 
static errr CheckEvents (bool wait)
 
static errr Term_xtra_nds (int n, int v)
 
static errr Term_curs_nds (int x, int y)
 
void draw_char (byte x, byte y, char c)
 
void draw_color_char (byte x, byte y, char c, byte clr)
 
static errr Term_wipe_nds (int x, int y, int n)
 
static errr Term_text_nds (int x, int y, int n, byte a, const char *cp)
 
void draw_tile (byte x, byte y, u16b tile)
 
static errr Term_pict_nds (int x, int y, int n, const byte *ap, const char *cp)
 
static void term_data_link (int i)
 
errr init_nds (void)
 
static void init_stuff (void)
 
void nds_init_fonts ()
 
void nds_fatal_err (const char *msg)
 
bool nds_load_file (const char *name, u16b *dest, u32b len)
 
bool nds_load_kbd ()
 
void kbd_init ()
 
void nds_init_buttons ()
 
void swap_font (bool bottom)
 
void on_irq ()
 
void nds_raw_print (const char *str)
 
bool nds_load_tile_bmp (const char *name, u16b *dest, u32b len)
 
bool nds_load_tile_file (char *name, u16b *dest, u32b len)
 
bool nds_load_tiles ()
 
static void hook_plog (const char *str)
 
static void hook_quit (const char *str)
 
void nds_exit (int code)
 
int main (int argc, char *argv[])
 

Variables

u16 * subfont_rgb_bin = (u16*)(0x06018400)
 
u16 * subfont_bgr_bin = (u16*)(0x0601C400)
 
u16 * top_font_bin
 
u16 * btm_font_bin
 
u16 * tiles_bin
 
byte nds_btn_cmds [NDS_NUM_MAPPABLE<< NDS_NUM_MODIFIER][NDS_CMD_LENGTH]
 
byte btn_defaults []
 
const s16 mappables [] = { KEY_A, KEY_B, KEY_X, KEY_Y, KEY_SELECT, KEY_START }
 
const s16 modifiers [] = { KEY_L, KEY_R }
 
u16b TILE_WIDTH
 
u16b TILE_HEIGHT
 
char * TILE_FILE
 
u16b NDS_SCREEN_COLS
 
u16b NDS_SCREEN_ROWS
 
const nds_kbd_key row0 []
 
const nds_kbd_key row1 []
 
const nds_kbd_key row2 []
 
const nds_kbd_key row3 []
 
const nds_kbd_key row4 []
 
char shifts [] = "`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}\\|;:\'\",<.>/?"
 
const nds_kbd_keykbdrows [] = {row0, row1, row2, row3, row4}
 
static term_data data [MAX_TERM_DATA]
 
u16b color_data []
 
static bool shift = false
 
static bool ctrl = false
 
static bool alt = false
 
static bool caps = false
 
byte process_special_keystrokes = 1
 
u16bebuf = (u16b*)(&BG_GFX[256*192])
 
u16b ebuf_read = 0
 
u16b ebuf_write = 0
 
byte nds_updated = 0
 

Detailed Description

Main file for playing on the Nintendo DS.

Copyright (c) 2010 Nick McConnell

Many of the routines are based on (or lifted directly from) brettk's excellent NethackDS: http://frodo.dyn.gno.org/~brettk/NetHackDS

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation

#define bmpxy2off (   x,
 
)    (((y-(y%h))*iw+(y%h))*w + x*h)

Referenced by nds_load_tile_bmp().

#define c1 (   a,
  i 
)    (RGB15((a[i]>>3),(a[i+1]>>3),(a[i+2]>>3)))
#define c2 (   a,
  i 
)    (RGB15((a[i+2]>>3),(a[i+1]>>3),(a[i]>>3)))

Referenced by nds_load_tile_bmp(), and roman_to_int().

#define DEF_TILE_FILE   "/angband/lib/xtra/graf/8x8.bmp"

Referenced by nds_load_tiles().

#define DEF_TILE_HEIGHT   8

Referenced by nds_load_tiles().

#define DEF_TILE_WIDTH   8

Referenced by nds_load_tiles().

#define DEF_TILES_PER_ROW   32

Referenced by Term_pict_nds().

#define h   TILE_HEIGHT
#define MAX_TERM_DATA   1

Referenced by init_nds().

#define NDS_BUTTON_FILE   "buttons.dat"

Referenced by nds_init_buttons().

#define NDS_BUTTON_MASK   (NDS_MAPPABLE_MASK | NDS_MODIFIER_MASK)
#define NDS_CMD_LENGTH   16 /* max. 15 keys/button + null terminator */

Referenced by nds_init_buttons().

#define NDS_MAPPABLE_MASK   (KEY_A | KEY_B | KEY_X | KEY_Y | KEY_START | KEY_SELECT)

Referenced by nds_buttons_to_btnid().

#define NDS_MODIFIER_MASK   (KEY_L | KEY_R)
#define NDS_NUM_MAPPABLE   6 /* A, B, X, Y, Select, Start */
#define NDS_NUM_MODIFIER   2 /* R, L */
#define NUM_FILES   3

Referenced by nds_load_kbd().

#define TILE_BUFFER_SIZE   (TILE_WIDTH*TILE_HEIGHT*(total_tiles_used+1)*2)

Referenced by nds_load_tiles().

#define total_tiles_used   512 /*hack, guess */
#define w   TILE_WIDTH

Typedef Documentation

typedef struct term_data term_data

Function Documentation

static errr CheckEvents ( bool  wait)
static
void do_vblank ( )
void draw_char ( byte  x,
byte  y,
char  c 
)

References btm_font_bin, and top_font_bin.

Referenced by nds_fatal_err(), and nds_raw_print().

void draw_color_char ( byte  x,
byte  y,
char  c,
byte  clr 
)

References btm_font_bin, and top_font_bin.

Referenced by Term_text_nds(), and Term_wipe_nds().

void draw_tile ( byte  x,
byte  y,
u16b  tile 
)

References TILE_HEIGHT, and TILE_WIDTH.

Referenced by main(), and Term_pict_nds().

u16b get_event ( )

References ebuf_read, ebuf_write, has_event(), and MAX_EBUF.

Referenced by CheckEvents().

static void handle_touch ( int  x,
int  y,
int  button,
bool  press 
)
static

References pixel_to_square(), and Term_mousepress().

Referenced by CheckEvents().

bool has_event ( )

References ebuf_write, and EVENT_SET.

Referenced by CheckEvents(), and get_event().

static void hook_plog ( const char *  str)
static

References nds_raw_print().

Referenced by main().

static void hook_quit ( const char *  str)
static

References i, nds_exit(), and nds_fatal_err().

Referenced by main().

errr init_nds ( void  )
static void init_stuff ( void  )
static

References init_file_paths(), path, and savefile.

Referenced by main().

void kbd_dotoggle ( bool *  flag,
int  how 
)

References flag.

Referenced by kbd_togglemod().

void kbd_init ( )

References i.

Referenced by main().

u16b kbd_mod_code ( u16  ret)

References alt, caps, ctrl, K_MODIFIER, and NULL.

Referenced by kbd_set_color_from_code(), and kbd_xy2key().

void kbd_set_color_from_code ( u16b  code,
byte  color 
)
void kbd_set_color_from_pos ( u16b  r,
u16b  k,
byte  color 
)

References nds_kbd_key::width.

Referenced by kbd_set_color_from_code().

void kbd_set_map ( )

References caps.

Referenced by kbd_togglemod().

void kbd_togglemod ( int  which,
int  how 
)
byte kbd_vblank ( )
u16b kbd_xy2key ( byte  x,
byte  y 
)

References nds_kbd_key::code, i, K_F, kbd_mod_code(), ox, oy, row, and nds_kbd_key::width.

Referenced by kbd_vblank().

int main ( int  argc,
char *  argv[] 
)
s16 nds_buttons_to_btnid ( u16  kd,
u16  kh 
)
void nds_check_buttons ( u16b  kd,
u16b  kh 
)

References nds_buttons_to_btnid(), and put_key_event().

Referenced by do_vblank().

void nds_exit ( int  code)

References do_vblank(), and i.

Referenced by hook_quit().

void nds_fatal_err ( const char *  msg)

References draw_char(), and i.

Referenced by hook_quit(), main(), nds_load_kbd(), and nds_load_tiles().

void nds_init_buttons ( )
void nds_init_fonts ( )

References ds_subfont, i, subfont_bgr_bin, and subfont_rgb_bin.

Referenced by main().

bool nds_load_file ( const char *  name,
u16b dest,
u32b  len 
)

References i, and NULL.

Referenced by nds_load_kbd(), and nds_load_tile_file().

bool nds_load_kbd ( )

References buf, i, nds_fatal_err(), nds_load_file(), and NUM_FILES.

Referenced by main().

bool nds_load_tile_bmp ( const char *  name,
u16b dest,
u32b  len 
)

References bmpxy2off, buf, c2, h, i, nds_raw_print(), SEEK_CUR, SEEK_SET, strnfmt(), and w.

Referenced by nds_load_tile_file().

bool nds_load_tile_file ( char *  name,
u16b dest,
u32b  len 
)
bool nds_load_tiles ( )
void nds_raw_print ( const char *  str)
void on_irq ( )

Referenced by main().

static void pixel_to_square ( int *const  x,
int *const  y,
const int  ox,
const int  oy 
)
static

References TILE_HEIGHT, and TILE_WIDTH.

Referenced by handle_touch().

void put_key_event ( byte  c)

References ebuf_write, EVENT_SET, and MAX_EBUF.

Referenced by do_vblank(), and nds_check_buttons().

void put_mouse_event ( byte  x,
byte  y 
)
void swap_font ( bool  bottom)

References subfont_bgr_bin, and subfont_rgb_bin.

Referenced by kbd_vblank(), and main().

static errr Term_curs_nds ( int  x,
int  y 
)
static

References TILE_HEIGHT, and TILE_WIDTH.

Referenced by term_data_link().

static void term_data_link ( int  i)
static
static void Term_init_nds ( term t)
static

References term::data.

Referenced by term_data_link().

static void Term_nuke_nds ( term t)
static

References term::data.

Referenced by term_data_link().

static errr Term_pict_nds ( int  x,
int  y,
int  n,
const byte ap,
const char *  cp 
)
static

References term::data, DEF_TILES_PER_ROW, draw_tile(), i, and Term.

Referenced by term_data_link().

static errr Term_text_nds ( int  x,
int  y,
int  n,
byte  a,
const char *  cp 
)
static

References term_win::a, draw_color_char(), i, term::scr, and Term.

Referenced by term_data_link().

static errr Term_wipe_nds ( int  x,
int  y,
int  n 
)
static

References term::data, draw_color_char(), i, and Term.

Referenced by term_data_link().

static errr Term_xtra_nds ( int  n,
int  v 
)
static

Variable Documentation

bool alt = false
static

Referenced by kbd_mod_code(), and kbd_togglemod().

u16* btm_font_bin

Referenced by draw_char(), and draw_color_char().

byte btn_defaults[]
Initial value:
=
{
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'z'}
bool caps = false
static
u16b color_data[]
Initial value:
= {
RGB15( 0, 0, 0),
RGB15( 31, 31, 31),
RGB15( 15, 15, 15),
RGB15( 31, 15, 0),
RGB15( 23, 0, 0),
RGB15( 0, 15, 9),
RGB15( 0, 0, 31),
RGB15( 15, 9, 0),
RGB15( 9, 9, 9),
RGB15( 23, 23, 23),
RGB15( 31, 0, 31),
RGB15( 31, 31, 0),
RGB15( 31, 0, 0),
RGB15( 0, 31, 0),
RGB15( 0, 31, 31),
RGB15( 23, 15, 9)
}
bool ctrl = false
static

Referenced by kbd_mod_code(), and kbd_togglemod().

term_data data[MAX_TERM_DATA]
static
u16b* ebuf = (u16b*)(&BG_GFX[256*192])
u16b ebuf_read = 0

Referenced by get_event().

u16b ebuf_write = 0
const nds_kbd_key* kbdrows[] = {row0, row1, row2, row3, row4}
const s16 mappables[] = { KEY_A, KEY_B, KEY_X, KEY_Y, KEY_SELECT, KEY_START }
const s16 modifiers[] = { KEY_L, KEY_R }

Referenced by wiz_tweak_item().

u16b NDS_SCREEN_COLS
u16b NDS_SCREEN_ROWS
byte nds_updated = 0

Referenced by kbd_vblank().

byte process_special_keystrokes = 1
Initial value:
= {
{16,(u16)'`'}, {16,(u16)'1'}, {16,(u16)'2'}, {16,(u16)'3'}, {16,(u16)'4'},
{16,(u16)'5'}, {16,(u16)'6'}, {16,(u16)'7'}, {16,(u16)'8'}, {16,(u16)'9'},
{16,(u16)'0'}, {16,(u16)'-'}, {16,(u16)'='}, {32,(u16)'\b'}, {0,0}}
Initial value:
= {
{24,(u16)'\t'}, {16,(u16)'q'}, {16,(u16)'w'}, {16,(u16)'e'}, {16,(u16)'r'},
{16,(u16)'t'}, {16,(u16)'y'}, {16,(u16)'u'}, {16,(u16)'i'}, {16,(u16)'o'},
{16,(u16)'p'}, {16,(u16)'['}, {16,(u16)']'}, {24,(u16)'\\'}, {0,0}}

Referenced by build_tunnel().

Initial value:
= {
{32,K_CAPS}, {16,(u16)'a'}, {16,(u16)'s'}, {16,(u16)'d'}, {16,(u16)'f'},
{16,(u16)'g'}, {16,(u16)'h'}, {16,(u16)'j'}, {16,(u16)'k'}, {16,(u16)'l'},
{16,(u16)';'}, {16,(u16)'\''}, {32,(u16)'\n'}, {0,0}}
#define K_CAPS
Definition: ds_kbd.h:21
Initial value:
= {
{40,K_SHIFT}, {16,(u16)'z'}, {16,(u16)'x'}, {16,(u16)'c'}, {16,(u16)'v'},
{16,(u16)'b'}, {16,(u16)'n'}, {16,(u16)'m'}, {16,(u16)','}, {16,(u16)'.'},
{16,(u16)'/'}, {40,K_SHIFT}, {0,0}}
#define K_SHIFT
Definition: ds_kbd.h:22
Initial value:
= {
{32,K_CTRL}, {24,K_ALT}, {128,(u16)' '}, {24,K_ALT}, {32,K_CTRL}, {0,0}}
#define K_ALT
Definition: ds_kbd.h:24
#define K_CTRL
Definition: ds_kbd.h:23
bool shift = false
static
char shifts[] = "`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}\\|;:\'\",<.>/?"
u16* subfont_bgr_bin = (u16*)(0x0601C400)

Referenced by nds_init_fonts(), and swap_font().

u16* subfont_rgb_bin = (u16*)(0x06018400)

Referenced by nds_init_fonts(), and swap_font().

char* TILE_FILE
u16b TILE_HEIGHT
u16b TILE_WIDTH
u16* tiles_bin
u16* top_font_bin

Referenced by draw_char(), and draw_color_char().