PROGRAMMER'S GUIDEVDP1 library
BackForward
VDP1 library

2. VDP1 Extended Processing Guide


2.1 Purpose

2.2 How to manage VRAM area

The VRAM area (512K bytes) is allocated and used as shown below.

[Explanation of each area]

[Allocation size of each area]
Allocate the size of each area as follows. One block is 32 bytes.

 Area name
 Number of blocks
 VRAM area reference switch command
 1
 System command area
 4x2
 User command area
 COMMAND_MAX × 2
 Gouraud shading table area
 (GOUR_TBL_MAX + 3) / 4 × 2
 Color look-up table area
 LOOKUP_TBL_MAX
 Block pool area
 All remaining blocks

COMMANND_MAX: Maximum number of commands
GOUR_TBL_MAX: Maximum number of Gouraud shading tables
LOOKUP_TBL_MAX: Maximum number of lookup tables

These values are defined by the VDP1 extended processing work area definition macro described later.

[Block allocation algorithm in block pool area]

● In the case of acquisition Search for free continuous block areas that satisfy the acquisition request block size, and allocate the smallest area.

● In case of release If the specified block area is released and there are adjacent free blocks, the free blocks are continuous and grouped into large free blocks.

2.3 Sprite command drawing order in framebuffer

You can set the drawing order for each command by specifying the drawing priority number when calling the following sprite command setting routines.

 SPR_2LocalCoord ()
 SPR_2SysClip ()
 SPR_2UserClip ()
 SPR_2line ()
 SPR_2polyLine ()
 SPR_2Polygon ()
 SPR_2NormSpr ()
 SPR_2ScaleSpr ()
 SPR_2DistSpr ()
 SPR_2Cmd ()

The drawing priority number indicates the drawing block number, and block number 0 is drawn first. Also, within the same block, they are drawn in the order in which the commands are registered.

The drawing order setting operation is performed when the SPR_2CloseCommand () and SPR_2FlushDrawPrty () routines are called, and the control word jump specification and link specification word in the command are changed.

The number of blocks for this drawing order management is specified in advance in the 2D work area definition. If you do not want to prioritize the drawing, you can specify it in the 2D work area definition and SPR_2OpenCommand ().

2.4 Program description example

An example of an actual program in C language is shown below.

#include <machine.h>
#define _SPR2_ / * Using sprite display extension library * /
#include "sega_spr.h"
#include "sega_scl.h"
#include "sega_int.h"

#define COMMAND_MAX 512 / * Maximum number of commands * / #define GOUR_TBL_MAX 512 / * Maximum number of gouro tables * / #define LOOKUP_TBL_MAX 512 / * Maximum number of lookup tables * / #define CHAR_MAX 100 / * Maximum number of characters * / #define DRAW_PRTY_MAX 256 / * Maximum number of drawing priority blocks * / SPR_2DefineWork (work2d, COMMAND_MAX, GOUR_TBL_MAX, LOOKUP_TBL_MAX, CHAR_MAX, DRAW_PRTY_MAX) / * 2D work area definition * / extern void vbStart (void); / * V-BLANK IN interrupt routine * / extern void vbEnd (void); / * V-BLANK OUT interrupt routine * / main () { set_imask (0); / * Enable interrupts * / SCL_Vdp2Init (); / * Scroll and priority initialization * / SCL_SetPriority (SCL_SP0 | SCL_SP1 | SCL_SP2 | SCL_SP3 | SCL_SP4 | SCL_SP5 | SCL_SP6 | SCL_SP7,7); SCL_SetSpriteMode (SCL_TYPE1, SCL_MIX, SCL_SP_WINDOW); SPR_2Initial (& work2d); / * Initialize 2D sprite display * / INT_ChgMsk (INT_MSK_NULL, INT_MSK_VBL_IN | INT_MSK_VBL_OUT); / * Disable V-BLANK interrupts * / INT_SetFunc (INT_SCU_VBLK_IN, & vbStart); / * Registration of V-BLANK IN interrupt routine * / INT_SetFunc (INT_SCU_VBLK_OUT, & vbEnd); / * Registration of V-BLANK OUT interrupt routine * / INT_ChgMsk (INT_MSK_VBL_IN | INT_MSK_VBL_OUT, INT_MSK_NULL); / * Enable V-BLANK interrupt * / for (;;) { SPR_2SetChar (...); / * Character dataset to VRAM * / } SPR_2FrameChgIntr (0xffff); / * Set frame change interval * / / * Set to indefinite mode * / for (;;) { ------------- / * Scroll dataset * / SPR_2OpenCommand (SPR_2DRAW_PRTY_OFF); / * Open command write * / SPR_2SysClip (0, & xy); / * System clip area command * / SPR_2LocalCoord (0, & xy); / * Local coordinate command * / SPR_2Polygon (...); / * Various sprite commands * / SPR_2NormSpr (...); / *. .. .. SPR_2CloseCommand (); / * Command write close * / SCL_DisplayFrame (); / * Wait for V-BLANK interrupt * / / * Sprite display and scrolling * / } } −V Blank processing routine (source file different from the above main) − #include <machine.h> #include "sega_spr.h" #include "sega_scl.h" #pragma interrupt (VbStart) #pragma interrupt (VbEnd) void VbStart (void) { SCL_VblankStart (); / * V blank start VDP interrupt processing * / -------- / * Other V blank start processing * / } void VbEnd (void) { SCL_VblankEnd (); / * V blank end VDP interrupt processing * / -------- }


BackForward
PROGRAMMER'S GUIDEVDP1 library
Copyright SEGA ENTERPRISES, LTD., 1997