Live data from Hacker News

Code Golfing in Commodore BASIC

imrannazar.com

11–20 of 42 posts

Re: Code Golfing in Commodore BASIC

#11
post #7
post #5

Using line number 1 instead of 10 seems like an easy 1 byte save.

they're stored as 16 bit little-endian word, so unless it's used for goto/gosub (whose targets are stored in petscii) the line number makes no difference.

Are they stored as 16 bit words before or after parsing the BASIC code?

Re: Code Golfing in Commodore BASIC

#12
Back in the 80s when type-in program magazines were common, in France we had the wonderful "Hebdogiciel" with a perpetually running BASIC programming contest called "deulignes" -- which means "twolines".

"Deulignes" programs could target any platform, but must only take 2 lines of BASIC (most implementations allow only a limited line length, often 255 characters).

Some programs were really impressive; I remember one complete breakout implementation in MSX-BASIC for instance. People actually made whole (small) games in 2 lines of BASIC!

Here's an example page : https://archive.org/details/hebdogiciel-french-098/page/n15/...

Re: Code Golfing in Commodore BASIC

#13
post #2

https://gkanold.wixsite.com/homeputerium/games-list-2023 Games written in ten lines of vintage BASIC. (Not related to the article but its title.)

^^^ An excellent event, which I hope more HN'ers will check out!

(If you're in Vienna, Austria, you can go to the Retro Gaming Museum and see the winning entries on a real computer, in person..)

Re: Code Golfing in Commodore BASIC

#15
post #12

Back in the 80s when type-in program magazines were common, in France we had the wonderful "Hebdogiciel" with a perpetually running BASIC programming contest called "deulignes" -- which means "twolines". "Deulignes" programs could target any platform, but must only take 2 lines of BASIC (most implementations allow only a limited line length, often 255 characters). Some programs were really impressive; I remember one…

In a roundabout way BASIC on those machines is like modern high-level languages.

Slow and inefficient for sure, but most of the magic is happening directly at the hardware level (sprites, memory-mapped IO, etc.), so there's a surprisingly large amount of stuff you can do with very acceptable performance.

Re: Code Golfing in Commodore BASIC

#16
post #12

Back in the 80s when type-in program magazines were common, in France we had the wonderful "Hebdogiciel" with a perpetually running BASIC programming contest called "deulignes" -- which means "twolines". "Deulignes" programs could target any platform, but must only take 2 lines of BASIC (most implementations allow only a limited line length, often 255 characters). Some programs were really impressive; I remember one…

+1 for mentionning the best (objectively :-) ) computer magazine of all time (in french, that is).

Et les dessins de Carali...

Re: Code Golfing in Commodore BASIC

#17
post #11
post #7

Earlier quoted context omitted.

they're stored as 16 bit little-endian word, so unless it's used for goto/gosub (whose targets are stored in petscii) the line number makes no difference.

Are they stored as 16 bit words before or after parsing the BASIC code?

The BASIC code is only in it's full textual form on screen. The moment you press return on it, it's tokenized, and it's stored tokenized both in memory and when saved. Unlike modern systems, the full textual representation of the code is never stored anywhere.

Re: Code Golfing in Commodore BASIC

#18
post #9

Earlier quoted context omitted.

Doesn’t BASIC tokenize those abbreviations to the exact same in-memory bytes like the full keywords?

Yes it does but the amount of bytes the author speaks about regards the amount of characters used for storing the program. That's why he uses the : and removes the spaces.

The stored version also uses token code points (single bytes >127), not literal tokens.

Re: Code Golfing in Commodore BASIC

#19
post #12

Back in the 80s when type-in program magazines were common, in France we had the wonderful "Hebdogiciel" with a perpetually running BASIC programming contest called "deulignes" -- which means "twolines". "Deulignes" programs could target any platform, but must only take 2 lines of BASIC (most implementations allow only a limited line length, often 255 characters). Some programs were really impressive; I remember one…

Do you think you'd be able to find that 2 line breakout? I'm currently doing a breakout implementation on my Commodore 64. In assembly though, so definitely more than two lines ;-) Nevertheless, a two line breakout in Basic would probably give lots of pointers on how to make things more compact.

Re: Code Golfing in Commodore BASIC

#20

I don't know anything about C64 or C64 BASIC, but would it be possible to intentionally write a shorter binary which will break the interpreter and do what we want instead? For example jump directly to a middle of the kernel ROM routine (akin to ROP in the modern days), or use a bad address in the "next line" offset etc.

In Commodore BASIC there's already SYS, which lets you jump to an arbitrary address anywhere in the 64k address space, including ROM. You can even include raw bytes in a BASIC program and have the CPU execute them as machine code.
Post reply on HN