FAQSGL programming related
BackForward
FAQ / SGL programming related

system



What on earth are you doing in the slInitSystem?

Q)
Please tell me what kind of operation the slInitSystem function is doing.
I would appreciate it if you could tell me the values and modes to be set.

A)
In the slInitSystem function, in addition to the contents specified by the argument, the following settings are made inside the function. If you want to make settings other than this, you need to set them with each setting function.

In addition, slInitSystem secures and initializes the work area used by other SGL functions.
If you use an SGL function, be sure to execute this function first. If you execute other SGL functions before executing slInitSystem, the operation cannot be guaranteed.

(0) Initialization of system variables
If a value other than 0 is entered, the following data will be entered

(1) Window size and vanishing point position for sprites and polygons
 Left
: 0
 Top
: 0
 Right
: ScreenXSize --1
 Bottom
: ScreenYSize --1
 Zlimit
: 0x7fff
 CenterX
: ScreenXSize / 2
 CenterY
: ScreenYSize / 2
 PersAngle
: 90 °
 ZdspLevel
: 1
* The contents of ScreenXSize and ScreenYSize change depending on the setting of the first argument.

(2) Scroll-related initial settings
Scroll surface displayed: NBG0, NBG1, RBG0
Scroll priority: NBG0 NBG1 NBG2 NBG3 RBG0
: 7 3 2 1 4
Sprite 0: SPR0
(Polygon) Priority: 6
Other sprites: SPR1 to SPR7
              : Five
Number of scroll colors: 256 color mode on each side Color RAM mode: 1 (2048 out of 32768 colors)
VRAM division: Divided for both banks A and B Character data: From NBG0, NBG1 25E60000: From RBG0 25E00000 Character size: 8x8 dot pattern name data on each side: From NBG0 25E76000: From NBG1 257E7800: From RBG0 PA 25E40000: From RBG0 PB 25E50000 Pattern name size: NBG0 1 word: 10-bit with inversion for each cell Pattern name: NBG1 and RBG0 1 word: No inversion, 12-bit pattern name Plain size: 64x64 on each side Screen color: 25E3FFFE black (R = 0, G = 0, B = 0)
Rotation parameter: From 25E3FF00 Sprite data: Mixing palette and RGB format Special effects function: Mosaic, color offset, etc. Not used Sprite type: scnSPR3
ASCII character set: 0x25e00000 (For RBG), 0x25e60000 (For NBG)

I want to change the number of processing frames dynamically.

Q)
How to dynamically change the number of processing frames with slDynamicFrame?

A)
The system variable SynchConst, which is set when using slDynamicFrame with SGL, always contains a positive integer.
The processing of the part corresponding to the minus in the third argument of slInitSystem is

slDynamicFrame

Is in charge.

Also, if the number of base intervals does not change, such as 1 to -1, you do not need to reconfigure SynchConst.

(Example 1)
Fixed interval → indefinite interval

/ * Switch from 1 int fixed to 2 int base indefinite mode * /
extern Uint8 SynchConst; / * unsigned int * / instead of signed int
                         / * ^^^^^^ ^^^^^^^^ * /
slInitSystem (TV_320x224, NULL, 1);
        ::
        ::
/ * Set indefinite interval mode-2 * /
slDynamicFrame (ON);
SynchConst = 2; / * Not -2 * /
slSynch ();

(Example 2)
Indefinite interval → fixed interval

/ * Change from 1 int indefinite interval to 1 int fixed interval * /
slInitSystem (TV_320x224, NULL, -1);
         ::
         ::
/ * Set fixed interval mode 1 * /
slDynamicFrame (OFF);
/ * No need to change SynchConst * /
slSynch ();


What is the difference between slInitSynch and slSynch?

Q)
Regarding slInitSynch () and slSynch (), what exactly is the difference between slInitSynch () and slSynch ()?

A)
slInitSynch always waits for the next drawing. In other words, if there is a processing omission, it waits until the processing is completed, but in slSynch, if there is a processing omission, it immediately ends and proceeds to the next processing. In other words, slSynch may cause dropped frames.


How can I use slSynch to detect processing failures?

Q)
When using slSynch (), frames will be dropped if the previous processing exceeds the drawing processing unit.
How should this check be done?

A)
First, set the third argument of slInitSystem to a negative number to enter dynamic frame mode.

Then look at the system variable SynchCount just before running slSynch. If SynchCount is negative, you know that the process is down.


When the program is placed in L-RAM, it runs out of control when the third argument of slInitSystem is negative.

Q)
I want to switch frames after waiting for the completion of writing to the frame buffer of VDP1, but the function

slInitSystem (Uint16 TVMode, TEXTURE * txtbl, Sint8 Count)

When I changed the parameter "Count" (frame switching count) of to a negative number, it went out of control.
This phenomenon occurs when the executable file is placed in LowRam.

A)
Do not put the executable program in LowRAM.

SGL does not consider putting the program in LowRAM because the transfer speed of LowRAM is slow and the SCU is out of the control of LowRAM.


About processing at the time of Z sort.

Q)
In the function group related to polygon sprite registration in SGL, what kind of process is the Z sort processing of SGL performed?

A)
In SGL, when displaying polygons and sprites, it usually has a FIXED type Z value as an argument, but of these, only the upper 16 bits, that is, the integer part, is used for actual sorting.

When entering a sprite or polygon into the buffer, the clipping due to the Z limit and the near limit is compared with the upper 16 bits of the Z value, and then the upper 8 bits of the integer part are used for primary sorting.
Furthermore, for polygons and sprites of the same order, secondary sorting is performed using the lower 8 bits of the integer part.
Therefore, it is not used for the fractional part.


I would like to switch the frame buffer freely.

Q)
Please let me know if there is a way to switch the frame buffer on your own with SGL.

A)
Unfortunately, SGL does not allow the user to switch framebuffers at will.


I don't know how to specify the palette.

Q)
I don't know how to specify the scroll function slPageNbg0 ~ 3 (Rbg0) and the palette to be used in the macro SPR_ATTRIBUTE.

A)
slPageNbg? The offset value given to is the offset address from the color RAM (0x25f00000).

Also, since the argument of SPR_ATTRIBUTE is information about the number of colors from the beginning of the color RAM, the boundary per color differs between 24-bit color and 15-bit color. Therefore, it is different from the address offset.
For example, in 24-bit mode, the 256th color is offset, which is 400h, but in 15-bit mode, it is 200h. In slPageNbg, the values given are 0x400 and 0x200, respectively, but in the case of SPR_ATTRIBUTE, both are 256 (0x100).


I want to do something like waiting for drawing.

Q)
In SGL, I think that sprites that are not drawn in time usually interrupt the process in the middle of drawing, but is it possible to control such as switching frames after waiting for the end of drawing?

A)
There is a function called slInitSystem in the SGL function, and the number of frames is specified in the third argument of this function. This usually puts a positive number, but if you put a negative number "-n" in it, it usually works on a frame base of "n" and only waits for drawing when it can't keep up. I can do it.


How do you do the processing that waits for the CPU processing?

Q)
In SGL, I want to process while waiting for CPU processing.

A)
Here is an example of the method for processing waiting for CPU processing with SGL.

  1. Set the maximum number of possible processes in the third argument of slInitSystem.
    However, since it supports only indefinite mode, it is necessary to set it with a negative number.

  2. When the CPU processing is finished (immediately before calling slSynch and slInitSynch), set the system variable SynchCount to the number of frames previously set in slInitSystem.
    As a caveat in this case, the following checks are required when changing this value.

    1. Disable interrupts.

    2. Check that it is not during the VBlank period. The check method is to check the V counter register of bit 3 of the screen status of VDP2 (address 25F80004).
      If it is not a VBlank period, perform the above change processing. If it is during the VBlank period, perform the processing of c.) And then the processing of a.) To c.) Again.

    3. Release the interrupt.

In SGL slSynch and slInitSynch, when the system variables SynchConst and SynchCount match, the following frame processing is performed. And SynchCount is the current number of INTs and SynchConst is the number of INTs specified by the user.
In other words, this process tricks the SGL system.


Which is better, DM transfer of texture data or for loop?

Q)
Which is better, SGL to transfer sprites in a for loop or DMA?

A)
Basically, it is better to transfer by DMA because it does not put a load on the main program.
However, CPU DMA has a weight of several clocks at startup, so if you are concerned about processing speed, memory copy by For Loop may be faster depending on the amount of data.


BackForward
FAQSGL programming related
Copyright SEGA ENTERPRISES, LTD ,. 1997