O2Hawk: Bug Fixes, controller support

This commit is contained in:
alyosha-tas 2019-12-14 11:46:45 -05:00
parent 51df281d38
commit ef046d60c8
9 changed files with 55 additions and 51 deletions

View File

@ -77,6 +77,8 @@ namespace BizHawk.Emulation.Common.Components.I8048
public const ushort DM = 64;
public const ushort SET_ADDR_M3 = 65;
public ushort test;
public I8048()
{
Reset();
@ -92,10 +94,9 @@ namespace BizHawk.Emulation.Common.Components.I8048
IDLE,
IDLE,
IDLE,
IDLE,
IDLE);
IRQS = 6;
IRQS = 5;
instr_pntr = irq_pntr = 0;
}

View File

@ -21,11 +21,12 @@ namespace BizHawk.Emulation.Common.Components.I8048
IDLE,
IDLE,
IDLE,
IDLE,
PUSH,
IDLE,
SET_ADDR, PC, ALU, 0);
IRQS = 9;
IRQS = 10;
}
public bool IRQPending;

View File

@ -96,7 +96,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
IDLE,
oper, A, port);
IRQS = 4;
IRQS = 9;
}
public void MOV_R(ushort dest, ushort src)
@ -119,6 +119,7 @@ namespace BizHawk.Emulation.Common.Components.I8048
IDLE,
IDLE,
IDLE,
//IDLE);
RD_P, A, 0);
IRQS = 9;

View File

@ -78,11 +78,26 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
return 0;
}
}
if (ppu_en && !copy_en)
if (ppu_en)
{
return ppu.ReadReg(addr_latch);
}
// if neither RAM or PPU is enabled, then a RD pulse from instruction IN A,BUS will latch controller
// onto the bus, but only if they are enabled correctly using port 2
if (kybrd_en)
{
if ((kb_byte & 7) == 1)
{
return controller_state_1;
}
if ((kb_byte & 7) == 0)
{
return controller_state_2;
}
}
Console.WriteLine(cpu.TotalExecutedCycles);
// not sure what happens if this case is reached, probably whatever the last value on the bus is
return 0;
}
@ -128,11 +143,12 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
// voice module goes here
}
}
if (ppu_en)
{
ppu.WriteReg(addr_latch, value);
//Console.WriteLine((addr_latch) + " " + value);
}
}
}
}
else if (port == 1)
@ -146,11 +162,12 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
cart_b1 = value.Bit(1);
cart_b0 = value.Bit(0);
//Console.WriteLine("main ctrl: " + value + " " + ppu_en + " " + RAM_en);
//Console.WriteLine("main ctrl: " + value + " " + ppu_en + " " + RAM_en + " " + cpu.TotalExecutedCycles);
}
else
{
// keyboard
kb_byte = value;
}
}
}

View File

@ -11,7 +11,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
public byte controller_state;
public byte controller_state_1, controller_state_2;
public bool in_vblank_old;
public bool in_vblank;
public bool vblank_rise;
@ -53,9 +53,6 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
// update the controller state on VBlank
GetControllerState(controller);
// check if controller state caused interrupt
do_controller_check();
// send the image on VBlank
SendVideoBuffer();
@ -89,36 +86,11 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
cpu.ExecuteOne();
}
public void do_controller_check()
{
// check if new input changed the input register and triggered IRQ
byte contr_prev = input_register;
input_register &= 0xF0;
if ((input_register & 0x30) == 0x20)
{
input_register |= (byte)(controller_state & 0xF);
}
else if ((input_register & 0x30) == 0x10)
{
input_register |= (byte)((controller_state & 0xF0) >> 4);
}
else if ((input_register & 0x30) == 0x00)
{
// if both polls are set, then a bit is zero if either or both pins are zero
byte temp = (byte)((controller_state & 0xF) & ((controller_state & 0xF0) >> 4));
input_register |= temp;
}
else
{
input_register |= 0xF;
}
}
public void GetControllerState(IController controller)
{
InputCallbacks.Call();
controller_state = _controllerDeck.ReadPort1(controller);
controller_state_1 = _controllerDeck.ReadPort1(controller);
controller_state_2 = _controllerDeck.ReadPort2(controller);
}
public int Frame => _frame;

View File

@ -59,11 +59,11 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
ser.Sync("IsLag", ref _islag);
_controllerDeck.SyncState(ser);
ser.Sync(nameof(controller_state), ref controller_state);
ser.Sync(nameof(controller_state_1), ref controller_state_1);
ser.Sync(nameof(controller_state_2), ref controller_state_2);
ser.Sync(nameof(in_vblank), ref in_vblank);
ser.Sync(nameof(in_vblank_old), ref in_vblank_old);
ser.Sync(nameof(vblank_rise), ref vblank_rise);
ser.Sync(nameof(input_register), ref input_register);
ser.Sync(nameof(RAM_en), ref RAM_en);
ser.Sync(nameof(ppu_en), ref ppu_en);
@ -79,6 +79,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
ser.Sync(nameof(_bios), ref _bios, false);
ser.Sync(nameof(RAM_Bank), ref RAM_Bank);
ser.Sync(nameof(addr_latch), ref addr_latch);
ser.Sync(nameof(kb_byte), ref kb_byte);
ser.Sync(nameof(frame_buffer), ref frame_buffer, false);
ser.Sync(nameof(_vidbuffer), ref _vidbuffer, false);

View File

@ -16,8 +16,6 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
[ServiceNotApplicable(typeof(IDriveLight))]
public partial class O2Hawk : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable, IRegionable, ISettable<O2Hawk.O2Settings, O2Hawk.O2SyncSettings>
{
public byte input_register;
// memory domains
public byte[] RAM = new byte[0x80];
@ -25,6 +23,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
public int RAM_Bank;
public byte addr_latch;
public byte kb_byte;
public bool ppu_en, RAM_en, kybrd_en, copy_en, lum_en, cart_b0, cart_b1;
public const bool P15 = true;

View File

@ -47,23 +47,23 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
if (c.IsPressed(Definition.BoolButtons[0]))
{
result -= 4;
result -= 1;
}
if (c.IsPressed(Definition.BoolButtons[1]))
{
result -= 8;
result -= 4;
}
if (c.IsPressed(Definition.BoolButtons[2]))
{
result -= 2;
result -= 8;
}
if (c.IsPressed(Definition.BoolButtons[3]))
{
result -= 1;
result -= 2;
}
if (c.IsPressed(Definition.BoolButtons[4]))
{
result -= 128;
result -= 16;
}
return result;

View File

@ -190,13 +190,13 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
{
// character is in drawing region, pick a pixel
int offset_y = LY - Sprites[i * 4];
int offset_x = 7 - ((cycle - 43) - Sprites[i * 4 + 1]);
int offset_x = ((cycle - 43) - Sprites[i * 4 + 1]);
int pixel_pick = (Sprite_Shapes[i * 8 + offset_y] >> offset_x) & 1;
if (pixel_pick == 1)
{
Core._vidbuffer[LY * 186 + (cycle - 43)] = (int) Color_Palette[(Sprites[i * 4 + 2] >> 3) & 0x7];
Core._vidbuffer[LY * 186 + (cycle - 43)] = (int) Color_Palette_SPR[(Sprites[i * 4 + 2] >> 3) & 0x7];
Pixel_Stat |= (byte)(i << 1);
}
}
@ -219,7 +219,7 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
if (pixel_pick == 1)
{
Core._vidbuffer[LY * 186 + (cycle - 43)] = (int)Color_Palette[(Foreground[i * 4 + 3] >> 1) & 0x7];
Core._vidbuffer[LY * 186 + (cycle - 43)] = (int)Color_Palette_SPR[(Foreground[i * 4 + 3] >> 1) & 0x7];
Pixel_Stat |= 0x80;
}
}
@ -365,7 +365,19 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
0x00, 0x00, 0x00, 0x54, 0x54, 0xFF, 0x7E, 00 // (boat 3 unk) 0x3F
};
public static readonly uint[] Color_Palette =
public static readonly uint[] Color_Palette_SPR =
{
0xFF676767, // grey
0xFF790000, // red
0xFF006D07, //green
0xFFC75151, // light red
0xFF1A37BE, // blue
0xFF94309F, // violet
0xFFCECECE, // light grey
0xFFFFFFFF, // white
};
public static readonly uint[] Color_Palette_BG =
{
0xFF006D07, //green
0xFF56C469, // light green