6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed May 08, 2024 2:52 pm

All times are UTC




Post new topic Reply to topic  [ 64 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
 Post subject: CP/M for the 6502!
PostPosted: Tue Oct 04, 2022 9:14 am 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
Interested parties may be, er, interested to know that I've just done a basic port of CP/M to the 6502.

https://github.com/davidgiven/cpm65

It currently runs on the BBC Micro (and Master and Tube), and the Commodore 64 (very slowly), but should be almost trivial to port to any system with a reasonable amount of contiguous RAM and zero page. It adds relocatable binaries, necessary to make programs portable between systems, but is otherwise essentially CP/M 2.2, just rewritten for the 6502. Naturally, there is no software whatsoever for it...

Also, if you're interested in watching about 45 hours of Youtube, I recorded myself programming it. Videos will be appearing here:

https://www.youtube.com/playlist?list=P ... RZL8K0zRDA


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Tue Oct 04, 2022 1:04 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 690
Location: North Tejas
Thanks for doing this and picking a permissive license.

Not promising anything will ever come of this, but I have been working on an 8080 processor simulator to run on my FLEX for 6502. It is currently stalled due to complexities around the differences between the CP/M and FLEX file system structures. A version for CPM65 would not have this problem.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Tue Oct 04, 2022 2:17 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
oooo, i wonder how difficult it would be to port to the 65816 plus the mentioned 8080 Emulator.... hhmm, does a version of CP/M exist that was written in C? that would make it much easier to port to any given architecture.
also i'm a bit confused why you're using ca65 for the assembly but then llvm-mos for the C. why not just do everything with one of them? so that you don't need to get 2 seperate utlities to build it.
or are the C files not needed to just generate a regular binary?


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Tue Oct 04, 2022 2:19 pm 
Offline

Joined: Fri Dec 21, 2018 1:05 am
Posts: 1076
Location: Albuquerque NM USA
Very cool! I’ll try porting it to CRC65 which has 58K RAM, serial port, compact disk interface, and run up to 29.5Mhz.
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Tue Oct 04, 2022 4:24 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
@Proxy Short answer to the last: I was going to do it all with cc65 but then couldn't figure out how to persuade cc65 to produce CP/M-65 binaries with the relocations. mos-llvm was easy to port (well, as easy as ELF parsing gets).

There isn't a CP/M in C, but I have actually thought about it. It'd make a fantastic stub OS for boot loaders, microcontrollers etc.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Wed Oct 05, 2022 12:46 am 
Offline

Joined: Fri Dec 21, 2018 1:05 am
Posts: 1076
Location: Albuquerque NM USA
I'm a casual user of CC65 in Windows development environment, so I'm trying to understand the various commands of CC65 embedded in CPM65 assembly and include files. CRC65 has 58K RAM from $0 to $E7FF, so what should be the values of __ZEROPAGE_SIZE__, __CODE_RUN__, __BSS_RUN__, __BSS_SIZE__ ?
Bill

Edit:
I should mention that I do have experiences with porting CP/M to Z80 and 68K machines. Since I'm porting CPM65 to a specific 6502 hardware, CRC65, I don't need relocatable 6502 code. My plan for CPM65 is putting BIOS/BDOS/CCP at top of RAM ending at $E7FF while CPM65 program starts from $300 (assuming $200-$2FF is allocated to BDOS calls).


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Wed Oct 05, 2022 9:53 am 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
For the BDOS and CCP, those symbols are magic --- the link script sets them (the linker thinks that binaries assemble at $0200 with zero page starting at $00, and then there's a tool that fixes up the result into a relocatable binary). For the BIOS, they're set by the platform linker script in scripts/c64.cfg or scripts/bbcmicro.cfg. The BDOS doesn't have to be relocatable but I haven't done that bit yet so for now I'd load and relocate it via the BIOS. The bottom of memory is easier because when it starts up the BDOS will try to adjust the bottom of the TPA and ZP workspace automatically.

The biggest difference between CP/M-80 and CP/M-65 is that the BDOS is only loaded once, on startup, and isn't reloaded on warm boots. Both the BBC Micro and C64 ports use the native file system to load it.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Wed Oct 05, 2022 2:20 pm 
Offline

Joined: Thu Jan 07, 2021 1:29 pm
Posts: 14
Very nice, congrats!
Will have a good look at it.

_________________
/NollKollTroll


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Thu Oct 06, 2022 2:30 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3354
Location: Ontario, Canada
Unsurprisingly, this very cool project is being discussed on Hacker News. :)

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Thu Oct 06, 2022 7:05 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Having a direct port of CP/M is very nice, so a big thanks to David on this. I've also started watching the videos... and will dive deeper into those. I've sorta figured out the BIOS interface, which is different to what I'm using now, but that should be pretty easy to change over. Most of the 6502 code I've seen or written has used the A/Y register pair for passing data/addresses/parameters and the X register for passing a command (as does DOS/65), so this CP/M port has the X/Y registers swapped in usage, not a big problem, but leveraging some of the CMOS instructions/addressing modes might be more cumbersome, but time will tell.

Sadly, I'm not a CC65 user but will look at it more closely.... but will likely look to move it over to WDC Tools (hate it or love it... it's what I use).

Chances are I can port it over to a modified version of my C02 Pocket (reconfigured for 56KB and RAM and 8KB of EPROM) and modify the BIOS to boot from the Microdrive. Ah... another project 8)

As the initial port seems to favor older retro machines, using newer storage (which all default to 512-byte blocks), I'll likely use a similar blocking routine to what DOS/65 uses. Unless I'm not up to date... I believe that CP/M 2.2 is limited to an 8MB maximum disk size and a maximum file size of 512KB. Is this correct??

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


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Thu Oct 06, 2022 8:45 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
I'm actually in the process of moving over to llvm-mos for doing the assembly. However, the only part which needs to be modified for a new port is the BIOS --- everything else, including the BDOS, uses the same binaries. Let me know if you need help. Documentation is, erm, lacking.

Re block size: yeah, everything from the BDOS down assumes traditional 128-byte sectors (I've tried to refer to these as 'records' where possible to avoid confusion). Deblocking ought to be simple; the C64 port does it due to the underlying 256-byte sector size. bios_WRITE takes a parameter to tell it whether a write should be deferred, performed immediately, or whether this is writing to a new allocation block and so the BDOS doesn't care about the state of the rest of the sector. CP/M 2.2 supports 8MB files (0x10000 records) and 1GB disks (0x10000 16k blocks), although you won't enjoy using a disk that size; it'll need an allocation bitmap which is a full 8kB long, which is ridiculous.

Re XA: that's actually what I've seen elsewhere; it frees up Y for doing indirect indexing, making things a lot easier for doing stuff with the value. It's what llvm-mos uses.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Fri Oct 07, 2022 8:20 pm 
Offline
User avatar

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

I built up a VM with the latest Ubuntu 22.04.1 running under Fusion (VM Ware on OSX). After installing a lot of stuff and building llvm-mos from your modified version, I was able to complete the build images for the C64 and Beeb. I mounted and autostarted the D64 image using Vice (runs on OSX) and it booted CPM/65, yay!

Now, is there an easy way to get the BDOS and CCP files and preferably the listing files separately?

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


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Fri Oct 07, 2022 8:30 pm 
Offline

Joined: Fri Dec 21, 2018 1:05 am
Posts: 1076
Location: Albuquerque NM USA
Impressive progress, floobydust. I’ve gotten absolutely nowhere trying to understand the inner working of CC65, BDOS, CCP, BIOS. They are too abstract for my simple-minded thought process. I think I’ll have better luck emulating your C02 pocket SBC hardware then following your progress implementing CPM65 on your C02 pocket SBC. Yep, in fact that’s what I’ll do.
Bill


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Fri Oct 07, 2022 9:25 pm 
Offline
User avatar

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 87
Excellent!

What do you mean by getting the BDOS and CCP files separately? The source is in src/bdos.s and src/ccp.s respectively (plus a bunch of macro packages).


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Fri Oct 07, 2022 9:47 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
The sources are no issue... but I find having a listing file is really nice, especially when I start moving it to WDC Tools. Some of the calculated values as operands don't always work the same between assemblers and that can cause all kinds of problems.

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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 64 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 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: