pub trait ScreenDataProvider {
    fn get_screen_mode(&self) -> ScrMode;
    fn set_screen_mode(&mut self, mode: ScrMode) -> bool;
    fn screen_primary_ref(&self) -> &ScreenArray;
    fn screen_primary_mut(&mut self) -> &mut ScreenArray;

    fn screen_secondary_ref(&self) -> &ScreenArray { ... }
    fn screen_secondary_mut(&mut self) -> &mut ScreenArray { ... }
    fn screen_palette_ref(&self) -> &[u8; 64] { ... }
    fn screen_palette_mut(&mut self) -> &mut [u8; 64] { ... }
}
Expand description

This trait should be implemented by the core chipset emulator types.

Required Methods§

Should return a currently selected screen mode.

Should set a requested screen mode and return true. If the provided mode can not be set this method should return false.

Should return a reference to the primary screen data.

Should return a mutable reference to the primary screen data.

Provided Methods§

Should return a reference to the secondary screen data.

Panics

This method may panic if the secondary screen is not supported by the underlying implementation.

Examples found in repository?
src/scr.rs (line 166)
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    fn save_scr<W: Write>(&self, mut dst: W) -> io::Result<()> {
        let mode = self.get_screen_mode();
        match mode {
            ScrMode::Classic(..) => dst.write_all(self.screen_primary_ref())?,
            ScrMode::HighColor(..)|ScrMode::HighRes(..) => {
                dst.write_all(&self.screen_primary_ref()[0..PIXELS_SIZE])?;
                dst.write_all(&self.screen_secondary_ref()[0..PIXELS_SIZE])?;
            }
        }
        if let ScrMode::HighRes(outmode, ..) = mode {
            dst.write_all(slice::from_ref(&outmode))?;
        }
        if let ScrMode::Classic(true)|
               ScrMode::HighColor(true)|
               ScrMode::HighRes(.., true) = mode {
            dst.write_all(self.screen_palette_ref())?;
        }
        Ok(())
    }

Should return a mutable reference to the secondary screen data.

Panics

This method may panic if the secondary screen is not supported by the underlying implementation.

Examples found in repository?
src/scr.rs (line 149)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    fn load_scr<R: Read + Seek>(&mut self, mut src: R) -> io::Result<()> {
        let end = src.seek(SeekFrom::End(0))?;
        let mode = match end {
            SCR_SIZE => ScrMode::Classic(false),
            SCR_PLUS_SIZE => ScrMode::Classic(true),
            SCR_HICOLOR_SIZE => ScrMode::HighColor(false),
            SCR_HICOLOR_PLUS_SIZE => ScrMode::HighColor(true),
            SCR_HIRES_SIZE|SCR_HIRES_PLUS_SIZE => {
                src.seek(SeekFrom::Current(
                    if end == SCR_HIRES_PLUS_SIZE {
                        -(PALETTE_SIZE as i64) - 1
                    }
                    else {
                        -1
                    }
                ))?;
                let mut color: u8 = 0;
                src.read_exact(slice::from_mut(&mut color))?;
                ScrMode::HighRes(color, end == SCR_HIRES_PLUS_SIZE)
            }
            _ => {
                return Err(io::Error::new(io::ErrorKind::InvalidData, "Screen format not recognized"));
            }
        };
        if !self.set_screen_mode(mode) {
            return Err(io::Error::new(io::ErrorKind::InvalidInput, "Screen format not supported"));
        }
        src.seek(SeekFrom::Start(0))?;
        match end {
            SCR_SIZE|SCR_PLUS_SIZE => {
                src.read_exact(self.screen_primary_mut())?;
            }
            SCR_HICOLOR_SIZE|SCR_HICOLOR_PLUS_SIZE|
            SCR_HIRES_SIZE|SCR_HIRES_PLUS_SIZE => {
                src.read_exact(&mut self.screen_primary_mut()[0..PIXELS_SIZE])?;
                src.read_exact(&mut self.screen_secondary_mut()[0..PIXELS_SIZE])?;
            }
            _ => {}
        }
        if let SCR_PLUS_SIZE|SCR_HICOLOR_PLUS_SIZE|SCR_HIRES_PLUS_SIZE = end {
            src.seek(SeekFrom::Start(end - PALETTE_SIZE))?;
            src.read_exact(self.screen_palette_mut())?;
        }
        Ok(())
    }

Should return a reference to the ULAplus palette.

Panics

This method may panic if ULAplus is not supported by the underlying implementation.

Examples found in repository?
src/scr.rs (line 175)
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    fn save_scr<W: Write>(&self, mut dst: W) -> io::Result<()> {
        let mode = self.get_screen_mode();
        match mode {
            ScrMode::Classic(..) => dst.write_all(self.screen_primary_ref())?,
            ScrMode::HighColor(..)|ScrMode::HighRes(..) => {
                dst.write_all(&self.screen_primary_ref()[0..PIXELS_SIZE])?;
                dst.write_all(&self.screen_secondary_ref()[0..PIXELS_SIZE])?;
            }
        }
        if let ScrMode::HighRes(outmode, ..) = mode {
            dst.write_all(slice::from_ref(&outmode))?;
        }
        if let ScrMode::Classic(true)|
               ScrMode::HighColor(true)|
               ScrMode::HighRes(.., true) = mode {
            dst.write_all(self.screen_palette_ref())?;
        }
        Ok(())
    }

Should return a mutable reference to the ULAplus palette.

Panics

This method may panic if ULAplus is not supported by the underlying implementation.

Examples found in repository?
src/scr.rs (line 155)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    fn load_scr<R: Read + Seek>(&mut self, mut src: R) -> io::Result<()> {
        let end = src.seek(SeekFrom::End(0))?;
        let mode = match end {
            SCR_SIZE => ScrMode::Classic(false),
            SCR_PLUS_SIZE => ScrMode::Classic(true),
            SCR_HICOLOR_SIZE => ScrMode::HighColor(false),
            SCR_HICOLOR_PLUS_SIZE => ScrMode::HighColor(true),
            SCR_HIRES_SIZE|SCR_HIRES_PLUS_SIZE => {
                src.seek(SeekFrom::Current(
                    if end == SCR_HIRES_PLUS_SIZE {
                        -(PALETTE_SIZE as i64) - 1
                    }
                    else {
                        -1
                    }
                ))?;
                let mut color: u8 = 0;
                src.read_exact(slice::from_mut(&mut color))?;
                ScrMode::HighRes(color, end == SCR_HIRES_PLUS_SIZE)
            }
            _ => {
                return Err(io::Error::new(io::ErrorKind::InvalidData, "Screen format not recognized"));
            }
        };
        if !self.set_screen_mode(mode) {
            return Err(io::Error::new(io::ErrorKind::InvalidInput, "Screen format not supported"));
        }
        src.seek(SeekFrom::Start(0))?;
        match end {
            SCR_SIZE|SCR_PLUS_SIZE => {
                src.read_exact(self.screen_primary_mut())?;
            }
            SCR_HICOLOR_SIZE|SCR_HICOLOR_PLUS_SIZE|
            SCR_HIRES_SIZE|SCR_HIRES_PLUS_SIZE => {
                src.read_exact(&mut self.screen_primary_mut()[0..PIXELS_SIZE])?;
                src.read_exact(&mut self.screen_secondary_mut()[0..PIXELS_SIZE])?;
            }
            _ => {}
        }
        if let SCR_PLUS_SIZE|SCR_HICOLOR_PLUS_SIZE|SCR_HIRES_PLUS_SIZE = end {
            src.seek(SeekFrom::Start(end - PALETTE_SIZE))?;
            src.read_exact(self.screen_palette_mut())?;
        }
        Ok(())
    }

Implementors§