LatchKeyKid Posted December 13, 2022 Share Posted December 13, 2022 I'm curious about RAM usage on the 2600. I've noticed when watching various youtube videos and reading online resources that registers like NUSIZ0 use every single bit fully. Is it possible to do that for RAM as well? If it's possible, is it practical to access the individual bits or does it use up too many CPU cycles? For example, if you're using a byte of RAM and only need the first 60 values, can you use the other four bits (nibble?) for something completely different to save on RAM? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted December 13, 2022 Share Posted December 13, 2022 21 hours ago, LatchKeyKid said: If it's possible, is it practical to access the individual bits or does it use up too many CPU cycles? For example, if you're using a byte of RAM and only need the first 60 values, can you use the other four bits (nibble?) yes, that's common practice. When using individual bits use the top 2 bits for anything time critical as they can quickly be tested for: For bit 7: BIT $ZP_RAM BPL SKIP ; branch if bit 7 is set to 0 BIT $ZP_RAM BMI SKIP ; branch if bit 7 is set to 1 For bit 6: BIT $ZP_RAM BVC SKIP ; branch if bit 6 is set to 0 BIT $ZP_RAM BVS SKIP ; branch if bit 6 is set to 1 Using BIT means the registers (A, X, Y) do not get overwritten. To test other bits uses the A register, and 2 extra cycles LDA $ZP_RAM AND #%00100000 ; bit 5 BEQ SKIP ; branch if bit 5 is set to 0 LDA #%00100000 ; bit 5 AND $ZP_RAM BNE SKIP ; branch if bit 5 is set to 1 Use %00010000 for bit 4 and so on. The LDA and AND can be in either order, just make sure the # goes with the bit to test. It's also common practice to reuse bytes of RAM for different things at different times. In Medieval Mayhem the RAM used for the castle walls is also used for the main menu: Wall1L ds 6 Wall1R ds 6 Wall2L ds 6 Wall2R ds 6 Wall3L ds 6 Wall3R ds 6 Wall4L ds 6 Wall4R ds 6 ; reuse of Wall RAM for main menu G48 EQU Wall1L ; uses all of Wall1L and Wall1R Option1 EQU Wall2L ; pointer to graphics for 1st displayed option Value1 EQU Wall2L+2 ; pointer to graphics for 1st displayed value Option2 EQU Wall2L+4 ; pointer to graphics for 2nd displayed option Value2 EQU Wall2R ; pointer to graphics for 2nd displayed value Option3 EQU Wall2R+2 ; pointer to graphics for 3rd displayed option Value3 EQU Wall2R+4 ; pointer to graphics for 3rd displayed value Option4 EQU Wall3L ; pointer to graphics for 4th displayed option Value4 EQU Wall3L+2 ; pointer to graphics for 4th displayed value TopOption EQU Wall3L+4 ; top option to display SelectedOption EQU Wall3L+5 ; option selected(0-9) HiLiteOption EQU Wall3R ; option to hilite (0-3) BitOn EQU Wall3R+1 ; ChangeCatch subroutine BitOff EQU Wall3R+2 ; ChangeCatch subroutine LastSelect EQU Wall3R+3 ; used to reset Attract Mode countdown Delay EQU Wall4R MMcolor EQU Wall4R+1 ; holds color of Medieval Mayhem logo SlctValueColor EQU Wall4R+2 ; holds color of selected menu value G48temp1 EQU Wall4R+3 ; holds lines remaining during Show48graphic G48temp2 EQU Wall4R+4 ; holds temp image data during Show48graphic ; end reuse of Wall RAM for main menu 1 Quote Link to comment Share on other sites More sharing options...
LatchKeyKid Posted December 14, 2022 Author Share Posted December 14, 2022 Thanks! I appreciate the detailed explanation as always. I'm glad to hear that the rest of the bits aren't wasted in those scenarios. I was curious if you could, for example, have multiple timers going on the same byte to count different things (like multiple independent effects counters) and am glad to hear that it's potentially possible. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.