ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
joydir.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
41Variable * joydir_semivars( Environment * _environment, char * _port ) {
42
44
45 Variable * joymove = variable_temporary( _environment, VT_BYTE, "(joymove)");
46 variable_store( _environment, joymove->name, 0 );
47 Variable * result = variable_temporary( _environment, VT_BYTE, "(result)");
48 variable_store( _environment, result->name, 0 );
49
50 char detectedLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedLabel, "%sdetected", label );
51 char detectedDownLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedDownLabel, "%sdetecteddown", label );
52 char detectedLeftLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedLeftLabel, "%sdetectedleft", label );
53 char detectedRightLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedRightLabel, "%sdetectedright", label );
54
55 variable_move( _environment, joy_vars( _environment, _port )->name, joymove->name );
56
57 cpu_bit_check( _environment, joymove->realName, JOY_UP, result->realName, VT_BITWIDTH( joymove->type ) );
58 variable_compare_and_branch_const( _environment, result->name, 0, detectedDownLabel, 1 );
59 variable_store( _environment, result->name, 1 );
60 cpu_jump( _environment, detectedLabel );
61
62 cpu_label( _environment, detectedDownLabel );
63 cpu_bit_check( _environment, joymove->realName, JOY_DOWN, result->realName, VT_BITWIDTH( joymove->type ) );
64 variable_compare_and_branch_const( _environment, result->name, 0, detectedLeftLabel, 1 );
65 variable_store( _environment, result->name, 2 );
66 cpu_jump( _environment, detectedLabel );
67
68 cpu_label( _environment, detectedLeftLabel );
69 cpu_bit_check( _environment, joymove->realName, JOY_LEFT, result->realName, VT_BITWIDTH( joymove->type ) );
70 variable_compare_and_branch_const( _environment, result->name, 0, detectedRightLabel, 1 );
71 variable_store( _environment, result->name, 4 );
72 cpu_jump( _environment, detectedLabel );
73
74 cpu_label( _environment, detectedRightLabel );
75 cpu_bit_check( _environment, joymove->realName, JOY_RIGHT, result->realName, VT_BITWIDTH( joymove->type ) );
76 variable_compare_and_branch_const( _environment, result->name, 0, detectedLabel, 1 );
77 variable_store( _environment, result->name, 8 );
78
79
80 cpu_label( _environment, detectedLabel );
81
82 return result;
83
84}
85
86Variable * joydir( Environment * _environment, int _port ) {
87
89
90 Variable * joymove = variable_temporary( _environment, VT_BYTE, "(joymove)");
91 variable_store( _environment, joymove->name, 0 );
92 Variable * result = variable_temporary( _environment, VT_BYTE, "(result)");
93 variable_store( _environment, result->name, 0 );
94
95 char detectedLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedLabel, "%sdetected", label );
96 char detectedDownLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedDownLabel, "%sdetecteddown", label );
97 char detectedLeftLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedLeftLabel, "%sdetectedleft", label );
98 char detectedRightLabel[MAX_TEMPORARY_STORAGE]; sprintf(detectedRightLabel, "%sdetectedright", label );
99
100 variable_move( _environment, joy( _environment, _port )->name, joymove->name );
101
102 cpu_bit_check( _environment, joymove->realName, JOY_UP, result->realName, VT_BITWIDTH( joymove->type ) );
103 variable_compare_and_branch_const( _environment, result->name, 0, detectedDownLabel, 1 );
104 variable_store( _environment, result->name, 1 );
105 cpu_jump( _environment, detectedLabel );
106
107 cpu_label( _environment, detectedDownLabel );
108 cpu_bit_check( _environment, joymove->realName, JOY_DOWN, result->realName, VT_BITWIDTH( joymove->type ) );
109 variable_compare_and_branch_const( _environment, result->name, 0, detectedLeftLabel, 1 );
110 variable_store( _environment, result->name, 2 );
111 cpu_jump( _environment, detectedLabel );
112
113 cpu_label( _environment, detectedLeftLabel );
114 cpu_bit_check( _environment, joymove->realName, JOY_LEFT, result->realName, VT_BITWIDTH( joymove->type ) );
115 variable_compare_and_branch_const( _environment, result->name, 0, detectedRightLabel, 1 );
116 variable_store( _environment, result->name, 4 );
117 cpu_jump( _environment, detectedLabel );
118
119 cpu_label( _environment, detectedRightLabel );
120 cpu_bit_check( _environment, joymove->realName, JOY_RIGHT, result->realName, VT_BITWIDTH( joymove->type ) );
121 variable_compare_and_branch_const( _environment, result->name, 0, detectedLabel, 1 );
122 variable_store( _environment, result->name, 8 );
123
124 cpu_label( _environment, detectedLabel );
125
126 return result;
127
128}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
void cpu_bit_check(Environment *_environment, char *_value, int _position, char *_result, int _bitwidth)
Definition 6309.c:5577
void variable_compare_and_branch_const(Environment *_environment, char *_source, int _destination, char *_name, int _positive)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
char * name
Definition _optimizer.c:672
Variable * joy(Environment *_environment, int _port)
Definition joy.c:68
Variable * joy_vars(Environment *_environment, char *_port)
Definition joy.c:41
#define JOY_RIGHT
Definition atari.h:46
#define JOY_LEFT
Definition atari.h:45
#define JOY_UP
Definition atari.h:43
#define JOY_DOWN
Definition atari.h:44
Variable * joydir(Environment *_environment, int _port)
Definition joydir.c:86
Variable * joydir_semivars(Environment *_environment, char *_port)
Definition joydir.c:41
char * name
Definition ugbc.h:979
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_BYTE
Definition ugbc.h:450
#define VT_BITWIDTH(t)
Definition ugbc.h:595
#define MAKE_LABEL
Definition ugbc.h:3351