Skip to content

Commit

Permalink
View history
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoAiresCastello committed Jul 31, 2024
1 parent 386c144 commit 02d3b15
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 82 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ fernando/
temp/
cppcheck
0.3/Build/files/main.ptm
0.4/build/root/AUTOEXEC
0.4/build/root/AUTORUN
0.4/build/root/AUTOSAVE
Binary file modified 0.4/build/PTM.exe
Binary file not shown.
2 changes: 0 additions & 2 deletions 0.4/build/root/HELLOINF

This file was deleted.

43 changes: 25 additions & 18 deletions 0.4/src/PTM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void PTM::run_main()
}
on_machine_cycle();
}

on_exit();
}

void PTM::halt()
Expand Down Expand Up @@ -161,6 +163,11 @@ void PTM::on_escape_key_pressed()
}
}

void PTM::on_exit()
{
autosave_program_file();
}

SDL_Keycode PTM::await_keypress()
{
SDL_Keycode key_pressed = 0;
Expand Down Expand Up @@ -284,6 +291,8 @@ t_program& PTM::get_prg()

void PTM::run_program_from_immediate_mode()
{
autosave_program_file();

prg_runner.run_program_from_immediate_mode(this, &prg, &intp);
}

Expand All @@ -305,6 +314,7 @@ void PTM::end_program()
void PTM::new_program()
{
prg.lines.clear();
last_program_filename = "";
}

void PTM::save_program(const t_string& filename, bool hex)
Expand All @@ -313,6 +323,8 @@ void PTM::save_program(const t_string& filename, bool hex)
filesys.save_program_binary(&prg, filename);
else
filesys.save_program_plaintext(&prg, filename);

last_program_filename = filename.to_upper();
}

bool PTM::load_program(const t_string& filename, bool hex)
Expand All @@ -323,6 +335,9 @@ bool PTM::load_program(const t_string& filename, bool hex)
filesys.load_program_binary(&intp, &prg, filename);
else
filesys.load_program_plaintext(&intp, &prg, filename);

if (!prg.lines.empty())
last_program_filename = filename.to_upper();

return !prg.lines.empty();
}
Expand Down Expand Up @@ -467,24 +482,6 @@ t_string PTM::input_string(const t_string& prompt, int maxlen)
return value;
}

void PTM::create_tilebuf(const t_string& name, int cols, int rows)
{
tilebufs[name] = std::make_shared<t_tilebuffer>(cols, rows);
}

bool PTM::has_tilebuf(const t_string& name)
{
return tilebufs.contains(name);
}

t_sptr<t_tilebuffer> PTM::get_tilebuf(const t_string& name)
{
if (tilebufs.contains(name))
return tilebufs[name];

return nullptr;
}

void PTM::add_sprite(const t_string& name, int x, int y, bool visible)
{
sprites[name] = scr.add_sprite(tilereg, t_pos(x, y));
Expand All @@ -504,3 +501,13 @@ void PTM::delete_all_sprites()
scr.delete_all_sprites();
sprites.clear();
}

const t_string& PTM::get_last_program_filename() const
{
return last_program_filename;
}

void PTM::autosave_program_file()
{
filesys.save_program_binary(&prg, autosave_file);
}
13 changes: 6 additions & 7 deletions 0.4/src/PTM.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
#include "t_namespace.h"
#include "t_pointers.h"
#include "t_sprite.h"
#include "t_tilebuffer.h"
#include "t_rect.h"

class PTM
{
public:
const t_string title = "PTM - Programmable Tile Machine";
const t_string version_string = "PTM 0.4";
const t_string copyright_notice = "` 2023-2024 Fernando Aires Castello";
const t_string autoexec_file = "AUTOEXEC";
const t_string autoexec_file = "AUTORUN";
const t_string autosave_file = "AUTOSAVE";

t_tile tilereg;
bool auto_screen_update = true;
Expand All @@ -35,6 +34,7 @@ class PTM
void pause(int frames);
void on_machine_cycle();
void on_escape_key_pressed();
void on_exit();
SDL_Keycode await_keypress();
void refresh_screen();
bool is_window_open() const;
Expand Down Expand Up @@ -72,20 +72,19 @@ class PTM
bool set_function_key(const t_string& keyname, const t_string& value);
t_list<t_string> list_function_keys();
t_string input_string(const t_string& prompt, int maxlen);
void create_tilebuf(const t_string& name, int cols, int rows);
bool has_tilebuf(const t_string& name);
t_sptr<t_tilebuffer> get_tilebuf(const t_string& name);
void add_sprite(const t_string& name, int x, int y, bool visible);
t_sprite_ptr get_sprite(const t_string& name);
void delete_all_sprites();
const t_string& get_last_program_filename() const;
void autosave_program_file();

private:
bool running = false;
bool halted = false;

t_string last_program_filename;
t_namespace<t_string> vars;
t_namespace<t_sprite_ptr> sprites;
t_namespace<t_sptr<t_tilebuffer>> tilebufs;

void init();
void run_tests();
Expand Down
7 changes: 3 additions & 4 deletions 0.4/src/PTML_ALL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ t_function_ptr PTML::get_cmd_pointer(const t_string& cmd)
CMD("VAR", VAR);
CMD("VARS", VARS);
CMD("VARS.CLR", VAR_CLR);
CMD("BUF.NEW", BUF_NEW);
CMD("BUF.PUT", BUF_PUT);
CMD("BUF.GET", BUF_GET);
CMD("COLOR", COLOR);
CMD("COLOR.MONO", COLOR_MONO);
CMD("COLOR.MULTI", COLOR_MULTI);
Expand Down Expand Up @@ -78,7 +75,9 @@ t_function_ptr PTML::get_cmd_pointer(const t_string& cmd)
CMD("LOAD", LOAD);
CMD("LOAD.SRC", LOAD_SRC);
CMD("FILES", FILES);
CMD("FILE.NAME", FILE_NAME);
CMD("FILE.REN", FILE_REN);
CMD("FILE.DEL", FILE_DEL);
CMD("PROG", PROG);
CMD("GOTO", GOTO);
CMD("GOTO.E", GOTO_IFE);
CMD("GOTO.NE", GOTO_IFNE);
Expand Down
11 changes: 10 additions & 1 deletion 0.4/src/PTML_FILESYSTEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void PTML::FILES()
}
}

void PTML::FILE_NAME()
void PTML::FILE_REN()
{
ARGC(2);
auto&& old_name = STR(1);
Expand All @@ -21,3 +21,12 @@ void PTML::FILE_NAME()
VALIDATE_FILENAME(new_name);
t_filesystem::rename_file(old_name, new_name);
}

void PTML::FILE_DEL()
{
ARGC(1);
auto&& name = STR(1);
REQUIRE_FILE(name);
VALIDATE_FILENAME(name);
t_filesystem::delete_file(name);
}
3 changes: 2 additions & 1 deletion 0.4/src/PTML_FILESYSTEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
namespace PTML
{
void FILES();
void FILE_NAME();
void FILE_REN();
void FILE_DEL();
}
30 changes: 0 additions & 30 deletions 0.4/src/PTML_GRAPHICS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,33 +328,3 @@ void PTML::REFRESH()
ARGC(0);
ptm->refresh_screen();
}

void PTML::BUF_NEW()
{
ARGC(3);
ptm->create_tilebuf(STR(1), NUM(2), NUM(3));
}

void PTML::BUF_PUT()
{
ARGC(3);
TILEBUF(STR(1));
int col = NUM(2);
int row = NUM(3);
CHK_TBUF_BOUNDS(buf, col, row);

IF_TILEREG_EMPTY_RET;

buf->set(TILEREG, col, row);
}

void PTML::BUF_GET()
{
ARGC(3);
TILEBUF(STR(1));
int col = NUM(2);
int row = NUM(3);
CHK_TBUF_BOUNDS(buf, col, row);

TILEREG = buf->get_ref(col, row);
}
3 changes: 0 additions & 3 deletions 0.4/src/PTML_GRAPHICS.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,4 @@ namespace PTML
void SCR_ON();
void SCR_OFF();
void REFRESH();
void BUF_NEW();
void BUF_PUT();
void BUF_GET();
}
7 changes: 7 additions & 0 deletions 0.4/src/PTML_PROGRAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ void PTML::LOAD_SRC()
}
}

void PTML::PROG()
{
REQUIRE_IMM;
ARGC(0);
scr->print_string_crlf(ptm->get_last_program_filename());
}

void PTML::RENUM()
{
REQUIRE_IMM;
Expand Down
1 change: 1 addition & 0 deletions 0.4/src/PTML_PROGRAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ namespace PTML
void LOAD();
void SAVE_SRC();
void LOAD_SRC();
void PROG();
void RENUM();
}
9 changes: 0 additions & 9 deletions 0.4/src/PTML_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,3 @@ t_sptr<t_sprite> PTML::get_sprite(const t_string& name)

return spr;
}

t_sptr<t_tilebuffer> PTML::get_tilebuffer(const t_string& name)
{
auto buf = ptm->get_tilebuf(name);
if (buf == nullptr)
error = err.tilebuf_not_found;

return buf;
}
1 change: 0 additions & 1 deletion 0.4/src/PTML_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ namespace PTML
void branch_if_keypress(t_branch_mode mode, bool positive);
bool try_load_program(const t_string& filename);
t_sptr<t_sprite> get_sprite(const t_string& name);
t_sptr<t_tilebuffer> get_tilebuffer(const t_string& name);
}
5 changes: 5 additions & 0 deletions 0.4/src/t_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ void t_filesystem::rename_file(const t_string& old_name, const t_string& new_nam
fs::rename(PATH(old_name), PATH(new_name));
}

void t_filesystem::delete_file(const t_string& name)
{
fs::remove(PATH(name));
}

void t_filesystem::save_program_plaintext(t_program* prg, const t_string& filename)
{
write_all_text(prg->all_lines_to_single_string(), filename);
Expand Down
1 change: 1 addition & 0 deletions 0.4/src/t_filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class t_filesystem
static void write_all_text(const t_string& text, const t_string& filename);
static void write_all_lines(const t_list<t_string>& lines, const t_string& filename);
static void rename_file(const t_string& old_name, const t_string& new_name);
static void delete_file(const t_string& name);
static void save_program_plaintext(t_program* prg, const t_string& filename);
static void load_program_plaintext(t_interpreter* intp, t_program* prg, const t_string& filename);
static void save_program_binary(t_program* prg, const t_string& filename);
Expand Down
10 changes: 5 additions & 5 deletions 0.4/src/t_main_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ void t_main_editor::reset()
{
function_keys[SDLK_F1] = "";
function_keys[SDLK_F2] = "color ";
function_keys[SDLK_F3] = "var ";
function_keys[SDLK_F3] = "files ";
function_keys[SDLK_F4] = "list ";
function_keys[SDLK_F5] = "run\n";
function_keys[SDLK_F6] = "save ";
function_keys[SDLK_F7] = "load ";
function_keys[SDLK_F8] = "fn.set ";
function_keys[SDLK_F8] = "";
function_keys[SDLK_F9] = "";
function_keys[SDLK_F10] = "";

function_keys_shifted[SDLK_F1] = "";
function_keys_shifted[SDLK_F2] = t_string::fmt("color %i,%i,%i\n", scr->default_fg, scr->default_bg, scr->default_bdr);
function_keys_shifted[SDLK_F3] = "vars\n";
function_keys_shifted[SDLK_F3] = "";
function_keys_shifted[SDLK_F4] = "list\n";
function_keys_shifted[SDLK_F5] = "files\n";
function_keys_shifted[SDLK_F5] = "";
function_keys_shifted[SDLK_F6] = "";
function_keys_shifted[SDLK_F7] = "";
function_keys_shifted[SDLK_F8] = "fn.list\n";
function_keys_shifted[SDLK_F8] = "";
function_keys_shifted[SDLK_F9] = "";
function_keys_shifted[SDLK_F10] = "";
}
Expand Down

0 comments on commit 02d3b15

Please sign in to comment.