ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_shell.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
41void shell_injection( Environment * _environment ) {
42
43 char versionString[MAX_TEMPORARY_STORAGE]; sprintf( versionString, "ugBASIC Runtime version %s", UGBASIC_VERSION );
44
45 Variable * presentationLine = variable_define( _environment, "SHELL_PRESENTATION", VT_STRING, 0 );
46 variable_store_string( _environment, presentationLine->name, versionString );
47 Variable * prompt = variable_define( _environment, "SHELL_PROMPT", VT_STRING, 0 );
48 variable_store_string( _environment, prompt->name, "READY" );
49 Variable * command = variable_define( _environment, "SHELL_COMMAND", VT_DSTRING, 0 );
50 Variable * loweredCommand = variable_define( _environment, "SHELL_LOWERED_COMMAND", VT_DSTRING, 0 );
51 Variable * commandRun = variable_define( _environment, "SHELL_COMMAND_RUN", VT_STRING, 0 );
52 variable_store_string( _environment, commandRun->name, "run" );
53 Variable * commandList = variable_define( _environment, "SHELL_COMMAND_LIST", VT_STRING, 0 );
54 variable_store_string( _environment, commandList->name, "list" );
55 Variable * syntaxError = variable_define( _environment, "SHELL_SYNTAX_ERROR", VT_STRING, 0 );
56 variable_store_string( _environment, syntaxError->name, "? SYNTAX ERROR" );
57 Variable * source = variable_retrieve( _environment, "SHELL_SOURCE" );
58 Variable * result = variable_temporary( _environment, VT_BYTE, "(result)");
59
60 cls( _environment, NULL );
61
62 cpu_label( _environment, "SHELL" );
63
64 print( _environment, presentationLine->name, 1, _environment->printRaw );
65
66 begin_do_loop( _environment );
67
68 cpu_label( _environment, "SHELLPROMPT" );
69
70 print_newline( _environment );
71
72 print( _environment, prompt->name, 1, _environment->printRaw );
73
74 input( _environment, command->name, VT_DSTRING );
75
76 outline0("; lowered");
77 loweredCommand = variable_string_lower( _environment, command->name );
78
79 outline0("; compare");
80 result = variable_compare( _environment, loweredCommand->name, commandRun->name );
81
82 outline0("; compare and branch");
83 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0xff, "PROGSTART", 1 );
84
85 outline0("; compare2");
86 result = variable_compare( _environment, loweredCommand->name, commandList->name );
87
88 outline0("; compare and branch2");
89 cpu_compare_and_branch_8bit_const( _environment, result->realName, 0xff, "PROGLIST", 1 );
90
91 print( _environment, syntaxError->name, 1, _environment->printRaw );
92
93 cpu_dsfree( _environment, loweredCommand->realName );
94 cpu_dsfree( _environment, command->realName );
95
96 end_do_loop( _environment );
97
98 cpu_label( _environment, "PROGLIST" );
99
100 print_newline( _environment );
101
102 print_buffer( _environment, source->name, 1, 1 );
103
104 cpu_jump( _environment, "SHELLPROMPT" );
105
106 cpu_label( _environment, "PROGSTART" );
107
108 home( _environment );
109
110 cls( _environment, NULL );
111
112}
void cpu_dsfree(Environment *_environment, char *_index)
Definition 6309.c:5917
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_jump(Environment *_environment, char *_label)
Definition 6309.c:3739
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(Environment *_environment, char *_name)
Variable * variable_string_lower(Environment *_environment, char *_string)
Emit code for = UPPER( ... ).
Variable * variable_define(Environment *_environment, char *_name, VariableType _type, int _value)
Define a variable for the program.
Variable * variable_store_string(Environment *_environment, char *_destination, char *_value)
Store a string to a variable.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_compare(Environment *_environment, char *_source, char *_destination)
Compare two variable and return the result of comparation.
void shell_injection(Environment *_environment)
Definition _shell.c:41
void cls(Environment *_environment, char *_paper)
Emit code for CLS.
Definition cls.c:48
void begin_do_loop(Environment *_environment)
Emit ASM code for DO ....
void end_do_loop(Environment *_environment)
Emit ASM code for ... LOOP.
Definition end_do_loop.c:49
void home(Environment *_environment)
Emit code for HOME.
Definition home.c:70
void print_newline(Environment *_environment)
Emit code for print a single newline.
Definition print.c:422
void print(Environment *_environment, char *_value, int _new_line, int _raw)
Emit code for PRINT... instruction.
Definition print.c:141
void print_buffer(Environment *_environment, char *_value, int _new_line, int _printable)
Emit code for PRINT... instruction.
int printRaw
Definition ugbc.h:3274
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_STRING
Definition ugbc.h:474
@ VT_BYTE
Definition ugbc.h:450
@ VT_DSTRING
Definition ugbc.h:483
#define outline0(s)
Definition ugbc.h:4252
#define UGBASIC_VERSION
Definition ugbc.h:63