ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
sprite_init.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
41#if defined(__c64__) || defined(__c64reu__) || defined(__c128__)
42
49/* <usermanual>
50@keyword SPRITE (function)
51
52@english
53
54This function can be used to define a hardware sprite. The first parameter must
55be a monochrome graphics resource, while the second parameter (optional) can be
56the identifier of an already defined sprite. If the second parameter is omitted,
57the sprite will be created using a new identifier.
58
59A sprite declaration can be followed by one or more optional flags that serve
60to better describe the desired characteristics of the sprite.
61
62With the ''MULTICOLOR'' flag you can indicate that the sprite is defined by more
63than one color. Depending on the video chipset considered, this can mean up to
644 colors instead of the single color. The opposite is given by the ''MONOCOLOR''
65flag, which defines a monochrome sprite.
66
67The ''EXPAND VERTICAL'' flag allows you to increase the height of the sprite
68and, depending on the video chipset considered, each pixel of the sprite will
69be drawn with more pixels on the screen. The opposite is obtained with the
70''COMPRESS VERTICAL'' flag.
71
72The ''EXPAND HORIZONTAL'' flag allows you to increase the width of the
73sprite and, depending on the video chipset considered, each pixel of the
74sprite will be drawn with more pixels on the screen. The opposite is
75obtained with the ''COMPRESS HORIZONTAL'' flag.
76
77The last flag is ''IGNORE COLOR'', which allows you to indicate the color to be
78considered as transparency (that is: ignored).
79
80Please note that defining a sprite allows you to change its appearance
81dynamically, and therefore allows you to perform (for example) animations.
82This redefinition should be understood as synchronous, and therefore the
83program should be written to ensure the appropriate timing, in order to
84avoid flickering.
85
86@italian
87
88Questa funzione può essere usata per definire uno sprite hardware. Il primo
89parametro deve essere una risorsa grafica monocromatica, mentre il secondo
90parametro (opzionale) può essere l'identificativo di uno sprite già definito.
91Se il secondo parametro viene omesso, lo sprite sarà creato utilizzando un nuovo
92identificativo.
93
94La dichiarazione di uno sprite può essere seguita da uno o più flag, opzionali,
95che servono a descrivere meglio le caratteristiche desiderate dello sprite.
96
97Con il flag ''MULTICOLOR'' si può indicare che lo sprite è definito da più di
98un colore. A seconda del chipset video considerato, questo può significare
99fino a 4 colori invece che il singolo colore. Il contrario è dato dal flag
100''MONOCOLOR'', che definisce uno sprite monocromatico.
101
102Il flag ''EXPAND VERTICAL'' permette di incrementare l'altezza dello sprite
103e, a seconda del chipset video considerato, ogni pixel dello sprite sarà
104disegnato con più pixel sullo schermo. Il contrario lo si ottiene con il
105flag ''COMPRESS VERTICAL''.
106
107Il flag ''EXPAND HORIZONTAL'' permette di incrementare la larghezza dello
108sprite e, a seconda del chipset video considerato, ogni pixel dello sprite
109sarà disegnato con più pixel sullo schermo. Il contrario lo si ottiene con
110il flag ''COMPRESS HORIZONTAL''.
111
112L'ultimo flag è ''IGNORE COLOR'', che consente di indicare il colore da
113considerare come trasparenza (cioè: ignorato).
114
115Si fa presente che la definizione di uno sprite consente di cambiare il suo
116aspetto dinamicamente, e quindi permette di effettuare (ad esempio) animazioni.
117Tale ridefinizione va intesa come sincrona, e quindi il programma dovrebbe
118essere scritto per garantire le opportune temporizzazioni, al fine di
119evitare flickering.
120
121@syntax = SPRITE( resource ) flags
122@syntax = SPRITE( resource, old ) flags
123
124@example ship = SPRITE( imageShip ) IGNORE BLACK
125
126@seeAlso SPRITE
127
128@target c64
129@target c64reu
130@target c128
131@target msx1
132@target coleco
133@target sc3000
134@target sg1000
135</usermanual> */
136Variable * sprite_init( Environment * _environment, char * _image, char * _sprite, int _flags ) {
137
138 if ( _environment->deployed.msprite ) {
140 }
141
142 Variable * index;
143
144 if ( _sprite ) {
145
146 index = variable_retrieve_or_define( _environment, _sprite, VT_SPRITE, 0 );
147
148 } else {
149
150 Variable * spriteCount = variable_retrieve( _environment, "SPRITECOUNT" );
151 index = variable_temporary( _environment, VT_SPRITE, "(sprite index)" );
152 variable_move_naked( _environment, spriteCount->name, index->name );
153 cpu_inc( _environment, spriteCount->realName );
154
155 }
156
157 Variable * image = variable_retrieve( _environment, _image );
158
159 Variable * realImage = sprite_converter( _environment, image->originalBitmap, image->originalWidth, image->originalHeight, image->originalDepth, NULL, _flags, 0, 0 );
160
161 if ( _flags & SPRITE_FLAG_MULTICOLOR) {
162 sprite_multicolor_var( _environment, index->name );
163 } else {
164 sprite_monocolor_var( _environment, index->name );
165 }
166
167 vic2_sprite_data_from( _environment, index->name, realImage->name );
168
169 if ( _flags & SPRITE_FLAG_EXPAND_VERTICAL) {
170 sprite_expand_horizontal_var( _environment, index->name );
171 } else {
172 sprite_compress_horizontal_var( _environment, index->name );
173 }
174
175 if ( _flags & SPRITE_FLAG_EXPAND_HORIZONTAL) {
176 sprite_expand_vertical_var( _environment, index->name );
177 } else {
178 sprite_compress_vertical_var( _environment, index->name );
179 }
180
181 return index;
182
183}
184
185#endif
void cpu_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_move_naked(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable without conversion.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
void sprite_compress_horizontal_var(Environment *_environment, char *_sprite)
Emit ASM code for SPRITE [int] COMPRESS HORIZONTAL.
void sprite_compress_vertical_var(Environment *_environment, char *_sprite)
Emit ASM code for SPRITE [expression] COMPRESS VERTICAL.
Variable * sprite_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, RGBi *_color, int _flags, int _slot_x, int _slot_y)
void sprite_expand_horizontal_var(Environment *_environment, char *_sprite)
Emit ASM code for SPRITE [expression] EXPAND HORIZONTAL.
void sprite_expand_vertical_var(Environment *_environment, char *_sprite)
Emit ASM code for SPRITE [expression] EXPAND VERTICAL.
Variable * sprite_init(Environment *_environment, char *_image, char *_sprite, int _flags)
Emit code for SPRITE(...).
Definition sprite_init.c:47
void sprite_monocolor_var(Environment *_environment, char *_sprite)
Emit ASM code for SPRITE [expression] MONOCOLOR.
void sprite_multicolor_var(Environment *_environment, char *_sprite)
Emit ASM code for SPRITE [expression] MULTICOLOR.
int msprite
Definition ugbc.h:1727
Deployed deployed
Definition ugbc.h:2921
char * originalBitmap
Definition ugbc.h:1142
int originalHeight
Definition ugbc.h:1148
int originalDepth
Definition ugbc.h:1151
char * name
Definition ugbc.h:979
int originalWidth
Definition ugbc.h:1145
char * realName
Definition ugbc.h:982
#define SPRITE_FLAG_EXPAND_VERTICAL
Definition ugbc.h:4561
struct _Variable Variable
Structure of a single variable.
#define SPRITE_FLAG_MULTICOLOR
Definition ugbc.h:4559
struct _Environment Environment
Structure of compilation environment.
@ VT_SPRITE
Definition ugbc.h:501
#define CRITICAL_CANNOT_MIX_SPRITES_MSPRITES()
Definition ugbc.h:3739
#define SPRITE_FLAG_EXPAND_HORIZONTAL
Definition ugbc.h:4563
void vic2_sprite_data_from(Environment *_environment, char *_sprite, char *_image)
Definition vic2.c:1511