- Top Stats

Top Posters Top Topic Starters Top Topics
AMSDOS 1288
arnoldemu 1128
TFM 1124
ervin 745
ronaldo 403
AMSDOS 55
arnoldemu 51
ervin 42
EgoTrip 35
Arnaud 33
FutureOS corner - 70683 Views TFM/FS 07:12, 01 October 10
Example Z80 as... - 66053 Views arnoldemu 10:59, 04 April 10
#CPCtelera 1.4... - 32989 Views ronaldo 13:59, 11 May 15
BASIC programm... - 30901 Views arnoldemu 16:23, 22 May 09
CHAMP Assemble... - 24968 Views Bruce Abbo... 12:59, 16 January 14


Author Topic: trying not to use IX  (Read 1249 times)

0 Members and 1 Guest are viewing this topic.

Offline trabitboy

  • Supporter
  • CPC664
  • *
  • Posts: 90
  • Country: be
  • Liked: 50
trying not to use IX
« on: 16: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?

Online Bryce

  • The Hardware Guy.
  • Supporter
  • 6128 Plus
  • *
  • Posts: 10.755
  • Country: wf
  • It's not broken, it just hasn't been fixed yet.
    • index.php?action=treasury
  • Liked: 3743
Re: trying not to use IX
« Reply #1 on: 16:19, 15 September 16 »
Maybe you should take a look at some disassembled GB code to see how the commercial GB coders did it?

Bryce.

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 829
  • Liked: 379
Re: trying not to use IX
« Reply #2 on: 16:34, 15 September 16 »
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.

Offline Docent

  • CPC6128
  • ****
  • Posts: 155
  • Country: pl
  • Liked: 104
Re: trying not to use IX
« Reply #3 on: 16:39, 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
« Last Edit: 17:13, 15 September 16 by Docent »

Offline trabitboy

  • Supporter
  • CPC664
  • *
  • Posts: 90
  • Country: be
  • Liked: 50
Re: trying not to use IX
« Reply #4 on: 16:55, 15 September 16 »
well lots of good answers thant you very much !   8)

Offline Prodatron

  • 6128 Plus
  • ******
  • Posts: 830
  • Country: de
  • Back on the Z80
    • index.php?action=treasury
    • SymbOS SYmbiosis Multitasking Based Operating System
  • Liked: 1059
Re: trying not to use IX
« Reply #5 on: 17: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.

[...]
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

Offline Axelay

  • 6128 Plus
  • ******
  • Posts: 545
  • Country: au
  • Liked: 344
Re: trying not to use IX
« Reply #6 on: 17:44, 15 September 16 »
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.

Offline Docent

  • CPC6128
  • ****
  • Posts: 155
  • Country: pl
  • Liked: 104
Re: trying not to use IX
« Reply #7 on: 19:21, 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

Offline trabitboy

  • Supporter
  • CPC664
  • *
  • Posts: 90
  • Country: be
  • Liked: 50
Re: trying not to use IX
« Reply #8 on: 10:24, 16 September 16 »
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 !!!!

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.587
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 852
Re: trying not to use IX
« Reply #9 on: 11:47, 16 September 16 »
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 some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)