OpenVMS Source-Code Demos

VT340_DEMO

//==============================================================================================================================
// title  : vt340_demo_101.c
// author : Neil Rieck  ( http://neilrieck.net/ )
// created: 2015-04-19
// purpose: to demo old "school i/o" to a vt-terminal
// to-do  : 1) write a routine to capture answer-back responses and palette queries (should be easy with sys$qio)
//          2) finish palette demos
//	    3) write a routine to cycle through xterm colors (would only work with emulators)
// ver who when   what
// --- --- ------ --------------------------------------------------------------------------------------------------------------
// 100 NSR 150419 original effort
//     NSR 150425 experiments with colored text
//     NSR 150426 testing with three emulators (Reflection for OpenVMS, Tera Term, PuTTY)
// 101 NSR 150427 added code to loop through colors using ANSI escapes
//     NSR 150502 added code to test advanced-video options
//		  finally got around to fixing a few bugs (this is still a work in progress)
//==============================================================================================================================
// Notes:
// 1. The "c" version of this software was only tested with terminal emulators, not real hardware
// 2. when testing with "Reflection For UNIX and OpenVMS" version 14.1
//	your TermType must be emulating VT102 or VT500-7
//		Setup-menu/Terminal-item/Terminal-Type-tab/Terminal-Type-radio-button
//	"Use ANSI Color" must be "ON"
//		Setup-menu/Terminal-item/Emulation-tab/Use-Ansi-Color-checkbox
//	you may need to lie about "Terminal ID" since older VMS + UNIX systems do not know about VT500
//		Setup-menu/Terminal-item/Emulation-tab/Terminal-ID-drop-down
// 3. when testing with "Tera Term" version 4.86
//	"Use ANSI Color" must be "ON"
//		Setup-menu/Additional-settings-item/Visual-tab/Enable-ANSI-Color-checkbox
//	"Terminal ID" is set in two places:
//		Setup-menu/Terminal-item/Terminal-ID-dropdown	(select whatever your OS understands; start with VT100)
//		Setup-menu/TCPIP-item/Term-Type-textbox		(enter xterm or ANSI)
// 4. TCP Stacks are supposed to fetch the terminal type from the client then set the terminal driver accordingly. Not all
//    VMS or OpenVMS stacks do this so make sure you execute "set term/inq" in your personal "login.com" script or in the
//    interactive section of the system-wide script "sys$manager:sylogin.com"
// 5. This demo includes experiments with colored text. This has nothing to do with ReGIS or Sixel Graphics
//	https://en.wikipedia.org/wiki/Sixel
//	https://en.wikipedia.org/wiki/ReGIS
//==============================================================================================================================
//
//	optional stuff for OpenVMS
//
#if defined(VMS)								// for VMS and OpenVMS only
#define __NEW_STARLET	1							// enable strict for OpenVMS Alpha 7.0 and later
#include <starlet.h>								// OpenVMS stuff
#include <lib$routines.h>							// defines functions like: lib$wait
#include <libwaitdef.h>								// defines constants like: lib$k_vax_f
#endif
//
//	includes for every implementation
//
#include <stdio.h>								//
#include "dec_device_controls.c"						// VT + LA device control codes
//
//	forward declarations
//
void nsr_delay(float);								//
void vt_positioning_tests();							//
void vt_adv_vid_tests();							//
void vt_color_tests();								//
//
//	macros (executable image will be slightly larger while faster)
//
#define	cursor_goto(y,x)			\
	printf("%s%d;%dH",CSI,y,x);
//
#define reset_video_w_eol			\
	printf("%s\n",VT$Normal);
//
#define reset_video				\
	printf(VT$Normal);
//
//==============================================================================
//
//	main()	"the big kahuna"
//
//==============================================================================
void main() {
	//
	vt_positioning_tests();
	nsr_delay(2.0);
	//
	vt_adv_vid_tests();
	nsr_delay(2.0);
	//
	vt_color_tests();
	nsr_delay(2.0);
	//
	printf("\n-i-exiting program\n");
}

//==============================================================================
//	vt_positioning_tests
//
// notes: if this test fails for any emulator connected to VMS/OpenVMS then
// make sure you have set your terminal type to VT something with either of
// these two DCL commands:
//	$set term/device=vt200
//	$set term/inq		(reads the emulator's "terminal id")
//==============================================================================
void vt_positioning_tests() {
	printf("\nVT Positioning Tests (Assuming you are a VT100 or higher)\n");
	printf("=========================================================\n");
	printf("with OpenVMS terminal driver set properly\n\n");
	nsr_delay(2.0);
	//
	printf("%s%s",VT$Clear,VT$Home);
	printf("just recleared the screen then homed the cursor\n");
	nsr_delay(1.0);
	//
	printf(VT$Clear);
	for (int y=1;y<20;y++) {
	    int x;
	    x = y * 2;
	    cursor_goto(y,x);
	    printf(VT$ClearLine);
	    printf("this is a test at line: %d %d",y,x);
	    nsr_delay(0.333);					// delay for 333 mS
	    //
	    //	Imagine a real-world service using sys$brkthru to place a message on this user's terminal.
	    //  He might be on an FMS form and we do not want to force him to use crtl-r to refresh his screen
	    //
	    if (x==10) {					// imagine this as real world alert
		printf(VT$SaveCursor);				// remember the current position
		printf(VT$Error);				// drop to line #24
		printf("fake alert to line #24");		//
		printf(VT$RestoreCursor);			// restore the cursor
		printf(" (line continues after fake alert)");	// this continues on line 10
	    }							//
	}							//
	printf("\n-i-exiting: vt_positioning_tests\n");
}
//==============================================================================
//	vt_adv_vid_tests
//==============================================================================
void vt_adv_vid_tests() {
	printf("\nVT Advanced Video Tests (Assuming you are a VT102 or higher)\n");
	printf("============================================================\n");
	printf("with OpenVMS terminal driver set properly\n\n");
	nsr_delay(2.0);
	//
	printf("%s%s%s\n",VT$Flash,"this should be flashing",VT$Normal);
	nsr_delay(1.0);
	//
	printf("%s%s%s\n",VT$Reverse,"this should be reverse video",VT$Normal);
	nsr_delay(1.0);
	//
	printf("%s%s%s\n",VT$Under,"this should be underlined",VT$Normal);
	nsr_delay(1.0);
	//
	printf("%s%s%s\n",VT$Bright,"this should be bright",VT$Normal);
	nsr_delay(1.0);
	//
	printf("\n-i-exiting: vt_adv_vid_tests\n");
}

//==============================================================================
//	vt_color_tests
//==============================================================================
void vt_color_tests() {
	//
	printf("\nVT Color Tests (Assuming you are a VT340 or higher)\n");
	printf("====================================================\n");
	printf("with ANSI-Colors enabled\n\n");
	nsr_delay(2.0);
	//
	printf("\nTest #1 (DEC escape codes)\n");			//
	reset_video;							//
	printf(VT$Red);							//
	printf("this is red text");					//
	reset_video_w_eol;						//
	nsr_delay(0.5);							//
	//
	printf(VT$RedOnBlue);						//
	printf("this is red on blue");					//
	reset_video_w_eol;						//
	nsr_delay(0.5);							//
	//
	//	cycle through 8 colors (or color palettes? more investigation required)
	//	using DEC escape codes
	//
	//			    +----- select foreground
	//			    |+---- color
	//	here we want:	CSI 31;46m
	//			       |+- color
	//			       +-- select background
	//
	printf("\nTest #2 (Cycle through DEC escape codes)\n");		//
	for (int i=0;i<=7;i++) {
	    printf("%s%s%d%s%d%s%d%s%d",
		CSI,	"3",			i,
			";4",			7-i,
			"m FG Color: ",		i,
			" on BG Color: ",	7-i);
	    reset_video_w_eol;
	}
	nsr_delay(0.5);							//
	//--------------------------------------------------------------
	//	playing with color palettes
	//--------------------------------------------------------------
#define set_palettes 0
#if set_palettes==1
	printf("hacking with palettes\n");
	printf(VT$SetPal7);						// just hacking
	printf(VT$SetPal8);						//
	printf(VT$SetPal9);						//
#endif
#define read_palettes 0							//
#if read_palettes==1							//
	printf("%s%s",CSI,"21;2;m");					// term will sent back colors (but I
#endif									// haven't yet written code to capture it)
	//--------------------------------------------------------------
	//	test #3		playing with DEC escapes
	//
	// note: all emulators tested appear to work with these escapes
	//--------------------------------------------------------------
	printf("\nTest #3 (DEC escape codes)\n");			//
	printf("%s%s",CSI,"41m");					//
	printf(" DEC :: this is ");					//
	printf("%s%s",CSI,"42m");					//
	printf(" a test ");						//
	reset_video_w_eol;						//
	nsr_delay(2.0);							//
	//--------------------------------------------------------------
	//	test #4		playing with ANSI escapes
	//
	// emulator	observations
	// ----------	---------------
	// reflection	all tests passed
	// Tera Term	no color displayed (was white text on black)
	// PuTTY	couldn't recover from color change (see the patch)
	//--------------------------------------------------------------
	printf("\nTest #4 (ANSI escape codes)\n");			//
	printf("%s%s",CSI,"=4F");					// red		foreground
	printf("%s%s",CSI,"=6G");					// green	background
	printf(" ANSI :: this is ");
	printf("%s%s",CSI,"=1F");					// blue		foreground
	printf("%s%s",CSI,"=5G");					// magenta	background
	printf(" a test ");						//
#define PUTTY 1
#if PUTTY==0
#then									// TeraTerm and Relection (not PuTTY)
	reset_video_w_eol;						//
#else									// TeraTerm, Relection and PuTTY
	printf(VT$Normal);						//
	printf("%s%s",CSI,"=7F");					// white	foreground
	printf("%s%s\n",CSI,"=0G");					// black	background
#endif
	nsr_delay(2.0);							//
	//--------------------------------------------------------------
	//	test #5		cycling trhough ANSI escapes
	//--------------------------------------------------------------
	printf("\nTest #5 (Cycle through ANSI escape codes)\n");	//
	//
	//
	//	cycle through 8 colors (color palettes? more investigation required)
	//	using ANSI escape codes
	//
	//			     +---- color
	//	here we want:	CSI =4F
	//			      +-- select foreground
	//
	for (int i=0;i<=7;i++) {
	    printf("%s%c%d%c",	CSI,	'=',	i,	'F');		// set foreground
	    printf("%s%c%d%c",	CSI,	'=',	7-i,	'G');		// set background
	    printf("%s%d%s%d",
		" FG Color: ",		i,
		" on BG Color: ",	7-i);
	    reset_video_w_eol;
	}
	//
	printf(VT$Normal);						//
	printf("-i-exiting: vt_color_tests\n");				//
}

//======================================================================
//	nsr_delay(float)
//======================================================================
//
#if defined(VMS)							// for VMS and OpenVMS only
//----------------------------------------------------------------------
//	this next bit of voodoo ensures we are using the correct float type on
//	various hardware platforms: VAX, Alpha, Itanium
//
#if __G_FLOAT != 0
#	define  FLOAT_TYPE  LIB$K_VAX_F
#elif __D_FLOAT != 0
#	define  FLOAT_TYPE  LIB$K_VAX_D
#elif __IEEE_FLOAT != 0
#	define  FLOAT_TYPE  LIB$K_IEEE_S
#else
#	error "Try specifying a floating point qualifier on the compile"
#endif
//
//	delay for the desired number of milliseconds
//
void nsr_delay(float fp_delay) {					//
    int rc;								//
    rc = lib$wait(&fp_delay,0,&FLOAT_TYPE);				//
}
#else									// for non-VMS systems
//
void nsr_delay(float fp_delay) {					//
    sleep(1);								//
}									//
#endif
//======================================================================