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
39/****************************************************************************
40 * CODE SECTION
41 ****************************************************************************/
42
43extern char DATATYPE_AS_STRING[][16];
44
45void vars_emit_constant_integer( Environment * _environment, char * _name, int _value ) {
46
47 outhead2("%s EQU $%4.4x", _name, _value );
48
49}
50
51void vars_emit_constant_integer_relative( Environment * _environment, char * _name, char * _relative, int _value ) {
52
53 outhead3("%s EQU %s+$%4.4x", _name, _relative, _value );
54
55}
56
57void vars_emit_constants( Environment * _environment ) {
58
59 int i=0;
60
61 if ( _environment->constants ) {
62 Constant * actual = _environment->constants;
63 while( actual ) {
64 if ( ! actual->emitted ) {
65 switch( actual->type ) {
66 case CT_INTEGER:
67 if ( actual->relative ) {
68 vars_emit_constant_integer_relative( _environment, actual->realName, actual->relative, actual->value );
69 } else {
70 vars_emit_constant_integer( _environment, actual->realName, actual->value );
71 }
72 break;
73 case CT_STRING:
74 break;
75 }
76 }
77 actual = actual->next;
78 }
79 }
80
81}
82
83void vars_emit_byte( Environment * _environment, char * _name, int _value ) {
84 if ( _name ) {
85 outhead2("%s fcb $%2.2x", _name, (unsigned char)( _value & 0xff ) );
86 } else {
87 outline1(" fcb $%2.2x", (unsigned char)( _value & 0xff ) );
88 }
89}
90
91void vars_emit_word( Environment * _environment, char * _name, int _value ) {
92 if ( _name ) {
93 outhead2("%s fdb $%4.4x", _name, (unsigned int)( _value & 0xffff ) );
94 } else {
95 outline1(" fdb $%4.4x", (unsigned int)( _value & 0xffff ) );
96 }
97}
98
99void vars_emit_dword( Environment * _environment, char * _name, int _value ) {
100 if ( _name ) {
101 outhead3("%s fdb $%4.4x,$%4.4x", _name, (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
102 } else {
103 outline2(" fdb $%4.4x,$%4.4x", (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
104 }
105}
106
107void vars_emit_number( Environment * _environment, char * _name, int _value ) {
108 if ( _name ) {
109 outhead3("%s fdb $%4.4x,$%4.4x", _name, (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
110 outhead1(" rzb %d", _environment->numberConfig.maxBytes - 4 );
111 } else {
112 outline2(" fdb $%4.4x,$%4.4x", (unsigned int)( (_value>>16) & 0xffff ), (unsigned int)( _value & 0xffff ) );
113 outhead1(" rzb %d", _environment->numberConfig.maxBytes - 4 );
114 }
115}
116
117void vars_emit_strips( Environment * _environment, char * _name, Strip * _strips ) {
118
119 int maxId = 0;
120 Strip * actual = _strips;
121 while( actual ) {
122 if ( maxId <= actual->id ) {
123 maxId = actual->id+1;
124 }
125 actual = actual->next;
126 }
127 int i=0;
128 for( i=0; i<maxId; ++i ) {
129 Strip * actual = _strips;
130 while( actual ) {
131 if ( actual->id == i ) {
132 outhead2("%sstrip%d", _name, i );
133 for( int j=0; j<actual->count; ++j ) {
134 outline1( "fcb $%2.2x", actual->frames[j] );
135 }
136 break;
137 }
138 actual = actual->next;
139 }
140 }
141
142 actual = _strips;
143 i = 0;
144 outhead1("%sstrip", _name );
145
146 for( i=0; i<maxId; ++i ) {
147 Strip * actual = _strips;
148 while( actual ) {
149 if ( actual->id == i ) {
150 outline2("fdb %sstrip%d", _name, i );
151 break;
152 }
153 actual = actual->next;
154 }
155 if ( ! actual ) {
156 outline0("fdb $0000" );
157 }
158 }
159
160}
161
162#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]