Skip to content

Commit

Permalink
View history
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoAiresCastello committed Jul 26, 2022
1 parent a32fd68 commit 462684d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 14 deletions.
Binary file modified Build/PTM.exe
Binary file not shown.
1 change: 1 addition & 0 deletions Build/test.ptml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
O35bIFRFU1QgUFJPR1JBTSBdfn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+
a2V5LmVzYy5vbg==
Q0FMTCBpbml0X2Nocg==
Q0FMTCBpbml0X3BhbA==

Expand Down
17 changes: 12 additions & 5 deletions PTM/t_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ bool t_command::execute(string& cmd, t_params& args) {
else if (cmd == "TILE.STORE") store_cur_tile(args);
else if (cmd == "TILE.PSTORE") parse_and_store_tile(args);
else if (cmd == "TILE.LOAD") load_cur_tile(args);
else if (cmd == "TILE.TRA") set_tile_transparency(args);
else if (cmd == "TILE.TRA.ON") set_tile_transparency(args, true);
else if (cmd == "TILE.TRA.OFF") set_tile_transparency(args, false);
// Tile buffer cursor
else if (cmd == "CSR.LAYER") select_layer(args);
else if (cmd == "CSR.SET") set_cursor_pos(args);
Expand Down Expand Up @@ -72,6 +73,8 @@ bool t_command::execute(string& cmd, t_params& args) {
else if (cmd == "KEY.GET") get_key_pressed(args);
else if (cmd == "KEY.CALL") call_if_key_pressed(args);
else if (cmd == "KEY.GOTO") goto_if_key_pressed(args);
else if (cmd == "KEY.ESC.ON") allow_exit_on_escape_key(args, true);
else if (cmd == "KEY.ESC.OFF") allow_exit_on_escape_key(args, false);
// Debug
else if (cmd == "DBG.FILE") save_debug_file(args);
// Conditionals
Expand Down Expand Up @@ -398,10 +401,9 @@ void t_command::set_wnd_bgcolor(t_params& arg) {
ARGC(1);
machine->wnd->SetBackColor(machine->pal->GetColorRGB(intp->require_number(arg[0])));
}
void t_command::set_tile_transparency(t_params& arg) {
ARGC(1);
int value = intp->require_number(arg[0]);
machine->tile_transparency = value > 0;
void t_command::set_tile_transparency(t_params& arg, bool transparent) {
ARGC(0);
machine->tile_transparency = transparent;
}
void t_command::select_layer(t_params& arg) {
ARGC(1);
Expand Down Expand Up @@ -727,3 +729,8 @@ void t_command::increment_variable(t_params& arg) {
auto& var = machine->vars[arr_id];
machine->vars[arr_id] = String::ToString(String::ToInt(var.value) + 1);
}

void t_command::allow_exit_on_escape_key(t_params& arg, bool allow) {
ARGC(0);
machine->exit_key = allow ? SDLK_ESCAPE : 0;
}
3 changes: 2 additions & 1 deletion PTM/t_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct t_command {
void clear_layer(t_params& arg);
void clear_rect(t_params& arg);
void set_wnd_bgcolor(t_params& arg);
void set_tile_transparency(t_params& arg);
void set_tile_transparency(t_params& arg, bool transparent);
void select_layer(t_params& arg);
void define_char(t_params& arg);
void define_color(t_params& arg);
Expand Down Expand Up @@ -79,4 +79,5 @@ struct t_command {
void clear_array(t_params& arg);
void copy_array(t_params& arg);
void increment_variable(t_params& arg);
void allow_exit_on_escape_key(t_params& arg, bool allow);
};
17 changes: 12 additions & 5 deletions PTM/t_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@ void t_compiler::run(t_program* prg) {
prg->lines.clear();
prg->labels.clear();
int src_line_nr = 1;
for (auto& srcline : prg->src_lines) {
for (auto& src_line : prg->src_lines) {
t_program_line new_line;
bool must_add_line = compile(prg, &new_line, srcline, src_line_nr);
bool must_add_line = compile(prg, &new_line, src_line, src_line_nr);
if (must_add_line) {
prg->lines.push_back(new_line);
}
src_line_nr++;
}
}
bool t_compiler::compile(t_program* prg, t_program_line* new_line, string src_line, int src_line_nr) {
int line_ix = prg->lines.size();
if (String::StartsWith(src_line, ' ')) {
add_error(src_line_nr, src_line, "Leading whitespace is not allowed");
return false;
}
src_line = String::Trim(src_line);
if (String::StartsWith(src_line, ';')) {
return false;
}
if (String::StartsWith(src_line, ":")) {
string label = String::Trim(String::Skip(src_line, 1));
prg->labels[label] = line_ix;
prg->labels[label] = prg->lines.size();
return false;
}
if (!src_line.empty() && !String::StartsWithLetter(src_line)) {
add_error(src_line_nr, src_line, "Syntax error");
return false;
}
new_line->src = src_line;
Expand Down Expand Up @@ -118,6 +125,6 @@ bool t_compiler::compile(t_program* prg, t_program_line* new_line, string src_li
return true;
}
void t_compiler::add_error(int line, string src, string msg) {
errors.push_back(String::Format("At line %i:\n%s\n\n%s",
errors.push_back(String::Format("COMPILATION ERROR\nAt line %i:\n%s\n\n%s",
line, msg.c_str(), src.c_str()));
}
4 changes: 3 additions & 1 deletion PTM/t_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ void t_interpreter::execute_current_line() {
void t_interpreter::on_keydown(SDL_Keycode key, bool ctrl, bool shift, bool alt) {
if (key == SDLK_RETURN && TKey::Alt()) {
wnd->ToggleFullscreen();
} else if (machine->exit_key != 0 && key == machine->exit_key) {
running = false;
} else {
machine->last_key_pressed = key;
}
}
void t_interpreter::abort(string error) {
running = false;
if (cur_line) {
errors.push_back(String::Format("At line %i:\n%s\n\n%s",
errors.push_back(String::Format("RUNTIME ERROR\nAt line %i:\n%s\n\n%s",
cur_line->src_line_nr, error.c_str(), cur_line->src.c_str()));
} else {
errors.push_back(error);
Expand Down
1 change: 1 addition & 0 deletions PTM/t_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct t_machine {
} text_color;
// Input
SDL_Keycode last_key_pressed = 0;
SDL_Keycode exit_key = 0;
// Sound
TSound* snd = nullptr;
// Comparisons
Expand Down
4 changes: 2 additions & 2 deletions PTM/t_program_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ void t_program_editor::compile_and_run() {
void t_program_editor::print_errors(std::vector<string>& errors) {
snd->Beep(2500, 100);
string error = errors[0];
while (running) {
while (running || !cfg->autorun.empty()) {
draw_screen_base();
print_border_top("RUNTIME ERROR", 0);
print_border_top("PTM", 0);
if (cfg->autorun.empty()) {
print_border_bottom("Press ENTER to continue...", 0);
} else {
Expand Down

0 comments on commit 462684d

Please sign in to comment.