I would like to run BASIC code, like you used to do on older computers, in Linux. (I am looking for a BASIC interpreter that can run OS functions natively)
What options do I have? (Preferably for Debian-based and Arch-based)
I would like to run BASIC code, like you used to do on older computers, in Linux. (I am looking for a BASIC interpreter that can run OS functions natively)
What options do I have? (Preferably for Debian-based and Arch-based)
If you want to run natively in Linux BASIC you have several packages in Debian to choose from:
Brandy is an interpreter for BBC BASIC V, the dialect of BASIC that Acorn Computers supplied with their ranges of desktop computers that use the ARM processor such as the Archimedes and Risc PC, and is still in use on these and compatibles.
BASIC V is a much extended version of BBC BASIC.
This was the BASIC used on the 6502-based BBC Micro that Acorn made during the 1980s.
bwBASIC can be configured to emulate features, commands, and functions available on different types of BASIC interpreters;
bwBASIC implements one feature not available in previous BASIC interpreters: a shell command can be entered interactively at the bwBASIC prompt, and the interpreter will execute it under a command shell.
For instance, the command "dir *.bas" can be entered in bwBASIC (under DOS, or "ls -l *.bas" under UNIX) and it will be executed as from the operating system command line.Shell commands can also be given on numbered lines in a bwBASIC program, so that bwBASIC can be used as a shell programming language. bwBASIC's implementation of the RMDIR, CHDIR, MKDIR, NAME, KILL, ENVIRON, and ENVIRON$() commands and functions offer further shell-processing capabilities.
To install them:
sudo apt-get install brandy bwbasic
As for my personal experience, I do prefer bwbasic
as it allows to have the power of BASIC in a text command line or shell script.
As an alternative, you also have several emulation packages of computers of the old, that obviously besides the BASIC syntax implement all the environment of some old computer you may want to relive.
Interestingly enough, bwbasic
in theory could allow automating operations in Unix e.g. building scripts using the BASIC language. Never tried it though.
You wrote in a comment to Foon's answer that
What I mean by "like old computers" is that its just there
Others have provided several different suggestions for BASIC interpreters that you could install on a Linux system, so I won't go there. Modern PCs generally don't come with built-in BASIC interpreters, so you are stuck booting something that can run an installed BASIC interpreter.
Rather, I'll take the above to mean that you want something that starts a BASIC interpreter automatically, similar to but not quite like how early microcomputers (such as the Apple II, Commodore C-64, Zinclair ZX-81, and their ilk) booted into a native BASIC interpreter.
There are basically three ways to do this that I can think of:
This is the least invasive, because it works fully within the system and environment you are used to.
Basically, through whatever means your desktop environment provides, you create a program launcher and set it up to launch the BASIC interpreter of your choice in a terminal. For extra effect, you can set specific fonts, colors, etc., to simulate an environment of days gone by. Exactly how you would do this depends on the desktop environment you are using, which you haven't specified, but right-clicking around where you are currently clicking to launch applications and looking for a choice to create a new launcher will be a good start.
This is a little more involved than a simple desktop launcher, but providers better isolation so you don't risk messing up your own files. First, install a BASIC interpreter; I'll use bwbasic
for the example, but anything goes, really, as long as it runs natively in a terminal. Then add a user and set its shell to be the bwbasic interpreter. This can be done through the GUI, but that depends on which desktop environment you are using; the portable approach is to do so in a terminal using useradd
. This will be something similar to
$ sudo -i
# grep -q "$(type -pP bwbasic)" /etc/shells || echo "$(type -pP bwbasic)" >>/etc/shells
# useradd --home /home/basic --create-home --shell "$(type -pP bwbasic)" basic
Then, you should be able to enter a clean BASIC environment through sudo:
$ sudo -i -u basic
You can create a launcher (as above) that executes this command in a terminal, if you want to.
Give your normal password when prompted by sudo. You can edit the sudoers configuration to avoid the password prompt if desired, but be aware that editing sudoers is somewhat complicated and even more so, risky; you could lock yourself out of the root account, making it quite difficult to repair the configuration.
This is the most invasive approach, but also gets you closest to how early microcomputers worked, by booting directly into a BASIC interpreter. I don't recommend this, and would consider it unlikely to work without significant work, but am including it for completeness.
The Linux kernel accepts a command line parameter (yes, the Linux kernel has command line parameters; you can see the currently booted command line by reading from /proc/cmdline) named init
, which specifies which program to execute once kernel initialization is complete. You can configure the boot loader (most likely GRUB) to allow you to boot a kernel entry that says that init
should be /usr/bin/bwbasic
(or whichever other BASIC interpreter you installed).
For this to work, the BASIC interpreter, as well as all files it requires, must be located on the root (/
) file system. This is because one of init's tasks is to mount all file systems, and because you are providing a non-init program as init, the non-root file systems will not have been mounted. (I believe another of init's tasks is to remount the root file system in read-write mode, so by the trivial approach you won't be able to save anything. You might, however, depending on the exact implementation details, be able to have the system execute something like mount -o remount,rw /
to remount the root file system read-write.) Your chosen BASIC interpreter must also not depend on anything else that init is responsible for, and you will not have access to any facilities handled by init or by any processes spawned by init (for example, networking or multiuser support).
A kernel command line of something like ro quiet init=/usr/bin/bwbasic
will probably get you pretty close to how it looked in the old days.
sudo echo
does not do what you mean and you're likely to encounter a -bash: /etc/shells: Permission denied
anyway as the >>
redirect is setup by bash before the rest of the command is evaluated. It's probably best to use type -P bwbasic | sudo tee -a /etc/shells
instead. See "permissions - How to insert text into a root-owned file using sudo? - Unix & Linux Stack Exchange
init
would be to configure the init system to use bwbasic
instead of agetty
and to not start an X11 display manager. (For others who don't know what I'm talking about, the kernel provides various "virtual consoles" accessible via Ctrl+Alt+F1 throuh Ctrl+Alt+F12 and the init system, by default, starts agetty
on 1 through 6 and an X11 Display Manager (which provides a login dialog) on 7. Before Upstart and systemd, this was controlled via /etc/inittab
.) getty
and its descendants handle console login prompts.
Since everyone seems to be assuming you mean "pre-IBM PC" by "older computers", I'm going to go the other route and offer an answer that interprets "older computers" to mean "IBM-compatibles before Windows 9x".
If, you meant computers running versions of MS-DOS that included QBASIC.EXE
, you have three options, depending on how strictly you define running them "on Linux":
If you've still got a copy of QBASIC.EXE
kicking around, you could use DOSBox or DOSEMU to run it in a virtualized DOS environment. (Both are available in Debian's repositories and are simple to set up. Just set a folder to be mounted as C:
, drop QBASIC.EXE
into it, and you're good to go.)
That'll give you perfect compatibility with old source code, but no integration with the host OS beyond "C:
is actually a folder, rather than a disk image".
I should clarify, however, that there's a trade-off between the two. DOSEMU will run in whatever terminal you want, but won't support the fancy low-level tricks some QBasic stuff used (eg. for specialized graphics modes). The only way to support that is a full emulator like DOSBox... but DOSBox will pop up its own window rather than using your terminal.
FreeBASIC has a qb
dialect/mode that aims for perfect compatibility with a large subset of QuickBASIC. (The unsupported stuff is mostly low-level stuff related to the fact that QuickBASIC was a 16-bit real-mode system while FreeBASIC is a 32-bit protected mode system.)
FreeBASIC offers Linux binaries, but you'll only find it in your package repository if you actually meant "Debian-family distros" rather than "Debian" and are running Ubuntu or an Ubuntu derivative like Mint.
The Linux builds of QB64 aren't even in the Ubuntu repositories, but it specifically aims to be the most compatible protected-mode QuickBASIC descendant and even provides an IDE that attempts to clone the QBasic/QuickBasic IDE.
My Debian systems, and probably most other Linux distributions, have several choices available directly through the package manager. Among them:
bwbasic
:The Bywater BASIC Interpreter (bwBASIC) implements a large superset of the ANSI Standard for Minimal BASIC (X3.60-1978) and a significant subset of the ANSI Standard for Full BASIC (X3.113-1987) in C. It also offers shell programming facilities as an extension of BASIC. bwBASIC seeks to be as portable as possible.
sdlbasic
:sdlBasic is a small, efficient and multiplatform BASIC interpreter for creating games using the power of SDL library. It was inspired by the old and glorious AMOS.
Just to throw out an alternative: there are multiple emulators for Linux that can run your old computers. As an example, with xkegs, if you boot it up, you should have an applesoft basic prompt waiting for you. Communicating with other linux stuff is an exercise left to the reader (hint: technically, I believe you can redirect output in your emulated apple to the emulated printer, which xkegs will then expose as a network socket which you can use e.g. nc to feed into some other piped applications etc. Not sure if there's a way to go the other way, but expect something similar could be done). I would expect the commodore 64 emulators would similarily have a way to run commodore's basic, etc.
kegs
does not seem to be one of them (no apt-cache search
result). And for some/most of the emulators, you will probably need to get an original ROM from somewhere.
Commented
Apr 16, 2017 at 17:05
init=/usr/bin/sdlbasic
to the Linux kernel, which if it works will get you much closer, but it may or may not even work.
There are a lot of alternatives. My suggestion is similar to ssokolow's answer. If you want a "modern" BASIC but with a syntax similar to the old BASIC interpreters, then you should give to BaCon a try. It's a BASIC transpiler which generates native code. The project has a pretty good manual, a lot of libraries and examples, and even an IDE written in BaCon.
The Python-based PC-BASIC offers exactly what you are looking for. Click on Documentation, and note the section entitled "Command-line Interface":
You can run PC-BASIC as a command-line interface by setting the interface=cli (or -b) option. No window will be opened: you can type BASIC commands straight into your Command Prompt/Terminal.
It's available via PyPi, and the website has installers for Linux .deb, Win, and Mac. I can tell you that it's also available in the Linux Mint repository.
You can run a C64 in your browser, and use BASIC that way.
http://codeazur.com.br/stuff/fc64_final/
Be aware the keyboard layout is different, i.e. Shift-2 for quotes.
http://jilltxt.net/wp-content/uploads/C64-keyboard-layout.png
Applesoft BASIC if you prefer- http://calormen.com/jsbasic/
There are emulators of other machines online,
but many of them go straight to whatever program you load,
without emulating the initial keyboard input required to get there.