Japanese
SGL User's ManualPROGRAMMER'S TUTORIAL
BackForward

8-12. Character numerical display

The SGL library functions explained here are mainly used for program debugging. The function displays the specified string, number, or matrix on the monitor using a scroll surface. ASCII cell data is used for the scroll data, and a rotating scroll screen is used for the scroll surface, and each is set to be available by default (at the system initialization stage).

Figure 8-30 Character numerical display image

Character/numeric display functions can be broadly classified into the following four types.

Calculate display position: Create a display position parameter for use in the function.
Display string: Displays the specified string on the screen.
Display numerical value: Displays the specified numerical value on the screen.
Display Matrix: Displays the specified matrix on the screen.

Below, we will explain each of these four function groups.

1) Calculation of display position
Set the display position of characters and numbers in each cell and convert it into a format that can be used with the following functions.

[void *slLocate ( Uint16 cell_x , Uint16 cell_y ) ;]
Create a display position parameter variable (void * type) that can be used with character/numeric display functions. Assign the XY coordinate values that indicate the display position on the monitor screen to the parameters in cell units (8 dots are counted as 1 cell).

2) Displaying character strings
Displays a string consisting of half-width alphanumeric characters on the screen.

[void slPrint ( char *disp_character , void *disp_pos ) ;]
Displays the specified string on the screen. Assign the string to be displayed (char type variable enclosed in “”) and display position (converted to void * type using “slLocate”) to the parameters. However, the string is limited to half-width alphanumeric characters.

3) Display of numerical values
Display numbers on the screen.

[void slPrintFX ( FIXED disp_num , void *disp_pos ) ;]
Displays the specified FIXED type value on the screen.
Assign the numerical value to be displayed (FIXED type variable) and display position (converted to void * type using “slLocate”) to the parameters.

[void slPrintHex ( Uint32 disp_num , void *disp_pos ) ;]
Displays the specified HEX type value on the screen. Assign the numerical value to be displayed (HEX type variable) and display position (converted to void * type with "slLocate") to the parameters.
The function “slPrintHex” does not display 0 in the upper bits when displaying numerical values (a space is inserted instead).

[void slDispHex ( Uint32 disp_num , void *disp_pos ) ;]
Displays the specified HEX type value on the screen. Assign the numerical value to be displayed (HEX type variable) and display position (converted to void * type with "slLocate") to the parameters.
In the case of the function "slDispHex", unlike "slPrintHex", the upper bit 0 is also displayed when displaying numerical values.

The functions "slPrintHex" and "slDispHex" are both used to display HEX-type numbers on the screen, but they differ in whether or not they display 0 in the upper bits. However, numbers are always displayed right justified.

Table 8-26 Difference between “slPrintHex” and “slDispHex”
Substitution value Output value
slPrintHex 00001111 1111
slDispHex 00001111 00001111
Note) The output value is the number actually drawn on the screen.

4) Matrix display
Display the matrix on the screen.

[void slPrintMatrix ( MATRIX disp_matrix , void * dsp_pos) ;]
Displays the specified matrix on the screen. Assign the matrix variable to be displayed and the display position (converted to void * type using slLocate) to the parameters.

The following sample program (Listing 8-10) actually uses the character and numerical display functions to display character strings and numerical values on the screen using a scroll screen.

Listing 8-10 sample_8_12: Character numerical display

/*------------------------------------------------ ----------------------*/
/* Text & Value Display */
/*------------------------------------------------ ----------------------*/
#include "sgl.h"

extern PDATA PD_PLANE1 , PD_PLANE2 , PD_PLANE3;

static void set_poly(ANGLE ang[XYZ] , FIXED pos[XYZ])
{
	slTranslate(pos[X] , pos[Y] , pos[Z]);
	slRotX(ang[X]);
	slRotY(ang[Y]);
	slRotZ(ang[Z]);
}

void ss_main(void)
{
	static ANGLE ang1[XYZ], ang2[XYZ], ang3[XYZ];
	static FIXED pos1[XYZ], pos2[XYZ], pos3[XYZ];
	static MATRIX mtptr;
	static ANGLE adang = DEGtoANG(0.5);
	static ANGLE tmp = DEGtoANG(0.0);

	slInitSystem(TV_320x224,NULL,1);

	slPrint("Sample program 8.12" , slLocate(6,2));

	ang1[X] = ang1[Y] = ang1[Z] = DEGtoANG(0.0);
	ang2[X] = ang2[Y] = ang2[Z] = DEGtoANG(0.0);
	ang3[X] = ang3[Y] = ang3[Z] = DEGtoANG(0.0);
	pos1[X] = toFIXED( 0.0);
	pos1[Y] = toFIXED( 40.0);
	pos1[Z] = toFIXED(170.0);
	pos2[X] = toFIXED( 0.0);
	pos2[Y] = toFIXED(-40.0);
	pos2[Z] = toFIXED( 0.0);
	pos3[X] = toFIXED( 0.0);
	pos3[Y] = toFIXED(-40.0);
	pos3[Z] = toFIXED( 0.0);

	slPrint("POLYGON ANGLE [Hex] =", slLocate(1,4));
	slPrint("POLYGON ANGLE [Dec] =", slLocate(1,6));
	slPrint("POLYGON ANGLE [Hex&0] =", slLocate(1,8));
	slPrint("POLYGON ANGLE [Dec&0] =", slLocate(1,10));
	slPrint("POLYGON ANGLE [FIX] =", slLocate(1,12));
	slPrint("DISPLAY Matrix :", slLocate(1,18));

	while(-1){
		slUnitMatrix(CURRENT);
		ang1[Z] = tmp;
		ang2[Z] = tmp;
		tmp +=adang;
		if(tmp< DEGtoANG(-90.0)){
			adang = DEGtoANG(0.5);
		} else if(tmp> DEGtoANG(90.0)){
			adang = DEGtoANG(-0.5);
		}

		slDispHex(slAng2Hex(tmp) , slLocate(26,4));
		slDispHex(slAng2Dec(tmp) , slLocate(26,6));
		slPrintHex(slAng2Hex(tmp) , slLocate(26,8));
		slPrintHex(slAng2Dec(tmp) , slLocate(26,10));
		slPrintFX(slAng2FX(tmp) , slLocate(26,12));

		slPushMatrix();
		{
			set_poly(ang1, pos1);
			slPutPolygon(&PD_PLANE1);

			slPushMatrix();
			{
				set_poly(ang2, pos2);
				slPutPolygon(&PD_PLANE2);

				slPushMatrix();
				{
					set_poly(ang3, pos3);
					ang3[Y] += DEGtoANG(5.0);
					slPutPolygon(&PD_PLANE3);
					slGetMatrix(mtptr);
					slPrintMatrix(mtptr , slLocate(0,20));
				}
				slPopMatrix();
			}	
			slPopMatrix();
		}
		slPopMatrix();

		slSynch();
	}
}

Flow 8-14 sample_8_12: Character numerical display


BackForward
SGL User's ManualPROGRAMMER'S TUTORIAL
Copyright SEGA ENTERPRISES, LTD., 1997