New: Console Mode editions of BBC BASIC

for discussion of bbc basic for windows/sdl, brandy and more
Post Reply
Deleted User 9295

New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

By popular request (well, three people!) I have created Console Mode editions of BBC BASIC for MacOS, Linux (64-bit), Windows (64-bit) and Raspbian (32-bit). These have no graphics and no sound (nor do they support a mouse, joystick etc.) but their text-mode features are reasonably complete, so far as the capabilities of the native console/terminal allow (notably, text viewports are not supported).

You can think of them as BBC BASIC for SDL 2.0 with all the SDL stuff removed, and indeed that is effectively how they were created! Their keyboard input is taken from stdin and their output is sent to stdout so you can use them for CGI applications or effectively as a replacement shell. Normal shell commands can be issued by preceding them with a * in the usual BBC BASIC way.

These editions consist of compact self-contained executables with no dependencies on any third-party libraries; the BBC BASIC interpreter they contain is identical to that in BBC BASIC for SDL 2.0. They should be considered as Beta test programs since they have not received extensive testing. They are, of course, completely free and can be downloaded as follows:
Supplied with the executables are a small number of BBC BASIC demo programs. Here is the output from 8queens.bbc as seen in the Windows 10 console:
queens_console_win64.png
User avatar
BigEd
Posts: 6261
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by BigEd »

Very nice indeed, thank you! It's impressive that the console works so well as a mode-7 style display.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

BigEd wrote: Mon Jun 29, 2020 10:37 am Very nice indeed, thank you! It's impressive that the console works so well as a mode-7 style display.
Fortunately most consoles/terminals, on all popular OSes, are designed to accept VT-100 escape sequences so they support most of the features you expect. As noted, one major exception is viewports, which they don't have.

One thing to be aware of, though, is that software resizing of the console (needed by MODE of course) is not universally supported. Obviously that was impossible on a real VT-100 but most consoles do support it via a 'private' DEC escape sequence, but one notable exception is the Raspbian console which seems not to be resizable (it is a configuration option in Xterm).

It's quite fun that you can, for example, change the colours and then run a standard shell command:

console_colour.png
User avatar
roland
Posts: 5148
Joined: Thu Aug 29, 2013 9:29 pm
Location: Born (NL)
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by roland »

For what I have seen now it works fine on OS X. Good work =D>
Schermafbeelding 2020-06-29 om 13.33.54.png
FPGAtom: 512 KB RAM, Real Time Clock and 64 colours
MAN WOMAN :shock:
User avatar
BigEd
Posts: 6261
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by BigEd »

I'm on a Mac, and it seems I have 8 byte floats and roughly 20 decimal digits of precision: hurrah!

But the inline assembler doesn't seem happy: P% can't take a number so large as TOP. Is there a tip for assembling?
>P.~TOP
1BD4DC30
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

BigEd wrote: Mon Jun 29, 2020 1:15 pm I'm on a Mac, and it seems I have 8 byte floats and roughly 20 decimal digits of precision: hurrah!
10-byte (80-bit) floats in fact! You can force the use of 8-byte floats by adding a # suffix to your variable or array names.
But the inline assembler doesn't seem happy: P% can't take a number so large as TOP. Is there a tip for assembling?
Yes, 64-bits posed a problem for the assembler; the best solution I could come up with was to use Q%:P% as the 64-bit program counter and M%:L% for the (optional) limit. Here's a 64-bit 'Hello World' program to get you going:

Code: Select all

      DIM limit%% -1, code%% 100, limit%% -1

      FOR pass% = 8 TO 11 STEP 3
        ]^P% = code%%
        ]^L% = limit%%
        [opt pass%
        .hello
        sub rsp,40
        mov rbp,"oswrch"
        lea rbx,[rel asciiz]
        .loop
        mov al,[rbx]  ; get next char
        inc rbx       ; bump pointer
        cmp al,0      ; is it a NUL?
        jz done       ; if so, exit
        movzx ecx,al  ; for Windows &
        mov edi,ecx   ; System V ABIs
        call rbp      ; output char
        jmp loop      ; continue
        ;
        .done
        add rsp,40
        ret
        ;
        .asciiz
        db "Hello world!"
        dw &0A0D
        db 0
        ]
      NEXT pass%

      CALL hello
User avatar
BigEd
Posts: 6261
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by BigEd »

Thanks! Works a charm:

Code: Select all

>RUN
000000011BD4DE56                                 opt pass%
000000011BD4DE56                      .hello     
000000011BD4DE56 48 83 EC 28                     sub rsp,40
000000011BD4DE5A 48 BD 43 88 7D 0E 01            mov rbp,"oswrch"
000000011BD4DE61 00 00 00                        
000000011BD4DE64 48 8D 1D 1A 00 00 00            lea rbx,[rel asciiz]
000000011BD4DE6B                      .loop      
000000011BD4DE6B 8A 03                           mov al,[rbx]  ; get next char
000000011BD4DE6D 48 FF C3                        inc rbx       ; bump pointer
000000011BD4DE70 3C 00                           cmp al,0      ; is it a NUL?
000000011BD4DE72 74 0C                           jz done       ; if so, exit
000000011BD4DE74 0F B6 C8                        movzx ecx,al  ; for Windows &
000000011BD4DE77 89 CF                           mov edi,ecx   ; System V ABIs
000000011BD4DE79 FF D5                           call rbp      ; output 
000000011BD4DE7B E9 EB FF FF FF                  jmp loop      ; continue
000000011BD4DE80                                 ;
000000011BD4DE80                      .done      
000000011BD4DE80 48 83 C4 28                     add rsp,40
000000011BD4DE84 C3                              ret
000000011BD4DE85                                 ;
000000011BD4DE85                      .asciiz    
000000011BD4DE85 48 65 6C 6C 6F 20 77            db "Hello world!"
000000011BD4DE8C 6F 72 6C 64 21                  
000000011BD4DE91 0D 0A                           dw &0A0D
000000011BD4DE93 00                              db 0
Hello world!
>
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by Soruk »

Working on my RasPi2. And a welcome return of immediate mode programming =D>

Out of sheer curiosity, does that mean that code is actually present in BBCSDL but just disabled, or was it specially re-inserted from older versions?
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Mon Jun 29, 2020 9:22 pmOut of sheer curiosity, does that mean that code is actually present in BBCSDL but just disabled, or was it specially re-inserted from older versions?
There's no code for the immediate-mode commands in the current release of BBCSDL, largely because I've tried to keep the assembler version (used for the Windows and 32-bit Linux editions) and the C version (used for the ARM and 64-bit editions) 'in step'. I do of course have 16-bit assembler code from older versions, but I'm not enthusiastic about trying to port it to 32-bit. It would have to be adapted anyway, because in my earlier BASICs the immediate-mode commands were tokenised (those tokens have since been reused and aren't available).

So my choices for future releases of BBCSDL are to keep the assembler and C versions in step, and not enable the immediate commands in either, or to enable them in the C version but not in the assembler version. It's a tricky decision: BB4W doesn't have them, nor does it really need them because one is expected always to use the IDE. The same largely applies to BBCSDL, but because the IDE is itself coded in BASIC there's a slightly stronger argument that the executable ('run time engine') should be more self-contained.

I'm unsure which way to jump at the moment and would welcome input from others.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

For clarity these are the immediate-mode commands accepted by the Console Mode editions of BBC BASIC:
  • AUTO [start[,step]]
  • DELETE [start[,end]]
  • EDIT line
  • LIST [start[,end]]
  • LOAD "filename"
  • NEW
  • RENUMBER [start[,step]]
  • SAVE "filename"
There is no OLD; that was specifically valuable on a BBC Micro after pressing Break but isn't very useful now. Although it would be possible for OLD to reverse the effect of NEW, it couldn't restore a program removed using DELETE (which is otherwise synonymous with NEW, as it is in Matrix Brandy but not ARM BASIC).

When a range of lines is accepted it is legitimate to write start, (i.e. with a trailing comma) which implies 'from that line to the end of the program', even though the syntax descriptions would not suggest this is legitimate.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Mon Jun 29, 2020 9:22 pm And a welcome return of immediate mode programming
I don't think I'd find immediate mode programming "welcome" having become used to an IDE! As you might have guessed the program I was trying to port to Matrix Brandy a couple of weeks ago was my SDLIDE.bbc, but I didn't pursue it after the complications of MOUSE. I suspect I would have hit other troublesome areas (e.g. the absence of ON TIME) had I persevered.

On the current topic, was it your decision to make DELETE delete the entire program or did you inherit it from upstream Brandy? I've done the same in my Console Mode editions but it's quite dangerous, and I wonder if I would be better to reject DELETE without any qualifiers as ARM BASIC does.
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by Soruk »

Richard Russell wrote: Tue Jun 30, 2020 1:55 pm
Soruk wrote: Mon Jun 29, 2020 9:22 pm And a welcome return of immediate mode programming
I don't think I'd find immediate mode programming "welcome" having become used to an IDE! As you might have guessed the program I was trying to port to Matrix Brandy a couple of weeks ago was my SDLIDE.bbc, but I didn't pursue it after the complications of MOUSE. I suspect I would have hit other troublesome areas (e.g. the absence of ON TIME) had I persevered.

On the current topic, was it your decision to make DELETE delete the entire program or did you inherit it from upstream Brandy? I've done the same in my Console Mode editions but it's quite dangerous, and I wonder if I would be better to reject DELETE without any qualifiers as ARM BASIC does.
That's something from upstream Brandy. You're quite right, it is dangerous. And, as you point out it's a deviation from ARM BASIC, and one I don't agree with. So I'll get that fixed. And, in your previous post you mention the lack of OLD. Matrix Brandy has it, but it doesn't work properly (nor in upstream), so I'm going to remove it (and have it generate an Unsupported error).
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Tue Jun 30, 2020 2:27 pmThat's something from upstream Brandy. You're quite right, it is dangerous. And, as you point out it's a deviation from ARM BASIC, and one I don't agree with. So I'll get that fixed.
I suppose I had better do the same then: I should learn to keep quiet to avoid giving myself extra work! :)

Whilst we're on the subject, another Matrix Brandy deviation from ARM BASIC that I don't like is that it accepts the commands in lowercase. I can see why that might have been thought to be useful, but as a result you cannot, for example, set the value of a variable like list in immediate mode (yes I know you could use LET):

Code: Select all

list = 100
Syntax error
I expect this is something else you inherited, what's your view on it?
Last edited by Deleted User 9295 on Tue Jun 30, 2020 3:16 pm, edited 1 time in total.
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by Soruk »

Richard Russell wrote: Tue Jun 30, 2020 3:11 pm
Soruk wrote: Tue Jun 30, 2020 2:27 pmThat's something from upstream Brandy. You're quite right, it is dangerous. And, as you point out it's a deviation from ARM BASIC, and one I don't agree with. So I'll get that fixed.
I suppose I had better do the same then: I should learn to keep quiet to avoid giving myself extra work! :)

Whilst we're on the subject, another Matrix Brandy deviation from ARM BASIC that I don't like is that it accepts the commands in lowercase. I can see why that might have been thought to be useful, but as a result you cannot, for example, set the value of a variable like list in immediate mode:

Code: Select all

list = 100
Syntax error
I expect this is something else you inherited, what's your view on it?
It is odd, and again something inherited from upstream. Out of habit I tend to type them in uppercase anyway. However, it is only the immediate mode commands that are "afflicted" in this way,

Code: Select all

print 100
Mistake
...which would be more ideal for them all. I guess the only one I've started getting in the habit of is "q." for "QUIT". I'll see what's involved in removing this.
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Tue Jun 30, 2020 3:16 pmI guess the only one I've started getting in the habit of is "q." for "QUIT".
Surely that shouldn't work anyway? QUIT isn't a command, it's a statement, so it's never legitimate to enter it in lowercase (unless, like my BASICs, there's a specific mode for that). Does Brandy have it as both a statement and a command, or what?
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by Soruk »

Richard Russell wrote: Tue Jun 30, 2020 3:19 pm
Soruk wrote: Tue Jun 30, 2020 3:16 pmI guess the only one I've started getting in the habit of is "q." for "QUIT".
Surely that shouldn't work anyway? QUIT isn't a command, it's a statement, so it's never legitimate to enter it in lowercase (unless, like my BASICs, there's a specific mode for that). Does Brandy have it as both a statement and a command, or what?
Yes, it does. Anyway, it was 5 lines to knock out (and one to replace it with), so I've taken a flexible approach in that lowercase commands are disabled by default, but can be enabled as a compile-time option. (I'm not going to make a SYS call to enable them run-time.)
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Tue Jun 30, 2020 3:34 pm Yes, it does.
Fascinating. The only possible reason I can think of is to allow QUIT to be entered in lowercase, so that was clearly thought to be important at some point. In a windowed desktop context can't you just click on the Close button anyway (of course that has a very different effect in the case of my Console Mode editions)?
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

I have updated the Console Mode editions of BBC BASIC to version 0.11. The differences in this version are:
  • Fixed a bug which made it fussy about the directory from which it was run.
  • DELETE with no explicit line-number range is no longer accepted.
  • LIST IF is implemented (as it always should have been).
The updated version may be downloaded from the same place as before:
steve3000
Posts: 2909
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by steve3000 »

This is brilliant! I've always missed the ability to instantly program up a calculation in BASIC when working on Windows or Mac, usually I end up using a bulky spreadsheet or unfriendly scientific calculator app... now I can use BASIC again :)
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

steve3000 wrote: Tue Jun 30, 2020 10:19 pm This is brilliant! I've always missed the ability to instantly program up a calculation in BASIC when working on Windows or Mac, usually I end up using a bulky spreadsheet or unfriendly scientific calculator app... now I can use BASIC again :)
What was your objection to using a 'full' (i.e. with graphics, sound and all the works) GUI version of BBC BASIC to do that? Admittedly the console editions are much more lightweight, but if I want to do a quick calculation I would usually run BBC BASIC for SDL 2.0 from a desktop icon and drop into immediate mode from the IDE.
steve3000
Posts: 2909
Joined: Sun Nov 25, 2012 12:43 am
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by steve3000 »

No objection from me, just restrictions on work computers mean I can’t install anything, so standalone executable which passes the automated virus scan is the only possibility - and this went through with no issues :)
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

steve3000 wrote: Tue Jun 30, 2020 11:28 pm No objection from me, just restrictions on work computers mean I can’t install anything, so standalone executable which passes the automated virus scan is the only possibility - and this went through with no issues :)
Ah, that's an excellent reason! It never occurred to me that the console editions would have that advantage, but I'm pleased you find them useful.
User avatar
BigEd
Posts: 6261
Joined: Sun Jan 24, 2010 10:24 am
Location: West Country
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by BigEd »

For myself, I simply have a preference for working from the command line and not using the mouse. A CLI Basic seems like a very natural thing. (Of course I'm happy to use SDL Basic too!)
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

BigEd wrote: Wed Jul 01, 2020 8:32 am For myself, I simply have a preference for working from the command line and not using the mouse. A CLI Basic seems like a very natural thing.
It's odd in a way that it has taken so long for such a thing to appear. Once I received the suggestion, I had a working version within hours - it was really quite a straightforward task to strip out all the SDL-specific code and replace it with a minimal VDU driver which outputs VT-100 escape sequences. The modular nature of my code helped a lot: I have always organised my BASICs into generic modules, with no dependency on the OS and environment, and platform-dependent modules. The former needed no changes at all.

If you have any suggestions for enhancements let me know. I'm also always on the lookout for more BASIC programs which can be used for demonstration purposes, so that means text-only programs but ideally ones that make use of colours, cursor movement etc. to achieve interesting or attractive effects. Having no control over the character size is a limitation, but in the modified '8queens.bbc' and 'snake.bbc' I worked around that by outputting pairs of characters where the original used only one.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Now updated to v0.12. The differences are:
  • On exit, a 'reset' escape sequence is sent only if stdout appears to be a terminal.
  • VDU 30,8 (home, left) now causes a scroll-down as it should.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

I have updated the Console Mode editions of BBC BASIC to version 0.13. The differences in this version are:
  • LISTIF is accepted (i.e. without a space, as other versions do).
  • RENUMBER now works even if only some lines are numbered.
  • New demo program 'chess.bbc' added (adapted from QBasic).
  • Demo program 'speed.bbc' modified to be more honest!
The updated version may be downloaded from the same place as before:
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by Soruk »

I missed V0.13. Something isn't quite right with V0.14...

Code: Select all

soruk@RaspberryPi2 ~/bbcbasic $ ./bbcbasic 
BBC BASIC for Linux Console v0.14
(C) Copyright R. T. Russell, 2020
>TIME=0:PRINT TIME
3.86547057E9
>_
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Sun Jul 05, 2020 5:42 pm I missed V0.13. Something isn't quite right with V0.14...
Indeed! You may have noticed that I haven't announced v0.14 because I realised that it was broken. I should perhaps have deleted it, but I assumed that nobody would download it without a release announcement. I have now!

Look out for an announcement about v0.15 before too long.
Soruk
Posts: 1136
Joined: Mon Jul 09, 2018 11:31 am
Location: Basingstoke, Hampshire
Contact:

Re: New: Console Mode editions of BBC BASIC

Post by Soruk »

Richard Russell wrote: Sun Jul 05, 2020 8:02 pm
Soruk wrote: Sun Jul 05, 2020 5:42 pm I missed V0.13. Something isn't quite right with V0.14...
Indeed! You may have noticed that I haven't announced v0.14 because I realised that it was broken. I should perhaps have deleted it, but I assumed that nobody would download it without a release announcement. I have now!

Look out for an announcement about v0.15 before too long.
I was a bit surprised, especially as I used the link on the 0.13 announcement.
...maybe version-number the zip files?
Matrix Brandy BASIC VI (work in progress) The Distillery (another work in progress) Note Quiz (New educational software for the BBC and modern kit)
BBC Master 128, PiTubeDirect (Pi 3B), Pi1MHz, 5.25+3.5in dual floppy.
Deleted User 9295

Re: New: Console Mode editions of BBC BASIC

Post by Deleted User 9295 »

Soruk wrote: Sun Jul 05, 2020 8:13 pm...maybe version-number the zip files?
Hmm, I've never bothered to do that (not least because automating it could be a pain) and I haven't the luxury of generous space at my personal site to leave multiple versions there. Well I could for these Console editions because they are tiny, but not BBCSDL.

I (try to) take more care with products that have reached a 1.00 version number, but I must say I'm pretty relaxed about Alpha and Beta releases.
Post Reply

Return to “modern implementations of classic programming languages”