Skip to content

Commit 1c52347

Browse files
committed
Add screen scale settings
1 parent b734972 commit 1c52347

File tree

5 files changed

+118
-26
lines changed

5 files changed

+118
-26
lines changed

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,13 @@ pub fn actual_main() {
505505
key_map.store(keymap, Ordering::Relaxed);
506506
false
507507
}
508-
PresentEvent::CycleScreenLayout { offset, swap } => {
509-
screen_layout = screen_layout.apply_settings_event(offset, swap);
508+
PresentEvent::CycleScreenLayout {
509+
offset,
510+
swap,
511+
top_screen_scale_offset,
512+
bottom_screen_scale_offset,
513+
} => {
514+
screen_layout = screen_layout.apply_settings_event(offset, swap, top_screen_scale_offset, bottom_screen_scale_offset);
510515
false
511516
}
512517
PresentEvent::Pause => true,

src/presenter/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ pub const PRESENTER_SCREEN_WIDTH: u32 = 960;
1818
pub const PRESENTER_SCREEN_HEIGHT: u32 = 544;
1919

2020
pub enum PresentEvent {
21-
Inputs { keymap: u32, touch: Option<(i16, i16)> },
22-
CycleScreenLayout { offset: i8, swap: bool },
21+
Inputs {
22+
keymap: u32,
23+
touch: Option<(i16, i16)>,
24+
},
25+
CycleScreenLayout {
26+
offset: i8,
27+
swap: bool,
28+
top_screen_scale_offset: i8,
29+
bottom_screen_scale_offset: i8,
30+
},
2331
Pause,
2432
Quit,
2533
}

src/presenter/vita.rs

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,52 @@ impl Presenter {
141141
self.pressed_btn = pressed.buttons;
142142

143143
if pressed.buttons & SCE_CTRL_PSBUTTON != 0 {
144-
const SHORTCUT_EVENTS: [(PresentEvent, SceCtrlButtons); 3] = [
145-
(PresentEvent::CycleScreenLayout { offset: -1, swap: false }, SCE_CTRL_LTRIGGER),
146-
(PresentEvent::CycleScreenLayout { offset: 1, swap: false }, SCE_CTRL_RTRIGGER),
147-
(PresentEvent::CycleScreenLayout { offset: 0, swap: true }, SCE_CTRL_CROSS),
144+
const SHORTCUT_EVENTS: [(PresentEvent, SceCtrlButtons); 5] = [
145+
(
146+
PresentEvent::CycleScreenLayout {
147+
offset: -1,
148+
swap: false,
149+
top_screen_scale_offset: 0,
150+
bottom_screen_scale_offset: 0,
151+
},
152+
SCE_CTRL_LTRIGGER,
153+
),
154+
(
155+
PresentEvent::CycleScreenLayout {
156+
offset: 1,
157+
swap: false,
158+
top_screen_scale_offset: 0,
159+
bottom_screen_scale_offset: 0,
160+
},
161+
SCE_CTRL_RTRIGGER,
162+
),
163+
(
164+
PresentEvent::CycleScreenLayout {
165+
offset: 0,
166+
swap: true,
167+
top_screen_scale_offset: 0,
168+
bottom_screen_scale_offset: 0,
169+
},
170+
SCE_CTRL_CROSS,
171+
),
172+
(
173+
PresentEvent::CycleScreenLayout {
174+
offset: 0,
175+
swap: false,
176+
top_screen_scale_offset: 0,
177+
bottom_screen_scale_offset: 1,
178+
},
179+
SCE_CTRL_CIRCLE,
180+
),
181+
(
182+
PresentEvent::CycleScreenLayout {
183+
offset: 0,
184+
swap: false,
185+
top_screen_scale_offset: 1,
186+
bottom_screen_scale_offset: 0,
187+
},
188+
SCE_CTRL_SQUARE,
189+
),
148190
];
149191

150192
for (event, button) in SHORTCUT_EVENTS {

src/screen_layouts.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,59 @@ use crate::presenter::{PRESENTER_SCREEN_HEIGHT, PRESENTER_SCREEN_WIDTH};
44
use crate::settings::SettingValue;
55
use screenlayouts::SCREEN_LAYOUTS;
66

7+
const SCALE_FACTORS: [f32; 8] = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0];
8+
79
pub struct ScreenLayout {
810
pub index: usize,
911
pub swap: bool,
12+
top_scale_index: usize,
13+
bottom_scale_index: usize,
1014
overlap: bool,
1115
screen_top: [f32; 16],
1216
screen_bottom: [f32; 16],
17+
bottom_inverse_mtx: [f32; 9],
1318
}
1419

1520
impl ScreenLayout {
1621
pub fn settings_value() -> SettingValue {
1722
SettingValue::List(0, SCREEN_LAYOUTS.iter().map(|(name, _)| name.to_string()).collect())
1823
}
1924

20-
pub fn new(index: usize, swap: bool) -> Self {
25+
pub fn scale_settings_value() -> SettingValue {
26+
SettingValue::List(3, SCALE_FACTORS.iter().map(|factor| format!("{}%", (factor * 100.0) as u8)).collect())
27+
}
28+
29+
fn scale_matrix(factor: f32) -> [f32; 9] {
30+
[factor, 0.0, 0.0, 0.0, factor, 0.0, 0.0, 0.0, 1.0]
31+
}
32+
33+
pub fn new(index: usize, swap: bool, top_scale_index: usize, bottom_scale_index: usize) -> Self {
2134
const GUEST_DISPLAY_DIM_MTX: [[f32; 3]; 4] = [
2235
[-(DISPLAY_WIDTH as f32 / 2.0), -(DISPLAY_HEIGHT as f32 / 2.0), 1.0],
2336
[DISPLAY_WIDTH as f32 / 2.0, -(DISPLAY_HEIGHT as f32 / 2.0), 1.0],
2437
[DISPLAY_WIDTH as f32 / 2.0, DISPLAY_HEIGHT as f32 / 2.0, 1.0],
2538
[-(DISPLAY_WIDTH as f32 / 2.0), DISPLAY_HEIGHT as f32 / 2.0, 1.0],
2639
];
27-
let a_mtx = &SCREEN_LAYOUTS[index].1[0];
28-
let b_mtx = &SCREEN_LAYOUTS[index].1[1];
40+
let mut a_mtx = SCREEN_LAYOUTS[index].1[0];
41+
let mut b_mtx = SCREEN_LAYOUTS[index].1[1];
42+
43+
let top_scale_mtx = Self::scale_matrix(SCALE_FACTORS[top_scale_index]);
44+
let bottom_scale_mtx = Self::scale_matrix(SCALE_FACTORS[bottom_scale_index]);
45+
46+
unsafe {
47+
math::neon::matmul3_neon(a_mtx.as_ptr() as _, top_scale_mtx.as_ptr() as _, a_mtx.as_mut_ptr());
48+
math::neon::matmul3_neon(b_mtx.as_ptr() as _, bottom_scale_mtx.as_ptr() as _, b_mtx.as_mut_ptr());
49+
}
50+
2951
let mut screen_top = [[0.0; 3]; 4];
3052
let mut screen_bottom = [[0.0; 3]; 4];
53+
let mut bottom_inverse_mtx = SCREEN_LAYOUTS[index].1[if swap { 2 } else { 3 }];
54+
55+
unsafe {
56+
let inverse_scale_mtx = Self::scale_matrix(1.0 / SCALE_FACTORS[if swap { top_scale_index } else { bottom_scale_index }]);
57+
math::neon::matmul3_neon(inverse_scale_mtx.as_ptr() as _, bottom_inverse_mtx.as_ptr() as _, bottom_inverse_mtx.as_mut_ptr());
58+
}
59+
3160
let overlap = unsafe {
3261
for i in 0..GUEST_DISPLAY_DIM_MTX.len() {
3362
math::neon::matvec3_neon(a_mtx.as_ptr() as _, GUEST_DISPLAY_DIM_MTX[i].as_ptr() as _, screen_top[i].as_mut_ptr());
@@ -52,9 +81,12 @@ impl ScreenLayout {
5281

5382
overlap
5483
};
84+
5585
ScreenLayout {
5686
index,
5787
swap,
88+
top_scale_index,
89+
bottom_scale_index,
5890
overlap,
5991
screen_top: [
6092
screen_top[0][0],
@@ -92,23 +124,22 @@ impl ScreenLayout {
92124
0.0,
93125
0.0,
94126
],
127+
bottom_inverse_mtx,
95128
}
96129
}
97130

98-
pub fn apply_settings_event(&self, offset: i8, swap: bool) -> ScreenLayout {
131+
pub fn apply_settings_event(&self, offset: i8, swap: bool, top_screen_scale_offset: i8, bottom_screen_scale_offset: i8) -> ScreenLayout {
99132
ScreenLayout::new(
100133
((SCREEN_LAYOUTS.len() as isize + (self.index as isize + offset as isize)) % SCREEN_LAYOUTS.len() as isize) as usize,
101134
self.swap ^ swap,
135+
((SCALE_FACTORS.len() as isize + (self.top_scale_index as isize + top_screen_scale_offset as isize)) % SCALE_FACTORS.len() as isize) as usize,
136+
((SCALE_FACTORS.len() as isize + (self.bottom_scale_index as isize + bottom_screen_scale_offset as isize)) % SCALE_FACTORS.len() as isize) as usize,
102137
)
103138
}
104139

105-
pub fn get_bottom_inverse_mtx(&self) -> &[f32; 9] {
106-
&SCREEN_LAYOUTS[self.index].1[if self.swap { 2 } else { 3 }]
107-
}
108-
109140
pub fn normalize_touch_points(&self, x: i16, y: i16) -> (i16, i16) {
110141
let mut touch_points = [x as f32, y as f32, 1.0];
111-
unsafe { math::neon::matvec3_neon(self.get_bottom_inverse_mtx().as_ptr() as _, touch_points.as_ptr() as _, touch_points.as_mut_ptr() as _) };
142+
unsafe { math::neon::matvec3_neon(self.bottom_inverse_mtx.as_ptr() as _, touch_points.as_ptr() as _, touch_points.as_mut_ptr() as _) };
112143
(touch_points[0] as i16 + DISPLAY_WIDTH as i16 / 2, touch_points[1] as i16 + DISPLAY_HEIGHT as i16 / 2)
113144
}
114145

src/settings.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ lazy_static! {
159159
pub static ref DEFAULT_SETTINGS: Settings = Settings(
160160
[
161161
Setting::new("Screen Layout", "Press PS + L Trigger or PS + R Trigger to cycle through layouts in game.", ScreenLayout::settings_value(), true),
162-
Setting::new("Swap screens", "Press PS + X to swap screens in game.", SettingValue::Bool(false), true),
162+
Setting::new("Swap screens", "Press PS + Cross to swap screens in game.", SettingValue::Bool(false), true),
163+
Setting::new("Top screen scale", "Press PS + Square to cycle screen sizes.", ScreenLayout::scale_settings_value(), true),
164+
Setting::new("Bottom screen scale", "Press PS + Circle to cycle screen sizes", ScreenLayout::scale_settings_value(), true),
163165
Setting::new("Language", "Some ROMs only come with one language. Make sure yours is multilingual.", Language::iter().into(), false),
164166
Setting::new("Joystick as D-Pad", "", SettingValue::Bool(true), true),
165167
Setting::new("Framelimit", "Limits gamespeed to 60fps", SettingValue::Bool(true), true),
@@ -181,23 +183,27 @@ lazy_static! {
181183
}
182184

183185
#[derive(Clone)]
184-
pub struct Settings([Setting; 8]);
186+
pub struct Settings([Setting; 10]);
185187

186188
const SCREEN_LAYOUT_SETTING: usize = 0;
187189
const SWAP_SCREEN_SETTING: usize = 1;
188-
const LANGUAGE_SETTING: usize = 2;
189-
const JOYSTICK_AS_DPAD_SETTING: usize = 3;
190-
const FRAMELIMIT_SETTING: usize = 4;
191-
const AUDIO_SETTING: usize = 5;
192-
const ARM7_EMU_SETTING: usize = 6;
193-
const ARM7_BLOCK_VALIDATION_SETTING: usize = 7;
190+
const TOP_SCREEN_SCALE_SETTING: usize = 2;
191+
const BOTTOM_SCREEN_SCALE_SETTING: usize = 3;
192+
const LANGUAGE_SETTING: usize = 4;
193+
const JOYSTICK_AS_DPAD_SETTING: usize = 5;
194+
const FRAMELIMIT_SETTING: usize = 6;
195+
const AUDIO_SETTING: usize = 7;
196+
const ARM7_EMU_SETTING: usize = 8;
197+
const ARM7_BLOCK_VALIDATION_SETTING: usize = 9;
194198

195199
impl Settings {
196200
pub fn screen_layout(&self) -> ScreenLayout {
197201
unsafe {
198202
ScreenLayout::new(
199203
self.0[SCREEN_LAYOUT_SETTING].value.as_list().unwrap_unchecked().0,
200204
self.0[SWAP_SCREEN_SETTING].value.as_bool().unwrap_unchecked(),
205+
self.0[TOP_SCREEN_SCALE_SETTING].value.as_list().unwrap_unchecked().0,
206+
self.0[BOTTOM_SCREEN_SCALE_SETTING].value.as_list().unwrap_unchecked().0,
201207
)
202208
}
203209
}
@@ -247,7 +253,7 @@ impl Settings {
247253
*self.0[ARM7_BLOCK_VALIDATION_SETTING].value.as_bool_mut().unwrap() = value;
248254
}
249255

250-
pub fn get_all_mut(&mut self) -> &mut [Setting; 8] {
256+
pub fn get_all_mut(&mut self) -> &mut [Setting; 10] {
251257
&mut self.0
252258
}
253259
}

0 commit comments

Comments
 (0)