Matrix Brandy BASIC VI for console and SDL1.2: V1.22.7 released

for discussion of bbc basic for windows/sdl, brandy and more
User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Tue Mar 24, 2020 10:17 am

This is possibly a silly question, but can the MODE 7 font be used in any other mode? My thinking is that because it's not tied to hardware, as it was in the BBC Micro, but is just another bitmapped font (albeit, at 16x20, a higher resolution than most) it ought to be possible to use it in any MODE with sufficient resolution, and not be restricted to teletext colour attributes and graphics.

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Tue Mar 24, 2020 3:00 pm

Richard Russell wrote:
Tue Mar 24, 2020 10:17 am
This is possibly a silly question, but can the MODE 7 font be used in any other mode? My thinking is that because it's not tied to hardware, as it was in the BBC Micro, but is just another bitmapped font (albeit, at 16x20, a higher resolution than most) it ought to be possible to use it in any MODE with sufficient resolution, and not be restricted to teletext colour attributes and graphics.
Currently, it's tied to MODE 7 due to the way the code is written. In all other modes, a character is assumed to be 8x8, and line spacing 8 (except MODEs 3, 6, 11, 14 and 17 where line spacing is 10).
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Wed Mar 25, 2020 9:12 am

Soruk wrote:
Tue Mar 24, 2020 3:00 pm
Currently, it's tied to MODE 7 due to the way the code is written. In all other modes, a character is assumed to be 8x8
OK, understood. In ARM BASIC running on RISC OS there must surely be a way of achieving higher-quality VDU 5 text in a graphics mode, for example if one was trying to write a GUI from scratch and wanted to label a button or something. Or am I wrong?

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Wed Mar 25, 2020 9:33 am

Richard Russell wrote:
Wed Mar 25, 2020 9:12 am
Soruk wrote:
Tue Mar 24, 2020 3:00 pm
Currently, it's tied to MODE 7 due to the way the code is written. In all other modes, a character is assumed to be 8x8
OK, understood. In ARM BASIC running on RISC OS there must surely be a way of achieving higher-quality VDU 5 text in a graphics mode, for example if one was trying to write a GUI from scratch and wanted to label a button or something. Or am I wrong?
The FontManager modules can do this, it's completely separate from the BBC-style text plotting.
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Wed Mar 25, 2020 10:18 am

Soruk wrote:
Wed Mar 25, 2020 9:33 am
The FontManager modules can do this, it's completely separate from the BBC-style text plotting.
I see, I'm entirely unfamiliar with that. Is there anything comparable available when using Matrix Brandy on Windows (or Linux for that matter)? Could I use the SYS statement to access an API function that would do something similar?

When I wanted to support scalable (e.g. TTF) fonts in my BASICs I just went for an extension of the VDU 5 (print text at graphics cursor) mechanism as that seemed the simplest approach. I miss it in Brandy!

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 12, 2020 10:38 am

Richard Russell wrote:
Wed Mar 25, 2020 10:18 am
Soruk wrote:
Wed Mar 25, 2020 9:33 am
The FontManager modules can do this, it's completely separate from the BBC-style text plotting.
I see, I'm entirely unfamiliar with that. Is there anything comparable available when using Matrix Brandy on Windows (or Linux for that matter)? Could I use the SYS statement to access an API function that would do something similar?

When I wanted to support scalable (e.g. TTF) fonts in my BASICs I just went for an extension of the VDU 5 (print text at graphics cursor) mechanism as that seemed the simplest approach. I miss it in Brandy!
At this stage, probably not. Someone with more advanced programming skills than me (not difficult!) could possibly use the new dlopen interface to load SDL_ttf and talk to it that way. But it seems rather messy, in due course after I've had a chance to make friends with the RISC OS FontManager interface (RPCEmu FTW!) I would look to re-implement that interface in Matrix Brandy, insofar as it makes sense for programming in BASIC.

(For example, there is a SYS call that sends the zero terminated string immediately following it to the VDU interface. It makes sense in machine code but when called from BASIC, it sends a snippet of the BASIC ROM code! So, I've opted to not implement that call at all, whereas most of the other SYS calls that send bytes or strings to the VDU interface are implemented.)
Matrix Brandy BASIC VI (work in progress)

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Fri Apr 24, 2020 10:28 am

Soruk wrote:
Tue Mar 24, 2020 3:00 pm
Richard Russell wrote:
Tue Mar 24, 2020 10:17 am
This is possibly a silly question, but can the MODE 7 font be used in any other mode? My thinking is that because it's not tied to hardware, as it was in the BBC Micro, but is just another bitmapped font (albeit, at 16x20, a higher resolution than most) it ought to be possible to use it in any MODE with sufficient resolution, and not be restricted to teletext colour attributes and graphics.
Currently, it's tied to MODE 7 due to the way the code is written. In all other modes, a character is assumed to be 8x8, and line spacing 8 (except MODEs 3, 6, 11, 14 and 17 where line spacing is 10).
I've implemented an analogue of OSWORD &0A for the teletext font, as OSWORD &79. It's one that, from what I can find, has never been assigned (and next to &7A which is Teletext related). It requires a block of 41 bytes, ?block%% is the character in question, and ?(block%%+1) to ?(block%%+40) is the character definition. Also, I've slightly redesigned the * character so it's more in keeping with the SAA5050 design. I never did like the RISC OS 5 teletext * shape.
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Fri Apr 24, 2020 12:41 pm

Soruk wrote:
Fri Apr 24, 2020 10:28 am
?block%% is the character in question
Am I right in assuming that only values up to 127 are meaningful?
I've slightly redesigned the * character so it's more in keeping with the SAA5050 design
Generally I used the Bedstead-extended font as a reference, which is based very closely on the SAA5050 ('quarter-dot' character rounding added, and then horizontally stretched by a 4/3 ratio I think).

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Fri Apr 24, 2020 12:47 pm

Richard Russell wrote:
Fri Apr 24, 2020 12:41 pm
Soruk wrote:
Fri Apr 24, 2020 10:28 am
?block%% is the character in question
Am I right in assuming that only values up to 127 are meaningful?
I've slightly redesigned the * character so it's more in keeping with the SAA5050 design
Generally I used the Bedstead-extended font as a reference, which is based very closely on the SAA5050 ('quarter-dot' character rounding added, and then horizontally stretched by a 4/3 ratio I think).
With my redesigned * character, yours and mine now look practically identical. As for valid characters, it's ANDed with &7F so &AA will give the same as &2A (*). However, unlike the display, the shuffle of characters when the high bit is set is NOT done.
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Fri Apr 24, 2020 2:08 pm

Soruk wrote:
Fri Apr 24, 2020 12:47 pm
However, unlike the display, the shuffle of characters when the high bit is set is NOT done.
Of course on the BBC Micro (etc.) the 'shuffle' happens when the high bit is not set (setting it gives you the native SAA5050 characters unshuffled).

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Fri Apr 24, 2020 2:17 pm

Richard Russell wrote:
Fri Apr 24, 2020 2:08 pm
Soruk wrote:
Fri Apr 24, 2020 12:47 pm
However, unlike the display, the shuffle of characters when the high bit is set is NOT done.
Of course on the BBC Micro (etc.) the 'shuffle' happens when the high bit is not set (setting it gives you the native SAA5050 characters unshuffled).
Quite probably, I shuffle with the high bit because the character symbols are stored in the order they're displayed at 32-127 (127 only displayed with 255).
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Fri Apr 24, 2020 3:48 pm

Soruk wrote:
Fri Apr 24, 2020 2:17 pm
I shuffle with the high bit because the character symbols are stored in the order they're displayed at 32-127 (127 only displayed with 255).
That's what I guessed. It does mean that the character set you store doesn't correspond to any standard: it's not teletext/videotex (because you've shuffled £, # and _) and it's not ASCII/ANSI (because of having fractions, divide symbol etc.). It's only now that you've exposed it with the new OSWORD that it matters (previously it was internal implementation detail hidden from the user).

For the record my internal 16x20 character set is ANSI/CP1252 but that's because it can be used in MODEs other than 7. There are quite a few substitutions necessary in MODE 7 to get the expected characters (some of which are stored in unused locations within the 0x80-0x9F block). So for example if you wanted to redefine the upwards-pointing arrow character in MODE 7 (which you might expect to be 0x5E) the character you'd actually have to change is 0x8D!

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sat Apr 25, 2020 11:43 am

Richard Russell wrote:
Fri Apr 24, 2020 3:48 pm
Soruk wrote:
Fri Apr 24, 2020 2:17 pm
I shuffle with the high bit because the character symbols are stored in the order they're displayed at 32-127 (127 only displayed with 255).
That's what I guessed. It does mean that the character set you store doesn't correspond to any standard: it's not teletext/videotex (because you've shuffled £, # and _) and it's not ASCII/ANSI (because of having fractions, divide symbol etc.). It's only now that you've exposed it with the new OSWORD that it matters (previously it was internal implementation detail hidden from the user).

For the record my internal 16x20 character set is ANSI/CP1252 but that's because it can be used in MODEs other than 7. There are quite a few substitutions necessary in MODE 7 to get the expected characters (some of which are stored in unused locations within the 0x80-0x9F block). So for example if you wanted to redefine the upwards-pointing arrow character in MODE 7 (which you might expect to be 0x5E) the character you'd actually have to change is 0x8D!
OK - small change (and rebuilt the nightlies for today), the shuffle is now taken into account, so the character map returned is exactly what is shown for a given code in text mode. It doesn't return graphics but those are easy enough to calculate should a program need them. (Indeed, Brandy uses a function to generate them, it doesn't store them as bitmaps.)
Matrix Brandy BASIC VI (work in progress)

User avatar
bakoulis
Posts: 342
Joined: Wed Feb 08, 2012 9:45 pm
Location: Athens, Greece
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by bakoulis » Sat Apr 25, 2020 4:47 pm

last build gives 1 warning on compilation.

Code: Select all

$ make
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/evaluate.c -c -o src/evaluate.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/graphsdl.c -c -o src/graphsdl.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/assign.c -c -o src/assign.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/mainstate.c -c -o src/mainstate.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/tokens.c -c -o src/tokens.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/mos.c -c -o src/mos.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/commands.c -c -o src/commands.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/functions.c -c -o src/functions.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/iostate.c -c -o src/iostate.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/variables.c -c -o src/variables.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/fileio.c -c -o src/fileio.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/soundsdl.c -c -o src/soundsdl.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/keyboard.c -c -o src/keyboard.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/miscprocs.c -c -o src/miscprocs.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/editor.c -c -o src/editor.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/stack.c -c -o src/stack.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/mos_sys.c -c -o src/mos_sys.o
src/mos_sys.c: In function ‘mos_sys_ext’:
src/mos_sys.c:501:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(outstring, 65534, file_handle);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/strings.c -c -o src/strings.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/lvalue.c -c -o src/lvalue.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/errors.c -c -o src/errors.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/convert.c -c -o src/convert.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/brandy.c -c -o src/brandy.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/statement.c -c -o src/statement.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/net.c -c -o src/net.o
gcc -O3 -I/usr/include/SDL -DUSE_SDL -DDEFAULT_IGNORE -Wall   src/heap.c -c -o src/heap.o
gcc  -o brandy src/evaluate.o src/graphsdl.o src/assign.o src/mainstate.o src/tokens.o src/mos.o src/commands.o src/functions.o src/iostate.o src/variables.o src/fileio.o src/soundsdl.o src/keyboard.o src/miscprocs.o src/editor.o src/stack.o src/mos_sys.o src/strings.o src/lvalue.o src/errors.o src/convert.o src/brandy.o src/statement.o src/net.o src/heap.o -lX11 -lm -lSDL -ldl
Ubuntu 19.3 64bit
2xElectron, 3xBBC B, BBC Master.
2xAcorn A310, A420/1, 2xA3000, 2xA3010, A3020, A4000, A5000.
2xRISC PC, Acorn Pocket Book, Acorn Pocket Book II.

scruss
Posts: 262
Joined: Sun Jul 01, 2018 4:12 pm
Location: Toronto
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by scruss » Sat Apr 25, 2020 8:53 pm

That warning's been there for as long as I can remember. It is the only use of fgets in the whole system that doesn't assign or check fgets()' return value, though.

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sat Apr 25, 2020 9:45 pm

I've checked in a change that will hopefully deal with this. None of my machines have that particular compiler version, so I have never seen that warning.
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Sat Apr 25, 2020 10:00 pm

Soruk wrote:
Sat Apr 25, 2020 9:45 pm
None of my machines have that particular compiler, so I have never seen that warning.
What's your take on the use of -O3 for everything, as that script shows? I more commonly use -O2 or -Os (or -Oz with clang) since -O3 seems to cause bloat, I presume because of inlining, with negligible if any benefit in speed.

User avatar
jgharston
Posts: 4039
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by jgharston » Sun Apr 26, 2020 12:54 am

Soruk wrote:
Fri Apr 24, 2020 10:28 am
I've implemented an analogue of OSWORD &0A for the teletext font, as OSWORD &79. It's one that, from what I can find, has never been assigned (and next to &7A which is Teletext related). It requires a block of 41 bytes...
If it needs a 41-byte control block then it must must must must must be OSWORD >&7F. OSWORD calls &15-&7F are defined to have a 16-byte control block, OSWORDs &80+ specify the control block length in the first two bytes of the control block.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

User avatar
jgharston
Posts: 4039
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by jgharston » Sun Apr 26, 2020 12:58 am

Soruk wrote:
Fri Apr 24, 2020 2:17 pm
Richard Russell wrote:
Fri Apr 24, 2020 2:08 pm
Soruk wrote:
Fri Apr 24, 2020 12:47 pm
However, unlike the display, the shuffle of characters when the high bit is set is NOT done.
Of course on the BBC Micro (etc.) the 'shuffle' happens when the high bit is not set (setting it gives you the native SAA5050 characters unshuffled).
Quite probably, I shuffle with the high bit because the character symbols are stored in the order they're displayed at 32-127 (127 only displayed with 255).
Calling for character=&23 should give the pattern for the hash symbol. Calling for character=&A3 should give the pattern for the pound symbol. Similarly for &5F/&DF underline/hash, &60/&E0 pound/underline.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Sun Apr 26, 2020 10:23 am

jgharston wrote:
Sun Apr 26, 2020 12:54 am
If it needs a 41-byte control block then it must must must must must be OSWORD >&7F.
Good catch! Not that Matrix Brandy is ever likely to be accessed via the Tube, but your point is well made.
Similarly for &5F/&DF underline/hash, &60/&E0 pound/underline.
The 16x20 character set isn't inherently limited to 128 characters (it happens to be currently in Matrix Brandy but it's a full 256 characters in BBCSDL) so I would be loathe to specify the new OSWORD in such a way that the upper half can never be accessed. For example in my case &5F is indeed the underscore but &DF is the Eszett (ß) and &E0 is lowercase a-grave (à).

If the new OSWORD provides a way to read the character patterns, should there not also be a way to redefine them (analogous with VDU 23)? Perhaps a pair of new OSWORDs could be defined: one to read and one to write?

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 26, 2020 10:40 am

jgharston wrote:
Sun Apr 26, 2020 12:58 am
Soruk wrote:
Fri Apr 24, 2020 2:17 pm
Richard Russell wrote:
Fri Apr 24, 2020 2:08 pm

Of course on the BBC Micro (etc.) the 'shuffle' happens when the high bit is not set (setting it gives you the native SAA5050 characters unshuffled).
Quite probably, I shuffle with the high bit because the character symbols are stored in the order they're displayed at 32-127 (127 only displayed with 255).
Calling for character=&23 should give the pattern for the hash symbol. Calling for character=&A3 should give the pattern for the pound symbol. Similarly for &5F/&DF underline/hash, &60/&E0 pound/underline.
And after my check-in yesterday, this is exactly what happens.
Matrix Brandy BASIC VI (work in progress)

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 26, 2020 11:18 am

jgharston wrote:
Sun Apr 26, 2020 12:54 am
Soruk wrote:
Fri Apr 24, 2020 10:28 am
I've implemented an analogue of OSWORD &0A for the teletext font, as OSWORD &79. It's one that, from what I can find, has never been assigned (and next to &7A which is Teletext related). It requires a block of 41 bytes...
If it needs a 41-byte control block then it must must must must must be OSWORD >&7F. OSWORD calls &15-&7F are defined to have a 16-byte control block, OSWORDs &80+ specify the control block length in the first two bytes of the control block.
Moved to &8B (139). ?block% and ?(block%+1) are the size, minimum 43, if too small the call returns doing nothing. ?(block%+2) is the character, and the data is in ?(block%+3) to ?(block%+42).
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Sun Apr 26, 2020 11:20 am

Richard Russell wrote:
Sun Apr 26, 2020 10:23 am
Perhaps a pair of new OSWORDs could be defined: one to read and one to write?
As they follow consecutively from 'Read teletext pixel' and 'Set teletext pixel' how about &8B for 'read 16x20 character' and &8C for 'redefine 16x20 character'? Both would take a 43-byte block (send length, receive length, character code, 40 bytes of bitmap).

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 26, 2020 11:51 am

Richard Russell wrote:
Sun Apr 26, 2020 11:20 am
Richard Russell wrote:
Sun Apr 26, 2020 10:23 am
Perhaps a pair of new OSWORDs could be defined: one to read and one to write?
As they follow consecutively from 'Read teletext pixel' and 'Set teletext pixel' how about &8B for 'read 16x20 character' and &8C for 'redefine 16x20 character'? Both would take a 43-byte block (send length, receive length, character code, 40 bytes of bitmap).
There's an idea (but unlikely I'll do that today), and I could extend OSBYTE 20 and 25 to reset the font to the defaults. As Matrix Brandy has a 16x20 font and a 12x20 SAA5050 font (drawn with square pixels, so it's a little narrow), this OSWORD only looks at the 16x20 version The 12x20 font is selectable and that is then returned via this OSWORD call.

Here's a silly demo of OSWORD &8B in use....

Code: Select all

   10REM Use MODE 12 for a double-height effect
   20MODE 20
   30DIM b%% 41
   40OFF
   50COLOUR 1:PROCvtxstring("Red")
   60COLOUR 2:PROCvtxstring("Green")
   70COLOUR 3:PROCvtxstring("Yellow")
   80COLOUR 4:PROCvtxstring("Blue")
   90COLOUR 5:PROCvtxstring("Magenta")
  100COLOUR 6:PROCvtxstring("Cyan")
  110COLOUR 7:PROCvtxstring("White")
  120PRINT:PRINT:PRINT
  130ON
  140END
  150:
  160DEFPROCletter(c%)
  170?b%%=3
  180?(b%%+1)=43
  190?(b%%+2)=c%
  200SYS "OS_Word", 139, b%%
  210VDU23,224
  220FOR x%=1 TO 16 STEP 2: VDU?(b%%+x%+2): NEXT
  230VDU23,225
  240FOR x%=1 TO 16 STEP 2: VDU?(b%%+x%+3): NEXT
  250VDU23,226
  260FOR x%=17 TO 32 STEP 2: VDU?(b%%+x%+2): NEXT
  270VDU23,227
  280FOR x%=17 TO 32 STEP 2: VDU?(b%%+x%+3): NEXT
  290VDU23,228
  300FOR x%=33 TO 40 STEP 2: VDU?(b%%+x%+2): NEXT:VDU0,0,0,0
  310VDU23,229
  320FOR x%=33 TO 40 STEP 2: VDU?(b%%+x%+3): NEXT:VDU0,0,0,0
  330VDU224,225,10,8,8
  340VDU226,227,10,8,8
  350VDU228,229,11,11
  360ENDPROC
  370:
  380DEFPROCvtxstring(s$)
  390LOCAL c%, p%
  400FOR p%=1 TO LEN(s$)
  410c%=ASC(MID$(s$,p%,1))
  420PROCletter(c%)
  430NEXT
  440ENDPROC
Edit: OSWORD was mis-implemented. Fixed.
Last edited by Soruk on Sun Apr 26, 2020 12:58 pm, edited 1 time in total.
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Sun Apr 26, 2020 12:43 pm

Soruk wrote:
Sun Apr 26, 2020 11:18 am
Moved to &8B (139). ?block% and ?(block%+1) are the size, minimum 43
As it's receiving data, shouldn't block%?0 = 3 and block%?1 = 43? If you set block%?0 = 43 and block%?1 = 0 the Tube will (uselessly) send 43 bytes and receive nothing!

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 26, 2020 12:54 pm

Richard Russell wrote:
Sun Apr 26, 2020 12:43 pm
Soruk wrote:
Sun Apr 26, 2020 11:18 am
Moved to &8B (139). ?block% and ?(block%+1) are the size, minimum 43
As it's receiving data, shouldn't block%?0 = 3 and block%?1 = 43? If you set block%?0 = 43 and block%?1 = 0 the Tube will (uselessly) send 43 bytes and receive nothing!
Yep, you're right, I completely misunderstood how this works (I've almost never touched OSWORD back in the day, and have never played with a machine with anything on the far end of the Tube. I am so making this up as I go along :lol: )

Code sample above adjusted to what it should be, and I've checked in the change to the code.
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Sun Apr 26, 2020 1:43 pm

Soruk wrote:
Sun Apr 26, 2020 12:54 pm
I am so making this up as I go along :lol: )
I don't see this being an issue, since we're both using SDL (admittedly SDL1 for you and SDL2 for me), but can I just confirm that in BBC BASIC for SDL 2.0 the 40 bytes would need to be in the order expected for a conventional top-down bitmap/surface, i.e. the top-left 'pixel' of the character corresponds to the MSB (bit 7) of the first byte. I would hate for us both to implement the OSWORDs only to discover they were incompatible in respect of byte order!

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 26, 2020 2:33 pm

Richard Russell wrote:
Sun Apr 26, 2020 1:43 pm
Soruk wrote:
Sun Apr 26, 2020 12:54 pm
I am so making this up as I go along :lol: )
I don't see this being an issue, since we're both using SDL (admittedly SDL1 for you and SDL2 for me), but can I just confirm that in BBC BASIC for SDL 2.0 the 40 bytes would need to be in the order expected for a conventional top-down bitmap/surface, i.e. the top-left 'pixel' of the character corresponds to the MSB (bit 7) of the first byte. I would hate for us both to implement the OSWORDs only to discover they were incompatible in respect of byte order!
That's a very good point. Endianness hurts my head, but the BASIC code snippet above should show you how it works.

I've just rebuilt today's nightlies so the example above should work in them.

Here's my OSWORD definitions:

Code: Select all

void osword139(int64 x) {
  char *block;
  int32 offset, i, ch;
  
  block=(char *)(basicvars.offbase+x);
  if ( ( block[0] < 3 ) || ( block[1] < 43 ) ) return;
  ch=block[2];
  if (ch==163) ch=96;
  if (ch==223) ch=35;
  if (ch==224) ch=95;
  ch = ch & 0x7F;
  offset = ch -32;
  if ((offset < 0) || (offset > 95)) return;
  for (i=0; i<= 19; i++) {
    block[(2*i)+3]=mode7font[offset][i] / 256;
    block[(2*i)+4]=mode7font[offset][i] % 256;
  }
}

void osword140(int64 x) {
  char *block;
  int32 offset, i, ch;
  
  block=(char *)(basicvars.offbase+x);
  if (block[0] < 43) return;
  ch=block[2];
  if (ch==163) ch=96;
  if (ch==223) ch=35;
  if (ch==224) ch=95;
  ch = ch & 0x7F;
  offset = ch -32;
  if ((offset < 0) || (offset > 95)) return;
  for (i=0; i<= 19; i++) {
    mode7font[offset][i] = block[(2*i)+4] + (256*block[(2*i)+3]);
  }
}
My font definitions, starts at character &20, storage order is the display order for &20-&7F (last only shown for &FF):

Code: Select all

static unsigned short mode7font[96][20];
Matrix Brandy BASIC VI (work in progress)

User avatar
Richard Russell
Posts: 1592
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Richard Russell » Sun Apr 26, 2020 3:40 pm

Soruk wrote:
Sun Apr 26, 2020 2:33 pm
Endianness hurts my head, but the BASIC code snippet above should show you how it works.
With minimum modifications to your code (considering I've not yet implemented the OSWORD call) I get this in BBCSDL, which seems promising:

osword139.png

Will it also work in Matrix Brandy if OSWORD is called in the standard BBC BASIC way (which is how I have to do it) rather than via your SYS extension? If so the degree of compatibility should be good:

Code: Select all

A% = 139 : X% = b%% MOD 256 : Y% = b%% DIV 256 : CALL &FFF1

Soruk
Posts: 774
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: Matrix Brandy BASIC VI for Linux with SDL: V1.22.4 released

Post by Soruk » Sun Apr 26, 2020 4:01 pm

Richard Russell wrote:
Sun Apr 26, 2020 3:40 pm
Soruk wrote:
Sun Apr 26, 2020 2:33 pm
Endianness hurts my head, but the BASIC code snippet above should show you how it works.
With minimum modifications to your code (considering I've not yet implemented the OSWORD call) I get this in BBCSDL, which seems promising:

osword139.png

Will it also work in Matrix Brandy if OSWORD is called in the standard BBC BASIC way (which is how I have to do it) rather than via your SYS extension? If so the degree of compatibility should be good:

Code: Select all

A% = 139 : X% = b%% MOD 256 : Y% = b%% DIV 256 : CALL &FFF1
Your example isn't 32-bit safe, let alone 64-bit. My "extension" using SYS "OS_Word" (or SYS 7) is actually the RISC OS way of doing it, which in RISC OS is 32-bit safe, and extended in Matrix Brandy to be 64-bit safe. Setting X%=b%% is at least 32-bit safe. (I've understood in BASIC you can set X% to point to the block and it'll work, whether or not Y% is set to block DIV 256)
Matrix Brandy BASIC VI (work in progress)

Post Reply

Return to “modern implementations of classic programming languages”