GBZ80:如何LD HL,(SP + E)影响H和C标志位? [英] GBZ80: How does LD HL,(SP+e) affect H and C flags?
问题描述
在游戏机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)
参考: http://www.devrs.com/gb/文件/ OP codes.html
推荐答案
我意识到这是一个老问题,但我前一阵子也有类似的问题,只是想加我的解决方案,绝对不存在的文件或开放源模拟器,正确地做它给我的知识。我花了一些实际调试一个真正的GAMEBOY,以找到解决方案。
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.
对于这两个16bit的SP + S8(符号立即)操作:
For both 16bit SP + s8 (signed immediate) operations:
如果有从7至8位溢出进位标志设置。
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.
我发现它更容易为正负符号立即(LUA)单独做的行为:
I found it easier to do the behaviour separately for both a positive and negative signed immediate (Lua):
local D8 = self:Read(self.PC+1)
local S8 = ((D8&127)-(D8&128))
local SP = self.SP + S8
if S8 >= 0 then
self.Cf = ( (self.SP & 0xFF) + ( S8 ) ) > 0xFF
self.Hf = ( (self.SP & 0xF) + ( S8 & 0xF ) ) > 0xF
else
self.Cf = (SP & 0xFF) <= (self.SP & 0xFF)
self.Hf = (SP & 0xF) <= (self.SP & 0xF)
end
这篇关于GBZ80:如何LD HL,(SP + E)影响H和C标志位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!