[4.1] Variable usage statistics (from the Scrolling Platformer Module)

jorotroid

Member
I'm not sure if everyone will find this as interesting as I do, but I think this one step on helping me understanding how 4.1 code is set up. While poking around the scrolling code trying to understand it, I wanted to know how the screenFlags were set, but I quickly found there there was a screenFlags declared in ModuleVariables.asm and a ScreenFlags declared in the Zero Page Ram. Trying to figure out the difference between them, I found that ScreenFlags was never actually used elsewhere in the code. This got me wondering if there were other declared variables like that in the code that never get used again. So I wrote a really slow script to count up how many times each variable shows up in the code.

There appears to be 55 variables that are only show up once in the code when they are declared, so that means that these variable are not being used at all and you are probably safe to remove them (at least in the scrolling platfromer module). I probably would leave in the 3 variables that are related to sound just in case. The variables with a * after their address represent variables that allocated more than one byte, and I just counted all variations of that variable as one. So for example a variable like Object_x_hi could appear in the code as Object_x_hi,x or Object_x_hi,y, but for my script all those variations would just add to the total count for Object_x_hi.

I see two ways this list could be helpful:
1. You can free up some space by removing variables that never get used.
2. The can help you decide if a variable might be better off in the Zero Page if it is more frequently use. Zero page variables have an address of 00FF or less. An example contender would be the variable xScroll at address 044E that gets used 55 times.

WARNING: Use this list as a guide to do further investigations on how to optimize your code. Assume my script that made this list isn't perfect. If you are thinking of removing a variable, try renaming it first. If my script was wrong and the variable was used more than once, then the assembler should give you an error so you will know that you should keep that variable.

I'll include my powershell script as an attachment if anyone wants to use it sometime down the line after their games and code have grown, but just so you know it's a pretty inefficient algorithm and could take about an hour+ to run.

#uses Address Name
----------------------------
0001 - R:0004:sound_local_byte_2
0001 - R:0009*:sound_local_word_2
0001 - R:000D:sound_param_byte_2
0001 - R:0069:screenTimer
0001 - R:006A:screenTimerMicro
0001 - R:00B7:spriteDrawTop
0001 - R:00B8:sprite_drawVoffset
0001 - R:00B9:sprite_drawHoffset
0001 - R:00D4:edge_trap_flag
0001 - R:00D6:seam_trigger_flag
0001 - R:0439*:updateNT_att_fire_Address_hif
0001 - R:0453:scrollNTCheck
0001 - R:0455:doUpdateColumn
0001 - R:0456:readyToUpdateScroll
0001 - R:0457:nametableOffset
0001 - R:0459:columnToPull
0001 - R:045C:eek:verwriteAtt_column
0001 - R:045D:eek:bjectScrollOffset
0001 - R:0463:colTemp
0001 - R:0464*:columnPointer
0001 - R:0469:NMI_scrollNT
0001 - R:046A:columnTrackerHi
0001 - R:046C:scrollUpdateInProgress
0001 - R:046D:ScreenFlags
0001 - R:046E:newNtCued
0001 - R:0470:rNT
0001 - R:0475:eek:bjectColumnHold
0001 - R:047C:theFlag
0001 - R:047D:tempObj
0001 - R:0602:textBoxFlag
0001 - R:060A:stringTemp
0001 - R:060B:stringEnd
0001 - R:062E:updateNT_status
0001 - R:0639:updateNT_bank
0001 - R:0640:updateNT_holdY
0001 - R:064E:updateCHR_max
0001 - R:064F:updateCHR_translate
0001 - R:0650:updateCHR_pointer
0001 - R:0656:updateHUD_MAX_VALUE
0001 - R:0664:HudImageToDraw
0001 - R:0665:boxToChange_width
0001 - R:0666:boxToChange_height
0001 - R:0667:boxToChangeX
0001 - R:0668:boxToChangeY
0001 - R:0669:boxToChange_attWidth
0001 - R:066A:boxToChange_attHeight
0001 - R:066E:sfxPriority
0001 - R:0670:updateHud_tile
0001 - R:0694:eek:bject1TilesToLoad
0001 - R:0699:mapLevel
0001 - R:069A:nt_var
0001 - R:069B:myEdgeAction
0001 - R:069C:mySolidAction
0001 - R:06D0:updateOneChrTile
0001 - R:06DE:ntTester
0002 - R:006C:ScreenByte00
0002 - R:006D:ScreenByte01
0002 - R:007F*:spriteSubPal_0
0002 - R:0083*:spriteSubPal_1
0002 - R:0087*:spriteSubPal_2
0002 - R:008B*:spriteSubPal_3
0002 - R:00B1:gameSubState
0002 - R:00E2:navToScreen
0002 - R:016C*:stream_return_address_lo
0002 - R:0172*:stream_return_address_hi
0002 - R:045A:columnToUpdate
0002 - R:045F:secondNametable
0002 - R:0471:lNT
0002 - R:0473:screenSeam
0002 - R:0474:ObjectSeamLoadFlag
0002 - R:057A*:Object_total_tiles
0002 - R:0609:stringGroupOffset
0002 - R:0615:underSlash
0002 - R:0616:underStomp
0002 - R:0617:underSecret
0002 - R:0618:underBoss
0002 - R:063E:updateNT_tableLeft
0002 - R:0643:OverwriteNT
0002 - R:064C:updateCHR_counter
0002 - R:064D:updateCHR_offset
0002 - R:0658:updateHUD_ROW
0002 - R:0659:updateHUD_COLUMN
0002 - R:0675:screenSpeed
0002 - R:0681:pathTile01
0002 - R:0682:pathTile02
0002 - R:0683:pathTile03
0002 - R:06C7:colX
0002 - R:06D8:player1_weapon
0003 - R:0010*:sound_param_word_1
0003 - R:0012*:sound_param_word_2
0003 - R:00A7:randomSeed2
0003 - R:00AD:eek:bjGraphicsBank
0003 - R:00B6:spriteDrawLeft
0003 - R:00CE:camPad_L_lo
0003 - R:00CF:camPad_L_hi
0003 - R:00D0:camPad_R_lo
0003 - R:00D1:camPad_R_hi
0003 - R:00D3:textVar
0003 - R:00D8:tempTileUpdate_lo
0003 - R:00D9:tempTileUpdate_hi
0003 - R:00DA*:tempChangeTiles
0003 - R:00E5:mapPosX
0003 - R:00E6:mapPosY
0003 - R:014E*:stream_channel_register_2
0003 - R:044C:updateCol_rows
0003 - R:0450:yScroll
0003 - R:0454:checkForSpriteZero
0003 - R:046B:scrollColumn
0003 - R:0472:scroll_hold
0003 - R:047E:loadMonsterColumnFlag
0003 - R:0552*:Object_table_lo_lo
0003 - R:055C*:Object_table_lo_hi
0003 - R:0566*:Object_table_hi_lo
0003 - R:0570*:Object_table_hi_hi
0003 - R:0600:canUpdateScreen
0003 - R:0603*:screenText
0003 - R:061A:HudHandler
0003 - R:061E:update_screen_att_offset
0003 - R:061F:update_screen_col_offset
0003 - R:0672:eek:bjectFrameCount
0003 - R:0678:screenTypeAndSongNumber
0003 - R:067A:mon2SpawnData
0003 - R:067B:mon3SpawnData
0003 - R:067C:mon4SpawnData
0003 - R:0680:pathTile00
0003 - R:0693:screenSpecificTilesToLoad
0003 - R:06A4:myHvel
0003 - R:06A5:myVvel
0003 - R:06CF:continueMap
0003 - R:06D1:writingText
0003 - R:06DC:updateNT_compensation
0003 - R:06EA:UserVar_0
0003 - R:06EE:myMoney
0003 - R:06EF:UserVar_5
0003 - R:06F0:UserVar_6
0003 - R:06F1:UserVar_7
0004 - R:0007*:sound_local_word_1
0004 - R:001D:apu_square_1_old
0004 - R:001E:apu_square_2_old
0004 - R:001F*:song_list_address
0004 - R:0021*:sfx_list_address
0004 - R:004D:selfNT_L
0004 - R:004E:selfNT_R
0004 - R:0053:eek:therNT_L
0004 - R:0054:eek:therNT_R
0004 - R:0055:selfCenterX
0004 - R:0056:selfCenterY
0004 - R:0057:eek:therCenterX
0004 - R:0058:eek:therCenterY
0004 - R:006F*:bckPal
0004 - R:00A0:newGO1Pal
0004 - R:00A1:newGO2Pal
0004 - R:00A5:sleeping
0004 - R:00AC:graphicsBank
0004 - R:00AF:chrRamBank
0004 - R:00B2:newGameState
0004 - R:00BD:tileset_offset
0004 - R:00CA*:updateHUD_POINTER
0004 - R:00D2:update_screen_data_flag
0004 - R:00D5:scrollRoomDataFlag
0004 - R:00D7:testFlagThing
0004 - R:00E4:activateWarpFlag
0004 - R:00E7:doNMI
0004 - R:010C*:stream_note_length_lo
0004 - R:0451:rowTracker
0004 - R:0466:OverwriteNT_column
0004 - R:0476:camL_lo
0004 - R:0478:camR_lo
0004 - R:0479:camR_hi
0004 - R:047A:tempNT
0004 - R:047F:loadingTilesFlag
0004 - R:0502*:Object_action_timer
0004 - R:053E*:Object_end_action
0004 - R:0548*:Object_edge_action
0004 - R:0598*:Object_ID
0004 - R:05D4*:Object_origin_x
0004 - R:05DE*:Object_origin_y
0004 - R:0601:DrawOrderTemp
0004 - R:060D:CurrentMonsterSpawnData
0004 - R:0610:gameTimerLo
0004 - R:0611:gameTimerHi
0004 - R:0612:gameTimer
0004 - R:0613:edgeLoaderInCue
0004 - R:0619:DrawFlags
0004 - R:061D:update_screen_hud_offset
0004 - R:0642:dummyVar2
0004 - R:0651:updateHUD_ASSET_TYPE
0004 - R:0657:updateHUD_BLANK
0004 - R:066C:sfxToPlay
0004 - R:0676:warpToScreen
0004 - R:067D:monsterGroup
0004 - R:067F:eek:bjectTilesToLoad
0004 - R:06A2:monsterCounter
0004 - R:06A3:targetCounter
0004 - R:06C6:eek:ctant
0004 - R:06D4*:eek:bjectID
0004 - R:06E2:moreText
0005 - R:0000:sound_region
0005 - R:0018*:base_address_note_table_lo
0005 - R:001A*:base_address_note_table_hi
0005 - R:001C:apu_data_ready
0005 - R:004F:eek:therLeft
0005 - R:0050:eek:therRight
0005 - R:0051:eek:therTop
0005 - R:0052:eek:therBottom
0005 - R:0067:buttonStates
0005 - R:009F:newPal
0005 - R:00BA*:sprite_pointer
0005 - R:00BC:sprite_tileOffset
0005 - R:0112*:stream_note_length_hi
0005 - R:0142*:stream_channel
0005 - R:0441*:updateNT_fire_Att
0005 - R:044B:updateCol_rowCounter
0005 - R:044D:updateCol_table
0005 - R:0477:camL_hi
0005 - R:0534*:Object_animation_offset_speed
0005 - R:0608:stringGroupPointer
0005 - R:0614:weaponsUnlocked
0005 - R:0629*:updateNT_fire_att_hi
0005 - R:063C:updateNT_details
0005 - R:067E:maxMonsters
0005 - R:069E:tempMaxSpeed
0005 - R:06A0:skipNMI
0005 - R:06C8:recoil_selfX
0005 - R:06C9:recoil_otherX
0005 - R:06CA:recoil_selfY
0005 - R:06CB:recoil_otherY
0005 - R:06CC:continueScreen
0005 - R:06D2:updatePalettes
0005 - R:06E6:arg3Temp
0005 - R:06E7:playerTimer_lo
0005 - R:06E8:playerTimer_hi
0005 - R:06ED:myLives
0006 - R:0025*:apu_register_sets
0006 - R:0049:selfLeft
0006 - R:004A:selfRight
0006 - R:004B:selfTop
0006 - R:004C:selfBottom
0006 - R:008F*:spritePalFade
0006 - R:00A2:newObj1Pal
0006 - R:00A3:newObj2Pal
0006 - R:00A6:randomSeed1
0006 - R:00BE*:drawOrder
0006 - R:00DE:screenPrizeCounter
0006 - R:0124*:stream_instrument_index
0006 - R:0400:HudChecker
0006 - R:0431*:updateNT_att_fire_Address_lo
0006 - R:0449:updateCol_columns
0006 - R:050C*:Object_animation_timer
0006 - R:0652:updateHUD_ASSET_X
0006 - R:065A:updateHUD_inverse
0006 - R:0673:currentObject
0006 - R:0677:warpMap
0006 - R:0687:CL_path
0006 - R:0689:BL_path
0006 - R:068B:BR_path
0006 - R:06A6*:screenTriggers
0006 - R:06CD:continuePositionX
0006 - R:06CE:continuePositionY
0006 - R:06DA:genericTimer
0006 - R:06E9:playerTimer_state
0007 - R:0003:sound_local_byte_1
0007 - R:0068:vBlankTimer
0007 - R:00E0:playerToSpawn
0007 - R:0118*:stream_note_length_counter_lo
0007 - R:0467:OverwriteNT_row
0007 - R:0516*:Object_health
0007 - R:0584*:Object_timer_0
0007 - R:062D:change_state
0007 - R:064A:hudElementTilesFull
0007 - R:066B:songToPlay
0007 - R:066F:currentSong
0007 - R:0679:mon1SpawnData
0007 - R:0684:TL_path
0007 - R:0688:CR_path
0007 - R:068C:currentPathTile_TL
0007 - R:068D:currentPathTile_TR
0007 - R:068E:currentPathTile_BL
0007 - R:068F:currentPathTile_BR
0007 - R:06A1:screen_transition_type
0007 - R:06E5:arg2Temp
0007 - R:06EB:myHealth
0008 - R:005F:collisionPoint2
0008 - R:0060:collisionPoint3
0008 - R:0061:collisionPoint4
0008 - R:0062:collisionPoint5
0008 - R:00DF:tileCollisionFlag
0008 - R:00E1:navFlag
0008 - R:00E3:loadObjectFlag
0008 - R:011E*:stream_note_length_counter_hi
0008 - R:0468:forceScroll
0008 - R:047B:eek:bjectID_forSeamLoad
0008 - R:060E:spawnX
0008 - R:060F:spawnY
0008 - R:0625*:updateNT_fire_att_lo
0008 - R:0634:updateNT_attHeight
0008 - R:0637*:updateNT_positionToUpdate
0008 - R:0649:hudElementTilesToLoad
0008 - R:0686:TR_path
0008 - R:068A:BC_path
0008 - R:0691:yPrev
0008 - R:06DB:prevent_scroll_flag
0009 - R:0014*:sound_param_word_3
0009 - R:0045*:updateNT_ntPointer
0009 - R:00A4:soft2001
0009 - R:00AB:screenType
0009 - R:00AE:tempBank
0009 - R:013C*:stream_duty_offset
0009 - R:0520*:Object_animation_frame
0009 - R:064B:hudTileCounter
0009 - R:0655:updateHUD_STRING
0009 - R:065B:hudElementTilesMax
0009 - R:0685:TC_path
0009 - R:0692:backgroundTilesToLoad
0009 - R:0698:currentScreen
0009 - R:06E3:arg0Temp
0009 - R:06E4:arg1Temp
0010 - R:00B0:gameState
0010 - R:00B4:newY
0010 - R:00B5:spriteOffset
0010 - R:00CC:npc_collision
0010 - R:044A:updateCol_columnCounter
0010 - R:0462:newNametable
0010 - R:0620:update_screen_bck_graphics_bank
0010 - R:063B:updateNT_att
0010 - R:0653:updateHUD_ASSET_Y
0010 - R:0671:ActivateHudUpdate
0010 - R:0690:xPrev
0010 - R:069D:tempAccAmount
0010 - R:069F:nt_index_hold
0010 - R:06D9:align_screen_flag
0010 - R:06E1:textboxOffsetHold
0011 - R:005E:collisionPoint1
0011 - R:0654:updateHUD_IMAGE
0012 - R:0016*:base_address_instruments
0012 - R:00B3:newX
0012 - R:012A*:stream_volume_offset
0012 - R:0136*:stream_pitch_offset
0012 - R:0184*:stream_tempo_lo
0012 - R:018A*:stream_tempo_hi
0012 - R:058E*:Object_flags
0012 - R:05E8*:Object_state_flags
0012 - R:060C:ObjectToLoad
0012 - R:0695:TileCounter
0012 - R:06DD:tilesToWrite
0012 - R:0700*:collisionTable2
0013 - R:0148*:stream_channel_register_1
0013 - R:015A*:stream_channel_register_4
0013 - R:0631:updateNT_rows
0013 - R:06D3:updateNametable
0014 - R:0001:sound_disable_update
0014 - R:000E*:sound_param_word_0
0014 - R:0160*:stream_read_address_lo
0014 - R:0166*:stream_read_address_hi
0014 - R:04F8*:Object_vulnerability
0014 - R:052A*:Object_action_step
0014 - R:0607:tempCol
0014 - R:0645:updateHUD_fire_Address_Lo
0014 - R:065C*:value
0015 - R:005D:collisionPoint0
0015 - R:0106*:stream_note
0015 - R:0178*:stream_tempo_counter_lo
0015 - R:017E*:stream_tempo_counter_hi
0015 - R:045B:scrollDirection
0015 - R:0461:leftNametable
0015 - R:0633:updateNT_attWidth
0015 - R:0646:updateHUD_fire_Address_Hi
0015 - R:0647:updateHUD_fire_Tile
0016 - R:000C:sound_param_byte_1
0016 - R:00C8*:updateNT_pointer
0016 - R:0130*:stream_arpeggio_offset
0016 - R:0401*:updateNT_fire_Address_Lo
0016 - R:0411*:updateNT_fire_Address_Hi
0016 - R:0421*:updateNT_fire_Tile
0016 - R:0452:showingNametable
0016 - R:0644:UpdateAtt
0017 - R:0460:rightNametable
0017 - R:0621:updateTile_00
0017 - R:0622:updateTile_01
0017 - R:0623:updateTile_02
0017 - R:0624:updateTile_03
0017 - R:063F:updateNT_attMask
0017 - R:06EC:myScore
0018 - R:0040:tempz
0018 - R:061C:update_screen_details
0019 - R:0039:loopTemp
0019 - R:066D:fireSoundByte
0020 - R:000B:sound_param_byte_0
0020 - R:00AA:screenBank
0020 - R:0154*:stream_channel_register_3
0020 - R:063D:DrawHudBytes
0021 - R:06DF:currentMap
0022 - R:0023*:song_address
0022 - R:062F:updateNT_columns
0022 - R:0636:updateNT_V_offset
0023 - R:005B:yHold_lo
0023 - R:048A*:Object_type
0023 - R:0641:updateNT_att_odds
0024 - R:0059:xHold_lo
0024 - R:0066:gamepad
0024 - R:046F:nt_hold
0025 - R:061B:update_screen
0026 - R:04A8*:Object_x_lo
0026 - R:0632:updateNT_rowCounter
0026 - R:063A:updateNT_offset
0026 - R:06E0:updateHUD_active
0027 - R:0300*:collisionTable
0027 - R:04BC*:Object_y_lo
0028 - R:044F:xScroll_hi
0029 - R:0047*:updateNT_pos
0029 - R:045E:currentNametable
0029 - R:0696:TilesToLoad
0031 - R:0002:sound_local_byte_0
0031 - R:05B6*:Object_bottom
0031 - R:0697:newScreen
0032 - R:05C0*:Object_left
0032 - R:0648:updateHUD_offset
0033 - R:0630:updateNT_columnCounter
0033 - R:0635:updateNT_H_offset
0035 - R:00CD:textboxHandler
0035 - R:05AC*:Object_top
0035 - R:0674:gameHandler
0036 - R:0458:columnTracker
0040 - R:003F:tempy
0040 - R:05CA*:Object_right
0045 - R:0100*:stream_flags
0046 - R:0480*:Object_status
0047 - R:04DA*:Object_h_speed_lo
0047 - R:04EE*:Object_movement
0049 - R:04C6*:Object_v_speed_lo
0051 - R:0494*:Object_physics_byte
0051 - R:04D0*:Object_v_speed_hi
0053 - R:04E4*:Object_h_speed_hi
0054 - R:005C:yHold_hi
0055 - R:044E:xScroll
0059 - R:003E:tempx
0060 - R:00A8:currentBank
0064 - R:05A2*:Object_scroll
0069 - R:005A:xHold_hi
0071 - R:003D:temp3
0074 - R:0065:tile_solidity
0074 - R:04B2*:Object_y_hi
0075 - R:0043*:collisionPointer
0080 - R:049E*:Object_x_hi
0081 - R:006B:player1_object
0085 - R:003C:temp2
0086 - R:0063:tileX
0091 - R:0005*:sound_local_word_0
0101 - R:0064:tileY
0105 - R:00A9:prevBank
0118 - R:003B:temp1
0132 - R:0041*:temp16
0363 - R:003A:temp
 

Attachments

  • varReporter.zip
    982 bytes · Views: 75

Kasumi

New member
I'll add an additional warning! A variable can be used even without its address/name appearing in the ROM or listing, so being able to rename a seemingly unused variable without any change in program behavior does not necessarily mean it's safe to remove.

Code:
temp .dsb 1
temp2 .dsb 1
something .dsb 1

ldx #1
lda temp,x;Accesses temp2, but not by name or address
In the above case it might have made more sense to just make temp .dsb 2, but some cases like that aren't as cut and dry.
 

Bucket Mouse

Active member
stringEnd only showed up once in 4.0.6 as well. Drove me crazy trying to find it, because it seemed to be the key to stringing all four text boxes together.

I wonder what TextBoxOffsetHold does.
 
Top Bottom