1
0

Minor cleanup
Some checks failed
CI / Typos (push) Successful in 6s
CI / Build (push) Successful in 40s
CI / Clippy (push) Failing after 58s

This commit is contained in:
Mark 2025-03-01 10:33:48 -08:00
parent 76e5f8f22d
commit 876de98ca9
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
4 changed files with 46 additions and 13 deletions

View File

@ -1,5 +1,7 @@
- improve collisions
- controls (input)
- clear lines
- deadlocks
- enum and consts for interrupt index
- fix asm loader
- document everything

View File

@ -57,6 +57,7 @@ redundant_feature_names = "deny"
multiple_crate_versions = "allow"
missing_safety_doc = "allow"
identity_op = "allow"
comparison_chain = "allow"
#
# MARK: dependencies

View File

@ -21,8 +21,10 @@ mod tetrisboard;
#[macro_use]
mod drivers;
const PIC_OFFSET: u8 = 32;
pub(crate) static VGA: Mutex<Vga13h> = Mutex::new(unsafe { Vga13h::new() });
pub(crate) static PIC: Mutex<PICDriver> = Mutex::new(PICDriver::new(32, 32 + 8));
pub(crate) static PIC: Mutex<PICDriver> = Mutex::new(PICDriver::new(PIC_OFFSET, PIC_OFFSET + 8));
pub(crate) static TICK_COUNTER: Mutex<u32> = Mutex::new(0);
pub(crate) static BOARD: Mutex<TetrisBoard> = Mutex::new(TetrisBoard::new());
pub(crate) static FALLING: Mutex<Option<FallingTetromino>> = Mutex::new(None);
@ -35,19 +37,36 @@ lazy_static! {
idt.divide_error.set_handler_fn(divide_handler);
idt.double_fault.set_handler_fn(double_fault_handler);
idt.interrupts[0].set_handler_fn(timer_handler);
idt.interrupts[InterruptIndex::Timer.as_idx()].set_handler_fn(timer_handler);
idt
};
}
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum InterruptIndex {
Timer = PIC_OFFSET,
Keyboard,
}
impl InterruptIndex {
fn as_u8(self) -> u8 {
self as u8
}
fn as_idx(self) -> usize {
usize::from(self.as_u8() - PIC_OFFSET)
}
}
extern "x86-interrupt" fn divide_handler(stack_frame: InterruptStackFrame) {
println!("DIVIDE ERROR {:?}", stack_frame);
}
extern "x86-interrupt" fn timer_handler(_stack_frame: InterruptStackFrame) {
if !*RUN_TICKS.lock() {
PIC.lock().send_eoi(32);
PIC.lock().send_eoi(InterruptIndex::Timer.as_u8());
return;
}
@ -69,7 +88,6 @@ extern "x86-interrupt" fn timer_handler(_stack_frame: InterruptStackFrame) {
if t % 6 == 0 {
if board.tetromino_free_below(fall_inner) {
fall_inner.translate(0, 1);
fall_inner.rotate_cw();
} else {
let mut x = None;
core::mem::swap(&mut x, &mut fall);
@ -80,7 +98,7 @@ extern "x86-interrupt" fn timer_handler(_stack_frame: InterruptStackFrame) {
*fall = Some(FallingTetromino::random(5, 1))
}
PIC.lock().send_eoi(32);
PIC.lock().send_eoi(InterruptIndex::Timer.as_u8());
}
extern "x86-interrupt" fn double_fault_handler(

View File

@ -93,18 +93,30 @@ impl FallingTetromino {
}
pub fn random(center_x: usize, center_y: usize) -> Self {
Self {
tetromino: Tetromino::choose_rand(),
direction: Direction::North,
color: VgaColor::choose_rand(),
Self::new(
Tetromino::choose_rand(),
VgaColor::choose_rand(),
center_x,
center_y,
}
)
}
pub fn translate(&mut self, x: usize, y: usize) {
self.center_x += x;
self.center_y += y;
pub fn translate(&mut self, x: i16, y: i16) {
if x > 0 {
let x = usize::try_from(x).unwrap();
self.center_x += x;
} else if x < 0 {
let x = usize::try_from(-x).unwrap();
self.center_x -= x;
}
if y > 0 {
let y = usize::try_from(y).unwrap();
self.center_y += y;
} else if y < 0 {
let y = usize::try_from(-y).unwrap();
self.center_y -= y;
}
}
pub fn rotate_cw(&mut self) {