FAQSBL programming related
■ | Advance
FAQ / SBL programming related

VDP



I want to match polygons and scrolls.

Q)
I would like to use the SBL library to display polygons and a rotating scroll screen in 3D synchronization. Is there a way to convert the viewpoint parameters of the SPR function to SCL parameters?

A)
It is certainly more time-consuming to handle SCL and SPR in the same space with SBL than with SGL.
If you do it in the following way, it will be roughly matched, so please try it.

(1) Setting the viewpoint and center point
The distance between the SPR viewpoint and the center point is 256 dots (in units of 1) by default, but in the case of SCL it is 400 dots.
Align this position using the SCL function (I think it's better than SPR).

As the default value
Viewpoint position (X = screen horizontal size / 2, Y = screen vertical size / 2, Z = 400)
Center point (X = screen horizontal size / 2, Y = screen vertical size / 2, Z = 0)
Is set to.

If this difference in the Z direction is set to 256, it will fit as the center.

(2) About angle and movement
The difference between SPR and SCL is that the direction of rotation and the method of movement are reversed.
Pass the reciprocal of the angle rotated by the SPR to the SCL.
However, fine adjustment may be required here, so please move it on the application side.


I don't understand the setting of the distance between the viewpoint and the reference point and the distance between the viewpoint and the projection surface.

Q)
As a result of trying the method of synchronizing the sprite and the scroll screen, the rotation was synchronized, but I could not understand the setting of the distance between the viewpoint and the reference point and the distance between the viewpoint and the projection plane. If you want to change the distance between the viewpoint and the reference point, do you move the RBG in the Z direction or change the scale?

please tell me in detail. For example, what is the setting value when the distance between the viewpoint and the reference point is 2.0 in the sprite function?

A)
The default value of the number of pixels on the screen for each of 1.0 for X and Y during fluoroscopic conversion to the screen (projection plane) is set to 256.
This default value can be changed with the SPR_3SetPixelCount function.
This value sets the scroll's viewpoint coordinates and the distance to the center point to be 256. I don't know how the value of 2.0 is set, but it seems to be set in proportion to this distance.


If the RBG is tilted too much, it will be clipped.

Q)
I am doing 3D rotation using RBG of the SCL library, but if I tilt the BG too much, Z clipping will occur. Under what conditions is this clipped? Also, is there a way to prevent Z-clip?

A)
It is said that Z clipping will be done, but are you talking about such contents?

When it is tilted backward by rotating the X-axis, it disappears from the screen for a moment when it is perpendicular to the screen, and when it is tilted further, the back side becomes visible. Is that so?

This phenomenon occurs when the viewpoint is parallel to the center point of the surface of revolution. As a countermeasure, we recommend that you always check the angle between the viewpoint and the surface of revolution, and if they are parallel, process them on the software side.


Inverted cells are not displayed correctly when NBG0 plane is used with 32k color and 2WORD.

Q)
When NBG0 plane is used with 32k color and 2WORD, cells that are not inverted are displayed correctly, but cells that are inverted are not displayed correctly.

A)
Is inversion left-right inversion? (There are up-down inversion and left-right inversion.) In the case of left-right inversion, only 16 colors and 256 colors can be used according to the VDP2 specifications.
Please refer to SEGA SATURN Developer's Infomation STN-37 for details.


The translucency that I want to hang only on SCL_SP2 also hangs on SCL_SP6.

Q)
I want to set the following priority and perform color calculation on BG only for sprites of SCL_SP2, but SCL_SP6 also becomes translucent. Specify the ratio of color calculation for only one sprite. Can't you do that?

A)
Have you selected a sprite type that has only 2 priority bits?

This can happen because the 3rd bit of (0) is ignored if types 0, 3, 4, 8 to F are set or nothing is set in the function SCL_SetSpriteMode.


Sprites flicker when Guro shading is applied.

Q)
If Gouraud shading is specified when using SPR_2NormSpr () or SPR_2Polygon (), that part will blink. When I stop it with the emulator, one side of the framebuffer is drawn correctly, but the other side is filled with a single color code that makes it unknown where only the part specified by Goulo is referenced. What are the possible causes?

A)

It is possible that.
Since the VDP1 library has the command table divided into two, it is necessary to call the SPR_2NormSpr function every frame change.
In the case of such a symptom, it is often caused by the method of registering only once and not calling the function because there is no change after that.
If possible, compare the contents of the command table and

  1. Is the address to the gourd that cannot be displayed correctly correct?
  2. Is the table set correctly at the address of the gourd?

Please confirm.

It hangs when repeated definition / deletion is repeated with SPR_2SetChar and SPR_2ClrChar.

Q)
In the SPR2 library of SBL, there was a phenomenon that sprites were repeatedly defined and deleted with SPR_2SetChar and SPR_2ClrChar, causing a hang.

When I put a check routine in SPR_2SetChar and checked it, it seems that a NULL pointer is returned even though there is still memory that can be allocated by allocBlock.
Also, since it is nothing to change the library every time, if you can not secure sprites with SPR_2SetChar from the next version upgrade, please return it so that an error is returned.

A)
Try changing it as follows.

static Vaddr allocBlock (Uint16 size) {
NullBlock * memblk = nullBlockTop;
NullBlock * prev = NULL;
NullBlock * second_best = NULL;
NullBlock * prev_second_best = NULL;
Vaddr p = (Vaddr) NULL;
while (memblk! = NULL) {
  if (memblk-> size == size)
    break;
  if (memblk-> size> size) {
     if ((second_best == NULL)
     || ((second_best! = NULL)
     && (memblk-> size <second_best-> size))) {
       second_best = memblk;
       prev_second_best = prev;
     }
  }
  prev = memblk;
  memblk = memblk-> next;
}
if (memblk == NULL) {
  memblk = second_best;
  prev = prev_second_best;
} 
if (memblk! = NULL) {
  Uint32 blocksize;     
  memblk-> size-= size;
  blocksize = (Uint32) memblk-> size * 32;
  p = (Vaddr) ((Uint32) memblk + blocksize-(Uint32) VRAM);
  if ((memblk-> size == 0) && (prev! = NULL))
    prev-> next = memblk-> next;
  }
  return p;
}


I want to display sprites in palette format.

Q)
How do I set the sprite display palette?

A)
When setting the palette number to Uint16 color, the low-order bits must be offset.
The amount of offset depends on the number of colors in the palette used (sprites to display).

(Please set all offset parts to 0)

(Example) When using the second palette with a 256-color sprite
Set the fourth argument, Uint16 color, given to the SPR_2NormSpr () function to 0x0100.

Uint16 color is equivalent to CMDCOLR (color control word) in the command table in the actual hardware-like operation of VDP1.
CMDCOLR (color control word) is also used to specify the priority with the scroll surface.

For more information,

reference
VDP1 User's Manual " 6.4 CMD COLR (Color Control Word) "
VDP2 User's Manual " 9.1 Sprite Data "
VDP2 User's Manual " 9.2 Priority and Color Arithmetic "
Please refer to.


I want to set a priority for sprites.

Q)
I want to set a priority for sprites.

A)
You can set up to eight sprite priority values.
The setting method is explained below, so please refer to it together with the hardware manual "VDP1 / VDP2 User's Manual".

1. Sprite type setting
void SCL_SetSpriteMode (Uint8 type, Uint8 colMode, Uint8 winMode)

Refer to "Program Library VDP2 Library User's Manual " to set the sprite type.
(SBL defaults to type 0)

"What is a sprite type?"
It is the data format when VDP2 receives the data in the frame buffer drawn by VDP1 and consists of 16 BIT. (8 BIT at high resolution) Depending on the type of sprite type

  • Number of colors that can be used
  • Number that can be set as priority
  • Shadow function selection bit
  • Numbers that can be used to specify the percentage of color operations

Etc. will change.
Select the sprite type according to the function you want to use.
(Note: The sprite type setting is valid only for color bank format (= palette format) sprite data. For RGB format sprite data, all the above function bits are considered to be 0. Please be careful.)

Details → VDP2 Manual Chapter 9 “ Sprite Data ” As an example, in the case of sprite type 5, as you can see from Figure 9.1 of the VDP2 Manual, there are 3 priority bits (PR0 to PR2 in the figure), so there are 8 priorities. It is possible to specify a register'.

* Please note that you do not directly specify the priority value.

2. How to set the sprite priority number register
Use the following function to set.

void SCL_SetPriority (Uint32 surface, Uint8 priority)
Function: Set the priority number of each screen.
surface: SCL_SP0, ... SCL_SP7, SCL_NBG0, SCL_NBG1, SCL_NBG2, SCL_NBG3, SCL_RBG0, SCL_RBG1, SCL_EXBG
priority: Specify a value from 0 to 7 (the face with 0 is not displayed).

"What is a sprite priority number register?"
A register that determines the priority of sprites.
There are a total of 8 registers from 0 to 7. (Corresponding to SCL_SP0, ..., SCL_SP7) It is referenced by the priority bit on the VDP1 frame buffer.
The actual priority number is set in this register.

3. How to set the priority bit
To set the priority bit when drawing a sprite, set it in the word data of the color code.

For polygons:
Uint16 color in the texture table SprTexture structure
→ Refer to Program Library User's Guide 2 VDP2 Library

For sprites:
3rd argument of SPR_2SetChar function Uint16 color
Or
Uint16 color in each sprite drawing function

Processing is performed by setting the priority bit to.
The bit position depends on the sprite type used.
See Figure 9.1 in the VDP2 manual to see which bits are priority bits.

Example: If you are using sprite type 5
  • Priority register 4
  • Specify the second of the 256 color palette

In this case, the value to be set is as follows.
0100000100000000 = 0x4100
 ||| |||
 ||| +++ ---------- Specify palette 1 +++ -------------- Specify priority register 4

caution:
Sprites are drawn in the order in which they are registered in the VDP1 command table (Z sort order).
(It is processed regardless of the priority bit setting.) Since the sprite has only one frame buffer, the data drawn earlier will be overwritten by the data written later.
If you overwrite a low-priority sprite on top of a high-priority sprite, the context with the BG will look strange.

See Figure 9.1 in the VDP2 manual to see which bits are priority bits.


The SCL_AllocColRam function cannot secure more than 256 colors.

Q)
SCL_AllocColRam (SCL_SPR, 512, OFF) returns 0.
It seems that an error is returned when trying to secure color data of 256 colors or more. What is the meaning?

A)
In this function, the color offset address is set for each screen, and it is not possible to manage the data area exceeding 256 colors well because it was considered mainly with this setting.

At the very beginning, you can get more than 512 colors, but once you register, you cannot get more than 256 colors.

As a workaround, when allocating a data area exceeding 256 colors, call the function as 256 colors at the end of allocating and manage it independently.
Normally, I think that it is a sprite that uses color data of 256 colors or more, so be sure to secure the color of the sprite last.


■ | Advance
FAQSBL programming related
Copyright SEGA ENTERPRISES, LTD ,. 1997