BBC Basic COLOUR statement

handy tools that can assist in the development of new software
Post Reply
JackB
Posts: 19
Joined: Thu Aug 19, 2021 2:01 pm
Location: Netherlands
Contact:

BBC Basic COLOUR statement

Post by JackB »

I’ve got a question and I hope anyone can help me.
I have been building my own SBC with BBC Basic using a serial connection. I’ve written my own MOS and implemented flow control and interrupts for the ACIA so I can escape from Basic programs. It is all working perfect.

Now I’m looking at implementing changes to some BASIC statements. I wanted to start with the COLOUR statement, because ANSI escape codes support text and background colors. And thus that should work via a serial connection.
I found the COLOUR statement in the source code. It looks like this:

; COLOUR numeric
; ==============
L938E:
lda #$11 ; Stack VDU 17 for COLOUR
pha
jsr L8821 ; Evaluate integer, check end of statement
jsr L9857
jmp L93DA ; Jump to send two bytes to OSWRCH

I’ve been going back and forth through subroutines being called, trying to understand what is done here, and I partially do, but what I cannot find out is where the colour number is stored. I assume it is at some zeropage address? But which one?
(By colour number I mean the number behind the COLOUR statement. So for instance in COLOUR 130, where does the 130 end up?)
Anyone who can enlighten me?
Acorn Atom / Electron German Issue 1/BBC Model B issue 7 / BBC Model B German / BBC Model B issue 4 board without case/ Coco2 / Dragon64.
User avatar
sweh
Posts: 3326
Joined: Sat Mar 10, 2012 12:05 pm
Location: 07410 New Jersey
Contact:

Re: BBC Basic COLOUR statement

Post by sweh »

If you just emulate VDU 17 (and potentially 19 and 20?) then you don't need to worry about what BASIC is doing under the covers; it's not really relevant. All you need to do is handle VDU 17,x in OSWRCH and send the appropriate ANSI sequences.

This is the beauty of the Beeb's design; the MOS does the heavy lifting and the language just needs to call the MOS. So if you changed language (eg used COMAL or LISP) then _that_ language would also be sending VDU 17,x to change colour.
Rgds
Stephen
JackB
Posts: 19
Joined: Thu Aug 19, 2021 2:01 pm
Location: Netherlands
Contact:

Re: BBC Basic COLOUR statement

Post by JackB »

Thanks for the quick response. =D> I did not think it would be that simple :D
Acorn Atom / Electron German Issue 1/BBC Model B issue 7 / BBC Model B German / BBC Model B issue 4 board without case/ Coco2 / Dragon64.
User avatar
jgharston
Posts: 5355
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: BBC Basic COLOUR statement

Post by jgharston »

COLOUR purely and simply sends VDU 17,n to OSWRCH, and NOTHING ELSE. It is *ENTIRELY* the job of the VDU drivers to decide what to do with that VDU sequence and ***NO*** business of any foreground application to impose any interpretation, expectation, or limitation on it. Evaluate the parameter. Send it to the VDU driver. FULL STOP.

See https://mdfs.net/Software/BBCBasic/Test ... g/VDUSpecs

See also:
Translating VDU sequences into ANSI sequences: https://mdfs.net/Software/BBCBasic/Testing/VDU/ANSI
Sample code: ansi.mac, console.c
Testing correct functioning of a VDU driver: https://mdfs.net/Software/BBCBasic/Testing/

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
jgharston
Posts: 5355
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: BBC Basic COLOUR statement

Post by jgharston »

Also, in general, you ***NEVER*** port BBC BASIC (View, Wordwise, Edit, Pascal, C, COMOL.....). You port the *MOS*. Provide the API that BASIC calls. All and every part of the I/O is the responsibility of the I/O, *NOT* the language.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
JackB
Posts: 19
Joined: Thu Aug 19, 2021 2:01 pm
Location: Netherlands
Contact:

Re: BBC Basic COLOUR statement

Post by JackB »

Just to show you the result :D
COLOUR.png
Acorn Atom / Electron German Issue 1/BBC Model B issue 7 / BBC Model B German / BBC Model B issue 4 board without case/ Coco2 / Dragon64.
User avatar
sweh
Posts: 3326
Joined: Sat Mar 10, 2012 12:05 pm
Location: 07410 New Jersey
Contact:

Re: BBC Basic COLOUR statement

Post by sweh »

Nice. The same idea applies to many things, so if you ever wanted to do graphics emulation (eg via a tektronics terminal) then the PLOT, DRAW, GCOL etc etc are also VDU codes. If you added sound capabilities to the machine then SOUND, ENVELOPE are OSWORD calls. You just need to know what MOS call BASIC is making, you don't need to know what BASIC is doing under the covers.
Rgds
Stephen
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BBC Basic COLOUR statement

Post by SteveF »

Looks good! An easy next step might be to allow setting the background colour with COLOUR 128+n - I haven't checked, but I think there are ANSI escape sequences for that too.
User avatar
jgharston
Posts: 5355
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: BBC Basic COLOUR statement

Post by jgharston »

JackB wrote: Thu May 09, 2024 11:13 am Just to show you the result :D
COLOUR.png
YAY! Similarly:
Image
SteveF wrote: Thu May 09, 2024 6:19 pm Looks good! An easy next step might be to allow setting the background colour with COLOUR 128+n - I haven't checked, but I think there are ANSI escape sequences for that too.
<esc>[<40+n>m
See the references: https://mdfs.net/Docs/Comp/Comms/ANSI.htm

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
jgharston
Posts: 5355
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: BBC Basic COLOUR statement

Post by jgharston »

and... youtube :)

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
JackB
Posts: 19
Joined: Thu Aug 19, 2021 2:01 pm
Location: Netherlands
Contact:

Re: BBC Basic COLOUR statement

Post by JackB »

Just saw your reply. I was already working on that. :D
Schermafbeelding 2024-05-10 141058.png
Acorn Atom / Electron German Issue 1/BBC Model B issue 7 / BBC Model B German / BBC Model B issue 4 board without case/ Coco2 / Dragon64.
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BBC Basic COLOUR statement

Post by SteveF »

Very nice! Do you fancy getting into the nightmare world of supporting CLS clearing to background colour? :-)
JackB
Posts: 19
Joined: Thu Aug 19, 2021 2:01 pm
Location: Netherlands
Contact:

Re: BBC Basic COLOUR statement

Post by JackB »

That already works. Didn't have to do anything for that :D
Schermafbeelding 2024-05-10 185817.png
Acorn Atom / Electron German Issue 1/BBC Model B issue 7 / BBC Model B German / BBC Model B issue 4 board without case/ Coco2 / Dragon64.
james
Posts: 348
Joined: Tue Aug 15, 2023 8:41 pm
Location: NE Hampshire
Contact:

Re: BBC Basic COLOUR statement

Post by james »

FWIW, the Master Reference Manual Part 2 https://www.stardot.org.uk/forums/viewtopic.php?t=20466 documents “How BASIC uses the MOS and filing systems” in section N.5
SteveF
Posts: 1697
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: BBC Basic COLOUR statement

Post by SteveF »

JackB wrote: Fri May 10, 2024 5:58 pm That already works. Didn't have to do anything for that :D
Wow! I thought that would be really hard, but it's a long time since I played with ANSI colour codes.
User avatar
lovebug
Posts: 1763
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: BBC Basic COLOUR statement

Post by lovebug »

nice work there, well done :+1:
Image Image Image Image
JackB
Posts: 19
Joined: Thu Aug 19, 2021 2:01 pm
Location: Netherlands
Contact:

Re: BBC Basic COLOUR statement

Post by JackB »

james wrote: Fri May 10, 2024 6:20 pm FWIW, the Master Reference Manual Part 2 https://www.stardot.org.uk/forums/viewtopic.php?t=20466 documents “How BASIC uses the MOS and filing systems” in section N.5
For anyone looking for the answer to my orginal question. From the mentioned section:
COLOUR
This calls OSWRCH with A first set to 17 (define text colour VDU command)
then with A set to the value given after COLOUR.
Acorn Atom / Electron German Issue 1/BBC Model B issue 7 / BBC Model B German / BBC Model B issue 4 board without case/ Coco2 / Dragon64.
Post Reply

Return to “development tools”