ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
mmob.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2024 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
47/* <usermanual>
48@keyword MMOB
49
50The instruction ''MMOB'' move a sprite on the screen. It is used to move the
51given ''sprite'' from a starting point with the coordinates ''sx,sy'' to a
52target point with the coordinates ''zx,zy''. The parameter ''gr'' sets the
53display size of the sprite (and thus changes the basic setting in ''MOB SET'').
54The movement speed is set with ''sp'', with larger values making the sprite
55move more slowly.
56
57The shortened form (without the target specification ''zx,zy'') simply
58positions the sprite in question at the selected coordinate ''sx,sy''.
59
60Like the Simons' Basic,
61sprites do not move independently of one another (in an interrupt),
62but only one after the other (one ''MMOB'' command controls one sprite,
63the next command the next sprite, etc.).
64
65The size and speed settings should be entered in ''MOB SET''. Almost all sprite
66related parameters are then collected there. The following values for are permitted:
67a ''0'' means 24×21 (normal), ''1'' means 48×21 (x-expanded), ''2'' means 24×42 (y-expanded),
68and finally ''3'' means 48×42 (double size).
69
70@english
71
72@italian
73
74@syntax
75
76@example
77
78</usermanual> */
79void mmob( Environment * _environment, char * _sprite, char * _sx, char * _sy, char * _zx, char * _zy, char * _gr, char * _sp ) {
80
82
83 Variable * sprite = variable_retrieve( _environment, _sprite );
84
85 if ( sprite->type != VT_SPRITE && sprite->type != VT_MSPRITE ) {
87 }
88
89 // The parameter ''gr'' sets the
90 // display size of the sprite (and thus changes the basic setting in ''MOB SET'').
91 // The following values ​​for are permitted:
92 // a ''0'' means 24×21 (normal), ''1'' means 48×21 (x-expanded), ''2'' means 24×42 (y-expanded),
93 // and finally ''3'' means 48×42 (double size).
94
95 if ( _gr ) {
96
97 char yExpandedLabel[MAX_TEMPORARY_STORAGE]; sprintf( yExpandedLabel, "%sexpy", label );
98 char nExpandedLabel[MAX_TEMPORARY_STORAGE]; sprintf( nExpandedLabel, "%sexpn", label );
99
100 Variable * gr = variable_retrieve( _environment, _gr);
101 Variable * tmp = variable_temporary( _environment, VT_BYTE, "(tmp)" );
102
103 cpu_and_8bit_const( _environment, gr->realName, 0x01, tmp->realName );
104 cpu_compare_and_branch_8bit_const( _environment, tmp->realName, 0, yExpandedLabel, 1 );
105 sprite_expand_horizontal_var( _environment, _sprite );
106
107 cpu_label( _environment, yExpandedLabel );
108 cpu_and_8bit_const( _environment, gr->realName, 0x02, tmp->realName );
109 cpu_compare_and_branch_8bit_const( _environment, tmp->realName, 0, nExpandedLabel, 1 );
110 sprite_expand_vertical_var( _environment, _sprite );
111 cpu_label( _environment, nExpandedLabel );
112
113 }
114
115 Variable * sx = variable_retrieve( _environment, _sx );
116 Variable * sy = variable_retrieve( _environment, _sy );
117
118 // The shortened form (without the target specification ''zx,zy'') simply
119 // positions the sprite in question at the selected coordinate ''sx,sy''.
120
121 sprite_at_vars( _environment, sprite->name, sx->name, sy->name );
122
123 if ( _zx && _zy ) {
124
125 // The instruction ''MMOB'' move a sprite on the screen. It is used to move the
126 // given ''sprite'' from a starting point with the coordinates ''sx,sy'' to a
127 // target point with the coordinates ''zx,zy''.
128 // Like the Simons' Basic,
129 // sprites do not move independently of one another (in an interrupt),
130 // but only one after the other (one ''MMOB'' command controls one sprite,
131 // the next command the next sprite, etc.).
132
133 Variable * zx = variable_retrieve( _environment, _zx );
134 Variable * zy = variable_retrieve( _environment, _zy );
135
136 Variable * x = variable_temporary( _environment, VT_POSITION, "(x)" );
137 Variable * y = variable_temporary( _environment, VT_POSITION, "(y)" );
138
139 Variable * path = variable_temporary( _environment, VT_PATH, "(path)" );
140
141 variable_move( _environment, create_path( _environment, sx->name, sy->name, zx->name, zy->name )->name, path->name );
142
143 char loopLabel[MAX_TEMPORARY_STORAGE]; sprintf( loopLabel, "%sloop", label );
144 char loopDoneLabel[MAX_TEMPORARY_STORAGE]; sprintf( loopDoneLabel, "%sdone", label );
145
146 cpu_label( _environment, loopLabel );
147
148 travel_path( _environment, path->name, x->name, y->name, NULL, NULL );
149
150 sprite_at_vars( _environment, sprite->name, x->name, y->name );
151
154 _environment,
155 variable_xor( _environment, x->name, zx->name )->name,
156 variable_xor( _environment, y->name, zy->name )->name
157 )->realName,
158 0, loopDoneLabel, 1 );
159
160 // The movement speed is set with ''sp'', with larger values making the sprite
161 // move more slowly.
162
163 if ( _sp ) {
164 Variable * sp = variable_retrieve( _environment, _sp );
165 wait_ticks_var( _environment, sp->name );
166 } else {
167 wait_ticks( _environment, 1 );
168 }
169
170 cpu_jump( _environment, loopLabel );
171
172 cpu_label( _environment, loopDoneLabel );
173
174 }
175
176}
177
void cpu_and_8bit_const(Environment *_environment, char *_left, int _right, char *_result)
Definition 6309.c:4230
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:1578
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
Variable * variable_xor(Environment *_environment, char *_left, char *_right)
Calculate logical "xor" and return it as the result.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_or(Environment *_environment, char *_left, char *_right)
Calculate logical "or" and return it as the result.
void wait_ticks_var(Environment *_environment, char *_timing)
Emit ASM code for WAIT [expression] TICKS.
Definition wait_ticks.c:65
void wait_ticks(Environment *_environment, int _timing)
Emit ASM code for WAIT # [integer] TICKS.
Definition wait_ticks.c:49
void sprite_at_vars(Environment *_environment, char *_sprite, char *_x, char *_y)
Emit ASM code for SPRITE [expression] AT ([expression],[expression]).
Definition sprite_at.c:71
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 * create_path(Environment *_environment, char *_x0, char *_y0, char *_x1, char *_y1)
Emit ASM code to implement CREATE PATH command.
Definition create_path.c:90
void mmob(Environment *_environment, char *_sprite, char *_sx, char *_sy, char *_zx, char *_zy, char *_gr, char *_sp)
Emit code for MOVE ....
Definition mmob.c:79
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
Variable * travel_path(Environment *_environment, char *_p, char *_x, char *_y, char *_times, char *_limited)
Emit ASM code to implement TRAVEL PATH command.
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
#define CRITICAL_MMOB_NEEDS_SPRITE(v)
Definition ugbc.h:3807
@ VT_POSITION
Definition ugbc.h:468
@ VT_MSPRITE
Definition ugbc.h:531
@ VT_BYTE
Definition ugbc.h:450
@ VT_SPRITE
Definition ugbc.h:501
@ VT_PATH
Definition ugbc.h:540
#define MAKE_LABEL
Definition ugbc.h:3351