mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-23 21:22:59 +01:00
d
d
This commit is contained in:
1 parent
3d06f94e48
commit
57787bfc7f
59 files changed
+9967
-410
No files matched your search
@@ -1,6 +1,25 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
#include "../bob64/window.h"
|
||||
|
||||
static char file_buffer[BOB64_SYSCALL_MAX_BUFFER];
|
||||
#define CAT_GUI_WIDTH 720u
|
||||
#define CAT_GUI_HEIGHT 520u
|
||||
#define CAT_GUI_COLUMNS 112u
|
||||
#define CAT_GUI_ROWS 31u
|
||||
#define CAT_GUI_FILE_CAPACITY (16u*BOB64_SYSCALL_MAX_BUFFER)
|
||||
static u8 gui_text[CAT_GUI_FILE_CAPACITY+1];
|
||||
static u32 gui_pixels[CAT_GUI_WIDTH*CAT_GUI_HEIGHT];
|
||||
static BOB64_GFX gui_graphics;
|
||||
static BOB64_WINDOW_MANAGER gui_manager;
|
||||
static BOB64_WINDOW gui_window;
|
||||
static BOB64_WINDOW_HANDLE gui_order[1];
|
||||
static BOB64_RECT gui_close_button={12,32,72,18};
|
||||
static BOB64_BUTTON_STATE gui_close_state;
|
||||
static const char *gui_filename;
|
||||
static usize gui_text_length,gui_top_offset;
|
||||
static char gui_status[32];
|
||||
|
||||
static usize text_length(const char *text) {
|
||||
usize length=0;
|
||||
@@ -13,6 +32,154 @@ static void write_text(const char *text) {
|
||||
(void)bob64_app_write(text,text_length(text));
|
||||
}
|
||||
|
||||
static int is_newline(u8 value) {return value=='\n'||value=='\r';}
|
||||
|
||||
static usize next_visual_line(usize offset) {
|
||||
usize column=0;
|
||||
while(offset<gui_text_length&&column<CAT_GUI_COLUMNS&&
|
||||
!is_newline(gui_text[offset])) {offset++;column++;}
|
||||
if(offset<gui_text_length&&is_newline(gui_text[offset])) {
|
||||
u8 first=gui_text[offset++];
|
||||
if(offset<gui_text_length&&is_newline(gui_text[offset])&&
|
||||
gui_text[offset]!=first)offset++;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
static usize previous_visual_line(usize offset) {
|
||||
usize current=0;
|
||||
if(!offset)return 0;
|
||||
while(current<offset) {
|
||||
usize next=next_visual_line(current);
|
||||
if(next>=offset)return current;
|
||||
if(next<=current)return current;
|
||||
current=next;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
static void scroll_next_line(void) {
|
||||
if(gui_top_offset>=gui_text_length)return;
|
||||
usize next=next_visual_line(gui_top_offset);
|
||||
gui_top_offset=next>=gui_text_length?
|
||||
previous_visual_line(gui_text_length):next;
|
||||
}
|
||||
|
||||
static void draw_visual_line(usize offset,s32 x,s32 y) {
|
||||
char line[CAT_GUI_COLUMNS+1];
|
||||
usize length=0;
|
||||
while(offset<gui_text_length&&length<CAT_GUI_COLUMNS&&
|
||||
!is_newline(gui_text[offset])) {
|
||||
u8 value=gui_text[offset++];
|
||||
line[length++]=(value>=32&&value<=126)?(char)value:
|
||||
(value=='\t'?' ':'.');
|
||||
}
|
||||
line[length]=0;
|
||||
bob64_gfx_text(&gui_graphics,x,y,line,0x00e2ebf5u,1);
|
||||
}
|
||||
|
||||
static void set_gui_status(const char *text) {
|
||||
usize i=0;
|
||||
while(i+1<sizeof(gui_status)&&text[i]){gui_status[i]=text[i];i++;}
|
||||
gui_status[i]=0;
|
||||
}
|
||||
|
||||
static s64 gui_view_file(const char *name,usize name_length) {
|
||||
BOB64_EVENT event,screen_event,routed;
|
||||
u32 screen_width,screen_height;
|
||||
s64 result=bob64_app_file_read_all(name,name_length,gui_text,
|
||||
CAT_GUI_FILE_CAPACITY);
|
||||
if(result<0)return result;
|
||||
gui_text_length=(usize)result;gui_text[gui_text_length]=0;
|
||||
gui_filename=name;gui_top_offset=0;
|
||||
set_gui_status(gui_text_length?"TEXT FILE":"EMPTY FILE");
|
||||
if(bob64_app_write("bob!",4)!=4)return -2;
|
||||
if(bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<CAT_GUI_WIDTH||screen_height<CAT_GUI_HEIGHT)return -3;
|
||||
if(bob64_wm_init(&gui_manager,&gui_window,1,gui_order,
|
||||
screen_width,screen_height))return -4;
|
||||
BOB64_WINDOW_HANDLE kernel_handle=bob64_app_window_create(
|
||||
(s32)(screen_width-CAT_GUI_WIDTH)/2,
|
||||
(s32)(screen_height-CAT_GUI_HEIGHT)/2,CAT_GUI_WIDTH,CAT_GUI_HEIGHT);
|
||||
if(!kernel_handle||(s64)kernel_handle<0)return -5;
|
||||
gui_manager.NextHandle=kernel_handle;
|
||||
BOB64_WINDOW_HANDLE app_handle=bob64_wm_create(&gui_manager,
|
||||
(s32)(screen_width-CAT_GUI_WIDTH)/2,
|
||||
(s32)(screen_height-CAT_GUI_HEIGHT)/2,CAT_GUI_WIDTH,CAT_GUI_HEIGHT,
|
||||
(void *)"Text viewer");
|
||||
if(app_handle!=kernel_handle) {
|
||||
if(app_handle)bob64_wm_destroy(&gui_manager,app_handle);
|
||||
bob64_app_window_destroy(kernel_handle);return -6;
|
||||
}
|
||||
gui_graphics.Pixels=gui_pixels;gui_graphics.Width=CAT_GUI_WIDTH;
|
||||
gui_graphics.Height=CAT_GUI_HEIGHT;
|
||||
gui_graphics.Capacity=CAT_GUI_WIDTH*CAT_GUI_HEIGHT;
|
||||
for(;;) {
|
||||
bob64_gfx_fill_rect(&gui_graphics,0,0,CAT_GUI_WIDTH,CAT_GUI_HEIGHT,
|
||||
0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(&gui_graphics,0,0,CAT_GUI_WIDTH,
|
||||
BOB64_WINDOW_TITLE_BAR_HEIGHT,0x00335d8cu);
|
||||
bob64_gfx_text(&gui_graphics,12,8,"TEXT VIEWER",0x00ffffffu,1);
|
||||
bob64_button_draw(&gui_graphics,&gui_close_button,"CLOSE",
|
||||
&gui_close_state);
|
||||
bob64_gfx_text(&gui_graphics,100,38,gui_filename,0x00e2ebf5u,1);
|
||||
bob64_gfx_text(&gui_graphics,550,38,gui_status,0x009eb3c7u,1);
|
||||
usize line_offset=gui_top_offset;
|
||||
for(u32 row=0;row<CAT_GUI_ROWS&&line_offset<gui_text_length;row++) {
|
||||
draw_visual_line(line_offset,12,62+(s32)(row*14));
|
||||
usize next=next_visual_line(line_offset);
|
||||
if(next<=line_offset)break;
|
||||
line_offset=next;
|
||||
}
|
||||
if(bob64_app_window_present(gui_window.Handle,gui_graphics.Pixels,
|
||||
gui_graphics.Width,gui_graphics.Height)!=
|
||||
(s64)(CAT_GUI_WIDTH*CAT_GUI_HEIGHT))return -7;
|
||||
if(bob64_app_wait_event(&event))return -8;
|
||||
screen_event=event;screen_event.X=event.ScreenX;
|
||||
screen_event.Y=event.ScreenY;
|
||||
s64 target=bob64_wm_dispatch(&gui_manager,&screen_event,&routed);
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character==0x1b||event.Character=='x'||event.Character=='X'))
|
||||
break;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
event.Key==(BOB64_EVENT_KEY_EXTENDED|0x48))
|
||||
gui_top_offset=previous_visual_line(gui_top_offset);
|
||||
else if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
event.Key==(BOB64_EVENT_KEY_EXTENDED|0x50))
|
||||
scroll_next_line();
|
||||
else if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
event.Key==(BOB64_EVENT_KEY_EXTENDED|0x49)) {
|
||||
for(u32 row=0;row<CAT_GUI_ROWS-1&&gui_top_offset;row++)
|
||||
gui_top_offset=previous_visual_line(gui_top_offset);
|
||||
} else if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
event.Key==(BOB64_EVENT_KEY_EXTENDED|0x51)) {
|
||||
for(u32 row=0;row<CAT_GUI_ROWS-1&&gui_top_offset<gui_text_length;row++)
|
||||
scroll_next_line();
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_WHEEL&&event.Wheel&&
|
||||
target==(s64)gui_window.Handle) {
|
||||
if(event.Wheel>0)gui_top_offset=previous_visual_line(gui_top_offset);
|
||||
else scroll_next_line();
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE) {
|
||||
BOB64_EVENT local=event;local.X=event.ScreenX-gui_window.X;
|
||||
local.Y=event.ScreenY-gui_window.Y;
|
||||
bob64_button_event(&gui_close_button,&gui_close_state,&local);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
target==(s64)gui_window.Handle) {
|
||||
BOB64_EVENT local=event;local.X=routed.X;local.Y=routed.Y;
|
||||
int clicked=bob64_button_event(&gui_close_button,&gui_close_state,
|
||||
&local);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&clicked)break;
|
||||
}
|
||||
}
|
||||
bob64_app_window_destroy(gui_window.Handle);
|
||||
bob64_wm_destroy(&gui_manager,gui_window.Handle);
|
||||
gui_filename=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
const char *name;
|
||||
usize name_length;
|
||||
@@ -21,6 +188,20 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
int read_any=0;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
if(startup->ArgumentCount==3&&startup->Arguments&&
|
||||
startup->Arguments[1]&&startup->Arguments[2]&&
|
||||
text_length(startup->Arguments[1])==3&&
|
||||
startup->Arguments[1][0]=='g'&&startup->Arguments[1][1]=='u'&&
|
||||
startup->Arguments[1][2]=='i') {
|
||||
name=startup->Arguments[2];
|
||||
name_length=text_length(name);
|
||||
if(!name_length||name_length>BOB64_SYSCALL_MAX_FILENAME)
|
||||
return -9;
|
||||
result=gui_view_file(name,name_length);
|
||||
if(result==-28)write_text("file too large for viewer\n");
|
||||
else if(result<0)write_text("cannot open viewer file\n");
|
||||
return result;
|
||||
}
|
||||
if(startup->ArgumentCount!=2||!startup->Arguments||
|
||||
!(name=startup->Arguments[1])||!(name_length=text_length(name))) {
|
||||
write_text("usage: cat FILE\n");
|
||||
|
||||
+107
-8
@@ -1,10 +1,18 @@
|
||||
typedef int count_t;
|
||||
typedef char byte_t;
|
||||
typedef int *int_ptr;
|
||||
typedef unsigned long long uint64_value;
|
||||
|
||||
struct size_probe { char tag; int value; long long wide; };
|
||||
int global_value = 42;
|
||||
byte_t global_message[5] = "bob!";
|
||||
void *global_value_address = &global_value;
|
||||
void *global_message_address = global_message;
|
||||
void *global_literal_address = "bob!";
|
||||
|
||||
int sum_values(int values[], int count) {
|
||||
count_t sum = 0;
|
||||
for (int i = 0; i < count; i = i + 1)
|
||||
for (int i = 0; i < count; i++)
|
||||
sum = sum + values[i];
|
||||
return sum;
|
||||
}
|
||||
@@ -12,18 +20,31 @@ int sum_values(int values[], int count) {
|
||||
count_t text_length(byte_t text[]) {
|
||||
count_t length = 0;
|
||||
while (text[length] != '\0')
|
||||
length = length + 1;
|
||||
length++;
|
||||
return length;
|
||||
}
|
||||
|
||||
int_ptr first_value(int_ptr values) {
|
||||
return values;
|
||||
int_ptr first = values;
|
||||
return first++;
|
||||
}
|
||||
|
||||
void *opaque_identity(int marker, void *value) {
|
||||
int *typed_value = value;
|
||||
if (marker != 42)
|
||||
*typed_value = 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
usize wide_division(usize value) {
|
||||
return value / 10 + value % 10;
|
||||
}
|
||||
|
||||
uint64_value add_unsigned_wide(uint64_value value,
|
||||
unsigned long long int amount) {
|
||||
return value + amount;
|
||||
}
|
||||
|
||||
int sum_sixteen(int a, int b, int c, int d, int e, int f, int g, int h,
|
||||
int i, int j, int k, int l, int m, int n, int o, int p) {
|
||||
return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p;
|
||||
@@ -34,11 +55,63 @@ int stack_argument_test(void) {
|
||||
9, 10, 11, 12, 13, 14, 15, 16);
|
||||
}
|
||||
|
||||
int do_while_test(void) {
|
||||
int count = 0;
|
||||
int total = 0;
|
||||
do {
|
||||
count++;
|
||||
if (count == 2) continue;
|
||||
total = total + count;
|
||||
} while (count < 4);
|
||||
return total;
|
||||
}
|
||||
|
||||
enum SwitchValue { SWITCH_ONE = 1, SWITCH_TWO, SWITCH_THREE };
|
||||
|
||||
int switch_test(enum SwitchValue value) {
|
||||
int total = 0;
|
||||
switch (value) {
|
||||
case SWITCH_ONE: total = 10; break;
|
||||
case SWITCH_TWO: total = 20;
|
||||
case SWITCH_THREE: total = total + 3; break;
|
||||
default: total = 99;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
int inspect_mixed_arguments(int a, int b, int c, int d, int *direct,
|
||||
int e, void *opaque, int f) {
|
||||
int *converted = opaque;
|
||||
return direct[0] + converted[1] + a + b + c + d + e + f;
|
||||
}
|
||||
|
||||
void *identity_with_stack_pointer(int a, int b, int c, int d, void *value,
|
||||
int marker) {
|
||||
int *typed_value = value;
|
||||
if (a + b + c + d != 10 || marker != 42)
|
||||
typed_value[0] = -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
count_t values[64];
|
||||
byte_t message[5] = "bob!";
|
||||
int_ptr value_pointer = first_value(values);
|
||||
int v0 = 0;
|
||||
void *opaque_values = values;
|
||||
void *opaque_pointer = opaque_identity(42, value_pointer);
|
||||
int_ptr restored_pointer = opaque_pointer;
|
||||
uintptr_t raw_global_address = (uintptr_t)&global_value;
|
||||
void *cast_opaque_address = (void *)raw_global_address;
|
||||
int *cast_global_pointer = (int *)cast_opaque_address;
|
||||
short cast_short = (short)0x10034;
|
||||
char cast_character = (char)0x142;
|
||||
short cast_negative = (short)0xffff;
|
||||
int cast_int = (int)0x10000002aULL;
|
||||
unsigned long long unsigned_wide = 0xffffffffffffffffULL;
|
||||
int_ptr global_value_pointer = global_value_address;
|
||||
byte_t *global_message_pointer = global_message_address;
|
||||
byte_t *global_literal_pointer = global_literal_address;
|
||||
int v0;
|
||||
int v1 = 1;
|
||||
int v2 = 2;
|
||||
int v3 = 3;
|
||||
@@ -77,20 +150,46 @@ int main(void) {
|
||||
int v36 = 36;
|
||||
int v37 = 37;
|
||||
int v38 = 38;
|
||||
int v39 = 39;
|
||||
int v39;
|
||||
v0 = 0;
|
||||
v39 = 39;
|
||||
v0++;
|
||||
++v0;
|
||||
v39--;
|
||||
++v39;
|
||||
values[0] = 12;
|
||||
values[1] = 13;
|
||||
values[2] = 17;
|
||||
values[63] = 42;
|
||||
if (sum_values(values, 3) == 42 && text_length(message) == 4 &&
|
||||
stack_argument_test() == 136 && values[63] == 42 &&
|
||||
value_pointer[63] == 42 && v0 + v39 == 39 &&
|
||||
stack_argument_test() == 136 && do_while_test() == 8 &&
|
||||
switch_test(2) == 23 &&
|
||||
inspect_mixed_arguments(1, 2, 3, 4, values, 5,
|
||||
identity_with_stack_pointer(1, 2, 3, 4,
|
||||
opaque_values, 42),
|
||||
6) == 46 &&
|
||||
values[0] == 12 && values[63] == 42 &&
|
||||
value_pointer[63] == 42 && restored_pointer[63] == 42 &&
|
||||
*cast_global_pointer == 42 && cast_short == 0x34 &&
|
||||
cast_character == 'B' && cast_negative == -1 && cast_int == 42 &&
|
||||
*global_value_pointer == 42 && global_message_pointer[1] == 'o' &&
|
||||
global_literal_pointer[0] == 'b' && v0 + v39 == 41 &&
|
||||
20 / 3 == 6 && 20 % 3 == 2 &&
|
||||
-20 / 3 == -6 && -20 % 3 == -2 &&
|
||||
wide_division(0x100000001ULL) == 429496736 &&
|
||||
sizeof(unsigned long long) == 8 &&
|
||||
add_unsigned_wide(unsigned_wide, 1ULL) == 0 &&
|
||||
unsigned_wide > 0x7fffffffffffffffULL &&
|
||||
(0x100000001ULL >> 32) == 1 &&
|
||||
((0x5a ^ 0x3c) & 0xff) == 0x66 &&
|
||||
(1 | 2 ^ 3 & 1) == 3 && (-8 >> 2) == -2) {
|
||||
(1 | 2 ^ 3 & 1) == 3 && (-8 >> 2) == -2 &&
|
||||
sizeof(char) == 1 && sizeof(short) == 2 && sizeof(int) == 4 &&
|
||||
sizeof(long) == 4 && sizeof(long long) == 8 && sizeof(usize) == 8 &&
|
||||
sizeof(void *) == 8 && sizeof(int *) == 8 &&
|
||||
sizeof(count_t[64]) == 256 &&
|
||||
sizeof(struct size_probe) == 16 && sizeof(values) == 256 &&
|
||||
sizeof(message) == 5 && sizeof(value_pointer) == 8 &&
|
||||
sizeof(values[0]) == 4 && sizeof(text_length(message)) == 4) {
|
||||
bob64_app_write(message, text_length(message));
|
||||
return 0;
|
||||
}
|
||||
|
||||
+16
-2
@@ -1,10 +1,13 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
|
||||
#define DEMO_WIDTH 640u
|
||||
#define DEMO_HEIGHT 400u
|
||||
|
||||
static u32 pixels[DEMO_WIDTH*DEMO_HEIGHT];
|
||||
static const BOB64_RECT close_button={552,8,72,22};
|
||||
static BOB64_BUTTON_STATE close_state;
|
||||
|
||||
static void draw_demo(BOB64_GFX *graphics) {
|
||||
u32 width=graphics->Width,height=graphics->Height;
|
||||
@@ -18,8 +21,9 @@ static void draw_demo(BOB64_GFX *graphics) {
|
||||
height-(u32)(margin*2),0x1b2b40u);
|
||||
bob64_gfx_fill_rect(graphics,margin,margin,width-(u32)(margin*2),
|
||||
(u32)header_height,0x345d89u);
|
||||
bob64_gfx_text(graphics,margin*2,margin*2,"BOB32 GRAPHICS DEMO",
|
||||
bob64_gfx_text(graphics,margin*2,margin*2,"BOB64 GRAPHICS DEMO",
|
||||
0x00ffffffu,3);
|
||||
(void)bob64_button_draw(graphics,&close_button,"CLOSE",&close_state);
|
||||
bob64_gfx_line(graphics,margin,header_height+margin*2,
|
||||
(s32)width-margin,header_height+margin*2,0x00f0c879u);
|
||||
bob64_gfx_text(graphics,margin*2,panel_y-margin*2,
|
||||
@@ -39,7 +43,8 @@ static void draw_demo(BOB64_GFX *graphics) {
|
||||
bob64_gfx_fill_rect(graphics,margin,panel_y+(s32)panel_height+margin,
|
||||
width-(u32)(margin*2),3,0x006d849fu);
|
||||
bob64_gfx_text(graphics,margin*2,
|
||||
(s32)height-margin*6,"PRESS X OR ESCAPE TO RETURN",0x00ffffffu,2);
|
||||
(s32)height-margin*6,"CLICK CLOSE OR PRESS X / ESCAPE",
|
||||
0x00ffffffu,2);
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
@@ -68,6 +73,15 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
(event.Character=='x'||event.Character=='X'||event.Character==0x1b)) {
|
||||
result=0;break;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE||
|
||||
event.Type==BOB64_EVENT_MOUSE_BUTTON) {
|
||||
if(bob64_button_event(&close_button,&close_state,&event)) {
|
||||
result=0;break;
|
||||
}
|
||||
draw_demo(&graphics);
|
||||
result=bob64_app_window_present(window,pixels,DEMO_WIDTH,DEMO_HEIGHT);
|
||||
if(result!=(s64)(DEMO_WIDTH*DEMO_HEIGHT))goto cleanup;
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
if(bob64_app_window_destroy(window)&&result==0)result=-6;
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
|
||||
#define ECHO_WINDOW_WIDTH 640u
|
||||
#define ECHO_WINDOW_HEIGHT 400u
|
||||
#define ECHO_LINE_CAPACITY 96u
|
||||
#define ECHO_LINE_LIMIT 48u
|
||||
#define ECHO_VISIBLE_LINES 26u
|
||||
|
||||
static u32 pixels[ECHO_WINDOW_WIDTH*ECHO_WINDOW_HEIGHT];
|
||||
static char lines[ECHO_LINE_LIMIT][ECHO_LINE_CAPACITY];
|
||||
static u32 line_count,scroll_offset;
|
||||
static BOB64_RECT close_button={552,4,72,18};
|
||||
static BOB64_BUTTON_STATE close_state;
|
||||
|
||||
static usize text_length(const char *text) {
|
||||
usize length=0;
|
||||
@@ -7,10 +21,131 @@ static usize text_length(const char *text) {
|
||||
return length;
|
||||
}
|
||||
|
||||
static int text_equals(const char *left,const char *right) {
|
||||
usize i=0;
|
||||
if(!left||!right)return 0;
|
||||
while(left[i]&&right[i]&&left[i]==right[i])i++;
|
||||
return !left[i]&&!right[i];
|
||||
}
|
||||
|
||||
static void append_new_line(void) {
|
||||
if(line_count<ECHO_LINE_LIMIT)line_count++;
|
||||
else {
|
||||
const char marker[]="...";
|
||||
for(usize i=0;i<sizeof(marker);i++)
|
||||
lines[ECHO_LINE_LIMIT-1][i]=marker[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void append_text(const char *text) {
|
||||
if(!text)return;
|
||||
for(usize i=0;text[i];i++) {
|
||||
if(line_count>=ECHO_LINE_LIMIT)return;
|
||||
u32 row=line_count-1;
|
||||
usize column=text_length(lines[row]);
|
||||
if(text[i]=='\n') {
|
||||
append_new_line();
|
||||
} else {
|
||||
if(column>=ECHO_LINE_CAPACITY-1) {
|
||||
append_new_line();
|
||||
if(line_count>=ECHO_LINE_LIMIT)return;
|
||||
row=line_count-1;column=0;
|
||||
}
|
||||
lines[row][column]=text[i];
|
||||
lines[row][column+1]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void build_lines(const BOB64_APP_STARTUP *startup) {
|
||||
line_count=1;scroll_offset=0;
|
||||
for(u64 i=2;i<startup->ArgumentCount;i++) {
|
||||
if(i>2)append_text(" ");
|
||||
append_text(startup->Arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void reveal_scroll(void) {
|
||||
u32 maximum=line_count>ECHO_VISIBLE_LINES?
|
||||
line_count-ECHO_VISIBLE_LINES:0;
|
||||
if(scroll_offset>maximum)scroll_offset=maximum;
|
||||
}
|
||||
|
||||
static int draw_window(BOB64_GFX *graphics) {
|
||||
bob64_gfx_fill_rect(graphics,0,0,ECHO_WINDOW_WIDTH,ECHO_WINDOW_HEIGHT,
|
||||
0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(graphics,0,0,ECHO_WINDOW_WIDTH,26,0x00335d8cu);
|
||||
bob64_gfx_text(graphics,12,8,"BOB64 ECHO",0x00ffffffu,1);
|
||||
if(bob64_button_draw(graphics,&close_button,"CLOSE",&close_state))return -1;
|
||||
bob64_gfx_text(graphics,16,34,"ARGUMENTS",0x008fc8ffu,1);
|
||||
for(u32 row=0;row<ECHO_VISIBLE_LINES&&scroll_offset+row<line_count;row++)
|
||||
bob64_gfx_text(graphics,16,52+(s32)row*12,
|
||||
lines[scroll_offset+row],0x00e2ebf5u,1);
|
||||
bob64_gfx_line(graphics,12,374,628,374,0x006d849fu);
|
||||
bob64_gfx_text(graphics,16,382,"UP/DOWN OR WHEEL SCROLL ESC CLOSE",
|
||||
0x009eb3c7u,1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static s64 run_gui(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_GFX graphics={pixels,ECHO_WINDOW_WIDTH,ECHO_WINDOW_HEIGHT,
|
||||
ECHO_WINDOW_WIDTH*ECHO_WINDOW_HEIGHT};
|
||||
BOB64_EVENT event;
|
||||
u32 screen_width,screen_height;
|
||||
u64 window;
|
||||
s64 result=-1;
|
||||
build_lines(startup);
|
||||
if(bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<ECHO_WINDOW_WIDTH||screen_height<ECHO_WINDOW_HEIGHT)return -2;
|
||||
window=bob64_app_window_create((s32)(screen_width-ECHO_WINDOW_WIDTH)/2,
|
||||
(s32)(screen_height-ECHO_WINDOW_HEIGHT)/2,
|
||||
ECHO_WINDOW_WIDTH,ECHO_WINDOW_HEIGHT);
|
||||
if(!window||(s64)window<0)return -3;
|
||||
if(bob64_app_window_focus(window)) {result=-4;goto cleanup;}
|
||||
if(bob64_app_write("bob!",4)!=4) {result=-5;goto cleanup;}
|
||||
for(;;) {
|
||||
reveal_scroll();
|
||||
if(draw_window(&graphics)) {result=-6;break;}
|
||||
result=bob64_app_window_present(window,pixels,ECHO_WINDOW_WIDTH,
|
||||
ECHO_WINDOW_HEIGHT);
|
||||
if(result!=(s64)(ECHO_WINDOW_WIDTH*ECHO_WINDOW_HEIGHT))break;
|
||||
if(bob64_app_wait_event(&event)) {result=-7;break;}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN) {
|
||||
if(event.Character==0x1b||event.Character=='x'||event.Character=='X') {
|
||||
result=0;break;
|
||||
}
|
||||
if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x48)&&scroll_offset)
|
||||
scroll_offset--;
|
||||
else if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x50))scroll_offset++;
|
||||
else if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x49))
|
||||
scroll_offset=scroll_offset>ECHO_VISIBLE_LINES?
|
||||
scroll_offset-ECHO_VISIBLE_LINES:0;
|
||||
else if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x51))
|
||||
scroll_offset+=ECHO_VISIBLE_LINES;
|
||||
else if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x47))scroll_offset=0;
|
||||
else if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x4f))
|
||||
scroll_offset=line_count;
|
||||
} else if(event.Type==BOB64_EVENT_MOUSE_WHEEL) {
|
||||
if(event.Wheel>0&&scroll_offset)scroll_offset--;
|
||||
else if(event.Wheel<0)scroll_offset++;
|
||||
} else if(event.Type==BOB64_EVENT_MOUSE_MOVE||
|
||||
event.Type==BOB64_EVENT_MOUSE_BUTTON) {
|
||||
if(bob64_button_event(&close_button,&close_state,&event)) {
|
||||
result=0;break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cleanup:
|
||||
if(bob64_app_window_destroy(window)&&result==0)result=-8;
|
||||
return result;
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
(startup->ArgumentCount&&!startup->Arguments))return -1;
|
||||
if(startup->ArgumentCount>1&&text_equals(startup->Arguments[1],"gui"))
|
||||
return run_gui(startup);
|
||||
for(u64 i=1;i<startup->ArgumentCount;i++) {
|
||||
const char *argument=startup->Arguments[i];
|
||||
if(i>1&&bob64_app_write_char(' ')<0)return -2;
|
||||
|
||||
+43
-6
@@ -47,12 +47,17 @@ static const BOB64_RECT delete_cancel_button={120,82,88,18};
|
||||
static const BOB64_RECT help_close_button={156,132,68,18};
|
||||
static const BOB64_RECT applications_run_button={8,38,68,16};
|
||||
static const BOB64_RECT applications_close_button={82,38,64,16};
|
||||
static const BOB64_RECT file_menu_rect={8,70,140,72};
|
||||
static const char *const file_menu_items[]={
|
||||
"OPEN SELECTED","RUN APP","DELETE FILE","CLOSE MENU"
|
||||
};
|
||||
static BOB64_BUTTON_STATE file_run_state,file_apps_state;
|
||||
static BOB64_BUTTON_STATE file_delete_state;
|
||||
static BOB64_BUTTON_STATE file_help_state;
|
||||
static BOB64_BUTTON_STATE applications_run_state,applications_close_state;
|
||||
static BOB64_BUTTON_STATE delete_yes_state,delete_cancel_state;
|
||||
static BOB64_BUTTON_STATE help_close_state;
|
||||
static BOB64_MENU_STATE file_menu_state={0,-1,0};
|
||||
static BOB64_TEXT_FIELD filename_field;
|
||||
static u32 file_count,selected_file,file_scroll;
|
||||
static u32 selected_application,application_scroll;
|
||||
@@ -608,13 +613,13 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
u32 list_bottom=window->Height>156?window->Height-156:70;
|
||||
u32 rows=list_bottom>70?(list_bottom-70)/14:0;
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+31,
|
||||
"UP DOWN / WHEEL MOVE",0x009eb3c7u,1);
|
||||
"UP/DN WHEEL MOVE M:MENU",0x009eb3c7u,1);
|
||||
bob64_button_draw(graphics,&file_run_button,"RUN APP",&file_run_state);
|
||||
bob64_button_draw(graphics,&file_apps_button,"APPS",&file_apps_state);
|
||||
bob64_button_draw(graphics,&file_delete_button,"DELETE",&file_delete_state);
|
||||
bob64_button_draw(graphics,&file_help_button,"HELP",&file_help_state);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+52,
|
||||
"O OPEN R REFRESH D DELETE",0x009eb3c7u,1);
|
||||
"ENTER OPEN/RUN O OPEN R REFRESH",0x009eb3c7u,1);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+61,editor_status,
|
||||
0x008fc8ffu,1);
|
||||
bob64_gfx_text(graphics,window->X+10,
|
||||
@@ -633,6 +638,10 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
}
|
||||
if(!file_count)bob64_gfx_text(graphics,window->X+10,window->Y+72,
|
||||
"NO FILES",0x008fc8ffu,1);
|
||||
if(file_menu_state.Open)
|
||||
bob64_menu_draw(graphics,&file_menu_rect,file_menu_items,
|
||||
sizeof(file_menu_items)/sizeof(file_menu_items[0]),18,
|
||||
&file_menu_state);
|
||||
} else if(window->Handle==delete_window) {
|
||||
bob64_gfx_text(graphics,window->X+16,window->Y+40,
|
||||
"DELETE THIS FILE?",0x00ffffffu,1);
|
||||
@@ -646,13 +655,15 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+38,
|
||||
"FILES: ARROWS/WHEEL SELECT",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+54,
|
||||
"O OPENS; A RUNS AN APP",0x00e2ebf5u,1);
|
||||
"ENTER OPENS FILES OR RUNS APPS",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+70,
|
||||
"D OR DELETE ASKS FIRST",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+86,
|
||||
"P OPENS THE APP LAUNCHER",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+102,
|
||||
"CTRL S SAVES; TAB SWITCHES",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+118,
|
||||
"M OPENS FILE ACTION MENU",0x00e2ebf5u,1);
|
||||
bob64_button_draw(graphics,&help_close_button,"CLOSE",
|
||||
&help_close_state);
|
||||
} else if(window->Handle==applications_window) {
|
||||
@@ -850,7 +861,10 @@ static void gui_key(const BOB64_EVENT *event) {
|
||||
gui_copy(editor_status,"WINDOW CLOSE FAILED",sizeof("WINDOW CLOSE FAILED"));
|
||||
}
|
||||
else if(manager.Focused==files_window) {
|
||||
if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) {
|
||||
if(event->Character=='m'||event->Character=='M') {
|
||||
file_menu_state.Open=1;file_menu_state.Selected=0;
|
||||
file_menu_state.Pressed=-1;
|
||||
} else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) {
|
||||
if(selected_file)selected_file--;
|
||||
gui_reveal_selected_file();
|
||||
gui_refresh_file_preview();
|
||||
@@ -864,8 +878,13 @@ static void gui_key(const BOB64_EVENT *event) {
|
||||
gui_refresh_files();editor_open_armed=0;
|
||||
} else if(event->Character=='a'||event->Character=='A') {
|
||||
gui_run_selected_app();editor_open_armed=0;
|
||||
} else if(event->Character=='o'||event->Character=='O'||
|
||||
event->Character=='\n')gui_open_selected_file();
|
||||
} else if(event->Character=='\n') {
|
||||
if(selected_file<file_count&&
|
||||
gui_is_application(file_entries[selected_file].Name))
|
||||
gui_run_selected_app();
|
||||
else gui_open_selected_file();
|
||||
} else if(event->Character=='o'||event->Character=='O')
|
||||
gui_open_selected_file();
|
||||
else if(event->Character=='d'||event->Character=='D')gui_delete_selected_file();
|
||||
else if(event->Character=='h'||event->Character=='H'||
|
||||
event->Character=='?')gui_open_help();
|
||||
@@ -915,6 +934,24 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
for(;;) {
|
||||
if(gui_draw(cursor_x,cursor_y))return -4;
|
||||
if(bob64_app_wait_event(&event))return -5;
|
||||
if(file_menu_state.Open) {
|
||||
BOB64_WINDOW *menu_window=bob64_wm_find(&manager,files_window);
|
||||
BOB64_RECT menu_screen=file_menu_rect;
|
||||
int action;
|
||||
screen_event=event;
|
||||
screen_event.X=event.ScreenX;screen_event.Y=event.ScreenY;
|
||||
if(menu_window) {
|
||||
menu_screen.X+=menu_window->X;
|
||||
menu_screen.Y+=menu_window->Y;
|
||||
}
|
||||
action=bob64_menu_event(&menu_screen,file_menu_items,
|
||||
sizeof(file_menu_items)/sizeof(file_menu_items[0]),18,
|
||||
&file_menu_state,&screen_event);
|
||||
if(action==0)gui_open_selected_file();
|
||||
else if(action==1)gui_run_selected_app();
|
||||
else if(action==2)gui_delete_selected_file();
|
||||
continue;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b&&
|
||||
manager.Focused==delete_window) {
|
||||
gui_finish_delete(0);continue;
|
||||
|
||||
+139
-1
@@ -1,4 +1,22 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
#include "../bob64/window.h"
|
||||
|
||||
#define INFO_GUI_WIDTH 520u
|
||||
#define INFO_GUI_HEIGHT 340u
|
||||
|
||||
static u32 gui_pixels[INFO_GUI_WIDTH*INFO_GUI_HEIGHT];
|
||||
static BOB64_GFX gui_graphics;
|
||||
static BOB64_WINDOW_MANAGER gui_manager;
|
||||
static BOB64_WINDOW gui_window;
|
||||
static BOB64_WINDOW_HANDLE gui_order[1];
|
||||
static BOB64_RECT gui_close_button={12,34,72,18};
|
||||
static BOB64_BUTTON_STATE gui_close_state;
|
||||
static BOB64_FILE_INFO gui_files[BOB64_SYSCALL_MAX_FILES];
|
||||
static u32 gui_width,gui_height;
|
||||
static s64 gui_display_status,gui_file_count;
|
||||
static u64 gui_total_bytes;
|
||||
|
||||
static void write_text(const char *text) {
|
||||
usize length=0;
|
||||
@@ -6,6 +24,13 @@ static void write_text(const char *text) {
|
||||
(void)bob64_app_write(text,length);
|
||||
}
|
||||
|
||||
static int text_equals(const char *left,const char *right) {
|
||||
usize i=0;
|
||||
if(!left||!right)return 0;
|
||||
while(left[i]&&right[i]&&left[i]==right[i])i++;
|
||||
return !left[i]&&!right[i];
|
||||
}
|
||||
|
||||
static void write_number(u64 value) {
|
||||
char digits[20];
|
||||
usize count=0;
|
||||
@@ -22,15 +47,128 @@ static void write_labeled_number(const char *label,u64 value) {
|
||||
write_text("\n");
|
||||
}
|
||||
|
||||
static void format_number(char *text,u64 value) {
|
||||
char digits[20];
|
||||
usize count=0,offset=0;
|
||||
do {digits[count++]=(char)('0'+value%10);value/=10;}
|
||||
while(value&&count<sizeof(digits));
|
||||
while(count)text[offset++]=digits[--count];
|
||||
text[offset]=0;
|
||||
}
|
||||
|
||||
static int refresh_gui_info(void) {
|
||||
gui_display_status=bob64_app_get_display(&gui_width,&gui_height);
|
||||
gui_file_count=bob64_app_list_files(gui_files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(gui_file_count<0||(u64)gui_file_count>BOB64_SYSCALL_MAX_FILES)return -1;
|
||||
gui_total_bytes=0;
|
||||
for(s64 i=0;i<gui_file_count;i++)gui_total_bytes+=gui_files[i].Size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void draw_labeled_number(const char *label,u64 value,s32 y) {
|
||||
char number[24];
|
||||
format_number(number,value);
|
||||
bob64_gfx_text(&gui_graphics,24,y,label,0x00dbe8f4u,1);
|
||||
bob64_gfx_text(&gui_graphics,256,y,number,0x008fc8ffu,1);
|
||||
}
|
||||
|
||||
static s64 run_gui(void) {
|
||||
BOB64_EVENT event,screen_event,routed;
|
||||
u32 screen_width,screen_height;
|
||||
if(refresh_gui_info())return -3;
|
||||
if(bob64_app_write("bob!",4)!=4)return -4;
|
||||
if(bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<INFO_GUI_WIDTH||screen_height<INFO_GUI_HEIGHT)return -5;
|
||||
if(bob64_wm_init(&gui_manager,&gui_window,1,gui_order,
|
||||
screen_width,screen_height))return -6;
|
||||
BOB64_WINDOW_HANDLE kernel_handle=bob64_app_window_create(
|
||||
(s32)(screen_width-INFO_GUI_WIDTH)/2,
|
||||
(s32)(screen_height-INFO_GUI_HEIGHT)/2,INFO_GUI_WIDTH,INFO_GUI_HEIGHT);
|
||||
if(!kernel_handle||(s64)kernel_handle<0)return -7;
|
||||
gui_manager.NextHandle=kernel_handle;
|
||||
BOB64_WINDOW_HANDLE app_handle=bob64_wm_create(&gui_manager,
|
||||
(s32)(screen_width-INFO_GUI_WIDTH)/2,
|
||||
(s32)(screen_height-INFO_GUI_HEIGHT)/2,INFO_GUI_WIDTH,INFO_GUI_HEIGHT,
|
||||
(void *)"System information");
|
||||
if(app_handle!=kernel_handle) {
|
||||
if(app_handle)bob64_wm_destroy(&gui_manager,app_handle);
|
||||
bob64_app_window_destroy(kernel_handle);return -8;
|
||||
}
|
||||
gui_graphics.Pixels=gui_pixels;gui_graphics.Width=INFO_GUI_WIDTH;
|
||||
gui_graphics.Height=INFO_GUI_HEIGHT;
|
||||
gui_graphics.Capacity=INFO_GUI_WIDTH*INFO_GUI_HEIGHT;
|
||||
for(;;) {
|
||||
bob64_gfx_fill_rect(&gui_graphics,0,0,INFO_GUI_WIDTH,INFO_GUI_HEIGHT,
|
||||
0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(&gui_graphics,0,0,INFO_GUI_WIDTH,
|
||||
BOB64_WINDOW_TITLE_BAR_HEIGHT,0x00335d8cu);
|
||||
bob64_gfx_text(&gui_graphics,12,8,"BOB64 SYSTEM INFORMATION",
|
||||
0x00ffffffu,1);
|
||||
bob64_button_draw(&gui_graphics,&gui_close_button,"CLOSE",
|
||||
&gui_close_state);
|
||||
bob64_gfx_text(&gui_graphics,112,39,"R REFRESH",0x009eb3c7u,1);
|
||||
draw_labeled_number("System call ABI",BOB64_SYSCALL_ABI_VERSION,76);
|
||||
if(gui_display_status)bob64_gfx_text(&gui_graphics,24,104,
|
||||
"Display unavailable",0x00dbe8f4u,1);
|
||||
else {
|
||||
char resolution[24],height_text[16];
|
||||
format_number(resolution,gui_width);
|
||||
format_number(height_text,gui_height);
|
||||
bob64_gfx_text(&gui_graphics,24,104,"Display",0x00dbe8f4u,1);
|
||||
bob64_gfx_text(&gui_graphics,256,104,resolution,
|
||||
0x008fc8ffu,1);
|
||||
bob64_gfx_text(&gui_graphics,292,104,"x",0x00dbe8f4u,1);
|
||||
bob64_gfx_text(&gui_graphics,310,104,height_text,
|
||||
0x008fc8ffu,1);
|
||||
}
|
||||
draw_labeled_number("Uptime (seconds)",bob64_app_ticks()/100,132);
|
||||
draw_labeled_number("RAM files",(u64)gui_file_count,160);
|
||||
draw_labeled_number("RAM file data (bytes)",gui_total_bytes,188);
|
||||
bob64_gfx_text(&gui_graphics,24,236,"ESCAPE OR CLOSE RETURNS",
|
||||
0x009eb3c7u,1);
|
||||
if(bob64_app_window_present(gui_window.Handle,gui_graphics.Pixels,
|
||||
gui_graphics.Width,gui_graphics.Height)!=
|
||||
(s64)(INFO_GUI_WIDTH*INFO_GUI_HEIGHT))return -9;
|
||||
if(bob64_app_wait_event(&event))return -10;
|
||||
screen_event=event;screen_event.X=event.ScreenX;
|
||||
screen_event.Y=event.ScreenY;
|
||||
s64 target=bob64_wm_dispatch(&gui_manager,&screen_event,&routed);
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character==0x1b||event.Character=='x'||event.Character=='X'))
|
||||
break;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character=='r'||event.Character=='R'))refresh_gui_info();
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE) {
|
||||
BOB64_EVENT local=event;local.X=event.ScreenX-gui_window.X;
|
||||
local.Y=event.ScreenY-gui_window.Y;
|
||||
bob64_button_event(&gui_close_button,&gui_close_state,&local);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
target==(s64)gui_window.Handle) {
|
||||
BOB64_EVENT local=event;local.X=routed.X;local.Y=routed.Y;
|
||||
int clicked=bob64_button_event(&gui_close_button,
|
||||
&gui_close_state,&local);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&clicked)break;
|
||||
}
|
||||
}
|
||||
bob64_app_window_destroy(gui_window.Handle);
|
||||
bob64_wm_destroy(&gui_manager,gui_window.Handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_FILE_INFO files[BOB64_SYSCALL_MAX_FILES];
|
||||
u32 width=0,height=0;
|
||||
s64 file_count,display_status;
|
||||
u64 total_bytes=0;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||startup->ArgumentCount!=0)
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
startup->ArgumentCount>2||
|
||||
(startup->ArgumentCount&&!startup->Arguments))
|
||||
return -1;
|
||||
if(bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -2;
|
||||
if(startup->ArgumentCount==2&&startup->Arguments&&
|
||||
text_equals(startup->Arguments[1],"gui"))return run_gui();
|
||||
display_status=bob64_app_get_display(&width,&height);
|
||||
file_count=bob64_app_list_files(files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(file_count<0||(u64)file_count>BOB64_SYSCALL_MAX_FILES)return -4;
|
||||
|
||||
+248
@@ -1,4 +1,32 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
#include "../bob64/window.h"
|
||||
|
||||
#define LS_GUI_WIDTH 480u
|
||||
#define LS_GUI_HEIGHT 380u
|
||||
#define LS_GUI_ROWS 15u
|
||||
|
||||
static u32 gui_pixels[LS_GUI_WIDTH*LS_GUI_HEIGHT];
|
||||
static BOB64_GFX gui_graphics;
|
||||
static BOB64_WINDOW_MANAGER gui_manager;
|
||||
static BOB64_WINDOW gui_window;
|
||||
static BOB64_WINDOW_HANDLE gui_order[1];
|
||||
static BOB64_FILE_INFO gui_files[BOB64_SYSCALL_MAX_FILES];
|
||||
static u32 gui_file_count,gui_selected,gui_scroll;
|
||||
static BOB64_RECT gui_close_button={12,36,72,18};
|
||||
static BOB64_RECT gui_open_button={92,36,72,18};
|
||||
static BOB64_BUTTON_STATE gui_close_state;
|
||||
static BOB64_BUTTON_STATE gui_open_state;
|
||||
static char gui_status[32];
|
||||
static u32 gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
static u64 gui_last_click_tick;
|
||||
|
||||
static usize text_length(const char *text) {
|
||||
usize length=0;
|
||||
if(text)while(text[length])length++;
|
||||
return length;
|
||||
}
|
||||
|
||||
static void write_text(const char *text) {
|
||||
usize length=0;
|
||||
@@ -16,11 +44,231 @@ static void write_size(u64 value) {
|
||||
while(count)bob64_app_write_char((u8)digits[--count]);
|
||||
}
|
||||
|
||||
static void format_size(char *buffer,u64 value) {
|
||||
char digits[20];
|
||||
usize count=0;
|
||||
do {digits[count++]=(char)('0'+value%10);value/=10;}
|
||||
while(value&&count<sizeof(digits));
|
||||
usize offset=0;
|
||||
while(count)buffer[offset++]=digits[--count];
|
||||
buffer[offset]=0;
|
||||
}
|
||||
|
||||
static void set_status(const char *text) {
|
||||
usize i=0;
|
||||
while(i+1<sizeof(gui_status)&&text[i]){gui_status[i]=text[i];i++;}
|
||||
gui_status[i]=0;
|
||||
}
|
||||
|
||||
static int executable_name(const char *name) {
|
||||
usize size=text_length(name);
|
||||
return size>5&&name[size-5]=='.'&&name[size-4]=='b'&&
|
||||
name[size-3]=='6'&&name[size-2]=='4'&&name[size-1]=='e';
|
||||
}
|
||||
|
||||
static void reveal_selection(void) {
|
||||
if(gui_selected<gui_scroll)gui_scroll=gui_selected;
|
||||
else if(gui_selected>=gui_scroll+LS_GUI_ROWS)
|
||||
gui_scroll=gui_selected-LS_GUI_ROWS+1;
|
||||
}
|
||||
|
||||
static void open_selected(void) {
|
||||
if(gui_selected>=gui_file_count) {
|
||||
set_status("NO FILE SELECTED");return;
|
||||
}
|
||||
const char *selected=gui_files[gui_selected].Name;
|
||||
const char *app_name=selected;
|
||||
const char *arguments[3];
|
||||
usize argument_count=1,app_name_length=text_length(selected);
|
||||
s64 child_status=-1;
|
||||
if(executable_name(selected))arguments[0]=selected;
|
||||
else {
|
||||
app_name="cat.b64e";app_name_length=8;
|
||||
arguments[0]=app_name;arguments[1]="gui";arguments[2]=selected;
|
||||
argument_count=3;
|
||||
}
|
||||
s64 result=bob64_app_run(app_name,app_name_length,argument_count,
|
||||
arguments,&child_status);
|
||||
if(result||child_status)set_status("APP FAILED");
|
||||
else set_status("OPENED");
|
||||
s64 count=bob64_app_list_files(gui_files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(count>=0)gui_file_count=(u32)count;
|
||||
if(gui_selected>=gui_file_count)
|
||||
gui_selected=gui_file_count?gui_file_count-1:0;
|
||||
reveal_selection();
|
||||
}
|
||||
|
||||
static int gui_run(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_EVENT event,screen_event,routed;
|
||||
s64 target;
|
||||
u32 screen_width,screen_height;
|
||||
s64 result=bob64_app_get_display(&screen_width,&screen_height);
|
||||
if(result||screen_width<LS_GUI_WIDTH||screen_height<LS_GUI_HEIGHT)return -2;
|
||||
if(bob64_wm_init(&gui_manager,&gui_window,1,gui_order,
|
||||
screen_width,screen_height))return -3;
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;gui_last_click_tick=0;
|
||||
BOB64_WINDOW_HANDLE kernel_handle=bob64_app_window_create(
|
||||
(s32)(screen_width-LS_GUI_WIDTH)/2,
|
||||
(s32)(screen_height-LS_GUI_HEIGHT)/2,LS_GUI_WIDTH,LS_GUI_HEIGHT);
|
||||
if(!kernel_handle||(s64)kernel_handle<0)return -4;
|
||||
gui_manager.NextHandle=kernel_handle;
|
||||
BOB64_WINDOW_HANDLE app_handle=bob64_wm_create(&gui_manager,
|
||||
(s32)(screen_width-LS_GUI_WIDTH)/2,
|
||||
(s32)(screen_height-LS_GUI_HEIGHT)/2,LS_GUI_WIDTH,LS_GUI_HEIGHT,
|
||||
(void *)"Files");
|
||||
if(app_handle!=kernel_handle) {
|
||||
if(app_handle)bob64_wm_destroy(&gui_manager,app_handle);
|
||||
bob64_app_window_destroy(kernel_handle);return -5;
|
||||
}
|
||||
gui_graphics.Pixels=gui_pixels;gui_graphics.Width=LS_GUI_WIDTH;
|
||||
gui_graphics.Height=LS_GUI_HEIGHT;
|
||||
gui_graphics.Capacity=LS_GUI_WIDTH*LS_GUI_HEIGHT;
|
||||
s64 count=bob64_app_list_files(gui_files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(count<0) {
|
||||
set_status("LIST FAILED");
|
||||
gui_file_count=0;
|
||||
} else {
|
||||
gui_file_count=(u32)count;
|
||||
set_status("ENTER TO OPEN");
|
||||
}
|
||||
if(startup->ArgumentCount==3&&startup->Arguments[2]) {
|
||||
int found=0;
|
||||
for(u32 i=0;i<gui_file_count;i++) {
|
||||
if(text_length(startup->Arguments[2])==
|
||||
text_length(gui_files[i].Name)) {
|
||||
usize n=0;
|
||||
while(startup->Arguments[2][n]&&
|
||||
startup->Arguments[2][n]==gui_files[i].Name[n])n++;
|
||||
if(!startup->Arguments[2][n]&&!gui_files[i].Name[n]) {
|
||||
gui_selected=i;found=1;break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found)reveal_selection();
|
||||
else set_status("FILE NOT FOUND");
|
||||
}
|
||||
for(;;) {
|
||||
bob64_gfx_fill_rect(&gui_graphics,0,0,LS_GUI_WIDTH,LS_GUI_HEIGHT,
|
||||
0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(&gui_graphics,0,0,LS_GUI_WIDTH,
|
||||
BOB64_WINDOW_TITLE_BAR_HEIGHT,0x00335d8cu);
|
||||
bob64_gfx_text(&gui_graphics,12,8,"BOB64 FILES",0x00ffffffu,1);
|
||||
bob64_gfx_text(&gui_graphics,12,26,"DOUBLE-CLICK OR ENTER/OPEN",
|
||||
0x009eb3c7u,1);
|
||||
bob64_button_draw(&gui_graphics,&gui_close_button,"CLOSE",
|
||||
&gui_close_state);
|
||||
bob64_button_draw(&gui_graphics,&gui_open_button,"OPEN",
|
||||
&gui_open_state);
|
||||
bob64_gfx_text(&gui_graphics,180,42,gui_status,0x008fc8ffu,1);
|
||||
for(u32 row=0;row<LS_GUI_ROWS;row++) {
|
||||
u32 index=gui_scroll+row;
|
||||
if(index>=gui_file_count)break;
|
||||
s32 y=70+(s32)(row*18);
|
||||
if(index==gui_selected)
|
||||
bob64_gfx_fill_rect(&gui_graphics,8,y-2,464,16,0x00335d8cu);
|
||||
bob64_gfx_text(&gui_graphics,14,y,gui_files[index].Name,
|
||||
index==gui_selected?0x00ffffffu:0x00dbe8f4u,1);
|
||||
char size_text[24];
|
||||
format_size(size_text,gui_files[index].Size);
|
||||
bob64_gfx_text(&gui_graphics,380,y,size_text,0x009eb3c7u,1);
|
||||
bob64_gfx_text(&gui_graphics,434,y,"B",0x009eb3c7u,1);
|
||||
}
|
||||
if(!gui_file_count)bob64_gfx_text(&gui_graphics,14,74,"NO FILES",
|
||||
0x008fc8ffu,1);
|
||||
if(bob64_app_window_present(gui_window.Handle,gui_graphics.Pixels,
|
||||
gui_graphics.Width,gui_graphics.Height)!=
|
||||
(s64)(LS_GUI_WIDTH*LS_GUI_HEIGHT))return -6;
|
||||
if(bob64_app_wait_event(&event))return -7;
|
||||
screen_event=event;screen_event.X=event.ScreenX;
|
||||
screen_event.Y=event.ScreenY;
|
||||
target=bob64_wm_dispatch(&gui_manager,&screen_event,&routed);
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character==0x1b||event.Character=='x'||event.Character=='X'))
|
||||
break;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character=='\n'||event.Character=='o'||event.Character=='O')) {
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
open_selected();
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
event.Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) {
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
if(gui_selected)gui_selected--;
|
||||
if(gui_selected<gui_scroll)gui_scroll=gui_selected;
|
||||
} else if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
event.Key==(BOB64_EVENT_KEY_EXTENDED|0x50)) {
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
if(gui_selected+1<gui_file_count)gui_selected++;
|
||||
if(gui_selected>=gui_scroll+LS_GUI_ROWS)
|
||||
gui_scroll=gui_selected-LS_GUI_ROWS+1;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_WHEEL&&event.Wheel&&
|
||||
target==(s64)gui_window.Handle) {
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
if(event.Wheel>0&&gui_selected)gui_selected--;
|
||||
else if(event.Wheel<0&&gui_selected+1<gui_file_count)gui_selected++;
|
||||
if(gui_selected<gui_scroll)gui_scroll=gui_selected;
|
||||
if(gui_selected>=gui_scroll+LS_GUI_ROWS)
|
||||
gui_scroll=gui_selected-LS_GUI_ROWS+1;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE) {
|
||||
BOB64_EVENT local=event;
|
||||
local.X=event.ScreenX-gui_window.X;
|
||||
local.Y=event.ScreenY-gui_window.Y;
|
||||
bob64_button_event(&gui_close_button,&gui_close_state,&local);
|
||||
bob64_button_event(&gui_open_button,&gui_open_state,&local);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&target==(s64)gui_window.Handle) {
|
||||
BOB64_EVENT local=event;local.X=routed.X;local.Y=routed.Y;
|
||||
int clicked=bob64_button_event(&gui_close_button,
|
||||
&gui_close_state,&local);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&clicked)break;
|
||||
int open=bob64_button_event(&gui_open_button,
|
||||
&gui_open_state,&local);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&open)open_selected();
|
||||
if((event.Buttons&BOB64_BUTTON_LEFT)&&routed.Y>=70) {
|
||||
u32 row=(u32)(routed.Y-70)/18;
|
||||
if(gui_scroll+row<gui_file_count) {
|
||||
gui_selected=gui_scroll+row;
|
||||
if(gui_last_clicked!=gui_scroll+row)
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
}
|
||||
} else if(!(event.Buttons&BOB64_BUTTON_LEFT)&&routed.Y>=70) {
|
||||
u32 row=(u32)(routed.Y-70)/18;
|
||||
u32 index=gui_scroll+row;
|
||||
if(index<gui_file_count) {
|
||||
u64 now=bob64_app_ticks();
|
||||
if(gui_last_clicked==index&&now-gui_last_click_tick<=50) {
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
open_selected();
|
||||
} else {
|
||||
gui_last_clicked=index;
|
||||
gui_last_click_tick=now;
|
||||
}
|
||||
}
|
||||
} else if(!(event.Buttons&BOB64_BUTTON_LEFT)) {
|
||||
gui_last_clicked=BOB64_SYSCALL_MAX_FILES;
|
||||
}
|
||||
}
|
||||
}
|
||||
bob64_app_window_destroy(gui_window.Handle);
|
||||
bob64_wm_destroy(&gui_manager,gui_window.Handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_FILE_INFO files[BOB64_SYSCALL_MAX_FILES];
|
||||
s64 count;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
if((startup->ArgumentCount==2||startup->ArgumentCount==3)&&
|
||||
startup->Arguments&&
|
||||
startup->Arguments[1]&&text_length(startup->Arguments[1])==3&&
|
||||
startup->Arguments[1][0]=='g'&&startup->Arguments[1][1]=='u'&&
|
||||
startup->Arguments[1][2]=='i') {
|
||||
if(bob64_app_write("bob!",4)!=4)return -8;
|
||||
return gui_run(startup);
|
||||
}
|
||||
count=bob64_app_list_files(files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(count<0) {
|
||||
write_text("cannot list files\n");
|
||||
|
||||
@@ -1,15 +1,94 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
|
||||
/* QEMU injects move, wheel, and button input through the selected mouse. */
|
||||
#define MOUSE_TEST_WIDTH 160u
|
||||
#define MOUSE_TEST_HEIGHT 96u
|
||||
|
||||
static u32 pixels[MOUSE_TEST_WIDTH*MOUSE_TEST_HEIGHT];
|
||||
static const BOB64_RECT mouse_test_button={40,55,80,18};
|
||||
|
||||
/* The QEMU runtime test injects a mouse move through the emulated PS/2 device. */
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_EVENT event;
|
||||
static const char passed[]="bob64 live mouse event passed\n";
|
||||
BOB64_GFX graphics;
|
||||
BOB64_BUTTON_STATE button_state={0};
|
||||
u32 screen_width,screen_height;
|
||||
u64 window;
|
||||
static const char move_passed[]="bob! live mouse move passed\n";
|
||||
static const char wheel_passed[]="bob! live mouse wheel passed\n";
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
if(bob64_app_wait_event(&event))return -2;
|
||||
if(event.Type!=BOB64_EVENT_MOUSE_MOVE||
|
||||
(!event.DeltaX&&!event.DeltaY))
|
||||
return -3;
|
||||
if(bob64_app_write(passed,sizeof(passed)-1)!=(s64)(sizeof(passed)-1))
|
||||
return -4;
|
||||
return 0;
|
||||
if(bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<MOUSE_TEST_WIDTH||screen_height<MOUSE_TEST_HEIGHT)return -2;
|
||||
window=bob64_app_window_create((s32)((screen_width-MOUSE_TEST_WIDTH)/2),
|
||||
(s32)((screen_height-MOUSE_TEST_HEIGHT)/2),MOUSE_TEST_WIDTH,
|
||||
MOUSE_TEST_HEIGHT);
|
||||
if(!window||(s64)window<0)return -3;
|
||||
graphics.Pixels=pixels;graphics.Width=MOUSE_TEST_WIDTH;
|
||||
graphics.Height=MOUSE_TEST_HEIGHT;
|
||||
graphics.Capacity=MOUSE_TEST_WIDTH*MOUSE_TEST_HEIGHT;
|
||||
bob64_gfx_fill_rect(&graphics,0,0,MOUSE_TEST_WIDTH,MOUSE_TEST_HEIGHT,
|
||||
0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(&graphics,0,0,MOUSE_TEST_WIDTH,24,0x00335d8cu);
|
||||
bob64_gfx_text(&graphics,8,8,"bob!",0x00ffffffu,1);
|
||||
bob64_gfx_text(&graphics,8,38,"MOVE AND WHEEL",0x00e2ebf5u,1);
|
||||
if(bob64_button_draw(&graphics,&mouse_test_button,"CLICK",&button_state)) {
|
||||
bob64_app_window_destroy(window);return -12;
|
||||
}
|
||||
if(bob64_app_window_present(window,pixels,MOUSE_TEST_WIDTH,
|
||||
MOUSE_TEST_HEIGHT)!=(s64)(MOUSE_TEST_WIDTH*MOUSE_TEST_HEIGHT)||
|
||||
bob64_app_window_focus(window)<0) {
|
||||
bob64_app_window_destroy(window);return -4;
|
||||
}
|
||||
for(;;) {
|
||||
if(bob64_app_wait_event(&event)) {
|
||||
bob64_app_window_destroy(window);return -5;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE&&
|
||||
(event.DeltaX||event.DeltaY))break;
|
||||
}
|
||||
if(event.WindowHandle!=window||event.X<0||
|
||||
event.X>=(s32)MOUSE_TEST_WIDTH||event.Y<0||
|
||||
event.Y>=(s32)MOUSE_TEST_HEIGHT) {
|
||||
bob64_app_window_destroy(window);return -6;
|
||||
}
|
||||
if(bob64_app_write(move_passed,sizeof(move_passed)-1)!=
|
||||
(s64)(sizeof(move_passed)-1)) {
|
||||
bob64_app_window_destroy(window);return -7;
|
||||
}
|
||||
for(;;) {
|
||||
if(bob64_app_wait_event(&event)) {
|
||||
bob64_app_window_destroy(window);return -8;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_WHEEL&&event.Wheel)break;
|
||||
}
|
||||
if(event.WindowHandle!=window||event.X<0||
|
||||
event.X>=(s32)MOUSE_TEST_WIDTH||event.Y<0||
|
||||
event.Y>=(s32)MOUSE_TEST_HEIGHT) {
|
||||
bob64_app_window_destroy(window);return -9;
|
||||
}
|
||||
if(bob64_app_write(wheel_passed,sizeof(wheel_passed)-1)!=
|
||||
(s64)(sizeof(wheel_passed)-1)) {
|
||||
bob64_app_window_destroy(window);return -10;
|
||||
}
|
||||
for(;;) {
|
||||
int clicked;
|
||||
if(bob64_app_wait_event(&event)) {
|
||||
bob64_app_window_destroy(window);return -13;
|
||||
}
|
||||
if(event.Type!=BOB64_EVENT_MOUSE_BUTTON)continue;
|
||||
if(event.WindowHandle!=window||event.X<0||
|
||||
event.X>=(s32)MOUSE_TEST_WIDTH||event.Y<0||
|
||||
event.Y>=(s32)MOUSE_TEST_HEIGHT) {
|
||||
bob64_app_window_destroy(window);return -14;
|
||||
}
|
||||
clicked=bob64_button_event(&mouse_test_button,&button_state,&event);
|
||||
if(clicked)break;
|
||||
}
|
||||
static const char button_passed[]="bob! live mouse button passed\n";
|
||||
if(bob64_app_write(button_passed,sizeof(button_passed)-1)!=
|
||||
(s64)(sizeof(button_passed)-1)) {
|
||||
bob64_app_window_destroy(window);return -15;
|
||||
}
|
||||
return bob64_app_window_destroy(window)<0?-11:0;
|
||||
}
|
||||
+17
-1
@@ -6,7 +6,8 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
static const char file_name[]="bob-app.txt";
|
||||
static const char stream_name[]="bob-stream.txt";
|
||||
static const char file_data[]="written by a C app";
|
||||
char file_copy[32];
|
||||
static const char string_haystack[]="prefix bob64! suffix";
|
||||
char file_copy[32],string_test[16]="",string_padding[8],formatted[40];
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
if(bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -2;
|
||||
u64 ticks_before=bob64_app_ticks();
|
||||
@@ -29,5 +30,20 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
bob64_memcmp(file_copy,file_data,sizeof(file_data)-1))return -10;
|
||||
if(bob64_app_file_close(handle))return -11;
|
||||
if(bob64_app_ticks()<ticks_before)return -12;
|
||||
if(bob64_strcpy(string_test,"bob")!=string_test||
|
||||
bob64_strncat(string_test,"64!ignored",3)!=string_test||
|
||||
bob64_strcmp(string_test,"bob64!")||
|
||||
bob64_strncmp(string_test,"bob64?",5)||
|
||||
bob64_strchr(string_test,'6')!=string_test+3||
|
||||
bob64_strrchr(string_test,'!')!=string_test+5||
|
||||
bob64_strstr(string_haystack,"bob64!")!=string_haystack+7||
|
||||
bob64_memchr(string_test,'4',sizeof(string_test))!=string_test+4)
|
||||
return -13;
|
||||
if(bob64_strncpy(string_padding,"bob",sizeof(string_padding))!=string_padding||
|
||||
bob64_strnlen(string_padding,sizeof(string_padding))!=3||
|
||||
string_padding[3]!=0||string_padding[7]!=0)return -14;
|
||||
if(bob64_snprintf(formatted,sizeof(formatted),"%s:%+05d:%#llx:%zu",
|
||||
"bob!",-7,(unsigned long long)42,(usize)3)!=17||
|
||||
bob64_strcmp(formatted,"bob!:-0007:0x2a:3"))return -15;
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user