def _fac(a, number, label, stz, sta): bytes = vm.py2fac(number) for i, byte in enumerate(bytes): if byte == 0: a(stz, add(label, i)) else: a(lda_imm, x8(byte)) a(sta, add(label, i))
def __call__(self): cmd = self.mem[memmap.FPU_COMMAND] if cmd == 0: return op1 = vm.fac2py(self.mem[_f0_start:_f0_end]) op2 = vm.fac2py(self.mem[_f1_start:_f1_end]) result = 0 status = aliases.FPU_OK if cmd in FPU_BINARY_MAP: try: result = FPU_BINARY_MAP[cmd](op1, op2) except ZeroDivisionError: status = aliases.ERR_FPU_DIVISION_BY_ZERO elif cmd in FPU_COMPARE_MAP: cmpresult = FPU_COMPARE_MAP[cmd](op1, op2) result = 1 if cmpresult else 0 else: status = aliases.ERR_FPU_INVALID_COMMAND self.mem[_f0_start:_f0_end] = vm.py2fac(result) self.mem[memmap.FPU_COMMAND] = 0 self.mem[memmap.FPU_STATUS] = status
def test_py2fac_sign_both(self): self.assertListEqual([0xff, 0x70, 0x56, 0x34, 0x12, 0x42], vm.py2fac(-1.234567e-42))
def test_py2fac_sign_mantissa_with_exponent(self): self.assertListEqual([0xf0, 0x70, 0x56, 0x34, 0x12, 0x42], vm.py2fac(-1.234567e42))
def test_py2fac_sign_mantissa(self): self.assertListEqual([0xf0, 0x70, 0x56, 0x34, 0x12, 0x06], vm.py2fac(-1234567))
def test_py2fac_exponent2(self): self.assertListEqual([0x00, 0x00, 0x00, 0x30, 0x12, 0x02], vm.py2fac(123))
def test_py2fac_exponent6(self): self.assertListEqual([0x00, 0x70, 0x56, 0x34, 0x12, 0x06], vm.py2fac(1234567))
def test_py2fac(self): self.assertListEqual([0x00, 0x70, 0x56, 0x34, 0x12, 0x00], vm.py2fac(1.234567))