├── source ├── plot.h ├── title.h ├── font.h ├── video.h ├── battlefx.h ├── textconsts.h ├── textfn.h ├── ui.h ├── btl_extypes.h ├── gameplay.h ├── saves.h ├── battle.h ├── fast_set.h ├── macros.h ├── textfn.c ├── maps.h ├── btl_types.h ├── textconsts.c ├── renderer.h ├── font.c ├── fast_set.s ├── video.c ├── pdata.h ├── init.c ├── saves.c ├── plot.c ├── battlefx.c ├── title.c ├── renderer.c ├── gameplay.c └── ui.c ├── data ├── lvl0.bin ├── lvl1.bin ├── btl_font.bin ├── btl_nums.bin ├── lvl0_vis.bin ├── lvl1_vis.bin ├── newrcd.bin ├── polylist.bin ├── btl_fingfx.bin ├── btl_finpal.bin ├── btl_nmegfx.bin ├── btl_nmepal.bin ├── btl_objmap.bin ├── btl_objpal.bin ├── btl_skygfx.bin ├── btl_skypal.bin ├── btl_uimap.bin ├── lvl0_flats.bin ├── lvl0_walls.bin ├── lvl1_flats.bin ├── lvl1_walls.bin ├── btl_charagfx.bin ├── btl_charapal.bin ├── btl_imsoftgfx.bin ├── btl_imsoftpal.bin ├── btl_menuicons.bin ├── btl_nmedata.bin ├── btl_starsgfx.bin ├── btl_starspal.bin ├── btl_tachiegfx.bin ├── btl_tachiepal.bin ├── btl_titlegfx.bin ├── btl_titlepal.bin ├── lvl0_backdrop.bin ├── lvl0_colmap.bin ├── lvl0_palette.bin ├── lvl0_sprites.bin ├── lvl0_twalls.bin ├── lvl1_backdrop.bin ├── lvl1_colmap.bin ├── lvl1_palette.bin ├── lvl1_twalls.bin ├── btl_titleobjgfx.bin ├── btl_titleobjpal.bin ├── btl_titlemenupal.bin └── btl_titlemenugfx.bin ├── music ├── cure.wav ├── door.wav ├── fall.wav ├── heal.wav ├── mod3.it ├── mod4.it ├── nope.wav ├── run.wav ├── tech.wav ├── warp.wav ├── MaHope.s3m ├── PIANO1a.it ├── cancel.wav ├── click.wav ├── climb.wav ├── cursor.wav ├── decide.wav ├── destroy.wav ├── locked.wav ├── select.wav ├── sword1.wav ├── sword5.wav ├── temp31.it ├── temp32.it ├── temp9a.it ├── victory.wav ├── airstrike.it ├── jingle13.wav ├── meleehit.wav ├── station02.wav ├── catchladder.wav ├── selectnone.wav ├── statusclose.wav └── statusopen.wav ├── README.md ├── Makefile └── LICENSE /source/plot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int plot_handle(); 4 | -------------------------------------------------------------------------------- /data/lvl0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0.bin -------------------------------------------------------------------------------- /data/lvl1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1.bin -------------------------------------------------------------------------------- /music/cure.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/cure.wav -------------------------------------------------------------------------------- /music/door.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/door.wav -------------------------------------------------------------------------------- /music/fall.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/fall.wav -------------------------------------------------------------------------------- /music/heal.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/heal.wav -------------------------------------------------------------------------------- /music/mod3.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/mod3.it -------------------------------------------------------------------------------- /music/mod4.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/mod4.it -------------------------------------------------------------------------------- /music/nope.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/nope.wav -------------------------------------------------------------------------------- /music/run.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/run.wav -------------------------------------------------------------------------------- /music/tech.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/tech.wav -------------------------------------------------------------------------------- /music/warp.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/warp.wav -------------------------------------------------------------------------------- /data/btl_font.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_font.bin -------------------------------------------------------------------------------- /data/btl_nums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_nums.bin -------------------------------------------------------------------------------- /data/lvl0_vis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_vis.bin -------------------------------------------------------------------------------- /data/lvl1_vis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_vis.bin -------------------------------------------------------------------------------- /data/newrcd.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/newrcd.bin -------------------------------------------------------------------------------- /data/polylist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/polylist.bin -------------------------------------------------------------------------------- /music/MaHope.s3m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/MaHope.s3m -------------------------------------------------------------------------------- /music/PIANO1a.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/PIANO1a.it -------------------------------------------------------------------------------- /music/cancel.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/cancel.wav -------------------------------------------------------------------------------- /music/click.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/click.wav -------------------------------------------------------------------------------- /music/climb.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/climb.wav -------------------------------------------------------------------------------- /music/cursor.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/cursor.wav -------------------------------------------------------------------------------- /music/decide.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/decide.wav -------------------------------------------------------------------------------- /music/destroy.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/destroy.wav -------------------------------------------------------------------------------- /music/locked.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/locked.wav -------------------------------------------------------------------------------- /music/select.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/select.wav -------------------------------------------------------------------------------- /music/sword1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/sword1.wav -------------------------------------------------------------------------------- /music/sword5.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/sword5.wav -------------------------------------------------------------------------------- /music/temp31.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/temp31.it -------------------------------------------------------------------------------- /music/temp32.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/temp32.it -------------------------------------------------------------------------------- /music/temp9a.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/temp9a.it -------------------------------------------------------------------------------- /music/victory.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/victory.wav -------------------------------------------------------------------------------- /data/btl_fingfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_fingfx.bin -------------------------------------------------------------------------------- /data/btl_finpal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_finpal.bin -------------------------------------------------------------------------------- /data/btl_nmegfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_nmegfx.bin -------------------------------------------------------------------------------- /data/btl_nmepal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_nmepal.bin -------------------------------------------------------------------------------- /data/btl_objmap.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_objmap.bin -------------------------------------------------------------------------------- /data/btl_objpal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_objpal.bin -------------------------------------------------------------------------------- /data/btl_skygfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_skygfx.bin -------------------------------------------------------------------------------- /data/btl_skypal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_skypal.bin -------------------------------------------------------------------------------- /data/btl_uimap.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_uimap.bin -------------------------------------------------------------------------------- /data/lvl0_flats.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_flats.bin -------------------------------------------------------------------------------- /data/lvl0_walls.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_walls.bin -------------------------------------------------------------------------------- /data/lvl1_flats.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_flats.bin -------------------------------------------------------------------------------- /data/lvl1_walls.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_walls.bin -------------------------------------------------------------------------------- /music/airstrike.it: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/airstrike.it -------------------------------------------------------------------------------- /music/jingle13.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/jingle13.wav -------------------------------------------------------------------------------- /music/meleehit.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/meleehit.wav -------------------------------------------------------------------------------- /music/station02.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/station02.wav -------------------------------------------------------------------------------- /data/btl_charagfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_charagfx.bin -------------------------------------------------------------------------------- /data/btl_charapal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_charapal.bin -------------------------------------------------------------------------------- /data/btl_imsoftgfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_imsoftgfx.bin -------------------------------------------------------------------------------- /data/btl_imsoftpal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_imsoftpal.bin -------------------------------------------------------------------------------- /data/btl_menuicons.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_menuicons.bin -------------------------------------------------------------------------------- /data/btl_nmedata.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_nmedata.bin -------------------------------------------------------------------------------- /data/btl_starsgfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_starsgfx.bin -------------------------------------------------------------------------------- /data/btl_starspal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_starspal.bin -------------------------------------------------------------------------------- /data/btl_tachiegfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_tachiegfx.bin -------------------------------------------------------------------------------- /data/btl_tachiepal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_tachiepal.bin -------------------------------------------------------------------------------- /data/btl_titlegfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_titlegfx.bin -------------------------------------------------------------------------------- /data/btl_titlepal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_titlepal.bin -------------------------------------------------------------------------------- /data/lvl0_backdrop.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_backdrop.bin -------------------------------------------------------------------------------- /data/lvl0_colmap.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_colmap.bin -------------------------------------------------------------------------------- /data/lvl0_palette.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_palette.bin -------------------------------------------------------------------------------- /data/lvl0_sprites.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_sprites.bin -------------------------------------------------------------------------------- /data/lvl0_twalls.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl0_twalls.bin -------------------------------------------------------------------------------- /data/lvl1_backdrop.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_backdrop.bin -------------------------------------------------------------------------------- /data/lvl1_colmap.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_colmap.bin -------------------------------------------------------------------------------- /data/lvl1_palette.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_palette.bin -------------------------------------------------------------------------------- /data/lvl1_twalls.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/lvl1_twalls.bin -------------------------------------------------------------------------------- /music/catchladder.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/catchladder.wav -------------------------------------------------------------------------------- /music/selectnone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/selectnone.wav -------------------------------------------------------------------------------- /music/statusclose.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/statusclose.wav -------------------------------------------------------------------------------- /music/statusopen.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/music/statusopen.wav -------------------------------------------------------------------------------- /source/title.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void title_screen(); 4 | void logo_screen(); 5 | void ending_credits(); 6 | -------------------------------------------------------------------------------- /data/btl_titleobjgfx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_titleobjgfx.bin -------------------------------------------------------------------------------- /data/btl_titleobjpal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_titleobjpal.bin -------------------------------------------------------------------------------- /data/btl_titlemenupal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DrLancer-X/inheritors-of-the-oubliette/HEAD/data/btl_titlemenupal.bin -------------------------------------------------------------------------------- /source/font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | uint16_t text_width(const char *text); 4 | void draw_text(uint8_t x, uint8_t y, const char *text); 5 | extern const uint8_t *GLYPH_W; 6 | -------------------------------------------------------------------------------- /source/video.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern volatile uint16_t *VIDEO_BUFFER; 4 | 5 | void flip_buffer(); 6 | void first_buffer(); 7 | void paleffect(int pal, int code); 8 | -------------------------------------------------------------------------------- /source/battlefx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "btl_types.h" 3 | 4 | int use_tech_indiv(int anim_timer, int t, struct actor *user, struct actor *targ, uint8_t tech, uint8_t *sp); 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # inheritors-of-the-oubliette 2 | GameBoy Advance dungeon crawling game 3 | 4 | Compilation instructions: Install the gba-dev group of packages with devkitpro and sox for the sound effect conversion. Clone the repository, navigate into the directory and type `make -j32`. 5 | -------------------------------------------------------------------------------- /source/textconsts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | extern const char * const ELEMENTS[]; 5 | extern const char * const STATUSES[]; 6 | extern const char * const ACC_DESC[]; 7 | extern const char * const BATTLE_MENU[]; 8 | extern const char * const CREDITS[]; 9 | extern const size_t CREDITS_NUM; 10 | -------------------------------------------------------------------------------- /source/textfn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Simple text functions, because stdio is too heavy for GBA (uses up too much iwram) 4 | void txt_erase(char *buf); 5 | void txt_set(char *buf, const char *txt); 6 | int txt_len(char *buf); 7 | void txt_append_str(char *buf, const char *append); 8 | void txt_append_num(char *buf, int num); 9 | -------------------------------------------------------------------------------- /source/ui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void show_message(int portrait, const char *text); 4 | void open_status(); 5 | uint8_t status_config(); 6 | int status_load(); 7 | void hide_display(); 8 | void draw_textbar(const char *text); 9 | void draw_iconmenu_plronly(uint8_t psel, uint8_t spronly, int offy); 10 | void draw_iconmenu(uint8_t psel, const uint8_t *icons, uint8_t ilen, uint8_t isel, uint8_t spronly, int offy); 11 | 12 | extern int MESSAGE_OFFSET; 13 | -------------------------------------------------------------------------------- /source/btl_extypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | // External types 4 | 5 | struct btl_enemy { 6 | uint8_t spriteid; 7 | uint8_t sptype; 8 | uint8_t fly; 9 | uint8_t flip; 10 | int16_t maxhp, maxmp, str, def, agi, mag; 11 | int16_t gem_accum; 12 | uint8_t equiptype; 13 | uint8_t eqatt[4]; 14 | uint8_t weak[4]; 15 | uint8_t spdata[8]; 16 | char mname[32]; 17 | char sname[32]; 18 | char ename[32]; 19 | char sdesc[128]; 20 | }; 21 | -------------------------------------------------------------------------------- /source/gameplay.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "renderer.h" 4 | 5 | void gameplay(); 6 | void loadMap(); 7 | int getDirX(uint8_t dir); 8 | int getDirY(uint8_t dir); 9 | int getDirZ(uint8_t dir); 10 | uint8_t getTexDirFrom(uint16_t x, uint16_t y, uint16_t z, uint8_t dir); 11 | int turnLeft(); 12 | int turnRight(); 13 | int after_boss(); 14 | 15 | struct lvldata { 16 | struct lvl_tile *map; 17 | const void *vis; 18 | const uint8_t *backdrop; 19 | }; 20 | -------------------------------------------------------------------------------- /source/saves.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct header_info { 5 | uint8_t magic[6]; 6 | uint8_t colspace; 7 | uint8_t curmem; 8 | uint8_t lrstrafe; 9 | }; 10 | 11 | struct saveinfo { 12 | uint8_t filled; 13 | char txt1[48]; 14 | char txt2[48]; 15 | char txt3[48]; 16 | char txt4[48]; 17 | }; 18 | 19 | struct saveinfo *retrieve_saves(); 20 | void write_save(uint8_t slot); 21 | void load_save(uint8_t slot); 22 | 23 | void load_config(); 24 | void save_config(); 25 | -------------------------------------------------------------------------------- /source/battle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "btl_types.h" 3 | 4 | void battle_engine(uint8_t *enemies, int ambush); 5 | void random_encounter(); 6 | void force_camera_facing(); 7 | void force_fixed_encounter(int idx); 8 | void get_bounds(int cur, int *x1, int *y1, int *x2, int *y2); 9 | 10 | int get_str(int i); 11 | int get_agi(int i); 12 | int get_def(int i); 13 | int get_mag(int i); 14 | int get_acc(struct actor *a); 15 | 16 | extern int BATTLE_MOD; 17 | extern int BATTLE_OUTCOME; 18 | extern int BATTLE_CANNOT_RUN; 19 | extern uint8_t BATTLE_SPOILS[]; 20 | -------------------------------------------------------------------------------- /source/fast_set.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // fast_set requires 4-byte aligned and multiple of 40 bytes data 5 | void fast_set(volatile void *dest, uint32_t v, uint32_t len); 6 | // fast_copy requires 4-byte aligned and multiple of 32 bytes data 7 | void fast_copy(volatile void *dest, const void *src, uint32_t len); 8 | // This copies one column, 64 bytes long, from src into dest 9 | void fast_copy_texcol(void *dest, const void *src); 10 | // This copies two columns, each 64 bytes long, from src1 and src2 into dest 11 | void fast_copy_texcols(void *dest, const void *src1, const void *src2); 12 | -------------------------------------------------------------------------------- /source/macros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #define OBJ_PAL(n) (((volatile uint16_t *)MEM_PAL_OBJ + ((n) << 4))) 7 | #define OBJ_CHR(x, y) (((volatile uint16_t *)0x6014000 + ((x) << 4) + ((y) << 9))) 8 | 9 | #define OBJMEM ((volatile OBJ_ATTR*)MEM_OAM) 10 | #define AFFMEM ((volatile OBJ_AFFINE*)MEM_OAM) 11 | 12 | #define OBJSET(i, cx, cy, x, y, p, a0, a1, a2) { \ 13 | OBJMEM[i].attr0 = ATTR0_Y(y) | ATTR0_4BPP | (a0); \ 14 | OBJMEM[i].attr1 = ATTR1_X(x) | (a1); \ 15 | OBJMEM[i].attr2 = ATTR2_ID(512 + ((cy) << 5) + (cx)) | ATTR2_PALBANK(p) | (a2); \ 16 | } 17 | 18 | #define AFFSET(i, a, b, c, d) { \ 19 | AFFMEM[i].pa = (a); \ 20 | AFFMEM[i].pb = (b); \ 21 | AFFMEM[i].pc = (c); \ 22 | AFFMEM[i].pd = (d); \ 23 | } 24 | 25 | //#define min(x, y) ((x) < (y) ? (x) : (y)) 26 | //#define max(x, y) ((x) > (y) ? (x) : (y)) 27 | #define clamp(x, a, b) (min(max((x), (a)), (b))) 28 | -------------------------------------------------------------------------------- /source/textfn.c: -------------------------------------------------------------------------------- 1 | // Simple text functions, because stdio is too heavy for GBA (uses up too much iwram) 2 | void txt_erase(char *buf) 3 | { 4 | buf[0] = '\0'; 5 | } 6 | void txt_set(char *buf, const char *txt) 7 | { 8 | int pos = 0; 9 | const char *p = txt; 10 | while (*p != '\0') 11 | buf[pos++] = *(p++); 12 | buf[pos] = '\0'; 13 | } 14 | int txt_len(const char *buf) 15 | { 16 | for (int i = 0;; i++) 17 | if (buf[i] == '\0') return i; 18 | } 19 | void txt_append_str(char *buf, const char *append) 20 | { 21 | int pos = txt_len(buf); 22 | const char *p = append; 23 | while (*p != '\0') 24 | buf[pos++] = *(p++); 25 | buf[pos] = '\0'; 26 | } 27 | void txt_append_num(char *buf, int num) 28 | { 29 | int pos = txt_len(buf); 30 | if (num < 0) { 31 | buf[pos++] = '-'; 32 | num *= -1; 33 | } 34 | int div = 1000000000; 35 | while (div > 1) { 36 | if (num >= div) { 37 | break; 38 | } 39 | div /= 10; 40 | } 41 | while (div > 1) { 42 | buf[pos++] = '0' + num / div; 43 | num %= div; 44 | div /= 10; 45 | } 46 | buf[pos++] = '0' + num; 47 | buf[pos] = '\0'; 48 | } 49 | -------------------------------------------------------------------------------- /source/maps.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "lvl0_palette_bin.h" 5 | #include "lvl0_colmap_bin.h" 6 | #include "lvl0_flats_bin.h" 7 | #include "lvl0_walls_bin.h" 8 | #include "lvl0_twalls_bin.h" 9 | #include "lvl0_backdrop_bin.h" 10 | #include "lvl0_bin.h" 11 | #include "lvl0_vis_bin.h" 12 | 13 | #include "lvl1_palette_bin.h" 14 | #include "lvl1_colmap_bin.h" 15 | #include "lvl1_flats_bin.h" 16 | #include "lvl1_walls_bin.h" 17 | #include "lvl1_twalls_bin.h" 18 | #include "lvl1_backdrop_bin.h" 19 | #include "lvl1_bin.h" 20 | #include "lvl1_vis_bin.h" 21 | 22 | 23 | struct mapinfo { 24 | const uint8_t *map; 25 | const uint8_t *vis; 26 | const uint8_t *backdrop; 27 | const uint8_t *palette; 28 | const uint8_t *colmap; 29 | const uint8_t *flats; 30 | const uint8_t *walls; 31 | const uint8_t *twalls; 32 | }; 33 | 34 | const struct mapinfo MAPS[] = { 35 | {lvl0_bin, lvl0_vis_bin, lvl0_backdrop_bin, lvl0_palette_bin, lvl0_colmap_bin, lvl0_flats_bin, lvl0_walls_bin, lvl0_twalls_bin}, 36 | {lvl1_bin, lvl1_vis_bin, lvl1_backdrop_bin, lvl1_palette_bin, lvl1_colmap_bin, lvl1_flats_bin, lvl1_walls_bin, lvl1_twalls_bin} 37 | }; 38 | -------------------------------------------------------------------------------- /source/btl_types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "btl_extypes.h" 4 | #include "btl_nmedata_bin.h" 5 | #include "pdata.h" 6 | 7 | #define NMEDATA ((const struct btl_enemy *)btl_nmedata_bin) 8 | #define NMEDATA_COUNT (btl_nmedata_bin_size / sizeof(struct btl_enemy)) 9 | 10 | #define EQATT_DMG 0 11 | #define EQATT_PCT 1 12 | #define EQATT_STR 2 13 | #define EQATT_WEAK 3 14 | 15 | #define SP_COST 0 16 | #define SP_DAMAGE 1 17 | #define SP_ELEM 2 18 | #define SP_INFLICT 3 19 | #define SP_ALL 4 20 | #define SP_CURE 5 21 | #define SP_REVIVE 6 22 | #define SP_HEAL 7 23 | 24 | #define ACC_POISONRING 0 25 | #define ACC_MPREGEN 1 26 | #define ACC_SPEEDBOOTS 2 27 | #define ACC_AMULET 3 28 | #define ACC_MPMAX 4 29 | 30 | struct actor { 31 | uint8_t active; // 0 - no. 1 - yes 32 | uint8_t id; // 0-1 for player, 0-5 for enemies. 0-5 for enemies must match 2-7 in actor list 33 | uint8_t side; // 0 - player, 1 - enemies 34 | uint8_t refx, flip, tick, var; 35 | struct pd_player *p; 36 | const struct btl_enemy *e; 37 | uint8_t x, y; 38 | uint8_t defending; 39 | }; 40 | 41 | /* 42 | Weapon (0) 43 | eq_power: Damage 44 | eq_chance: Accuracy 45 | eq_strong: Element 46 | eq_weak: Inflicts 47 | 48 | Armour (1) 49 | eq_power: Defense 50 | eq_chance: Dodge 51 | eq_strong: Strong against element 52 | eq_weak: Weak against element 53 | 54 | Helmet (2) 55 | eq_power: Defense 56 | eq_chance: Dodge 57 | eq_strong: Strong against element 58 | eq_weak: Weak against element 59 | 60 | Accessory (3) 61 | eq_power: Type 62 | eq_chance: 63 | eq_strong: 64 | eq_weak: 65 | */ 66 | -------------------------------------------------------------------------------- /source/textconsts.c: -------------------------------------------------------------------------------- 1 | #include "textconsts.h" 2 | 3 | const char * const ELEMENTS[] = { 4 | "Infernal", 5 | "Frigid", 6 | "Heavenly", 7 | "Baleful" 8 | }; 9 | const char * const STATUSES[] = { 10 | "Poison", 11 | "Extra Poison", 12 | "Paralysis", 13 | "Weakness", 14 | "Barrier", 15 | "Regen", 16 | "Fast", 17 | "Inviso", 18 | }; 19 | const char * const ACC_DESC[] = { 20 | "Prevents poison", 21 | "Regenerates Qi during battle", 22 | "Gives an extra turn in battle", 23 | "Prevents all negative status conditions", 24 | "Keeps wearer's Qi completely filled during battle", 25 | }; 26 | const char * const BATTLE_MENU[] = { 27 | "Attack", 28 | "Use spirit technique", 29 | "Defend", 30 | "Pass", 31 | "Escape", 32 | }; 33 | 34 | const char * const CREDITS[] = { 35 | "With the rival clans expelled from the Oubliette,", 36 | "the Qilin clan's legacy has been secured.", 37 | "", 38 | "The spirit crystals and godrelics retrieved by", 39 | "Qilin Hawk and Qilin Star will be used to", 40 | "support the younger generation for centuries", 41 | "to come, further cementing the Qilin clan's", 42 | "position in the immortal world.", 43 | "", 44 | "", 45 | "", 46 | "", 47 | "", 48 | "INHERITORS of the OUBLIETTE", 49 | "---------- ---------", 50 | "", 51 | "(c) 2021 \x7FSOFT", 52 | "", 53 | "", 54 | "--- Credits ---", 55 | "", 56 | "GAME DESIGN:", 57 | "", 58 | "Mahou Shoujo * Magical Moestar", 59 | "one60hp", 60 | "", 61 | "", 62 | "PROGRAMMING:", 63 | "", 64 | "Mahou Shoujo * Magical Moestar", 65 | "", 66 | "", 67 | "GRAPHICS:", 68 | "", 69 | "one60hp", 70 | "", 71 | "", 72 | "MUSIC:", 73 | "", 74 | "one60hp", 75 | "", 76 | "", 77 | "LEVEL DESIGN:", 78 | "", 79 | "one60hp", 80 | "", 81 | "", 82 | "", 83 | "Thanks for playing!", 84 | }; 85 | const size_t CREDITS_NUM = sizeof(CREDITS) / sizeof(CREDITS[0]); 86 | -------------------------------------------------------------------------------- /source/renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct poly_t { 5 | uint16_t id, tex; 6 | }; 7 | 8 | struct rclist_bin { 9 | signed char x, y, z; 10 | unsigned char t, p, c, flip_u, flip_v; 11 | int pos; 12 | }; 13 | 14 | struct rc_bin { 15 | unsigned char x, y, c, z; 16 | //signed short u, v, du, dv; 17 | unsigned int uv, duv; 18 | } __attribute__((packed)); 19 | 20 | struct lvl_tile { 21 | unsigned char texs[6]; // n e s w u d 22 | unsigned char flags; 23 | unsigned char special; 24 | }; 25 | 26 | static const int SCR_W = 240; 27 | static const int SCR_H = 160; 28 | static const int TEX_W = 64; 29 | static const int TEX_H = 64; 30 | static const int TEX_SIZE = TEX_W * TEX_H; 31 | 32 | static const int DIR_N = 0; 33 | static const int DIR_E = 1; 34 | static const int DIR_S = 2; 35 | static const int DIR_W = 3; 36 | static const int DIR_U = 4; 37 | static const int DIR_D = 5; 38 | 39 | static const int PLAT_CEIL = 0; 40 | static const int PLAT_FRONT = 1; 41 | static const int PLAT_SIDE = 2; 42 | static const int PLAT_SPRITE = 3; 43 | 44 | static const int PERSP_FWD = 0; 45 | static const int PERSP_STEP1 = 1; 46 | static const int PERSP_STEP2 = 2; 47 | static const int PERSP_ROT1 = 3; 48 | static const int PERSP_ROT2 = 4; 49 | static const int PERSP_STRAFE1 = 5; 50 | static const int PERSP_STRAFE2 = 6; 51 | static const int PERSP_UP1 = 7; 52 | static const int PERSP_UP2 = 8; 53 | static const int PERSP_MAX = 9; 54 | 55 | static const int POLYLIST_SIZE = 2048; 56 | 57 | extern uint8_t COLSPACE; 58 | 59 | __attribute__((section(".iwram"), long_call, target("arm"))) 60 | uint32_t render_begin(const struct lvl_tile *, const void *, int, int, int, int, int); 61 | 62 | __attribute__((section(".iwram"), long_call, target("arm"))) 63 | uint32_t render_draw(const struct lvl_tile *lvltiles, volatile uint16_t *scr, uint32_t px, uint32_t py, uint32_t pz, uint32_t persp, uint32_t pd, uint32_t polylist_n, uint32_t lim); 64 | 65 | void load_palette(const uint8_t *palette_bin, const uint8_t *colmap_bin); 66 | void init_textures(const uint8_t *flats, const uint8_t *walls, const uint8_t *twalls); 67 | 68 | void update_colspace(); 69 | -------------------------------------------------------------------------------- /source/font.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "btl_font_bin.h" 9 | #include "macros.h" 10 | #include "pdata.h" 11 | #include "font.h" 12 | #include "fast_set.h" 13 | #include "renderer.h" 14 | 15 | const uint8_t *GLYPH_W = btl_font_bin + 0; 16 | const uint16_t *GLYPH_POS = (const uint16_t *)(btl_font_bin + 96); 17 | #define ROW_W ((btl_font_bin_size - 288) / 8) 18 | #define ROW_POS(i) (btl_font_bin + 288 + ROW_W*(i)) 19 | const uint8_t * const GLYPH_ROWS[] = {ROW_POS(0), ROW_POS(1), ROW_POS(2), ROW_POS(3), ROW_POS(4), ROW_POS(5), ROW_POS(6), ROW_POS(7)}; 20 | #define WAIT_HBLANK() do {} while (!(REG_DISPSTAT & DSTAT_IN_HBL)) 21 | 22 | uint16_t text_width(const char *text) 23 | { 24 | const char *p = text; 25 | uint16_t w = 0; 26 | while (*p != '\0') { 27 | uint8_t g = *p - ' '; 28 | w += GLYPH_W[g]; 29 | p++; 30 | } 31 | return w; 32 | } 33 | 34 | //uint8_t dbuffer[1024]; 35 | 36 | void draw_text(uint8_t draw_x, uint8_t draw_y, const char *text) 37 | { 38 | //uint8_t prow = 255; 39 | for (int y = 0; y < 8; y++) { 40 | const char *p = text; 41 | uint8_t shift = (draw_x & 3) << 2; 42 | volatile uint16_t *o = OBJ_CHR(draw_x >> 3, (draw_y + y) >> 3) + (((draw_y + y) & 7) << 1) + ((draw_x & 7) >> 2); 43 | //volatile uint16_t *o = (uint16_t *)(dbuffer + ((uint16_t)draw_x >> 3 << 5)) + (((draw_y + y) & 7) << 1) + ((draw_x & 7) >> 2); 44 | uint16_t odata = *o; 45 | 46 | while (*p != '\0') { 47 | uint8_t g = *p - ' '; 48 | const uint8_t *gp = GLYPH_ROWS[y] + GLYPH_POS[g]; 49 | for (uint8_t x = 0; x < GLYPH_W[g]; x++) { 50 | if (*gp != 0) { 51 | odata = (odata & ~(0x000F << shift)) | ((uint16_t)*gp << shift); 52 | } 53 | shift = (shift + 4) & 15; 54 | if (shift == 0) { 55 | *o = odata; 56 | if ((uint32_t)o & 2) { 57 | o += 15; 58 | } else { 59 | o++; 60 | } 61 | odata = *o; 62 | } 63 | gp++; 64 | } 65 | p++; 66 | } 67 | *o = odata; 68 | } 69 | //WAIT_HBLANK(); 70 | //if (prow != 255) fast_copy(OBJ_CHR(0, prow), dbuffer, 1024); 71 | } 72 | -------------------------------------------------------------------------------- /source/fast_set.s: -------------------------------------------------------------------------------- 1 | .text 2 | .code 16 3 | 4 | .section .iwram, "ax", %progbits; 5 | .arm; 6 | .align 4; 7 | .global fast_set; 8 | .type fast_set STT_FUNC; 9 | 10 | fast_set: 11 | /* r0: *dest */ 12 | /* r1: v */ 13 | /* r2: len */ 14 | push {r4-r11} 15 | add r2, r0, r2 16 | mov r3, r1 17 | mov r4, r1 18 | mov r5, r1 19 | mov r6, r1 20 | mov r7, r1 21 | mov r8, r1 22 | mov r9, r1 23 | mov r10, r1 24 | mov r11, r1 25 | fast_set_lup: 26 | stmia r0!, {r1,r3,r4,r5,r6,r7,r8,r9,r10,r11} /* 10 */ 27 | stmia r0!, {r1,r3,r4,r5,r6,r7,r8,r9,r10,r11} /* 20 */ 28 | stmia r0!, {r1,r3,r4,r5,r6,r7,r8,r9,r10,r11} /* 30 */ 29 | stmia r0!, {r1,r3,r4,r5,r6,r7,r8,r9,r10,r11} /* 40 */ 30 | cmp r0, r2 31 | BNE fast_set_lup 32 | pop {r4-r11} 33 | bx lr 34 | 35 | .section .iwram, "ax", %progbits; 36 | .arm; 37 | .align 4; 38 | .global fast_copy; 39 | .type fast_copy STT_FUNC; 40 | 41 | fast_copy: 42 | /* r0: *dest */ 43 | /* r1: *src */ 44 | /* r2: len */ 45 | push {r4-r10} 46 | add r2, r0, r2 47 | fast_copy_lup: 48 | ldmia r1!, {r3,r4,r5,r6,r7,r8,r9,r10} 49 | stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} 50 | cmp r0, r2 51 | BNE fast_copy_lup 52 | pop {r4-r10} 53 | bx lr 54 | 55 | .section .iwram, "ax", %progbits; 56 | .arm; 57 | .align 4; 58 | .global fast_copy_texcol; 59 | .type fast_copy_texcol STT_FUNC; 60 | 61 | fast_copy_texcol: 62 | /* r0: *dest */ 63 | /* r1: *src */ 64 | push {r4-r9} 65 | ldmia r1!, {r2,r3,r4,r5,r6,r7,r8,r9} 66 | stmia r0!, {r2,r3,r4,r5,r6,r7,r8,r9} 67 | ldmia r1!, {r2,r3,r4,r5,r6,r7,r8,r9} 68 | stmia r0!, {r2,r3,r4,r5,r6,r7,r8,r9} 69 | 70 | pop {r4-r9} 71 | bx lr 72 | 73 | .section .iwram, "ax", %progbits; 74 | .arm; 75 | .align 4; 76 | .global fast_copy_texcols; 77 | .type fast_copy_texcols STT_FUNC; 78 | 79 | fast_copy_texcols: 80 | /* r0: *dest */ 81 | /* r1: *src1 */ 82 | /* r2: *src2 */ 83 | push {r4-r10} 84 | ldmia r1!, {r3,r4,r5,r6,r7,r8,r9,r10} 85 | stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} 86 | ldmia r1!, {r3,r4,r5,r6,r7,r8,r9,r10} 87 | stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} 88 | ldmia r2!, {r3,r4,r5,r6,r7,r8,r9,r10} 89 | stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} 90 | ldmia r2!, {r3,r4,r5,r6,r7,r8,r9,r10} 91 | stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} 92 | 93 | pop {r4-r10} 94 | bx lr 95 | 96 | -------------------------------------------------------------------------------- /source/video.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "video.h" 5 | #include "macros.h" 6 | #include "pdata.h" 7 | 8 | volatile uint16_t *VIDEO_BUFFER = (volatile uint16_t *)MEM_VRAM_BACK; 9 | 10 | void flip_buffer() { 11 | REG_DISPCNT = REG_DISPCNT ^ DCNT_PAGE; 12 | if (REG_DISPCNT & DCNT_PAGE) { 13 | VIDEO_BUFFER = (volatile uint16_t *)MEM_VRAM_FRONT; 14 | } else { 15 | VIDEO_BUFFER = (volatile uint16_t *)MEM_VRAM_BACK; 16 | } 17 | } 18 | 19 | void first_buffer() { 20 | REG_DISPCNT = REG_DISPCNT & ~DCNT_PAGE; 21 | VIDEO_BUFFER = (volatile uint16_t *)MEM_VRAM_BACK; 22 | } 23 | 24 | void paleffect(int pal, int code) 25 | { 26 | volatile uint16_t *p = OBJ_PAL(pal); 27 | 28 | switch (code) { 29 | case STATUS_POISON: 30 | for (int i = 0; i < 16; i++) { 31 | *p = *p & (31 << 5); 32 | p++; 33 | } 34 | break; 35 | case STATUS_BADPOISON: 36 | for (int i = 0; i < 16; i++) { 37 | *p = (*p & (31 << 5)) | (3 << 5); 38 | p++; 39 | } 40 | break; 41 | case STATUS_PARA: 42 | for (int i = 0; i < 16; i++) { 43 | *p = *p & ((31 << 5) | 31); 44 | p++; 45 | } 46 | break; 47 | case STATUS_WEAK: 48 | for (int i = 0; i < 16; i++) { 49 | *p = *p & (31 << 10); 50 | p++; 51 | } 52 | break; 53 | case STATUS_BARRIER: 54 | for (int i = 0; i < 16; i++) { 55 | *p = *p | (31 << 10); 56 | p++; 57 | } 58 | break; 59 | case STATUS_REGEN: 60 | for (int i = 0; i < 16; i++) { 61 | *p = *p | (31 << 5); 62 | p++; 63 | } 64 | break; 65 | case STATUS_FAST: 66 | for (int i = 0; i < 16; i++) { 67 | *p = *p | 31; 68 | p++; 69 | } 70 | break; 71 | case STATUS_INVISO: 72 | for (int i = 0; i < 16; i++) { 73 | *p = *p & 0x56B5; 74 | p++; 75 | } 76 | break; 77 | case PALEFFECT_ENEMYFLASH: 78 | for (int i = 0; i < 16; i++) { 79 | if ((*p & 0x739C) == 0) { 80 | *p = 0x7FFF; 81 | } else { 82 | *p = 0x0000; 83 | } 84 | p++; 85 | } 86 | break; 87 | case PALEFFECT_DAMAGE: 88 | for (int i = 0; i < 16; i++) { 89 | *p = *p & 31; 90 | p++; 91 | } 92 | break; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /source/pdata.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "renderer.h" 3 | 4 | #define STONE_STAT_CALC(x) ((x) >> 1) 5 | 6 | #define EQUIP_WEAPON 0 7 | #define EQUIP_BODY 1 8 | #define EQUIP_HEAD 2 9 | #define EQUIP_ACC 3 10 | #define EQUIP_MAX 4 11 | 12 | #define STATUS_POISON 0 13 | #define STATUS_BADPOISON 1 14 | #define STATUS_PARA 2 15 | #define STATUS_WEAK 3 16 | #define STATUS_BARRIER 4 17 | #define STATUS_REGEN 5 18 | #define STATUS_FAST 6 19 | #define STATUS_INVISO 7 20 | #define STATUS_MAX 8 21 | 22 | #define PALEFFECT_ENEMYFLASH 8 23 | #define PALEFFECT_DAMAGE 9 24 | 25 | /*0 STATUS_POISON - Lose health every turn 26 | 1 STATUS_BADPOISON - Lose more health every turn 27 | 2 STATUS_PARA - Paralysis (40% of moves fail) 28 | 3 STATUS_WEAK - Takes extra damage 29 | 30 | 4 STATUS_BARRIER - Takes less damage 31 | 5 STATUS_REGEN - Regains health per turn 32 | 6 STATUS_FAST - Extra turns 33 | 7 STATUS_INVISO - Harder to hit*/ 34 | 35 | #define SLOTS_MAX 4 36 | #define PLOT_MAX 8 37 | 38 | #define INV_MAX 32 39 | #define PLAYERS_MAX 2 40 | 41 | #define ICONS_MAX 5 42 | 43 | #define CMEM_SCUR 0 44 | #define CMEM_SPLR 1 45 | #define CMEM_SEQUIPA 2 46 | #define CMEM_SEQUIPB 4 47 | // 5-11 are used 48 | #define CMEM_SSTONEA 12 49 | #define CMEM_SSTONEB 14 50 | // 15-21 are used 51 | #define CMEM_STECHSA 22 52 | // 23 is used 53 | #define CMEM_SAVESLOT 24 54 | #define CMEM_CONFIG 25 55 | #define CMEM_BCUR 26 56 | // 27 is used 57 | #define CMEM_BTARG 28 58 | // 29-31 used 59 | #define CMEM_BTEC 32 60 | // 33 used 61 | #define CMEM_STECP 34 62 | // 35 used 63 | #define CMEM_MAX 64 64 | 65 | // All data about a player that needs to be persisted 66 | struct pd_player { 67 | uint8_t pid; 68 | 69 | int16_t hp; 70 | int16_t maxhp; 71 | int16_t mp; 72 | int16_t maxmp; 73 | int16_t str; 74 | int16_t def; 75 | int16_t agi; 76 | int16_t mag; 77 | 78 | uint8_t equip[EQUIP_MAX]; 79 | uint8_t status[STATUS_MAX]; 80 | uint8_t slots[SLOTS_MAX]; 81 | }; 82 | 83 | struct pd_gamestate { 84 | uint8_t x, y, z, d, map; 85 | uint8_t climbing; 86 | struct pd_player pl[PLAYERS_MAX]; 87 | uint8_t equip_qty[INV_MAX]; 88 | uint8_t gem_qty[INV_MAX]; 89 | uint8_t plot[PLOT_MAX]; 90 | uint32_t ticks; 91 | uint8_t cmem[CMEM_MAX]; 92 | }; 93 | 94 | #define PLOT_BASE 0 // basic progression 95 | #define PLOT_TUT 5 // tutorial bits 96 | #define PLOT_ELVL 6 // max encountered enemy 97 | #define PLOT_ENC 7 // random encounters 98 | 99 | #define TUTORIAL_FIRSTEQUIP 1 // first equipment 100 | #define TUTORIAL_FIRSTGEM 2 // first spirit crystal 101 | #define TUTORIAL_RESERVED3 4 // 102 | #define TUTORIAL_RESERVED4 8 // 103 | #define TUTORIAL_RESERVED5 16 // 104 | #define TUTORIAL_RESERVED6 32 // 105 | #define TUTORIAL_RESERVED7 64 // 106 | #define TUTORIAL_RESERVED8 128 // 107 | 108 | extern uint8_t CMEM_ON; 109 | #define CMEM gs.cmem 110 | 111 | //---end persistable data-- 112 | 113 | extern struct pd_gamestate gs; 114 | extern int16_t CURRENT_MOD; 115 | extern uint32_t TICKER; 116 | extern uint16_t INKEY, INKEY_PRESSED; 117 | extern uint16_t KB_TURNLEFT, KB_TURNRIGHT, KB_STRAFELEFT, KB_STRAFERIGHT; 118 | extern uint8_t RELOAD_PALETTE; 119 | extern uint8_t WON_GAME; 120 | extern uint8_t NEW_GAME; 121 | -------------------------------------------------------------------------------- /source/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "soundbank_bin.h" 12 | #include "btl_objpal_bin.h" 13 | #include "btl_objmap_bin.h" 14 | 15 | #include "renderer.h" 16 | #include "pdata.h" 17 | #include "gameplay.h" 18 | #include "macros.h" 19 | #include "fast_set.h" 20 | #include "saves.h" 21 | #include "title.h" 22 | #include "video.h" 23 | 24 | struct pd_gamestate gs; 25 | 26 | int16_t CURRENT_MOD = -1; 27 | int16_t curr_playing_mod = -1; 28 | uint8_t RELOAD_PALETTE = 0; 29 | uint32_t TICKER = 0; 30 | uint16_t INKEY = 0, INKEY_PRESSED = 0; 31 | uint8_t WON_GAME = 0; 32 | uint8_t NEW_GAME; 33 | 34 | uint8_t CMEM_ON = 1; 35 | uint16_t KB_TURNLEFT = KEY_LEFT; 36 | uint16_t KB_TURNRIGHT = KEY_RIGHT; 37 | uint16_t KB_STRAFELEFT = KEY_L; 38 | uint16_t KB_STRAFERIGHT = KEY_R; 39 | 40 | uint16_t inkey_last = 0; 41 | 42 | __attribute__((section(".iwram"), long_call, target("arm"))) 43 | void irqvector() 44 | { 45 | mmFrame(); 46 | inkey_last = INKEY; 47 | INKEY = ~REG_KEYINPUT; 48 | INKEY_PRESSED = INKEY & ~inkey_last; 49 | if (CURRENT_MOD != curr_playing_mod) { 50 | curr_playing_mod = CURRENT_MOD; 51 | if (mmActive()) mmStop(); 52 | if (CURRENT_MOD != -1) 53 | mmStart(CURRENT_MOD, MM_PLAY_LOOP); 54 | } 55 | TICKER++; 56 | } 57 | 58 | void initCnt() 59 | { 60 | REG_DISPCNT = DCNT_MODE4 | DCNT_BG2 | DCNT_OBJ_2D | DCNT_OBJ; 61 | REG_WAITCNT = WS_PREFETCH | WS_ROM2_N8 | WS_ROM0_S1 | WS_ROM0_N3 | WS_SRAM_8; // 0x4317, suitable for actual hw 62 | 63 | oam_init(obj_mem, 128); 64 | } 65 | 66 | void initIrq() 67 | { 68 | IRQ_INIT(); 69 | irq_add(II_VBLANK, mmVBlank); 70 | irq_enable(II_VBLANK); 71 | } 72 | 73 | static void *maxmod_buffer = NULL; 74 | static uint8_t maxmod_mix_memory[MM_MIXLEN_31KHZ]; 75 | 76 | void initMaxmod() 77 | { 78 | if (maxmod_buffer != NULL) 79 | free(maxmod_buffer); 80 | 81 | uint8_t channels = 8; 82 | uint16_t mix_len = MM_MIXLEN_31KHZ; 83 | mm_gba_system sys; 84 | 85 | maxmod_buffer = malloc(mix_len + (channels * (MM_SIZEOF_MODCH + MM_SIZEOF_ACTCH + MM_SIZEOF_MIXCH))); 86 | 87 | sys.mixing_mode = MM_MIX_31KHZ; 88 | sys.mod_channel_count = channels; 89 | sys.mix_channel_count = channels; 90 | sys.wave_memory = (mm_addr) (maxmod_buffer); 91 | sys.module_channels = (mm_addr) (maxmod_buffer + mix_len); 92 | sys.active_channels = (mm_addr) (maxmod_buffer + mix_len + (channels * (MM_SIZEOF_MODCH))); 93 | sys.mixing_channels = (mm_addr) (maxmod_buffer + mix_len + (channels * (MM_SIZEOF_MODCH + MM_SIZEOF_ACTCH))); 94 | sys.mixing_memory = maxmod_mix_memory; 95 | sys.soundbank = (mm_addr)soundbank_bin; 96 | 97 | mmInit(&sys); 98 | mmSetVBlankHandler(irqvector); 99 | mmSetModuleVolume(256); 100 | } 101 | 102 | void initPdata() 103 | { 104 | for (int i = 0; i < PLAYERS_MAX; i++) { 105 | for (int j = 0; j < EQUIP_MAX; j++) 106 | gs.pl[i].equip[j] = 255; 107 | for (int j = 0; j < STATUS_MAX; j++) 108 | gs.pl[i].status[j] = 0; 109 | for (int j = 0; j < SLOTS_MAX; j++) 110 | gs.pl[i].slots[j] = 255; 111 | } 112 | gs.x = 9; 113 | gs.y = 9; 114 | gs.z = 1; 115 | gs.d = DIR_W; 116 | gs.map = 0; 117 | gs.climbing = 0; 118 | 119 | gs.pl[0].pid = 0; 120 | gs.pl[0].maxhp = 100; 121 | gs.pl[0].maxmp = 20; 122 | gs.pl[0].str = 30; 123 | gs.pl[0].def = 15; 124 | gs.pl[0].agi = 20; 125 | gs.pl[0].mag = 10; 126 | gs.pl[0].equip[EQUIP_WEAPON] = 26; 127 | 128 | gs.pl[1].pid = 1; 129 | gs.pl[1].maxhp = 80; 130 | gs.pl[1].maxmp = 60; 131 | gs.pl[1].str = 15; 132 | gs.pl[1].def = 10; 133 | gs.pl[1].agi = 15; 134 | gs.pl[1].mag = 30; 135 | gs.pl[1].equip[EQUIP_WEAPON] = 20; 136 | 137 | for (int i = 0; i < PLAYERS_MAX; i++) { 138 | gs.pl[i].hp = gs.pl[i].maxhp; 139 | gs.pl[i].mp = gs.pl[i].maxmp; 140 | } 141 | for (int i = 0; i < INV_MAX; i++) { 142 | gs.equip_qty[i] = 0; 143 | gs.gem_qty[i] = 0; 144 | } 145 | for (int i = 0; i < PLOT_MAX; i++) { 146 | gs.plot[i] = 0; 147 | } 148 | gs.plot[PLOT_ELVL] = 4; 149 | gs.plot[PLOT_ENC] = 8 + rand() % 10; 150 | /* 151 | gs.plot[PLOT_BASE] = 5; 152 | gs.x = 12; 153 | gs.y = 2; 154 | gs.z = 1; 155 | */ 156 | /* 157 | gs.equip_qty[0] = 1; 158 | gs.equip_qty[1] = 1; 159 | gs.equip_qty[2] = 1; 160 | gs.equip_qty[3] = 1; 161 | gs.equip_qty[4] = 1; 162 | gs.equip_qty[5] = 1; 163 | gs.gem_qty[2] = 1; 164 | gs.gem_qty[3] = 1; 165 | */ 166 | } 167 | 168 | void initVmem() 169 | { 170 | fast_copy(OBJ_PAL(0), btl_objpal_bin + (COLSPACE << 9), 512); 171 | fast_copy(OBJ_CHR(0, 0), btl_objmap_bin, 8192); 172 | } 173 | 174 | int main() 175 | { 176 | int skip_titlescreen = 0; 177 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_WHITE; 178 | REG_BLDY = 16; 179 | 180 | initCnt(); 181 | initIrq(); 182 | initMaxmod(); 183 | load_config(); 184 | for (;;) { 185 | if (!skip_titlescreen) logo_screen(); 186 | 187 | for (;;) { 188 | oam_init(obj_mem, 128); 189 | TICKER = 0; 190 | first_buffer(); 191 | initPdata(); 192 | initVmem(); 193 | NEW_GAME = 1; 194 | if (!skip_titlescreen) title_screen(); 195 | initVmem(); 196 | loadMap(); 197 | gameplay(); 198 | if (WON_GAME) { 199 | WON_GAME = 0; 200 | ending_credits(); 201 | break; 202 | } 203 | } 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /source/saves.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "pdata.h" 7 | #include "saves.h" 8 | #include "textfn.h" 9 | #include "renderer.h" 10 | 11 | const size_t save_size = sizeof(struct saveinfo) + sizeof(struct pd_gamestate); 12 | volatile uint8_t *sram = (volatile uint8_t *)MEM_SRAM; 13 | 14 | void read_bytes(void *out, volatile void *in, size_t n) 15 | { 16 | for (size_t i = 0; i < n; i++) { 17 | ((uint8_t *)out)[i] = ((volatile uint8_t *)in)[i]; 18 | } 19 | } 20 | void write_bytes(const void *from, volatile void *to, size_t n) 21 | { 22 | for (size_t i = 0; i < n; i++) { 23 | ((volatile uint8_t *)to)[i] = ((const uint8_t *)from)[i]; 24 | } 25 | } 26 | 27 | int check_magic() 28 | { 29 | if (sram[0] == 'I' && sram[1] == 'o' && sram[2] == 't' && sram[3] == 'O') { 30 | // Now check that the struct size is the same. 31 | uint16_t size_check; 32 | read_bytes(&size_check, &sram[4], sizeof(size_check)); 33 | if (size_check == save_size) { 34 | return 1; 35 | } 36 | } 37 | return 0; 38 | } 39 | 40 | void write_magic() 41 | { 42 | // First check magic 43 | if (!check_magic()) { 44 | // The check failed. This means that things are in an indeterminate state 45 | // and we cannot make assumptions about the contents of SRAM 46 | 47 | // Erase all save slots (just erasing the 'filled' byte is enough) 48 | for (int i = 0; i < 5; i++) { 49 | size_t save_pos = i * save_size + sizeof(struct header_info); 50 | sram[save_pos] = 0; 51 | } 52 | // Now write the magic 53 | sram[0] = 'I'; 54 | sram[1] = 'o'; 55 | sram[2] = 't'; 56 | sram[3] = 'O'; 57 | // Write size 58 | uint16_t size_check = save_size; 59 | write_bytes(&size_check, &sram[4], sizeof(size_check)); 60 | } 61 | 62 | // Before we update the config info, temp disable the magic. 63 | // This is in case we lose power mid-write 64 | 65 | sram[0] = 'W'; 66 | // Write config 67 | struct header_info header; 68 | memset(&header, 0, sizeof(header)); 69 | header.colspace = COLSPACE; 70 | header.curmem = CMEM_ON; 71 | header.lrstrafe = (KB_STRAFELEFT == KEY_L) ? 1 : 0; 72 | // Don't write over magic 73 | write_bytes(((const void *)&header) + 6, &sram[6], sizeof(header) - 6); 74 | 75 | // Fix the magic again 76 | sram[0] = 'I'; 77 | } 78 | 79 | struct saveinfo *retrieve_saves() 80 | { 81 | // We assume we have 32kb of sram 82 | 83 | struct saveinfo *saves = malloc(sizeof(struct saveinfo) * 5); 84 | for (int i = 0; i < 5; i++) saves[i].filled = 0; 85 | 86 | // First, check if our magic is there. If not, all saves are empty 87 | if (check_magic()) { 88 | // Read each save in 89 | for (int i = 0; i < 5; i++) { 90 | size_t save_pos = i * save_size + sizeof(struct header_info); 91 | read_bytes(&saves[i], &sram[save_pos], sizeof(struct saveinfo)); 92 | } 93 | } 94 | 95 | return saves; 96 | } 97 | 98 | void write_save(uint8_t slot) 99 | { 100 | gs.ticks = TICKER; 101 | 102 | uint32_t seconds_played; 103 | if (gs.ticks > 20000000) { 104 | seconds_played = gs.ticks / 60; 105 | } else { 106 | seconds_played = gs.ticks * 100 / 5973; 107 | } 108 | 109 | write_magic(); 110 | 111 | struct saveinfo *save = malloc(sizeof(struct saveinfo)); 112 | save->filled = 0; // We will write this byte last 113 | txt_set(save->txt1, "Life: "); 114 | for (int i = 0; i < 2; i++) { 115 | if (gs.pl[i].pid != 0xFF) { 116 | txt_append_num(save->txt1, gs.pl[i].hp); 117 | txt_append_str(save->txt1, "/"); 118 | txt_append_num(save->txt1, gs.pl[i].maxhp); 119 | txt_append_str(save->txt1, " "); 120 | } 121 | } 122 | txt_set(save->txt2, "Qi: "); 123 | for (int i = 0; i < 2; i++) { 124 | if (gs.pl[i].pid != 0xFF) { 125 | txt_append_num(save->txt2, gs.pl[i].mp); 126 | txt_append_str(save->txt2, "/"); 127 | txt_append_num(save->txt2, gs.pl[i].maxmp); 128 | txt_append_str(save->txt2, " "); 129 | } 130 | } 131 | int stones = 0; 132 | for (int i = 0; i < 2; i++) { 133 | for (int j = 0; j < SLOTS_MAX; j++) { 134 | if (gs.pl[i].slots[j] != 0xFF) stones++; 135 | } 136 | } 137 | for (int i = 0; i < INV_MAX; i++) { 138 | stones += gs.gem_qty[i]; 139 | } 140 | txt_set(save->txt3, "Spirit crystals: "); 141 | txt_append_num(save->txt3, stones); 142 | 143 | txt_set(save->txt4, "Time played: "); 144 | int mins = seconds_played / 60 % 60; 145 | int hours = mins / 60; 146 | seconds_played %= 60; 147 | if (hours > 0) { 148 | txt_append_num(save->txt4, hours); 149 | txt_append_str(save->txt4, ":"); 150 | if (mins < 10) txt_append_str(save->txt4, "0"); 151 | } 152 | if (mins > 0) { 153 | txt_append_num(save->txt4, mins); 154 | txt_append_str(save->txt4, ":"); 155 | if (seconds_played < 10) txt_append_str(save->txt4, "0"); 156 | } 157 | 158 | txt_append_num(save->txt4, seconds_played); 159 | 160 | txt_append_str(save->txt4, "s"); 161 | 162 | // Write the save, then pdata 163 | size_t save_pos = slot * save_size + sizeof(struct header_info); 164 | write_bytes(save, &sram[save_pos], sizeof(struct saveinfo)); 165 | write_bytes(&gs, &sram[save_pos + sizeof(struct saveinfo)], sizeof(struct pd_gamestate)); 166 | 167 | // Write the 'filled' byte 168 | sram[save_pos] = 1; 169 | 170 | free(save); 171 | } 172 | void load_save(uint8_t slot) 173 | { 174 | size_t save_pos = slot * save_size + sizeof(struct header_info); 175 | read_bytes(&gs, &sram[save_pos + sizeof(struct saveinfo)], sizeof(struct pd_gamestate)); 176 | TICKER = gs.ticks; 177 | } 178 | 179 | void load_config() 180 | { 181 | if (check_magic()) { 182 | struct header_info header; 183 | read_bytes(&header, &sram[0], sizeof(header)); 184 | COLSPACE = header.colspace; 185 | CMEM_ON = header.curmem; 186 | if (header.lrstrafe) { 187 | KB_TURNLEFT = KEY_LEFT; 188 | KB_TURNRIGHT = KEY_RIGHT; 189 | KB_STRAFELEFT = KEY_L; 190 | KB_STRAFERIGHT = KEY_R; 191 | } else { 192 | KB_STRAFELEFT = KEY_LEFT; 193 | KB_STRAFERIGHT = KEY_RIGHT; 194 | KB_TURNLEFT = KEY_L; 195 | KB_TURNRIGHT = KEY_R; 196 | } 197 | update_colspace(); 198 | } 199 | } 200 | void save_config() 201 | { 202 | write_magic(); 203 | } 204 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | include $(DEVKITARM)/gba_rules 10 | 11 | #--------------------------------------------------------------------------------- 12 | # TARGET is the name of the output 13 | # BUILD is the directory where object files & intermediate files will be placed 14 | # SOURCES is a list of directories containing source code 15 | # INCLUDES is a list of directories containing extra header files 16 | # DATA is a list of directories containing binary data 17 | # GRAPHICS is a list of directories containing files to be processed by grit 18 | # 19 | # All directories are specified relative to the project directory where 20 | # the makefile is found 21 | # 22 | #--------------------------------------------------------------------------------- 23 | TARGET := $(notdir $(CURDIR)) 24 | BUILD := build 25 | SOURCES := source 26 | INCLUDES := include 27 | DATA := data 28 | MUSIC := music 29 | 30 | #--------------------------------------------------------------------------------- 31 | # options for code generation 32 | #--------------------------------------------------------------------------------- 33 | ARCH := -mthumb -mthumb-interwork 34 | 35 | OPTIM := -O3 36 | 37 | CFLAGS := -Wall $(OPTIM) \ 38 | -mcpu=arm7tdmi -mtune=arm7tdmi \ 39 | $(ARCH) 40 | 41 | CFLAGS += $(INCLUDE) 42 | 43 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 44 | 45 | ASFLAGS := $(ARCH) 46 | LDFLAGS = $(ARCH) 47 | 48 | #--------------------------------------------------------------------------------- 49 | # any extra libraries we wish to link with the project 50 | #--------------------------------------------------------------------------------- 51 | LIBS := -lmm -ltonc 52 | 53 | 54 | #--------------------------------------------------------------------------------- 55 | # list of directories containing libraries, this must be the top level containing 56 | # include and lib 57 | #--------------------------------------------------------------------------------- 58 | LIBDIRS := $(LIBGBA) $(DEVKITPRO)/libtonc 59 | 60 | #--------------------------------------------------------------------------------- 61 | # no real need to edit anything past this point unless you need to add additional 62 | # rules for different file extensions 63 | #--------------------------------------------------------------------------------- 64 | 65 | 66 | ifneq ($(BUILD),$(notdir $(CURDIR))) 67 | #--------------------------------------------------------------------------------- 68 | 69 | export OUTPUT := $(CURDIR)/$(TARGET) 70 | 71 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 72 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \ 73 | $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) 74 | 75 | export DEPSDIR := $(CURDIR)/$(BUILD) 76 | 77 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 78 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 79 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 80 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 81 | 82 | export ITFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.it $(MUSIC)/*.s3m)),$(CURDIR)/$(MUSIC)/$(dir)) 83 | export WAVFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.wav)),$(CURDIR)/$(MUSIC)/$(dir)) 84 | 85 | ifneq ($(strip $(MUSIC)),) 86 | export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(MUSIC)/*.*)),$(CURDIR)/$(BUILD)/$(dir)) 87 | BINFILES += soundbank.bin 88 | endif 89 | 90 | #--------------------------------------------------------------------------------- 91 | # use CXX for linking C++ projects, CC for standard C 92 | #--------------------------------------------------------------------------------- 93 | ifeq ($(strip $(CPPFILES)),) 94 | #--------------------------------------------------------------------------------- 95 | export LD := $(CC) 96 | #--------------------------------------------------------------------------------- 97 | else 98 | #--------------------------------------------------------------------------------- 99 | export LD := $(CXX) 100 | #--------------------------------------------------------------------------------- 101 | endif 102 | #--------------------------------------------------------------------------------- 103 | 104 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 105 | 106 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 107 | 108 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 109 | 110 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 111 | 112 | export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ 113 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 114 | -I$(CURDIR)/$(BUILD) 115 | 116 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 117 | 118 | .PHONY: $(BUILD) clean 119 | 120 | #--------------------------------------------------------------------------------- 121 | $(BUILD): 122 | @[ -d $@ ] || mkdir -p $@ 123 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 124 | 125 | #--------------------------------------------------------------------------------- 126 | clean: 127 | @echo clean ... 128 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba 129 | src: 130 | $(CC) -S -O0 -fverbose-asm -mcpu=arm7tdmi -mtune=arm7tdmi -o src-O0.S source/template.c 131 | printarch: 132 | @echo $(ARCH) 133 | printver: 134 | $(CC) -v 135 | 136 | #--------------------------------------------------------------------------------- 137 | else 138 | 139 | #--------------------------------------------------------------------------------- 140 | # main targets 141 | #--------------------------------------------------------------------------------- 142 | 143 | $(OUTPUT).gba : $(OUTPUT).elf 144 | 145 | $(OUTPUT).elf : $(OFILES) 146 | 147 | $(OFILES_SOURCES) : $(HFILES) 148 | 149 | #--------------------------------------------------------------------------------- 150 | # The bin2o rule should be copied and modified 151 | # for each extension used in the data directories 152 | #--------------------------------------------------------------------------------- 153 | 154 | #--------------------------------------------------------------------------------- 155 | # rule to build soundbank from music files 156 | #--------------------------------------------------------------------------------- 157 | soundbank.bin soundbank.h : $(ITFILES) 158 | #--------------------------------------------------------------------------------- 159 | @cp $(ITFILES) . 160 | for i in $(WAVFILES) ; do \ 161 | sox $$i -D `basename $$i` rate -I 31536 ; \ 162 | done 163 | @mmutil $(AUDIOFILES) -v -osoundbank.bin -hsoundbank.h 164 | 165 | #--------------------------------------------------------------------------------- 166 | # This rule links in binary data with the .bin extension 167 | #--------------------------------------------------------------------------------- 168 | %.bin.o %_bin.h : %.bin 169 | #--------------------------------------------------------------------------------- 170 | @echo $(notdir $<) 171 | @$(bin2o) 172 | 173 | 174 | -include $(DEPSDIR)/*.d 175 | #--------------------------------------------------------------------------------------- 176 | endif 177 | #--------------------------------------------------------------------------------------- 178 | -------------------------------------------------------------------------------- /data/btl_titlemenugfx.bin: -------------------------------------------------------------------------------- 1 | "!1#!#"1#!!"2""2#122!22!22"22"!"2#2222222!!!!!!!!2!#!"###1####"#""222122222!!1!22!"11!"!#22!22!"1!"#!!!####!##!"12#1"@DD@D"BD$4#D$CD#D"BDD4#D$D$CD"BCDB2DDD"D"B2#422$C22$C22D"2@D@BDDD2"B$"2#D22DC22DD22@2D$$D$C$D$$$DDB$D2$CD#$C"###4####C"#BC"C"DD@DBBDB22D242B2C222B$$4@D@$@B@2@2@$DD"D4BDDC4$"$BB#D22$D22$"4$"DDD@DBBD#$$$#C###C$##C$CDD"B42#4BC"B13113111131313@43DDD4D43DDD4@4DDD@C4C4DDDD3DCCDDDD@4CD3DD@DCCDCDD@D43DD!!!!!!!"3#!""#13#!#!#!"!"!231!#"2""2#12!22!22"1""2#!12##2!2"21!"321!!"3222!"1!"!!##!!!22"!1"#12##1!"D$$$$$$$DD"B3#DDC$C""B#43#$#C$#BC$C"@@DDDDB$"$2B3C4$BDCD#DB"BCDB2DDD"D"D2#4B2$C22$C22D"4DD@D"BD"2#$42D##2D$B2D"@D@B@2@4@C@B@DD$"DB3BD2D4$$"DBD3B2BD22$"4$DDD"$D$##C$$CBB$C22"C$4DDDD"B#42##4$BCD"B1313111133313D@CDC4D@DD343DDDD4D4CDDD4@4DD3DD3CD@DD@3CDCDD@DD43DD"!1322!"!!"#!32!#2!#!#!312"2222222222!!##!"###"""22#!22#22!12!!""12!32!2!"2!1!!2#!22!#22!#2!#"3222@DDD"B@$43@BCD@2D@@2@@$DDD"BDDDD$B$"B#$32$#C2$#C$B#CDDD@$BBDB34D2DBB"D222C222D222D2DDDD$B$DB##C$"#CD##C"BC"DDD@B"BD22#$22D#22D$42DDD$DDD$C"B"B42$3C2$CC2$C"2$CDB4DDDB$B$2B#$22$#22$#2$B#D"D3BC2C2C2133111131113131@43DDD3DCDDDD44D4DDD43D4DDDC4@DD43DCDDDD4D3DDDDDC4DDUUQQUQQUQQQQQQQUQQQQQQQQQQUQQQQUQQQQQQQQUUUUQQUUUQUUUQQQUQQQQUQQQQQUUUUUUQUUQUUQUQQUQQQUQU -------------------------------------------------------------------------------- /source/plot.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fast_set.h" 4 | #include "pdata.h" 5 | #include "gameplay.h" 6 | #include "soundbank.h" 7 | #include "renderer.h" 8 | #include "video.h" 9 | #include "battle.h" 10 | #include "ui.h" 11 | #include "macros.h" 12 | #include "btl_tachiegfx_bin.h" 13 | #include "btl_tachiepal_bin.h" 14 | #include "btl_objmap_bin.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define PLOT_HANDLE(v_, x_, y_, z_, f_) \ 23 | do { \ 24 | if (((v_) == gs.plot[PLOT_BASE]) && ((x_) == gs.x) && ((y_) == gs.y) && ((z_) == gs.z)) { \ 25 | f_(); \ 26 | MESSAGE_OFFSET = 0; \ 27 | gs.plot[PLOT_BASE] = v_+1; \ 28 | } \ 29 | } while(0); 30 | 31 | #define Q_HAWK 0 32 | #define Q_STAR 1 33 | #define D_THUNDER 2 34 | #define D_SKY 3 35 | #define D_PATRIARCH 4 36 | #define D_RAVEN 5 37 | #define R_EMPEROR 6 38 | 39 | static void draw_sp(int s) 40 | { 41 | MESSAGE_OFFSET = -32; 42 | fast_copy(OBJ_PAL(15), btl_tachiepal_bin + (s << 7) + (COLSPACE << 5), 32); 43 | for (uint32_t y = 0; y < 8; y++) { 44 | fast_copy(OBJ_CHR(24, 0 + y), btl_tachiegfx_bin + (y << 8) + (s << 11), 256); 45 | } 46 | OBJSET(127, 24, 0, 88, 80, 15, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 47 | } 48 | static void draw_sp_fadein(int s) 49 | { 50 | draw_sp(s); 51 | REG_BLDCNT = BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 52 | REG_BLDALPHA = BLDA_BUILD(0, 16); 53 | OBJSET(127, 24, 0, 88, 80, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 54 | for (int i = 0; i <= 16; i++) { 55 | REG_BLDALPHA = BLDA_BUILD(i, 16-i); 56 | VBlankIntrWait(); 57 | } 58 | OBJSET(127, 24, 0, 88, 80, 15, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 59 | } 60 | static void hide_sp() 61 | { 62 | obj_hide(&oam_mem[127]); 63 | fast_copy(OBJ_CHR(0, 0), btl_objmap_bin, 8192); 64 | } 65 | static void dissolve_sp(int fboss) 66 | { 67 | REG_BLDCNT = BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 68 | REG_BLDALPHA = BLDA_BUILD(16, 0); 69 | OBJSET(127, 24, 0, 88, 80, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 70 | 71 | for (int i = 0; i < 19; i++) { 72 | int v = i; 73 | if (i >= 12) OBJSET(127, 24, 0, 87 - (i-12)/4, 80, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 74 | REG_BLDALPHA = BLDA_BUILD(min(20 - v, 16), min(v, 16)); 75 | VBlankIntrWait(); 76 | 77 | if (fboss) { 78 | OBJSET(127, 24, 0, 88, 80, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 79 | v++; 80 | REG_BLDALPHA = BLDA_BUILD(min(20 - v, 16), min(v + 1, 16)); 81 | VBlankIntrWait(); 82 | } 83 | 84 | v++; 85 | REG_BLDALPHA = BLDA_BUILD(min(20 - v, 16), v); 86 | VBlankIntrWait(); 87 | if (i >= 12) OBJSET(127, 24, 0, 89 + (i-12)/4, 80, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 88 | v--; 89 | REG_BLDALPHA = BLDA_BUILD(min(20 - v, 16), min(v, 16)); 90 | VBlankIntrWait(); 91 | 92 | if (fboss) { 93 | OBJSET(127, 24, 0, 88, 80, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 94 | v--; 95 | REG_BLDALPHA = BLDA_BUILD(min(20 - v, 16), min(v + 1, 16)); 96 | VBlankIntrWait(); 97 | } 98 | 99 | v++; 100 | REG_BLDALPHA = BLDA_BUILD(min(20 - v, 16), min(v, 16)); 101 | VBlankIntrWait(); 102 | } 103 | hide_sp(); 104 | } 105 | 106 | static void wait() 107 | { 108 | for (int i = 0; i < 50; i++) { 109 | VBlankIntrWait(); 110 | } 111 | } 112 | 113 | 114 | void plot1() { 115 | show_message(Q_HAWK, "\"The portal worked. Our Qilin clan may yet realise some good fortune from this after all.\""); 116 | show_message(Q_STAR, "\"So this is the ancient training ground... I can already sense the presence of spirit entities.\""); 117 | show_message(Q_HAWK, "\"Be careful, clan sister Star. While the spirit crystals have the potential to bring us great power, the spirit entities are not to be underestimated.\""); 118 | show_message(Q_STAR, "\"I know that, clan brother Hawk. With these godrelics the clan patriarch provided us, we should surely be fine.\""); 119 | show_message(Q_HAWK, "\"These may be almighty relics back in our realm, but this is an ancient macrocosm. That is why the rewards will be so great. Because the risk is even higher.\""); 120 | show_message(Q_STAR, "\"Look, we should just hurry along and see if we can find something good to take back to the clan. The portal only opens once every 10,000 years after all. I don't want to miss anything.\""); 121 | } 122 | 123 | void plot2() { 124 | CURRENT_MOD = MOD_TEMP32; 125 | force_camera_facing(); 126 | draw_sp_fadein(1); 127 | wait(); 128 | show_message(D_THUNDER, "\"Halt! You have trespassed upon the sacred training grounds of the great Dragonfly clan! Hand over any treasures you have found and leave at once!\""); 129 | show_message(Q_STAR, "\"Who the hell are you? I've never heard of this Dragonfly clan before. Our Qilin clan has been using these grounds to train our chosen sons and daughters for hundreds of thousands of years!\""); 130 | show_message(D_THUNDER, "\"That you do not show proper respect to the great Dragonfly Thunderbolt is an insult so great that it can only be washed away with the blood of your entire clan!\""); 131 | show_message(Q_HAWK, "\"Listen, I don't know who you are and I don't care. I'm only going to warn you once. Turn around and leave now or you will regret it.\""); 132 | show_message(D_THUNDER, "\"Apparently rudeness and overconfidence go hand in hand. Very well, but it is you who will soon regret your rash choice of actions!\""); 133 | hide_sp(); 134 | force_fixed_encounter(21); 135 | draw_sp(1); 136 | if (after_boss()) return; 137 | CURRENT_MOD = MOD_TEMP32; 138 | wait(); 139 | show_message(D_THUNDER, "\"They are too powerful. I can't go on. Forgive me, Patriarch.\""); 140 | show_message(Q_HAWK, "\"I told you not to mess with us.\""); 141 | wait(); 142 | dissolve_sp(0); 143 | gs.plot[PLOT_ELVL] = 8; 144 | } 145 | void plot3() { 146 | CURRENT_MOD = MOD_TEMP32; 147 | force_camera_facing(); 148 | draw_sp_fadein(2); 149 | wait(); 150 | show_message(D_SKY, "\"I finally managed to track you down! You will pay for what you did to the young scion of the Dragonfly clan, Dragonfly Thunderbolt!\""); 151 | show_message(Q_HAWK, "\"There's more of you Dragonfly people around? All right, I'll bite. What's your name?\""); 152 | show_message(D_SKY, "\"You would do well to learn the name of Dragonfly Sky, the Holy Daughter of the Dragonfly clan!\""); 153 | show_message(Q_STAR, "\"I'm not sure we really need to learn it, though.\""); 154 | 155 | hide_sp(); 156 | force_fixed_encounter(22); 157 | draw_sp(2); 158 | if (after_boss()) return; 159 | CURRENT_MOD = MOD_TEMP32; 160 | wait(); 161 | show_message(D_SKY, "\"How is this possible?\""); 162 | show_message(Q_HAWK, "\"All we wanted you to do was leave us alone... what was your name again?\""); 163 | show_message(D_SKY, "\"You... you... augh!\""); 164 | wait(); 165 | dissolve_sp(0); 166 | gs.plot[PLOT_ELVL] = 12; 167 | } 168 | void plot4() { 169 | CURRENT_MOD = MOD_TEMP32; 170 | force_camera_facing(); 171 | draw_sp_fadein(3); 172 | wait(); 173 | show_message(D_PATRIARCH, "\"How dare you spill the blood of the younger generation of the Dragonfly clan! This insult you have dealt us is close to unendurable. Now only I, Dragonfly Patriarch, can address this insult to my clan!\""); 174 | show_message(Q_STAR, "\"Listen, we have no great emnity with you. Your clan simply needs to do a better job keepings its Chosen in check. We are willing to walk away.\""); 175 | show_message(D_PATRIARCH, "\"The time for words has long passed.\""); 176 | show_message(Q_HAWK, "\"He's in no mood to negotiate. Star, get ready!\""); 177 | hide_sp(); 178 | force_fixed_encounter(23); 179 | draw_sp(3); 180 | if (after_boss()) return; 181 | CURRENT_MOD = MOD_TEMP32; 182 | wait(); 183 | show_message(D_PATRIARCH, "\"It's not over. You will not get away with this.\""); 184 | wait(); 185 | dissolve_sp(0); 186 | gs.plot[PLOT_ELVL] = 16; 187 | } 188 | void plot5() { 189 | CURRENT_MOD = MOD_TEMP32; 190 | force_camera_facing(); 191 | draw_sp_fadein(4); 192 | wait(); 193 | show_message(D_RAVEN, "\"I see some intrusive insects have emerged.\""); 194 | show_message(Q_HAWK, "\"Oh great. Don't tell me, you're the Dragonfly Matriarch and you're really angry with us for demolishing your clan.\""); 195 | show_message(D_RAVEN, "\"I don't have one whit of care for your clan squabbles, but I will take possession of those spirit crystals and spirit items you've been hoarding.\""); 196 | show_message(Q_STAR, "\"We aren't going to let you do that!\""); 197 | hide_sp(); 198 | force_fixed_encounter(24); 199 | draw_sp(4); 200 | if (after_boss()) return; 201 | CURRENT_MOD = MOD_TEMP32; 202 | wait(); 203 | show_message(D_RAVEN, "\"Thunder... Sky... I'm sorry...\""); 204 | wait(); 205 | dissolve_sp(0); 206 | gs.plot[PLOT_ELVL] = 20; 207 | } 208 | void plot6() { 209 | CURRENT_MOD = MOD_TEMP32; 210 | force_camera_facing(); 211 | draw_sp_fadein(5); 212 | wait(); 213 | show_message(R_EMPEROR, "\"I see others have come for what is rightfully mine, but only I, Righteous Emperor, have the strength to take it!\""); 214 | show_message(Q_HAWK, "\"Try telling that to the Dragonfly clan.\""); 215 | show_message(R_EMPEROR, "\"Laugh it up while you still can. Your adventure and your lives end here.\""); 216 | show_message(Q_STAR, "\"Hawk, watch out!\""); 217 | hide_sp(); 218 | force_fixed_encounter(25); 219 | draw_sp(5); 220 | if (after_boss()) return; 221 | CURRENT_MOD = MOD_TEMP32; 222 | wait(); 223 | show_message(R_EMPEROR, "\"What... how?\""); 224 | show_message(Q_HAWK, "\"We learned how to fight here. Our ancestors stretching back to time memorial trained on these grounds.\""); 225 | show_message(Q_STAR, "\"As far as we are concerned, this place is ours. Who are you, and why did you come here?\""); 226 | show_message(R_EMPEROR, "\"Ugh...\""); 227 | wait(); 228 | dissolve_sp(1); 229 | wait(); 230 | MESSAGE_OFFSET = 0; 231 | CURRENT_MOD = MOD_MAHOPE; 232 | show_message(Q_HAWK, "\"He's dead.\""); 233 | show_message(Q_STAR, "\"I'm glad that's over. Clan brother Hawk, grab everything that you can and let's go.\""); 234 | show_message(Q_HAWK, "\"The Qilin will never be vanquished.\""); 235 | show_message(Q_STAR, "\"Never.\""); 236 | } 237 | 238 | int plot_handle() 239 | { 240 | BATTLE_CANNOT_RUN = 1; 241 | PLOT_HANDLE(0, 8, 9, 1, plot1); // 2/280 242 | PLOT_HANDLE(5, 7, 12, 3, plot2); // 20/280 243 | PLOT_HANDLE(8, 2, 9, 6, plot3); // 73/280 244 | PLOT_HANDLE(9, 5, 8, 15, plot4); // 154/280 245 | PLOT_HANDLE(10, 14, 3, 12, plot5); // 219/280 246 | PLOT_HANDLE(11, 12, 2, 0, plot6); // 247 | PLOT_HANDLE(11, 12, 3, 0, plot6); // 248 | BATTLE_CANNOT_RUN = 0; 249 | if (BATTLE_OUTCOME == -1) return 1; 250 | if (gs.plot[PLOT_BASE] == 12) { 251 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 252 | WON_GAME = 1; 253 | for (int i = 0; i <= 16; i++) { 254 | REG_BLDY = i; 255 | VBlankIntrWait(); 256 | VBlankIntrWait(); 257 | VBlankIntrWait(); 258 | VBlankIntrWait(); 259 | } 260 | return 1; 261 | } 262 | return 0; 263 | } 264 | -------------------------------------------------------------------------------- /source/battlefx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "macros.h" 6 | #include "soundbank.h" 7 | #include "fast_set.h" 8 | #include "renderer.h" 9 | #include "font.h" 10 | #include "ui.h" 11 | #include "textfn.h" 12 | #include "textconsts.h" 13 | #include "gameplay.h" 14 | #include "battle.h" 15 | #include "battlefx.h" 16 | #include "video.h" 17 | 18 | #include "btl_objmap_bin.h" 19 | #include "btl_objpal_bin.h" 20 | #include "btl_nums_bin.h" 21 | #include "btl_menuicons_bin.h" 22 | 23 | #include "btl_charagfx_bin.h" 24 | #include "btl_charapal_bin.h" 25 | #include "btl_nmegfx_bin.h" 26 | #include "btl_nmepal_bin.h" 27 | #include "btl_nmedata_bin.h" 28 | 29 | #include "btl_types.h" 30 | 31 | #include "pdata.h" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | static int anim_timer = -1; 42 | static int t; 43 | static int x1, y1, x2, y2; 44 | static int id; 45 | static int cx, cy; 46 | static struct actor *user, *targ; 47 | static uint8_t tech; 48 | static uint8_t *sp; 49 | static struct { 50 | int x, y, digit, life, green; 51 | } *digits = NULL; 52 | static int digits_n = 0; 53 | 54 | static int anim_model; // 0 - melee. 1 - offensive tech. 2 - beneficial tech 55 | 56 | static int targ_hit = 0; 57 | 58 | #define ODRW(sx, sy, dx, dy, pal, attr0, attr1, attr2) \ 59 | do { \ 60 | if ((dx) >= 0 && (dy) >= 0 && (dx) < 240 && (dy) < 160 && *sp != 0xFF) { \ 61 | OBJSET(*sp, (sx), (sy), (dx), (dy), (pal), (attr0), (attr1), (attr2)); \ 62 | (*sp)--; \ 63 | } \ 64 | } while(0); 65 | 66 | #define RAND(x, y) (rand() % ((y) - (x) + 1) + x) 67 | 68 | static void add_digits(int x, int y, int v) 69 | { 70 | int green = 0; 71 | if (v < 0) { 72 | v = -v; 73 | green = 1; 74 | } 75 | x -= 4; 76 | if (v >= 10) x += 4; 77 | if (v >= 100) x += 4; 78 | if (v >= 1000) x += 4; 79 | int i = 0; 80 | for (;;) { 81 | digits[digits_n].x = x; 82 | digits[digits_n].y = y - i; 83 | digits[digits_n].digit = v % 10; 84 | digits[digits_n].life = 40 - (i * 2); 85 | digits[digits_n].green = green; 86 | x -= 8; 87 | digits_n++; 88 | i++; 89 | v /= 10; 90 | if (v == 0) break; 91 | } 92 | } 93 | static void add_miss(int x, int y) 94 | { 95 | digits[digits_n].x = x - 8; 96 | digits[digits_n].y = y - 4; 97 | digits[digits_n].digit = -1; 98 | digits[digits_n].life = 40; 99 | digits[digits_n].green = 0; 100 | digits_n++; 101 | } 102 | 103 | int get_weapon() 104 | { 105 | // If this is a creature that carries a weapon, use it 106 | if (user->side == 1) { 107 | if (user->e->equiptype == EQUIP_WEAPON) { 108 | return user->e->spriteid; 109 | } 110 | } 111 | 112 | return user->p->equip[EQUIP_WEAPON]; 113 | } 114 | 115 | void get_base_stats(int *acc, int *dmg, int *elem, int *inflict) 116 | { 117 | *elem = 0xFF; 118 | *inflict = 0xFF; 119 | if (tech != 0xFF) { 120 | *acc = 100; 121 | *elem = NMEDATA[tech].spdata[SP_ELEM]; 122 | *dmg = NMEDATA[tech].spdata[SP_DAMAGE]; 123 | *inflict = NMEDATA[tech].spdata[SP_INFLICT]; 124 | } else { // Weapon 125 | int w = get_weapon(); 126 | if (w == 0xFF) { 127 | // No weapon 128 | // Damage is equal to 1/4 of str 129 | *acc = 90; 130 | *dmg = get_str(user->id + user->side * 2) / 4; 131 | *elem = 0xFF; 132 | *inflict = 0xFF; 133 | } else { 134 | *dmg = NMEDATA[w].eqatt[EQATT_DMG]; 135 | *acc = NMEDATA[w].eqatt[EQATT_PCT]; 136 | *elem = NMEDATA[w].eqatt[EQATT_STR]; 137 | *inflict = NMEDATA[w].eqatt[EQATT_WEAK]; 138 | } 139 | } 140 | 141 | } 142 | 143 | static void inflict_status(int dmg, int inflict) 144 | { 145 | if (inflict == 0xFF) return; 146 | 147 | if (get_acc(targ) == ACC_POISONRING && inflict <= 1) return; 148 | if (get_acc(targ) == ACC_AMULET && inflict <= 3) return; 149 | 150 | int chance = 50; 151 | // Positive status effects always work 152 | if (inflict >= 4 && inflict <= 7) chance = 100; 153 | // Non-damaging effects always work 154 | if (dmg == 0) chance = 100; 155 | 156 | int roll = (rand() % 100) + 1; 157 | if (roll <= chance) { 158 | // 5 rounds of status 159 | targ->p->status[inflict] = 5; 160 | } 161 | } 162 | static void non_damaging(int dmg, int inflict) { 163 | if (tech == 0xFF) return; // should not happen 164 | 165 | // Healing-type skills 166 | 167 | if (NMEDATA[tech].spdata[SP_CURE]) { 168 | // Remove negative statuses 169 | for (int i = 0; i < 4; i++) { 170 | targ->p->status[i] = 0; 171 | } 172 | } 173 | if (NMEDATA[tech].spdata[SP_CURE]) { 174 | // Remove negative statuses 175 | for (int i = 0; i < 4; i++) { 176 | targ->p->status[i] = 0; 177 | } 178 | } 179 | if (NMEDATA[tech].spdata[SP_REVIVE]) { 180 | if (targ->p->hp == 0) targ->p->hp = 1; 181 | } 182 | if (NMEDATA[tech].spdata[SP_HEAL]) { 183 | int heal_amt = dmg; 184 | int skill = get_mag(user->id + user->side * 2); 185 | 186 | heal_amt = heal_amt * (100 + skill) / 100; 187 | 188 | add_digits(cx, cy, -heal_amt); 189 | targ->p->hp = min(targ->p->hp + heal_amt, targ->p->maxhp); 190 | targ_hit = 1; 191 | mmEffect(SFX_HEAL); 192 | } 193 | inflict_status(dmg, inflict); 194 | 195 | 196 | } 197 | static void damage() 198 | { 199 | int acc, dmg, elem, inflict; 200 | get_base_stats(&acc, &dmg, &elem, &inflict); 201 | if (dmg == 0 || (tech != 0xFF && NMEDATA[tech].spdata[SP_HEAL])) { 202 | non_damaging(dmg, inflict); 203 | return; 204 | } 205 | // Damage increased by skill (str or mag) 206 | int skill; 207 | if (tech == 0xFF) skill = get_str(user->id + user->side * 2); 208 | else skill = get_mag(user->id + user->side * 2); 209 | 210 | dmg = dmg * (100 + skill) / 100; 211 | if (elem != 0xFF) { 212 | // Damage multiplied by weakness, reduced by strength 213 | if (targ->e) { 214 | if (targ->e->weak[elem] == 1) dmg = dmg * 25 / 10; 215 | if (targ->e->weak[elem] == -1) dmg = dmg * 4 / 10; 216 | } 217 | for (int i = EQUIP_BODY; i <= EQUIP_HEAD; i++) { 218 | int eq = targ->p->equip[i]; // Armour and helms 219 | if (eq != 0xFF) { 220 | if (NMEDATA[eq].eqatt[EQATT_WEAK] == elem) dmg = dmg * 25 / 10; 221 | if (NMEDATA[eq].eqatt[EQATT_STR] == elem) dmg = dmg * 4 / 10; 222 | } 223 | } 224 | } 225 | 226 | // Accuracy increased by agility 227 | int inacc = 100 - acc; 228 | inacc = inacc * 100 / (100 + get_agi(user->id + user->side * 2)); 229 | 230 | // Damage reduced by defense 231 | int def = get_def(id); 232 | 233 | // Add armour bonuses 234 | { 235 | for (int i = EQUIP_BODY; i <= EQUIP_HEAD; i++) { 236 | int eq = targ->p->equip[i]; // Armour and helms 237 | if (eq != 0xFF) { 238 | def += NMEDATA[eq].eqatt[EQATT_DMG]; 239 | inacc += NMEDATA[eq].eqatt[EQATT_PCT]; 240 | } 241 | } 242 | } 243 | 244 | dmg = dmg * 100 / (100 + def); 245 | 246 | if (targ->p->status[STATUS_WEAK] > 0) dmg *= 2; 247 | if (targ->p->status[STATUS_BARRIER] > 0) dmg /= 2; 248 | if (targ->defending) dmg /= 2; 249 | 250 | // Target agility 251 | inacc = inacc * (100 + get_agi(targ->id + targ->side * 2)) / 100; 252 | 253 | // Inviso 254 | if (targ->p->status[STATUS_INVISO] > 0) inacc = 100 - ((100 - inacc) / 2); 255 | 256 | // Did we hit? 257 | int roll = rand() % 100; 258 | if (roll >= inacc) { 259 | // Hit 260 | // Do we inflict a status effect? 261 | inflict_status(dmg, inflict); 262 | add_digits(cx, cy, dmg); 263 | targ->p->hp = max(targ->p->hp - dmg, 0); 264 | targ_hit = 1; 265 | mmEffect(SFX_MELEEHIT); 266 | } else { 267 | add_miss(cx, cy); 268 | } 269 | } 270 | 271 | static void redden_palette() 272 | { 273 | paleffect(8 + id, PALEFFECT_DAMAGE); 274 | /* 275 | volatile uint16_t *p = OBJ_PAL(8 + id); 276 | for (int i = 0; i < 16; i++) { 277 | *p = *p & 31; 278 | p++; 279 | } 280 | */ 281 | 282 | } 283 | 284 | static void target_healed() 285 | { 286 | if (!targ_hit) return; 287 | 288 | paleffect(8 + id, STATUS_REGEN); 289 | if (id >= 2) { 290 | uint8_t sp = 84 + id - 2; 291 | uint8_t shsp = 90 + id - 2; 292 | int xoff = RAND(-2, 2); 293 | int yoff = RAND(-2, 2); 294 | BFN_SET(obj_mem[sp].attr0, BFN_GET(obj_mem[sp].attr0, ATTR0_Y) + yoff, ATTR0_Y); 295 | BFN_SET(obj_mem[sp].attr1, BFN_GET(obj_mem[sp].attr1, ATTR1_X) + xoff, ATTR1_X); 296 | BFN_SET(obj_mem[shsp].attr1, BFN_GET(obj_mem[shsp].attr1, ATTR1_X) + xoff, ATTR1_X); 297 | } 298 | } 299 | 300 | static void target_hurt() 301 | { 302 | if (!targ_hit) return; 303 | 304 | redden_palette(); 305 | if (id >= 2) { 306 | uint8_t sp = 84 + id - 2; 307 | uint8_t shsp = 90 + id - 2; 308 | int xoff = RAND(-2, 2); 309 | int yoff = RAND(-2, 2); 310 | BFN_SET(obj_mem[sp].attr0, BFN_GET(obj_mem[sp].attr0, ATTR0_Y) + yoff, ATTR0_Y); 311 | BFN_SET(obj_mem[sp].attr1, BFN_GET(obj_mem[sp].attr1, ATTR1_X) + xoff, ATTR1_X); 312 | BFN_SET(obj_mem[shsp].attr1, BFN_GET(obj_mem[shsp].attr1, ATTR1_X) + xoff, ATTR1_X); 313 | } 314 | } 315 | 316 | static int plain_atk() 317 | { 318 | if (t == 0) { 319 | mmEffect(SFX_SWORD5); 320 | } 321 | if (t == 15) { 322 | damage(); 323 | } 324 | if (t < 30) { 325 | if (t >= 15 && t < 30) target_hurt(); 326 | ODRW(RAND(20, 27), 2, cx - 12 - 30 + (t * 2), cy - 12 - 30 + (t * 2), 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 327 | ODRW(RAND(20, 27), 2, cx - 4 - 30 + (t * 2), cy - 4 - 30 + (t * 2), 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 328 | ODRW(RAND(20, 27), 2, cx + 4 - 30 + (t * 2), cy + 4 - 30 + (t * 2), 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 329 | return 0; 330 | } else { 331 | return 1; 332 | } 333 | } 334 | 335 | static int tech_atk() 336 | { 337 | if (t == 0) { 338 | mmEffect(SFX_TECH); 339 | } 340 | if (t == 15) { 341 | damage(); 342 | } 343 | if (t < 30) { 344 | if (t >= 15 && t < 30) target_hurt(); 345 | ODRW(RAND(20, 26) + (t / 5), 1, cx + RAND(-30,30) - 4, cy + RAND(-30,30) - 4, 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 346 | ODRW(RAND(20, 26) + (t / 5), 1, cx + RAND(-30,30) - 4, cy + RAND(-30,30) - 4, 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 347 | ODRW(RAND(20, 26) + (t / 5), 1, cx + RAND(-30,30) - 4, cy + RAND(-30,30) - 4, 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 348 | return 0; 349 | } else { 350 | return 1; 351 | } 352 | } 353 | 354 | static int heal_atk() 355 | { 356 | if (t == 0) { 357 | mmEffect(SFX_CURE); 358 | } 359 | if (t == 15) { 360 | damage(); 361 | } 362 | if (t < 30) { 363 | if (t >= 15 && t < 30) target_healed(); 364 | ODRW(RAND(20, 26) + (t / 5), 1, cx + RAND(-30,30) - 4, cy + RAND(-30,30) - 4, 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 365 | ODRW(RAND(20, 26) + (t / 5), 1, cx + RAND(-30,30) - 4, cy + RAND(-30,30) - 4, 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 366 | ODRW(RAND(20, 26) + (t / 5), 1, cx + RAND(-30,30) - 4, cy + RAND(-30,30) - 4, 4, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 367 | return 0; 368 | } else { 369 | return 1; 370 | } 371 | } 372 | 373 | static int cont_atk() 374 | { 375 | if (anim_model == 0) return plain_atk(); 376 | else if (anim_model == 1) return tech_atk(); 377 | else if (anim_model == 2) return heal_atk(); 378 | else return plain_atk(); 379 | } 380 | 381 | static void draw_digits() 382 | { 383 | for (int i = 0; i < digits_n; i++) { 384 | if (digits[i].life > 0) { 385 | if (digits[i].digit == -1) { 386 | ODRW(14, 3, digits[i].x, digits[i].y + 10 - digits[i].life / 2, 1, ATTR0_WIDE, ATTR1_SIZE_16x8, 0); 387 | } else { 388 | ODRW(6+digits[i].digit, 2, digits[i].x, digits[i].y + 10 - digits[i].life / 2, digits[i].green ? 2 : 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 389 | } 390 | digits[i].life--; 391 | } 392 | } 393 | } 394 | 395 | void elem_col() 396 | { 397 | anim_model = 0; 398 | if (tech != 0xFF) anim_model = 1; 399 | 400 | int colcode = -1; 401 | int acc, dmg, elem, inflict; 402 | get_base_stats(&acc, &dmg, &elem, &inflict); 403 | switch (elem) { 404 | case 0: colcode = PALEFFECT_DAMAGE; break; 405 | case 1: colcode = STATUS_WEAK; break; 406 | case 2: colcode = STATUS_PARA; break; 407 | case 3: colcode = STATUS_INVISO; break; 408 | } 409 | 410 | int good = 0; 411 | if (tech != 0xFF) { 412 | if (NMEDATA[tech].spdata[SP_INFLICT] >= 4 && NMEDATA[tech].spdata[SP_INFLICT] <= 7) good = 1; 413 | if (NMEDATA[tech].spdata[SP_CURE] > 0) good = 1; 414 | if (NMEDATA[tech].spdata[SP_HEAL] > 0) good = 1; 415 | if (NMEDATA[tech].spdata[SP_REVIVE] > 0) good = 1; 416 | } 417 | if (good) { 418 | anim_model = 2; 419 | colcode = STATUS_POISON; 420 | } 421 | fast_copy(OBJ_PAL(4), btl_objpal_bin + (4 << 5) + (COLSPACE << 9), 32); 422 | paleffect(4, colcode); 423 | } 424 | 425 | int use_tech_indiv(int anim_timer_, int t_, struct actor *user_, struct actor *targ_, uint8_t tech_, uint8_t *sp_) 426 | { 427 | if (!digits) { 428 | digits = malloc(sizeof(digits[0]) * 64); 429 | memset(digits, 0, sizeof(digits[0]) * 64); 430 | } 431 | int new_tick = (anim_timer != anim_timer_); 432 | anim_timer = anim_timer_; 433 | t = t_; 434 | tech = tech_; 435 | sp = sp_; 436 | user = user_; 437 | targ = targ_; 438 | id = targ->id + (targ->side * 2); 439 | get_bounds(id, &x1, &y1, &x2, &y2); 440 | cx = (x1 + x2) / 2; 441 | cy = (y1 + y2) / 2; 442 | 443 | elem_col(); 444 | 445 | if (anim_timer == 0) { 446 | targ_hit = 0; 447 | digits_n = 0; 448 | } 449 | 450 | if (new_tick) draw_digits(); 451 | 452 | int r = cont_atk(); 453 | if (r == 1) { 454 | // Waiting for digits to finish displaying 455 | for (int i = 0; i < digits_n; i++) { 456 | if (digits[i].life > 0) return 0; 457 | } 458 | return 1; 459 | } 460 | 461 | return 0; 462 | } 463 | -------------------------------------------------------------------------------- /source/title.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "soundbank.h" 10 | #include "macros.h" 11 | #include "font.h" 12 | #include "fast_set.h" 13 | #include "ui.h" 14 | #include "pdata.h" 15 | #include "saves.h" 16 | #include "textfn.h" 17 | #include "btl_types.h" 18 | #include "textconsts.h" 19 | #include "title.h" 20 | #include "video.h" 21 | 22 | #include "btl_uimap_bin.h" 23 | #include "btl_charapal_bin.h" 24 | #include "btl_charagfx_bin.h" 25 | #include "btl_menuicons_bin.h" 26 | #include "btl_nums_bin.h" 27 | #include "btl_nmedata_bin.h" 28 | 29 | #include "btl_imsoftgfx_bin.h" 30 | #include "btl_imsoftpal_bin.h" 31 | #include "btl_skygfx_bin.h" 32 | #include "btl_skypal_bin.h" 33 | #include "btl_starsgfx_bin.h" 34 | #include "btl_starspal_bin.h" 35 | #include "btl_fingfx_bin.h" 36 | #include "btl_finpal_bin.h" 37 | #include "btl_titlegfx_bin.h" 38 | #include "btl_titlepal_bin.h" 39 | #include "btl_titleobjgfx_bin.h" 40 | #include "btl_titleobjpal_bin.h" 41 | #include "btl_titlemenugfx_bin.h" 42 | #include "btl_titlemenupal_bin.h" 43 | 44 | void title_video_init() 45 | { 46 | REG_DISPCNT = DCNT_MODE4 | DCNT_BG2 | DCNT_OBJ_1D | DCNT_OBJ; 47 | 48 | } 49 | 50 | void title_video_restore() 51 | { 52 | REG_DISPCNT = DCNT_MODE4 | DCNT_BG2 | DCNT_OBJ_2D | DCNT_OBJ; 53 | } 54 | 55 | void logo_anim() 56 | { 57 | title_video_init(); 58 | mmEffect(SFX_STATION02); 59 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_WHITE; 60 | 61 | load_palette(btl_skypal_bin, NULL); 62 | //fast_copy((volatile uint16_t *)MEM_PAL_BG, btl_skypal_bin + (COLSPACE << 9), 512); 63 | fast_copy(OBJ_PAL(0), btl_imsoftpal_bin + (COLSPACE << 9), 512); 64 | fast_copy(OBJ_CHR(0, 0), btl_imsoftgfx_bin, btl_imsoftgfx_bin_size); 65 | uint8_t sp; 66 | 67 | size_t sky_pos = (1024 - 160) * 240; 68 | /* 69 | for (uint32_t y = 0; y < 9; y++) { 70 | for (uint32_t x = 0; x < 8; x++) { 71 | OBJSET(sp, sp * 4, 0, x * 16 + 56, y * 16 + 8, 15, ATTR0_SQUARE | ATTR0_AFF, ATTR1_SIZE_16x16 | ATTR1_AFF_ID(x + y), 0); 72 | obj_hide(&obj_mem[sp]); 73 | sp++; 74 | } 75 | } 76 | */ 77 | 78 | VBlankIntrWait(); 79 | 80 | int fr = 0; 81 | 82 | for (;;) { 83 | if (INKEY_PRESSED & KEY_ANY) break; 84 | if (fr <= 256) 85 | REG_BLDY = (256 - fr) >> 4; 86 | if (fr > 64 && fr <= 308) { 87 | sp = 0; 88 | for (uint32_t y = 0; y < 9; y++) { 89 | for (uint32_t x = 0; x < 8; x++) { 90 | uint32_t i = x + y; 91 | int v = i * 12 + 128 - fr; 92 | if (v < 64) { 93 | OBJSET(sp, sp * 4, 0, x * 16 + 56, y * 16 + 8, 15 - (max(v + 16, 0) / 5), ATTR0_SQUARE | ATTR0_AFF, ATTR1_SIZE_16x16 | ATTR1_AFF_ID(x + y), 0); 94 | } 95 | sp++; 96 | } 97 | } 98 | for (int i = 0; i <= 15; i++) { 99 | int v = i * 12 + 128 - fr; 100 | if (v >= 0 && v < 64) { 101 | int scale = (v + 64) * 4; 102 | //AFFSET(i, scale, 0, 0, scale); 103 | obj_aff_rotscale(&obj_aff_mem[i], scale, scale, v * 1024); 104 | } 105 | } 106 | } 107 | if (fr == 308) { 108 | REG_BLDCNT = BLD_TOP(BLD_OBJ) | BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 109 | } 110 | if (fr >= 308 && fr <= 372) { 111 | int fade = clamp((fr - 308) / 4, 0, 16); 112 | REG_BLDALPHA = BLDA_BUILD(16-fade, fade); 113 | } 114 | if (fr == 373) { 115 | for (sp = 0; sp < 72; sp++) { 116 | obj_hide(&obj_mem[sp]); 117 | } 118 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 119 | } 120 | if (fr >= 373) { 121 | REG_BLDY = clamp((fr - 373) / 4, 0, 16); 122 | } 123 | fast_copy((volatile uint16_t *)MEM_VRAM_FRONT, &btl_skygfx_bin[sky_pos], 38400); 124 | VBlankIntrWait(); 125 | if (sky_pos == 0) break; 126 | sky_pos -= 240; 127 | fr++; 128 | if (fr >= 500) break; 129 | } 130 | } 131 | 132 | void draw_menu(int cur, uint16_t attr0) 133 | { 134 | uint8_t sp = 116; 135 | for (int i = 0; i < 4; i++) { 136 | int y = 102 + i * 14; 137 | if (i == 3) y = 149; 138 | int x = 0; 139 | if (cur == i) x += 16; 140 | OBJSET(sp, x, 2 * i, 82, y, 14, ATTR0_WIDE | attr0, ATTR1_SIZE_32x16, 0); 141 | sp++; 142 | OBJSET(sp, x+4, 2 * i, 82 + 32, y, 14, ATTR0_WIDE | attr0, ATTR1_SIZE_32x16, 0); 143 | sp++; 144 | OBJSET(sp, x+8, 2 * i, 82 + 64, y, 14, ATTR0_WIDE | attr0, ATTR1_SIZE_32x16, 0); 145 | sp++; 146 | } 147 | } 148 | void screenanim() 149 | { 150 | if (TICKER % 16 == 0) { 151 | int frame = (TICKER / 16) % 2; 152 | load_palette(btl_titlepal_bin + 4096 + (frame ? 2048 : 0), NULL); 153 | //fast_copy((volatile uint16_t *)MEM_PAL_BG, btl_titlepal_bin + 4096 + (frame ? 2048 : 0) + (COLSPACE << 9), 512); 154 | fast_copy((volatile uint16_t *)MEM_VRAM_FRONT, btl_titlegfx_bin + (240*240) + (240*200) + (frame ? 240*160 : 0), 38400); 155 | } 156 | } 157 | void fadeout(int ani) 158 | { 159 | int bl = (ani % 128) - 64; 160 | if (bl < 0) bl *= -1; 161 | bl = (bl / 8) + 7; 162 | 163 | while (bl >= 0) { 164 | REG_BLDALPHA = BLDA_BUILD(bl, 16 - bl); 165 | for (int j = 0; j < 8; j++) { 166 | screenanim(); 167 | VBlankIntrWait(); 168 | if (INKEY_PRESSED & KEY_ANY) break; 169 | } 170 | bl--; 171 | if (INKEY_PRESSED & KEY_ANY) break; 172 | } 173 | oam_init(obj_mem, 4); 174 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 175 | for (int i = 0; i < 16; i++) { 176 | REG_BLDY = i; 177 | for (int j = 0; j < 8; j++) { 178 | if (INKEY_PRESSED & KEY_ANY) break; 179 | mmSetModuleVolume(256 - ((i * 8 + j) * 2)); 180 | screenanim(); 181 | VBlankIntrWait(); 182 | } 183 | if (INKEY_PRESSED & KEY_ANY) break; 184 | } 185 | REG_BLDY = 16; 186 | CURRENT_MOD = -1; 187 | VBlankIntrWait(); 188 | mmSetModuleVolume(256); 189 | } 190 | void title_screen_play() 191 | { 192 | CURRENT_MOD = MOD_AIRSTRIKE; 193 | 194 | fast_copy(OBJ_PAL(15), btl_titleobjpal_bin + (COLSPACE << 5), 32); 195 | fast_copy(OBJ_PAL(14), btl_titlemenupal_bin + (COLSPACE << 5), 32); 196 | fast_copy(OBJ_CHR(0, 0), btl_titlemenugfx_bin, btl_titlemenugfx_bin_size); 197 | fast_copy(OBJ_CHR(0, 8), btl_titleobjgfx_bin, btl_titleobjgfx_bin_size); 198 | 199 | for (int t = 0; t < 2; t++) { 200 | 201 | 202 | size_t sky_pos = 0; 203 | int sky_y = 0; 204 | const uint8_t *titledata; 205 | const uint8_t *paldata; 206 | int sky_lim; 207 | if (t == 0) { 208 | sky_lim = 80; 209 | titledata = btl_titlegfx_bin; 210 | paldata = btl_titlepal_bin; 211 | } else { 212 | sky_lim = 40; 213 | titledata = btl_titlegfx_bin + (240 * 240); 214 | paldata = btl_titlepal_bin + 2048; 215 | } 216 | load_palette(paldata, NULL); 217 | //fast_copy((volatile uint16_t *)MEM_PAL_BG, paldata + (COLSPACE << 9), 512); 218 | int i; 219 | int x = t == 0 ? 2 : 4; 220 | for (i = 0; i <= 16; i++) { 221 | if (INKEY_PRESSED & KEY_ANY) break; 222 | REG_BLDY = 16 - i; 223 | fast_copy((volatile uint16_t *)MEM_VRAM_FRONT, &titledata[sky_pos], 38400); 224 | if (i % x == x - 1) { 225 | sky_pos += 240; 226 | sky_y++; 227 | } 228 | } 229 | while (sky_y <= sky_lim) { 230 | if (INKEY_PRESSED & KEY_ANY) break; 231 | fast_copy((volatile uint16_t *)MEM_VRAM_FRONT, &titledata[sky_pos], 38400); 232 | if (i % x == x - 1) { 233 | sky_pos += 240; 234 | sky_y++; 235 | } 236 | i++; 237 | int v = sky_lim - sky_y; 238 | if (v < 16) REG_BLDY = 16 - v; 239 | VBlankIntrWait(); 240 | } 241 | if (INKEY_PRESSED & KEY_ANY) break; 242 | } 243 | load_palette(btl_titlepal_bin + 4096, NULL); 244 | //fast_copy((volatile uint16_t *)MEM_PAL_BG, btl_titlepal_bin + 4096 + (COLSPACE << 9), 512); 245 | fast_copy((volatile uint16_t *)MEM_VRAM_FRONT, btl_titlegfx_bin + (240*240) + (240*200), 38400); 246 | for (int i = 0; i <= 16; i++) { 247 | REG_BLDY = 16 - i; 248 | screenanim(); 249 | VBlankIntrWait(); 250 | } 251 | 252 | REG_BLDCNT = BLD_TOP(BLD_OBJ) | BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 253 | 254 | for (int i = 0; i < 4; i++) { 255 | OBJSET(i, i * 8, 8, i * 64 + 6, 38, 15, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 256 | } 257 | for (int i = 0; i <= 16; i++) { 258 | REG_BLDALPHA = BLDA_BUILD(i, 16 - i); 259 | for (int j = 0; j < 8; j++) { 260 | if (INKEY_PRESSED & KEY_ANY) goto skip; 261 | screenanim(); 262 | VBlankIntrWait(); 263 | } 264 | if (INKEY_PRESSED & KEY_ANY) break; 265 | } 266 | 267 | REG_BLDCNT = BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 268 | 269 | for (int i = 0; i <= 16; i++) { 270 | REG_BLDALPHA = BLDA_BUILD(i, 16 - i); 271 | for (int j = 0; j < 8; j++) { 272 | screenanim(); 273 | draw_menu(-1, ATTR0_BLEND); 274 | VBlankIntrWait(); 275 | } 276 | } 277 | skip: 278 | REG_BLDCNT = BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 279 | for (int i = 0; i < 4; i++) { 280 | OBJSET(i, i * 8, 8, i * 64 + 6, 38, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 281 | } 282 | int cur = 0; 283 | int ani = 0; 284 | for (;;) { 285 | for (;;) { 286 | int bl = (ani % 128) - 64; 287 | if (bl < 0) bl *= -1; 288 | bl = (bl / 8) + 7; 289 | REG_BLDALPHA = BLDA_BUILD(bl, 16 - bl); 290 | ani++; 291 | screenanim(); 292 | draw_menu(cur, 0); 293 | VBlankIntrWait(); 294 | if (INKEY_PRESSED & KEY_UP) { 295 | cur = (cur + 2) % 3; 296 | mmEffect(SFX_CURSOR); 297 | } else if (INKEY_PRESSED & KEY_DOWN) { 298 | cur = (cur + 1) % 3; 299 | mmEffect(SFX_CURSOR); 300 | } else if (INKEY_PRESSED & KEY_ACCEPT) { 301 | mmEffect(SFX_SELECT); 302 | break; 303 | } 304 | } 305 | draw_menu(-1, 0); 306 | switch (cur) { 307 | case 0: 308 | fadeout(ani); 309 | return; 310 | case 1: 311 | oam_init(obj_mem, 4); 312 | oam_init(&obj_mem[116], 12); 313 | 314 | int r = status_load(); 315 | 316 | oam_init(obj_mem, 128); 317 | fast_copy(OBJ_CHR(0, 0), btl_titlemenugfx_bin, btl_titlemenugfx_bin_size); 318 | fast_copy(OBJ_CHR(0, 8), btl_titleobjgfx_bin, btl_titleobjgfx_bin_size); 319 | for (int i = 0; i < 4; i++) { 320 | OBJSET(i, i * 8, 8, i * 64 + 6, 38, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 321 | } 322 | 323 | if (r == 1) { 324 | fadeout(ani); 325 | return; 326 | } 327 | 328 | break; 329 | case 2: 330 | oam_init(obj_mem, 4); 331 | oam_init(&obj_mem[116], 12); 332 | 333 | status_config(); 334 | 335 | oam_init(obj_mem, 128); 336 | fast_copy(OBJ_CHR(0, 8), btl_titleobjgfx_bin, btl_titleobjgfx_bin_size); 337 | for (int i = 0; i < 4; i++) { 338 | OBJSET(i, i * 8, 8, i * 64 + 6, 38, 15, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_64x64, 0); 339 | } 340 | 341 | break; 342 | } 343 | 344 | } 345 | 346 | int b = 0; 347 | for (;;) { 348 | if (INKEY_PRESSED & KEY_ANY) break; 349 | int bl = (b % 128) - 64; 350 | if (bl < 0) bl *= -1; 351 | bl = bl / 8 + 8; 352 | REG_BLDALPHA = BLDA_BUILD(bl, 16 - bl); 353 | VBlankIntrWait(); 354 | b++; 355 | 356 | 357 | } 358 | } 359 | 360 | void logo_screen() 361 | { 362 | logo_anim(); 363 | mmEffectCancelAll(); 364 | title_video_restore(); 365 | oam_init(obj_mem, 72); 366 | VBlankIntrWait(); 367 | } 368 | 369 | void title_screen() 370 | { 371 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 372 | REG_BLDY = 16; 373 | title_screen_play(); 374 | title_video_restore(); 375 | oam_init(obj_mem, 4); 376 | oam_init(&obj_mem[116], 16); 377 | 378 | VBlankIntrWait(); 379 | } 380 | 381 | static uint32_t starscroll = 0; 382 | static void draw_stars() 383 | { 384 | fast_copy(VIDEO_BUFFER, &btl_starsgfx_bin[starscroll], 38400); 385 | starscroll = (starscroll + 240) % 230400; 386 | } 387 | 388 | void ending_credits() 389 | { 390 | CURRENT_MOD = MOD_MAHOPE; 391 | oam_init(obj_mem, 128); 392 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 393 | REG_BLDY = 16; 394 | load_palette(btl_starspal_bin, NULL); 395 | fast_copy(OBJ_CHR(0, 0), btl_uimap_bin + (7 << 13), 8192); 396 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (7 << 13), 8192); 397 | 398 | VBlankIntrWait(); 399 | for (int i = 0; i < 16; i++) { 400 | REG_BLDY = 15 - i; 401 | for (int j = 0; j < 8; j++) { 402 | draw_stars(); 403 | VBlankIntrWait(); 404 | flip_buffer(); 405 | } 406 | } 407 | REG_BLDCNT = BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 408 | int y = 0; 409 | int line = 0; 410 | while (line < CREDITS_NUM + 10) { 411 | int trrow; 412 | int v; 413 | if ((y % 30) < 15) { 414 | trrow = 9; 415 | v = (15 - y % 15); 416 | } else { 417 | trrow = 0; 418 | v = (y % 15); 419 | } 420 | REG_BLDALPHA = BLDA_BUILD(16 - v, v); 421 | for (int i = 0; i < 10; i++) { 422 | uint16_t attr0 = (i == trrow) ? (ATTR0_WIDE | ATTR0_BLEND) : ATTR0_WIDE; 423 | for (int j = 0; j < 7; j++) { 424 | OBJSET(i * 8 + j, j * 4, (i + line) % 10, j * 32 + 8, ((i * 30) + 29 - (y % 30)) / 2, 1, attr0, ATTR1_SIZE_32x8, 0); 425 | } 426 | } 427 | draw_stars(); 428 | y++; 429 | if (y % 30 == 0) { 430 | fast_copy(OBJ_CHR(0, (line % 10)), btl_uimap_bin + (7 << 13), 1024); 431 | if (line < CREDITS_NUM) { 432 | int x = (224 - text_width(CREDITS[line])) / 2; 433 | draw_text(x, (line % 10) * 8, CREDITS[line]); 434 | } 435 | line++; 436 | } 437 | VBlankIntrWait(); 438 | flip_buffer(); 439 | } 440 | 441 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 442 | REG_BLDY = 16; 443 | for (int i = 0; i <= 16; i++) { 444 | REG_BLDY = i; 445 | for (int j = 0; j < 16; j++) { 446 | mmSetModuleVolume(max(256 - ((i * 16 + j)), 0)); 447 | draw_stars(); 448 | VBlankIntrWait(); 449 | flip_buffer(); 450 | } 451 | } 452 | CURRENT_MOD = MOD_PIANO1A; 453 | load_palette(btl_finpal_bin, NULL); 454 | fast_copy(VIDEO_BUFFER, &btl_fingfx_bin[0], 38400); 455 | VBlankIntrWait(); 456 | flip_buffer(); 457 | for (int i = 0; i <= 16; i++) { 458 | REG_BLDY = 16 - i; 459 | for (int j = 0; j < 8; j++) { 460 | mmSetModuleVolume(min(((i * 8 + j)*2), 256)); 461 | VBlankIntrWait(); 462 | } 463 | } 464 | for (;;) { 465 | if (INKEY_PRESSED & KEY_ANY) break; 466 | VBlankIntrWait(); 467 | } 468 | for (int i = 0; i <= 16; i++) { 469 | REG_BLDY = i; 470 | for (int j = 0; j < 8; j++) { 471 | mmSetModuleVolume(max(256 - ((i * 8 + j)*2), 0)); 472 | VBlankIntrWait(); 473 | } 474 | } 475 | CURRENT_MOD = -1; 476 | mmSetModuleVolume(256); 477 | oam_init(obj_mem, 128); 478 | } 479 | -------------------------------------------------------------------------------- /source/renderer.c: -------------------------------------------------------------------------------- 1 | // TODO: I've got the transparency data being copied to trcol but have nothing using it yet 2 | 3 | #include "newrcd_bin.h" 4 | #include "polylist_bin.h" 5 | #include 6 | #include 7 | 8 | #include "renderer.h" 9 | #include "fast_set.h" 10 | 11 | #include 12 | #include 13 | 14 | uint8_t COLSPACE = 3; 15 | 16 | //static const struct rclist_bin *rclist = (const struct rclist_bin *)rcdlist_bin; 17 | //static const struct rc_bin *rcbins = (const struct rc_bin *)rcd_bin; 18 | //static const uint16_t *drawlist = ((const uint16_t *)drawlist_bin) + 13 * 2; 19 | //static const uint32_t *drawlist_idx = (const uint32_t *)drawlist_bin; 20 | static const uint16_t *polyinfo = (const uint16_t *)polylist_bin; 21 | 22 | static const uint16_t *newrcd = ((const uint16_t *)newrcd_bin); 23 | static const uint32_t *newrcd_lookup = ((const uint32_t *)newrcd_bin); 24 | 25 | static const uint8_t *textures_flats_bin; 26 | static const uint8_t *textures_walls_bin; 27 | static const uint8_t *textures_twalls_bin; 28 | 29 | uint8_t col_lut[256 * 32]; 30 | 31 | uint16_t poly_list[2300]; 32 | uint16_t *curr_poly_list; 33 | 34 | const uint8_t *palette_data; 35 | 36 | void load_palette(const uint8_t *palette_bin, const uint8_t *colmap_bin) 37 | { 38 | palette_data = palette_bin; 39 | fast_copy((volatile void *)MEM_PAL_BG, palette_data + (COLSPACE << 9), 512); 40 | if (colmap_bin) 41 | fast_copy(col_lut, colmap_bin, 8192); 42 | } 43 | void init_textures(const uint8_t *flats, const uint8_t *walls, const uint8_t *twalls) 44 | { 45 | textures_flats_bin = flats; 46 | textures_walls_bin = walls; 47 | textures_twalls_bin = twalls; 48 | } 49 | void update_colspace() 50 | { 51 | fast_copy((volatile void *)MEM_PAL_BG, palette_data + (COLSPACE << 9), 512); 52 | } 53 | 54 | __attribute__((section(".iwram"), long_call, target("arm"))) 55 | uint32_t render_begin(const struct lvl_tile *lvltiles, const void *lvl_vis, int px, int py, int pz, int pp, int pd) 56 | { 57 | const uint32_t *lvl_vis_lut = lvl_vis; 58 | const uint16_t *lvl_vis_data = lvl_vis; 59 | uint32_t lut_pos = lvl_vis_lut[pz * 256 + py * 16 + px]; 60 | //uint32_t lut_size = lvl_vis_lut[pz * 256 + py * 16 + px + 1] - lut_pos; 61 | 62 | lvl_vis_data = &lvl_vis_data[lut_pos]; 63 | LZ77UnCompWram(lvl_vis_data, poly_list); 64 | uint32_t poly_list_pos = poly_list[pd * PERSP_MAX + pp]; 65 | uint32_t poly_list_size = poly_list[pd * PERSP_MAX + pp + 1] - poly_list_pos; 66 | curr_poly_list = &poly_list[poly_list_pos]; 67 | 68 | return poly_list_size; 69 | } 70 | 71 | __attribute__((section(".iwram"), long_call, target("arm"))) 72 | static inline uint8_t remap(uint8_t v, uint8_t z) 73 | { 74 | //return v; 75 | return col_lut[((z >> 3) << 8) | v]; 76 | } 77 | 78 | __attribute__((section(".iwram"), long_call, target("arm"))) 79 | static inline uint32_t min(uint32_t x, uint32_t y) 80 | { 81 | //return x < y ? x : y; 82 | return y ^ ((x ^ y) & -(x < y)); 83 | } 84 | 85 | static uint32_t poly_i; 86 | static uint16_t poly_id, polydat; 87 | static uint32_t tex_dir, wx, wz, wy, vert, idx, texid, count, i, pos; 88 | static uint16_t xy, compressed_uv, pack, xytarg; 89 | static uint32_t uv, duv, uv2, duv2; 90 | static uint32_t jump_to; 91 | static uint8_t texcol[128]; 92 | static uint8_t trcol[128]; 93 | static uint8_t z, z2, c, j, texel, texel2; 94 | static const uint8_t *tex; 95 | 96 | 97 | __attribute__((section(".iwram"), long_call, target("arm"))) 98 | static inline void trcolu(char x, volatile uint16_t *scr) 99 | { 100 | //const uint8_t PURPLE = 184; 101 | //const uint8_t GREEN = 71; 102 | //const uint8_t CYAN = 112; 103 | //const uint8_t YELLOW = 232; 104 | //scr[0] = 184; // Purple 105 | //scr[1] = 71; // Green 106 | //scr[2] = 112; // Cyan 107 | //scr[3] = 232; // Yellow 108 | const uint8_t *trcol_1 = &trcol[0]; 109 | const uint8_t *trcol_2 = &trcol[64]; 110 | const uint8_t *texcol_1 = &texcol[0]; 111 | const uint8_t *texcol_2 = &texcol[64]; 112 | while (xy < xytarg) { 113 | uint32_t uvtarg; 114 | uint8_t trc1, trc2; 115 | switch (x) { 116 | case 'L': 117 | trc1 = trcol_1[(uv & 0x7E00) >> 9]; 118 | uv &= 0x7FFF7FFF; 119 | uvtarg = (uv & 0xFE00FE00) + (((uint32_t)(trc1 & 0x7F) + 1) << 9); 120 | uvtarg |= 0xFFFF0000; 121 | if (trc1 & 0x80) goto trcolu_i; 122 | trcolu_l: 123 | while ((uv & 0xFFFF) < (uvtarg & 0xFFFF) && (uv & 0xFFFF0000) < (uvtarg & 0xFFFF0000) && xy < xytarg) { 124 | scr[xy] = (scr[xy] & 0xFF00) | remap(texcol_1[(uv & 0x7E00) >> 9], z); 125 | //scr[xy] = (scr[xy] & 0xFF00) | PURPLE; 126 | uv = (uv + duv) & 0xFFFFFFFF; 127 | xy += SCR_W >> 1; 128 | } 129 | break; 130 | case 'R': 131 | trc2 = trcol_2[(uv & 0x7E000000) >> (9+16)]; 132 | uv &= 0x7FFF7FFF; 133 | uvtarg = (uv & 0xFE00FE00) + (((uint32_t)(trc2 & 0x7F) + 1) << (9+16)); 134 | uvtarg |= 0x0000FFFF; 135 | if (trc2 & 0x80) goto trcolu_i; 136 | trcolu_r: 137 | while ((uv & 0xFFFF) < (uvtarg & 0xFFFF) && (uv & 0xFFFF0000) < (uvtarg & 0xFFFF0000) && xy < xytarg) { 138 | scr[xy] = (scr[xy] & 0x00FF) | ((uint16_t)(remap(texcol_2[(uv & 0x7E000000) >> (9+16)], z2)) << 8); 139 | //scr[xy] = (scr[xy] & 0x00FF) | ((uint16_t)(YELLOW) << 8); 140 | uv = (uv + duv) & 0xFFFFFFFF; 141 | xy += SCR_W >> 1; 142 | } 143 | break; 144 | case 'D': 145 | trc1 = trcol_1[(uv & 0x7E00) >> 9]; 146 | trc2 = trcol_2[(uv & 0x7E000000) >> (9+16)]; 147 | uv &= 0x7FFF7FFF; 148 | 149 | uvtarg = (uv & 0xFE00FE00) + (((trc1 & 0x7F) + 1) << (9)) + (((trc2 & 0x7F) + 1) << (9+16)); 150 | 151 | if (trc1 & 0x80) { 152 | if (trc2 & 0x80) goto trcolu_i; 153 | else goto trcolu_r; 154 | } else if (trc2 & 0x80) goto trcolu_l; 155 | 156 | while ((uv & 0xFFFF) < (uvtarg & 0xFFFF) && (uv >> 16) < (uvtarg >> 16) && xy < xytarg) { 157 | scr[xy] = remap(texcol_1[(uv & 0x7E00) >> 9], z) | (remap(texcol_2[(uv & 0x7E000000) >> (9 + 16)], z2) << 8); 158 | 159 | xy += SCR_W >> 1; 160 | uv = (uv + duv) & 0xFFFFFFFF; 161 | } 162 | break; 163 | case 'I': 164 | uvtarg = 0; 165 | trcolu_i: 166 | while ((uv & 0xFFFF) < (uvtarg & 0xFFFF) && (uv >> 16) < (uvtarg >> 16) && xy < xytarg) { 167 | uv = (uv + duv) & 0xFFFFFFFF; 168 | xy += SCR_W >> 1; 169 | } 170 | break; 171 | } 172 | } 173 | } 174 | 175 | __attribute__((section(".iwram"), long_call, target("arm"))) 176 | uint32_t render_draw(const struct lvl_tile *lvltiles, volatile uint16_t *scr, uint32_t px, uint32_t py, uint32_t pz, uint32_t persp, uint32_t pd, uint32_t polylist_n, uint32_t lim) 177 | { 178 | /* 179 | uint32_t poly_i; 180 | uint16_t poly_id, polydat; 181 | uint32_t tex_dir, wx, wz, wy, vert, idx, texid, count, i, pos; 182 | uint16_t xy, compressed_uv, pack, xytarg; 183 | uint32_t uv, duv, uv2, duv2; 184 | uint32_t jump_to; 185 | uint8_t texcol[128]; 186 | uint8_t trcol[128]; 187 | uint8_t z, z2, c, j, texel, texel2, trxel, trxel2; 188 | const uint8_t *tex; 189 | */ 190 | for (poly_i = 0; poly_i < polylist_n; poly_i++) { 191 | poly_id = curr_poly_list[poly_i]; 192 | polydat = polyinfo[polyinfo[persp] + poly_id]; 193 | 194 | tex_dir = ((polydat & 0xE000) >> 13); 195 | wx = ((polydat & 0x1E00) >> 9); 196 | wz = ((polydat & 0x01E0) >> 5); 197 | wy = ((polydat & 0x001E) >> 1); 198 | vert = ((polydat & 0x0001) >> 0); 199 | 200 | if (tex_dir < 4) { 201 | tex_dir = (tex_dir + pd) & 3; 202 | } 203 | 204 | idx = ((pz - wz) & 0xF) << 8; 205 | switch (pd) { 206 | case DIR_N: 207 | default: 208 | idx |= ((px + wx) & 0xF); 209 | idx |= ((py - wy) & 0xF) << 4; 210 | break; 211 | case DIR_S: 212 | idx |= ((px - wx) & 0xF); 213 | idx |= ((py + wy) & 0xF) << 4; 214 | break; 215 | case DIR_E: 216 | idx |= ((px + wy) & 0xF); 217 | idx |= ((py + wx) & 0xF) << 4; 218 | break; 219 | case DIR_W: 220 | idx |= ((px - wy) & 0xF); 221 | idx |= ((py - wx) & 0xF) << 4; 222 | break; 223 | } 224 | texid = lvltiles[idx].texs[tex_dir]; 225 | 226 | pos = newrcd_lookup[persp]; 227 | pos += newrcd[pos + poly_id] * 4; 228 | 229 | //scr[((uint32_t)texid) % 19200] = 10000; 230 | //scr[((uint32_t)poly_id) % 19200] = 10000; 231 | //continue; 232 | 233 | if (!vert) { // rows 234 | if (tex_dir == DIR_D) 235 | tex = &textures_flats_bin[TEX_W * TEX_H * ((texid - 1) * 4 + pd)]; 236 | else 237 | tex = &textures_flats_bin[TEX_W * TEX_H * ((texid - 1) * 4 + 3 - pd)]; 238 | count = newrcd[pos++]; // lp_count 239 | for (i = 0; i < count; i++) { 240 | xy = newrcd[pos++]; 241 | compressed_uv = newrcd[pos++]; 242 | pack = newrcd[pos++]; 243 | z = pack & 0xFF; 244 | scr[xy] = (scr[xy] & 0xFF00) | remap(tex[compressed_uv], z); 245 | } 246 | 247 | count = newrcd[pos++]; // rp_count 248 | for (i = 0; i < count; i++) { 249 | xy = newrcd[pos++]; 250 | compressed_uv = newrcd[pos++]; 251 | pack = newrcd[pos++]; 252 | z = pack & 0xFF; 253 | scr[xy] = (scr[xy] & 0x00FF) | (remap(tex[compressed_uv], z) << 8); 254 | } 255 | 256 | count = newrcd[pos++]; // dp_count 257 | for (i = 0; i < count; i++) { 258 | xy = newrcd[pos++]; 259 | pack = newrcd[pos++]; 260 | z = pack & 0xFF; 261 | c = (pack & 0xFF00) >> 8; 262 | uv = newrcd[pos++]; 263 | uv |= (newrcd[pos++]) << 16; 264 | duv = newrcd[pos++]; 265 | duv |= (newrcd[pos++]) << 16; 266 | 267 | for (j = 0; j < c; j++) { 268 | texel = tex[((uv & 0x7E000000) >> 25) * TEX_W + ((uv & 0x7E00) >> 9)]; 269 | uv = (uv + duv) & 0x7FFF7FFF; 270 | texel2 = tex[((uv & 0x7E000000) >> 25) * TEX_W + ((uv & 0x7E00) >> 9)]; 271 | uv = (uv + duv) & 0x7FFF7FFF; 272 | scr[xy] = remap(texel, z) | (remap(texel2, z) << 8); 273 | xy++; 274 | } 275 | } 276 | 277 | } else { // cols 278 | if (texid < 128) { 279 | tex = &textures_walls_bin[TEX_W * TEX_H * (texid - 1)]; 280 | wall_solid: 281 | 282 | count = newrcd[pos++]; // lp_count 283 | for (i = 0; i < count; i++) { 284 | xy = newrcd[pos++]; 285 | pack = newrcd[pos++]; 286 | z = pack & 0xFF; 287 | c = (pack & 0xFF00) >> 8; 288 | uv = newrcd[pos++]; 289 | uv |= (newrcd[pos++]) << 16; 290 | duv = newrcd[pos++]; 291 | fast_copy_texcol(texcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W]); 292 | for (j = 0; j < c; j++) { 293 | scr[xy] = (scr[xy] & 0xFF00) | remap(texcol[(uv & 0x7E00) >> 9], z); 294 | uv += duv; 295 | xy += SCR_W >> 1; 296 | } 297 | } 298 | 299 | count = newrcd[pos++]; // rp_count 300 | for (i = 0; i < count; i++) { 301 | xy = newrcd[pos++]; 302 | pack = newrcd[pos++]; 303 | z = pack & 0xFF; 304 | c = (pack & 0xFF00) >> 8; 305 | uv = newrcd[pos++]; 306 | uv |= (newrcd[pos++]) << 16; 307 | duv = newrcd[pos++]; 308 | 309 | fast_copy_texcol(texcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W]); 310 | for (j = 0; j < c; j++) { 311 | scr[xy] = (scr[xy] & 0x00FF) | ((uint16_t)(remap(texcol[(uv & 0x7E00) >> 9], z)) << 8); 312 | uv += duv; 313 | xy += SCR_W >> 1; 314 | } 315 | } 316 | 317 | count = newrcd[pos++]; // dp_count 318 | for (i = 0; i < count; i++) { 319 | xy = newrcd[pos++]; 320 | pack = newrcd[pos++]; 321 | z = pack & 0xFF; 322 | z2 = (pack & 0xFF00) >> 8; 323 | uv = newrcd[pos++]; 324 | uv |= (newrcd[pos++]) << 16; 325 | uv2 = newrcd[pos++]; 326 | uv2 |= (newrcd[pos++]) << 16; 327 | 328 | duv = newrcd[pos++]; 329 | duv2 = newrcd[pos++]; 330 | 331 | c = newrcd[pos++]; 332 | fast_copy_texcols(texcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W], &tex[((uv2 & 0x7E000000) >> 25) * TEX_W]); 333 | const uint8_t *texcol_1 = &texcol[0]; 334 | const uint8_t *texcol_2 = &texcol[64]; 335 | 336 | for (j = 0; j < c; j++) { 337 | texel = texcol_1[(uv & 0x7E00) >> 9]; 338 | texel2 = texcol_2[(uv2 & 0x7E00) >> 9]; 339 | 340 | scr[xy] = remap(texel, z) | (remap(texel2, z2) << 8); 341 | uv = (uv + duv) & 0x7FFF7FFF; 342 | uv2 = (uv2 + duv2) & 0x7FFF7FFF; 343 | xy += SCR_W >> 1; 344 | } 345 | } 346 | } else { // Transparent wall textures 347 | if (texid == 128) continue; 348 | tex = &textures_twalls_bin[TEX_SIZE * ((texid - 129) << 1)]; 349 | if (tex[TEX_SIZE] == 127) goto wall_solid; 350 | count = newrcd[pos++]; // lp_count 351 | for (i = 0; i < count; i++) { 352 | xy = newrcd[pos++]; 353 | pack = newrcd[pos++]; 354 | z = pack & 0xFF; 355 | xytarg = ((pack & 0xFF00) >> 8) * (SCR_W >> 1) + xy; 356 | uv = newrcd[pos++]; 357 | uv |= (newrcd[pos++]) << 16; 358 | duv = newrcd[pos++]; 359 | jump_to = 0; 360 | fast_copy_texcol(texcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W]); 361 | fast_copy_texcol(trcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W + TEX_SIZE]); 362 | uv = (uv & 0x7FFF); 363 | trcolu('L', scr); 364 | } 365 | 366 | count = newrcd[pos++]; // rp_count 367 | for (i = 0; i < count; i++) { 368 | xy = newrcd[pos++]; 369 | pack = newrcd[pos++]; 370 | z2 = pack & 0xFF; 371 | xytarg = ((pack & 0xFF00) >> 8) * (SCR_W >> 1) + xy; 372 | uv2 = newrcd[pos++]; 373 | uv2 |= (newrcd[pos++]) << 16; 374 | duv2 = newrcd[pos++]; 375 | jump_to = 0; 376 | fast_copy_texcol(&texcol[64], &tex[((uv2 & 0x7E000000) >> 25) * TEX_W]); 377 | fast_copy_texcol(&trcol[64], &tex[((uv2 & 0x7E000000) >> 25) * TEX_W + TEX_SIZE]); 378 | uv = ((uv2 & 0x7FFF) << 16); 379 | duv = (duv2 << 16); 380 | trcolu('R', scr); 381 | } 382 | 383 | count = newrcd[pos++]; // dp_count 384 | for (i = 0; i < count; i++) { 385 | xy = newrcd[pos++]; 386 | pack = newrcd[pos++]; 387 | z = pack & 0xFF; 388 | z2 = (pack & 0xFF00) >> 8; 389 | uv = newrcd[pos++]; 390 | uv |= (newrcd[pos++]) << 16; 391 | uv2 = newrcd[pos++]; 392 | uv2 |= (newrcd[pos++]) << 16; 393 | 394 | duv = newrcd[pos++]; 395 | duv2 = newrcd[pos++]; 396 | 397 | xytarg = newrcd[pos++] * (SCR_W >> 1) + xy; 398 | 399 | fast_copy_texcols(texcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W], &tex[((uv2 & 0x7E000000) >> 25) * TEX_W]); 400 | fast_copy_texcols(trcol, &tex[((uv & 0x7E000000) >> 25) * TEX_W + TEX_SIZE], &tex[((uv2 & 0x7E000000) >> 25) * TEX_W + TEX_SIZE]); 401 | uv = (uv & 0x7FFF) | ((uv2 & 0x7FFF) << 16); 402 | duv = duv | (duv2 << 16); 403 | trcolu('D', scr); 404 | } 405 | } 406 | } 407 | } 408 | return 0; 409 | } 410 | -------------------------------------------------------------------------------- /source/gameplay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "fast_set.h" 4 | #include "pdata.h" 5 | #include "gameplay.h" 6 | #include "maps.h" 7 | #include "soundbank.h" 8 | #include "renderer.h" 9 | #include "video.h" 10 | #include "battle.h" 11 | #include "ui.h" 12 | #include "macros.h" 13 | #include "plot.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define MOVE_WAIT 6 23 | 24 | static int skip_encounters = 0; 25 | static int show_loc = 0; 26 | 27 | struct lvl_tile *lvl_bin = NULL; 28 | const void *lvl_vis_bin; 29 | const uint8_t *lvl_backdrop; 30 | static int GAMEPLAY_MUS = -1; 31 | 32 | void loadMap() { 33 | struct mapinfo m = MAPS[gs.map]; 34 | 35 | if (lvl_bin == NULL) lvl_bin = malloc(sizeof(struct lvl_tile) * 4096); 36 | fast_copy(lvl_bin, m.map, sizeof(struct lvl_tile) * 4096); 37 | 38 | lvl_vis_bin = m.vis; 39 | lvl_backdrop = m.backdrop; 40 | load_palette(m.palette, m.colmap); 41 | init_textures(m.flats, m.walls, m.twalls); 42 | } 43 | 44 | void drawBackdrop(int persp) { 45 | if (((uint16_t *)lvl_backdrop)[0] == 240) { 46 | fast_copy(VIDEO_BUFFER, lvl_backdrop, 38400); 47 | } else { 48 | volatile uint16_t *scrptr_p = VIDEO_BUFFER; 49 | const uint8_t *backdrop_p = &lvl_backdrop[4 + ((gs.d * 3) + (persp == PERSP_ROT1 ? 1 : 0) + (persp == PERSP_ROT2 ? 2 : 0)) * 80]; 50 | 51 | for (int y = 0; y < 160; y++) { 52 | fast_copy(scrptr_p, backdrop_p, 224); // 16 bytes left 53 | ((volatile uint32_t *)scrptr_p)[56] = ((const uint32_t *)backdrop_p)[56]; 54 | ((volatile uint32_t *)scrptr_p)[57] = ((const uint32_t *)backdrop_p)[57]; 55 | ((volatile uint32_t *)scrptr_p)[58] = ((const uint32_t *)backdrop_p)[58]; 56 | ((volatile uint32_t *)scrptr_p)[59] = ((const uint32_t *)backdrop_p)[59]; 57 | scrptr_p += 120; 58 | backdrop_p += 1200; 59 | } 60 | } 61 | } 62 | 63 | void drawInstant(int persp) { 64 | drawBackdrop(persp); 65 | 66 | uint32_t polylist_n = render_begin(lvl_bin, lvl_vis_bin, gs.x, gs.y, gs.z, persp, gs.d); 67 | render_draw(lvl_bin, VIDEO_BUFFER, gs.x, gs.y, gs.z, persp, gs.d, polylist_n, 9999); 68 | VBlankIntrWait(); 69 | flip_buffer(); 70 | } 71 | 72 | void drawMovingFrame(int persp) { 73 | int waitfor = TICKER + MOVE_WAIT; 74 | drawInstant(persp); 75 | while (TICKER < waitfor) { 76 | VBlankIntrWait(); 77 | } 78 | } 79 | 80 | int getDirX(uint8_t dir) { 81 | switch (dir) { 82 | case DIR_W: return -1; break; 83 | case DIR_E: return 1; break; 84 | } 85 | return 0; 86 | } 87 | int getDirY(uint8_t dir) { 88 | switch (dir) { 89 | case DIR_N: return -1; break; 90 | case DIR_S: return 1; break; 91 | } 92 | return 0; 93 | } 94 | int getDirZ(uint8_t dir) { 95 | switch (dir) { 96 | case DIR_U: return 1; break; 97 | case DIR_D: return -1; break; 98 | } 99 | return 0; 100 | } 101 | int isLadder(uint8_t tex) { 102 | if (gs.map == 0) 103 | if (tex == 14 || tex == 23 || tex == 24 || tex == 26 || tex == 30 || tex == 34 || tex == 35) return 1; 104 | if (gs.map == 1) 105 | if (tex == 5 || tex == 7 || tex == 11 || tex == 14) return 1; 106 | return 0; 107 | } 108 | int isRestoreTile(uint8_t tex) { 109 | if (gs.map == 0) 110 | if (tex == 7 || tex == 8 || tex == 10 || tex == 17 || tex == 37) return 1; 111 | if (gs.map == 1) 112 | if (tex == 10) return 1; 113 | return 0; 114 | } 115 | int isOutsideDoor(uint8_t tex) { 116 | if (gs.map == 0) 117 | if (tex == 25 || tex == 37 || tex == 38) return 1; 118 | if (gs.map == 1) 119 | if (tex == 8 || tex == 16 || tex == 17 || tex == 18) return 1; 120 | return 0; 121 | } 122 | int isDoor(uint8_t tex) { 123 | if (gs.map == 0) 124 | if (tex >= 133 && tex <= 140) return 1; 125 | return 0; 126 | } 127 | int isSwitch(uint8_t tex) { 128 | if (gs.map == 0) 129 | if (tex == 5 || tex == 6 || tex == 8 || tex == 9 || tex == 11 || tex == 12) return 1; 130 | return 0; 131 | } 132 | int isPlaque(uint8_t tex) { 133 | if (gs.map == 0) 134 | if (tex == 15 || tex == 16 || tex == 18 || tex == 36) return 1; 135 | return 0; 136 | } 137 | uint8_t toggleSwitch(uint8_t tex) { 138 | int switch_base; 139 | if (tex == 5 || tex == 6) switch_base = 5; 140 | if (tex == 8 || tex == 9) switch_base = 8; 141 | if (tex == 11 || tex == 12) switch_base = 11; 142 | 143 | int swplot = -1; 144 | 145 | if (gs.plot[PLOT_BASE] >= 1 && gs.plot[PLOT_BASE] <= 3 && gs.x == 6 && gs.y == 13 && gs.z == 0) swplot = 1; 146 | if (gs.plot[PLOT_BASE] >= 3 && gs.plot[PLOT_BASE] <= 5 && gs.x == 6 && gs.y == 7 && gs.z == 3) swplot = 3; 147 | if (gs.plot[PLOT_BASE] >= 6 && gs.plot[PLOT_BASE] <= 8 && gs.x == 9 && gs.y == 6 && gs.z == 3) swplot = 6; 148 | 149 | int offset = tex - switch_base; 150 | 151 | if (swplot != -1) { 152 | if (offset == 1) { 153 | // Enable switch 154 | gs.plot[PLOT_BASE] = swplot + 2; 155 | } else { 156 | // Disable switch 157 | gs.plot[PLOT_BASE] = swplot + 1; 158 | } 159 | } 160 | 161 | return switch_base + (offset ^ 1); 162 | 163 | 164 | switch (tex) { 165 | case 5: return 6; 166 | case 6: return 5; 167 | case 8: return 9; 168 | case 9: return 8; 169 | case 11: return 12; 170 | case 12: return 11; 171 | } 172 | return 0xFF; 173 | } 174 | 175 | void moveDir(uint8_t dir) { 176 | gs.x += getDirX(dir); 177 | gs.y += getDirY(dir); 178 | gs.z += getDirZ(dir); 179 | } 180 | uint8_t getTexDirFrom(uint16_t x, uint16_t y, uint16_t z, uint8_t dir) { 181 | return lvl_bin[(z << 8) | (y << 4) | (x)].texs[dir]; 182 | } 183 | uint8_t getTexDir(uint8_t dir) { 184 | return getTexDirFrom(gs.x, gs.y, gs.z, dir); 185 | } 186 | int isBlocked(uint8_t dir) { 187 | if (lvl_bin[(gs.z << 8) | (gs.y << 4) | (gs.x)].flags & (128 >> dir)) { 188 | return 1; 189 | } 190 | return 0; 191 | } 192 | 193 | int phaseForward() { 194 | gs.climbing = 0; 195 | drawMovingFrame(PERSP_STEP1); 196 | drawMovingFrame(PERSP_STEP2); 197 | moveDir(gs.d); 198 | drawMovingFrame(PERSP_FWD); 199 | return 1; 200 | } 201 | 202 | int moveForward() { 203 | uint8_t dir = gs.d; 204 | if (!isBlocked(dir)) { 205 | gs.climbing = 0; 206 | drawMovingFrame(PERSP_STEP1); 207 | drawMovingFrame(PERSP_STEP2); 208 | moveDir(dir); 209 | drawMovingFrame(PERSP_FWD); 210 | return 1; 211 | } else { 212 | if (isLadder(getTexDir(dir))) { 213 | if (!isBlocked(DIR_U)) { 214 | gs.climbing = 1; 215 | mmEffect(SFX_CLIMB); 216 | drawMovingFrame(PERSP_UP1); 217 | drawMovingFrame(PERSP_UP2); 218 | moveDir(DIR_U); 219 | drawMovingFrame(PERSP_FWD); 220 | return 1; 221 | } 222 | } 223 | } 224 | return 0; 225 | } 226 | 227 | int moveBackward() { 228 | // Special check in case we are on a ladder 229 | if (gs.climbing) { 230 | if (isLadder(getTexDir(gs.d)) || isLadder(getTexDirFrom(gs.x, gs.y, gs.z-1, gs.d))) { 231 | if (!isBlocked(DIR_D)) { 232 | moveDir(DIR_D); 233 | mmEffect(SFX_CLIMB); 234 | drawMovingFrame(PERSP_UP2); 235 | drawMovingFrame(PERSP_UP1); 236 | drawMovingFrame(PERSP_FWD); 237 | return 1; 238 | } 239 | } 240 | } 241 | 242 | uint8_t dir = (gs.d + 2) & 3; 243 | if (!isBlocked(dir)) { 244 | gs.climbing = 0; 245 | moveDir(dir); 246 | drawMovingFrame(PERSP_STEP2); 247 | drawMovingFrame(PERSP_STEP1); 248 | drawMovingFrame(PERSP_FWD); 249 | return 1; 250 | } 251 | return 0; 252 | } 253 | 254 | int strafeRight() { 255 | uint8_t dir = (gs.d + 1) & 3; 256 | if (!isBlocked(dir)) { 257 | gs.climbing = 0; 258 | drawMovingFrame(PERSP_STRAFE1); 259 | drawMovingFrame(PERSP_STRAFE2); 260 | moveDir(dir); 261 | drawMovingFrame(PERSP_FWD); 262 | return 1; 263 | } 264 | return 0; 265 | } 266 | 267 | int strafeLeft() { 268 | uint8_t dir = (gs.d - 1) & 3; 269 | if (!isBlocked(dir)) { 270 | gs.climbing = 0; 271 | moveDir(dir); 272 | drawMovingFrame(PERSP_STRAFE2); 273 | drawMovingFrame(PERSP_STRAFE1); 274 | drawMovingFrame(PERSP_FWD); 275 | return 1; 276 | } 277 | return 0; 278 | } 279 | 280 | int turnRight() { 281 | drawMovingFrame(PERSP_ROT1); 282 | drawMovingFrame(PERSP_ROT2); 283 | gs.d = (gs.d + 1) & 3; 284 | drawMovingFrame(PERSP_FWD); 285 | 286 | return 0; 287 | } 288 | 289 | int turnLeft() { 290 | gs.d = (gs.d - 1) & 3; 291 | drawMovingFrame(PERSP_ROT2); 292 | drawMovingFrame(PERSP_ROT1); 293 | drawMovingFrame(PERSP_FWD); 294 | 295 | return 0; 296 | } 297 | 298 | void fall() { 299 | moveDir(DIR_D); 300 | drawMovingFrame(PERSP_UP2); 301 | drawMovingFrame(PERSP_UP1); 302 | drawMovingFrame(PERSP_FWD); 303 | if (isBlocked(DIR_D)) { 304 | mmEffect(SFX_FALL); 305 | } else if (isLadder(getTexDir(gs.d))) { 306 | mmEffect(SFX_CATCHLADDER); 307 | gs.climbing = 1; 308 | } 309 | } 310 | 311 | void game_over() 312 | { 313 | CURRENT_MOD = MOD_TEMP9A; 314 | show_message(-1, "Your inheritor's quest has come to an end."); 315 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 316 | for (int i = 0; i <= 16; i++) { 317 | REG_BLDY = i; 318 | VBlankIntrWait(); 319 | VBlankIntrWait(); 320 | VBlankIntrWait(); 321 | VBlankIntrWait(); 322 | } 323 | CURRENT_MOD = -1; 324 | } 325 | 326 | void victory() 327 | { 328 | mmEffect(SFX_VICTORY); 329 | const char *msg = "You were victorious in combat!"; 330 | if (BATTLE_SPOILS[0] != 0xFF) { 331 | msg = "You were victorious in combat! You have obtained the following:"; 332 | } 333 | 334 | show_message(-1, msg); 335 | int got_eq = 0; 336 | int got_gem = 0; 337 | for (int i = 0; i < 6; i++) { 338 | uint8_t ico = BATTLE_SPOILS[i]; 339 | if (ico != 0xFF) { 340 | if (ico >= 80) { // equipment 341 | gs.equip_qty[ico - 80]++; 342 | if (ico - 80 < 20) got_eq = 1; 343 | } else if (ico >= 40) { // soulstone 344 | gs.gem_qty[ico - 40]++; 345 | got_gem = 1; 346 | } 347 | } 348 | BATTLE_SPOILS[i] = 0xFF; 349 | } 350 | 351 | if (got_gem && !(gs.plot[PLOT_TUT] & TUTORIAL_FIRSTGEM)) { 352 | gs.plot[PLOT_TUT] |= TUTORIAL_FIRSTGEM; 353 | 354 | show_message(1, "Is this...?"); 355 | show_message(0, "Correct, this is what we came here for. The inert form of these spirit creatures; spirit crystals."); 356 | show_message(1, "Fantastic; we can use these to gain some of the powers of these spirit creatures. They will also be invaluable treasures to bring back to the clan."); 357 | show_message(-1, "(Press START to open up the menu and select the second option to equip your party with spirit crystals. Spirit crystals improve your stats and give you access to more techniques.)"); 358 | } 359 | if (got_eq && !(gs.plot[PLOT_TUT] & TUTORIAL_FIRSTEQUIP)) { 360 | 361 | gs.plot[PLOT_TUT] |= TUTORIAL_FIRSTEQUIP; 362 | show_message(1, "That creature seems to have dropped something..."); 363 | show_message(0, "Yes, this is a fantastic find. The latent Qi in this place has coalesced into godrelics. Powerful equipment that will help us survive in here."); 364 | show_message(1, "Indeed, this is a fortunate discovery. We should equip it at once."); 365 | show_message(-1, "(Press START to open up the menu and select the first option to equip your party with godrelics. Godrelics can improve your combat potential, reduce the damage you take and more.)"); 366 | } 367 | 368 | mmEffectCancelAll(); 369 | } 370 | 371 | int openDoor(uint8_t dir) 372 | { 373 | // Is this door locked? 374 | int plotdoor = -1; 375 | if ((gs.x == 6) && (gs.y == 10) && (gs.z == 2)) plotdoor = 1; 376 | if ((gs.x == 5) && (gs.y == 11) && (gs.z == 3)) plotdoor = 3; 377 | if ((gs.x == 8) && (gs.y == 8) && (gs.z == 5)) plotdoor = 6; 378 | if (gs.plot[PLOT_BASE] == plotdoor || gs.plot[PLOT_BASE] == plotdoor + 1) { 379 | mmEffect(SFX_LOCKED); 380 | if (gs.plot[PLOT_BASE] == 1 || gs.plot[PLOT_BASE] == 3 || gs.plot[PLOT_BASE] == 6) { 381 | for (int i = 0; i < 16; i++) { 382 | VBlankIntrWait(); 383 | } 384 | } 385 | switch (gs.plot[PLOT_BASE]) { 386 | case 1: 387 | show_message(0, "A locked door..."); 388 | show_message(1, "We should look around and see if there is something that unlocks this. The antecedents were very fond of their elaborate mechanical contraptions and devices."); 389 | gs.plot[PLOT_BASE]++; 390 | break; 391 | case 3: 392 | show_message(0, "Looks like another locked door. We should search for another switch or button, see if something opens this."); 393 | gs.plot[PLOT_BASE]++; 394 | break; 395 | case 6: 396 | show_message(1, "Locked again..."); 397 | show_message(0, "This is starting to get old. Did you see anything on the wall that we might have missed on the way here?"); 398 | show_message(1, "I don't think so, but we should certainly look around."); 399 | gs.plot[PLOT_BASE]++; 400 | break; 401 | default: 402 | break; 403 | } 404 | 405 | return 0; 406 | } 407 | 408 | mmEffect(SFX_DOOR); 409 | int x = gs.x; 410 | int y = gs.y; 411 | int z = gs.z; 412 | lvl_bin[(z << 8) | (y << 4) | (x)].texs[dir] += 8; 413 | lvl_bin[(z << 8) | (y << 4) | (x)].flags &= ~(128 >> dir); 414 | 415 | drawInstant(PERSP_FWD); 416 | for (int i = 0; i <= 16; i++) { 417 | VBlankIntrWait(); 418 | } 419 | 420 | moveForward(); 421 | lvl_bin[(z << 8) | (y << 4) | (x)].texs[dir] -= 8; 422 | lvl_bin[(z << 8) | (y << 4) | (x)].flags |= (128 >> dir); 423 | 424 | return 1; 425 | } 426 | 427 | int openOutsideDoor(uint8_t dir) 428 | { 429 | mmEffect(SFX_DOOR); 430 | 431 | drawInstant(PERSP_STEP1); 432 | for (int i = 0; i <= MOVE_WAIT; i++) VBlankIntrWait(); 433 | REG_BLDCNT = BLD_TOP(BLD_ALL | BLD_BACKDROP) | BLD_BLACK; 434 | for (int i = 0; i <= 16; i++) { 435 | REG_BLDY = i; 436 | VBlankIntrWait(); 437 | } 438 | gs.map ^= 1; 439 | loadMap(); 440 | gs.x += getDirX(dir); 441 | gs.y += getDirY(dir); 442 | gs.z += getDirZ(dir); 443 | drawInstant(PERSP_FWD); 444 | 445 | for (int i = 0; i <= 16; i++) { 446 | REG_BLDY = 16 - i; 447 | VBlankIntrWait(); 448 | } 449 | 450 | return 1; 451 | } 452 | 453 | int interactEnv() 454 | { 455 | uint8_t dir = gs.d; 456 | if (isBlocked(dir)) { 457 | uint8_t t = getTexDir(dir); 458 | if (isLadder(t)) return moveForward(); 459 | if (isDoor(t)) return openDoor(dir); 460 | if (isOutsideDoor(t)) return openOutsideDoor(dir); 461 | if (isSwitch(t)) { 462 | mmEffect(SFX_CLICK); 463 | lvl_bin[(gs.z << 8) | (gs.y << 4) | (gs.x)].texs[dir] = toggleSwitch(t); 464 | drawInstant(PERSP_FWD); 465 | } 466 | if (isPlaque(t)) { 467 | show_message(-1, "The mysterious plaque evades your attempts at comprehension."); 468 | } 469 | } 470 | return 0; 471 | } 472 | 473 | int after_boss() 474 | { 475 | if (BATTLE_OUTCOME == -1) { 476 | game_over(); 477 | return 1; 478 | } 479 | if (BATTLE_OUTCOME == 1) { 480 | victory(); 481 | } 482 | CURRENT_MOD = GAMEPLAY_MUS; 483 | return 0; 484 | } 485 | 486 | static int fuzz = 0; 487 | __attribute__((section(".iwram"), long_call, target("arm"))) 488 | void hblank() 489 | { 490 | REG_BLDY = max((fuzz - ((REG_VCOUNT - fuzz) & 0x1F)) >> 3, 0); 491 | REG_BG2X = ((((((REG_VCOUNT + fuzz) & 0xF) - 8)) << 4)) * fuzz; 492 | } 493 | 494 | void gameplay() { 495 | mmSetModuleVolume(0); 496 | GAMEPLAY_MUS = MOD_TEMP31; 497 | BATTLE_OUTCOME = 0; 498 | CURRENT_MOD = -1; 499 | 500 | drawInstant(PERSP_FWD); 501 | if (NEW_GAME) { 502 | mmEffect(SFX_WARP); 503 | irq_add(II_HBLANK, hblank); 504 | irq_enable(II_HBLANK); 505 | for (int i = 0; i <= 128; i++) { 506 | 507 | fuzz = 128 - i; 508 | REG_BLDY = (128 - i) / 8; 509 | if (i == 112) CURRENT_MOD = GAMEPLAY_MUS; 510 | mmSetModuleVolume(max(i * 16 - 1792, 0)); 511 | VBlankIntrWait(); 512 | } 513 | REG_BG2PA = 256; 514 | irq_disable(II_HBLANK); 515 | } else { 516 | CURRENT_MOD = GAMEPLAY_MUS; 517 | for (int i = 0; i <= 16; i++) { 518 | REG_BLDY = (16 - i); 519 | mmSetModuleVolume(i * 16); 520 | VBlankIntrWait(); 521 | } 522 | } 523 | for (;;) { // Main loop 524 | if (show_loc) { 525 | // Show coords 526 | 527 | for (int i = 0; i < 7; i++) obj_hide(&oam_mem[i]); 528 | int val = gs.x; 529 | if (val / 10 != 0) OBJSET(0, 6 + val / 10, 2, 0, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 530 | OBJSET(1, 6 + val % 10, 2, 6, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 531 | val = gs.y; 532 | if (val / 10 != 0) OBJSET(2, 6 + val / 10, 2, 20, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 533 | OBJSET(3, 6 + val % 10, 2, 26, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 534 | val = gs.z; 535 | if (val / 10 != 0) OBJSET(4, 6 + val / 10, 2, 40, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 536 | OBJSET(5, 6 + val % 10, 2, 46, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 537 | val = gs.d; 538 | OBJSET(6, 6 + val, 2, 60, 0, 1, ATTR0_SQUARE, ATTR1_SIZE_8x8, 0); 539 | 540 | 541 | } 542 | // Use up a random number 543 | rand(); 544 | 545 | // First, check if we are falling 546 | if (!gs.climbing && !isBlocked(DIR_D)) { 547 | fall(); 548 | continue; 549 | } 550 | int old_x = gs.x; 551 | int old_y = gs.y; 552 | int moved = 0; 553 | if (INKEY_PRESSED & KEY_A) moved = interactEnv(); 554 | else if (INKEY & KEY_UP) moved = moveForward(); 555 | else if (INKEY & KEY_DOWN) moved = moveBackward(); 556 | else if (INKEY & KB_TURNLEFT) moved = turnLeft(); 557 | else if (INKEY & KB_TURNRIGHT) moved = turnRight(); 558 | else if (INKEY & KB_STRAFELEFT) moved = strafeLeft(); 559 | else if (INKEY & KB_STRAFERIGHT) moved = strafeRight(); 560 | else if (INKEY & KEY_START) open_status(); 561 | else if (INKEY & KEY_B) open_status(); 562 | 563 | if (moved) { 564 | if (old_x != gs.x || old_y != gs.y) { 565 | if (isRestoreTile(getTexDir(DIR_D))) { 566 | mmEffect(SFX_HEAL); 567 | for (int i = 0; i < 2; i++) { 568 | gs.pl[i].hp = gs.pl[i].maxhp; 569 | gs.pl[i].mp = gs.pl[i].maxmp; 570 | } 571 | show_message(-1, "Stepping on the tile has healed and reenergised you."); 572 | } 573 | if (plot_handle() == 1) return; 574 | else CURRENT_MOD = GAMEPLAY_MUS; 575 | if (!skip_encounters) { 576 | gs.plot[PLOT_ENC]--; 577 | if (gs.plot[PLOT_ENC] <= 0) { 578 | gs.plot[PLOT_ENC] = 10 + rand() % 30; 579 | BATTLE_OUTCOME = 0; 580 | random_encounter(); 581 | if (BATTLE_OUTCOME == -1) { 582 | game_over(); 583 | return; 584 | } 585 | 586 | if (BATTLE_OUTCOME == 1) { 587 | victory(); 588 | } 589 | CURRENT_MOD = GAMEPLAY_MUS; 590 | } 591 | } 592 | } 593 | } 594 | 595 | VBlankIntrWait(); 596 | } 597 | } 598 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /source/ui.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "soundbank.h" 10 | #include "macros.h" 11 | #include "font.h" 12 | #include "fast_set.h" 13 | #include "ui.h" 14 | #include "pdata.h" 15 | #include "saves.h" 16 | #include "textfn.h" 17 | #include "btl_types.h" 18 | #include "textconsts.h" 19 | #include "battle.h" 20 | #include "video.h" 21 | 22 | #include "btl_objmap_bin.h" 23 | #include "btl_uimap_bin.h" 24 | #include "btl_charapal_bin.h" 25 | #include "btl_charagfx_bin.h" 26 | #include "btl_menuicons_bin.h" 27 | #include "btl_nums_bin.h" 28 | #include "btl_nmedata_bin.h" 29 | 30 | int MESSAGE_OFFSET = 0; 31 | 32 | void wrap_text(int pos_x, int pos_y, const int *linelim, int linespacing, const char *text) 33 | { 34 | char linbuf[100]; 35 | int line = 0; 36 | int linelen = 0; 37 | int lim = linelim[0]; 38 | int draw_y = pos_y; 39 | const char *linebegin = text; 40 | const char *p = linebegin; 41 | const char *lastspace = NULL; 42 | 43 | while (*p != '\0') { 44 | if (*p == ' ') { 45 | lastspace = p; 46 | } 47 | linelen += GLYPH_W[*p - ' ']; 48 | if (linelen > lim) { 49 | memcpy(linbuf, linebegin, lastspace - linebegin); 50 | linbuf[lastspace - linebegin] = '\0'; 51 | draw_text(pos_x - lim, draw_y, linbuf); 52 | draw_y += linespacing; 53 | line++; 54 | lim = linelim[line]; 55 | linebegin = lastspace + 1; 56 | p = linebegin; 57 | lastspace = NULL; 58 | linelen = 0; 59 | continue; 60 | } 61 | p++; 62 | } 63 | memcpy(linbuf, linebegin, p - linebegin); 64 | linbuf[p - linebegin] = '\0'; 65 | draw_text(pos_x - lim, draw_y, linbuf); 66 | } 67 | void show_message(int portrait, const char *text) 68 | { 69 | //fast_copy(OBJ_PAL(0), btl_objpal_bin + (COLSPACE << 9), 512); 70 | 71 | const int linelim_dlg[] = {168, 168, 184, 184, 184, 184}; 72 | const int linelim_txt[] = {184, 184, 184, 184, 184, 184}; 73 | const int *linelim; 74 | int linespacing; 75 | if (portrait == -1) { // Text box 76 | linelim = linelim_txt; 77 | linespacing = 8; 78 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (1 << 13), 8192); 79 | } else { // Dialogue box 80 | linelim = linelim_dlg; 81 | linespacing = 8; 82 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (0 << 13), 8192); 83 | } 84 | 85 | wrap_text(188, 68, linelim, linespacing, text); 86 | 87 | if (portrait >= 0) { 88 | // Portrait 89 | fast_copy(OBJ_PAL(8), btl_charapal_bin + (portrait<<7) + (COLSPACE << 5), 32); 90 | fast_copy(OBJ_CHR(4, 4), btl_charagfx_bin + (portrait<<7) + 0, 64); 91 | fast_copy(OBJ_CHR(4, 5), btl_charagfx_bin + (portrait<<7) + 64, 64); 92 | } 93 | 94 | // Now wait for vblank 95 | VBlankIntrWait(); 96 | 97 | if (portrait >= 0) 98 | OBJSET(12, 4, 4, 24+1, 48+1 + MESSAGE_OFFSET, 8, ATTR0_SQUARE | ATTR0_BLEND | ATTR0_AFF, ATTR1_SIZE_16x16 | ATTR1_AFF_ID(8), 0); 99 | 100 | // Message box 101 | OBJSET(15, 0, 8, 24, 48 + MESSAGE_OFFSET, 1, ATTR0_SQUARE | ATTR0_BLEND | ATTR0_AFF, ATTR1_SIZE_64x64 | ATTR1_AFF_ID(8), 0); 102 | OBJSET(14, 8, 8, 24+64, 48 + MESSAGE_OFFSET, 1, ATTR0_SQUARE | ATTR0_BLEND | ATTR0_AFF, ATTR1_SIZE_64x64 | ATTR1_AFF_ID(8), 0); 103 | OBJSET(13, 16, 8, 24+128, 48 + MESSAGE_OFFSET, 1, ATTR0_SQUARE | ATTR0_BLEND | ATTR0_AFF, ATTR1_SIZE_64x64 | ATTR1_AFF_ID(8), 0); 104 | 105 | // Quick fading anim 106 | REG_BLDCNT = BLD_BOT(BLD_BG2 | BLD_BACKDROP) | BLD_STD; 107 | for (int i = 1; i <= 20; i++) { 108 | uint32_t scale = 576 - (i << 4); 109 | uint32_t offset = 64 - (64 * 256 / scale); 110 | // 48x13 111 | obj_set_pos(&oam_mem[15], 24 + offset, 48 + MESSAGE_OFFSET); 112 | obj_set_pos(&oam_mem[13], 24+128 - offset, 48 + MESSAGE_OFFSET); 113 | 114 | obj_set_pos(&oam_mem[12], 24+1 + offset * 7 / 5, 48+1 + offset * 3 / 8 + MESSAGE_OFFSET); 115 | AFFSET(8, scale, 0, 0, scale); 116 | REG_BLDALPHA = BLD_EVA(min(i, 16)) | BLD_EVB(max(16-i, 0)); 117 | //REG_BLDALPHA = BLD_EVA(16) | BLD_EVB(0); 118 | 119 | VBlankIntrWait(); 120 | } 121 | int spoils_x = 112 + 12; 122 | for (int i = 0; i < 6; i++) { 123 | if (BATTLE_SPOILS[i] != 0xFF) { 124 | spoils_x -= 12; 125 | } 126 | } 127 | for (int i = 0; i < 6; i++) { 128 | if (BATTLE_SPOILS[i] != 0xFF) { 129 | VBlankIntrWait(); 130 | VBlankIntrWait(); 131 | uint8_t ico = BATTLE_SPOILS[i]; 132 | int sx = (i % 3) * 2 + 24; 133 | int sy = (i / 3) * 2 + 8; 134 | fast_copy(OBJ_CHR(sx, sy), btl_menuicons_bin + (ico << 8) + 0, 64); 135 | fast_copy(OBJ_CHR(sx, sy+1), btl_menuicons_bin + (ico << 8) + 64, 64); 136 | OBJSET(11 - i, sx, sy, spoils_x, 80 + MESSAGE_OFFSET, 1, ATTR0_SQUARE | ATTR0_BLEND, ATTR1_SIZE_16x16, 0); 137 | spoils_x += 24; 138 | VBlankIntrWait(); 139 | if (INKEY_PRESSED & (KEY_A | KEY_B)) break; 140 | VBlankIntrWait(); 141 | if (INKEY_PRESSED & (KEY_A | KEY_B)) break; 142 | } 143 | } 144 | 145 | for (;;) { 146 | if (INKEY_PRESSED & (KEY_A | KEY_B)) break; 147 | VBlankIntrWait(); 148 | } 149 | 150 | // Fade out 151 | 152 | for (int i = 1; i <= 16; i++) { 153 | REG_BLDALPHA = BLD_EVB(i) | BLD_EVA(16-i); 154 | VBlankIntrWait(); 155 | } 156 | 157 | // Disable sprites 158 | oam_init(&oam_mem[6], 10); 159 | } 160 | 161 | void draw_textbar(const char *text) 162 | { 163 | hide_display(); 164 | fast_copy(OBJ_CHR(0, 6), btl_objmap_bin + (6 * 1024), 2048); 165 | uint16_t w = text_width(text); 166 | draw_text((128 - w) / 2, 51, text); 167 | VBlankIntrWait(); 168 | for (int i = 0; i < 4; i++) { 169 | OBJSET(15 - i, 4 * i, 6, 56 + i * 32, 2, 1, ATTR0_WIDE, ATTR1_SIZE_32x16, 0); 170 | } 171 | } 172 | 173 | void draw_iconmenu_plronly(uint8_t psel, uint8_t spronly, int offy) 174 | { 175 | // Player info 176 | for (uint32_t i = 0; i < 2; i++) { 177 | OBJSET(125 - i * 4, 0, (i == psel) * 3 + 0, i * 63 + 0, 138 + offy, 0, ATTR0_WIDE, ATTR1_SIZE_32x16, 0); 178 | OBJSET(124 - i * 4, 0, (i == psel) * 3 + 2, i * 63 + 0, 154 + offy, 0, ATTR0_WIDE, ATTR1_SIZE_32x8, 0); 179 | OBJSET(123 - i * 4, 0, (i == psel) * 3 + 0, i * 63 + 32, 138 + offy, 0, ATTR0_WIDE, ATTR1_SIZE_32x16 | ATTR1_HFLIP, 0); 180 | OBJSET(122 - i * 4, 0, (i == psel) * 3 + 2, i * 63 + 32, 154 + offy, 0, ATTR0_WIDE, ATTR1_SIZE_32x8 | ATTR1_HFLIP, 0); 181 | if (gs.pl[i].pid != 0xFF) { 182 | uint8_t p = gs.pl[i].pid; 183 | // Portrait 184 | if (!spronly) { 185 | fast_copy(OBJ_PAL(8 + i), btl_charapal_bin + (p << 7) + (COLSPACE << 5), 32); 186 | int status = 0xFF; 187 | for (int j = 0; j < STATUS_MAX; j++) { 188 | if (gs.pl[i].status[j] > 0) status = j; 189 | } 190 | if (status != 0xFF) { 191 | paleffect(8 + i, status); 192 | } 193 | fast_copy(OBJ_CHR(4 + i * 2, 4), btl_charagfx_bin + (p << 7) + 0, 64); 194 | fast_copy(OBJ_CHR(4 + i * 2, 5), btl_charagfx_bin + (p << 7) + 64, 64); 195 | } 196 | OBJSET(97-i, 4+i*2, 4, i * 63 + 4, 141 + offy, 8 + i, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 197 | 198 | int v, maxv, pad, low; 199 | // HP 200 | v = gs.pl[i].hp; 201 | maxv = gs.pl[i].maxhp; 202 | pad = (v < 100 ? 5 : 0) + (v < 10 ? 5 : 0); 203 | low = v < (maxv >> 2) ? 1 : 0; 204 | if (!spronly) fast_copy(OBJ_CHR(8 + i * 4, 4), btl_nums_bin + ((v + (psel == i ? 2000 : 0)) << 6), 64); 205 | if (!spronly) fast_copy(OBJ_CHR(10 + i * 4, 4), btl_nums_bin + ((maxv + (psel == i ? 2000 : 0)) << 6), 64); 206 | 207 | OBJSET(110 - i * 4, 8 + i * 4, 4, 23 + i * 63 + pad, 141 + offy, 1 + low, ATTR0_WIDE, ATTR1_SIZE_16x8, 0); 208 | OBJSET(109 - i * 4, 10 + i * 4, 4, 44 + i * 63, 141 + offy, 1 + low, ATTR0_WIDE, ATTR1_SIZE_16x8, 0); 209 | // MP 210 | v = gs.pl[i].mp; 211 | maxv = gs.pl[i].maxmp; 212 | pad = (v < 100 ? 5 : 0) + (v < 10 ? 5 : 0); 213 | low = v < (maxv >> 2) ? 1 : 0; 214 | if (!spronly) fast_copy(OBJ_CHR(8 + i * 4, 5), btl_nums_bin + ((v + (psel == i ? 3000 : 1000)) << 6), 64); 215 | if (!spronly) fast_copy(OBJ_CHR(10 + i * 4, 5), btl_nums_bin + ((maxv + (psel == i ? 3000 : 1000)) << 6), 64); 216 | OBJSET(108 - i * 4, 8 + i * 4, 5, 23 + i * 63 + pad, 150 + offy, 1 + low, ATTR0_WIDE, ATTR1_SIZE_16x8, 0); 217 | OBJSET(107 - i * 4, 10 + i * 4, 5, 44 + i * 63, 150 + offy, 1 + low, ATTR0_WIDE, ATTR1_SIZE_16x8, 0); 218 | 219 | // Sep 220 | OBJSET(112 - i, 5, (i == psel) * 2, i * 63 + 39, 141 + offy, 1, ATTR0_TALL, ATTR1_SIZE_8x16, 0); 221 | } 222 | } 223 | } 224 | void draw_iconmenu(uint8_t psel, const uint8_t *icons, uint8_t ilen, uint8_t isel, uint8_t spronly, int offy) { 225 | draw_iconmenu_plronly(psel, spronly, offy); 226 | int ioff = isel == 0xFF ? 0 : isel - 2; 227 | ioff = max(min(ioff, ilen - 5), 0); 228 | // Left menu arrow 229 | OBJSET(126, 4, 0, ioff > 0 ? 126 : 123, 138 + offy, 0, ATTR0_TALL, ATTR1_SIZE_8x32, 0); 230 | // Right menu arrow 231 | OBJSET(127, 4, 0, ioff < ilen - 5 ? 232 : 236, 138 + offy, 0, ATTR0_TALL, ATTR1_SIZE_8x32 | ATTR1_HFLIP, 0); 232 | 233 | // Icons 234 | for (uint8_t x = 0; x < 5; x++) { 235 | uint8_t i = x + ioff; 236 | uint8_t ico = i < ilen ? icons[i] : 39; 237 | if (!spronly) fast_copy(OBJ_CHR(x * 2 + 6, 0), btl_menuicons_bin + (ico << 8) + (i == isel ? 128 : 0), 64); 238 | if (!spronly) fast_copy(OBJ_CHR(x * 2 + 6, 1), btl_menuicons_bin + (ico << 8) + (i == isel ? 192 : 64), 64); 239 | if (i != isel) { 240 | OBJSET(117-x, 16, 1, 130 + 21 * x, 138 + offy, 0, ATTR0_SQUARE, ATTR1_SIZE_32x32, 0); 241 | } else { 242 | OBJSET(117-x, 16, 4, 130 + 21 * x, 138 + offy, 0, ATTR0_SQUARE, ATTR1_SIZE_32x32 | ATTR1_VFLIP, 0); 243 | } 244 | OBJSET(102-x, 6 + (x << 1), 0, 133 + x * 21, 141 + offy, 0, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 245 | } 246 | } 247 | const char *get_name(int pid) 248 | { 249 | if (pid == 0) return NMEDATA[26].mname; 250 | else return NMEDATA[19+pid].mname; 251 | } 252 | uint8_t status_selplayer(int cm) 253 | { 254 | uint8_t plrcount = gs.pl[1].pid != 0xFF ? 2 : 1; 255 | uint8_t cur = clamp(CMEM_ON ? CMEM[cm] : 0, 0, plrcount - 1); 256 | 257 | draw_iconmenu_plronly(cur, 0, 0); 258 | draw_textbar(get_name(gs.pl[cur].pid)); 259 | for (;;) { 260 | VBlankIntrWait(); 261 | if (INKEY_PRESSED & KEY_START) { 262 | hide_display(); 263 | return 0xFE; 264 | } 265 | else if (INKEY_PRESSED & KEY_B) { 266 | mmEffect(SFX_CANCEL); 267 | hide_display(); 268 | return 0xFF; 269 | } 270 | else if (INKEY_PRESSED & KEY_A) { 271 | mmEffect(SFX_SELECT); 272 | hide_display(); 273 | return cur; 274 | } 275 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 276 | cur = min(cur ^ 1, plrcount - 1); 277 | mmEffect(SFX_CURSOR); 278 | CMEM[cm] = cur; 279 | draw_iconmenu_plronly(cur, 0, 0); 280 | draw_textbar(get_name(gs.pl[cur].pid)); 281 | } 282 | } 283 | 284 | return 0; 285 | } 286 | 287 | 288 | void hide_display() 289 | { 290 | for (int i = 12; i < 32; i++) 291 | obj_hide(&obj_mem[i]); 292 | } 293 | 294 | void show_equipment(uint8_t plr, uint8_t eq, uint8_t ico, uint8_t id) 295 | { 296 | hide_display(); 297 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (4 << 13), 8192); 298 | 299 | fast_copy(OBJ_CHR(24, 8), btl_menuicons_bin + (ico << 8) + 0, 64); 300 | fast_copy(OBJ_CHR(24, 9), btl_menuicons_bin + (ico << 8) + 64, 64); 301 | 302 | if (id != 0xFF) { 303 | draw_text(28, 68 + 4, NMEDATA[id].ename); 304 | char txt[48]; 305 | switch (eq) { 306 | case 0: 307 | txt_set(txt, "Damage: "); 308 | txt_append_num(txt, NMEDATA[id].eqatt[EQATT_DMG]); 309 | txt_append_str(txt, " (Acc: "); 310 | txt_append_num(txt, NMEDATA[id].eqatt[EQATT_PCT]); 311 | txt_append_str(txt, "%)"); 312 | draw_text(28, 68+16 + 2, txt); 313 | 314 | if (NMEDATA[id].eqatt[EQATT_STR] != 0xFF) { 315 | txt_set(txt, "Damage type: "); 316 | txt_append_str(txt, ELEMENTS[NMEDATA[id].eqatt[EQATT_STR]]); 317 | draw_text(28, 68+32, txt); 318 | } 319 | if (NMEDATA[id].eqatt[EQATT_WEAK] != 0xFF) { 320 | txt_set(txt, "Inflicts: "); 321 | txt_append_str(txt, STATUSES[NMEDATA[id].eqatt[EQATT_WEAK]]); 322 | draw_text(28, 68+48 - 2, txt); 323 | } 324 | break; 325 | case 1: 326 | case 2: 327 | txt_set(txt, "Defense: "); 328 | txt_append_num(txt, NMEDATA[id].eqatt[EQATT_DMG]); 329 | txt_append_str(txt, " (Block chance: "); 330 | txt_append_num(txt, NMEDATA[id].eqatt[EQATT_PCT]); 331 | txt_append_str(txt, "%)"); 332 | draw_text(28, 68+16 + 2, txt); 333 | if (NMEDATA[id].eqatt[EQATT_STR] != 0xFF) { 334 | txt_set(txt, "Protects against: "); 335 | txt_append_str(txt, ELEMENTS[NMEDATA[id].eqatt[EQATT_STR]]); 336 | draw_text(28, 68+32, txt); 337 | } 338 | if (NMEDATA[id].eqatt[EQATT_WEAK] != 0xFF) { 339 | txt_set(txt, "Vulnerable to: "); 340 | txt_append_str(txt, ELEMENTS[NMEDATA[id].eqatt[EQATT_WEAK]]); 341 | draw_text(28, 68+48 - 2, txt); 342 | } 343 | break; 344 | case 3: 345 | const int linelim[] = {157, 157, 157}; 346 | wrap_text(185, 68+16+2, linelim, 16, ACC_DESC[NMEDATA[id].eqatt[EQATT_DMG]]); 347 | break; 348 | } 349 | 350 | //draw_text(33, 68+16, "Line 2"); 351 | //draw_text(33, 68+32, "Line 3"); 352 | //draw_text(33, 68+48, "Line 4"); 353 | } else { 354 | const char *str; 355 | switch (eq) { 356 | case 0: default: str = "No weapon"; break; 357 | case 1: str = "No armour"; break; 358 | case 2: str = "No helmet"; break; 359 | case 3: str = "No accessory"; break; 360 | } 361 | draw_text(48, 64+28, str); 362 | } 363 | 364 | VBlankIntrWait(); 365 | OBJSET(12, 24, 8, 24+3, 37+24, 0, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 366 | 367 | // Message box 368 | OBJSET(15, 0, 8, 24, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 369 | OBJSET(14, 8, 8, 24+64, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 370 | OBJSET(13, 16, 8, 24+128, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 371 | } 372 | 373 | void stat_text(char *txt, const char *str, int baseval, int addval) 374 | { 375 | txt_set(txt, str); 376 | txt_append_num(txt, baseval + addval); 377 | 378 | if (addval != 0) { 379 | txt_append_str(txt, " (+"); 380 | txt_append_num(txt, addval); 381 | txt_append_str(txt, ")"); 382 | } 383 | } 384 | 385 | void show_stone(uint8_t plr, uint8_t eq, uint8_t ico, uint8_t id, uint8_t remfirst) 386 | { 387 | hide_display(); 388 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (4 << 13), 8192); 389 | 390 | fast_copy(OBJ_CHR(24, 8), btl_menuicons_bin + (ico << 8) + 0, 64); 391 | fast_copy(OBJ_CHR(24, 9), btl_menuicons_bin + (ico << 8) + 64, 64); 392 | 393 | int base_maxhp = gs.pl[plr].maxhp; 394 | int base_maxmp = gs.pl[plr].maxmp; 395 | int base_str = gs.pl[plr].str; 396 | int base_def = gs.pl[plr].def; 397 | int base_agi = gs.pl[plr].agi; 398 | int base_mag = gs.pl[plr].mag; 399 | 400 | if (remfirst) { 401 | // Remove current soulstone from stats 402 | uint8_t tid = gs.pl[plr].slots[eq]; 403 | if (tid != 0xFF) { 404 | base_maxhp -= STONE_STAT_CALC(NMEDATA[tid].maxhp); 405 | base_maxmp -= STONE_STAT_CALC(NMEDATA[tid].maxmp); 406 | base_str -= STONE_STAT_CALC(NMEDATA[tid].str); 407 | base_def -= STONE_STAT_CALC(NMEDATA[tid].def); 408 | base_agi -= STONE_STAT_CALC(NMEDATA[tid].agi); 409 | base_mag -= STONE_STAT_CALC(NMEDATA[tid].mag); 410 | } 411 | } 412 | int add_maxhp = 0; 413 | int add_maxmp = 0; 414 | int add_str = 0; 415 | int add_def = 0; 416 | int add_agi = 0; 417 | int add_mag = 0; 418 | 419 | if (id != 0xFF) { 420 | draw_text(28, 68 + 4, NMEDATA[id].mname); 421 | add_maxhp = STONE_STAT_CALC(NMEDATA[id].maxhp); 422 | add_maxmp = STONE_STAT_CALC(NMEDATA[id].maxmp); 423 | add_str = STONE_STAT_CALC(NMEDATA[id].str); 424 | add_def = STONE_STAT_CALC(NMEDATA[id].def); 425 | add_agi = STONE_STAT_CALC(NMEDATA[id].agi); 426 | add_mag = STONE_STAT_CALC(NMEDATA[id].mag); 427 | } else { 428 | draw_text(48, 64+4, "No spirit crystal"); 429 | } 430 | char txt[48]; 431 | stat_text(txt, "Life: ", base_maxhp, add_maxhp); 432 | draw_text(28, 68 + 16 + 2, txt); 433 | stat_text(txt, "Qi: ", base_maxmp, add_maxmp); 434 | draw_text(28 + 80, 68 + 16 + 2, txt); 435 | stat_text(txt, "Str: ", base_str, add_str); 436 | draw_text(28, 68 + 32, txt); 437 | stat_text(txt, "Def: ", base_def, add_def); 438 | draw_text(28 + 80, 68 + 32, txt); 439 | stat_text(txt, "Agi: ", base_agi, add_agi); 440 | draw_text(28, 68 + 48 - 2, txt); 441 | stat_text(txt, "Mag: ", base_mag, add_mag); 442 | draw_text(28 + 80, 68 + 48 - 2, txt); 443 | 444 | VBlankIntrWait(); 445 | OBJSET(12, 24, 8, 24+3, 37+24, 0, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 446 | 447 | // Message box 448 | OBJSET(15, 0, 8, 24, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 449 | OBJSET(14, 8, 8, 24+64, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 450 | OBJSET(13, 16, 8, 24+128, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 451 | } 452 | void show_tech(uint8_t plr, uint8_t ico, uint8_t id) 453 | { 454 | hide_display(); 455 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (4 << 13), 8192); 456 | 457 | fast_copy(OBJ_CHR(24, 8), btl_menuicons_bin + (ico << 8) + 0, 64); 458 | fast_copy(OBJ_CHR(24, 9), btl_menuicons_bin + (ico << 8) + 64, 64); 459 | 460 | char txt[48]; 461 | txt_set(txt, NMEDATA[id].sname); 462 | txt_append_str(txt, " (Qi cost: "); 463 | txt_append_num(txt, NMEDATA[id].spdata[SP_COST]); 464 | txt_append_str(txt, ")"); 465 | draw_text(28, 68 + 4, txt); 466 | 467 | const int linelim[] = {157, 157, 157}; 468 | wrap_text(185, 68+16+2, linelim, 16, NMEDATA[id].sdesc); 469 | 470 | VBlankIntrWait(); 471 | OBJSET(12, 24, 8, 24+3, 37+24, 0, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 472 | 473 | // Message box 474 | OBJSET(15, 0, 8, 24, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 475 | OBJSET(14, 8, 8, 24+64, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 476 | OBJSET(13, 16, 8, 24+128, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 477 | } 478 | void show_save(struct saveinfo *saves, uint8_t ico, uint8_t cur) 479 | { 480 | hide_display(); 481 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (4 << 13), 8192); 482 | 483 | fast_copy(OBJ_CHR(24, 8), btl_menuicons_bin + (ico << 8) + 0, 64); 484 | fast_copy(OBJ_CHR(24, 9), btl_menuicons_bin + (ico << 8) + 64, 64); 485 | 486 | if (saves[cur].filled == 0x01) { 487 | draw_text(28, 68 + 4, saves[cur].txt1); 488 | draw_text(28, 68 + 16 + 2, saves[cur].txt2); 489 | draw_text(28, 68 + 32, saves[cur].txt3); 490 | draw_text(28, 68 + 48 - 2, saves[cur].txt4); 491 | } else { 492 | draw_text(48, 64+28, "Unoccupied save slot"); 493 | } 494 | 495 | VBlankIntrWait(); 496 | OBJSET(12, 24, 8, 24+3, 37+24, 0, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 497 | 498 | // Message box 499 | OBJSET(15, 0, 8, 24, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 500 | OBJSET(14, 8, 8, 24+64, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 501 | OBJSET(13, 16, 8, 24+128, 37, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 502 | } 503 | 504 | uint8_t status_equip_sel(uint8_t plr, uint8_t eq) 505 | { 506 | // Fill equipment list 507 | uint8_t icons[INV_MAX]; 508 | uint8_t icons_id[INV_MAX]; 509 | uint8_t menulen = 0; 510 | for (int i = 0; i < INV_MAX; i++) { 511 | if (i >= NMEDATA_COUNT) break; 512 | if (NMEDATA[i].equiptype == eq) { 513 | uint8_t qty = gs.equip_qty[i]; 514 | if (gs.pl[plr].equip[eq] == i) qty++; 515 | if (qty > 0) { 516 | icons[menulen] = 80 + i; 517 | icons_id[menulen] = i; 518 | menulen++; 519 | } 520 | } 521 | } 522 | icons[menulen] = 20 + eq; 523 | icons_id[menulen] = 0xFF; 524 | menulen++; 525 | 526 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SEQUIPB + plr*4 + eq] : 0, 0, menulen - 1); 527 | for (;;) { 528 | show_equipment(plr, eq, icons[cur], icons_id[cur]); 529 | 530 | draw_iconmenu(plr, icons, menulen, cur, 0, 0); 531 | for (;;) { 532 | if (INKEY_PRESSED & KEY_START) { 533 | return 1; 534 | } 535 | else if (INKEY_PRESSED & KEY_B) { 536 | mmEffect(SFX_CANCEL); 537 | return 0; 538 | } 539 | else if (INKEY_PRESSED & KEY_A) { 540 | 541 | // Unequip existing equipment 542 | if (gs.pl[plr].equip[eq] != 0xFF) { 543 | gs.equip_qty[gs.pl[plr].equip[eq]]++; 544 | } 545 | gs.pl[plr].equip[eq] = icons_id[cur]; 546 | if (gs.pl[plr].equip[eq] != 0xFF) { 547 | mmEffect(SFX_DECIDE); 548 | gs.equip_qty[gs.pl[plr].equip[eq]]--; 549 | } else { 550 | mmEffect(SFX_SELECTNONE); 551 | } 552 | return 0; 553 | } 554 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 555 | cur = (cur + ((INKEY_PRESSED & KEY_LEFT) ? menulen - 1 : 1)) % menulen; 556 | mmEffect(SFX_CURSOR); 557 | CMEM[CMEM_SEQUIPB + plr*4 + eq] = cur; 558 | break; 559 | draw_iconmenu(plr, icons, menulen, cur, 0, 0); 560 | } 561 | VBlankIntrWait(); 562 | } 563 | } 564 | 565 | return 0; 566 | } 567 | uint8_t status_stones_sel(uint8_t plr, uint8_t eq) 568 | { 569 | // Fill stones list 570 | uint8_t icons[INV_MAX]; 571 | uint8_t icons_id[INV_MAX]; 572 | uint8_t menulen = 0; 573 | for (int i = 0; i < INV_MAX; i++) { 574 | if (i >= NMEDATA_COUNT) break; 575 | uint8_t qty = gs.gem_qty[i]; 576 | if (gs.pl[plr].slots[eq] == i) qty++; 577 | if (qty > 0) { 578 | icons[menulen] = 40 + i; 579 | icons_id[menulen] = i; 580 | menulen++; 581 | } 582 | } 583 | icons[menulen] = 24; 584 | icons_id[menulen] = 0xFF; 585 | menulen++; 586 | 587 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SSTONEB + plr*4 + eq] : 0, 0, menulen - 1); 588 | for (;;) { 589 | show_stone(plr, eq, icons[cur], icons_id[cur], 1); 590 | 591 | draw_iconmenu(plr, icons, menulen, cur, 0, 0); 592 | for (;;) { 593 | if (INKEY_PRESSED & KEY_START) { 594 | return 1; 595 | } 596 | else if (INKEY_PRESSED & KEY_B) { 597 | mmEffect(SFX_CANCEL); 598 | return 0; 599 | } 600 | else if (INKEY_PRESSED & KEY_A) { 601 | 602 | // Unequip existing stone 603 | uint8_t tid = gs.pl[plr].slots[eq]; 604 | if (tid != 0xFF) { 605 | gs.gem_qty[tid]++; 606 | // Remove stats 607 | gs.pl[plr].maxhp -= STONE_STAT_CALC(NMEDATA[tid].maxhp); 608 | gs.pl[plr].maxmp -= STONE_STAT_CALC(NMEDATA[tid].maxmp); 609 | gs.pl[plr].str -= STONE_STAT_CALC(NMEDATA[tid].str); 610 | gs.pl[plr].def -= STONE_STAT_CALC(NMEDATA[tid].def); 611 | gs.pl[plr].agi -= STONE_STAT_CALC(NMEDATA[tid].agi); 612 | gs.pl[plr].mag -= STONE_STAT_CALC(NMEDATA[tid].mag); 613 | 614 | gs.pl[plr].hp = clamp(gs.pl[plr].hp, 0, gs.pl[plr].maxhp); 615 | gs.pl[plr].mp = clamp(gs.pl[plr].mp, 0, gs.pl[plr].maxmp); 616 | } 617 | tid = icons_id[cur]; 618 | gs.pl[plr].slots[eq] = tid; 619 | if (tid != 0xFF) { 620 | gs.gem_qty[tid]--; 621 | int full_hp = gs.pl[plr].hp == gs.pl[plr].maxhp; 622 | int full_mp = gs.pl[plr].mp == gs.pl[plr].maxmp; 623 | // Add stats 624 | gs.pl[plr].maxhp += STONE_STAT_CALC(NMEDATA[tid].maxhp); 625 | gs.pl[plr].maxmp += STONE_STAT_CALC(NMEDATA[tid].maxmp); 626 | gs.pl[plr].str += STONE_STAT_CALC(NMEDATA[tid].str); 627 | gs.pl[plr].def += STONE_STAT_CALC(NMEDATA[tid].def); 628 | gs.pl[plr].agi += STONE_STAT_CALC(NMEDATA[tid].agi); 629 | gs.pl[plr].mag += STONE_STAT_CALC(NMEDATA[tid].mag); 630 | if (full_hp) gs.pl[plr].hp = gs.pl[plr].maxhp; 631 | if (full_mp) gs.pl[plr].mp = gs.pl[plr].maxmp; 632 | 633 | mmEffect(SFX_DECIDE); 634 | } else { 635 | mmEffect(SFX_SELECTNONE); 636 | } 637 | return 0; 638 | } 639 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 640 | cur = (cur + ((INKEY_PRESSED & KEY_LEFT) ? menulen - 1 : 1)) % menulen; 641 | mmEffect(SFX_CURSOR); 642 | CMEM[CMEM_SSTONEB + plr*4 + eq] = cur; 643 | break; 644 | draw_iconmenu(plr, icons, menulen, cur, 0, 0); 645 | } 646 | VBlankIntrWait(); 647 | } 648 | } 649 | 650 | return 0; 651 | } 652 | uint8_t status_techs_sel(uint8_t plr, uint8_t tid) 653 | { 654 | // Only revive and heal make sense out of battle 655 | if (NMEDATA[tid].spdata[SP_REVIVE] || NMEDATA[tid].spdata[SP_HEAL]) { 656 | int mpcost = NMEDATA[tid].spdata[SP_COST]; 657 | if (gs.pl[plr].mp < mpcost) { 658 | mmEffect(SFX_NOPE); 659 | draw_textbar("Insufficient Qi"); 660 | return 0; 661 | } 662 | int all = NMEDATA[tid].spdata[SP_ALL]; 663 | int from = 0; 664 | int to = 1; 665 | if (!all) { 666 | uint8_t t = status_selplayer(CMEM_STECP); 667 | if (t == 0xFE) return 1; 668 | if (t == 0xFF) return 0; 669 | from = t; 670 | to = t; 671 | } 672 | gs.pl[plr].mp -= mpcost; 673 | mmEffect(SFX_HEAL); 674 | for (int i = from; i <= to; i++) { 675 | int hpheal = NMEDATA[tid].spdata[SP_DAMAGE]; 676 | hpheal = hpheal * (100 + get_mag(plr)) / 100; 677 | gs.pl[i].hp = min(gs.pl[i].hp + hpheal, gs.pl[i].maxhp); 678 | } 679 | } 680 | return 0; 681 | } 682 | uint8_t status_equip() { 683 | uint8_t plr = status_selplayer(CMEM_SPLR); 684 | if (plr == 0xFE) return 1; 685 | if (plr == 0xFF) return 2; 686 | 687 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SEQUIPA + plr] : 0, 0, 3); 688 | 689 | for (;;) { 690 | uint8_t icons[4]; 691 | 692 | for (int i = 0; i < 4; i++) { 693 | icons[i] = 20 + i; 694 | if (gs.pl[plr].equip[i] != 0xFF) { 695 | icons[i] = gs.pl[plr].equip[i] + 80; 696 | } 697 | } 698 | 699 | show_equipment(plr, cur, icons[cur], gs.pl[plr].equip[cur]); 700 | 701 | draw_iconmenu(plr, icons, 4, cur, 0, 0); 702 | for (;;) { 703 | if (INKEY_PRESSED & KEY_START) { 704 | return 1; 705 | } 706 | else if (INKEY_PRESSED & KEY_B) { 707 | mmEffect(SFX_CANCEL); 708 | return 0; 709 | } 710 | else if (INKEY_PRESSED & KEY_A) { 711 | mmEffect(SFX_SELECT); 712 | if (status_equip_sel(plr, cur) == 1) { 713 | return 1; 714 | } 715 | break; 716 | } 717 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 718 | cur = (cur + ((INKEY_PRESSED & KEY_LEFT) ? 3 : 1)) % 4; 719 | mmEffect(SFX_CURSOR); 720 | CMEM[CMEM_SEQUIPA + plr] = cur; 721 | break; 722 | } 723 | VBlankIntrWait(); 724 | } 725 | } 726 | } 727 | uint8_t status_stones() { 728 | uint8_t plr = status_selplayer(CMEM_SPLR); 729 | if (plr == 0xFE) return 1; 730 | if (plr == 0xFF) return 2; 731 | 732 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SSTONEA + plr] : 0, 0, 3); 733 | 734 | for (;;) { 735 | uint8_t icons[4]; 736 | for (int i = 0; i < 4; i++) { 737 | icons[i] = 24; 738 | if (gs.pl[plr].slots[i] != 0xFF) { 739 | icons[i] = gs.pl[plr].slots[i] + 40; 740 | } 741 | } 742 | 743 | show_stone(plr, cur, icons[cur], gs.pl[plr].slots[cur], 1); 744 | 745 | draw_iconmenu(plr, icons, 4, cur, 0, 0); 746 | for (;;) { 747 | if (INKEY_PRESSED & KEY_START) { 748 | return 1; 749 | } 750 | else if (INKEY_PRESSED & KEY_B) { 751 | mmEffect(SFX_CANCEL); 752 | return 0; 753 | } 754 | else if (INKEY_PRESSED & KEY_A) { 755 | mmEffect(SFX_SELECT); 756 | if (status_stones_sel(plr, cur) == 1) { 757 | return 1; 758 | } 759 | break; 760 | } 761 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 762 | cur = (cur + ((INKEY_PRESSED & KEY_LEFT) ? 3 : 1)) % 4; 763 | mmEffect(SFX_CURSOR); 764 | CMEM[CMEM_SSTONEA + plr] = cur; 765 | break; 766 | } 767 | VBlankIntrWait(); 768 | } 769 | } 770 | } 771 | uint8_t status_techs() { 772 | uint8_t plr = status_selplayer(CMEM_SPLR); 773 | if (plr == 0xFE) return 1; 774 | if (plr == 0xFF) return 2; 775 | 776 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_STECHSA + plr] : 0, 0, 3); 777 | 778 | for (;;) { 779 | uint8_t icons[5]; 780 | uint8_t icons_id[5]; 781 | int menulen = 0; 782 | uint8_t pid = gs.pl[plr].pid; 783 | icons[menulen] = pid == 0 ? 66 : pid + 59; 784 | icons_id[menulen] = pid == 0 ? 26 : pid + 19; 785 | menulen++; 786 | 787 | for (int i = 0; i < 4; i++) { 788 | uint8_t tid = gs.pl[plr].slots[i]; 789 | if (tid != 0xFF) { 790 | icons[menulen] = tid + 40; 791 | icons_id[menulen] = tid; 792 | menulen++; 793 | } 794 | } 795 | 796 | show_tech(plr, icons[cur], icons_id[cur]); 797 | 798 | draw_iconmenu(plr, icons, menulen, cur, 0, 0); 799 | for (;;) { 800 | if (INKEY_PRESSED & KEY_START) { 801 | return 1; 802 | } 803 | else if (INKEY_PRESSED & KEY_B) { 804 | mmEffect(SFX_CANCEL); 805 | return 0; 806 | } 807 | else if (INKEY_PRESSED & KEY_A) { 808 | mmEffect(SFX_SELECT); 809 | if (status_techs_sel(plr, icons_id[cur]) == 1) { 810 | return 1; 811 | } 812 | break; 813 | } 814 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 815 | cur = (cur + ((INKEY_PRESSED & KEY_LEFT) ? menulen - 1 : 1)) % menulen; 816 | mmEffect(SFX_CURSOR); 817 | CMEM[CMEM_SSTONEA + plr] = cur; 818 | break; 819 | } 820 | VBlankIntrWait(); 821 | } 822 | } 823 | } 824 | void save_sel(uint8_t cur) 825 | { 826 | write_save(cur); 827 | } 828 | 829 | uint8_t status_save() { 830 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SAVESLOT] : 0, 0, 4); 831 | 832 | struct saveinfo *saves = NULL; 833 | 834 | for (;;) { 835 | uint8_t icons[5]; 836 | if (saves == NULL) 837 | saves = retrieve_saves(); 838 | 839 | for (int i = 0; i < 5; i++) { 840 | icons[i] = saves[i].filled == 0x01 ? 15 + i : 10 + i; 841 | } 842 | 843 | show_save(saves, icons[cur], cur); 844 | draw_iconmenu(255, icons, 5, cur, 0, 0); 845 | for (;;) { 846 | if (INKEY_PRESSED & KEY_START) { 847 | return 1; 848 | } 849 | else if (INKEY_PRESSED & KEY_B) { 850 | mmEffect(SFX_CANCEL); 851 | return 0; 852 | } 853 | else if (INKEY_PRESSED & KEY_A) { 854 | mmEffect(SFX_DECIDE); 855 | save_sel(cur); 856 | free(saves); 857 | saves = NULL; 858 | break; 859 | } 860 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 861 | cur = (cur + ((INKEY_PRESSED & KEY_LEFT) ? 4 : 1)) % 5; 862 | mmEffect(SFX_CURSOR); 863 | CMEM[CMEM_SAVESLOT] = cur; 864 | break; 865 | } 866 | VBlankIntrWait(); 867 | } 868 | } 869 | if (saves != NULL) free(saves); 870 | 871 | return 0; 872 | } 873 | void draw8x2(int sp1, int sp2, int x, int y, int dx, int dy) 874 | { 875 | OBJSET(sp1, x, y, dx, dy, 1, ATTR0_WIDE, ATTR1_SIZE_32x16, 0); 876 | OBJSET(sp2, x+4, y, dx+32, dy, 1, ATTR0_WIDE, ATTR1_SIZE_32x16, 0); 877 | } 878 | 879 | uint8_t status_config() 880 | { 881 | fast_copy(OBJ_CHR(0, 8), btl_uimap_bin + (3 << 13), 8192); 882 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_CONFIG] : 0, 0, 2); 883 | uint8_t saved_colspace = COLSPACE; 884 | uint8_t cfg_cursormem = CMEM_ON ? 0 : 1; 885 | uint8_t cfg_lrturn = (KB_STRAFELEFT == KEY_L) ? 0 : 1; 886 | 887 | for (;;) { 888 | int x, y, dx, dy; 889 | x = 0; y = 8; dx = 16; dy = 48; 890 | if (cur == 0) x += 8; 891 | draw8x2(31, 30, x, y, dx, dy); 892 | x = 0; y = 10; dx = 16; dy = 72; 893 | if (cur == 1) x += 8; 894 | draw8x2(29, 28, x, y, dx, dy); 895 | x = 0; y = 12; dx = 16; dy = 96; 896 | if (cur == 2) x += 8; 897 | draw8x2(27, 26, x, y, dx, dy); 898 | 899 | // Display modes 900 | for (int i = 0; i < 4; i++) { 901 | x = 16 + i * 2; y = 8; dx = 154 + 18 * i; dy = 48; 902 | if (COLSPACE == i) x += 8; 903 | OBJSET(25 - i, x, y, dx, dy, 1, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); 904 | } 905 | // Cursor mem 906 | for (int i = 0; i < 2; i++) { 907 | x = 16 + i * 4; y = 10; dx = 158 + 34 * i; dy = 72; 908 | if (cfg_cursormem == i) x += 8; 909 | OBJSET(21 - i, x, y, dx, dy, 1, ATTR0_WIDE, ATTR1_SIZE_32x16, 0); 910 | } 911 | // Controls 912 | for (int i = 0; i < 2; i++) { 913 | x = i * 8; y = 14; dx = 94 + 66 * i; dy = 96; 914 | if (cfg_lrturn == i) x += 16; 915 | draw8x2(19 - i, 17 - i, x, y, dx, dy); 916 | } 917 | // Help 918 | draw8x2(15, 14, 16, 12, 2, 120); 919 | draw8x2(13, 12, 24, 12, 66, 120); 920 | 921 | for (;;) { 922 | VBlankIntrWait(); 923 | if (INKEY_PRESSED & KEY_START) { 924 | COLSPACE = saved_colspace; 925 | update_colspace(); 926 | return 1; 927 | } 928 | else if (INKEY_PRESSED & KEY_B) { 929 | mmEffect(SFX_CANCEL); 930 | COLSPACE = saved_colspace; 931 | update_colspace(); 932 | return 0; 933 | } 934 | else if (INKEY_PRESSED & KEY_A) { 935 | mmEffect(SFX_DECIDE); 936 | CMEM_ON = cfg_cursormem == 0 ? 1 : 0; 937 | if (cfg_lrturn == 1) { 938 | KB_STRAFELEFT = KEY_LEFT; 939 | KB_STRAFERIGHT = KEY_RIGHT; 940 | KB_TURNLEFT = KEY_L; 941 | KB_TURNRIGHT = KEY_R; 942 | } else { 943 | KB_TURNLEFT = KEY_LEFT; 944 | KB_TURNRIGHT = KEY_RIGHT; 945 | KB_STRAFELEFT = KEY_L; 946 | KB_STRAFERIGHT = KEY_R; 947 | } 948 | save_config(); 949 | return 0; 950 | } 951 | else if (INKEY_PRESSED & (KEY_LEFT | KEY_RIGHT)) { 952 | int cfgmax = (cur == 0) ? 4 : 2; 953 | int dir = (INKEY_PRESSED & KEY_LEFT) ? cfgmax - 1 : 1; 954 | switch (cur) { 955 | case 0: 956 | COLSPACE = (COLSPACE + dir) % cfgmax; 957 | update_colspace(); 958 | break; 959 | case 1: 960 | cfg_cursormem = (cfg_cursormem + dir) % cfgmax; 961 | break; 962 | case 2: 963 | cfg_lrturn = (cfg_lrturn + dir) % cfgmax; 964 | break; 965 | } 966 | mmEffect(SFX_SELECT); 967 | break; 968 | } 969 | else if (INKEY_PRESSED & (KEY_UP | KEY_DOWN)) { 970 | cur = (cur + ((INKEY_PRESSED & KEY_UP) ? 2 : 1)) % 3; 971 | mmEffect(SFX_CURSOR); 972 | CMEM[CMEM_CONFIG] = cur; 973 | break; 974 | } 975 | 976 | } 977 | } 978 | 979 | return 0; 980 | } 981 | 982 | uint8_t status_submenu(uint8_t *icons, int menulen, uint8_t cur) 983 | { 984 | uint8_t r = 0; 985 | //draw_iconmenu(255, icons, menulen, 255, 0, 0); 986 | switch (cur) { 987 | case 0: r = status_equip(); break; 988 | case 1: r = status_stones(); break; 989 | case 2: r = status_techs(); break; 990 | case 3: r = status_save(); break; 991 | case 4: r = status_config(); break; 992 | } 993 | if (r == 2) r = 0; 994 | return r; 995 | } 996 | 997 | void iconmenu_scroll(int off) { 998 | for (int i = 96; i < 128; i++) { 999 | int y = BFN_GET(obj_mem[i].attr0, ATTR0_Y); 1000 | BFN_SET(obj_mem[i].attr0, y + off, ATTR0_Y); 1001 | } 1002 | } 1003 | 1004 | void status_root_msgbar(uint8_t cur) 1005 | { 1006 | const char *msgbar = NULL; 1007 | switch (cur) { 1008 | case 0: msgbar = "Equip weapons / armour"; break; 1009 | case 1: msgbar = "Equip spirit crystals"; break; 1010 | case 2: msgbar = "Use spirit techniques"; break; 1011 | case 3: msgbar = "Save your progress"; break; 1012 | case 4: msgbar = "Configuration"; break; 1013 | } 1014 | if (msgbar) draw_textbar(msgbar); 1015 | } 1016 | 1017 | void open_status() { 1018 | mmEffect(SFX_STATUSOPEN); 1019 | uint8_t icons[5] = {5, 6, 7, 8, 9}; 1020 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SCUR] : 0, 0, 4); 1021 | 1022 | draw_iconmenu(255, icons, 5, cur, 0, 21); 1023 | // Scroll open 1024 | for (int i = 0; i < 21; i++) { 1025 | VBlankIntrWait(); 1026 | //draw_iconmenu(255, icons, 5, cur, 1, 20 - i); 1027 | iconmenu_scroll(-1); 1028 | } 1029 | status_root_msgbar(cur); 1030 | for (;;) { 1031 | if (INKEY_PRESSED & (KEY_START | KEY_B)) break; 1032 | else if (INKEY_PRESSED & KEY_LEFT) { 1033 | cur = (cur + 4) % 5; 1034 | mmEffect(SFX_CURSOR); 1035 | draw_iconmenu(255, icons, 5, cur, 0, 0); 1036 | status_root_msgbar(cur); 1037 | } 1038 | else if (INKEY_PRESSED & KEY_RIGHT) { 1039 | cur = (cur + 1) % 5; 1040 | mmEffect(SFX_CURSOR); 1041 | draw_iconmenu(255, icons, 5, cur, 0, 0); 1042 | status_root_msgbar(cur); 1043 | } 1044 | else if (INKEY_PRESSED & KEY_A) { 1045 | mmEffect(SFX_SELECT); 1046 | hide_display(); 1047 | uint8_t r = status_submenu(icons, 5, cur); 1048 | hide_display(); 1049 | if (r == 1) break; 1050 | draw_iconmenu(255, icons, 5, cur, 0, 0); 1051 | status_root_msgbar(cur); 1052 | } 1053 | CMEM[CMEM_SCUR] = cur; 1054 | VBlankIntrWait(); 1055 | } 1056 | hide_display(); 1057 | // Scroll shut 1058 | mmEffect(SFX_STATUSCLOSE); 1059 | for (int i = 0; i < 21; i++) { 1060 | VBlankIntrWait(); 1061 | iconmenu_scroll(1); 1062 | //draw_iconmenu(255, icons, 5, cur, 1, i + 1); 1063 | } 1064 | oam_init((OBJ_ATTR *)&OBJMEM[96], 32); 1065 | } 1066 | 1067 | int status_load() 1068 | { 1069 | fast_copy(OBJ_CHR(0, 0), btl_uimap_bin + (5 << 13), 16384); 1070 | struct saveinfo *saves = retrieve_saves(); 1071 | uint8_t cur = clamp(CMEM_ON ? CMEM[CMEM_SAVESLOT] : 0, 0, 4); 1072 | 1073 | for (;;) { 1074 | //hide_display(); 1075 | fast_copy(OBJ_CHR(0, 0), btl_uimap_bin + (5 << 13), 8192); 1076 | 1077 | if (saves[cur].filled == 0x01) { 1078 | draw_text(28, 4 + 4, saves[cur].txt1); 1079 | draw_text(28, 4 + 16 + 2, saves[cur].txt2); 1080 | draw_text(28, 4 + 32, saves[cur].txt3); 1081 | draw_text(28, 4 + 48 - 2, saves[cur].txt4); 1082 | } else { 1083 | draw_text(48, 0+28, "Unoccupied save slot"); 1084 | } 1085 | 1086 | VBlankIntrWait(); 1087 | for (int i = 0; i < 5; i++) { 1088 | int x, y, dx, dy; 1089 | x = i * 4; 1090 | y = 8; 1091 | if (saves[i].filled == 0x01) y += 4; 1092 | dx = 40 * i + 24; 1093 | dy = 96; 1094 | OBJSET(31-i, x, y, dx, dy, cur == i ? 3 : 1, ATTR0_SQUARE, ATTR1_SIZE_32x32, 0); 1095 | } 1096 | 1097 | OBJSET(15, 0, 0, 24, 28, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 1098 | OBJSET(14, 8, 0, 24+64, 28, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 1099 | OBJSET(13, 16, 0, 24+128, 28, 1, ATTR0_SQUARE, ATTR1_SIZE_64x64, 0); 1100 | 1101 | 1102 | for (;;) { 1103 | VBlankIntrWait(); 1104 | if (INKEY_PRESSED & KEY_B) { 1105 | free(saves); 1106 | return 0; 1107 | } 1108 | else if (INKEY_PRESSED & KEY_LEFT) { 1109 | cur = (cur + 4) % 5; 1110 | mmEffect(SFX_CURSOR); 1111 | break; 1112 | } 1113 | else if (INKEY_PRESSED & KEY_RIGHT) { 1114 | cur = (cur + 1) % 5; 1115 | mmEffect(SFX_CURSOR); 1116 | break; 1117 | } 1118 | else if (INKEY_PRESSED & KEY_A) { 1119 | if (saves[cur].filled == 0x01) { 1120 | mmEffect(SFX_DECIDE); 1121 | free(saves); 1122 | load_save(cur); 1123 | NEW_GAME = 0; 1124 | return 1; 1125 | } else { 1126 | mmEffect(SFX_NOPE); 1127 | } 1128 | } 1129 | } 1130 | } 1131 | } 1132 | --------------------------------------------------------------------------------