ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
dojo_open_port.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 OPEN PORT
41
42@english
43
44The ''OPEN PORT'' instruction allows you to open a port previously created with the
45''CREATE PORT'' command. This command accepts, as a parameter, the string with the
46unique and printable identification code of the port, equivalent to an 8-digit hexadecimal
47code. The result of the call will be the same identifier, which can be used for other
48instructions. The instruction will issue an error if the port is unknown. In case the
49provided port is an empty string, this command will behave like ''CREATE PORT''.
50
51@italian
52
53L'istruzione ''OPEN PORT'' permette di aprire una porta creata in precedenza con il comando
54''CREATE PORT''. Questo comando accetta, come parametro, la stringa con il codice
55identificativo univoco e stampabile della porta, equivalente a un codice di 8 cifre esadecimali.
56Il risultato della chiamata sarà il medesimo identificativo, utilizzabile per le altre istruzioni.
57L'istruzione emetterà un errore nel caso in cui la porta sia sconosciuta. Nel caso in cui la
58porta fornita sia una stringa vuota, questo comando si comporterà come ''CREATE PORT''.
59
60@syntax [[DOJO] OPEN] PORT( id )
61
62@example handle = OPEN PORT( "ce420000" )
63
64@alias DOJO OPEN PORT
65@alias PORT
66
67@seeAlso CREATE PORT
68
69@target atari, coco
70</usermanual> */
71
72/* <usermanual>
73@keyword DOJO OPEN PORT
74
75@english
76
77@italian
78
79@alias OPEN PORT
80@alias PORT
81
82@target atari, coco
83</usermanual> */
84
85/* <usermanual>
86@keyword PORT
87
88@english
89
90@italian
91
92@alias OPEN PORT
93@alias DOJO OPEN PORT
94
95@target atari, coco
96</usermanual> */
97
98Variable * dojo_open_port( Environment * _environment, char * _port ) {
99
101
102 Variable * port = variable_retrieve_or_define( _environment, _port, VT_BYTE, 0 );
103 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(address)" );
104 Variable * size = variable_temporary( _environment, VT_BYTE, "(size)" );
105
106 switch( port->type ) {
107 case VT_STRING: {
108 cpu_move_8bit( _environment, port->realName, size->realName );
109 cpu_addressof_16bit( _environment, port->realName, address->realName );
110 cpu_inc_16bit( _environment, address->realName );
111 break;
112 }
113 case VT_DSTRING: {
114 cpu_dsdescriptor( _environment, port->realName, address->realName, size->realName );
115 break;
116 }
117 default:
119 break;
120 }
121
122 Variable * dojoHandle = variable_temporary( _environment, VT_DOJOKA, "(dojo handle)" );
123 Variable * result = variable_temporary( _environment, VT_BYTE, "(unique id)" );
124
125 dojo_begin( _environment );
126 dojo_put_request( _environment, DOJO_CMD_OPEN_PORT, NULL, NULL, address->realName, size->realName, result->realName );
127 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0, label, 0 );
128 dojo_partial( _environment );
129 dojo_get_responsed( _environment, result->realName, dojoHandle->realName, NULL );
130
131 cpu_label( _environment, label );
132 dojo_end( _environment );
133
134 cpu_move_8bit( _environment, result->realName, "DOJOERROR" );
135
136 return dojoHandle;
137
138}
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_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_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_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_open_port(Environment *_environment, char *_port)
char * realName
Definition ugbc.h:982
#define DOJO_OPEN_PORT_STRING_REQUIRED(v, t)
Definition ugbc.h:3815
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_DOJOKA
Definition ugbc.h:534
@ VT_STRING
Definition ugbc.h:474
@ VT_BYTE
Definition ugbc.h:450
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_DSTRING
Definition ugbc.h:483
#define DOJO_CMD_OPEN_PORT
Definition ugbc.h:4732
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]