~calebccff/cnes

An NES emulator written in C++, imgui and SFML.
4a4109ca — Caleb Connolly 2 years ago
PPU: start implementing internal behaviour properly
4d40078e — Caleb Connolly 2 years ago
run valgrind/kcachegrind and do some optimisations
0e568759 — Caleb Connolly 2 years ago
huge refactor + cleanup

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~calebccff/cnes
read/write
git@git.sr.ht:~calebccff/cnes

You can also use your local clone with git send-email.

#cnes

A NES emulator written in C++, imgui and SFML.

ImGui to SFML bindings are from https://github.com/eliasdaler/imgui-sfml.

#Example 6502 program

processor 6502

    SEG
    ORG $4020 ; Cartridge address

; 8-bit Fibonacci sequence generator
; TODO: Add 16-bit support :D
Reset
    LDA #$01 ; Load the value VAL_A into the accumulator
LoopForever
    STA $01  ; Store A in zero page address 0
    STA $4018 ; Print A
    ADC $00  ; Add value in address $00
    STA $02  ; Store result in address $02
    STA $4018 ; 4018 is unused(?) on the NES, so here I'm using it to print a byte
    ADC $01  ; Add value in addres $01
    STA $00  ; Store result in $00
    STA $4018 ; Print A
    ADC $02  ; Add value in $02
    JMP LoopForever ; Jump back to the LoopForever label

    ORG $FFFA ; Address of section

        ; Store the 16-bit address of the Reset label
        ; to be jumped to when any of these vectors occur
        ; This address is usually mapped to cartridge ROM in the NES
    .word Reset ; in the NMI vector
    .word Reset ; The Reset Vector
    .word Reset ; And the IRQ/BRK vector

    END

Can be compiled with dasm:

dasm docs/fib.asm -f3 -v5 -0test.bin

You can inspect the file test.bin with a hex editor and you should see the following:

; xxd test.bin | head -n 1
00000000: a901 8501 6500 8502 8d18 4065 0185 008d  ....e.....@e....

The file is padded by 0x0FFA bytes up until the address of the reset vectors.

#Tests

Tests can be run by invoking cnes with the -t flag.

Some unit tests depend on pre-compiled 6502 binaries, these are installed to /usr/share/cnes/tests/, for local builds set the TESTS_PATH build flag to a relative path, e.g.

meson compile -C build -DTESTS_PATH=tests