6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 9:21 pm

All times are UTC




Post new topic Reply to topic  [ 72 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: CP/M for the 6502!
PostPosted: Fri Oct 07, 2022 10:04 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
plasmo wrote:
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


Bill,

It was a bit of a shotgun process... installed all of the listed tools, then started finding the missing pieces to rebuild and install llvm-mos, then find and install the missing bits to get cpm65 to build.

I'm putting together a small parts list now (Mouser) and will make some modifications to my 3.3V prototype setup. That will extend the memory by putting in a larger SRAM and changing the config on the '22V10 PLD. Once that's done, I'll modify the BIOS to allow a boot profile from the Microdrive. I'll probably use a standard partition record format and then a custom boot block that will load a BIOS stub that acts as a layer between my existing BIOS and what BDOS requires. Once that's done, it's just a load of BDOS and CCP... hopefully :shock:

In any case, It will be a little while before I get to that point. I'll post progress of course.

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


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

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 90
Oh, I see! Well, the good news is that my build system is set up to generate listings automatically --- look in .obj/cc65/src. The bad news is that cc65 helpfully censors all the useful bits, so the end result looks like this:

Code:
000039r 1  A9 00            lda #0
00003Br 1  8D rr rr         sta ccp_fcb + fcb::ex
00003Er 1  8D rr rr         sta ccp_fcb + fcb::s2
000041r 1  8D rr rr         sta ccp_fcb + fcb::cr
000044r 1  A9 01            lda #1
000046r 1  8D rr rr         sta ccp_fcb + fcb::dr
000049r 1               
000049r 1  A9 rr            lda #<ccp_fcb
00004Br 1  85 rr            sta param+0
00004Dr 1  A9 rr            lda #>ccp_fcb
00004Fr 1  85 rr            sta param+1
000051r 1  20 rr rr         jsr entry_OPENFILE
000054r 1  90 1E            zif_cs
000056r 1  A9 rr                lda #<no_ccp
000058r 1  A2 rr                ldx #>no_ccp
00005Ar 1  20 rr rr             jsr internal_WRITESTRING
00005Dr 1  4C rr rr             jmp *
000060r 1                   no_ccp:
000060r 1  43 6F 75 6C          .byte "Couldn't open CCP", 13, 10, 0
000064r 1  64 6E 27 74 
000068r 1  20 6F 70 65 
000074r 1                   zendif


Note that you don't have to rebuild these... the only bit you need to write to do a port is the BIOS. You can use the same BDOS and CCP binaries everywhere!


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

Joined: Fri Dec 21, 2018 1:05 am
Posts: 1119
Location: Albuquerque NM USA
floobydust wrote:
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.

Yep I agree, CC65 is a complex package with configuration file, pseudo directives, control commands, and recursive macros to manage many software modules, so it can be quite difficult for a newbie to untangle all these interconnected software modules. A full listing is an important intermediate step for me because it includes all the software modules, flatten the includes, hierarchy and macros, and resolve all symbols into one file so it is easier to search and understand the whole program. I’m further hampered by having no knowledge of Linux nor llvm-mos and I’m not good at C, so I think following your exploration of CPM65 port to your pocket SBC is probably the best path for me.
Bill


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

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
hjalfi wrote:
Oh, I see! Well, the good news is that my build system is set up to generate listings automatically --- look in .obj/cc65/src. The bad news is that cc65 helpfully censors all the useful bits, so the end result looks like this:

Code:
000039r 1  A9 00            lda #0
00003Br 1  8D rr rr         sta ccp_fcb + fcb::ex
00003Er 1  8D rr rr         sta ccp_fcb + fcb::s2
000041r 1  8D rr rr         sta ccp_fcb + fcb::cr
000044r 1  A9 01            lda #1
000046r 1  8D rr rr         sta ccp_fcb + fcb::dr
000049r 1               
000049r 1  A9 rr            lda #<ccp_fcb
00004Br 1  85 rr            sta param+0
00004Dr 1  A9 rr            lda #>ccp_fcb
00004Fr 1  85 rr            sta param+1
000051r 1  20 rr rr         jsr entry_OPENFILE
000054r 1  90 1E            zif_cs
000056r 1  A9 rr                lda #<no_ccp
000058r 1  A2 rr                ldx #>no_ccp
00005Ar 1  20 rr rr             jsr internal_WRITESTRING
00005Dr 1  4C rr rr             jmp *
000060r 1                   no_ccp:
000060r 1  43 6F 75 6C          .byte "Couldn't open CCP", 13, 10, 0
000064r 1  64 6E 27 74 
000068r 1  20 6F 70 65 
000074r 1                   zendif


Note that you don't have to rebuild these... the only bit you need to write to do a port is the BIOS. You can use the same BDOS and CCP binaries everywhere!


Okay, so if that's the listing file, it's not going to be very useful... sad but true. When I look an instruction like "sta ccp_fcb + fcb::ex", it's not clear to me what the operand is, as I don't know the syntax using :: for example. A full listing file would be helpful in getting these bits worked out. Also, I can't find any such directory ".obj/cc65/src" in my Ubuntu system... so perhaps I'm still missing something for the build?

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


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 2:13 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Just FYI, found the .obj directory... it's hidden by default. So, found the listing files as well.

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


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 3:27 am 
Offline

Joined: Mon Feb 15, 2021 2:11 am
Posts: 100
floobydust wrote:
Quote:
When I look an instruction like "sta ccp_fcb + fcb::ex", it's not clear to me what the operand is, as I don't know the syntax using :: for example.


The :: syntax is used by ca65 to denote structure fields/offsets. So with fcb::ex, there will be a structure named fcb defined somewhere that has a field ex. I'd guess it is the structure for a file control block. Likely ccp_fcp is the address of an instance of a file control block. I'd interpret that instruction as storing the accumulator into the ex field of a file control block located at ccp_fcp.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 5:00 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
hjalfi wrote:
Oh, I see! Well, the good news is that my build system is set up to generate listings automatically --- look in .obj/cc65/src. The bad news is that cc65 helpfully censors all the useful bits, so the end result looks like this:

Code:
000039r 1  A9 00            lda #0
00003Br 1  8D rr rr         sta ccp_fcb + fcb::ex
00003Er 1  8D rr rr         sta ccp_fcb + fcb::s2
000041r 1  8D rr rr         sta ccp_fcb + fcb::cr


That is because the assembler is generating a relocatable object file to be fed to the linker. No way for it to know what the final physical addresses will be.

Way back when I did a lot of programming with M80, I wrote a program to take the link map and update the listing with physical addresses. At least M80 was kind enough to put the offset from the base address of the module into the listing instead of "rr" which is very unhelpful.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 5:07 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
Proxy wrote:
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.

My understanding is that CP/M for the Z8000 as well as the later versions of CP/M-68K were written in C. The problem is that the result is probably too big to be acceptable in a 64K address space. The initial version of CP/M was written in PL/M, but it was rewritten in assembly language to get the size down.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 5:37 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
hjalfi wrote:
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.

I have given this some thought as well as watching the first of the videos.

I hope you are open to constructive criticism because I am about to give you some...

* You chose to dispense with the sector number translation table for dealing with sector interleaving on disk.

The only truly "standard" CP/M disk format is the 8" single-sided, single-density floppy disk with 128 bytes per sector. Sector interleaving is done via the number translation table instead of formatting them out of order. This was because some of the early systems were not able to format a diskette; those users were told to buy preformatted "IBM" media.

Without the translation table, you lose the ability to deal with virtual disk files in the "standard" format.

Try this: can you interchange files with CP/M-80 running on a C128 or a C64 cartridge? Or if there is a port to the Apple II in the future, with the CP/M Softcard? I do not know whether they are physically or logically interleaved, but why preclude the possibility?

* The 6809 is not compatible with the 6800 at the machine code level. The designers of FLEX for the 6809 made a sad mistake of reusing the .CMD file extension for executable files, condemning users with the likelihood of running programs on the "wrong" processor.

It is probably best to choose something other than .COM for CPM65 executables.

* To encourage new software for the system, it would be helpful to have written documentation about

- the memory map of the system.
- the BDOS calls and which registers are used.
- the BIOS calling convention.
- sample code not obscured by macros or assembler-specific directives for interfacing with the system. Not everyone is going to want or be able to use them.
- a hexadecimal dump of the binary of a small executable program to illustrate how the relocation tables work.


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

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 90
The reason for dispensing with the sector translation table is because that logic is more of a BIOS thing than a BDOS thing --- the BDOS shouldn't have to concern itself with tracks and sectors, merely using consecutive logical block numbers (which is what it's using internally anyway). If the BIOS wants a translation table it's perfectly welcome to implement one. Apart from anything else, assuming that every track has the same number of sectors isn't valid; consider the Commodore 1541, where tracks can have anything from 17 to 21 sectors (IIRC).

Re the .COM extension: there's actually a magic number in the header which can be checked for processor version (although currently it's not).

There is some very basic documentation at https://raw.githubusercontent.com/david ... c/NOTES.md, but yeah, it needs work.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 11:45 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
hjalfi wrote:
The reason for dispensing with the sector translation table is because that logic is more of a BIOS thing than a BDOS thing --- the BDOS shouldn't have to concern itself with tracks and sectors, merely using consecutive logical block numbers (which is what it's using internally anyway). If the BIOS wants a translation table it's perfectly welcome to implement one. Apart from anything else, assuming that every track has the same number of sectors isn't valid; consider the Commodore 1541, where tracks can have anything from 17 to 21 sectors (IIRC).

It has been too long since I have worked with a CP/M BIOS and cannot remember whether the sector number translation occurs with 128-byte logical sectors or potentially larger physical sectors. I will have to research this. Be sure to read section 6.12 of the CP/M 2 Alteration guide, especially the part about the contents of register C upon call to the WRITE subroutine and the deblocking algorithms in Appendix G. I also seem to recall a mention of a bug in the published sample code, but do not remember the details. An easier solution may have been to set the translation table to 1-to-1 and physically format interleaved sectors for other than the "standard" interchange format.

The question remains: can you handle a CP/M disk from a C128 or a C64 cartridge?

hjalfi wrote:
Re the .COM extension: there's actually a magic number in the header which can be checked for processor version (although currently it's not).

Several people are talking about 8080 simulation. It also matters to prevent mistaking a 6502 binary as a CP/M-80 one.

hjalfi wrote:
There is some very basic documentation at https://raw.githubusercontent.com/david ... c/NOTES.md, but yeah, it needs work.

Particular attention is needed to cover the differences between yours and the documented CP/M-80 interface.

I could not find any mention of the second FCB and it appears you do not appear to set aside 256 bytes for a PSP. Also, the default "DMA" address in CP/M-80 is 80h overwriting the command line buffer in the PSP.

The ideal would be to write your own document to cover the programming interface, but that would be a lot of work. Still, if you want to attract new software...


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

Joined: Thu Oct 12, 2017 10:51 pm
Posts: 90
BillG wrote:
The question remains: can you handle a CP/M disk from a C128 or a C64 cartridge?


I'm not really sure what you're trying to say here. Why wouldn't it be able to? The CP/M cartridge used a normal 1571 or 1581 disk drive, IIRC (I've never actually used one myself). Of course, you'd need to add support for the disk format in the BIOS as all I have support for is the 1541, but you'd need that anyway.


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 2:58 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
hjalfi wrote:
BillG wrote:
The question remains: can you handle a CP/M disk from a C128 or a C64 cartridge?


I'm not really sure what you're trying to say here. Why wouldn't it be able to? The CP/M cartridge used a normal 1571 or 1581 disk drive, IIRC (I've never actually used one myself). Of course, you'd need to add support for the disk format in the BIOS as all I have support for is the 1541, but you'd need that anyway.

CPM-80 was infamous for "no two systems share a compatible disk format." Well, it was not quite that bad, but it was close. Unless the disk parameter tables were identical, including the sector number translation, reliable interchange was not possible.

You are developing this using emulation, right? Try creating a CP/M-80 virtual disk in a C128 emulator and test whether file interchange works...


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 6:23 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
I am going to have to conclude that watching video of a system being built is not a recommended way to learn about it.

I am trying to watch pt 2 but keep drifting in and out. At around 3:07:11, I woke up screaming. On the screen was the following code:
Code:
    inc temp+2     ; advance pointer
    bcc :+
    inc temp+3
:

    dec temp+0     ; decrement count
    bcc :+
    dec temp+1
:

It is pretty commonly accepted on this forum that the way to increment and decrement 16-bit quantities are:
Code:
    inc temp+2     ; advance pointer
    bne :+
    inc temp+3
:

    lda temp+0     ; decrement count
    bne :+
    dec temp+1
:
    dec temp+0

You have obviously fixed this later, but I do not think I can make myself watch any more video...


Top
 Profile  
Reply with quote  
 Post subject: Re: CP/M for the 6502!
PostPosted: Sun Oct 09, 2022 7:16 pm 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
Actually, looking at the whole loop, I would rewrite
Code:
    ldy #0
zeroloop:
    tya
    sta (temp+2),y ; zero a byte

    inc temp+2     ; advance pointer
    bcc :+
    inc temp+3
:

    dec temp+0     ; decrement count
    bcc :+
    dec temp+1
:

    lda temp+0
    ora temp+1
    bne zeroloop  ; wait until count is zero

as
Code:
    ldy #0
    tya
    ldx temp+0
zeroloop:
    sta (temp+2),y ; zero a byte

    iny            ; advance pointer
    bne :+
    inc temp+3
:

    dex            ; decrement count
    bne zeroloop   ; wait until count is zero
    ldx temp+1
    beq exitloop
    dec temp+1
    ldx #0
    jmp zeroloop
exitloop:

assuming that register X need not be preserved.


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

All times are UTC


Who is online

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