instructions.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:pytari2600 作者: ajgrah2000 项目源码 文件源码
def subc(self, a, b, c):

        if 0 == self.pc_state.P.get_D():
            r  = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value - ctypes.c_byte(c).value).value
            rs = ctypes.c_byte((a - b - c) & 0xFF).value
            self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)]) # Negative
            self.pc_state.P.set_Z((0,1)[rs == 0])   # Zero
            self.pc_state.P.set_V((0,1)[r != rs])   # Overflow

            r = a - b - c 
            self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow
            result = a - b - c
        elif 1 == self.pc_state.P.get_D():
            # Decimal subtraction
            # FIXME need to fix flags

            r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) - (((b>>4) & 0xF)* 10 + ((b & 0xF) %10)) - c).value

            # rc = a + b + c
            self.pc_state.P.set_N((0,1)[r < 0])
            self.pc_state.P.set_Z((0,1)[r == 0x0])
            #  Need to check/fix conditions for V
            # self.pc_state.P.V = (rc != r) ? 1:0;   # Overflow
            self.pc_state.P.set_V(1)   # Overflow

            self.pc_state.P.set_C((0,1)[(r >= 0) and (r <= 99)])
            result = (((int(r/10) % 10) << 4) & 0xf0) + (r%10)

        return result & 0xFF
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号