News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_JonB

Extending the CCP in CP/M 2.2

Started by JonB, 09:23, 05 May 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JonB

Hello everybody!


I'm starting to hack about with the source code for CP/M 2.2 on a home built FPGA based machine. I have the source code of the BIOS and all of CP/M and can build and deploy to the machine (described here in case you're interested: Grant's home-designed CP/M machine).


The source is all here and it is well commented http://searle.hostei.com/grant/Multicomp/cpm/FPGA_CPM_files.zip .


So to the point. I want to alter the CCP so that when loading a transient program, if not found in the current user space, it falls back to user 0 and re-attempts the load. I would also say "..and if that fails, fall back to Drive A:, User 0 and try again" but I think there is not enough spare in the CCP's address space for that.


Fortunately there are 13 spare bytes between the CCP and BIOS that can be used (they are full of NULLs) and a subroutine commented as VERIFY along with two buffers PATTRN1 and PATTRN2 plus a call to VERIFY that we can remove.


So now we are left with a decent chunk of space in which to make our changes. And they are like this (refer to UNKWN1: in the source cpm22.asm for context):


;   Here a file name was typed. Prepare to execute it.
;
UNKWN1: LD      DE,FCB+9        ;an extension specified?
        LD      A,(DE)
        CP      ' '
        JP      NZ,SYNERR       ;yes, not allowed.
UNKWN2: PUSH    DE
        CALL    DSELECT         ;select specified drive.
        POP     DE
        LD      HL,COMFILE      ;set the extension to 'COM'.
        CALL    MOVE3
        CALL    OPENFCB         ;and open this file.
        JP      NZ,UNKWNL       ;jump to load
        CALL    GETUSR          ;get current user
        CP      0               ;already zero?
        JP      Z,UNKWN9        ;already user zero, not found
        LD      (SAVEUSR),A     ;not zero, save it
        LD      E,0             ;switch to user zero
        CALL    GETSETUC
        CALL    OPENFCB         ;try to open at User 0
        JP      Z,UNKWNA        ;not found at user 0
        LD      A,(SAVEUSR)     ;restore
        LD      E,A
        CALL    GETSETUC
;
;   Load in the program.
;
UNKWNL: LD      HL,TBASE        ;store the program starting here.
.
.


;
;   Get here if some error occured.
;
UNKWNA: LD      A,(SAVEUSR)     ;restore USER number
        LD      E,A
        CALL    GETSETUC
UNKWN9: CALL    RESETDR         ;inproper format.
        JP      SYNERR
UNKWN0: LD      BC,BADLOAD      ;read error or won't fit.
        CALL    PLINE
        JP      GETBACK
BADLOAD:.TEXT   "Bad load"
        .DB     0
COMFILE:.TEXT   "COM"           ;command file extension.


The effect of switching to USER 0 and restoring it is that when you are in a different user it will load and run a program from USER 0 if not found in your present user.


The assumption made here is that once the executable file is open it is safe to revert the user number prior to loading (at comment ";restore" just above label UNKWNL:). The program does load and run.


However, it is only working some of the time; when loading a program from USER 0 from a different user and the loaded program takes a filename as an argument, certain programs crash or do other odd things.


I'm not sure why just yet, I expect there is something more required than just a call to GETSETUC when restoring the original user number. One thing I thought is we should restore after loading the program, not between open and load (as I do).


All advice welcome!


Regards
JonB

FloppySoftware

Quote from: JonB on 09:23, 05 May 15
I'm not sure why just yet, I expect there is something more required than just a call to GETSETUC when restoring the original user number. One thing I thought is we should restore after loading the program, not between open and load (as I do).

Sure.
Best to do following steps:
1. Remember current user number.
2. Set user number 0.
3. Open, read and close the file under the user number 0.
4. Set old user number.
5. Run the program.
The support for user numbers in CP/M is very basic.
In fact, you can't open a file under a user number and write to it under a different user number.
In SamaruX, my Unix like shell for CP/M, to ensure I can read/write/etc. to any file under any user number, I do:
1. set file user number
2. do the desired BDOS file operation: read, write, rename, etc.
3. set previous user number
Anyway, it would be very interesting for you to read the book The Programmer's CP/M Handbook, by Andy Johnson-Laird.
He describes and implements with source code what you want, but patching the CCP at BIOS level.
The source code is freely downloable at the Unofficial CP/M Website (and the book is here and there too).
Good luck!


floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

JonB

I have that book, it is very errm "wordy". Have not read it all, yet.


I think I will revisit my code and restore U0 after file close. But I was wondering about the code that sets up the default FCB, but I assume it is done before the TP is loaded, because these kinds of programs seem to work properly.

FloppySoftware

Quote from: JonB on 12:53, 05 May 15
I have that book, it is very errm "wordy". Have not read it all, yet.

It's the best book ever written about CP/M 2, specially if you are interested in porting CP/M.

It have lots of code regarding BDOS & BIOS, and two kind of BIOS sources: a standard one, and a enhanced one (including the extensión you are talking about).
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

JonB

#4
I couldn't make sense of it. Lousy 8080 mnemonics. Fortuantely my cp/m 2.2 code is in Z80 (hurrah!) although it is a straight port, not optimised to take advantage of the Z80's extra features.


So. I have looked again and spotted some buglets and squashed them. Seems I zapped register A accidentally while restoring a user number so I did an EX AF,AF' befoer and after the call to my restore routine. Sorted, though I'm not sure it is fully functional yet, but it does appear to be working now. What is most interesting is the need to maintain my CCP size at 100H and this means looking for places where I can save a byte or two. There are four free bytes now. Wow, I hear you say! A whole four bytes!


Meanwhile, thank you for your advice...


Cheers
JonB

FloppySoftware

Quote from: JonB on 15:49, 05 May 15
What is most interesting is the need to maintain my CCP size at 100H

You have the disassembled (source) code.
You can change above limit if you want. ;)
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

TFM

@JonB Seriously, take a look a the Z-System. All you want to do was done before. Search for Z3Plus in the net. And start at gaby.de (english available).

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

JonB

Yes, but I need to stay on a 100h boundary I believe. So I tried extending the thing by 100h and my Aztec C compiler wouldn't work (out of memory). Grrrrr..


Anyway, this whole thing came about from me using Montezuma CP/M 2.2 on the TRS-80 Model 4. I'd put the compiler in USER 0 and use a different user for a workspace (source etc), one per project. Works fine. I've just gone back to it to check a few things out and I see that it makes User 0 fully public, which means if (for example) you try to open a text file from User 5 and it is present on User 0, it opens. Save it and it is written to User 5. Same thing with .COM files. Hmm, I would like to do the same for my FPGA CP/M box, so I guess it's into BIOS land for me. Or BDOS...

TFM

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

JonB

Quote from: TFM on 16:58, 05 May 15
@JonB Seriously, take a look a the Z-System. All you want to do was done before. Search for Z3Plus in the net. And start at gaby.de (english available).


Can't find any install instructions that don't use MOVCPM.COM or SYSTEM.COM, neither of which I have (installation is performed via the monitor - one loads the assembled .hex files into the monitor (send as text in a terminal program) followed by a program to write it all to the disk. Then jump to the program entry point and it installs.


Not sure how I'd use Z-sys under this situation. Plus I really don't like their user guide, it spends gazillions of pages telling you why it is so great, but not how to install it. I guess the authors have big heads?

TFM

Oh man, I know from own experience to write the handbook is always the hardest part. The reason for ending up this way is that out there are always zillions of nasty jealous people giving one shit for a great project so the damn handbook ends up to be a pamphlet of of self defense - sadly.  :laugh:
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

FloppySoftware

Quote from: JonB on 17:02, 05 May 15
Yes, but I need to stay on a 100h boundary I believe. So I tried extending the thing by 100h and my Aztec C compiler wouldn't work (out of memory). Grrrrr..


Anyway, this whole thing came about from me using Montezuma CP/M 2.2 on the TRS-80 Model 4. I'd put the compiler in USER 0 and use a different user for a workspace (source etc), one per project. Works fine. I've just gone back to it to check a few things out and I see that it makes User 0 fully public, which means if (for example) you try to open a text file from User 5 and it is present on User 0, it opens. Save it and it is written to User 5. Same thing with .COM files. Hmm, I would like to do the same for my FPGA CP/M box, so I guess it's into BIOS land for me. Or BDOS...
But that feature is done by the CCP or by the compiler?
Of course, as TFM suggests, the Z-System has that improvement over CP/M 2.
Oh, by the way... CP/M 3 has that feature also (and a lot more)!
:)
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

FloppySoftware

Quote from: TFM on 17:08, 05 May 15
Oh man, I know from own experience to write the handbook is always the hardest part.

Agreed!!!  ;D
floppysoftware.es < NEW URL!!!
cpm-connections.blogspot.com.es

JonB

Quote from: JonB on 17:02, 05 May 15
Yes, but I need to stay on a 100h boundary I believe. So I tried extending the thing by 100h and my Aztec C compiler wouldn't work (out of memory). Grrrrr..


Anyway, this whole thing came about from me using Montezuma CP/M 2.2 on the TRS-80 Model 4. I'd put the compiler in USER 0 and use a different user for a workspace (source etc), one per project. Works fine. I've just gone back to it to check a few things out and I see that it makes User 0 fully public, which means if (for example) you try to open a text file from User 5 and it is present on User 0, it opens. Save it and it is written to User 5. Same thing with .COM files. Hmm, I would like to do the same for my FPGA CP/M box, so I guess it's into BIOS land for me. Or BDOS...


Yes, that is what Montezuma does. User 0 is fully public for reads, but not writes. So if I open a file from a different user that's not visible to DIR, but if you subsequently save, the file is written to the current user. That seems usable to me.

Powered by SMFPacks Menu Editor Mod