ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
dojo_ping.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
37extern char DATATYPE_AS_STRING[][16];
38
39/* <usermanual>
40@keyword PING
41
42@english
43
44The ''PING'' instruction allows you to check whether the server is active and
45whether communication is occurring correctly. It can be invoked without parameters,
46to check whether the connection is working, or with one or two parameters, to check
47whether the connection does not compromise the data transmitted. To check this,
48you need to know that the two parameters, if provided, will be used to compose the
49response. So, for example, by providing ''&H15'' and ''&H16'' as input parameters,
50the result obtained should be ''&H15162A2B'' (in the case of a "big endian"
51computer) or ''&2B2A1615'' (in the case of a "little endian" computer).
52
53@italian
54
55L'istruzione ''PING'' consente di verificare se il server è attivo e se la
56comunicazione avviene correttamente. Si può invocare senza parametri, per
57verificare se la connessione funziona, o con uno o due parametri, per verificare
58che la connessione non comprometta i dati trasmessi. Per verificarlo è necessario
59sapere che i due parametri, se forniti, saranno utilizzati per comporre la risposta.
60Quindi, ad esempio, fornendo ''&H15'' e ''&H16'' come parametri in ingresso, il
61risultato ottenuto dovrà essere ''&H15162A2B'' (in caso di computer "big endian") oppure
62''&2B2A1615'' (in caso di computer "little endian").
63
64@syntax [DOJO] PING[ ( [param1 [,param2] ] ) ]
65
66@example response = PING( &H15, &H16 )
67@example IF response = "15162A2B" OR response = "2B2A1615" THEN
68@example PRINT "Data transmission ok!"
69@example ENDIF
70
71@seeAlso DOJO PING
72
73@target atari, coco
74</usermanual> */
75
76/* <usermanual>
77@keyword DOJO PING
78
79@english
80
81@italian
82
83@alias PING
84
85@target atari, coco
86</usermanual> */
87
88Variable * dojo_ping( Environment * _environment, char * _param1, char * _param2 ) {
89
91
92 Variable * result = variable_temporary( _environment, VT_BYTE, "(ping ok)" );
93
94 Variable * param1 = NULL;
95 if ( _param1 ) {
96 param1 = variable_retrieve_or_define( _environment, _param1, VT_BYTE, 0 );
97 }
98 Variable * param2 = NULL;
99 if ( _param2 ) {
100 param2 = variable_retrieve_or_define( _environment, _param2, VT_BYTE, 0 );
101 }
102
103 Variable * dword = variable_temporary( _environment, VT_DWORD, "(pinged)" );
104
105 dojo_begin( _environment );
106 dojo_put_request0( _environment, DOJO_CMD_PING, (param1)?param1->realName:NULL, (param2)?param2->realName:NULL, result->realName );
107 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0, label, 0 );
108 dojo_partial( _environment );
109 // wait_milliseconds( _environment, 500 );
110 dojo_get_responsed( _environment, result->realName, dword->realName, NULL );
111
112 cpu_label( _environment, label );
113 dojo_end( _environment );
114
115 cpu_move_8bit( _environment, result->realName, "DOJOERROR" );
116
117 return dword;
118
119}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
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_begin(Environment *_environment)
Definition dojo.c:53
Variable * dojo_ping(Environment *_environment, char *_param1, char *_param2)
Definition dojo_ping.c:88
char * realName
Definition ugbc.h:982
#define DOJO_CMD_PING
Definition ugbc.h:4730
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_BYTE
Definition ugbc.h:450
@ VT_DWORD
Definition ugbc.h:460
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]