ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
dojo_peek_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 PEEK MESSAGE
41
42@english
43
44The ''PEEK MESSAGE'' statement lets you know whether or not a message is present
45on a given ''port'' (and ''channel''). If it is present, it returns ''TRUE'', otherwise
46it returns ''FALSE''. If it is, you can retrieve the message using the ''GET MESSAGE'' command.
47Note that the keyword ''MESSAGE'' can be omitted.
48
49@italian
50
51L'istruzione ''PEEK MESSAGE'' permette di sapere se è presente o meno un messaggio su una
52data porta (''port'') (e canale, ''channell''). Se è presente, restituisce ''TRUE'' altrimenti
53restituirà ''FALSE''. In caso positivo, sarà possibile recuperare il messaggio utilizzando
54il comando ''GET MESSAGE''. Da notare che la parola chiave ''MESSAGE'' può essere omessa.
55
56@syntax [DOJO] PEEK [MESSAGE]( port[, channel] )
57
58@example IF PEEK MESSAGE( myPort ) THEN: PRINT "there are messages!": ENDIF
59
60@alias DOJO PEEK MESSAGE
61
62@seeAlso GET MESSAGE
63
64@target atari, coco
65</usermanual> */
66
67/* <usermanual>
68@keyword DOJO PEEK MESSAGE
69
70@english
71
72@italian
73
74@alias PEEK MESSAGE
75
76@target atari, coco
77</usermanual> */
78
79
80 Variable * dojo_peek_message( Environment * _environment, char * _port, char * _channel ) {
81
83
84 Variable * port = variable_retrieve_or_define( _environment, _port, VT_BYTE, 0 );
85 Variable * channel = NULL;
86 if ( _channel ) {
87 channel = variable_retrieve_or_define( _environment, _channel, VT_BYTE, 0 );
88 }
89 Variable * peek = variable_temporary( _environment, VT_SBYTE, "(size)");
90 Variable * result = variable_temporary( _environment, VT_SBYTE, "(result)");
91 Variable * esito = variable_temporary( _environment, VT_BYTE, "(result)");
92
93 if ( port->type != VT_DOJOKA ) {
95 }
96
97 cpu_store_8bit( _environment, peek->realName, 0 );
98
99 dojo_begin( _environment );
100 dojo_put_requestds( _environment, DOJO_CMD_SELECT_PORT, NULL, NULL, port->realName, 4, esito->realName );
101 cpu_compare_and_branch_8bit_const( _environment, esito->realName, 0, label, 0 );
102 dojo_put_request0( _environment, DOJO_CMD_PEEK_MESSAGE, channel ? channel->realName : NULL, NULL, esito->realName );
103 cpu_compare_and_branch_8bit_const( _environment, esito->realName, 0, label, 0 );
104 dojo_partial( _environment );
105 dojo_get_responsed( _environment, result->realName, peek->realName, NULL );
106 cpu_label( _environment, label );
107 dojo_end( _environment );
108
109 cpu_move_8bit( _environment, esito->realName, "DOJOERROR" );
110
111 return peek;
112
113}
114
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
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.
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_get_responsed(Environment *_environment, char *_status, char *_data, char *_size)
Definition dojo.c:133
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
Variable * dojo_peek_message(Environment *_environment, char *_port, char *_channel)
char * realName
Definition ugbc.h:982
#define DOJO_CMD_PEEK_MESSAGE
Definition ugbc.h:4735
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_DOJOKA
Definition ugbc.h:534
@ VT_BYTE
Definition ugbc.h:450
@ VT_SBYTE
Definition ugbc.h:452
#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]