ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
in.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
48/* <usermanual>
49@keyword IN
50
51@english
52
53The ''IN'' command is used to read a value from a specific input/output (I/O) port.
54The ''port'' parameter indicates the exact address of the I/O port from which you want to
55acquire the data. The port address varies depending on the architecture of the
56computer and the connected peripheral.
57
58When the program encounters the ''IN'' instruction, it stops executing and reads
59the binary value present on the specified port. The value read from the port is
60converted into a numeric format understandable by the program and is assigned
61to the value variable.
62
63The ''IN'' command is often used to read data from sensors connected to I/O ports,
64such as temperature, humidity, light sensors, etc. It can be used to control the
65status of external devices, such as motors, relays, displays, etc. In combination
66with other instructions, the ''IN'' command can be used to implement serial
67communication with other devices.
68
69@italian
70
71Il comando ''IN'' viene utilizzato per leggere un valore da una porta di
72input/output (I/O) specifica. Il parametro ''port'' indica l'indirizzo esatto della
73porta I/O da cui si desidera acquisire i dati. L'indirizzo della porta varia a
74seconda dell'architettura del computer e della periferica collegata.
75
76Quando il programma incontra l'istruzione ''IN'', interrompe l'esecuzione e
77legge il valore binario presente sulla porta specificata. Il valore letto dalla
78porta viene convertito in un formato numerico comprensibile dal programma e
79assegnato alla variabile valore.
80
81Il comando ''IN'' viene spesso utilizzato per leggere dati da sensori collegati
82a porte I/O, come temperatura, umidità, sensori di luce, ecc. Può essere
83utilizzato per controllare lo stato di dispositivi esterni, come motori, relè,
84display, ecc. In combinazione con altre istruzioni, il comando ''IN'' può essere
85utilizzato per implementare la comunicazione seriale con altri dispositivi.
86
87@syntax = IN(port)
88
89@example x = IN( &HBC00 )
90
91@target c128z
92@target coleco
93@target cpc
94@target msx1
95@target sc3000
96@target sg1000
97@target vg5000
98@target zx
99</usermanual> */
100
101Variable * in_var( Environment * _environment, char * _port ) {
102
103 Variable * port = variable_retrieve_or_define( _environment, _port, VT_WORD, 0 );
104
105 Variable * value = variable_temporary( _environment, VT_BYTE, "(value)" );
106
107 cpu_in( _environment, port->realName, value->realName );
108
109 return value;
110
111}
void cpu_in(Environment *_environment, char *_port, char *_value)
Definition 6309.c:6357
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * in_var(Environment *_environment, char *_port)
Emit ASM code for IN.
Definition in.c:101
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_BYTE
Definition ugbc.h:450