YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Video.cpp
浏览该文件的文档.
1 /*
2  © 2012-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #include "YCLib/YModules.h"
29 #include YFM_YCLib_Video
30 #include YFM_YCLib_NativeAPI
31 
32 namespace platform_ex
33 {
34 
35 #if YCL_DS
36 using ::lcdMainOnTop;
37 using ::lcdMainOnBottom;
38 using ::lcdSwap;
39 using ::videoSetMode;
40 using ::videoSetModeSub;
41 
42 using ::touchRead;
43 #endif
44 
45 } // namespace platform_ex;
46 
47 namespace platform
48 {
49 
50 namespace
51 {
52 
54 static_assert(sizeof(PixelType) == sizeof(PixelType::Trait::IntegerType),
55  "Wrong size of pixel type found.");
56 static_assert(yalignof(PixelType) == yalignof(PixelType::Trait::IntegerType),
57  "Wrong alignment of pixel type found.");
58 
59 #if YCL_DS
60 
61 extern "C"
62 {
63  extern const u8 default_font[];
64 }
65 
66 ::PrintConsole mainConsole{
67  {
68  reinterpret_cast<std::uint16_t*>(const_cast<u8*>(default_font)), \
69  // font graphics;
70  0, 0, 4, // font palette, font color count and bpp;
71  0, // first ASCII character in the set;
72  128, // number of characters in the set;
73  true // convert single color;
74  },
75  0, 0, // font background map and graphics;
76  22, 3, // map and char base;
77  0, -1, // background layer in use and background ID;
78  0, 0, // cursor X and Y coordinates;
79  0, 0, // prev-cursor X and Y coordinates;
80  32, 24, // console width and height;
81  0, 0, // window X and Y coordinates;
82  32, 24, //window width and height;
83  3, // tab size;
84  0, // font character offset;
85  0, // selected palette;
86  nullptr, // print callback;
87  false, // console initialized
88  true, // load graphics;
89 };
90 
91 PrintConsole*
92 consoleMainInit()
93 {
94  ::videoSetMode(MODE_0_2D);
95  ::vramSetBankA(VRAM_A_MAIN_BG);
96  return ::consoleInit(nullptr, mainConsole.bgLayer,
97  BgType_Text4bpp, BgSize_T_256x256,
98  mainConsole.mapBase, mainConsole.gfxBase, true, true);
99 }
100 #endif
101 
102 }
103 
104 
105 void
106 #if YCL_DS
107 YConsoleInit(std::uint8_t dspIndex, Color fc, Color bc)
108 {
109 #define BITALPHA BIT(15)
110 // PrintConsole* p(dspIndex ? consoleMainInit() : consoleDemoInit());
111 
112  if(YB_LIKELY(dspIndex ? consoleMainInit() : consoleDemoInit()))
113  {
114  //使用 ANSI Escape 序列 CUrsor Position 指令设置光标位置为左上角。
115  std::printf("\x1b[0;0H");
116 
117  std::uint16_t* bg_palette = dspIndex ? BG_PALETTE : BG_PALETTE_SUB;
118 
119  bg_palette[0] = PixelType(bc).Integer | BITALPHA;
120  bg_palette[255] = PixelType(fc).Integer | BITALPHA;
121  }
122 #elif YCL_Win32 || YCL_Android
123 YConsoleInit(std::uint8_t, Color, Color)
124 {
125 // TODO: Implementation.
126 #else
127 # error "Unsupported platform found."
128 #endif
129 }
130 
131 
132 bool
134 {
135 #if YCL_DS
136  platform_ex::ResetVideo();
137  platform_ex::lcdMainOnTop();
138 #endif
139  return true;
140 }
141 }
142 
143 namespace platform_ex
144 {
145 
146 #if YCL_DS
147 void
148 ResetVideo()
149 {
150  REG_BG0CNT = 0,
151  REG_BG1CNT = 0,
152  REG_BG2CNT = 0,
153  REG_BG3CNT = 0,
154  REG_BG0CNT_SUB = 0,
155  REG_BG1CNT_SUB = 0,
156  REG_BG2CNT_SUB = 0,
157  REG_BG3CNT_SUB = 0;
158  ::vramDefault();
159  ::vramSetBanks_EFG(VRAM_E_LCD, VRAM_F_LCD, VRAM_G_LCD),
160  ::vramSetBankH(VRAM_H_LCD),
161  ::vramSetBankI(VRAM_I_LCD);
162 // memset(OAM, 0, SPRITE_COUNT * sizeof(SpriteEntry));
163 // memset(OAM_SUB, 0, SPRITE_COUNT * sizeof(SpriteEntry));
164  ::videoSetMode(MODE_5_2D);
165  ::videoSetModeSub(MODE_5_2D);
166 }
167 
168 
170 InitScrUp(int& id)
171 {
172  //初始化背景,并得到屏幕背景ID 。
173  id = ::bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
174 
175  //获得屏幕背景所用的显存地址。
176  return reinterpret_cast<platform::BitmapPtr>(::bgGetGfxPtr(id));
177 }
178 
180 InitScrDown(int& id)
181 {
182  //初始化背景,并得到屏幕背景ID 。
183  id = ::bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
184 
185  //获得屏幕背景所用的显存地址。
186  return reinterpret_cast<platform::BitmapPtr>(::bgGetGfxPtr(id));
187 }
188 
189 void
190 ScreenSynchronize(platform::PixelType* buf, const platform::PixelType* src)
191  ynothrow
192 {
193  using ScreenBufferType = platform::PixelType[SCREEN_WIDTH * SCREEN_HEIGHT];
194 
195  ::DC_FlushRange(src, sizeof(ScreenBufferType));
196  ::dmaCopyWordsAsynch(3, src, buf, sizeof(ScreenBufferType));
197 }
198 #endif
199 
200 #if YCL_DS || YF_Hosted
201 bool
202 DSVideoState::IsLCDMainOnTop() const
203 {
204 # if YCL_DS
205  return REG_POWERCNT & POWER_SWAP_LCDS;
206 # else
207  return LCD_main_on_top;
208 #endif
209 }
210 
211 void
212 DSVideoState::SetLCDMainOnTop(bool b)
213 {
214 # if YCL_DS
215  b ? lcdMainOnTop() : lcdMainOnBottom();
216 # else
217  LCD_main_on_top = b;
218 #endif
219 }
220 
221 void
222 DSVideoState::SwapLCD()
223 {
224 # if YCL_DS
225  lcdSwap();
226 # else
227  LCD_main_on_top = !LCD_main_on_top;
228 #endif
229 }
230 #endif
231 
232 }
233 
YF_API bool InitVideo()
初始化视频输出。
Definition: Video.cpp:133
std::size_t size ynothrow
#define yalignof(_type)
指定特定类型的对齐。
Definition: ydef.h:442
YF_API void YConsoleInit(std::uint8_t dspIndex, Color fc=ColorSpace::White, Color bc=ColorSpace::Black)
启动控制台。
Color
控制台颜色枚举。
Definition: Video.h:458
std::uint8_t u8
通用数据类型。
Definition: yadaptor.h:67
PixelType * BitmapPtr
Definition: Video.h:295
#define YB_LIKELY(expr)
Definition: ydef.h:297