Skip to content

Commit

Permalink
WIP on debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
emoon committed Mar 30, 2024
1 parent c95323b commit 4380b77
Show file tree
Hide file tree
Showing 24 changed files with 360 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ if (WIN32)
endif()

if (APPLE)
target_compile_options(quaesar PRIVATE -DFILEFLAG_DIR=1 -DFILEFLAG_DIR=1 -D_ftelli64=ftell -D_fseeki64=fseek -D_fseeko64=fseeko -Dfseeko64=fseeko -Dftello64=ftell)
target_compile_options(quaesar PRIVATE -Wno-macro-redefined -Wno-deprecated-declarations -DFILEFLAG_DIR=1 -DFILEFLAG_DIR=1 -D_ftelli64=ftell -D_fseeki64=fseek -D_fseeko64=fseeko -Dfseeko64=fseeko -Dftello64=ftell)
endif()

if (LINUX OR UNIX)
Expand Down
93 changes: 93 additions & 0 deletions data/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
79 changes: 79 additions & 0 deletions data/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Source Code Pro Variable Font
=============================

This download contains Source Code Pro as both variable fonts and static fonts.

Source Code Pro is a variable font with this axis:
wght

This means all the styles are contained in these files:
SourceCodePro-VariableFont_wght.ttf
SourceCodePro-Italic-VariableFont_wght.ttf

If your app fully supports variable fonts, you can now pick intermediate styles
that aren’t available as static fonts. Not all apps support variable fonts, and
in those cases you can use the static font files for Source Code Pro:
static/SourceCodePro-ExtraLight.ttf
static/SourceCodePro-Light.ttf
static/SourceCodePro-Regular.ttf
static/SourceCodePro-Medium.ttf
static/SourceCodePro-SemiBold.ttf
static/SourceCodePro-Bold.ttf
static/SourceCodePro-ExtraBold.ttf
static/SourceCodePro-Black.ttf
static/SourceCodePro-ExtraLightItalic.ttf
static/SourceCodePro-LightItalic.ttf
static/SourceCodePro-Italic.ttf
static/SourceCodePro-MediumItalic.ttf
static/SourceCodePro-SemiBoldItalic.ttf
static/SourceCodePro-BoldItalic.ttf
static/SourceCodePro-ExtraBoldItalic.ttf
static/SourceCodePro-BlackItalic.ttf

Get started
-----------

1. Install the font files you want to use

2. Use your app's font picker to view the font family and all the
available styles

Learn more about variable fonts
-------------------------------

https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts
https://variablefonts.typenetwork.com
https://medium.com/variable-fonts

In desktop apps

https://theblog.adobe.com/can-variable-fonts-illustrator-cc
https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts

Online

https://developers.google.com/fonts/docs/getting_started
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts

Installing fonts

MacOS: https://support.apple.com/en-us/HT201749
Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux
Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows

Android Apps

https://developers.google.com/fonts/docs/android
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts

License
-------
Please read the full license text (OFL.txt) to understand the permissions,
restrictions and requirements for usage, redistribution, and modification.

You can use them in your products & projects – print or digital,
commercial or otherwise.

This isn't legal advice, please consider consulting a lawyer and see the full
license for all details.
Binary file added data/static/SourceCodePro-Black.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-BlackItalic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-Bold.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-BoldItalic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-ExtraBold.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-ExtraBoldItalic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-ExtraLight.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-ExtraLightItalic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-Italic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-Light.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-LightItalic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-Medium.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-MediumItalic.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-Regular.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-SemiBold.ttf
Binary file not shown.
Binary file added data/static/SourceCodePro-SemiBoldItalic.ttf
Binary file not shown.
70 changes: 70 additions & 0 deletions src/debugger/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
#include "options.h"
#include "memory.h"
#include "newcpu.h"
#include "debug.h"
// clang-format on

#include "disassembly_view.h"
#include "debugger_api.h"

extern int debugger_active;

extern DebuggerAPI s_debugger_api;

static Debugger* s_debugger = nullptr;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -20,6 +28,8 @@ Debugger* Debugger_create() {
SDL_Window* window =
SDL_CreateWindow("Quaesar: Debugger", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);

DebuggerAPI_register(&s_debugger_api, nullptr);

// From 2.0.18: Enable native IME.
#ifdef SDL_HINT_IME_SHOW_UI
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
Expand All @@ -45,6 +55,8 @@ Debugger* Debugger_create() {
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

io.Fonts->AddFontFromFileTTF("../data/static/SourceCodePro-Regular.ttf", 24.0f);

// Setup Dear ImGui style
ImGui::StyleColorsDark();
// ImGui::StyleColorsLight();
Expand Down Expand Up @@ -160,6 +172,8 @@ Debugger* Debugger_create() {
debugger->memory_view = new MemoryView();
debugger->d_view = DisassemblyView_create(debugger->capstone);

s_debugger = debugger;

return debugger;
}

Expand Down Expand Up @@ -283,8 +297,10 @@ void Debugger_toggle(Debugger* debugger, DebuggerMode mode) {
uint32_t window_flags = SDL_GetWindowFlags(debugger->window);

if (window_flags & SDL_WINDOW_HIDDEN) {
activate_debugger_new();
SDL_ShowWindow(debugger->window);
} else {
deactivate_debugger();
SDL_HideWindow(debugger->window);
}
}
Expand All @@ -302,3 +318,57 @@ void Debugger_destroy(Debugger* debugger) {

delete debugger;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static void* create(void* user_data) { return nullptr; }
static void check_exception(void* self) { }
static void cop_debug(void* self, uint32_t addr, uint32_t nextaddr, uint16_t word1, uint16_t word2, int hpos, int vpos) { }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static void update(void* self) {
set_special (SPCFLAG_BRK);

SDL_Event e;

while (1) {
while (SDL_PollEvent(&e) != 0) {
// User requests quit
switch (e.type) {
case SDL_QUIT: // User closes the window
// TODO: Fix me
exit(0);
break;
default:
break;

case SDL_KEYDOWN:
if (e.key.keysym.sym == SDLK_ESCAPE) {
exit(0);
}
break;
}

Debugger_update_event(&e);
}

Debugger_update(s_debugger);
}
}

static void live_update(void* self) { }
static void destroy(void* self) { }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DebuggerAPI s_debugger_api = {
nullptr,
create,
check_exception,
cop_debug,
update,
live_update,
destroy,
};

67 changes: 67 additions & 0 deletions src/debugger_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "debugger_api.h"
#include <vector>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct Debugger {
void* user_data;
DebuggerAPI* api;
};

static std::vector<Debugger> s_debuggers;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool DebuggerAPI_has_debugger() {
return !s_debuggers.empty();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DebuggerAPI_register(DebuggerAPI* api, void* user_data) {
void* self = api->create(user_data);

Debugger debugger = { user_data, api };

s_debuggers.push_back(debugger);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DebuggerAPI_check_exception() {
for (Debugger& debugger : s_debuggers) {
debugger.api->check_exception(debugger.user_data);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DebuggerAPI_debug_copper(uint32_t addr, uint32_t nextaddr, uint16_t word1, uint16_t word2, int hpos, int vpos) {
for (Debugger& debugger : s_debuggers) {
debugger.api->debug_copper(debugger.user_data, addr, nextaddr, word1, word2, hpos, vpos);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DebuggerAPI_update() {
for (Debugger& debugger : s_debuggers) {
debugger.api->update(debugger.user_data);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DebuggerAPI_live_update() {
for (Debugger& debugger : s_debuggers) {
debugger.api->live_update(debugger.user_data);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void DebuggerAPI_destroy() {
for (Debugger& debugger : s_debuggers) {
debugger.api->destroy(debugger.user_data);
}
}
26 changes: 26 additions & 0 deletions src/debugger_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <stdint.h>

#define DEBUGGER_API_ENABLE 1

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct DebuggerAPI {
void* priv_data;
void* (*create)(void* user_data);
void (*check_exception)(void* self);
void (*debug_copper)(void* self, uint32_t addr, uint32_t nextaddr, uint16_t word1, uint16_t word2, int hpos, int vpos);
void (*update)(void* self);
void (*live_update)(void* self);
void (*destroy)(void* self);
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool DebuggerAPI_has_debugger();
void DebuggerAPI_register(DebuggerAPI* api, void* user_data);
void DebuggerAPI_check_exception();
void DebuggerAPI_debug_copper(uint32_t addr, uint32_t nextaddr, uint16_t word1, uint16_t word2, int hpos, int vpos);
void DebuggerAPI_update();
void DebuggerAPI_live_update();
Loading

0 comments on commit 4380b77

Please sign in to comment.