1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-01 05:41:31 +00:00

nes: updated presets

This commit is contained in:
Steven Hugg 2019-07-25 21:23:47 -04:00
parent 6fdc366d03
commit 5c9f05da23
4 changed files with 20 additions and 6 deletions

View File

@ -9,6 +9,8 @@ Press controller buttons to hear sound effects.
// link the pattern table into CHR ROM // link the pattern table into CHR ROM
//#link "chr_generic.s" //#link "chr_generic.s"
// setup Famitone library
//#link "famitone2.s" //#link "famitone2.s"
void __fastcall__ famitone_update(void); void __fastcall__ famitone_update(void);
//#link "music_aftertherain.s" //#link "music_aftertherain.s"
@ -29,7 +31,7 @@ void main(void)
//famitone_init(after_the_rain_music_data); //famitone_init(after_the_rain_music_data);
famitone_init(danger_streets_music_data); famitone_init(danger_streets_music_data);
sfx_init(demo_sounds); sfx_init(demo_sounds);
// set music callback // set music callback function for NMI
nmi_set_callback(famitone_update); nmi_set_callback(famitone_update);
// play music // play music
music_play(0); music_play(0);

View File

@ -140,6 +140,7 @@ void update_offscreen() {
} }
} }
// scrolls the screen left one pixel
void scroll_left() { void scroll_left() {
// update nametable every 16 pixels // update nametable every 16 pixels
if ((x_scroll & 15) == 0) { if ((x_scroll & 15) == 0) {
@ -149,7 +150,7 @@ void scroll_left() {
++x_scroll; ++x_scroll;
} }
// function to scroll window up and down until end // main loop, scrolls left continuously
void scroll_demo() { void scroll_demo() {
// get data for initial segment // get data for initial segment
new_segment(); new_segment();
@ -159,7 +160,7 @@ void scroll_demo() {
// ensure VRAM buffer is cleared // ensure VRAM buffer is cleared
ppu_wait_nmi(); ppu_wait_nmi();
vrambuf_clear(); vrambuf_clear();
// split at x_scroll // split at sprite zero and set X scroll
split(x_scroll, 0); split(x_scroll, 0);
// scroll to the left // scroll to the left
scroll_left(); scroll_left();

View File

@ -16,11 +16,13 @@ that display their own pixels.
bool ppu_is_on = false; bool ppu_is_on = false;
// simple 6502 delay loop (5 cycles per loop)
#define DELAYLOOP(n) \ #define DELAYLOOP(n) \
__asm__("ldy #%b", n); \ __asm__("ldy #%b", n); \
__asm__("@1: dey"); \ __asm__("@1: dey"); \
__asm__("bne @1"); __asm__("bne @1");
// call every frame to split screen
void monobitmap_split() { void monobitmap_split() {
// split screen at line 128 // split screen at line 128
split(0,0); split(0,0);
@ -28,6 +30,7 @@ void monobitmap_split() {
PPU.control = PPU.control ^ 0x10; // bg bank 1 PPU.control = PPU.control ^ 0x10; // bg bank 1
} }
// set a pixel at (x,y) color 1=set, 0=clear
void monobitmap_set_pixel(byte x, byte y, byte color) { void monobitmap_set_pixel(byte x, byte y, byte color) {
byte b; byte b;
// compute pattern table address // compute pattern table address
@ -56,6 +59,7 @@ void monobitmap_set_pixel(byte x, byte y, byte color) {
} }
} }
// draw a line from (x0,y0) to (x1,y1)
void monobitmap_draw_line(int x0, int y0, int x1, int y1, byte color) { void monobitmap_draw_line(int x0, int y0, int x1, int y1, byte color) {
int dx = abs(x1-x0); int dx = abs(x1-x0);
int sx = x0<x1 ? 1 : -1; int sx = x0<x1 ? 1 : -1;
@ -72,24 +76,26 @@ void monobitmap_draw_line(int x0, int y0, int x1, int y1, byte color) {
} }
} }
// write values 0..255 // write values 0..255 to nametable
void monobitmap_put_256inc() { void monobitmap_put_256inc() {
word i; word i;
for (i=0; i<256; i++) for (i=0; i<256; i++)
vram_put(i); vram_put(i);
} }
// sets up attribute table
void monobitmap_put_attrib() { void monobitmap_put_attrib() {
vram_fill(0x00, 0x10); // first palette vram_fill(0x00, 0x10); // first palette
vram_fill(0x55, 0x10); // second palette vram_fill(0x55, 0x10); // second palette
} }
// clears pattern table
void monobitmap_clear() { void monobitmap_clear() {
// clear pattern table
vram_adr(0x0); vram_adr(0x0);
vram_fill(0x0, 0x2000); vram_fill(0x0, 0x2000);
} }
// sets up PPU for monochrome bitmap
void monobitmap_setup() { void monobitmap_setup() {
monobitmap_clear(); monobitmap_clear();
// setup nametable A and B // setup nametable A and B
@ -123,6 +129,7 @@ const byte MONOBMP_PALETTE[16] = {
0x03, 0x30, 0x30 0x03, 0x30, 0x30
}; };
// demo function, draws a bunch of lines
void monobitmap_demo() { void monobitmap_demo() {
byte i; byte i;
static const byte x1 = 16; static const byte x1 = 16;
@ -147,17 +154,21 @@ void monobitmap_demo() {
void main(void) void main(void)
{ {
// setup and draw some lines
monobitmap_setup(); monobitmap_setup();
pal_bg(MONOBMP_PALETTE); pal_bg(MONOBMP_PALETTE);
monobitmap_demo(); monobitmap_demo();
ppu_on_all(); ppu_on_all();
// wait for key press
while (!pad_trigger(0)) { while (!pad_trigger(0)) {
ppu_wait_nmi(); ppu_wait_nmi();
monobitmap_split(); monobitmap_split();
} }
// set up again
ppu_off(); ppu_off();
monobitmap_setup(); monobitmap_setup();
ppu_on_all(); ppu_on_all();
// realtime display where 1 pixel per frame
ppu_is_on = true; ppu_is_on = true;
monobitmap_demo(); monobitmap_demo();
while(1) { while(1) {

View File

@ -19,12 +19,12 @@ const JSNES_PRESETS = [
{id:'metacursor.c', name:'Controllers'}, {id:'metacursor.c', name:'Controllers'},
{id:'vrambuffer.c', name:'VRAM Buffer'}, {id:'vrambuffer.c', name:'VRAM Buffer'},
{id:'statusbar.c', name:'Split Status Bar'}, {id:'statusbar.c', name:'Split Status Bar'},
{id:'horizscroll.c', name:'Offscreen Scrolling'},
{id:'siegegame.c', name:'Siege Game'}, {id:'siegegame.c', name:'Siege Game'},
{id:'tint.c', name:'Color Emphasis'}, {id:'tint.c', name:'Color Emphasis'},
{id:'rletitle.c', name:'Title Screen RLE'}, {id:'rletitle.c', name:'Title Screen RLE'},
{id:'aputest.c', name:'Sound Tester'}, {id:'aputest.c', name:'Sound Tester'},
{id:'music.c', name:'Music Player'}, {id:'music.c', name:'Music Player'},
{id:'horizscroll.c', name:'Offscreen Scrolling'},
{id:'monobitmap.c', name:'Monochrome Bitmap'}, {id:'monobitmap.c', name:'Monochrome Bitmap'},
{id:'fami.c', name:'Famitone Demo'}, {id:'fami.c', name:'Famitone Demo'},
{id:'shoot2.c', name:'Solarian Game'}, {id:'shoot2.c', name:'Solarian Game'},