Better global data support for tools

Assembler Macros

Copyright © 2000 Jarno van der Linden.


Fast search index

freegd
getgdconst
getgdrw
globaldata
globaldataend
<global data tool>


freegd

Force a global data area to be freed

Synopsis

freegd <name> 

Inputs

Description

Normally, the global data will be deleted when the process exits. This macro allows you to force immediate deletion. If you need to use the global data again, you must get a pointer to the data again using the getgd macro. This will create a fresh copy, without any of the changes made before freegd. You better be absolutely sure that the program doesn't use the global data anywhere after it has been freed.

For this macro to work, the name of the data area must be equal to the tool defining the data area. The best way to ensure this is to always use the globaldata and globaldataend macros to define the data.

At present, this macro is does nothing when applied to constant global data.

Example

getgdrw demo/gd/my_data, p0
cpy.i 42,[p0+MYDATA_ANSWER]

; Do lots of stuff...
[...]

; I guarantee not to need the data again from here
freegd demo/gd/my_data

; Do lots more stuff...
[...]

Result

The named global data will be deleted halfway through the program, freeing up valuable resources.

See also

getgdrw


getgdconst

Get a pointer to a constant global data area

Synopsis

getgdconst <name>,<data pointer> 

Inputs

Outputs

Description

This macro fetches a pointer to the named constant global data area. The data

For this macro to work, the name of the data area must be equal to the tool defining the data area. The best way to ensure this is to always use the globaldata and globaldataend macros to define the data.

Example

globaldata 'demo/gd/my_data', GD_CONST
	dc.d 3.141592654
	dc.b 'This is a chunk of constant global data',0
globaldataend

[...]

getgdconst demo/gd/my_data, p0
printf "String = %s\n", (p0+8)

Result

String = This is a chunk of constant global data

See also

freegd getgdrw


getgdrw

Get a pointer to a read/write global data area

Synopsis

getgdrw <name>,<data pointer> 

Inputs

Outputs

Description

This macro fetches a pointer to the named read/write global data area.

For this macro to work, the name of the data area must be equal to the tool defining the data area. The best way to ensure this is to always use the globaldata and globaldataend macros to define the data.

Example

globaldata 'demo/gd/my_data'
	dc.i 69
	dc.b 'This is a chunk of read/write global data',0
	blk.b 256-42,0
globaldataend

[...]

getgdrw demo/gd/my_data, p0
printf "Value = %d\n", [p0]
cpy.p 42,[p0]
printf "New value = %d\n", [p0]

Result

Value = 69
New value = 42

See also

freegd getgdconst


globaldata

Begins a global data section

Synopsis

globaldata "<name>" [, <type>] 

Inputs

Description

Starts a global data area definition. The data will be wrapped in a tool, whose name is the given name. So the name determines where this tool is located.

The created tool can be called to obtain a pointer to the global data.

If the type is GD_RW, the data can be read and written to. Each process will get its own copy of the global data. A type of GD_CONST on the other hand indicates that the data is read-only. The data will be shared by all processes. The type defaults to GD_RW.

The data is aligned on an 8 byte boundary. Any extra alignment you insert with .align, for example, will be part of the data structure. It is probably not a good idea to start a new data or code section within the global data definition.

Example

globaldata 'demo/gd/my_data'
	dc.i 69
	dc.b 'This is a chunk of read/write global data',0
	blk.b 256-42,0
globaldataend

globaldata 'demo/gd/my_const_data', GD_CONST
	dc.d 3.141592654
	dc.b 'This is a chunk of constant global data',0
globaldataend

Result

A tool called demo/gd/my_data which contains the given read/write global data, and a tool called demo/gd/my_const_data which contains the given constant global data.

See also

globaldataend


globaldataend

End a global data section

Synopsis

globaldataend 

Description

Ends a global data section.

See also

globaldata


<global data tool>

Global data tool created by the globaldata macro

Inputs

Outputs

Description

The global data tool that is created by the globaldata macro can be called to obtain a pointer to the global data (or a copy thereof, depending on whether the global data is constant or not).

You probably want to use the getgdconst and getgdrw macro instead of calling the tool directly.

Example

qcall demo/gd/my_data, (0 : p0)
printf "Value = %d\n", [p0]
cpy.p 42,[p0]
printf "New value = %d\n", [p0]
qcall demo/gd/my_data, (1 : p~)

Result

Value = 69
New value = 42

See also

globaldata getgdconst getgdrw