ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
asciicode.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 ASCII CODE
47
48@english
49
50The ''ASCII CODE'' command capture a keystroke "on the Fly",
51and return the equivalent ASCII code instead of internal ''SCANCODE''.
52This command is a fundamental tool for making programs more interactive.
53It allows you to read a character typed by the user without having to press
54the enter key.
55
56Unlike other input commands, ''ASCII CODE'' does not require the user to press
57Enter to send the character, while the typed character is not displayed on
58the screen. It return directly the ASCII code of the typed character, or
59a special value (0) if no key was pressed. It is equivalent to write
60''ASC( INKEY$() )'', but faster, since no string is created. Note that
61the reading speed could vary significantly depending on the target.
62
63This command allows you to create simple games in which the user must
64press specific keys to control a character or object. It can be used
65to create more responsive user interfaces, in which the user can interact
66with the program in real time or that respond to certain key combinations,
67automating certain operations.
68
69Due to the limitations of 7-bit ASCII encoding, ''ASCII CODE'' could only
70read characters in the standard ASCII set. Use ''SCANCODE'' if you need
71to be able to detect any key.
72
73@italian
74
75Il comando ''ASCII CODE'' cattura una pressione di tasto "al volo" e
76restituisce il codice ASCII equivalente invece dello ''SCANCODE'' interno.
77Questo comando è uno strumento fondamentale per rendere i programmi più interattivi.
78Consente di leggere un carattere digitato dall'utente senza dover premere il
79tasto Invio.
80
81A differenza di altri comandi di input, ''ASCII CODE'' non richiede all'utente
82di premere Invio per inviare il carattere, mentre il carattere digitato non
83viene visualizzato sullo schermo. Restituisce direttamente il codice ASCII
84del carattere digitato o un valore speciale (0) se non è stato premuto alcun
85tasto. È equivalente alla scrittura di ''ASC(INKEY$())'', ma più veloce,
86poiché non viene creata alcuna stringa. Nota che la velocità di lettura
87potrebbe variare in modo significativo a seconda del target.
88
89Questo comando consente di creare semplici giochi in cui l'utente
90deve premere tasti specifici per controllare un personaggio o
91un oggetto. Può essere utilizzato per creare interfacce utente
92più reattive, in cui l'utente può interagire con il programma in
93tempo reale o che rispondono a determinate combinazioni di tasti,
94automatizzando determinate operazioni.
95
96A causa delle limitazioni della codifica ASCII a 7 bit, ''ASCII CODE''
97poteva leggere solo caratteri nel set ASCII standard. Utilizzare
98''SCANCODE'' se è necessario essere in grado di rilevare qualsiasi
99tasto.
100
101@syntax = ASCII CODE
102
103@example IF ASCII CODE = 42 THEN
104@example PRINT "ASTERISK has been pressed!"
105@example ENDIF
106
107@seeAlso SCANCODE
108@alias ASCIICODE
109
110</usermanual> */
111
112/* <usermanual>
113@keyword ASCIICODE
114
115@english
116
117@italian
118
119@syntax = ASCIICODE
120
121@example IF ASCIICODE = 42 THEN
122@example PRINT "ASTERISK has been pressed!"
123@example ENDIF
124
125@seeAlso SCANCODE
126@alias ASCII CODE
127
128</usermanual> */
129
130Variable * asciicode( Environment * _environment ) {
131
132 Variable * result = variable_temporary( _environment, VT_BYTE, "(result of ASCIICODE)");
133
134 cia_asciicode( _environment, result->realName );
135
136 return result;
137
138}
139
140#endif
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * asciicode(Environment *_environment)
Definition asciicode.c:43
void cia_asciicode(Environment *_environment, char *_result)
Definition cia.c:166
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450
char DATATYPE_AS_STRING[][16]