mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-23 06:32:11 +00:00
138 lines
6.2 KiB
C
138 lines
6.2 KiB
C
|
|
//this example code shows how to put some text in nametable
|
|
|
|
#include "neslib.h"
|
|
|
|
#include <string.h>
|
|
|
|
#pragma data-name (push,"CHARS")
|
|
#pragma data-name(pop)
|
|
|
|
const unsigned char TILESET[48*16] = {/*{w:8,h:8,bpp:1,count:48,brev:1,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}*/
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
0x7e,0x42,0x42,0x46,0x46,0x46,0x7e,0x00,0x7e,0x42,0x42,0x46,0x46,0x46,0x7e,0x00,
|
|
0x08,0x08,0x08,0x18,0x18,0x18,0x18,0x00,0x08,0x08,0x08,0x18,0x18,0x18,0x18,0x00,
|
|
0x3e,0x22,0x02,0x3e,0x30,0x30,0x3e,0x00,0x3e,0x22,0x02,0x3e,0x30,0x30,0x3e,0x00,
|
|
0x3c,0x24,0x04,0x1e,0x06,0x26,0x3e,0x00,0x3c,0x24,0x04,0x1e,0x06,0x26,0x3e,0x00,
|
|
0x44,0x44,0x44,0x7e,0x0c,0x0c,0x0c,0x00,0x44,0x44,0x44,0x7e,0x0c,0x0c,0x0c,0x00,
|
|
0x3c,0x20,0x20,0x3e,0x06,0x26,0x3e,0x00,0x3c,0x20,0x20,0x3e,0x06,0x26,0x3e,0x00,
|
|
0x3e,0x22,0x20,0x3e,0x26,0x26,0x3e,0x00,0x3e,0x22,0x20,0x3e,0x26,0x26,0x3e,0x00,
|
|
0x3e,0x02,0x02,0x06,0x06,0x06,0x06,0x00,0x3e,0x02,0x02,0x06,0x06,0x06,0x06,0x00,
|
|
0x3c,0x24,0x24,0x7e,0x46,0x46,0x7e,0x00,0x3c,0x24,0x24,0x7e,0x46,0x46,0x7e,0x00,
|
|
0x3e,0x22,0x22,0x3e,0x06,0x06,0x06,0x00,0x3e,0x22,0x22,0x3e,0x06,0x06,0x06,0x00,
|
|
0x3c,0x24,0x24,0x7e,0x62,0x62,0x62,0x00,0x3c,0x24,0x24,0x7e,0x62,0x62,0x62,0x00,
|
|
0x7c,0x44,0x44,0x7e,0x62,0x62,0x7e,0x00,0x7c,0x44,0x44,0x7e,0x62,0x62,0x7e,0x00,
|
|
0x7e,0x42,0x40,0x60,0x60,0x62,0x7e,0x00,0x7e,0x42,0x40,0x60,0x60,0x62,0x7e,0x00,
|
|
0x7e,0x42,0x42,0x62,0x62,0x62,0x7e,0x00,0x7e,0x42,0x42,0x62,0x62,0x62,0x7e,0x00,
|
|
0x7c,0x40,0x40,0x7c,0x60,0x60,0x7c,0x00,0x7c,0x40,0x40,0x7c,0x60,0x60,0x7c,0x00,
|
|
0x3c,0x20,0x20,0x3c,0x30,0x30,0x30,0x00,0x3c,0x20,0x20,0x3c,0x30,0x30,0x30,0x00,
|
|
0x7e,0x42,0x40,0x6e,0x62,0x62,0x7e,0x00,0x7e,0x42,0x40,0x6e,0x62,0x62,0x7e,0x00,
|
|
0x42,0x42,0x42,0x7e,0x62,0x62,0x62,0x00,0x42,0x42,0x42,0x7e,0x62,0x62,0x62,0x00,
|
|
0x10,0x10,0x10,0x18,0x18,0x18,0x18,0x00,0x10,0x10,0x10,0x18,0x18,0x18,0x18,0x00,
|
|
0x04,0x04,0x04,0x06,0x06,0x46,0x7e,0x00,0x04,0x04,0x04,0x06,0x06,0x46,0x7e,0x00,
|
|
0x44,0x44,0x44,0x7e,0x62,0x62,0x62,0x00,0x44,0x44,0x44,0x7e,0x62,0x62,0x62,0x00,
|
|
0x20,0x20,0x20,0x30,0x30,0x30,0x3e,0x00,0x20,0x20,0x20,0x30,0x30,0x30,0x3e,0x00,
|
|
0xfe,0x92,0x92,0xd2,0xd2,0xd2,0xd2,0x00,0xfe,0x92,0x92,0xd2,0xd2,0xd2,0xd2,0x00,
|
|
0x7e,0x42,0x42,0x62,0x62,0x62,0x62,0x00,0x7e,0x42,0x42,0x62,0x62,0x62,0x62,0x00,
|
|
0x7e,0x46,0x46,0x42,0x42,0x42,0x7e,0x00,0x7e,0x46,0x46,0x42,0x42,0x42,0x7e,0x00,
|
|
0x7e,0x42,0x42,0x7e,0x60,0x60,0x60,0x00,0x7e,0x42,0x42,0x7e,0x60,0x60,0x60,0x00,
|
|
0x7e,0x42,0x42,0x42,0x42,0x4e,0x7e,0x00,0x7e,0x42,0x42,0x42,0x42,0x4e,0x7e,0x00,
|
|
0x7c,0x44,0x44,0x7e,0x62,0x62,0x62,0x00,0x7c,0x44,0x44,0x7e,0x62,0x62,0x62,0x00,
|
|
0x7e,0x42,0x40,0x7e,0x06,0x46,0x7e,0x00,0x7e,0x42,0x40,0x7e,0x06,0x46,0x7e,0x00,
|
|
0x7e,0x10,0x10,0x18,0x18,0x18,0x18,0x00,0x7e,0x10,0x10,0x18,0x18,0x18,0x18,0x00,
|
|
0x42,0x42,0x42,0x62,0x62,0x62,0x7e,0x00,0x42,0x42,0x42,0x62,0x62,0x62,0x7e,0x00,
|
|
0x64,0x64,0x64,0x64,0x2c,0x2c,0x3c,0x00,0x64,0x64,0x64,0x64,0x2c,0x2c,0x3c,0x00,
|
|
0x49,0x49,0x49,0x49,0x69,0x69,0x7f,0x00,0x49,0x49,0x49,0x49,0x69,0x69,0x7f,0x00,
|
|
0x42,0x42,0x42,0x3c,0x62,0x62,0x62,0x00,0x42,0x42,0x42,0x3c,0x62,0x62,0x62,0x00,
|
|
0x42,0x42,0x42,0x7e,0x18,0x18,0x18,0x00,0x42,0x42,0x42,0x7e,0x18,0x18,0x18,0x00,
|
|
0x7e,0x42,0x02,0x7e,0x60,0x62,0x7e,0x00,0x7e,0x42,0x02,0x7e,0x60,0x42,0x7e,0x00,
|
|
0x10,0x10,0x18,0x18,0x18,0x00,0x18,0x00,0x10,0x10,0x18,0x18,0x18,0x00,0x18,0x00,
|
|
0x18,0x7e,0x40,0x7e,0x06,0x7e,0x18,0x00,0x18,0x7e,0x40,0x7e,0x06,0x7e,0x18,0x00,
|
|
0x00,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x18,0x00,0x00,0x00,
|
|
0x00,0x00,0x3c,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x3c,0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
|
|
0x18,0x18,0x08,0x10,0x00,0x00,0x00,0x00,0x18,0x18,0x08,0x10,0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x18,0x18,0x08,0x10,0x00,0x00,0x00,0x00,0x18,0x18,0x08,0x10,0x00,
|
|
0x7c,0x7c,0x7c,0x7c,0x7c,0x7c,0x7c,0x00,0x7c,0x7c,0x7c,0x7c,0x7c,0x7c,0x7c,0x00,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
};
|
|
|
|
void put_str(unsigned int addr, char* str) {
|
|
vram_adr(addr);
|
|
vram_write(str, strlen(str));
|
|
}
|
|
|
|
#pragma charmap(0x20, 0x2f);
|
|
#pragma charmap('!', 0x25);
|
|
#pragma charmap('$', 0x26);
|
|
#pragma charmap(':', 0x27);
|
|
#pragma charmap('-', 0x28);
|
|
#pragma charmap('.', 0x29);
|
|
#pragma charmap('\'', 0x2a);
|
|
#pragma charmap(',', 0x2b);
|
|
#pragma charmap('#', 0x2c);
|
|
#pragma charmap('_', 0x2d);
|
|
// 0-9
|
|
#pragma charmap(0x30, 0x1);
|
|
#pragma charmap(0x31, 0x2);
|
|
#pragma charmap(0x32, 0x3);
|
|
#pragma charmap(0x33, 0x4);
|
|
#pragma charmap(0x34, 0x5);
|
|
#pragma charmap(0x35, 0x6);
|
|
#pragma charmap(0x36, 0x7);
|
|
#pragma charmap(0x37, 0x8);
|
|
#pragma charmap(0x38, 0x9);
|
|
#pragma charmap(0x39, 0xa);
|
|
// A-Z
|
|
#pragma charmap(0x41, 0xb);
|
|
#pragma charmap(0x42, 0xc);
|
|
#pragma charmap(0x43, 0xd);
|
|
#pragma charmap(0x44, 0xe);
|
|
#pragma charmap(0x45, 0xf);
|
|
#pragma charmap(0x46, 0x10);
|
|
#pragma charmap(0x47, 0x11);
|
|
#pragma charmap(0x48, 0x12);
|
|
#pragma charmap(0x49, 0x13);
|
|
#pragma charmap(0x4a, 0x14);
|
|
#pragma charmap(0x4b, 0x15);
|
|
#pragma charmap(0x4c, 0x16);
|
|
#pragma charmap(0x4d, 0x17);
|
|
#pragma charmap(0x4e, 0x18);
|
|
#pragma charmap(0x4f, 0x19);
|
|
#pragma charmap(0x50, 0x1a);
|
|
#pragma charmap(0x51, 0x1b);
|
|
#pragma charmap(0x52, 0x1c);
|
|
#pragma charmap(0x53, 0x1d);
|
|
#pragma charmap(0x54, 0x1e);
|
|
#pragma charmap(0x55, 0x1f);
|
|
#pragma charmap(0x56, 0x20);
|
|
#pragma charmap(0x57, 0x21);
|
|
#pragma charmap(0x58, 0x22);
|
|
#pragma charmap(0x59, 0x23);
|
|
#pragma charmap(0x5a, 0x24);
|
|
|
|
|
|
void main(void)
|
|
{
|
|
//copy tileset to RAM
|
|
vram_adr(0x0);
|
|
vram_write((unsigned char*)TILESET, sizeof(TILESET));
|
|
// set palette color
|
|
pal_col(0,0x0);
|
|
pal_col(3,0x30);
|
|
|
|
put_str(NTADR_A(2,2),"HELLO, WORLD!");
|
|
put_str(NTADR_A(2,4),"THIS CODE PRINTS SOME TEXT");
|
|
put_str(NTADR_A(2,5),"USING CC65'S TRANSLATION");
|
|
put_str(NTADR_A(2,6),"TABLE PRAGMAS, ALLOWING US");
|
|
put_str(NTADR_A(2,7),"TO PUT TILES IN ANY ORDER");
|
|
put_str(NTADR_A(2,8),"-- EXCEPT CAN'T USE ZERO");
|
|
put_str(NTADR_A(2,10),"# $0123456789 A-Z _MAIN #");
|
|
|
|
ppu_on_all();//enable rendering
|
|
|
|
while(1);//do nothing, infinite loop
|
|
}
|