scc examples

git-svn-id: svn://kolibrios.org@719 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
jacekm 2008-02-08 11:42:16 +00:00
parent 1967c25fac
commit 7bcf433fb8
3 changed files with 365 additions and 0 deletions

View File

@ -0,0 +1,67 @@
#asm
use32
org 0x0
db 'MENUET01'
dd 0x01
dd _main
dd I_END
dd 0x100000
dd 0x7fff0
dd 0x0,0x0
include 'INTRINS.ASM'
#endasm
#include "klib.h"
void main()
{int event;
int button_id;
draw_window();
while(1)
{
event=s_get_event();
switch(event)
{
case 1: draw_window(); break;
case 2: get_button(); break;
case 3: button_id=get_button();
if(button_id==1) s_quit();
break;
}
}
}
char text1[50]="THIS IS AN EXAMPLE OF C";
char text2[50]="PROGRAM IN KOLIBRIOS";
char text3[50]="";
char text4[50]="SUCCESS";
int p_text[4];
draw_window()
{int i; /* for index */
int y;y=25;
p_text[0]=&text1[0];
p_text[1]=&text2[0];
p_text[2]=&text3[0];
p_text[3]=&text4[0];
begin_draw();
window(100,100,320,150,0x03ffffff,0x805080d0,0x005080d0);
label(8,8,0x10ddeeff,"Example application");
buttonT(50,35,60,12,0x111111,1, "Click Me!", 0xFFFFFF);
for(i=0;i<4;i++)
label(20,40+(y+=10),0x000000,p_text[i]);
end_draw();
}
#asm
I_END:
#endasm

View File

@ -0,0 +1,140 @@
;
; Small-C Run Time Library for Win NT
;
; Nasm version 17/Nov/98 H T Walheim
; Revised: 20/Nov/98 HTW [Bugs in switch]
;
_CCARGC:
;B+ Ellipses arguments ( ,...)
;cl - argument count
xor eax,eax
movzx eax,cl ; No sign-extension
ret
;E:.
;B+ Compare
__ult:
;B+ ???
cmp eax,ebx
ja true
xor eax,eax
ret
;E:.
__ugt:
;B+ ???
cmp eax,ebx
jb true
xor eax,eax
ret
;E:.
__ule:
;B+ ???
cmp eax,ebx
jae true
xor eax,eax
ret
;E:.
__uge:
;B+ ???
cmp eax,ebx
jbe true
xor eax,eax
ret
;E:.
__eq:
;B+ ???
cmp eax,ebx
je true
xor eax,eax
ret
;E:.
__ne:
;B+ ???
cmp eax,ebx
jne true
xor eax,eax
ret
;E:.
__lt:
;B+ ???
cmp eax,ebx
jg true
xor eax,eax
ret
;E:.
__gt:
;B+ ???
cmp eax,ebx
jl true
xor eax,eax
ret
;E:.
__le:
;B+ ???
cmp eax,ebx
jge true
xor eax,eax
ret
;E:.
__ge:
;B+ ???
cmp eax,ebx
jle true
xor eax,eax
ret
;E:.
;E:.
__lneg:
;B+ Logical Negate of Primary
or eax,eax
jnz false
true:
mov eax,1
ret
false:
xor eax,eax
ret
;E:.
__switch:
;B+ Execute "switch" statement
;eax - switch value
;[esp] - pointer to switch table
; dd addr1,value1
; ...
; dd 0
; [jmp default]
; continuation
;
; Revised: 20/Nov/98 [JECXZ needed]
pop ebx
jmp skip
back:
add ebx,8 ;next case-pair
skip:
mov ecx,[ebx] ;case-label location (adress)
jecxz default
cmp eax,[ebx+4] ;test case-value
jnz back
jmp ecx ;match -- jump to case
default:
add ebx,4
jmp ebx ;jump to default/continuation
;E:.

View File

@ -0,0 +1,158 @@
/********* C library *********/
get_event()
{
#asm
mov eax,10
int 0x40
#endasm
}
get_key()
{
#asm
mov eax,2
int 0x40
and eax,0x0000ff00
shr eax,8
#endasm
}
get_button()
{
#asm
mov eax,17
int 0x40
shr eax,8
#endasm
}
begin_draw()
{
#asm
mov ebx,1
mov eax,12
int 0x40
#endasm
}
end_draw()
{
#asm
mov ebx,2
mov eax,12
int 0x40
#endasm
}
window(x1,y1,w,h,c_area,c_grab,c_fram)
int x1,y1,w,h; /* esp +32 +28 +24 +20 */
int c_area,c_grab,c_fram; /* esp +16 +12 +8 */
{
#asm
; color of frames
mov edi,[esp+8]
; color of grab bar bit 8->color gl
mov esi,[esp+12]
; color of work area bit 8-> color gl
mov edx,[esp+16]
;left / width
mov ebx,[esp+32]
shl ebx,16
mov bx,[esp+24]
;top / height
mov ecx,[esp+28]
shl ecx,16
mov cx,[esp+20]
;execute
mov eax,0
int 0x40
#endasm
}
label(x,y,color,p_string)
int x,y,color; /* esp +20 +16 +12 */
char *p_string; /* esp +8 */
{
#asm
mov ebx,[esp+20]
shl ebx,16
mov bx,[esp+16]
mov ecx,[esp+12]
mov edx,[esp+8]
;find text lenght
xor esi,esi
.next:
cmp byte [edx+esi],0
jz .good
inc esi
jmp .next
.good:
mov eax,4
int 0x40
#endasm
}
// Button + Text
buttonT(x1,y1,w,h,color,id,p_string, str_color)
int x1,y1,w,h; /* esp +28 +24 +20 +16 */
int color,id;
char *p_string;
int str_color;
{
button(x1,y1,w,h,color,id);
label(x1+4,y1+2,str_color,p_string);
}
button(x1,y1,w,h,color,id)
int x1,y1,w,h; /* esp +28 +24 +20 +16 */
int color,id; /* esp +12 +8 */
{
#asm
;left / width
mov ebx,[esp+28]
shl ebx,16
mov bx,[esp+20]
;top / height
mov ecx,[esp+24]
shl ecx,16
mov cx,[esp+16]
mov edx,[esp+8]
mov esi,[esp+12]
mov eax,8
int 0x40
#endasm
}
s_quit()
{
#asm
mov eax,-1
int 0x40
#endasm
}
/*
s_get_event()
s_get_key()
s_get_button()
s_begin_draw()
s_end_draw()
s_draw_window(x1,y1,w,h,c_area,c_grab,c_fram)
s_print_text(x,y,color,p_string)
s_draw_button(x1,y1,w,h,color,id)
s_quit()
*/
/*****************************/