Yesterday when I was traveling back to Amsterdam I suddenly a very nice idea for a series of articles here on my weblog.
As many know I am a software engineer (or a programmer as they called that in the past :P). In the more then the 20 years I am coding I have seen many programming languages. It should be fun for me to take a look back at them all and maybe it is also nice for those who have an interest in this area. So every now and then I will give one of the languages I have worked or am working with some special attention.
I will start with a review of ZX 81 Basic. The ZX 81 was one of the first home computers that came out in the early 1980’s. It had a build in Basic version.
Basic (Beginners All-purpose Symbolic Instruction Code) was not really meant to develop in, but it was meant to learn programming. Most Basic-versions were interpreter language, which meant on execution of the program the original source was translated to system instruction (commands that a computer can understand and execute).
ZX 81 Basic was a very minimal version of Basic. The instruction set is very limited.
Interesting was though that while you where enter code, ZX 81 Basic completed the instruction for you. So when you entered an “I’ it knew when you meant just an “I” or you needed the “if” instruction and display the complete instruction on the screen. It did this pretty good.
ZX81 Basic did not have any really graphic functions. After all it was complete black/white and the only way to do anything with plotting small blocks on the screen.
Below a typical example of piece of ZX81 Basic code. Looking at it, I would have done some thing different, but as said…. “Code is Poetry” , so it is all up to the coder :
1000 REM recursive subroutine
1010 IF x>8 OR x<1 OR y>8 OR y<1 THEN RETURN
1020 IF b$(s,1)<>a$(y,x) THEN RETURN
1030 IF SCREEN$ (20-y*2,2+x*3)<>” ” THEN RETURN
1040 PRINT AT 20-y*2,1+x*3; PAPER 5+((y+x)=INT ((y+x)/2)*2);(” ” AND s<10); s
1050 IF s=64 THEN PRINT AT 21,8;”SOLVED IN “;m; ” MOVES” : STOP
1060 LET s=s+1: LET b$(s)=”23456789″: LET m=m+1
1070 LET x=x+x2: LET y=y+y1: GO SUB 1000: LET y=y-y1: LET x=x-x2
1080 LET x=x+x2: LET y=y-y1: GO SUB 1000: LET y=y+y1: LET x=x-x2
1090 LET x=x+x1: LET y=y+y2: GO SUB 1000: LET y=y-y2: LET x=x-x1
1100 LET x=x+x1: LET y=y-y2: GO SUB 1000: LET y=y+y2: LET x=x-x1
1110 LET x=x-x1: LET y=y+y2: GO SUB 1000: LET y=y-y2: LET x=x+x1
1120 LET x=x-x1: LET y=y-y2: GO SUB 1000: LET y=y+y2: LET x=x+x1
1130 LET x=x-x2: LET y=y+y1: GO SUB 1000: LET y=y-y1: LET x=x+x2
1140 LET x=x-x2: LET y=y-y1: GO SUB 1000: LET y=y+y1: LET x=x+x2
1150 IF b$(s)>=”0″ THEN LET b$(s)=b$(s,2 TO ): GO TO 1070
1155 LET s=s-1 : REM obsolete backtracking path
1160 PRINT AT 20-y*2,1+x*3; PAPER 8;” ”
1170 RETURN
Edit: Somehow the code example was messed up. There were some codes in there that were translated as HTML, which it should not. It looks now a lot better I have to say.
not my kind of work…
it’s a bit messy. In this case it’s not poetry, it’s spaghetti (H)
What does the code do?
@Huub: I can understand… programming is something you really must like (and most programmers as me are weird people :P) especially when you do it as profession. If you do not it will drive you crazy.
@Patrick: If I remember right it is recurring routine for plotting points (or “blocks” in case of the ZX81 🙂 ) on the screen.
Personally I would have turned line 1040 into a subroutine and write it all nice and clear out.
As far as i know, that is not possible in Basic? The code isn’t that messed up.
After 1040, the are missing so line 1050 to 1150 are not seperated in the example.
Looks like the writer made an mistake and inserted 1155 to correct 😉
Wow, your theme eat my haha
should be –> After 1040, the are missing
LOL i cannot insert an carrier return linefeed, Even with spaces and quotes your theme eats it haha
Last try –> After 1040, the carrier return linefeed are missing
You are right. The linefeeds are missing. I have to look into that.
But in Basic you can building routine. GOSUB/RETURN is in most Basic-version available. More modern versions have even functions and alike.
Copied the code example to notepad, so all weird codes were removed. That helped a lot.
BTW Patrick that line 1055 could have been a mistake. But most Basic versions know the RENUMBER-instruction (or a variant of that) to renumber all lines. So “RENUMBER 10” would renumber all the lines of the program with an interval of 10 (and of course references to line-numbers are changed accordingly).
That would not explain th 55 😉 Also to complex thinking for the ZX (h)
I know how often i had to put lines in between. Next to chubby fingers, the editor wasn’t very flexible in editing ;D
I think you misunderstood me. The 55 line was not caused by RENUM, but you could “solve” it with RENUM. RENUM was the ZX81 Basic interpretation of the RENUMBER command of many other Basic Version.
The 55 line could be caused by the correction of a mistake. On the other hand, coding in not an linear process. Often while coding you modify parts of the code you already had done. At least, I do so all the time.
The editor of the ZX81 was indeed not comparable with anything we know nowadays, but it was still was more advanced then Edlin (which is still part of Windows Vista 🙂 ).
Idd.
Almost 11 years past, so I guess it’s to for someone to point out that is not a ZX81 BASIC code, but ZX Spectrum, probably.
* time for