SGL User's ManualPROGRAMMER'S STRUCT
BackForward

8-8. Normal scroll screen

The normal scroll screen "NBG0 to 3" can be scrolled vertically and horizontally (however, only NBG0 and NBG1). Here, we will explain these two functions together with a sample program.

Moving the normal scroll screen

The normal scroll screen "NBG0 to 3" can be moved vertically and horizontally by changing the scroll display position.
The figure below is an image of this.

<Fig. 8-18 Scroll display position image>

Use the library function “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 the position on the scroll map where the monitor is placed, with the upper left of the monitor as the representative point and one point on the scroll map as a parameter.
Substitute the XY coordinate values that represent the scroll coordinate system for the parameters.

Also, 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.

<Fig. 8-19 Processing when scrolling exceeds the display area>

The following two sample programs (Listing 8-2 and 8-3) use SGL library functions to realize horizontal scrolling and vertical / horizontal scrolling, respectively.

Listing 8-2 sample_8_8_1: Horizontal scrolling

/ * ------------------------------------------------ ---------------------- * /
/ * Graphic Scroll [X axis] * /
/ * ------------------------------------------------ ---------------------- * /
#include "sgl.h"
#include "ss_scrol.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 vertical and horizontal movement

/ * ------------------------------------------------ ---------------------- * /
/ * Graphic Scroll [X & Y axis] * /
/ * ------------------------------------------------ ---------------------- * /
#include "sgl.h"
#include "ss_scrol.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: Vertical and horizontal scroll movement

Enlarging / reducing the normal scroll screen

Of the normal scroll screens, "NBG0, NBG1" can be scrolled up or down (maximum: 1/4 to 256 times). The figure below is an image of this.

Figure 8-20 Scroll scaling image

The range that can be reduced or reduced by using the normal scroll screen "NBG0, NBG1" differs depending on the reduction setting of the scroll function setting.

Table 8-20 Changes in enlargement / reduction range due to reduction settings

Reduction setting
1x 1/2 times 1/4 times
 Expansion and contraction
1 to 256 times 1/2 to 256 times 1/4 to 256 times

To zoom in / out the normal scroll screen with SGL, use the library function "slZoomNbg0,1" corresponding to the normal scroll screen "NBG0, NBG1".

[Void slZoomNbg0,1 (FIXED scale_x, FIXED scale_y);]
Enlarges / reduces the normal scroll screen "NBG0, NBG1".
Substitute the scroll vertical and horizontal magnifications as reciprocals for the parameters.
For example, if you want to enlarge it by 2 times, substitute 1/2 for the parameter, and if you want to reduce it by 1/2, substitute 2. The limit value that can be selected for the reduction range changes depending on the reduction setting (see the table above).

About parameter setting of enlargement / reduction function

You need to substitute the reciprocal of the desired multiple for the parameter used to scale the scroll (eg 1/2 if you want 2.0 times).
This is because the value pointed to by the parameter does not directly represent the scale value.
The value assigned as the parameter of the enlargement / reduction function indicates the amount of movement to the next dot to be displayed after displaying one dot of the scroll.
If 2.0 is specified as the movement amount, the scroll will skip one dot at a time and the next dot will be displayed, and as a result, the scroll will be reduced to 1/2 times and drawn.
If the movement amount is 1.0, it will be displayed once, if the movement amount is 2.0, it will be displayed 1/2 times, and if the movement amount is 1/2, the same dot will be displayed twice, resulting in 2.0 times display.

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

Listing 8-4 sample_8_8_3: Scroll scaling
/ * ------------------------------------------------ ---------------------- * /
/ * Graphic Scroll & Expansion & Reduction * /
/ * ------------------------------------------------ ---------------------- * /
#include "sgl.h"
#include "ss_scrol.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 STRUCT
Copyright SEGA ENTERPRISES, LTD., 1997