8 ms·
Commodore Basic as a Scripting Language
- burlesona 6y agoLast updated in 2014... should it have 2014 in the headline? This is kind of neat, OP what interested you about it to submit it?
- harel 6y agoI 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.
- deleted 6y ago[deleted]
- deleted 6y ago[deleted]
- noobermin 6y agoThe 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.
- lokedhs 6y agoI 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.
- skissane 6y agoYes. 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.
- noobermin 6y agoI 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.
- bdowling 6y agoThe 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.
- noobermin 6y agoInteresting, 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).
- bni 6y agoThe 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.
- herio 6y agoThe 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.
- skissane 6y ago> 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.
- abiogenesis 6y agohttps://github.com/mist64/cbmbasic/blob/master/runtime.c 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.
- classichasclass 6y agoIt'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 https://www.pagetable.com/?p=774 for the routine in its entirety.
- AlbertoGP 6y agoWow, 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!
- jwr 6y agoMight very well be a better solution for writing software than bash, which seems to be the trend lately.
- hnlmorg 6y agoWhile 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/ 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.
- tssva 6y agoTechnically it does support functions. They are just extremely limited.
- hnlmorg 6y ago"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 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?
- tssva 6y agoApplesoft 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.
- pharaohgeek 6y agoI 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.
- tenebrisalietum 6y agoInteresting. 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.
- ivanhoe 6y agoBut can we POKE in it? :)
- kjs3 6y agoIf 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 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.