From 517605d7da27f5943e3799f0f1147c50f8dc6294 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 4 Jul 2019 15:22:42 -0400 Subject: [PATCH] minor tweaks --- presets/nes/attributes.c | 22 ++++++++++------------ presets/nes/horizmask.c | 6 +++--- presets/nes/siegegame.c | 5 ++--- src/platform/nes.ts | 10 +++++----- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/presets/nes/attributes.c b/presets/nes/attributes.c index 360e5799..ad64b1bb 100644 --- a/presets/nes/attributes.c +++ b/presets/nes/attributes.c @@ -1,9 +1,7 @@ - /* Setting the attribute table, which controls palette selection for the nametable. We copy it from an array in ROM to video RAM. */ - #include "neslib.h" #include #include @@ -11,16 +9,6 @@ for the nametable. We copy it from an array in ROM to video RAM. // link the pattern table into CHR ROM //#link "chr_generic.s" -/*{pal:"nes",layout:"nes"}*/ -const char PALETTE[16] = { - 0x03, // screen color - - 0x11,0x30,0x27,0x0, // background palette 0 - 0x1c,0x20,0x2c,0x0, // background palette 1 - 0x00,0x10,0x20,0x0, // background palette 2 - 0x06,0x16,0x26 // background palette 3 -}; - // attribute table in PRG ROM const char ATTRIBUTE_TABLE[0x40] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // rows 0-3 @@ -33,6 +21,16 @@ const char ATTRIBUTE_TABLE[0x40] = { 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f // rows 28-29 }; +/*{pal:"nes",layout:"nes"}*/ +const char PALETTE[16] = { + 0x03, // screen color + + 0x11,0x30,0x27,0x0, // background palette 0 + 0x1c,0x20,0x2c,0x0, // background palette 1 + 0x00,0x10,0x20,0x0, // background palette 2 + 0x06,0x16,0x26 // background palette 3 +}; + // main function, run after console reset void main(void) { // set background palette colors diff --git a/presets/nes/horizmask.c b/presets/nes/horizmask.c index eb58337b..7bfba9e6 100644 --- a/presets/nes/horizmask.c +++ b/presets/nes/horizmask.c @@ -59,7 +59,7 @@ void new_building() { void update_nametable() { register word addr; // a buffer drawn to the nametable vertically - char buf[32]; + char buf[PLAYROWS]; // divide x_scroll by 8 // to get nametable X position byte x = (x_scroll/8 + 32) & 63; @@ -68,9 +68,9 @@ void update_nametable() { else addr = NTADR_B(x&31, 4); // clear empty space - memset(buf, 0, PLAYROWS-bldg_height); + memset(buf, 0, sizeof(buf)); // draw a random star - buf[rand8() & 31] = '.'; + buf[rand8() & 15] = '.'; // draw roof buf[PLAYROWS-bldg_height-1] = bldg_char & 3; // draw rest of building diff --git a/presets/nes/siegegame.c b/presets/nes/siegegame.c index 185d7308..5cd98d8b 100644 --- a/presets/nes/siegegame.c +++ b/presets/nes/siegegame.c @@ -1,10 +1,8 @@ - /* A character-based surround-the-opponent game. Reads from nametable RAM to determine collisions, and also to help the AI avoid walls. */ - #include #include #include @@ -30,10 +28,11 @@ to help the AI avoid walls. byte getchar(byte x, byte y) { // compute VRAM read address word addr = NTADR_A(x,y); + // result goes into rd byte rd; // wait for VBLANK to start ppu_wait_nmi(); - // set vram address and read byte + // set vram address and read byte into rd vram_adr(addr); vram_read(&rd, 1); // scroll registers are corrupt diff --git a/src/platform/nes.ts b/src/platform/nes.ts index e25a6239..e4e4931f 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -17,15 +17,15 @@ const JSNES_PRESETS = [ {id:'flicker.c', name:'Flickering Sprites'}, {id:'metacursor.c', name:'Controllers'}, {id:'vrambuffer.c', name:'VRAM Buffer'}, - {id:'tint.c', name:'Color Emphasis'}, - {id:'rletitle.c', name:'Title Screen RLE'}, {id:'statusbar.c', name:'Split Status Bar'}, {id:'horizmask.c', name:'Offscreen Scrolling'}, - {id:'monobitmap.c', name:'Monochrome Bitmap'}, + {id:'siegegame.c', name:'Siege Game'}, + {id:'tint.c', name:'Color Emphasis'}, + {id:'rletitle.c', name:'Title Screen RLE'}, {id:'aputest.c', name:'Sound Tester'}, {id:'music.c', name:'Music Player'}, + {id:'monobitmap.c', name:'Monochrome Bitmap'}, {id:'fami.c', name:'Famitone Demo'}, - {id:'siegegame.c', name:'Siege Game'}, {id:'shoot2.c', name:'Solarian Game'}, {id:'climber.c', name:'Platform Game'}, {id:'bankswitch.c', name:'Bank Switching'}, @@ -114,7 +114,7 @@ class JSNESPlatform extends Base6502Platform implements Platform { if (this.frameindex < 10) this.audio.feedSample(0, 1); // avoid popping at powerup else - this.audio.feedSample(left+right, 1); + this.audio.feedSample((left+right)*0.5, 1); }, onStatusUpdate: function(s) { console.log(s);