Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2015-01-18 04:45:41

bashaus
New member
Registered: 2015-01-18
Posts: 1

Compilation-constants in Assembly

Hello everyone

In C programming, you can use the #define syntax to create a constant for the compiler which will not be represented in code.
Is there an alternative for doing something along these sorts of lines with Assembly?

Example, in C:

    #define TILE_IS_WALK_AND_CYCLE 0
    #define TILE_IS_GRASS 1
    #define TILE_IS_WATER 2
    #define TILE_IS_CYCLE_ONLY 3
    #define TILE_IS_WALK_ONLY 4
    #define TILE_IS_CYCLE_ONLY 5

What would the equivalent be in Z80 assembly?

Thanks for your help!

Offline

 

#2 2015-01-21 16:34:48

Ben
Member
Registered: 2015-01-21
Posts: 10

Re: Compilation-constants in Assembly

Hi,

I'm not sure but I think, as once compiled the constants have been replaced by their value, it depends on your compiler syntax.
For example, with WLA-DX, you can use : ".DEFINE name value" as indicated here : http://ftp.sunet.se/pub/aminet/dev/cross/wla-dx.readme

***********************************************************
----------------
.DEFINE IF $FF0F
----------------

Assigns a number or a string to a definition label.

By default all defines are local to the file where they are
presented. If you want to make the definition visible to all the
files in the project, use .EXPORT.

Here are some examples:

.DEFINE X 1000
.DEFINE FILE "level01.bin"
.DEFINE TXT1 "hello and welcome", 1, "to a new world...", 0
.DEFINE BYTES 1, 2, 3, 4, 5
.DEFINE COMPUTATION X+1

All definitions with multiple values are marked as data strings,
and .DB is about the only place where you can later on use them.

.DEFINE BYTES 1, 2, 3, 4, 5
.DB 0, BYTES, 6

is the same as

.DB 0, 1, 2, 3, 4, 5, 6

Note that you must do your definition before you use it, otherwise
WLA will use the final value of the definition. Here's an example
of this:

.DEFINE AAA 10
.DB AAA            ; will be 10.
.REDEFINE AAA 11

but

.DB AAA            ; will be 11.
.DEFINE AAA 10
.REDEFINE AAA 11

You can also create definitions on the command line. Here's an
example of this:

wla-gb -vl -DMOON -DNAME=john -DPRICE=100 -DADDRESS=$100 math.s

MOON's value will be 0, NAME is a string definition with value "john",
PRICE's value will be 100, and ADDRESS's value will be $100.

Note that

.DEFINE AAA = 10   ; the same as ".DEFINE AAA 10".

works as well.

This is not a compulsory directive.

***********************************************************

Even if you're not using WLA-GX, i think you can try this : compiler syntax are quite similar.

I hope it will help you.

Last edited by Ben (2015-01-21 16:35:19)


[Ben]
-----------------------------------------------------

Offline

 

#3 2015-01-26 07:12:03

Sanqui
Moderator
Registered: 2013-01-04
Posts: 20

Re: Compilation-constants in Assembly

In RGBDS, you can use EQU to define constants.

Code:

TILE_IS_WALK_AND_CYCLE  EQU 0
TILE_IS_GRASS           EQU 1
TILE_IS_WATER           EQU 2

etc.

Last edited by Sanqui (2015-01-26 07:13:09)

Offline

 

#4 2015-02-01 12:57:25

NicklausW
Member
Registered: 2014-02-09
Posts: 22

Re: Compilation-constants in Assembly

WLA lets you do three syntactically correct forms of define:

.define pizza 7
.def pizza 7
.equ pizza 7

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson