• Please review our updated Terms and Rules here

Help customising BBC BASIC in CP/M 2.2 (Z80)?

nockieboy

Experienced Member
Joined
May 12, 2017
Messages
261
Location
UK - Kent
I've got my custom video card (prototype) working nicely with my DIY Z80 computer now, and I thought I'd tweak the copy of BBC BASIC that I have in CP/M so that it can clear the screen, position the cursor etc. using the (included in the BBC BASIC distribution) BBCDIST.MAC file to use my system's specific clear screen / cursor positioning routines.

Problem is, I'm unsure of what to do next. I guess I need to compile the BBCDIST.MAC file somehow, but I don't have the BBCBASIC source to link it to and I'm really not sure where to go from here. The documentation on R.T.Russell's website doesn't define any process for customising BBC BASIC, other than mentioning that it can be done.

Does anyone with more experience and knowledge of CP/M have any light they can shine on what I should do next? Or should I contact the creator of BBC BASIC to ask?

Thanks.
 
Have you thought of doing a manual patch on the BBC BASIC .COM file - this might be easier? If you know the codes you need to replace, you could find them in the .COM, and edit the binary file. This will be practical ONLY if the codes are the same size, or of there's some free space in the code in the current file.

With BASIC, it's so easy to create your own CLS (etc) functions, does it need to be hardwired for a specific terminal. I think I have the BBC BASIC files here, I'll have a look, but I don't think I've got something per-set for my terminal (Amstard PCW, or H19 I think). Things like WordStar, for example, have an INSTALL process which allows setting various terminal codes into a space at the top of the .COM, and there's spare bytes for the various code $ sizes that might be needed.

Geoff
 
Not to worry - I've had a reply from Richard Russell himself, who can't remember enough about Z80 assembly or the build process to tell me how to use the configuration patch (his own words), so perhaps I shouldn't be so hard on my own failing memory. ;)

He did point out, however, that the source code for the Z80 BBC BASIC is available from here, so I should be able to just make the changes I need to the source and rebuild from scratch. Off to give it a go. :)
 
So, from looking at the source for patch.z80 I have deduced that the ‘customisation’ occupies the first 256 bytes of the executable BBCBASIC from $0100 to $01FF (noting that some of these locations are reserved).

By ‘tweaking’, reassembling patch.z80 and overlaying the first 100h bytes of the executable should give you your customisation.

I assume (due to the limitation of < 256 bytes) that this customisation code would contain jumps or calls to either external ROM code or loadable library software to implement the desired additional functionality.

Dave
 
So, from looking at the source for patch.z80 I have deduced that the ‘customisation’ occupies the first 256 bytes of the executable BBCBASIC from $0100 to $01FF (noting that some of these locations are reserved).

By ‘tweaking’, reassembling patch.z80 and overlaying the first 100h bytes of the executable should give you your customisation.

I assume (due to the limitation of < 256 bytes) that this customisation code would contain jumps or calls to either external ROM code or loadable library software to implement the desired additional functionality.

Dave

Yes indeed - the first 256 bytes have some space for custom code, but you mustn't exceed 01F4H where some settings are stored before the main code starts at 0200H. Now I've got the source code, I'm just trying to convert it over to assemble with TASM (rightly or wrongly, my go-to assembler) as it'll probably take me longer to learn how to do it the other way. :( Once that's done, however, I might even be able to implement the draw commands for my video display at some point in the future.
 
Okay, I'm nearly there with the conversion from ZMAC assembly to TASM-friendly assembly code. I've just hit the final set of assembly errors and cannot work out how to translate the offending directives to something TASM will understand.

The BBC BASIC assembly constitutes a number of sub-assemblies for various functions, the main code residing in main.z80. It would appear the sub-assemblies are meant to be linked (using ZMAC? I have no experience with this software and am not THAT experienced with assembly in any case) and have references to various labels in other assemblies etc. as you'd expect. This is all fine. The problem I have is that in the source code, there are a number of - directives, I suppose - that are just simply the word PAGE.

Annoyingly I can find no help on the PAGE directive in the ZMAC manual online that I'm using.

If I were to guess at its function, I would imagine the code immediately following the PAGE directive would be aligned to the nearest memory page?

But then the code actually references PAGE is if it were a label?! I'm really at a loss as to how it functions. I've included the main source for the BBC BASIC program below. In summary:

1) Line 76 lists PAGE as an external reference EDIT: This is fine - it's declared in other sub-assembly
2) Lines 158, 848, 900, 995, 1025, 1154, 1172, 1198, 1354 and 1382 use PAGE as a label/address EDIT: These are fine - they're referencing the label in a sub-assembly
3) But PAGE crops up as if it's a directive on lines 274, 698 and 1075

I even considered if the PAGE occurrences in 3) above were the result of OCR typos from scanning the code from a printed source, but the code is from the website I linked in an earlier post and is in use in the cpmish distribution.

It also crops up in the sub-assemblies too.

Can anyone put me out of my misery and explain what's going on with PAGE please?

View attachment main.z80.txt

EDIT: Clarification - ignore the comments about using PAGE as a label - there's actually an external declaration for PAGE in another sub-assembly, it points to a single word in memory which stores the address of the start of the user's program. Doesn't explain the directive-like occurrences (item 3 in the list above) though...?
 
Last edited:
i think its an error in translation... page is used as a routine name but also an assembly directive.
it cant be both. I would comment out all lines with only page on them (directive)
if it still complains (page might be a reserved word) change "page" to some other name except in the keyword lookup table.

joe
 
It's possible there are two separate usages of PAGE.

One is a WORD memory location as in "LD HL,(PAGE)".

The other is a MACRO to align the assembly location pointer to a page boundary (256 bytes).

The other time I have come across PAGE is to throw a new page in the assembler listing file.

For it to be a MACRO, it is either inherent within the assembler itself (in which case it should be documented) or it is defined by the user and should appear as part of their source code or include files.

It is a bit naughty to have two things identified the same, but two different usages though.

Dave
 
In case it's any use, I found the BBC BASIC that I have, with a config file BBCDISI.MAC to handle all the screen/clock commands. Again, no clear indic as to the 'proper' way of doing it, but if you change the code as required, compile it, and then overlay the block in the full prog - would that not do the trick?

The version I have is set up for VT100 type codes, i.e. CLS is ESC + '[2J'.

Geoff
 
In case it's any use, I found the BBC BASIC that I have, with a config file BBCDISI.MAC to handle all the screen/clock commands. Again, no clear indic as to the 'proper' way of doing it, but if you change the code as required, compile it, and then overlay the block in the full prog - would that not do the trick?

The version I have is set up for VT100 type codes, i.e. CLS is ESC + '[2J'.

Geoff

Thanks Geoff, that's exactly what I'd tried originally - however, as you've pointed out, the only way to incorporate the newly-assembled BBCDIST.MAC file is just to overwrite the first 100h bytes of the BBCBASIC.COM file with the new binary. I just edited in the new keycodes and PUTCSR routine using a hex editor in the end.

I was hoping to be able to get the BBCBASIC source working so that I could make a few more alterations than the initial 100 bytes 'config' area allows (like graphics routines for my video display etc), but the cpmish repository that (presumably) houses a buildable version of the BBCBASIC source as part of the bigger package is all but impossible for me to build (and I've tried).

Problem is, I have a deep-rooted dislike of Linux and I am unable to build cpmish in my Ubuntu VM because of the usual string of broken dependencies and extra packages that Linux requires to do the most basic of activities that Windows does with one click... :mad: I thought a good OS was supposed to be transparent to the user

Anyway, I've probably alienated myself from most of you now with my Linux rant. ;) Sorry about that.

I'll try contacting the owner of the cpmish project to find out if they're willing to explain how I can build the project and maybe even just build the part I'm interested in, the BBCBASIC file, from the source files. I've managed to get the 'converted' source files to build with TASM, but it's not working properly and just throws the 'Mistake' error every time I enter a command.
 
I'll try contacting the owner of the cpmish project to find out if they're willing to explain how I can build the project and maybe even just build the part I'm interested in, the BBCBASIC file, from the source files. I've managed to get the 'converted' source files to build with TASM, but it's not working properly and just throws the 'Mistake' error every time I enter a command.

a bit late maybe but you do know BBC basic only accepts UPPER case commands ?
 
a bit late maybe but you do know BBC basic only accepts UPPER case commands ?

Oh yes, I'd worked that out years ago. ;)

I sorted the problem in the end - managed to get the cpmish source to assemble after a lot of playing around - so I'm happy now. As soon as I finish the hardware graphics engine in my FPGA I'll be able to add a few drawing commands to BBCBASIC, hopefully!
 
Oh yes, I'd worked that out years ago. ;)

I sorted the problem in the end - managed to get the cpmish source to assemble after a lot of playing around - so I'm happy now. As soon as I finish the hardware graphics engine in my FPGA I'll be able to add a few drawing commands to BBCBASIC, hopefully!

With the VDU subsystem this is relatively easy to do, for my Z80 with (8 bit ISA) VGA card project I did some graphics primitives too. Ported the CP/M BBC basic (I think it was 2.0) to 'native' mode. I wanted to add a complete CP/M system later to it but lost interest. :)

Now I am fiddling with the Amstrad NC200 and David's cpm-ish, trying to add some features like UART support (almost working, data gets corrupted sometimes), screen backlight timer (working), multiple partitions on the CF card (work in progress) etc.
Later on if the 'environment' is stable I will also add some graphics stuff to the cpm-ish version of BBC basic.
 
Wow that's really good work. Love the case for the Z80 computer! :D

I'd thought about trying to get hold of an old 8-bit ISA graphics card to do the video output for my system, but I can't seem to get hold of one for reasonable money these days, so I went the FPGA route as it provides a lot of versatility and I was able to do the PS/2 port and audio as well from the same chip. Hell of a learning curve, though, and I needed (and am still making use of) lots of help via the forums to get it done.
 
Back
Top