<commit_before>/*
	demos.c : functions to show off kernel features :P.
	(C)2012-2013 <NAME>, UnSX Team.
	Part of AliceOS, the Alice Operating System.
	Released under the MIT License.
*/
#include <demos.h>
#include <sys/types.h>
#include <sys/helpers.h>
#include <kdefs.h>
#include <krand.h>
#include <printk.h>
#include <serial.h>
#include <berp.h>
#include <fs/ramdisk.h>
#include <vga/palettes.h>
#include <vga/font.h>
#include <vga/mode13h.h>
#include <vga/mode12h.h>
#include <vga/mode3h.h>

demo_t demos[DEMO_COUNT] =
{
	{"blockgfx", "80x50 16-color block graphics demo", demo_blockgfx},
	{"crapgfx", "basic mode 12h demo", demo_crapgfx},
	{"realgfx", "basic mode 13h demo", demo_realgfx},
	{"cmap", "text mode character map", demo_cmap},
};

/* list available demos */
void listdemos( void )
{
	unsigned int i;
	mode_3h.fbputs("Available demos:\n");
	for ( i=0; i<DEMO_COUNT; i++ )
		mode_3h.fbprintf(" - %s : %s\n",demos[i].name,demos[i].desc);
}

/* Character map */
void demo_cmap( void )
{
	/* no startup code, we already assume we're in mode 3h since boot */
	mode_3h.fbsetattr(15,0,EXATTR_NOSCR);
	Uint16 i;
	Uint16 x,y;
	x = 4;
	y = 4;
	for ( i=0; i<128; i++ )
	{
		mode_3h.drawchar(x,y,i);
		x++;
		if ( x >= 20 )
		{
			x = 4;
			y++;
		}
	}
	x = 24;
	y = 4;
	for ( i=128; i<256; i++ )
	{
		mode_3h.drawchar(x,y,i);
		x++;
		if ( x >= 40 )
		{
			x = 24;
			y++;
		}
	}
}

/* 80x50 graphics demo */
void demo_blockgfx( void )
{
	/* no startup code, we already assume we're in mode 3h since boot */
	mode_3h.fbsetattr(15,0,EXATTR_NOSCR);
	printk(SERIAL_A,"Running Block GFX demo\n");
	img_t aliceimg;
	if ( loadimg(&aliceimg,"alice3h.img") )
		BERP("error loading alice3h.img");
	mode_3h.clear();
	mode_3h.drawimg(&aliceimg,0,0,0,0,80,50,0);
	mode_3h.drawrect(50,21,25,8,4);
	mode_3h.fbprintf("%[4E%{51,11%s %s%{51,13%s.%s.%s%s (%s)",_kname,_kver_code,_kver_maj,_kver_min,_kver_low,_kver_suf,_karch);
	mode_3h.drawhline(0,0,80,7);
	mode_3h.drawhline(0,49,80,7);
	mode_3h.drawvline(0,0,50,7);
	mode_3h.drawvline(79,0,50,7);
}

/* mode 12h graphics demo */
void demo_crapgfx( void )
{
	printk(SERIAL_A,"Running Mode 12h GFX demo\n");
	mode_12h.setmode();
	mode_12h.setpal(&alicepal[0]);
	fnt_t font8;
	if ( loadfnt(&font8,"fbfont8.fnt") )
		BERP("error loading fbfont8.fnt");
	mode_12h.setfont(&font8);
	Uint16 x,y;
	int i = 0;
	/* 16 color set */
	x = 8;
	y = 8;
	while ( i < 16 )
	{
		mode_12h.drawrect(x,y,32,32,i);
		x+=32;
		if ( !((++i)%8) )
		{
			x=8;
			y+=32;
		}
	}
	
	/* draw some colorful noise */
	x = 272;
	y = 8;
	do
	{
		mode_12h.putpixel(x,y,krand()%16);
		x++;
		if ( x >= 528 )
		{
			x = 272;
			y++;
		}
	}
	while ( (x < 528) && (y < 72) );
	
	/* there's enough space to draw this */
	img_t aliceimg;
	if ( loadimg(&aliceimg,"alice13h_16.img") )
		BERP("error loading alice13h_16.img");
	mode_12h.drawimg(&aliceimg,8,80,0,0,320,200,0);
	
	img_t aliceimg2;
	if ( loadimg(&aliceimg2,"alice3h.img") )
		BERP("error loading alice3h.img");
	mode_12h.drawimg(&aliceimg2,336,80,0,0,80,50,0);

	/* draw test strings */
	mode_12h.fbsetattr(7,0,EXATTR_MASKED);
	mode_12h.fbprintf("%[E%{1,-3%s %s%{1,-2%s.%s.%s%s  (%s)",_kname,_kver_code,_kver_maj,_kver_min,_kver_low,_kver_suf,_karch);
	mode_12h.fbprintf("%[7%{-14,-2Mode 12h test");
	mode_12h.fbsetattr(7,0,EXATTR_MASKED|EXATTR_RCW90);
	mode_12h.fbprintf("%[F%{-3,2R%{-3,3o%{-3,4t%{-3,5a%{-3,6t%{-3,7e%{-3,8d%{-3,10t%{-3,11e%{-3,12x%{-3,13t");
	
	/* draw some lines */<commit_msg>Added a character map display on the mode 12h demo (something I forgot)<commit_after>/*
	demos.c : functions to show off kernel features :P.
	(C)2012-2013 <NAME>, UnSX Team.
	Part of AliceOS, the Alice Operating System.
	Released under the MIT License.
*/
#include <demos.h>
#include <sys/types.h>
#include <sys/helpers.h>
#include <kdefs.h>
#include <krand.h>
#include <printk.h>
#include <serial.h>
#include <berp.h>
#include <fs/ramdisk.h>
#include <vga/palettes.h>
#include <vga/font.h>
#include <vga/mode13h.h>
#include <vga/mode12h.h>
#include <vga/mode3h.h>

demo_t demos[DEMO_COUNT] =
{
	{"blockgfx", "80x50 16-color block graphics demo", demo_blockgfx},
	{"crapgfx", "basic mode 12h demo", demo_crapgfx},
	{"realgfx", "basic mode 13h demo", demo_realgfx},
	{"cmap", "text mode character map", demo_cmap},
};

/* list available demos */
void listdemos( void )
{
	unsigned int i;
	mode_3h.fbputs("Available demos:\n");
	for ( i=0; i<DEMO_COUNT; i++ )
		mode_3h.fbprintf(" - %s : %s\n",demos[i].name,demos[i].desc);
}

/* Character map */
void demo_cmap( void )
{
	/* no startup code, we already assume we're in mode 3h since boot */
	mode_3h.fbsetattr(15,0,EXATTR_NOSCR);
	Uint16 i;
	Uint16 x,y;
	x = 4;
	y = 4;
	for ( i=0; i<128; i++ )
	{
		mode_3h.drawchar(x,y,i);
		x++;
		if ( x >= 20 )
		{
			x = 4;
			y++;
		}
	}
	x = 24;
	y = 4;
	for ( i=128; i<256; i++ )
	{
		mode_3h.drawchar(x,y,i);
		x++;
		if ( x >= 40 )
		{
			x = 24;
			y++;
		}
	}
}

/* 80x50 graphics demo */
void demo_blockgfx( void )
{
	/* no startup code, we already assume we're in mode 3h since boot */
	mode_3h.fbsetattr(15,0,EXATTR_NOSCR);
	printk(SERIAL_A,"Running Block GFX demo\n");
	img_t aliceimg;
	if ( loadimg(&aliceimg,"alice3h.img") )
		BERP("error loading alice3h.img");
	mode_3h.clear();
	mode_3h.drawimg(&aliceimg,0,0,0,0,80,50,0);
	mode_3h.drawrect(50,21,25,8,4);
	mode_3h.fbprintf("%[4E%{51,11%s %s%{51,13%s.%s.%s%s (%s)",_kname,_kver_code,_kver_maj,_kver_min,_kver_low,_kver_suf,_karch);
	mode_3h.drawhline(0,0,80,7);
	mode_3h.drawhline(0,49,80,7);
	mode_3h.drawvline(0,0,50,7);
	mode_3h.drawvline(79,0,50,7);
}

/* mode 12h graphics demo */
void demo_crapgfx( void )
{
	printk(SERIAL_A,"Running Mode 12h GFX demo\n");
	mode_12h.setmode();
	mode_12h.setpal(&alicepal[0]);
	fnt_t font8;
	if ( loadfnt(&font8,"fbfont8.fnt") )
		BERP("error loading fbfont8.fnt");
	mode_12h.setfont(&font8);
	Uint16 x,y;
	int i = 0;
	/* 16 color set */
	x = 8;
	y = 8;
	while ( i < 16 )
	{
		mode_12h.drawrect(x,y,32,32,i);
		x+=32;
		if ( !((++i)%8) )
		{
			x=8;
			y+=32;
		}
	}
	
	/* draw some colorful noise */
	x = 272;
	y = 8;
	do
	{
		mode_12h.putpixel(x,y,krand()%16);
		x++;
		if ( x >= 528 )
		{
			x = 272;
			y++;
		}
	}
	while ( (x < 528) && (y < 72) );
	
	/* there's enough space to draw this */
	img_t aliceimg;
	if ( loadimg(&aliceimg,"alice13h_16.img") )
		BERP("error loading alice13h_16.img");
	mode_12h.drawimg(&aliceimg,8,80,0,0,320,200,0);
	
	img_t aliceimg2;
	if ( loadimg(&aliceimg2,"alice3h.img") )
		BERP("error loading alice3h.img");
	mode_12h.drawimg(&aliceimg2,336,80,0,0,80,50,0);
	
	/* drawing a character map would be fine too */
	mode_12h.fbsetattr(15,0,EXATTR_MASKED);
	x = 8;
	y = 288;
	for ( i=0; i<128; i++ )
	{
		mode_12h.drawchar(x,y,i);
		x+=8;
		if ( x >= 136 )
		{
			x = 8;
			y+=8;
		}
	}
	x = 144;
	y = 288;
	for ( i=128; i<256; i++ )
	{
		mode_12h.drawchar(x,y,i);
		x+=8;
		if ( x >= 272 )
		{
			x = 144;
			y+=8;
		}
	}
	

	/* draw test strings */
	mode_12h.fbsetattr(7,0,EXATTR_MASKED);
	mode_12h.fbprintf("%[E%{1,-3%s %s%{1,-2%s.%s.%s%s  (%s)",_kname,_kver_code,_kver_maj,_kver_min,_kver_low,_kver_suf,_karch);
	mode_12h.fbprintf("%[7%{-14,-2Mode 12h test");
	mode_12h.fbsetattr(7,0,EXATTR_MASKED|EXATTR_RCW90);
	mode_12h.fbprintf("%[F%{-3,2R%{-3,3o%{-3,4t%{-3,5a%{-3,6t%{-3,7e%{-3,8d%{-3,10t%{-3,11e%{-3,12x%{-3,13t");
	
	/* draw some lines */
{'fraction_non_alphanumeric': 0.20360262008733623, 'fraction_numerical': 0.08119541484716157, 'mean_word_length': 3.982324949014276, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1731803', 'n_tokens_mistral': 3973, 'n_tokens_neox': 3558, 'n_words': 641}