ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
tilemap_at.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
41extern char DATATYPE_AS_STRING[][16];
42
49/* <usermanual>
50@keyword TILEMAP AT
51
52@english
53This function allows to know which is the tile present in a tilemap,
54given the coordinates of the tile itself. If the tilemap has more than
55one layer, the first layer will be returned. If you need to retrieve the
56tile of a different level, you have to indicate the layer with the ''LAYER''
57keyword.
58
59@italian
60Questa funzione permette di conoscere quale sia il tile di una mappa,
61date le coordinate del tile stesso. Se la mappa ha più di un livello,
62verrà restituito il primo livello. Se si deve recuperare il tile
63di un livello diverso, si deve indicare con la parola chiave ''LAYER''.
64
65@syntax = TILEMAP [LAYER layer] map AT([x],[y])
66
67@example tile = TILEMAP map AT(0,0)
68@example tile = TILEMAP map LAYER 2 AT(0,0)
69
70@target all
71</usermanual> */
72Variable * tilemap_at( Environment * _environment, char * _tilemap, char * _x, char * _y, char * _layer ) {
73
74 Variable * tilemap = NULL;
75 Variable * x = NULL;
76 Variable * y = NULL;
77 Variable * layer = NULL;
78 Variable * frame = variable_temporary( _environment, VT_BYTE, "(frame)" );
79
80 tilemap = variable_retrieve( _environment, _tilemap );
81 if ( tilemap->type != VT_TILEMAP ) {
83 }
84
85 Variable * width = variable_temporary( _environment, VT_BYTE, "(width)" );
86 variable_store( _environment, width->name, tilemap->mapWidth );
87 Variable * height = NULL;
88 if ( _layer ) {
89 height = variable_temporary( _environment, VT_BYTE, "(height)" );
90 variable_store( _environment, height->name, tilemap->mapHeight );
91 }
92
93 x = variable_retrieve_or_define( _environment, _x, VT_BYTE, 0 );
94 y = variable_retrieve_or_define( _environment, _y, VT_BYTE, 0 );
95 if ( _layer ) {
96 layer = variable_retrieve_or_define( _environment, _layer, VT_BYTE, 0 );
97 }
98
99 Variable * mul = variable_mul( _environment, width->name, y->name );
100 Variable * offset = variable_add( _environment, mul->name, x->name );
101 if ( layer ) {
102 Variable * mul2 = variable_mul( _environment, width->name, height->name );
103 Variable * mul3 = variable_mul( _environment, mul2->name, layer->name );
104 variable_move( _environment, variable_add( _environment, mul3->name, offset->name )->name, offset->name );
105 }
106 cpu_move_8bit_indirect2_16bit( _environment, tilemap->realName, offset->realName, frame->realName );
107
108 return frame;
109
110}
111
void cpu_move_8bit_indirect2_16bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5323
Variable * variable_add(Environment *_environment, char *_source, char *_destination)
Add two variable and return the sum of them.
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.
Variable * variable_mul(Environment *_environment, char *_source, char *_destination)
Make a multiplication between two variable and return the product of them.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
int offset
Definition _optimizer.c:681
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
int mapHeight
Definition ugbc.h:1158
int mapWidth
Definition ugbc.h:1156
char * realName
Definition ugbc.h:982
Variable * tilemap_at(Environment *_environment, char *_tilemap, char *_x, char *_y, char *_layer)
Return the height of a TILEMAP.
Definition tilemap_at.c:72
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_TILEMAP
Definition ugbc.h:525
@ VT_BYTE
Definition ugbc.h:450
#define CRITICAL_TILEMAP_HEIGHT_NO_TILEMAP(v)
Definition ugbc.h:3652
char DATATYPE_AS_STRING[][16]