mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Print some extra useful information
This commit is contained in:
parent
6c9c23f79e
commit
e5a8b39924
|
@ -48,7 +48,7 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
let ctx = addr2line::Context::new(&object)?;
|
||||
|
||||
for (i, address) in gwilym_encoding::decode(&cli.dump).into_iter().enumerate() {
|
||||
for (i, address) in gwilym_encoding::decode(&cli.dump)?.into_iter().enumerate() {
|
||||
print_address(&ctx, i, address.into(), modification_time)?;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ fn is_interesting_function(function_name: &str, path: &str) -> bool {
|
|||
mod gwilym_encoding {
|
||||
use std::sync::OnceLock;
|
||||
|
||||
const ALPHABET: &[u8] = b"-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
|
||||
const ALPHABET: &[u8] = b"0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
// pub fn encode_16(input: u16) -> [u8; 3] {
|
||||
// let input = input as usize;
|
||||
|
@ -207,7 +207,15 @@ mod gwilym_encoding {
|
|||
// ]
|
||||
// }
|
||||
|
||||
pub fn decode(input: &str) -> Vec<u32> {
|
||||
pub fn decode(input: &str) -> anyhow::Result<Vec<u32>> {
|
||||
let Some((input, version)) = input.rsplit_once('v') else {
|
||||
anyhow::bail!("Does not contain version");
|
||||
};
|
||||
|
||||
if version != "1" {
|
||||
anyhow::bail!("Only version 1 is supported");
|
||||
}
|
||||
|
||||
let mut result = vec![];
|
||||
|
||||
let mut previous_value = None;
|
||||
|
@ -224,7 +232,7 @@ mod gwilym_encoding {
|
|||
}
|
||||
}
|
||||
|
||||
result
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn decode_chunk(chunk: &[u8]) -> u32 {
|
||||
|
|
94
agb/fnt/OFL.txt
Normal file
94
agb/fnt/OFL.txt
Normal file
|
@ -0,0 +1,94 @@
|
|||
Copyright (c) 2021, TakWolf (https://takwolf.com),
|
||||
with Reserved Font Name 'Ark Pixel'.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://openfontlicense.org
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
BIN
agb/fnt/ark-pixel-10px-proportional-latin.ttf
Normal file
BIN
agb/fnt/ark-pixel-10px-proportional-latin.ttf
Normal file
Binary file not shown.
|
@ -102,12 +102,12 @@ impl core::fmt::Display for Frames {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
write!(f, "v1")
|
||||
}
|
||||
}
|
||||
|
||||
mod gwilym_encoding {
|
||||
const ALPHABET: &[u8] = b"-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
|
||||
const ALPHABET: &[u8] = b"0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
pub fn encode_16(input: u16) -> [u8; 3] {
|
||||
let input = input as usize;
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
use core::panic::PanicInfo;
|
||||
use core::{fmt::Write, panic::PanicInfo};
|
||||
|
||||
use alloc::{format, vec};
|
||||
|
||||
use crate::{
|
||||
backtrace,
|
||||
display::{busy_wait_for_vblank, HEIGHT, WIDTH},
|
||||
display::{bitmap3::Bitmap3, busy_wait_for_vblank, HEIGHT, WIDTH},
|
||||
dma::dma3_exclusive,
|
||||
interrupt, mgba, syscall,
|
||||
};
|
||||
|
||||
mod text;
|
||||
|
||||
pub fn render_backtrace(trace: &backtrace::Frames, info: &PanicInfo) -> ! {
|
||||
interrupt::free(|_cs| {
|
||||
dma3_exclusive(|| {
|
||||
|
@ -16,11 +18,20 @@ pub fn render_backtrace(trace: &backtrace::Frames, info: &PanicInfo) -> ! {
|
|||
let mut gba = unsafe { crate::Gba::new_in_entry() };
|
||||
|
||||
gba.dma.dma().dma3.disable();
|
||||
let mut gfx = gba.display.video.bitmap3();
|
||||
|
||||
let qrcode_string_data = format!("https://agbrs.dev/crash#v1-{trace}");
|
||||
let qrcode_string_data = format!("https://agbrs.dev/crash#{trace}");
|
||||
crate::println!("Stack trace: {qrcode_string_data}");
|
||||
|
||||
draw_qr_code(&mut gba, &qrcode_string_data);
|
||||
let location = draw_qr_code(&mut gfx, &qrcode_string_data);
|
||||
|
||||
let mut trace_text_render =
|
||||
text::BitmapTextRender::new(&mut gfx, (location, 8).into(), 0x0000);
|
||||
let _ = write!(&mut trace_text_render, "https://agbrs.dev/crash\n{trace}");
|
||||
|
||||
let mut panic_text_render =
|
||||
text::BitmapTextRender::new(&mut gfx, (8, location).into(), 0x0000);
|
||||
let _ = write!(&mut panic_text_render, "{info}");
|
||||
|
||||
busy_wait_for_vblank();
|
||||
|
||||
|
@ -35,9 +46,8 @@ pub fn render_backtrace(trace: &backtrace::Frames, info: &PanicInfo) -> ! {
|
|||
})
|
||||
}
|
||||
|
||||
fn draw_qr_code(gba: &mut crate::Gba, qrcode_string_data: &str) {
|
||||
let mut gfx = gba.display.video.bitmap3();
|
||||
|
||||
/// Returns the width / height of the QR code + padding in pixels
|
||||
fn draw_qr_code(gfx: &mut Bitmap3<'_>, qrcode_string_data: &str) -> i32 {
|
||||
const MAX_VERSION: qrcodegen_no_heap::Version = qrcodegen_no_heap::Version::new(6);
|
||||
|
||||
let mut temp_buffer = vec![0; MAX_VERSION.buffer_len()];
|
||||
|
@ -50,13 +60,13 @@ fn draw_qr_code(gba: &mut crate::Gba, qrcode_string_data: &str) {
|
|||
qrcodegen_no_heap::QrCodeEcc::Medium,
|
||||
qrcodegen_no_heap::Version::MIN,
|
||||
MAX_VERSION,
|
||||
Some(qrcodegen_no_heap::Mask::new(0)),
|
||||
None,
|
||||
true,
|
||||
) {
|
||||
Ok(qr_code) => qr_code,
|
||||
Err(e) => {
|
||||
crate::println!("Error generating qr code: {e:?}");
|
||||
return;
|
||||
return 8;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -70,4 +80,6 @@ fn draw_qr_code(gba: &mut crate::Gba, qrcode_string_data: &str) {
|
|||
gfx.draw_point(x, y, colour);
|
||||
}
|
||||
}
|
||||
|
||||
qr_code.size() * 2 + 8 * 2
|
||||
}
|
||||
|
|
97
agb/src/panics_render/text.rs
Normal file
97
agb/src/panics_render/text.rs
Normal file
|
@ -0,0 +1,97 @@
|
|||
use core::fmt::Write;
|
||||
|
||||
use crate::{
|
||||
display::{bitmap3::Bitmap3, Font, HEIGHT, WIDTH},
|
||||
fixnum::Vector2D,
|
||||
include_font,
|
||||
};
|
||||
|
||||
static FONT: Font = include_font!("fnt/ark-pixel-10px-proportional-latin.ttf", 10);
|
||||
|
||||
pub struct BitmapTextRender<'bitmap, 'gba> {
|
||||
head_position: Vector2D<i32>,
|
||||
start_x: i32,
|
||||
bitmap: &'bitmap mut Bitmap3<'gba>,
|
||||
colour: u16,
|
||||
previous_char: Option<char>,
|
||||
}
|
||||
|
||||
impl<'bitmap, 'gba> BitmapTextRender<'bitmap, 'gba> {
|
||||
pub fn new(
|
||||
bitmap: &'bitmap mut Bitmap3<'gba>,
|
||||
position: Vector2D<i32>,
|
||||
start_colour: u16,
|
||||
) -> Self {
|
||||
Self {
|
||||
head_position: position,
|
||||
start_x: position.x,
|
||||
bitmap,
|
||||
colour: start_colour,
|
||||
previous_char: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn render_letter(&mut self, c: char) {
|
||||
let letter = FONT.letter(c);
|
||||
|
||||
self.head_position.x += letter.xmin as i32
|
||||
+ self
|
||||
.previous_char
|
||||
.take()
|
||||
.map_or(0, |c| letter.kerning_amount(c));
|
||||
self.previous_char = Some(c);
|
||||
|
||||
if self.head_position.x + letter.width as i32 >= WIDTH {
|
||||
self.newline();
|
||||
}
|
||||
|
||||
if self.head_position.y + letter.height as i32 >= HEIGHT {
|
||||
return;
|
||||
}
|
||||
|
||||
let y_position_start =
|
||||
self.head_position.y + FONT.ascent() - letter.height as i32 - letter.ymin as i32;
|
||||
|
||||
for y in 0..letter.height as usize {
|
||||
for x in 0..letter.width as usize {
|
||||
let rendered = letter.bit_absolute(x, y);
|
||||
if rendered {
|
||||
self.bitmap.draw_point(
|
||||
x as i32 + self.head_position.x,
|
||||
y as i32 + y_position_start,
|
||||
self.colour,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.head_position.x += letter.advance_width as i32;
|
||||
}
|
||||
|
||||
fn render_char(&mut self, c: char) {
|
||||
match c {
|
||||
'\n' => {
|
||||
self.newline();
|
||||
}
|
||||
' ' => {
|
||||
self.head_position.x += FONT.letter(' ').advance_width as i32;
|
||||
}
|
||||
letter => self.render_letter(letter),
|
||||
}
|
||||
}
|
||||
|
||||
fn newline(&mut self) {
|
||||
self.head_position.x = self.start_x;
|
||||
self.head_position.y += FONT.line_height();
|
||||
}
|
||||
}
|
||||
|
||||
impl<'bitmap, 'gba> Write for BitmapTextRender<'bitmap, 'gba> {
|
||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
for c in s.chars() {
|
||||
self.render_char(c);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue