From ce019b5632d83a7cb0a7a7b2831a67425ae07220 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sat, 2 Mar 2019 17:15:03 -0600 Subject: [PATCH] nes: fixed binary GET for Firefox, DASM errors, disassembler --- presets/nes/ex0.asm | 4 ++- presets/nes/ex1.asm | 9 +++-- presets/nes/ex2.asm | 7 ++-- presets/nes/ex3.asm | 72 +++++++++++++++++++--------------------- src/platform/nes.ts | 22 ++++++------ src/project.ts | 22 ++++++------ src/ui.ts | 13 +++++++- src/worker/workermain.ts | 2 ++ tss | 2 +- 9 files changed, 87 insertions(+), 66 deletions(-) diff --git a/presets/nes/ex0.asm b/presets/nes/ex0.asm index b5020e42..26a90ce2 100644 --- a/presets/nes/ex0.asm +++ b/presets/nes/ex0.asm @@ -13,17 +13,19 @@ ;;;;; START OF CODE Start: +; wait for PPU warmup; clear CPU RAM NES_INIT ; set up stack pointer, turn off PPU jsr WaitSync ; wait for VSYNC jsr ClearRAM ; clear RAM jsr WaitSync ; wait for VSYNC (and PPU warmup) - +; set palette lda #$3f ; $3F -> A register sta PPU_ADDR ; write high byte first lda #$00 ; $00 -> A register sta PPU_ADDR ; $3F00 -> PPU address lda #$1c ; $1C = light blue color sta PPU_DATA ; $1C -> PPU data +; activate PPU graphics lda #CTRL_NMI sta PPU_CTRL ; enable NMI lda #MASK_COLOR diff --git a/presets/nes/ex1.asm b/presets/nes/ex1.asm index 42574a67..678bd8a0 100644 --- a/presets/nes/ex1.asm +++ b/presets/nes/ex1.asm @@ -13,17 +13,21 @@ ;;;;; START OF CODE Start: +; wait for PPU warmup; clear CPU RAM NES_INIT ; set up stack pointer, turn off PPU jsr WaitSync ; wait for VSYNC jsr ClearRAM ; clear RAM jsr WaitSync ; wait for VSYNC (and PPU warmup) +; set palette and nametable VRAM jsr SetPalette ; set palette colors - jsr HelloVRAM ; set PPU video RAM + jsr HelloVRAM ; print message in name table +; reset PPU address and scroll registers lda #0 sta PPU_ADDR sta PPU_ADDR ; PPU addr = $0000 sta PPU_SCROLL - sta PPU_SCROLL ; scroll = $0000 + sta PPU_SCROLL ; PPU scroll = $0000 +; activate PPU graphics lda #CTRL_NMI sta PPU_CTRL ; enable NMI lda #MASK_BG @@ -88,4 +92,3 @@ Palette: org $10000 incbin "jroatch.chr" - diff --git a/presets/nes/ex2.asm b/presets/nes/ex2.asm index f44c5806..381d90a4 100644 --- a/presets/nes/ex2.asm +++ b/presets/nes/ex2.asm @@ -15,18 +15,21 @@ ScrollPos word ; used during NMI ;;;;; START OF CODE Start: +; wait for PPU warmup; clear CPU RAM NES_INIT ; set up stack pointer, turn off PPU jsr WaitSync ; wait for VSYNC jsr ClearRAM ; clear RAM jsr WaitSync ; wait for VSYNC (and PPU warmup) - +; set palette and nametable VRAM jsr SetPalette ; set palette colors jsr FillVRAM ; set PPU video RAM +; reset PPU address and scroll registers lda #0 sta PPU_ADDR sta PPU_ADDR ; PPU addr = $0000 sta PPU_SCROLL sta PPU_SCROLL ; scroll = $0000 +; activate PPU graphics lda #CTRL_NMI sta PPU_CTRL ; enable NMI lda #MASK_BG @@ -41,7 +44,7 @@ FillVRAM: subroutine .loop: tya ; Y -> A ora #$40 ; A = A OR $40 - sta PPU_DATA ; X -> PPU data port + sta PPU_DATA ; A -> PPU data port inx ; X = X + 1 bne .loop ; repeat until 256 bytes dey ; Y = Y - 1 diff --git a/presets/nes/ex3.asm b/presets/nes/ex3.asm index bb83c58f..6f39e107 100644 --- a/presets/nes/ex3.asm +++ b/presets/nes/ex3.asm @@ -43,55 +43,53 @@ Start: ; fill video RAM FillVRAM: subroutine - PPU_SETADDR $2000 + PPU_SETADDR $2000 ldy #$10 .loop: - stx PPU_DATA - inx - bne .loop - dey - bne .loop - rts + stx PPU_DATA ; X -> PPU data port + inx ; X = X + 1 + bne .loop ; repeat until 256 bytes + dey ; Y = Y - 1 + bne .loop ; repeat until Y is 0 + rts ; return to caller -; +; initialize OAM data InitSprites: subroutine - lda #1 - ldx #0 + lda #1 ; A = 1 + ldx #0 ; X = 0 .loop - sta SpriteBuf,x - jsr NextRandom - inx - bne .loop - rts + sta SpriteBuf,x ; store to OAM buffer + jsr NextRandom ; get next random number + inx ; X = X + 1 + bne .loop ; loop until X wraps + rts ; return to caller -; +; move sprite data MoveSprites: subroutine - lda #1 - ldx #0 + lda #1 ; A = 1 + ldx #0 ; X = 0 .loop - sta Temp1 - and #3 - clc - adc SpriteBuf,x - sta SpriteBuf,x - lda Temp1 - jsr NextRandom - inx - bne .loop - rts + sta Temp1 ; save A + and #3 ; keep lower 2 bits + clc ; clear carry before add + adc SpriteBuf,x ; add to sprite buffer + sta SpriteBuf,x ; store in sprite buffer + lda Temp1 ; restore A + jsr NextRandom ; get next random number + inx ; X = X + 1 + bne .loop ; loop until X wraps + rts ; return to caller ; set palette colors - SetPalette: subroutine - PPU_SETADDR $3f00 - ldx #32 + PPU_SETADDR $3f00 .loop: - lda Palette,y - sta PPU_DATA - iny - dex - bne .loop - rts + lda Palette,y ; lookup byte in ROM + sta PPU_DATA ; store byte to PPU data + iny ; Y = Y + 1 + cpy #32 ; is Y equal to 32? + bne .loop ; not yet, loop + rts ; return to caller ;;;;; COMMON SUBROUTINES diff --git a/src/platform/nes.ts b/src/platform/nes.ts index aa494da1..c8de1348 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -80,13 +80,13 @@ const _JSNESPlatform = function(mainElement) { var frameindex = 0; var ntvideo; var ntlastbuf; - + class JSNESPlatform extends Base6502Platform implements Platform { getPresets() { return JSNES_PRESETS; } start() { - var self = this; + this.debugPCDelta = 1; var debugbar = $("
").appendTo(mainElement); audio = new SampleAudio(audioFrequency); video = new RasterVideo(mainElement,256,224,{overscan:true}); @@ -99,7 +99,7 @@ const _JSNESPlatform = function(mainElement) { // toggle buttons $('