ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
frames.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
48/* <usermanual>
49@keyword FRAMES
50
51@english
52This function allows you to obtain the number of frames that make up a set of images (''ATLAS'').
53If applied to a single image resource (''IMAGE''), however, it always returns 1.
54The value is obtained by retrieving it from the resource itself, and therefore is
55constant for the entire duration of the execution.
56
57There is also a compile-level function for this keyword, which is called when the value
58is used to initialize a constant. In this case, the value is that taken from inspecting
59the instructions at the time of compilation.
60
61@italian
62Questa funzione permette di ottenere il numero di fotogrammi di cui è composta una risorsa che
63contiene un'insieme di immagini (''ATLAS''). Se applicato a una risorsa di tipo singola
64immagine (''IMAGE''), invece, ritorna sempre 1. Il valore è ottenuto recuperandolo dalla risorsa stessa,
65e quindi è costante per l'intera durata dell'esecuzione.
66
67Di questa parola chiave esiste anche una funzione a livello di compilazione,
68che viene richiamata quando il valore viene utilizzato per inizializzare una
69costante. In tal caso, il valore è quello desunto dall'ispezione delle
70istruzioni al momento della compilazione.
71
72@syntax = FRAMES(images)
73
74@example animazione := LOAD ATLAS("images.png") FRAME SIZE (16, 16)
75@example FOR i = 0 TO FRAMES(animazione)
76@example PRINT "frame ";i
77@example NEXT
78
79@usedInExample images_load_06.bas
80@usedInExample multitasking_example_06.bas
81
82@alias FRAME
83@alias IMAGES COUNT
84@alias IMAGE COUNT
85@alias FRAMES COUNT
86@alias FRAME COUNT
87
88</usermanual> */
89
90/* <usermanual>
91@keyword FRAME
92
93@english
94
95@italian
96
97@syntax = FRAME(images)
98
99@example animazione := LOAD ATLAS("images.png") FRAME SIZE (16, 16)
100@example FOR i = 0 TO FRAME(animazione)
101@example PRINT "frame ";i
102@example NEXT
103
104@alias FRAMES
105@alias IMAGES COUNT
106@alias IMAGE COUNT
107
108</usermanual> */
109
110/* <usermanual>
111@keyword IMAGES COUNT
112
113@english
114
115@italian
116
117@syntax = IMAGES COUNT(images)
118
119@example animazione := LOAD IMAGES("images.png") FRAME SIZE (16, 16)
120@example FOR i = 0 TO IMAGES COUNT(animazione)
121@example PRINT "frame ";i
122@example NEXT
123
124@usedInExample images_load_06.bas
125@usedInExample multitasking_example_06.bas
126
127@alias FRAMES
128@alias IMAGES COUNT
129@alias IMAGE COUNT
130@alias FRAMES COUNT
131@alias FRAME COUNT
132
133@target all
134</usermanual> */
135
136/* <usermanual>
137@keyword FRAMES COUNT
138
139@english
140
141@italian
142
143@syntax = FRAMES COUNT(images)
144
145@example animazione := LOAD IMAGES("images.png") FRAME SIZE (16, 16)
146@example FOR i = 0 TO FRAMES COUNT(animazione)
147@example PRINT "frame ";i
148@example NEXT
149
150@usedInExample images_load_06.bas
151@usedInExample multitasking_example_06.bas
152
153@alias FRAME
154@alias IMAGES COUNT
155@alias FRAMES
156
157</usermanual> */
158
159
160int frames( Environment * _environment, char * _image ) {
161
162 if ( _environment->emptyProcedure ) {
163 return 0xffff;
164 }
165
166 Variable * v = variable_retrieve( _environment, _image );
167 switch( v->type ) {
168 case VT_SEQUENCE:
169 if ( !v->valueBuffer ) {
171 }
172 return v->frameCount;
173 break;
174 case VT_IMAGES:
175 if ( !v->valueBuffer ) {
177 }
178 return v->frameCount;
179 break;
180 case VT_IMAGE:
181 if ( !v->valueBuffer ) {
183 }
184 return 1;
185 break;
186 default:
188 }
189
190}
Variable * variable_retrieve(Environment *_environment, char *_name)
int frames(Environment *_environment, char *_image)
Emit code for FRAMES(...).
Definition frames.c:160
int emptyProcedure
Definition ugbc.h:2932
unsigned char * valueBuffer
Definition ugbc.h:1061
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
int frameCount
Definition ugbc.h:1137
#define CRITICAL_NOT_ASSIGNED_IMAGES(v)
Definition ugbc.h:3534
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_IMAGES
Definition ugbc.h:495
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define CRITICAL_NOT_IMAGES(v)
Definition ugbc.h:3533
#define CRITICAL_NOT_ASSIGNED_SEQUENCE(v)
Definition ugbc.h:3569
#define CRITICAL_NOT_ASSIGNED_IMAGE(v)
Definition ugbc.h:3513