1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-30 06:50:39 +00:00
8bitworkshop/presets/nes/attributes.c

52 lines
1.5 KiB
C
Raw Normal View History

2019-05-22 15:45:05 +00:00
/*
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 <string.h>
#include <stdlib.h>
2019-03-10 16:17:12 +00:00
// link the pattern table into CHR ROM
//#link "chr_generic.s"
2019-05-16 14:08:01 +00:00
// attribute table in PRG ROM
const char ATTRIBUTE_TABLE[0x40] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // rows 0-3
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, // rows 4-7
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, // rows 8-11
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // rows 12-15
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // rows 16-19
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, // rows 20-23
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // rows 24-27
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f // rows 28-29
};
2019-07-04 19:22:42 +00:00
/*{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) {
2019-05-16 14:08:01 +00:00
// set background palette colors
2019-03-10 16:17:12 +00:00
pal_bg(PALETTE);
2019-05-16 14:08:01 +00:00
// fill nametable with diamonds
2019-05-21 17:06:48 +00:00
vram_adr(NAMETABLE_A); // start address ($2000)
vram_fill(0x16, 32*30); // fill nametable (960 bytes)
2019-05-16 14:08:01 +00:00
// copy attribute table from PRG ROM to VRAM
vram_write(ATTRIBUTE_TABLE, sizeof(ATTRIBUTE_TABLE));
// enable PPU rendering (turn on screen)
ppu_on_all();
// infinite loop
2019-05-16 14:08:01 +00:00
while (1) { }
}