ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
csprite_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(__msx1__) || defined(__coleco__) || defined(__sc3000__) || defined(__sg1000__)
42
49 /* <usermanual>
50@keyword CSPRITE
51@target msx1
52@target coleco
53@target sg1000
54@target sc3000
55</usermanual> */
56Variable * csprite_init( Environment * _environment, char * _image, char *_sprite, int _flags ) {
57
58 Variable * index;
59 Variable * startIndex = variable_temporary( _environment, VT_SPRITE, "(sprite index)" );
60 Variable * image = variable_retrieve( _environment, _image );
61 Variable * spriteCount;
62
63 if ( _sprite ) {
64
65 index = variable_retrieve_or_define( _environment, _sprite, VT_SPRITE, 0 );
66 cpu_move_8bit( _environment, index->realName, startIndex->realName );
67 cpu_math_and_const_8bit( _environment, startIndex->realName, 0x1f );
68 spriteCount = variable_temporary( _environment, VT_SPRITE, "(sprite index)" );
69 cpu_move_8bit( _environment, startIndex->realName, spriteCount->realName );
70
71 } else {
72
73 index = variable_temporary( _environment, VT_SPRITE, "(sprite index)" );
74 spriteCount = variable_retrieve( _environment, "SPRITECOUNT" );
75 variable_move_naked( _environment, spriteCount->name, startIndex->name );
76
77 }
78
79 int c = 0;
80
81 for (int i=0; i<image->originalColors; ++i ) {
82 if ( image->originalPalette[i].index == COLOR_TRANSPARENT ) continue;
83 ++c;
84 variable_move_naked( _environment, spriteCount->name, index->name );
85 Variable * realImage = sprite_converter( _environment, image->originalBitmap, image->originalWidth, image->originalHeight, image->originalDepth, &image->originalPalette[i], _flags, 0, 0 );
86 tms9918_sprite_data_from( _environment, index->name, realImage->name );
87 cpu_inc( _environment, spriteCount->realName );
88 }
89
90 cpu_store_8bit( _environment, index->realName, ( c ) << 4 );
91
92 cpu_math_add_8bit( _environment, index->realName, startIndex->realName, index->realName );
93
94 if ( _sprite ) {
95
96 } else {
97
98 variable_move_naked( _environment, spriteCount->name, "SPRITECOUNT" );
99
100 }
101
102 return index;
103
104}
105
106#endif
void cpu_math_add_8bit(Environment *_environment, char *_source, char *_destination, char *_other)
CPU 6309: emit code to add two 8 bit values
Definition 6309.c:1017
void cpu_inc(Environment *_environment, char *_variable)
Definition 6309.c:4555
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_math_and_const_8bit(Environment *_environment, char *_source, int _mask)
CPU 6309: emit code to mask with "and" a value of 8 bit
Definition 6309.c:1451
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(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.
Variable * csprite_init(Environment *_environment, char *_image, char *_sprite, int _flags)
Emit code for SPRITE(...).
Variable * sprite_converter(Environment *_environment, char *_data, int _width, int _height, int _depth, RGBi *_color, int _flags, int _slot_x, int _slot_y)
#define COLOR_TRANSPARENT
Definition cga.h:36
unsigned char index
Definition ugbc.h:437
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 originalColors
Definition ugbc.h:1154
int originalWidth
Definition ugbc.h:1145
RGBi originalPalette[MAX_PALETTE]
Definition ugbc.h:1169
char * realName
Definition ugbc.h:982
void tms9918_sprite_data_from(Environment *_environment, char *_sprite, char *_image)
Definition tms9918.c:1158
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_SPRITE
Definition ugbc.h:501