Japanese
FAQSBL programming related
■ | Go forward
FAQ/SBL programming related

VDP



I want to match polygons and scrolls.

Q)
I would like to use the SBL library to synchronize and display polygons and rotating scroll screens in 3D, but is there a way to convert the viewpoint parameters of the SPR function to SCL parameters?

A)
It is true that handling SCL and SPR in the same space with SBL takes more effort than with SGL.
If you follow the method below, I think you can roughly match it, so please give it a try.

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

As a 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)
It is set to

I think if you set the difference in the Z direction to 256, it will fit as the center.

(2) About angle and movement
The difference between SPR and SCL is that the rotation direction and movement method are reversed.
Pass the reciprocal of the angle rotated by SPR to SCL.
However, it may be necessary to make minor adjustments here, so please respond by moving etc. on the app side.


I don't really understand how to set the distance between the viewpoint and the reference point, and the distance between the viewpoint and the projection plane.

Q)
As a result of trying to synchronize the sprite and the scroll screen, I was able to synchronize the rotation, but I couldn't understand how to set the distance between the viewpoint and the reference point, and the distance between the viewpoint and the projection plane. When changing 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, in a sprite function, if the distance between the viewpoint and the reference point is 2.0, what is the setting value?

A)
The default value is set to 256 as the number of screen pixels for each 1.0 in X and Y when performing perspective conversion to the screen (projection surface).
This default value can be changed using the SPR_3SetPixelCount function.
Set this value so that the distance between the scroll viewpoint coordinates and the center point is 256. I don't know how the value 2.0 is set, but I think it is set in proportion to this distance.


If you tilt RBG too much, it will be clipped.

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

A)
You mentioned that the image will be Z-clipped, but is this what you are talking about?

If you tilt it backwards by rotating it on the X axis, it will momentarily disappear from the screen until it is perpendicular to the screen, and if you tilt it further, you will be able to see the back side. Is that so?

This phenomenon occurs when the viewpoint becomes parallel to the center point of the rotation plane. As a countermeasure to this problem, we recommend that you constantly check the angle between the viewpoint and the rotation plane, and if they become parallel, use the software to process it.


When using NBG0 side with 32k color and 2WORD, inverted cells are not displayed correctly.

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

A)
Does reversal mean horizontal reversal? (There are vertical reversal and horizontal reversal.) For horizontal reversal, only 16 colors and 256 colors can be used according to the VDP2 specifications.
Please refer to SEGASATURN Developer's Information STN-37 for details.


The translucency that I want to apply only to SCL_SP2 also applies to SCL_SP6.

Q)
I would like to set the priority order as below and perform color calculations on the BG only for the SCL_SP2 sprite, but SCL_SP6 also becomes semi-transparent. Specify the color calculation ratio to only one sprite. Is it not possible?

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

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


Sprites flicker when applying Gouro shading.

Q)
If Gouraud shading is specified when using SPR_2NormSpr() or SPR_2Polygon(), etc., that part will flicker. If you stop the emulator and look at it, you will see that one side of the frame buffer is drawn correctly, but the other side is filled with a single color using a color code that is not known from where the Gouraud specification was referenced. What are the possible causes?

A)

This is possible.
Since the VDP1 library has a command table divided into two parts, it is necessary to call the SPR_2NormSpr function every time there is a frame change.
In the case of such symptoms, the cause is often that the function is registered only once and then the function is not called since there are no changes.
If possible, compare the contents of the command table,

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

Please confirm.

Hangs when repeatedly defining/deleting SPR_2SetChar and SPR_2ClrChar.

Q)
In SBL's SPR2 library, there was a hang-up phenomenon when repeatedly defining and deleting sprites using SPR_2SetChar and SPR_2ClrChar.

When I added a check routine to SPR_2SetChar and looked into it, I found that even though there was still memory that could be allocated using allocBlock, a NULL pointer was being returned.
Also, since there is no need to change the library every time, could you please make it possible to return an error if a sprite cannot be secured with SPR_2SetChar from the next version update?

A)
Try changing it as below.

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, it is necessary to give an offset to the lower bits.
The amount of offset changes depending on the number of colors in the palette used (displayed sprite).

(Please set all offset parts to 0)

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

In addition, Uint16 color corresponds to CMDCOLR (color control word) in the command table in actual hardware VDP1 operation.
CMDCOLR (color control word) is also used to specify the priority of the scroll surface.

For more information,

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


I want to set priority to sprites.

Q)
I want to set priority to sprites.

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

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

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

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

  • Number of available colors
  • Number that can be set as priority
  • Shadow feature selection bit
  • Numbers that can be used to specify percentages for color calculations

etc. will change.
Select the sprite type according to the function you want to use.
(Note: Sprite type settings are only valid for color bank format (=palette format) sprite data.For RGB format sprite data, all of the above function bits are assumed to be 0. please note.)

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

* Please note that the priority value is not directly specified.

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

void SCL_SetPriority(Uint32 surface , Uint8 priority)
Function: Set the priority number for 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 between 0 and 7 (faces with 0 specified will not be displayed).

"What is the sprite priority number register?"
This register determines the priority of sprites.
There are 8 registers in total, numbered 0-7. (Corresponds to SCL_SP0,...,SCL_SP7) Referenced by the priority bit on the VDP1 frame buffer.
Set the actual priority number in this register.

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

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

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

Processing is performed by setting the priority bit.
The bit position changes depending on the sprite type used.
Please refer to Figure 9.1 in the VDP2 manual to determine which bits are the priority bits.

Example: If using sprite type 5
  • priority register 4
  • Specify the second of the 256-color palette

In this case, the values to set are as follows:
0100000100000000 = 0x4100
 ||| |||
 ||| +++----------Specify palette number 1
 +++--------------Specify priority register 4

Note:
Sprites are drawn in the order they are registered in the VDP1 command table (Z sort order).
(It is processed regardless of the priority bit settings.) Since the sprite frame buffer has only one side, data drawn first will be overwritten by data written later.
If you overwrite a sprite with a lower priority on a sprite with a higher priority, the front-back relationship with the BG will look strange.

Please refer to Figure 9.1 in the VDP2 manual to determine which bits are the priority bits.


It is not possible to allocate more than 256 colors using the SCL_AllocColRam function.

Q)
SCL_AllocColRam(SCL_SPR, 512, OFF) returns 0.
It seems that when I try to secure color data for 256 colors or more, an error returns.What does this mean?

A)
In this function, the color offset address is set for each screen, and because this setting is the main focus, it is not possible to secure a data area that exceeds 256 colors and manage it properly.

Initially, you can obtain more than 512 colors, but once you register, you cannot obtain more than 256 colors.

As a workaround, if you want to allocate a data area that exceeds 256 colors, call a function as 256 colors at the end of allocating and manage it independently.
Sprites usually use color data of 256 colors or more, so be sure to reserve the colors for sprites last.


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