Skip to content

Commit

Permalink
Merge pull request #49 from clandrew/clandrew/f256k_kernel_unblock
Browse files Browse the repository at this point in the history
Looks great!  Thanks for contributing!
  • Loading branch information
dtremblay authored Nov 7, 2023
2 parents 35eb2c3 + d183390 commit 1dfb25c
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 56 deletions.
11 changes: 8 additions & 3 deletions Main/Devices/BoardVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ public enum BoardVersion
RevU,
RevUPlus,
RevJr_6502,
RevJr_65816
RevJr_65816,
RevF256K_6502,
RevF256K_65816
}

public static class BoardVersionHelpers
{
public static bool IsJr(BoardVersion boardVersion)
public static bool IsF256(BoardVersion boardVersion)
{
return boardVersion == BoardVersion.RevJr_6502 || boardVersion == BoardVersion.RevJr_65816;
return boardVersion == BoardVersion.RevJr_6502 ||
boardVersion == BoardVersion.RevJr_65816 ||
boardVersion == BoardVersion.RevF256K_6502 ||
boardVersion == BoardVersion.RevF256K_65816;
}
}
}
15 changes: 14 additions & 1 deletion Main/Devices/PS2KeyboardRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ public class PS2KeyboardRegister: MemoryLocations.MemoryRAM
private byte ps2PacketCntr = 0;
private int packetLength = 0;
private byte[] ps2packet = new byte[6];
private Mode mode; // Mode 1 for C256, Mode 2 for F256
public delegate void TriggerInterruptDelegate();
public TriggerInterruptDelegate TriggerKeyboardInterrupt;
public TriggerInterruptDelegate TriggerMouseInterrupt;

public PS2KeyboardRegister(int StartAddress, int Length) : base(StartAddress, Length)
public enum Mode
{
Mode1,
Mode2
}

public PS2KeyboardRegister(int StartAddress, int Length, Mode m) : base(StartAddress, Length)
{
mode = m;
}

// This is used to simulate the Keyboard Register
Expand Down Expand Up @@ -144,6 +152,11 @@ public override byte ReadByte(int Address)
}
return data[0];
}
else if (Address == 4 && mode == Mode.Mode2)
{
// PS2 mode 2 keyboards are not currently supported, so always return 0b11, indicating that they keyboard and mouse queues are empty.
return 3;
}
else if (Address == 5)
{
return 0;
Expand Down
38 changes: 24 additions & 14 deletions Main/FoenixSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)
keyboardAddress = MemoryMap.KBD_DATA_BUF_U;
break;
case BoardVersion.RevJr_6502:
case BoardVersion.RevF256K_6502:
memSize = 1024*1024; // Includes both RAM and flash.
keyboardAddress = MemoryMap.KBD_DATA_BUF_JR;
clock = 6293000;
is6502 = true;
break;
case BoardVersion.RevJr_65816:
case BoardVersion.RevF256K_65816:
memSize = 1024 * 1024;
keyboardAddress = MemoryMap.KBD_DATA_BUF_JR;
clock = 6293000;
Expand All @@ -67,7 +69,7 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)
codec = new CodecRAM(MemoryMap.CODEC_WR_CTRL, 4);
sdcard = new CH376SRegister(MemoryMap.SDCARD_DATA, MemoryMap.SDCARD_SIZE);
}
else if (BoardVersionHelpers.IsJr(boardVersion))
else if (BoardVersionHelpers.IsF256(boardVersion))
{
codec = new CodecRAM(MemoryMap.CODEC_WR_CTRL_JR, 3); // unlike the FMX, this register is 16-bits in F256Jr
sdcard = new F256SDController(MemoryMap.SDCARD_JR, 2);
Expand All @@ -78,7 +80,7 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)
sdcard = new GabeSDController(MemoryMap.GABE_SDC_CTRL_START, MemoryMap.GABE_SDC_CTRL_SIZE);
}

if (!BoardVersionHelpers.IsJr(boardVersion))
if (!BoardVersionHelpers.IsF256(boardVersion))
{
// These are the strictly 65816-based machines
MemMgr = new MemoryManager
Expand All @@ -91,7 +93,7 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)

// Special devices
MATH = new MathCoproRegister(MemoryMap.MATH_START, MemoryMap.MATH_END - MemoryMap.MATH_START + 1), // 48 bytes
PS2KEYBOARD = new PS2KeyboardRegister(keyboardAddress, 5),
PS2KEYBOARD = new PS2KeyboardRegister(keyboardAddress, 5, PS2KeyboardRegister.Mode.Mode1),
SDCARD = sdcard,
INTERRUPT = new InterruptController(MemoryMap.INT_PENDING_REG0, 4),
UART1 = new UART(MemoryMap.UART1_REGISTERS, 8),
Expand All @@ -114,14 +116,14 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)
}
else
{
// This is either a 6502-based machine, or a 65816-based Jr with the same memory map
// This is a 6502 or 85816-based F256 machine; both have the same memory map
MemMgr = new MemoryManager
{
RAM = new MemoryRAM(MemoryMap.RAM_START, memSize),
FLASHJR = new FlashJr(MemoryMap.RAM_START, 0x08_0000),
// vicky will store 4 pages of data
VICKY = new MemoryRAM(0, 4 * 0x2000),
PS2KEYBOARD = new PS2KeyboardRegister(keyboardAddress, 5),
PS2KEYBOARD = new PS2KeyboardRegister(keyboardAddress, 5, PS2KeyboardRegister.Mode.Mode2),
MATRIXKEYBOARD = new MatrixKeyboardRegister(MemoryMap.MATRIX_KEYBOARD_VIA0_PORT_B, 4, MemoryMap.MATRIX_KEYBOARD_VIA1_PORT_B, 4),
MATH = new MathCoproRegister(MemoryMap.MATH_START_JR, MemoryMap.MATH_END_JR - MemoryMap.MATH_START_JR + 1), // 32 bytes
SDCARD = sdcard,
Expand All @@ -142,7 +144,7 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)
// Load the kernel.hex if present
ResetCPU(DefaultKernel);

if (!BoardVersionHelpers.IsJr(boardVersion))
if (!BoardVersionHelpers.IsF256(boardVersion))
{
// Write bytes $9F in the joystick registers to mean that they are not installed.
MemMgr.WriteWord(0xAFE800, 0x9F9F);
Expand Down Expand Up @@ -183,7 +185,15 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)
}
else
{
MemMgr.WriteByte(MemoryMap.REVOFJR, 0x2);
if (boardVersion == BoardVersion.RevJr_6502 || boardVersion == BoardVersion.RevJr_65816)
{
MemMgr.WriteByte(MemoryMap.REVOFJR, 0x2);
}
else
{
System.Diagnostics.Debug.Assert(boardVersion == BoardVersion.RevF256K_6502 || boardVersion == BoardVersion.RevF256K_65816);
MemMgr.WriteByte(MemoryMap.REVOFJR, 0x12);
}
MemMgr.VICKY.WriteWord(0xD000 - 0xC000, 1);
MemMgr.VICKY.WriteWord(0xD002 - 0xC000, 0x1540);
string applicationDirectory = System.AppContext.BaseDirectory;
Expand Down Expand Up @@ -211,7 +221,7 @@ public FoenixSystem(BoardVersion version, string DefaultKernel)

private void TimerEvent0()
{
if (!BoardVersionHelpers.IsJr(boardVersion))
if (!BoardVersionHelpers.IsF256(boardVersion))
{
byte mask = MemMgr.ReadByte(MemoryLocations.MemoryMap.INT_MASK_REG0);
if (!CPU.DebugPause && !CPU.Flags.IrqDisable && ((~mask & (byte)Register0.FNX0_INT02_TMR0) == (byte)Register0.FNX0_INT02_TMR0))
Expand All @@ -238,7 +248,7 @@ private void TimerEvent0()
}
private void TimerEvent1()
{
if (!BoardVersionHelpers.IsJr(boardVersion))
if (!BoardVersionHelpers.IsF256(boardVersion))
{
byte mask = MemMgr.ReadByte(MemoryLocations.MemoryMap.INT_MASK_REG0);
if (!CPU.DebugPause && !CPU.Flags.IrqDisable && ((~mask & (byte)Register0.FNX0_INT03_TMR1) == (byte)Register0.FNX0_INT03_TMR1))
Expand Down Expand Up @@ -280,7 +290,7 @@ private void TimerEvent2()

private void RTCAlarmEvents()
{
if (!BoardVersionHelpers.IsJr(boardVersion))
if (!BoardVersionHelpers.IsF256(boardVersion))
{
byte mask = MemMgr.ReadByte(MemoryLocations.MemoryMap.INT_MASK_REG0);
if (!CPU.DebugPause && !CPU.Flags.IrqDisable && ((~mask & (byte)Register0.FNX0_INT05_RTC) == (byte)Register0.FNX0_INT05_RTC))
Expand Down Expand Up @@ -357,15 +367,15 @@ public bool ResetCPU(string filename)
string extension = info.Extension.ToUpper();
if (info.Name.StartsWith("kernel"))
{
if (BoardVersionHelpers.IsJr(boardVersion))
if (BoardVersionHelpers.IsF256(boardVersion))
{
MemMgr.MMU.Reset();
}
}
else
{
// Ensure the first LUTs are set correctly - but don't overwrite the kernel.
if (BoardVersionHelpers.IsJr(boardVersion))
if (BoardVersionHelpers.IsF256(boardVersion))
{
MemMgr.MMU.SetActiveLUT(0);
MemMgr.MMU.WriteByte(0x8, 0);
Expand Down Expand Up @@ -447,7 +457,7 @@ public bool ResetCPU(string filename)
} while (reader.BaseStream.Position < info.Length);
reader.Close();

if (!BoardVersionHelpers.IsJr(boardVersion))
if (!BoardVersionHelpers.IsF256(boardVersion))
{
// This is pretty messed up... ERESET points to $FF00, which has simple load routine.
MemMgr.WriteWord(MemoryMap.VECTOR_ERESET, 0xFF00);
Expand Down Expand Up @@ -497,7 +507,7 @@ public bool ResetCPU(string filename)
// Copy the data into memory
MemMgr.RAM.CopyBuffer(DataBuffer, 0, DataStartAddress, flen);

if (BoardVersionHelpers.IsJr(boardVersion))
if (BoardVersionHelpers.IsF256(boardVersion))
{
bool binOverlapsFlash = DataStartAddress >= 0x08_0000;
if (binOverlapsFlash)
Expand Down
8 changes: 7 additions & 1 deletion Main/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ private static Dictionary<String,String> DecodeProgramArguments(string[] args)
case "jr816":
context.Add("version", "RevJr816");
break;
case "f256k":
context.Add("version", "RevF256K");
break;
case "f256k816":
context.Add("version", "RevF256K816");
break;
default:
Console.Out.WriteLine("Invalid board specified: " + verArg + ". Must be one of b, c, u, u+, jr, jr816");
Console.Out.WriteLine("Invalid board specified: " + verArg + ". Must be one of b, c, u, u+, jr, jr816, f256k, f256k816");
context["Continue"] = "false";
break;
}
Expand Down
10 changes: 5 additions & 5 deletions Main/UI/CPUWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ private void DebugPanel_Paint(object sender, PaintEventArgs e)

private void DisplayInterruptTooltips()
{
bool isJunior = BoardVersionHelpers.IsJr(boardVersion);
if (isJunior)
bool isF256 = BoardVersionHelpers.IsF256(boardVersion);
if (isF256)
{
// this is going to be confusing - the F256 Interrupts are different
// Register 0
Expand Down Expand Up @@ -462,7 +462,7 @@ public void RunButton_Click(object sender, EventArgs e)
IRQPC = -1;
kernel.MemMgr.INTERRUPT.WriteFromGabe(0, 0);
kernel.MemMgr.INTERRUPT.WriteFromGabe(1, 0);
if (!BoardVersionHelpers.IsJr(kernel.GetVersion()))
if (!BoardVersionHelpers.IsF256(kernel.GetVersion()))
{
kernel.MemMgr.INTERRUPT.WriteFromGabe(2, 0);
kernel.MemMgr.INTERRUPT.WriteFromGabe(3, 0);
Expand Down Expand Up @@ -896,7 +896,7 @@ private void CPUWindow_KeyDown(object sender, KeyEventArgs e)
private void BreakOnIRQCheckBox_CheckedChanged(object sender, EventArgs e)
{
bool visible = BreakOnIRQCheckBox.Checked;
if (BoardVersionHelpers.IsJr(boardVersion))
if (BoardVersionHelpers.IsF256(boardVersion))
{
// Row 1
SOFCheckbox.Visible = visible;
Expand Down Expand Up @@ -1002,7 +1002,7 @@ private bool InterruptMatchesCheckboxes()
}

// The F256s do not have the following registers
if (!BoardVersionHelpers.IsJr(kernel.GetVersion()))
if (!BoardVersionHelpers.IsF256(kernel.GetVersion()))
{
//Read Interrupt Register 2 - we don't handle these yet
byte reg2 = kernel.MemMgr.INTERRUPT.ReadByte(2);
Expand Down
22 changes: 20 additions & 2 deletions Main/UI/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1dfb25c

Please sign in to comment.