ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
wait_milliseconds.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
49void wait_milliseconds( Environment * _environment, int _timing ) {
50
51 int timing = _timing / 20;
52
53 if ( _environment->protothread && !_environment->protothreadForbid && _environment->procedureName ) {
54
56
57 char waitVariableName[MAX_TEMPORARY_STORAGE]; sprintf(waitVariableName, "%swaitms%s", _environment->procedureName, label );
58 char doneLabel[MAX_TEMPORARY_STORAGE]; sprintf(doneLabel, "%sdone%sstep", _environment->procedureName, label );
59
61 memset( ((struct _Environment *)_environment)->arrayDimensionsEach, 0, sizeof( int ) * MAX_ARRAY_DIMENSIONS );
62 ((struct _Environment *)_environment)->arrayDimensionsEach[0] = _environment->protothreadConfig.count;
63 ((struct _Environment *)_environment)->arrayDimensions = 1;
64 variable_define( _environment, waitVariableName, VT_TARRAY, 0 );
65 variable_array_type( _environment, waitVariableName, VT_WORD );
67
68 variable_move_to_mt( _environment, variable_add_const( _environment, get_timer( _environment )->name, timing )->name, waitVariableName );
69
70 begin_loop( _environment, 1 );
71 Variable * result = variable_temporary( _environment, VT_WORD, "(temporary)" );
72 variable_move_from_mt( _environment, waitVariableName, result->name );
74 variable_greater_than( _environment,
75 get_timer( _environment )->name,
76 result->name,
77 1
78 )->name, 0xff, doneLabel, 1 );
79 end_loop( _environment, 1 );
80
81 cpu_label( _environment, doneLabel );
82
83 } else {
84
85 wait_ticks( _environment, timing );
86
87 }
88
89}
90
99void wait_milliseconds_var( Environment * _environment, char * _timing ) {
100
101 Variable * realTiming = variable_div_const( _environment, variable_retrieve_or_define( _environment, _timing, VT_WORD, 0 )->name, 20, NULL );
102
103 if ( _environment->protothread && !_environment->protothreadForbid && _environment->procedureName ) {
104
106
107 char waitVariableName[MAX_TEMPORARY_STORAGE]; sprintf(waitVariableName, "%swaitms%s", _environment->procedureName, label );
108 char doneLabel[MAX_TEMPORARY_STORAGE]; sprintf(doneLabel, "%sdone%sstep", _environment->procedureName, label );
109
111 memset( ((struct _Environment *)_environment)->arrayDimensionsEach, 0, sizeof( int ) * MAX_ARRAY_DIMENSIONS );
112 ((struct _Environment *)_environment)->arrayDimensionsEach[0] = _environment->protothreadConfig.count;
113 ((struct _Environment *)_environment)->arrayDimensions = 1;
114 variable_define( _environment, waitVariableName, VT_TARRAY, 0 );
115 variable_array_type( _environment, waitVariableName, VT_WORD );
117
118 variable_move_to_mt( _environment, variable_add( _environment, get_timer( _environment )->name, realTiming->name )->name, waitVariableName );
119
120 begin_loop( _environment, 1 );
121 Variable * result = variable_temporary( _environment, VT_WORD, "(temporary)" );
122 variable_move_from_mt( _environment, waitVariableName, result->name );
124 variable_greater_than( _environment,
125 get_timer( _environment )->name,
126 result->name,
127 1
128 )->name, 0xff, doneLabel, 1 );
129 end_loop( _environment, 1 );
130
131 cpu_label( _environment, doneLabel );
132
133 } else {
134
135 wait_ticks_var( _environment, realTiming->name );
136
137 }
138
139}
140
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
Variable * variable_add(Environment *_environment, char *_source, char *_destination)
Add two variable and return the sum of them.
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_greater_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
void variable_compare_and_branch_const(Environment *_environment, char *_source, int _destination, char *_name, int _positive)
Variable * variable_array_type(Environment *_environment, char *_name, VariableType _type)
Variable * variable_add_const(Environment *_environment, char *_source, int _destination)
Add a variable with a constant, and return the sum of them.
Variable * variable_move_from_mt(Environment *_environment, char *_source, char *_destination)
Increment a variable by one.
Variable * variable_div_const(Environment *_environment, char *_source, int _destination, char *_remainder)
Variable * variable_define(Environment *_environment, char *_name, VariableType _type, int _value)
Define a variable for the program.
Variable * variable_move_to_mt(Environment *_environment, char *_source, char *_destination)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * name
Definition _optimizer.c:672
Variable * get_timer(Environment *_environment)
Definition timer.c:47
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 begin_loop(Environment *_environment, int _do)
Emit ASM code for DO ....
Definition begin_loop.c:49
void end_loop(Environment *_environment, int _do)
Emit ASM code for ... LOOP.
Definition end_loop.c:49
Structure of compilation environment.
Definition ugbc.h:2269
int protothread
Definition ugbc.h:2830
int arrayDimensions
Definition ugbc.h:2718
int arrayDimensionsEach[MAX_ARRAY_DIMENSIONS]
Definition ugbc.h:2723
ProtothreadConfig protothreadConfig
Definition ugbc.h:2430
char * procedureName
Definition ugbc.h:2775
int protothreadForbid
Definition ugbc.h:2845
char * name
Definition ugbc.h:979
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define MAX_ARRAY_DIMENSIONS
Definition ugbc.h:566
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_TARRAY
Definition ugbc.h:480
@ VT_WORD
Definition ugbc.h:455
#define MAKE_LABEL
Definition ugbc.h:3351
void wait_milliseconds(Environment *_environment, int _timing)
Emit ASM code for WAIT # [integer] MS.
void wait_milliseconds_var(Environment *_environment, char *_timing)
Emit ASM code for WAIT [expression] MILLISECONDS.