Skip to content

Commit

Permalink
Release 0.5.6.8
Browse files Browse the repository at this point in the history
---------------
Added tool to generate PGZ files.
Updated the Uploader Dialog to allow for sending PGX and PGZ files.
Updated IDE start-up to accept PGX and PGZ files - from "Load Executable menu" and drag-n-drop.
  • Loading branch information
Daniel Tremblay committed Jun 3, 2022
1 parent f3cd22a commit 346a5fe
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 177 deletions.
2 changes: 1 addition & 1 deletion Main/Display/Gpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ private unsafe void DrawTiles(int* p, bool gammaCorrection, byte TextColumns, in
{
return;
}
bool smallTiles = (reg & 8) > 0;
bool smallTiles = (reg & 0x10) > 0;

int tileSize = (smallTiles ? 8 : 16);
int strideLine = tileSize * 16;
Expand Down
56 changes: 31 additions & 25 deletions Main/FileFormat/HexFile.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
using FoenixIDE.MemoryLocations;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace FoenixIDE.Simulator.FileFormat
{
public class HexFile
{

static public String Load(MemoryRAM ram, string Filename, int gabeAddressBank, out int startAddress, out int length)
static public bool Load(MemoryRAM ram, string Filename, int gabeAddressBank, out List<int> blocks, out List<int> blockLengths)
{
int bank = 0;
int address = 0;
int addrCursor = 0;

String processedFileName = Filename;
startAddress = -1;
length = -1;
blocks = new List<int>();
blockLengths = new List<int>();
int startAddress = -1;

if (!System.IO.File.Exists(Filename))
{
OpenFileDialog f = new OpenFileDialog
{
Title = "Select a kernel file",
Filter = "Hex Files|*.hex|All Files|*.*"
};
if (f.ShowDialog() == DialogResult.OK)
{
processedFileName = f.FileName;
}
else
{
return null;
}
return false;
}


Expand All @@ -50,40 +41,55 @@ static public String Load(MemoryRAM ram, string Filename, int gabeAddressBank, o
{
// data row. The next n bytes are data to be loaded into memory
case "00":
address = GetByte(offset, 0, 2);
if (startAddress == -1 && ((address & 0xFF00) != 0xFF00))
addrCursor = GetByte(offset, 0, 2);
if (startAddress == -1)
{
startAddress = bank + address;
startAddress = bank + addrCursor;
}
if (bank <= ram.Length)
{
for (int i = 0; i < data.Length; i += 2)
{
int b = GetByte(data, i, 1);
ram.WriteByte(bank + address, (byte)b);
ram.WriteByte(bank + addrCursor, (byte)b);
// Copy bank $38 or $18 to page 0
if (bank == gabeAddressBank)
{
ram.WriteByte(address, (byte)b);
ram.WriteByte(addrCursor, (byte)b);
}
address++;
addrCursor++;
}
}

break;

// end of file - just ignore
case "01":
length = address;
if (startAddress != -1)
{
blocks.Add(startAddress);
blockLengths.Add(bank + addrCursor - startAddress);
}
break;

case "02":
bank = GetByte(data, 0, 2) * 16;
if (startAddress != -1)
{
blocks.Add(startAddress);
blockLengths.Add(addrCursor);
}
break;

// extended linear address
// lower byte will populate the bank number.
case "04":
if (startAddress != -1)
{
blocks.Add(startAddress);
blockLengths.Add(bank + addrCursor - startAddress);
startAddress = -1;
}
bank = GetByte(data, 0, 2) << 16;
break;

Expand All @@ -102,7 +108,7 @@ static public String Load(MemoryRAM ram, string Filename, int gabeAddressBank, o
break;
}
}
return processedFileName;
return true;
}

// Read a two-character hex string into a byte
Expand Down
4 changes: 4 additions & 0 deletions Main/FileFormat/ResourceChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public bool Add(Resource resource)
{
return false;
}
else
{
// TODO - do we need to delete overlapping resources? Or maybe only if start and lenght match exactly?
}
}
}
resources.Add(resource);
Expand Down
137 changes: 107 additions & 30 deletions Main/FoenixSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using FoenixIDE.Simulator.Devices;
using FoenixIDE.Simulator.FileFormat;
using FoenixIDE.UI;
using System.IO;
using System.Windows.Forms;

namespace FoenixIDE
{
Expand Down Expand Up @@ -184,17 +186,17 @@ public void SetVersion(BoardVersion rev)
boardVersion = rev;
}
// return true if the CPU was reset and the program was loaded
public bool ResetCPU(string kernelFilename)
public bool ResetCPU(string filename)
{
if (CPU != null)
{
CPU.DebugPause = true;
//CPU.Halt();
}

if (kernelFilename != null)
if (filename != null)
{
LoadedKernel = kernelFilename;
LoadedKernel = filename;
}

// If the reset vector is not set in Bank 0, but it is set in Bank 18, the copy bank 18 into bank 0.
Expand All @@ -203,51 +205,126 @@ public bool ResetCPU(string kernelFilename)
{
BasePageAddress = 0x38_0000;
}
FileInfo info = new FileInfo(LoadedKernel);
if (!info.Exists)
{
OpenFileDialog f = new OpenFileDialog
{
Title = "Select a kernel file",
Filter = "Hex Files|*.hex|PGX Files|*.pgx|PGZ Files|*.pgz"
};
if (f.ShowDialog() == DialogResult.OK)
{
LoadedKernel = f.FileName;
info = new FileInfo(LoadedKernel);
}
}
string extension = info.Extension.ToUpper();
if (extension.Equals(".HEX"))
{
if (!HexFile.Load(MemMgr.RAM, LoadedKernel, BasePageAddress, out _, out _))
{
return false;
}
}
else if (extension.Equals(".PGX"))
{
FileInfo f = new FileInfo(LoadedKernel);
int flen = (int)(f.Length - 8);
BinaryReader reader = new BinaryReader(f.OpenRead());
// The first four byte contain PGX,0x1
byte[] header = reader.ReadBytes(4);
// The next four bytes contain the start address
int FnxAddressPtr = reader.ReadInt32();
// The rest of the file is data
byte[] DataBuffer = reader.ReadBytes(flen);
reader.Close();

if (LoadedKernel.EndsWith(".fnxml", true, null))
// This is pretty messed up... ERESET points to $FF00, which has simple load routine.
MemMgr.WriteWord(MemoryMap.VECTOR_ERESET, 0xFF00);
MemMgr.WriteLong(0xFF00, 0x78FB18); // CLC, XCE, SEI
MemMgr.WriteByte(0xFF03, 0x5C); // JML
MemMgr.WriteLong(0xFF04, FnxAddressPtr);
}
else if (extension.Equals(".PGZ"))
{
FileInfo f = new FileInfo(LoadedKernel);
BinaryReader reader = new BinaryReader(f.OpenRead());
byte header = reader.ReadByte(); // this should be Z for 24-bits and z for 32-bits
int size = header == 'z' ? 4 : 3;
int FnxAddressPtr = -1;

do
{
byte[] bufAddr = reader.ReadBytes(size);
byte[] bufLength = reader.ReadBytes(size);
int address = bufAddr[0] + bufAddr[1] * 0x100 + bufAddr[2] * 0x10000 + (size == 4 ? bufAddr[3] * 0x1000000 : 0);
int blockLength = bufLength[0] + bufLength[1] * 0x100 + bufLength[2] * 0x10000 + (size == 4 ? bufLength[3] * 0x1000000 : 0);
if (blockLength == 0)
{
FnxAddressPtr = address;
}
else
{
byte[] DataBuffer = reader.ReadBytes(blockLength);
MemMgr.CopyBuffer(DataBuffer, 0, address, blockLength);

// TODO - make this backward compatible
if (address >= (BasePageAddress + 0xFF00) && (address < (BasePageAddress + 0xFFFF)))
{
int pageFFLen = blockLength - ((address + blockLength) - (BasePageAddress + 0x1_0000));
if (pageFFLen > blockLength)
{
pageFFLen = blockLength;
}
MemMgr.CopyBuffer(DataBuffer, 0, address - BasePageAddress, pageFFLen);
}
}

} while (reader.BaseStream.Position < f.Length);
reader.Close();

// This is pretty messed up... ERESET points to $FF00, which has simple load routine.
MemMgr.WriteWord(MemoryMap.VECTOR_ERESET, 0xFF00);
MemMgr.WriteLong(0xFF00, 0x78FB18); // CLC, XCE, SEI
MemMgr.WriteByte(0xFF03, 0x5C); // JML
MemMgr.WriteLong(0xFF04, FnxAddressPtr);
}
else if (extension.Equals(".FNXML"))
{
this.ResetMemory();
FoeniXmlFile fnxml = new FoeniXmlFile(this, ResCheckerRef);
fnxml.Load(LoadedKernel);
boardVersion = fnxml.Version;
}

// Load the .LST file if it exists
if (lstFile == null)
{
lstFile = new ListFile(LoadedKernel);
}
else
{
LoadedKernel = HexFile.Load(MemMgr.RAM, LoadedKernel, BasePageAddress, out _, out _);
if (LoadedKernel != null)
// TODO: This results in lines of code to be shown in incorrect order - Fix
ListFile tempList = new ListFile(LoadedKernel);
foreach (DebugLine line in tempList.Lines.Values)
{
if (lstFile == null)
if (lstFile.Lines.ContainsKey(line.PC))
{
lstFile = new ListFile(LoadedKernel);
lstFile.Lines.Remove(line.PC);
}
else
{
// TODO: This results in lines of code to be shown in incorrect order - Fix
ListFile tempList = new ListFile(LoadedKernel);
foreach (DebugLine line in tempList.Lines.Values)
lstFile.Lines.Add(line.PC, line);
for (int i = 1; i < line.commandLength; i++)
{
if (lstFile.Lines.ContainsKey(line.PC + i))
{
if (lstFile.Lines.ContainsKey(line.PC))
{
lstFile.Lines.Remove(line.PC);
}
lstFile.Lines.Add(line.PC, line);
for (int i = 1; i < line.commandLength; i++)
{
if (lstFile.Lines.ContainsKey(line.PC + i))
{
lstFile.Lines.Remove(line.PC + i);
}
}
lstFile.Lines.Remove(line.PC + i);
}
}
}
else
{
return false;
}
}

// See if lines of code exist in the 0x18_0000 to 0x18_FFFF block for RevB or 0x38_0000 to 0x38_FFFF block for Rev C
// See if lines of code exist in the 0x18_0000 to 0x18_FFFF block for RevB/RevU or 0x38_0000 to 0x38_FFFF block for RevC/RevU+
List<DebugLine> copiedLines = new List<DebugLine>();
if (lstFile.Lines.Count > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions Main/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.6.7")]
[assembly: AssemblyFileVersion("0.5.6.7")]
[assembly: AssemblyVersion("0.5.6.8")]
[assembly: AssemblyFileVersion("0.5.6.8")]
Loading

0 comments on commit 346a5fe

Please sign in to comment.