Skip to content

Conversation

assembler-0
Copy link
Owner

@assembler-0 assembler-0 commented Sep 7, 2025

Summary by CodeRabbit

  • New Features
    • Added a 6502 CPU emulator reachable via the shell "6502" command; runs a built-in demo and prints a concise post-run summary of registers, flags, memory, and PC for quick testing and learning.

Copy link

coderabbitai bot commented Sep 7, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds C linkage guards to Console public declarations, registers a new Shell command "6502", integrates C++ compilation into the kernel build, and introduces a C++ 6502 emulator with an extern "C" Entry6502 entry point and its header.

Changes

Cohort / File(s) Summary
Console C linkage
kernel/etc/Console.h
Wraps public Console function prototypes in an extern "C" block guarded by #ifdef __cplusplus; no signature changes.
Shell command registration
kernel/etc/Shell.c
Adjusts includes to add ports/6502/6502.h (keeps NIC include); adds shell command entry { "6502", Entry6502 } to the commands table.
Build system: C++ enablement
meson.build
Adds clang++ lookup, C++ flags (-std=gnu++17, -fno-exceptions, -fno-rtti, etc.), include dirs for ports/6502 and ports, compiles ports/6502/6502.cpp to objects and links them into the kernel.
6502 emulator (new)
ports/6502/6502.cpp, ports/6502/6502.h
New C++ 6502 emulator implementation (MEM/CPU, addressing modes, opcode set, execute loop) exposing extern "C" void Entry6502(const char * args); header declares void Entry6502(const char * args);.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Shell as Shell (kernel/etc/Shell.c)
  participant Entry as Entry6502 (ports/6502/6502.cpp)
  participant CPU as 6502 CPU/MEM
  participant Console as Console API

  User->>Shell: types "6502"
  Shell->>Entry: Entry6502(args)
  rect rgb(235,245,255)
    note right of Entry: initialize MEM & CPU, set reset vector, load test program
    Entry->>CPU: Init()/Reset()
    Entry->>CPU: Load program @0xF000
  end
  loop run cycles / until BRK
    Entry->>CPU: Fetch/Decode/Execute (step)
    alt page-cross or branch taken
      CPU-->>CPU: adjust cycles/PC
    else normal
      CPU-->>CPU: update regs/flags/memory
    end
  end
  Entry->>Console: print registers/flags/memory (via Console API)
  Console-->>User: output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Development #117 — Appears to include the same changes (Console C linkage, ports/6502 sources, meson.build updates); likely directly related.
  • THE vbe is cooked #62 — Modifies Console API declarations/console features; strongly related to the Console.h linkage changes.

Poem

I nibble opcodes by moonlit code,
A tiny CPU upon my road.
Shell beckons, Entry opens the gate,
Cycles hum and flags update.
Hoppity hop — the emulator’s awake! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ce19a3 and 29b520a.

📒 Files selected for processing (3)
  • meson.build (5 hunks)
  • ports/6502/6502.cpp (1 hunks)
  • ports/6502/6502.h (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Development

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (1)
kernel/etc/Shell.c (1)

1173-1174: Add help entry for the new “6502” command

So users discover it via ‘help’. Consider adding a short description under Development commands.

 static const HelpEntry dev_cmds[] = {
     {"elfload <path>", "Load ELF executable"},
     {"alloc <size>", "Allocate memory"},
     {"panic <msg>", "Trigger panic"},
     {"vmemfreelist", "Show VMem free list"},
     {"heapvallvl <0/1/2>", "Set heap validation level"},
     {"fstest", "Run filesystem tests"},
     {"arptest", "Perform ARP test"},
     {"setup", "Copy system files"},
-    {"isocp <iso> <vfs>", "Copy from ISO to VFS"}
+    {"isocp <iso> <vfs>", "Copy from ISO to VFS"},
+    {"6502", "Run the 6502 emulator demo"}
 };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f32ee9c and 7ce19a3.

📒 Files selected for processing (5)
  • kernel/etc/Console.h (2 hunks)
  • kernel/etc/Shell.c (2 hunks)
  • meson.build (4 hunks)
  • ports/6502/6502.cpp (1 hunks)
  • ports/6502/6502.h (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
ports/6502/6502.h (1)
ports/6502/6502.cpp (2)
  • Entry6502 (363-406)
  • Entry6502 (363-363)
ports/6502/6502.cpp (1)
kernel/etc/Console.c (2)
  • PrintKernelF (260-267)
  • PrintKernel (181-199)
kernel/etc/Shell.c (1)
ports/6502/6502.cpp (2)
  • Entry6502 (363-406)
  • Entry6502 (363-363)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
kernel/etc/Shell.c (1)

2-3: Includes look good

6502 header inclusion is correct given the new inc_dirs; no issues spotted.

ports/6502/6502.cpp (1)

208-219: Overflow flag computation is fine; keep it boolean

Assignment to a 1-bit field from 0x80 coerces to 0/1; this is intentional and correct. Just a note that the semantics are clear.

@assembler-0 assembler-0 merged commit d5e101c into main Sep 7, 2025
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant