From 525a88e0b6b85a2b72f7c3a7d8b722b82e037240 Mon Sep 17 00:00:00 2001 From: ADM228 <91823517+ADM228@users.noreply.github.com> Date: Thu, 6 Jun 2024 18:08:06 +0300 Subject: [PATCH] =?UTF-8?q?Optimized=20some=20more=20shit,=20mode=20macros?= =?UTF-8?q?=20added=20CODE:=20=20=20=20=20=20=20=207516=20=E2=86=92=207492?= =?UTF-8?q?=20-=20diff:=20=2024=20ZEROPAGE:=20=20=20=20165=20=20=E2=86=92?= =?UTF-8?q?=20164=20=20-=20diff:=20=201=20XCD=5FBANK=5F00:=207917=20?= =?UTF-8?q?=E2=86=92=207735=20-=20diff:=20=20182=20XCD=5FBANK=5F01:=202880?= =?UTF-8?q?=20=E2=86=92=202719=20-=20diff:=20=20161=20XCD=5FBANK=5F02:=201?= =?UTF-8?q?298=20=E2=86=92=201273=20-=20diff:=20=2025?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Total size reduction: 393 bytes --- LIB/nesdash.h | 36 ++++++++++++++++++++++++------- SAUCE/famidash.h | 20 ++++++++--------- SAUCE/functions/draw_sprites.h | 23 ++++++++++---------- SAUCE/functions/sprite_loading.h | 16 +++++++------- SAUCE/functions/x_movement.h | 4 ++-- SAUCE/gamemodes/gamemode_ball.h | 10 ++++----- SAUCE/gamemodes/gamemode_cube.h | 10 ++++----- SAUCE/gamemodes/gamemode_spider.h | 2 +- SAUCE/gamemodes/gamemode_wave.h | 6 +++--- SAUCE/gamestates/state_game.h | 2 +- 10 files changed, 75 insertions(+), 54 deletions(-) diff --git a/LIB/nesdash.h b/LIB/nesdash.h index 00c56684..9e2a0729 100644 --- a/LIB/nesdash.h +++ b/LIB/nesdash.h @@ -109,16 +109,28 @@ extern uint8_t parallax_scroll_column_start; #define idx16_lo_NOC(arr, idx) (__A__ = idx<<1, __asm__("tay\n lda %v, y", arr), __A__) #define idx16_hi_NOC(arr, idx) (__A__ = idx<<1, __asm__("tay\n lda %v+1, y", arr), __A__) -// store a word's high and low bytes into separate places -#define storeWordSeparately(word, low, high) \ - (__AX__ = word, \ - __asm__("STA %v", low), \ - __asm__("STX %v", high)) - -#define pal_fade_to_withmusic(from, to) (++auto_fs_updates, pal_fade_to(from, to), auto_fs_updates = 0) +#define uint8_dec(arr, idx) ( \ + __AX__ = idx << 8, \ + __asm__("dec %v,x", arr), \ + __asm__("lda %v,x", arr), \ + __A__ \ +) + +#define uint8_inc(arr, idx) ( \ + __AX__ = idx << 8, \ + __asm__("inc %v,x", arr), \ + __asm__("lda %v,x", arr), \ + __A__ \ +) + +#define uint8_store(arr, idx, val) ( \ + __A__ = idx, \ + __asm__("tay"), \ + __A__ = val, \ + __asm__("sta %v, y", arr)) // Yes i had to actually fucking use inline asm to get this to run fast -#define store_short_arr_NOC(arr, idx, word) ( \ +#define uint16_store_NOC(arr, idx, word) ( \ __A__ = idx<<1, \ __asm__("tay"), \ __A__ = LSB(word), \ @@ -126,6 +138,14 @@ extern uint8_t parallax_scroll_column_start; __A__ = MSB(word), \ __asm__("sta %v+1, y", arr)) +// store a word's high and low bytes into separate places +#define storeWordSeparately(word, low, high) \ + (__AX__ = word, \ + __asm__("STA %v", low), \ + __asm__("STX %v", high)) + +#define pal_fade_to_withmusic(from, to) (++auto_fs_updates, pal_fade_to(from, to), auto_fs_updates = 0) + // set palette color, index 0..31 // completely inlines and replaces neslib's extern uint8_t PAL_UPDATE; diff --git a/SAUCE/famidash.h b/SAUCE/famidash.h index 49fd86e8..cc507eac 100644 --- a/SAUCE/famidash.h +++ b/SAUCE/famidash.h @@ -131,7 +131,7 @@ unsigned char eject_U; // from up unsigned short address; unsigned char x; // room loader code unsigned char y; -unsigned short index; +unsigned char index; unsigned short index2; unsigned char temp_x; unsigned char temp_y; @@ -280,15 +280,15 @@ unsigned char practice_bg_color_type; // the funny uh uhhhhh um the uhh sprite storidge // X_lowbyte, X_highbyte, Y_lowbyte, Y_highbyte, object id, unused, unused, unused #define max_loaded_sprites 16 -unsigned short activesprites_x[max_loaded_sprites]; -unsigned short activesprites_y[max_loaded_sprites]; -unsigned char activesprites_type[max_loaded_sprites]; -unsigned char activesprites_anim_frame[max_loaded_sprites]; -signed char activesprites_anim_frame_count[max_loaded_sprites]; - -unsigned char activesprites_realx[max_loaded_sprites]; -unsigned char activesprites_realy[max_loaded_sprites]; -unsigned char activesprites_active[max_loaded_sprites]; +uint16_t activesprites_x[max_loaded_sprites]; +uint16_t activesprites_y[max_loaded_sprites]; +uint8_t activesprites_type[max_loaded_sprites]; +uint8_t activesprites_anim_frame[max_loaded_sprites]; +int8_t activesprites_anim_frame_count[max_loaded_sprites]; + +uint8_t activesprites_realx[max_loaded_sprites]; +uint8_t activesprites_realy[max_loaded_sprites]; +uint8_t activesprites_active[max_loaded_sprites]; diff --git a/SAUCE/functions/draw_sprites.h b/SAUCE/functions/draw_sprites.h index a63a1e11..869a5a59 100644 --- a/SAUCE/functions/draw_sprites.h +++ b/SAUCE/functions/draw_sprites.h @@ -52,12 +52,12 @@ void draw_sprites(void){ } index = shuffle_offset; if (index < 0xF0) { - if (activesprites_type[low_byte(index)] & 0x80) continue; + if (activesprites_type[index] & 0x80) continue; } - temp_y = activesprites_realy[low_byte(index)]; - if (!activesprites_active[low_byte(index)]) continue; - temp_x = activesprites_realx[low_byte(index)]; + temp_y = activesprites_realy[index]; + if (!activesprites_active[index]) continue; + temp_x = activesprites_realx[index]; if (temp_x == 0) temp_x = 1; if (temp_x > 0xf0) continue; @@ -67,27 +67,28 @@ void draw_sprites(void){ #define needs_reload tmp4 #define animation_ptr tmpptr1 #define animation_data_ptr tmpptr2 - if (activesprites_type[low_byte(index)] > 0x80) {} + if (activesprites_type[index] > 0x80) {} else { if (temp_y < 0xf0) { needs_reload = 0; - spr_type = activesprites_type[low_byte(index)]; + spr_type = activesprites_type[index]; animation_ptr = (unsigned char * const)animation_frame_list[spr_type]; // If this sprite has animations, then this pointer will not be null if (animation_ptr) { // Reduce the frame counter by one to see if we need to move to the next frame // If this frame has expired, then move to the next animation frame - animation_frame_count = --activesprites_anim_frame_count[low_byte(index)]; + animation_frame_count = uint8_dec(activesprites_anim_frame_count, index); if (animation_frame_count >= 0x80) { - animation_frame = ++activesprites_anim_frame[low_byte(index)]; + animation_frame = uint8_inc(activesprites_anim_frame, index); // if the animation frame is past the length, wrap it around back to zero if (animation_frame >= animation_frame_length[spr_type]) { - activesprites_anim_frame[low_byte(index)] = animation_frame = 0; + activesprites_anim_frame[index] = 0; + animation_frame = 0; } // and then set the animation_frame_count to be reloaded needs_reload = 1; } else { - animation_frame = activesprites_anim_frame[low_byte(index)]; + animation_frame = activesprites_anim_frame[index]; } // Now load the data for this frame of animation @@ -95,7 +96,7 @@ void draw_sprites(void){ // it to read all the bytes at once tmplong = ((unsigned long int*)animation_ptr)[animation_frame]; if (needs_reload) { - activesprites_anim_frame_count[low_byte(index)] = low_byte(tmplong); + uint8_store(activesprites_anim_frame_count, index, low_byte(tmplong)); } // And finally, load the pointer for this animation animation_data_ptr = (unsigned char*)high_word(tmplong); diff --git a/SAUCE/functions/sprite_loading.h b/SAUCE/functions/sprite_loading.h index 35f57a99..205d4859 100644 --- a/SAUCE/functions/sprite_loading.h +++ b/SAUCE/functions/sprite_loading.h @@ -209,7 +209,7 @@ char sprite_height_lookup(){ } lastbgcolortype = type; } - activesprites_type[low_byte(index)] = 0xFF; + activesprites_type[index] = 0xFF; return 0; } @@ -217,7 +217,7 @@ char sprite_height_lookup(){ else if (type >= SPEED_05_PORTAL && type <= SPEED_20_PORTAL) // Speed portals return 0x1F; else if ((type >= 0x2A && type <= 0x43) || (type >= 0x47 && type <= 0x4A)) { // Decorations - if (twoplayer || !decorations) activesprites_type[low_byte(index)] = 0xFF; + if (twoplayer || !decorations) activesprites_type[index] = 0xFF; return 0; } @@ -266,17 +266,17 @@ char sprite_height_lookup(){ return 0x2f; case COIN1: if (coin1_obtained[level]) { - activesprites_type[low_byte(index)] = COINGOTTEN1; + activesprites_type[index] = COINGOTTEN1; } return 0x17; case COIN2: if (coin2_obtained[level]) { - activesprites_type[low_byte(index)] = COINGOTTEN2; + activesprites_type[index] = COINGOTTEN2; } return 0x17; case COIN3: if (coin3_obtained[level]) { - activesprites_type[low_byte(index)] = COINGOTTEN3; + activesprites_type[index] = COINGOTTEN3; } return 0x17; case SPEED_30_PORTAL: @@ -389,7 +389,7 @@ static void sprite_gamemode_main() { static void sprite_gamemode_controller_check() { if (pad_new[controllingplayer] & PAD_A) { - cube_data[currplayer] &= 0x01; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 0x01); if (collided == BLUE_ORB) { currplayer_gravity ^= 0x01; currplayer_vel_y = (!currplayer_gravity) ? PAD_HEIGHT_BLUE^0xFFFF : PAD_HEIGHT_BLUE; @@ -419,7 +419,7 @@ void sprite_collide_lookup() { case BIG_SPIKE_TOP: case SMALL_SPIKE_BOTTOM: case SMALL_SPIKE_TOP: - cube_data[currplayer] |= 0x01; return; + uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x01); return; // Portal game mode switches case S_BLOCK: dashing[currplayer] = 0; return; @@ -437,7 +437,7 @@ void sprite_collide_lookup() { case SHIP_MODE: gamemode = collided; robotjumptime[currplayer] = 0; - target_scroll_y = activesprites_y[index]; + target_scroll_y = activesprites_y[index & 0x7F]; // return; // fallthrough case NOSPRITE: diff --git a/SAUCE/functions/x_movement.h b/SAUCE/functions/x_movement.h index 3444aede..576b4b9f 100644 --- a/SAUCE/functions/x_movement.h +++ b/SAUCE/functions/x_movement.h @@ -69,11 +69,11 @@ void x_movement(){ if (currplayer_y < 0x0600 && scroll_y == 0x08){ - cube_data[currplayer] |= 0x01; //DIE if player goes too high + uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x01); //DIE if player goes too high } - else if (!(pad[controllingplayer] & PAD_A)) cube_data[currplayer] &= 1; + else if (!(pad[controllingplayer] & PAD_A)) uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); } #pragma code-name(pop) diff --git a/SAUCE/gamemodes/gamemode_ball.h b/SAUCE/gamemodes/gamemode_ball.h index 63bdbeaa..7745f8af 100644 --- a/SAUCE/gamemodes/gamemode_ball.h +++ b/SAUCE/gamemodes/gamemode_ball.h @@ -9,7 +9,7 @@ void ball_movement(void){ // currplayer_gravity // currplayer_vel_y is signed - if ((pad_new[controllingplayer] & PAD_A) && currplayer_vel_y != 0) cube_data[currplayer] |= 0x02; + if ((pad_new[controllingplayer] & PAD_A) && currplayer_vel_y != 0) uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x02); if (!dashing[currplayer]) { if(!mini){ @@ -51,20 +51,20 @@ void ball_movement(void){ Generic.y = high_byte(currplayer_y) + 1; } - if (pad_new[controllingplayer] & PAD_A) cube_data[currplayer] |= 2; + if (pad_new[controllingplayer] & PAD_A) uint8_store(cube_data, currplayer, cube_data[currplayer] | 2); if(high_byte(currplayer_vel_y) & 0x80){ if(bg_coll_U()){ // check collision above high_byte(currplayer_y) = high_byte(currplayer_y) - eject_U; currplayer_vel_y = 0; - cube_data[currplayer] &= 1; //fix for orb + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); //fix for orb } } else{ if(bg_coll_D()){ // check collision below high_byte(currplayer_y) = high_byte(currplayer_y) - eject_D; currplayer_vel_y = 0; - cube_data[currplayer] &= 1; //fix for orb + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); //fix for orb } } @@ -82,7 +82,7 @@ void ball_movement(void){ } if(kandotemp2[currplayer] == 1){ if (!(pad[controllingplayer] & PAD_A)){ - cube_data[currplayer] &= 1; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); kandotemp2[currplayer] = 0; } } diff --git a/SAUCE/gamemodes/gamemode_cube.h b/SAUCE/gamemodes/gamemode_cube.h index 63692b09..0b9b8283 100644 --- a/SAUCE/gamemodes/gamemode_cube.h +++ b/SAUCE/gamemodes/gamemode_cube.h @@ -9,7 +9,7 @@ void cube_movement(void){ // currplayer_vel_y is signed //if(currplayer_vel_y < 0x400){ - if ((pad_new[controllingplayer] & PAD_A) && currplayer_vel_y != 0) cube_data[currplayer] |= 0x02; + if ((pad_new[controllingplayer] & PAD_A) && currplayer_vel_y != 0) uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x02); if (!dashing[currplayer]) { if(!mini){ @@ -67,7 +67,7 @@ void cube_movement(void){ if (gamemode == 0 && currplayer_vel_y == 0 && dashing[currplayer] == 0){ //if(bg_coll_D2()) { - cube_data[currplayer] &= 1; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); if(pad[controllingplayer] & PAD_A) { if (!currplayer_gravity) { if (!mini) currplayer_vel_y = JUMP_VEL; // JUMP @@ -81,7 +81,7 @@ void cube_movement(void){ } } else if (gamemode == 4 && !retro_mode && (currplayer_vel_y == 0)){ - cube_data[currplayer] &= 1; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); if(pad_new[controllingplayer] & PAD_A) { if (!currplayer_gravity) { if (!mini) currplayer_vel_y = ROBOT_JUMP_VEL; // JUMP @@ -97,7 +97,7 @@ void cube_movement(void){ } else if (gamemode == 4 && retro_mode && (currplayer_vel_y == 0)){ - cube_data[currplayer] &= 1; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); if(pad[controllingplayer] & PAD_A) { if (!currplayer_gravity) { if (!mini) currplayer_vel_y = ROBOT_JUMP_VEL; // JUMP @@ -114,7 +114,7 @@ void cube_movement(void){ else if (gamemode == 4 && robotjumptime[currplayer]) { cube_data[currplayer] = 0; - if (robotjumptime[currplayer]) robotjumptime[currplayer]--; + if (robotjumptime[currplayer]) uint8_dec(robotjumptime, currplayer); if(pad[controllingplayer] & PAD_A) { if (robotjumpframe[0]) robotjumpframe[0]++; if ( robotjumpframe[0] > 3 ) robotjumpframe[0] = 3; diff --git a/SAUCE/gamemodes/gamemode_spider.h b/SAUCE/gamemodes/gamemode_spider.h index 795d4cea..e1f024a3 100644 --- a/SAUCE/gamemodes/gamemode_spider.h +++ b/SAUCE/gamemodes/gamemode_spider.h @@ -87,7 +87,7 @@ void spider_movement(void){ if (currplayer_vel_y != 0){ if(pad_new[controllingplayer] & PAD_A) { - cube_data[currplayer] |= 2; + uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x02); } } } diff --git a/SAUCE/gamemodes/gamemode_wave.h b/SAUCE/gamemodes/gamemode_wave.h index 925de5c1..ecb1787d 100644 --- a/SAUCE/gamemodes/gamemode_wave.h +++ b/SAUCE/gamemodes/gamemode_wave.h @@ -41,14 +41,14 @@ void wave_movement(void){ if(bg_coll_U() && kandowavewalk){ // check collision above high_byte(currplayer_y) = high_byte(currplayer_y) - eject_U; currplayer_vel_y = 0; - cube_data[currplayer] &= 1; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); } } else{ if(bg_coll_D() && kandowavewalk){ // check collision below high_byte(currplayer_y) = high_byte(currplayer_y) - eject_D; currplayer_vel_y = 0; - cube_data[currplayer] &= 1; + uint8_store(cube_data, currplayer, cube_data[currplayer] & 1); } } kandowavewalk = 0; @@ -58,7 +58,7 @@ void wave_movement(void){ if (currplayer_vel_y != 0){ if(pad_new[controllingplayer] & PAD_A) { - cube_data[currplayer] |= 2; + uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x02); } } } diff --git a/SAUCE/gamestates/state_game.h b/SAUCE/gamestates/state_game.h index 81eb5e8b..e8c6154e 100644 --- a/SAUCE/gamestates/state_game.h +++ b/SAUCE/gamestates/state_game.h @@ -16,7 +16,7 @@ void x_movement_coll() { if (high_byte(currplayer_x) > 0x10) { bg_coll_floor_spikes(); // check for spikes at the left of the player (fixes standing on spikes) if (bg_coll_R()) { - if (!(options & platformer)) {cube_data[currplayer] |= 0x01; } + if (!(options & platformer)) {uint8_store(cube_data, currplayer, cube_data[currplayer] | 0x01);} else {currplayer_vel_x = 0; } } }