ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
jmove.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 /* <usermanual>
42 @keyword JMOVE
43
44 @english
45
46 The ''JMOVE'' command allows you to update two variables (abscissa and ordinate)
47 according to the detected position of the joystick. In addition to indicating the
48 variables that will be updated, it is possible to indicate the minimum and maximum
49 movement limits. If the variables are already beyond the limits, no updates will
50 be made. Note that, to support a range that starts from zero (0), you need to use
51 a signed data type to represent the coordinates.
52
53 @italian
54
55Il comando JMOVE permette di aggiornare due variabili (ascissa e ordinata) secondo
56la posizione rilevata del joystick. Oltre ad indicare le variabili che saranno
57oggetto di aggiornamento, è possibile indicare i limiti minimo e massimo di
58movimento. Se le variabili sono già oltre i limiti, non saranno effettuati
59aggiornamenti. Si noti che, per supportare un intervallo che parte da zero (0), è
60necessario utilizzare un tipo di dati con segno per rappresentare le coordinate.
61
62@syntax JMOVE [port,]x,y,minx,maxx,miny,maxy[,stepx,stepy]
63@syntax JMOVE [port,]x,y,min,max
64
65@example JMOVE 0, playerX, playerY, 0, 10, 0, 42
66
67@target all
68</usermanual> */
69
70void jmove( Environment * _environment, char * _port, char * _x, char * _y, char * _minx, char * _maxx, char * _miny, char *_maxy, char * _xstep, char * _ystep ) {
71
73
74 Variable * x = variable_retrieve( _environment, _x );
75 Variable * y = variable_retrieve( _environment, _y );
76
77 Variable * xstep = NULL;
78 if ( _xstep ) {
79 xstep = variable_retrieve( _environment, _xstep );
80 } else {
81 xstep = variable_temporary( _environment, VT_BYTE, "(xstep)" );
82 variable_store( _environment, xstep->name, 1 );
83 }
84
85 Variable * ystep = NULL;
86 if ( _ystep ) {
87 ystep = variable_retrieve( _environment, _ystep );
88 } else {
89 ystep = variable_temporary( _environment, VT_BYTE, "(ystep)" );
90 variable_store( _environment, ystep->name, 1 );
91 }
92
93 Variable * result = variable_temporary( _environment, VT_SBYTE, "(compare)" );
94
95 Variable * joymove = joydir_semivars( _environment, _port );
96
97 char detectedLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedLabel, "%sdetected", label );
98 char detectedDownLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedDownLabel, "%sdetecteddown", label );
99 char detectedLeftLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedLeftLabel, "%sdetectedleft", label );
100 char detectedRightLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedRightLabel, "%sdetectedright", label );
101
102 variable_compare_and_branch_const( _environment, joymove->name, 2, detectedDownLabel, 0 );
103 add_complex_vars( _environment, y->name, ystep->name, _miny, _maxy, 1 );
104 cpu_jump( _environment, detectedLabel );
105
106 cpu_label( _environment, detectedDownLabel );
107 variable_compare_and_branch_const( _environment, joymove->name, 1, detectedLeftLabel, 0 );
108 add_complex_vars( _environment, y->name, variable_complement_const( _environment, ystep->name, 0 )->name, _miny, _maxy, 1 );
109 cpu_jump( _environment, detectedLabel );
110
111 cpu_label( _environment, detectedLeftLabel );
112 variable_compare_and_branch_const( _environment, joymove->name, 8, detectedRightLabel, 0 );
113 add_complex_vars( _environment, x->name, xstep->name, _minx, _maxx, 1 );
114 cpu_jump( _environment, detectedLabel );
115
116 cpu_label( _environment, detectedRightLabel );
117 variable_compare_and_branch_const( _environment, joymove->name, 4, detectedLabel, 0 );
118 add_complex_vars( _environment, x->name, variable_complement_const( _environment, xstep->name, 0 )->name, _minx, _maxx, 1 );
119
120 cpu_label( _environment, detectedLabel );
121
122}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
Variable * variable_retrieve(Environment *_environment, char *_name)
void variable_compare_and_branch_const(Environment *_environment, char *_source, int _destination, char *_name, int _positive)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
Variable * variable_complement_const(Environment *_environment, char *_source, int _value)
Calculate the complement of a variable.
void add_complex_vars(Environment *_environment, char *_variable, char *_expression, char *_limit_lower, char *_limit_upper, int _clamp)
Emit code for ADD x,y,a TO b.
Definition add.c:136
void jmove(Environment *_environment, char *_port, char *_x, char *_y, char *_minx, char *_maxx, char *_miny, char *_maxy, char *_xstep, char *_ystep)
Definition jmove.c:70
Variable * joydir_semivars(Environment *_environment, char *_port)
Definition joydir.c:41
char * name
Definition ugbc.h:979
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450
@ VT_SBYTE
Definition ugbc.h:452
#define MAKE_LABEL
Definition ugbc.h:3351