ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
locate.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 LOCATE
50
51@english
52The ''LOCATE'' command moves the text cursor to specific coordinates,
53and this new location sets the start position for all subsequent
54text printing until commanded otherwise.
55
56All console positions are measured in “text coordinates”, which are
57measured in units of one printed character on console, with the
58x-coordinate controlling the horizontal position and the
59y-coordinate referring to the vertical.
60
61The top left-hand corner of the console has coordinates of 0,0
62whereas text coordinates of 15,10 refer to a position 15 characters
63from the left-hand edge of the console and 10 characters from the top.
64
65The range of these coordinates will depend on the size of your character
66set and the dimensions of the display area allocated, known as a “console".
67
68All coordinate measurements are taken using text coordinates relative to
69the current console. If you try and print something outside of these
70console,the console will be automatically scrolled down.
71
72The current console is automatically treated as a window, so there is no
73need to "open" one.
74
75@italian
76Il comando ''LOCATE'' sposta il cursore del testo su coordinate specifiche,
77e questa nuova posizione definisce la posizione iniziale per tutti i successivi
78comandi di stampa testo fino a quando non viene comandato diversamente.
79
80Tutte le posizioni della console sono misurate in "coordinate di testo", che sono
81misurate in unità di un carattere stampato sulla console, con la coordinata x
82che controlla la posizione orizzontale e la coordinata y riferita alla
83posizione verticale.
84
85L'angolo in alto a sinistra della console ha coordinate 0,0
86mentre le coordinate di testo di 15,10 si riferiscono a una posizione di 15 caratteri
87dal bordo sinistro della console e 10 caratteri dall'alto.
88
89L'intervallo di queste coordinate dipenderà dalle dimensioni del carattere
90e le dimensioni dell'area di visualizzazione assegnata, denominata "console".
91
92Tutte le misurazioni di coordinate vengono effettuate utilizzando le coordinate
93di testo relative a la console corrente. Provare a stampare qualcosa al di fuori di questi
94limiti verrà automaticamente fatta scorrere verso il basso.
95
96La schermata corrente viene automaticamente trattata come una console, quindi non c'è
97bisogno di "aprirne" una.
98
99@syntax LOCATE [x],[y]
100
101@example LOCATE 15,0
102@example LOCATE ,20
103
104@usedInExample texts_position_01.bas
105@usedInExample texts_position_02.bas
106
107@seeAlso AT$
108@seeAlso CMOVE
109</usermanual> */
110void locate( Environment * _environment, char * _x, char * _y ) {
111
112 if ( _x ) {
113 Variable * windowCX = variable_retrieve( _environment, "XCURSYS" );
114 Variable * consoleX1 = variable_retrieve( _environment, "CONSOLEX1" );
115 Variable * x = variable_retrieve_or_define( _environment, _x, VT_BYTE, 0 );
116 variable_move( _environment, x->name, windowCX->name );
117 variable_add_inplace_vars( _environment, windowCX->name, consoleX1->name );
118 }
119
120 if ( _y ) {
121 Variable * windowCY = variable_retrieve( _environment, "YCURSYS" );
122 Variable * consoleY1 = variable_retrieve( _environment, "CONSOLEY1" );
123 Variable * y = variable_retrieve_or_define( _environment, _y, VT_BYTE, 0 );
124 variable_move( _environment, y->name, windowCY->name );
125 variable_add_inplace_vars( _environment, windowCY->name, consoleY1->name );
126 }
127
128}
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
void variable_add_inplace_vars(Environment *_environment, char *_source, char *_destination)
Add two variable and return the sum of them on the first.
void locate(Environment *_environment, char *_x, char *_y)
Emit code for LOCATE ...,....
Definition locate.c:110
char * name
Definition ugbc.h:979
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450