ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
peek.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
52/* <usermanual>
53@keyword PEEK
54
55@english
56
57''PEEK'' is a command that allows you to "peek" into
58your computer's memory. In practice, it allows you to read the value stored
59in a specific memory cell.
60
61When using ''PEEK'', you give the command the memory ''address'' you want to know
62the contents of. The command will then return the numeric value (a byte)
63stored at that address.
64
65''PEEK'' allows you to read data directly from memory, without going
66through the normal program variables. On some systems, it is possible to
67read the state of input/output ports using ''PEEK''. With caution,
68''PEEK'' can be used to access memory reserved for the operating system,
69or the ugBASIC program. Although it is generally discouraged, as it can
70cause system instability or crashes, it can also speed up some operations.
71
72The use of ''PEEK'' is highly dependent on the computer architecture and
73operating system. Valid memory addresses and the meaning of the values
74read may vary from one system to another. Improper use of ''PEEK'' can cause
75damage to your system or corrupt data. It is important to have a thorough
76understanding of how your computer works before using this command.
77
78@italian
79
80''PEEK'' è un comando che consente di "sbirciare"
81nella memoria del computer. In pratica, consente di leggere il valore
82memorizzato in una specifica cella di memoria.
83
84Quando si utilizza ''PEEK'', si fornisce al comando l'''indirizzo'' di memoria
85di cui si desidera conoscere il contenuto. Il comando restituirà quindi il
86valore numerico (un byte) memorizzato in quell'indirizzo.
87
88''PEEK'' consente di leggere i dati direttamente dalla memoria, senza passare
89attraverso le normali variabili del programma. Su alcuni sistemi, è possibile
90leggere lo stato delle porte di input/output utilizzando ''PEEK''. Con cautela,
91''PEEK'' può essere utilizzato per accedere alla memoria riservata al sistema
92operativo o al programma ugBASIC. Sebbene sia generalmente sconsigliato,
93in quanto può causare instabilità o crash del sistema, può anche velocizzare
94alcune operazioni.
95
96L'utilizzo di ''PEEK'' dipende fortemente dall'architettura del computer e
97dal sistema operativo. Gli indirizzi di memoria validi e il significato dei
98valori letti possono variare da un sistema all'altro. L'uso improprio di
99''PEEK'' può causare danni al sistema o dati corrotti. È importante avere
100una conoscenza approfondita del funzionamento del computer prima di utilizzare
101questo comando.
102
103@syntax = PEEK( address )
104
105@example x = PEEK(1024)
106
107@seeAlso PEEKW
108@seeAlso PEEKD
109@seeAlso D!PEEKW
110
111@alias MEMPEEK
112
113</usermanual> */
114
115/* <usermanual>
116@keyword MEMPEEK
117
118@english
119
120@italian
121
122@syntax = MEMPEEK( address )
123
124@example x = MEMPEEK(1024)
125
126@alias PEEK
127
128</usermanual> */
129
130Variable * peek_var( Environment * _environment, char * _location ) {
131
132 Variable * location = variable_retrieve_or_define( _environment, _location, VT_ADDRESS, 0 );
133
134 Variable * result = variable_temporary( _environment, VT_BYTE, "(result)" );
135
136 cpu_peek( _environment, location->realName, result->realName );
137
138 return result;
139
140}
141
142/* <usermanual>
143@keyword PEEKW
144
145@english
146
147''PEEKW'' is a command that allows you to "peek" into
148your computer's memory. In practice, it allows you to read the value stored
149in a specific memory cell.
150
151When using ''PEEKW'', you give the command the memory ''address'' you want to know
152the contents of. The command will then return the numeric value (a word)
153stored at that address.
154
155''PEEKW'' allows you to read data directly from memory, without going
156through the normal program variables. On some systems, it is possible to
157read the state of input/output ports using ''PEEKW''. With caution,
158''PEEKW'' can be used to access memory reserved for the operating system,
159or the ugBASIC program. Although it is generally discouraged, as it can
160cause system instability or crashes, it can also speed up some operations.
161
162The use of ''PEEKW'' is highly dependent on the computer architecture and
163operating system. Valid memory addresses and the meaning of the values
164read may vary from one system to another. Improper use of ''PEEKW'' can cause
165damage to your system or corrupt data. It is important to have a thorough
166understanding of how your computer works before using this command.
167
168@italian
169
170''PEEKW'' è un comando che consente di "sbirciare"
171nella memoria del computer. In pratica, consente di leggere il valore
172memorizzato in una specifica cella di memoria.
173
174Quando si utilizza ''PEEKW'', si fornisce al comando l'''address'' di memoria
175di cui si desidera conoscere il contenuto. Il comando restituirà quindi il
176valore numerico (un byte) memorizzato in quell'indirizzo.
177
178''PEEKW'' consente di leggere i dati direttamente dalla memoria, senza passare
179attraverso le normali variabili del programma. Su alcuni sistemi, è possibile
180leggere lo stato delle porte di input/output utilizzando ''PEEKW''. Con cautela,
181''PEEKW'' può essere utilizzato per accedere alla memoria riservata al sistema
182operativo o al programma ugBASIC. Sebbene sia generalmente sconsigliato,
183in quanto può causare instabilità o crash del sistema, può anche velocizzare
184alcune operazioni.
185
186L'utilizzo di ''PEEKW'' dipende fortemente dall'architettura del computer e
187dal sistema operativo. Gli indirizzi di memoria validi e il significato dei
188valori letti possono variare da un sistema all'altro. L'uso improprio di
189''PEEKW'' può causare danni al sistema o dati corrotti. È importante avere
190una conoscenza approfondita del funzionamento del computer prima di utilizzare
191questo comando.
192
193@syntax = PEEKW( address )
194
195@example x = PEEKW(1024)
196
197@seeAlso PEEK
198@seeAlso PEEKD
199@alias D!PEEK
200
201</usermanual> */
202
203Variable * peekw_var( Environment * _environment, char * _location ) {
204
205 Variable * location = variable_retrieve_or_define( _environment, _location, VT_ADDRESS, 0 );
206
207 Variable * result = variable_temporary( _environment, VT_WORD, "(result)" );
208
209 cpu_peekw( _environment, location->realName, result->realName );
210
211 return result;
212
213}
214
215/* <usermanual>
216@keyword PEEKD
217
218@english
219
220''PEEKD'' is a command that allows you to "peek" into
221your computer's memory. In practice, it allows you to read the value stored
222in a specific memory cell.
223
224When using ''PEEKD'', you give the command the memory ''address'' you want to know
225the contents of. The command will then return the numeric value (a double word)
226stored at that address.
227
228''PEEKD'' allows you to read data directly from memory, without going
229through the normal program variables. On some systems, it is possible to
230read the state of input/output ports using ''PEEKD''. With caution,
231''PEEKD'' can be used to access memory reserved for the operating system,
232or the ugBASIC program. Although it is generally discouraged, as it can
233cause system instability or crashes, it can also speed up some operations.
234
235The use of ''PEEKD'' is highly dependent on the computer architecture and
236operating system. Valid memory addresses and the meaning of the values
237read may vary from one system to another. Improper use of ''PEEKD'' can cause
238damage to your system or corrupt data. It is important to have a thorough
239understanding of how your computer works before using this command.
240
241@italian
242
243''PEEKD'' è un comando che consente di "sbirciare"
244nella memoria del computer. In pratica, consente di leggere il valore
245memorizzato in una specifica cella di memoria.
246
247Quando si utilizza ''PEEKD'', si fornisce al comando l'''address'' di memoria
248di cui si desidera conoscere il contenuto. Il comando restituirà quindi il
249valore numerico (un byte) memorizzato in quell'indirizzo.
250
251''PEEKD'' consente di leggere i dati direttamente dalla memoria, senza passare
252attraverso le normali variabili del programma. Su alcuni sistemi, è possibile
253leggere lo stato delle porte di input/output utilizzando ''PEEKD''. Con cautela,
254''PEEKD'' può essere utilizzato per accedere alla memoria riservata al sistema
255operativo o al programma ugBASIC. Sebbene sia generalmente sconsigliato,
256in quanto può causare instabilità o crash del sistema, può anche velocizzare
257alcune operazioni.
258
259L'utilizzo di ''PEEKD'' dipende fortemente dall'architettura del computer e
260dal sistema operativo. Gli indirizzi di memoria validi e il significato dei
261valori letti possono variare da un sistema all'altro. L'uso improprio di
262''PEEKD'' può causare danni al sistema o dati corrotti. È importante avere
263una conoscenza approfondita del funzionamento del computer prima di utilizzare
264questo comando.
265
266@syntax = PEEKD( address )
267
268@example x = PEEKD(1024)
269
270@seeAlso PEEK
271@seeAlso PEEKW
272
273</usermanual> */
274Variable * peekd_var( Environment * _environment, char * _location ) {
275
276 Variable * location = variable_retrieve_or_define( _environment, _location, VT_ADDRESS, 0 );
277
278 Variable * result = variable_temporary( _environment, VT_DWORD, "(result)" );
279
280 cpu_peekd( _environment, location->realName, result->realName );
281
282 return result;
283
284}
void cpu_peekd(Environment *_environment, char *_address, char *_target)
Definition 6309.c:432
void cpu_peekw(Environment *_environment, char *_address, char *_target)
Definition 6309.c:399
void cpu_peek(Environment *_environment, char *_address, char *_target)
Definition 6309.c:366
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 * peekd_var(Environment *_environment, char *_location)
Definition peek.c:274
Variable * peek_var(Environment *_environment, char *_location)
Emit ASM code for PEEK(...).
Definition peek.c:130
Variable * peekw_var(Environment *_environment, char *_location)
Definition peek.c:203
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
@ VT_DWORD
Definition ugbc.h:460
@ VT_ADDRESS
Definition ugbc.h:465