Sir Muffington
Sir Muffington

Reputation: 321

Porting from Santaka ZX Spectrum clone code to Z80 to compile a Santaka game - how to translate to this dialect?

This is a continuation of https://retrocomputing.stackexchange.com/questions/27077

I am trying to port my father's game for the Z80 compiler. I have managed to read up on the tutorials and other resources (like other BASIC programming examples) to solve primitive issues with compiling the game, but still is unsolved by me:

dump.bas:182: error: Syntax Error. Unexpected token 'INT' <INT>
6220 GO TO 6221 ; INT(RND*3)*4
dump.bas:206: error: Operator AND cannot be used with STRINGS
7040 PRINT AT y(e)-1,x(e)+1;"__" AND r(e)=1
dump.bas:291: error: Cannot convert value to string. Use STR() function
dump.bas:292: error: Cannot convert value to string. Use STR() function
 9992 READ L$: LET L=LEN L$: LET S=0: LET K=2: LET N=N+1
 9993 IF L=0 THEN RETURN 
dump.bas:295: error: Cannot convert string to a value. Use VAL() function
9996 IF K<L THEN POKE A,C: LET S=S+C: LET K=K+2: LET A=A+1: GO TO 9994

So for the first error the semicolon does not get recognized. Is it possible in Z80's BASIC dialect to change this code so that it runs? For each line I added the corresponding code unless there's two lines in a row.

This seems like a specific dialect, how do I port this for the zxbasic compiler(Z80)?

Or is this code corrupt from using a bad TAP converter?

I still have a tape recorded .WAV file.

Upvotes: 1

Views: 161

Answers (1)

karttu
karttu

Reputation: 159

Here's my attempt to crack this nut.

Problem 1

dump.bas:182: error: Syntax Error. Unexpected token 'INT' <INT>
6220 GO TO 6221 ; INT(RND*3)*4

Semicolon is typically not an operator or token in BASIC, except in PRINT statements. Also the GO TO is to the very next line, which makes no sense - there would not be any lines to skip over. Furthermore the INT(RND*3)*4 is just hanging there. All of this implies to me that this might be a jump table implementation.

Sinclair BASIC RND returns values [0,1) , thus INT(RND*3)*4 would yield values 0, 4, or 8. You mention that code might have corrupted and that is very likely with old tapes. Semicolon's value in hex is 0x3B and plus sign's is 0x2B - that's one bit's difference.

I would therefore wager that the line is supposed to be:

6220 GO TO 6221 + INT(RND*3)*4

Your father's code makes a random jump to 6221, 6225, or 6229, which would be easy to verify by seeing a bit more of the code.

Problem 2

dump.bas:206: error: Operator AND cannot be used with STRINGS
7040 PRINT AT y(e)-1,x(e)+1;"__" AND r(e)=1

Sinclair BASIC allows using AND with strings. It is an inline conditional stating that the string is to be output only if the condition returns non-zero. This is described in chapter 13 of the ZXSpectrum BASIC Programming manual. I would say that the BASIC environment you are using (you don't specify which) is not ZXSpectrum BASIC compatible.

An example on how this works on a ZXSpectrum 48k BASIC. The first two lines are the output of the program below it. Coloured emphasis added by me.

ZX BASIC example program 1

Problem 3

dump.bas:291: error: Cannot convert value to string. Use STR() function
dump.bas:292: error: Cannot convert value to string. Use STR() function
9992 READ L$: LET L=LEN L$: LET S=0: LET K=2: LET N=N+1
9993 IF L=0 THEN RETURN 
dump.bas:295: error: Cannot convert string to a value. Use VAL() function
9996 IF K<L THEN POKE A,C: LET S=S+C: LET K=K+2: LET A=A+1: GO TO 9994

Here again I believe your BASIC environment is not compatible with ZXSpectrum BASIC which allows naming number and string variables with the same identifier.

Line 9992 reads a DATA definition into string L$ and then assigns the string length into number variable L. It's confusing maybe, but works in ZX BASIC. The error on line 9993 IF L=0 is a result of the BASIC implementation you're using thinking that L is a string. Same with line 9996 IF K<L.

Example from ZXSpectrum 48k BASIC:

ZX BASIC example program 2

Summary

BASIC dialects vary a lot and many (most?) programs are not easily portable from one environment to another. As suggested in the referred question, your best course of action is to run the program in an emulator.

When you write a question, please include as much relevant information and context as possible. These three problems were fairly easy to detect but it would have saved some time if I had at least the code surrounding the first GO TO line.

Finally, there is no "Z80 BASIC" or "Z80 compiler". I think you might be using boriel/zxbasic but surely you should have mentioned which environment you are having problems with.

Postscript

Good luck with restoring your father's code. I think it's a great idea and I hope you manage to get it running!

Upvotes: 2

Related Questions