Jump to content
IGNORED

Reading from the screen


timwylie

Recommended Posts

Hello. I've been playing with IntyBasic and was curious how the PEEK function is implemented, and if I can even do what I want. If I have previously written to the screen using PRINT, how can I read the value on the screen?

 

Before getting into sprites and all, I wanted to make an old school ascii-based game. The only issue is after the screen has scrolled, I need to check a position on the screen to see if it has a certain character- a basic collision detection.

Say I have some code like:

PRINT AT 200 COLOR 5, "#"

 

Now later I want to know if that location still has the value I printed? I can't seem to get it to work even with the correct hex value for character and color, so I think PEEK isn't reading where I think it is. I was using PEEK($200+200). Anyway, I'd appreciate the help. Thanks.

Link to comment
Share on other sites

Don't forget that the characters aren't stored as direct ASCII values in BACKTAB.

 

The following code :-

 

P=PEEK($200+200) AND (255*
Generates the following assembler :-

    MVI 712,R0
    ANDI #2040,R0
Which is a 16 bit RAM access and masks off the code for the character. If you want to test P against a '#' (which was the previously stored character at screen location 200) you need to look up the character in this ASCII table :-

 

http://www.asciitable.com/

 

Then subtract 32 from it and multiply the result by 8. So... in the case of '#' it would become :-

 

='#' is ASCII code 35

=(35-32) * 8

=24

 

So your code would become :-

IF P=24 THEN
It'd be much easier if the IntyBASIC evaluation parser could interpret :-

 

IF P=('#'-' ')*8 THEN
instead.

 

How about it nanochess?

  • Like 1
Link to comment
Share on other sites

 

The test.bas program has the line "if peek($0200) = $010f then poke $0202,$10f", so it looks like it should work with 16 bit, I think.

I remembered the old manual said 8-bit value. Now looking at the newer manual, it doesn't say that. I think it should now be able to get 16-bit value.

 

The manual have this expression.

'A=PEEK(expr) Reads memory'

 

#A=PEEK(expr) adding # before A I think should get 16-bit value and store it into 16-bit variable A.

Link to comment
Share on other sites

I remembered the old manual said 8-bit value. Now looking at the newer manual, it doesn't say that. I think it should now be able to get 16-bit value.

 

The manual have this expression.

'A=PEEK(expr) Reads memory'

 

#A=PEEK(expr) adding # before A I think should get 16-bit value and store it into 16-bit variable A.

 

I was looking at version 0.5, for the record.

Link to comment
Share on other sites

I was already using ascii plus the color. It's still not working.

 

Here's a simple example:

PRINT AT 220 COLOR 2,"#"

#CURRV = PEEK($0200 + 220)
IF CURRV = 3*8 + 2 THEN
...

 

Also (off-topic), why isn't there an END IF, and why are the equality and assignment operators the same? Maybe those are both relics from BASIC.

Edited by timwylie
Link to comment
Share on other sites

I was able to get it to work. Just a stupid mistake. I missed the # before the variable.

I've made this same mistake. If you misspell a variable name, a new variable gets created. Of course, the new variable never has the value you want...

Edited by catsfolly
  • Like 1
Link to comment
Share on other sites

Yeah. The problem was that the manual wasn't clear on the symbol name for the scanning/parsing. I assumed the # was not part of the actual variable name, and simply denoted to the compiler to make it 16bit when first used. Anyway, it's working now. :) Thanks to everyone for the help!

  • Like 1
Link to comment
Share on other sites

It'd be much easier if the IntyBASIC evaluation parser could interpret :-

 

IF P=('#'-' ')*8 THEN
instead.

 

How about it nanochess?

 

 

Consider it done for IntyBASIC v0.7 :) but I think I'll translate automatically into Intellivision codes, so '$' would give you 4.

 

I think I'll use double quotes instead of single, because already single quote is reserved for REM.

 

I remembered the old manual said 8-bit value. Now looking at the newer manual, it doesn't say that. I think it should now be able to get 16-bit value.

 

The manual have this expression.

'A=PEEK(expr) Reads memory'

 

#A=PEEK(expr) adding # before A I think should get 16-bit value and store it into 16-bit variable A.

 

I'll add a clarification to manual about this. PEEK always reads 16-bits and you can operate in this value as expression evaluator is 16-bits.

 

Of course the information is missing if you save it into a 8-bit variable.

 

I was already using ascii plus the color. It's still not working.

 

Here's a simple example:

PRINT AT 220 COLOR 2,"#"

#CURRV = PEEK($0200 + 220)

IF CURRV = 3*8 + 2 THEN

...

 

Also (off-topic), why isn't there an END IF, and why are the equality and assignment operators the same? Maybe those are both relics from BASIC.

 

In order to simplify, the parser is per-line like in old BASIC. The END IF would be more PASCAL/C style.

 

And of course I like the double usage of = for equality/assignment operator. It simplifies code and avoids possibility of potential syntax pitfalls.

 

Also I've added a clarification of variable usage to manual.

  • Like 1
Link to comment
Share on other sites

Thinking about it how about implementing Inty specific functions for chr$() and ASC() instead? That would kinda make more sense to me.

Yep, but I don't want to mess with string support. I'll think about it. I prefer the scheme for getting a character code.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...