ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
put_key.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
41#if defined(__c128__) || defined(__c64__) || defined(__c64reu__)
42
43extern char DATATYPE_AS_STRING[][16];
44
45/* <usermanual>
46@keyword PUT KEY
47
48@english
49
50The ''PUT KEY'' command allows you to simulate pressing a key on your computer
51keyboard. Basically, you enter a string of characters and ugBASIC will use
52it as if they were typed one after the other. This can be very useful for
53automating certain actions, such as automatically entering your password
54or emulating keystrokes.
55
56This can be used to automatically enters a password into a game or application,
57or to simulate an user interaction with the program itself, such as pressing a
58button or selecting a menu. It can help to create sequences of commands that
59are executed automatically, such as a macro.
60
61The maximum length of the string you can enter depends on the keyboard buffer,
62but normally is up to 10 characters.
63
64Please note that this feature is available with the "asynchronous" keyboard
65reading mechanism or in some specific, selected targets. To enable this
66keyboard reading mode you must use the ''DEFINE KEYBOARD ASYNC''.
67
68@italian
69
70Il comando ''PUT KEY'' consente di simulare la pressione di un tasto sulla
71tastiera del computer. In pratica, si immette una stringa di caratteri e
72ugBASIC la utilizzerà come se fossero stati digitati uno dopo l'altro.
73 Questo può essere molto utile per automatizzare determinate azioni, come
74 l'immissione automatica della password o l'emulazione di sequenze di tasti.
75
76Questo può essere utilizzato per immettere automaticamente una password in un
77gioco o in un'applicazione, o per simulare un'interazione dell'utente con il
78programma stesso, come la pressione di un pulsante o la selezione di un menu.
79Può aiutare a creare sequenze di comandi che vengono eseguiti automaticamente,
80come una macro.
81
82La lunghezza massima della stringa che è possibile immettere dipende dal
83buffer della tastiera, ma normalmente è fino a 10 caratteri.
84
85Da notare che questa funzionalità è disponibile con il meccanismo di lettura
86della tastiera di tipo "asincrono" oppure in alcuni, specifici, target selezionati.
87Per abilitare questa modalità di lettura della tastiera è necessario utilizzare
88la direttiva ''DEFINE KEYBOARD ASYNC''.
89
90@syntax PUT KEY string
91
92@example PUT KEY "yes"
93
94@target atari
95@target atarixl
96@target c128
97@target c64
98@target c64reu
99@target coco
100@target coco3
101@target cpc
102@target d32
103@target d64
104@target mo5
105@target msx1
106@target pc128op
107@target plus4
108@target sg1000
109@target to8
110@target vic20
111</usermanual> */
112
113void put_key( Environment * _environment, char * _string ) {
114
115 Variable * string = variable_retrieve( _environment, _string );
116 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(address)" );
117 Variable * size = variable_temporary( _environment, VT_BYTE, "(size)" );
118
119 switch( string->type ) {
120 case VT_STRING:
121 cpu_move_8bit( _environment, string->realName, size->realName );
122 cpu_addressof_16bit( _environment, string->realName, address->realName );
123 cpu_inc_16bit( _environment, address->realName );
124 break;
125 case VT_DSTRING:
126 cpu_dsdescriptor( _environment, string->realName, address->realName, size->realName );
127 break;
128 case VT_CHAR:
129 cpu_addressof_16bit( _environment, string->realName, address->realName );
130 cpu_store_8bit( _environment, size->realName, 1 );
131 break;
132 }
133
134 cia_put_key( _environment, address->realName, size->realName );
135
136}
137
138#endif
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6309.c:5977
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int size
Definition _optimizer.c:678
void put_key(Environment *_environment, char *_string)
Definition put_key.c:43
void cia_put_key(Environment *_environment, char *_string, char *_size)
Definition cia.c:240
VariableType type
Definition ugbc.h:988
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_STRING
Definition ugbc.h:474
@ VT_BYTE
Definition ugbc.h:450
@ VT_CHAR
Definition ugbc.h:498
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_DSTRING
Definition ugbc.h:483
char DATATYPE_AS_STRING[][16]