CP/M for the 6502?
Posted: Thu Aug 18, 2022 12:53 pm
I'm getting this peculiar urge to port CP/M to the 6502. I need help.
So, what I'm thinking about is a fairly simple rewrite of CP/M 2.2, initially targeted at something like a C64 with 1541 disk, although I'd like it to be portable (I have more experience with the BBC Micro). This consists of a BIOS, containing all the platform-specific stuff, the BDOS which has the filesystem and I/O layer, and the CCP command processor which gets loaded on demand.
The biggest issue is that the 6502 and the 8080/Z80 tend to have dramatically different address space designs. The former likes memory-mapped I/O, the latter likes I/O instructions. This means that the userland in CP/M systems all tend to be very similar: lots of RAM starting at 0000. Programs can be compiled at the fixed address of 0100 and they'll run on anything. (There were some CP/M systems with a different base address but they never prospered.) 6502 systems have zero page at 0000, the stack at 0100, vectors right at the top of memory, I/O scattered throughout --- the C64 has video memory from 0400 to 0800 IIRC. Then there's zero page. The C64 has the MMU registers at the bottom. The BBC Micro Tube has the Tube workspace at the top. So, your program load address will vary depending on system.
So, I thought that to be at all useful, you'd need relocatable binaries. This would allow programs to be loaded anywhere. But, simple relocation isn't enough as the system would also need to assign zero page addresses. This shouldn't actually be hard using the traditional approach of adding the required address to bytes in the program (either high byte of load address or low byte of zero page address). It would also have the side effect of making it easy to implement TSRs, which would be a nice bonus and is something that CP/M was never very good at. This means that the same program could be loaded at 0400 on a BBC Micro Tube system with ZP starting at 00, or at 0800 on a C64 with ZP starting at 02. (Or at 0200/00 on a PET.)
Size-wise I would expect the 6502 version to be similar to the 8080 version: the BDOS is 3.5kB, the CCP is 2kB. So, on a C64, assuming a 2kB BIOS, you'd get about a 55kB TPA, which is respectable. A BBC Micro Tube system would get a bit more. A stock BBC Micro B would get 17kB in MODE 7, which is pretty miserable. A BBC Micro in mode 3 would get about 4kB, which is pathetic, but at least it would run.
In terms of prior art: I know of DOS/65 by Richard Leary, but it's got an encumbered license and so I can't use it; and OUP/M, which has no license at all and is specific for OSI machines, but is very similar to what I have in mind. So I know it's possible. Have I missed anything?
So, what I'm thinking about is a fairly simple rewrite of CP/M 2.2, initially targeted at something like a C64 with 1541 disk, although I'd like it to be portable (I have more experience with the BBC Micro). This consists of a BIOS, containing all the platform-specific stuff, the BDOS which has the filesystem and I/O layer, and the CCP command processor which gets loaded on demand.
The biggest issue is that the 6502 and the 8080/Z80 tend to have dramatically different address space designs. The former likes memory-mapped I/O, the latter likes I/O instructions. This means that the userland in CP/M systems all tend to be very similar: lots of RAM starting at 0000. Programs can be compiled at the fixed address of 0100 and they'll run on anything. (There were some CP/M systems with a different base address but they never prospered.) 6502 systems have zero page at 0000, the stack at 0100, vectors right at the top of memory, I/O scattered throughout --- the C64 has video memory from 0400 to 0800 IIRC. Then there's zero page. The C64 has the MMU registers at the bottom. The BBC Micro Tube has the Tube workspace at the top. So, your program load address will vary depending on system.
So, I thought that to be at all useful, you'd need relocatable binaries. This would allow programs to be loaded anywhere. But, simple relocation isn't enough as the system would also need to assign zero page addresses. This shouldn't actually be hard using the traditional approach of adding the required address to bytes in the program (either high byte of load address or low byte of zero page address). It would also have the side effect of making it easy to implement TSRs, which would be a nice bonus and is something that CP/M was never very good at. This means that the same program could be loaded at 0400 on a BBC Micro Tube system with ZP starting at 00, or at 0800 on a C64 with ZP starting at 02. (Or at 0200/00 on a PET.)
Size-wise I would expect the 6502 version to be similar to the 8080 version: the BDOS is 3.5kB, the CCP is 2kB. So, on a C64, assuming a 2kB BIOS, you'd get about a 55kB TPA, which is respectable. A BBC Micro Tube system would get a bit more. A stock BBC Micro B would get 17kB in MODE 7, which is pretty miserable. A BBC Micro in mode 3 would get about 4kB, which is pathetic, but at least it would run.
In terms of prior art: I know of DOS/65 by Richard Leary, but it's got an encumbered license and so I can't use it; and OUP/M, which has no license at all and is specific for OSI machines, but is very similar to what I have in mind. So I know it's possible. Have I missed anything?