timwylie Posted March 10, 2014 Share Posted March 10, 2014 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. Quote Link to comment Share on other sites More sharing options...
Kiwi Posted March 10, 2014 Share Posted March 10, 2014 I think PEEK can only get 8-bit bytes and the screen data is in 16-bit WORDs. Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted March 10, 2014 Share Posted March 10, 2014 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 THENinstead. How about it nanochess? 1 Quote Link to comment Share on other sites More sharing options...
+5-11under Posted March 10, 2014 Share Posted March 10, 2014 I think PEEK can only get 8-bit bytes and the screen data is in 16-bit WORDs. 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. Quote Link to comment Share on other sites More sharing options...
Kiwi Posted March 10, 2014 Share Posted March 10, 2014 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. Quote Link to comment Share on other sites More sharing options...
+5-11under Posted March 11, 2014 Share Posted March 11, 2014 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. Quote Link to comment Share on other sites More sharing options...
timwylie Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) 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 March 11, 2014 by timwylie Quote Link to comment Share on other sites More sharing options...
timwylie Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) I was able to get it to work. Just a stupid mistake. I missed the # before the variable. Edited March 11, 2014 by timwylie 2 Quote Link to comment Share on other sites More sharing options...
catsfolly Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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 March 11, 2014 by catsfolly 1 Quote Link to comment Share on other sites More sharing options...
timwylie Posted March 11, 2014 Author Share Posted March 11, 2014 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! 1 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted March 12, 2014 Share Posted March 12, 2014 It'd be much easier if the IntyBASIC evaluation parser could interpret :- IF P=('#'-' ')*8 THENinstead. 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. 1 Quote Link to comment Share on other sites More sharing options...
timwylie Posted March 12, 2014 Author Share Posted March 12, 2014 Okay. I didn't realize the parser was per-line and not a general token-based CFG. Thanks for the clarification! Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted March 12, 2014 Share Posted March 12, 2014 Consider it done for IntyBASIC v0.7 but I think I'll translate automatically into Intellivision codes, so '$' would give you 4. Thinking about it how about implementing Inty specific functions for chr$() and ASC() instead? That would kinda make more sense to me. Quote Link to comment Share on other sites More sharing options...
+nanochess Posted March 13, 2014 Share Posted March 13, 2014 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. 1 Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted March 13, 2014 Share Posted March 13, 2014 I don't think you'd need string support. If the functions just converted to and from Inty "ASCII" that'd be a big help to coders. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.