Cisano Posted February 14, 2022 Share Posted February 14, 2022 (edited) My game has 4k+4k and I need global static variables. If it possible to define them in one bank only? If yes, how? Thanks. Edited February 14, 2022 by Cisano Quote Link to comment Share on other sites More sharing options...
+Karl G Posted February 14, 2022 Share Posted February 14, 2022 Unless I am misunderstanding you here, all 128 bytes of your zero page RAM will be accessible from both banks. Edit: I misread your question. I don't know of a way to force variables to only be visible from one bank. Quote Link to comment Share on other sites More sharing options...
Cisano Posted February 14, 2022 Author Share Posted February 14, 2022 I have this (a small part) in my code in the Bank 0 FreqFtgrGrp0 .byte #5 ColorWall .byte #$f4 ColorWater .byte #$94 Now, in the Bank 1 I have some code uses these variables. I don't want to re-define in the Bank 1, because I must change the name. How can I use them in the Bank 1? Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted February 14, 2022 Share Posted February 14, 2022 Are they variables (will be changed while the game is running) or are they constants (set once, never changed again)? Quote Link to comment Share on other sites More sharing options...
Cisano Posted February 14, 2022 Author Share Posted February 14, 2022 They are constants. Oh, I made a mistake in the title... (now changed) Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted February 14, 2022 Share Posted February 14, 2022 FreqFtgrGrp0 = 5 ColorWall = $f4 ColorWater = $94 ;-- an example of usage: LDA #ColorWall STA COLUPF You just need to treat constants as labels that get assigned values. 1 Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted February 14, 2022 Share Posted February 14, 2022 (edited) Have a master file that includes all the other files. e.g., "main.asm" includes "zeropage.asm" and "BANK1.asm" etc. when you assemble, you assemble "main.asm". The vars and constants get defined, wherever, somewhere in that (or included files)... and when your banks come around, those symbols are already defined. In fact dasm doesn't need stuff to be defined before use; the assembler does multiple passes. Does this help? edit: I guess I misunderstood the Q! Edited February 14, 2022 by Andrew Davie Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted February 14, 2022 Share Posted February 14, 2022 1 hour ago, Cisano said: FreqFtgrGrp0 .byte #5 ColorWall .byte #$f4 ColorWater .byte #$94 You are not defining variables or constants here. You are defining data which is stored in ROM. For constants see @splendidnut's post. Quote Link to comment Share on other sites More sharing options...
Cisano Posted February 14, 2022 Author Share Posted February 14, 2022 Everywhere the variable is used, get the that value. But only in the Bank where is declared. A solution for both the Banks? PS. Andrew Davie all the code is amost done and this is the last step. Quote Link to comment Share on other sites More sharing options...
glurk Posted February 14, 2022 Share Posted February 14, 2022 3 hours ago, Cisano said: I have this (a small part) in my code in the Bank 0 FreqFtgrGrp0 .byte #5 ColorWall .byte #$f4 ColorWater .byte #$94 Now, in the Bank 1 I have some code uses these variables. I don't want to re-define in the Bank 1, because I must change the name. How can I use them in the Bank 1? Those are not variables or constants. Those are tables. Three one-byte tables. As was said, just define them as labels. Quote Link to comment Share on other sites More sharing options...
Cisano Posted February 14, 2022 Author Share Posted February 14, 2022 Ok, Ok I have understood my mistake and how to do. That was a table Thanks to all. When complete, I show you the game. Bye. Quote Link to comment Share on other sites More sharing options...
tokumaru Posted February 15, 2022 Share Posted February 15, 2022 There are legitimate reasons for having equivalent tables in multiple banks with different contents though, even though it turned out that this was not what the OP needed. If that was the case though, you'd just need to make sure that the tables started at the same addresses in every bank, and that all the lengths matched. Only one set of tables would need labels. For the others, you could optionally write code to have the assembler validate their positions (i.e. compare the PC at the position where the label would be to the label of the original table and stop assembly in case of a mismatch). Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted February 15, 2022 Share Posted February 15, 2022 To build upon @splendidnut's example, if you define color constants you can easily switch between NTSC and PAL builds: NTSC = 0 PAL = 1 PAL60 = 2 COMPILE_VERSION = NTSC BLACK = $00 WHITE = $0E IF COMPILE_VERSION = NTSC GREY = $00 YELLOW = $10 ORANGE = $20 RED_ORANGE = $30 RED = $40 PURPLE = $50 VIOLET = $60 INDIGO = $70 BLUE = $80 BLUE2 = $90 TURQUOISE = $A0 CYAN = $B0 GREEN = $C0 YELLOW_GREEN = $D0 OCHRE_GREEN = $E0 OCHRE = $F0 ELSE GREY = $00 YELLOW = $20 ; no real equivalent ORANGE = $20 RED_ORANGE = $40 RED = $60 PURPLE = $80 VIOLET = $A0 INDIGO = $C0 BLUE = $D0 BLUE2 = $B0 TURQUOISE = $90 CYAN = $70 GREEN = $50 YELLOW_GREEN = $30 OCHRE_GREEN = $30 ; no real equivalent OCHRE = $20 ; no real equivalent ENDIF Then use those constants in your code like this: lda #GREEN+4 sta COLUP0 lda #VIOLET+8 sta COLUP1 The +4 and +8 set the LUMA value. 2 Quote Link to comment Share on other sites More sharing options...
+Al_Nafuur Posted February 15, 2022 Share Posted February 15, 2022 27 minutes ago, SpiceWare said: Then use those constants in your code like this: lda #GREEN+4 sta COLUP0 lda #VIOLET+8 sta COLUP1 The +4 and +8 set the LUMA value. You might also use constants for the LUMA : DARKEST = $0 DARKER = $2 DARK = $4 LIGHT = $6 LIGHTER = $8 BRIGHT = $A BRIGHTER = $C BRIGHTEST = $E lda #DARKEST+GREEN 2 Quote Link to comment Share on other sites More sharing options...
Cisano Posted March 15, 2022 Author Share Posted March 15, 2022 Thanks to everyone. 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.