mirror of
https://github.com/imjasonh/nescript
synced 2026-07-09 01:16:12 +00:00
codereview: address four residual concerns from the hardware review
- Analyzer: new `W0108` warning when an array's byte size exceeds 256. The codegen lowers `arr[i]` to `LDA base,X` and the 6502's X register is 8 bits, so elements past byte 255 are unreachable. The old debug bounds check silently skipped arrays in that range; it now clamps the compare to 255 and the analyzer diagnoses the declaration up front. - UxROM `__bank_select`: the routine previously wrote the bank number to a fixed `$FFF0`, which works on emulators that don't simulate bus conflicts (jsnes, Mesen permissive) but is broken on real hardware because a single ROM byte can't match every possible bank number. Fixed by `TAX; STA __bank_select_table,X` — the store lands at `table + bank_num`, whose ROM byte is exactly `bank_num`, so CPU bus = A = ROM = no conflict. New `LabelAbsoluteX` addressing-mode variant in the assembler resolves the table's base address through the existing fixup pass. The two existing UxROM example ROMs shift a few bytes but their goldens still match (jsnes is bus-conflict-permissive). - Source maps: new `source_map_survives_aggressive_peephole_folding` regression test. The reviewer was worried peephole could drop `__src_<N>` labels and silently leave stale source-map entries. Peephole actually treats labels as block boundaries and never deletes them — the test pins that down by compiling a program tailored to trip every peephole fold and asserting every codegen-recorded source marker survives into the final linker label table. - Frame-overrun counter: new `debug_frame_overrun_counter_reads_back_from_user_code` end-to-end test that proves the contract works: NMI emits `INC $07FF`, user `peek(0x07FF)` lowers to `LDA $07FF`, and the RAM allocator doesn't hand out `$07FF` to a user variable. https://claude.ai/code/session_01MaNVcDmK9gsspRkdxowQAM
This commit is contained in:
parent
9b54ff83c0
commit
c5297567d2
11 changed files with 354 additions and 20 deletions
|
|
@ -1455,11 +1455,28 @@ pub fn gen_bank_select(mapper: Mapper) -> Vec<Instruction> {
|
|||
out.push(Instruction::implied(RTS));
|
||||
}
|
||||
Mapper::UxROM => {
|
||||
// UxROM: write bank number to any address in $8000-$FFFF.
|
||||
// We use $FFF0 so the write lands in the fixed bank's
|
||||
// tail area where the linker can back it with a matching
|
||||
// bank-table byte to avoid bus conflicts.
|
||||
out.push(Instruction::new(STA, AM::Absolute(0xFFF0)));
|
||||
// UxROM: write the bank number to any address in
|
||||
// $8000-$FFFF. On boards with bus conflicts the CPU's
|
||||
// write and the ROM byte at that address are ANDed on
|
||||
// the data bus, so we must write to an address whose
|
||||
// ROM byte already equals the bank number. The linker
|
||||
// splices a 256-byte table (`__bank_select_table`,
|
||||
// bytes 0..255) into the fixed bank, and we index into
|
||||
// it with X = bank number: `STA __bank_select_table, X`
|
||||
// stores A (= bank number) at
|
||||
// `__bank_select_table + X`, whose ROM byte is exactly
|
||||
// X, so bus = A = X = ROM — no conflict.
|
||||
//
|
||||
// Previously this wrote to a fixed `$FFF0`, which
|
||||
// happens to work on emulators that don't simulate bus
|
||||
// conflicts (jsnes, Mesen permissive) but would glitch
|
||||
// on real hardware because a single ROM byte can't
|
||||
// match every possible bank number.
|
||||
out.push(Instruction::implied(TAX));
|
||||
out.push(Instruction::new(
|
||||
STA,
|
||||
AM::LabelAbsoluteX("__bank_select_table".into()),
|
||||
));
|
||||
out.push(Instruction::implied(RTS));
|
||||
}
|
||||
Mapper::MMC3 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue