reading the keyboard from VolksForth#

(Basic taken from "Thomas E. Rowley - Atari Basic spielend lernen")

Basic Version #

10 REM read a keypress
20 PRINT "PRESS ANY KEY"
30 POKE 764,255
35 IF PEEK(764)=255 THEN 35
36 KEY=PEEK(764)
40 CLOSE #1:OPEN #1,4,0,"K:":GET #1,A
50 PRINT "The Key-Code of "; CHR$(A); " is "; KEY
60 GOTO 30

volksForth version using direct memory access the same way as the BASIC example does#

: GETKEY ( read a keypress )
  ." Press any key" CR
  255 764 C!
  BEGIN
        764 C@
        255 < IF
           764 C@ 
           KEY ." The Key-Code of " DUP EMIT ."  is " . CR
           255 764 C!
        THEN
  REPEAT ;

alternative, more elegant version using the build in words "KEY?" and "KEY"

: GETKEY ( read a keypress )
  ." Press any key" CR
  BEGIN
        KEY? IF
           764 C@ KEY 
           ." The Key-Code of "  DUP EMIT ." is "  . CR
        THEN
  REPEAT ;
 

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-3) was last changed on 03-Feb-2023 16:21 by Carsten Strotmann  
G’day (anonymous guest) My Prefs
© 2010-2021 AtariWiki
All content in the Wiki is licensed under Creative Commons Share Alike License, unless otherwise noted.
JSPWiki v2.8.3