PEEK/POKE Video buffer - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: PEEK/POKE Video buffer (/showthread.php?tid=812) |
PEEK/POKE Video buffer - BDS107 - 08-25-2022 Hello everyone, In the good old days we used PEEK and POKE to read and write on the screen address. See also the example below. Code: (Select All) SCREEN 0 If we use SCREEN _NEWIMAGE(80, 25, 0) it no longer works. See example below. Any suggestions on how to use PEEK/POKE? Code: (Select All) SCREEN _NEWIMAGE(80, 25, 0) RE: PEEK/POKE Video buffer - OldMoses - 08-25-2022 PEEK/POKE emulate the old DOS/QBasic system so I'd expect it to work with SCREEN 0. With the newer screen modes you probably need to investigate _MEM and _MEMIMAGE usage. I'm just starting to play with mem commands myself, but here's what I came up with. It seems to be doing what you're trying, plus it's safer, memory wise. Code: (Select All) SCREEN _NEWIMAGE(80, 25, 0) Oops, changed that STEP back to 4 for the spacing. RE: PEEK/POKE Video buffer - SMcNeill - 08-25-2022 Swap over to _MEM, which is the modern version of PEEK/POKE. It's been ages since I last used PEEK and POKE as your example, so I'm having trouble sorting out what it's supposed to do. Our screen is 80 * 25 * 2bytes per character in size, so 4000 bytes. FOR a = 0 TO 4000 STEP 4 <-- this would address every other pixel on the screen x = INT(RND * 2) + 48 <-- x is either 49 or 50, which is ASC for either "0" or "1" y = ((INT(RND * 2)) * 8) + 2 <-- y is either 2 or 10... light green and dark green in color? POKE a, x <-- set the character to CHR$(x) POKE a + 1, y <-- set the color to y NEXT All this does is place 0's and 1's at alternating points of the screen and change their color from light green to dark green? Yes? I'm thinking this is more-or-less, what you're looking for with modern mem commands: Code: (Select All) Screen 0 Edit: OldMoses beat me to it while I was typing up my answer. RE: PEEK/POKE Video buffer - OldMoses - 08-25-2022 Oh, that's right. Unsigned byte, not integer as I did in my example. RE: PEEK/POKE Video buffer - BDS107 - 08-25-2022 The program with the green 1 and 0 was actually an example of PEEK/POKE. But I see that the same thing can be achieved with _MEMPUT. So a _MEMGET does the opposite. So I can and will change this. Can you still use PCOPY to copy screens? Or do you use _MEMCOPY? I think PCOPY is going faster? RE: PEEK/POKE Video buffer - SMcNeill - 08-25-2022 PCOPY still works, though there's also a _COPYIMAGE routine now which you could make use of. 99% of the old QBASIC commands work exactly as they used to, with the main exceptions being the ones which relied on OS specific memory addresses and such (such as several of the PEEK/POKE calls), and DEF Fn, which hasn't ever been added to the language yet. RE: PEEK/POKE Video buffer - BDS107 - 08-25-2022 OK, I just did a test with PCOPY, it works. Even with screens of 80x25 or 80x50 characters. And yes, even with 80x53 characters. RE: PEEK/POKE Video buffer - OldMoses - 08-25-2022 (08-25-2022, 11:50 AM)BDS107 Wrote: The program with the green 1 and 0 was actually an example of PEEK/POKE. Yes, _MEMGET is pretty much like PEEK. It has a statement and a function form depending on the use of parenthesis. _MEMGET m, m.offset, c% or c% = _MEMGET(m, m.offset, INTEGER) |