mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
Translated
最终翻译完成了,但是感觉翻译的不好。根据这篇文章的英语语法和习惯和平常的很不一样
This commit is contained in:
parent
81a4caf055
commit
f2ebdc374e
@ -1,185 +0,0 @@
|
|||||||
Translating by robsean
|
|
||||||
Learning BASIC Like It's 1983
|
|
||||||
======
|
|
||||||
I was not yet alive in 1983. This is something that I occasionally regret. I am especially sorry that I did not experience the 8-bit computer era as it was happening, because I think the people that first encountered computers when they were relatively simple and constrained have a huge advantage over the rest of us.
|
|
||||||
|
|
||||||
Today, (almost) everyone knows how to use a computer, but very few people, even in the computing industry, grasp all of what is going on inside of any single machine. There are now [so many layers of software][1] doing so many different things that one struggles to identify the parts that are essential. In 1983, though, home computers were unsophisticated enough that a diligent person could learn how a particular computer worked through and through. That person is today probably less mystified than I am by all the abstractions that modern operating systems pile on top of the hardware. I expect that these layers of abstractions were easy to understand one by one as they were introduced; today, new programmers have to try to understand them all by working top to bottom and backward in time.
|
|
||||||
|
|
||||||
Many famous programmers, particularly in the video game industry, started programming games in childhood on 8-bit computers like the Apple II and the Commodore 64. John Romero, Richard Garriott, and Chris Roberts are all examples. It’s easy to see how this happened. In the 8-bit computer era, many games were available only as printed BASIC listings in computer magazines and [books][2]. If you wanted to play one of those games, you had to type in the whole program by hand. Inevitably, you would get something wrong, so you would have to debug your program. By the time you got it working, you knew enough about how the program functioned to start modifying it yourself. If you were an avid gamer, you became a good programmer almost by necessity.
|
|
||||||
|
|
||||||
I also played computer games throughout my childhood. But the games I played came on CD-ROMs. I sometimes found myself having to google how to fix a crashing installer, which would involve editing the Windows Registry or something like that. This kind of minor troubleshooting may have made me comfortable enough with computers to consider studying computer science in college. But it never taught me anything crucial about how computers worked or how to control them.
|
|
||||||
|
|
||||||
Now, of course, I tell computers what to do for a living. All the same, I can’t help feeling that I missed out on some fundamental insight afforded only to those that grew up programming simpler computers. What would it have been like to encounter computers for the first time in the early 1980s? How would that have been different from the experience of using a computer today?
|
|
||||||
|
|
||||||
This post is going to be a little different from the usual Two-Bit History post because I’m going to try to imagine an answer to these questions.
|
|
||||||
|
|
||||||
### 1983
|
|
||||||
|
|
||||||
It was just last week that you saw [the Commodore 64 ad][3] on TV. Now that M*A*S*H was over, you were in the market for something new to do on Monday nights. This Commodore 64 thing looked even better than the Apple II that Rudy’s family had in their basement. Plus, the ad promised that the new computer would soon bring friends “knocking down” your door. You knew several people at school that would rather be hanging out at your house than Rudy’s anyway, if only they could play Zork there.
|
|
||||||
|
|
||||||
So you persuaded your parents to buy one. Your mother said that they would consider it only if having a home computer meant that you stayed away from the arcade. You reluctantly agreed. Your father thought he would start tracking the family’s finances in MultiPlan, the spreadsheet program he had heard about, which is why the computer got put in the living room. A year later, though, you would be the only one still using it. You were finally allowed to put it on the desk in your bedroom, right under your Police poster.
|
|
||||||
|
|
||||||
(Your sister protested this decision, but it was 1983 and computers [weren’t for her][4].)
|
|
||||||
|
|
||||||
Dad picked it up from [ComputerLand][5] on the way home from work. The two of you laid the box down next to the TV and opened it. “WELCOME TO THE WORLD OF FRIENDLY COMPUTING,” said the packaging. Twenty minutes later, you weren’t convinced—the two of you were still trying to connect the Commodore to the TV set and wondering whether the TV’s antenna cable was the 75-ohm or 300-ohm coax type. But eventually you were able to turn your TV to channel 3 and see a grainy, purple image.
|
|
||||||
|
|
||||||
![Commodore 64 startup screen][6]
|
|
||||||
|
|
||||||
`READY`, the computer reported. Your father pushed the computer toward you, indicating that you should be the first to give it a try. `HELLO`, you typed, carefully hunting for each letter. The computer’s response was baffling.
|
|
||||||
|
|
||||||
![Commodore 64 syntax error][7]
|
|
||||||
|
|
||||||
You tried typing in a few different words, but the response was always the same. Your father said that you had better read through the rest of the manual. That would be no mean feat—[the manual that came with the Commodore 64][8] was a small book. But that didn’t bother you, because the introduction to the manual foreshadowed wonders.
|
|
||||||
|
|
||||||
The Commodore 64, it claimed, had “the most advanced picture maker in the microcomputer industry,” which would allow you “to design your own pictures in four different colors, just like the ones you see on arcade type video games.” The Commodore 64 also had “built-in music and sound effects that rival many well known music synthesizers.” All of these tools would be put in your hands, because the manual would walk you through it all:
|
|
||||||
|
|
||||||
> Just as important as all the available hardware is the fact that this USER’S GUIDE will help you develop your understanding of computers. It won’t tell you everything there is to know about computers, but it will refer you to a wide variety of publications for more detailed information about the topics presented. Commodore wants you to really enjoy your new COMMODORE 64. And to have fun, remember: programming is not the kind of thing you can learn in a day. Be patient with yourself as you go through the USER’S GUIDE.
|
|
||||||
|
|
||||||
That night, in bed, you read through the entire first three chapters—”Setup,” “Getting Started,” and “Beginning BASIC Programming”—before finally succumbing to sleep with the manual splayed across your chest.
|
|
||||||
|
|
||||||
### Commodore BASIC
|
|
||||||
|
|
||||||
Now, it’s Saturday morning and you’re eager to try out what you’ve learned. One of the first things the manual teaches you how to do is change the colors on the display. You follow the instructions, pressing `CTRL-9` to enter reverse type mode and then holding down the space bar to create long lines. You swap between colors using `CTRL-1` through `CTRL-8`, reveling in your sudden new power over the TV screen.
|
|
||||||
|
|
||||||
![Commodore 64 color bands][9]
|
|
||||||
|
|
||||||
As cool as this is, you realize it doesn’t count as programming. In order to program the computer, you learned last night, you have to speak to it in a language called BASIC. To you, BASIC seems like something out of Star Wars, but BASIC is, by 1983, almost two decades old. It was invented by two Dartmouth professors, John Kemeny and Tom Kurtz, who wanted to make computing accessible to undergraduates in the social sciences and humanities. It was widely available on minicomputers and popular in college math classes. It then became standard on microcomputers after Bill Gates and Paul Allen wrote the MicroSoft BASIC interpreter for the Altair. But the manual doesn’t explain any of this and you won’t learn it for many years.
|
|
||||||
|
|
||||||
One of the first BASIC commands the manual suggests you try is the `PRINT` command. You type in `PRINT "COMMODORE 64"`, slowly, since it takes you a while to find the quotation mark symbol above the `2` key. You hit `RETURN` and this time, instead of complaining, the computer does exactly what you told it to do and displays “COMMODORE 64” on the next line.
|
|
||||||
|
|
||||||
Now you try using the `PRINT` command on all sorts of different things: two numbers added together, two numbers multiplied together, even several decimal numbers. You stop typing out `PRINT` and instead use `?`, since the manual has advised you that `?` is an abbreviation for `PRINT` often used by expert programmers. You feel like an expert already, but then you remember that you haven’t even made it to chapter three, “Beginning BASIC Programming.”
|
|
||||||
|
|
||||||
You get there soon enough. The chapter begins by prompting you to write your first real BASIC program. You type in `NEW` and hit `RETURN`, which gives you a clean slate. You then type your program in:
|
|
||||||
|
|
||||||
```
|
|
||||||
10 ?"COMMODORE 64"
|
|
||||||
20 GOTO 10
|
|
||||||
```
|
|
||||||
|
|
||||||
The 10 and the 20, the manual explains, are line numbers. They order the statements for the computer. They also allow the programmer to refer to other lines of the program in certain commands, just like you’ve done here with the `GOTO` command, which directs the program back to line 10. “It is good programming practice,” the manual opines, “to number lines in increments of 10—in case you need to insert some statements later on.”
|
|
||||||
|
|
||||||
You type `RUN` and stare as the screen clogs with “COMMODORE 64,” repeated over and over.
|
|
||||||
|
|
||||||
![Commodore 64 showing result of printing "Commodore 64" repeatedly][10]
|
|
||||||
|
|
||||||
You’re not certain that this isn’t going to blow up your computer. It takes you a second to remember that you are supposed to hit the `RUN/STOP` key to break the loop.
|
|
||||||
|
|
||||||
The next few sections of the manual teach you about variables, which the manual tells you are like “a number of boxes within the computer that can each hold a number or a string of text characters.” Variables that end in a `%` symbol are whole numbers, while variables ending in a `$` symbol are strings of characters. All other variables are something called “floating point” variables. The manual warns you to be careful with variable names because only the first two letters of the name are actually recognized by the computer, even though nothing stops you from making a name as long as you want it to be. (This doesn’t particularly bother you, but you could see how 30 years from now this might strike someone as completely insane.)
|
|
||||||
|
|
||||||
You then learn about the `IF... THEN...` and `FOR... NEXT...` constructs. With all these new tools, you feel equipped to tackle the next big challenge the manual throws at you. “If you’re the ambitious type,” it goads, “type in the following program and see what happens.” The program is longer and more complicated than any you have seen so far, but you’re dying to know what it does:
|
|
||||||
|
|
||||||
```
|
|
||||||
10 REM BOUNCING BALL
|
|
||||||
20 PRINT "{CLR/HOME}"
|
|
||||||
25 FOR X = 1 TO 10 : PRINT "{CRSR/DOWN}" : NEXT
|
|
||||||
30 FOR BL = 1 TO 40
|
|
||||||
40 PRINT " ●{CRSR LEFT}";:REM (● is a Shift-Q)
|
|
||||||
50 FOR TM = 1 TO 5
|
|
||||||
60 NEXT TM
|
|
||||||
70 NEXT BL
|
|
||||||
75 REM MOVE BALL RIGHT TO LEFT
|
|
||||||
80 FOR BL = 40 TO 1 STEP -1
|
|
||||||
90 PRINT " {CRSR LEFT}{CRSR LEFT}●{CRSR LEFT}";
|
|
||||||
100 FOR TM = 1 TO 5
|
|
||||||
110 NEXT TM
|
|
||||||
120 NEXT BL
|
|
||||||
130 GOTO 20
|
|
||||||
```
|
|
||||||
|
|
||||||
The program above takes advantage of one of the Commodore 64’s coolest features. Non-printable command characters, when passed to the `PRINT` command as part of a string, just do the action they usually perform instead of printing to the screen. This allows you to replay arbitrary chains of commands by printing strings from within your programs.
|
|
||||||
|
|
||||||
It takes you a long time to type in the above program. You make several mistakes and have to re-enter some of the lines. But eventually you are able to type `RUN` and behold a masterpiece:
|
|
||||||
|
|
||||||
![Commodore 64 bouncing ball][11]
|
|
||||||
|
|
||||||
You think that this is a major contender for the coolest thing you have ever seen. You forget about it almost immediately though, because once you’ve learned about BASIC’s built-in functions like `RND` (which returns a random number) and `CHR$` (which returns the character matching a given number code), the manual shows you a program that many years from now will still be famous enough to be made the title of an [essay anthology][12]:
|
|
||||||
|
|
||||||
```
|
|
||||||
10 PRINT "{CLR/HOME}"
|
|
||||||
20 PRINT CHR$(205.5 + RND(1));
|
|
||||||
40 GOTO 20
|
|
||||||
```
|
|
||||||
|
|
||||||
When run, the above program produces a random maze:
|
|
||||||
|
|
||||||
![Commodore 64 maze program][13]
|
|
||||||
|
|
||||||
This is definitely the coolest thing you have ever seen.
|
|
||||||
|
|
||||||
### PEEK and POKE
|
|
||||||
|
|
||||||
You’ve now made it through the first four chapters of the Commodore 64 manual, including the chapter titled “Advanced BASIC,” so you’re feeling pretty proud of yourself. You’ve learned a lot this Saturday morning. But this afternoon (after a quick lunch break), you’re going to learn something that will make this magical machine in your living room much less mysterious.
|
|
||||||
|
|
||||||
The next chapter in the manual is titled “Advanced Color and Graphic Commands.” It starts off by revisiting the colored bars that you were able to type out first thing this morning and shows you how you can do the same thing from a program. It then teaches you how to change the background colors of the screen.
|
|
||||||
|
|
||||||
In order to do this, you need to use the BASIC `PEEK` and `POKE` commands. Those commands allow you to, respectively, examine and write to a memory address. The Commodore 64 has a main background color and a border color. Each is controlled by a specially designated memory address. You can write any color value you would like to those addresses to make the background or border that color.
|
|
||||||
|
|
||||||
The manual explains:
|
|
||||||
|
|
||||||
> Just as variables can be thought of as a representation of “boxes” within the machine where you placed your information, you can also think of some specially defined “boxes” within the computer that represent specific memory locations.
|
|
||||||
>
|
|
||||||
> The Commodore 64 looks at these memory locations to see what the screen’s background and border color should be, what characters are to be displayed on the screen—and where—and a host of other tasks.
|
|
||||||
|
|
||||||
You write a program to cycle through all the available combinations of background and border color:
|
|
||||||
|
|
||||||
```
|
|
||||||
10 FOR BA = 0 TO 15
|
|
||||||
20 FOR BO = 0 TO 15
|
|
||||||
30 POKE 53280, BA
|
|
||||||
40 POKE 53281, BO
|
|
||||||
50 FOR X = 1 TO 500 : NEXT X
|
|
||||||
60 NEXT BO : NEXT BA
|
|
||||||
```
|
|
||||||
|
|
||||||
While the `POKE` commands, with their big operands, looked intimidating at first, now you see that the actual value of the number doesn’t matter that much. Obviously, you have to get the number right, but all the number represents is a “box” that Commodore just happened to store at address 53280. This box has a special purpose: Commodore uses it to determine what color the screen’s background should be.
|
|
||||||
|
|
||||||
![Commodore 64 changing background colors][14]
|
|
||||||
|
|
||||||
You think this is pretty neat. Just by writing to a special-purpose box in memory, you can control a fundamental property of the computer. You aren’t sure how the Commodore 64’s circuitry takes the value you write in memory and changes the color of the screen, but you’re okay not knowing that. At least you understand everything up to that point.
|
|
||||||
|
|
||||||
### Special Boxes
|
|
||||||
|
|
||||||
You don’t get through the entire manual that Saturday, since you are now starting to run out of steam. But you do eventually read all of it. In the process, you learn about many more of the Commodore 64’s special-purpose boxes. There are boxes you can write to control what is on screen—one box, in fact, for every place a character might appear. In chapter six, “Sprite Graphics,” you learn about the special-purpose boxes that allow you to define images that can be moved around and even scaled up and down. In chapter seven, “Creating Sound,” you learn about the boxes you can write to in order to make your Commodore 64 sing “Michael Row the Boat Ashore.” The Commodore 64, it turns out, has very little in the way of what you would later learn is called an API. Controlling the Commodore 64 mostly involves writing to memory addresses that have been given special meaning by the circuitry.
|
|
||||||
|
|
||||||
The many years you ultimately spend writing to those special boxes stick with you. Even many decades later, when you find yourself programming a machine with an extensive graphics or sound API, you know that, behind the curtain, the API is ultimately writing to those boxes or something like them. You will sometimes wonder about younger programmers that have only ever used APIs, and wonder what they must think the API is doing for them. Maybe they think that the API is calling some other, hidden API. But then what do think that hidden API is calling? You will pity those younger programmers, because they must be very confused indeed.
|
|
||||||
|
|
||||||
If you enjoyed this post, more like it come out every two weeks! Follow [@TwoBitHistory][15] on Twitter or subscribe to the [RSS feed][16] to make sure you know when a new post is out.
|
|
||||||
|
|
||||||
Previously on TwoBitHistory…
|
|
||||||
|
|
||||||
> Have you ever wondered what a 19th-century computer program would look like translated into C?
|
|
||||||
>
|
|
||||||
> This week's post: A detailed look at how Ada Lovelace's famous program worked and what it was trying to do.<https://t.co/BizR2Zu7nt>
|
|
||||||
>
|
|
||||||
> — TwoBitHistory (@TwoBitHistory) [August 19, 2018][17]
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://twobithistory.org/2018/09/02/learning-basic.html
|
|
||||||
|
|
||||||
作者:[Two-Bit History][a]
|
|
||||||
选题:[lujun9972][b]
|
|
||||||
译者:[译者ID](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]: https://twobithistory.org
|
|
||||||
[b]: https://github.com/lujun9972
|
|
||||||
[1]: https://www.youtube.com/watch?v=kZRE7HIO3vk
|
|
||||||
[2]: https://en.wikipedia.org/wiki/BASIC_Computer_Games
|
|
||||||
[3]: https://www.youtube.com/watch?v=ZekAbt2o6Ms
|
|
||||||
[4]: https://www.npr.org/sections/money/2014/10/21/357629765/when-women-stopped-coding
|
|
||||||
[5]: https://www.youtube.com/watch?v=MA_XtT3VAVM
|
|
||||||
[6]: https://twobithistory.org/images/c64_startup.png
|
|
||||||
[7]: https://twobithistory.org/images/c64_error.png
|
|
||||||
[8]: ftp://www.zimmers.net/pub/cbm/c64/manuals/C64_Users_Guide.pdf
|
|
||||||
[9]: https://twobithistory.org/images/c64_colors.png
|
|
||||||
[10]: https://twobithistory.org/images/c64_print_loop.png
|
|
||||||
[11]: https://twobithistory.org/images/c64_ball.gif
|
|
||||||
[12]: http://10print.org/
|
|
||||||
[13]: https://twobithistory.org/images/c64_maze.gif
|
|
||||||
[14]: https://twobithistory.org/images/c64_background.gif
|
|
||||||
[15]: https://twitter.com/TwoBitHistory
|
|
||||||
[16]: https://twobithistory.org/feed.xml
|
|
||||||
[17]: https://twitter.com/TwoBitHistory/status/1030974776821665793?ref_src=twsrc%5Etfw
|
|
184
translated/tech/20180902 Learning BASIC Like It-s 1983.md
Normal file
184
translated/tech/20180902 Learning BASIC Like It-s 1983.md
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
学习 BASIC 像它的1983年
|
||||||
|
======
|
||||||
|
我没有生活在1983年.我偶尔有一些遗憾。我相当遗憾,我没有体验8位计算机时代的到来,因为我认为第一次遇到相对简单和过于受约束的计算机的人们,有超过我们的一些人的巨大的优势。
|
||||||
|
|
||||||
|
今天,(大多数)每个人知道如何使用一台计算机,但是很少有人,甚至是在计算机工业中,明白在一些单台机器内部正在发生什么的全部。现在有[如此多软件层次][1]努力来识别必不可少的部分来做如此多不同的事情。在1983年,虽然,家用电脑足够简单,一个用功的人能学到一台特定计算机是如何工作的。现在这人可能比我通过所有堆积在硬件顶部的现代操作系统的抽象概念较少迷惑。我认为像他们采用的这些抽象概念的层次是容易一个接一个理解的;今天,新的程序员不得不通过自上而下的逆流时间上的工作来尝试理解它们。
|
||||||
|
|
||||||
|
很多著名的程序员,尤其在计算机游戏工业,童年在8位计算机上开始编程游戏,像,苹果 II 和 Commodore 64。John Romero, Richard Garriott,和 Chris Roberts 都是例子。如何发生是容易看到的。在8位计算机时代,很多游戏仅可在计算机杂质和[书籍][2]中作为印刷的BASIC列表获得。如果你想玩这些游戏中其中一个,你不得手工不键入完整的程序。不可避免的,你可能得到一些错误,所以你可能不得不调试你的程序。等到你获得它工作, 你充分知道程序如何起作用来开始你自己修改它。如果你是一个着迷的游戏玩家,你不可避免地也成为一个好的程序员。
|
||||||
|
|
||||||
|
在童年我也玩电脑游戏。但是我玩的游戏在只读光盘上。我有时发现我自己不得不搜索如何修复一个崩溃的安装器,这可能涉及编辑 Windows 注册表或一些像这样的事情。这类少数的使用计算机来考虑在大学中学习计算机科学的故障诊断可能使我足够舒适。但是在大学中从不教我一些关键性的关于计算机如何工作或如何控制它们的事。
|
||||||
|
|
||||||
|
当然,现在我告诉计算机为了活动而做什么。尽管如此,我请不自觉地感到,我缺少一些基本的仅被给予这些成长为简单编程的计算机人的深刻见解。在20世纪80年代初,第一次偶然遇到计算机会是什么样子?与今天使用计算机的经验相比会有怎样的不同?
|
||||||
|
|
||||||
|
这篇张贴文将与通常的二位历史贴文有一点不同,因为我将为这些问题尝试设想一个答案。
|
||||||
|
|
||||||
|
### 1983
|
||||||
|
|
||||||
|
仅仅是上周,你在电视上看到 [Commodore 64 广告][3] ,现在 M*A*S*H 结束了,在星期一晚上,你正在市场上采购没做过的一些东西。这个 Commodore 64 甚至看起来比 Apple II 更好,鲁迪(译者注:应该是拥有 Apple II 的人)的家人在他们的地下室。而且,广告承诺新的计算机将一会携带朋友们“击倒”你的门。你知道一些在学校的人们只要他们能在这里玩 Zork,他们宁愿在你的家里过把瘾,也不愿呆在鲁迪的家里。
|
||||||
|
|
||||||
|
所以,你说服你的父母去买一台.你的妈妈说,她们可以考虑它,如果有一台家庭电脑,意味着你离开娱乐厅。你勉强同意。你的爸爸想,他可以开始在 MultiPlan (译注:电子表格程序)中跟踪家庭的资金。 MultiPlan 是他曾听到过的电子表格程序, 这是为什么计算机放在客厅的原因。然而,一年后,你将是唯一仍然使用它的人。你最终被允许把它放到你的卧室中的桌子上,正好在你的警察海报下面。
|
||||||
|
|
||||||
|
(你的姐姐抗议这个决定,但是,它是在1983年,并且计算机[不是给她][4]。)
|
||||||
|
|
||||||
|
父亲在从工作到回家的路上从 [ComputerLand][5] 处拿到它。你俩把盒子放置在电视机的旁边,并打开它。外包装上说“欢迎来到友好的计算机世界”。二十分钟以后,你不确信—你俩仍然试图来连接 Commodore 到电视机,并且想知道是否电视机的天线电缆是75欧姆或300欧姆同轴电缆。但是,你最终能够转到你的电视机到频道3,并看到一个粒状的,紫色的图像。
|
||||||
|
|
||||||
|
![Commodore 64 启动屏幕][6]
|
||||||
|
|
||||||
|
计算机报告,`READY`。你的爸爸把计算机推向你,标志着你应该第一个人来给它一个尝试。你小心翼翼地敲击每个字母,键入,`HELLO`。计算机的回应是令人困惑的。
|
||||||
|
|
||||||
|
![Commodore 64 语法错误][7]
|
||||||
|
|
||||||
|
你尝试输入一些很少变化的不同的单词,但是回应总是相同的。你的爸爸说,你最好通读手册的剩余部分。这可能不意味着是秘籍—[随 Commodore 64 一起提供的手册][8] 是一小本书。但是这不会困住你,因为手册的引进是奇迹的预兆。
|
||||||
|
|
||||||
|
Commodore 64,它声称,有“微型计算机工业中最高级的图画制作器”,能允许“设计你拥有四种不同颜色的图画,就像你在看到的街机电子游戏”。Commodore 64 也有“内置的音乐和声音效果,比得上很多著名的语言音响合成器”。所有的这些工具将被放到你的手上,因为手册将陪伴你贯穿它全部:
|
||||||
|
|
||||||
|
> 正像与所有可用的硬件重要一样,这本用户的指南将帮助你详尽阐述你的计算机的理解。它不会在这里告诉你有必要知道的关于计算机的任何事,但是它将谈及你到一个关于涉及的主题的详细情报方面的种类繁多的出版物。Commodore 希望你来真正地享受你的新 COMMODORE 64 。并且来玩得开心,记住:编程不是你能在一天内就学会的一种东西。你自己要有耐心,因为你将翻阅用户指南。
|
||||||
|
|
||||||
|
那一夜,在床上,你通读整个前三个章节—“安装”,“入门”,和“开始 BASIC 编程”—在最终抵挡不住睡意前,手册被交叉放在胸前。
|
||||||
|
|
||||||
|
### Commodore BASIC
|
||||||
|
|
||||||
|
现在是星期六早上,你急于尝试你已经学到的什么。手册教你如何做的第一件事是更改在显示器上的颜色。你仿效指令,按下 `CTRL-9` 来进入相反的情况的类型模式,然后拖住空格键来创建长行。你可以使用 `CTRL-1` 到 `CTRL-8` 在不同的颜色之间交换,在电视机屏幕上陶醉于你的突然的新的力量。
|
||||||
|
|
||||||
|
![Commodore 64 颜色带][9]
|
||||||
|
|
||||||
|
尽管这很酷,你意识到它不算为编程。为了编程计算机,你昨晚已经学到,你必须以一种称为 BASIC 的语言与计算机交谈。对于你,BASIC 看起来像星球大战外的一些东西,但是,到1983年,BASIC 大约二十年了。它由两位达特茅斯教授,John Kemeny 和 Tom Kurtz 发明,他们想让社会科学和人文科学中的本科生可访问计算机。它在微型计算机上是普遍地可用的,并流行在大学数学课中。在比尔盖茨和保罗艾伦为 Altair 编写 MicroSoft BASIC 解释器后,在微型计算机上变成标准。但是手册没有任何解释这个,并且你很多年不会学到它。
|
||||||
|
|
||||||
|
手册建议你尝试中的第一个 BASIC 命令是 `PRINT` 命令。你慢慢地键入 `PRINT "COMMODORE 64"`,因为你花费一点时间来在`2`按键上面找到引号符号。你单击 `RETURN` ,这一次,并不是抱怨,计算机准确地做你告诉它去做的事,并在下一行中显示 “COMMODORE 64” 。
|
||||||
|
|
||||||
|
现在你尝试在各种各样不同的东西上使用 `PRINT` 命令:两个数字加在一起,两个数字乘在一起,甚至几个十进制数字。你停止输入 `PRINT` ,并使用 `?` 代替,因为手册已经正式告知你 `?` 是 `PRINT` 的一个缩写,通常被专业程序员使用。你感觉已经像一个专家,不过你想起你还没有看“开始 BASIC 编程”的三个章节。
|
||||||
|
|
||||||
|
你不久达到目的。该章节开始催促你来写你的第一个真正的 BASIC 程序。你输入 `NEW` 并单击 `RETURN`,这给你一个干净黑板(slate)。然后你在其中输入你的程序:
|
||||||
|
|
||||||
|
```
|
||||||
|
10 ?"COMMODORE 64"
|
||||||
|
20 GOTO 10
|
||||||
|
```
|
||||||
|
|
||||||
|
手册解释,10和20是行号。它们为计算机排序语句。它们也允许程序员来引用在某系命令中程序的其它行,正像你已经完成的 `GOTO` 命令, 它监督程序回到行10。“它是好的编程惯例”,手册认为,“以10的增量来编号行—以备你以后需要插入一些语句”。
|
||||||
|
|
||||||
|
你输入 `RUN` ,并盯着用“COMMODORE 64”堵塞的屏幕 ,重复的一遍又一遍。
|
||||||
|
|
||||||
|
![Commodore 64 显示反复打印 "Commodore 64" 的结果][10]
|
||||||
|
|
||||||
|
你不确定这不会引爆你的计算机。它花费一秒钟才想起你应该单击 `RUN/STOP` 按键来打断循环。
|
||||||
|
|
||||||
|
手册接下来的一些部分教你变量,手册告诉你变量像“在计算机中许多的暗盒,它们每个可以容纳一个数字或一个文本字符的字符串”。以一个 `%` 符号结尾的变量是一个整数,与此同时,以一个 `$` 符号结尾的变量是一个字符字符串。其余的所有变量是一些称为“浮点”变量的东西。手册警告你小心变量名称,因为计算机仅识别变量名称的前两个字母,尽管不阻止你想要的名称长度。(这并不是特别困扰你,但是你可能看到今后30年,这可能打击一些人像彻底地精神失常一样)。
|
||||||
|
|
||||||
|
你接着学习 `IF... THEN...` 和 `FOR... NEXT...` 结构体。有所有的这些新的工具,你感觉有能力来解决的接下来的手册扔给你的大挑战。“如果你是有野心的人”,很好,“输入下面的程序,并查看会发生什么”。该程序比你目前已经看到的程序更长、更复杂,但是,你渴望知道它将做什么:
|
||||||
|
|
||||||
|
```
|
||||||
|
10 REM BOUNCING BALL
|
||||||
|
20 PRINT "{CLR/HOME}"
|
||||||
|
25 FOR X = 1 TO 10 : PRINT "{CRSR/DOWN}" : NEXT
|
||||||
|
30 FOR BL = 1 TO 40
|
||||||
|
40 PRINT " ●{CRSR LEFT}";:REM (● is a Shift-Q)
|
||||||
|
50 FOR TM = 1 TO 5
|
||||||
|
60 NEXT TM
|
||||||
|
70 NEXT BL
|
||||||
|
75 REM MOVE BALL RIGHT TO LEFT
|
||||||
|
80 FOR BL = 40 TO 1 STEP -1
|
||||||
|
90 PRINT " {CRSR LEFT}{CRSR LEFT}●{CRSR LEFT}";
|
||||||
|
100 FOR TM = 1 TO 5
|
||||||
|
110 NEXT TM
|
||||||
|
120 NEXT BL
|
||||||
|
130 GOTO 20
|
||||||
|
```
|
||||||
|
|
||||||
|
上面的程序利用 Commodore 64 最酷的特色之一。不可打印的命令字符,当传递到 `PRINT` 命令时,作为字符串的一部分,仅仅做它们通常执行的动作,而不是打印到屏幕。这允许你通过打印来自你程序中的字符串来重演任意的命令链。
|
||||||
|
|
||||||
|
输入上面的程序花费很长时间。你犯一些错误,并不得不重新输入一些行。但是,你最终能够输入 `RUN` ,并看见一个杰作:
|
||||||
|
|
||||||
|
![Commodore 64 反弹球][11]
|
||||||
|
|
||||||
|
你认为这是你见过的最酷的事是一个主要的竞争者。不过你几乎立即忘记它,因为一旦你已经学习 BASIC 的内置的函数,像 `RND` (它返回一个随机数字) 和 `CHR$` (它返回匹配一个给定数字的字符),手册向你展示一个很多年的程序,到现在仍然足够著名,能够成为一个[论文选集][12]的题目
|
||||||
|
|
||||||
|
```
|
||||||
|
10 PRINT "{CLR/HOME}"
|
||||||
|
20 PRINT CHR$(205.5 + RND(1));
|
||||||
|
40 GOTO 20
|
||||||
|
```
|
||||||
|
|
||||||
|
当运行时,上面的程序产生一个随机的迷宫:
|
||||||
|
|
||||||
|
![Commodore 64 迷宫程序][13]
|
||||||
|
|
||||||
|
这肯定是你曾经见过最酷的事。
|
||||||
|
|
||||||
|
### PEEK 和 POKE
|
||||||
|
|
||||||
|
你现在看过 Commodore 64 手册的前四章节,包含标题为“高级的 BASIC” 的章节, 所以你觉得你自己十分自豪。这个星期六早上,你已经学习很多东西。但是这个下午(在一个快速午餐打断后),你继续去学习一些东西,这将使这个在你的客厅中奇妙的机器变得更不神秘。
|
||||||
|
|
||||||
|
在手册中的下一个章节被标题为“高级颜色和图像命令”。以通过再次讨论颜色条开始,你能够输入我们这个早上的第一件事,并向你显示你如何能够从一个程序中做相同的事。然后它教你如何更改屏幕的背景颜色。
|
||||||
|
|
||||||
|
为此,你需要使用最简单的 `PEEK` 和 `POKE` 命令。这些命令分别允许你来检查和写到存储器地址。Commodore 64 有一个主要背景颜色和一个边界背景颜色。每个颜色通过一个特定的内存地址控制。你可以写任何你喜欢的这些地址的颜色值到背景颜色或边界颜色。
|
||||||
|
|
||||||
|
手册解释:
|
||||||
|
|
||||||
|
> 正像变量可以被认为在机器中的一种放置你的信息的表现形式,你也可以认为在计算机中代表特殊内存位置的一些特殊定义的“容器”。
|
||||||
|
>
|
||||||
|
> Commodore 64 寻找这些内存位置来查看屏幕的背景和边界应该是什么样的颜色,什么样的字符能够被显示在屏幕上—在哪里—很多其它的任务。
|
||||||
|
|
||||||
|
你写一个程序来循环所有可用的背景和边界的颜色的混合体:
|
||||||
|
|
||||||
|
```
|
||||||
|
10 FOR BA = 0 TO 15
|
||||||
|
20 FOR BO = 0 TO 15
|
||||||
|
30 POKE 53280, BA
|
||||||
|
40 POKE 53281, BO
|
||||||
|
50 FOR X = 1 TO 500 : NEXT X
|
||||||
|
60 NEXT BO : NEXT BA
|
||||||
|
```
|
||||||
|
|
||||||
|
虽然 `POKE` 命令,带有它们的大量的运算数,开始时看起来很吓人,现在你看到数字的真实的值不是很要紧。明显地,你不得不获取正确的数字,但是所有的数字代表的是一个 Commodore 正好出现在存储在地址53280处的“容器”。这个容器有一个特殊的用途: Commodore 使用它来决定屏幕背景应该是什么颜色。
|
||||||
|
|
||||||
|
![Commodore 64 更改背景颜色][14]
|
||||||
|
|
||||||
|
你认为这是非常有条理的. 仅仅通过写入内存中一个特殊目的的容器中,你可以控制一台计算机的基础属性。你不确定 Commodore 64 的电路系统如何使用你写图内存中的值,并更改屏幕的颜色,但是,你不知道这些也没事。至少你理解到这点的每一件事。
|
||||||
|
|
||||||
|
### 特殊容器
|
||||||
|
|
||||||
|
那个周六,你没有读完整本手册,因为你现在开始精疲力尽。但是你终于读完它的全部。在这个过程中,你学到更多关于 Commodore 64 的特殊目的容器。它们是你可以写的容器来控制在屏幕上是什么—一个容器,事实上,每一个位置都可能出现一个角色f。在第六章节中,“小精灵图形”,你学到特殊目的容器允许你来定义能被四周移动和甚至缩放的图像。在第七章节中,“创建声音”,你学到你能写入的容器以便使你的 Commodore 64 歌唱 “Michael Row the Boat Ashore”。Commodore 64,转到外面,你可能以后学习一个称为 API 的非常有限的方法。控制 Commodore 64 大多涉及通过电路系统给定特殊意义来写到内存地址。
|
||||||
|
|
||||||
|
你最终花费很多年写到这些粘住你的特殊容器。甚至几十年后,当你发现你自己用一组大量的图形或声音 API 编程一个机器时,你知道 API ,在隐蔽物的后面, API 最终是写到这些容器或一些像它们的东西。你有时会怀疑曾经使用过 API 的年轻程序员,他们一定会好奇并思考 API 正在为他们做什么。可能他们认为 API 正在调用一些其它隐藏的 API 。但是,随后思考隐藏的 API 正在调用什么?你同情这些年轻的程序员,因为他们一定非常迷惑。
|
||||||
|
|
||||||
|
如果你喜欢这篇张贴文, 更喜欢它每两周出来一次!在Twitter上关注 [@TwoBitHistory][15] 或订阅[ RSS 源][16]来确保你知道新的张贴文出来的时间。
|
||||||
|
|
||||||
|
先前关于TwoBitHistory…
|
||||||
|
|
||||||
|
> 你曾经好奇一个19世纪计算机程序翻译到 C 语言程序的可能的样子吗?
|
||||||
|
>
|
||||||
|
> 这周帖子: 一个详细的说明查看,Ada Lovelace 的著名程序的工作,和它将尝试去做什么。<https://t.co/BizR2Zu7nt>
|
||||||
|
>
|
||||||
|
> — TwoBitHistory (@TwoBitHistory) [2018年8月19日][17]
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
通过:https://twobithistory.org/2018/09/02/learning-basic.html
|
||||||
|
|
||||||
|
作者:[Two-Bit History][a]
|
||||||
|
选题:[lujun9972][b]
|
||||||
|
译者:[robsean](https://github.com/robsean)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://twobithistory.org
|
||||||
|
[b]: https://github.com/lujun9972
|
||||||
|
[1]: https://www.youtube.com/watch?v=kZRE7HIO3vk
|
||||||
|
[2]: https://en.wikipedia.org/wiki/BASIC_Computer_Games
|
||||||
|
[3]: https://www.youtube.com/watch?v=ZekAbt2o6Ms
|
||||||
|
[4]: https://www.npr.org/sections/money/2014/10/21/357629765/when-women-stopped-coding
|
||||||
|
[5]: https://www.youtube.com/watch?v=MA_XtT3VAVM
|
||||||
|
[6]: https://twobithistory.org/images/c64_startup.png
|
||||||
|
[7]: https://twobithistory.org/images/c64_error.png
|
||||||
|
[8]: ftp://www.zimmers.net/pub/cbm/c64/manuals/C64_Users_Guide.pdf
|
||||||
|
[9]: https://twobithistory.org/images/c64_colors.png
|
||||||
|
[10]: https://twobithistory.org/images/c64_print_loop.png
|
||||||
|
[11]: https://twobithistory.org/images/c64_ball.gif
|
||||||
|
[12]: http://10print.org/
|
||||||
|
[13]: https://twobithistory.org/images/c64_maze.gif
|
||||||
|
[14]: https://twobithistory.org/images/c64_background.gif
|
||||||
|
[15]: https://twitter.com/TwoBitHistory
|
||||||
|
[16]: https://twobithistory.org/feed.xml
|
||||||
|
[17]: https://twitter.com/TwoBitHistory/status/1030974776821665793?ref_src=twsrc%5Etfw
|
Loading…
Reference in New Issue
Block a user