Search code examples
peekzx81

ZX81 ‘BASIC’ peek function


I want to find the code of a character printed.

This is the code:

10 Print AT 2,2; "T"
20 Let C=Peek(Peek 16398+256*Peek 16399)
30 Print Peek(C)

It should just print the Code value of T.

I could later use:

40 Print Peek (Code C) 

Or something.

But the 10-30 bit doesn't work. It always returns '0' -With different letters too: G,T 'black graphic' and M,

What am I doing wrong?

Will be used for collision detection.


Solution

  • jdehaan's right, printing the T without a trailing ; will move the cursor down to the next line after printing. (With ;, it's be one position to the right.)

    To read the character you'd just written you'd have to move back a position again:

    PRINT AT 2,2;"T";AT 2,2;
    PRINT PEEK(PEEK 16398+PEEK 16399*256)
    

    gives me 57, which is the character code for T.