GBZ80:LD HL,(SP+e) 如何影响 H 和 C 标志?
在 Gameboy Z80 上,LD HL,(SP+e)
操作究竟如何影响 H 和 C 标志? (半进位+进位)
On Gameboy Z80, exactly how does the LD HL,(SP+e)
operation affect H and C flags? (Half-carry + carry)
Reference: http://www.devrs.com/gb/files/opcodes.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我意识到这是一个老问题,但我不久前遇到了类似的问题,只想添加我的解决方案,因为据我所知,绝对没有文档或开源模拟器可以正确执行此操作。我在真正的游戏机上进行了一些实际调试来找到解决方案。
对于 16 位 SP + s8(有符号立即数)操作:
如果第 7 位到第 8 位发生溢出,则设置进位标志。
如果从第 3 位溢出到第 4 位,则设置半进位标志。
我发现对正数和负数立即数(Lua)分别执行该行为更容易:
I realise this is an old question but I had a similar problem a while ago and would just like to add my solution as there is absolutely no documentation or open-source emulator that does it correctly to my knowledge. Took me some actual debugging on a real gameboy to find the solution.
For both 16bit SP + s8 (signed immediate) operations:
the carry flag is set if there's an overflow from the 7th to 8th bit.
the half carry flag is set if there's an overflow from the 3rd into the 4th bit.
I found it easier to do the behaviour separately for both a positive and negative signed immediate (Lua):
如下所示: http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html SP+e 之和影响半进位和进位标志,因此应检查第 3 位到第 4 位以及第 7 位到第 8 位(从 0 开始!)是否有进位
As seen here: http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html The sum of SP+e affects the Half Carry and the Carry flag, so you should check if there's carry from bit 3 to 4 and from 7 to 8 (Starting by 0!)