From 50420107a07991f4e1fcc1bba3bb1389fc9ebb09 Mon Sep 17 00:00:00 2001 From: BrandonWoodrum <73505232+BrandonWoodrum@users.noreply.github.com> Date: Wed, 2 Dec 2020 14:09:29 -0500 Subject: [PATCH 1/4] Update SIC_CPU.cs --- SIC Simulator/SIC_CPU.cs | 328 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 324 insertions(+), 4 deletions(-) diff --git a/SIC Simulator/SIC_CPU.cs b/SIC Simulator/SIC_CPU.cs index 9698cfd..084af88 100644 --- a/SIC Simulator/SIC_CPU.cs +++ b/SIC Simulator/SIC_CPU.cs @@ -157,8 +157,7 @@ public void StoreByte(int address, byte data) MachineStateIsNotSaved = true; } - - /// + /// Loader section Brandon Woodrum and Nick Konopko /// Load's an Object File Representation from a File /// into this SIC VM's Memory /// NO RELOCATION IS PERFORMACE (ABSOLUTE LOADING) @@ -166,22 +165,343 @@ public void StoreByte(int address, byte data) /// public void LoadObjectFile(String AbsoluteFilePath) { + //function that only loads from TRecords no mod + //int c = 0; + String l; + System.IO.StreamReader f = new System.IO.StreamReader(AbsoluteFilePath); + + while((l = f.ReadLine()) != null) + { + if(l[0] == 'H') + { + ReadHeaderRecord(l); + } + if (l[0] == 'T') + { + ReadTextRecord(l); + } + if (l[0] == 'E') + { + continue; + } + + } } + //class for MOD constructor that holds info for Modification + class Mod + { + //data fields + int address = 0; + int half = 0; + Mod next = null; + bool error = false; + + //if our head is which is a place holder is returned then nothing was found in search. this sets its boolean to true + public void seterr() + { + this.error = true; + } + //tells if its head or not + public bool geterr() + { + return this.error; + } + + //sets all values for created mod + public void set(int address, int half) + { + this.address = address; + this.half = half; + this.next = null; + } + //sets and gets for data fields + public void setNext(Mod t) + { + this.next = t; + } + public Mod getNext() + { + return this.next; + } - private void ReadHeaderRecord(System.IO.Stream s) + public int getaddress() + { + return this.address; + } + public int gethalf() + { + return this.half; + } + + //searches linked list for Mod record matching T-record starting address within ending address, if error mod is returned as place holder nothing was found + public Mod search(Mod head, int start, int length) + { + int end = start + length; + Mod error = new Mod(); + error.seterr(); + while(head.next != null) + { + if(!(start <= head.address && head.address <= end)) + { + head = head.next; + } + else + { + return head; + } + } + return error; + + } + } + //relocation function for MOD records + private int NotAbs(int x, String AbsoluteFilePath) { + Mod head = new Mod(); + + Mod last = head; + int newStart = 0; + int c = 0; + String l; + System.IO.StreamReader f = new System.IO.StreamReader(AbsoluteFilePath); + int y = 0; + int difference = 0; + //reads file to create MOD record objects + while ((l = f.ReadLine()) != null) + + { + if (l[0] == 'H') + { + difference = unr(l, x); + } + if (l[0] == 'M') + { + Mod current = new Mod(); + last.setNext(current); + last = current; + ReadModRecordR(l, current); + } + + } + String l2; + System.IO.StreamReader f2 = new System.IO.StreamReader(AbsoluteFilePath); + //reads file to generate memory, passing mod head to ReadTEXTR so that it can search for appropriate MOD + while ((l2 = f2.ReadLine()) != null) + { + if (l2[0] == 'H') + { + + newStart = ReadHeaderRecordR(l2, x, difference); + } + if (l2[0] == 'T') + { + ReadTextRecordR(l2, x, head, difference); + } + if (l2[0] == 'E') + { + continue; + } + } + newStart += difference; + return newStart; } + //parses mod record and returns correct offset minus or plus for trecord. + private void ReadModRecordR(String T, Mod current) + { //may not need Flag anymore + //alternate solution to plus or minus + /* bool flag = false; + if (x >= y) + { + flag = true; + + } + else if (x < y) + { + flag = false; + }*/ + + ///end block + + String address = T.Substring(2,6); + String h = T.Substring(8, 2); + int addressR = System.Int32.Parse(address); + int a = 0; + int l = System.Int32.Parse(h); + + //start block + //if true then new start position was larger than old so plus difference. + /* if(flag == true) + { + y = (x-y); + }*/ + + + //end block + /* String OPER = T.Substring(10, 1); + if (OPER.Equals("+")) + a += y; + else + { + a -= y; + }*/ + //1048576 for XE check + // if ((y > 8000 || y < 0)) + // { + //error for out of bounds new position.//exit here + // exit(0); + // return;//this is fake return its not real. + // } + // else + // {// sets mods data fields + current.set(addressR, l); + return; + // } - private void ReadTextRecord(System.IO.Stream s) + } + + //ABS + //reads header record for no mod + private void ReadHeaderRecord(String T) { + //gets starting address, but why? + string address = T.Substring(8, 6); + + } + //reads and loads text into memory for nomod + private void ReadTextRecord(String T) + { + //String T; + // T = s.ToString(); + string address = T.Substring(2, 6); + string Length = T.Substring(8, 2); + int a = System.Int32.Parse(address); + int l = System.Int32.Parse(Length); + LoadToMemory(T, a, l); + } + //NOT ABS + //reads and loads text into memory with mod as needed. + public static string ReplaceAt(this string str, int index, int length, string replace) + { + return str.Remove(index, Math.Min(length, str.Length - index)) + .Insert(index, replace); } + private void ReadTextRecordR(String T, int x, Mod head, int difference) + { + //String T; + // T = s.ToString(); + string address = T.Substring(2, 6); + string Length = T.Substring(8, 2); + int a = System.Int32.Parse(address); + int l = System.Int32.Parse(Length); + Mod test = new Mod(); + test = head.search(head, a, l); + //start math hereeeee!!!!!!!!!!!!!!!!!!!!!! + bool MODnofound = test.geterr(); + int u = 0; + //if MOD record found gets new address for Textrecord then loads into memory. + if (MODnofound != true) + { + int length = T.Length - 9; + string mo = T.Substring(10, length); + u = test.gethalf(); + int len = mo.Length - u; + string buff = mo.Substring(len, u); + int H = System.Int32.Parse(buff); + H += difference; + string some; + some = H.ToString(); + ReplaceAt(mo, len, u, some); + ReplaceAt(T, 10, length, some); + + } + a += difference; + LoadToMemory(T, a, l); + } + //read header record, but I think its obsolete. implememented function that does this ones job. to be deleted. + private int ReadHeaderRecordR(String T, int x, int difference) + { + //gets starting address, but why? + bool SICXECHECKPLACEHOLDER = false; + string address = T.Substring(8, 6); + int a = System.Int32.Parse(address); + string length = T.Substring(14, 6); + int b = System.Int32.Parse(length); + int bottom = a + b + difference; + + if(SICXECHECKPLACEHOLDER == false) + { + if(bottom < 8000 && bottom > 0) + { + return a; + } + else + { + return ErrorMessage; + } + } + else + { + if (bottom < 1048576 && bottom > 0) + { + return a; + } + else + { + return ErrorMessage; + } + } + + + + } + //does headerrecordreaders job from above, math is handled on return and send to Mod reader. + private int unr(String T, int x) + { + string address = T.Substring(8, 6); + int a = System.Int32.Parse(address); + // int NewPCCounter = 0; + /* bool flag = false; + if (x >= a) + { + flag = true; + + } + else if (x < a) + { + flag = false; + } + if (flag == true) + { + NewPCCounter += (a - x); + } + else + { + NewPCCounter -= (a - x); + }*/ + int difference = x - a; + //hopefully this updates PC counter so that Restart function works, hopefully.*************************************// + /* if(SIC == true) + if (NewPCCounter > 8000 || NewPCCounter < 0) + { + //error for out of bounds new pc counter. + return -1; + } + else + { + this.PC = NewPCCounter; + }*/ + //returns header record start address. + // comments comments look at this shit with scott + return difference; + } + public void InitializePC(int PCValue) { this.PC = PCValue; From 19bd81ce5637ff70820522b849ca236c0df06b3e Mon Sep 17 00:00:00 2001 From: BrandonWoodrum <73505232+BrandonWoodrum@users.noreply.github.com> Date: Thu, 3 Dec 2020 12:51:02 -0500 Subject: [PATCH 2/4] Update SIC_CPU.cs --- SIC Simulator/SIC_CPU.cs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/SIC Simulator/SIC_CPU.cs b/SIC Simulator/SIC_CPU.cs index 084af88..cf8a279 100644 --- a/SIC Simulator/SIC_CPU.cs +++ b/SIC Simulator/SIC_CPU.cs @@ -157,7 +157,7 @@ public void StoreByte(int address, byte data) MachineStateIsNotSaved = true; } - /// Loader section Brandon Woodrum and Nick Konopko + /// Loader section Brandon Woodrum and Nick Konopko /// Load's an Object File Representation from a File /// into this SIC VM's Memory /// NO RELOCATION IS PERFORMACE (ABSOLUTE LOADING) @@ -190,8 +190,7 @@ public void LoadObjectFile(String AbsoluteFilePath) } //class for MOD constructor that holds info for Modification - class Mod - { + public class Mod { //data fields int address = 0; int half = 0; @@ -258,7 +257,7 @@ public Mod search(Mod head, int start, int length) } } //relocation function for MOD records - private int NotAbs(int x, String AbsoluteFilePath) + public int NotAbs(int x, String AbsoluteFilePath) { Mod head = new Mod(); @@ -310,7 +309,7 @@ private int NotAbs(int x, String AbsoluteFilePath) return newStart; } //parses mod record and returns correct offset minus or plus for trecord. - private void ReadModRecordR(String T, Mod current) + public void ReadModRecordR(String T, Mod current) { //may not need Flag anymore //alternate solution to plus or minus /* bool flag = false; @@ -365,7 +364,7 @@ private void ReadModRecordR(String T, Mod current) //ABS //reads header record for no mod - private void ReadHeaderRecord(String T) + public void ReadHeaderRecord(String T) { //gets starting address, but why? @@ -373,7 +372,7 @@ private void ReadHeaderRecord(String T) } //reads and loads text into memory for nomod - private void ReadTextRecord(String T) + public void ReadTextRecord(String T) { //String T; // T = s.ToString(); @@ -391,7 +390,7 @@ public static string ReplaceAt(this string str, int index, int length, string re .Insert(index, replace); } - private void ReadTextRecordR(String T, int x, Mod head, int difference) + public void ReadTextRecordR(String T, int x, Mod head, int difference) { //String T; // T = s.ToString(); @@ -425,7 +424,7 @@ private void ReadTextRecordR(String T, int x, Mod head, int difference) } //read header record, but I think its obsolete. implememented function that does this ones job. to be deleted. - private int ReadHeaderRecordR(String T, int x, int difference) + public int ReadHeaderRecordR(String T, int x, int difference) { //gets starting address, but why? bool SICXECHECKPLACEHOLDER = false; @@ -442,8 +441,8 @@ private int ReadHeaderRecordR(String T, int x, int difference) return a; } else - { - return ErrorMessage; + {//error message here + return 0; } } else @@ -453,8 +452,8 @@ private int ReadHeaderRecordR(String T, int x, int difference) return a; } else - { - return ErrorMessage; + { //error message goes here + return 0; } } @@ -462,7 +461,7 @@ private int ReadHeaderRecordR(String T, int x, int difference) } //does headerrecordreaders job from above, math is handled on return and send to Mod reader. - private int unr(String T, int x) + public int unr(String T, int x) { string address = T.Substring(8, 6); int a = System.Int32.Parse(address); From 693e0e1a00c2c35993bf3e3ab4630068a5ba9055 Mon Sep 17 00:00:00 2001 From: BrandonWoodrum <73505232+BrandonWoodrum@users.noreply.github.com> Date: Thu, 3 Dec 2020 13:03:25 -0500 Subject: [PATCH 3/4] Update Form1.cs --- SIC Simulator/Form1.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SIC Simulator/Form1.cs b/SIC Simulator/Form1.cs index 568308c..8930962 100644 --- a/SIC Simulator/Form1.cs +++ b/SIC Simulator/Form1.cs @@ -656,7 +656,8 @@ private void loadObjectFileToolStripMenuItem_Click(object sender, EventArgs e) // Call the loader!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - + int PCHolder = this.SICVirtualMachine.NotAbs(NewAddress, ObjectFileName); + this.SICVirtualMachine.PC = PCHolder; // Return address (absolute) of first instruction after relocation // This will be placed in the PC From c3c4f8dba598638f271b2ab1477cc2fbb378bd23 Mon Sep 17 00:00:00 2001 From: BrandonWoodrum <73505232+BrandonWoodrum@users.noreply.github.com> Date: Fri, 4 Dec 2020 11:59:25 -0500 Subject: [PATCH 4/4] Relocating Loader bug fixes --- SIC Simulator/Form1.cs | 2 + SIC Simulator/SIC_CPU.cs | 79 ++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/SIC Simulator/Form1.cs b/SIC Simulator/Form1.cs index 8930962..fa2e411 100644 --- a/SIC Simulator/Form1.cs +++ b/SIC Simulator/Form1.cs @@ -658,6 +658,8 @@ private void loadObjectFileToolStripMenuItem_Click(object sender, EventArgs e) int PCHolder = this.SICVirtualMachine.NotAbs(NewAddress, ObjectFileName); this.SICVirtualMachine.PC = PCHolder; + this.RefreshCPUDisplays(); + // Return address (absolute) of first instruction after relocation // This will be placed in the PC diff --git a/SIC Simulator/SIC_CPU.cs b/SIC Simulator/SIC_CPU.cs index cf8a279..095f76f 100644 --- a/SIC Simulator/SIC_CPU.cs +++ b/SIC Simulator/SIC_CPU.cs @@ -190,6 +190,7 @@ public void LoadObjectFile(String AbsoluteFilePath) } //class for MOD constructor that holds info for Modification + [Serializable()] public class Mod { //data fields int address = 0; @@ -256,6 +257,7 @@ public Mod search(Mod head, int start, int length) } } + //relocation function for MOD records public int NotAbs(int x, String AbsoluteFilePath) { @@ -293,7 +295,7 @@ public int NotAbs(int x, String AbsoluteFilePath) if (l2[0] == 'H') { - newStart = ReadHeaderRecordR(l2, x, difference); + ReadHeaderRecordR(l2, x, difference); } if (l2[0] == 'T') { @@ -301,13 +303,21 @@ public int NotAbs(int x, String AbsoluteFilePath) } if (l2[0] == 'E') { + newStart = ReadERecordR(l2, difference); continue; } } - newStart += difference; + return newStart; } + + public int ReadERecordR(String T, int current) { + string Length = T.Substring(1, 6); + int a = int.Parse(Length, System.Globalization.NumberStyles.HexNumber); + a += current; + return a; + } //parses mod record and returns correct offset minus or plus for trecord. public void ReadModRecordR(String T, Mod current) { //may not need Flag anymore @@ -325,11 +335,11 @@ public void ReadModRecordR(String T, Mod current) ///end block - String address = T.Substring(2,6); - String h = T.Substring(8, 2); - int addressR = System.Int32.Parse(address); + String address = T.Substring(1,6); + String h = T.Substring(7, 2); + int addressR = System.Int32.Parse(address, System.Globalization.NumberStyles.HexNumber); int a = 0; - int l = System.Int32.Parse(h); + int l = System.Int32.Parse(h, System.Globalization.NumberStyles.HexNumber); //start block //if true then new start position was larger than old so plus difference. @@ -378,13 +388,13 @@ public void ReadTextRecord(String T) // T = s.ToString(); string address = T.Substring(2, 6); string Length = T.Substring(8, 2); - int a = System.Int32.Parse(address); - int l = System.Int32.Parse(Length); + int a = System.Int32.Parse(address, System.Globalization.NumberStyles.HexNumber); + int l = System.Int32.Parse(Length, System.Globalization.NumberStyles.HexNumber); LoadToMemory(T, a, l); } //NOT ABS //reads and loads text into memory with mod as needed. - public static string ReplaceAt(this string str, int index, int length, string replace) + public string ReplaceAt(string str, int index, int length, string replace) { return str.Remove(index, Math.Min(length, str.Length - index)) .Insert(index, replace); @@ -394,10 +404,10 @@ public void ReadTextRecordR(String T, int x, Mod head, int difference) { //String T; // T = s.ToString(); - string address = T.Substring(2, 6); - string Length = T.Substring(8, 2); - int a = System.Int32.Parse(address); - int l = System.Int32.Parse(Length); + string address = T.Substring(1, 6); + string Length = T.Substring(7, 2); + int a = System.Int32.Parse(address, System.Globalization.NumberStyles.HexNumber); + int l = System.Int32.Parse(Length, System.Globalization.NumberStyles.HexNumber); Mod test = new Mod(); test = head.search(head, a, l); //start math hereeeee!!!!!!!!!!!!!!!!!!!!!! @@ -407,53 +417,60 @@ public void ReadTextRecordR(String T, int x, Mod head, int difference) if (MODnofound != true) { int length = T.Length - 9; - string mo = T.Substring(10, length); + string mo = T.Substring(9, length); u = test.gethalf(); int len = mo.Length - u; - string buff = mo.Substring(len, u); - int H = System.Int32.Parse(buff); + string buff = mo.Substring(len-1, u); + int H = System.Int32.Parse(buff, System.Globalization.NumberStyles.HexNumber); H += difference; string some; some = H.ToString(); - ReplaceAt(mo, len, u, some); - ReplaceAt(T, 10, length, some); + some = ReplaceAt(mo, len-1, u, some); + T = ReplaceAt(T, 9, length, some); } a += difference; + + Console.WriteLine(T); + Console.WriteLine(a); + Console.WriteLine(l); + LoadToMemory(T, a, l); } //read header record, but I think its obsolete. implememented function that does this ones job. to be deleted. - public int ReadHeaderRecordR(String T, int x, int difference) - { + public void ReadHeaderRecordR(String T, int x, int difference) + {//testing this + Console.WriteLine(T); //gets starting address, but why? bool SICXECHECKPLACEHOLDER = false; - string address = T.Substring(8, 6); - int a = System.Int32.Parse(address); - string length = T.Substring(14, 6); - int b = System.Int32.Parse(length); + string address = T.Substring(8, 5); + int a = System.Int32.Parse(address, System.Globalization.NumberStyles.HexNumber); + string length = T.Substring(13, 6); + Console.WriteLine(length); + int b = System.Int32.Parse(length, System.Globalization.NumberStyles.HexNumber); int bottom = a + b + difference; if(SICXECHECKPLACEHOLDER == false) { if(bottom < 8000 && bottom > 0) { - return a; + return; } else {//error message here - return 0; + return; } } else { if (bottom < 1048576 && bottom > 0) { - return a; + return; } else { //error message goes here - return 0; + return; } } @@ -463,8 +480,8 @@ public int ReadHeaderRecordR(String T, int x, int difference) //does headerrecordreaders job from above, math is handled on return and send to Mod reader. public int unr(String T, int x) { - string address = T.Substring(8, 6); - int a = System.Int32.Parse(address); + string address = T.Substring(7, 6); + int a = System.Int32.Parse(address, System.Globalization.NumberStyles.HexNumber); // int NewPCCounter = 0; /* bool flag = false; if (x >= a) @@ -484,7 +501,7 @@ public int unr(String T, int x) { NewPCCounter -= (a - x); }*/ - int difference = x - a; + int difference = x-a; //hopefully this updates PC counter so that Restart function works, hopefully.*************************************// /* if(SIC == true) if (NewPCCounter > 8000 || NewPCCounter < 0)