1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-26 10:49:17 +00:00

VCS has memory map; nes presets

This commit is contained in:
Steven Hugg 2019-02-22 12:27:09 -05:00
parent 3c911b8869
commit 4e3ac25318
3 changed files with 138 additions and 3 deletions

128
presets/nes/flicker.c Normal file
View File

@ -0,0 +1,128 @@
#include <stdlib.h>
#include <string.h>
// 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"
///// METASPRITES
// define a 2x2 metasprite
#define DEF_METASPRITE_2x2(name,code,pal)\
const unsigned char name[]={\
0, 0, (code)+0, pal, \
8, 0, (code)+1, pal, \
0, 8, (code)+2, pal, \
8, 8, (code)+3, pal, \
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, \
0, 0, (code)+1, (pal)|OAM_FLIP_H, \
8, 8, (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,
};
const char PALETTE[32] = {
0x03, // background color
0x11,0x30,0x27, 0, // ladders and pickups
0x1c,0x20,0x2c, 0, // floor blocks
0x00,0x10,0x20, 0,
0x06,0x16,0x26, 0,
0x16,0x35,0x24, 0, // enemy sprites
0x00,0x37,0x25, 0, // rescue person
0x0d,0x2d,0x3a, 0,
0x0d,0x27,0x2a // player sprites
};
// setup PPU and tables
void setup_graphics() {
// clear sprites
oam_clear();
// set palette colors
pal_all(PALETTE);
// turn on PPU
ppu_on_all();
}
// number of actors (4 h/w sprites each)
#define NUM_ACTORS 48
// 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];
// main program
void main() {
char i;
char oam_id;
setup_graphics();
// initialize actors with random values
for (i=0; i<NUM_ACTORS; i++) {
actor_x[i] = rand();
actor_y[i] = rand();
actor_dx[i] = (rand() & 7) - 3;
actor_dy[i] = (rand() & 7) - 3;
}
// loop forever
while (1) {
// start with OAMid/sprite 0
oam_id = 0;
// draw and move all actors
// (note we don't reset i each loop iteration)
while (oam_id < 252) {
// 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]);
actor_x[i] += actor_dx[i];
actor_y[i] += actor_dy[i];
i++;
}
// hide rest of sprites
oam_hide_rest(oam_id);
// wait for next frame
ppu_wait_frame();
}
}

View File

@ -19,6 +19,7 @@ const JSNES_PRESETS = [
{id:'statusbar.c', name:'Status Bar'},
{id:'sprites.c', name:'Sprites'},
{id:'metasprites.c', name:'Metasprites'},
{id:'flicker.c', name:'Flickering Sprites'},
{id:'metacursor.c', name:'Controllers'},
{id:'neslib5.c', name:'RLE Unpack'},
{id:'music.c', name:'Music Player'},
@ -92,7 +93,6 @@ const _JSNESPlatform = function(mainElement) {
ntvideo.create();
$(ntvideo.canvas).hide();
ntlastbuf = new Uint32Array(0x1000);
ntlastbuf.fill(-1);
// toggle buttons
$('<button>').text("Video").appendTo(debugbar).click(() => { $(video.canvas).toggle() });
$('<button>').text("Nametable").appendTo(debugbar).click(() => { $(ntvideo.canvas).toggle() });
@ -157,7 +157,6 @@ const _JSNESPlatform = function(mainElement) {
// don't update if view is hidden
if (! $(ntvideo.canvas).is(":visible"))
return;
// TODO: doesn't work on scrolling example
var a = 0;
var attraddr = 0;
var idata = ntvideo.getFrameData();
@ -171,7 +170,7 @@ const _JSNESPlatform = function(mainElement) {
var t = nes.ppu.ptTile[name];
attraddr = (a & 0x2c00) | 0x3c0 | (a & 0x0C00) | ((a >> 4) & 0x38) | ((a >> 2) & 0x07);
var attr = nes.ppu.mirroredLoad(attraddr);
var tag = name ^ (attr<<9);
var tag = name ^ (attr<<9) ^ 0x80000000;
if (tag != ntlastbuf[a & 0xfff]) {
ntlastbuf[a & 0xfff] = tag;
var i = row*64*8*8 + col*8;

View File

@ -43,6 +43,12 @@ var PLATFORM_PARAMS = {
code_size: 0xf000,
data_start: 0x80,
data_size: 0x80,
extra_segments:[
{name:'TIA Registers',start:0x00,size:0x80,type:'io'},
{name:'PIA RAM',start:0x80,size:0x80,type:'ram'},
{name:'PIA Ports and Timer',start:0x280,size:0x18,type:'io'},
{name:'Cartridge ROM',start:0xf000,size:0x1000,type:'rom'},
],
},
'mw8080bw': {
code_start: 0x0,
@ -762,11 +768,13 @@ function assembleDASM(step:BuildStep) {
lst.text = alst;
lst.lines = [];
}
var segments = step.params.extra_segments;
return {
output:aout,
listings:listings,
errors:errors,
symbolmap:symbolmap,
segments:segments
};
}