ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
poke.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 POKE
50
51@english
52
53The ''POKE'' is the write equivalent of the ''PEEK'' command, meaning it allows you
54to modify the contents of a specific memory cell. Essentially, ''POKE'' allows you
55to "write" a numeric value to a particular location in your computer's memory.
56
57In many 8-bit systems, ''POKE'' was used to directly configure hardware, such as
58changing the color of the screen or the sound. By combining ''POKE'' with ''PEEK'',
59you could create custom graphics and sound effects, going beyond the standard
60ugBASIC capabilities.
61
62''POKE'' gives you very fine-grained control over your computer's memory, and
63it allows you to create special effects and customizations that would otherwise
64be impossible. It is a great tool for understanding how a computer works internally.
65
66Improper use of ''POKE'' can cause your computer to freeze or corrupt data.
67Randomly modifying memory can have unpredictable consequences. Valid memory
68addresses and their meanings vary from system to system.
69
70There is also a version of this command that works within a copper list.
71
72@italian
73
74''POKE'' è l'equivalente in scrittura del comando ''PEEK'', il che significa
75che consente di modificare il contenuto di una specifica cella di memoria,
76ovvero di un singolo byte.
77In sostanza, ''POKE'' consente di "scrivere" un valore numerico in una posizione
78specifica nella memoria del computer.
79
80In molti sistemi a 8 bit, ''POKE'' veniva utilizzato per configurare direttamente
81l'hardware, ad esempio per cambiare il colore dello schermo o il suono. Combinando
82''POKE'' con ''PEEK'', era possibile creare effetti grafici ed effetti sonori
83personalizzati, andando oltre le capacità standard di ugBASIC.
84
85''POKE'' offre un controllo molto preciso sulla memoria del computer e consente
86di creare effetti speciali e personalizzazioni che altrimenti sarebbero
87impossibili. È un ottimo strumento per comprendere il funzionamento interno
88di un computer.
89
90L'uso improprio di ''POKE'' può causare il blocco o la corruzione dei dati
91del computer. La modifica casuale della memoria può avere conseguenze imprevedibili.
92Gli indirizzi di memoria validi e il loro significato variano da sistema a sistema.
93
94Esiste anche una versione di questo comando che funziona all'interno di una copper list.
95
96@syntax POKE address, value
97
98@example POKE 32768, 2
99
100@seeAlso POKEW
101@seeAlso POKED
102@seeAlso D!POKE
103
104</usermanual> */
105
106void poke_var( Environment * _environment, char * _address, char * _value ) {
107
108 Variable * address = variable_retrieve_or_define( _environment, _address, VT_ADDRESS, 0 );
109
110 if ( variable_exists( _environment, _value ) ) {
111 Variable * value = variable_retrieve( _environment, _value );
112 if ( VT_BITWIDTH( value->type ) == 8 ) {
113 cpu_poke( _environment, address->realName, value->realName );
114 } else {
115 Variable * realValue = variable_temporary( _environment, VT_BYTE, "(byte)" );
116 variable_move( _environment, value->name, realValue->name );
117 cpu_poke( _environment, address->realName, realValue->realName );
118 }
119 } else {
120 cpu_poke_const( _environment, address->realName, 0 );
121 }
122
123}
124
125/* <usermanual>
126@keyword POKEW
127
128@english
129
130The ''POKEW'' is the write equivalent of the ''PEEKW'' command, meaning it allows you
131to modify the contents of two memory cells. Essentially, ''POKEW'' allows you
132to "write" a numeric value to a particular location in your computer's memory.
133
134In many 8-bit systems, ''POKEW'' was used to directly configure hardware, such as
135changing the color of the screen or the sound. By combining ''POKEW'' with ''PEEKW'',
136you could create custom graphics and sound effects, going beyond the standard
137ugBASIC capabilities.
138
139''POKEW'' gives you very fine-grained control over your computer's memory, and
140it allows you to create special effects and customizations that would otherwise
141be impossible. It is a great tool for understanding how a computer works internally.
142
143Improper use of ''POKEW'' can cause your computer to freeze or corrupt data.
144Randomly modifying memory can have unpredictable consequences. Valid memory
145addresses and their meanings vary from system to system.
146
147There is also a version of this command that works within a copper list.
148
149@italian
150
151''POKEW'' è l'equivalente in scrittura del comando ''PEEKW'', il che significa
152che consente di modificare il contenuto di una specifica cella di memoria,
153ovvero di un singolo byte. In sostanza, ''POKEW'' consente di "scrivere" un
154valore numerico in una posizione specifica nella memoria del computer.
155
156In molti sistemi a 8 bit, ''POKEW'' veniva utilizzato per configurare direttamente
157l'hardware, ad esempio per cambiare il colore dello schermo o il suono. Combinando
158''POKEW'' con ''PEEKW'', era possibile creare effetti grafici ed effetti sonori
159personalizzati, andando oltre le capacità standard di ugBASIC.
160
161''POKEW'' offre un controllo molto preciso sulla memoria del computer e consente
162di creare effetti speciali e personalizzazioni che altrimenti sarebbero
163impossibili. È un ottimo strumento per comprendere il funzionamento interno
164di un computer.
165
166L'uso improprio di ''POKEW'' può causare il blocco o la corruzione dei dati
167del computer. La modifica casuale della memoria può avere conseguenze imprevedibili.
168Gli indirizzi di memoria validi e il loro significato variano da sistema a sistema.
169
170Esiste anche una versione di questo comando che funziona all'interno di una copper list.
171
172@syntax POKEW address, value
173
174@example POKEW 32768, 2
175
176@seeAlso POKE
177@seeAlso POKED
178@alias D!POKE
179
180</usermanual> */
181
182/* <usermanual>
183@keyword D!POKE
184@alias POKEW
185</usermanual> */
186
187void pokew_var( Environment * _environment, char * _address, char * _value ) {
188
189 Variable * address = variable_retrieve_or_define( _environment, _address, VT_ADDRESS, 0 );
190
191 if ( variable_exists( _environment, _value ) ) {
192 Variable * value = variable_retrieve( _environment, _value );
193 if ( VT_BITWIDTH( value->type ) == 16 ) {
194 cpu_pokew( _environment, address->realName, value->realName );
195 } else {
196 Variable * realValue = variable_temporary( _environment, VT_WORD, "(word)" );
197 variable_move( _environment, value->name, realValue->name );
198 cpu_pokew( _environment, address->realName, realValue->realName );
199 }
200 } else {
201 cpu_pokew_const( _environment, address->realName, 0 );
202 }
203
204}
205
206/* <usermanual>
207@keyword POKED
208
209@english
210
211The ''POKED'' is the write equivalent of the ''PEEKD'' command, meaning it allows you
212to modify the contents of four memory cells. Essentially, ''POKED'' allows you
213to "write" a numeric value to a particular location in your computer's memory.
214
215In many 8-bit systems, ''POKED'' was used to directly configure hardware, such as
216changing the color of the screen or the sound. By combining ''POKED'' with ''PEEKD'',
217you could create custom graphics and sound effects, going beyond the standard
218ugBASIC capabilities.
219
220''POKED'' gives you very fine-grained control over your computer's memory, and
221it allows you to create special effects and customizations that would otherwise
222be impossible. It is a great tool for understanding how a computer works internally.
223
224Improper use of ''POKED'' can cause your computer to freeze or corrupt data.
225Randomly modifying memory can have unpredictable consequences. Valid memory
226addresses and their meanings vary from system to system.
227
228There is also a version of this command that works within a copper list.
229
230@italian
231
232''POKED'' è l'equivalente in scrittura del comando ''PEEKD'', il che significa
233che consente di modificare il contenuto di una specifica cella di memoria,
234ovvero di un singolo byte. In sostanza, ''POKED'' consente di "scrivere" un
235valore numerico in una posizione specifica nella memoria del computer.
236
237In molti sistemi a 8 bit, ''POKED'' veniva utilizzato per configurare direttamente
238l'hardware, ad esempio per cambiare il colore dello schermo o il suono. Combinando
239''POKED'' con ''PEEKD'', era possibile creare effetti grafici ed effetti sonori
240personalizzati, andando oltre le capacità standard di ugBASIC.
241
242''POKED'' offre un controllo molto preciso sulla memoria del computer e consente
243di creare effetti speciali e personalizzazioni che altrimenti sarebbero
244impossibili. È un ottimo strumento per comprendere il funzionamento interno
245di un computer.
246
247L'uso improprio di ''POKED'' può causare il blocco o la corruzione dei dati
248del computer. La modifica casuale della memoria può avere conseguenze imprevedibili.
249Gli indirizzi di memoria validi e il loro significato variano da sistema a sistema.
250
251Esiste anche una versione di questo comando che funziona all'interno di una copper list.
252
253@syntax POKED address, value
254
255@example POKED 32768, 2
256
257@seeAlso POKE
258@seeAlso POKEW
259
260</usermanual> */
261
262void poked_var( Environment * _environment, char * _address, char * _value ) {
263
264 Variable * address = variable_retrieve_or_define( _environment, _address, VT_ADDRESS, 0 );
265
266 if ( variable_exists( _environment, _value ) ) {
267 Variable * value = variable_retrieve( _environment, _value );
268 if ( VT_BITWIDTH( value->type ) == 32 ) {
269 cpu_poked( _environment, address->realName, value->realName );
270 } else {
271 Variable * realValue = variable_temporary( _environment, VT_DWORD, "(dword)" );
272 variable_move( _environment, value->name, realValue->name );
273 cpu_poked( _environment, address->realName, realValue->realName );
274 }
275 } else {
276 cpu_poked_const( _environment, address->realName, 0 );
277 }
278
279
280}
void cpu_pokew(Environment *_environment, char *_address, char *_source)
Definition 6309.c:410
void cpu_poked(Environment *_environment, char *_address, char *_source)
Definition 6309.c:445
void cpu_poke_const(Environment *_environment, char *_address, int _source)
Definition 6309.c:388
void cpu_poked_const(Environment *_environment, char *_address, int _source)
Definition 6309.c:458
void cpu_pokew_const(Environment *_environment, char *_address, int _source)
Definition 6309.c:421
void cpu_poke(Environment *_environment, char *_address, char *_source)
Definition 6309.c:377
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int variable_exists(Environment *_environment, char *_name)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
void poked_var(Environment *_environment, char *_address, char *_value)
Definition poke.c:262
void poke_var(Environment *_environment, char *_address, char *_value)
Emit ASM code for POKE.
Definition poke.c:106
void pokew_var(Environment *_environment, char *_address, char *_value)
Definition poke.c:187
char * name
Definition ugbc.h:979
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_WORD
Definition ugbc.h:455
@ VT_BYTE
Definition ugbc.h:450
@ VT_DWORD
Definition ugbc.h:460
@ VT_ADDRESS
Definition ugbc.h:465
#define VT_BITWIDTH(t)
Definition ugbc.h:595