Hot answers tagged

59

Your mention of TRS-80 provides a clue. In the TRS-80 character set, the space normally occupied by the ASCII [ character is instead a ↑ (up arrow) character. Old versions of BASIC (such as this one from 1964) use the up arrow character to indicate exponentiation, probably because at that time the ^ character was not even in the ASCII standard. (There is ...


43

Yes, BASIC is much slower than assembly for many operations. For an easy example, try out this program on a Commodore 64 or emulator: for i = 1024 to 1984 : poke i,peek(i) or 128 : next You will see each character on the screen reverse, row by row, over the course of ten seconds. By contrast, the exact same routine in machine language inverts the entire ...


43

[W]ere these interpreters implemented as tree-walker interpreters or bytecode interpreters? Neither, or both. They are kind of source code interpreters - much like (classic) shell scripts - except they used a tokenized storage format (*1). Their structure was dictated by balancing lack of memory, lack of interpreter code and desired optimization for speed (*...


42

BBC BASIC, first shipped in 1981, includes the EVAL keyword, which means "ask the interpreter to evaluate this string as an expression". Since strings can be mutated, a program can mutate what will be evaluated at runtime. The BBC MOS also provides *SPOOL (write screen output to a file) and *EXEC (read text from a file and act as if it had been typed), if ...


37

In old computer books of cheaper sort, (Paperback or pocket books) it was quite common that they couldn't type set all special characters directly. Either they did as in this case, changed the character for something the computer in question didn't use, but the type setter could handle. In this case this is normally mentioned in the foreword of the book. ...


25

It is the exponentiation operator. Why is that? On a TRS-80 Model III the line of BASIC entered would literally be: LET Z1 = M * D1 * (PQ / A) [ 3 To get the [ character you would press the up arrow key. You would press the same up arrow key on its predecessor, the TRS-80 Model I. However, it would display as: LET Z1 = M * D1 * (PQ / A) ↑ 3 This is ...


22

The big improvement to the language in Locomotive BASIC, compared to Sinclair BASIC (and many other BASICs), was the addition of timer support: AFTER 50,0 GOSUB 320 would call the subroutine at line 320 after a second, and EVERY 500,0 GOSUB 320 would call the subroutine every ten seconds. In both cases, the first value is the interval in fiftieths of a ...


20

Given that HP’s Rocky Mountain BASIC could load and run parts of code from disk, and given those parts of code could be plain text and the files could also be saved on the fly, I would say yes it should be possible. I don’t know if anyone tried to do that with RMB though. There were definitely self modifying programs using peek and poke but of course your ...


20

Was Locomotive BASIC significantly better than Sinclair BASIC? TL;DR: Oh, yes, it was! I'm aware that both Basics were more advanced than the C64 Microsoft implementation, Comparison of C64 BASIC to other BASICs of the same time is never in favour for the C64, as it's a quick port of the original 1977 PET Version. but neither [Locomotive BASIC, ...


18

In Commodore BASIC (used in the PET, VIC20, C64, C16, Plus/4, and C128) which is derived from Microsoft BASIC, it is possible to output screen-editor control codes in PRINT statements. Thus a common technique used to create dynamically-generated BASIC lines is to PRINT the generated line followed by control codes to return to the start of the line and then ...


18

The Sinclair systems were tokenised directly at the keyboard, so there was almost no lexical analysis. Keys were inputs to a state machine that implemented the BASIC language structure in a ROM table. The first keystroke would have a label on it -- maybe the P key was also labelled Print, G was Goto, and the L key was Let. After that was hit, the state ...


17

You need to use OpenMSX, and get the system ROMs for the machine in question. Then run OpenMSX, set the machine to the FS-A1WSX. There's a little menu button at the top left of the OpenMSX window. In there, set your tape to the WAV file. Then: 10 M$ = "E4E8O3G16G32R32G2G4R4O4C8D8E8F8G2G8F8E8F4E8D8E4D8C4" 20 PLAY M$+M$ The listing above is the content of ...


16

This example reveals a rounding error under Commodore BASIC V2.0: A=0.3:B=0.6:IF A+B<>0.9 THEN PRINT A+B-0.9 Running this on a C64 yields a difference of 2.32830644e-10. Other pairs that fail are 0.4+0.5, 0.6+0.1 and 0.8+0.1. Please note that also the order in which the numbers are summed up affects the result. 0.6+0.1-0.7 yields a difference, ...


16

The disk handling routine at 15619 will look ahead in the currently-executing BASIC line to see what command needs to be performed. As Ross Ridge observes, it evidently doesn't modify the BASIC interpreter's internal state when doing this, and so when the RANDOMIZE USR 15619 call returns, the interpreter will continue at the next statement. If the REM wasn't ...


16

Most implementations of BASIC for 8-bit home computers were interpreters, and in that sense they're similar to the standard versions of Python. You could typically expect simple programs to run 100 times slower in BASIC than in assembly of ordinary quality. However, it would normally take much less time to write that program in BASIC than in assembly. For ...


16

Here is the listing for Motie, followed immediately by Rescue. The full list of archived issues of People's Computer Co. (PCC) is here.


16

Most early 8-bit personal computer Basic interpreters were tokenized recursive descent interpreters. Tokenized to reduce the size of the program text, as well as speed up the interpreter by not have to parse text at runtime, and runtime recursive descent, trading off stack space usage versus having to build a parse tree in memory beforehand. Very few (if ...


15

were these interpreters implemented as tree-walker interpreters (simply traversing the parse tree) or bytecode interpreters? I have been looking at various BASICs for the last while. The answer is "all of the above". Pure interpreters - Tiny BASIC TinyBASIC parsed the line to the extent of converting the line number to an 8-bit value to see if the line ...


14

GW-BASIC allowed you to load in arbitrary code using CHAIN MERGE, where you could take an ASCII-coded (non-binary) BASIC program or snippet and transfer control to a specific line number. As no renumbering occurred, you could overwrite or remove sections of your code prior to the chaining. This program snippet works in this PC-BASIC emulator: 10 PRINT "...


14

BBC BASIC didn't use the PEEK or POKE keywords, but had the ? operator and statement which had the same effect. So the statement ?128 = 0 is equivalent to POKE 128, 0, and the expression ?128 is equivalent to PEEK 128. However, it also had ! and $ which did 32-bit and string peeks and pokes and e.g. $128 = "HELLO" would write the ASCII bytes of "HELLO" into ...


13

Using this expression A-INT(A/B)*B


13

I think the earliest BASIC dialects on micros to use these constructs for strings were North Star BASIC and Apple Integer BASIC in 1977, both presumably influenced by HP BASIC. The Apple lineage isn’t surprising since Steve Wozniak worked at HP. The origin of this approach to substring addressing could be FORTRAN, which uses a syntax of the form A(I:L).


11

INPUT LINE a$ See the ZX Spectrum Basic manual. Note that plain INPUT a$ will accept quite arbitrary string expressions, e.g. entering "a"+"b" is the same as entering "ab", and you can even use other (defined) string variables. The quotes are thus nothing more than a part of the string expression.


10

Some old Operating Systems I hear have only BASIC Programming Language It was more the case that BASIC was the operating system. Various commands for working with devices like floppy disks and printers were added to the dialect of BASIC running on that machine. Turning it on would result in the BASIC READY prompt where you could type in a program, or begin ...


10

Probably the most modern BASIC available for the 6502 - though it requires a 65C02 - is Acorn's BBC BASIC IV as released for the BBC Master. It can be ported to other 65C02-based hardware by implementing a few of the MOS API entry points it relies on, and dummying out the rest; several people have done so for home-built SBCs. The standard version occupies ...


10

Here is my favourite example for this problem. I often use it to show Excel's mathematical shortcomings, but not surprisingly it works the same in the C64: 10 A = 0.1 20 B = 0.1 30 FOR I = 1 TO 10 40 D = B 50 B = 20 * A - 19 * B 60 PRINT B 70 A = D 80 NEXT I In every iteration, the algorithm should be doing 20 * 0.1 - 19 * 0.1 = 0.1, but the output on this ...


10

MOD is an operator, not a function. Try ? 10 mod 9 and see yourself.


10

M-BASIC-80 knows the modifier "A" for the SAVE command - So, you should be able to create a readable ASCII file directly on the Kaypro computer by doing LOAD "MYPROG.BAS" LIST SAVE "MYPROG.TXT",A If you don't want to mess with old disks on a modern computer (I recommend you don't even start to look into this), your best bet would be to set up a serial RS-...


9

The ZX Spectrum has VAL function, which is able to evaluate a string as a numeric expression. Such string can contain any valid BASIC expression. VAL$ does the same but with string expressions. On the other hand, the SAM Coupé BASIC (influenced by the Sinclair BASIC to some extent) has KEYIN, which allows a BASIC program to interpret a string as a BASIC ...


9

Did you, by any chance, use Beta Basic for the Spectrum? There you could assign memory ranges to strings and vice versa like 10 REM Move memory to a string 20 LET a$=MEMORY$()(16384 TO 22527) 30 REM Move back 40 POKE 16384,a$ I doubt standard Sinclair BASIC would have allowed anything like that. With a bit of machine code, you could, however, easily ...


Only top voted, non community-wiki answers of a minimum length are eligible