diff --git a/toolbox/mm.cpp b/toolbox/mm.cpp index f3c7c71..66d2a32 100644 --- a/toolbox/mm.cpp +++ b/toolbox/mm.cpp @@ -114,6 +114,35 @@ namespace MM return 0; } + uint16_t DisposePtr(uint16_t trap) + { + /* + * on entry: + * A0 Pointer to the nonrelocatable block to be disposed of + * + * on exit: + * D0 Result code + * + */ + + uint32_t mcptr = cpuGetAReg(0); + + fprintf(stderr, "%04x DisposePtr(%08x)\n", trap, mcptr); + + + auto iter = PtrMap.find(mcptr); + + if (iter == PtrMap.end()) return memWZErr; + PtrMap.erase(iter); + + uint8_t *ptr = mcptr + Memory; + + mplite_free(&pool, ptr); + + return 0; + } + + uint16_t NewPtr(uint16_t trap) { diff --git a/toolbox/mm.h b/toolbox/mm.h index 72774a4..5d0f959 100644 --- a/toolbox/mm.h +++ b/toolbox/mm.h @@ -7,12 +7,14 @@ namespace MM { enum { - memFullErr = -108 + memFullErr = -108, + memWZErr = -111, }; bool Init(uint8_t *memory, uint32_t memorySize, uint32_t reserved); uint16_t BlockMove(uint16_t trap); + uint16_t DisposePtr(uint16_t trap); uint16_t NewPtr(uint16_t trap); }