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, use _function: ... ; Event processing ; Event pointer is set in r4 register rts nop
EventTop: ----+ | | +------------------+ +-->| *work = NULL | | *before = NULL | +-- | *next | | | *exad() | | | user[] | | +------------------+ | | +------------------+ +------------------+ +--> | *work | ---> | *next | -+ | *before | | | | +-- | *next | | | | | | *exad() | +------------------+ | | | user[] | +-------------------------+ | +------------------+ | | | +------------------+ | +------------------+ +-> | *next = NULL | EventLast: ---+--> | *work | | | | *before | | | | *next = NULL | +------------------+ | *exad() | | user[] | +------------------+
typedef struct rob{ FIXED posX , posY , posZ ; ANGLE angX , angY , angZ ; PDATA *pat; } ROBOT ; /* This structure must 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 work on 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-> exad = (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 part
90.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
◆ After executing " slIntBackCancel ", if the following conditions are set, Calling " slGetPeripheral " fails. For ports set to SMPC control mode with " slSetPortSelect1 ,2", output settings were made with " slSetPortDir1 ,2". External latch input was enabled with " slSetPortExt1,2 ".
◆ After executing " slIntBackCancel ", if the following conditions are set, Calling " slGetStatus " fails. For ports set to SMPC control mode with " slSetPortSelect1 ,2", output settings were made with " slSetPortDir1 ,2". External latch input was enabled 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 calculate .data.l polygon_tbl ; Table of normal vectors and vertex numbers for each polygon .data.l NbPolygon ; Number of polygons to calculate .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 ; Vertex number used for polygon number 0 (For triangular polygons, P2 and P3 will be the same number) ... .data.l Nx,Ny,Nz ; Normal vector of polygon number NbPolygon - 1 .data.w P0,P1,P2,P3 ; Number of the vertex used in polygon number NbPolygon - 1
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 ; Specify either the flag Single_Plane or Dual_Plane ; to indicate whether to display the face that has become the back side due to front/back determination. .data.b SortMode ; Declare the calculation method for the position used as the sorting standard and the use of optional ; functions. One of SORT_CEN, SORT_MIN, SORT_MAX, or SORT_BFR. SORT_CEN : Uses the average of the four specified Z positions as the sorting criterion SORT_MIN : Use the smallest Z position among 4 points SORT_MAX : Use the largest Z position among 4 points SORT_BFR : Use the Z position of the most recently displayed polygon ; The polygon will always be displayed in front of the previous polygon. Specify the following options in addition to ; these. Specify multiple UseTexture, UseLight, UseClip options. can do. UseTexture : Specify this when using a texture (deformed sprite). UseLight : The color of the polygon is offset by the inner product of the light source ; vector and the normal vector to express brightness and darkness. Cannot be used at the same time as UseTexture. UseClip : When using large polygons, use this when the display position overflows and ; cannot be displayed correctly. .data.w TextNum ; When using a texture, use it as a character registration number. .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. (Shadows to sprites usually use 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) Displays without being affected by the window. MESHon : Display as a mesh. MESHoff : (default) Normal display. ECdis : Disable end code when using textures. ECenb : (default) Enable end code when using textures. SPdis : When using textures, disable spaces (display in palette 0 colors). ; However, if the data written to the frame buffer becomes 0000, it will not be displayed, so please ; adjust the priority etc. values so that it does not become 0000. SPenb : (default) Enable spacing when using textures. CL16Bnk : (default) Texture color mode is 16-color color bank method にします。 CL16Look : 16-color lookup table method for texture color mode にします。 CL64Bnk : Set the texture color mode to 64-color color bank method. CL128Bnk : Set the texture color mode to 128-color color bank method. CL256Bnk : Set the texture color mode to 256-color color bank method. CL32KRGB : Set the texture color mode to RGB with 32000 colors. CL_Replace : (default) Set to rewrite mode. CL_Trans : Display semi-transparent. CL_Half : Displays at half brightness. CL_Shadow : Displays shadow. CL_Gouraud : Specifies Gouraud shading. Specify one display mode for each group. .data.w Color ; Specify the display color. If it is affected by the light source, or if you specify a display mode ; other than CL_Replace, it must be in RGB mode. Also, when using a texture and ; in CL32KRGB mode, the specification here will be ignored. .data.w GouraudTable ; Specifies the Gouraud shading table. If CL_Gouraud is specified, it specifies the offset ; position of the Gouraud shading table. Specify the offset position by setting SpriteVRAM (0x25c00000) to 0 and ; incrementing it by 1 every 8 bytes. For example, if you have data at 0x25c12000: ; ( 0x25c12000 - 0x25c00000 ) / 0x08 = 0x2400 .data.w Function ; Specifies the sprite display function. Specifies whether to display as polygons, textures, or ; polylines. To specify, choose one from the following six options: sprNoflip : Show texture. sprHflip : Displays the texture by flipping it horizontally. sprVflip : Displays the texture by flipping it vertically. sprHVflip : Displays the texture flipped both vertically and horizontally. sprPolygon : Display as polygons. sprPolyLine: Displays polylines (polygon outlines only). When creating a table in C language, the ATTR type is declared and the above data table can be created by using the ATTRIBUTE macro. 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{ /* Color definition structure */ 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 (specify toFIXED(ORIGINAL) for same size) */ /* X position Y position Y position */ /* sample character data */ SPR_ATTR tattr = SPR_ATTRIBUTE(PN_Triangle,CL_Triangle,No_Gouraud,CL16Bnk,sprNoflip|_ZmCC); /* | | | | | |__ Rotation center position */ /* | | | | |__ No character reversal */ /* | | | |__ 16 colors color bank mode */ /* | | |___ Do not use Gouraud shading */ /* pattern number color bank number */ main() { ANGLE ang = DEGtoANG (0.0); *( Uint32 * )( 0x06002500 ) = ( Uint32 )( 0x060007f0 ); /* Apparently, during a clock change, the 68K for sound reads the switch data and prepares the data at the address set here, but it doesn't seem to be working properly, so for now I'll put an address with unpressed data 0xFFFF. */ slInitSystem( TV_320x224, form_tbl, 1 ); /* System initialization */ SetTexture( pic_tbl, Max_Picture ); /* Set of character data */ SetColor(); /* Set of color data */ while( -1 ) { slDispSprite( tpos, &tattr, ang ); /* Registering sprites */ 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 ]; : /* Initialize 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 Gouraud table →31-----16-------0-------0-------0
<Light source calculation method from Ver3.0> Angle between light source and surface →0------45------90-----135-----180 Gouraud table →31-----24------16-------8-------0