From: John Tsiombikas Date: Thu, 20 Oct 2022 03:05:46 +0000 (+0300) Subject: turns X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=gbajam22;a=commitdiff_plain;h=d489941c3101412810a6f355e35e027c7d51b350 turns --- diff --git a/Makefile b/Makefile index b7b0903..2789830 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ name = gbajam22 elf = $(name).elf bin = $(name).gba -data = data/color.raw data/color.pal data/height.raw +data = data/color.raw data/color.pal data/height.raw \ + data/spr_game.raw data/spr_game.pal libs = libs/maxmod/libmm.a diff --git a/src/data.h b/src/data.h index e3f3290..08dfa70 100644 --- a/src/data.h +++ b/src/data.h @@ -7,10 +7,13 @@ #define CONV_RGB24_RGB15(r, g, b) \ (((r) >> 3) | (((uint16_t)(g) & 0xf8) << 2) | (((uint16_t)(b) & 0xf8) << 7)) -#define VOX_SZ 256 +#define VOX_SZ 512 extern unsigned char color_pixels[]; extern unsigned char color_cmap[]; extern unsigned char height_pixels[]; +extern unsigned char spr_game_pixels[]; +extern unsigned char spr_game_cmap[]; + #endif /* DATA_H_ */ diff --git a/src/data.s b/src/data.s index 7a6431d..e18f11a 100644 --- a/src/data.s +++ b/src/data.s @@ -3,6 +3,8 @@ .globl color_pixels .globl color_cmap .globl height_pixels + .globl spr_game_pixels + .globl spr_game_cmap .align 1 color_pixels: @@ -13,3 +15,10 @@ color_cmap: .align 1 height_pixels: .incbin "data/height.raw" + + .align 1 +spr_game_pixels: + .incbin "data/spr_game.raw" + .align 1 +spr_game_cmap: + .incbin "data/spr_game.pal" diff --git a/src/gamescr.c b/src/gamescr.c index e3ff340..e330a28 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -30,7 +30,9 @@ static struct screen gamescr = { gamescr_vblank }; -static int nframes, num_vbl, backbuf; +static uint16_t *framebuf; + +static int nframes, backbuf; static uint16_t *vram[] = { gba_vram_lfb0, gba_vram_lfb1 }; static int32_t pos[2], angle; @@ -39,6 +41,8 @@ static struct voxscape *vox; #define COLOR_HORIZON 192 #define COLOR_ZENITH 255 +#define MAX_SPR 8 +static uint16_t oam[4 * MAX_SPR]; struct screen *init_game_screen(void) @@ -59,25 +63,37 @@ static int gamescr_start(void) if(!(vox = vox_create(VOX_SZ, VOX_SZ, height_pixels, color_pixels))) { panic(get_pc(), "vox_create"); } - vox_proj(vox, 45, 2, VOX_SZ / 5); + vox_proj(vox, 30, 2, 85); /* setup color image palette */ - for(i=0; i<192; i++) { + for(i=0; i<256; i++) { int r = color_cmap[i * 3]; int g = color_cmap[i * 3 + 1]; int b = color_cmap[i * 3 + 2]; gba_bgpal[i] = (((uint16_t)b << 7) & 0x7c00) | (((uint16_t)g << 2) & 0x3e0) | (((uint16_t)r >> 3) & 0x1f); } + /* + intr_disable(); + interrupt(INTR_HBLANK, hblank); + REG_DISPSTAT |= DISPSTAT_IEN_HBLANK; + unmask(INTR_HBLANK); + intr_enable(); + */ - /* setup sky gradient palette */ - for(i=0; i<64; i++) { - int t = (i << 8) / 64; - int r = (0xcc00 + (0x55 - 0xcc) * t) >> 8; - int g = (0x7700 + (0x88 - 0x77) * t) >> 8; - int b = (0xff00 + (0xcc - 0xff) * t) >> 8; - int cidx = COLOR_HORIZON + i; - gba_bgpal[cidx] = ((b << 7) & 0x7c00) | ((g << 2) & 0x3e0) | (r >> 3); - } + spr_setup(16, 2, spr_game_pixels, spr_game_cmap); + + wait_vblank(); + spr_clear(); + spr_oam(oam, 0, 516, 0, 144, SPR_SZ16 | SPR_256COL); + spr_oam(oam, 1, 516, 16, 144, SPR_SZ16 | SPR_256COL); + spr_oam(oam, 2, 516, 32, 144, SPR_SZ16 | SPR_256COL); + spr_oam(oam, 3, 520, 48, 144, SPR_SZ16 | SPR_256COL); + + spr_oam(oam, 4, 512, 176, 144, SPR_SZ16 | SPR_256COL); + spr_oam(oam, 5, 516, 192, 144, SPR_SZ16 | SPR_256COL); + spr_oam(oam, 6, 516, 208, 144, SPR_SZ16 | SPR_256COL); + spr_oam(oam, 7, 516, 224, 144, SPR_SZ16 | SPR_256COL); + dma_copy16(3, (void*)OAM_ADDR, oam, sizeof oam / 2, 0); nframes = 0; return 0; @@ -85,16 +101,15 @@ static int gamescr_start(void) static void gamescr_stop(void) { + /*mask(INTR_HBLANK);*/ } static void gamescr_frame(void) { - unsigned char *fb; - backbuf = ++nframes & 1; - fb = (unsigned char*)vram[backbuf]; + framebuf = vram[backbuf]; - vox_framebuf(vox, 240, 160, fb, -1); + vox_framebuf(vox, 240, 160, framebuf, -1); update(); draw(); @@ -106,21 +121,30 @@ static void gamescr_frame(void) if(!(nframes & 15)) { emuprint("vbl: %d", vblperf_count); } +#ifdef VBLBAR vblperf_begin(); +#else + vblperf_count = 0; +#endif } #define WALK_SPEED 0x40000 -#define TURN_SPEED 0x100 +#define TURN_SPEED 0x200 + +static volatile uint16_t input; static void update(void) { int32_t fwd[2], right[2]; - uint16_t input; if((input = read_input())) { - if(input & BN_LT) angle += TURN_SPEED; - if(input & BN_RT) angle -= TURN_SPEED; + if(input & BN_LT) { + angle += TURN_SPEED; + } + if(input & BN_RT) { + angle -= TURN_SPEED; + } fwd[0] = -SIN(angle); fwd[1] = COS(angle); @@ -144,19 +168,82 @@ static void update(void) pos[1] -= right[1]; } - vox_view(vox, pos[0], pos[1], -30, angle); + vox_view(vox, pos[0], pos[1], -40, angle); } } static void draw(void) { + dma_fill16(3, framebuf, 0, 240 * 160 / 2); + //fillblock_16byte(framebuf, 0, 240 * 160 / 16); + vox_render(vox); //vox_sky_grad(vox, COLOR_HORIZON, COLOR_ZENITH); - vox_sky_solid(vox, COLOR_ZENITH); + //vox_sky_solid(vox, COLOR_ZENITH); } +#define MAXBANK 0x100 + ARM_IWRAM static void gamescr_vblank(void) { - num_vbl++; + static int bank, bankdir, theta, scale; + int32_t sa, ca; + + theta = -(bank << 3); + scale = MAXBANK + (abs(bank) >> 3); + sa = SIN(theta) / scale; + ca = COS(theta) / scale; + + REG_BG2X = -ca * 120 - sa * 80 + (120 << 8); + REG_BG2Y = sa * 120 - ca * 80 + (80 << 8); + + REG_BG2PA = ca; + REG_BG2PB = sa; + REG_BG2PC = -sa; + REG_BG2PD = ca; + + if((input & (BN_LT | BN_RT)) == 0) { + if(bank) { + bank -= bankdir << 4; + } + } else if(input & BN_LT) { + bankdir = -1; + if(bank > -MAXBANK) bank -= 16; + } else if(input & BN_RT) { + bankdir = 1; + if(bank < MAXBANK) bank += 16; + } +} + +/* +static uint16_t skygrad[] __attribute__((section(".data"))) = { + + 0x662a, 0x660a, 0x660a, 0x660b, 0x660b, 0x660b, 0x660b, 0x6a0b, 0x6a0c, + 0x6a0c, 0x6a0c, 0x6a0c, 0x6a0c, 0x6a0d, 0x6a0d, 0x6a0d, 0x6a0d, 0x6a0d, + 0x6a0d, 0x6a0e, 0x6e0e, 0x6e0e, 0x6e0e, 0x6e0e, 0x6e0f, 0x6e0f, 0x6e0f, + 0x6e0f, 0x6e0f, 0x6e0f, 0x6e10, 0x6e10, 0x7210, 0x7210, 0x7210, 0x7211, + 0x7211, 0x7211, 0x71f1, 0x71f1, 0x71f2, 0x71f2, 0x71f2, 0x71f2, 0x71f2, + 0x75f2, 0x75f3, 0x75f3, 0x75f3, 0x75f3, 0x75f3, 0x75f4, 0x75f4, 0x75f4, + 0x75f4, 0x75f4, 0x75f5, 0x79f5, 0x79f5, 0x79f5, 0x79f5, 0x79f5, 0x79f6, + 0x79f6, 0x79f6, 0x79f6, 0x79f6, 0x79f7, 0x79f7, 0x79f7, 0x7df7, 0x7df7, + 0x7df7, 0x7df8, 0x7df8, 0x7df8, 0x7dd8, 0x7dd8, 0x7dd9, 0x7dd9, + + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, + 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9, 0x7dd9 +}; + +ARM_IWRAM +static void hblank(void) +{ + int vcount = REG_VCOUNT; + gba_bgpal[255] = skygrad[vcount]; } +*/ diff --git a/src/gba/main.c b/src/gba/main.c index 6e5dbc0..a520caf 100644 --- a/src/gba/main.c +++ b/src/gba/main.c @@ -51,9 +51,7 @@ int main(void) ARM_IWRAM static void vblank(void) { -#ifdef VBLBAR vblperf_count++; -#endif curscr->vblank(); diff --git a/src/gba/sprite.c b/src/gba/sprite.c index c77ae90..fdb0318 100644 --- a/src/gba/sprite.c +++ b/src/gba/sprite.c @@ -15,16 +15,18 @@ void spr_setup(int xtiles, int ytiles, unsigned char *pixels, unsigned char *cma for(j=0; j<8; j++) { *dst++ = src[j * 64]; *dst++ = src[j * 64 + 1]; + *dst++ = src[j * 64 + 2]; + *dst++ = src[j * 64 + 3]; } - src += 2; + src += 4; - if((i & 31) == 31) { + if((i & 15) == 15) { src += 7 * 64; /* skip to the next row of tiles (skip 7 rows of pixels) */ } } cptr = (uint16_t*)CRAM_OBJ_ADDR; - for(i=0; i<16; i++) { + for(i=0; i<128; i++) { unsigned char r = *cmap++ >> 3; unsigned char g = *cmap++ >> 3; unsigned char b = *cmap++ >> 3; diff --git a/src/gbaregs.h b/src/gbaregs.h index 3396cc9..d6126e1 100644 --- a/src/gbaregs.h +++ b/src/gbaregs.h @@ -347,7 +347,9 @@ #define DMACNT_32BIT 0x04000000 #define DMACNT_VBLANK 0x10000000 #define DMACNT_HBLANK 0x20000000 -#define DMACNT_SOUND 0x30000000 +#define DMACNT_SPECIAL 0x30000000 +#define DMACNT_SOUND DMACNT_SPECIAL +#define DMACNT_VIDEO DMACNT_SPECIAL #define DMACNT_IEN 0x40000000 #define DMACNT_EN 0x80000000 diff --git a/src/voxscape.c b/src/voxscape.c index 60c2781..b57cad4 100644 --- a/src/voxscape.c +++ b/src/voxscape.c @@ -10,13 +10,14 @@ /* hardcoded dimensions for the GBA */ #define FBWIDTH 240 #define FBHEIGHT 160 +#define FBPITCH 240 /* map size */ -#define XSZ 256 -#define YSZ 256 -#define XSHIFT 8 -#define XMASK 0xff -#define YMASK 0xff -#define HSCALE 20 +#define XSZ 512 +#define YSZ 512 +#define XSHIFT 9 +#define XMASK 0x1ff +#define YMASK 0x1ff +#define HSCALE 40 #define NO_LERP @@ -232,22 +233,25 @@ void vox_proj(struct voxscape *vox, int fov, int znear, int zfar) * for each column step along this line and compute height for each pixel * fill the visible (top) part of each column */ - +ARM_IWRAM void vox_render(struct voxscape *vox) { int i; vox_begin(vox); for(i=0; inslices; i++) { + /*if(i >= 10 && (i & 1) == 0) { + continue; + }*/ vox_render_slice(vox, i); } } +ARM_IWRAM void vox_begin(struct voxscape *vox) { int i; - memset(vox->fb, 0, FBWIDTH * FBHEIGHT); memset(vox->coltop, 0, FBWIDTH * sizeof *vox->coltop); if(!(vox->valid & SLICELEN)) { @@ -270,42 +274,14 @@ void vox_render_slice(struct voxscape *vox, int n) z = vox->znear + n; len = vox->slicelen[n] >> 8; - xstep = (((COS(vox->angle) >> 4) * len) >> 4) / FBWIDTH; - ystep = (((SIN(vox->angle) >> 4) * len) >> 4) / FBWIDTH; - - x = vox->x - SIN(vox->angle) * z - xstep * (FBWIDTH / 2); - y = vox->y + COS(vox->angle) * z - ystep * (FBWIDTH / 2); - - for(i=1; i> 16) & YMASK) << XSHIFT) + ((x >> 16) & XMASK); - if(offs == last_offs) { - hval = last_hval; - color = last_col; - } else { - hval = vox->height[offs] - vox->vheight; - hval = hval * HSCALE / (vox->znear + n) + vox->horizon; - if(hval > FBHEIGHT) hval = FBHEIGHT; - color = vox->color[offs]; - last_offs = offs; - last_hval = hval; - last_col = color; - } - if(hval > vox->coltop[col]) { - colstart = FBHEIGHT - hval; - colheight = hval - vox->coltop[col]; - fbptr = vox->fb + colstart * (FBWIDTH / 2) + i; + xstep = (((COS(vox->angle) >> 4) * len) >> 4) / (FBWIDTH / 2); + ystep = (((SIN(vox->angle) >> 4) * len) >> 4) / (FBWIDTH / 2); - for(j=0; jcoltop[col] = hval; - } - x += xstep; - y += ystep; + x = vox->x - SIN(vox->angle) * z - xstep * (FBWIDTH / 4); + y = vox->y + COS(vox->angle) * z - ystep * (FBWIDTH / 4); - col++; + for(i=0; i> 16) & YMASK) << XSHIFT) + ((x >> 16) & XMASK); if(offs == last_offs) { hval = last_hval; @@ -322,11 +298,11 @@ void vox_render_slice(struct voxscape *vox, int n) if(hval > vox->coltop[col]) { colstart = FBHEIGHT - hval; colheight = hval - vox->coltop[col]; - fbptr = vox->fb + colstart * (FBWIDTH / 2) + i; + fbptr = vox->fb + colstart * (FBPITCH / 2) + i; for(j=0; jcoltop[col] = hval; } @@ -338,37 +314,24 @@ void vox_render_slice(struct voxscape *vox, int n) ARM_IWRAM void vox_sky_solid(struct voxscape *vox, uint8_t color) { - int i, j, colh0, colh1, colhboth; + int i, j, colheight; uint16_t *fbptr; - for(i=1; ifb + i; - colh0 = FBHEIGHT - vox->coltop[i << 1]; - colh1 = FBHEIGHT - vox->coltop[(i << 1) + 1]; - colhboth = colh0 < colh1 ? colh0 : colh1; + colheight = FBHEIGHT - vox->coltop[i << 1]; - for(j=0; j colh1) { - for(j=colhboth; jhorizon; uint8_t grad[FBHEIGHT]; uint16_t *fbptr; @@ -381,27 +344,13 @@ void vox_sky_grad(struct voxscape *vox, uint8_t chor, uint8_t ctop) grad[i] = chor; } - for(i=1; ifb + i; - colh0 = FBHEIGHT - vox->coltop[i << 1]; - colh1 = FBHEIGHT - vox->coltop[(i << 1) + 1]; - colhboth = colh0 < colh1 ? colh0 : colh1; + colheight = FBHEIGHT - vox->coltop[i << 1]; - for(j=0; j colh1) { - for(j=colhboth; j