Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Commodore Basic as a Scripting Language (github.com/mist64)
91 points by harel on June 26, 2020 | hide | past | favorite | 44 comments


While this is cool pet project (intentional pun), Microsoft Basic 6502 was, in my personal opinion, one of the worst BASIC implementations of that era. If we're going early 80s BASIC then I'd prefer to use BBC BASIC which supported functions amongst other things -- albeit still not as readable as modern structured programming.

There's still a few BASIC implementations floating about for modern systems too. FreeBASIC (https://www.freebasic.net/) is one worth checking out.

Personally I still have quite a few of those 80s micro computers and occasionally hook them up to teach my kids programming.


Came here to say this. Commodore BASIC (which was really by Microsoft, as you've pointed out) was by far my least favourite of the 8-bit BASICs I used.

It was even worse than Sinclair BASIC due to the lack of drawing commands (yes, I know you could get these as extensions on a cartridge - I didn't have that). The main issues with Sinclair BASIC were limited functions and the fact you had to use key combinations to enter most keywords.

I also remember it as being slow as all hell when compared to other BASICs, although that might just be the opposite of whatever rose-tinted nostalgia is.

I loved the Commodore 64 but its BASIC sucked. Commodore continued to royally eff up with Amiga BASIC which, if memory serves, was also basically[1] by Microsoft. I immediately switched over to AMOS by Francois Lionet, which was great, although with hindsight wish I'd given Blitz a go too.

[1] Pun also intended, even though dreadful.


To be fair to Microsoft, the C64 BASIC was notoriously outdated when the C64 shipped. Jack Tramiel managed to buy an unlimited-use license to Microsoft's BASIC in 1977, and was determined to get his money's worth. On the bright side, the C64 BASIC was great at motivating new programmers to learn assembly programming so they could avoid it, and in the process finding out how computers really work. :)


This. I remember the C64 BASIC mostly as a glorified loader for the machine code. I even typed in a monitor published in some magazine just so I could push the machine nearer its limits.


Cut my teeth on Oric Atmos BASIC, and I can verify that my eyes still scan magazine listings intuitively looking for the DATA statements that indicate fast BLIT code ..


it motivated me to learn C.


M. Lionet has resurfaced in recent years and is busy working on a new BASIC. Given that he wrote both STOS and AMOS back in the day I'm looking forward to seeing how the new project turns out.

https://www.aoz.studio/the-aoz-story


Interestingly enough, Microsoft's BASIC was the fastest of all the early home computer BASICs sold in the US. Much faster than Timex Sinclair, Atari, and TI/99 BASIC. And it achieved those speeds with decent precision in FP.

Apple, Commodore, and the IBM PC all used Microsoft BASIC and were the fastest standard BASICs.

Across the pond the BBC Micro had a faster BASIC, and by the mid-80s there were lots of faster BASICs you could buy from 3rd parties.


BBC BASIC was also fast. A lot of the "Better" BASICs were also quite a bit slower at the time.

Microsoft BASIC was relatively swift compared to most early peers, had decent precision FP, and had limited interoperability between platforms. This made it ideal for small business, education, and magazine listings.

So once again Microsoft won with an inferior product by turning it into a de facto standard :-)

I did like the simplicity of it.


Lovely thing about the BBC was the I/o breakout that meant you could easily wire it up to another processor and do stuff. For those of us at the time, growing up with alternative systems, such features were a real wonder, and a reason to lug everything over to my BBC-owning neighbours place for a weekend hacking ..

I love it that this ethos has persisted in the ZX Spectrum Next design[1], which also allows for the .. limited .. 8-bit (well, max'ed out actually) machine to access a .. rather large super-computer, by comparison, and by that I mean a raspberry-pi Zero ...

I wonder, if ZX Next is a paradigm which develops further into a viable market (imho, this already exists, elsewhere and otherwise..) then what sort of crazy machines might we be sporting on our wrists and in pockets, soon enough?

I mean, ZX Next ideology, in a PDA ..

[1] - https://www.specnext.com


What I remember about C64 BASIC is that variable names were significant to only two characters. It was horrendous for any sizable program.

What did people do for a development environment on the C64? I remember that it was not fun at all using straight Commodore tools. For example, the disk was unbelievable slow. At the time, I also had Atari 800- it was a much nicer system.


I share your opinion about the C64's poor basic -- only reinforced by the fact I'm toying with coding again for the Commodore, since it was my first love -- but someone pointed out the incredibly good game Pirates! by Sid Meier was mostly written in C64 BASIC!

(I had trouble believing this, but all the info I found online points to this being true)


As a huge retro fan with a collection of over 30 systems, I thoroughly encourage you to pick up C64 coding and give it another go.

And for anyone else thinking about this subject, consider this: every year for the last decade now the following systems have had new programs written for them by thriving communities: Amstrad CPC6128, C64, ZXSpectrum, BBC Micro B, Oric Atmos, Jupiter Ace (!), Apple II .. actually, never mind. Lets just try this experiment: dig out the old computer from your attic, dust it off, get your docs together, and go find the .. rather eager, I'm sure .. community of hackers that are keeping these machines alive.

Honestly, I have a ton of iDevices with App Store crap on them. The only releases I get really excited about lately are for the Amstrad CPC6128 and Atmos, though .. its just so fun to see crazy new stuff being made for these 'ancient' machines ..

So yeah, please get to coding. Docs for some of these systems are easier now than ever!


> Lets just try this experiment: dig out the old computer from your attic, dust it off

I would... but my dad sold it decades ago, in order to buy me my PC XT clone. It seemed like a good move at the time (and I learned to program with GWBASIC for the PC), but today I want to go back in time and tell my dad to keep the C64!

Of course I've used VICE and other emulators. BMC64 on the Raspberry Pi feels like the real thing, computer-as-appliance. But I really, really want the beige "breadbin" C64 keyboard for the full experience.

I'm looking into buying a used C64 from my local eBay clone (note: I'm not from the US or the UK). But I keep fearing someone will sell me a defective C64 or that I won't be able to plug it into a modern LCD.

Thanks for the encouragement!


"They" should just have an emulator for all these machines on the raspberry pi, with a shell keyboard that makes it look like these machines.


There's a lot of enjoyment to be had actually using these retro systems. A large part of it is nostalgia, I wont deny that. But the way those systems directly interfaced with the hardware does bring some enjoyment too. I think of it like playing vinyl, some people enjoy the colourisation that vinyl adds to the sound but other people enjoy the tactile nature of the medium. Typing your code directly on an Amstrad, BBC Micro or Apple II is a bit like that in that there are technically better ways to do it these days but using the original machines gives you an irrational sense of enjoyment.


I used to explore what happened reading/writing to memory locations connected to the expansion cards on the Apple ][. I later had a Spectravideo PC and one of the first things I did was explore the memory by writing into different locations to see what happened. I also wrote a Z-80 disassembler to try to reverse engineer how much of the system worked (unfortunately, I never got around to properly decoding multi-byte opcodes).


Oh, the Open Pandora, which is literally loaded to the gills with all of the emulators, is a regular treat. But the joy of sitting on an old machine and putting it through its paces is quite something else ..


A Raspberry Pi with BMC64 is almost there. It feels like the real deal: you boot it up in seconds, and shut it down by unplugging it. But I want the C64 look & feel with its keyboard. If someone made a USB replica of a fully functional C64 keyboard I'd be in heaven.

(I'm aware of the TheC64 project, but it seems sold out at the moment, and not easy to get in all parts of the world).


One of my favorite games for the Atari 800 was Sid Meier's chopper rescue, this one:

https://www.youtube.com/watch?v=rUyebYD5UO0

Written partially in Atari BASIC... I wonder which environment Sid Meier preferred.


It was. It does use machine code utility routines for various things though. I never looked into it much, but did list the basic part at some point.


Your comment reminds me of HP9845 Basic. After using it everything else felt brain dead. Not just other versions of basic either.

https://www.hp9845.net/9845/software/basic/


Technically it does support functions. They are just extremely limited.


"Extremely limited" is fair. They were just one line formulas so pretty useless most of the time. Of course you also had sub-routines via GOSUB (which was defined in the very first BASIC specification in the 60s) but those didn't support parameters passing and GOSUB is only slightly less ugly than GOTO. Sadly "Commodore BASIC" didn't support multi-line user defined functions like BBC BASIC:

    REM Squaring a number using FN
    A=4
    B=FN_Square(A)
    PRINT A;" squared is ";B
    END
 
    DEF FN_Square(Num)
    =Num^2
(Source: http://www.bbcbasic.co.uk/bbcwin/tutorial/chapter17.html)

I'll grant you that even with BBC BASIC the syntax isn't pretty with the = token taking the place of a RETURN statement. BASIC definitely had its quirks.

I think Applesoft BASIC (also a Microsoft BASIC) supported multi-line FN blocks. Can't find anything conclusive online to confirm this though - perhaps someone on here remembers?


Applesoft BASIC also only supported numeric single line functions.

The first BASIC I used was Tandy TRS-80 Level II BASIC which shipped on all but the earliest of the TRS-80 Model I's. Microsoft wrote this BASIC also and it didn't support any type of user defined functions. Microsoft created a Level III BASIC for the TRS-80 which was their first consumer product. This did support single line functions and I think but am not absolutely sure that it supported string as well as numeric functions.


https://github.com/mist64/cbmbasic/blob/master/runtime.c:

    * CBMBASIC implements CHRGET/CHRGOT as self-modifying
    * code in the zero page.
I did quite a bit of programming on the C64 but I didn't know that. I always thought that, although there is no technical reason not to, zero page is only used for storing data and not code.


It's entirely for speed reasons. It's a very hot routine and exists in RAM to facilitate speedily loading and updating the BASIC text pointer, which is embedded within it, so having it in zero page optimizes it further. Modifying this code fragment to point to your own code and add additional commands to BASIC was called a "wedge" and for some systems was the only easy way to do so. It is a central component of all 6502 Microsoft BASIC variants. See https://www.pagetable.com/?p=774 for the routine in its entirety.


Wow, I did my own BASIC extension back in the day and just now I learned from you where the name “wedge BASIC” came from. Thanks!


Interesting.

However, there's really nothing special about Commodore BASIC 2.0. It was a very basic Microsoft BASIC; not as minimal as Apple Integer BASIC but not as good as something like GW-BASIC on the PC.

The Commodore BASIC 2.0 supported none of the hardware features of the C64 that weren't provided by the Commodore Kernal through PRINT statements. So you can clear the screen and change text color through embedding the appropriate control codes in strings or use ASC function, but accessing the VIC-II or SID had to be done through assembly or PEEKs and POKEs. So honestly making it a general scripting runtime can work easily.

If you want to use a real BASIC as a scripting language you want to check out FreeBASIC. It's an reimplementation of Microsoft's QBASIC with OOP and other extensions.


The main interpreter (cbmbasic.c) seems to be generated code but it's not clear where or how it was generated (specifically, what it was generated from). The rest of the code looks for the most part looks handwritten.


I read about this project when it came out. If I understand correctly, it's actually the original C64 implementation, decompiled into C. It's a really neat implementation.


Yes. From reading cbmbasic.c, I can see a couple of things clearly:

1) This code was generated by the LLVM C-backend (llvm_cbe), which converts LLVM IR to C code

2) The code contains variables for the 6502 registers.

This suggests it was generated by translating 6502 machine code to LLVM IR, and then converting the LLVM IR to C.


The structure of a loop around a big switch statement (based on value at PC) to blocks of code that manipulate the register variables (A, X, Y, PC, etc) and RAM looks exactly like an emulator core.

The code also appears to include the Commodore BASIC ROM. (See initialization of llvm_cbe_ROM in cbmbasic.c).

So, it looks like an emulator that was written in some other language then converted to C using the LLVM C backend.


I see. I guessed from the llvm prefixes everywhere it had something to do with llvm ir, I just am merely aware of llvm ir but don't use it personally.


Interesting, but curious, are there legality issues here or is the binary safely considered abandonware at this point? (I mean it is for the most part).


The C64 ROM has been included in emulators without restrictions for the last 20-30 years. So I think anyone claiming copyright now would have an uphill battle.

It's a completely different situation than for Amiga ROMs, for some reason.


The Amiga IP was always under some form of active management following CBMs fall. First Escom AG in Germany, then Gateway, Amino developments and then finally Cloanto. AmigaOS was/is also under active development by Hyperion entertainment. I've excluded quite a lot of twists and turns but the sum is that AmigaOS was always under active ownership and development.

While the Amiga was actively worked on nobody really cared about the 8-bit stuff. The Commodore name and trademark was not actually included in the IP package, it went to Tulip Computers in the Netherlands. From there it went on to Yeahronimo ventures and then into C= holdings.

The patents and copyrights were always in the big IP package passed around but since there was no real money in dead 8-bit stuff nobody actively enforced the rights on those ROMs. As such I think it would be hard for anybody today to start trying to enforce the IP rights on the 8-bit ROMs, they are so widely spread, distributed and used.

All the IP rights (except the Commodore name and trademark) is now owned and managed by Cloanto. You can buy legal copies of all the ROMs and software from them, they also seem very amenable to make deals with makers of retro computers etc.


> As such I think it would be hard for anybody today to start trying to enforce the IP rights on the 8-bit ROMs, they are so widely spread, distributed and used.

IANAL, but while you can lose a trademark through non-enforcement, I don't believe the same applies to copyrights. Turning a blind eye to infringement, even for years on end, doesn't necessarily prevent an attempt to go after it in the future.

> All the IP rights (except the Commodore name and trademark) is now owned and managed by Cloanto. You can buy legal copies of all the ROMs and software from them, they also seem very amenable to make deals with makers of retro computers etc.

I don't know who owns Cloanto. But even if its current owner(s) are nice and friendly people – it could end up being owned by someone else in the future who is more focused on extracting as much money as possible (like what happened to Unix with the SCO saga). Maybe the current owner(s) go bankrupt, pass away, fall on hard times, etc, and the business ends up being sold to someone only interested in maximising their return at any cost.


If you want BASIC as a scripting language, and VB isn't the answer, then you can get the remarkably capable BBC BASIC for many platforms for not much money at http://www.bbcbasic.co.uk/bbcbasic.html.

A couple of years ago I got an software exception request (regulated industry...don't ask) from a developer who wanted permission to use this. No one had any idea what to make of it, so it bubbled up to me. Turns out the developer was British, started out on BBC BASIC, and even though nothing in the app was BASIC, he'd written an amazingly comprehensive testing scaffold in it. I granted the request on the condition that they train at least 2 other devs to maintain it. It was impressive enough I bought my own copy and used it for various scripting tasks on Windows until PowerShell became what the cool kids used.


I love this. I got my start programming in BASIC on my C64 at the ripe old age of 6. While something like this has little practical value, it certainly provides a lot of nostalgia for someone like me.


Last updated in 2014... should it have 2014 in the headline?

This is kind of neat, OP what interested you about it to submit it?


I originally submitted it a while ago and it failed to attract attention. I received a note from HN inviting me to resubmit so I did. I love it. I learned to program the VIC-20 before I could properly speak English. The experience is so embedded in my psyche that I couldn't NOT re/post this.


But can we POKE in it? :)


Might very well be a better solution for writing software than bash, which seems to be the trend lately.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: