Skip to content

Commit

Permalink
Fix last cave barrier and more graphical issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andwn committed Feb 22, 2022
1 parent b30f546 commit a51b87f
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 64 deletions.
4 changes: 2 additions & 2 deletions boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ RomStart:

RomHeader:
.ascii "SEGA MEGA DRIVE "
.ascii "GRIND 2022.JAN"
.ascii "GRIND 2022.FEB"
.ascii "Doukutsu Monogatari MD "
.ascii "Cave Story MD "
.ascii "GM ANDYG002-A7"
.ascii "GM ANDYG002-A8"
dc.w 0
.ascii "J6 "
dc.l 0x000000
Expand Down
2 changes: 1 addition & 1 deletion inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef uint32_t u32;
//#define PROFILE_BG
#ifdef PROFILE_BG
#define PF_BGCOLOR(c) ({ \
*((volatile uint32_t*) 0xC00004) = GFX_WRITE_CRAM_ADDR(0); \
*((volatile uint32_t*) 0xC00004) = 0xC0000000; \
*((volatile uint16_t*) 0xC00000) = c; \
})
#else
Expand Down
8 changes: 4 additions & 4 deletions inc/sheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
#define SHEET_LOAD(sdef, frames, fsize, index, dma, ...) { \
static const uint8_t fa[frames<<1] = { __VA_ARGS__ }; \
for(uint16_t i = 0; i < frames; i++) { \
if(fa[i<<1] >= (sdef)->numAnimation) \
error_other("Anim out of range"); \
if(fa[(i<<1)+1] >= (sdef)->animations[fa[i<<1]]->numFrame) \
error_other("Frame out of range"); \
/*if(fa[i<<1] >= (sdef)->numAnimation) */ \
/* error_other("Anim out of range"); */ \
/*if(fa[(i<<1)+1] >= (sdef)->animations[fa[i<<1]]->numFrame) */ \
/* error_other("Frame out of range"); */ \
vdp_tiles_load_from_rom(SPR_TILES(sdef,fa[i<<1],fa[(i<<1)+1]),(index)+i*(fsize),fsize);\
} \
}
Expand Down
6 changes: 1 addition & 5 deletions src/ai/balrog.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,13 @@ void ai_balrog_drop_in(Entity *e) {
e->state = 1;
e->grounded = FALSE;
e->frame = ARMSUP; // falling;
//e->x -= pixel_to_sub(16);
}
/* fallthrough */
case 1:
{
// since balrog often falls through the ceiling we must wait until he is
// free-falling before we start checking to see if he hit the floor
uint16_t x = sub_to_block(e->x), y = sub_to_block(e->y);
if(((stage_get_block_type(x, y-1) | stage_get_block_type(x, y+1)) & 0x41) != 0x41) {
if(((blk(e->x, 0, e->y, -16) | blk(e->x, 0, e->y, 0) | blk(e->x, 0, e->y, 16)) & 0x41) != 0x41) {
e->state = 2;
}
}
Expand All @@ -330,8 +328,6 @@ void ai_balrog_drop_in(Entity *e) {
e->frame = DUCK;
e->state = 3;
e->timer = 0;

//SmokeSide(o, 4, DOWN);
camera_shake(30);
}
}
Expand Down
17 changes: 4 additions & 13 deletions src/ai/lastcave.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ void ai_red_demon(Entity *e) {
case 50:
{
e->frame = 4;
//EmFireAngledShot(o, OBJ_RED_DEMON_SHOT, 0, 0x800);
Entity *shot = entity_create(e->x, e->y, OBJ_RED_DEMON_SHOT, 0);
THROW_AT_TARGET(shot, player.x, player.y, 0x800);
sound_play(SND_EM_FIRE, 5);
Expand Down Expand Up @@ -257,7 +256,6 @@ void ai_red_demon(Entity *e) {
case 50:
{
e->frame = 6;
//EmFireAngledShot(o, OBJ_RED_DEMON_SHOT, 0, 0x800);
Entity *shot = entity_create(e->x, e->y, OBJ_RED_DEMON_SHOT, 0);
THROW_AT_TARGET(shot, player.x, player.y, 0x800);
sound_play(SND_EM_FIRE, 5);
Expand Down Expand Up @@ -302,28 +300,21 @@ void ai_red_demon(Entity *e) {
{
e->flags &= ~NPC_SHOOTABLE;
e->attack = 0;

if (e->grounded) {
e->state = 51;
e->frame = 2;

camera_shake(10);
//SmokeClouds(o, 12, 4, 4);
//e->SpawnXP(19);

sound_play(SND_BIG_CRASH, 6);

// needed to prevent status bars from not disappearing
//game.bossbar.object = NULL;
}
}
break;

case 51:
{
e->x_speed *= 7;
e->x_speed /= 8;

if(e->x_speed) {
e->x_speed *= 7;
e->x_speed /= 8;
}
e->frame = 8;
}
break;
Expand Down
1 change: 0 additions & 1 deletion src/ai/monsterx.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ void ai_monsterx(Entity *e) {
entities_clear_by_type(OBJ_X_DOOR);
entities_clear_by_type(OBJ_X_TREAD);
entities_clear_by_type(OBJ_X_INTERNALS);
entities_clear_by_type(OBJ_FORCEFIELD);
player.grounded = FALSE; // Stop player from floating where treads were
playerPlatform = NULL; // I SAID STOP DAMMIT
e->state = STATE_DELETE;
Expand Down
7 changes: 0 additions & 7 deletions src/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ void song_play(uint8_t id) {
xgm_music_pause();
vdp_vsync(); aftervsync();
vdp_vsync();
// Linker puts real addresses, need to adjust to use mapped one
//uint32_t address = (uint32_t) song_info[id].song;
//uint16_t chunk = address >> 19;
//if(chunk >= 7) {
// ssf_setbank(7, chunk);
// address = 0x380000 | (address & 0x7FFFF);
//}
xgm_music_play(song_info[id].song);
}
songPlaying = id;
Expand Down
4 changes: 2 additions & 2 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ void entities_replace(uint16_t event, uint16_t type, uint8_t direction, uint16_t
// number of sprites
int32_t x = e->x;
int32_t y = e->y;
flags |= e->flags;
if(type > 0) flags |= e->flags;
uint16_t id = e->id;
e = entity_delete(e);
Entity *new = entity_create_ext(x, y, type, flags, id, event);
Expand All @@ -979,7 +979,7 @@ void entities_replace(uint16_t event, uint16_t type, uint8_t direction, uint16_t
if(e->event == event) {
int32_t x = e->x;
int32_t y = e->y;
flags |= e->flags;
if(type > 0) flags |= e->flags;
uint16_t id = e->id;
e = entity_delete_inactive(e); // So Balrog doesn't delete every entity in the room
Entity *new = entity_create_ext(x, y, type, flags, id, event);
Expand Down
14 changes: 11 additions & 3 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ void game_main(uint8_t load) {
//vdp_color(15, 0x000);
// This is the SGDK font with a blue background for the message window
if(cfg_language != LANG_JA) {
disable_ints;
z80_request();
vdp_font_load(TS_MsgFont.tiles);
z80_release();
enable_ints;
}
effects_init();
game_reset(load);
Expand All @@ -50,11 +54,9 @@ void game_main(uint8_t load) {

while(TRUE) {
PF_BGCOLOR(0x000);
//#ifdef PROFILE_BG
//vdp_set_backcolor(0);
//#endif

if(paused) {
PF_BGCOLOR(0x0E0);
paused = update_pause();
} else {
// Pressing start opens the item menu (unless a script is running)
Expand Down Expand Up @@ -105,13 +107,16 @@ void game_main(uint8_t load) {
vdp_set_display(TRUE);
} else {
// HUD on top
PF_BGCOLOR(0x00E);
hud_update();
// Boss health, camera
PF_BGCOLOR(0x0EE);
if(!gameFrozen) {
if(showingBossHealth) tsc_update_boss_health();
camera_update();
}
// Run the next set of commands in a script if it is running
PF_BGCOLOR(0x0E0);
uint8_t rtn = tsc_update();
// Nonzero return values exit the game, or switch to the ending sequence
if(rtn > 0) {
Expand All @@ -136,12 +141,15 @@ void game_main(uint8_t load) {
break;
}
}
PF_BGCOLOR(0xEE0);
window_update();
// Handle controller locking
uint16_t lockstate = joystate, oldlockstate = oldstate;
if(controlsLocked) joystate = oldstate = 0;
// Don't update this stuff if a script is using <PRI
PF_BGCOLOR(0xE00);
effects_update();
PF_BGCOLOR(0xE0E);
if(!gameFrozen) {
player_update();
entities_update(TRUE);
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ void aftervsync() {
if(ready) {
if(inFade) vdp_sprites_clear();
vdp_sprites_update();
if(gamemode == GM_GAME) stage_update(); // Scrolling
ready = FALSE;
}
if(gamemode == GM_GAME) stage_update(); // Scrolling
//joy_update();

z80_release();
Expand Down
15 changes: 15 additions & 0 deletions src/pause.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void draw_itemmenu(uint8_t resetCursor) {
vdp_map_xy(VDP_PLAN_W, WINDOW_ATTR(8), 38, y);
vdp_map_xy(VDP_PLAN_W, 0, 39, y);

disable_ints;
z80_request();
// Load the 4 tiles for the selection box. Since the menu can never be brought up
// during scripts we overwrite the face image
vdp_tiles_load_from_rom(TS_ItemSel.tiles, TILE_FACEINDEX, TS_ItemSel.numTile);
Expand Down Expand Up @@ -164,6 +166,8 @@ void draw_itemmenu(uint8_t resetCursor) {
itemSprite[i] = (VDPSprite) {};
}
}
z80_release();
enable_ints;
// Draw item cursor at first index (default selection)
if(resetCursor) {
selectedItem = -6 + currentWeapon;
Expand Down Expand Up @@ -208,15 +212,26 @@ uint8_t update_pause() {
hud_show();
hud_force_redraw();
vdp_sprites_clear();

disable_ints;
z80_request();
vdp_tiles_load_from_rom(TILE_BLANK,TILE_HUDINDEX+8,1);
vdp_tiles_load_from_rom(TILE_BLANK,TILE_HUDINDEX+9,1);
vdp_tiles_load_from_rom(TILE_BLANK,TILE_HUDINDEX+12,1);
vdp_tiles_load_from_rom(TILE_BLANK,TILE_HUDINDEX+13,1);
z80_release();
enable_ints;
aftervsync();
// Reload shared sheets we clobbered
disable_ints;
z80_request();
sheets_load_stage(stageID, TRUE, FALSE);
z80_release();
enable_ints;

selectedItem = 0;
aftervsync();

// Reload TSC Events for the current stage
tsc_load_stage(stageID);
// Put the sprites for player/entities/HUD back
Expand Down
17 changes: 17 additions & 0 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "weapon.h"

#include "player.h"
#include "xgm.h"

#define PLAYER_SPRITE_TILES_QUEUE() ({ \
uint8_t f = player.frame + ((playerEquipment & EQUIP_MIMIMASK) ? 10 : 0); \
Expand Down Expand Up @@ -1068,7 +1069,11 @@ uint8_t player_inflict_damage(uint16_t damage) {
w->level -= 1;
w->energy += weapon_info[w->type].experience[w->level - 1];
w->energy -= damage;
disable_ints;
z80_request();
sheets_refresh_weapon(w);
z80_release();
enable_ints;
entity_create(player.x, player.y,
cfg_language == LANG_JA ? OBJ_LEVELDOWN_JA : OBJ_LEVELDOWN, 0);
} else {
Expand Down Expand Up @@ -1139,7 +1144,11 @@ void player_give_weapon(uint8_t id, uint8_t ammo) {
TILES_QUEUE(SPR_TILES(weapon_info[WEAPON_POLARSTAR].sprite,0,0),
TILE_WEAPONINDEX,6);
}
disable_ints;
z80_request();
sheets_load_weapon(w);
z80_release();
enable_ints;
break;
}
} else {
Expand Down Expand Up @@ -1185,7 +1194,11 @@ void player_trade_weapon(uint8_t id_take, uint8_t id_give, uint8_t ammo) {
w->maxammo = ammo;
w->ammo = ammo;
}
disable_ints;
z80_request();
sheets_load_weapon(w);
z80_release();
enable_ints;
}
}

Expand All @@ -1196,11 +1209,15 @@ void player_refill_ammo() {
}

void player_delevel_weapons() {
disable_ints;
z80_request();
for(uint8_t i = 0; i < MAX_WEAPONS; i++) {
playerWeapon[i].level = 1;
playerWeapon[i].energy = 0;
sheets_refresh_weapon(&playerWeapon[i]);
}
z80_release();
enable_ints;
}

void player_heal(uint8_t health) {
Expand Down
5 changes: 5 additions & 0 deletions src/saveselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "vdp.h"
#include "weapon.h"
#include "window.h"
#include "xgm.h"

#include "gamemode.h"

Expand Down Expand Up @@ -56,6 +57,8 @@ static uint8_t refresh_file(uint8_t index) {
SaveEntry file;

system_peekdata(index, &file);
disable_ints;
z80_request();
vdp_text_clear(VDP_PLAN_A, 6, y, 16); // Erase any previous stage name text
if(cfg_language >= LANG_JA && cfg_language <= LANG_KO) {
vdp_text_clear(VDP_PLAN_A, 6, y+1, 16); // And a second line underneath
Expand Down Expand Up @@ -140,6 +143,8 @@ static uint8_t refresh_file(uint8_t index) {
vdp_text_clear(VDP_PLAN_A, 24, y+2, 12);
vdp_text_clear(VDP_PLAN_A, 24, y+3, 12);
}
z80_release();
enable_ints;
return file.used;
}

Expand Down
Loading

0 comments on commit a51b87f

Please sign in to comment.