From 73ed0778f2e1dd5a7241b7a406a24e70b5602717 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 11 Dec 2022 22:04:22 -0600 Subject: [PATCH] Add cleanup code for CDev calls. The new CDev root code generated by ORCA/C will now branch to this code after each CDev call, giving it an opportunity to clean up if necessary. Specifically, it will dispose of the user ID allocated for the CDev if it is going away after this call. There are several cases where this occurs, which need to be detected based on the message code passed to the CDev and in some cases other factors. --- cc.asm | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/cc.asm b/cc.asm index c794916..3ddb0f8 100644 --- a/cc.asm +++ b/cc.asm @@ -375,6 +375,60 @@ start ds 2 start of the command line string targv ds 4 end +**************************************************************** +* +* ~CDevCleanup - cleanup code run after a CDev call +* +* Inputs: +* A+X - CDev result value +* 1,S - Original data bank to restore +* 2,S - Return address +* 5,S - Message code passed to CDev +* 7,S - Old user ID from before the call (0 if none) +* +* Notes: +* This routine handles cases where the CDev is going +* away and so the user ID allocated for it needs to be +* disposed of to avoid being leaked. +* +**************************************************************** +* +~CDevCleanup start +MachineCDEV equ 1 +BootCDEV equ 2 +CloseCDEV equ 5 +AboutCDEV equ 8 + + tay stash low word of result + + lda 5,s if message == CloseCDEV + cmp #CloseCDEV + beq cleanup + cmp #BootCDEV or message == BootCDEV + beq cleanup + cmp #AboutCDEV or message == AboutCDEV + bne lb1 + lda 7,s and original user ID was 0 + beq cleanup (i.e. CDev window was not open) + bra ret +lb1 cmp #MachineCDEV or message == MachineCDEV + bne ret + tya and return value is 0 + bne ret + txa + bne ret + +cleanup pea 0 ...then dispose of user ID + jsl >~DAID + +ret tya store return value in result space + sta 5,s + txa + sta 7,s + plb restore data bank + rtl return to original caller + end + **************************************************************** * * ~CUMul2 - unsigned multiply