pyxel/
settings.rs

1use crate::channel::{Note, Speed, Volume};
2use crate::image::{Color, Rgb24};
3use crate::keys::{Key, KEY_ESCAPE};
4use crate::oscillator::{Effect, Gain, ToneIndex};
5use crate::tone::{Noise, Waveform};
6
7// System
8pub const VERSION: &str = "2.3.18";
9pub const BASE_DIR: &str = ".pyxel";
10pub const WATCH_INFO_FILE_ENVVAR: &str = "PYXEL_WATCH_INFO_FILE";
11pub const DEFAULT_TITLE: &str = "Pyxel";
12pub const DEFAULT_FPS: u32 = 30;
13pub const DEFAULT_QUIT_KEY: Key = KEY_ESCAPE;
14pub const DEFAULT_CAPTURE_SCALE: u32 = 2;
15pub const DEFAULT_CAPTURE_SEC: u32 = 10;
16pub const DISPLAY_RATIO: f64 = 0.75;
17pub const BACKGROUND_COLOR: Rgb24 = 0x202224;
18pub const MAX_ELAPSED_MS: u32 = 100;
19pub const NUM_MEASURE_FRAMES: u32 = 10;
20pub const ICON_SIZE: u32 = 16;
21pub const ICON_SCALE: u32 = 4;
22pub const ICON_COLKEY: Option<Color> = Some(0);
23pub const ICON_DATA: [&str; ICON_SIZE as usize] = [
24    "0000000110000000",
25    "0000011F71100000",
26    "00011FF11FF11000",
27    "011FF111111FF110",
28    "17E1111111111C71",
29    "1E1EE111111CC1C1",
30    "1E111EE11CC111C1",
31    "1E11111E711111C1",
32    "1E111111C11111C1",
33    "1E111111C11111C1",
34    "1E111111C11111C1",
35    "17E11111C1111C71",
36    "011EE111C11CC110",
37    "00011EE1CCC11000",
38    "0000011E71100000",
39    "0000000110000000",
40];
41
42// Resource
43pub const APP_FILE_EXTENSION: &str = ".pyxapp";
44pub const APP_STARTUP_SCRIPT_FILE: &str = ".pyxapp_startup_script";
45pub const RESOURCE_FILE_EXTENSION: &str = ".pyxres";
46pub const RESOURCE_ARCHIVE_NAME: &str = "pyxel_resource.toml";
47pub const RESOURCE_FORMAT_VERSION: u32 = 4;
48pub const PALETTE_FILE_EXTENSION: &str = ".pyxpal";
49
50// Graphics
51pub const NUM_COLORS: u32 = 16;
52pub const MAX_COLORS: u32 = 255;
53pub const NUM_IMAGES: u32 = 3;
54pub const IMAGE_SIZE: u32 = 256;
55pub const NUM_TILEMAPS: u32 = 8;
56pub const TILEMAP_SIZE: u32 = 256;
57pub const TILE_SIZE: u32 = 8;
58pub const DEFAULT_COLORS: [Rgb24; NUM_COLORS as usize] = [
59    0x000000, 0x2b335f, 0x7e2072, 0x19959c, 0x8b4852, 0x395c98, 0xa9c1ff, 0xeeeeee, //
60    0xd4186c, 0xd38441, 0xe9c35b, 0x70c6a9, 0x7696de, 0xa3a3a3, 0xFF9798, 0xedc7b0,
61];
62pub const COLOR_BLACK: Color = 0;
63pub const COLOR_NAVY: Color = 1;
64pub const COLOR_PURPLE: Color = 2;
65pub const COLOR_GREEN: Color = 3;
66pub const COLOR_BROWN: Color = 4;
67pub const COLOR_DARK_BLUE: Color = 5;
68pub const COLOR_LIGHT_BLUE: Color = 6;
69pub const COLOR_WHITE: Color = 7;
70pub const COLOR_RED: Color = 8;
71pub const COLOR_ORANGE: Color = 9;
72pub const COLOR_YELLOW: Color = 10;
73pub const COLOR_LIME: Color = 11;
74pub const COLOR_CYAN: Color = 12;
75pub const COLOR_GRAY: Color = 13;
76pub const COLOR_PINK: Color = 14;
77pub const COLOR_PEACH: Color = 15;
78pub const CURSOR_WIDTH: u32 = 8;
79pub const CURSOR_HEIGHT: u32 = 8;
80pub const CURSOR_DATA: [&str; CURSOR_HEIGHT as usize] = [
81    "11111100", "17776100", "17761000", "17676100", "16167610", "11016761", "00001610", "00000100",
82];
83pub const MIN_FONT_CODE: char = 32 as char;
84pub const MAX_FONT_CODE: char = 127 as char;
85pub const NUM_FONT_ROWS: u32 = 16;
86pub const FONT_WIDTH: u32 = 4;
87pub const FONT_HEIGHT: u32 = 6;
88pub const FONT_DATA: [u32; MAX_FONT_CODE as usize - MIN_FONT_CODE as usize + 1] = [
89    0x000000, 0x444040, 0xaa0000, 0xaeaea0, 0x6c6c40, 0x824820, 0x4a4ac0, 0x440000, 0x244420,
90    0x844480, 0xa4e4a0, 0x04e400, 0x000480, 0x00e000, 0x000040, 0x224880, 0x6aaac0, 0x4c4440,
91    0xc248e0, 0xc242c0, 0xaae220, 0xe8c2c0, 0x68eae0, 0xe24880, 0xeaeae0, 0xeae2c0, 0x040400,
92    0x040480, 0x248420, 0x0e0e00, 0x842480, 0xe24040, 0x4aa860, 0x4aeaa0, 0xcacac0, 0x688860,
93    0xcaaac0, 0xe8e8e0, 0xe8e880, 0x68ea60, 0xaaeaa0, 0xe444e0, 0x222a40, 0xaacaa0, 0x8888e0,
94    0xaeeaa0, 0xcaaaa0, 0x4aaa40, 0xcac880, 0x4aae60, 0xcaeca0, 0x6842c0, 0xe44440, 0xaaaa60,
95    0xaaaa40, 0xaaeea0, 0xaa4aa0, 0xaa4440, 0xe248e0, 0x644460, 0x884220, 0xc444c0, 0x4a0000,
96    0x0000e0, 0x840000, 0x06aa60, 0x8caac0, 0x068860, 0x26aa60, 0x06ac60, 0x24e440, 0x06ae24,
97    0x8caaa0, 0x404440, 0x2022a4, 0x8acca0, 0xc444e0, 0x0eeea0, 0x0caaa0, 0x04aa40, 0x0caac8,
98    0x06aa62, 0x068880, 0x06c6c0, 0x4e4460, 0x0aaa60, 0x0aaa40, 0x0aaee0, 0x0a44a0, 0x0aa624,
99    0x0e24e0, 0x64c460, 0x444440, 0xc464c0, 0x6c0000, 0xeeeee0,
100];
101pub const NUM_SCREEN_TYPES: u32 = 3;
102
103// Audio
104pub const CLOCK_RATE: u32 = 2_048_000; // 2.048MHz
105pub const SAMPLE_RATE: u32 = 22050; // 22.05kHz
106pub const NUM_SAMPLES: u32 = 512; // 512 / 22050 = 23.2ms
107pub const TICKS_PER_SECOND: u32 = 120;
108pub const CLOCKS_PER_TICK: u32 = CLOCK_RATE / TICKS_PER_SECOND;
109pub const OSCILLATOR_RESOLUTION: u32 = 32;
110pub const VIBRATO_DEPTH: f64 = 0.015;
111pub const VIBRATO_FREQUENCY: f64 = 6.0;
112
113pub const NUM_CHANNELS: u32 = 4;
114pub const NUM_TONES: u32 = 4;
115pub const NUM_SOUNDS: u32 = 64;
116pub const NUM_MUSICS: u32 = 8;
117pub const NUM_WAVEFORM_STEPS: u32 = 32;
118
119pub const INITIAL_CHANNEL_GAIN: Gain = 0.125;
120pub const INITIAL_SOUND_SPEED: Speed = 30;
121pub const INITIAL_NOISE_REG: u16 = 1 << 14;
122
123pub const TONE_TRIANGLE: ToneIndex = 0;
124pub const TONE_SQUARE: ToneIndex = 1;
125pub const TONE_PULSE: ToneIndex = 2;
126pub const TONE_NOISE: ToneIndex = 3;
127
128pub const EFFECT_NONE: Effect = 0;
129pub const EFFECT_SLIDE: Effect = 1;
130pub const EFFECT_VIBRATO: Effect = 2;
131pub const EFFECT_FADEOUT: Effect = 3;
132pub const EFFECT_HALF_FADEOUT: Effect = 4;
133pub const EFFECT_QUARTER_FADEOUT: Effect = 5;
134
135pub const MAX_TONE: ToneIndex = 9;
136pub const MAX_NOTE: Note = 12 * 5 - 1; // 5 octaves
137pub const MAX_VOLUME: Volume = 7;
138pub const MAX_EFFECT: Effect = 5;
139
140pub const DEFAULT_TONES: [(Gain, Noise, Waveform); NUM_TONES as usize] = [
141    // Triangle
142    (
143        1.0,
144        Noise::Off,
145        [
146            8, 9, 10, 11, 12, 13, 14, 15, 15, 14, 13, 12, 11, 10, 9, 8, //
147            7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 7,
148        ],
149    ),
150    // Square
151    (
152        0.3,
153        Noise::Off,
154        [
155            15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, //
156            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
157        ],
158    ),
159    // Pulse
160    (
161        0.3,
162        Noise::Off,
163        [
164            15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, //
165            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
166        ],
167    ),
168    // Noise
169    (0.6, Noise::LongPeriod, [0; 32]),
170];