ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
console_restore.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
46/* <usermanual>
47@keyword CONSOLE RESTORE
48
49@english
50The command ''CONSOLE RESTORE'' allows you to restore the constraints of the given
51console, previously saved with the command ''CONSOLE SAVE''.
52
53@italian
54Il comando ''CONSOLE RESTORE'' permette di ripristinare i vincoli della console
55data, e salvati in precedenza con il comando ''CONSOLE SAVE''.
56
57@syntax CONSOLE RESTORE number
58
59@example CONSOLE RESTORE 2
60
61@target all
62</usermanual> */
63/* <usermanual>
64@keyword CONSOLE USE
65
66@english
67
68@italian
69
70@syntax CONSOLE USE number
71
72@example CONSOLE USE 2
73
74@target all
75</usermanual> */
76void console_restore( Environment * _environment, int _number ) {
77
79 int displacement;
80
81 if ( _number == _environment->activeConsole.id ) {
82 return;
83 }
84
85 Variable * xcursys = variable_retrieve( _environment, "XCURSYS" );
86 Variable * ycursys = variable_retrieve( _environment, "YCURSYS" );
87
88 // -----------------------
89
90 displacement = ( _environment->activeConsole.id * 8 ) + 6;
91
92 sprintf( offset, "+%d", displacement++ );
93 cpu_move_8bit( _environment, xcursys->realName, address_displacement( _environment, "CONSOLES", offset ) );
94 sprintf( offset, "+%d", displacement++ );
95 cpu_move_8bit( _environment, ycursys->realName, address_displacement( _environment, "CONSOLES", offset ) );
96
97 memcpy( &_environment->activeConsole, &_environment->consoles[_number], sizeof( Console ) );
98
99 displacement = ( _number * 8 );
100
101 cpu_store_8bit( _environment, "CONSOLEID", _number );
102
103 sprintf( offset, "+%d", displacement++ );
104 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), "CONSOLEX1" );
105 sprintf( offset, "+%d", displacement++ );
106 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), "CONSOLEY1" );
107 sprintf( offset, "+%d", displacement++ );
108 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), "CONSOLEX2" );
109 sprintf( offset, "+%d", displacement++ );
110 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), "CONSOLEY2" );
111 sprintf( offset, "+%d", displacement++ );
112 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), "CONSOLEW" );
113 sprintf( offset, "+%d", displacement++ );
114 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), "CONSOLEH" );
115
116 sprintf( offset, "+%d", displacement++ );
117 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), xcursys->realName );
118 sprintf( offset, "+%d", displacement++ );
119 cpu_move_8bit( _environment, address_displacement( _environment, "CONSOLES", offset ), ycursys->realName );
120
121 console_calculate_vars( _environment );
122
123}
124
125void console_restore_vars( Environment * _environment, char * _number ) {
126
127 Variable * xcursys = variable_retrieve( _environment, "XCURSYS" );
128 Variable * ycursys = variable_retrieve( _environment, "YCURSYS" );
129
131
132 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(consoles)" );
133 cpu_addressof_16bit( _environment, "CONSOLES", address->realName );
134
135 Variable * number = variable_retrieve_or_define( _environment, _number, VT_BYTE, 0 );
136 char doNothingLabel[MAX_TEMPORARY_STORAGE]; sprintf( doNothingLabel, "%sconsole", label );
137 char doNothingLabel2[MAX_TEMPORARY_STORAGE]; sprintf( doNothingLabel2, "%sconsole2", label );
138 cpu_compare_and_branch_8bit_const( _environment, "CONSOLEID", 0xff, doNothingLabel2, 1 );
139 cpu_compare_and_branch_8bit( _environment, number->realName, "CONSOLEID", doNothingLabel, 1 );
140
141 Variable * actualNumber = variable_temporary( _environment, VT_BYTE, 0 );
142 cpu_move_8bit( _environment, "CONSOLEID", actualNumber->realName );
143
144 cpu_math_mul2_const_8bit( _environment, actualNumber->realName, 3, 0 );
145 cpu_math_add_16bit_with_8bit( _environment, address->realName, actualNumber->realName, address->realName );
146 cpu_math_add_16bit_const( _environment, address->realName, 6, address->realName );
147 cpu_move_8bit_indirect( _environment, xcursys->realName, address->realName );
148
149 cpu_move_8bit_indirect( _environment, xcursys->realName, address->realName );
150 cpu_inc_16bit( _environment, address->realName );
151 cpu_move_8bit_indirect( _environment, ycursys->realName, address->realName );
152
153 cpu_label( _environment, doNothingLabel2 );
154
155 cpu_move_8bit( _environment, number->realName, "CONSOLEID" );
156 cpu_addressof_16bit( _environment, "CONSOLES", address->realName );
157
158 cpu_move_8bit( _environment, "CONSOLEID", actualNumber->realName );
159 cpu_math_mul2_const_8bit( _environment, actualNumber->realName, 3, 0 );
160 cpu_math_add_16bit_with_8bit( _environment, address->realName, actualNumber->realName, address->realName );
161
162 cpu_move_8bit_indirect2( _environment, address->realName, "CONSOLEX1" );
163 cpu_inc_16bit( _environment, address->realName );
164 cpu_move_8bit_indirect2( _environment, address->realName, "CONSOLEY1" );
165 cpu_inc_16bit( _environment, address->realName );
166 cpu_move_8bit_indirect2( _environment, address->realName, "CONSOLEX2" );
167 cpu_inc_16bit( _environment, address->realName );
168 cpu_move_8bit_indirect2( _environment, address->realName, "CONSOLEY2" );
169 cpu_inc_16bit( _environment, address->realName );
170 cpu_move_8bit_indirect2( _environment, address->realName, "CONSOLEW" );
171 cpu_inc_16bit( _environment, address->realName );
172 cpu_move_8bit_indirect2( _environment, address->realName, "CONSOLEH" );
173 cpu_inc_16bit( _environment, address->realName );
174 cpu_move_8bit_indirect2( _environment, address->realName, xcursys->realName );
175 cpu_inc_16bit( _environment, address->realName );
176 cpu_move_8bit_indirect2( _environment, address->realName, ycursys->realName );
177
178 console_calculate_vars( _environment );
179
180 cpu_label( _environment, doNothingLabel );
181
182}
void cpu_math_mul2_const_8bit(Environment *_environment, char *_source, int _steps, int _signed)
CPU 6309: emit code to double for several times a 8 bit value
Definition 6309.c:1397
void cpu_math_add_16bit_with_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
Definition 6309.c:1708
void cpu_move_8bit_indirect(Environment *_environment, char *_source, char *_value)
Definition 6309.c:5239
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
void cpu_math_add_16bit_const(Environment *_environment, char *_source, int _destination, char *_other)
Definition 6309.c:1674
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_move_8bit_indirect2(Environment *_environment, char *_value, char *_source)
Definition 6309.c:5294
void cpu_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
void cpu_compare_and_branch_8bit(Environment *_environment, char *_source, char *_destination, char *_label, int _positive)
Definition 6309.c:851
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
void console_calculate_vars(Environment *_environment)
Definition 6847.c:316
Variable * variable_retrieve(Environment *_environment, char *_name)
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.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
int offset
Definition _optimizer.c:681
void console_restore(Environment *_environment, int _number)
Emit code for CONSOLE.
void console_restore_vars(Environment *_environment, char *_number)
int id
Definition ugbc.h:2204
Console activeConsole
Definition ugbc.h:2910
Console consoles[MAX_CONSOLES]
Definition ugbc.h:2916
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450
@ VT_ADDRESS
Definition ugbc.h:465
struct _Console Console
#define MAKE_LABEL
Definition ugbc.h:3351