Skip to content

Commit f8bb29f

Browse files
authored
Merge pull request #13 from Neotron-Compute/ansi-console
Add Colour Text and other changes.
2 parents 7c4cccb + ab31b86 commit f8bb29f

File tree

10 files changed

+363
-86
lines changed

10 files changed

+363
-86
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Jonathan 'theJPster' Pallant <[email protected]>"]
55
edition = "2018"
66
description = "Common BIOS code and API for all Neotron systems."
77
license = "GPL-3.0-or-later"
8-
respository = "https://github.com/neotron-compute/neotron-common-bios.git"
8+
repository = "https://github.com/neotron-compute/neotron-common-bios.git"
99
homepage = "https://github.com/neotron-compute/neotron-common-bios"
1010
readme = "README.md"
1111

src/audio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! Audio related types.
44
//!
5-
//! Note that all types in this file *must* be `#[repr(C)]` and ABI stable.
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
67
78
// Copyright (C) The Neotron Developers, 2019-2022
89
//

src/bus.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! Neotron Bus related types.
44
//!
5-
//! Note that all types in this file *must* be `#[repr(C)]` and ABI stable.
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
67
78
// Copyright (C) The Neotron Developers, 2019-2022
89
//

src/hid.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! Human Interface Device (keyboard/mouse) related types.
44
//!
5-
//! Note that all types in this file *must* be `#[repr(C)]` and ABI stable.
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
67
78
// Copyright (C) The Neotron Developers, 2019-2022
89
//

src/i2c.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! I²C Bus related types.
44
//!
5-
//! Note that all types in this file *must* be `#[repr(C)]` and ABI stable.
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
67
78
// Copyright (C) The Neotron Developers, 2019-2022
89
//

src/lib.rs

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub const API_VERSION: Version = Version::new(0, 6, 1);
5555
/// function.
5656
#[repr(C)]
5757
pub struct Api {
58+
// ========================================================================
59+
// Version and Metadata
60+
// ========================================================================
5861
/// Gets the version number of the BIOS API.
5962
///
6063
/// You need this value to determine which of the following API calls are
@@ -69,6 +72,10 @@ pub struct Api {
6972
/// a Rust string. It is unspecified as to whether the string is located
7073
/// in Flash ROM or RAM (but it's likely to be Flash ROM).
7174
pub bios_version_get: extern "C" fn() -> ApiString<'static>,
75+
76+
// ========================================================================
77+
// Serial Port Support
78+
// ========================================================================
7279
/// Get information about the Serial ports in the system.
7380
///
7481
/// Serial ports are ordered octet-oriented pipes. You can push octets
@@ -106,6 +113,10 @@ pub struct Api {
106113
data: ApiBuffer,
107114
timeout: crate::Option<Timeout>,
108115
) -> crate::Result<usize>,
116+
117+
// ========================================================================
118+
// Time Support
119+
// ========================================================================
109120
/// Get the current wall time.
110121
///
111122
/// The Neotron BIOS does not understand time zones, leap-seconds or the
@@ -119,7 +130,7 @@ pub struct Api {
119130
/// If the BIOS does not have a battery-backed clock, or if that battery
120131
/// has failed to keep time, the system starts up assuming it is the
121132
/// epoch.
122-
pub time_get: extern "C" fn() -> Time,
133+
pub time_clock_get: extern "C" fn() -> Time,
123134
/// Set the current wall time.
124135
///
125136
/// See `time_get` for a description of now the Neotron BIOS should handle
@@ -129,7 +140,17 @@ pub struct Api {
129140
/// time (e.g. the user has updated the current time, or if you get a GPS
130141
/// fix). The BIOS should push the time out to the battery-backed Real
131142
/// Time Clock, if it has one.
132-
pub time_set: extern "C" fn(time: Time),
143+
pub time_clock_set: extern "C" fn(time: Time),
144+
/// Get the current monotonic system time.
145+
///
146+
/// This value will never go backwards and it should never wrap.
147+
pub time_ticks_get: extern "C" fn() -> Ticks,
148+
/// Report the system tick rate, in ticks-per-second.
149+
pub time_ticks_per_second: extern "C" fn() -> Ticks,
150+
151+
// ========================================================================
152+
// Persistent Configuration Support
153+
// ========================================================================
133154
/// Get the configuration data block.
134155
///
135156
/// Configuration data is, to the BIOS, just a block of bytes of a given
@@ -140,6 +161,10 @@ pub struct Api {
140161
///
141162
/// See `configuration_get`.
142163
pub configuration_set: extern "C" fn(buffer: ApiByteSlice) -> crate::Result<()>,
164+
165+
// ========================================================================
166+
// Video Output Support
167+
// ========================================================================
143168
/// Does this Neotron BIOS support this video mode?
144169
pub video_is_valid_mode: extern "C" fn(mode: video::Mode) -> bool,
145170
/// Does this Neotron BIOS require extra VRAM (passed with
@@ -255,6 +280,10 @@ pub struct Api {
255280
///
256281
pub video_set_whole_palette:
257282
unsafe extern "C" fn(start: *const video::RGBColour, length: usize),
283+
284+
// ========================================================================
285+
// Memory Region Support
286+
// ========================================================================
258287
/// Find out about regions of memory in the system.
259288
///
260289
/// The first region (index `0`) must be the 'application region' which is
@@ -272,12 +301,20 @@ pub struct Api {
272301
/// application space available). The OS will prefer lower numbered regions
273302
/// (other than Region 0), so faster memory should be listed first.
274303
pub memory_get_region: extern "C" fn(region_index: u8) -> crate::Result<types::MemoryRegion>,
304+
305+
// ========================================================================
306+
// Human Interface Device Support
307+
// ========================================================================
275308
/// Get the next available HID event, if any.
276309
///
277310
/// This function doesn't block. It will return `Ok(None)` if there is no event ready.
278311
pub hid_get_event: extern "C" fn() -> crate::Result<crate::Option<hid::HidEvent>>,
279312
/// Control the keyboard LEDs.
280313
pub hid_set_leds: extern "C" fn(leds: hid::KeyboardLeds) -> crate::Result<()>,
314+
315+
// ========================================================================
316+
// I²C Bus Support
317+
// ========================================================================
281318
/// Get information about the I²C Buses in the system.
282319
///
283320
/// I²C Bus 0 should be the one connected to the Neotron Bus.
@@ -309,6 +346,10 @@ pub struct Api {
309346
tx2: ApiByteSlice,
310347
rx: ApiBuffer,
311348
) -> crate::Result<()>,
349+
350+
// ========================================================================
351+
// Audio Support
352+
// ========================================================================
312353
/// Get information about the Audio Mixer channels
313354
pub audio_mixer_channel_get_info:
314355
extern "C" fn(audio_mixer_id: u8) -> crate::Result<audio::MixerChannelInfo>,
@@ -398,6 +439,10 @@ pub struct Api {
398439
/// How many samples in the current format can be read right now using
399440
/// `audio_input_data`?
400441
pub audio_input_get_count: extern "C" fn() -> crate::Result<usize>,
442+
443+
// ========================================================================
444+
// Neotron (SPI) Bus Support
445+
// ========================================================================
401446
/// Select a Neotron Bus Peripheral. This drives the SPI chip-select line
402447
/// low for that peripheral. Selecting a peripheral de-selects any other
403448
/// peripherals. Select peripheral 'None' to select no peripherals. If
@@ -463,18 +508,12 @@ pub struct Api {
463508
/// # Ok::<(), neotron_common_bios::Error>(())
464509
/// ```
465510
pub bus_exchange: extern "C" fn(buffer: ApiBuffer) -> crate::Result<()>,
466-
/// Busy-waits for a period of time.
467-
///
468-
/// This is better than spinning in a loop a million times as:
469-
///
470-
/// a) deferred interrupts can be processed
471-
/// b) the timing is based on clock frequency and so relatively accurate.
472-
///
473-
/// If you are drawing to the screen, you may want `Api::video_wait_for_line` instead.
511+
/// Get bus interrupt status.
474512
///
475-
/// If you want to delay for long periods, track the wall-clock time
476-
/// instead.
477-
pub delay: extern "C" fn(timeout: Timeout),
513+
/// Up to 32 interrupts can be returned as a single 32-bit value. A bit is
514+
/// set when the interrupt is pending. There is no masking - ignore the bits
515+
/// you don't care about.
516+
pub bus_interrupt_status: extern "C" fn() -> u32,
478517
}
479518

480519
// ============================================================================

src/serial.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! Serial Port / UART related types.
44
//!
5-
//! Note that all types in this file *must* be `#[repr(C)]` and ABI stable.
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
67
78
// Copyright (C) The Neotron Developers, 2019-2022
89
//

src/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! Contains types used in the Neotron API.
44
//!
5-
//! Note that all types in this file *must* be `#[repr(C)]` and ABI stable.
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
67
78
// Copyright (C) The Neotron Developers, 2019-2022
89
//
@@ -129,6 +130,13 @@ pub struct Time {
129130
pub nsecs: u32,
130131
}
131132

133+
/// Represents a tick of some internal monotonic clock.
134+
///
135+
/// Usually runs at 1 kHz.
136+
#[repr(C)]
137+
#[derive(Debug, Clone)]
138+
pub struct Ticks(pub u64);
139+
132140
/// The kinds of memory we know about
133141
#[repr(C)]
134142
#[derive(Debug, Clone)]

src/version.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! # Version
22
//!
33
//! Contains the version API.
4+
//!
5+
//! Note that all types in this file that are exported in the `Api` structure
6+
//! *must* be `#[repr(C)]` and ABI stable.
47
58
// Copyright (C) The Neotron Developers, 2019-2022
69
//

0 commit comments

Comments
 (0)