Jump to content
IGNORED

Global Constants


Cisano

Recommended Posts

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?

Link to comment
Share on other sites

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 by Andrew Davie
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

 

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...