ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_vars.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#if defined(__coco__) || defined(__coco3__) || defined(__d32__) || defined(__d64__) || defined(__mo5__) || defined(__pc128op__) || defined(__to8__) || \
38 defined(__cocob__) || defined(__coco3b__) || defined(__d32b__) || defined(__d64b__)
39
40/****************************************************************************
41 * CODE SECTION
42 ****************************************************************************/
43
44extern char DATATYPE_AS_STRING[][16];
45
46void vars_emit_constant_integer( Environment * _environment, char * _name, int _value ) {
47
48 outhead2("%s EQU $%4.4x", _name, _value );
49
50}
51
52void vars_emit_constant_integer_relative( Environment * _environment, char * _name, char * _relative, int _value ) {
53
54 outhead3("%s EQU %s+$%4.4x", _name, _relative, _value );
55
56}
57
58void vars_emit_constants( Environment * _environment ) {
59
60 int i=0;
61
62 if ( _environment->constants ) {
63 Constant * actual = _environment->constants;
64 while( actual ) {
65 if ( ! actual->emitted ) {
66 switch( actual->type ) {
67 case CT_INTEGER:
68 if ( actual->relative ) {
69 vars_emit_constant_integer_relative( _environment, actual->realName, actual->relative, actual->value );
70 } else {
71 vars_emit_constant_integer( _environment, actual->realName, actual->value );
72 }
73 break;
74 case CT_STRING:
75 break;
76 }
77 }
78 actual = actual->next;
79 }
80 }
81
82}
83
84void vars_emit_byte( Environment * _environment, char * _name, int _value ) {
85 if ( _name ) {
86 outhead2("%s fcb $%2.2x", _name, (unsigned char)( _value & 0xff ) );
87 } else {
88 outline1(" fcb $%2.2x", (unsigned char)( _value & 0xff ) );
89 }
90}
91
92void vars_emit_word( Environment * _environment, char * _name, int _value ) {
93 if ( _name ) {
94 outhead2("%s fdb $%4.4x", _name, (unsigned int)( _value & 0xffff ) );
95 } else {
96 outline1(" fdb $%4.4x", (unsigned int)( _value & 0xffff ) );
97 }
98}
99
100void vars_emit_dword( Environment * _environment, char * _name, int _value ) {
101 if ( _name ) {
102 outhead3("%s fdb $%4.4x,$%4.4x", _name, (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
103 } else {
104 outline2(" fdb $%4.4x,$%4.4x", (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
105 }
106}
107
108void vars_emit_number( Environment * _environment, char * _name, int _value ) {
109 if ( _name ) {
110 outhead3("%s fdb $%4.4x,$%4.4x", _name, (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
111 outhead1(" rzb %d", _environment->numberConfig.maxBytes - 4 );
112 } else {
113 outline2(" fdb $%4.4x,$%4.4x", (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
114 outhead1(" rzb %d", _environment->numberConfig.maxBytes - 4 );
115 }
116}
117
118void vars_emit_strips( Environment * _environment, char * _name, Strip * _strips ) {
119
120 int maxId = 0;
121 Strip * actual = _strips;
122 while( actual ) {
123 if ( maxId <= actual->id ) {
124 maxId = actual->id+1;
125 }
126 actual = actual->next;
127 }
128 int i=0;
129 for( i=0; i<maxId; ++i ) {
130 Strip * actual = _strips;
131 while( actual ) {
132 if ( actual->id == i ) {
133 outhead2("%sstrip%d", _name, i );
134 for( int j=0; j<actual->count; ++j ) {
135 outline1( "fcb $%2.2x", actual->frames[j] );
136 }
137 break;
138 }
139 actual = actual->next;
140 }
141 }
142
143 actual = _strips;
144 i = 0;
145 outhead1("%sstrip", _name );
146
147 for( i=0; i<maxId; ++i ) {
148 Strip * actual = _strips;
149 while( actual ) {
150 if ( actual->id == i ) {
151 outline2("fdb %sstrip%d", _name, i );
152 break;
153 }
154 actual = actual->next;
155 }
156 if ( ! actual ) {
157 outline0("fdb $0000" );
158 }
159 }
160
161}
162
163#endif
void vars_emit_constant_integer(Environment *_environment, char *_name, int _value)
Definition _vars.c:46
void vars_emit_word(Environment *_environment, char *_name, int _value)
Definition _vars.c:92
void vars_emit_dword(Environment *_environment, char *_name, int _value)
Definition _vars.c:100
void vars_emit_number(Environment *_environment, char *_name, int _value)
Definition _vars.c:108
void vars_emit_constants(Environment *_environment)
Definition _vars.c:58
void vars_emit_byte(Environment *_environment, char *_name, int _value)
Definition _vars.c:84
void vars_emit_strips(Environment *_environment, char *_name, Strip *_strips)
Definition _vars.c:118
void vars_emit_constant_integer_relative(Environment *_environment, char *_name, char *_relative, int _value)
Definition _vars.c:52
char * relative
Definition ugbc.h:829
int emitted
Definition ugbc.h:827
int value
Definition ugbc.h:815
ConstantType type
Definition ugbc.h:805
struct _Constant * next
Definition ugbc.h:832
char * realName
Definition ugbc.h:803
NumberConfig numberConfig
Definition ugbc.h:2410
Constant * constants
Definition ugbc.h:2611
int maxBytes
Definition ugbc.h:2261
int id
Definition ugbc.h:965
struct _Strip * next
Definition ugbc.h:969
int count
Definition ugbc.h:967
int frames[MAX_FRAMES_PER_STRIP]
Definition ugbc.h:966
@ CT_STRING
Definition ugbc.h:789
@ CT_INTEGER
Definition ugbc.h:788
#define outline2(s, a, b)
Definition ugbc.h:4254
struct _Environment Environment
Structure of compilation environment.
struct _Strip Strip
struct _Constant Constant
Structure of a single constant.
#define outhead3(s, a, b, c)
Definition ugbc.h:4249
#define outline0(s)
Definition ugbc.h:4252
#define outhead2(s, a, b)
Definition ugbc.h:4248
#define outline1(s, a)
Definition ugbc.h:4253
#define outhead1(s, a)
Definition ugbc.h:4247
char DATATYPE_AS_STRING[][16]