diff --git a/toolbox/mm.cpp b/toolbox/mm.cpp index 5fe8e57..503bdfb 100644 --- a/toolbox/mm.cpp +++ b/toolbox/mm.cpp @@ -145,69 +145,8 @@ namespace MM } - 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 SetMemError(memWZErr); - PtrMap.erase(iter); - - uint8_t *ptr = mcptr + Memory; - - mplite_free(&pool, ptr); - - return SetMemError(0); - } - - uint16_t DisposeHandle(uint16_t trap) - { - /* - * on entry: - * A0 Handle to be disposed of - * - * on exit: - * D0 Result code - * - */ - - uint32_t hh = cpuGetAReg(0); - - fprintf(stderr, "%04x DisposeHandle(%08x)\n", trap, hh); - - - auto iter = HandleMap.find(hh); - - if (iter == HandleMap.end()) return SetMemError(memWZErr); - - HandleInfo info = iter->second; - - HandleMap.erase(iter); - - uint8_t *ptr = info.address + Memory; - - mplite_free(&pool, ptr); - - HandleQueue.push_back(hh); - - return SetMemError(0); - } - - + #pragma mark Pointers uint16_t NewPtr(uint16_t trap) { @@ -257,6 +196,56 @@ namespace MM return SetMemError(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 SetMemError(memWZErr); + PtrMap.erase(iter); + + uint8_t *ptr = mcptr + Memory; + + mplite_free(&pool, ptr); + + return SetMemError(0); + } + + uint32_t GetPtrSize(uint16_t trap) + { + /* + * on entry: + * A0 pointer + * + * on exit: + * D0 size (32-bit) or error code + * + */ + + uint32_t mcptr = cpuGetAReg(0); + + fprintf(stderr, "%08x GetPtrSize(%08x,)\n", trap, mcptr); + + auto iter = PtrMap.find(mcptr); + + if (iter == PtrMap.end()) return SetMemError(memWZErr); + + return iter->second; + } + uint16_t SetPtrSize(uint16_t trap) { /* @@ -277,7 +266,6 @@ namespace MM auto iter = PtrMap.find(mcptr); if (iter == PtrMap.end()) return SetMemError(memWZErr); - PtrMap.erase(iter); uint8_t *ptr = mcptr + Memory; @@ -286,9 +274,14 @@ namespace MM return SetMemError(memFullErr); } + // update the size. + iter->second = newSize; + return SetMemError(0); } + #pragma mark Handles + uint16_t NewHandle(uint16_t trap) { /* @@ -350,6 +343,85 @@ namespace MM return SetMemError(0); } + uint16_t DisposeHandle(uint16_t trap) + { + /* + * on entry: + * A0 Handle to be disposed of + * + * on exit: + * D0 Result code + * + */ + uint32_t hh = cpuGetAReg(0); + + fprintf(stderr, "%04x DisposeHandle(%08x)\n", trap, hh); + + + auto iter = HandleMap.find(hh); + + if (iter == HandleMap.end()) return SetMemError(memWZErr); + + HandleInfo info = iter->second; + + HandleMap.erase(iter); + + uint8_t *ptr = info.address + Memory; + + mplite_free(&pool, ptr); + + HandleQueue.push_back(hh); + + return SetMemError(0); + } + + #pragma mark Handle attributes + + // these are all nops for now. + + uint16_t HLock(uint16_t trap) + { + /* + * on entry: + * A0 Handle + * + * on exit: + * D0 Result code + * + */ + + uint32_t hh = cpuGetAReg(0); + + fprintf(stderr, "%04x HLock(%08x)\n", trap, hh); + + auto iter = HandleMap.find(hh); + + if (iter == HandleMap.end()) return SetMemError(memWZErr); + + return 0; + } + + uint16_t HUnlock(uint16_t trap) + { + /* + * on entry: + * A0 Handle + * + * on exit: + * D0 Result code + * + */ + + uint32_t hh = cpuGetAReg(0); + + fprintf(stderr, "%04x HUnlock(%08x)\n", trap, hh); + + auto iter = HandleMap.find(hh); + + if (iter == HandleMap.end()) return SetMemError(memWZErr); + + return 0; + } } \ No newline at end of file diff --git a/toolbox/mm.h b/toolbox/mm.h index e0cd7a5..14aa171 100644 --- a/toolbox/mm.h +++ b/toolbox/mm.h @@ -15,14 +15,21 @@ namespace MM uint16_t BlockMove(uint16_t trap); uint32_t CompactMem(uint16_t trap); - uint16_t DisposePtr(uint16_t trap); + uint16_t DisposeHandle(uint16_t trap); + uint16_t DisposePtr(uint16_t trap); + + uint32_t GetHandleSize(uint16_t); + uint32_t GetPtrSize(uint16_t); - uint16_t NewPtr(uint16_t trap); uint16_t NewHandle(uint16_t trap); + uint16_t NewPtr(uint16_t trap); - uint16_t SetPtrSize(uint16_t); uint16_t SetHandleSize(uint16_t); + uint16_t SetPtrSize(uint16_t); + + uint16_t HLock(uint16_t trap); + uint16_t HUnlock(uint16_t trap); } diff --git a/toolbox/toolbox.cpp b/toolbox/toolbox.cpp index fe43ebf..435e4a3 100644 --- a/toolbox/toolbox.cpp +++ b/toolbox/toolbox.cpp @@ -54,10 +54,23 @@ namespace ToolBox { d0 = MM::SetPtrSize(trap); break; + // GetPtrSize (p: Ptr) : Size + case 0xa021: + d0 = MM::GetPtrSize(trap); + break; + case 0xA023: d0 = MM::DisposeHandle(trap); break; + case 0xa029: + d0 = MM::HLock(trap); + break; + + case 0xa02a: + d0 = MM::HUnlock(trap); + break; + // BlockMove (sourcePtr,destPtr: Ptr; byteCount: Size); case 0xa02e: d0 = MM::BlockMove(trap);