Punch wrote:
ZX sounds like a cool platform to experiment on.
If an NES or C64 veteran were to experiment with the ZX Spectrum for the first time, he would first have to spend time wrapping his head around the Z80.
In subroutines in 6502 games that move an object of a particular type, I've often needed random access to the fields of an object. Say field 5 of a particular object is its health.
- Read field 5 of the object with array index X in struct-of-arrays (6502, C64)
lda object_health,x: 4 cycles, 3.9 μs - Read field 5 of the object pointed by A0 in array-of-structs (68000, Amiga)
move.w 10(a0),d0: 12 cycles, 1.7 μs - Read field 5 of the object pointed by IX in array-of-structs (Z80, ZX Spectrum)
ld a,(ix+5): 19 cycles, 5.4 μs
Is there a Z80 tutorial specifically targeted at people with a 6502 background, which explains how common idioms of game state organization on the 6502 translate efficiently to the 8080 family (8080/8085, Z80, LR35902), whose indexed modes are slow (Z80) or software-defined using
add (others)? I have been told the 8080 family expects arrays to be aligned to the start of a 256-byte page, so that the program can load the field number in L and the object number in H or vice versa, but then any array with fewer than 256 elements wastes the remainder of the page. For the cases I'm considering (10-30 fields of 5-20 objects), aligning them without
crossing pages is easy, but aligning them to the
start of a page appears trickier. Would I have to consider the RAM as an "atlas" analogous to a
texture atlas, with RAM being a two-dimensional array divided into rectangular sub-arrays, each with object index as one dimension, field index as the other dimension, and a stride of 256 bytes?
Some 8080-family coders suggest organizing data for a single-instruction, multiple-data (SIMD) approach that steps through two arrays at a time using DE and HL. For example, a program would update object positions in four passes: add horizontal acceleration to horizontal velocity of all objects, then add horizontal velocity to horizontal position of all objects, then add vertical acceleration to vertical velocity of all objects, then add vertical velocity to vertical position of all objects. Pixel shaders on modern graphics programs work similarly. But that doesn't work so well when a particular operation needs to be performed only on particular types of object or only in certain circumstances, which is often the case for enemy AI code that has to determine the accelerations for each object based on collision response, displacement to the player object, and other factors.
If I have asked before, and I am asking again, it's because when I did get an answer, it was one that I couldn't understand how to apply. Hence "wrapping my head around the Z80". Would basic questions like this be better received in a forum organized around a particular platform using an 8080 family CPU, such as
Spectrum Computing (or, in the case of other platforms,
SMS Power or
gbdev.gg8.se)?