PIC_Simulator_Simon/PIC_Simulator/Register.cs

358 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace PIC_Simulator
{
class Register
{
// Speicherarray anlegen:
List<int[]> arrMemList = new List<int[]>();
// BANK 0 definieren
byte BANK0_INDF = 0x0; //0000 0000
byte BANK0_TMR0 = 0x0; //0000 0000
byte BANK0_PCL = 0x0; //0000 0000
byte BANK0_STATUS = 0x18; //0001 1000
byte BANK0_FSR = 0x0; //0000 0000
byte BANK0_PORTA = 0x0; //0000 0000
byte BANK0_PORTB = 0x0; //0000 0000
byte BANK0_EEDATA = 0x0; //0000 0000
byte BANK0_EEADR = 0x0; //0000 0000
// BANK 1 definieren
byte BANK1_INDF = 0x0; //0000 0000
byte BANK1_OPTION_REG = 0xFF; //1111 1111
byte BANK1_PCL = 0x0; //0000 0000
byte BANK1_STATUS = 0x18; //0001 1000
byte BANK1_FSR = 0x0; //0000 0000
byte BANK1_TRISA = 0x1F; //0001 1111
byte BANK1_TRISB = 0xFF; //1111 1111
byte BANK1_EECON1 = 0x0; //0000 0000
byte BANK1_EECON2 = 0x0; //0000 0000
// Gemeinsam genutzte Register
byte BANK_PCLATH = 0x0; //0000 0000
byte BANK_INTCON = 0x0; //0000 0000
//############## PIC COMMANDS BINARY #############################
// --- Bit-Oriented File Register Operations ---
public string BCF = "0100"; // 4 Stellen zum Vergleichen
public string BSF = "0101";
public string BTFSC = "0110";
public string BTFSS = "0111";
//--- Byte-Oriented File Register Operations ---
public string ADDWF = "000111"; //6 Stellen zum Vergleichen
public string ANDWF = "000101"; //6
public string COMF = "001001"; //6
public string DECF = "000011"; //6
public string DECFSZ = "001011"; //6
public string INCF = "001010"; //6
public string INCFSZ = "001111"; //6
public string IORWF = "000100"; //6
public string MOVF = "001000"; //6
public string RLF = "001101"; //6
public string RRF = "001100"; //6
public string SUBWF = "000010"; //6
public string SWAPF = "001110"; //6
public string XORWF = "000110"; //6
public string CLRF = "0000011"; //7 Stellen zum Vergleichen
public string CLRW = "0000010"; //7
public string MOVWF = "0000001"; //7
public string NOP1 = "00000000000000"; //14 Stellen zum Vergleichen
public string NOP2 = "00000000100000"; //14
public string NOP3 = "00000001000000"; //14
public string NOP4 = "00000001100000"; //14
// --- Literal and Control Operations ---
public string CALL = "100"; //3 Stellen zum Vergleichen
public string GOTO = "101"; //3
public string MOVLW = "1100"; //4 Stellen zum Vergleichen
public string RETLW = "1101"; //4
public string SUBLW = "11110"; //5 Stellen zum Vergleichen
public string ADDLW = "11111"; //5
public string ANDLW = "111001"; //6 Stellen zum Vergleichen
public string IORLW = "111000"; //6
public string XORLW = "111010"; //6
public string CLRWDT = "00000001100100"; //14
public string RETFIE = "00000000001001"; //14
public string RETURN = "00000000001000"; //14
public string SLEEP = "00000001100011"; //14
//############## PIC COMMANDS BINARY #############################
// Findet den auszuführenden Befehl
public void findOrder(string Order)
{
string OrderBinary;
string Reduced;
// Hex to Int Umrechnung Funktionsaufruf
OrderBinary = hex2binary(Order);
// 14 Zeichen
Reduced = OrderBinary;
if (Reduced.Equals(NOP1))
{
MessageBox.Show("Erfolgreich NOP1" + Reduced);
}
else if (Reduced.Equals(NOP2))
{
MessageBox.Show("Erfolgreich NOP2" + Reduced);
}
else if (Reduced.Equals(NOP3))
{
MessageBox.Show("Erfolgreich NOP3" + Reduced);
}
else if (Reduced.Equals(NOP4))
{
MessageBox.Show("Erfolgreich NOP4" + Reduced);
}
else if (Reduced.Equals(CLRWDT))
{
MessageBox.Show("Erfolgreich CLRWDT" + Reduced);
}
else if (Reduced.Equals(RETFIE))
{
MessageBox.Show("Erfolgreich RETFIE" + Reduced);
}
else if (Reduced.Equals(RETURN))
{
MessageBox.Show("Erfolgreich RETURN" + Reduced);
}
else if (Reduced.Equals(SLEEP))
{
MessageBox.Show("Erfolgreich SLEEP" + Reduced);
}
else
{ // Reduzieren und Vergleich mit 7 Zeichen
Reduced = OrderBinary.Substring(0, 7);
}
//7 Zeichen
if (Reduced.Equals(CLRF))
{
MessageBox.Show("Erfolgreich CLRF" + Reduced);
}
else if (Reduced.Equals(CLRW))
{
MessageBox.Show("Erfolgreich CLRW" + Reduced);
}
else if (Reduced.Equals(MOVWF))
{
MessageBox.Show("Erfolgreich MOVWF" + Reduced);
}
else {
// Reduzieren und Vergleich mit 6 Zeichen
Reduced = OrderBinary.Substring(0, 6);
}
// 6 Zeichen
if (Reduced.Equals(ANDWF))
{
MessageBox.Show("Erfolgreich ANDWF " + Reduced);
}
else if (Reduced.Equals(COMF))
{
MessageBox.Show("Erfolgreich COMF " + Reduced);
}
else if (Reduced.Equals(DECF))
{
MessageBox.Show("Erfolgreich DECF " + Reduced);
}
else if (Reduced.Equals(DECFSZ))
{
MessageBox.Show("Erfolgreich DECFSZ " + Reduced);
}
else if (Reduced.Equals(INCF))
{
MessageBox.Show("Erfolgreich INCF " + Reduced);
}
else if (Reduced.Equals(INCFSZ))
{
MessageBox.Show("Erfolgreich INCFSZ " + Reduced);
}
else if (Reduced.Equals(IORWF))
{
MessageBox.Show("Erfolgreich IORWF " + Reduced);
}
else if (Reduced.Equals(MOVF))
{
MessageBox.Show("Erfolgreich MOVF " + Reduced);
}
else if (Reduced.Equals(RLF))
{
MessageBox.Show("Erfolgreich RLF " + Reduced);
}
else if (Reduced.Equals(RRF))
{
MessageBox.Show("Erfolgreich RRF " + Reduced);
}
else if (Reduced.Equals(SUBWF))
{
MessageBox.Show("Erfolgreich SUBWF " + Reduced);
}
else if (Reduced.Equals(SWAPF))
{
MessageBox.Show("Erfolgreich SWAPF " + Reduced);
}
else if (Reduced.Equals(XORWF))
{
MessageBox.Show("Erfolgreich XORWF " + Reduced);
}
else if (Reduced.Equals(ANDLW))
{
MessageBox.Show("Erfolgreich ANDLW " + Reduced);
}
else if (Reduced.Equals(IORLW))
{
MessageBox.Show("Erfolgreich IORLW " + Reduced);
}
else if (Reduced.Equals(XORLW))
{
MessageBox.Show("Erfolgreich XORLW " + Reduced);
}
else
{ // Reduzieren und Vergleich mit 5 Zeichen
Reduced = OrderBinary.Substring(0, 5);
}
// 5 Zeichen
if (Reduced.Equals(SUBLW))
{
MessageBox.Show("Erfolgreich SUBLW " + Reduced);
}
else if (Reduced.Equals(ADDLW))
{
MessageBox.Show("Erfolgreich ADDLW " + Reduced);
}
else
{ // Reduzieren und Vergleich mit 4 Zeichen
Reduced = OrderBinary.Substring(0, 4);
}
//4 Zeichen
if (Reduced.Equals(BCF))
{
MessageBox.Show("Erfolgreich BCF " + Reduced);
}
else if (Reduced.Equals(BSF))
{
MessageBox.Show("Erfolgreich BSF " + Reduced);
}
else if (Reduced.Equals(BTFSC))
{
MessageBox.Show("Erfolgreich DBTFSC " + Reduced);
}
else if (Reduced.Equals(BTFSS))
{
MessageBox.Show("Erfolgreich BTFSS " + Reduced);
}
else if (Reduced.Equals(MOVLW))
{
MessageBox.Show("Erfolgreich MOVLW " + Reduced);
}
else if (Reduced.Equals(RETLW))
{
MessageBox.Show("Erfolgreich RETLW " + Reduced);
}
else
{// Reduzieren und Vergleich mit 3 Zeichen
Reduced = OrderBinary.Substring(0, 3);
}
if (Reduced.Equals(CALL))
{
MessageBox.Show("Erfolgreich CALL " + Reduced);
}
else if (Reduced.Equals(GOTO))
{
MessageBox.Show("Erfolgreich GOTO " + Reduced);
}
else { }
}
private string hex2binary(string hexvalue)
{
string binaryval = "";
binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2).PadLeft(14,'0');
return binaryval;
}
private void fillpicmemory()
{
int[] line1 = new int[8];
int[] line2 = new int[8];
int[] line3 = new int[8];
int[] line4 = new int[8];
int[] line5 = new int[8];
int[] line6 = new int[8];
int[] line7 = new int[8];
int[] line8 = new int[8];
int[] line9 = new int[8];
int[] line10 = new int[8];
int[] line11 = new int[8];
int[] line12 = new int[8];
int[] line13 = new int[8];
int[] line14 = new int[8];
int[] line15 = new int[8];
int[] line16 = new int[8];
int[] line17 = new int[8];
int[] line18 = new int[8];
int[] line19 = new int[8];
int[] line20 = new int[8];
int[] line21 = new int[8];
int[] line22 = new int[8];
int[] line23 = new int[8];
int[] line24 = new int[8];
int[] line25 = new int[8];
int[] line26 = new int[8];
int[] line27 = new int[8];
int[] line28 = new int[8];
int[] line29 = new int[8];
int[] line30 = new int[8];
int[] line31 = new int[8];
}
}
}