ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
tile_belong.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"
37
38/****************************************************************************
39 * CODE SECTION
40 ****************************************************************************/
41
49/* <usermanual>
50@keyword TILE BELONG TO
51
52@english
53The ''TILE ... BELONG TO ... '' command allows you to check if a certain ''TILE'' belongs
54to the set of tiles that make up a TILES. In general, ''TILES'' are made up of multiple
55simple tiles and, when drawn, actually occupy multiple tiles. This command allows you to
56make distinctions.
57
58@italian
59Il comando ''TILE ... BELONG TO ...'' permette di verificare se un determinato ''TILE''
60appartiene all'insieme dei tiles che compongono un ''TILES''. In generale, i ''TILES''
61sono formati da più tile semplici e, quando vengono disegnati, occupano effettivamente
62più tile. Questo comando consente di effettuare distinzioni.
63
64@syntax = TILE tile BELONG TO tiles
65
66@example = TILE tile BELONG TO multitiles
67
68@target all
69</usermanual> */
70Variable * tile_belong( Environment * _environment, char * _tile, char * _tiles ) {
71
73
74 outhead1("%sbelong:", label );
75
76 Variable * tile = variable_retrieve_or_define( _environment, _tile, VT_TILE, 0 );
77 Variable * tiles = variable_retrieve_or_define( _environment, _tiles, VT_TILES, 0 );
78
79 Variable * curTile = variable_temporary( _environment, VT_BYTE, "(tile)" );
80 cpu_move_8bit( _environment, tile->realName, curTile->realName );
81
82 Variable * minTile = variable_cast( _environment, tile_get_first( _environment, _tiles )->name, VT_WORD );
83 Variable * tileWidth = tile_get_width( _environment, _tiles );
84 Variable * tileHeight = tile_get_height( _environment, _tiles );
85 Variable * maxTile = variable_mul( _environment, tileWidth->name, tileHeight->name );
86
87 variable_add_inplace_vars( _environment, maxTile->name, minTile->name );
88
89 return variable_and( _environment,
90 variable_greater_than( _environment, curTile->name, minTile->name, 1 )->name,
91 variable_less_than( _environment, curTile->name, maxTile->name, 1 )->name
92 );
93
94}
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_less_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
Variable * variable_and(Environment *_environment, char *_left, char *_right)
Calculate logical "and" and return it as the result.
Variable * variable_greater_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
Variable * variable_mul(Environment *_environment, char *_source, char *_destination)
Make a multiplication between two variable and return the product of them.
void variable_add_inplace_vars(Environment *_environment, char *_source, char *_destination)
Add two variable and return the sum of them on the first.
Variable * variable_cast(Environment *_environment, char *_source, VariableType _type)
Cast a variable from a type to another.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * name
Definition _optimizer.c:672
Variable * tile_get_first(Environment *_environment, char *_tile)
Emit code for TILE FIRST(...).
Variable * tile_get_height(Environment *_environment, char *_tile)
Emit code for TILE HEIGHT(...).
Variable * tile_get_width(Environment *_environment, char *_tile)
Emit code for TILE WIDTH(...).
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
Variable * tile_belong(Environment *_environment, char *_tile, char *_tiles)
Emit code for TILE ... BELONG TO ....
Definition tile_belong.c:70
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_TILE
Definition ugbc.h:504
@ VT_WORD
Definition ugbc.h:455
@ VT_TILES
Definition ugbc.h:507
@ VT_BYTE
Definition ugbc.h:450
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247