From 2141bd682b5d91ebb10a88140592f4006d3632aa Mon Sep 17 00:00:00 2001 From: Colin Halseth Date: Mon, 22 Jan 2024 22:07:01 -0800 Subject: [PATCH] Godot player basic save/load and colourizing --- .../Debuggers/CartInfoDebug.cs | 28 +++++ .../Debuggers/CartInfoDebug.tscn | 49 +++++++++ .../Debuggers/Disassembler.Row.tscn | 71 +++++++++++++ .../Debuggers/Disassembler.cs | 54 ++++++++-- .../Debuggers/Disassembler.tscn | 76 ++++++++++++- .../Debuggers/DisassemblerRow.cs | 65 ++++++++++++ .../Debuggers/PaletteDebugger.cs | 80 +------------- .../Debuggers/PaletteDebugger.tscn | 3 +- Gameboy.Player.Godot/Gameboy.tscn | 53 +++++++--- Gameboy.Player.Godot/LcdColorTheme.cs | 100 ++++++++++++++++++ Gameboy.Player.Godot/TextureRenderer.cs | 32 +++++- Gameboy.Player.Godot/console.png | Bin 0 -> 29267 bytes Gameboy.Player.Godot/console.png.import | 34 ++++++ Gameboy.Player.Godot/project.godot | 1 + Gameboy/GameBoy.cs | 30 ++++++ Gameboy/hardware/game/Cartidge.cs | 2 - Gameboy/hardware/game/CartridgeAdapter.cs | 2 +- Gameboy/hardware/game/CartridgeHeader.cs | 19 ++++ Qkmaxware.Vm.LR35902/Disassembler.cs | 3 +- 19 files changed, 591 insertions(+), 111 deletions(-) create mode 100644 Gameboy.Player.Godot/Debuggers/CartInfoDebug.cs create mode 100644 Gameboy.Player.Godot/Debuggers/CartInfoDebug.tscn create mode 100644 Gameboy.Player.Godot/Debuggers/Disassembler.Row.tscn create mode 100644 Gameboy.Player.Godot/Debuggers/DisassemblerRow.cs create mode 100644 Gameboy.Player.Godot/LcdColorTheme.cs create mode 100644 Gameboy.Player.Godot/console.png create mode 100644 Gameboy.Player.Godot/console.png.import diff --git a/Gameboy.Player.Godot/Debuggers/CartInfoDebug.cs b/Gameboy.Player.Godot/Debuggers/CartInfoDebug.cs new file mode 100644 index 0000000..e30f9f3 --- /dev/null +++ b/Gameboy.Player.Godot/Debuggers/CartInfoDebug.cs @@ -0,0 +1,28 @@ +using Godot; +using System; +using System.Linq; +using System.Collections.Generic; +using Qkmaxware.Emulators.Gameboy.Hardware; + +namespace Qkmaxware.Emulators.Gameboy.Player; +public partial class CartInfoDebug : Control { + + [Export] public TextureRenderer Player; + + private RichTextLabel text; + + // Called when the node enters the scene tree for the first time. + public override void _Ready() { + text = this.GetNode("ScrollContainer/MarginContainer/RichTextLabel"); + } + + public void Refresh() { + var str = string.Empty; + + if (Player?.Console?.GetCartridge() is Cartridge cart) { + str = cart.Info.ToString(); + } + + this.text.Text = str; + } +} diff --git a/Gameboy.Player.Godot/Debuggers/CartInfoDebug.tscn b/Gameboy.Player.Godot/Debuggers/CartInfoDebug.tscn new file mode 100644 index 0000000..fb3d42c --- /dev/null +++ b/Gameboy.Player.Godot/Debuggers/CartInfoDebug.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=3 format=3 uid="uid://t7khq15qfjuw"] + +[ext_resource type="Texture2D" uid="uid://divrqb47wvwvt" path="res://reload.png" id="1_0a8i2"] +[ext_resource type="Script" path="res://Debuggers/CartInfoDebug.cs" id="1_m4mxx"] + +[node name="Cartridge Info" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_m4mxx") + +[node name="ScrollContainer" type="ScrollContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = 44.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="RichTextLabel" type="RichTextLabel" parent="ScrollContainer/MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +fit_content = true + +[node name="Reload" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -95.0 +offset_bottom = 31.0 +grow_horizontal = 0 +text = "Reload" +icon = ExtResource("1_0a8i2") +expand_icon = true + +[connection signal="pressed" from="Reload" to="." method="Refresh"] diff --git a/Gameboy.Player.Godot/Debuggers/Disassembler.Row.tscn b/Gameboy.Player.Godot/Debuggers/Disassembler.Row.tscn new file mode 100644 index 0000000..77e7e3c --- /dev/null +++ b/Gameboy.Player.Godot/Debuggers/Disassembler.Row.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=2 format=3 uid="uid://c2fsn6ee6p522"] + +[ext_resource type="Script" path="res://Debuggers/DisassemblerRow.cs" id="1_1mo4q"] + +[node name="Row" type="HBoxContainer"] +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 31.0 +grow_horizontal = 2 +size_flags_horizontal = 3 +script = ExtResource("1_1mo4q") + +[node name="Address" type="HBoxContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Decimal" type="Button" parent="Address"] +layout_mode = 2 +text = "x10" + +[node name="Hex" type="Button" parent="Address"] +layout_mode = 2 +text = "x16" + +[node name="Label" type="Label" parent="Address"] +layout_mode = 2 +text = "0x900" + +[node name="Instruction" type="HBoxContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Decimal" type="Button" parent="Instruction"] +layout_mode = 2 +text = "x10" + +[node name="Hex" type="Button" parent="Instruction"] +layout_mode = 2 +text = "x16" + +[node name="Name" type="Button" parent="Instruction"] +layout_mode = 2 +text = "Inst" + +[node name="Label" type="Label" parent="Instruction"] +layout_mode = 2 +text = "Jump" + +[node name="Args" type="HBoxContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Decimal" type="Button" parent="Args"] +layout_mode = 2 +text = "x10" + +[node name="Hex" type="Button" parent="Args"] +layout_mode = 2 +text = "x16" + +[node name="Label" type="Label" parent="Args"] +layout_mode = 2 +text = "120" + +[connection signal="pressed" from="Address/Decimal" to="." method="AddressModeDecimal"] +[connection signal="pressed" from="Address/Hex" to="." method="AddressModeHex"] +[connection signal="pressed" from="Instruction/Decimal" to="." method="InstructionModeDecimal"] +[connection signal="pressed" from="Instruction/Hex" to="." method="InstructionModeHex"] +[connection signal="pressed" from="Instruction/Name" to="." method="InstructionModeName"] +[connection signal="pressed" from="Args/Decimal" to="." method="ArgModeDecimal"] +[connection signal="pressed" from="Args/Hex" to="." method="ArgModeHex"] diff --git a/Gameboy.Player.Godot/Debuggers/Disassembler.cs b/Gameboy.Player.Godot/Debuggers/Disassembler.cs index df2f2c1..a4d68ed 100644 --- a/Gameboy.Player.Godot/Debuggers/Disassembler.cs +++ b/Gameboy.Player.Godot/Debuggers/Disassembler.cs @@ -10,27 +10,59 @@ public partial class Disassembler : Control { [Export] public TextureRenderer Player; - private RichTextLabel text; + [Export] public PackedScene RowPrefab; + + private Control container; + private Label pageLabel; + + public int Page {get; private set;} + public int PageSize = 1000; private Qkmaxware.Vm.LR35902.Disassembler disassembler = new Qkmaxware.Vm.LR35902.Disassembler(Endianness.LittleEndian); // Called when the node enters the scene tree for the first time. public override void _Ready() { - text = this.GetNode("ScrollContainer/RichTextLabel"); + container = this.GetNode("ScrollContainer/MarginContainer/VBoxContainer"); + pageLabel = this.GetNode