ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
dojo_put_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 PUT MESSAGE
41
42@english
43
44The ''PUT MESSAGE'' statement allows you to send a message to the ''port'' (and optionally
45the given ''channel''). The message must be a string or an array (up to 256 bytes). If there is an error sending, an
46error is raised and the statement returns ''FALSE''. Otherwise, it returns ''TRUE''.
47
48@italian
49
50L'istruzione ''PUT MESSAGE'' consente di inviare un messaggio sulla porta (''port'')
51ed, eventualmente, sul canale (''channel'') dato. Il messaggio deve essere una stringa
52oppure un array (fino a un massimo di 256 bytes). In caso di errore nell'invio, viene
53emesso un errore e l'istruzione restituità ''FALSE''. Altrimenti, restituirà ''TRUE'.
54
55@syntax = [DOJO] PUT [MESSAGE]( port[, channel], message )
56@syntax [DOJO] PUT [MESSAGE] port[, channel], message )
57
58@example PUT MESSAGE port, "hello!"
59@example DIM a(20) AS BYTE: a(1)=42: PUT port, 42, a
60
61@alias DOJO PUT MESSAGE
62
63@seeAlso DOJO ERROR
64
65@target atari, coco
66</usermanual> */
67
68/* <usermanual>
69@keyword DOJO PUT MESSAGE
70
71@english
72
73@italian
74
75@alias PUT MESSAGE
76
77@target atari, coco
78</usermanual> */
79
80 Variable * dojo_put_message( Environment * _environment, char * _port, char * _channel, char * _message ) {
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 * message = variable_retrieve( _environment, _message );
90 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(address)");
91 Variable * size = variable_temporary( _environment, VT_BYTE, "(size)");
92 Variable * result = variable_temporary( _environment, VT_SBYTE, "(result)");
93
94 if ( port->type != VT_DOJOKA ) {
96 }
97
98 switch( message->type ) {
99 case VT_STRING: {
100 cpu_move_8bit( _environment, message->realName, size->realName );
101 cpu_addressof_16bit( _environment, message->realName, address->realName );
102 cpu_inc_16bit( _environment, address->realName );
103 break;
104 }
105 case VT_DSTRING: {
106 cpu_dsdescriptor( _environment, message->realName, address->realName, size->realName );
107 break;
108 }
109 case VT_TARRAY: {
110 if ( VT_BITWIDTH( message->arrayType ) != 8 ) {
112 }
113 if ( VT_BITWIDTH( message->size ) >= 255 ) {
115 }
116 cpu_addressof_16bit( _environment, message->realName, address->realName );
117 cpu_store_8bit( _environment, size->realName, message->size );
118 break;
119 }
120 default:
121 if ( message->size < 256 && message->size > 0 ) {
122 cpu_addressof_16bit( _environment, message->realName, address->realName );
123 cpu_store_8bit( _environment, size->realName, message->size );
124 } else {
126 }
127 break;
128 }
129
130 dojo_begin( _environment );
131 dojo_put_requestds( _environment, DOJO_CMD_SELECT_PORT, NULL, NULL, port->realName, 4, result->realName );
132 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0, label, 0 );
133 dojo_put_request( _environment, DOJO_CMD_PUT_MESSAGE, channel ? channel->realName : NULL, NULL, address->realName, size->realName, result->realName );
134 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0, label, 0 );
135 dojo_partial( _environment );
136 dojo_get_response0( _environment, result->realName );
137
138 cpu_label( _environment, label );
139 dojo_end( _environment );
140
141 cpu_move_8bit( _environment, result->realName, "DOJOERROR" );
142
143 char labelReturn[MAX_TEMPORARY_STORAGE]; sprintf( labelReturn, "%srv", label );
144 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0, labelReturn, 1 );
145 cpu_store_8bit( _environment, result->realName, 0xff );
146 cpu_label( _environment, labelReturn );
147
148 return result;
149
150}
151
void cpu_addressof_16bit(Environment *_environment, char *_source, char *_destination)
Definition 6309.c:1485
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_inc_16bit(Environment *_environment, char *_variable)
Definition 6309.c:4565
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(Environment *_environment, char *_name)
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_request(Environment *_environment, int _command, char *_param1, char *_param2, char *_address, char *_size, char *_result)
Definition dojo.c:73
void dojo_get_response0(Environment *_environment, char *_status)
Definition dojo.c:113
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
Variable * dojo_put_message(Environment *_environment, char *_port, char *_channel, char *_message)
int size
Definition ugbc.h:1077
VariableType type
Definition ugbc.h:988
VariableType arrayType
Definition ugbc.h:1125
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
#define DOJO_PUT_MESSAGE_ARRAY_TYPE_UNSUPPORTED(v, t)
Definition ugbc.h:3819
#define DOJO_PUT_MESSAGE_DOJOKA_REQUIRED(v, t)
Definition ugbc.h:3816
struct _Environment Environment
Structure of compilation environment.
@ VT_DOJOKA
Definition ugbc.h:534
@ VT_TARRAY
Definition ugbc.h:480
@ VT_STRING
Definition ugbc.h:474
@ VT_BYTE
Definition ugbc.h:450
@ VT_SBYTE
Definition ugbc.h:452
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_DSTRING
Definition ugbc.h:483
#define DOJO_CMD_PUT_MESSAGE
Definition ugbc.h:4734
#define DOJO_PUT_MESSAGE_ARRAY_SIZE_UNSUPPORTED(v, t)
Definition ugbc.h:3820
#define DOJO_PUT_MESSAGE_STRING_REQUIRED(v, t)
Definition ugbc.h:3817
#define DOJO_CMD_SELECT_PORT
Definition ugbc.h:4733
#define VT_BITWIDTH(t)
Definition ugbc.h:595
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]