6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue May 14, 2024 7:23 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Fri Oct 14, 2022 1:28 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
In the past, this post would have been wildly off topic. But with both operating systems making moves to colonize the 6502 world, maybe it is time...

As I worked on implementing FLEX on the 6502, I compiled this list of significant contrasts with CP/M-80 version 2.2, its primary competition at the time. Note that I am a user and fan of both.

This is not a comparison of the characteristics of 80xx and 68xx processors unless they directly impact the design of the respective operating system.


Ways in which CP/M is better:

* More memory is generally available for user programs. The 808x and Z80 processors have special input and output instructions which meant that precious parts of the limited 64K address space did not have to be reserved for interfacing peripheral devices. CP/M was designed to reside in the uppermost end of the address space and it can be moved to adapt to the memory size of individual systems in a manner transparent to application programs. The command processor (CCP) was intended to be overwritten by user programs if the space it occupied was needed; it is automagically reloaded as part of a "warm boot" on program terminaton. The FLEX memory map usually contains "wasted" space because of the location of I/O devices; the system image is at a fixed address and cannot be moved to provide more usable contiguous RAM.

* Commonly used commands such as DIR and TYPE are built into the command processor so disk access is not required to use them. FLEX requires they reside as executable files on a mounted disk, however, this fact makes renaming or replacing FLEX commands not only possible, but easy.

* The "current drive" concept is a very convenient way to designate a "working drive." FLEX users have to use a utility program to set and view the designation of the working drive.

* CP/M was more popular. The primary benefits are greater software availability and better coverage in published works.

* Better console interface for programming. FLEX offers no standard way to determine whether a character is available or to read that character without echo.

* CP/M is faster writing to disk. FLEX uses links within sectors to manage space allocation. Writing a FLEX sector requires reading it first to get the linkage information.

* CP/M is faster processing files. CP/M deals in 128-byte records; the default FLEX interface is a byte at a time.

* CP/M can support up to sixteen disk drives; this is an advantage today using emulation as the only cost of additional drives are small incremental amounts of memory to manage them. Standard FLEX only handles four drives.

* CP/M supports larger physical sector sizes while FLEX is stuck at 256 bytes. Larger physical sectors equals higher storage capacity for the same disk due to less overhead from sector headers and gaps. Sector blocking and deblocking does add complexity but often results in faster disk throughput.

* A CP/M File Control Block (FCB) is only 33 bytes long (36 for random files) while a FLEX FCB is 320 bytes. CP/M files share one "DMA" buffer for data transfer while each FLEX FCB contains its own sector buffer.

* The CP/M system call interface is more "modern" with a function code in a register. The FLEX API is a jump table to subroutines and a bunch of global system variables. Expanding the capabilities of FLEX quickly runs into available memory space limitations. To make matters worse, there is no way to determine which version of FLEX is running.

* CP/M SUBMIT and XSUB scripting is more powerful than the FLEX EXEC command.

* CP/M implementations may support the IOBYTE with limited support for redirecting character input and output.

* CP/M came with a debugger as standard equipment. The FLEX DEBUG package was an added cost option and it was painfully slow to use; it was actually a processor simulator with advanced capabilities similar to an in-circuit emulator.

* CP/M text files may contain hard Tab characters to conserve disk space. FLEX offsets that somewhat by implementing automatic compression of consecutive space characters in text files.

* Direct access files may contain unallocated space AKA sparse files. This feature may not have been used very much?

* All files may be accessed in direct mode; FLEX supports random access only for specially created files.

* CP/M-80 uses the .COM extension for executable files; CP/M-86 uses .CMD so users cannot accidently attempt to run programs for the "wrong" processor. FLEX uses the .CMD extension for both 6800 and 6809 systems; there is no easy way to distinguish between them.


Ways in which FLEX is better:

* FLEX recognizes an "end of line" character, more accurately described as a command separator, to allow typing more than one command on a line.

* The operating system did not reserve much disk space for itself. CP/M disks reserved several tracks for the operating system even when the disk is not intended to be bootable. Once loaded, FLEX does not require a bootable disk remain mounted.

* FLEX reserves a "system" FCB in memory for loading programs. If a program does not need to access more than one file at a time, it may choose to "reuse" this FCB instead of allocating its own.

* FLEX sets aside a separate region of memory to load and execute most system utility programs. This is an historical artifact from the days of very little memory which has benefit today: something like a text editor or BASIC interpreter can easily allow the user to execute most FLEX system commands without having to exit and reload.

* FLEX has provision to automatically display meaningful error messages instead of an error number.

* A "system drive" can be designated to hold commonly used programs. While not as nice as a search path, it was quite usable. The system and working drive can be set to "automatic" so that multiple drives are searched to find a file. This facility could have been made perfect if FLEX had used a "current drive" concept like CP/M to specify the working drive, plus adding a third "temporary drive" designation for scratch files.

* File space allocation granularity is a single sector. This was especially beneficial when storing a large number of small files on a low capacity disk.

* File space allocation is managed by the use of linked lists of sectors. While not an ideal approach, it does provide some significant benefits:

- Only one directory entry is used for a file. Large CP/M files may occupy more than one directory entry.

- FLEX has a slight advantage in that once a file is opened, the directory need not be accessed again to read the entire file sequentially.

- There is no limit on the number of files on a disk until it is full. The directory can be expanded as needed.

- Damage to the directory of a disk leaves open the possibility to recover files as the sector chains still exist. Programs have been written to find "orphaned" chains of sectors and convert them to files.

- The cost in terms of memory usage to manage a disk is constant. The allocation vector of a large CP/M disk can be unreasonably huge unless wastefully big block sizes are adopted.

- A hierarchical directory structure may be created using a third-party addition (now only for 6809 systems), though application programs may only access the "current directory" on each drive. Still, half of a solution is better than no solution or worse, the user number kludge CP/M provided. A major redesign of the BDOS space allocation scheme would be required to add subdirectories to CP/M, and a disk containing such subdirectories cannot be safely written on unmodified systems.

- FLEX is much more hard drive and emulator friendly. The third sector of track zero on each disk is the "System Information Record" containing information about the volume such as a name, number, the date on which it was formatted along with structural parameters such as the number of tracks on the disk, the number of sectors on a track as well as the start and end of the free sector chain and the number of free sectors. This is enough metadata for the system or a disk emulator to properly handle the volume. You just have to provide a way to properly format the volume. The absolute minimum size of a virtual FLEX volume is two tracks of five sectors per track; I have actually created such tiny "disks" to transfer files to someone else. They can "mount" it in their emulator and copy the data to their main disk.

* The I, O and P commands allow redirecting program input and output. Not as nice as UNIX or DOS, but again, a partial solution is better than none. The CP/M XSUB utility provides a very limited form of redirection only for input.

* FLEX optionally "paginates" output to the console, pausing after each screenful of text. While not as usable as a general "MORE" command, it is better than nothing.

* Compression of consecutive space characters in text files is built in to the system. Unfortunately, it uses the hard Tab character, precluding its use in files.

* System utilities carry a version number and a command (VERSION) displays it. Unfortunately, many (most?) third-party programs do not adhere to this standard, but at least there is a standard.

* Files are automatically treated as a stream of bytes. But that comes at a cost; each file control block (FCB) contains a sector buffer and disk access is generally slower because data is moved twice.

* Operating system support is provided to aid parsing a command line and converting numbers. CP/M will parse the first two file names into default FCBs, but that is it.

* FLEX was doing "autoexec" long before IBM decided to get into the personal computer business. The final step of system startup is to look for a file named "STARTUP.TXT" on the boot disk. If found, the first line is read and executed as if it was typed by the user. Multiple commands may be executed this way by the use of the command separator character. If more is needed, the EXEC command may be used to pass control to a file containing more commands. The CP/M CCP may be patched to execute a command at boot time, but it is a manual process requiring proficiency with utilities such SYSGEN and the system debugger.

* FLEX is actually a two-task operating system. The second task is used for background printing if an interrupt timer is available.


The motivation for creating the list: relatively easy ways to improve FLEX

* Implement a "MORE" command

* Expand to handle up to 10 disk drives (10 because drives are identified by number rather than letter)

* Implement a native debugger

* Add RAM disk to make frequently used commands "resident"

* Add "temporary drive" designation

* Add an optional "current drive" mode

* Add hierarchical directories

* Add support to store the time a file is written (there are two reserved bytes in directory entries)

* Add installable disk driver

* Add command history

* Add support for more than one free memory pool

Edit: fixed some typing errors, specified version 2.2 of CP/M-80, added FLEX friendliness with hard drives and emulation, STARTUP


Last edited by BillG on Sat Oct 15, 2022 11:16 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2022 1:37 pm 
Offline

Joined: Fri Dec 21, 2018 1:05 am
Posts: 1076
Location: Albuquerque NM USA
Great summary! I know about CP/M but I know nothing of FLEX. I'm interested in both for 6502. I hope to hear more about porting FLEX & CP/M to 6502.
Bill


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2022 5:27 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8183
Location: Midwestern USA
BillG wrote:
...I compiled this list of significant contrasts with CP/M-80

* Commonly used commands such as DIR and TYPE are built into the command processor so disk access is not required to use them. FLEX requires they reside as executable files on a mounted disk, however, this fact makes renaming or replacing FLEX commands not only possible, but easy.

In this respect, FLEX would be better. The more commands embedded into the CCP (what we would now refer to as a “shell”), the larger the CCP’s memory foot print, and the slower command parsing becomes. These, of course, would have been important considerations back when 64KB was a luxury and the MPU screamed along at one MHz. Of course, more disk activity was unwelcome back then as well...

Quote:
* CP/M was more popular. The primary benefits are greater software availability and better coverage in published works.

This is the biggie. Back in the day, CP/M was everywhere, and everyone and his uncle was publishing CP/M software (albeit on multiple disk formats). Despite my long experience with computers (dating back to 1970), I had never even heard of FLEX until it came up here...and I did have some early experience with the MC6800.

Quote:
* CP/M is faster writing to disk.

That's mostly moot with today’s hardware. However, given the sedate pace at which the floppy disks of the 1970s moved, anything that could speed up disk I/O was certainly welcome. Incidentally, the first CP/M system I ever used had an eight inch disk drive. Looking back at it, it wasn’t much faster than a Commodore 1541.

Quote:
* CP/M is faster processing files. CP/M deals in 128-byte records; the default FLEX interface is a byte at a time.

Seen from today’s perspective, the FLEX interface would be more “modern.” Case in point, UNIX and Linux model a byte-at-a-time low-level file interface, although the API call can specify more than one datum per call. The obvious benefit is a user application that is reading and writing files is completely shielded from the uncouth details of how the disk drive organizes data, and only has to tell the APIs how many bytes are to be moved.

Quote:
* CP/M can support up to sixteen disk drives; this is an advantage today using emulation as the only cost of additional drives are small incremental amounts of memory to manage them. Standard FLEX only handles four drives.

In this respect, both operating systems are archaic (as is, to some extent, MS-DOS and all forms of Windows). The 16-drive limit of CP/M vs. the four-drive limit of FLEX isn't really a big deal, as few systems back then had more than two disks—drives were costly and in the case of the full-height mechanisms that dominated in the 1970s, took up a lot room in the computer’s chassis. I never saw a CP/M system with more than two drives.

Quote:
* CP/M supports larger physical sector sizes while FLEX is stuck at 256 bytes...Sector blocking and deblocking does add complexity...

Obviously a clear advantage on CP/M’s side, especially if one were to decide one day to use a CD or DVD drive with CP/M—such drives natively present a 4096-byte block size. While blocking/deblocking does insert some complication, the process is entirely compute-bound, which on modern hardware would be a negligible burden to the MPU.

Quote:
* Direct access files may contain unallocated space AKA sparse files. This feature may not have been used very much?

I’ve created sparse files a few times on my (then UNIX, now Linux) machines, but I can’t recall having ever seen them used on CP/M. The ability to create a sparse file in CP/M is more “accidental” than intentional—it’s an artifact of how CP/M allocates disk space to files.

Quote:
* FLEX recognizes an "end of line" character, more accurately described as a command separator, to allow typing more than one command on a line.

That feature was anticipated in UNIX’s Bourne shell (the semicolon). It is useful, but also means the CCP/shell has to buffer the original command sequence somewhere in that valuable memory so it can pick through it one command at a time.

Quote:
* The operating system did not reserve much disk space for itself. CP/M disks reserved several tracks for the operating system even when the disk is not intended to be bootable. Once loaded, FLEX does not require a bootable disk remain mounted.

Not a big deal with today’s mass storage.

Quote:
* FLEX has provision to automatically display meaningful error messages instead of an error number.

Such a feature is possible in CP/M’s CCP, at the expense of the CCP needing more memory...a lot more if a complete catalog of error messages is implemented.

Quote:
* File space allocation granularity is a single sector. This was especially beneficial when storing a large number of small files on a low capacity disk.

This feature was a side-effect of FLEX’s byte-at-a-time file I/O model. UNIX and Linux also support this economical approach to allocating disk storage.

From today’s perspective, I think implementing CP/M would be the better choice, although to me it’s kind of like choosing between rancid meat and going without dinner. :D

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Last edited by BigDumbDinosaur on Fri Oct 14, 2022 9:38 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2022 9:21 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Thanks for the opening comparison.

I also would have an interest in having a port of FLEX on the 6502.

Also, for this particular thread, perhaps including DOS/65 (from Rich Leary) would be beneficial, as it's basically a functional remake of CP/M on the 6502, with full source available.

- as for CCP, I think the memory footprint is around 2KB, which I guess isn't too bad. But having the luxury of overwriting it for user programs is fine. However, if SUBMIT is used to do batch execution (from a .SUB file), then one would likely need to ensure that the CCP doesn't get clobbered in the process.

BTW - how is that 40-year old steak?

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 14, 2022 9:49 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8183
Location: Midwestern USA
floobydust wrote:
- as for CCP, I think the memory footprint is around 2KB, which I guess isn't too bad. But having the luxury of overwriting it for user programs is fine. However, if SUBMIT is used to do batch execution (from a .SUB file), then one would likely need to ensure that the CCP doesn't get clobbered in the process.

That would mean the space into which the CCP has been loaded, as well as any workspace it needs, has to somehow be protected. That would be an interesting thing to work out in a 65xx implementation, although less so with the 65C816. With the latter, and assuming it has at least 128K to work with, all parts of CP/M could be permanently loaded into bank $00 and bank $01 and higher could be the TPA. Not only would that simplify the processing of SUBMIT by the CCP, it would eliminate some disk I/O. Plus there would be room to add more internal commands to the CCP.

Quote:
BTW - how is that 40-year old steak?

See attached. :D

Attachment:
puking10.jpg
puking10.jpg [ 54.81 KiB | Viewed 851 times ]

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 15, 2022 11:48 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
BigDumbDinosaur wrote:
BillG wrote:
* Commonly used commands such as DIR and TYPE are built into the command processor so disk access is not required to use them. FLEX requires they reside as executable files on a mounted disk, however, this fact makes renaming or replacing FLEX commands not only possible, but easy.

In this respect, FLEX would be better. The more commands embedded into the CCP (what we would now refer to as a “shell”), the larger the CCP’s memory foot print, and the slower command parsing becomes. These, of course, would have been important considerations back when 64KB was a luxury and the MPU screamed along at one MHz. Of course, more disk activity was unwelcome back then as well...

Parsing would extract the command name, search for it in a command table and going to disk if not found. The size of the command table is not going to make a big difference in execution time. The concern about size is if a bigger CCP caused an overflow onto an additional reserved boot track.

BigDumbDinosaur wrote:
BillG wrote:
* FLEX recognizes an "end of line" character, more accurately described as a command separator, to allow typing more than one command on a line.

That feature was anticipated in UNIX’s Bourne shell (the semicolon). It is useful, but also means the CCP/shell has to buffer the original command sequence somewhere in that valuable memory so it can pick through it one command at a time.

The command line buffer is 128 bytes on both. It may matter for CP/M because the buffer is reused by default for a sector buffer. As for FLEX, the system call to read a line reuses that buffer so a program needs to either save the state of the command line or provide its own line entry code if needed.

BigDumbDinosaur wrote:
BillG wrote:
* File space allocation granularity is a single sector. This was especially beneficial when storing a large number of small files on a low capacity disk.

This feature was a side-effect of FLEX’s byte-at-a-time file I/O model. UNIX and Linux also support this economical approach to allocating disk storage.

It is a direct effect of the sector linked list allocation system instead of a block allocation system. The byte vs record transfer model had nothing to do with it.

Thanks for the comments.


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 15, 2022 12:12 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
floobydust wrote:
I also would have an interest in having a port of FLEX on the 6502.

I am still working on it. As they say, the final 20% of the operating system code is taking 80% of the development time. It appears you have changed your mind about putting the system image in ROM? The utilities are only about half done. The editor is still missing several commands and there are some bugs to fix. The assembler cannot handle much of the 6502 instruction set yet.

floobydust wrote:
Also, for this particular thread, perhaps including DOS/65 (from Rich Leary) would be beneficial, as it's basically a functional remake of CP/M on the 6502, with full source available.

Rich and David will have to speak for themselves about their work as I am not familiar with them. Also, DOS/65 is sometimes confused with DOS65, a fairly mature system with lots of languages and other software: http://retro.hansotten.nl/6502-sbc/dos65/

floobydust wrote:
- as for CCP, I think the memory footprint is around 2KB, which I guess isn't too bad. But having the luxury of overwriting it for user programs is fine. However, if SUBMIT is used to do batch execution (from a .SUB file), then one would likely need to ensure that the CCP doesn't get clobbered in the process.

Protecting CCP is not an issue.

This is how SUBMIT works: Create a file named $$$.SUB containing the lines of the script file in reverse order, one line per 128-byte record. Warm boot to reload CCP. If it detects the presence of $$$.SUB, it reads the last record of the file, decrements the record count, then executes the line. Repeat until the file is exhausted.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 18, 2022 4:11 pm 
Offline

Joined: Mon Feb 15, 2021 2:11 am
Posts: 100
BigDumbDinosaur wrote:

Attachment:
puking10.jpg


That was me, yesterday. Stomach bugs bite.


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 22, 2022 1:10 pm 
Offline

Joined: Sun Feb 22, 2004 9:01 pm
Posts: 78
BillG wrote:
* FLEX was doing "autoexec" long before IBM decided to get into the personal computer business. The final step of system startup is to look for a file named "STARTUP.TXT" on the boot disk. (...) The CP/M CCP may be patched to execute a command at boot time, but it is a manual process requiring proficiency with utilities such SYSGEN and the system debugger.

I thought CP/M did have autoexec facilities. On reset, the BIOS loads the BDOS and CCP, looks for BOOT.COM and BOOT.SUB and if found passes that to the CCP on startup.

_________________
--
JGH - http://mdfs.net


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Ask Jeeves [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: