雅达利2600 BASIC编程 (2015)
Atari 2600 BASIC Programming (2015)

原始链接: https://huguesjohnson.com/programming/atari-2600-basic/

## Atari 2600 BASIC:极度限制下的编程 作者进行了一项极具挑战性的实验:在 Atari 2600 BASIC 系统下编程,该系统因硬件限制而功能严重受限。程序最多只能包含 64 个符号(数字、变量、关键字),最多 9 行代码,仅提供基本的数学函数和简陋的图形——两个可移动的点和简单的蜂鸣声。 尽管存在这些限制,作者发现这项练习出乎意料地引人入胜,这源于最初的解释器本身仅占用 64 字节的内存。使用原始硬件证明了令人沮丧,但带有触摸屏键盘支持的 Nintendo DS 模拟器提供了一种令人惊讶的可用体验。 作者通过“推文大小”的程序分享他们的作品,包括一个基本的点移动程序和一个荒谬简单的“足球模拟器”。他们还成功地在限制范围内实现了诸如欧几里得 GCD 和中点/斜率计算之类的算法。甚至可以实现一个简陋的 Model-View-Controller 模式。虽然诸如素数确定或十六进制转换之类的任务被证明是不可能的,但该项目突出了在如此极端的限制下编程所需的创造力,并提供了对现代编程便利性的独特视角。

黑客新闻 新的 | 过去的 | 评论 | 提问 | 展示 | 工作 | 提交 登录 雅达利2600 BASIC编程 (2015) (huguesjohnson.com) 6点 由 mondobe 1小时前 | 隐藏 | 过去的 | 收藏 | 1评论 帮助 kstrauser 5分钟前 [–] 这是我的第一台“电脑”!在尝到Vic 20的味道后,我乞求父母给我买了这个,想自己也拥有一个。那是个不成功的开始,至少可以说是这样。64字节能做的事情不多。之后,我乞求要一台Timex Sinclair 1000。16KB的RAM也不多,但足以进行实验和学习。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文
"You need a more mentally challenging job"

This was a friend's reaction when I told him about this article idea. Like most people he wasn't intimately familiar with Atari 2600 BASIC so this response followed my explanation of the limitations:

-Your entire program can not exceed 64 symbols - a symbol being a number, variable, or reserved word (i.e. Goto, If, Then)
-There's a maximum of 9 lines, not really an issue considering the first item
-You only get integers from 0-99
-Only five math functions are available (+,-,*,÷,mod)
-In terms of graphics, you have two dots you can move by setting their coordinates
-You can play a range of beeps but I'm not musically inclined so I can't map them to notes
-Instead of a keyboard you have two 12 button pads to work with

If this sounds horribly limited and lame it's because you haven't yet thought about the hardware it's running on...

Atari 2600 BASIC was programmed by Warren Robinett who is 100x smarter than me and anyone reading this. Well, unless you are him in which case "Hi! Adventure is the greatest Atari 2600 game ever made!". Anyway, since you're probably not him it'll hurt your brain to think about how difficult it was to write a BASIC interpreter for the Atari 2600 that consumed just 64 bytes of memory. Not gigabytes, not megabytes, not even kilobytes - 64 bytes. The Atari 2600 had 128 bytes of RAM and half of that was used for the 64 symbol program you entered so the IDE and interpreter had to be extremely lean.

You should now be in awe of this program.

Not quite as challenging is writing a useful program in just 64 symbols but that's exactly what I'm going to attempt. Think of all those times you tried to cram your thoughts into a 140 character tweet. Now take away 76 characters and try writing a functional program instead of a description of the burrito you just ate.

Before I get to that though, here's a little more back-story which you're free to skip...

I own all the pieces required to run this on the original hardware - Atari 2600, BASIC Programming cartridge, and keypad controllers. Setting all this up and using the original controllers is an exercise in frustration. The 24 keys you get on the two keypads aren't enough so there's a toggle system to shuffle between key sets. If that description sounds confusing it's because, well, it's really confusing.

Even using an emulator like Stella is painful, arguably more painful than the old-school approach. What works amazingly well though is the version that was included on Atari's Greatest Hits Volume 2 for the Nintendo DS. Some madman actually took the time to emulate the dual keypads on the DS touchscreen:

Emulated keypad on the Nintendo DS

It had to be a lot of work to accomplish this and it's sad to think that I'm probably the only person on earth who used it for more than 30 seconds. If you ever feel insane enough to try Atari 2600 BASIC Programming this is definitely the way to go.

The downside to doing this on the DS is that the screenshots look terrible. See how they compare to taking a snapshot in Stella:

Screenshot comparison

So you're not going to get a lot of pictures. It's just text and dots anyway, you're not missing much.

Alright, on to the programs. I'm not going to include a tutorial or the sample programs from the manual, those are perfectly findable on the Google.

Let's start with something simple, moving one of the dots around with the keypad:

1 If Key=2 Then Ver1←Ver1-5
2 If Key=4 Then Hor1←Hor1-5
3 If Key=6 Then Hor1←Hor1+5
4 If Key=8 Then Ver1←Ver1+5
5 Goto 1


Although that only uses five lines it exhausts nearly all available symbols which obviously limits the gaming possibilities.

If my previous comment about Twitter and burritos wasn't transparent enough I'll cut directly to the chase - I have a very difficult time imagining a practical use for Twitter. As far as I can tell the main purpose is to feed people's sense of self-importance. It's the modern equivalent of covering your car with bumper stickers.

However, this experiment has led me to an almost worthwhile application - sharing Atari 2600 BASIC programs. In any programming language it's an interesting challenge to fit an entire functional program into under 140 characters. The challenge is increased further by preserving space to support # and @ tags. Since Atari 2600 BASIC programs are limited to 64 symbols they will almost always fit into a tweet. The only tricky part is that many of the Atari 2600 BASIC symbols are comprised of multiple characters, i.e. "Goto" is one symbol but four characters. That's OK, we can abbreviate these without changing the functionality of the program.

For example, here's the dot moving program in tweet form:


With controller options highly limited I could only come up with one complete game. I call it "The World's Worst Football Simulator". Specifically, it's simulating the experience of Devin Hester trying to get past the punter on a kick return:

1 S←0
2 Hor2←90, Ver2←0
3 Hor1←0, Ver1←50
4 Ver2←Ver2+1
5 If (Key>0) Then Hor1←Hor1+1
6 If Hit Then Goto 3
7 If Hor1<95 Then Goto 4
8 S←S+1, Note←90
9 Goto 3




Let's move over to some common math programs that you'd probably have to tackle in your first week of CS 101.

First up is an implementation of Euclid's Algorithm for computing greatest common divisor complete with animations and sound:

1 Ver1←0, Ver2←9
2 Hor1←50, Hor2←30
3 If (Hor2=0) Then Goto 8
4 T←Hor2
5 Hor2←Hor1 Mod Hor2
6 Hor1←T
7 Goto 3
8 Print Hor1, Note←Hor1

This also fits into a tweet with a bit-o-crunching:


Finding the midpoint and slope of a line is totally doable with room to spare:

1 Hor1←5, Hor2←10
2 Ver1<20, Ver2←60
3 X←(Hor1+Hor2)÷2
4 Y←(Ver1+Ver2)÷2
5 Print X, Print Y
6 S←(Ver2-Ver1)÷(Hor2-Hor1)
7 Print S

And the tweet version goes a little something like this:


And for all you software architect types, here's the smallest working implementation of the Model-View-Controller (MVC) design pattern ever produced (that I'm aware of):

1 M←Key
2 If (M=0) Then Goto 1
3 Hor1←Hor1+M
4 Goto 1

It's even smaller as a tweet:



To wrap things up, here are a few ideas I thought of that aren't possible to implement, or maybe are by someone smarter than me:

-Decimal to hex conversion - I tried about four different approaches and none were close to fitting.
-Computing Pi to any digits - there are several methods and all require operations that aren't available, even the ol' 22/7 solution is no good because that will just return 3
-Determining whether a number is prime - similar issues to computing Pi, probably doable for numbers under 10 though.
-Any of the Beagle Bros "two-liners", Apple II fans will know what I'm talking about.



Related



All source code and software on this site is distributed under The MIT License (copyright 2000-2026 Hugues Johnson) unless otherwise noted.

All other content on this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License unless otherwise noted.

All opinions on this site reflect my personal views and do not represent views of my current, or any former, employer.

Site theme is based on Bootstrap licensed under The MIT License. Site font is Ubuntu licensed under Ubuntu Font License. Navigation logo font is Audiowide licensed under Open Font License.

This site does not contain advertisements or sponsored content. I am not remotely interested in either so don't ask.

Privacy policy: I don't care even a little about who visits this site. The content delivery network I use collects semi-identifiable information like user agent and IP address. I use this data to detect malicious traffic and problematic bots. I do not share or sell any usage or traffic data. This site does not use cookies.

联系我们 contact @ memedata.com