sjasm and data structure arrays

Page 2/2
1 |

By DarkSchneider

Paladin (965)

DarkSchneider's picture

08-04-2014, 20:28

I think I don't understand, this
ld h,(ix+enemy_data.x+1)
Does not access to enemy_data[0].status?, because it has a +1, the next byte. Or maybe using structs a +1 implies "+1 struct"?

By ARTRAG

Enlighted (6923)

ARTRAG's picture

08-04-2014, 20:36

The +1 is because the .x field is a word, so L is loaded with the lower byte and H with the upper byte of the filed.
It has nothing to do with the array of structs.
To change array elements in the array you need to do:

[...]
	ld	de,enemy_data
	add ix,de
[...]

while if you want to aim to the previous or to the successive element without moving IX you need to do

[...]
	ld  a,(ix+enemy_data.y-enemy_data)
[...]
	ld  a,(ix+enemy_data.kind+enemy_data)
[...]

By DarkSchneider

Paladin (965)

DarkSchneider's picture

08-04-2014, 20:49

OK.

By that code it seems that using the struct name we get its size, is that right?. So we could do:

ld a, (ix+(enemy_data*index)+enemy_data.y)

By ARTRAG

Enlighted (6923)

ARTRAG's picture

08-04-2014, 21:26

correct!

By Daemos

Paragon (2044)

Daemos's picture

08-04-2014, 22:15

I like to add that once you load your array start point into ix it is very easy to work with enemies. You can for example do a lot of compares by for example loading the two characters into ix and iy and do all sorts of stuff directly by utilizing ix and iy.

When handling a object in game you can leave the ix value unchanged and use it at any point of your call for fetching and writing the required values.

It can allow you to write very complex enemy interactions Smile

Page 2/2
1 |