From ef046d60c89495a243f8207c773acdde11078de5 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Sat, 14 Dec 2019 11:46:45 -0500 Subject: [PATCH] O2Hawk: Bug Fixes, controller support --- .../CPUs/Intel8048/I8048.cs | 5 +-- .../CPUs/Intel8048/Interrupts.cs | 3 +- .../CPUs/Intel8048/OP_Tables.cs | 3 +- .../Consoles/Magnavox/Odyssey2/MemoryMap.cs | 23 +++++++++++-- .../Magnavox/Odyssey2/O2Hawk.IEmulator.cs | 34 ++----------------- .../Magnavox/Odyssey2/O2Hawk.IStatable.cs | 5 +-- .../Consoles/Magnavox/Odyssey2/O2Hawk.cs | 3 +- .../Magnavox/Odyssey2/O2HawkControllers.cs | 10 +++--- .../Consoles/Magnavox/Odyssey2/PPU.cs | 20 ++++++++--- 9 files changed, 55 insertions(+), 51 deletions(-) diff --git a/BizHawk.Emulation.Cores/CPUs/Intel8048/I8048.cs b/BizHawk.Emulation.Cores/CPUs/Intel8048/I8048.cs index 2603d0012b..f78def506f 100644 --- a/BizHawk.Emulation.Cores/CPUs/Intel8048/I8048.cs +++ b/BizHawk.Emulation.Cores/CPUs/Intel8048/I8048.cs @@ -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; } diff --git a/BizHawk.Emulation.Cores/CPUs/Intel8048/Interrupts.cs b/BizHawk.Emulation.Cores/CPUs/Intel8048/Interrupts.cs index fef15a7326..43538aa616 100644 --- a/BizHawk.Emulation.Cores/CPUs/Intel8048/Interrupts.cs +++ b/BizHawk.Emulation.Cores/CPUs/Intel8048/Interrupts.cs @@ -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; diff --git a/BizHawk.Emulation.Cores/CPUs/Intel8048/OP_Tables.cs b/BizHawk.Emulation.Cores/CPUs/Intel8048/OP_Tables.cs index aab23b4c56..c621e18f68 100644 --- a/BizHawk.Emulation.Cores/CPUs/Intel8048/OP_Tables.cs +++ b/BizHawk.Emulation.Cores/CPUs/Intel8048/OP_Tables.cs @@ -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; diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/MemoryMap.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/MemoryMap.cs index 161f17cf7b..a6e47b66d7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/MemoryMap.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/MemoryMap.cs @@ -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; } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IEmulator.cs index 9a22912827..16cfe79487 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IEmulator.cs @@ -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; diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs index cf87f77347..3a36ac178e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.IStatable.cs @@ -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); diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.cs index e89da32798..86493a0907 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2Hawk.cs @@ -16,8 +16,6 @@ namespace BizHawk.Emulation.Cores.Consoles.O2Hawk [ServiceNotApplicable(typeof(IDriveLight))] public partial class O2Hawk : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable, IRegionable, ISettable { - 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; diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllers.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllers.cs index 28fc2c1584..0535df5038 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/O2HawkControllers.cs @@ -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; diff --git a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/PPU.cs b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/PPU.cs index 300b1a7585..68ee4f2588 100644 --- a/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Magnavox/Odyssey2/PPU.cs @@ -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