//	M072 : Transmission by YMODEM
option unsigned;

define	port, bno = 0;
define	fEnd = _FALSE;

//------------------------------------------------------------------------------//
//	Transmission by YMODEM														//
//																				//
//	Return	: None																//
//------------------------------------------------------------------------------//
function main()
{
	define	i, x, y;
	define	$menu[] = {"Send file by MODEM", "Receive file by YMODEM", "End"};

	_Cls();
	_Print("Please set COM port by dialog.\n");

	_EnableStdRClk(0);				//	Prohibition of popup menu by standard right click
									//	With this setting "_OnRClick ()" is executed when right clicking

	//	Set the parameters in the dialog and generate the COM port
	if (port = _ComCreateByDialog()) {
		_ComOpen(port);
		while (!fEnd) {
			_Print("\nRight click and select a process from the popup menu.\n");
			_Stop();
		}
		_ComClose(port);
		_ComDelete(port);
	}
}
//------------------------------------------------------------------------------//
//	Right click processing														//
//																				//
//	Argument:	x - x position			shift - Shift key flag					//
//				y - y position			ctrl  - Ctrl key flag					//
//																				//
//	Return	: None																//
//------------------------------------------------------------------------------//
function _OnRClick(x, y, shift, ctrl)
{
	define	$menu[] = {	"Send folder with YMODEM",
						"File transmission with YMODEM",
						"Receive files with YMODEM",
						"End"};
	define	id, bytes;
	define	$file, $folder, $wild;

	id = _PopupMenu($menu[], x, y);								//	Pop-up menu

	if		(id == 0) {											//	- Send folder?
		$folder = $_GetFolder("Please select a folder to send");
		if ($folder != "") {
			$wild = $_Input('Please specify a wild card (ex. "*. Txt", "*. *" ...)');
			if ($wild != "") {
				$folder = $_PathCat($folder, $wild);
				_ComSendYModem(port, $folder, _TRUE, _TRUE);	//		Send folders by YMODEM
			}
		}
	}
	else if (id == 1) {											//	- Send File?
		$file = $_GetOpenFile("Please select the file to send", "All(*.*)/*.*/Text(*.txt)/*.txt", "txt");
		if ($file != "") {
			_ComSendYModem(port, $file);						//		File transmission by YMODEM
		}
	}
	else if (id == 2) {											//	- Receive file?
		$file = $_GetFolder("Please select a folder to store received data", "All(*.*)/*.*/Text(*.txt)/*.txt", "txt");
		if ($file != "") {
			_ComRecvYModem(port, $file, _TRUE);					//		Receive file by YMODEM
		}
	}
	else if (id == 3) {											//	- End?
		fEnd = _TRUE;											//		End of program
	}
	_Restart();
}
