From a2422209c164091a65806a1c154a390d47748334 Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Fri, 30 Jun 2023 22:33:35 +0100 Subject: [PATCH 1/6] Add `TAG` and `OWNER`, plus constants for enum values. --- indirection.inc | 178 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 167 insertions(+), 11 deletions(-) diff --git a/indirection.inc b/indirection.inc index 7158362..01a3c0a 100644 --- a/indirection.inc +++ b/indirection.inc @@ -139,6 +139,8 @@ enum E_INDIRECTION E_INDIRECTION_CLAIM, // Called by `Indirect_Claim`. E_INDIRECTION_RELEASE, // Called by `Indirect_Release`. E_INDIRECTION_METADATA, // Only used by end-users. + E_INDIRECTION_TAG, // Save the encoded parameters tag of this callback. + E_INDIRECTION_OWNER // Attach the function to players etc. } stock @@ -147,6 +149,25 @@ stock INDIRECTION_DATA = 0, INDIRECTION_TAG = 0; +// Constant offsets for assembly. +const + E_INDIRECTION_ALWAYS_NULL_cells = _:E_INDIRECTION_ALWAYS_NULL, + E_INDIRECTION_HANDER_cells = _:E_INDIRECTION_HANDER, + E_INDIRECTION_CLAIM_cells = _:E_INDIRECTION_CLAIM, + E_INDIRECTION_RELEASE_cells = _:E_INDIRECTION_RELEASE, + E_INDIRECTION_METADATA_cells = _:E_INDIRECTION_METADATA, + E_INDIRECTION_TAG_cells = _:E_INDIRECTION_TAG, + E_INDIRECTION_OWNER_cells = _:E_INDIRECTION_OWNER, + E_INDIRECTION_cells = _:E_INDIRECTION, + E_INDIRECTION_ALWAYS_NULL_bytes = _:E_INDIRECTION_ALWAYS_NULL * cellbytes, + E_INDIRECTION_HANDER_bytes = _:E_INDIRECTION_HANDER * cellbytes, + E_INDIRECTION_CLAIM_bytes = _:E_INDIRECTION_CLAIM * cellbytes, + E_INDIRECTION_RELEASE_bytes = _:E_INDIRECTION_RELEASE * cellbytes, + E_INDIRECTION_METADATA_bytes = _:E_INDIRECTION_METADATA * cellbytes, + E_INDIRECTION_TAG_bytes = _:E_INDIRECTION_TAG * cellbytes, + E_INDIRECTION_OWNER_bytes = _:E_INDIRECTION_OWNER * cellbytes, + E_INDIRECTION_bytes = _:E_INDIRECTION * cellbytes; + stock const INDIRECTION_NAUGHT = 0; @@ -321,7 +342,6 @@ stock Indirect_Call__(meta, GLOBAL_TAG_TYPES:...) { const cells0 = 4 * cellbytes; const cells1 = -1 * cellbytes; - const cells2 = 1 * cellbytes; const cells3 = 1 * cellbytes; const cells4 = 2 * cellbytes; static @@ -367,7 +387,7 @@ stock Indirect_Call__(meta, GLOBAL_TAG_TYPES:...) if (!INDIRECTION_DATA) { // Get the function at `func - COD + 4`. - #emit CONST.pri cells2 + #emit CONST.pri E_INDIRECTION_HANDER_bytes #emit ADD #emit LOAD.I // Call it, passing `func` as a proper pointer, NOT skipping `PROC`. @@ -667,7 +687,6 @@ stock Indirect_Array(func, tag, const params[], size = sizeof (params)) #endif const cells1 = 5 * cellbytes; const cells2 = 6 * cellbytes; - const cells3 = 1 * cellbytes; const cells4 = 1 * cellbytes; const cells5 = 2 * cellbytes; static @@ -733,7 +752,7 @@ stock Indirect_Array(func, tag, const params[], size = sizeof (params)) #emit STOR.alt INDIRECTION_DATA // Get the function at `func - COD + 4`. #emit LOAD.pri INDIRECTION_DATA - #emit ADD.C cells3 + #emit ADD.C E_INDIRECTION_HANDER_bytes #emit LOAD.I // Call it, passing `func` as a proper pointer, NOT skipping `PROC`. #emit SCTRL 6 @@ -788,6 +807,146 @@ stock Indirect_Array(func, tag, const params[], size = sizeof (params)) return 0; } +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer with attached Tagdata. + * + * Gets extra data from the pointer. + * + *//*------------------------------------------------------------------------**/ + +stock Indirect_GetTag_(func) +{ + if (func >= gsCodSize) + { + // Get the data at `func - COD`. + #emit LOAD.S.pri func + #emit LOAD.alt gsCodSize + #emit SUB + #emit MOVE.alt + #emit LOAD.I + #emit STOR.S.pri func + if (func) + { + // Probably a string. + return 0; + } + {} + // I'm relying on `alt` not changing here... + // Get the function at `func - COD + 16`. + #emit CONST.pri E_INDIRECTION_TAG_bytes + #emit ADD + #emit LOAD.I + #emit RETN + } + return 0; +} +#define Indirect_GetTag(%0) Indirect_GetTag_(_:%0) + +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer to attach Tagdata to. + * The Tagdata. + *//*------------------------------------------------------------------------**/ + +stock Indirect_SetTag_(func, data) +{ + if (func >= gsCodSize) + { + // Get the data at `func - COD`. + #emit LOAD.S.pri func + #emit LOAD.alt gsCodSize + #emit SUB + #emit MOVE.alt + #emit LOAD.I + #emit STOR.S.pri func + if (func) + { + // Probably a string. + return; + } + {} + // I'm relying on `alt` not changing here... + // Get the function at `func - COD + 16`. + #emit CONST.pri E_INDIRECTION_TAG_bytes + #emit ADD + #emit LOAD.S.alt data + #emit XCHG + #emit STOR.I + } +} +#define Indirect_SetTag(%0) Indirect_SetTag_(_:%0) + +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer with attached Ownerdata. + * + * Gets extra data from the pointer. + * + *//*------------------------------------------------------------------------**/ + +stock Indirect_GetOwner_(func) +{ + if (func >= gsCodSize) + { + // Get the data at `func - COD`. + #emit LOAD.S.pri func + #emit LOAD.alt gsCodSize + #emit SUB + #emit MOVE.alt + #emit LOAD.I + #emit STOR.S.pri func + if (func) + { + // Probably a string. + return 0; + } + {} + // I'm relying on `alt` not changing here... + // Get the function at `func - COD + 16`. + #emit CONST.pri E_INDIRECTION_OWNER_bytes + #emit ADD + #emit LOAD.I + #emit RETN + } + return 0; +} +#define Indirect_GetOwner(%0) Indirect_GetOwner_(_:%0) + +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer to attach Ownerdata to. + * The Ownerdata. + *//*------------------------------------------------------------------------**/ + +stock Indirect_SetOwner_(func, data) +{ + if (func >= gsCodSize) + { + // Get the data at `func - COD`. + #emit LOAD.S.pri func + #emit LOAD.alt gsCodSize + #emit SUB + #emit MOVE.alt + #emit LOAD.I + #emit STOR.S.pri func + if (func) + { + // Probably a string. + return; + } + {} + // I'm relying on `alt` not changing here... + // Get the function at `func - COD + 16`. + #emit CONST.pri E_INDIRECTION_OWNER_bytes + #emit ADD + #emit LOAD.S.alt data + #emit XCHG + #emit STOR.I + } +} +#define Indirect_SetOwner(%0) Indirect_SetOwner_(_:%0) + /*-------------------------------------------------------------------------*//** * indirection * The function pointer with attached metadata. @@ -798,7 +957,6 @@ stock Indirect_Array(func, tag, const params[], size = sizeof (params)) stock Indirect_GetMeta_(func) { - const cells0 = 4 * cellbytes; if (func >= gsCodSize) { // Get the data at `func - COD`. @@ -816,7 +974,7 @@ stock Indirect_GetMeta_(func) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri cells0 + #emit CONST.pri E_INDIRECTION_METADATA_bytes #emit ADD #emit LOAD.I #emit RETN @@ -833,7 +991,6 @@ stock Indirect_GetMeta_(func) stock Indirect_SetMeta_(func, data) { - const cells0 = 4 * cellbytes; if (func >= gsCodSize) { // Get the data at `func - COD`. @@ -851,7 +1008,7 @@ stock Indirect_SetMeta_(func, data) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri cells0 + #emit CONST.pri E_INDIRECTION_METADATA_bytes #emit ADD #emit LOAD.S.alt data #emit XCHG @@ -897,7 +1054,7 @@ stock Indirect_Claim_(func) #emit POP.pri #emit SCTRL 5 // Get the function at `func - COD + 8`. - #emit CONST.pri 8 + #emit CONST.pri E_INDIRECTION_CLAIM_bytes #emit ADD #emit LOAD.I #emit SCTRL 6 @@ -920,7 +1077,6 @@ stock Indirect_Claim_(func) stock Indirect_Release_(func) { - const cells0 = 3 * cellbytes; if (func >= gsCodSize) { // Get the data at `func - COD`. @@ -944,7 +1100,7 @@ stock Indirect_Release_(func) #emit POP.pri #emit SCTRL 5 // Get the function at `func - COD + 12`. - #emit CONST.pri cells0 + #emit CONST.pri E_INDIRECTION_RELEASE_cells #emit ADD #emit LOAD.I #emit SCTRL 6 From c69f4fb50c6effc9f06c88560d187fc0282e6c33 Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Sat, 1 Jul 2023 10:55:58 +0100 Subject: [PATCH 2/6] Use correct release call offset. --- indirection.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indirection.inc b/indirection.inc index 01a3c0a..0781d4f 100644 --- a/indirection.inc +++ b/indirection.inc @@ -1100,7 +1100,7 @@ stock Indirect_Release_(func) #emit POP.pri #emit SCTRL 5 // Get the function at `func - COD + 12`. - #emit CONST.pri E_INDIRECTION_RELEASE_cells + #emit CONST.pri E_INDIRECTION_RELEASE_bytes #emit ADD #emit LOAD.I #emit SCTRL 6 From 26ac16fe12b9fbf959a04ca6febad2b329107a0b Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Sat, 1 Jul 2023 11:25:33 +0100 Subject: [PATCH 3/6] It turns out you can use enum values directly in assembly. Thus we use the real name for cell offsets and `__` suffix for byte offsets. --- indirection.inc | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/indirection.inc b/indirection.inc index 0781d4f..7b2e814 100644 --- a/indirection.inc +++ b/indirection.inc @@ -151,22 +151,14 @@ stock // Constant offsets for assembly. const - E_INDIRECTION_ALWAYS_NULL_cells = _:E_INDIRECTION_ALWAYS_NULL, - E_INDIRECTION_HANDER_cells = _:E_INDIRECTION_HANDER, - E_INDIRECTION_CLAIM_cells = _:E_INDIRECTION_CLAIM, - E_INDIRECTION_RELEASE_cells = _:E_INDIRECTION_RELEASE, - E_INDIRECTION_METADATA_cells = _:E_INDIRECTION_METADATA, - E_INDIRECTION_TAG_cells = _:E_INDIRECTION_TAG, - E_INDIRECTION_OWNER_cells = _:E_INDIRECTION_OWNER, - E_INDIRECTION_cells = _:E_INDIRECTION, - E_INDIRECTION_ALWAYS_NULL_bytes = _:E_INDIRECTION_ALWAYS_NULL * cellbytes, - E_INDIRECTION_HANDER_bytes = _:E_INDIRECTION_HANDER * cellbytes, - E_INDIRECTION_CLAIM_bytes = _:E_INDIRECTION_CLAIM * cellbytes, - E_INDIRECTION_RELEASE_bytes = _:E_INDIRECTION_RELEASE * cellbytes, - E_INDIRECTION_METADATA_bytes = _:E_INDIRECTION_METADATA * cellbytes, - E_INDIRECTION_TAG_bytes = _:E_INDIRECTION_TAG * cellbytes, - E_INDIRECTION_OWNER_bytes = _:E_INDIRECTION_OWNER * cellbytes, - E_INDIRECTION_bytes = _:E_INDIRECTION * cellbytes; + E_INDIRECTION_ALWAYS_NULL__ = _:E_INDIRECTION_ALWAYS_NULL * cellbytes, + E_INDIRECTION_HANDER__ = _:E_INDIRECTION_HANDER * cellbytes, + E_INDIRECTION_CLAIM__ = _:E_INDIRECTION_CLAIM * cellbytes, + E_INDIRECTION_RELEASE__ = _:E_INDIRECTION_RELEASE * cellbytes, + E_INDIRECTION_METADATA__ = _:E_INDIRECTION_METADATA * cellbytes, + E_INDIRECTION_TAG__ = _:E_INDIRECTION_TAG * cellbytes, + E_INDIRECTION_OWNER__ = _:E_INDIRECTION_OWNER * cellbytes, + E_INDIRECTION__ = _:E_INDIRECTION * cellbytes; stock const INDIRECTION_NAUGHT = 0; @@ -387,7 +379,7 @@ stock Indirect_Call__(meta, GLOBAL_TAG_TYPES:...) if (!INDIRECTION_DATA) { // Get the function at `func - COD + 4`. - #emit CONST.pri E_INDIRECTION_HANDER_bytes + #emit CONST.pri E_INDIRECTION_HANDER__ #emit ADD #emit LOAD.I // Call it, passing `func` as a proper pointer, NOT skipping `PROC`. @@ -752,7 +744,7 @@ stock Indirect_Array(func, tag, const params[], size = sizeof (params)) #emit STOR.alt INDIRECTION_DATA // Get the function at `func - COD + 4`. #emit LOAD.pri INDIRECTION_DATA - #emit ADD.C E_INDIRECTION_HANDER_bytes + #emit ADD.C E_INDIRECTION_HANDER__ #emit LOAD.I // Call it, passing `func` as a proper pointer, NOT skipping `PROC`. #emit SCTRL 6 @@ -834,7 +826,7 @@ stock Indirect_GetTag_(func) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_TAG_bytes + #emit CONST.pri E_INDIRECTION_TAG__ #emit ADD #emit LOAD.I #emit RETN @@ -868,7 +860,7 @@ stock Indirect_SetTag_(func, data) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_TAG_bytes + #emit CONST.pri E_INDIRECTION_TAG__ #emit ADD #emit LOAD.S.alt data #emit XCHG @@ -904,7 +896,7 @@ stock Indirect_GetOwner_(func) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_OWNER_bytes + #emit CONST.pri E_INDIRECTION_OWNER__ #emit ADD #emit LOAD.I #emit RETN @@ -938,7 +930,7 @@ stock Indirect_SetOwner_(func, data) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_OWNER_bytes + #emit CONST.pri E_INDIRECTION_OWNER__ #emit ADD #emit LOAD.S.alt data #emit XCHG @@ -974,7 +966,7 @@ stock Indirect_GetMeta_(func) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_METADATA_bytes + #emit CONST.pri E_INDIRECTION_METADATA__ #emit ADD #emit LOAD.I #emit RETN @@ -1008,7 +1000,7 @@ stock Indirect_SetMeta_(func, data) {} // I'm relying on `alt` not changing here... // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_METADATA_bytes + #emit CONST.pri E_INDIRECTION_METADATA__ #emit ADD #emit LOAD.S.alt data #emit XCHG @@ -1054,7 +1046,7 @@ stock Indirect_Claim_(func) #emit POP.pri #emit SCTRL 5 // Get the function at `func - COD + 8`. - #emit CONST.pri E_INDIRECTION_CLAIM_bytes + #emit CONST.pri E_INDIRECTION_CLAIM__ #emit ADD #emit LOAD.I #emit SCTRL 6 @@ -1100,7 +1092,7 @@ stock Indirect_Release_(func) #emit POP.pri #emit SCTRL 5 // Get the function at `func - COD + 12`. - #emit CONST.pri E_INDIRECTION_RELEASE_bytes + #emit CONST.pri E_INDIRECTION_RELEASE__ #emit ADD #emit LOAD.I #emit SCTRL 6 From 111f75a27cd275ae5352c2cdbf6bed4a9b448445 Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Sun, 2 Jul 2023 11:50:46 +0100 Subject: [PATCH 4/6] Add `NEXT` to indirection. --- indirection.inc | 80 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/indirection.inc b/indirection.inc index 7b2e814..015ca1a 100644 --- a/indirection.inc +++ b/indirection.inc @@ -140,7 +140,8 @@ enum E_INDIRECTION E_INDIRECTION_RELEASE, // Called by `Indirect_Release`. E_INDIRECTION_METADATA, // Only used by end-users. E_INDIRECTION_TAG, // Save the encoded parameters tag of this callback. - E_INDIRECTION_OWNER // Attach the function to players etc. + E_INDIRECTION_OWNER, // Attach the function to players etc. + E_INDIRECTION_NEXT // Next pointer in a generic list of callbacks. } stock @@ -158,6 +159,7 @@ const E_INDIRECTION_METADATA__ = _:E_INDIRECTION_METADATA * cellbytes, E_INDIRECTION_TAG__ = _:E_INDIRECTION_TAG * cellbytes, E_INDIRECTION_OWNER__ = _:E_INDIRECTION_OWNER * cellbytes, + E_INDIRECTION_NEXT__ = _:E_INDIRECTION_NEXT * cellbytes, E_INDIRECTION__ = _:E_INDIRECTION * cellbytes; stock const @@ -799,6 +801,76 @@ stock Indirect_Array(func, tag, const params[], size = sizeof (params)) return 0; } +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer with attached Nextdata. + * + * Gets extra data from the pointer. + * + *//*------------------------------------------------------------------------**/ + +stock Indirect_GetNext_(func) +{ + if (func >= gsCodSize) + { + // Get the data at `func - COD`. + #emit LOAD.S.pri func + #emit LOAD.alt gsCodSize + #emit SUB + #emit MOVE.alt + #emit LOAD.I + #emit STOR.S.pri func + if (func) + { + // Probably a string. + return 0; + } + {} + // I'm relying on `alt` not changing here... + // Get the function at `func - COD + 16`. + #emit CONST.pri E_INDIRECTION_NEXT__ + #emit ADD + #emit LOAD.I + #emit RETN + } + return 0; +} +#define Indirect_GetNext(%0) Indirect_GetNext_(_:%0) + +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer to attach Nextdata to. + * The Nextdata. + *//*------------------------------------------------------------------------**/ + +stock Indirect_SetNext_(func, data) +{ + if (func >= gsCodSize) + { + // Get the data at `func - COD`. + #emit LOAD.S.pri func + #emit LOAD.alt gsCodSize + #emit SUB + #emit MOVE.alt + #emit LOAD.I + #emit STOR.S.pri func + if (func) + { + // Probably a string. + return; + } + {} + // I'm relying on `alt` not changing here... + // Get the function at `func - COD + 16`. + #emit CONST.pri E_INDIRECTION_NEXT__ + #emit ADD + #emit LOAD.S.alt data + #emit XCHG + #emit STOR.I + } +} +#define Indirect_SetNext(%0,%1) Indirect_SetNext_(_:(%0),%1) + /*-------------------------------------------------------------------------*//** * indirection * The function pointer with attached Tagdata. @@ -867,7 +939,7 @@ stock Indirect_SetTag_(func, data) #emit STOR.I } } -#define Indirect_SetTag(%0) Indirect_SetTag_(_:%0) +#define Indirect_SetTag(%0,%1) Indirect_SetTag_(_:(%0),%1) /*-------------------------------------------------------------------------*//** * indirection @@ -937,7 +1009,7 @@ stock Indirect_SetOwner_(func, data) #emit STOR.I } } -#define Indirect_SetOwner(%0) Indirect_SetOwner_(_:%0) +#define Indirect_SetOwner(%0,%1) Indirect_SetOwner_(_:(%0),%1) /*-------------------------------------------------------------------------*//** * indirection @@ -1007,7 +1079,7 @@ stock Indirect_SetMeta_(func, data) #emit STOR.I } } -#define Indirect_SetMeta(%0) Indirect_SetMeta_(_:%0) +#define Indirect_SetMeta(%0,%1) Indirect_SetMeta_(_:(%0),%1) /*-------------------------------------------------------------------------*//** * indirection From 5ad981fb7d7ff316baa60977a752c5737bbd8b0f Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Mon, 3 Jul 2023 13:25:11 +0100 Subject: [PATCH 5/6] Set owners in EBC at a low level. --- indirection.inc | 50 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/indirection.inc b/indirection.inc index 015ca1a..9a3018f 100644 --- a/indirection.inc +++ b/indirection.inc @@ -873,9 +873,9 @@ stock Indirect_SetNext_(func, data) /*-------------------------------------------------------------------------*//** * indirection - * The function pointer with attached Tagdata. + * The function pointer with a tag. * - * Gets extra data from the pointer. + * Gets the tag of the pointer. * *//*------------------------------------------------------------------------**/ @@ -909,11 +909,11 @@ stock Indirect_GetTag_(func) /*-------------------------------------------------------------------------*//** * indirection - * The function pointer to attach Tagdata to. - * The Tagdata. + * The function pointer to attach a tag to. + * The tag. *//*------------------------------------------------------------------------**/ -stock Indirect_SetTag_(func, data) +stock bool:Indirect_SetTag_(func, tag) { if (func >= gsCodSize) { @@ -934,18 +934,20 @@ stock Indirect_SetTag_(func, data) // Get the function at `func - COD + 16`. #emit CONST.pri E_INDIRECTION_TAG__ #emit ADD - #emit LOAD.S.alt data + #emit LOAD.S.alt tag #emit XCHG #emit STOR.I + return true; } + return false; } #define Indirect_SetTag(%0,%1) Indirect_SetTag_(_:(%0),%1) /*-------------------------------------------------------------------------*//** * indirection - * The function pointer with attached Ownerdata. + * The function pointer with an owner. * - * Gets extra data from the pointer. + * Gets the owner of the pointer. * *//*------------------------------------------------------------------------**/ @@ -983,7 +985,13 @@ stock Indirect_GetOwner_(func) * The Ownerdata. *//*------------------------------------------------------------------------**/ -stock Indirect_SetOwner_(func, data) +/*-------------------------------------------------------------------------*//** + * indirection + * The function pointer to attach an owner to. + * The owner. + *//*------------------------------------------------------------------------**/ + +stock Indirect_SetOwner_(func, owner) { if (func >= gsCodSize) { @@ -1000,14 +1008,22 @@ stock Indirect_SetOwner_(func, data) return; } {} - // I'm relying on `alt` not changing here... - // Get the function at `func - COD + 16`. - #emit CONST.pri E_INDIRECTION_OWNER__ - #emit ADD - #emit LOAD.S.alt data - #emit XCHG - #emit STOR.I + #emit STOR.S.alt func + if (ReadAmxMemory(func + E_INDIRECTION_NEXT__)) + { + // Can't use this list pointer to save the owner. + return false; + } + // Store the owner. + WriteAmxMemory(func + E_INDIRECTION_OWNER__, owner), + // Change the claim pointer to our internal one, so we add it to the + // list if this is ever claimed. + owner = ReadAmxMemory(func + E_INDIRECTION_CLAIM__), + WriteAmxMemory(func + E_INDIRECTION_NEXT__, owner), + WriteAmxMemory(func + E_INDIRECTION_CLAIM__, _:addressof (Indirect_EBCClaim_)); + return true; } + return false; } #define Indirect_SetOwner(%0,%1) Indirect_SetOwner_(_:(%0),%1) @@ -1077,7 +1093,9 @@ stock Indirect_SetMeta_(func, data) #emit LOAD.S.alt data #emit XCHG #emit STOR.I + return true; } + return false; } #define Indirect_SetMeta(%0,%1) Indirect_SetMeta_(_:(%0),%1) From 0abcc4cfa441ef87da48662eaa7440e07d9c2bce Mon Sep 17 00:00:00 2001 From: Alex Cole Date: Thu, 6 Jul 2023 09:49:41 +0100 Subject: [PATCH 6/6] Write the EBC claim function. --- indirection.inc | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/indirection.inc b/indirection.inc index 9a3018f..bbdb73e 100644 --- a/indirection.inc +++ b/indirection.inc @@ -166,7 +166,9 @@ stock const INDIRECTION_NAUGHT = 0; static stock - gsCodSize = 0; // The size of `COD`. + gsCodSize = 0, // The size of `COD`. + gsKnownOwnedCallbacks = 0, + gsFakeE_INDIRECTION[E_INDIRECTION]; #if !defined YSI_MAX_STRING #define YSI_MAX_STRING (144) @@ -857,7 +859,7 @@ stock Indirect_SetNext_(func, data) if (func) { // Probably a string. - return; + return false; } {} // I'm relying on `alt` not changing here... @@ -867,7 +869,9 @@ stock Indirect_SetNext_(func, data) #emit LOAD.S.alt data #emit XCHG #emit STOR.I + return true; } + return false; } #define Indirect_SetNext(%0,%1) Indirect_SetNext_(_:(%0),%1) @@ -927,7 +931,7 @@ stock bool:Indirect_SetTag_(func, tag) if (func) { // Probably a string. - return; + return false; } {} // I'm relying on `alt` not changing here... @@ -981,10 +985,34 @@ stock Indirect_GetOwner_(func) /*-------------------------------------------------------------------------*//** * indirection - * The function pointer to attach Ownerdata to. - * The Ownerdata. + * The function pointer to claim with owner. + * + * Replaces the default CLAIM function so this is called instead, then + * forwards to the original. + * *//*------------------------------------------------------------------------**/ +#define CALL@Indirect_EBCClaim_%8() Indirect_EBCClaim_%8(gsFakeE_INDIRECTION) + +static stock Indirect_EBCClaim_(func[E_INDIRECTION]) +{ + // Reset the claim pointer. + func[E_INDIRECTION_CLAIM] = func[E_INDIRECTION_NEXT]; + // Add this callback to the list of known callbacks. + func[E_INDIRECTION_NEXT] = gsKnownOwnedCallbacks; + gsKnownOwnedCallbacks = ref(func[E_INDIRECTION_NEXT]); + // Re-claim the function using the original pointer. + #emit LOAD.S.alt func + // Reset the frame. + #emit POP.pri + #emit SCTRL 5 + // Perfect call forward. + #emit CONST.pri E_INDIRECTION_CLAIM__ + #emit ADD + #emit LOAD.I + #emit SCTRL 6 +} + /*-------------------------------------------------------------------------*//** * indirection * The function pointer to attach an owner to. @@ -1005,7 +1033,7 @@ stock Indirect_SetOwner_(func, owner) if (func) { // Probably a string. - return; + return false; } {} #emit STOR.S.alt func @@ -1083,7 +1111,7 @@ stock Indirect_SetMeta_(func, data) if (func) { // Probably a string. - return; + return false; } {} // I'm relying on `alt` not changing here...