PEEK: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The '''PEEK''' function returns the value that is contained at a certain memory address offset. '''QB64 currently has limited access!''' {{PageSyntax}} :: variable = PEEK(''segment_offset'') * Reads the specified memory ''segment_offset'' value. * Use DEF SEG before PEEK to specify which memory segment to work in. * PEEK only reads the memory byte value. Not certain bits. (See AND) * Important SCREEN segments using PEEK and [[POKE]...") |
No edit summary |
||
Line 7: | Line 7: | ||
* Reads the specified memory ''segment_offset'' value. | * Reads the specified memory ''segment_offset'' value. | ||
* Use [[DEF SEG]] before PEEK to specify which memory segment to work in. | * Use [[DEF SEG]] before PEEK to specify which memory segment to work in. | ||
* PEEK only reads the memory byte value. Not certain bits. (See [[AND]]) | * PEEK only reads the memory byte value. Not certain bits. (See [[AND]]) | ||
* Important [[SCREEN (statement)|SCREEN]] segments using [[PEEK]] and [[POKE]] include &HB800 (text segment) and &HA000 (graphics segment). | * Important [[SCREEN (statement)|SCREEN]] segments using [[PEEK]] and [[POKE]] include &HB800 (text segment) and &HA000 (graphics segment). | ||
* To return to Basic default segment use [[DEF SEG]] without any arguments. | * To return to Basic default segment use [[DEF SEG]] without any arguments. | ||
* '''Warning: DEF SEG, VARSEG , VARPTR, PEEK or POKE access QB64's emulated 16 bit conventional memory block!''' | * '''Warning: DEF SEG, VARSEG , VARPTR, PEEK or POKE access QB64's emulated 16 bit conventional memory block!''' | ||
: '''It is highly recommended that QB64's [[_MEM]] memory system be used to avoid running out of memory.''' | : '''It is highly recommended that QB64's [[_MEM]] memory system be used to avoid running out of memory.''' | ||
''Example:'' Checking the 8 keyboard bit settings using a PEEK return value. | ''Example:'' Checking the 8 keyboard bit settings using a PEEK return value. | ||
{{CodeStart}} | {{CodeStart}} | ||
SCREEN 12 | SCREEN 12 | ||
{{Cl|DEF SEG}} = 0 ' BIOS area | {{Cl|DEF SEG}} = 0 ' BIOS area | ||
Line 22: | Line 22: | ||
DO: {{Cl|_LIMIT}} 100 | DO: {{Cl|_LIMIT}} 100 | ||
port = {{Cl|PEEK}}(1047) | port = {{Cl|PEEK}}(1047) | ||
IF port > 0 THEN LOCATE 26, 19: COLOR 11: | IF port > 0 THEN LOCATE 26, 19: COLOR 11: | ||
PRINT "Turn ALL Locks off to see each key's bit value!" | PRINT "Turn ALL Locks off to see each key's bit value!" | ||
END IF | END IF | ||
Line 46: | Line 46: | ||
LOOP UNTIL {{Cl|INP}}(&H60) = 1 ' escape key exit | LOOP UNTIL {{Cl|INP}}(&H60) = 1 ' escape key exit | ||
{{Cl|POKE}} 1047, oldvalue ' IMPORTANT reset to original settings | {{Cl|POKE}} 1047, oldvalue ' IMPORTANT reset to original settings | ||
{{Cl|DEF SEG}} | {{Cl|DEF SEG}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: '''NOTE: Keyboard Port function key settings cannot be reset on NT machines!''' | : '''NOTE: Keyboard Port function key settings cannot be reset on NT machines!''' | ||
Line 55: | Line 55: | ||
''See also:'' | ''See also:'' | ||
* [[POKE]] {{text|(write to memory)}}, [[INP]] {{text|(read register)}} | * [[POKE]] {{text|(write to memory)}}, [[INP]] {{text|(read register)}} | ||
* [[DEF SEG]], [[VARSEG]], [[VARPTR]] | * [[DEF SEG]], [[VARSEG]], [[VARPTR]] | ||
* [[_MEMGET (function)]], [[_MEMPUT]] | * [[_MEMGET (function)]], [[_MEMPUT]] | ||
* [[DEF SEG = 0]], [[Scancodes]] {{text|(demo)}} | * [[DEF SEG = 0]], [[Scancodes]] {{text|(demo)}} |
Revision as of 02:19, 23 January 2023
The PEEK function returns the value that is contained at a certain memory address offset. QB64 currently has limited access!
Syntax
- variable = PEEK(segment_offset)
- Reads the specified memory segment_offset value.
- Use DEF SEG before PEEK to specify which memory segment to work in.
- PEEK only reads the memory byte value. Not certain bits. (See AND)
- Important SCREEN segments using PEEK and POKE include &HB800 (text segment) and &HA000 (graphics segment).
- To return to Basic default segment use DEF SEG without any arguments.
- Warning: DEF SEG, VARSEG , VARPTR, PEEK or POKE access QB64's emulated 16 bit conventional memory block!
- It is highly recommended that QB64's _MEM memory system be used to avoid running out of memory.
Example: Checking the 8 keyboard bit settings using a PEEK return value.
SCREEN 12 DEF SEG = 0 ' BIOS area oldvalue = PEEK(1047) ' IMPORTANT! save initial setting to reset later DO: _LIMIT 100 port = PEEK(1047) IF port > 0 THEN LOCATE 26, 19: COLOR 11: PRINT "Turn ALL Locks off to see each key's bit value!" END IF COLOR 14:LOCATE 2, 25 PRINT "PEEK(1047) ="; port; "present keyboard port byte value" LOCATE 5, 35 IF (port AND 1) = 1 THEN COLOR 10: PRINT "R SHIFT PRESSED " ELSE COLOR 12: PRINT "R SHIFT RELEASED" LOCATE 7, 35 IF (port AND 2) = 2 THEN COLOR 10: PRINT "L SHIFT PRESSED " ELSE COLOR 12: PRINT "L SHIFT RELEASED" LOCATE 9, 35 IF (port AND 4) = 4 THEN COLOR 10: PRINT "CTRL KEY PRESSED " ELSE COLOR 12: PRINT "CTRL KEY RELEASED" LOCATE 11, 35 IF (port AND 8) = 8 THEN COLOR 10: PRINT "ALT KEY PRESSED " ELSE COLOR 12: PRINT "ALT KEY RELEASED" LOCATE 13, 35 IF (port AND 16) = 16 THEN COLOR 10: PRINT "SCROLL LOCK ON " ELSE COLOR 12: PRINT "SCROLL LOCK OFF" LOCATE 15, 35 IF (port AND 32) = 32 THEN COLOR 10: PRINT "NUMBER LOCK ON " ELSE COLOR 12: PRINT "NUMBER LOCK OFF" LOCATE 17, 35 IF (port AND 64) = 64 THEN COLOR 10: PRINT "CAPS LOCK ON " ELSE COLOR 12: PRINT "CAPS LOCK OFF" LOCATE 19, 35 IF (port AND 128) = 128 THEN COLOR 10: PRINT "INSERT MODE ON " ELSE COLOR 12: PRINT "INSERT MODE OFF" COLOR 11: LOCATE 21, 20: PRINT "Press mode keys to change or [ESC] to quit!"; LOOP UNTIL INP(&H60) = 1 ' escape key exit POKE 1047, oldvalue ' IMPORTANT reset to original settings DEF SEG |
- NOTE: Keyboard Port function key settings cannot be reset on NT machines!
See Example: SelectScreen (Screen 0 row highlighting)
See also:
- POKE (write to memory), INP (read register)
- DEF SEG, VARSEG, VARPTR
- _MEMGET (function), _MEMPUT
- DEF SEG = 0, Scancodes (demo)
- PEEK and POKE Library
- Screen Memory