LoginLogin
Might make SBS readonly: thread

PEEK and POKE instructions

Root / Submissions / [.]

MinxrodCreated:
Download:QR Codes
Version:1.2Size:~100KB
This is an example usage of the _ASMLOAD program to add two* new instructions, PEEK and POKE, into Petit Computer. Changes last only until returning to the main menu. *POKE is actually split into two instructions now, but they're basically the same. Demos VRAMPOKE - POKE demo. Writes characters that are normally inaccessible to VRAM. Extremely simple. MEMVIEW - PEEK demo. A basic RAM viewer. This WILL crash if you try to read memory that isn't mapped. The controls for MEMVIEW are: up/down to scroll, left/right to scroll by a page, and Y to jump to a specific address. 3DDEMO - "advanced" PEEK/POKE combined demo. Displays a 3D cube using the 3D hardware of the system. Slight seizure warning, the vertex colors are semi-random/flash colors Controls: Up/down/left/right to rotate, A to exit. Note that if you exit with SELECT in DIRECT mode, the de-initialization function will not be called, and you won't be able to see the console text. The 3D renderer writes to the same BG layer as the text console, so you can't really use the console at the same time as the 3D features. Instructions You must also have _ASMLOAD downloaded for this to work.
POKE2 addr, value
POKE4 addr, value32
value = PEEK(addr)
POKE2 allows you to write a 16-bit value to the given address. This is a normal PTC formatted integer. POKE4 allows you to write a 32 bit value to the given address. This uses the fraction and sign bits of the PTC number type as data, and so requires some adjustment from a normal PTC integer. PEEK allows you to read a 16-bit value from the given address. The result is a normal PTC integer. `addr` must be the value of an address, divided by 4096. Example:
'desired address: 0x06000004
ADDR = &H06000+&H004/4096
POKE2 ADDR, &HD031 'writes a red "1" to VRAM
This is due to the format of PTC numbers being 20.12 fixed point, and the normal range of numbers not being enough to access all the interesting memory locations. The value provided (or read by `PEEK`) is a normal PTC integer. Changelog When downloading, if the file hasn't changed since the last version you don't need to re-download it. Version 1.2.0 - Update PRGs for _ASMLOAD v1.1 Version 1.1.0 - More demos - POKE split into two instructions for usability reasons Version 1.0.0 - Initial Release For the assembly source code as well as some extra stuff to help write your own new instructions, see https://github.com/Minxrod/PTC-ASM. Notes This program requires _ASMLOAD. If you don't have it, it will throw an error. I think if you run VRAMPOKE without ASM_MEM, it crashes. The other programs have better error checking, and shouldn't (but still might) crash. PEEK replaces the TALKCHK function. You will be unable to use TALKCHK if you use this program. Size of program is mostly from the two GRPs, the actual codes are much smaller.

It would be interesting to see a function to format a 16 bit value so you don't have to do the divides and multiplies yourself. Cool concept.

Replying to:snail_
It would be interesting to see a function to format a 16 bit value so you don't have to do the divides and multiplies yourself. Cool concept.
The 16 bit values shouldn't need formatting, only the address because of size issues. Unless you mean for the address itself, in which case it could be useful, but functions are harder to add over commands because there are no free empty slots available, it has to replace or patch something.