Compare commits

..

No commits in common. "main" and "v0.3.0" have entirely different histories.
main ... v0.3.0

7 changed files with 35 additions and 56 deletions

View File

@ -1,6 +1,7 @@
// This example contains information adapted from the MSPGCC project's documentation.
// As such, it is licensed under the GPL, to the extent that such a thing is possible.
// https://mspgcc.sourceforge.net/manual/ln16.html
#![feature(decl_macro)]
fn main() {
println!("Hello, world!")

View File

@ -1,4 +1,5 @@
//! Helper library for msp430-asm
#![feature(decl_macro)]
pub mod split_twice {
/// Slices a collection into a beginning, middle, and end, based on two unordered indices
pub trait SplitTwice<'t> {
@ -62,51 +63,30 @@ pub mod cursor {
use std::fmt::{Arguments, Display};
/// Moves to the {line}th previous line
#[macro_export]
macro_rules! previous {
($line:literal) => {
csi!("{}F", $line)
};
pub macro previous($line:literal) {
csi!("{}F", $line)
}
/// Injects a Command Sequence Introducer
#[macro_export]
macro_rules! csi {
($($t:tt)*) => {
format_args!("\x1b[{}", format_args!($($t)*))
};
pub macro csi($($t:tt)*) {
format_args!("\x1b[{}", format_args!($($t)*))
}
/// Formats the args with a foreground [Color]
#[macro_export]
macro_rules! fg {
($fg:expr, $($t:tt)*) => {
Colorized::new(Some($fg), None, format_args!($($t)*))
};
pub macro fg($fg:expr, $($t:tt)*) {
Colorized::new(Some($fg), None, format_args!($($t)*))
}
/// Formats the args with a background [Color]
#[macro_export]
macro_rules! bg {
($bg:expr, $(t:tt)*) => {
Colorized::new(None, Some($bg), format_args!($($t)*))
};
pub macro bg($bg:expr, $(t:tt)*) {
Colorized::new(None, Some($bg), format_args!($($t)*))
}
/// Formats the args with both a foreground and background [Color]
#[macro_export]
macro_rules! color {
($fg:expr, $bg:expr, $($t:tt)*) => {
Colorized::new(Some($fg), Some($bg), format_args!($($t)*))
}
pub macro color($fg:expr, $bg:expr, $($t:tt)*) {
Colorized::new(Some($fg), Some($bg), format_args!($($t)*))
}
pub use bg;
pub use color;
pub use csi;
pub use fg;
pub use previous;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Color {
#[default]

View File

@ -1,6 +1,7 @@
// © 2023-2024 John Breaux
//See LICENSE.md for license
//! Simple frontend for the assembler
#![feature(decl_macro)]
use argp::parse_args_or_exit;
use libmsp430::{
assembler::Assemble,
@ -65,16 +66,14 @@ mod repl {
use std::io::{stderr, Write};
/// Formats the line number
macro_rules! linenr {
($n: expr) => {
format_args!("{:4}: ", $n)
};
macro linenr($n: expr) {
format_args!("{:4}: ", $n)
}
/// [println], but without the newline
macro_rules! printfl {($($x: expr),+) => {
macro printfl ($($x: expr),+) {
{print!($($x),+); let _ = ::std::io::stdout().flush();}
}}
}
/// Runs the read-evaluate-print loop
pub fn repl(buf: &mut String) -> Result<(), Box<dyn Error>> {

View File

@ -1,11 +1,13 @@
; © 2023-2024 John Breaux
; Comtains spoilers for Microcorruption Halifax! Be warned!
; just hash the first 0x140 B and stick them in memory
const:
.define msize 0x1 ; length of each hash in bytes
.define hsize 0x3 ; bytes kept per hash (only needs to be 3 to determine 1 byte of sram)
.define sr_len 0x140 ; number of bytes in sram to dump
.define ha_len 0x3c0 ; number of bytes in hash array (hsize * sr_len)
.define haddr 0x7000 ; address of the big hash array
.define iaddr 0x8000 ; address of the sram input buffer
.define kaddr 0x9000 ; address of the key buffer
@ -22,7 +24,7 @@ external_func:
.define puts #0x4586
; memcpy(void *dest, void *src, size_t len)
.define memcpy #0x45a4
; sha256_internal(void *sram_addr, size_t sr_len, void * sha_buf)
; sha256_internal(void * sram_addr, size_t sr_len, void * sha_buf)
.define sha256_internal #0x45b6
; memset(void* buf, char value, size_t length)
.define memset #0x45c8
@ -33,10 +35,10 @@ get_sram_hashes:
mov #haddr, r13 ; set destination to 0x8000
sr_loop:
mov r11, r15 ; mov addr r15
call sha256_internal ; sha256_internal (i, msize, haddr + i * hsize)
call sha256_internal ; <sha256_internal>
add #hsize, r13 ; keep 3 bytes of the output
inc r11 ; inc r11
cmp #sr_len, r11 ; do that sram_len times
cmp #sr_len, r11 ; do that 0x1000 times
jnc sr_loop
print_hex:
@ -51,27 +53,27 @@ print_hex:
clrc
and #0xf, r14
mov.b HEX_LUT(r15), r15
call putchar ; putchar (HEX_LUT[haddr[i] >> 4])
call putchar ; <putchar>
mov.b HEX_LUT(r14), r15
call putchar ; putchar (HEX_LUT[haddr[i] & 0xf])
inc r11
cmp #sr_len * hsize, r11 ; do that sram_length * hash_size times
call putchar ; <putchar>
inc r11 ; inc r11
cmp #ha_len, r11 ; do that sram_length*3 times
jnc ph_loop
mov.b #'\n', r15 ; '\n'
call putchar ; putchar ('\n')
mov.b #0xa, r15 ; '\n'
call #0x4578 ; putchar ('\n')
take_input:
mov #sr_len, r14
mov #iaddr, r15
call getsn ; getsn (iaddr, sr_len)
call getsn ; <getsn>
check_all_passwords:
;for i in 0..sr_len:
clr r9
pw_loop:
; memcpy (kaddr, iaddr + i, len)
; memcpy(kaddr, iaddr + i, len)
mov #0x10, r13
mov #iaddr, r14
add r9, r14
@ -82,7 +84,7 @@ check_all_passwords:
push #0x42
call INT
add #4, sp
; INT (7f)
; INT(7f)
unlock7f:
push #0
push #0

View File

@ -5,7 +5,7 @@
pub mod token;
use self::token::*;
use self::token::{Special, TokenKind, *};
use crate::span::Span;
use std::{
iter::Peekable,

View File

@ -173,10 +173,6 @@ impl<'t> Parser<'t> {
self.take();
Expr::Number(n)
}
Kind::Char(c) => {
self.take();
Expr::Number(c as _)
}
Kind::Identifier => {
self.take();
Expr::Ident(lexeme)

View File

@ -645,12 +645,13 @@ pub mod canonical {
Expr::Number(tail)
}
Expr::Binary(head, tails) => {
let mut tails = tails.into_iter().map(|(op, tail)| (op, tail.to_canonical()));
let mut head = match head.to_canonical() {
Expr::Number(n) => n,
head => return Expr::Binary(head.into(), tails.collect()),
head => return Expr::Binary(head.into(), tails),
};
let mut tails = tails.into_iter();
for (op, tail) in &mut tails {
let tail = tail.to_canonical();
// If the canonical tail isn't a number, rebuild and return
let Expr::Number(tail) = tail else {
return Expr::Binary(