From: Lauri Kasanen Date: Mon, 1 May 2017 18:00:28 +0000 (+0300) Subject: Trampoline stack X-Git-Tag: V2.17~142^2~9 X-Git-Url: https://git.sur5r.net/?p=cc65;a=commitdiff_plain;h=d091a57e918244f0d6a7b651b908f7f08a2cee95 Trampoline stack --- diff --git a/src/cc65/trampoline.c b/src/cc65/trampoline.c new file mode 100644 index 000000000..1f35a0f3c --- /dev/null +++ b/src/cc65/trampoline.c @@ -0,0 +1,102 @@ +/*****************************************************************************/ +/* */ +/* trampoline.c */ +/* */ +/* Trampoline management */ +/* */ +/* */ +/* */ +/* (C) 2017, Mega Cat Studios */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#include +#include + +/* common */ +#include "chartype.h" +#include "check.h" +#include "coll.h" +#include "scanner.h" +#include "intptrstack.h" +#include "xmalloc.h" + +/* cc65 */ +#include "codeent.h" +#include "error.h" +#include "trampoline.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + +/* Trampolines */ +static IntPtrStack Trampolines; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void PushTrampoline (void *Ptr, unsigned char Val) +/* Push the current trampoline */ +{ + if (IPS_IsFull (&Trampolines)) { + Error ("Trampoline stack overflow"); + } else { + IPS_Push (&Trampolines, Val, Ptr); + } +} + + + +void PopTrampoline (void) +/* Remove the current trampoline */ +{ + if (IPS_GetCount (&Trampolines) < 1) { + Error ("Trampoline stack is empty"); + } else { + IPS_Drop (&Trampolines); + } +} + + + +void GetTrampoline (void **Ptr, unsigned char *Val) +/* Get the current trampoline */ +{ + if (IPS_GetCount (&Trampolines) < 1) { + *Ptr = NULL; + *Val = 0; + } else { + long Temp; + IPS_Get (&Trampolines, &Temp, Ptr); + *Val = Temp; + } +} diff --git a/src/cc65/trampoline.h b/src/cc65/trampoline.h new file mode 100644 index 000000000..f110bd42e --- /dev/null +++ b/src/cc65/trampoline.h @@ -0,0 +1,65 @@ +/*****************************************************************************/ +/* */ +/* trampoline.h */ +/* */ +/* Trampoline management */ +/* */ +/* */ +/* */ +/* (C) 2017, Mega Cat Studios */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef TRAMPOLINE_H +#define TRAMPOLINE_H + + + +#include + +/* common */ +#include "attrib.h" + +/* cc65 */ +#include "opcodes.h" + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void PushTrampoline (void *Ptr, unsigned char Val); +/* Push the current trampoline */ + +void PopTrampoline (void); +/* Pop the current trampoline */ + +void GetTrampoline (void **Ptr, unsigned char *Val); +/* Get the current trampoline, if any */ + + +/* End of trampoline.h */ + +#endif