forked from KolibriOS/kolibrios
Add 'cubeline', 'cubetext' and 'gears' source code to SVN.
git-svn-id: svn://kolibrios.org@1789 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
cb34862f9d
commit
caaa70b394
15
programs/demos/cubeline/trunk/Makefile
Normal file
15
programs/demos/cubeline/trunk/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
OUTFILE = cubeline
|
||||
|
||||
SRCS = main.cpp fps.cpp
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
CPPFLAGS = -I$(TINYGL)\include -O2
|
||||
|
||||
LIBR = TinyGL m
|
||||
LIBS = $(addprefix -l,$(LIBR)) -L$(TINYGL)\lib
|
||||
|
||||
all: $(OUTFILE)
|
||||
objcopy $(OUTFILE) -O binary
|
||||
|
||||
include $(MENUETDEV)/makefiles/Makefile_for_cpp_program
|
24
programs/demos/cubeline/trunk/ProcessTab.h
Normal file
24
programs/demos/cubeline/trunk/ProcessTab.h
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
struct process_table_entry_
|
||||
{
|
||||
__u32 cpu_usage __attribute__((packed));
|
||||
__u16 pos_in_windowing_stack __attribute__((packed));
|
||||
__u16 win_stack_val_at_ecx __attribute__((packed));
|
||||
__u16 rez1 __attribute__((packed));
|
||||
char name[11] __attribute__((packed));
|
||||
__u8 rez2 __attribute__((packed));
|
||||
__u32 memstart __attribute__((packed));
|
||||
__u32 memused __attribute__((packed));
|
||||
__u32 pid __attribute__((packed));
|
||||
__u32 winx_start,winy_start __attribute__((packed));
|
||||
__u32 winx_size,winy_size __attribute__((packed));
|
||||
__u8 slot __attribute__((packed));
|
||||
__u8 rez3 __attribute__((packed));
|
||||
__u32 clarx_start,clary_start __attribute__((packed));
|
||||
__u32 clarx_size,clary_size __attribute__((packed));
|
||||
__u8 win_condition __attribute__((packed));
|
||||
__u8 buf[955] __attribute__((packed));
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TYPEWIN(D,C,B,A,Y,RR,GG,BB) (D<<31)|(C<<30)|(B<<29)|(A<<28)|(Y<<24)|\
|
||||
(RR<<16)|(GG<<8)|BB
|
188
programs/demos/cubeline/trunk/SysCall.h
Normal file
188
programs/demos/cubeline/trunk/SysCall.h
Normal file
@ -0,0 +1,188 @@
|
||||
#ifndef __cplusplus
|
||||
|
||||
//"inline" ôóíêöèè äëÿ âûçîâà ñèñòåìíûõ ôóíêöèé Kolibri â C - â èìåíè ôóíêöèè êîë-âî ïàðàìåòðîâ
|
||||
//SysCall# (íîìåð_ñèñòåìíîé_ôóíêöèè, ïàðàìåòðû,...)
|
||||
|
||||
static inline int SysCall1 (int EAX__) __attribute__((always_inline));
|
||||
static inline int SysCall2 (int EAX__, int EBX__) __attribute__((always_inline));
|
||||
static inline int SysCall3 (int EAX__, int EBX__, int ECX__) __attribute__((always_inline));
|
||||
static inline int SysCall4 (int EAX__, int EBX__, int ECX__, int EDX__) __attribute__((always_inline));
|
||||
static inline int SysCall5 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__) __attribute__((always_inline));
|
||||
static inline int SysCall6 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__) __attribute__((always_inline));
|
||||
|
||||
|
||||
static inline int SysCall1 (int EAX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall2 (int EAX__, int EBX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall3 (int EAX__, int EBX__, int ECX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall4 (int EAX__, int EBX__, int ECX__, int EDX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall5 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall6 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile(""::"D"(EDI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//"inline" ôóíêöèè äëÿ âûçîâà ñèñòåìíûõ ôóíêöèé Kolibri â C++
|
||||
//SysCall(íîìåð_ñèñòåìíîé_ôóíêöèè, ïàðàìåòðû,...)
|
||||
|
||||
static inline int SysCall (int EAX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__) __attribute__((always_inline));
|
||||
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile(""::"D"(EDI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
46
programs/demos/cubeline/trunk/fps.cpp
Normal file
46
programs/demos/cubeline/trunk/fps.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include<menuet/os.h>
|
||||
#include "SysCall.h"
|
||||
|
||||
/*******************************************************************************
|
||||
ФУНКЦИЯ ОПРЕДЕЛЕНИЯ FPS
|
||||
x,y - координаты вывода FPS на окно
|
||||
возвращает время в сотых долях секунды затрачиваемое на 1 цикл
|
||||
*/
|
||||
|
||||
int time1=0;
|
||||
int time2=0;
|
||||
int fps1=0;
|
||||
int timerend=0;
|
||||
|
||||
int Fps (long x, long y)//функция определения FPS
|
||||
{
|
||||
int tr;
|
||||
|
||||
time1 = SysCall(26,9);//определяем время прошедшее момента запуска системы
|
||||
|
||||
if (timerend==0)
|
||||
{
|
||||
time2=time1;
|
||||
timerend=time1;
|
||||
}
|
||||
|
||||
tr = time1 - timerend;
|
||||
|
||||
if ((time1 - time2) < 100)//если прошло менее 1 секунды
|
||||
{ //увеличиваем счетчик fps
|
||||
fps1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//выводим число fps
|
||||
SysCall(13,(x<<16)+23,(y<<16)+7,0x00555555); //НАРИСОВАТЬ ПОЛОСУ
|
||||
SysCall(47,4<<16,fps1,(x<<16)+y,0xfafafa);//ВЫВЕСТИ В ОКНО ПРИЛОЖЕНИЯ ЧИСЛО
|
||||
fps1=0;
|
||||
time2=time1;
|
||||
}
|
||||
|
||||
timerend=time1;
|
||||
|
||||
return tr;
|
||||
}
|
||||
//******************************************************************************
|
251
programs/demos/cubeline/trunk/main.cpp
Normal file
251
programs/demos/cubeline/trunk/main.cpp
Normal file
@ -0,0 +1,251 @@
|
||||
/*
|
||||
Ïðèìåð âçÿò èç íàáîðà ïðèìåðîâ ê êîìïèëÿòîðó XS Compiler
|
||||
|
||||
iadn
|
||||
http://www.iadn.narod.ru
|
||||
iadn@bk.ru
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include<menuet/os.h>
|
||||
#include <kosgl.h> //TinyGL
|
||||
|
||||
#include "SysCall.h"
|
||||
#include "ProcessTab.h"
|
||||
|
||||
|
||||
int Fps (long x, long y);
|
||||
extern "C"{
|
||||
void app_main(void);
|
||||
}
|
||||
|
||||
struct {
|
||||
int x,y;
|
||||
int dx,dy;
|
||||
} win;
|
||||
|
||||
#define CUBE_STEP 0.1
|
||||
|
||||
#define KEY_ESC 1
|
||||
#define KEY_F 33
|
||||
|
||||
char *title1 = "TinyGL in KolibriOS";
|
||||
char *title2 = "F full screen";
|
||||
char *title3 = "ESC - exit";
|
||||
char *fps = "FPS:";
|
||||
|
||||
unsigned char FullScreen = 0;
|
||||
unsigned char skin = 3;
|
||||
|
||||
float angle;
|
||||
process_table_entry_* pri;
|
||||
KOSGLContext cgl;
|
||||
|
||||
void draw_cube()
|
||||
{
|
||||
float x,y,z;
|
||||
glBegin(GL_LINES);
|
||||
|
||||
for(y=-0.5;y<=0.5;y+=CUBE_STEP)
|
||||
{
|
||||
// the front
|
||||
glColor3f(0,y+0.5,0);
|
||||
glVertex3f(-0.5,y,-0.5);
|
||||
glColor3f(1,y+0.5,0);
|
||||
glVertex3f(0.5,y,-0.5);
|
||||
|
||||
// the back
|
||||
glColor3f(0,y+0.5,1);
|
||||
glVertex3f(-0.5,y,0.5);
|
||||
glColor3f(1,y+0.5,1);
|
||||
glVertex3f(0.5,y,0.5);
|
||||
|
||||
//right side
|
||||
glColor3f(1,y+0.5,0);
|
||||
glVertex3f(0.5,y,-0.5);
|
||||
glColor3f(1,y+0.5,1);
|
||||
glVertex3f(0.5,y,0.5);
|
||||
|
||||
//left side
|
||||
glColor3f(0,y+0.5,0);
|
||||
glVertex3f(-0.5,y,-0.5);
|
||||
glColor3f(0,y+0.5,1);
|
||||
glVertex3f(-0.5,y,0.5);
|
||||
}
|
||||
|
||||
for(x=-0.5;x<=0.5;x+=CUBE_STEP)
|
||||
{
|
||||
// the front
|
||||
glColor3f(x+0.5,1,0);
|
||||
glVertex3f(x,0.5,-0.5);
|
||||
glColor3f(x+0.5,0,0);
|
||||
glVertex3f(x,-0.5,-0.5);
|
||||
|
||||
// the back
|
||||
glColor3f(x+0.5,1,1);
|
||||
glVertex3f(x,0.5,0.5);
|
||||
glColor3f(x+0.5,0,1);
|
||||
glVertex3f(x,-0.5,0.5);
|
||||
|
||||
// the top
|
||||
glColor3f(x+0.5,1,0);
|
||||
glVertex3f(x,0.5,-0.5);
|
||||
glColor3f(x+0.5,1,1);
|
||||
glVertex3f(x,0.5,0.5);
|
||||
|
||||
// the bottom
|
||||
glColor3f(x+0.5,0,0);
|
||||
glVertex3f(x,-0.5,-0.5);
|
||||
glColor3f(x+0.5,0,1);
|
||||
glVertex3f(x,-0.5,0.5);
|
||||
}
|
||||
|
||||
for(z=-0.5;z<=0.5;z+=CUBE_STEP)
|
||||
{
|
||||
// the top
|
||||
glColor3f(0,1,z+0.5);
|
||||
glVertex3f(-0.5,0.5,z);
|
||||
glColor3f(1,1,z+0.5);
|
||||
glVertex3f(0.5,0.5,z);
|
||||
|
||||
// the bottom
|
||||
glColor3f(0,0,z+0.5);
|
||||
glVertex3f(-0.5,-0.5,z);
|
||||
glColor3f(1,0,z+0.5);
|
||||
glVertex3f(0.5,-0.5,z);
|
||||
|
||||
// right side
|
||||
glColor3f(1,1,z+0.5);
|
||||
glVertex3f(0.5,0.5,z);
|
||||
glColor3f(1,0,z+0.5);
|
||||
glVertex3f(0.5,-0.5,z);
|
||||
|
||||
// left side
|
||||
glColor3f(0,1,z+0.5);
|
||||
glVertex3f(-0.5,0.5,z);
|
||||
glColor3f(0,0,z+0.5);
|
||||
glVertex3f(-0.5,-0.5,z);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawGL()
|
||||
{
|
||||
glLoadIdentity(); // óñòàíàâëèâàåì åäåíè÷íóþ ìàòðèöó
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glTranslatef(0.0, 0.0, -3.0);
|
||||
glRotatef(angle, 1.0, 0.0, 0.0);
|
||||
glRotatef(2.0*angle, 0.0, 1.0, 0.0);
|
||||
glRotatef(3.0*angle, 0.0, 0.0, 1.0);
|
||||
|
||||
draw_cube();
|
||||
|
||||
kosglSwapBuffers();
|
||||
}
|
||||
|
||||
void reshape()
|
||||
{
|
||||
__menuet__get_process_table((process_table_entry*)pri,-1);
|
||||
glViewport(0, 0, pri->winx_size, pri->winy_size-20);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void disabletgl()
|
||||
{
|
||||
kosglDestroyContext(cgl);
|
||||
delete pri;
|
||||
}
|
||||
|
||||
void Title()
|
||||
{
|
||||
__menuet__write_text(300,8,0x10ffffff,fps,strlen(fps));
|
||||
__menuet__write_text(8,8,0x10ffffff,title1,strlen(title1));
|
||||
__menuet__write_text(180,8,0x00ffffff,title2,strlen(title2));
|
||||
__menuet__write_text(600,8,0x00ffffff,title3,strlen(title3));
|
||||
}
|
||||
|
||||
void draw_window(void)
|
||||
{
|
||||
// start redraw
|
||||
__menuet__window_redraw(1);
|
||||
// define&draw window
|
||||
__menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0);
|
||||
// end redraw
|
||||
__menuet__window_redraw(2);
|
||||
// display string
|
||||
Title();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
||||
win.x = 100;
|
||||
win.y = 100;
|
||||
win.dx = 400;
|
||||
win.dy = 400;
|
||||
|
||||
draw_window();
|
||||
|
||||
cgl = kosglCreateContext( 0, 0);
|
||||
kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glClearDepth(1.0);
|
||||
glEnable( GL_CULL_FACE );
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
pri=new process_table_entry_;
|
||||
SysCall(66,1,1);
|
||||
|
||||
reshape();
|
||||
|
||||
do{
|
||||
|
||||
if (angle < 360.0) angle += 0.001 + 0.1*Fps (330,8);
|
||||
else angle = 0.0;
|
||||
|
||||
DrawGL();
|
||||
|
||||
switch(__menuet__check_for_event())
|
||||
{
|
||||
case 1: draw_window();
|
||||
reshape();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
switch(__menuet__getkey()){
|
||||
|
||||
case KEY_F:
|
||||
if(!FullScreen){
|
||||
skin=0;
|
||||
SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff);
|
||||
draw_window();
|
||||
reshape();
|
||||
FullScreen = 1;
|
||||
}
|
||||
else{
|
||||
skin=3;
|
||||
draw_window();
|
||||
SysCall(67,win.x,win.y,win.dx,win.dy);
|
||||
reshape();
|
||||
FullScreen = 0;
|
||||
};
|
||||
break;
|
||||
|
||||
case KEY_ESC: disabletgl();
|
||||
return;}
|
||||
break;
|
||||
|
||||
case 3: disabletgl();
|
||||
return;
|
||||
}
|
||||
}while(1);
|
||||
}
|
15
programs/demos/cubetext/trunk/Makefile
Normal file
15
programs/demos/cubetext/trunk/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
OUTFILE = cubetext
|
||||
|
||||
SRCS = main.cpp fps.cpp bmp.cpp
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
CPPFLAGS = -I$(TINYGL)\include -O2
|
||||
|
||||
LIBR = TinyGL m
|
||||
LIBS = $(addprefix -l,$(LIBR)) -L$(TINYGL)\lib
|
||||
|
||||
all: $(OUTFILE)
|
||||
objcopy $(OUTFILE) -O binary
|
||||
|
||||
include $(MENUETDEV)/makefiles/Makefile_for_cpp_program
|
24
programs/demos/cubetext/trunk/ProcessTab.h
Normal file
24
programs/demos/cubetext/trunk/ProcessTab.h
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
struct process_table_entry_
|
||||
{
|
||||
__u32 cpu_usage __attribute__((packed));
|
||||
__u16 pos_in_windowing_stack __attribute__((packed));
|
||||
__u16 win_stack_val_at_ecx __attribute__((packed));
|
||||
__u16 rez1 __attribute__((packed));
|
||||
char name[11] __attribute__((packed));
|
||||
__u8 rez2 __attribute__((packed));
|
||||
__u32 memstart __attribute__((packed));
|
||||
__u32 memused __attribute__((packed));
|
||||
__u32 pid __attribute__((packed));
|
||||
__u32 winx_start,winy_start __attribute__((packed));
|
||||
__u32 winx_size,winy_size __attribute__((packed));
|
||||
__u8 slot __attribute__((packed));
|
||||
__u8 rez3 __attribute__((packed));
|
||||
__u32 clarx_start,clary_start __attribute__((packed));
|
||||
__u32 clarx_size,clary_size __attribute__((packed));
|
||||
__u8 win_condition __attribute__((packed));
|
||||
__u8 buf[955] __attribute__((packed));
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TYPEWIN(D,C,B,A,Y,RR,GG,BB) (D<<31)|(C<<30)|(B<<29)|(A<<28)|(Y<<24)|\
|
||||
(RR<<16)|(GG<<8)|BB
|
188
programs/demos/cubetext/trunk/SysCall.h
Normal file
188
programs/demos/cubetext/trunk/SysCall.h
Normal file
@ -0,0 +1,188 @@
|
||||
#ifndef __cplusplus
|
||||
|
||||
//"inline" ôóíêöèè äëÿ âûçîâà ñèñòåìíûõ ôóíêöèé Kolibri â C - â èìåíè ôóíêöèè êîë-âî ïàðàìåòðîâ
|
||||
//SysCall# (íîìåð_ñèñòåìíîé_ôóíêöèè, ïàðàìåòðû,...)
|
||||
|
||||
static inline int SysCall1 (int EAX__) __attribute__((always_inline));
|
||||
static inline int SysCall2 (int EAX__, int EBX__) __attribute__((always_inline));
|
||||
static inline int SysCall3 (int EAX__, int EBX__, int ECX__) __attribute__((always_inline));
|
||||
static inline int SysCall4 (int EAX__, int EBX__, int ECX__, int EDX__) __attribute__((always_inline));
|
||||
static inline int SysCall5 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__) __attribute__((always_inline));
|
||||
static inline int SysCall6 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__) __attribute__((always_inline));
|
||||
|
||||
|
||||
static inline int SysCall1 (int EAX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall2 (int EAX__, int EBX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall3 (int EAX__, int EBX__, int ECX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall4 (int EAX__, int EBX__, int ECX__, int EDX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall5 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall6 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile(""::"D"(EDI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//"inline" ôóíêöèè äëÿ âûçîâà ñèñòåìíûõ ôóíêöèé Kolibri â C++
|
||||
//SysCall(íîìåð_ñèñòåìíîé_ôóíêöèè, ïàðàìåòðû,...)
|
||||
|
||||
static inline int SysCall (int EAX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__) __attribute__((always_inline));
|
||||
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile(""::"D"(EDI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
442
programs/demos/cubetext/trunk/bmp.cpp
Normal file
442
programs/demos/cubetext/trunk/bmp.cpp
Normal file
@ -0,0 +1,442 @@
|
||||
//
|
||||
// bmp.cpp - source file / freeware
|
||||
//
|
||||
// David Henry - tfc_duke@hotmail.com
|
||||
//
|
||||
|
||||
|
||||
#include "bmp.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libc/stubs.h>
|
||||
|
||||
extern "C"{
|
||||
long filelength(int fhandle);
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// LoadFileBMP() - load a Windows/OS2 BITMAP image
|
||||
// [.bmp].
|
||||
//
|
||||
// parameters :
|
||||
// - filename [in] : image source file
|
||||
// - pixels [out] : 32 bits rgb image data
|
||||
// - width [out] : image width in pixels
|
||||
// - height [out] : image height in pixels
|
||||
// - flipvert [in] : flip vertically
|
||||
//
|
||||
// return value :
|
||||
// - -1 : no image data
|
||||
// - 0 : failure
|
||||
// - 1 : success
|
||||
//
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// accepted image formats :
|
||||
// # RGB 1-4-8-24-32 bits WINDOWS - OS/2
|
||||
// # RLE 4-8 bits WINDOWS
|
||||
// --------------------------------------------------
|
||||
|
||||
int LoadFileBMP( const char *filename, unsigned char **pixels, int *width, int *height, bool flipvert )
|
||||
{
|
||||
FILE *file; // file stream
|
||||
BITMAPFILEHEADER *bmfh; // bitmap file header
|
||||
BITMAPINFOHEADER *bmih; // bitmap info header (windows)
|
||||
BITMAPCOREHEADER *bmch; // bitmap core header (os/2)
|
||||
RGBTRIPLE *os2_palette; // pointer to the color palette os/2
|
||||
RGBQUAD *win_palette; // pointer to the color palette windows
|
||||
char *buffer; // buffer storing the entire file
|
||||
unsigned char *ptr; // pointer to pixels data
|
||||
int bitCount; // number of bits per pixel
|
||||
int compression; // compression type (rgb/rle)
|
||||
int row, col, i; // temporary variables
|
||||
int w, h; // width, height
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// read the entire file in the buffer
|
||||
|
||||
file = fopen(filename,"rb");
|
||||
|
||||
if( !file)
|
||||
return 0;
|
||||
|
||||
long flen = filelength(fileno(file));
|
||||
|
||||
buffer = new char[ flen + 1 ];
|
||||
int rd = fread(buffer, flen, 1, file);
|
||||
char *pBuff = buffer;
|
||||
|
||||
fclose(file);
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// read the header
|
||||
bmfh = (BITMAPFILEHEADER *)pBuff;
|
||||
pBuff += sizeof( BITMAPFILEHEADER );
|
||||
|
||||
// verify that it's a BITMAP file
|
||||
if( bmfh->bfType != BITMAP_ID )
|
||||
{
|
||||
delete [] buffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bmch = (BITMAPCOREHEADER *)pBuff;
|
||||
bmih = (BITMAPINFOHEADER *)pBuff;
|
||||
|
||||
|
||||
if( (bmih->biCompression < 0) || (bmih->biCompression > 3) )
|
||||
{
|
||||
// OS/2 style
|
||||
pBuff += sizeof( BITMAPCOREHEADER );
|
||||
|
||||
bitCount = bmch->bcBitCount;
|
||||
compression = BI_OS2;
|
||||
|
||||
w = bmch->bcWidth;
|
||||
h = bmch->bcHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
// WINDOWS style
|
||||
pBuff += sizeof( BITMAPINFOHEADER );
|
||||
|
||||
bitCount = bmih->biBitCount;
|
||||
compression = bmih->biCompression;
|
||||
|
||||
w = bmih->biWidth;
|
||||
h = bmih->biHeight;
|
||||
}
|
||||
|
||||
|
||||
if( width )
|
||||
*width = w;
|
||||
|
||||
if( height )
|
||||
*height = h;
|
||||
|
||||
|
||||
if( !pixels )
|
||||
{
|
||||
delete [] buffer;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// read the palette
|
||||
|
||||
if( bitCount <= 8 )
|
||||
{
|
||||
// 24 and 32 bits images are not paletted
|
||||
|
||||
// ajust the palette pointer to the memory in the buffer
|
||||
os2_palette = (RGBTRIPLE *)pBuff;
|
||||
win_palette = (RGBQUAD *)pBuff;
|
||||
|
||||
// [number of colors in the palette] * [size of one pixel]
|
||||
pBuff += (1 << bitCount) * (bitCount >> 3) * sizeof( unsigned char );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// allocate memory to store pixel data
|
||||
*pixels = new unsigned char[ w * h * 3 ];
|
||||
ptr = &(*pixels)[0];
|
||||
|
||||
|
||||
// move the pixel data pointer to the begening of bitmap data
|
||||
pBuff = buffer + (bmfh->bfOffBits * sizeof( char ));
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// read pixel data following the image compression
|
||||
// type and the number of bits per pixels
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
switch( compression )
|
||||
{
|
||||
case BI_OS2:
|
||||
case BI_RGB:
|
||||
{
|
||||
for( row = h - 1; row >= 0; row-- )
|
||||
{
|
||||
if( flipvert )
|
||||
ptr = &(*pixels)[ row * w * 3 ];
|
||||
|
||||
switch( bitCount )
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
// RGB 1 BITS
|
||||
for( col = 0; col < (int)(w / 8); col++ )
|
||||
{
|
||||
// read the current pixel
|
||||
unsigned char color = *((unsigned char *)(pBuff++));
|
||||
|
||||
for( i = 7; i >= 0; i--, ptr += 3 )
|
||||
{
|
||||
// convert indexed pixel (1 bit) into rgb (32 bits) pixel
|
||||
int clrIdx = ((color & (1<<i)) > 0);
|
||||
|
||||
if( compression == BI_OS2 )
|
||||
{
|
||||
ptr[2] = os2_palette[ clrIdx ].rgbtRed;
|
||||
ptr[1] = os2_palette[ clrIdx ].rgbtGreen;
|
||||
ptr[0] = os2_palette[ clrIdx ].rgbtBlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr[2] = win_palette[ clrIdx ].rgbRed;
|
||||
ptr[1] = win_palette[ clrIdx ].rgbGreen;
|
||||
ptr[0] = win_palette[ clrIdx ].rgbBlue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
// RGB 4 BITS
|
||||
for( col = 0; col < (int)(w / 2); col++, ptr += 6 )
|
||||
{
|
||||
// read the current pixel
|
||||
unsigned char color = *((unsigned char *)(pBuff++));
|
||||
|
||||
// convert indexed pixel (4 bits) into rgb (32 bits) pixel
|
||||
int clrIdx;
|
||||
|
||||
if( compression == BI_OS2 )
|
||||
{
|
||||
clrIdx = (color >> 4);
|
||||
ptr[2] = os2_palette[ clrIdx ].rgbtRed;
|
||||
ptr[1] = os2_palette[ clrIdx ].rgbtGreen;
|
||||
ptr[0] = os2_palette[ clrIdx ].rgbtBlue;
|
||||
|
||||
clrIdx = (color & 0x0F);
|
||||
ptr[6] = os2_palette[ clrIdx ].rgbtRed;
|
||||
ptr[5] = os2_palette[ clrIdx ].rgbtGreen;
|
||||
ptr[4] = os2_palette[ clrIdx ].rgbtBlue;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
clrIdx = (color >> 4);
|
||||
ptr[2] = win_palette[ clrIdx ].rgbRed;
|
||||
ptr[1] = win_palette[ clrIdx ].rgbGreen;
|
||||
ptr[0] = win_palette[ clrIdx ].rgbBlue;
|
||||
|
||||
clrIdx = (color & 0x0F);
|
||||
ptr[6] = win_palette[ clrIdx ].rgbRed;
|
||||
ptr[5] = win_palette[ clrIdx ].rgbGreen;
|
||||
ptr[4] = win_palette[ clrIdx ].rgbBlue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 8:
|
||||
{
|
||||
// RGB 8 BITS
|
||||
for( col = 0; col < w; col++, ptr += 3 )
|
||||
{
|
||||
// read the current pixel
|
||||
unsigned char color = *((unsigned char *)(pBuff++));
|
||||
|
||||
// convert indexed pixel (8 bits) into rgb (32 bits) pixel
|
||||
if( compression == BI_OS2 )
|
||||
{
|
||||
ptr[2] = os2_palette[ color ].rgbtRed;
|
||||
ptr[1] = os2_palette[ color ].rgbtGreen;
|
||||
ptr[0] = os2_palette[ color ].rgbtBlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr[2] = win_palette[ color ].rgbRed;
|
||||
ptr[1] = win_palette[ color ].rgbGreen;
|
||||
ptr[0] = win_palette[ color ].rgbBlue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 24:
|
||||
{
|
||||
// RGB 24 BITS
|
||||
for( col = 0; col < w; col++, ptr += 3 )
|
||||
{
|
||||
// convert bgr pixel (24 bits) into rgb (32 bits) pixel
|
||||
RGBTRIPLE *pix = (RGBTRIPLE *)pBuff;
|
||||
pBuff += sizeof( RGBTRIPLE );
|
||||
|
||||
ptr[2] = pix->rgbtRed;
|
||||
ptr[1] = pix->rgbtGreen;
|
||||
ptr[0] = pix->rgbtBlue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 32:
|
||||
{
|
||||
// RGB 32 BITS
|
||||
for( col = 0; col < w; col++, ptr += 3 )
|
||||
{
|
||||
// // convert bgr pixel (32 bits) into rgb (32 bits) pixel
|
||||
RGBQUAD *pix = (RGBQUAD *)pBuff;
|
||||
pBuff += sizeof( RGBQUAD );
|
||||
|
||||
ptr[2] = pix->rgbRed;
|
||||
ptr[1] = pix->rgbGreen;
|
||||
ptr[0] = pix->rgbBlue;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BI_RLE8:
|
||||
{
|
||||
// RLE 8 BITS
|
||||
for( row = h - 1; row >= 0; row-- )
|
||||
{
|
||||
if( flipvert )
|
||||
ptr = &(*pixels)[ row * w * 3 ];
|
||||
|
||||
for( col = 0; col < w; /* nothing */ )
|
||||
{
|
||||
// get one packet (2 bytes)
|
||||
unsigned char byte1 = *((unsigned char *)(pBuff++));
|
||||
unsigned char byte2 = *((unsigned char *)(pBuff++));
|
||||
|
||||
|
||||
if( byte1 == RLE_COMMAND )
|
||||
{
|
||||
// absolute encoding
|
||||
for( i = 0; i < byte2; i++, ptr += 3, col++ )
|
||||
{
|
||||
// read the current pixel
|
||||
unsigned char color = *((unsigned char *)(pBuff++));
|
||||
|
||||
// convert indexed pixel (8 bits) into rgb (32 bits) pixel
|
||||
ptr[2] = win_palette[ color ].rgbRed;
|
||||
ptr[1] = win_palette[ color ].rgbGreen;
|
||||
ptr[0] = win_palette[ color ].rgbBlue;
|
||||
}
|
||||
|
||||
if( (byte2 % 2) == 1 )
|
||||
pBuff++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// read next pixels
|
||||
for( i = 0; i < byte1; i++, ptr += 3, col++ )
|
||||
{
|
||||
// convert indexed pixel (8 bits) into rgb (32 bits) pixel
|
||||
ptr[2] = win_palette[ byte2 ].rgbRed;
|
||||
ptr[1] = win_palette[ byte2 ].rgbGreen;
|
||||
ptr[0] = win_palette[ byte2 ].rgbBlue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BI_RLE4:
|
||||
{
|
||||
// RLE 4 BITS
|
||||
unsigned char color;
|
||||
int bytesRead = 0; // number of bytes read
|
||||
|
||||
for( row = h - 1; row >= 0; row-- )
|
||||
{
|
||||
if( flipvert )
|
||||
ptr = &(*pixels)[ row * w * 3 ];
|
||||
|
||||
for( col = 0; col < w; /* nothing */ )
|
||||
{
|
||||
// get one packet (2 bytes)
|
||||
unsigned char byte1 = *((unsigned char *)(pBuff++));
|
||||
unsigned char byte2 = *((unsigned char *)(pBuff++));
|
||||
|
||||
bytesRead += 2;
|
||||
|
||||
|
||||
if( byte1 == RLE_COMMAND )
|
||||
{
|
||||
// absolute encoding
|
||||
unsigned char databyte;
|
||||
|
||||
for( i = 0; i < byte2; i++, ptr += 3, col++ )
|
||||
{
|
||||
if( (i % 2) == 0 )
|
||||
{
|
||||
// read the current pixel
|
||||
databyte = *((unsigned char *)(pBuff++));
|
||||
bytesRead++;
|
||||
|
||||
color = (databyte >> 4); // 4 first bits
|
||||
}
|
||||
else
|
||||
{
|
||||
color = (databyte & 0x0F); // 4 last bits
|
||||
}
|
||||
|
||||
// convert indexed pixel (4 bits) into rgb (32 bits) pixel
|
||||
ptr[2] = win_palette[ color ].rgbRed;
|
||||
ptr[1] = win_palette[ color ].rgbGreen;
|
||||
ptr[0] = win_palette[ color ].rgbBlue;
|
||||
}
|
||||
|
||||
while( (bytesRead % 2) != 0 )
|
||||
{
|
||||
pBuff++;
|
||||
bytesRead++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// read next pixels
|
||||
for( i = 0; i < byte1; i++, ptr += 3, col++ )
|
||||
{
|
||||
if( (i % 2) == 0 )
|
||||
color = (byte2 >> 4); // 4 first bits
|
||||
else
|
||||
color = (byte2 & 0x0F); // 4 last bits
|
||||
|
||||
// convert indexed pixel (4 bits) into rgb (32 bits) pixel
|
||||
ptr[2] = win_palette[ color ].rgbRed;
|
||||
ptr[1] = win_palette[ color ].rgbGreen;
|
||||
ptr[0] = win_palette[ color ].rgbBlue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// free buffer memory
|
||||
delete [] buffer;
|
||||
|
||||
|
||||
// return success
|
||||
return 1;
|
||||
}
|
142
programs/demos/cubetext/trunk/bmp.h
Normal file
142
programs/demos/cubetext/trunk/bmp.h
Normal file
@ -0,0 +1,142 @@
|
||||
//
|
||||
// bmp.h - header file / freeware
|
||||
//
|
||||
// David Henry - tfc_duke@hotmail.com
|
||||
//
|
||||
|
||||
#ifndef __BITMAP_H_
|
||||
#define __BITMAP_H_
|
||||
|
||||
|
||||
|
||||
// magic number "BM"
|
||||
#define BITMAP_ID ('B' + ('M'<<8))
|
||||
|
||||
|
||||
|
||||
// header byte type for RLE
|
||||
#define RLE_COMMAND 0
|
||||
#define RLE_ENDOFLINE 0
|
||||
#define RLE_ENDOFBITMAP 1
|
||||
#define RLE_DELTA 2
|
||||
|
||||
#define BI_OS2 -1
|
||||
|
||||
|
||||
// compression type
|
||||
#define BI_RGB 0
|
||||
#define BI_RLE8 1
|
||||
#define BI_RLE4 2
|
||||
#define BI_BITFIELDS 3
|
||||
|
||||
|
||||
|
||||
#pragma warning( disable : 4103 )
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// tagBITMAPFILEHEADER - bitmap file header.
|
||||
// --------------------------------------------
|
||||
|
||||
#pragma pack(2)
|
||||
|
||||
typedef struct tagBITMAPFILEHEADER // bmfh
|
||||
{
|
||||
unsigned short bfType; // magic number "BM"
|
||||
unsigned int bfSize; // file size
|
||||
unsigned short bfReserved1; // reserved
|
||||
unsigned short bfReserved2; // reserved
|
||||
unsigned int bfOffBits; // offset to bitmap data
|
||||
|
||||
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
|
||||
|
||||
#pragma pack(4)
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// tagBITMAPCOREHEADER - bitmap core header.
|
||||
// --------------------------------------------
|
||||
|
||||
typedef struct tagBITMAPCOREHEADER // bmch
|
||||
{
|
||||
unsigned int bcSize; // size of the structure
|
||||
unsigned short bcWidth; // image width
|
||||
unsigned short bcHeight; // image height
|
||||
unsigned short bcPlanes; // must be equal to 1
|
||||
unsigned short bcBitCount; // number of bits per pixel
|
||||
|
||||
} BITMAPCOREHEADER, *PBITMAPCOREHEADER;
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// tagRGBTRIPLE - 24 bits pixel
|
||||
// --------------------------------------------
|
||||
|
||||
typedef struct tagRGBTRIPLE // rgbt
|
||||
{
|
||||
unsigned char rgbtBlue; // blue
|
||||
unsigned char rgbtGreen; // green
|
||||
unsigned char rgbtRed; // red
|
||||
|
||||
} RGBTRIPLE, *PRGBTRIPLE;
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// tagRGBQUAD - 32 bits pixel
|
||||
// --------------------------------------------
|
||||
|
||||
typedef struct tagRGBQUAD // rgbt
|
||||
{
|
||||
unsigned char rgbBlue; // blue
|
||||
unsigned char rgbGreen; // green
|
||||
unsigned char rgbRed; // red
|
||||
unsigned char rgbReserved; // reserved
|
||||
|
||||
} RGBQUAD, *PRGBQUAD;
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// tagBITMAPCOREINFO - bitmap core info.
|
||||
// --------------------------------------------
|
||||
|
||||
typedef struct tagBITMAPCOREINFO // bmci
|
||||
{
|
||||
BITMAPCOREHEADER bmciHeader; // size of the structure
|
||||
RGBTRIPLE bcmiColors[1]; // color palette
|
||||
|
||||
} BITMAPCOREINFO, *PBITMAPCOREINFO;
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
// BITMAPFILEHEADER - bitmap info header.
|
||||
// --------------------------------------------
|
||||
|
||||
typedef struct tagBITMAPINFOHEADER
|
||||
{
|
||||
unsigned int biSize; // size of the structure
|
||||
int biWidth; // image width
|
||||
int biHeight; // image height
|
||||
unsigned short biPlanes; // must be equal to 1
|
||||
unsigned short biBitCount; // number of bits per pixel
|
||||
unsigned int biCompression; // compression type
|
||||
unsigned int biSizeImage; // size of data bitmap
|
||||
int biXPelsPerMeter; // number of pixels per meter on the X axis
|
||||
int biYPelsPerMeter; // number of pixels per meter on the Y axis
|
||||
unsigned int biClrUsed; // number of colors used
|
||||
unsigned int biClrImportant; // number of important colors
|
||||
|
||||
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
|
||||
|
||||
|
||||
|
||||
// prototype
|
||||
int LoadFileBMP( const char *filename, unsigned char **pixels, int *width, int *height, bool flipvert );
|
||||
|
||||
|
||||
|
||||
#endif // __BITMAP_H_
|
47
programs/demos/cubetext/trunk/fps.cpp
Normal file
47
programs/demos/cubetext/trunk/fps.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include<menuet/os.h>
|
||||
#include "SysCall.h"
|
||||
|
||||
/*******************************************************************************
|
||||
ФУНКЦИЯ ОПРЕДЕЛЕНИЯ FPS
|
||||
x,y - координаты вывода FPS на окно
|
||||
возвращает время в сотых долях секунды затрачиваемое на 1 цикл
|
||||
|
||||
*/
|
||||
|
||||
int time1=0;
|
||||
int time2=0;
|
||||
int fps1=0;
|
||||
int timerend=0;
|
||||
|
||||
int Fps (long x, long y)//функция определения FPS
|
||||
{
|
||||
int tr;
|
||||
|
||||
time1 = SysCall(26,9);//определяем время прошедшее момента запуска системы
|
||||
|
||||
if (timerend==0)
|
||||
{
|
||||
time2=time1;
|
||||
timerend=time1;
|
||||
}
|
||||
|
||||
tr = time1 - timerend;
|
||||
|
||||
if ((time1 - time2) < 100)//если прошло менее 1 секунды
|
||||
{ //увеличиваем счетчик fps
|
||||
fps1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//выводим число fps
|
||||
SysCall(13,(x<<16)+23,(y<<16)+7,0x00555555); //НАРИСОВАТЬ ПОЛОСУ
|
||||
SysCall(47,4<<16,fps1,(x<<16)+y,0xfafafa);//ВЫВЕСТИ В ОКНО ПРИЛОЖЕНИЯ ЧИСЛО
|
||||
fps1=0;
|
||||
time2=time1;
|
||||
}
|
||||
|
||||
timerend=time1;
|
||||
|
||||
return tr;
|
||||
}
|
||||
//******************************************************************************
|
BIN
programs/demos/cubetext/trunk/logio.bmp
Normal file
BIN
programs/demos/cubetext/trunk/logio.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
223
programs/demos/cubetext/trunk/main.cpp
Normal file
223
programs/demos/cubetext/trunk/main.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
/*
|
||||
iadn
|
||||
http://www.iadn.narod.ru
|
||||
iadn@bk.ru
|
||||
*/
|
||||
#include<menuet/os.h>
|
||||
#include <kosgl.h> //TinyGL
|
||||
#include <string.h>
|
||||
|
||||
#include "SysCall.h"
|
||||
#include "ProcessTab.h"
|
||||
#include "bmp.h"
|
||||
|
||||
|
||||
int Fps (long x, long y);
|
||||
extern "C"{
|
||||
void app_main(void);
|
||||
}
|
||||
|
||||
struct {
|
||||
int x,y;
|
||||
int dx,dy;
|
||||
} win;
|
||||
|
||||
#define KEY_ESC 1
|
||||
#define KEY_F 33
|
||||
|
||||
char *title1 = "TinyGL in KolibriOS";
|
||||
char *title2 = "F full screen";
|
||||
char *title3 = "ESC - exit";
|
||||
char *fps = "FPS:";
|
||||
|
||||
unsigned char FullScreen = 0;
|
||||
unsigned char skin = 3;
|
||||
|
||||
static GLuint* TexObj;
|
||||
|
||||
float angle = 0.0;
|
||||
process_table_entry_* pri;
|
||||
KOSGLContext cgl;
|
||||
|
||||
struct V3{
|
||||
float v1;
|
||||
float v2;
|
||||
float v3;
|
||||
} ptrv[8] = {{-1.0,1.0,1.0},
|
||||
{-1.0,-1.0,1.0},
|
||||
{1.0,-1.0,1.0},
|
||||
{1.0,1.0,1.0},
|
||||
{-1.0,1.0,-1.0},
|
||||
{-1.0,-1.0,-1.0},
|
||||
{1.0,-1.0,-1.0},
|
||||
{1.0,1.0,-1.0}};
|
||||
|
||||
struct T2{
|
||||
float t1;
|
||||
float t2;
|
||||
} ptrt[4] = {
|
||||
{0.0, 0.0},
|
||||
{1.0, 0.0},
|
||||
{1.0, 1.0},
|
||||
{0.0, 1.0}
|
||||
};
|
||||
|
||||
void DrawQUADS(V3* ptr, int iv1, int iv2, int iv3, int iv4, T2* ptrt, int it1, int it2, int it3, int it4)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2fv((float*)&ptrt[it1]);
|
||||
glVertex3fv((float*)&ptr[iv1]);
|
||||
glTexCoord2fv((float*)&ptrt[it2]);
|
||||
glVertex3fv((float*)&ptr[iv2]);
|
||||
glTexCoord2fv((float*)&ptrt[it3]);
|
||||
glVertex3fv((float*)&ptr[iv3]);
|
||||
glTexCoord2fv((float*)&ptrt[it4]);
|
||||
glVertex3fv((float*)&ptr[iv4]);
|
||||
glEnd();
|
||||
}
|
||||
void DrawGL()
|
||||
{
|
||||
glLoadIdentity(); // óñòàíàâëèâàåì åäåíè÷íóþ ìàòðèöó
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glTranslatef(0.0, 0.0, -6.0);
|
||||
glRotatef(angle, 1.0, 0.0, 0.0);
|
||||
glRotatef(2.0*angle, 0.0, 1.0, 0.0);
|
||||
glRotatef(3.0*angle, 0.0, 0.0, 1.0);
|
||||
|
||||
DrawQUADS((V3*)&ptrv,0,1,2,3,(T2*)&ptrt,3,0,1,2);
|
||||
DrawQUADS((V3*)&ptrv,0,3,7,4,(T2*)&ptrt,1,2,3,0);
|
||||
DrawQUADS((V3*)&ptrv,4,7,6,5,(T2*)&ptrt,2,3,0,1);
|
||||
DrawQUADS((V3*)&ptrv,5,6,2,1,(T2*)&ptrt,3,0,1,2);
|
||||
DrawQUADS((V3*)&ptrv,7,3,2,6,(T2*)&ptrt,3,0,1,2);
|
||||
DrawQUADS((V3*)&ptrv,5,1,0,4,(T2*)&ptrt,3,0,1,2);
|
||||
|
||||
kosglSwapBuffers();
|
||||
}
|
||||
|
||||
void reshape()
|
||||
{
|
||||
__menuet__get_process_table((process_table_entry*)pri,-1);
|
||||
glViewport(0, 0, pri->winx_size, pri->winy_size-20);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(50.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void disabletgl()
|
||||
{
|
||||
kosglDestroyContext(cgl);
|
||||
delete pri;
|
||||
}
|
||||
|
||||
void Title()
|
||||
{
|
||||
__menuet__write_text(300,8,0x10ffffff,fps,strlen(fps));
|
||||
__menuet__write_text(8,8,0x10ffffff,title1,strlen(title1));
|
||||
__menuet__write_text(180,8,0x00ffffff,title2,strlen(title2));
|
||||
__menuet__write_text(600,8,0x00ffffff,title3,strlen(title3));
|
||||
}
|
||||
|
||||
void draw_window(void)
|
||||
{
|
||||
// start redraw
|
||||
__menuet__window_redraw(1);
|
||||
// define&draw window
|
||||
__menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0);
|
||||
// end redraw
|
||||
__menuet__window_redraw(2);
|
||||
// display string
|
||||
Title();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
||||
win.x = 100;
|
||||
win.y = 100;
|
||||
win.dx = 400;
|
||||
win.dy = 400;
|
||||
|
||||
draw_window();
|
||||
|
||||
cgl = kosglCreateContext( 0, 0);
|
||||
kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glClearDepth(1.0);
|
||||
glEnable( GL_CULL_FACE );
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
int width, height;
|
||||
unsigned char* texture;
|
||||
LoadFileBMP( "./logio.bmp", &texture, &width, &height, false );
|
||||
|
||||
/* Setup texturing */
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
||||
|
||||
/* generate texture object IDs */
|
||||
glGenTextures(1, TexObj);
|
||||
glBindTexture(GL_TEXTURE_2D, *TexObj);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glBindTexture(GL_TEXTURE_2D, *TexObj);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
pri=new process_table_entry_;
|
||||
SysCall(66,1,1);
|
||||
|
||||
reshape();
|
||||
|
||||
do{
|
||||
|
||||
angle += 0.001 + 0.1*Fps (330,8);
|
||||
|
||||
DrawGL();
|
||||
|
||||
switch(__menuet__check_for_event())
|
||||
{
|
||||
case 1: draw_window();
|
||||
reshape();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
switch(__menuet__getkey()){
|
||||
|
||||
case KEY_F:
|
||||
if(!FullScreen){
|
||||
skin=0;
|
||||
SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff);
|
||||
draw_window();
|
||||
reshape();
|
||||
FullScreen = 1;
|
||||
}
|
||||
else{
|
||||
skin=3;
|
||||
draw_window();
|
||||
SysCall(67,win.x,win.y,win.dx,win.dy);
|
||||
reshape();
|
||||
FullScreen = 0;
|
||||
};
|
||||
break;
|
||||
|
||||
case KEY_ESC: disabletgl();
|
||||
return;}
|
||||
break;
|
||||
|
||||
case 3: disabletgl();
|
||||
return;
|
||||
}
|
||||
}while(1);
|
||||
}
|
||||
|
||||
|
1
programs/demos/cubetext/trunk/readme.txt
Normal file
1
programs/demos/cubetext/trunk/readme.txt
Normal file
@ -0,0 +1 @@
|
||||
Лого KolibriOS - Lrz
|
15
programs/demos/gears/trunk/Makefile
Normal file
15
programs/demos/gears/trunk/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
OUTFILE = gears
|
||||
|
||||
SRCS = main.cpp fps.cpp
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
CPPFLAGS = -I$(TINYGL)\include -O2
|
||||
|
||||
LIBR = TinyGL m
|
||||
LIBS = $(addprefix -l,$(LIBR)) -L$(TINYGL)\lib
|
||||
|
||||
all: $(OUTFILE)
|
||||
objcopy $(OUTFILE) -O binary
|
||||
|
||||
include $(MENUETDEV)/makefiles/Makefile_for_cpp_program
|
24
programs/demos/gears/trunk/ProcessTab.h
Normal file
24
programs/demos/gears/trunk/ProcessTab.h
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
struct process_table_entry_
|
||||
{
|
||||
__u32 cpu_usage __attribute__((packed));
|
||||
__u16 pos_in_windowing_stack __attribute__((packed));
|
||||
__u16 win_stack_val_at_ecx __attribute__((packed));
|
||||
__u16 rez1 __attribute__((packed));
|
||||
char name[11] __attribute__((packed));
|
||||
__u8 rez2 __attribute__((packed));
|
||||
__u32 memstart __attribute__((packed));
|
||||
__u32 memused __attribute__((packed));
|
||||
__u32 pid __attribute__((packed));
|
||||
__u32 winx_start,winy_start __attribute__((packed));
|
||||
__u32 winx_size,winy_size __attribute__((packed));
|
||||
__u8 slot __attribute__((packed));
|
||||
__u8 rez3 __attribute__((packed));
|
||||
__u32 clarx_start,clary_start __attribute__((packed));
|
||||
__u32 clarx_size,clary_size __attribute__((packed));
|
||||
__u8 win_condition __attribute__((packed));
|
||||
__u8 buf[955] __attribute__((packed));
|
||||
} __attribute__((packed));
|
||||
|
||||
#define TYPEWIN(D,C,B,A,Y,RR,GG,BB) (D<<31)|(C<<30)|(B<<29)|(A<<28)|(Y<<24)|\
|
||||
(RR<<16)|(GG<<8)|BB
|
188
programs/demos/gears/trunk/SysCall.h
Normal file
188
programs/demos/gears/trunk/SysCall.h
Normal file
@ -0,0 +1,188 @@
|
||||
#ifndef __cplusplus
|
||||
|
||||
//"inline" ôóíêöèè äëÿ âûçîâà ñèñòåìíûõ ôóíêöèé Kolibri â C - â èìåíè ôóíêöèè êîë-âî ïàðàìåòðîâ
|
||||
//SysCall# (íîìåð_ñèñòåìíîé_ôóíêöèè, ïàðàìåòðû,...)
|
||||
|
||||
static inline int SysCall1 (int EAX__) __attribute__((always_inline));
|
||||
static inline int SysCall2 (int EAX__, int EBX__) __attribute__((always_inline));
|
||||
static inline int SysCall3 (int EAX__, int EBX__, int ECX__) __attribute__((always_inline));
|
||||
static inline int SysCall4 (int EAX__, int EBX__, int ECX__, int EDX__) __attribute__((always_inline));
|
||||
static inline int SysCall5 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__) __attribute__((always_inline));
|
||||
static inline int SysCall6 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__) __attribute__((always_inline));
|
||||
|
||||
|
||||
static inline int SysCall1 (int EAX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall2 (int EAX__, int EBX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall3 (int EAX__, int EBX__, int ECX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall4 (int EAX__, int EBX__, int ECX__, int EDX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall5 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall6 (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile(""::"D"(EDI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
//"inline" ôóíêöèè äëÿ âûçîâà ñèñòåìíûõ ôóíêöèé Kolibri â C++
|
||||
//SysCall(íîìåð_ñèñòåìíîé_ôóíêöèè, ïàðàìåòðû,...)
|
||||
|
||||
static inline int SysCall (int EAX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__) __attribute__((always_inline));
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__) __attribute__((always_inline));
|
||||
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static inline int SysCall (int EAX__, int EBX__, int ECX__, int EDX__, int ESI__, int EDI__)
|
||||
{
|
||||
asm volatile(""::"a"(EAX__));
|
||||
asm volatile(""::"b"(EBX__));
|
||||
asm volatile(""::"c"(ECX__));
|
||||
asm volatile(""::"d"(EDX__));
|
||||
asm volatile(""::"S"(ESI__));
|
||||
asm volatile(""::"D"(EDI__));
|
||||
asm volatile("int $0x40");
|
||||
|
||||
register int res;
|
||||
asm volatile("":"=a"(res):);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
46
programs/demos/gears/trunk/fps.cpp
Normal file
46
programs/demos/gears/trunk/fps.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "SysCall.h"
|
||||
|
||||
/*******************************************************************************
|
||||
ФУНКЦИЯ ОПРЕДЕЛЕНИЯ FPS
|
||||
x,y - координаты вывода FPS на окно
|
||||
возвращает время в сотых долях секунды затрачиваемое на 1 цикл
|
||||
|
||||
*/
|
||||
|
||||
int time1=0;
|
||||
int time2=0;
|
||||
int fps1=0;
|
||||
int timerend=0;
|
||||
|
||||
int Fps (long x, long y)//функция определения FPS
|
||||
{
|
||||
int tr;
|
||||
|
||||
time1 = SysCall(26,9);//определяем время прошедшее момента запуска системы
|
||||
|
||||
if (timerend==0)
|
||||
{
|
||||
time2=time1;
|
||||
timerend=time1;
|
||||
}
|
||||
|
||||
tr = time1 - timerend;
|
||||
|
||||
if ((time1 - time2) < 100)//если прошло менее 1 секунды
|
||||
{ //увеличиваем счетчик fps
|
||||
fps1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//выводим число fps
|
||||
SysCall(13,(x<<16)+23,(y<<16)+7,0x00555555); //НАРИСОВАТЬ ПОЛОСУ
|
||||
SysCall(47,4<<16,fps1,(x<<16)+y,0xfafafa);//ВЫВЕСТИ В ОКНО ПРИЛОЖЕНИЯ ЧИСЛО
|
||||
fps1=0;
|
||||
time2=time1;
|
||||
}
|
||||
|
||||
timerend=time1;
|
||||
|
||||
return tr;
|
||||
}
|
||||
//******************************************************************************
|
345
programs/demos/gears/trunk/main.cpp
Normal file
345
programs/demos/gears/trunk/main.cpp
Normal file
@ -0,0 +1,345 @@
|
||||
/*
|
||||
Ïðèìåð âçÿò èç íàáîðà ïðèìåðîâ áèáëèîòåêè Mesa
|
||||
|
||||
iadn
|
||||
http://www.iadn.narod.ru
|
||||
iadn@bk.ru
|
||||
*/
|
||||
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
#include<menuet/os.h>
|
||||
#include <kosgl.h> //TinyGL
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SysCall.h"
|
||||
#include "ProcessTab.h"
|
||||
|
||||
int Fps (long x, long y);
|
||||
extern "C"{
|
||||
void app_main(void);
|
||||
}
|
||||
|
||||
struct {
|
||||
int x,y;
|
||||
int dx,dy;
|
||||
} win;
|
||||
|
||||
#define KEY_ESC 1
|
||||
#define KEY_F 33
|
||||
|
||||
char *title1 = "TinyGL in KolibriOS";
|
||||
char *title2 = "F full screen";
|
||||
char *title3 = "ESC - exit";
|
||||
char *fps = "FPS:";
|
||||
|
||||
unsigned char FullScreen = 0;
|
||||
unsigned char skin = 3;
|
||||
|
||||
process_table_entry_* pri;
|
||||
KOSGLContext cgl;
|
||||
|
||||
static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
|
||||
static GLuint limit;
|
||||
static GLuint count = 1;
|
||||
|
||||
/*
|
||||
* Draw a gear wheel. You'll probably want to call this function when
|
||||
* building a display list since we do a lot of trig here.
|
||||
*
|
||||
* Input: inner_radius - radius of hole at center
|
||||
* outer_radius - radius at center of teeth
|
||||
* width - width of gear
|
||||
* teeth - number of teeth
|
||||
* tooth_depth - depth of tooth
|
||||
*/
|
||||
static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth )
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth/2.0;
|
||||
r2 = outer_radius + tooth_depth/2.0;
|
||||
|
||||
da = 2.0*M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel( GL_FLAT );
|
||||
|
||||
glNormal3f( 0.0, 0.0, 1.0 );
|
||||
|
||||
/* draw front face */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<=teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin( GL_QUADS );
|
||||
da = 2.0*M_PI / teeth / 4.0;
|
||||
for (i=0;i<teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f( 0.0, 0.0, -1.0 );
|
||||
|
||||
/* draw back face */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<=teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin( GL_QUADS );
|
||||
da = 2.0*M_PI / teeth / 4.0;
|
||||
for (i=0;i<teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
|
||||
glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
|
||||
u = r2*cos(angle+da) - r1*cos(angle);
|
||||
v = r2*sin(angle+da) - r1*sin(angle);
|
||||
len = sqrt( u*u + v*v );
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f( v, -u, 0.0 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
|
||||
glNormal3f( cos(angle), sin(angle), 0.0 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
|
||||
glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
|
||||
u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
|
||||
v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
|
||||
glNormal3f( v, -u, 0.0 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
|
||||
glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
|
||||
glNormal3f( cos(angle), sin(angle), 0.0 );
|
||||
}
|
||||
|
||||
glVertex3f( r1*cos(0.0), r1*sin(0.0), width*0.5 );
|
||||
glVertex3f( r1*cos(0.0), r1*sin(0.0), -width*0.5 );
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel( GL_SMOOTH );
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
for (i=0;i<=teeth;i++) {
|
||||
angle = i * 2.0*M_PI / teeth;
|
||||
glNormal3f( -cos(angle), -sin(angle), 0.0 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
|
||||
glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void init( void )
|
||||
{
|
||||
static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 };
|
||||
static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
|
||||
static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
|
||||
static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
|
||||
|
||||
glLightfv( GL_LIGHT0, GL_POSITION, pos );
|
||||
glEnable( GL_CULL_FACE );
|
||||
glEnable( GL_LIGHTING );
|
||||
glEnable( GL_LIGHT0 );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red );
|
||||
gear( 1.0, 4.0, 1.0, 20, 0.7 );
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green );
|
||||
gear( 0.5, 2.0, 2.0, 10, 0.7 );
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue );
|
||||
gear( 1.3, 2.0, 0.5, 10, 0.7 );
|
||||
glEndList();
|
||||
|
||||
glEnable( GL_NORMALIZE );
|
||||
|
||||
glViewport(0, 0, (GLint)500, (GLint)480);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum( -1.0, 1.0, -1, 1, 5.0, 60.0 );
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef( 0.0, 0.0, -40.0 );
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void reshape()
|
||||
{
|
||||
__menuet__get_process_table((process_table_entry*)pri,-1);
|
||||
glViewport(0, 0, pri->winx_size, pri->winy_size-20);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 60.0);
|
||||
glTranslatef( 0.0, 0.0, 20.0 );
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void disabletgl()
|
||||
{
|
||||
kosglDestroyContext(cgl);
|
||||
delete pri;
|
||||
}
|
||||
|
||||
void Title()
|
||||
{
|
||||
__menuet__write_text(300,8,0x10ffffff,fps,strlen(fps));
|
||||
__menuet__write_text(8,8,0x10ffffff,title1,strlen(title1));
|
||||
__menuet__write_text(180,8,0x00ffffff,title2,strlen(title2));
|
||||
__menuet__write_text(600,8,0x00ffffff,title3,strlen(title3));
|
||||
}
|
||||
|
||||
void draw_window(void)
|
||||
{
|
||||
// start redraw
|
||||
__menuet__window_redraw(1);
|
||||
// define&draw window
|
||||
__menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0);
|
||||
// end redraw
|
||||
__menuet__window_redraw(2);
|
||||
// display string
|
||||
Title();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
||||
win.x = 100;
|
||||
win.y = 100;
|
||||
win.dx = 400;
|
||||
win.dy = 400;
|
||||
|
||||
draw_window();
|
||||
|
||||
cgl = kosglCreateContext( 0, 0);
|
||||
kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl);
|
||||
|
||||
init();
|
||||
|
||||
pri=new process_table_entry_;
|
||||
SysCall(66,1,1);
|
||||
|
||||
reshape();
|
||||
|
||||
do{
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef( view_rotx, 1.0, 0.0, 0.0 );
|
||||
glRotatef( view_roty, 0.0, 1.0, 0.0 );
|
||||
glRotatef( view_rotz, 0.0, 0.0, 1.0 );
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( -2.0, -2.0, 0.0 );
|
||||
glRotatef( angle, 0.0, 0.0, 1.0 );
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( 4.1, -2.0, 0.0 );
|
||||
glRotatef( -2.0*angle-9.0, 0.0, 0.0, 1.0 );
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( -2.1, 4.2, 0.0 );
|
||||
glRotatef( -2.0*angle-25.0, 0.0, 0.0, 1.0 );
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
kosglSwapBuffers();
|
||||
|
||||
angle += 0.01 + 0.3* Fps (330,8);
|
||||
|
||||
switch(SysCall(11))
|
||||
{
|
||||
case 1: draw_window();
|
||||
reshape();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
switch(__menuet__getkey()){
|
||||
|
||||
case KEY_F:
|
||||
if(!FullScreen){
|
||||
skin=0;
|
||||
SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff);
|
||||
draw_window();
|
||||
reshape();
|
||||
FullScreen = 1;
|
||||
}
|
||||
else{
|
||||
skin=3;
|
||||
draw_window();
|
||||
SysCall(67,win.x,win.y,win.dx,win.dy);
|
||||
reshape();
|
||||
FullScreen = 0;
|
||||
};
|
||||
break;
|
||||
|
||||
case KEY_ESC: disabletgl();
|
||||
return;}
|
||||
break;
|
||||
|
||||
case 3: disabletgl();
|
||||
return;
|
||||
}
|
||||
}while(1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user