2019-02-15 18:54:15 +00:00
|
|
|
|
|
|
|
#include "neslib.h"
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-02-21 19:19:29 +00:00
|
|
|
// link the pattern table into CHR ROM
|
|
|
|
//#link "chr_generic.s"
|
2019-02-15 18:54:15 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 dy = 1; // y scroll direction
|
|
|
|
// infinite loop
|
|
|
|
while (1) {
|
|
|
|
// wait for next frame
|
|
|
|
ppu_wait_frame();
|
|
|
|
// update y variable
|
|
|
|
y += dy;
|
|
|
|
// change direction when hitting either edge of scroll area
|
|
|
|
if (y >= 479) dy = -1;
|
|
|
|
if (y == 0) dy = 1;
|
2019-04-15 23:37:11 +00:00
|
|
|
// set scroll register
|
|
|
|
scroll(x, y);
|
2019-02-15 18:54:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// main function, run after console reset
|
|
|
|
void main(void) {
|
|
|
|
// set palette colors
|
2019-04-15 23:37:11 +00:00
|
|
|
pal_col(0,0x02); // set screen to dark blue
|
|
|
|
pal_col(1,0x14); // pink
|
|
|
|
pal_col(2,0x20); // grey
|
|
|
|
pal_col(3,0x30); // white
|
2019-02-15 18:54:15 +00:00
|
|
|
|
|
|
|
// write text to name table
|
|
|
|
put_str(NTADR_A(2,0), "Nametable A, Line 0");
|
|
|
|
put_str(NTADR_A(2,15), "Nametable A, Line 15");
|
|
|
|
put_str(NTADR_A(2,29),"Nametable A, Line 29");
|
|
|
|
put_str(NTADR_C(2,0), "Nametable C, Line 0");
|
|
|
|
put_str(NTADR_C(2,15), "Nametable C, Line 15");
|
|
|
|
put_str(NTADR_C(2,29),"Nametable C, Line 29");
|
|
|
|
|
|
|
|
// enable PPU rendering (turn on screen)
|
|
|
|
ppu_on_all();
|
|
|
|
|
|
|
|
// scroll window back and forth
|
|
|
|
scroll_demo();
|
|
|
|
}
|