Japanese
SGL User's ManualPROGRAMMER'S TUTORIAL
BackForward

8-5. Storing scroll data in memory

Here, we will explain the types of scroll data and how to store each type of scroll data in memory.

Scroll data type

SGL broadly divides scroll-related data into the following three types, depending on the information they contain.

1) Character pattern data : Information in dot units of character pattern
(In the text, it may be abbreviated as CG.)

2) Pattern name data : Information related to character pattern identification and arrangement
(May be abbreviated as PN in the text)

3) Color palette data : Color data when using color palette

In terms of the scroll screen composition unit explained in “Section 8-2: Scroll composition unit”, this is

1) is information in dot units up to the character pattern
2) is the placement information of the character pattern after the page

That's what it means. The data in 1) and 2) is stored in a memory area called VRAM and accessed to be used for actual drawing.

3) is the color information in palette format used for scrolling.
Palette format is a color setting method that uses 16 colors, 256 colors, or 2048 colors (1024 colors depending on settings) as one palette for each character pattern.
The color palette is

RGB data of individual colors: Color identification number within the palette stored in color RAM: Identification number for each palette used in character pattern: Used in pattern name data

It consists of three data.
Color palette data is stored in a memory area called color RAM, and is used for actual drawing when accessed.

Storing scroll data in VRAM

VRAM is a general term for data area for storing graphic data such as scrolling. In SGL, VRAM is divided into four parts. The areas are called VRAM-A0, A1, B0, and B1, and various data related to scrolling are stored in these four data areas called banks. The Sega Saturn's VRAM capacity is 4Mbits, so the VRAM capacity of each bank is 1Mbits.
Actual drawing is performed by accessing these four data areas and reading the scroll data. The figure below shows the VRAM address.

Figure 8-5 VRAM address map

In SGL, scroll information is stored in these four VRAM banks and called up as needed to actually draw the scroll surface on the screen.
In the sample program, this data storage work is performed using two functions (registered in the program): "Cel2VRAM" and "Map2VRAM".
This function is not supported as a library function, so please use it as a reference only.

[void Cel2VRAM ( cel_adr , VRAM_adr , chara_size ) ;]
Store character pattern data in VRAM.
Assign the start address of the memory where the character pattern is currently stored, the start address of the VRAM where the character pattern data is stored, and the number of characters and patterns to the parameters.

[void Map2VRAM (pat_adr, VRAM_adr, mapY, mapX, pal_off, map_off);]
Store pattern name data in VRAM.
The parameters include the start address of the memory where the pattern name table is currently stored, the start address of the VRAM that stores the pattern name data, the vertical and horizontal sizes of the map in cells, the offset value of the color palette to be used next, and finally. Substitute the offset value of the map data.

Notes on storing data in VRAM 1

There are some limitations to storing scroll data in the VRAM bank mentioned above due to hardware performance issues.
Although we will not discuss the details of the restrictions here, please ensure that at least the following two conditions are met.

1) VRAM bank usage priority according to scroll type
Do not store scroll data for the normal scroll screen and rotary scroll screen in the same VRAM bank.

2) VRAM bank storage limit for pattern name data
All pattern name data can only be stored in a maximum of two banks, one of VRAM_A0, B0 and one of VRAM_A1, B1.

Figure 8-6 VRAM bank storage limit for pattern name data

If these two conditions are not followed, the scroll rendering will be affected by the following:

If 1) is not followed
Due to the priority order of VRAM bank usage, normal scroll screen data is ignored and only rotary scroll screen data is valid.

If 2) is not followed
If pattern name data is stored in a VRAM bank with the same number at the end of the VRAM bank name, scrolling will not be drawn correctly or will not be drawn at all.

Regarding restrictions on PN storage

For details on PN storage limits, refer to “HARDWARE MANUAL vol.2: VDP2 User's Manual”.

Notes on storing data in VRAM 2

The notes regarding data storage that will be explained below are related to the initial settings of SGL.

In the default state, SGL already stores scroll data (including color data) for character and numerical display called ASCII cells in memory.
Therefore, if you overwrite the ASCII scroll data stored in the default state with other scroll data, the character/numeric display functions supported by SGL will not be able to be used correctly.

The ASCII scroll consists of 128 cells and 256 colors, and uses the normal scroll screen "NBG0".

ASCII scroll data is stored in the RAM area as shown below.

Figure 8-7 ASCII scroll data storage area

Character data: 2000H from address 0x25e60000
Map data: 1000H from address 0x25e76000
Palette data: 20H from address 0x25f00000

When using ASCII scrolling, be sure to specify an offset when storing scroll data, and avoid writing scroll data to the above area.

Color RAM

Color RAM is used for all color control of palette-style sprites and scrolling screens. Color data consists of 5 bits or 8 bits for each RGB color, depending on the color RAM mode. There are three color RAM modes as shown in the table below.

Table 8-4 Color RAM mode

color mode color bit Data size Number of colors
mode 0 RGB each 5 bits, total 15 bits 1 word 1024 out of 32768 colors
mode 1 RGB each 5 bits, total 15 bits 1 word 1024 out of 32768 colors
mode 2 RGB 8 bits each, total 24 bits 2 words 1024 out of 16.77 million colors

note)
In mode 0, the color RAM is divided into two parts, and by writing data to the first half, the same data is automatically written to the second half.

Color RAM mode is represented in the actual color RAM as the following image.

Figure 8-8 Color RAM address map

Color RAM mode is selected and used in the following cases.

Color RAM mode 0: Used when using the extended color calculation function.
Color RAM mode 1: Use when you want to use 2048 colors out of 32768 colors.
Color RAM mode 2: Use when you want to use 2048 colors out of 16.77 million colors.

As you can see from Figure 8-8, color RAM mode 0 divides the color RAM area into two banks and stores the same color data in each bank. Therefore, the number of colors that can be used is halved compared to color RAM mode 1, but expanded color calculation functions can be used instead.
However, this SGL library function does not support extended color calculation mode.

Note
If you want to use the extended color calculation mode, please refer to “HARDWARE MANUAL vol.2”.

The difference between mode 1 and mode 2 is the number of colors that can be used.
Mode 1 can use 2048 colors out of 32768 colors, and mode 2 can use 1024 colors out of 16.77 million colors.
For this reason, mode 1 can use a larger number of colors than mode 2, but because the data length that makes up the color data is shorter than mode 2, the range of colors that can be selected is more rough than mode 2. Become.
Conversely, in mode 2, the maximum number of colors that can be used at once is half that of mode 1, but because the data length that makes up the color data is longer than in mode 1, it is possible to use deeper gradations.

Use the library function “slColRAMMode” to set the color RAM mode.

[void slColRAMMode ( Uint16 mode );]
Determine the color RAM mode.
Assign the #define value in the table below that corresponds to the color RAM mode to the parameter.

Table 8-5 “slColRAMMode” parameter substitution value
Color RAM mode
mode 0 mode 1 mode 2
Assignment value CRM16_1024 CRM16_2048 CRM_1024

note)
2048 colors available only when color RAM mode 1 is selected

Color RAM initial settings

Color RAM is set to mode 1 when the system is initialized.

Data storage in color RAM

SGL stores color information (color palette information) in color RAM and calls it as needed to draw scroll screens.

[void Pal2CRAM ( col_adr , CRAM_adr , col_no. ) ;]
Stores color information (color palette information) in color RAM.
Assign the start address in memory where the color palette to be registered is currently stored, the start address of the color RAM where it is stored, and the color palette size to the parameters.


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