 REM >SerPortTst

 REM This program displays the status of joysticks one and two using
 REM the 'Joystick_Status' SWI that is compatible with the standard
 REM set by 'The Serial Port'.

 REM Set up the screen
 MODE 0
 @% = &506
 PRINT "Joystick status read using 'The Serial Port' standard SWI..."
 VDU 28,0,31,79,4

 loops%=0
 REPEAT
   IF loops%=0 OR loops%>20 THEN
     loops%=0
     PRINT ',"R1","L1","D1","U1","F1"," ","R2","L2","D2","U2","F2"
   ENDIF

   REM Read the current state of both joysticks
   REM (Could also use: SYS &81540 TO status%)
   SYS "Joystick_Status" TO status%
   REM SYS &81540 TO status%

   REM Print out the current state of each joystick
   FOR stick%=0 TO 8 STEP 8

     REM Print out the current state of each "field"
     FOR field%=0 TO 4

         pressed% = (status% AND 1 << (field% + stick%)) <> 0
         PRINT ;pressed%,;

     NEXT
     PRINT " ",;
     WAIT

   NEXT
   PRINT

   loops% = loops% + 1

   oldtime% = TIME
   REPEAT UNTIL TIME-oldtime% > 50


 UNTIL FALSE

 END
