nes preset updates

This commit is contained in:
Steven Hugg 2019-04-15 19:37:11 -04:00
parent 9108bb5e1c
commit 4ddc183f74
11 changed files with 106 additions and 188 deletions

View File

@ -13,64 +13,30 @@
///// METASPRITES
#define TILE 0xd8
#define ATTR 0
// define a 2x2 metasprite
#define DEF_METASPRITE_2x2(name,code,pal)\
const unsigned char name[]={\
0, 0, (code)+0, pal, \
0, 8, (code)+1, pal, \
8, 0, (code)+2, pal, \
8, 8, (code)+3, pal, \
const unsigned char metasprite[]={
0, 0, TILE+0, ATTR,
0, 8, TILE+1, ATTR,
8, 0, TILE+2, ATTR,
8, 8, TILE+3, ATTR,
128};
// define a 2x2 metasprite, flipped horizontally
#define DEF_METASPRITE_2x2_FLIP(name,code,pal)\
const unsigned char name[]={\
8, 0, (code)+0, (pal)|OAM_FLIP_H, \
8, 8, (code)+1, (pal)|OAM_FLIP_H, \
0, 0, (code)+2, (pal)|OAM_FLIP_H, \
0, 8, (code)+3, (pal)|OAM_FLIP_H, \
128};
DEF_METASPRITE_2x2(playerRStand, 0xd8, 0);
DEF_METASPRITE_2x2(playerRRun1, 0xdc, 0);
DEF_METASPRITE_2x2(playerRRun2, 0xe0, 0);
DEF_METASPRITE_2x2(playerRRun3, 0xe4, 0);
DEF_METASPRITE_2x2(playerRJump, 0xe8, 0);
DEF_METASPRITE_2x2(playerRClimb, 0xec, 0);
DEF_METASPRITE_2x2(playerRSad, 0xf0, 0);
DEF_METASPRITE_2x2_FLIP(playerLStand, 0xd8, 0);
DEF_METASPRITE_2x2_FLIP(playerLRun1, 0xdc, 0);
DEF_METASPRITE_2x2_FLIP(playerLRun2, 0xe0, 0);
DEF_METASPRITE_2x2_FLIP(playerLRun3, 0xe4, 0);
DEF_METASPRITE_2x2_FLIP(playerLJump, 0xe8, 0);
DEF_METASPRITE_2x2_FLIP(playerLClimb, 0xec, 0);
DEF_METASPRITE_2x2_FLIP(playerLSad, 0xf0, 0);
DEF_METASPRITE_2x2(personToSave, 0xba, 1);
const unsigned char* const playerRunSeq[16] = {
playerLRun1, playerLRun2, playerLRun3,
playerLRun1, playerLRun2, playerLRun3,
playerLRun1, playerLRun2,
playerRRun1, playerRRun2, playerRRun3,
playerRRun1, playerRRun2, playerRRun3,
playerRRun1, playerRRun2,
};
/*{pal:"nes",layout:"nes"}*/
const char PALETTE[32] = {
0x03, // background color
0x03, // screen color
0x25,0x30,0x27,0x00, // ladders and pickups
0x1C,0x20,0x2C,0x00, // floor blocks
0x00,0x10,0x20,0x00,
0x06,0x16,0x26,0x00,
0x11,0x30,0x27,0x0, // background palette 0
0x1c,0x20,0x2c,0x0, // background palette 1
0x00,0x10,0x20,0x0, // background palette 2
0x06,0x16,0x26,0x0, // background palette 3
0x16,0x35,0x24,0x00, // enemy sprites
0x00,0x37,0x25,0x00, // rescue person
0x0D,0x2D,0x1A,0x00,
0x0D,0x27,0x2A // player sprites
0x16,0x35,0x24,0x0, // sprite palette 0
0x00,0x37,0x25,0x0, // sprite palette 1
0x0d,0x2d,0x3a,0x0, // sprite palette 2
0x0d,0x27,0x2a // sprite palette 3
};
// setup PPU and tables
@ -87,11 +53,11 @@ void setup_graphics() {
#define NUM_ACTORS 24
// actor x/y positions
char actor_x[NUM_ACTORS];
char actor_y[NUM_ACTORS];
// actor x/y deltas per frame
char actor_dx[NUM_ACTORS];
char actor_dy[NUM_ACTORS];
byte actor_x[NUM_ACTORS];
byte actor_y[NUM_ACTORS];
// actor x/y deltas per frame (signed)
sbyte actor_dx[NUM_ACTORS];
sbyte actor_dy[NUM_ACTORS];
// main program
void main() {
@ -117,7 +83,7 @@ void main() {
// wrap around actor array
if (i >= NUM_ACTORS)
i -= NUM_ACTORS;
oam_id = oam_meta_spr(actor_x[i], actor_y[i], oam_id, playerRunSeq[i&15]);
oam_id = oam_meta_spr(actor_x[i], actor_y[i], oam_id, metasprite);
actor_x[i] += actor_dx[i];
actor_y[i] += actor_dy[i];
++i;

View File

@ -1,30 +1,20 @@
#include "neslib.h"
#include <string.h>
// link the pattern table into CHR ROM
//#link "chr_generic.s"
// function to write a string into the name table
// adr = start address in name table
// str = pointer to string
void put_str(unsigned int adr, const char *str) {
vram_adr(adr); // set PPU read/write address
vram_write(str, strlen(str)); // write bytes to PPU
}
// main function, run after console reset
void main(void) {
// set palette colors
pal_col(0,0x02);
pal_col(1,0x14);
pal_col(2,0x20);
pal_col(3,0x30);
pal_col(0,0x02); // set screen to dark blue
pal_col(1,0x14); // pink
pal_col(2,0x20); // grey
pal_col(3,0x30); // white
// write text to name table
put_str(NTADR_A(2,2),"HELLO, WORLD!");
put_str(NTADR_A(2,4),"Hello, World!");
put_str(NTADR_A(2,6),"\x14 \x15 \x16 \x17 \x18 \x19");
vram_adr(NTADR_A(2,2)); // set address
vram_write("HELLO, WORLD!", 13); // write bytes to video RAM
// enable PPU rendering (turn on screen)
ppu_on_all();

View File

@ -44,7 +44,7 @@ void new_building() {
void update_nametable() {
register word addr;
// a buffer drawn to the nametable vertically
char buf[PLAYROWS];
char buf[32];
// divide x_scroll by 8
// to get nametable X position
byte x = ((x_scroll >> 3)+32) & 63;
@ -61,7 +61,7 @@ void update_nametable() {
// draw rest of building
memset(buf+PLAYROWS-bldg_height, bldg_char, bldg_height);
// draw vertical slice in name table
vrambuf_put(addr ^ 0xc000, buf, sizeof(buf));
vrambuf_put(addr ^ 0xc000, buf, PLAYROWS);
// every 4 columns, update attribute table
if ((x & 3) == 1) {
// compute attribute table address
@ -90,16 +90,13 @@ void scroll_demo() {
if ((x_scroll & 7) == 0) {
update_nametable();
}
// manually force vram update
// flush and clear VRAM buffer after NMI
// ensure VRAM buffer is cleared
ppu_wait_nmi();
flush_vram_update(updbuf);
vrambuf_clear();
// reset ppu address
vram_adr(0x0);
// set scroll register
// and increment x_scroll
split(x_scroll++, 0);
// split at x_scroll
split(x_scroll, 0);
// increment x_scroll
++x_scroll;
}
}
@ -142,13 +139,14 @@ void main(void) {
// set sprite 0
oam_clear();
oam_spr(1, 30, 0xa0, 1, 0);
oam_spr(1, 30, 0xa0, 0, 0);
// clip left 8 pixels of screen
ppu_mask(MASK_SPR|MASK_BG);
// clear vram buffer
vrambuf_clear();
set_vram_update(updbuf);
// enable PPU rendering (turn on screen)
ppu_on_all();

View File

@ -87,11 +87,11 @@ void setup_graphics() {
#define NUM_ACTORS 16
// actor x/y positions
char actor_x[NUM_ACTORS];
char actor_y[NUM_ACTORS];
// actor x/y deltas per frame
char actor_dx[NUM_ACTORS];
char actor_dy[NUM_ACTORS];
byte actor_x[NUM_ACTORS];
byte actor_y[NUM_ACTORS];
// actor x/y deltas per frame (signed)
sbyte actor_dx[NUM_ACTORS];
sbyte actor_dy[NUM_ACTORS];
// main program
void main() {
@ -130,7 +130,10 @@ void main() {
}
// draw and move all actors
for (i=0; i<NUM_ACTORS; i++) {
oam_id = oam_meta_spr(actor_x[i], actor_y[i], oam_id, playerRunSeq[i&15]);
byte runseq = actor_x[i] & 7;
if (actor_dx[i] >= 0)
runseq += 8;
oam_id = oam_meta_spr(actor_x[i], actor_y[i], oam_id, playerRunSeq[runseq]);
actor_x[i] += actor_dx[i];
actor_y[i] += actor_dy[i];
}

View File

@ -13,64 +13,30 @@
///// METASPRITES
#define TILE 0xd8
#define ATTR 0
// define a 2x2 metasprite
#define DEF_METASPRITE_2x2(name,code,pal)\
const unsigned char name[]={\
0, 0, (code)+0, pal, \
0, 8, (code)+1, pal, \
8, 0, (code)+2, pal, \
8, 8, (code)+3, pal, \
const unsigned char metasprite[]={
0, 0, TILE+0, ATTR,
0, 8, TILE+1, ATTR,
8, 0, TILE+2, ATTR,
8, 8, TILE+3, ATTR,
128};
// define a 2x2 metasprite, flipped horizontally
#define DEF_METASPRITE_2x2_FLIP(name,code,pal)\
const unsigned char name[]={\
8, 0, (code)+0, (pal)|OAM_FLIP_H, \
8, 8, (code)+1, (pal)|OAM_FLIP_H, \
0, 0, (code)+2, (pal)|OAM_FLIP_H, \
0, 8, (code)+3, (pal)|OAM_FLIP_H, \
128};
DEF_METASPRITE_2x2(playerRStand, 0xd8, 0);
DEF_METASPRITE_2x2(playerRRun1, 0xdc, 0);
DEF_METASPRITE_2x2(playerRRun2, 0xe0, 0);
DEF_METASPRITE_2x2(playerRRun3, 0xe4, 0);
DEF_METASPRITE_2x2(playerRJump, 0xe8, 0);
DEF_METASPRITE_2x2(playerRClimb, 0xec, 0);
DEF_METASPRITE_2x2(playerRSad, 0xf0, 0);
DEF_METASPRITE_2x2_FLIP(playerLStand, 0xd8, 0);
DEF_METASPRITE_2x2_FLIP(playerLRun1, 0xdc, 0);
DEF_METASPRITE_2x2_FLIP(playerLRun2, 0xe0, 0);
DEF_METASPRITE_2x2_FLIP(playerLRun3, 0xe4, 0);
DEF_METASPRITE_2x2_FLIP(playerLJump, 0xe8, 0);
DEF_METASPRITE_2x2_FLIP(playerLClimb, 0xec, 0);
DEF_METASPRITE_2x2_FLIP(playerLSad, 0xf0, 0);
DEF_METASPRITE_2x2(personToSave, 0xba, 1);
const unsigned char* const playerRunSeq[16] = {
playerLRun1, playerLRun2, playerLRun3,
playerLRun1, playerLRun2, playerLRun3,
playerLRun1, playerLRun2,
playerRRun1, playerRRun2, playerRRun3,
playerRRun1, playerRRun2, playerRRun3,
playerRRun1, playerRRun2,
};
/*{pal:"nes",layout:"nes"}*/
const char PALETTE[32] = {
0x03, // background color
0x03, // screen color
0x25,0x30,0x27,0x00, // ladders and pickups
0x1C,0x20,0x2C,0x00, // floor blocks
0x00,0x10,0x20,0x00,
0x06,0x16,0x26,0x00,
0x11,0x30,0x27,0x0, // background palette 0
0x1c,0x20,0x2c,0x0, // background palette 1
0x00,0x10,0x20,0x0, // background palette 2
0x06,0x16,0x26,0x0, // background palette 3
0x16,0x35,0x24,0x00, // enemy sprites
0x00,0x37,0x25,0x00, // rescue person
0x0D,0x2D,0x1A,0x00,
0x0D,0x27,0x2A // player sprites
0x16,0x35,0x24,0x0, // sprite palette 0
0x00,0x37,0x25,0x0, // sprite palette 1
0x0d,0x2d,0x3a,0x0, // sprite palette 2
0x0d,0x27,0x2a // sprite palette 3
};
// setup PPU and tables
@ -87,11 +53,11 @@ void setup_graphics() {
#define NUM_ACTORS 16
// actor x/y positions
char actor_x[NUM_ACTORS];
char actor_y[NUM_ACTORS];
// actor x/y deltas per frame
char actor_dx[NUM_ACTORS];
char actor_dy[NUM_ACTORS];
byte actor_x[NUM_ACTORS];
byte actor_y[NUM_ACTORS];
// actor x/y deltas per frame (signed)
sbyte actor_dx[NUM_ACTORS];
sbyte actor_dy[NUM_ACTORS];
// main program
void main() {
@ -112,8 +78,7 @@ void main() {
oam_id = 0;
// draw and move all actors
for (i=0; i<NUM_ACTORS; i++) {
oam_id = oam_meta_spr(actor_x[i], actor_y[i], oam_id,
playerRunSeq[i&15]);
oam_id = oam_meta_spr(actor_x[i], actor_y[i], oam_id, metasprite);
actor_x[i] += actor_dx[i];
actor_y[i] += actor_dy[i];
}

View File

@ -87,11 +87,11 @@ void setup_graphics() {
#define NUM_ACTORS 16
// actor x/y positions
char actor_x[NUM_ACTORS];
char actor_y[NUM_ACTORS];
// actor x/y deltas per frame
char actor_dx[NUM_ACTORS];
char actor_dy[NUM_ACTORS];
byte actor_x[NUM_ACTORS];
byte actor_y[NUM_ACTORS];
// actor x/y deltas per frame (signed)
sbyte actor_dx[NUM_ACTORS];
sbyte actor_dy[NUM_ACTORS];
// main program
void main() {

View File

@ -22,22 +22,23 @@ void scroll_demo() {
while (1) {
// wait for next frame
ppu_wait_frame();
// set scroll register
scroll(x, y);
// update y variable
y += dy;
// change direction when hitting either edge of scroll area
if (y >= 479) dy = -1;
if (y == 0) dy = 1;
// set scroll register
scroll(x, y);
}
}
// main function, run after console reset
void main(void) {
// set palette colors
pal_col(1,0x04);
pal_col(2,0x20);
pal_col(3,0x30);
pal_col(0,0x02); // set screen to dark blue
pal_col(1,0x14); // pink
pal_col(2,0x20); // grey
pal_col(3,0x30); // white
// write text to name table
put_str(NTADR_A(2,0), "Nametable A, Line 0");

View File

@ -5,25 +5,22 @@
// include NESLIB header
#include "neslib.h"
// include CC65 NES Header (PPU)
#include <nes.h>
// link the pattern table into CHR ROM
//#link "chr_generic.s"
/*{pal:"nes",layout:"nes"}*/
const char PALETTE[32] = {
0x03, // background color
0x03, // screen color
0x11,0x30,0x27,0x0, // ladders and pickups
0x1c,0x20,0x2c,0x0, // floor blocks
0x00,0x10,0x20,0x0,
0x06,0x16,0x26,0x0,
0x11,0x30,0x27,0x0, // background palette 0
0x1c,0x20,0x2c,0x0, // background palette 1
0x00,0x10,0x20,0x0, // background palette 2
0x06,0x16,0x26,0x0, // background palette 3
0x16,0x35,0x24,0x0, // enemy sprites
0x00,0x37,0x25,0x0, // rescue person
0x0d,0x2d,0x3a,0x0,
0x0d,0x27,0x2a // player sprites
0x16,0x35,0x24,0x0, // sprite palette 0
0x00,0x37,0x25,0x0, // sprite palette 1
0x0d,0x2d,0x3a,0x0, // sprite palette 2
0x0d,0x27,0x2a // sprite palette 3
};
// setup PPU and tables
@ -40,11 +37,11 @@ void setup_graphics() {
#define NUM_ACTORS 64
// actor x/y positions
char actor_x[NUM_ACTORS];
char actor_y[NUM_ACTORS];
// actor x/y deltas per frame
char actor_dx[NUM_ACTORS];
char actor_dy[NUM_ACTORS];
byte actor_x[NUM_ACTORS];
byte actor_y[NUM_ACTORS];
// actor x/y deltas per frame (signed)
sbyte actor_dx[NUM_ACTORS];
sbyte actor_dy[NUM_ACTORS];
// main program
void main() {

View File

@ -19,14 +19,13 @@ void put_str(unsigned int adr, const char *str) {
// function to scroll window up and down until end
void scroll_demo() {
int x = 0; // x scroll position
int y = 0; // y scroll position
int dx = 1; // y scroll direction
int dx = 1; // x scroll direction
// infinite loop
while (1) {
// set scroll register
// waits for NMI, which means no frame-skip?
split(x, 0);
// update y variable
// update x variable
x += dx;
// change direction when hitting either edge of scroll area
if (x >= 479) dx = -1;
@ -64,7 +63,7 @@ void main(void) {
// set sprite 0
oam_clear();
oam_spr(1, 30, 0xa0, 1, 0);
oam_spr(1, 30, 0xa0, 0, 0);
// enable PPU rendering (turn on screen)
ppu_on_all();

View File

@ -24,26 +24,25 @@ void scroll_demo() {
// write message to string array
sprintf(str, "%6x %6d", y, y);
// write string array into VRAM buffer
// if buffer is full this will wait for next frame
vrambuf_put(NTADR_A(2,y%30), str, 32);
// wait for next frame
// and flush VRAM buffer
vrambuf_flush();
// set scroll (shadow) registers
scroll(x, y);
// update y variable
y += dy;
// change direction when hitting either edge of scroll area
if (y >= 479) dy = -1;
if (y == 0) dy = 1;
// set scroll (shadow) registers
scroll(x, y);
}
}
// main function, run after console reset
void main(void) {
// set palette colors
pal_col(1,0x04);
pal_col(2,0x20);
pal_col(3,0x30);
pal_col(0,0x02); // set screen to dark blue
pal_col(1,0x14); // pink
pal_col(2,0x20); // grey
pal_col(3,0x30); // white
// clear vram buffer
vrambuf_clear();

View File

@ -21,7 +21,6 @@ const JSNES_PRESETS = [
{id:'metasprites.c', name:'Metasprites'},
{id:'flicker.c', name:'Flickering Sprites'},
{id:'metacursor.c', name:'Controllers'},
{id:'metatrigger.c', name:'Trigger Mode + Vbright'},
{id:'rletitle.c', name:'Title Screen RLE'},
{id:'statusbar.c', name:'Split Status Bar'},
{id:'horizmask.c', name:'Offscreen Scrolling'},
@ -114,6 +113,7 @@ class JSNESPlatform extends Base6502Platform implements Platform {
},
//TODO: onBatteryRamWrite
});
//this.nes.ppu.showSpr0Hit = true;
//this.nes.ppu.clipToTvSize = false;
this.nes.stop = () => {
// TODO: trigger breakpoint