The following sample program (Listing 8-5) is an example of actually rotating a rotating scroll screen using SGL library functions.
Listing 8-5 sample_8_9_1: 2D rotation of scroll
/*------------------------------------------------ ----------------------*/ /* Graphic Rotation */ /*------------------------------------------------ ----------------------*/ #include "sgl.h" #include "ss_scroll.h" #define RBG0_CEL_ADR VDP2_VRAM_A0 #define RBG0_MAP_ADR VDP2_VRAM_B0 #define RBG0_COL_ADR ( VDP2_COLRAM + 0x00200 ) #define RBG0_PAR_ADR ( VDP2_VRAM_A1 + 0x1fe00 ) #define BACK_COL_ADR ( VDP2_VRAM_A1 + 0x1fffe ) void ss_main(void) { ANGLE yama_angz = DEGtoANG(0.0); FIXED posx = toFIXED(128.0) , posy = toFIXED(64.0); slInitSystem(TV_320x224,NULL,1); slTVOff(); slPrint("Sample program 8.9.1" , slLocate(9,2)); slColRAMMode(CRM16_1024); slBack1ColSet((void *)BACK_COL_ADR , 0); slRparaInitSet((void *)RBG0_PAR_ADR); slCharRbg0(COL_TYPE_256 , CHAR_SIZE_1x1); slPageRbg0((void *)RBG0_CEL_ADR , 0 , PNB_1WORD|CN_10BIT); slPlaneRA(PL_SIZE_1x1); sl1MapRA((void *)RBG0_MAP_ADR); slOverRA(2); Cel2VRAM(yama_cel , (void *)RBG0_CEL_ADR , 31808); Map2VRAM(yama_map, (void *)RBG0_MAP_ADR, 32, 16, 1, 0); Pal2CRAM(yama_pal , (void *)RBG0_COL_ADR , 256); slDispCenterR(toFIXED(160.0) , toFIXED(112.0)); slLookR(toFIXED(128.0) , toFIXED(64.0)); slScrAutoDisp(NBG0ON | RBG0ON); slTVOn(); while(1){ slZrotR(yama_angz); yama_angz += DEGtoANG(1.0); slSynch(); } }
Table usage: | [K_OFF | K_ON ]| |
Coefficient data size: | [K_2WORD | K_1WORD]| |
Coefficient mode: | [K_MODE0 | K_MODE1 | K_MODE2 | K_MODE3]| |
Line color: | [K_LINECOL]| |
Deformation unit: | [K_DOT | K_LINE ]| |
Fixed coefficient: | [K_FIX ]| |
List 8-6 sample_8_9_2: 3D rotation
#include "sgl.h" #include "ss_scroll.h" #define RBG0RB_CEL_ADR (VDP2_VRAM_A0 ) #define RBG0RB_MAP_ADR (VDP2_VRAM_B0 ) #define RBG0RB_COL_ADR (VDP2_COLRAM + 0x00200) #define RBG0RA_CEL_ADR (RBG0RB_CEL_ADR + 0x06e80) #define RBG0RA_MAP_ADR (RBG0RB_MAP_ADR + 0x02000) #define RBG0RA_COL_ADR (RBG0RB_COL_ADR + 0x00200) #define RBG0_KTB_ADR (VDP2_VRAM_A1 ) #define RBG0_PRA_ADR (VDP2_VRAM_A1 + 0x1fe00) #define RBG0_PRB_ADR (RBG0_PRA_ADR + 0x00080) #define BACK_COL_ADR (VDP2_VRAM_A1 + 0x1fffe) void ss_main(void) { FIXED posy = toFIXED(0.0); ANGLE angz = DEGtoANG(0.0); ANGLE angz_up = DEGtoANG(0.0); slInitSystem(TV_320x224,NULL,1); slTVOff(); slPrint("Sample program 8.9.2" , slLocate(9,2)); slColRAMMode(CRM16_1024); slRparaInitSet((void *)RBG0_PRA_ADR); slMakeKtable((void *)RBG0_KTB_ADR); slCharRbg0(COL_TYPE_256 , CHAR_SIZE_1x1); slPageRbg0((void *)RBG0RB_CEL_ADR , 0 , PNB_1WORD|CN_12BIT); slPlaneRA(PL_SIZE_1x1); sl1MapRA((void *)RBG0RA_MAP_ADR); slOverRA(0); slKtableRA((void *)RBG0_KTB_ADR , K_FIX | K_DOT | K_2WORD | K_ON); Cel2VRAM(tuti_cel , (void *)RBG0RA_CEL_ADR , 65536); Map2VRAM(tuti_map, (void *)RBG0RA_MAP_ADR, 64, 64, 2, 884); Pal2CRAM(tuti_pal , (void *)RBG0RA_COL_ADR , 160); slPlaneRB(PL_SIZE_1x1); sl1MapRB((void *)RBG0RB_MAP_ADR); slOverRB(0); slKtableRB((void *)RBG0_KTB_ADR , K_FIX | K_DOT | K_2WORD | K_ON); Cel2VRAM(sora_cel , (void *)RBG0RB_CEL_ADR , 28288); Map2VRAM(sora_map, (void *)RBG0RB_MAP_ADR, 64, 20, 1, 0); Pal2CRAM(sora_pal , (void *)RBG0RB_COL_ADR , 256); slRparaMode(K_CHANGE); slBack1ColSet((void *)BACK_COL_ADR , 0); slScrAutoDisp(NBG0ON | RBG0ON); slTVOn(); while(1) { slCurRpara(RA); slUnitMatrix(CURRENT); slTranslate(toFIXED(0.0) , toFIXED(0.0) + posy , toFIXED(100.0)); posy -= toFIXED(5.0); slRotX(DEGtoANG(-90.0)); slRotZ(angz); slScrMatSet(); slCurRpara(RB); slUnitMatrix(CURRENT); slTranslate(toFIXED(160.0) , toFIXED(155.0) , toFIXED(100.0)); slRotZ(angz); slScrMatSet(); angz_up += DEGtoANG(0.5); angz = (slSin(angz_up)>> Four); slSynch(); } }