diff --git a/inc/common.h b/inc/common.h index 8fbd3690..5cd9dc63 100644 --- a/inc/common.h +++ b/inc/common.h @@ -32,7 +32,7 @@ uint8_t FPS; // just match the index, and on NTSC they are roughly index*5/6 for speed and // index*6/5 for time respectively. uint16_t time_tab[0x100]; -uint16_t speed_tab[0x100]; +int16_t speed_tab[0x100]; // Default is a bit slow due to branching, but compensates in case x is too large // Negative values are invalid. Always use -SPEED(x) instead of SPEED(-x) @@ -81,19 +81,19 @@ const int16_t cos2[0x100]; // pixel - single dot on screen (1x1) // tile - genesis VDP tile (8x8) // block - Cave Story tile (16x16) -#define sub_to_pixel(x) ((x)>>CSF) +#define sub_to_pixel(x) ((x)>>9) #define sub_to_tile(x) ((x)>>12) #define sub_to_block(x) ((x)>>13) -#define pixel_to_sub(x) ((x)<>3) #define pixel_to_block(x) ((x)>>4) -#define tile_to_sub(x) ((x)<<12) +#define tile_to_sub(x) (((int32_t)(x))<<12) #define tile_to_pixel(x) ((x)<<3) #define tile_to_block(x) ((x)>>1) -#define block_to_sub(x) ((x)<<13) +#define block_to_sub(x) (((int32_t)(x))<<13) #define block_to_pixel(x) ((x)<<4) #define block_to_tile(x) ((x)<<1) diff --git a/inc/player.h b/inc/player.h index 6021fc3f..fef26f43 100644 --- a/inc/player.h +++ b/inc/player.h @@ -70,7 +70,7 @@ void player_draw(); uint8_t player_invincible(); // Inflict damage on the player, will start the animation, knockback, red numbers, // sound, iframes, and check for death -uint8_t player_inflict_damage(int16_t damage); +uint8_t player_inflict_damage(uint16_t damage); // Makes the player sprite visible/invisible void player_show(); diff --git a/inc/stdint.h b/inc/stdint.h index ea9883c6..2f1adf08 100644 --- a/inc/stdint.h +++ b/inc/stdint.h @@ -4,11 +4,11 @@ typedef signed char int8_t; typedef signed short int16_t; -typedef signed int int32_t; +typedef signed long int32_t; typedef unsigned char uint8_t; typedef unsigned short uint16_t; -typedef unsigned int uint32_t; +typedef unsigned long uint32_t; // SGDK Compatibility diff --git a/inc/vdp.h b/inc/vdp.h index 6a70ec74..596453b5 100644 --- a/inc/vdp.h +++ b/inc/vdp.h @@ -228,55 +228,55 @@ * \brief * Set VDP command to read specified VRAM address. */ -#define GFX_READ_VRAM_ADDR(adr) ((0x0000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x00) +#define GFX_READ_VRAM_ADDR(adr) ((0x0000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x00) /** * \brief * Set VDP command to read specified CRAM address. */ -#define GFX_READ_CRAM_ADDR(adr) ((0x0000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x20) +#define GFX_READ_CRAM_ADDR(adr) ((0x0000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x20) /** * \brief * Set VDP command to read specified VSRAM address. */ -#define GFX_READ_VSRAM_ADDR(adr) ((0x0000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x10) +#define GFX_READ_VSRAM_ADDR(adr) ((0x0000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x10) /** * \brief * Set VDP command to write at specified VRAM address. */ -#define GFX_WRITE_VRAM_ADDR(adr) ((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x00) +#define GFX_WRITE_VRAM_ADDR(adr) ((0x4000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x00) /** * \brief * Set VDP command to write at specified CRAM address. */ -#define GFX_WRITE_CRAM_ADDR(adr) ((0xC000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x00) +#define GFX_WRITE_CRAM_ADDR(adr) ((0xC000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x00) /** * \brief * Set VDP command to write at specified VSRAM address. */ -#define GFX_WRITE_VSRAM_ADDR(adr) ((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x10) +#define GFX_WRITE_VSRAM_ADDR(adr) ((0x4000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x10) /** * \brief * Set VDP command to issue a DMA transfert to specified VRAM address. */ -#define GFX_DMA_VRAM_ADDR(adr) ((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x80) +#define GFX_DMA_VRAM_ADDR(adr) ((0x4000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x80) /** * \brief * Set VDP command to issue a DMA transfert to specified CRAM address. */ -#define GFX_DMA_CRAM_ADDR(adr) ((0xC000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x80) +#define GFX_DMA_CRAM_ADDR(adr) ((0xC000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x80) /** * \brief * Set VDP command to issue a DMA transfert to specified VSRAM address. */ -#define GFX_DMA_VSRAM_ADDR(adr) ((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x90) +#define GFX_DMA_VSRAM_ADDR(adr) ((0x4000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0x90) /** * \brief * Set VDP command to issue a DMA VRAM copy to specified VRAM address. */ -#define GFX_DMA_VRAMCOPY_ADDR(adr) ((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0xC0) +#define GFX_DMA_VRAMCOPY_ADDR(adr) ((0x4000 + (((uint32_t)(adr)) & 0x3FFF)) << 16) + ((((uint32_t)(adr)) >> 14) | 0xC0) /** * \brief diff --git a/src/ai/balfrog.c b/src/ai/balfrog.c index f9e8bed8..095f06ff 100644 --- a/src/ai/balfrog.c +++ b/src/ai/balfrog.c @@ -343,7 +343,7 @@ void ai_balfrog(Entity *e) { if(e->timer <= TIME_8(150)) { Entity *balrog = entity_find_by_type(OBJ_BALROG); if(balrog) { - e->hidden ^= 1; + e->hidden = (e->timer & 2); balrog->hidden = !e->hidden; } } diff --git a/src/ai/ballos2.c b/src/ai/ballos2.c index b606f741..af1bf540 100644 --- a/src/ai/ballos2.c +++ b/src/ai/ballos2.c @@ -568,8 +568,8 @@ void ai_ballos_target(Entity *e) { } /* fallthrough */ case 1: { - e->hidden ^= 1; - if (++e->timer == TIME_8(20)) { // lightning attack + e->hidden = (++e->timer & 2); + if (e->timer == TIME_8(20)) { // lightning attack if(!e->dir) entity_create(e->x_mark, e->y_mark - 0x2000, OBJ_LIGHTNING, NPC_OPTION2); } else if(e->timer >= TIME_8(30)) { e->state = STATE_DELETE; diff --git a/src/ai/basic.c b/src/ai/basic.c index 2a304170..3bb29bb9 100644 --- a/src/ai/basic.c +++ b/src/ai/basic.c @@ -351,7 +351,7 @@ void onspawn_teleLight(Entity *e) { } void ai_teleLight(Entity *e) { - if(e->state) e->hidden ^= 1; + if(e->state) e->hidden = (++e->timer & 2); else e->hidden = TRUE; } @@ -408,8 +408,8 @@ void ai_player(Entity *e) { } /* fallthrough */ case 21: { - e->hidden ^= 1; - if(++e->timer > TIME_8(50)) { + e->hidden = (++e->timer & 2); + if(e->timer > TIME_8(50)) { e->state = STATE_DELETE; } } diff --git a/src/ai/doctorm.c b/src/ai/doctorm.c index 838b5c78..5c246cfa 100644 --- a/src/ai/doctorm.c +++ b/src/ai/doctorm.c @@ -319,8 +319,8 @@ void ai_muscle_doctor(Entity *e) { case STATE_TELEPORT+1: { //if (dr_tp_out(o)) - e->hidden ^= 1; - if(++e->timer > TIME(30)) { + e->hidden = (++e->timer & 2); + if(e->timer > TIME(30)) { e->state++; e->timer = 0; e->hidden = TRUE; @@ -363,8 +363,8 @@ void ai_muscle_doctor(Entity *e) { case STATE_TELEPORT+4: { //if (dr_tp_in(o)) - e->hidden ^= 1; - if(++e->timer > TIME(30)) { + e->hidden = (++e->timer & 2); + if(e->timer > TIME(30)) { e->eflags |= NPC_SHOOTABLE; e->attack = DAMAGE_NORMAL; e->hidden = FALSE; diff --git a/src/ai/hell.c b/src/ai/hell.c index 24c28b2d..0bbc6149 100644 --- a/src/ai/hell.c +++ b/src/ai/hell.c @@ -465,8 +465,8 @@ void ai_bute_arrow(Entity *e) { case 20: // hit something { - e->hidden ^= 1; - if(++e->timer > TIME_8(30)) e->state = STATE_DELETE; + e->hidden = (++e->timer & 2); + if(e->timer > TIME_8(30)) e->state = STATE_DELETE; } break; } diff --git a/src/ai/item.c b/src/ai/item.c index a8b5e414..f6dd0ff9 100644 --- a/src/ai/item.c +++ b/src/ai/item.c @@ -118,7 +118,7 @@ void ai_missile(Entity *e) { e->state = STATE_DELETE; return; } else if(e->timer > TIME_10(350)) { - e->hidden ^= 1; + e->hidden = (e->timer & 2); } } else if(!e->state) { // Hide the sprite when under a breakable block @@ -155,7 +155,7 @@ void ai_heart(Entity *e) { e->state = STATE_DELETE; return; } else if(e->timer > TIME_10(350)) { - e->hidden ^= 1; + e->hidden = (e->timer & 2); } } else if(!e->state) { // Hide the sprite when under a breakable block diff --git a/src/ai/regu.c b/src/ai/regu.c index 7cc732af..3feeeec9 100644 --- a/src/ai/regu.c +++ b/src/ai/regu.c @@ -555,11 +555,11 @@ void ai_king(Entity *e) { /* fallthrough */ case 41: { - e->hidden ^= 1; - if (++e->timer > 100) { + e->hidden = (++e->timer & 2); + if (e->timer > TIME_8(100)) { effect_create_smoke(e->x >> CSF, e->y >> CSF); e->state = 42; - e->hidden = 0; + e->hidden = FALSE; e->frame = 6; // Sword } } @@ -713,8 +713,8 @@ void ai_booster_falling(Entity *e) { /* fallthrough */ case 21: { - e->hidden ^= 1; - if (++e->timer > TIME(100)) { + e->hidden = (++e->timer & 2); + if (e->timer > TIME(100)) { //SmokeClouds(o, 4, 16, 16); e->state = STATE_DELETE; } diff --git a/src/ai/toroko.c b/src/ai/toroko.c index ae946573..18e123fe 100644 --- a/src/ai/toroko.c +++ b/src/ai/toroko.c @@ -308,8 +308,8 @@ void ai_torokoBoss(Entity *e) { /* fallthrough */ case 141: { - e->hidden ^= 1; - if (++e->timer > TIME_8(100)) { + e->hidden = (++e->timer & 2); + if (e->timer > TIME_8(100)) { SMOKE_AREA((e->x >> CSF) - 8, e->y >> CSF, 16, 16, 2); e->state = STATE_DELETE; } diff --git a/src/camera.c b/src/camera.c index fae34628..2851b6bd 100644 --- a/src/camera.c +++ b/src/camera.c @@ -42,14 +42,12 @@ void camera_init() { void camera_set_position(int32_t x, int32_t y) { // Don't let the camera leave the stage - if(x > block_to_sub(stageWidth) - (SCREEN_HALF_W< block_to_sub(stageHeight) - ((SCREEN_HALF_H+2)< block_to_sub(stageWidth) - pixel_to_sub(SCREEN_HALF_W)) + x = block_to_sub(stageWidth) - pixel_to_sub(SCREEN_HALF_W); + if(y > block_to_sub(stageHeight) - pixel_to_sub(SCREEN_HALF_H+2)) + y = block_to_sub(stageHeight) - pixel_to_sub(SCREEN_HALF_H+2); + if(x < pixel_to_sub(SCREEN_HALF_W)) x = pixel_to_sub(SCREEN_HALF_W); + if(y < pixel_to_sub(SCREEN_HALF_H+2)) y = pixel_to_sub(SCREEN_HALF_H+2); // Apply camera.x = camera.x_mark = x; camera.y = camera.y_mark = y; @@ -123,14 +121,16 @@ void camera_update() { x_next = pixel_to_sub(SCREEN_HALF_W + 8); y_next = pixel_to_sub(SCREEN_HALF_H + 16); } else { - if(x_next < pixel_to_sub(SCREEN_HALF_W + 2)) + if(x_next < pixel_to_sub(SCREEN_HALF_W + 2)) { x_next = pixel_to_sub(SCREEN_HALF_W + 2); - else if(x_next > block_to_sub(stageWidth) - pixel_to_sub(SCREEN_HALF_W + 2)) + } else if(x_next > block_to_sub(stageWidth) - pixel_to_sub(SCREEN_HALF_W + 2)) { x_next = block_to_sub(stageWidth) - pixel_to_sub(SCREEN_HALF_W + 2); - if(y_next < pixel_to_sub(SCREEN_HALF_H + 2)) + } + if(y_next < pixel_to_sub(SCREEN_HALF_H + 2)) { y_next = pixel_to_sub(SCREEN_HALF_H + 2); - else if(y_next > block_to_sub(stageHeight) - pixel_to_sub(SCREEN_HALF_H + 2)) + } else if(y_next > block_to_sub(stageHeight) - pixel_to_sub(SCREEN_HALF_H + 2)) { y_next = block_to_sub(stageHeight) - pixel_to_sub(SCREEN_HALF_H + 2); + } } // Shifted values camera.x_shifted = (x_next >> CSF) - SCREEN_HALF_W; @@ -154,7 +154,7 @@ void camera_update() { } else { int16_t x = sub_to_tile(x_next) + (morphingColumn == 1 ? 30 : -30); int16_t y = sub_to_tile(y_next) - 16 /*+ morphingRow*/; - if(x >= 0 && x < stageWidth << 1) { + if(x >= 0 && x < (int16_t)(stageWidth) << 1) { for(uint16_t i = 32; i--; ) { // It's actually faster to just draw garbage than have these checks //if(y >= stageHeight << 1) break; @@ -180,7 +180,7 @@ void camera_update() { } else { int16_t y = sub_to_tile(y_next) + (morphingRow == 1 ? 15 : -15); int16_t x = sub_to_tile(x_next) - 32 /*+ morphingColumn*/; - if(y >= 0 && y < stageHeight << 1) { + if(y >= 0 && y < (int16_t)(stageHeight) << 1) { for(uint16_t i = 64; i--; ) { //if(x >= stageWidth << 1) break; //if(x >= 0) { diff --git a/src/db/npc.c b/src/db/npc.c index c304e761..e022b458 100644 --- a/src/db/npc.c +++ b/src/db/npc.c @@ -158,9 +158,9 @@ const npc_info_def npc_info[NPC_COUNT + 9 + 20 + 13] = { { &SPR_BigDoorFrame,NOSHEET, PAL1, 1, &ai_null, &ai_null, &ai_null }, // Large Door (Frame) { &SPR_BigDoor, NOSHEET, PAL1, 1, &onspawn_doorway, &ai_doorway, &ai_null }, // Large Door { &SPR_Doctor, NOSHEET, PAL3, 1, &onspawn_snap, &ai_doctor, &ai_null }, // Doctor - { &SPR_ToroBoss, NOSHEET, PAL3, 2, &onspawn_torokoBoss, &ai_torokoBoss, &ondeath_torokoBoss }, - { NULL, SHEET_BLOCK, PAL1, 1, &onspawn_persistent, &ai_torokoBlock, &ai_null }, - { NULL, SHEET_FLOWER, PAL3, 1, &onspawn_persistent, &ai_torokoFlower, &ondeath_default }, + { &SPR_ToroBoss, NOSHEET, PAL3, 1, &onspawn_torokoBoss, &ai_torokoBoss, &ondeath_torokoBoss }, // Toroko+ + { NULL, SHEET_BLOCK, PAL1, 1, &onspawn_persistent, &ai_torokoBlock, &ai_null }, // Block she throws + { NULL, SHEET_FLOWER, PAL3, 1, &onspawn_persistent, &ai_torokoFlower, &ondeath_default }, // That turn into flowers { &SPR_Jenka, NOSHEET, PAL3, 1, &onspawn_jenka, &ai_null, &ai_null }, // Jenka /* 0x090 (144) */ { &SPR_Toroko, NOSHEET, PAL3, 1, &onspawn_persistent, &ai_toroko_tele_in, &ai_null }, diff --git a/src/entity.c b/src/entity.c index 477919b0..3f40cd81 100644 --- a/src/entity.c +++ b/src/entity.c @@ -440,38 +440,38 @@ void entity_update_collision(Entity *e) { } uint8_t collide_stage_leftwall(Entity *e) { - uint16_t block_x, block_y1, block_y2; - uint8_t pxa1, pxa2; - block_x = pixel_to_block(sub_to_pixel(e->x_next) - - (e->dir ? e->hit_box.right : e->hit_box.left)); - block_y1 = pixel_to_block(sub_to_pixel(e->y_next) - e->hit_box.top + 3); - block_y2 = pixel_to_block(sub_to_pixel(e->y_next) + e->hit_box.bottom - 3); - pxa1 = stage_get_block_type(block_x, block_y1); - pxa2 = stage_get_block_type(block_x, block_y2); + int16_t xoff = e->dir ? e->hit_box.right : e->hit_box.left; + uint16_t pixel_x = (e->x_next >> CSF) - xoff; + uint16_t pixel_y = (e->y_next >> CSF); + uint16_t block_x = pixel_to_block(pixel_x); + uint16_t block_y1 = pixel_to_block(pixel_y - e->hit_box.top + 3); + uint16_t block_y2 = pixel_to_block(pixel_y + e->hit_box.bottom - 3); + uint8_t pxa1 = stage_get_block_type(block_x, block_y1); + uint8_t pxa2 = stage_get_block_type(block_x, block_y2); if(pxa1 == 0x41 || pxa2 == 0x41 || pxa1 == 0x43 || pxa2 == 0x43 || (!((e->eflags|e->nflags)&NPC_IGNORE44) && (pxa1 == 0x44 || pxa2 == 0x44))) { e->x_speed = 0; - e->x_next = pixel_to_sub( - block_to_pixel(block_x) + block_to_pixel(1) + e->hit_box.left); + e->x_next &= ~0x1FF; // Align to pixel + e->x_next += pixel_to_sub(min((pixel_x & ~0xF) + 16 - pixel_x, 3)); return TRUE; } return FALSE; } uint8_t collide_stage_rightwall(Entity *e) { - uint16_t block_x, block_y1, block_y2; - uint8_t pxa1, pxa2; - block_x = pixel_to_block(sub_to_pixel(e->x_next) + - (e->dir ? e->hit_box.left : e->hit_box.right)); - block_y1 = pixel_to_block(sub_to_pixel(e->y_next) - e->hit_box.top + 3); - block_y2 = pixel_to_block(sub_to_pixel(e->y_next) + e->hit_box.bottom - 3); - pxa1 = stage_get_block_type(block_x, block_y1); - pxa2 = stage_get_block_type(block_x, block_y2); + int16_t xoff = e->dir ? e->hit_box.left : e->hit_box.right; + uint16_t pixel_x = (e->x_next >> CSF) + xoff; + uint16_t pixel_y = (e->y_next >> CSF); + uint16_t block_x = pixel_to_block(pixel_x); + uint16_t block_y1 = pixel_to_block(pixel_y - e->hit_box.top + 3); + uint16_t block_y2 = pixel_to_block(pixel_y + e->hit_box.bottom - 3); + uint8_t pxa1 = stage_get_block_type(block_x, block_y1); + uint8_t pxa2 = stage_get_block_type(block_x, block_y2); if(pxa1 == 0x41 || pxa2 == 0x41 || pxa1 == 0x43 || pxa2 == 0x43 || (!((e->eflags|e->nflags)&NPC_IGNORE44) && (pxa1 == 0x44 || pxa2 == 0x44))) { e->x_speed = 0; - e->x_next = pixel_to_sub( - block_to_pixel(block_x) - e->hit_box.right); + e->x_next &= ~0x1FF; + e->x_next -= pixel_to_sub(min(pixel_x - (pixel_x & ~0xF), 3)); return TRUE; } return FALSE; diff --git a/src/error.c b/src/error.c index 09f0f384..9ee1d3dd 100644 --- a/src/error.c +++ b/src/error.c @@ -57,11 +57,11 @@ void _error() { // Registers x = 2; y = 4; for(uint16_t i = 0; i < 8; i++) { - sprintf(buf, "D%hu=%08X", i, v_err_reg[i]); + sprintf(buf, "D%hu=%08lX", i, v_err_reg[i]); VDP_drawTextBG(PLAN_A, buf, x, y+i); } for(uint16_t i = 0; i < 8; i++) { - sprintf(buf, "A%hu=%08X", i, v_err_reg[i+8]); + sprintf(buf, "A%hu=%08lX", i, v_err_reg[i+8]); VDP_drawTextBG(PLAN_A, buf, x, y+i+8); } @@ -73,7 +73,7 @@ void _error() { y = 20; sprintf(buf, "FUNC=%04hX INST=%04hX", v_err_ext1, v_err_ext2); VDP_drawTextBG(PLAN_A, buf, x, y++); - sprintf(buf, "ADDR=%06X", v_err_addr); + sprintf(buf, "ADDR=%06lX", v_err_addr); VDP_drawTextBG(PLAN_A, buf, x, y++); break; case 2: // Illegal @@ -83,7 +83,7 @@ void _error() { break; } x = 2; y = 20; - sprintf(buf, "PC=%06X", v_err_pc); + sprintf(buf, "PC=%06lX", v_err_pc); VDP_drawTextBG(PLAN_A, buf, x, y++); sprintf(buf, "SR= %04hX", v_err_sr); VDP_drawTextBG(PLAN_A, buf, x, y++); @@ -97,13 +97,13 @@ void _error() { // Prevent wrapping around after reaching top of the stack if((uint32_t) sp < 0xFFF000) break; x = 15; - sprintf(buf, "SP+%02X=%08X", i << 3, *sp); + sprintf(buf, "SP+%02X=%08lX", i << 3, *sp); VDP_drawTextBG(PLAN_A, buf, x, y); sp++; if((uint32_t) sp < 0xFFF000) break; x = 30; - sprintf(buf, "%08X", *sp); + sprintf(buf, "%08lX", *sp); VDP_drawTextBG(PLAN_A, buf, x, y); sp++; diff --git a/src/ntsc.c b/src/ntsc.c index 52000dfd..df9cd949 100644 --- a/src/ntsc.c +++ b/src/ntsc.c @@ -35,7 +35,7 @@ const uint16_t time_tab_ntsc[0x100] = { 0x0129, 0x012b, 0x012c, 0x012d, 0x012e, 0x012f, 0x0131, 0x0132, }; -const uint16_t speed_tab_ntsc[0x100] = { +const int16_t speed_tab_ntsc[0x100] = { 0x0000, 0x0001, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0010, 0x0011, 0x0012, 0x0013, diff --git a/src/player.c b/src/player.c index e9195b4c..bc87073a 100644 --- a/src/player.c +++ b/src/player.c @@ -53,18 +53,17 @@ uint8_t walk_time; VDPSprite airTankSprite; -void player_update_bounds(); -void player_update_booster(); -void player_update_interaction(); -void player_update_air_display(); +static void player_update_booster(); +static void player_update_interaction(); +static void player_update_air_display(); -void player_update_movement(); -void player_update_walk(); -void player_update_jump(); -void player_update_float(); +static void player_update_movement(); +static void player_update_walk(); +static void player_update_jump(); +static void player_update_float(); -void player_prev_weapon(); -void player_next_weapon(); +static void player_prev_weapon(); +static void player_next_weapon(); // Default values for player void player_init() { @@ -178,16 +177,16 @@ void player_update() { lastBoostState = playerBoostState; // The above code to slow down the booster needs to always run. // As such we check again whether the booster is enabled - if(playerBoostState == BOOST_OFF && sub_to_block(player.y) < stageHeight - 1) { + uint16_t px = player.x_next >> CSF, py = player.y_next >> CSF; + uint16_t bx = px >> 4, by = py >> 4; + if(playerBoostState == BOOST_OFF && bx > 0 && bx < stageWidth - 1 && by > 0 && by < stageHeight - 1) { uint8_t blockl_next, blocku_next, blockr_next, blockd_next; // Ok so, making the collision with ceiling <= 0 pushes the player out of // the ceiling during the opening scene with Kazuma on the computer. // Hi Kazuma! blocku_next = player.y_speed < 0 ? collide_stage_ceiling(&player) : FALSE; - blockl_next = (player.x_speed <= 0 || playerPlatform) ? - collide_stage_leftwall(&player) : FALSE; - blockr_next = (player.x_speed >= 0 || playerPlatform) ? - collide_stage_rightwall(&player) : FALSE; + blockl_next = (player.x_speed <= 0 || playerPlatform) ? collide_stage_leftwall(&player) : FALSE; + blockr_next = (player.x_speed >= 0 || playerPlatform) ? collide_stage_rightwall(&player) : FALSE; if(ledge_time == 0) { if(player.grounded) { player.grounded = collide_stage_floor_grounded(&player); @@ -442,17 +441,17 @@ void player_update() { } } -void player_update_movement() { +static void player_update_movement() { player_update_walk(); player_update_jump(); player.x_next = player.x + player.x_speed; player.y_next = player.y + player.y_speed; } -void player_update_walk() { - uint16_t acc; - uint16_t fric; - uint16_t max_speed; +static void player_update_walk() { + int16_t acc; + int16_t fric; + int16_t max_speed; if(pal_mode) { max_speed = 810; if(player.grounded) { @@ -504,11 +503,11 @@ void player_update_walk() { } } -void player_update_jump() { - uint16_t jumpSpeed; - uint16_t gravity; - uint16_t gravityJump; - uint16_t maxFallSpeed; +static void player_update_jump() { + int16_t jumpSpeed; + int16_t gravity; + int16_t gravityJump; + int16_t maxFallSpeed; if(pal_mode) { jumpSpeed = 0x500; gravity = 0x50; @@ -557,10 +556,10 @@ void player_update_jump() { } } -void player_update_float() { - uint16_t acc; - uint16_t fric; - uint16_t max_speed; +static void player_update_float() { + int16_t acc; + int16_t fric; + int16_t max_speed; if(pal_mode) { acc = 256; fric = 128; @@ -608,7 +607,7 @@ void player_update_bullets() { } } -void player_update_interaction() { +static void player_update_interaction() { // Interaction with entities when pressing down if(cfg_updoor ? joy_pressed(BUTTON_UP) : joy_pressed(BUTTON_DOWN)) { Entity *e = entityList; @@ -679,7 +678,7 @@ void player_start_booster() { sound_play(SND_BOOSTER, 3); } -void player_update_booster() { +static void player_update_booster() { if(!(playerEquipment & (EQUIP_BOOSTER08 | EQUIP_BOOSTER20))) playerBoostState = BOOST_OFF; if(!joy_down(btn[cfg_btn_jump])) playerBoostState = BOOST_OFF; if(playerBoostState == BOOST_OFF) return; @@ -696,10 +695,10 @@ void player_update_booster() { if (joy_down(BUTTON_LEFT)) player.dir = 0; else if (joy_down(BUTTON_RIGHT)) player.dir = 1; - uint8_t blockl = collide_stage_leftwall(&player), - blockr = collide_stage_rightwall(&player); // Don't bump in the opposite direction when hitting the ceiling if(player.y_speed <= 0 && collide_stage_ceiling(&player)) player.y_speed = 0; + uint8_t blockl = collide_stage_leftwall(&player), + blockr = collide_stage_rightwall(&player); collide_stage_floor(&player); switch(playerBoostState) { @@ -821,7 +820,7 @@ void player_show_map_name(uint8_t ttl) { } } -void draw_air_percent() { +static void draw_air_percent() { uint8_t airTemp = airPercent; uint32_t numberTiles[3][8]; if(airTemp >= 100) { @@ -837,7 +836,7 @@ void draw_air_percent() { } -void player_update_air_display() { +static void player_update_air_display() { // Blink for a second after getting out of the water if(airPercent == 100) { if(airDisplayTime == TIME_8(50)) { @@ -984,7 +983,7 @@ uint8_t player_invincible() { return playerIFrames > 0 || tscState; } -uint8_t player_inflict_damage(int16_t damage) { +uint8_t player_inflict_damage(uint16_t damage) { // Show damage numbers effect_create_damage(-damage, sub_to_pixel(player.x), sub_to_pixel(player.y)); // Take health @@ -1030,14 +1029,7 @@ uint8_t player_inflict_damage(int16_t damage) { return FALSE; } -void player_update_bounds() { - if(sub_to_block(player.y) > stageHeight) { - player.health = 0; - tsc_call_event(PLAYER_OOB_EVENT); - } -} - -void player_prev_weapon() { +static void player_prev_weapon() { for(int16_t i = currentWeapon - 1; i % MAX_WEAPONS != currentWeapon; i--) { if(i < 0) i = MAX_WEAPONS - 1; if(playerWeapon[i].type > 0) { @@ -1052,7 +1044,7 @@ void player_prev_weapon() { } } -void player_next_weapon() { +static void player_next_weapon() { for(int16_t i = currentWeapon + 1; i % MAX_WEAPONS != currentWeapon; i++) { if(i >= MAX_WEAPONS) i = 0; if(playerWeapon[i].type > 0) { diff --git a/src/splash.c b/src/splash.c index 4337fac6..3c731bd4 100644 --- a/src/splash.c +++ b/src/splash.c @@ -42,8 +42,8 @@ void splash_main() { camera.y -= 8 << CSF; // Cancel the offset, we want to use absolute positions camera.target = NULL; // Create Balrog entity - Entity *blg = entity_create(SCREEN_HALF_W<linkedEntity = entity_create(SCREEN_HALF_W<linkedEntity = entity_create(pixel_to_sub(SCREEN_HALF_W), pixel_to_sub(SCREEN_HALF_H), OBJ_SEGALOGO, 0); uint16_t timer = 0; while(++timer <= TIME(250) && !joy_pressed(BUTTON_C) && !joy_pressed(BUTTON_START)) { diff --git a/src/system.c b/src/system.c index 2e347d39..0c74a911 100644 --- a/src/system.c +++ b/src/system.c @@ -662,7 +662,8 @@ uint32_t system_load_counter() { return 0xFFFFFFFF; } // Convert LE -> BE - uint32_t rtn = (buffer[0]<<24) + (buffer[1]<<16) + (buffer[2]<<8) + buffer[3]; + uint32_t rtn = (((uint32_t)(buffer[0]))<<24) + (((uint32_t)(buffer[1]))<<16) + + (((uint32_t)(buffer[2]))<<8) + buffer[3]; // Split out so the time can be displayed on the title screen counter.frame = rtn % 50; counter.second = (rtn / 50) % 60; @@ -718,5 +719,5 @@ static uint16_t LS_readWord(uint8_t file, uint32_t addr) { } static uint32_t LS_readLong(uint8_t file, uint32_t addr) { - return (LS_readWord(file, addr) << 16) + LS_readWord(file, addr+2); + return (((uint32_t)(LS_readWord(file, addr))) << 16) + LS_readWord(file, addr+2); } diff --git a/src/titlescreen.c b/src/titlescreen.c index dae65905..fe3d057a 100644 --- a/src/titlescreen.c +++ b/src/titlescreen.c @@ -155,7 +155,7 @@ uint8_t titlescreen_main() { sprite_pos(sprCursor, 13*8-4, (12*8+cursor*16)-4); sprite_add(sprCursor); - if(besttime > 0 && besttime < 100*60*50) system_draw_counter(); + if(besttime > 0 && besttime < 300000) system_draw_counter(); ready = TRUE; vsync(); aftervsync(); diff --git a/src/tsc.c b/src/tsc.c index ee74528f..21de45d2 100644 --- a/src/tsc.c +++ b/src/tsc.c @@ -206,7 +206,7 @@ uint8_t tsc_load(Event *eventList, const uint8_t *TSC, uint8_t max) { // Make sure it isn't more than can be handled if(eventCount > max) { char str[40]; - sprintf(str, "Too many events: %hu\nIn TSC at: %06X", eventCount, (uint32_t) TSC); + sprintf(str, "Too many events: %hu\nIn TSC at: %06lX", eventCount, (uint32_t) TSC); error_other(str); } // Step through ROM data until finding all the events @@ -608,7 +608,7 @@ uint8_t execute_command() { VDP_clearPlan(PLAN_A, TRUE); entities_clear(); sprites_clear(); - entity_create(240 << CSF, 120 << CSF, OBJ_NPC_PLAYER, 0)->state = 100; + entity_create((int32_t) 240 << CSF, (int32_t) 120 << CSF, OBJ_NPC_PLAYER, 0)->state = 100; tsc_load_stage(ID_CREDITS); } else { stage_load_credits(args[0]); @@ -1184,8 +1184,8 @@ uint8_t execute_command() { VDP_setEnable(FALSE); // Disable camera camera.target = NULL; - camera.x = SCREEN_HALF_W << CSF; - camera.y = SCREEN_HALF_H << CSF; + camera.x = (int32_t)SCREEN_HALF_W << CSF; + camera.y = (int32_t)SCREEN_HALF_H << CSF; camera.x_shifted = 0; camera.y_shifted = 0; // Reset plane positions diff --git a/src/vdp_tile.c b/src/vdp_tile.c index 320f1497..50f04dd6 100644 --- a/src/vdp_tile.c +++ b/src/vdp_tile.c @@ -101,7 +101,7 @@ void VDP_fillTileMap(uint16_t plan, uint16_t tile, uint16_t ind, uint16_t num) *plctrl = GFX_WRITE_VRAM_ADDR(addr); - const uint32_t tile32 = (tile << 16) | tile; + const uint32_t tile32 = (((uint32_t)(tile)) << 16) | tile; i = num >> 3; while (i--) @@ -202,7 +202,7 @@ void VDP_fillTileMapInc(uint16_t plan, uint16_t basetile, uint16_t ind, uint16_t *plctrl = GFX_WRITE_VRAM_ADDR(addr); tile = basetile; - tile32 = (tile << 16) | tile; + tile32 = (((uint32_t)(tile)) << 16) | tile; step = 0x10001; i = num >> 3; @@ -401,8 +401,8 @@ void VDP_setTileMapDataEx(uint16_t plan, const uint16_t *data, uint16_t basetile src32 = (uint32_t*) data; baseindex = basetile & TILE_INDEX_MASK; baseflags = basetile & TILE_ATTR_MASK; - bi32 = (baseindex << 16) | baseindex; - bf32 = (baseflags << 16) | baseflags; + bi32 = (((uint32_t)(baseindex)) << 16) | baseindex; + bf32 = (((uint32_t)(baseflags)) << 16) | baseflags; i = num >> 3; while (i--) diff --git a/src/xgm/xgm.c b/src/xgm/xgm.c index f35a949f..49451b00 100644 --- a/src/xgm/xgm.c +++ b/src/xgm/xgm.c @@ -45,7 +45,7 @@ void XGM_startPlay(const uint8_t *song) { // sample address in sample bank data addr = song[(i * 4) + 0] << 8; - addr |= song[(i * 4) + 1] << 16; + addr |= (uint32_t)(song[(i * 4) + 1]) << 16; // silent sample ? use null sample address if (addr == 0xFFFF00) addr = (uint32_t) smp_null; @@ -67,7 +67,7 @@ void XGM_startPlay(const uint8_t *song) addr = ((uint32_t) song) + 0x100; // bypass sample data (use the sample data size) addr += song[0xFC] << 8; - addr += song[0xFD] << 16; + addr += ((uint32_t)song[0xFD]) << 16; // and bypass the music data size field addr += 4; @@ -333,7 +333,7 @@ uint32_t XGM_getElapsed() Z80_releaseBus(); - result = (values[0] << 0) | (values[1] << 8) | (values[2] << 16); + result = (values[0] << 0) | (values[1] << 8) | ((uint32_t)(values[2]) << 16); // fix possible 24 bit negative value (parsing first extra frame) if (result >= 0xFFFFF0) return 0;