~swisschili/toolchain-6502

4bccd44af8e0c86de4d53fc0f192b48e76d6c5e8 — swissChili 3 months ago d3764d4
Fixed a memory leak where the screen would not be freed when used with the debugger
8 files changed, 123 insertions(+), 13 deletions(-)

M common.c
M common.h
M docs/content/styles.scss
M docs/templates/home.html
M docs/templates/page.html
M gui.c
M main.c
M screen.c
M common.c => common.c +6 -3
@@ 7,15 7,18 @@
catch_t g_catch[MAX_CATCH_LEN];
unsigned g_catch_len;

void throw_(const char *msg, const char *file, unsigned int line)
void unwind()
{
	fprintf(stderr, "\033[31mException thrown:\033[33m %s:%d\033[0m %s\n", file, line, msg);

	for (int i = g_catch_len - 1; i >= 0; i--)
	{
		g_catch[i].fn(g_catch[i].arg);
	}
}

void throw_(const char *msg, const char *file, unsigned int line)
{
	fprintf(stderr, "\033[31mException thrown:\033[33m %s:%d\033[0m %s\n", file, line, msg);
	unwind();
	exit(1);
}


M common.h => common.h +1 -0
@@ 28,6 28,7 @@ extern catch_t g_catch[MAX_CATCH_LEN];
extern unsigned g_catch_len;

void throw_(const char *msg, const char *file, unsigned int line);
void unwind();
void catch_(handle_t hdl, intptr_t arg);

#define THROW(msg) throw_(msg, __FILENAME__, __LINE__)

M docs/content/styles.scss => docs/content/styles.scss +108 -4
@@ 1,7 1,29 @@
html,
body
$code: #f2f4f4;

$bg: #1d1F21;
$fg: #abb2bf;

$black:   #1e2127;
$red:     #e06c75;
$green:   #a0ea98;
$yellow:  #d1ed8b;
$blue:    #81A1C1;
$magenta: #cb80ce;
$cyan:    #87dfe5;
$white:   #abb2bf;

@import url('https://rsms.me/inter/inter.css');
html
{
	font-family: /*'Segoe UI', 'Roboto', 'San Francisco', 'IBM Plex Sans',*/ sans-serif;
	font-family: 'Inter', sans-serif;
}

@supports (font-variation-settings: normal)
{
	html
	{
		font-family: 'Inter var', sans-serif;
	}
}

body


@@ 18,11 40,24 @@ h4 code

code
{
	background: #f2f4f4;
	background: $code;
	border-radius: 5px;
	padding: 3px 5px 3px 5px;
}

a,
a:visited
{
	color: #0242f2;
	text-decoration: underline;

	&:hover
	{
		color: #0056b3;
		text-decoration: none;
	}
}

.container
{
	width: 60em;


@@ 45,6 80,11 @@ code
{
	display: grid;
	grid-template-columns: 16em auto;

	.sidebar
	{
		margin-right: 1em;
	}
}

video


@@ 58,6 98,11 @@ video
	{
		display: flex;
		flex-direction: column;

		.sidebar
		{
			margin-right: none;
		}
	}

	.container


@@ 66,3 111,62 @@ video
		margin: 1em;
	}
}

.hljs
{
	display: block;
	overflow-x: auto;
	background: $code;
	padding: 1em;
	color: $black;
	font-size: 1rem;
	font-family: monospace;
	font-variant-ligatures: normal;
	font-weight: 500;
}
.hljs-comment, .hljs-quote
{
	font-style: italic;
	color: $green;
}
.hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-regexp, .hljs-deletion
{
	font-weight: 500;
}
.hljs-variable, .hljs-template-variable, .hljs-tag
{
	font-weight: 600;
}
.hljs-number, .hljs-builtin-name, .hljs-literal, .hljs-type, .hljs-params, .hljs-link
{
	font-weight: 400;
	font-style: italic;
}
.hljs-attribute
{
	font-weight: 700;
}
.hljs-string,  .hljs-symbol, .hljs-bullet, .hljs-addition
{
	font-style: italic;
	color: $red;
}
.hljs-title, .hljs-section
{
	font-style: underline;
	color: $blue;
}
.hljs-keyword, .hljs-built_in, .hljs-selector-tag
{
	color: $blue;
	font-weight: bold;
}
.hljs-emphasis
{
	font-weight: 700;
}
.hljs-strong
{
	font-weight: 700;
	opacity: 1;
}

M docs/templates/home.html => docs/templates/home.html +0 -2
@@ 1,8 1,6 @@
<html>
	<head>
		<meta name="viewport" content="width=device-width">
		<link rel="stylesheet"
			href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css">
		<link rel="stylesheet" href="styles.css">
		<title>${title}</title>
	</head>

M docs/templates/page.html => docs/templates/page.html +1 -2
@@ 1,8 1,6 @@
<html>
	<head>
		<meta name="viewport" content="width=device-width">
		<link rel="stylesheet"
			href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/default.min.css">
		<link rel="stylesheet" href="styles.css">
		<title>${title}</title>
	</head>


@@ 33,6 31,7 @@

		<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js"></script>
		<script>
			hljs.initHighlightingOnLoad();
			document.addEventListener('DOMContentLoaded', (event) => {
				document.querySelectorAll('pre code').forEach((block) => {
					hljs.highlightBlock(block);

M gui.c => gui.c +4 -1
@@ 100,7 100,8 @@ void gui(gui_arg_t *arg)
		nk_input_begin(ctx);
		while (SDL_PollEvent(&evt))
		{
			if (evt.type == SDL_QUIT) goto cleanup;
			if (evt.type == SDL_QUIT)
				goto cleanup;
			nk_sdl_handle_event(&evt);
		}
		nk_input_end(ctx);


@@ 235,6 236,8 @@ cleanup:
	SDL_Quit();

	cmd(mq, "quit");

	printf("Cleaned up GUI\n");
}



M main.c => main.c +2 -0
@@ 163,6 163,8 @@ int main(int argc, char **argv)
		run_mq(&cpu, mq_to_cpu);
	}

	unwind();

	if (should_read)
	{
		free_cpu(&cpu);

M screen.c => screen.c +1 -1
@@ 66,7 66,7 @@ sdl_screen_t new_sdl_screen(uint8_t size)

void free_sdl_screen(sdl_screen_t *scr)
{
	//free(scr->fb);
	puts("Freed SDL Screen");
	SDL_DestroyTexture(scr->tex);
	SDL_DestroyRenderer(scr->r);
	SDL_DestroyWindow(scr->win);