YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Video.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2012 - 2013.
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/Video.h"
29 #include "YCLib/NativeAPI.h"
30 
31 namespace platform_ex
32 {
33 
34 #if YCL_DS
35 using ::lcdMainOnTop;
36 using ::lcdMainOnBottom;
37 using ::lcdSwap;
38 using ::videoSetMode;
39 using ::videoSetModeSub;
40 
41 using ::touchRead;
42 #endif
43 
44 } // namespace platform_ex;
45 
46 namespace platform
47 {
48 
49 namespace
50 {
51 #if YCL_DS
52  extern "C"
53  {
54  extern const u8 default_font[];
55  }
56 
57  PrintConsole mainConsole =
58  {
59  //Font:
60  {
61  reinterpret_cast<u16*>(
62  const_cast<u8*>(default_font)), //font gfx
63  0, //font palette
64  0, //font color count
65  4, //bpp
66  0, //first ascii character in the set
67  128, //number of characters in the font set
68  true //convert single color
69  },
70  0, //font background map
71  0, //font background gfx
72  22, //map base
73  3, //char base
74  0, //bg layer in use
75  -1, //bg id
76  0,0, //cursorX cursorY
77  0,0, //prevcursorX prevcursorY
78  32, //console width
79  24, //console height
80  0, //window x
81  0, //window y
82  32, //window width
83  24, //window height
84  3, //tab size
85  0, //font character offset
86  0, //selected palette
87  0, //print callback
88  false, //console initialized
89  true, //load graphics
90  };
91 
92  PrintConsole*
93  consoleMainInit()
94  {
95  videoSetMode(MODE_0_2D);
96  vramSetBankA(VRAM_A_MAIN_BG);
97  return consoleInit(nullptr, mainConsole.bgLayer,
98  BgType_Text4bpp, BgSize_T_256x256,
99  mainConsole.mapBase, mainConsole.gfxBase, true, true);
100  }
101 #endif
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  PixelType* bg_palette = dspIndex ? BG_PALETTE : BG_PALETTE_SUB;
118 
119  bg_palette[0] = bc | BITALPHA;
120  bg_palette[255] = fc | BITALPHA;
121  }
122 #elif YCL_MINGW32
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
137  //设置显示模式。
138  ::vramSetBankA(VRAM_A_MAIN_BG);
139  ::vramSetBankC(VRAM_C_SUB_BG);
140  //设置主显示引擎渲染上屏。
141  platform_ex::lcdMainOnTop();
142 // platform_ex::lcdMainOnBottom();
143 // platform_ex::lcdSwap();
144 #endif
145  return true;
146 }
147 }
148 
149 namespace platform_ex
150 {
151 
152 #if YCL_DS
153 void
154 ResetVideo()
155 {
156  REG_BG0CNT = REG_BG1CNT = REG_BG2CNT = REG_BG3CNT = 0;
157  REG_BG0CNT_SUB = REG_BG1CNT_SUB = REG_BG2CNT_SUB = REG_BG3CNT_SUB = 0;
158  ::vramSetPrimaryBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
159  ::vramSetBankE(VRAM_E_LCD);
160  ::vramSetBankF(VRAM_F_LCD);
161  ::vramSetBankG(VRAM_G_LCD);
162  ::vramSetBankH(VRAM_H_LCD);
163  ::vramSetBankI(VRAM_I_LCD);
164  std::fill_n(VRAM_A, 0x90000, 0);
165 // memset(OAM, 0, SPRITE_COUNT * sizeof(SpriteEntry));
166 // memset(OAM_SUB, 0, SPRITE_COUNT * sizeof(SpriteEntry));
167  videoSetMode(MODE_5_2D);
168  videoSetModeSub(MODE_5_2D);
169 }
170 
171 
173 InitScrUp(int& id)
174 {
175  //初始化背景,并得到屏幕背景ID 。
176  id = ::bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
177 
178  //获得屏幕背景所用的显存地址。
179  return ::bgGetGfxPtr(id);
180 }
181 
183 InitScrDown(int& id)
184 {
185  //初始化背景,并得到屏幕背景ID 。
186  id = ::bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
187 
188  //获得屏幕背景所用的显存地址。
189  return ::bgGetGfxPtr(id);
190 }
191 
192 void
194  ynothrow
195 {
196  typedef platform::PixelType
197  ScreenBufferType[SCREEN_WIDTH * SCREEN_HEIGHT];
198 
199 // YAssert(safe_dma_copy(buf, src, sizeof(ScreenBufferType)) == 0,
200 // "Screen sychronize failure.");
201  DC_FlushRange(src, sizeof(ScreenBufferType));
202  dmaCopyWordsAsynch(3, src, buf, sizeof(ScreenBufferType));
203 // std::memcpy(buf, src, sizeof(ScreenBufferType));
204 }
205 #endif
206 
207 }
208