|
1 |
| -#![feature(restricted_std)] |
| 1 | +#![no_std] |
2 | 2 | #![no_main]
|
3 | 3 |
|
4 |
| -use core::{ffi::c_void, f32::consts::PI}; |
| 4 | +use core::f32::consts::PI; |
5 | 5 |
|
6 |
| -use psp::{sys, vram_alloc::get_vram_allocator, BUF_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, |
| 6 | +use psp::{ |
| 7 | + math::{cosf32, sinf32}, |
7 | 8 | sys::{
|
8 |
| - TexturePixelFormat, DisplayPixelFormat, GuPrimitive, VertexType, GuState, |
| 9 | + self, ClearBuffer, DepthFunc, DisplayPixelFormat, FrontFaceDirection, GuContextType, |
| 10 | + GuPrimitive, GuState, GuSyncBehavior, GuSyncMode, LightComponent, LightType::Pointlight, |
| 11 | + MatrixMode, ScePspFVector3, ShadingModel, TexturePixelFormat, VertexType, |
| 12 | + |
9 | 13 | sceAudioChReserve, sceAudioOutput, sceAudioGetChannelRestLen,
|
10 |
| - sceAudioSetChannelDataLen, ThreadAttributes, ScePspFVector3, |
| 14 | + sceAudioSetChannelDataLen, |
11 | 15 | },
|
| 16 | + vram_alloc::get_vram_allocator, |
| 17 | + Align16, BUF_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, |
12 | 18 | };
|
13 | 19 |
|
14 | 20 | mod crab;
|
| 21 | +use crab::CRAB_VERTICES; |
15 | 22 |
|
16 | 23 | psp::module!("crab-rave", 1, 1);
|
17 | 24 |
|
18 |
| -static mut LIST: psp::Align16<[u32; 0x40000]> = psp::Align16([0; 0x40000]); |
| 25 | +const LIGHT_DISTANCE: f32 = 5.0; |
| 26 | + |
| 27 | +static mut LIST: Align16<[u32; 0x40000]> = Align16([0; 0x40000]); |
19 | 28 |
|
20 | 29 | static AUDIO_CLIP: [u8; 672320] = *include_bytes!("../assets/crabrave.pcm");
|
21 | 30 |
|
22 | 31 | const MAX_VOL: i32 = 0x8000;
|
23 | 32 | const MAX_SAMPLES: usize = 65472;
|
24 | 33 | const CHANNEL: i32 = 0;
|
25 | 34 |
|
26 |
| - |
27 |
| -#[no_mangle] |
28 | 35 | fn psp_main() {
|
29 | 36 | psp::enable_home_button();
|
30 | 37 |
|
31 |
| - let mut allocator = get_vram_allocator().unwrap(); |
32 |
| - let fbp0 = allocator.alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm8888).as_mut_ptr_from_zero(); |
33 |
| - let fbp1 = allocator.alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm8888).as_mut_ptr_from_zero(); |
34 |
| - let zbp = allocator.alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm4444).as_mut_ptr_from_zero(); |
| 38 | + let np_vertex_format: VertexType = VertexType::NORMAL_32BITF | VertexType::VERTEX_32BITF; |
35 | 39 |
|
36 | 40 | unsafe {
|
37 | 41 | sceAudioChReserve(CHANNEL, MAX_SAMPLES as i32, psp::sys::AudioFormat::Stereo)
|
38 | 42 | };
|
39 | 43 | let mut start_pos: usize = 0;
|
40 | 44 | let mut restlen = 0;
|
41 | 45 |
|
42 |
| - unsafe {sys::sceKernelChangeCurrentThreadAttr(0, ThreadAttributes::VFPU)}; |
43 |
| - |
44 |
| - |
45 | 46 | unsafe {
|
| 47 | + sys::sceKernelChangeCurrentThreadAttr(0, sys::ThreadAttributes::VFPU); |
| 48 | + sys::sceKernelDcacheWritebackAll(); |
| 49 | + |
| 50 | + let mut allocator = get_vram_allocator().unwrap(); |
| 51 | + let fbp0 = allocator |
| 52 | + .alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm8888) |
| 53 | + .as_mut_ptr_from_zero(); |
| 54 | + let fbp1 = allocator |
| 55 | + .alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm8888) |
| 56 | + .as_mut_ptr_from_zero(); |
| 57 | + let zbp = allocator |
| 58 | + .alloc_texture_pixels(BUF_WIDTH, SCREEN_HEIGHT, TexturePixelFormat::Psm4444) |
| 59 | + .as_mut_ptr_from_zero(); |
46 | 60 |
|
47 | 61 | sys::sceGuInit();
|
48 |
| - sys::sceGuStart( |
49 |
| - sys::GuContextType::Direct, |
50 |
| - &mut LIST as *mut _ as *mut c_void, |
51 |
| - ); |
| 62 | + sys::sceGuStart(GuContextType::Direct, &mut LIST.0 as *mut _ as _); |
52 | 63 | sys::sceGuDrawBuffer(DisplayPixelFormat::Psm8888, fbp0 as _, BUF_WIDTH as i32);
|
53 |
| - sys::sceGuDispBuffer(SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32, fbp1 as _, BUF_WIDTH as i32); |
| 64 | + sys::sceGuDispBuffer( |
| 65 | + SCREEN_WIDTH as i32, |
| 66 | + SCREEN_HEIGHT as i32, |
| 67 | + fbp1 as _, |
| 68 | + BUF_WIDTH as i32, |
| 69 | + ); |
54 | 70 | sys::sceGuDepthBuffer(zbp as _, BUF_WIDTH as i32);
|
55 |
| - sys::sceGuOffset(2048 - (SCREEN_WIDTH/2), 2048 - (SCREEN_HEIGHT/2)); |
| 71 | + sys::sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2)); |
56 | 72 | sys::sceGuViewport(2048, 2048, SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32);
|
57 |
| - sys::sceGuDepthRange(65535, 0); |
| 73 | + sys::sceGuDepthRange(0xc350, 0x2710); |
58 | 74 | sys::sceGuScissor(0, 0, SCREEN_WIDTH as i32, SCREEN_HEIGHT as i32);
|
59 | 75 | sys::sceGuEnable(GuState::ScissorTest);
|
| 76 | + sys::sceGuDepthFunc(DepthFunc::GreaterOrEqual); |
| 77 | + sys::sceGuFrontFace(FrontFaceDirection::Clockwise); |
| 78 | + sys::sceGuShadeModel(ShadingModel::Smooth); |
| 79 | + sys::sceGuEnable(GuState::DepthTest); |
| 80 | + sys::sceGuEnable(GuState::CullFace); |
| 81 | + sys::sceGuEnable(GuState::ClipPlanes); |
60 | 82 | sys::sceGuEnable(GuState::Lighting);
|
61 | 83 | sys::sceGuEnable(GuState::Light0);
|
62 |
| - sys::sceGuFrontFace(sys::FrontFaceDirection::Clockwise); |
| 84 | + sys::sceGuEnable(GuState::Light1); |
| 85 | + sys::sceGuEnable(GuState::Light2); |
| 86 | + sys::sceGuEnable(GuState::Light3); |
63 | 87 | sys::sceGuFinish();
|
64 |
| - sys::sceGuSync(sys::GuSyncMode::Finish, sys::GuSyncBehavior::Wait); |
| 88 | + sys::sceGuSync(GuSyncMode::Finish, GuSyncBehavior::Wait); |
65 | 89 | sys::sceDisplayWaitVblankStart();
|
66 | 90 | sys::sceGuDisplay(true);
|
| 91 | + |
67 | 92 | let mut val = 0.0;
|
68 | 93 |
|
69 | 94 | loop {
|
@@ -95,60 +120,78 @@ fn psp_main() {
|
95 | 120 |
|
96 | 121 | restlen = sceAudioGetChannelRestLen(CHANNEL);
|
97 | 122 |
|
98 |
| - |
99 |
| - sys::sceGuStart( |
100 |
| - sys::GuContextType::Direct, |
101 |
| - &mut LIST as *mut _ as *mut c_void |
102 |
| - ); |
103 |
| - sys::sceGuClearColor(0xff554433); |
| 123 | + sys::sceGuStart(GuContextType::Direct, &mut LIST.0 as *mut _ as _); |
| 124 | + sys::sceGuClearColor(0x554433); |
104 | 125 | sys::sceGuClearDepth(0);
|
105 |
| - sys::sceGuClear( |
106 |
| - sys::ClearBuffer::COLOR_BUFFER_BIT | |
107 |
| - sys::ClearBuffer::DEPTH_BUFFER_BIT |
108 |
| - ); |
| 126 | + sys::sceGuClear(ClearBuffer::COLOR_BUFFER_BIT | ClearBuffer::DEPTH_BUFFER_BIT); |
| 127 | + |
| 128 | + for i in 0..4 { |
| 129 | + let pos = ScePspFVector3 { |
| 130 | + x: cosf32(i as f32 * (PI / 2.0) + val as f32 * (PI / 180.0)) * LIGHT_DISTANCE, |
| 131 | + y: 0.0, |
| 132 | + z: (sinf32(i as f32 * (PI / 2.0) + val as f32 * (PI / 180.0)) * LIGHT_DISTANCE), |
| 133 | + }; |
| 134 | + sys::sceGuLight( |
| 135 | + i, |
| 136 | + Pointlight, |
| 137 | + LightComponent::DIFFUSE | LightComponent::SPECULAR, |
| 138 | + &pos, |
| 139 | + ); |
| 140 | + sys::sceGuLightColor(i, LightComponent::DIFFUSE, 0xff00_ffff); |
| 141 | + sys::sceGuLightColor(i, LightComponent::SPECULAR, 0xffff_ffff); |
| 142 | + sys::sceGuLightAtt(i, 0.0, 1.0, 0.0); |
| 143 | + } |
| 144 | + |
| 145 | + sys::sceGuSpecular(12.0); |
| 146 | + sys::sceGuAmbient(0x0022_2222); |
109 | 147 |
|
110 |
| - sys::sceGumMatrixMode(sys::MatrixMode::Projection); |
| 148 | + sys::sceGumMatrixMode(MatrixMode::Projection); |
111 | 149 | sys::sceGumLoadIdentity();
|
112 |
| - sys::sceGumPerspective(75.0, 16.0 / 9.0, 0.5, 1000.0); |
| 150 | + sys::sceGumPerspective(75.0, 16.0 / 9.0, 1.0, 1000.0); |
113 | 151 |
|
114 |
| - sys::sceGumMatrixMode(sys::MatrixMode::View); |
| 152 | + sys::sceGumMatrixMode(MatrixMode::View); |
| 153 | + let pos = ScePspFVector3 { |
| 154 | + x: 0.0, |
| 155 | + y: 0.0, |
| 156 | + z: -9.0, |
| 157 | + }; |
115 | 158 | sys::sceGumLoadIdentity();
|
| 159 | + sys::sceGumTranslate(&pos); |
116 | 160 |
|
117 |
| - sys::sceGumMatrixMode(sys::MatrixMode::Model); |
| 161 | + sys::sceGumMatrixMode(MatrixMode::Model); |
| 162 | + let pos = ScePspFVector3 { |
| 163 | + x: 0.0, |
| 164 | + y: -1.5, |
| 165 | + z: 0.0, |
| 166 | + }; |
118 | 167 | sys::sceGumLoadIdentity();
|
| 168 | + sys::sceGumTranslate(&pos); |
119 | 169 |
|
| 170 | + sys::sceGuColor(0xff7777); |
120 | 171 |
|
121 |
| - let pos = sys::ScePspFVector3 { x: -1.0, y: 0.0, z: -8.0 }; |
| 172 | + sys::sceGumMatrixMode(MatrixMode::Model); |
122 | 173 | let rot = ScePspFVector3 {
|
123 | 174 | x: val * 0.79 * (PI / 180.0),
|
124 | 175 | y: val * 0.98 * (PI / 180.0),
|
125 | 176 | z: val * 1.32 * (PI / 180.0),
|
126 | 177 | };
|
127 |
| - |
128 |
| - sys::sceGumTranslate(&pos); |
| 178 | + sys::sceGumLoadIdentity(); |
129 | 179 | sys::sceGumRotateXYZ(&rot);
|
130 | 180 |
|
131 |
| - sys::sceGuLight(0, sys::LightType::Pointlight, sys::LightComponent::DIFFUSE, |
132 |
| - &ScePspFVector3 { |
133 |
| - x: -1.0, y: 0.0, z: -2.0 |
134 |
| - } |
135 |
| - ); |
136 |
| - |
137 |
| - sys::sceGuLightColor(0, sys::LightComponent::DIFFUSE, 0xff00ffff); |
138 |
| - sys::sceGuMaterial(sys::LightComponent::DIFFUSE, 0xff0000ff); |
139 |
| - |
| 181 | + sys::sceGuColor(0xff0000ff); |
140 | 182 | sys::sceGumDrawArray(
|
141 | 183 | GuPrimitive::Triangles,
|
142 |
| - VertexType::VERTEX_32BITF | VertexType::TRANSFORM_3D | VertexType::INDEX_16BIT, |
143 |
| - crab::INDICES.0.len() as i32, |
144 |
| - &crab::INDICES as *const _ as *const _, |
145 |
| - &crab::VERTICES as *const _ as *const _, |
| 184 | + np_vertex_format | VertexType::TRANSFORM_3D, |
| 185 | + CRAB_VERTICES.0.len() as i32, |
| 186 | + core::ptr::null(), |
| 187 | + &CRAB_VERTICES.0 as *const _ as _, |
146 | 188 | );
|
147 |
| - |
148 | 189 | sys::sceGuFinish();
|
149 |
| - sys::sceGuSync(sys::GuSyncMode::Finish, sys::GuSyncBehavior::Wait); |
| 190 | + sys::sceGuSync(GuSyncMode::Finish, GuSyncBehavior::Wait); |
| 191 | + |
150 | 192 | sys::sceDisplayWaitVblankStart();
|
151 | 193 | sys::sceGuSwapBuffers();
|
| 194 | + |
152 | 195 | val += 1.0;
|
153 | 196 | }
|
154 | 197 | }
|
|
0 commit comments