ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
tilemap_index.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
43/* <usermanual>
44@keyword TILEMAP INDEX
45
46@english
47
48The ''TILEMAP INDEX'' allows you to know the identifier of the tile located
49in correspondence with the given set of coordinates. In particular, given a
50tile map as parameter, you can know what the tile is at the x, y position and,
51if present and given, at the given layer.
52
53@italian
54
55L'istruzione ''TILEMAP INDEX'' consente di conoscere l'identificativo della
56tile che si trova in corrispondenza del set di coordinate date. In particolare,
57data una mappa di tiles come parametro, si può conoscere quale sia il tile alla
58posizione x, y e, se presente, al layer dato.
59
60@syntax = TILEMAP INDEX( column, row [, layer] )
61
62@example index = TILEMAP INDEX( 0, 0 )
63@example index = TILEMAP INDEX( 0, 0, 1 )
64
65@seeAlso TILEMAP TILE AT
66
67@target all
68@verified
69</usermanual> */
70/* <usermanual>
71@keyword TILEMAP TILE AT
72
73@english
74
75@italian
76
77@syntax = TILEMAP TILE AT( column, row [, layer] )
78
79@example index = TILEMAP TILE AT( 0, 0 )
80@example index = TILEMAP TILE AT( 0, 0, 1 )
81
82@alias TILEMAP INDEX
83
84@target all
85@verified
86</usermanual> */
87
88Variable * tilemap_index_vars( Environment * _environment, char * _tilemap, char * _column, char * _row, char * _layer ) {
89
91
92 Variable * tilemap = NULL;
93 Variable * column = NULL;
94 Variable * row = NULL;
95 Variable * layer = NULL;
96
97 if ( _column ) {
98 column = variable_retrieve( _environment, _column );
99 }
100
101 if ( _row ) {
102 row = variable_retrieve( _environment, _row );
103 }
104
105 if ( _layer ) {
106 layer = variable_retrieve( _environment, _layer );
107 }
108
109 tilemap = variable_retrieve( _environment, _tilemap );
110 if ( tilemap->type != VT_TILEMAP ) {
112 }
113
114 Variable * tileset = variable_retrieve( _environment, tilemap->tileset->name );
115
116 int size = tilemap->mapWidth * tilemap->mapHeight;
117
118 Variable * index = NULL;
119
120 if ( tilemap->size > 255 ) {
121 index = variable_temporary( _environment, VT_WORD, "(index)" );
122 } else {
123 index = variable_temporary( _environment, VT_BYTE, "(index)" );
124 }
125
126 variable_store( _environment, index->name, 0 );
127
128 if ( row && column ) {
129 Variable * mapWidth = variable_temporary( _environment, VT_BYTE, "(map width)");
130 variable_store( _environment, mapWidth->name, tilemap->mapWidth );
131 index = variable_add( _environment, index->name, variable_mul( _environment, row->name, mapWidth->name )->name );
132 index = variable_add( _environment, index->name, column->name );
133 }
134
135 if ( layer ) {
136 Variable * sizeSize = variable_temporary( _environment, VT_WORD, "(size)");
137 variable_store( _environment, sizeSize->name, size );
138 index = variable_add( _environment, index->name, variable_mul( _environment, layer->name, sizeSize->name )->name );
139 }
140
141 Variable * frame = variable_temporary( _environment, VT_BYTE, "(frame)" );
142
143 if ( tilemap->size > 255 ) {
144 cpu_move_8bit_indirect2_16bit( _environment, tilemap->realName, index->realName, frame->realName );
145 } else {
146 cpu_move_8bit_indirect2_8bit( _environment, tilemap->realName, index->realName, frame->realName );
147 }
148
149 return frame;
150
151}
152
void cpu_move_8bit_indirect2_8bit(Environment *_environment, char *_value, char *_offset, char *_source)
Definition 6309.c:5307
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_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 size
Definition _optimizer.c:678
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
Variable * tilemap_index_vars(Environment *_environment, char *_tilemap, char *_column, char *_row, char *_layer)
struct _Variable Variable
Structure of a single variable.
#define CRITICAL_TILEMAP_INDEX_INVALID_TILEMAP(v)
Definition ugbc.h:3655
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_TILEMAP
Definition ugbc.h:525
@ VT_BYTE
Definition ugbc.h:450
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]