ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
running.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
46/* <usermanual>
47@keyword RUNNING
48
49@english
50This command lets you know if a thread is in a "running" state or not. A
51thread is in this state if it has started and has not yet finished its execution.
52Moreover, it is possible to know if a specific procedure is running on a given
53thread, by using the second syntax.
54
55@italian
56Questo comando permette di sapere se un thread si trova in uno stato di "running" o meno.
57Un thread è in tale stato se è iniziato e ancora non ha terminato la propria esecuzione.
58Inoltre, è possibile sapere se una procedura specifica è in esecuzione su un dato thread,
59utilizzando la seconda sintassi.
60
61@syntax = RUNNING(thread[,procedur])
62
63@example IF NOT RUNNING(wheel) THEN
64@example wheel = SPAWN wheelManager
65@example ENDIF
66</usermanual> */
67Variable * running( Environment * _environment, char * _thread_id, char * _procedure ) {
68
69 _environment->anyProtothread = 1;
70
71 if ( _environment->protothreadForbid ) {
73 }
74
76
77 char protothreadLabel[MAX_TEMPORARY_STORAGE]; sprintf( protothreadLabel, "%srunning", label );
78
79 Variable * threadId = variable_retrieve_or_define( _environment, _thread_id, VT_THREAD, 0 );
80 Variable * state = variable_temporary( _environment, VT_THREAD, "(state)" );
81 Variable * result = variable_temporary( _environment, VT_SBYTE, "(is running)" );
82
83 variable_store( _environment, result->name, 0 );
84
85 if ( _procedure ) {
86 Variable * addressRegistered = variable_temporary( _environment, VT_ADDRESS, "(address)");
87 cpu_protothread_get_address( _environment, threadId->realName, addressRegistered->realName );
88 char procedureName[MAX_TEMPORARY_STORAGE]; sprintf( procedureName, "PROC%s", _procedure );
89 Variable * addressProcedure = variable_temporary( _environment, VT_ADDRESS, "(address)");
90 cpu_addressof_16bit( _environment, procedureName, addressProcedure->realName );
91 cpu_compare_and_branch_8bit_const( _environment, variable_compare( _environment, addressRegistered->name, addressProcedure->name )->realName, 0x00, label, 1 );
92 }
93
94 cpu_protothread_get_state( _environment, threadId->realName, state->realName );
95 variable_compare_and_branch_const( _environment, state->name, PROTOTHREAD_STATUS_RUNNING, protothreadLabel, 1 );
96 variable_compare_and_branch_const( _environment, state->name, PROTOTHREAD_STATUS_YIELDED, protothreadLabel, 1 );
97 variable_store( _environment, result->name, 0x00 );
98 cpu_jump( _environment, label );
99 cpu_label( _environment, protothreadLabel );
100 variable_store( _environment, result->name, 0xff );
101 cpu_label( _environment, label );
102
103 return result;
104
105}
106
void cpu_protothread_get_state(Environment *_environment, char *_index, char *_state)
Definition 6309.c:6237
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
void cpu_protothread_get_address(Environment *_environment, char *_index, char *_address)
Definition 6309.c:6258
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_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
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_compare(Environment *_environment, char *_source, char *_destination)
Compare two variable and return the result of comparation.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
Variable * running(Environment *_environment, char *_thread_id, char *_procedure)
Emit code for RUN PARALLEL.
Definition running.c:67
int anyProtothread
Definition ugbc.h:2835
int protothreadForbid
Definition ugbc.h:2845
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_THREAD
Definition ugbc.h:492
@ VT_SBYTE
Definition ugbc.h:452
@ VT_ADDRESS
Definition ugbc.h:465
#define PROTOTHREAD_STATUS_YIELDED
Definition ugbc.h:4548
#define CRITICAL_MULTITASKING_FORBIDDEN()
Definition ugbc.h:3703
#define PROTOTHREAD_STATUS_RUNNING
Definition ugbc.h:4547
#define MAKE_LABEL
Definition ugbc.h:3351