Skip to content

Commit

Permalink
Merge pull request #39 from milomg/format
Browse files Browse the repository at this point in the history
Format everything
  • Loading branch information
1whatleytay authored Jan 10, 2025
2 parents b0f616c + 1390eb3 commit b3dad6a
Show file tree
Hide file tree
Showing 97 changed files with 1,664 additions and 1,100 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
src-tauri
target/
3 changes: 3 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ First, please install the following tools:
- [Yarn (Classic)](https://yarnpkg.com)

Before development, install dependencies using

```
yarn install
```

To run for development, use

```shell
yarn tauri dev
```

To build a binary for your platform, use

```shell
yarn tauri build
```
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ To install Saturn, visit the [releases](https://github.com/1whatleytay/saturn/re
There are usually two trains to pick from. If you're not sure, pick the **Latest** release.

| Train | Usage |
|---------------------------------------------------------------------------------------|------------------------------------------------|
| ------------------------------------------------------------------------------------- | ---------------------------------------------- |
| [Latest](https://github.com/1whatleytay/saturn/releases/latest) v0.1.9 | Stable, complete release for most users. |
| [Pre-Release](https://github.com/1whatleytay/saturn/releases/tag/app-v0.1.10) v0.1.10 | Latest experimental features. Sometimes buggy. |

Trying out the pre-release versions of Saturn helps the project out.
If you encounter an issue, please [file a bug](https://github.com/1whatleytay/saturn/issues/new).
We appreciate every report we can get.

Under the releases page, select the release you want to download and open Assets,
Under the releases page, select the release you want to download and open Assets,

- On **Windows**, select the file ending in `.msi`.
- On **macOS**, select the file ending in `.dmg`.
- On **Linux**, select either `.deb` (for Debian supporting distros) or `.AppImage`.
- On **Windows**, select the file ending in `.msi`.
- On **macOS**, select the file ending in `.dmg`.
- On **Linux**, select either `.deb` (for Debian supporting distros) or `.AppImage`.

Then follow the instructions in the installer. Once the installer finishes, Saturn should be installed on your system.

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "yarn wasm && vue-tsc --noEmit && vite build",
"preview": "vite preview",
"tauri": "tauri",
"format": "prettier --write . && cd src-backend && cargo fmt && cd ../src-tauri && cargo fmt && cd ../src-wasm && cargo fmt",
"cargo-bump": "cd src-backend && cargo update && cd ../src-tauri && cargo update && cd ../src-wasm && cargo update"
},
"dependencies": {
Expand Down
20 changes: 10 additions & 10 deletions src-backend/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::keyboard::{KeyboardHandler, KeyboardState, KEYBOARD_SELECTOR};
use serde::Serialize;
use std::collections::HashMap;
use std::io::Cursor;
Expand All @@ -6,13 +7,12 @@ use std::sync::{Arc, Mutex};
use titan::assembler::binary::{Binary, RegionFlags};
use titan::assembler::line_details::LineDetails;
use titan::assembler::string::{assemble_from, assemble_from_path, SourceError};
use titan::cpu::memory::{Mountable, Region};
use titan::cpu::memory::section::SectionMemory;
use titan::cpu::memory::{Mountable, Region};
use titan::cpu::{Memory, State};
use titan::execution::elf::inspection::Inspection;
use titan::elf::Elf;
use titan::elf::program::ProgramHeaderFlags;
use crate::keyboard::{KeyboardHandler, KeyboardState, KEYBOARD_SELECTOR};
use titan::elf::Elf;
use titan::execution::elf::inspection::Inspection;

pub const TIME_TRAVEL_HISTORY_SIZE: usize = 1000;

Expand Down Expand Up @@ -42,8 +42,7 @@ pub enum AssemblerResult {
}

pub fn get_elf_finished_pcs(elf: &Elf) -> Vec<u32> {
elf
.program_headers
elf.program_headers
.iter()
.filter(|header| header.flags.contains(ProgramHeaderFlags::EXECUTABLE))
.map(|header| header.virtual_address + header.data.len() as u32)
Expand Down Expand Up @@ -130,11 +129,10 @@ pub fn assemble_text(text: &str, path: Option<&str>) -> Result<Binary, SourceErr
}
}


pub fn create_elf_state<Mem: Memory + Mountable>(
elf: &Elf,
heap_size: u32,
mut memory: Mem
mut memory: Mem,
) -> State<Mem> {
for header in &elf.program_headers {
let region = Region {
Expand All @@ -160,7 +158,9 @@ pub fn create_elf_state<Mem: Memory + Mountable>(
state
}

pub fn configure_keyboard(memory: &mut SectionMemory<KeyboardHandler>) -> Arc<Mutex<KeyboardState>> {
pub fn configure_keyboard(
memory: &mut SectionMemory<KeyboardHandler>,
) -> Arc<Mutex<KeyboardState>> {
let handler = KeyboardHandler::new();
let keyboard = handler.state.clone();

Expand Down Expand Up @@ -206,7 +206,7 @@ pub fn assemble_binary(text: &str, path: Option<&str>) -> (Option<Vec<u8>>, Asse
let (binary, result) = AssemblerResult::from_result_with_binary(result, text);

let Some(binary) = binary else {
return (None, result)
return (None, result);
};

let elf: Elf = binary.create_elf();
Expand Down
4 changes: 2 additions & 2 deletions src-backend/src/channels.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::cmp::min;
use std::sync::Mutex;
use futures::channel::mpsc;
use futures::lock::{Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard};
use futures::StreamExt;
use std::cmp::min;
use std::sync::Mutex;

struct ByteChannelReceiver {
receiver: mpsc::Receiver<Vec<u8>>, // this might panic in WASM
Expand Down
30 changes: 15 additions & 15 deletions src-backend/src/decode.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
use std::io::Cursor;
use serde::Serialize;
use titan::unit::instruction::{InstructionDecoder, InstructionParameter};
use num::ToPrimitive;
use serde::Serialize;
use std::io::Cursor;
use titan::elf::Elf;
use titan::execution::elf::detailed_inspection::{make_inspection_lines, InspectionLine};
use titan::unit::instruction::{InstructionDecoder, InstructionParameter};

#[derive(Serialize)]
#[serde(tag="type", content="value")]
#[serde(tag = "type", content = "value")]
pub enum ParameterItem {
Register(u32),
Immediate(u16),
Address(u32),
Offset { offset: u16, register: u32 }
Offset { offset: u16, register: u32 },
}

#[derive(Serialize)]
pub struct InstructionDetails {
pc: u32,
instruction: u32,
name: &'static str,
parameters: Vec<ParameterItem>
parameters: Vec<ParameterItem>,
}

fn parameter_to_item(parameter: InstructionParameter) -> ParameterItem {
match parameter {
InstructionParameter::Register(name) => ParameterItem::Register(name.to_u32().unwrap()),
InstructionParameter::Immediate(imm) => ParameterItem::Immediate(imm),
InstructionParameter::Address(address) => ParameterItem::Address(address),
InstructionParameter::Offset(offset, register) =>
ParameterItem::Offset { offset, register: register.to_u32().unwrap() }
InstructionParameter::Offset(offset, register) => ParameterItem::Offset {
offset,
register: register.to_u32().unwrap(),
},
}
}

Expand All @@ -39,7 +41,8 @@ pub fn decode_instruction(pc: u32, instruction: u32) -> Option<InstructionDetail
pc,
instruction,
name: inst.name(),
parameters: inst.parameters()
parameters: inst
.parameters()
.into_iter()
.map(parameter_to_item)
.collect(),
Expand All @@ -66,15 +69,12 @@ pub fn detailed_disassemble(bytes: Vec<u8>) -> Result<Vec<InspectionItem>, Strin
pc: inst.pc,
instruction: inst.instruction,
name: inst.name,
parameters: inst.parameters
.into_iter()
.map(parameter_to_item)
.collect()
}
parameters: inst.parameters.into_iter().map(parameter_to_item).collect(),
},
},
InspectionLine::Blank => InspectionItem::Blank,
InspectionLine::Comment(value) => InspectionItem::Comment { message: value },
InspectionLine::Label(value) => InspectionItem::Label { name: value }
InspectionLine::Label(value) => InspectionItem::Label { name: value },
})
.collect())
}
10 changes: 7 additions & 3 deletions src-backend/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::keyboard::KeyboardState;
use crate::syscall::SyscallState;
use std::sync::{Arc, Mutex};
use titan::assembler::binary::Binary;
use titan::cpu::{Memory, State};
use titan::cpu::memory::{Mountable, Region};
use titan::execution::Executor;
use titan::cpu::{Memory, State};
use titan::execution::trackers::Tracker;
use titan::execution::Executor;

pub struct ExecutionState<Mem: Memory, Track: Tracker<Mem>> {
pub debugger: Arc<Executor<Mem, Track>>,
Expand All @@ -14,7 +14,11 @@ pub struct ExecutionState<Mem: Memory, Track: Tracker<Mem>> {
pub finished_pcs: Vec<u32>,
}

pub fn state_from_binary<Mem: Memory + Mountable>(binary: Binary, heap_size: u32, mut memory: Mem) -> State<Mem> {
pub fn state_from_binary<Mem: Memory + Mountable>(
binary: Binary,
heap_size: u32,
mut memory: Mem,
) -> State<Mem> {
for region in binary.regions {
let region = Region {
start: region.address,
Expand Down
14 changes: 8 additions & 6 deletions src-backend/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::execution::ReadDisplayTarget;
use num::FromPrimitive;
use serde::Serialize;
use std::sync::{Arc, Mutex};
use num::FromPrimitive;
use titan::cpu::{Memory, State};
use titan::unit::register::RegisterName;
use crate::execution::ReadDisplayTarget;

#[derive(Clone, Serialize)]
pub struct FlushDisplayState {
Expand All @@ -28,17 +28,19 @@ impl Default for FlushDisplayState {

impl FlushDisplayState {
fn get_target(&self) -> ReadDisplayTarget {
if let Some(register) = self.register
.and_then(|register| RegisterName::from_u8(register)) {
if let Some(register) = self
.register
.and_then(|register| RegisterName::from_u8(register))
{
ReadDisplayTarget::Register(register)
} else {
ReadDisplayTarget::Address(self.address)
}
}

pub fn flush<Mem: Memory>(&mut self, state: &mut State<Mem>) {
let address = self.get_target().to_address(&state.registers);

self.data = read_display(address, self.width, self.height, &mut state.memory);
}
}
Expand Down
Loading

0 comments on commit b3dad6a

Please sign in to comment.