News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_trabitboy

trying not to use IX

Started by trabitboy, 14:04, 15 September 16

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

trabitboy

Hi,
I am now reasonably "fluent" in z80 and I thought I would have a quick look at the gameboy spec ( bouuuuuuuuuuuu ).
I just realized there is no IX !

I use it quite a lot to curse data structures such as

; baddie address is in HL
push HL
pop IX
ld A, (IX+2) ; say ... baddie health
dec A
ld (IX+2),A

what would be the optimal way to avoid use of IX ?

I can imagine "cursing forward" HL using :
; baddie address is in HL
push HL
ld B,0
ld C,2; say ... baddie health
add HL,BC
ld A, (HL)
dec A
ld (HL),A
pop HL

Any other optimised/readable recipes?

Bryce

Maybe you should take a look at some disassembled GB code to see how the commercial GB coders did it?

Bryce.

andycadley

Cursing forward with HL (using INC H or INC L where possible) is a pretty standard way of doing things even in "real" Z80 as it's often faster than the indexed instructions.

Docent

#3
Quote from: trabitboy on 14:04, 15 September 16
Hi,
I am now reasonably "fluent" in z80 and I thought I would have a quick look at the gameboy spec ( bouuuuuuuuuuuu ).
I just realized there is no IX !

I use it quite a lot to curse data structures such as

; baddie address is in HL
push HL
pop IX
ld A, (IX+2) ; say ... baddie health
dec A
ld (IX+2),A

what would be the optimal way to avoid use of IX ?

I can imagine "cursing forward" HL using :
; baddie address is in HL
push HL
ld B,0
ld C,2; say ... baddie health
add HL,BC
ld A, (HL)
dec A
ld (HL),A
pop HL

Any other optimised/readable recipes?

You can use Gameboy cpu specific instructions:
ldi a,(hl) - loads a from (hl) and increments hl
ldi (hl),a
ldd a,(hl) - loads a from (hl) and decrements hl

bear in mind that Sharp LR35902 (Gameboy cpu) has many other differences:
- no alternate register set
- no exchange instructions
- no instructions with DD,ED,FD prefix (ie - no ix,iy related instructions, no 16bit operations like adc hl,bc or  ld bc,(nn))
- no conditionals on parity/sign/overflow
- no in/out
- djnz replaced with stop
Some instructions have different opcodes, there are also a few new instructions.

Here's the list of mnemonics, you can see the difference:)
Gameboy (LR35902) OPCODES

trabitboy

well lots of good answers thant you very much !   8)

Prodatron

IMHO the Gameboy CPU is much closer to the 8080 than to the Z80, but it's still using the Zilog-way for writing the mnemonics.
But maybe it still may help to study some 8080 source codes.

Quote from: trabitboy on 14:04, 15 September 16
[...]
ld A, (HL)
dec A
ld (HL),A
[...]
Any other optimised/readable recipes?

You can replace this with DEC (HL)

GRAPHICAL Z80 MULTITASKING OPERATING SYSTEM

Axelay

Page aligned tables can help with using hl, then as andycadley says, an 8 bit inc or dec on l can be used to traverse it.


Also grouping the enemy data in blocks of related information, if it suits your structures.  So if you have a table of 16 enemies, you might start a table with just the x & y co-ordinates at &8000, then at &8020 you could have the enemy hits and some other related data byte taking the next 32 bytes.  Now checking the collisions need only take 2 incs or decs per baddie traversing through the first table starting at &8000, and if a collision is detected you only need use a set 5,l to get to the hits for the relevant enemy in the table starting at &8020, and a res 5,l to get hl pointing back to the co-ordinates.

Docent

Quote from: Prodatron on 15:30, 15 September 16
IMHO the Gameboy CPU is much closer to the 8080 than to the Z80, but it's still using the Zilog-way for writing the mnemonics.
But maybe it still may help to study some 8080 source codes.
It will be waste of time - by default 8080 mnemonics use completely different naming convention, eg.
mov a,b -> ld a,b
ldax b -> ld a, (bc)
while almost every source for Gameboy is based on z80 mnemonics

trabitboy

I am looking at this relatively recent homebrew :
GitHub - furrtek/Airaki: Tile-matching RPG puzzle game for the Nintendo GameBoy

I am humbled by the level of the answers in this thread ( particularly astonished by the solution of axelay ), and I thank you again !!!!

AMSDOS

A game boy coder would be coding it all in Assembly. IndeX Registers become more useful when handling code between Assembly and another Language, it can be used In-house with Assembly, though it's possible to use your other registers. I think when I've seen it being used in Assembly, it's usually to hold some value from another Register Pair you need to use while avoiding the use of PUSH & POP (which are also slow).
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod