no message
This commit is contained in:
		@@ -68,21 +68,26 @@ static const char DefaultLuaTicPath[] = TIC_LOCAL "default.tic";
 | 
				
			|||||||
static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic";
 | 
					static const char DefaultMoonTicPath[] = TIC_LOCAL "default_moon.tic";
 | 
				
			||||||
static const char DefaultJSTicPath[] = TIC_LOCAL "default_js.tic";
 | 
					static const char DefaultJSTicPath[] = TIC_LOCAL "default_js.tic";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char* getRomName(const char* name)
 | 
					static const char* getName(const char* name, const char* ext)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	static char path[FILENAME_MAX];
 | 
						static char path[FILENAME_MAX];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	strcpy(path, name);
 | 
						strcpy(path, name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	size_t ps = strlen(path);
 | 
						size_t ps = strlen(path);
 | 
				
			||||||
	size_t es = strlen(CartExt);
 | 
						size_t es = strlen(ext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!(ps > es && strstr(path, CartExt) + es == path + ps))
 | 
						if(!(ps > es && strstr(path, ext) + es == path + ps))
 | 
				
			||||||
		strcat(path, CartExt);
 | 
							strcat(path, ext);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return path;
 | 
						return path;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char* getCartName(const char* name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return getName(name, CartExt);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void scrollBuffer(char* buffer)
 | 
					static void scrollBuffer(char* buffer)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	memmove(buffer, buffer + CONSOLE_BUFFER_WIDTH, CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH);
 | 
						memmove(buffer, buffer + CONSOLE_BUFFER_WIDTH, CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH);
 | 
				
			||||||
@@ -343,7 +348,7 @@ static bool onConsoleLoadSectionCommand(Console* console, const char* param)
 | 
				
			|||||||
			if(pos)
 | 
								if(pos)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				pos[sizeof(CartExt) - 1] = 0;
 | 
									pos[sizeof(CartExt) - 1] = 0;
 | 
				
			||||||
				const char* name = getRomName(param);
 | 
									const char* name = getCartName(param);
 | 
				
			||||||
				s32 size = 0;
 | 
									s32 size = 0;
 | 
				
			||||||
				void* data = fsLoadFile(console->fs, name, &size);
 | 
									void* data = fsLoadFile(console->fs, name, &size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -475,7 +480,7 @@ static void onConsoleLoadDemoCommandConfirmed(Console* console, const char* para
 | 
				
			|||||||
	else if(strcmp(param, DefaultJSTicPath) == 0)
 | 
						else if(strcmp(param, DefaultJSTicPath) == 0)
 | 
				
			||||||
		data = getDemoCart(console, tic_script_js, &size);
 | 
							data = getDemoCart(console, tic_script_js, &size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const char* name = getRomName(param);
 | 
						const char* name = getCartName(param);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	strcpy(console->romName, name);
 | 
						strcpy(console->romName, name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -560,7 +565,7 @@ static void onConsoleLoadCommandConfirmed(Console* console, const char* param)
 | 
				
			|||||||
	if(param)
 | 
						if(param)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		s32 size = 0;
 | 
							s32 size = 0;
 | 
				
			||||||
		const char* name = getRomName(param);
 | 
							const char* name = getCartName(param);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(TIC80_PRO)
 | 
					#if defined(TIC80_PRO)
 | 
				
			||||||
		if(fsIsDir(console->fs, name))
 | 
							if(fsIsDir(console->fs, name))
 | 
				
			||||||
@@ -1621,6 +1626,11 @@ static void onConsoleExportCommand(Console* console, const char* param)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if defined(TIC80_PRO)
 | 
					#if defined(TIC80_PRO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char* getProjectName(const char* name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return getName(name, ".ticp");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void buf2str(const void* data, s32 size, char* ptr, bool flip)
 | 
					static void buf2str(const void* data, s32 size, char* ptr, bool flip)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	enum {Len = 2};
 | 
						enum {Len = 2};
 | 
				
			||||||
@@ -1682,6 +1692,10 @@ static CartSaveResult saveProject(Console* console, const char* name)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	tic_mem* tic = console->tic;
 | 
						tic_mem* tic = console->tic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bool success = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(name && strlen(name))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
		char* stream = (char*)SDL_malloc(sizeof(tic_cartridge) * 3);
 | 
							char* stream = (char*)SDL_malloc(sizeof(tic_cartridge) * 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(stream)
 | 
							if(stream)
 | 
				
			||||||
@@ -1698,12 +1712,65 @@ static CartSaveResult saveProject(Console* console, const char* name)
 | 
				
			|||||||
			ptr = printSection(ptr, "PATTERNS", MUSIC_PATTERNS, (const u8*)&tic->cart.sound.music.patterns.data, sizeof(tic_track_pattern));
 | 
								ptr = printSection(ptr, "PATTERNS", MUSIC_PATTERNS, (const u8*)&tic->cart.sound.music.patterns.data, sizeof(tic_track_pattern));
 | 
				
			||||||
			ptr = printSection(ptr, "TRACKS", 	MUSIC_TRACKS, (const u8*)&tic->cart.sound.music.tracks.data, sizeof(tic_track));
 | 
								ptr = printSection(ptr, "TRACKS", 	MUSIC_TRACKS, (const u8*)&tic->cart.sound.music.tracks.data, sizeof(tic_track));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fsWriteFile(name, stream, strlen(stream));
 | 
								name = getProjectName(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								s32 size = strlen(stream);
 | 
				
			||||||
 | 
								if(size && fsSaveFile(console->fs, name, stream, size, true))
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									strcpy(console->romName, name);
 | 
				
			||||||
 | 
									success = true;
 | 
				
			||||||
 | 
									studioRomSaved();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			SDL_free(stream);
 | 
								SDL_free(stream);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if (strlen(console->romName))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							return saveProject(console, console->romName);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else return CART_SAVE_MISSING_NAME;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return CART_SAVE_ERROR;
 | 
						return success ? CART_SAVE_OK : CART_SAVE_ERROR;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void onConsoleSaveProjectCommandConfirmed(Console* console, const char* param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						CartSaveResult rom = saveProject(console, param);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if(rom == CART_SAVE_OK)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							printBack(console, "\nproject ");
 | 
				
			||||||
 | 
							printFront(console, console->romName);
 | 
				
			||||||
 | 
							printBack(console, " saved!\n");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else if(rom == CART_SAVE_MISSING_NAME)
 | 
				
			||||||
 | 
							printBack(console, "\nproject name is missing\n");
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printBack(console, "\nproject saving error");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						commandDone(console);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void onConsoleSaveProjectCommand(Console* console, const char* param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if(param && strlen(param) && fsExistsFile(console->fs, getProjectName(param)))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							static const char* Rows[] =
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"THE PROJECT",
 | 
				
			||||||
 | 
								"ALREADY EXISTS",
 | 
				
			||||||
 | 
								"",
 | 
				
			||||||
 | 
								"DO YOU WANT TO",
 | 
				
			||||||
 | 
								"OVERWRITE IT?",
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							confirmCommand(console, Rows, COUNT_OF(Rows), param, onConsoleSaveProjectCommandConfirmed);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							onConsoleSaveProjectCommandConfirmed(console, param);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@@ -1731,7 +1798,7 @@ static CartSaveResult saveCartName(Console* console, const char* name)
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				s32 size = tic->api.save(&tic->cart, buffer);
 | 
									s32 size = tic->api.save(&tic->cart, buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				name = getRomName(name);
 | 
									name = getCartName(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if(size && fsSaveFile(console->fs, name, buffer, size, true))
 | 
									if(size && fsSaveFile(console->fs, name, buffer, size, true))
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
@@ -1761,11 +1828,7 @@ static CartSaveResult saveCart(Console* console)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void onConsoleSaveCommandConfirmed(Console* console, const char* param)
 | 
					static void onConsoleSaveCommandConfirmed(Console* console, const char* param)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(TIC80_PRO)
 | 
					 | 
				
			||||||
	CartSaveResult rom = saveProject(console, param);
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
	CartSaveResult rom = saveCartName(console, param);
 | 
						CartSaveResult rom = saveCartName(console, param);
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(rom == CART_SAVE_OK)
 | 
						if(rom == CART_SAVE_OK)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -1783,7 +1846,7 @@ static void onConsoleSaveCommandConfirmed(Console* console, const char* param)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void onConsoleSaveCommand(Console* console, const char* param)
 | 
					static void onConsoleSaveCommand(Console* console, const char* param)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if(param && strlen(param) && fsExistsFile(console->fs, getRomName(param)))
 | 
						if(param && strlen(param) && fsExistsFile(console->fs, getCartName(param)))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		static const char* Rows[] =
 | 
							static const char* Rows[] =
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -2019,6 +2082,9 @@ static const struct
 | 
				
			|||||||
	{"new", 	NULL, "create new cart",			onConsoleNewCommand},
 | 
						{"new", 	NULL, "create new cart",			onConsoleNewCommand},
 | 
				
			||||||
	{"load", 	NULL, "load cart", 					onConsoleLoadCommand},
 | 
						{"load", 	NULL, "load cart", 					onConsoleLoadCommand},
 | 
				
			||||||
	{"save", 	NULL, "save cart",	 				onConsoleSaveCommand},
 | 
						{"save", 	NULL, "save cart",	 				onConsoleSaveCommand},
 | 
				
			||||||
 | 
					#if defined(TIC80_PRO)
 | 
				
			||||||
 | 
						{"savep", 	NULL, "save cart project",	 		onConsoleSaveProjectCommand},
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
	{"run",		NULL, "run loaded cart",			onConsoleRunCommand},
 | 
						{"run",		NULL, "run loaded cart",			onConsoleRunCommand},
 | 
				
			||||||
	{"resume",	NULL, "resume run cart",			onConsoleResumeCommand},
 | 
						{"resume",	NULL, "resume run cart",			onConsoleResumeCommand},
 | 
				
			||||||
	{"dir",		"ls", "show list of files", 		onConsoleDirCommand},
 | 
						{"dir",		"ls", "show list of files", 		onConsoleDirCommand},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user