Skip to content

Commit eb7c01f

Browse files
committed
Add fmt::Display for Time, and a basic video memory API.
1 parent 1defc9b commit eb7c01f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ license = "GPL-3.0-or-later"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12+
chrono = { version = "0.4", default-features=false }

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ pub struct Api {
164164
/// fix). The BIOS should push the time out to the battery-backed Real
165165
/// Time Clock, if it has one.
166166
pub time_set: extern "C" fn(time: Time),
167+
/// Get the memory address for the video buffer.
168+
///
169+
/// Currently this only supports text mode. Each character on screen uses
170+
/// two consecutive bytes - one for the glyph and one for the attribute.
171+
pub video_memory_info_get:
172+
extern "C" fn(address: &mut *mut u8, width_cols: &mut u8, height_rows: &mut u8),
167173
}
168174

169175
/// Serial Port / UART related types.
@@ -348,4 +354,16 @@ impl core::fmt::Display for ApiString<'_> {
348354
}
349355
}
350356

357+
impl core::fmt::Display for Time {
358+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::result::Result<(), core::fmt::Error> {
359+
use chrono::prelude::*;
360+
let our_epoch = Utc.ymd(2001, 1, 1).and_hms(0, 0, 0).timestamp();
361+
let time = chrono::Utc.timestamp(
362+
i64::from(self.seconds_since_epoch) + our_epoch,
363+
((u32::from(self.frames_since_second) * 1_000_000) / 60) * 1_000,
364+
);
365+
write!(f, "{}", time)
366+
}
367+
}
368+
351369
// End of file

0 commit comments

Comments
 (0)