;*******************************************************************************
; Title:        TestACS
; Author:       Fred Graute
; Copyright:    (C) Fred Graute 2006
; Version:      1.06, Sunday the 7th of May, 2006
;
; Changes:      Converted to ObjAsm source code by Philip Ludlam
;               Updated for the A9home by Fred Graute
;
;*******************************************************************************
; This program is free software; you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the Free
; Software Foundation; either version 2 of the License, or (at your option)
; any later version.
;
; This program is distributed in the hope that it will be useful, but WITHOUT
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
; FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more
; details.
;
; You should have received a copy of the GNU General Public License along with
; this program; if not, write to the Free Software Foundation, Inc., 59 Temple
; Place - Suite 330, Boston, MA 02111-1307, USA

;*******************************************************************************

                TTL     > TestACS

                GET     hdr.Macros
                GET     hdr.DebugRep
                GET     hdr.RegNames
                GET     hdr.SWINames

                AREA    TestACS,CODE,READONLY

                ENTRY

;-------------------------------------------------------------------------------
Start           B       Entry                   ; Entry instruction
                DCD     &79766748               ; Magic value 1
                DCD     &216C6776               ; Magic value 2
                DCD     End-Start               ; Read only size
                DCD     0                       ; Read/write size
                DCD     32                      ; 26 or 32 bit build

Entry           SWI     OS_EnterOS
                MOV     R9,#2                   ;
                ADR     R8,VarNames             ; -> list of variable names

Loop            MOV     R7,#0                   ; 0,1,2,3 = none,left,right,both
                MOV     R0,#&79                 ; reason = &79 => scan keyboard

                cmp     r9,#1
                FN_Debug "Testing Shift","LO",&10000
                FN_Debug "Testing Ctrl","EQ",&10000
                FN_Debug "Testing Alt","HI",&10000

                ADD     R1,R9,#&83              ; test left modifier key
                SWI     XOS_Byte                ; returns &FF if pressed, else 0
                MOVVS   R1,#0                   ; if error then not pressed
                CMP     R1,#&FF                 ; return EQ if pressed, else NE
                ORREQ   R7,R7,#1                ; if left key pressed set bit 0

                ADD     R1,R9,#&86              ; test right modifier key
                SWI     XOS_Byte                ; returns &FF if pressed, else 0
                MOVVS   R1,#0                   ; if error then not pressed
                CMP     R1,#&FF                 ; return EQ if pressed, else NE
                ORREQ   R7,R7,#2                ; if right key pressed set bit 1

                FN_Debug "Right mod down","EQ",&10000
                FN_Debug "Right mod up","NE",&10000

                STR     R7,[R12,#0]             ; store value to set variable to

                ADD     R0,R8,R9,LSL #4         ; -> variable name
                FN_Debug "Variable name = %0s","",&10000
                FN_Debug "Value to set  = %7x","",&10000
                FN_Debug "--#--","",&10000
                ADD     R1,R12,#0               ; -> value to set variable to
                MOV     R2,#4                   ; size of value, 4 since integer
                MOV     R3,#0                   ; 0 => no name pointer
                MOV     R4,#1                   ; 1 => variable is an integer
                SWI     XOS_SetVarVal           ; assign value to variable

                SUBS    R9,R9,#1                ;
                BPL     Loop                    ;

                FN_Debug "Dump regs","",&0
                SWI     &7C
                MOV     PC,LR                   ; say bye bye

                dbpf_Rep

VarNames
VarShift        DCSP   16,"Shift$Pressed"
VarCtrl         DCSP   16,"Ctrl$Pressed"
VarAlt          DCSP   16,"Alt$Pressed"
Licence         DCS    " FJG, 2006. Licence: GPL."
                ALIGN

End
                END
