e
E
This commit is contained in:
@@ -24,6 +24,19 @@ pub fn _print(args: core::fmt::Arguments) {
|
||||
})
|
||||
|
||||
}
|
||||
pub fn serial_reply(chr: char) -> char {
|
||||
use core::fmt::Write;
|
||||
use x86_64::instructions::interrupts;
|
||||
|
||||
let mut chr_return: char = 'X';
|
||||
|
||||
interrupts::without_interrupts(|| {
|
||||
SERIAL1.lock().send(chr as u8);
|
||||
chr_return = SERIAL1.lock().receive() as char ;
|
||||
});
|
||||
|
||||
chr_return
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serial_print {
|
||||
|
||||
@@ -8,6 +8,7 @@ use alloc::vec::Vec;
|
||||
|
||||
pub use crate::{print, println, serial_print, serial_println};
|
||||
pub use crate::kernel::render::Color;
|
||||
use crate::kernel::serial::serial_reply;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
@@ -30,6 +31,14 @@ impl Stdin {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Serial {}
|
||||
|
||||
impl Serial {
|
||||
pub fn reply_char(c: char) -> char {
|
||||
serial_reply(c)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Screen {}
|
||||
impl Screen {
|
||||
pub fn terminal_mode() {
|
||||
|
||||
@@ -126,11 +126,7 @@ impl Interpreter {
|
||||
},
|
||||
Operator::Exp => {
|
||||
return Ok(Value::Number({
|
||||
let mut val = 1.0;
|
||||
for _ in 0..(right as i64) {
|
||||
val *= left
|
||||
};
|
||||
val
|
||||
super::functions::exp(left, right)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ use alloc::format;
|
||||
use alloc::string::String;
|
||||
use crate::println;
|
||||
|
||||
const PI: f64 = 3.14159265358979323846264338327950288419716939937510;
|
||||
|
||||
pub fn run_func(func: String, x: f64) -> Result<f64, String> {
|
||||
match func.as_str() {
|
||||
"sqrt" => sqrt(x),
|
||||
@@ -36,14 +38,51 @@ fn factorial(x: f64) -> Result<f64, String> {
|
||||
Ok((1..=x).fold(1, |a, b| a * b) as f64)
|
||||
}
|
||||
|
||||
fn sin(x: f64) -> Result<f64, String> {
|
||||
Ok(libm::sin(x))
|
||||
fn cos(mut x: f64) -> Result<f64, String> {
|
||||
while x > PI {
|
||||
x -= PI;
|
||||
}
|
||||
|
||||
let res = 1.0 - trig_term(x, 2) + trig_term(x, 4) - trig_term(x, 6) + trig_term(x, 8) - trig_term(x, 10);
|
||||
if res >= -1.0 && res <= 1.0 {
|
||||
Ok(res)
|
||||
} else {
|
||||
panic!("something is very wrong with the cos function : {}", res);
|
||||
}
|
||||
}
|
||||
|
||||
fn cos(x: f64) -> Result<f64, String> {
|
||||
Ok(libm::cos(x))
|
||||
fn sin(mut x: f64) -> Result<f64, String> {
|
||||
while x > PI {
|
||||
x -= PI;
|
||||
}
|
||||
|
||||
|
||||
let res = x - trig_term(x, 3) + trig_term(x, 5) - trig_term(x, 7) + trig_term(x, 9) - trig_term(x, 11);
|
||||
if res >= -1.0 && res <= 1.0 {
|
||||
Ok(res)
|
||||
} else {
|
||||
panic!("something is very wrong with the sin function: {}", res);
|
||||
}
|
||||
}
|
||||
|
||||
fn tan(x: f64) -> Result<f64, String> {
|
||||
Ok(libm::tan(x))
|
||||
}
|
||||
|
||||
pub fn exp(x: f64, y: f64) -> f64 {
|
||||
let mut res = 1.0;
|
||||
for _ in 0..(y as usize) {
|
||||
res *= x
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
fn trig_term(x: f64, y: usize) -> f64 {
|
||||
let mut ex = 1.0;
|
||||
for _ in 0..y {
|
||||
ex *= x;
|
||||
}
|
||||
let fact = (1..=y).fold(1, |a, b| a*b);
|
||||
|
||||
ex as f64 / fact as f64
|
||||
}
|
||||
@@ -43,7 +43,7 @@ const RICKROLL2: &str = "
|
||||
1a###w#*mObo*oatXkW*oo#*###p `--' `---' `----' `-----' | |-'
|
||||
`--'";
|
||||
|
||||
use crate::{println};
|
||||
use crate::{println, serial_println};
|
||||
use alloc::{string::String, boxed::Box, vec::Vec};
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec};
|
||||
use vga::writers::{GraphicsWriter, PrimitiveDrawing};
|
||||
|
||||
use crate::{print, printerr, println, std, std::application::{Application, Error}, user::bin::*};
|
||||
use crate::std::io::{Color, write, Screen, Stdin};
|
||||
use crate::std::io::{Color, write, Screen, Stdin, Serial};
|
||||
use crate::std::random::Random;
|
||||
use crate::user::bin::gigachad_detector::GigachadDetector;
|
||||
use crate::user::bin::grapher::Grapher;
|
||||
@@ -122,6 +122,10 @@ async fn exec() -> Result<(), Error> {
|
||||
let mut game = snake::Game::new();
|
||||
game.run(args).await?;
|
||||
}
|
||||
"serial" => {
|
||||
let c = Serial::reply_char('e');
|
||||
println!("{}", c);
|
||||
}
|
||||
"gameoflife" => {
|
||||
let mut game = gameoflife::GameOfLife::new();
|
||||
game.run(Vec::new()).await?;
|
||||
|
||||
@@ -62,7 +62,7 @@ impl Position {
|
||||
}
|
||||
|
||||
|
||||
pub fn rotated_around(&self, angle: Direction, p: Position) -> Position { // rotates by an angle around a point
|
||||
pub fn rotated_aroundte(&self, angle: Direction, p: Position) -> Position { // rotates by an angle around a point
|
||||
|
||||
// gets coords relative to point to rotate around
|
||||
let mut p_offset = self.get_offset(&p);
|
||||
|
||||
Reference in New Issue
Block a user