ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
rotate_vector.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 ROTATE VECTOR
50
51@english
52
53This command allows you to rotate a two-dimensional ''VECTOR'' by a given angle.
54
55@italian
56
57Questo comando consente di ruotare un vettore bidimensionale (''VECTOR'') di un certo angolo dato.
58
59@syntax = ROTATE VECTOR( vector, angle )
60
61@example DIM p AS VECTOR
62@example v = CREATE VECTOR( 10, 10 )
63@example v = ROTATE VECTOR( v, 1.57 )
64
65</usermanual> */
66
67Variable * rotate_vector( Environment * _environment, char * _v, char * _a ) {
68
70
71 Variable * vector = variable_define( _environment, "rotatevector__vector", VT_VECTOR2, 0 );
72 Variable * angle = variable_define( _environment, "rotatevector__angle", VT_FLOAT, 0 );
73
74 Variable * x = vector_get_x( _environment, vector->name );
75 Variable * y = vector_get_y( _environment, vector->name );
76
77 Variable * ca = fp_cos( _environment, angle->name );
78 Variable * sa = fp_sin( _environment, angle->name );
79
80 Variable * xpca = variable_mul( _environment, x->name, ca->name );
81 Variable * ypsa = variable_mul( _environment, y->name, sa->name );
82 Variable * xpsa = variable_mul( _environment, x->name, sa->name );
83 Variable * ypca = variable_mul( _environment, y->name, ca->name );
84
85 cpu_move_16bit( _environment, variable_cast( _environment, variable_sub( _environment, xpca->name, ypsa->name)->name, VT_POSITION )->realName, vector->realName );
86 cpu_move_16bit( _environment, variable_cast( _environment, variable_add( _environment, xpsa->name, ypca->name)->name, VT_POSITION )->realName, address_displacement( _environment, vector->realName, "2" ) );
87
88 cpu_return( _environment );
89
91
92 Variable * vp = variable_retrieve( _environment, "rotatevector__vector" );
93 Variable * ap = variable_retrieve( _environment, "rotatevector__angle" );
94
95 Variable * v = variable_retrieve( _environment, _v );
96 Variable * a = variable_retrieve_or_define( _environment, _a, VT_FLOAT, 0 );
97
98 variable_move( _environment, v->name, vp->name );
99 variable_move( _environment, a->name, ap->name );
100
101 cpu_call( _environment, "lib_rotate_vector" );
102
103 return vp;
104
105}
106
void cpu_move_16bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 16 bit
Definition 6309.c:1474
void cpu_call(Environment *_environment, char *_label)
Definition 6309.c:3755
void cpu_return(Environment *_environment)
Definition 6309.c:4030
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_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
Variable * variable_define(Environment *_environment, char *_name, VariableType _type, int _value)
Define a variable for the program.
Variable * variable_mul(Environment *_environment, char *_source, char *_destination)
Make a multiplication between two variable and return the product of them.
Variable * variable_sub(Environment *_environment, char *_source, char *_dest)
Make a differenze between two variable and return the difference of them.
Variable * variable_cast(Environment *_environment, char *_source, VariableType _type)
Cast a variable from a type to another.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Variable * fp_cos(Environment *_environment, char *_angle)
Definition fp_cos.c:82
Variable * fp_sin(Environment *_environment, char *_angle)
Definition fp_sin.c:82
Variable * rotate_vector(Environment *_environment, char *_v, char *_a)
Emit ASM code to implement CREATE PATH command.
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
#define deploy_end(s)
Definition ugbc.h:4365
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_FLOAT
Definition ugbc.h:522
@ VT_POSITION
Definition ugbc.h:468
@ VT_VECTOR2
Definition ugbc.h:543
#define deploy_begin(s)
Definition ugbc.h:4356
Variable * vector_get_x(Environment *_environment, char *_vector)
Variable * vector_get_y(Environment *_environment, char *_vector)