BBC Basic COLOUR statement
BBC Basic COLOUR statement
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?
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.
Re: BBC Basic COLOUR statement
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.
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
Stephen
Re: BBC Basic COLOUR statement
Thanks for the quick response. I did not think it would be that simple
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.
Re: BBC Basic COLOUR statement
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/
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
>_
Re: BBC Basic COLOUR statement
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
>_
Re: BBC Basic COLOUR statement
Just to show you the result
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.
Re: BBC Basic COLOUR statement
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
Stephen
Re: BBC Basic COLOUR statement
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.
Re: BBC Basic COLOUR statement
Code: Select all
$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
Re: BBC Basic COLOUR statement
and... youtube
Code: Select all
$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
Re: BBC Basic COLOUR statement
Just saw your reply. I was already working on that.
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.
Re: BBC Basic COLOUR statement
Very nice! Do you fancy getting into the nightmare world of supporting CLS clearing to background colour?
Re: BBC Basic COLOUR statement
That already works. Didn't have to do anything for that
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.
Re: BBC Basic COLOUR statement
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
Re: BBC Basic COLOUR statement
For anyone looking for the answer to my orginal question. From the mentioned section: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
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.