★ SGL User's Manual ★ Supplementary Manual
void * eventtbl [] = {
init_camera,
init_player1,
init_player2,
init_enemyctrl
};;
void InitGame () {
void ** evrdptr;
EVENT * evptr;
int cnt;
slInitEvent (); / * Initialize event management variables * /
evrptr = eventtbl;
for (cnt = sizeof (eventtbl) / sizeof (void *); cnt-> 0;) {
evptr = slSetEvent (* evrptr ++);
}
slSetSprTVMode ( TV_320x224 );
}
void Game () {
slExecuteEvent (); / * Execute event * /
slSynch (); / * Polygon data output and video display synchronization * /
}
void function ( EVENT * evptr) {
... / * Event processing * /
}
When writing in assembly language, _function:
...; Event processing; Event pointer is set in r4 register rts
nop
EventTop : ---- +
|
| + ------------------ +
+-> | * work = NULL |
| * before = NULL |
+-| * next |
| | * exit () |
| | user [] |
| + ------------------ +
|
| + ------------------ + + ------------------ +
+-> | * Work | ---> | * next |-+
| * before | | | |
+-| * next | | | |
| | * exit () | + ------------------ + |
| | user [] | + ------------------------- +
| + ------------------ + |
| | + ------------------ +
| + ------------------ + +-> | * next = NULL |
EventLast : --- +-> | * work | | |
| * before | | |
| * next = NULL | + ------------------ +
| * exit () |
| user [] |
+ ------------------ +
typedef struct rob {
FIXED posX, posY, posZ;
ANGLE angX, angY, angZ;
PDATA * pat;
} ROBOT; / * This structure should not exceed 112 bytes * /
void rob_control ( EVENT * evptr) {
ROBOT * rbptr;
rbptr = (ROBOT *) evptr-> user;
rbptr-> posX = to_fixed (0);
rbptr-> posY = to_fixed (0);
rbptr-> posZ = to_fixed (0);
rbptr-> pat = & PD_Robot;
}
typedef struct road {
struct road * next;
FIXED posX, posY, posZ;
PDATA * pat;
} ROAD;
typedef struct rdat {
Sint16 px, py, pz;
Uint16 pn;
} ROAD_DAT;
ROAD_DAT roadtbl [] = {
{0, 0, 0, PN_ROAD},
{0, 0, 100, PN_ROAD},
{0, 0, 200, PN_ROAD}
};;
void InitRoadControl ( EVENT * evptr) {
WORK * wkptr;
ROAD * rdptr;
ROAD_DAT * rdtptr;
int cnt;
rdptr = (ROAD *) evptr;
rdtptr = roadtbl;
for (cnt = sizeof (roadtbl) / sizeof (ROAD_DAT); cnt-> 0;) {
if ((wkptr = slGetWork ()) == NULL ) {
break;
}
rdptr-> next = (ROAD *) wkptr; / * The first pointer is * /
/ * Enter the work of the event * /
rdptr = (ROAD *) wkptr;
rdptr-> posX = rdtptr-> px << 16; / * Position * /
rdptr-> posY = rdtptr-> py >> 16;
rdptr-> posZ = rdtptr-> pz >> 16;
rdptr-> pat = pattbl [rdptr-> pn]; / * Pattern data * /
rdtptr ++;
}
rdptr-> next = NULL ; / * End mark * /
evptr-> exit = (void *) RoadControl;
}
/ * 3.SGL System Variable Clear * /
for (dst = (Uint8 *) SystemWork, i = 0; i <SystemSize; i ++) {
* dst = 0;
}
/ * 3.SGL System Variable Clear * /
for (dst = (Uint8 *) SystemWork, i = 0; i <SystemSize; i ++) {
* dst ++ = 0;
/ * ^^ * /
}
0x0010_8000
━━━━━━━━
↑↑
│ └── Decimal part └──────── Integer part90.0 °: 0x4000 45.0 °: 0x2000 22.5 °: 0x1000 11.25 °: 0x0800
M00 , M01 , M02 ,
M10 , M11 , M12 ,
M20 , M21 , M22 ,
M30 , M31 , M32
void main ()
{
slInitSystem ( TV_320x224 , NULL , 1);
{
slSetLanguage ( SMPC_JAPAN );
slSetSoundOutput ( SMPC_SOUND_STEREO );
(void) slSetSmpcMemory ();
}
{
SmpcDateTime * dt = & ( Smpc_Status- > rtc);
dt-> year = 0x1999;
dt-> month = SMPC_FRI | SMPC_DEC ;
dt-> date = 0x31;
dt-> hour = 0x23;
dt-> minute = 0x59;
dt-> second = 0x59;
(void) slSetDateTime ();
}
(void) slResetDisable ();
while ( TRUE ) {
if ( slCheckReset () == SMPC_RES_ON ) {
(void) slClearReset ();
break;
}
if ( Per_Connect1 ) {
PerDigital * pad;
pad = Smpc_Peripheral + 0;
if (! (Pad-> data & PER_DGT_ST )) break;
}
slSynch ();
}
(void) slResetEnable ();
(void) slIntBackCancel ();
while ( TRUE ) slSynch ();
}
slNMIRequestWait
slResetDisableWait
slResetEnableWait
slSetDateTimeWait
slSetSmpcMemoryWait
slSetPortDir1,2
slSetPortExt1,2
slSetPortSelect1,2
◆ If the following conditions are set after executing "slIntBackCancel"
Calling " slGetPeripheral " fails.
" SlSetPortSelect1 , 2" for the port, which was to SMPC control mode in the " SlSetPortDir1 , 2" and the output set in.
External latch input was allowed with " slSetPortExt1,2".
◆ If the following conditions are set after executing "slIntBackCancel"
Calling " slGetStatus " fails.
" SlSetPortSelect1 , 2" for the port, which was to SMPC control mode in the " SlSetPortDir1 , 2" and the output set in.
External latch input was allowed with " slSetPortExt1,2".
☆ Maximum number of caching commands ... 31 ☆ Maximum peripheral data size ... 15 bytes * 30 ports
.data.l point_tbl; Table of vertex coordinates .data.l NbPoint; Number of vertices to be calculated .data.l polygon_tbl; Table of normal vector and vertex number of each polygon .data.l NbPolygon; Number of polygons to be calculated. data.l attribute_tbl; Table of attributes for each polygon point_tbl:
.data.l X, Y, Z; Coordinate data of vertex number 0 .data.l X, Y, Z; Coordinate data of vertex number 1 ...
.data.l X, Y, Z; Coordinate data of vertex number NbPoint -1
static POINT point_CUBE [] = {
POStoFIXED (-80, -80, -80),
POStoFIXED (80, -80, -80),
POStoFIXED (80, 80, -80),
POStoFIXED (-80, 80, -80),
POStoFIXED (80, -80, 80),
POStoFIXED (-80, -80, 80),
POStoFIXED (-80, 80, 80),
POStoFIXED (80, 80, 80)
};;
polygon_tbl:
.data.l Nx, Ny, Nz; Normal vector of polygon number 0 .data.w P0, P1, P2, P3; Number of vertices used in polygon number 0 (for triangular polygons, P2 and P3 are the same Become a number)
...
.data.l Nx, Ny, Nz; Normal vector of polygon number NbPolygon --1 .data.w P0, P1, P2, P3; Vertex number used in polygon number NbPolygon --1; Number
static POLYGON polygon_CUBE [] = {
{ POStoFIXED (0, 0, -1), {0, 1, 2, 3}},
| __ | __
{ POStoFIXED (1, 0, 0), {1, 4, 7, 2}},
{ POStoFIXED (-1, 0, 0), {5, 0, 3, 6}},
{ POStoFIXED (0, -1, 0), {4, 1, 0, 5}},
{ POStoFIXED (0, 1, 0), {2, 7, 6, 3}},
{ POStoFIXED (0, 0, 1), {4, 5, 6, 7}},
};;
attribute_tbl:
.DATA.B Revcheck; whether Kano flag to display a surface which is on the back side by front and back determination Single_Plane and Dual_Plane specify one of.
.data.b SortMode; Declares how to calculate the position to be used as the basis for sorting and the use of optional functions.
SORT_CEN , SORT_MIN , SORT_MAX , SORT_BFR SORT_CEN : Uses the average of the specified 4 Z positions as the sorting reference SORT_MIN : Uses the smallest Z position of the 4 points SORT_MAX : 4 points Uses the largest Z position among them SORT_BFR : Uses the Z position of the previously displayed polygon Always displayed in front of the previous polygon Options are specified in addition to these UseTexture , UseLight , UseClip options Can be specified more than once.
UseTexture : Specify when using a texture (transformation sprite).
UseLight : The color of the polygon is offset by the inner product of the light source vector and the normal vector to express lightness and darkness.
Cannot be used at the same time as UseTexture.
UseClip : When using a large polygon, use it when the display position overflows and cannot be displayed correctly.
.data.w TextNum; When using a texture, use it as the registration number of the character.
.data.w DispMode; Specifies the polygon display mode.
The display modes that can be specified are as follows: MSBon : Set only the most significant bit to 1 when writing to the frame buffer. (Shadow on sprites usually uses this)
HSSon : High speed shrink enabled HSSoff : High speed shrink disabled (default)
Window_In : Display inside the specified window.
Window_Out : Display outside the window.
No_Window : (default) Display without being affected by the window.
MESHon : Display as a mesh.
MESHoff : (default) Normal display.
ECdis : Disables end code when using textures.
ECenb : (default) Enables end code when using textures.
SPdis : Disables spaces (displayed in palette 0 color) when using textures.
However, if the data written to the frame buffer becomes 0000, it will not be displayed, so adjust the value such as priority so that it does not become 0000.
SPenb : (default) Enables space when using textures.
CL16Bnk : (default) Sets the color mode of the texture to the 16-color color bank method.
CL16Look: Sets the texture color mode to a 16-color look-up table.
CL64Bnk : Set the color mode of the texture to the 64 color bank method.
CL128Bnk : Set the color mode of the texture to the 128 color bank method.
CL256Bnk : Sets the color mode of the texture to the 256-color color bank method.
CL32KRGB : Set the color mode of the texture to the RGB method of 32000 colors.
CL_Replace : (default) Enter rewrite mode.
CL_Trans : Display semi-transparently.
CL_Half : Display at half brightness.
CL_Shadow : Show shadow.
CL_Gouraud : Specifies Gouraud shading.
Specify one of each group as the display mode.
.data.w Color; Specifies the display color.
If it is affected by a light source, or if you specify a display mode other than CL_Replace , it must be in RGB mode.
Also, when using textures and in CL32KRGB mode, the indication here is ignored.
.data.w GouraudTable; Specifies the Gouraud shading table.
If CL_Gouraud is specified, it indicates the offset position of the Gouraud shading table. The offset position is specified by setting SpriteVRAM (0x25c00000) to 0 and advancing by 1 every 8 bytes.
For example, if there is data in 0x25c12000 (0x25c12000 --0x25c00000) / 0x08 = 0x2400
.data.w Function; Specifies the sprite display function.
Specifies whether to display as polygons, textures, or polylines.
Select one from the following six to specify.
sprNoflip: Shows the texture.
sprHflip: Displays the texture horizontally inverted.
sprVflip: Inverts the texture vertically and displays it.
sprHVflip: Inverts the texture both vertically and horizontally.
sprPolygon : Display as a polygon.
sprPolyLine : Shows polylines (polygon contours only).
When creating a table in C language, ATTR type is declared and ATTRIBUTE
You can create the above data table by using macros.
example)
static ATTR attr_CUBE [] = {
ATTRIBUTE ( Single_Plane , SORT_MIN , No_Texture , CD_MediumGreen ,
No_Gouraud , Window_In , sprPolygon , UseLight ),
ATTRIBUTE ( Single_Plane , SORT_MIN , No_Texture , CD_MediumBlue ,
No_Gouraud , Window_In , sprPolygon , UseLight ),
ATTRIBUTE ( Single_Plane , SORT_MIN , No_Texture , CD_MediumMagenta ,
No_Gouraud , Window_In , sprPolygon , UseLight ),
ATTRIBUTE ( Single_Plane , SORT_MIN , No_Texture , CD_MediumWhite ,
No_Gouraud , Window_In , sprPolygon , UseLight ),
ATTRIBUTE ( Single_Plane , SORT_MIN , No_Texture , CD_MediumYellow ,
No_Gouraud , Window_In , sprPolygon , UseLight ),
ATTRIBUTE ( Single_Plane , SORT_MIN , No_Texture , CD_MediumRed ,
No_Gouraud , Window_In , sprPolygon , UseLight )
};
SPR_ATTR attr_AM2Logo = {
SPR_ATTRIBUTE (PN_AM2_Logo, CL_AM2_Logo, No_Gouraud , Window_In | ECdis ,
sprNoflip | _ZmCB )
};;
_ZmLT _ZmCT _ZmRT
+ ------- + ------- +
| | |
_ZmLC + ---- _ZmCC ------ + _ZmRC
| | |
+ ------- + ------- +
_ZmLB _ZmCB _ZmRB
#define CGtop 0x10000
#define TEXTBL (hs, vs, cga) {hs, vs, (cga) >> 3, ((hs) & 0x1f8) >> 5 | (vs)}
#define AdjCG (cga, hs, vs, col) ((cga + (((hs) * (vs) * 4) >> (col)) + 0x1f) & 0x7ffe0)
#define PICTBL (txno, cmod, cga) {txno, cmod, cga}
#define CL_Triangle 0x00
static const Uint16 triangle [] = {
0x0000,0x0001,0x1000,0x0000, / * Sprite character data * /
0x0000,0x0012,0x2100,0x0000,
0x0000,0x0123,0x3210,0x0000,
0x0000,0x1234,0x4321,0x0000,
0x0001,0x2344,0x4432,0x1000,
0x0012,0x3333,0x3333,0x2100,
0x0122,0x2222,0x2222,0x2210,
0x1111,0x1111,0x1111,0x1111
};
enum patn {
PN_Triangle, / * Sprite pattern number * /
Max_Texture, / * Total number of patterns * /
Max_Picture = Max_Texture / * Total number of characters * /
};
enum cga {/ * character address * /
CG_Triangle = CGtop,
CG_Next = AdjCG (CG_Triangle, 16, 8, COL_16 )
};
TEXTURE form_tbl [] = {/ * Pattern size data * /
TEXTBL (16, 8, CG_Triangle)
};
PICTURE pic_tbl [] = {/ * Character definition table * /
PICTBL (PN_Triangle, COL_16 , triangle)
};
static const Sint16 Triangle_Color [] = {/ * color data * /
RGB (0, 0, 31), RGB (0, 0, 29), RGB (0, 0, 27),
RGB (0, 0, 25), RGB (0, 0, 23), RGB (0, 0, 21), RGB (0, 0, 19),
RGB (0, 0, 17), RGB (0, 0, 15), RGB (0, 0, 13), RGB (0, 0, 11),
RGB (0, 0, 9), RGB (0, 0, 7), RGB (0, 0, 5), RGB (0, 0, 3)
};
typedef struct {/ * structure for color definition * /
Sint16 * src;
void * dst;
Sint16 size;
} COLMAP;
static const COLMAP ctrns_list [] = {/ * color definition table * /
{Triangle_Color,
(void *) ( VDP2_COLRAM + (CL_Triangle + 1) * 2),
sizeof (Triangle_Color)
}
};
extern TEXTURE * FormTbl ;
/ * * /
/ * Character data transfer * /
/ * * /
void SetTexture (PICTURE * pcptr, Uint32 NbPicture) {
TEXTURE * txptr;
for (; NbPicture-> 0; pcptr ++) {
txptr = FormTbl + pcptr-> texno;
slDMACopy (pcptr-> pcsrc,
(void *) ( SpriteVRAM + ((txptr-> CGadr) >> 3)),
(txptr-> Hsize * txptr-> Vsize * 4) >> (pcptr-> cmode));
}
}
/ * * /
/ * Color data transfer * /
/ * * /
void SetColor () {
COLMAP * cmptr;
Sint16 cnt;
slTVOff ();
cmptr = ctrns_list;
for (cnt = sizeof (ctrns_list) / sizeof (COLMAP); cnt-> 0; cmptr ++) {
slDMACopy (cmptr-> src, cmptr-> dst, cmptr-> size);
}
slTVOn ();
}
/ * Sample character display position * /
FIXED tpos [] = { toFIXED (1.0), toFIXED (2.0), toFIXED (2.0), toFIXED (4.0)};
/ * | | | | _ Display scale * /
/ * X position Y position Y position ( toFIXED ( ORIGINAL ) for 1x magnification)
Please specify) * /
/ * Sample character data * /
SPR_ATTR tattr = SPR_ATTRIBUTE (PN_Triangle, CL_Triangle, No_Gouraud , CL16Bnk , sprNoflip | _ZmCC );
/ * | | | | | | __ Rotation center position * /
/ * | | | | | __ No character inversion * /
/ * | | | | __ 16-color color bank mode * /
/ * | | | ___ Do not use Gouraud shading * /
/ * Pattern number Color bank number * /
main () {
ANGLE ang = DEGtoANG (0.0);
* ( Uint32 *) (0x06002500) = ( Uint32 ) (0x060007f0);
/ * During the clock change, 68K for sound reads the switch data,
It seems that data will be prepared at the address set here,
It seems that it is not working well, so for the time being, enter the address with the data 0xFFFF that has not been pressed * /
slInitSystem ( TV_320x224 , form_tbl, 1); / * System initialization * /
SetTexture (pic_tbl, Max_Picture); / * Set character data * /
SetColor (); / * Set color data * /
while (-1) {
slDispSprite (tpos, & tattr, ang); / * Sprite registration * /
ang + = DEGtoANG (3.0);
slSynch (); / * Sprite output with synchronization to screen display * /
}
}
ATTRIBUTE ( Single_Plane , SORT_CEN , 0, 0xffa0, 0xe000,
CL16Look | MESHoff | CL_Gouraud , sprNoflip , UseGouraud )
VECTOR gr_point [] = {/ * Vertex normal vector data * /
toFIXED (-0.873), toFIXED (0.436), toFIXED (0.217),
toFIXED (-0.873), toFIXED (-0.436), toFIXED (0.217),
::
::
};
XPDATA PD_BOX = {/ * Model table specification * /
point_BOX, / * Vertex position data table * /
sizeof (point_BOX) / sizeof ( POINT ), / * Number of vertices * /
polygon_BOX, / * Polygon definition table * /
sizeof (polygon_BOX) / sizeof ( POLYGON ), / * Number of polygons * /
attribute_BOX2, / * Polygon attribute table * /
gr_point / * Vertex normal vector data * /
};
slInitGouraud (( GOURAUDTBL *) gr_tab, ( Uint32 ) 300, 0xe000, addr);
slIntFunction ( slGouraudTblCopy );
FIXED light [ XYZ ];
light [ X ] = toFIXED (1.0);
light [ Y ] = toFIXED (0.0);
light [ Z ] = toFIXED (0.0);
slPutPolygonX (& PD_BOXx, ( FIXED *) light);
static GOURAUDTBL gr_tab [300];
void ss_main (void)
{
FIXED light [ XYZ ];
::
/ * Initialization of real-time glow program * /
slInitGouraud (( GOURAUDTBL *) gr_tab, ( Uint32 ) 300, 0xe000, addr);
slGouraudTblCopy ();
slSynch ();
::
light [ X ] = toFIXED (1.0);
light [ Y ] = toFIXED (0.0);
light [ Z ] = toFIXED (0.0);
while (1)
{
::
slPushMatrix ();
{
::
/ ** /
slPutPolygonX (& PD_BOX, ( FIXED *) light);
}
slPopMatrix ();
slSynch ();
}
}
ATTRIBUTE ( Single_Plane , SORT_CEN , 1, No_Palet , No_Gouraud ,
CL32KRGB | MESHoff , sprNoflip , UseNearClip );
<Light source calculation method up to Ver2.1x> Angle between light source and surface → 0 ------ 45 ------ 90 ----- 135 ----- 180 Goo table → 31 ----- 16 ------ -0 ------ 0 ------ 0
<Light source calculation method from Ver3.0> Angle between light source and surface → 0 ------ 45 ------ 90 ----- 135 ----- 180 Goo table → 31 ----- 24 ----- -16 ------ -8 ------ 0
★ SGL User's Manual ★ Supplementary Manual