1use serde::{Deserialize, Serialize};
2
3use crate::consts::{SCREEN_HEIGHT, SCREEN_WIDTH};
4
5#[derive(Default, Clone, Debug, Serialize, Deserialize)]
6pub struct Input {
7 pub pad: Pad,
8}
9
10#[derive(Default, Clone, Debug, Serialize, Deserialize)]
11pub struct Pad {
12 pub up: bool,
13 pub down: bool,
14 pub left: bool,
15 pub right: bool,
16 pub a: bool,
17 pub b: bool,
18 pub start: bool,
19 pub select: bool,
20}
21
22#[derive(Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
23pub struct Color {
24 pub r: u8,
25 pub g: u8,
26 pub b: u8,
27}
28
29impl Color {
30 pub const fn new(r: u8, g: u8, b: u8) -> Self {
31 Self { r, g, b }
32 }
33}
34
35#[derive(Clone)]
36pub struct FrameBuffer {
37 pub width: usize,
38 pub height: usize,
39 pub buf: Vec<Color>,
40}
41
42impl Default for FrameBuffer {
43 fn default() -> Self {
44 Self::new(SCREEN_WIDTH as _, SCREEN_HEIGHT as _)
45 }
46}
47
48impl FrameBuffer {
49 pub fn new(width: usize, height: usize) -> Self {
50 Self {
51 width,
52 height,
53 buf: vec![Color::new(0, 0, 0); width * height],
54 }
55 }
56
57 pub fn get(&self, x: usize, y: usize) -> Color {
58 assert!(x < self.width);
59 assert!(y < self.height);
60 self.buf[y * self.width + x]
61 }
62
63 pub fn set(&mut self, x: usize, y: usize, color: Color) {
64 assert!(x < self.width);
65 assert!(y < self.height);
66 self.buf[y * self.width + x] = color;
67 }
68}
69
70#[derive(Default)]
71pub struct AudioBuffer {
72 pub buf: Vec<AudioSample>,
73}
74
75impl AudioBuffer {
76 pub fn new() -> Self {
77 Self { buf: vec![] }
78 }
79}
80
81pub struct AudioSample {
82 pub right: i16,
83 pub left: i16,
84}
85
86impl AudioSample {
87 pub fn new(right: i16, left: i16) -> Self {
88 Self { right, left }
89 }
90}
91
92pub trait LinkCable {
93 fn send(&mut self, data: u8);
94 fn try_recv(&mut self) -> Option<u8>;
95}