From e5ef0fac5f15886cd34c0e56d15013f1561f6e08 Mon Sep 17 00:00:00 2001 From: Safiire Date: Sat, 14 Mar 2015 05:01:27 -0700 Subject: [PATCH] Updated my nes symbol library, register names, fixed a problem with hex numbers --- examples/demo.asm | 38 +++++++-------- lib/instruction.rb | 2 +- nes_lib/nes.sym | 112 ++++++++++++++++++++++++++++++--------------- 3 files changed, 94 insertions(+), 58 deletions(-) diff --git a/examples/demo.asm b/examples/demo.asm index 7adefdc..4e250f4 100644 --- a/examples/demo.asm +++ b/examples/demo.asm @@ -139,7 +139,7 @@ lda #$01 sta nes.apu.channel_enable lda #$00 - sta nes.apu.square1.reg2 + sta nes.apu.pulse1.ramp_control rts . @@ -175,11 +175,11 @@ .scope load_palette lda #$3F ldx #$00 - sta nes.ppu.address - stx nes.ppu.address + sta nes.vram.address2 + stx nes.vram.address2 loop: lda palette, x - sta nes.ppu.data + sta nes.vram.io inx cpx #$20 bne loop @@ -198,12 +198,12 @@ lda #>bg sta $11 lda #$24 - sta nes.ppu.address + sta nes.vram.address2 lda #$00 - sta nes.ppu.address + sta nes.vram.address2 loop: lda ($10), y - sta nes.ppu.data + sta nes.vram.io iny bne loop inc $11 @@ -217,7 +217,7 @@ lda #$00 .scope loop: - sta nes.ppu.data + sta nes.vram.io iny bne loop dex @@ -241,7 +241,7 @@ ; Update the sprite, I don't exactly understand the DMA call yet. update_sprite: lda #>sprite - sta nes.ppu.sprite_dma ; Jam page $200-$2FF into SPR-RAM, how do we get these numbers? + sta nes.sprite.dma ; Jam page $200-$2FF into SPR-RAM, how do we get these numbers? lda sprite.x beq hit_left cmp #$F7 @@ -324,16 +324,16 @@ reverse_dx: ; Scroll the screen if we have to scroll_screen: ldx #$00 ; Reset VRAM Address to $0000 - stx nes.ppu.address - stx nes.ppu.address + stx nes.vram.address2 + stx nes.vram.address2 ldx scroll zp ; Do we need to scroll at all? beq no_scroll dex stx scroll zp lda #$00 - sta nes.ppu.scroll ; Write 0 for Horiz. Scroll value - stx nes.ppu.scroll ; Write the value of 'scroll' for Vert. Scroll value + sta nes.vram.address1 ; Write 0 for Horiz. Scroll value + stx nes.vram.address1 ; Write the value of 'scroll' for Vert. Scroll value no_scroll: rts @@ -344,11 +344,11 @@ no_scroll: low_c: pha lda #$84 - sta nes.apu.square1.reg1 + sta nes.apu.pulse1.control lda #$AA - sta nes.apu.square1.reg3 + sta nes.apu.pulse1.ft lda #$09 - sta nes.apu.square1.reg4 + sta nes.apu.pulse1.ct pla rts @@ -358,11 +358,11 @@ low_c: high_c: pha lda #$86 - sta nes.apu.square1.reg1 + sta nes.apu.pulse1.control lda #$69 - sta nes.apu.square1.reg3 + sta nes.apu.pulse1.ft lda #$08 - sta nes.apu.square1.reg4 + sta nes.apu.pulse1.ct pla rts diff --git a/lib/instruction.rb b/lib/instruction.rb index 5a58596..2449936 100644 --- a/lib/instruction.rb +++ b/lib/instruction.rb @@ -17,7 +17,7 @@ module Assembler6502 Mnemonic = '([A-Za-z]{3})' Hex8 = '\$([A-Fa-f0-9]{2})' Hex16 = '\$([A-Fa-f0-9]{4})' - Immediate = '\#\$([0-9A-F]{2})' + Immediate = '\#\$([0-9A-Fa-f]{2})' Sym = '([a-zZ-Z_][a-zA-Z0-9_\.]+)' Branches = '(BPL|BMI|BVC|BVS|BCC|BCS|BNE|BEQ|bpl|bmi|bvc|bvs|bcc|bcs|bne|beq)' XReg = '[Xx]' diff --git a/nes_lib/nes.sym b/nes_lib/nes.sym index 5f6729a..9deb4ef 100644 --- a/nes_lib/nes.sym +++ b/nes_lib/nes.sym @@ -1,65 +1,101 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Let's start a little library for naming parts of memory in the NES -; We can move this to a separate library file later. ; ; Including this file will not emit any instructions or data into your binary ; It only defines symbols in the symbol table to name memory addresses ; ; Author: Saf Allen 2015 +; I picked up some extra register names for mappers etc here: +; http://wiki.nesdev.com/w/index.php/Registers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .org $0000 .scope nes .scope ppu .org $2000 - .space control1 1 ; Control registers 1 and 2 - .space control2 1 - .space status 1 ; PPU status - .space sprite_address 1 ; Sprite memory address - .space sprite_data 1 ; Sprite memory data - .space scroll 1 ; Background scroll - .space address 1 ; Indexing into PPU memory address - .space data 1 ; Read or write to PPU memory location through this register + .space control1 1 ; $2000 + .space control2 1 ; $2001 + .space status 1 ; $2002 + . + .scope sprite + .space address 1 ; $2003 + .space io 1 ; $2004 .org $4014 - .space sprite_dma 1 ; DMA access to sprite memory + .space dma 1 ; $4014 + . + .scope vram + .org $2005 + .space address1 1 ; $2005 + .space address2 1 ; $2006 + .space io 1 ; $2007 . + ; Now let's do the APU registers .org $4000 .scope apu - .scope square1 ; Control of Square 1 - .space reg1 1 - .space reg2 1 - .space reg3 1 - .space reg4 1 + .scope pulse1 + .space control 1 ; $4000 + .space ramp_control 1 ; $4001 + .space ft 1 ; $4002 + .space ct 1 ; $4003 . - .scope square2 ; Control of Square 2 - .space reg1 1 - .space reg2 1 - .space reg3 1 - .space reg4 1 + .scope pulse2 + .space control 1 ; $4004 + .space ramp_control 1 ; $4005 + .space ft 1 ; $4006 + .space ct 1 ; $4007 . - .scope triangle ; Control of Triangle - .space reg1 1 - .space reg2 1 - .space reg3 1 - .space reg4 1 + .scope triangle + .space control1 1 ; $4008 + .space control2 1 ; $4009 + .space freq1 1 ; $400A + .space freq2 1 ; $400B . - .scope noise ; Control of Noise - .space reg1 1 - .space reg2 1 - .space reg3 1 - .space reg4 1 + .scope noise + .space control1 1 ; $400C + .space control2 1 ; $400D + .space freq1 1 ; $400E + .space freq2 1 ; $400F . - .scope dmc ; Control of DMC - .space reg1 1 - .space reg2 1 - .space reg3 1 - .space reg4 1 + .scope dmc + .space control 1 ; $4010 + .space da 1 ; $4011 + .space address 1 ; $4012 + .space dl 1 ; $4013 . .org $4015 - .space channel_enable 1 ; Enable or disble channels + .space channel_enable 1 ; $4015 . .org $4016 - .space controller1 1 ; Player 1 joystick - .space controller2 1 ; Player 2 joystick + .space controller1 1 ; $4016 + .space controller2 1 ; $4017 + .scope mapper + .org $8000 + .space unrom 1 + .org $8000 + .space cnrom 1 + .org $8000 + .space mmc1_control 1 + .org $A000 + .space mmc1_vrom_low 1 + .org $C000 + .space mmc1_vrom_high 1 + .org $E000 + .space mmc1_prog 1 + .org $8000 + .space mmc3_command 1 + .space mmc3_page 1 + .org $A000 + .space mmc3_mirror 1 + .space mmc3_sram 1 + .org $C000 + .space mmc3_clock 1 + .space mmc3_latch 1 + .org $E000 + .space mmc3_clock_off 1 + .space mmc3_clock_on 1 + . . + +; Let's put PC back somewhere sane +.org $0000