Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 8609 → Rev 8610

/contrib/sdk/sources/newlib/libc/include/sys/kos.h
0,0 → 1,461
////////////////////////////////////////////
// Copyright (C) 2021 maxcodehack, GPLv2 //
// KolibriOS Syscalls //
// sys/kos.h //
// //
// Syscalls scheme: kos_XxxYyy //
// (e.g. kos_DrawWindow) //
////////////////////////////////////////////
 
#include <stdint.h>
#include <string.h>
 
typedef unsigned int color_t;
 
// Struct for App running
#pragma pack(push,1)
typedef struct
{
unsigned p00;
unsigned p04;
char *p08;
unsigned p12;
unsigned p16;
char p20;
char *p21;
} kos_Struct70;
#pragma pack(pop)
 
// Blitter struct
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
int srcx;
int srcy;
int srcw;
int srch;
void *bitmap;
int stride;
};
 
// Process info for sysfn 9
#pragma pack(push, 1)
struct proc_info
{
unsigned long cpu_usage;
unsigned short pos_in_stack;
unsigned short slot;
unsigned short reserved;
char name[12];
unsigned long address;
unsigned long memory_usage;
unsigned long ID;
unsigned long left,top;
unsigned long width,height;
unsigned short thread_state;
unsigned short reserved2;
unsigned long cleft, ctop, cwidth, cheight;
unsigned char window_state;
unsigned char reserved3[1024-71];
};
#pragma pack(pop)
 
// Color struct for sysfn ?
struct kolibri_system_colors {
color_t frame_area;
color_t grab_bar;
color_t grab_bar_button;
color_t grab_button_text;
color_t grab_text;
color_t work_area;
color_t work_button;
color_t work_button_text;
color_t work_text;
color_t work_graph;
};
 
typedef union __attribute__((packed))
{
uint32_t val;
struct
{
short x;
short y;
};
} pos_t;
 
 
/// Window Syscalls:
// Start drawing
static inline void kos_BeginDraw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
 
// End drawing
static inline void kos_EndDraw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
 
// Draw window
static inline void kos_DrawWindow(int x, int y, int w, int h, const char *title,
color_t bgcolor, uint32_t style)
{
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | ((w-1) & 0xFFFF)),
"c"((y << 16) | ((h-1) & 0xFFFF)),
"d"((style << 24) | (bgcolor & 0xFFFFFF)),
"D"(title),
"S"(0) : "memory");
};
 
// Change window size
#define OLD -1
static inline void kos_ChangeWindow(int new_x, int new_y, int new_w, int new_h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
);
}
 
/// Other GUI functions:
// Draw text
static inline void kos_DrawText(int x, int y, const char *text, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(strlen(text)),"c"(color)
:"memory");
}
 
// Draw button
static inline void kos_DrawButton(int x, int y, int w, int h, int id, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(8),
"b"(x * 65536 + w),
"c"(y * 65536 + h),
"d"(id),
"S"(color));
};
 
// Draw button with text
void kos_DrawButtonWithText(int x, int y, int w, int h, int id, color_t color, const char* text)
{
kos_DrawButton(x, y, w, h, id, color);
 
int tx = ((((-strlen(text))*8)+w)/2)+x;
int ty = h/2-7+y;
 
kos_DrawText(tx, ty, text, 0x90000000);
};
 
// Draw line
static inline void kos_DrawLine(int x_start, int y_start, int x_end, int y_end, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(38), "d"(color),
"b"((x_start << 16) | x_end),
"c"((y_start << 16) | y_end));
}
 
// Draw bar
static inline void kos_DrawBar(int x, int y, int w, int h, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(13), "d"(color),
"b"((x << 16) | w),
"c"((y << 16) | h));
}
 
// Put one pixel
void kos_PutPixel(int x, int y, color_t color) {
__asm__ __volatile__("int $0x40"
::"a"(1),
"b"(x),
"c"(y),
"d"(color));
}
 
// Draw bitmap image
static inline void kos_DrawBitmap(void *bitmap, int x, int y, int w, int h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
 
 
/// Skin:
// Return skin height
static inline uint32_t kos_SkinHeight(void)
{
uint32_t height;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(height)
:"a"(48),"b"(4));
return height;
};
 
/// Mouse:
// Get mouse position
#define POS_SCREEN 0
#define POS_WINDOW 1
 
static inline
pos_t kos_GetMousePos(int origin)
{
pos_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=a"(val)
:"a"(37),"b"(origin));
return val;
}
 
// Get mouse buttons
static inline
uint32_t kos_GetMouseButtons(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(2));
return val;
};
 
// Get mouse wheels
static inline
uint32_t kos_GetMouseWheels(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(val)
:"a"(37),"b"(7));
return val;
};
 
// Load cursor
static inline uint32_t kos_LoadCursor(void *path, uint32_t flags)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37), "b"(4), "c"(path), "d"(flags));
return val;
}
 
// Set cursor
static inline uint32_t kos_SetCursor(uint32_t cursor)
{
uint32_t old;
__asm__ __volatile__(
"int $0x40"
:"=a"(old)
:"a"(37), "b"(5), "c"(cursor));
return old;
};
 
// Destroy cursor
static inline int kos_DestroyCursor(uint32_t cursor)
{
int ret;
__asm__ __volatile__(
"int $0x40"
:"=a"(ret)
:"a"(37), "b"(6), "c"(cursor)
:"memory");
return ret;
};
 
/// OS Events:
#define evReDraw 1
#define evKey 2
#define evButton 3
#define evExit 4
#define evDesktop 5
#define evMouse 6
#define evIPC 7
#define evNetwork 8
#define evDebug 9
 
static inline
uint32_t kos_WaitForEventTimeout(uint32_t time)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(23), "b"(time));
return val;
};
static inline uint32_t kos_CheckForEvent(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
static inline uint32_t kos_WaitForEvent(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(10));
return val;
};
 
/// Eventmask:
#define EVM_REDRAW 1
#define EVM_KEY 2
#define EVM_BUTTON 4
#define EVM_EXIT 8
#define EVM_BACKGROUND 16
#define EVM_MOUSE 32
#define EVM_IPC 64
#define EVM_STACK 128
#define EVM_DEBUG 256
#define EVM_STACK2 512
#define EVM_MOUSE_FILTER 0x80000000
#define EVM_CURSOR_FILTER 0x40000000
static inline uint32_t kos_SetMaskForEvents(uint32_t event_mask)
{
uint32_t old_event_mask;
__asm__ __volatile__(
"int $0x40"
:"=a"(old_event_mask)
:"a"(40),"b"(event_mask));
return old_event_mask;
};
 
/// Other:
// Get key
int kos_GetKey()
{
unsigned short key;
__asm__ __volatile__("int $0x40":"=a"(key):"0"(2));
if(!(key & 0xFF)) return (key>>8)&0xFF; else return 0;
}
 
// Get pressed button ID
static inline
uint32_t kos_GetButtonID(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(17));
return val>>8;
};
 
// Sleep..
static inline void kos_Delay(uint32_t time)
{
__asm__ __volatile__(
"int $0x40"
::"a"(5), "b"(time)
:"memory");
};
 
// Get screen size
static inline
pos_t kos_ScreenSize()
{
pos_t size;
__asm__ __volatile__(
"int $0x40"
:"=a"(size)
:"a"(14));
 
return size;
};
 
// Get system color table
static inline void kos_GetSystemColors(struct kolibri_system_colors *color_table)
{
__asm__ __volatile__ ("int $0x40"
:
:"a"(48),"b"(3),"c"(color_table),"d"(40)
);
}
 
// SysFn 9
static inline void kos_ProcessInfo(char *info)
{
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1)
:"memory");
};
 
// Blitter
static inline void Blit(void *bitmap, int dst_x, int dst_y,
int src_x, int src_y, int w, int h,
int src_w, int src_h, int stride)
{
volatile struct blit_call bc;
bc.dstx = dst_x;
bc.dsty = dst_y;
bc.w = w;
bc.h = h;
bc.srcx = src_x;
bc.srcy = src_y;
bc.srcw = src_w;
bc.srch = src_h;
bc.stride = stride;
bc.bitmap = bitmap;
__asm__ __volatile__(
"int $0x40"
::"a"(73),"b"(0),"c"(&bc.dstx));
};
 
void kos_RunApp(char* app, char* param)
{
kos_Struct70 r;
r.p00 = 7;
r.p04 = 0;
r.p08 = param;
r.p12 = 0;
r.p16 = 0;
r.p20 = 0;
r.p21 = app;
__asm__ __volatile__ ("int $0x40"::"a"(70), "b"(&r));
}
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/games/fridge/fridge.c
1,5 → 1,5
// Includes //
#include <kos32sys.h>
#include <sys/kos.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
8,19 → 8,6
#include <kolibri_libimg.h>
// #include "mp3.h"
 
 
// C-- event defines //
#define evReDraw 1
#define evKey 2
#define evButton 3
#define evExit 4
#define evDesktop 5
#define evMouse 6
#define evIPC 7
#define evNetwork 8
#define evDebug 9
 
 
// Code //
#define button_color 0xbbbbbb
#define button_size 44
41,8 → 28,8
 
// Load pictures //
char temp_path[4096];
char* HORIZONTAL_IMAGE;
char* VERTICAL_IMAGE;
Image* HORIZONTAL_IMAGE;
Image* VERTICAL_IMAGE;
 
char* load_file_inmem(char* fname, int32_t* read_sz)
{
70,8 → 57,8
 
void load_pictures() {
const int icon_rgb_field_size = button_size*button_size;
char *image_data,
*filedata;
Image *image_data;
char *filedata;
strcpy(temp_path, "h.png");
 
99,24 → 86,24
 
 
// GUI functions //
void redraw_buttons() {
void RedrawButtons() {
for (int j = 5, x = 0; x<field_size; j+=button_size, x++)
for (int i = 15, y = 0; y<field_size; i+=button_size, y++)
{
// 0x50 mean button without drawing, but with border when press
// ((y+1)*10)+x+1 mean button id
define_button(65536 * i + (button_size), 65536 * j + (button_size), (0x50 << 24) | ((y+1)*10)+x+1, 0);
kos_DrawButton(i, j, button_size, button_size, (0x50 << 24) | ((y+1)*10)+x+1, 0);
if (field[x][y]) draw_bitmap(VERTICAL_IMAGE, i, j, button_size, button_size);
else draw_bitmap(HORIZONTAL_IMAGE, i, j, button_size, button_size);
if (field[x][y]) kos_DrawBitmap(VERTICAL_IMAGE, i, j, button_size, button_size);
else kos_DrawBitmap(HORIZONTAL_IMAGE, i, j, button_size, button_size);
}
}
 
void draw_game_window(){
BeginDraw();
DrawWindow(215, 100, 220, 220, title, button_color, 0x34);
redraw_buttons();
EndDraw();
kos_BeginDraw();
kos_DrawWindow(215, 100, 220, 220, title, button_color, 0x34);
RedrawButtons();
kos_EndDraw();
}
 
 
142,22 → 129,20
 
// Need refactoring:
void draw_victory_window() {
BeginDraw();
DrawWindow(215,100,220, 220,title,button_color,0x34);
kos_BeginDraw();
kos_DrawWindow(215,100,220, 220,title,button_color,0x34);
draw_text_sysNEW("Ну вы, и", 10, 10, strlen("Ну вы, и"), 0xB1, 0x000000);
draw_text_sysNEW("медвежатник,", 10, 50, strlen("Ну вы, и медвежатник,"), 0xB1, 0x000000);
draw_text_sysNEW("Шеф!", 12, 90, strlen("Шеф!"), 0xB1, 0x000000);
define_button(65536 * ((220/2)-(50)) + 140, 65536 * 140 + 25+12, BUTTON_RESTART, 0x9A9A9A);
kos_DrawButton(((220/2)-(50)), 140, 140, 25+12, BUTTON_RESTART, 0x9A9A9A);
draw_text_sysNEW("Заново", 80, 145, strlen("Заново"), 0xB1, 0x000000);
EndDraw();
kos_EndDraw();
}
 
 
 
void Button() {
int id = get_os_button();
int id = kos_GetButtonID();
if (id == 1) exit(0); else
if (id == BUTTON_RESTART) {
SetUp();
178,12 → 163,12
if (field[y][x]) field[y][x] = 0; else field[y][x] = 1;
redraw_buttons();
RedrawButtons();
}
}
 
 
int fridge_opened() {
int FridgeOpened() {
int fr_op = 0;
for (int y = 0; y<field_size; y++)
for (int x = 0; x<field_size; x++)
201,29 → 186,23
if (kolibri_libimg_init() == -1)
{
printf("Can not load libimg.obj!\n");
printf("Can not load libimg!\n");
exit(1);
}
load_pictures();
draw_game_window();
while(1)
{
switch(get_os_event())
switch(kos_WaitForEvent())
{
case evButton:
Button();
if (fridge_opened()) {
if (FridgeOpened()) {
victory = 1;
draw_victory_window();
}
break;
case evKey:
get_key();
break;
case evReDraw:
if (!victory) draw_game_window();
else draw_victory_window();