spot_imgspot_img

BASICally, Its Retro Machine Language

- Advertisement -


We loved [Beej’s] journey down reminiscence lane taking a look at a BASIC recreation, The Wizard’s Citadel, written for the Exidy Sorcerer. It appeared in a 1980 journal that included the title graphic above. It reminded us how, again in these days, we did issues with BASIC that you simply shouldn’t have the ability to do and it typically appears to be like, right now, quite cryptic.

Particularly, even when you realize fashionable BASIC, these few traces may offer you a pause:

10 REM"_(C2SLFF4
40 POKE 260,218: POKE 261,1: T = USR(0): T = PEEK(-2049)
80 Q = RND(-(2*T+1))

Line 10 is a remark, however a wierd one. Definitely that doesn’t matter, proper? Really, it’s a key a part of the motion. On line 40, you’ll be able to see some pokes to put in writing on to reminiscence and a peek to learn some reminiscence worth again. The USR operate calls some machine language program. It’s possible you’ll notice the entire thing is to get some worth T to seed the random quantity generator in line 80.

This leads to a couple apparent questions. First, how does USR know what to name? Second, the place is the machine language program? The small print assorted by system, in fact, however on this case, this system is aware of that location 259 has a bounce instruction that USR referred to as. So poking an deal with into 260 and 261 was telling USR the place it ought to go.

However what’s at that deal with? Understand that an outdated pc just like the Sorcerer didn’t have megabytes of reminiscence being swapped about by an working system. That implies that issues tended to be in recognized locations and that BASIC needed to be considered about storing supply code.

As was frequent on the time, a line like “10 PRINT 1+1” would get tokenized. On this case, every line would get a pointer to the following line, a two-byte line quantity, a single-byte token for “PRINT” after which extra bytes to characterize the remainder of the road. Within the case of textual content in a string or a comment, the bytes had been simply the textual content with a zero to terminate the string.

The primary line entered would at all times be at deal with 469. So? In case you think about the format of the REM assertion, there might be a pointer at 469 and 470, the road quantity at 471 and 472, and the REM token at 473. Meaning the opposite bytes simply get poured into deal with 474 and past.

That may look like an odd quantity till you take a look at the pokes in line 40. Understand that POKE works on bytes, not phrases. So poking 1 into 261 provides you an deal with of 256 + no matter is within the low byte, on this case 218. Add 256 and 218, and also you get… 474! So USR goes to name that odd string in line 10!

There may be extra to the detective story, however if you wish to know precisely what the REM did, you’ll be able to learn the unique submit.

- Advertisement -

Related Articles

Latest Articles