Skip to content

Commit

Permalink
Wonderful port, working this time
Browse files Browse the repository at this point in the history
  • Loading branch information
pinobatch committed Mar 29, 2024
1 parent 1abd380 commit f04e38b
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 63 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ __pycache__/
# these are unrelated to NES savtool's image format
/gameboy/gb240p.sav
/gba/build
/gba/240pee_mb.elf
/gba/240pee_mb.gba
/gba/240pee_mb.sav
/gba/240p*.elf
/gba/240p*.gba
/gba/*.sav
/gba/.map
/gba/compile_commands.json
/nes/obj/nes/*.s
/nes/obj/nes/*.sav
/nes/obj/nes/last-commit*
Expand Down
4 changes: 4 additions & 0 deletions gba/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
0.24 (future)
* Replace Grid and Linearity with Monoscope (thanks Lorenzoone)
* Sound test: add surround option
* Hill zone: scroll the top scanline too (thanks Lorenzoone)
* Shadow sprite: fix sprite when changing background
(thanks Lorenzoone)
* Port from libgba to libtonc
* Reflect rebranding of Twitter to X

0.23 (2023-03-03)
Expand Down
2 changes: 1 addition & 1 deletion gba/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Limits
Building
--------
Build requirements: GNU Coreutils and Make (use devkitPro MSYS on
Windows), devkitARM, libgba, Python 3, and Pillow.
Windows), devkitARM, libtonc, Python 3, and Pillow.

Under Windows, open a devkitPro MSYS and type `make`. Under Linux
or macOS, once you have installed `gba-dev` using pacman, type these:
Expand Down
68 changes: 34 additions & 34 deletions gba/src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,48 @@ The window
static void load_help_bg(void) {

// Load pattern table
LZ77UnCompVram(helpbgtiles_chrTiles, PATRAM4(3, 272));
LZ77UnCompVram(helpsprites_chrTiles, SPR_VRAM(CHARACTER_VRAM_BASE));
LZ77UnCompVram(helpbgtiles_chrTiles, tile_mem[3][272].data);
LZ77UnCompVram(helpsprites_chrTiles, tile_mem_obj[0][CHARACTER_VRAM_BASE].data);

// Clear VWF canvas
dma_memset16(PATRAM4(3, 0), 0x1111 * FG_BGCOLOR, 32*WINDOW_WIDTH*17);
memset16(tile_mem[3][0].data, 0x1111 * FG_BGCOLOR, 16*WINDOW_WIDTH*17);

// Load background SCREENMAT
dma_memset16(MAP[BGMAP][0], TILE_BACK_WALL, 64*(BACK_WALL_HT - 1));
dma_memset16(MAP[BGMAP][BACK_WALL_HT - 1], TILE_BACK_WALL_BOTTOM, 30*2);
dma_memset16(MAP[BGMAP][BACK_WALL_HT], TILE_FLOOR_TOP, 30*2);
dma_memset16(MAP[BGMAP][BACK_WALL_HT + 1], TILE_FLOOR, 64*(19 - BACK_WALL_HT));
memset16(se_mat[BGMAP][0], TILE_BACK_WALL, 32*(BACK_WALL_HT - 1));
memset16(se_mat[BGMAP][BACK_WALL_HT - 1], TILE_BACK_WALL_BOTTOM, 30);
memset16(se_mat[BGMAP][BACK_WALL_HT], TILE_FLOOR_TOP, 30);
memset16(se_mat[BGMAP][BACK_WALL_HT + 1], TILE_FLOOR, 32*(19 - BACK_WALL_HT));
for (unsigned int x = 0; x < 4; ++x) {
// ccccvhtt tttttttt
MAP[BGMAP][SHADOW_Y][SHADOW_X + x] = TILE_FLOOR_SHADOW + x;
MAP[BGMAP][SHADOW_Y][SHADOW_X + 4 + x] = TILE_FLOOR_SHADOW + 0x0403 - x;
MAP[BGMAP][SHADOW_Y + 1][SHADOW_X + x] = TILE_FLOOR_SHADOW + 0x0800 + x;
MAP[BGMAP][SHADOW_Y + 1][SHADOW_X + 4 + x] = TILE_FLOOR_SHADOW + 0x0C03 - x;
se_mat[BGMAP][SHADOW_Y][SHADOW_X + x] = TILE_FLOOR_SHADOW + x;
se_mat[BGMAP][SHADOW_Y][SHADOW_X + 4 + x] = TILE_FLOOR_SHADOW + 0x0403 - x;
se_mat[BGMAP][SHADOW_Y + 1][SHADOW_X + x] = TILE_FLOOR_SHADOW + 0x0800 + x;
se_mat[BGMAP][SHADOW_Y + 1][SHADOW_X + 4 + x] = TILE_FLOOR_SHADOW + 0x0C03 - x;
}

// Clear window SCREENMAT
dma_memset16(MAP[FGMAP], TILE_FG_BLANK, 32*21*2);
dma_memset16(MAP[FGMAP + 1], TILE_FG_XPARENT, 32*21*2);
memset16(se_mat[FGMAP], TILE_FG_BLANK, 32*21);
memset16(se_mat[FGMAP + 1], TILE_FG_XPARENT, 32*21);

// Left border
MAP[FGMAP][0][0] = TILE_FG_CORNER1;
MAP[FGMAP][1][0] = TILE_FG_CORNER2;
se_mat[FGMAP][0][0] = TILE_FG_CORNER1;
se_mat[FGMAP][1][0] = TILE_FG_CORNER2;
for (unsigned int i = 2; i < 19; ++i) {
MAP[FGMAP][i][0] = TILE_FG_LEFT;
se_mat[FGMAP][i][0] = TILE_FG_LEFT;
}
MAP[FGMAP][19][0] = TILE_FG_CORNER2 + 0x0800;
MAP[FGMAP][20][0] = TILE_FG_CORNER1 + 0x0800;
se_mat[FGMAP][19][0] = TILE_FG_CORNER2 + 0x0800;
se_mat[FGMAP][20][0] = TILE_FG_CORNER1 + 0x0800;

// Divider lines
dma_memset16(&(MAP[FGMAP][2][1]), TILE_FG_DIVIDER, 16*2);
dma_memset16(&(MAP[FGMAP][18][1]), TILE_FG_DIVIDER, 16*2);
memset16(&(se_mat[FGMAP][2][1]), TILE_FG_DIVIDER, 16);
memset16(&(se_mat[FGMAP][18][1]), TILE_FG_DIVIDER, 16);

// Make the frame
loadMapRowMajor(&(MAP[FGMAP][1][1]), 0*WINDOW_WIDTH,
loadMapRowMajor(&(se_mat[FGMAP][1][1]), 0*WINDOW_WIDTH,
WINDOW_WIDTH, 1);
loadMapRowMajor(&(MAP[FGMAP][3][1]), 1*WINDOW_WIDTH,
loadMapRowMajor(&(se_mat[FGMAP][3][1]), 1*WINDOW_WIDTH,
WINDOW_WIDTH, PAGE_MAX_LINES);
loadMapRowMajor(&(MAP[FGMAP][4+PAGE_MAX_LINES][1]), (PAGE_MAX_LINES + 1)*WINDOW_WIDTH,
loadMapRowMajor(&(se_mat[FGMAP][4+PAGE_MAX_LINES][1]), (PAGE_MAX_LINES + 1)*WINDOW_WIDTH,
WINDOW_WIDTH, 1);

help_bg_loaded = 1;
Expand Down Expand Up @@ -186,8 +186,8 @@ static void help_draw_cursor(unsigned int objx) {

static void help_draw_page(helpdoc_kind doc_num, unsigned int left, unsigned int keymask) {
// Draw document title
dma_memset16(PATRAM4(3, 0), FG_BGCOLOR*0x1111, WINDOW_WIDTH * 32);
vwf8Puts(PATRAM4(3, 0), helptitles[doc_num], 0, FG_FGCOLOR);
memset16(tile_mem[3][0].data, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 16);
vwf8Puts(tile_mem[3][0].data, helptitles[doc_num], 0, FG_FGCOLOR);

// Look up the address of the start of this page's text
help_cur_page = help_wanted_page;
Expand All @@ -196,9 +196,9 @@ static void help_draw_page(helpdoc_kind doc_num, unsigned int left, unsigned int

// Draw lines of text to the screen
while (y < PAGE_MAX_LINES) {
u32 *dst = PATRAM4(3, (y + 1)*WINDOW_WIDTH);
u32 *dst = tile_mem[3][(y + 1)*WINDOW_WIDTH].data;
++y;
dma_memset16(dst, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 32);
memset16(dst, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 16);
src = vwf8Puts(dst, src, left, FG_FGCOLOR);

// Break on NUL terminator or skip others
Expand All @@ -208,8 +208,8 @@ static void help_draw_page(helpdoc_kind doc_num, unsigned int left, unsigned int

// Clear unused lines that had been used
for (unsigned int clear_y = y; clear_y < help_height; ++clear_y) {
u32 *dst = PATRAM4(3, (clear_y + 1)*WINDOW_WIDTH);
dma_memset16(dst, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 32);
u32 *dst = tile_mem[3][(clear_y + 1)*WINDOW_WIDTH].data;
memset16(dst, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 16);
}

// Save how many lines are used and move the cursor up if needed
Expand All @@ -220,22 +220,22 @@ static void help_draw_page(helpdoc_kind doc_num, unsigned int left, unsigned int

// Draw status line depending on size of document and which
// keys are enabled
u32 *dst = PATRAM4(3, (PAGE_MAX_LINES + 1)*WINDOW_WIDTH);
dma_memset16(dst, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 32);
u32 *dst = tile_mem[3][(PAGE_MAX_LINES + 1)*WINDOW_WIDTH].data;
memset16(dst, FG_BGCOLOR*0x1111, WINDOW_WIDTH * 16);

if (help_cumul_pages[doc_num + 1] - help_cumul_pages[doc_num] > 1) {
posprintf(help_line_buffer, "\x1D %d/%d \x1C",
help_wanted_page - help_cumul_pages[doc_num] + 1,
help_cumul_pages[doc_num + 1] - help_cumul_pages[doc_num]);
vwf8Puts(PATRAM4(3, (PAGE_MAX_LINES + 1)*WINDOW_WIDTH),
vwf8Puts(tile_mem[3][(PAGE_MAX_LINES + 1)*WINDOW_WIDTH].data,
help_line_buffer, 0, FG_FGCOLOR);
}
if (keymask & KEY_UP) {
vwf8Puts(PATRAM4(3, (PAGE_MAX_LINES + 1)*WINDOW_WIDTH),
vwf8Puts(tile_mem[3][(PAGE_MAX_LINES + 1)*WINDOW_WIDTH].data,
"\x1E\x1F""A: Select", 40, FG_FGCOLOR);
}
if (keymask & KEY_B) {
vwf8Puts(PATRAM4(3, (PAGE_MAX_LINES + 1)*WINDOW_WIDTH),
vwf8Puts(tile_mem[3][(PAGE_MAX_LINES + 1)*WINDOW_WIDTH].data,
"B: Exit", WINDOW_WIDTH * 8 - 28, FG_FGCOLOR);
}
}
Expand Down
31 changes: 13 additions & 18 deletions gba/src/placeholder.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ it freely, subject to the following restrictions:
"Source" is the preferred form of a work for making changes to it.
*/
#include <tonc.h>
#include <string.h>
#include "global.h"

#include "bggfx_chr.h"
#include "spritegfx_chr.h"

Expand All @@ -43,7 +40,7 @@ unsigned short player_facing = 0;
#define OBJ_VRAM_BASE 16

static void load_player(void) {
LZ77UnCompVram(spritegfx_chrTiles, SPR_VRAM(16));
LZ77UnCompVram(spritegfx_chrTiles, &(tile_mem_obj[0][16].data));
player_x = 56 << 8;
player_dx = player_frame = player_facing = 0;
}
Expand Down Expand Up @@ -131,41 +128,39 @@ static const unsigned short bgcolors10[16] = {
};

static void put1block(unsigned int x, unsigned int y) {
MAP[PFMAP][y][x] = 12 | 0x0000;
MAP[PFMAP][y][x+1] = 13 | 0x0000;
MAP[PFMAP][y+1][x] = 14 | 0x0000;
MAP[PFMAP][y+1][x+1] = 15 | 0x0000;
se_mat[PFMAP][y][x] = 12 | 0x0000;
se_mat[PFMAP][y][x+1] = 13 | 0x0000;
se_mat[PFMAP][y+1][x] = 14 | 0x0000;
se_mat[PFMAP][y+1][x+1] = 15 | 0x0000;
}

void load_common_bg_tiles(void) {
bitunpack2(PATRAM4(0, 0), bggfx_chrTiles, sizeof(bggfx_chrTiles));
bitunpack2(&(tile_mem[0][0].data), bggfx_chrTiles, sizeof(bggfx_chrTiles));
}

void load_common_obj_tiles(void) {
bitunpack2(SPR_VRAM(0), bggfx_chrTiles, sizeof(bggfx_chrTiles));
bitunpack2(&(tile_mem_obj[0][0].data), bggfx_chrTiles, sizeof(bggfx_chrTiles));
}

static void draw_bg(void) {
load_common_bg_tiles();

// Draw background map: sky, top row of floor, bottom row of floor
dma_memset16(MAP[PFMAP][0], 0x0004, 2*32*18);
dma_memset16(MAP[PFMAP][18], 11 | 0x1000, 2*30);
dma_memset16(MAP[PFMAP][19], 1 | 0x1000, 2*30);
memset16(se_mat[PFMAP][0], 0x0004, 32*18);
memset16(se_mat[PFMAP][18], 11 | 0x1000, 30);
memset16(se_mat[PFMAP][19], 1 | 0x1000, 30);
put1block(2, 14);
put1block(2, 16);
put1block(26, 14);
put1block(26, 16);

// sorry I was gone
const char return_msg[] =
"\x08""\x08""In May 2018,\n"
"\x22""\x10""Pino returned to the GBA scene.";

"\x08""\x08""In March 2024,\n"
"\x22""\x10""Pino switched to Wonderful Toolchain.";
vwfDrawLabels(return_msg, PFMAP, 0x1000 + 32);
}

void lame_boy_demo() {
void lame_boy_demo(void) {
// Forced blanking
REG_DISPCNT = DCNT_BLANK;
draw_bg();
Expand Down
6 changes: 3 additions & 3 deletions gba/src/vwflabels.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ void vwfDrawLabels(const char *labelset, unsigned int sbb, unsigned int tilenum)
txtw = (((txtw - 1) | 0x07) + 1) >> 3; // Round up to whole tile

// Clear this many tiles to color 0 and draw into them using color 1
void *chrdst = PATRAM4(0, tilenum & 0x07FF);
dma_memset16(chrdst, 0x0000, 32 * txtw);
void *chrdst = &(tile_mem[0][tilenum & 0x07FF].data);
memset16(chrdst, 0x0000, 16 * txtw);
const char *strend = vwf8Puts(chrdst, labelset + 2, x & 0x07, 1);

// Fill the SCREENMAT
loadMapRowMajor(&(MAP[sbb][y >> 3][x >> 3]), tilenum & 0xF3FF, txtw, 1);
loadMapRowMajor(&(se_mat[sbb][y >> 3][x >> 3]), tilenum & 0xF3FF, txtw, 1);
tilenum += txtw;

if (*strend == 0) break;
Expand Down
3 changes: 0 additions & 3 deletions gba/tonc_migration.txt

This file was deleted.

3 changes: 3 additions & 0 deletions gba/tools/paginate_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def render_help(docs, defines=None):
lines.append('helptitles:')
lines.extend(' .word helptitle_%s' % doc[1] for doc in docs)

# ensure files end with newline
lines.extend("")
lines_header.extend("")
return ["\n".join(lines), "\n".join(lines_header)]

def parse_define(s):
Expand Down
3 changes: 2 additions & 1 deletion gba/tools/vwfbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def main(argv=None):
"#define VWFCHR_H__",
"extern const unsigned char vwfChrData[" + str(int(len(tiledata) / 8)) + "][8];\n"
"extern const unsigned char vwfChrWidths[" + str(len(widths)) + "];\n"
"#endif"]
"#endif",
'']
with open(argv[3], 'w') as outfp:
outfp.write('\n'.join(out))

Expand Down
Loading

0 comments on commit f04e38b

Please sign in to comment.