-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmain.rs
More file actions
72 lines (64 loc) · 2.47 KB
/
Copy pathmain.rs
File metadata and controls
72 lines (64 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! A basic graphics example that only clears the screen.
#![no_std]
#![no_main]
use core::ffi::c_void;
use psp::sys::{self, DisplayPixelFormat, GuState, TexturePixelFormat};
use psp::vram_alloc::VramAllocator;
use psp::{BUF_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH};
psp::module!("sample_gu_background", 1, 1);
static mut LIST: psp::Align16<[u32; 0x40000]> = psp::Align16([0; 0x40000]);
fn psp_main() {
psp::enable_home_button();
let allocator = VramAllocator::take().unwrap();
let fbp0 = allocator
.alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm8888)
.unwrap()
.as_mut_ptr_from_zero();
let fbp1 = allocator
.alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm8888)
.unwrap()
.as_mut_ptr_from_zero();
let zbp = allocator
.alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm4444)
.unwrap()
.as_mut_ptr_from_zero();
unsafe {
sys::sceGuInit();
sys::sceGuStart(
sys::GuContextType::Direct,
&mut LIST as *mut _ as *mut c_void,
);
sys::sceGuDrawBuffer(DisplayPixelFormat::Psm8888, fbp0 as _, BUF_WIDTH as i32);
sys::sceGuDispBuffer(
SCREEN_WIDTH as i32,
SCREEN_HEIGHT as i32,
fbp1 as _,
BUF_WIDTH as i32,
);
sys::sceGuDepthBuffer(zbp as _, BUF_WIDTH as i32);
sys::sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2));
sys::sceGuViewport(2048, 2048, SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32);
sys::sceGuDepthRange(65535, 0);
sys::sceGuScissor(0, 0, SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32);
sys::sceGuEnable(GuState::ScissorTest);
sys::sceGuFinish();
sys::sceGuSync(sys::GuSyncMode::Finish, sys::GuSyncBehavior::Wait);
sys::sceDisplayWaitVblankStart();
sys::sceGuDisplay(true);
loop {
sys::sceGuStart(
sys::GuContextType::Direct,
&mut LIST as *mut _ as *mut c_void,
);
sys::sceGuClearColor(0xff554433);
sys::sceGuClearDepth(0);
sys::sceGuClear(
sys::ClearBuffer::COLOR_BUFFER_BIT | sys::ClearBuffer::DEPTH_BUFFER_BIT,
);
sys::sceGuFinish();
sys::sceGuSync(sys::GuSyncMode::Finish, sys::GuSyncBehavior::Wait);
sys::sceDisplayWaitVblankStart();
sys::sceGuSwapBuffers();
}
}
}