Japanese
SGL User's ManualPROGRAMMER'S TUTORIAL
BackForward

8-8. Normal scroll screen

On the normal scroll screen “NBG0 to 3”, scrolling can be moved vertically and horizontally and enlarged/reduced (only NBG0 and NBG1). Here, we will explain these two functions along with sample programs.

Moving the normal scroll screen

On the normal scroll screen “NBG0-3”, it is possible to move the scroll vertically and horizontally by changing the scroll display position.
An image of this is shown below.

Figure 8-18 Scroll display position image

Use the library functions “slScrPosNbg0 to 3” to move the scroll display position.
“slScrPosNbg0~3” is also used to set the initial scroll position.

[void slScrPosNbg0~3 ( FIXED posx , FIXED posy ) ;]
Set the display start position of the normal scroll screen “Nbg0 to 3”.
The scroll display position is determined by where on the scroll map the monitor is placed.The top left of the monitor is the representative point, and a point on the scroll map is specified as a parameter.
Assign the XY coordinate values representing the scroll coordinate system to the parameters.

Additionally, if the scroll display position moves up, down, left, or right, and the scroll exceeds the display area, the scroll will start drawing again from the opposite end.

Figure 8-19 Processing when scrolling exceeds the display area

The following two sample programs (Listings 8-2 and 8-3) use SGL library functions to achieve horizontal and vertical scrolling.

Listing 8-2 sample_8_8_1: Horizontal scroll movement

/*------------------------------------------------ ----------------------*/
/* Graphic Scroll [X axis] */
/*------------------------------------------------ ----------------------*/
#include "sgl.h"
#include "ss_scroll.h"

#define NBG1_CEL_ADR ( VDP2_VRAM_B1 + 0x02000 )
#define NBG1_MAP_ADR ( VDP2_VRAM_B1 + 0x12000 )
#define NBG1_COL_ADR ( VDP2_COLRAM + 0x00200 )
#define BACK_COL_ADR ( VDP2_VRAM_A1 + 0x1fffe )

void ss_main(void)
{
	FIXED yama_posx = SIPOSX , yama_posy = SIPOSY;

	slInitSystem(TV_320x224,NULL,1);
	slTVOff();
	slPrint("Sample program 8.8.1" , slLocate(9,2));

	slColRAMMode(CRM16_1024);
	slBack1ColSet((void *)BACK_COL_ADR , 0);

	slCharNbg1(COL_TYPE_256 , CHAR_SIZE_1x1);
	slPageNbg1((void *)NBG1_CEL_ADR , 0 , PNB_1WORD|CN_12BIT);
	slPlaneNbg1(PL_SIZE_1x1);
	slMapNbg1((void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR);
	Cel2VRAM(yama_cel , (void *)NBG1_CEL_ADR , 31808);
	Map2VRAM(yama_map, (void *)NBG1_MAP_ADR, 32, 16, 1, 256);
	Pal2CRAM(yama_pal , (void *)NBG1_COL_ADR , 256);

	slScrPosNbg1(yama_posx, yama_posy);
	slScrAutoDisp(NBG0ON | NBG1ON);
	slTVOn();

	while(1) {
		slScrPosNbg1(yama_posx, yama_posy);
		yama_posx += POSX_UP;

		slSynch();
	} 
}

Flow 8-3 sample_8_8_1: Horizontal scroll movement

Listing 8-3 sample_8_8_2: Scroll vertically and horizontally

/*------------------------------------------------ ----------------------*/
/* Graphic Scroll [X & Y axis ] */
/*------------------------------------------------ ----------------------*/
#include "sgl.h"
#include "ss_scroll.h"

#define NBG1_CEL_ADR ( VDP2_VRAM_B1 + 0x02000 )
#define NBG1_MAP_ADR ( VDP2_VRAM_B1 + 0x12000 )
#define NBG1_COL_ADR ( VDP2_COLRAM + 0x00200 )
#define BACK_COL_ADR ( VDP2_VRAM_A1 + 0x1fffe )

void ss_main(void)
{
	FIXED yama_posx = SIPOSX , yama_posy = SIPOSY;
	Uint16 scroll_flg = YOKO;
	
	slInitSystem(TV_320x224,NULL,1);
	slTVOff();
	slPrint("Sample program 8.8.2" , slLocate(9,2));

	slColRAMMode(CRM16_1024);
	slBack1ColSet((void *)BACK_COL_ADR , 0);

	slCharNbg1(COL_TYPE_256 , CHAR_SIZE_1x1);
	slPageNbg1((void *)NBG1_CEL_ADR , 0 , PNB_1WORD|CN_12BIT);
	slPlaneNbg1(PL_SIZE_1x1);
	slMapNbg1((void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR);
	Cel2VRAM(yama_cel , (void *)NBG1_CEL_ADR , 31808);
	Map2VRAM(yama_map, (void *)NBG1_MAP_ADR, 32, 16, 1, 256);
	Pal2CRAM(yama_pal , (void *)NBG1_COL_ADR , 256);

	slScrPosNbg1(yama_posx, yama_posy);
	slScrAutoDisp(NBG0ON | NBG1ON);
	slTVOn();

	while(1){
		if (scroll_flg == YOKO) {
			if(yama_posx> = (SX * 2 + SIPOSX)) {
				scroll_flg = TATE;
				yama_posx = SIPOSX;
			} else yama_posx += POSX_UP;
		} else if (scroll_flg == TATE) {
			if(yama_posy> = (SY * 2 + SIPOSY)) {
				scroll_flg = YOKO;
				yama_posy = SIPOSY;
			} else yama_posy += POSY_UP;
		}
		slScrPosNbg1(yama_posx, yama_posy);

		slSynch();
	} 
}
Flow 8-4 sample_8_8_2: Scroll vertical and horizontal movement

Scaling the normal scroll screen

Scroll can be enlarged or reduced (maximum: 1/4 to 256 times) on “NBG0, NBG1” of the normal scroll screen. An image of this is shown below.

Figure 8-20 Scroll scaling image

When scaling the scroll using the normal scroll screen "NBG0, NBG1", the range that can be reduced will differ depending on the reduction setting in the scroll function settings.

Table 8-20 Changes in scaling range due to scaling settings

Reduce settings
1x 1/2 times 1/4 times
 Enlarge/reduce range
1~256x 1/2 to 256 times 1/4 to 256 times

To scale the normal scroll screen with SGL, use the library functions "slZoomNbg0,1" that correspond to the normal scroll screens "NBG0, NBG1", respectively.

[void slZoomNbg0,1 ( FIXED scale_x , FIXED scale_y );]
Enlarge/reduce the normal scroll screen “NBG0,NBG1”.
Assign the scroll vertical and horizontal magnification as reciprocal numbers to the parameters.
For example, if you want to enlarge it by 2 times, assign 1/2 to the parameter, and if you want to reduce it by 1/2, assign 2 to the parameter. The selectable limit value for the reduction range changes depending on the reduction setting (see the table above).

About scaling function parameter settings

The parameter used to scale the scroll must be assigned the reciprocal of the desired multiple (for example, 1/2 if you want 2.0x).
This is because the value pointed to by the parameter does not directly represent the scale value.
The value assigned as a parameter of the scaling function indicates the amount of movement from scrolling one dot to the next dot to be displayed.
If you specify 2.0 as the amount of movement, the scroll will skip one dot at a time and display the next dot, and as a result, the scroll will be reduced to 1/2 when drawn.
If the amount of movement is 1.0, it will be 1x, if the amount of movement is 2.0, it will be 1/2 times, and if the amount of movement is 1/2, the same dot will be displayed twice, so it will be displayed 2.0 times as a result.

The following sample program (Listing 8-4) is an example of actually scaling a normal scroll screen using SGL library functions.

Listing 8-4 sample_8_8_3: Scroll scaling
/*------------------------------------------------ ----------------------*/
/* Graphic Scroll & Expansion & Reduction */
/*------------------------------------------------ ----------------------*/
#include "sgl.h"
#include "ss_scroll.h"

#define NBG1_CEL_ADR VDP2_VRAM_B0
#define NBG1_MAP_ADR ( VDP2_VRAM_B0 + 0x10000 )
#define NBG1_COL_ADR ( VDP2_COLRAM + 0x00200 )
#define BACK_COL_ADR ( VDP2_VRAM_A1 + 0x1fffe )

void ss_main(void)
{
	FIXED yama_posx = toFIXED(0.0), yama_posy = toFIXED(0.0);
	FIXED yama_zoom = toFIXED(1.0);
	FIXED up_down = toFIXED(-0.1);

	slInitSystem(TV_320x224,NULL,1);
	slTVOff();
	slPrint("Sample program 8.8.3" , slLocate(9,2));

	slColRAMMode(CRM16_1024);
	slBack1ColSet((void *)BACK_COL_ADR , 0);

	slCharNbg1(COL_TYPE_256 , CHAR_SIZE_1x1);
	slPageNbg1((void *)NBG1_CEL_ADR , 0 , PNB_1WORD|CN_10BIT);
	slPlaneNbg1(PL_SIZE_1x1);
	slMapNbg1((void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR , (void *)NBG1_MAP_ADR);
	Cel2VRAM(yama_cel , (void *)NBG1_CEL_ADR , 31808);
	Map2VRAM(yama_map, (void *)NBG1_MAP_ADR, 32, 16, 1, 0);
	Pal2CRAM(yama_pal , (void *)NBG1_COL_ADR , 256);

	slZoomModeNbg1(ZOOM_HALF);

	slScrPosNbg1(yama_posx, yama_posy);
	slScrAutoDisp(NBG0ON | NBG1ON);
	slTVOn();

	while(1){
		if(yama_posx> = SX) {
			if(yama_zoom> = toFIXED(1.5))
				up_down = toFIXED(-0.1);
			else if(yama_zoom< = toFIXED(0.7))
				up_down = toFIXED(0.1);
			yama_zoom += up_down;
			yama_posx = toFIXED(0.0);
			slZoomNbg1(yama_zoom, yama_zoom);
		}
		slScrPosNbg1(yama_posx, yama_posy);
		yama_posx += POSX_UP;

		slSynch();
	} 
}

Flow 8-5 sample_8_8_3: Scroll scaling


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