ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
timer.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/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
49/* <usermanual>
50@keyword TIMER
51
52@english
53This variable represents a "timer", which is the number of sixtieths / fiftieths
54of a second that have passed since the machine was turned on. This variable,
55when used as a value, measures the elapsed time. However, it can be set to an
56arbitrary value, such as 0, to measure a defined period of time.
57
58The refresh rate of this timer depends on the type of video standard used,
59that is, PAL (50Hz) or NTSC (60Hz).
60
61This variable can be abbreviated as ''TI''.
62
63@italian
64Questa variable rappresenta un "timer", ovvero il numero di sessantesimi /
65cinquantesimi di secondo che sono passati dall'accensione della macchina.
66Questa variabile, se usata come valore, misura il tempo passato. Può essere
67comunque impostata ad un valore arbitrario, come ad esempio 0, per misurare un
68periodo di tempo definito.
69
70La frequenza di aggiornamento di questo timer dipende dal tipo di standard
71video utilizzato, ovvero se PAL (50Hz) oppure NTSC (60Hz).
72
73Questa variabile può essere abbreviata come ''TI''.
74
75@syntax = TIMER
76@syntax TIMER = [50th/60th seconds]
77
78@example PRINT TIMER
79
80@usedInExample contrib_sierpinski.bas
81@usedInExample contrib_sierpinski2.bas
82@usedInExample contrib_sierpinski3.bas
83
84@seeAlso TI
85@target c128
86</usermanual> */
87/* <usermanual>
88@keyword TI
89
90@english
91
92@italian
93
94@alias TIMER
95</usermanual> */
96Variable * get_timer( Environment * _environment ) {
97
98 Variable * result = variable_temporary( _environment, VT_WORD, "(result of get timer)");
99
100 char resultAddress[MAX_TEMPORARY_STORAGE];
101 cpu_move_8bit( _environment, "$A2", result->realName );
102 sprintf(resultAddress, "%s", address_displacement(_environment, result->realName, "1") );
103 cpu_move_8bit( _environment, "$A1", resultAddress );
104 // sprintf(resultAddress, "%s", address_displacement(_environment, result->realName, "2") );
105 // cpu_move_8bit( _environment, "$A2", resultAddress );
106
107 return result;
108
109}
110
119/* <usermanual>
120@keyword TIMER
121</usermanual> */
122
123void set_timer( Environment * _environment, char * _value ) {
124
125 Variable * value = variable_retrieve_or_define( _environment, _value, VT_WORD, 0 );
126
127 char valueAddress[MAX_TEMPORARY_STORAGE];
128 cpu_move_8bit( _environment, value->realName, "$A2" );
129 sprintf(valueAddress, "%s", address_displacement(_environment, value->realName, "1") );
130 cpu_move_8bit( _environment, valueAddress, "$A1" );
131 cpu_move_8bit( _environment, "#0", "$A0" );
132
133}
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
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.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
void set_timer(Environment *_environment, char *_value)
Definition timer.c:67
Variable * get_timer(Environment *_environment)
Definition timer.c:47
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455