Skip to content

Commit

Permalink
canary
Browse files Browse the repository at this point in the history
  • Loading branch information
neri committed May 14, 2022
1 parent 76aa8f7 commit 46ee59e
Show file tree
Hide file tree
Showing 22 changed files with 587 additions and 140 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A hobby operating system written in Rust that supports WebAssembly.
* llvm (ld.lld)
* qemu + ovmf (optional)

### To build
### build

1. Install llvm
2. Install rust (nightly)
Expand All @@ -43,13 +43,13 @@ If you get an error that the linker cannot be found, configure your linker in `~
linker = "/opt/homebrew/opt/llvm/bin/ld.lld"
```

### To run on qemu
### run on qemu

1. Copy qemu's OVMF for x64 to `var/ovmfx64.fd`.
2. Follow the build instructions to finish the installation.
3. `make run`

### To run on real hardware
### run on real hardware

* Copy the files in the path `mnt/efi` created by the build to a USB memory stick and reboot your computer.
* You may need to change settings such as SecureBoot.
Expand Down
2 changes: 1 addition & 1 deletion apps/noiz2bg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#![no_main]
#![no_std]

use megstd::{sys::syscall::*, window::*, *};
use megstd::{sys::syscall::*, window::*};

#[no_mangle]
fn _start() {
Expand Down
10 changes: 5 additions & 5 deletions apps/test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct App {
}

impl App {
const WINDOW_WIDTH: isize = 240;
const WINDOW_HEIGHT: isize = 160;
const WINDOW_WIDTH: isize = 160;
const WINDOW_HEIGHT: isize = 144;

fn new() -> Self {
let presenter = GameWindow::with_options(
Expand Down Expand Up @@ -105,7 +105,7 @@ impl App {
Self::WINDOW_WIDTH / v1::TILE_SIZE - 4,
Self::WINDOW_HEIGHT / v1::TILE_SIZE - 4,
),
v1::NameTableEntry::from_index(0),
v1::NameTableEntry::from_index(1),
);

screen.set_name(
Expand All @@ -120,7 +120,7 @@ impl App {
);

let mut player = Player::new(
Point::new(Self::WINDOW_WIDTH / 2, Self::WINDOW_HEIGHT / 2),
Point::new(Self::WINDOW_WIDTH / 2 - 8, Self::WINDOW_HEIGHT / 2 - 8),
1,
Direction::Neutral,
);
Expand All @@ -134,7 +134,7 @@ impl App {

screen.set_sprite(0x21, 0xE0, v1::PALETTE_1);

let chars = b"Welcome to MYOS";
let chars = b"Hello world!";
for (index, char) in chars.iter().enumerate() {
self.presenter
.screen()
Expand Down
14 changes: 11 additions & 3 deletions lib/megstd/src/drawing/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1887,17 +1887,25 @@ impl Drawable for OwnedBitmap {

impl OwnedBitmap {
#[inline]
pub fn same_format<'b, T: AsRef<ConstBitmap<'b>>>(
template: &T,
pub fn new<'b, T: AsRef<ConstBitmap<'b>>>(
template_bitmap: &T,
size: Size,
bg_color: Color,
) -> OwnedBitmap {
match template.as_ref() {
match template_bitmap.as_ref() {
ConstBitmap::Indexed(_) => Self::Indexed(OwnedBitmap8::new(size, bg_color.into())),
ConstBitmap::Argb32(_) => Self::Argb32(OwnedBitmap32::new(size, bg_color.into())),
}
}

#[inline]
pub fn same_format(&self, size: Size, bg_color: Color) -> OwnedBitmap {
match self {
Self::Indexed(_) => Self::Indexed(OwnedBitmap8::new(size, bg_color.into())),
Self::Argb32(_) => Self::Argb32(OwnedBitmap32::new(size, bg_color.into())),
}
}

#[inline]
pub fn into_bitmap<'a>(&'a mut self) -> Bitmap<'a> {
match self {
Expand Down
28 changes: 27 additions & 1 deletion lib/megstd/src/drawing/coords.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{convert::TryFrom, ops::*};
use core::{convert::TryFrom, mem::swap, ops::*};

pub type FloatType = f64;

Expand All @@ -25,6 +25,19 @@ impl Point {
self.y
}

#[inline]
pub const fn swap(&mut self) {
swap(&mut self.x, &mut self.y);
}

#[inline]
pub const fn swapped(&self) -> Self {
Self {
x: self.y,
y: self.x,
}
}

pub fn line_to<F>(&self, other: Point, mut f: F)
where
F: FnMut(Self),
Expand Down Expand Up @@ -190,6 +203,19 @@ impl Size {
pub const fn bounds(&self) -> Rect {
Rect::new(0, 0, self.width, self.height)
}

#[inline]
pub const fn swap(&mut self) {
swap(&mut self.width, &mut self.height);
}

#[inline]
pub const fn swapped(&self) -> Self {
Self {
width: self.height,
height: self.width,
}
}
}

impl Add<Self> for Size {
Expand Down
11 changes: 6 additions & 5 deletions lib/megstd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! MEG-OS standard library like std
#![no_std]
#![feature(const_mut_refs)]
#![feature(alloc_error_handler)]
#![feature(asm_experimental_arch)]
#![feature(const_mut_refs)]
#![feature(const_swap)]
#![feature(toowned_clone_into)]

#[macro_use]
pub mod sys;
Expand All @@ -13,15 +15,13 @@ pub mod fs;
pub mod game;
pub mod io;
pub mod mem;
pub mod osstr;
pub mod path;
pub mod rand;
pub mod string;
pub mod time;
pub mod uuid;

pub use osstr::*;
mod osstr;

#[cfg(feature = "window")]
pub mod window {
pub use crate::sys::window::*;
Expand All @@ -31,5 +31,6 @@ extern crate alloc;

pub use prelude::*;
mod prelude {
pub use crate::sys::prelude::*;
pub use crate::{osstr::*, sys::prelude::*};
pub use alloc::{boxed::Box, rc::Rc, string::String, sync::Arc, vec::Vec};
}
Loading

0 comments on commit 46ee59e

Please sign in to comment.