YSTest: DSVideo.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

DSVideo.cpp
浏览该文件的文档.
1 /*
2 © 2015, 2018 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
29 #include "YCLib/YModules.h"
30 #include YFM_DS_YCLib_DSVideo // for ystdex::replace_cast;
31 #include YFM_YCLib_NativeAPI
32
33 namespace platform_ex
34 {
35
36 using namespace platform;
37
38 namespace
39 {
40
41 #if YCL_DS
42 extern "C" const ::u8 default_font[];
43
44 ::PrintConsole mainConsole{
45 {
46 reinterpret_cast<std::uint16_t*>(const_cast<::u8*>(default_font)), \
47 // font graphics;
48 nullptr, 0, 4, // font palette, font color count and bpp;
49 0, // first ASCII character in the set;
50 128, // number of characters in the set;
51 true // convert single color;
52 },
53 nullptr, nullptr, // font background map and graphics;
54 22, 3, // map and char base;
55 0, -1, // background layer in use and background ID;
56 0, 0, // cursor X and Y coordinates;
57 0, 0, // prev-cursor X and Y coordinates;
58 32, 24, // console width and height;
59 0, 0, // window X and Y coordinates;
60 32, 24, //window width and height;
61 3, // tab size;
62 0, // font character offset;
63 0, // selected palette;
64 nullptr, // print callback;
65 false, // console initialized
66 true, // load graphics;
67 };
68 #endif
69
70 } // unnamed namespace;
71
72 #if YCL_DS
73 void
74 ResetVideo()
75 {
76 REG_BG0CNT = 0,
77 REG_BG1CNT = 0,
78 REG_BG2CNT = 0,
79 REG_BG3CNT = 0,
80 REG_BG0CNT_SUB = 0,
81 REG_BG1CNT_SUB = 0,
82 REG_BG2CNT_SUB = 0,
83 REG_BG3CNT_SUB = 0;
84 ::vramDefault();
85 ::vramSetBanks_EFG(VRAM_E_LCD, VRAM_F_LCD, VRAM_G_LCD),
86 ::vramSetBankH(VRAM_H_LCD),
87 ::vramSetBankI(VRAM_I_LCD);
88 // std::fill_n(static_cast<void*>(OAM), SPRITE_COUNT * sizeof(SpriteEntry), 0),
89 // std::fill_n(static_cast<void*>(OAM_SUB), SPRITE_COUNT * sizeof(SpriteEntry),
90 // 0);
91 ::videoSetMode(MODE_5_2D);
92 ::videoSetModeSub(MODE_5_2D);
93 }
94
95
96 platform::Pixel*
97 InitScrUp(int& id)
98 {
99 id = ::bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
100 return ystdex::replace_cast<platform::Pixel*>(::bgGetGfxPtr(id));
101 }
102
103 platform::Pixel*
104 InitScrDown(int& id)
105 {
106 id = ::bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
107 return ystdex::replace_cast<platform::Pixel*>(::bgGetGfxPtr(id));
108 }
109
110 void
111 ScreenSynchronize(platform::Pixel* buf, const platform::Pixel* src)
112 ynothrow
113 {
114 using ScreenBufferType = platform::Pixel[SCREEN_WIDTH * SCREEN_HEIGHT];
115
116 ::DC_FlushRange(src, sizeof(ScreenBufferType));
117 ::dmaCopyWordsAsynch(3, src, buf, sizeof(ScreenBufferType));
118 }
119
120 void
121 DSConsoleInit(bool use_customed, YSLib::Drawing::Color fc,
122 YSLib::Drawing::Color bc) ynothrow
123 {
124 if(YB_LIKELY(use_customed ? []{
125 ::videoSetMode(MODE_0_2D);
126 ::vramSetBankA(VRAM_A_MAIN_BG);
127 return ::consoleInit({}, mainConsole.bgLayer,
128 BgType_Text4bpp, BgSize_T_256x256,
129 mainConsole.mapBase, mainConsole.gfxBase, true, true);
130 }() : ::consoleDemoInit()))
131 {
132 // NOTE: Set cursor position to left top side.
133 std::printf("\x1b[0;0H");
134
135 const auto bg_palette(use_customed ? BG_PALETTE : BG_PALETTE_SUB);
136
137 bg_palette[0] = Pixel(bc).Integer | BIT(15),
138 bg_palette[255] = Pixel(fc).Integer | BIT(15);
139 }
140 }
141 #endif
142
143
144 #if YCL_DS || YF_Hosted
145 bool
146 DSVideoState::IsLCDMainOnTop() const
147 {
148 # if YCL_DS
149 return REG_POWERCNT & POWER_SWAP_LCDS;
150 # else
151 return LCD_main_on_top;
152 #endif
153 }
154
155 void
156 DSVideoState::SetLCDMainOnTop(bool b)
157 {
158 # if YCL_DS
159 b ? ::lcdMainOnTop() : ::lcdMainOnBottom();
160 # else
161 LCD_main_on_top = b;
162 #endif
163 }
164
165 void
166 DSVideoState::SwapLCD()
167 {
168 # if YCL_DS
169 ::lcdSwap();
170 # else
171 LCD_main_on_top = !LCD_main_on_top;
172 # endif
173 }
174 #endif
175
176 } // namespace platform_ex;
177
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:128
platform_ex
平台扩展命名空间。
Definition: Android.h:46
YSLib::UI::fc
fc
Definition: Console.h:93
YSLib::Drawing::src
src
Definition: YGDI.h:442
platform
默认平台命名空间。
Definition: Container.h:56
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:827
YSLib::Text::buf
YB_ATTR_nodiscard YB_PURE const char * buf
Definition: TextFile.h:83
YModules.h
YCLib 库模块配置文件。
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199