how to exit without reloading CCP?

Post Reply
nippur72
Member
Posts: 29
Joined: Sat Sep 29, 2018 4:47 pm

how to exit without reloading CCP?

Post by nippur72 »

is there a way to exit from a compiled program without forcing the reload of the CCP ?

As far as I know, small .COM files can simply "RET" to return to prompt, assuming that the CCP memory area hasn't been overwritten.
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Re: how to exit without reloading CCP?

Post by dom »

At the moment, the classic CP/M target issues a jp 0 at the end of execution.

However, if you edit lib/target/cpm/classic/cpm_crt0.asm you can change it to do whatever you like. If changing it to a ret works, then I'll add an option to allow it to be chosen at compile time.
sblendorio
Member
Posts: 20
Joined: Tue Jan 19, 2021 9:03 am

Re: how to exit without reloading CCP?

Post by sblendorio »

Interesting. There is now an option?
nippur72
Member
Posts: 29
Joined: Sat Sep 29, 2018 4:47 pm

Re: how to exit without reloading CCP?

Post by nippur72 »

One issue might be the stack set by Z88DK. If it's set to use the maximum available memory (e.g. LD SP, <START_OF_BIOS>) then the CCP is surely to get corrupted and you can't exit to the system without reloading the CCP.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: how to exit without reloading CCP?

Post by stefano »

I've been thinking at it today.
For what I could observe the cp/m sets the stack just before BDOS, which probably destroys the CCP.
I noticed that the CCP position is sometimes predicted referring to the BIOS position and subtracting a fixed constant on those machines with a full 64k range covered.
Probably we might roughly predict a safe position for the stack dynamically basing on the current SP value and subtracting the probable size.

The Dominic's suggestion is not difficult to use though.
You need to edit cpm_crt0.asm, change JP 0 to RET, and force a safe position for SP, far enough from you program (e.g. add 0x2000 to you compiled .bin file size)
nippur72
Member
Posts: 29
Joined: Sat Sep 29, 2018 4:47 pm

Re: how to exit without reloading CCP?

Post by nippur72 »

Instead of using the current SP value, the pointer (0001H) contains the start of BIOS from which you can derive the start of CCP (-5632 bytes in the CPM2.2 system I'm logged into).

I had a look at the disassembly of CCP+BDOS, for hints on how the stack is handled:

- BDOS has its own stack (48 bytes)
- CCP has a 16 bytes stack located almost at the end of CCP before BDOS as @stefano already noticed.
- After a transient program terminates, the stack pointer is restored to its fixed location at the end of CCP
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: how to exit without reloading CCP?

Post by stefano »

I checked it too and I confirm you have 48 bytes (plus few more which BDOS users as temporary variables) before overlapping the CCP.
If they are enough, there's no need to move the stack.
I wouldn't rely on a fixed offset from the BIOS to track down a value for SP, though. Any deviation from an ideal system (e.g. a BIOS in ROM at bottom and little RAM) will make your program crash.
nippur72
Member
Posts: 29
Joined: Sat Sep 29, 2018 4:47 pm

Re: how to exit without reloading CCP?

Post by nippur72 »

is it 48 or 16? because when a transient prg is launched the stack is the CCP one (16) not the BDOS one (48) (at least as far as I've understood from the disassembly).
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: how to exit without reloading CCP?

Post by stefano »

48 on the Bondwell 2, the BDOS stack is BEFORE the code.
At the very beginning the BDOS seems to have few more bytes used as internal BDOS variables, still after the CCP block.
Post Reply