ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
dojo_get_message.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 extern char DATATYPE_AS_STRING[][16];
38
39/* <usermanual>
40@keyword GET MESSAGE
41
42@english
43
44The ''GET MESSAGE'' statement allows you to retrieve the message present on the
45specified port (''port''), and possibly on the specific channel (''channel'').
46If used as a function, the message is returned as a string; otherwise,
47the type of the given variable is used to parse the incoming type. If there are
48no messages at the time of the call, or if the port is unknown, an empty string
49will be returned or the given variable is untouched. The actual
50error must be retrieved with the ''DOJO ERROR'' command. If you want to avoid
51fetching a message from an empty message queue, you can use the ''PEEK MESSAGE'' statement.
52Note that ''MESSAGE'' keyword is optional.
53
54@italian
55
56L'istruzione ''GET MESSAGE'' permette di recuperare il messaggio presente sulla
57porta indicata (''port''), ed eventualmente sul canale specifico (''channel'').
58Il messaggio viene restituito come una stringa se si utilizza la notazione
59in forma di funzione, mentre viene decodificato secondo il tipo utilizzato come
60parametro, nell'altro caso. Se non vi sono messaggi al momento
61della chiamata, oppure se la porta è sconosciuta, sarà restituita una stringa vuota.
62L'errore effetivo va recuperato con il comando ''DOJO ERROR''. Se si vuole evitare
63di prelevare un messaggio da una coda messaggi vuota, è possibile usare l'istruzione
64''PEEK MESSAGE''. Da notare che la parola chiave ''MESSAGE'' è opzionale.
65
66@syntax = [DOJO] GET [MESSAGE]( port[, channel] )
67@syntax [DOJO] GET [MESSAGE] port[, channel], variable
68
69@example message = GET MESSAGE( myPort, myChannel )
70@example DIM a(42): GET MESSAGE myPort, 42, a
71
72@alias DOJO GET MESSAGE
73
74@seeAlso PEEK MESSAGE
75@seeAlso DOJO ERROR
76
77@target atari, coco
78</usermanual> */
79
80/* <usermanual>
81@keyword DOJO GET MESSAGE
82
83@english
84
85@italian
86
87@alias GET MESSAGE
88
89@target atari, coco
90</usermanual> */
91
92 Variable * dojo_get_message( Environment * _environment, char * _port, char * _channel ) {
93
95
96 Variable * port = variable_retrieve_or_define( _environment, _port, VT_BYTE, 0 );
97 Variable * channel = NULL;
98 if ( _channel ) {
99 channel = variable_retrieve_or_define( _environment, _channel, VT_BYTE, 0 );
100 }
101 Variable * result = variable_temporary( _environment, VT_DSTRING, "(result)");
102 Variable * size = variable_temporary( _environment, VT_BYTE, "(size)");
103 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(size)");
104 Variable * esito = variable_temporary( _environment, VT_BYTE, "(result)");
105
106 if ( port->type != VT_DOJOKA ) {
108 }
109
110 dojo_begin( _environment );
111 dojo_put_requestds( _environment, DOJO_CMD_SELECT_PORT, NULL, NULL, port->realName, 4, esito->realName );
112 cpu_compare_and_branch_8bit_const( _environment, esito->realName, 0, label, 0 );
113 dojo_put_request0( _environment, DOJO_CMD_GET_MESSAGE, channel ? channel->realName : NULL, NULL, esito->realName );
114 cpu_compare_and_branch_8bit_const( _environment, esito->realName, 0, label, 0 );
115 dojo_partial( _environment );
116 dojo_get_response_size( _environment, esito->realName, size->realName );
117 cpu_dsalloc( _environment, size->realName, result->realName );
118 cpu_dsdescriptor( _environment, result->realName, address->realName, NULL );
119 dojo_get_response_payload( _environment, address->realName );
120 dojo_end( _environment );
121
122 cpu_label( _environment, label );
123
124 cpu_move_8bit( _environment, esito->realName, "DOJOERROR" );
125
126 return result;
127
128}
129
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_dsalloc(Environment *_environment, char *_size, char *_index)
Definition 6309.c:5895
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
void cpu_dsdescriptor(Environment *_environment, char *_index, char *_address, char *_size)
Definition 6309.c:5977
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)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
int size
Definition _optimizer.c:678
void dojo_put_request0(Environment *_environment, int _command, char *_param1, char *_param2, char *_result)
Definition dojo.c:63
void dojo_partial(Environment *_environment)
Definition dojo.c:103
void dojo_end(Environment *_environment)
Definition dojo.c:173
void dojo_put_requestds(Environment *_environment, int _command, char *_param1, char *_param2, char *_data, int _size, char *_result)
Definition dojo.c:93
void dojo_begin(Environment *_environment)
Definition dojo.c:53
void dojo_get_response_size(Environment *_environment, char *_status, char *_size)
Definition dojo.c:143
void dojo_get_response_payload(Environment *_environment, char *_address)
Definition dojo.c:153
Variable * dojo_get_message(Environment *_environment, char *_port, char *_channel)
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
#define DOJO_CMD_GET_MESSAGE
Definition ugbc.h:4736
struct _Environment Environment
Structure of compilation environment.
@ VT_DOJOKA
Definition ugbc.h:534
@ VT_BYTE
Definition ugbc.h:450
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_DSTRING
Definition ugbc.h:483
#define DOJO_PEEK_MESSAGE_DOJOKA_REQUIRED(v, t)
Definition ugbc.h:3818
#define DOJO_CMD_SELECT_PORT
Definition ugbc.h:4733
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]