INC instructions

GB & Gameboy Color Programming (with the GBZ80 CPU)
Post Reply
Limonadd
Posts: 6
Joined: Sat May 04, 2019 12:46 am

INC instructions

Post by Limonadd » Sat May 04, 2019 4:57 pm

Hey! You said in your tutorial that the command INC -reg16- was bugged. But what kind of bug is it?
And if we use it with an 8 bits register, is there still a bug?

User avatar
akuyou
Posts: 328
Joined: Mon Apr 22, 2019 3:19 am

Re: INC instructions

Post by akuyou » Sat May 04, 2019 9:34 pm

I didn't really explain it well enough did I? I'll get that fixed.

Basically the only problem is if you have the 16 bit registers pointing to the &FE?? range - otherwise there is no problem.

To be honest, this isn't really something to worry about - if you're not using sprites, then you won't have an issue, and if you are, well you probably want to buffer the sprites, and copy them using DMA during Vblank anyway, so you won't need to use INC/DEC during any copy routine... I guess you still need to be careful about if you were using them as loop/score counters and they hit this range though.

Please see the link below for details of the bug:
http://www.devrs.com/gb/files/faqs.html#SpriteBug

here's my tutorial using DMA for sprites (so you won't have to worry about the bug if you use sprites):
http://www.chibiakumas.com/z80/platform3.php#LessonP30

If you want to be sure it won't be a problem, you could avoid the 16 bit commands with a function like this:

Code: Select all

addHL:
	push af
		ld a,1
		add l
		ld l,a
		ld a,h
		adc 0
		ld h,a
	pop af
	ret
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Limonadd
Posts: 6
Joined: Sat May 04, 2019 12:46 am

Re: INC instructions

Post by Limonadd » Sat May 04, 2019 10:04 pm

Oh ok, I see, thanks a lot! :D

Post Reply

Return to “Gameboy Assembly Programming”