From f263a04f0fc5e3ae5edfe87854025c650bc10035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 11 May 2017 11:41:36 +0200 Subject: [PATCH] direct set PCL --- PIC_Simulator/PIC/PICProgramm.cs | 120 ++++++++++++++++--------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/PIC_Simulator/PIC/PICProgramm.cs b/PIC_Simulator/PIC/PICProgramm.cs index 3aca4ee..894548c 100644 --- a/PIC_Simulator/PIC/PICProgramm.cs +++ b/PIC_Simulator/PIC/PICProgramm.cs @@ -760,62 +760,26 @@ namespace PIC_Simulator.PIC return PCCounter >= befehle.Count; } - private uint GetRegister(uint index) - { - // register die nur einmal auf bank1 + 2 existieren - if (index == ADDR_PCL + 0x80) return Register[ADDR_PCL]; - if (index == ADDR_STATUS + 0x80) return Register[ADDR_STATUS]; - if (index == ADDR_FSR + 0x80) return Register[ADDR_FSR]; - if (index == ADDR_PCLATH + 0x80) return Register[ADDR_PCLATH]; - if (index == ADDR_INTCON + 0x80) return Register[ADDR_INTCON]; - - if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0) - { - return Register[0x80 + index]; - } - else - { - return Register[index]; - } - } - - private void SetRegister(uint index, uint wert) - { - // register die nur einmal auf bank1 + 2 existieren - if (index == ADDR_PCL) { Register[ADDR_PCL] = wert; return; } - if (index == ADDR_STATUS) { Register[ADDR_STATUS] = wert; return; } - if (index == ADDR_FSR) { Register[ADDR_FSR] = wert; return; } - if (index == ADDR_PCLATH) { Register[ADDR_PCLATH] = wert; return; } - if (index == ADDR_INTCON) { Register[ADDR_INTCON] = wert; return; } - - if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0) - { - Register[0x80 + index] = wert; - } - else - { - Register[index] = wert; - } - } - - private void SetRegister(uint index, uint bit, bool wert) - { - SetRegister(index, SetBit(GetRegister(index), bit, wert)); - } - - public void SetRegisterOhneBank(uint index, uint bit, bool wert) - { - Register[index] = SetBit(Register[index], bit, wert); - } - public void SetRegisterOhneBank(uint index, uint wert) { - Register[index] = wert; - } + // register die nur einmal auf bank1 + 2 existieren + if (index == ADDR_PCL + 0x80) index -= 0x80; + if (index == ADDR_STATUS + 0x80) index -= 0x80; + if (index == ADDR_FSR + 0x80) index -= 0x80; + if (index == ADDR_PCLATH + 0x80) index -= 0x80; + if (index == ADDR_INTCON + 0x80) index -= 0x80; - public bool GetRegisterOhneBank(uint index, uint bit) - { - return GetBit(Register[index], bit); + if (index == ADDR_PCL) // PC direkt setzen + { + wert &= 0xFF; // Only Low 8 Bit + uint high = GetRegister(ADDR_PCLATH); + high &= 0x1F; // Only Bit <0,1,2,3,4> + high <<= 8; + + PCCounter = (int) (high | wert) - 1; + } + + Register[index] = wert; } public uint GetRegisterOhneBank(uint index) @@ -824,15 +788,55 @@ namespace PIC_Simulator.PIC if (index == ADDR_UNIMPL_B) return 0; // register die nur einmal auf bank1 + 2 existieren - if (index == ADDR_PCL + 0x80) return Register[ADDR_PCL]; - if (index == ADDR_STATUS + 0x80) return Register[ADDR_STATUS]; - if (index == ADDR_FSR + 0x80) return Register[ADDR_FSR]; - if (index == ADDR_PCLATH + 0x80) return Register[ADDR_PCLATH]; - if (index == ADDR_INTCON + 0x80) return Register[ADDR_INTCON]; + if (index == ADDR_PCL + 0x80) index -= 0x80; + if (index == ADDR_STATUS + 0x80) index -= 0x80; + if (index == ADDR_FSR + 0x80) index -= 0x80; + if (index == ADDR_PCLATH + 0x80) index -= 0x80; + if (index == ADDR_INTCON + 0x80) index -= 0x80; return Register[index]; } + private uint GetRegister(uint index) + { + if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0) + { + return GetRegisterOhneBank(0x80 + index); + } + else + { + return GetRegisterOhneBank(index); + } + } + + private void SetRegister(uint index, uint wert) + { + if ((Register[ADDR_STATUS] & STATUS_BIT_RP0) == STATUS_BIT_RP0) + { + SetRegisterOhneBank(0x80 + index, wert); + } + else + { + SetRegisterOhneBank(index, wert); + } + } + + public void SetRegisterOhneBank(uint index, uint bit, bool wert) + { + SetRegisterOhneBank(index, SetBit(GetRegisterOhneBank(index), bit, wert)); + } + + + private void SetRegister(uint index, uint bit, bool wert) + { + SetRegister(index, SetBit(GetRegister(index), bit, wert)); + } + + public bool GetRegisterOhneBank(uint index, uint bit) + { + return GetBit(GetRegisterOhneBank(index), bit); + } + public static bool AdditionDigitCarry(uint a, uint b) { a &= 0x0F;