mirror of
https://github.com/imjasonh/nescript
synced 2026-07-09 01:16:12 +00:00
M4+M5: Optimizer passes, type casting, bank switching, math runtime
Milestone 4 — Optimization & Polish: - Strength reduction: multiply by power-of-2 → shift left - Zero-page promotion analysis: rank variables by access frequency - `as` type casting expression in parser/AST/analyzer - `scroll(x, y)` statement - `--asm-dump` flag for viewing generated assembly - Extended optimizer tests (strength reduction, frequency analysis) Milestone 5 — Bank Switching & Release: - Mapper support: MMC1 (1), UxROM (2), MMC3 (4) in parser and ROM builder - Bank declarations: `bank Name: prg` / `bank Name: chr` - Linker::with_mapper for mapper-aware ROM generation - Software multiply (8x8→16, shift-and-add algorithm) - Software divide (8÷8→8, restoring division algorithm) - ROM tests for mapper encoding round-trip - Integration test for MMC1 compilation 210 tests total (18 new), all pre-commit checks pass. https://claude.ai/code/session_01W6eQFStA66EuMKHUFo2rx3
This commit is contained in:
parent
058f7a87b6
commit
5434dda114
15 changed files with 865 additions and 13 deletions
|
|
@ -3,13 +3,14 @@ mod tests;
|
|||
|
||||
use crate::asm;
|
||||
use crate::asm::{AddressingMode as AM, Instruction, Opcode::*};
|
||||
use crate::parser::ast::Mirroring;
|
||||
use crate::parser::ast::{Mapper, Mirroring};
|
||||
use crate::rom::RomBuilder;
|
||||
use crate::runtime;
|
||||
|
||||
/// Link compiled code into a complete NES ROM.
|
||||
pub struct Linker {
|
||||
mirroring: Mirroring,
|
||||
mapper: Mapper,
|
||||
}
|
||||
|
||||
/// A smiley face CHR tile for the default sprite (M1).
|
||||
|
|
@ -50,7 +51,14 @@ const DEFAULT_PALETTE: [u8; 32] = [
|
|||
|
||||
impl Linker {
|
||||
pub fn new(mirroring: Mirroring) -> Self {
|
||||
Self { mirroring }
|
||||
Self {
|
||||
mirroring,
|
||||
mapper: Mapper::NROM,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_mapper(mirroring: Mirroring, mapper: Mapper) -> Self {
|
||||
Self { mirroring, mapper }
|
||||
}
|
||||
|
||||
/// Link all code sections into a .nes ROM.
|
||||
|
|
@ -110,6 +118,7 @@ impl Linker {
|
|||
|
||||
// Build ROM
|
||||
let mut builder = RomBuilder::new(self.mirroring);
|
||||
builder.set_mapper(crate::rom::mapper_number(self.mapper));
|
||||
builder.set_prg(prg);
|
||||
|
||||
// CHR ROM with default sprite tile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue