|
Update: The project has moved to Sourceforge. |
|
Attention Slashdot crowd, here is a little background: This application is a recompiled version of the original Commodore 64 binary – it is not a reimplementation, so while it runs at pretty much the maximum possible speed, it is still 100% compatible. The huge C file in the archive has been produced by feeding the original 6502 code into my static recompiler and optimizing it with LLVM. The original operating system interface (character I/O, LOAD, SAVE etc.) has been reimplemented in native C, so Commodore BASIC interfaces nicely with OS X/Windows/Unix – you can use pipe I/O, and you can pass the filename of a BASIC program on the command line. Yes, you could also just run a standard C64 emulator, but it wouldn’t be nearly this speed, and everything would run inside a sandbox; and there would be no way to interface this to your OS. |
A while back, I released Apple I BASIC and Commodore BASIC as a scripting language for Mac OS X 10.5 on Intel. It did not work on any other OS or on a different CPU type.
Today, we are releasing Commodore BASIC as a Scripting Language – it works on Linux, Windows, Mac OS X 10.4/10.5 (Intel and PowerPC), and you even get the source, so you can adapt it to other operating systems and CPUs.
Download it here: cbmbasic.zip
The archive comes with binaries for Mac OS X and Windows. The source compiles on Linux, Windows and Mac OS X. All code is BSD-licensed. Main work by Michael Steil, speed optimizations, Linux and Windows fixes by James Abbatiello.
The core of the BASIC interpreter is in the file cbmbasic.c, which is platform, endianness and bitness independent. For all I/O, it calls out into runtime.c, do it should be able to adapt this project for any OS by just changing runtime.c.
All function calls that the core interpreter can’t handle end up in kernal_dispatch() in runtime.c, where a switch statement dispatches these to C functions. For Commodore BASIC, runtime.c has to support several Commodore KERNAL library routines. Some of them are very important (CHRIN, CHROUT) and some are only used for certain BASIC statements (LOAD, SAVE, OPEN, SETTIM). runtime.c does not implement all functions yet.
Feel free to port cbmbasic to your system and architecture of choice, and extend runtime.c to support more functions. If you like, send your changes back to us (mist64<at>mac<dot>com, abbeyj<at>gmail<dot>com), so we can update the main project and give your changes to everyone. We’re also interested how fast you can get it with different compilers and settings.
See my old article for more info as well as some insights on how it is done.
|
See also: |
only one word: T H A N K S !
Woh. Blast from the past!
Least readable code EVER!
I like the effort but the code is indeed completely unreadable. cbmbasic.c is a whopping 1.2Mb, which is really insane.
@DusK, bart: The code is statically recompiled 6502 code – there is no way to make it more readable. :-)
Also, this is a very nice test for compilers. Intel’s C Compiler for example refuses to optimize it, because the function is too big.
i’m not involved in the develop of cbmbasic, so i just try to guest.
i think the cbmbasic.c file is generated by llvm (low level virtual machine) so to modify it you need to change the source llvm file (mist64 and abbeyj mike think you share it?) or the llvm back-end (not an easy task).
[...] Commodore BASIC as a Scripting Language for UNIX and Windows – now Open Source Today, we are releasing Commodore BASIC as a Scripting Language – it works on Linux, Windows, Mac OS X 10.4/10.5 (Intel and PowerPC), and you even get the source, so you can adapt it to other operating systems and CPUs. [...]
[...] pagetable.com » Blog Archive » Commodore BASIC as a Scripting Language for UNIX and Windows – now … (tags: programming osx mac language apple computer languages scripting commodore basic) [...]
[...] Commodore 64 Basic interpretators ļauj izbaudīt 20 gadu pagātni Windows, MacOS X un Linux [...]
@lorenzo: Correct, LLVM is used to do a first pass of optimization and create C code that works with many C compilers. The input to LLVM is (simplified) the original 6502 code of Commodore BASIC. I’m sorry, but nothing more readable exists.
Why can’t I run the scripts/games that you have linked to in the other article? It just keeps giving “STRING TOO LONG” error.
Running linux here btw.
[...] http://www.pagetable.com/?p=48 [...]
@anon: Those were for Apple I BASIC, not for (Microsoft) Commodore BASIC.
[...] Commodore BASIC as a Scripting Language for UNIX and Windows – now Open Source – A port of the Commodore BASIC interpreter, now as a script interpreter for Linux, OSX and Windows. Very cool. The memories… (tags: programming commodore c64 nostalgia scripting osx ) Tags: c64 · commodore · Linky · nostalgia · osx · Programming · scripting [...]
[...] Sunset Boulevard. Free binary downloads are available for Windows and Mac, source code for Linux. Commodore BASIC as a Scripting Language for UNIX and Windows – now Open Source [...]
What new manner of machine be it? …this Commodore
10 print”fuck off microsoft, long live commodore”
20 goto 10
Geeky coolness. Gonna port AMOS next? or AmigaDOS? :D
Port TI-Extended Basic with Speech Synthesizer support so we can recall the wonderful days of gosub/return call char, call hchar, call vchar, call sprite, call coinc and call sound…
This is really useful! Are you going to support redirection of a stdin pipe where “INPUT” doesn’t print the “?” like in apple1basic? Also, it would be nice if it weren’t so strict with inputs being in caps, but there’s probably a reason for it being that way that I don’t understand. Oh, and I noticed the Windows port likes to put #’s after printing out variables or the input. When I fullscreen, it’s shown as a garbage character.
The .bas file referenced below just prints the input after “YOU SAID “:
C:\cbmbasic>echo test | cbmbasic.exe test.bas
?#
YOU SAID test
C:\cbmbasic>
@hiroshi: You might be seeing the PETSCII 0×1D characters (CSR RIGHT) – when the screen is the current output device, it replaces some SPACE characters with this. You can support this in CHROUT. Patches are welcome. :-)
@Keptwench: I’m actually working on getting Amiga programs working in my recompiler, yes. And James recently got some DOS programs working.
Cool! But it won’t be complete without POKE and SYS!
Does this mean we could see AmigaDOS and other programs running natively, without having to use such things as UAE?
[...] Commodore BASIC para Mac OS X, Linux y Windows, una versión para ordenadores modernos de ese lenguaje que tantas mentes dañó (¡así nos hemos quedado!) que se ejecutar directamente desde la consola para recordar viejos tiempos. (Vía Lifehacker.) [...]
@Ghostwolf: The idea is to run Amiga applications that only use exec.library and dos.library calls and don’t do UI or access hardware directly, natively on modern systems.
[...] Sunset Boulevard. Free binary downloads are available for Windows and Mac, source code for Linux. Commodore BASIC as a Scripting Language for UNIX and Windows – now Open Source [...]
For those who are interested in running AmigaOS applications natively, please see the AROS project: http://aros.sourceforge.net/
This project recreates the Amiga’s entire API in a portable manner, including but not limited to graphics.library and intuition.library. It runs under Windows, Linux, and even on bare metal. In essence, it is the closest thing you can get to an open source edition of AmigaOS Classic.
No emulator needed.
I just left a comment, but it didn’t appear. No indication that it was awaiting moderation either. Just . . . nothing.
Trying again:
For those who are interested in running Amiga applications under your OS of choice, without the use of an emulator, please see the AROS project at http colon slash slash aros dot sf dot net. (Sorry for the URL munging, but it looks like this commenting system pukes on URLs). No emulation involved; the only requirement is to recompile the Amiga application to your host environment. AROS is the closest thing to an open source AmigaOS Classic you’ll ever find.
@Samuel: links work for me ;-)
http://aros.sourceforge.net/ – an amazing project!
[...] pagetable.com » Blog Archive » Commodore BASIC as a Scripting Language for UNIX and Windows – now … Today, we are releasing Commodore BASIC as a Scripting Language – it works on Linux, Windows, Mac OS X 10.4/10.5 (Intel and PowerPC), and you even get the source, so you can adapt it to other operating systems and CPUs. (tags: windows vintage unix c64 2008 2008-11) [...]
It seems like this is CASE SENSITIVE and all BASIC commands have to be in CAPS! Is there an easy way to change this?
thanks!
This is just incredibly cool. Thanks!!
@Bob: You could change CHRIN() in runtime.c to make all input uppercase, but then you would lose the possibility to use lowercase in strings. Another idea would be to swap upper case and lower case on both CHRIN() and CHROUT() – so keywords would have to be lower case, but BASIC would preserve the case.
Commodore BASIC had hooks for external extensions in the tokenizer, detokenizer and interpreter; I’m thinking about providing these hooks to runtime.c. :-)
Is there a possibility that we could see a version of amiga basic also? But This is wonderful; just to run old C-64 programs.
@mafutha: Please read earlier posts.
Now if you can figure out how to read my old 5.25″ floppies that failed to read because my floppy reader was “out of alignment” you’d be my hero!\
Long live C-64!
WOW, very nice. Looking forward to this evolving and doing some “machine language”
Load the Accumulator!
I am very impressed but miss TI and TI$.
It shouldn’t be too hard to implement, and would mean timing loops using TI would work correctly.
I love Jiffies.
[...] Update: Commodore BASIC as a Scripting Language for UNIX and Windows – now Open Source [...]
Michael: your “recompiler” and your words about your work related to Amiga programs really impresses me! I would like to know more about it. Precisely I would like to know in what extend it could be ported to AROS which could provide almost all native functions as it reimplements original libraries from scratch (and that means it’s not limited to dos and exec). And what about recompiling third-party #?.library #?.device and so on? What do you think? Am I only dreaming?
Is there a way to quit infinite loops and go back to the interpreter? I’m afraid my PC’s keyboard lacks RUN/STOP.
[...] Commodore BASIC as a Scripting Language for UNIX and Windows – Now Open Source (Michael Steil) [...]
Amazing stuff. I started learning programming on C-64, so this is incredibly emotional thing to see implemented. Well done.
[...] Sunset Boulevard. Free binary downloads are available for Windows and Mac, source code for Linux. Commodore BASIC as a Scripting Language for UNIX and Windows – now Open Source [...]
[...] pagetable.com: Commodore BASIC as a Scripting Language for UNIX and Windows – now Open SourceFor those with way too much time on their hands.Tags: programming languages opensource basic c64 commodore64 [...]
[...] di far interagire un bel programmino in Basic con il vostro sistema operativo. Trovate tutto su Pagetable.com. [...]
i hope further improvements can be done on this BASIC. like having to support GUI. :D
my standard test of a BASIC is to run a for/next loop and then print the counter number. on this Basic I get a strange printed thingy after each print. try it
10 FOR N = 1 TO 10
20 PRINT N
30 NEXT N