惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
爱范儿
爱范儿
WordPress大学
WordPress大学
V
V2EX
宝玉的分享
宝玉的分享
小众软件
小众软件
B
Blog
博客园 - 叶小钗
U
Unit 42
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
H
Help Net Security
P
Proofpoint News Feed
D
Docker
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
月光博客
月光博客

Secret Weblog

Becoming More Xee: A Modern XPath and XSLT Engine in Rust Looking for new challenges! Repeat Yourself, A Bit The Curious Case of Quentell The Humble For Loop in Rust The Humble For Loop in JavaScript Don Question Best Practices I Was a 1980s Teenage Programmer Part 5: Achieving Assembly The Tooling Shift I Was a 1980s Teenage Programmer Part 3: MSX-2 JavaScript: when you need two ways to do it! Empowering Programming Languages Bloat and Retrofuturism Refreshing my Blog Again Random Rust Impressions Apilar: An Alife System I Was a 1980s Teenage Programmer Part 2: Olivetti M24 I Was a 1980s Teenage Programmer: the Alphatronic SolidJS fits my brain Is premature optimization the root of all evil? Framework Patterns: JavaScript edition Roll Your Own Frameworks Framework Patterns Secret Weblog Highlights Refactoring to Multiple Exit Points mstform: a form library for mobx-state-tree Seven Years: A Very Personal History of the Web Morepath 0.16 released!
I Was a 1980s Teenage Programmer Part 4: The Call of Asse...
Martijn Faassen · 2024-05-31 · via Secret Weblog

This is Part 4 of a series.

Creating games with BASIC

Me and my friend were on a quest to develop games for the MSX-2. Creating "real" games seemed more in reach back then - the graphics were simple, there was no 3D, so we had the hope we could do it. Our skills weren't great, and BASIC was too slow for this purpose, but we had fun and learned many things.

MSX BASIC had a lot of high level commands to do graphics (and sound too). You could draw a line and a circle, you could define and move around sprites, you could copy bitmapped graphics to other areas of the screen.

Using POKE and PEEK to directly change and access memory was possible, and some other platforms like the Commodore 64 required that to do anything cool, but to me, POKE and PEEK remained a mystery and weren't really necessary to know about. I knew that if I POKEed the wrong place it would crash the machine.

Elite

At some point my friend and I obtained the game Elite, which was released on the MSX. This game was wildly different: unlike a 2d game with a fixed, simple action-oriented mission, like almost all other games on the platform, it was an open world 3d game where you were a space trader and you could roam a giant universe of stars trading your wares and fighting.

It was different. It was an extremely impressive game to us then. I'm even more amazed by it today and if you're a software developer, you will be as well if you watch this video:

No matter how ambitious I and my friends were about creating real games on the MSX, I don't remember we ever had any ambition to create something like Elite. We knew it was beyond us.

My friend and I knew the MSX could do smooth vertical scrolling. We'd seen games do it. But we didn't know how to do it from BASIC. There was no command. Until one day my friend had made a major discovery: the magical "VDP(24)" command. I don't know anymore how he had learned about it, but it changed our world. Suddenly we had access to a whole new ability!

Many years later I learned that VDP stands for Video Display Processor and that VDP(24) controlled register 23 (but BASIC started to count at 1 for this). This was like POKE and PEEK; a feature not fully exposed to BASIC.

Many years later as well, on a whim, I googled how to do vertical scrolling on the MSX-2. Even though this platform by then was very obsolete, I immediately found many resources that described how to do it. You still can. What was such a breakthrough for us was a trivial search away in the internet era.

Smooth horizontal scrolling on the MSX-2 was not possible with an equivalent VDP command.

Many side-scrolling games existed on the MSX, such as the famous Nemesis series made by Konami (more commonly known as Gradius was named on the MSX), but they all used character-tile based scrolling, which wasn't smooth:

Yet in 1989 we saw a new game in the Gradius genre, Space Manbow, also made by Konami, that had smooth horizontal scrolling. But we knew there was no hardware support for this. How did they do it?

We figured it out, and it was pretty insane:

There was a special VDP register that let you adjust the horizontal and vertical centering of the whole screenThis is Part 3 of a series.. It was actually exposed with a proper BASIC command, called SET ADJUST. You could recenter the screen from -7 to +8 pixels both horizontally and vertically.

Space Manbow adjusted the screen horizontally for 16 pixels, so scrolling was smooth, and then do a tile-based "jumpy" scroll after that, at the same time setting the adjust back to the extreme other end. This way each tile could scroll smoothly. It used black sprites to mask over the left and right sides of the screen, so you couldn't see the edge shifting.

BASIC KUN

A temporary reprieve arrived in the form of MSX-BASIC KUN, also known as X-BASIC. This was a BASIC compiler, but it didn't come in the shape of a compiler. There wasn't a program to translate your BASIC into machine code. Instead you gained a new BASIC command, CALL TURBO ON, which would enable this magic. You could surround your BASIC code with CALL TURBO ON and CALL TURBO OFF blocks and that code would be a LOT faster; online I read from 15 to 100 times faster. There were a few restrictions to the BASIC you could write in a turbo block. But it was like sorcery. We had no real idea how it could even work, but it did.

Lightbulb

But we knew that to write REAL games we'd have to learn assembly. But I just didn't get even the fundamentals.

At one point at school I talked to a guy who had done assembly. I asked him how I could do an IF in assembly (a conditional statement). He gave me the revelation: you'd first execute an arithmetic instruction, like substract. Then if the result of this operation was zero, the Z flag would be set. Then you used a conditional jump instruction, that would only jump if Z was set (or the inverse, when it wasn't set).

A lightbulb went off over my head. So that is how you do it!

I think still remember where I was when I was talking to him, on the ground floor of the school near where the coat hangers were, though I don't remember his face or name.

Next time...

Thanks for reading part 4 of this series! Next time we'll discuss me actually writing Z80 assembly code.