Click here to Skip to main content
15,892,697 members
Articles / Containers / Virtual Machine

An extendable report editor

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
3 Sep 2008CPOL3 min read 41.2K   2K   35  
An extendable report editor. You can simply add your own controls without recompiling the program or writing annoying plug-ins.
<?xml version="1.0" encoding="gb2312"?>
<WorkShop>
<CommonFiles>
<RunTimeLib>
<AllFiles>
<file name="_bootloader.asm">
<![CDATA[
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; _bootloader.asm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if @Version gt 510
	.model FLAT
endif
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
_DATA SEGMENT
__reserved		DD 		20 dup(?)               ;80 bytes reserved
__fltused       dd      9875h                   ; Floating point used flag
__infinity      db      6 dup(0), 0f0h, 07fh    ; Floating point infinity
__nan           db      6 dup(0ffh), 0f8h, 0ffh ; Floating point NaN
_DATA ENDS
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;;the first instruction in first _TEXT segment 
;;must be call __init
_TEXT SEGMENT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_boot_loader proc
	call __init
endless:
	int 0
	jmp endless
	ret 
_boot_loader endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;int exit(int exit_code)
_exit proc
	int 0
	ret
_exit endp

;;int putchar(int ch)
_putchar proc
	int 1
	ret
_putchar endp

;;int set_pixel(int x,int y,COLORREG c)
_set_pixel proc
	int 2
	ret
_set_pixel endp

;;int set_bk_color(COLORREF c)
_set_bk_color proc
	int 3
	ret
_set_bk_color endp

;;int arc(int nLeftRect,int nTopRect,int nRightRect,int nBottomRect,
;;				int nXRadial1,int nYRadial1,int nXRadial2,int nYRadial2)
_arc proc
	int 4
	ret
_arc endp

;;int line(int l,int t,int r,int b)
_line proc
	int 6
	ret
_line endp

;;int get_rect(int i,int *l,int *t,int *r,int *b)
_get_rect proc
	mov ebp,esp
	int 7
	pop eax
	mov ebx, dword ptr [ebp + 20]
	mov dword ptr [ebx],eax
	pop eax
	mov ebx, dword ptr [ebp + 16]
	mov dword ptr [ebx],eax	
	pop eax
	mov ebx, dword ptr [ebp + 12]
	mov dword ptr [ebx],eax	
	pop eax
	mov ebx, dword ptr [ebp + 8]
	mov dword ptr [ebx],eax		
	ret
_get_rect endp

;;int set_pen(int style,int width,COLORREF color)
_set_pen proc
	int 8
	ret
_set_pen endp

;;int set_rect(int i,int l,int t,int r,int b)
_set_rect proc
	int 9
	ret
_set_rect endp

;;int set_brush(int style,COLORREF color,int hatch)
_set_brush proc
	int 10
	ret
_set_brush endp

;;int fill_rect(int l,int t,int w,int h)
_fill_rect proc
	int 12
	ret
_fill_rect endp

;;int draw_text(char *str,int size,RECT *rect,DWORD format)
_draw_text proc
	int 13
	ret
_draw_text endp

;;int set_stock_font(int stock_font)
_set_stock_font proc
	int 14
	ret
_set_stock_font endp
;;int ellipse(int l,int t,int w,int h)
_ellipse proc
	int 15
	ret
_ellipse endp

;;int get_name(int i,char *buf,int max)
_get_name proc
	int 16
	ret
_get_name endp

;;int get_self_num()
_get_self_num proc
	int 17
	pop eax  ;;the return number
	ret
_get_self_num endp

;;int get_cookie_size(int i)
_get_cookie_size proc
	int 18
	pop eax
_get_cookie_size endp

;;int set_cookie_size(int i,int size)
_set_cookie_size proc
	int 19
	ret
_set_cookie_size endp

;;int get_cookie_offset(int i)
_get_cookie_offset proc
	int 20
	pop eax
	ret
_get_cookie_offset endp

;;int set_cookie_offset(int i,int off)
_set_cookie_offset proc
	int 21
	ret
_set_cookie_offset endp

;;int read_cookie(int i,void *buf,int rsize)
_read_cookie proc
	int 22
	pop eax
_read_cookie endp

;;int write_cookie(int i,void *buf,int wsize)
_write_cookie proc
	int 23
	pop eax
_write_cookie endp

;;int set_text_color(COLORREF color)
_set_text_color proc
	int 24
	ret
_set_text_color endp

;;int set_bk_mode(int mode)
_set_bk_mode proc
	int 25
	ret
_set_bk_mode endp

;;int set_font(LOGFONT *lf)
_set_font proc
	int 26
_set_font endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_TEXT ENDS
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
_DATA SEGMENT
fzero           DQ   0	            ;Floating point zero
_DATA ENDS
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
_TEXT SEGMENT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__purecall proc
	ret								;;nothing
__purecall endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__allmul proc 
	mov         eax,dword ptr [esp+8]
	mov         ecx,dword ptr [esp+10h]
	or          ecx,eax
	mov         ecx,dword ptr [esp+0Ch]
	jne         hard
	mov         eax,dword ptr [esp+4]
	mul         eax,ecx
	ret         10h
hard:
	push        ebx
	mul         eax,ecx
	mov         ebx,eax
	mov         eax,dword ptr [esp+8]
	mul         eax,dword ptr [esp+14h]
	add         ebx,eax
	mov         eax,dword ptr [esp+8]
	mul         eax,ecx
	add         edx,ebx
	pop         ebx
	ret         10h
__allmul endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__ftol proc
	push        ebp
	mov         ebp,esp
	add         esp,0F4h
	wait
	fnstcw      word ptr [ebp-2]
	wait
	mov         ax,word ptr [ebp-2]
	or          ah,0Ch
	mov         word ptr [ebp-4],ax
	fldcw       word ptr [ebp-4]
	fistp       qword ptr [ebp-0Ch]
	fldcw       word ptr [ebp-2]
	mov         eax,dword ptr [ebp-0Ch]
	mov         edx,dword ptr [ebp-8]
	leave
	ret			0
__ftol endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__chkstk proc
	push        ecx
	cmp         eax,1000h
	lea         ecx,[esp+8]
	jb          lastpage 
probepages:
	sub         ecx,1000h
	sub         eax,1000h
	test        dword ptr [ecx],eax
	cmp         eax,1000h
	jae         probepages
lastpage:
	sub         ecx,eax
	mov         eax,esp
	test        dword ptr [ecx],eax
	mov         esp,ecx
	mov         ecx,dword ptr [eax]
	mov         eax,dword ptr [eax+4]
	push        eax
	ret
_chkstk endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_atexit proc
	ret
_atexit endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CIasin proc
    fld     st(0)                   ; Load x
    fld     st(0)                   ; Load x
    fmul                            ; Multiply (x squared)
    fld1                            ; Load 1
    fsubr                           ; 1 - (x squared)
    fsqrt                           ; Square root of (1 - x squared)
    fpatan                          ; This gives the arc sine !
    ret
__CIasin endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CIacos proc
    fld     st(0)                   ; Load x
    fld     st(0)                   ; Load x
    fmul                            ; Multiply (x squared)
    fld1                            ; Load 1
    fsubr                           ; 1 - (x squared)
    fsqrt                           ; Square root of (1 - x squared)
    fxch                            ; Exchange st, st(1)
    fpatan                          ; This gives the arc cosine !
    ret
__CIacos endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_pow proc    
    push    ebp
    mov     ebp,esp
    sub     esp,12                  ; Allocate temporary space
    push    edi                     ; Save register edi
    push    eax                     ; Save register eax
    mov     dword ptr [ebp-12],0    ; Set negation flag to zero
    fld     qword ptr [ebp+16]      ; Load real from stack
    fld     qword ptr [ebp+8]       ; Load real from stack
    mov     edi,offset flat:fzero   ; Point to real zero
    fcom    qword ptr [edi]         ; Compare x with zero
    fstsw   ax                      ; Get the FPU status word
    mov     al,ah                   ; Move condition flags to AL
    lahf                            ; Load Flags into AH
    and     al,    69               ; Isolate  C0, C2 and C3
    and     ah,    186              ; Turn off CF, PF and ZF
    or      ah,al                   ; Set new  CF, PF and ZF
    sahf                            ; Store AH into Flags
    jb      __fpow1                 ; Re-direct if x < 0
    ja      __fpow3                 ; Re-direct if x > 0
    fxch                            ; Swap st, st(1)
    fcom    qword ptr [edi]         ; Compare y with zero
    fxch                            ; Restore x as top of stack
    fstsw   ax                      ; Get the FPU status word
    mov     al,ah                   ; Move condition flags to AL
    lahf                            ; Load Flags into AH
    and     al,69                   ; Isolate  C0, C2 and C3
    and     ah,186                  ; Turn off CF, PF and ZF
    or      ah,al                   ; Set new  CF, PF and ZF
    sahf                            ; Store AH into Flags
    ja      __fpow3                 ; Re-direct if y > 0
    fstp    st(1)                   ; Set new stack top and pop
    mov     eax,1                   ; Set domain error (EDOM)
    jmp     __fpow6                 ; End of case
__fpow1:        
	fxch                            ; Put y on top of stack
    fld    st(0)                    ; Duplicate y as st(1)
    frndint                         ; Round to integer
    fxch                            ; Put y on top of stack
    fcomp                           ; y = int(y) ?
    fstsw   ax                      ; Get the FPU status word
    mov     al,ah                   ; Move condition flags to AL
    lahf                            ; Load Flags into AH
    and     al,    69               ; Isolate  C0, C2 and C3
    and     ah,    186              ; Turn off CF, PF and ZF
    or      ah,al                   ; Set new  CF, PF and ZF
    sahf                            ; Store AH into Flags
    je      __fpow2                 ; Proceed if y = int(y)
    fstp    st(1)                   ; Set new stack top and pop
    fldz                            ; Set result to zero
    fstp    st(1)                   ; Set new stack top and pop
    mov     eax,1                   ; Set domain error (EDOM)
    jmp     __fpow6                 ; End of case
__fpow2:        
	fist    dword ptr [ebp-12]      ; Store y as integer
    and     dword ptr [ebp-12],1    ; Set bit if y is odd
    fxch                            ; Put x on top of stack
    fabs                            ; x = |x|
__fpow3:        
	fldln2                          ; Load log base e of 2
    fxch    st(1)                   ; Exchange st, st(1)
    fyl2x                           ; Compute the natural log(x)
    fmul                            ; Compute y * ln(x)
    fldl2e                          ; Load log base 2(e)
    fmulp   st(1),st(0)             ; Multiply x * log base 2(e)
    fst     st(1)                   ; Push result
    frndint                         ; Round to integer
    fsub    st(1),st(0)             ; Subtract
    fxch                            ; Exchange st, st(1)
    f2xm1                           ; Compute 2 to the (x - 1)
    fld1                            ; Load real number 1
    fadd                            ; 2 to the x
    fscale                          ; Scale by power of 2
    fstp    st(1)                   ; Set new stack top and pop
    test    dword ptr [ebp-12],1    ; Negation required ?
    je      __fpow4                 ; No, re-direct
    fchs                            ; Negate the result
__fpow4:       
	fstp    qword ptr [ebp-8]       ; Save (double)pow(x, y)
    fld     qword ptr [ebp-8]       ; Load (double)pow(x, y)
    fxam                            ; Examine st
    fstsw   ax                      ; Get the FPU status word
    cmp     ah,5                    ; Infinity ?
    jne     __fpow6                 ; No, end of case
    mov     eax,2                   ; Set range error (ERANGE)
__fpow6:        
	pop     eax                     ; Restore register eax
    pop     edi                     ; Restore register edi
    mov     esp,ebp                 ; Deallocate temporary space
    pop     ebp
    ret
_pow            endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CIpow proc
    sub     esp,16                  ; Allocate stack space for args
    fstp    qword ptr [esp+8]       ; Copy y onto stack
    fstp    qword ptr [esp]         ; Copy x onto stack
    call    _pow                    ; Call pow
    add     esp,16                  ; Remove args from stack
    ret
__CIpow endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_ceil proc 
    push    ebp
    mov     ebp,esp
    sub     esp,4                   ; Allocate temporary space
    fld     qword ptr [ebp+8]       ; Load real from stack
    fstcw   [ebp-2]                 ; Save control word
    fclex                           ; Clear exceptions
    mov     word ptr [ebp-4],0b63h  ; Rounding control word
    fldcw   [ebp-4]                 ; Set new rounding control
    frndint                         ; Round to integer
    fclex                           ; Clear exceptions
    fldcw   [ebp-2]                 ; Restore control word
    mov     esp,ebp                 ; Deallocate temporary space
    pop     ebp
    ret
_ceil endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_log10 proc
    push    ebp
    mov     ebp,esp
    fld     qword ptr [ebp+8]       ; Load real from stack
    fldlg2                          ; Load log base 10 of 2
    fxch    st(1)                   ; Exchange st, st(1)
    fyl2x                           ; Compute the log base 10(x)
    pop     ebp
    ret
_log10 endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_modf  proc
    push    ebp
    mov     ebp,esp
    push    edi                     ; Save register edi
    fld     qword ptr [ebp+8]       ; Load real from stack
    mov     edi,dword ptr [ebp+16]  ; Put integer address in edi
    fld     st(0)                   ; Duplicate st
    frndint                         ; Round to integer
    fcom    st(1)                   ; Compare with orignal value
    fstsw   ax                      ; Get the FPU status word
    test    byte ptr [ebp+15],080h  ; Test if number is negative
    je      __fmodf1                ; Re-direct if positive
    sahf                            ; Store AH to flags
    jae     __fmodf2                ; Re-direct if greater or equal
    fld1                            ; Load the constant 1
    fadd                            ; Increment integer part
    jmp     __fmodf2                ; End of case
__fmodf1:
    sahf                            ; Store AH to flags
    jbe     __fmodf2                ; Re-direct if less or equal
    fld1                            ; Load constant 1
    fsub                            ; Decrement integer part
__fmodf2:       
    fst     qword ptr [edi]         ; Store integer part
    fsub                            ; Subtract to get fraction
    pop     edi                     ; Restore register edi
    mov     esp,ebp                 ; Restore stack pointer
    pop     ebp
    ret
_modf endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CIfmod proc
    fxch    st(1)                   ; Swap arguments
__CIfmod1:   
    fprem                           ; Get the partial remainder
    fstsw   ax                      ; Get coprocessor status
    test    ax,0400h                ; Complete remainder ?
    jnz     __CIfmod1               ; No, go get next remainder
    fstp    st(1)                   ; Set new top of stack
    ret
__CIfmod endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_ceil proc
    push    ebp
    mov     ebp,esp
    sub     esp,4                   ; Allocate temporary space
    fld     qword ptr [ebp+8]       ; Load real from stack
    fstcw   [ebp-2]                 ; Save control word
    fclex                           ; Clear exceptions
    mov     word ptr [ebp-4],0b63h  ; Rounding control word
    fldcw   [ebp-4]                 ; Set new rounding control
    frndint                         ; Round to integer
    fclex                           ; Clear exceptions
    fldcw   [ebp-2]                 ; Restore control word
    mov     esp,ebp                 ; Deallocate temporary space
    pop     ebp
    ret
_ceil endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_floor proc
    push    ebp
    mov     ebp,esp
    sub     esp,4                   ; Allocate temporary space
    fld     qword ptr [ebp+8]       ; Load real from stack
    fstcw   [ebp-2]                 ; Save control word
    fclex                           ; Clear exceptions
    mov     word ptr [ebp-4],0763h  ; Rounding control word
    fldcw   [ebp-4]                 ; Set new rounding control
    frndint                         ; Round to integer
    fclex                           ; Clear exceptions
    fldcw   [ebp-2]                 ; Restore control word
    mov     esp,ebp
    pop     ebp
    ret
_floor endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_tanh proc
    push    ebp
    mov     ebp,esp
    fld     qword ptr [ebp+8]       ; Load real from stack
    fld     st(0)                   ; Duplicate stack top
    fadd                            ; Compute 2 * x
    fldl2e                          ; Load log base 2(e)
    fmulp   st(1),st(0)             ; Multiply x * log base 2(e)
    fst     st(1)                   ; Push result
    frndint                         ; Round to integer
    fsub    st(1),st(0)             ; Subtract
    fxch                            ; Exchange st, st(1)
    f2xm1                           ; Compute 2 to the (x - 1)
    fld1                            ; Load real number 1
    fadd                            ; 2 to the x
    fscale                          ; Scale by power of 2
    fstp    st(1)                   ; Set new stack top and pop
    fld1                            ; Load constant 1
    fadd                            ; Compute exp(2*x)+1
    fld1                            ; Load the constant 1
    fld1                            ; Load the constant 1
    fadd                            ; Set divisor to 2
    fdivr                           ; Compute 2/(exp(2*x)+1)
    fld1                            ; Load constant 1
    fsubr                           ; Compute the hyperbolic tangent
    pop     ebp                     ; Restore register bp
    ret
_tanh endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CItanh proc
    sub     esp,8                   ; Allocate stack space for x
    fstp    qword ptr [esp]         ; Copy x onto stack
    call    _tanh                   ; Call tanh
    add     esp,8                   ; Remove x from stack
    ret
__CItanh endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_sinh proc
    push    ebp
    mov     ebp,esp
    sub     esp,8                   ; Allocate temporary space
    fld     qword ptr [ebp+8]       ; Load real from stack
    fchs                            ; Set x = -x
    fldl2e                          ; Load log base 2(e)
    fmulp   st(1),st(0)             ; Multiply x * log base 2(e)
    fst     st(1)                   ; Push result
    frndint                         ; Round to integer
    fsub    st(1),st(0)             ; Subtract
    fxch                            ; Exchange st, st(1)
    f2xm1                           ; Compute 2 to the (x - 1)
    fld1                            ; Load real number 1
    fadd                            ; 2 to the x
    fscale                          ; Scale by power of 2
    fstp    st(1)                   ; Set new stack top and pop
    fstp    qword ptr [ebp-8]       ; Save exp(-x)
    fld     qword ptr [ebp+8]       ; Load real from stack
    fldl2e                          ; Load log base 2(e)
    fmulp   st(1),st(0)             ; Multiply x * log base 2(e)
    fst     st(1)                   ; Push result
    frndint                         ; Round to integer
    fsub    st(1),st(0)             ; Subtract
    fxch                            ; Exchange st, st(1)
    f2xm1                           ; Compute 2 to the (x - 1)
    fld1                            ; Load real number 1
    fadd                            ; 2 to the x
    fscale                          ; Compute exp(-x)
    fstp    st(1)                   ; Set new stack top and pop
    fld     qword ptr [ebp-8]       ; Get exp(x)
    fsub                            ; Compute exp(x) - exp(-x)
    fld1                            ; Load the constant 1
    fld1                            ; Load the constant 1
    fadd                            ; Set divisor to 2
    fdiv                            ; Compute the hyperbolic sine
    mov     esp,ebp                 ; Deallocate temporary space
    pop     ebp
    ret
_sinh endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CIsinh proc
    sub     esp,8                   ; Allocate stack space for x
    fstp    qword ptr [esp]         ; Copy x onto stack
    call    _sinh                   ; Call sinh
    add     esp,8                   ; Remove x from stack
    ret
__CIsinh endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_atan2 proc
    push    ebp
    mov     ebp,esp
    fld     qword ptr [ebp+8]       ; Load real from stack
    fld     qword ptr [ebp+16]      ; Load real from stack
    fpatan                          ; Take the arctangent
    mov     esp,ebp
    pop     ebp
    ret
_atan2 endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_cosh proc
    push    ebp
    mov     ebp,esp
    sub     esp,8                   ; Allocate temporary space
    fld     qword ptr [ebp+8]       ; Load real from stack
    fchs                            ; Set x = -x
    fldl2e                          ; Load log base 2(e)
    fmulp   st(1),st(0)             ; Multiply x * log base 2(e)
    fst     st(1)                   ; Push result
    frndint                         ; Round to integer
    fsub    st(1),st(0)             ; Subtract
    fxch                            ; Exchange st, st(1)
    f2xm1                           ; Compute 2 to the (x - 1)
    fld1                            ; Load real number 1
    fadd                            ; 2 to the x
    fscale                          ; Scale by power of 2
    fstp    st(1)                   ; Set new stack top and pop
    fstp    qword ptr [ebp-8]       ; Save exp(-x)
    fld     qword ptr [ebp+8]       ; Load real from stack
    fldl2e                          ; Load log base 2(e)
    fmulp   st(1),st(0)             ; Multiply x * log base 2(e)
    fst     st(1)                   ; Push result
    frndint                         ; Round to integer
    fsub    st(1),st(0)             ; Subtract
    fxch                            ; Exchange st, st(1)
    f2xm1                           ; Compute 2 to the (x - 1)
    fld1                            ; Load real number 1
    fadd                            ; 2 to the x
    fscale                          ; Compute exp(-x)
    fstp    st(1)                   ; Set new stack top and pop
    fld     qword ptr [ebp-8]       ; Get exp(x)
    fadd                            ; Compute exp(x) + exp(-x)
    fld1                            ; Load the constant 1
    fld1                            ; Load the constant 1
    fadd                            ; Set divisor to 2
    fdiv                            ; Compute the hyperbolic cosine
    mov     esp,ebp                 ; Deallocate temporary space
    pop     ebp
    ret
_cosh endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__CIcosh proc
    sub     esp,8                   ; Allocate stack space for x
    fstp    qword ptr [esp]         ; Copy x onto stack
    call    _cosh                   ; Call cosh
    add     esp,8                   ; Remove x from stack
    ret
__CIcosh endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_frexp proc
    push    ebp
    mov     ebp,esp
    push    edi                     ; Save register edi
    fld     qword ptr [ebp+8]       ; Load real from stack
    mov     edi,dword ptr [ebp+16]  ; Put exponent address in edi
    ftst                            ; Test st for zero
    fstsw   ax                      ; Put test result in ax
    sahf                            ; Set flags based on test
    jnz     __frexp1                ; Re-direct if not zero
    fld     st(0)                   ; Set exponent to zero
    jmp     __frexp2                ; End of case
__frexp1:  
    fxtract                         ; Get exponent and significand
    fld1                            ; Load constant 1
    fld1                            ; Load constant 1
    fadd                            ; Constant 2
    fdiv                            ; Significand / 2
    fxch                            ; Swap st, st(1)
    fld1                            ; Load constant 1
    fadd                            ; Increment exponent
    fistp   dword ptr [edi]         ; Store result exponent and pop
__frexp2:
    pop     edi                     ; Restore register edi
    mov     esp,ebp
    pop     ebp
    ret
_frexp          endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_ldexp proc 
    push    ebp
    mov     ebp,esp
    sub     esp,8                   ; Allocate temporary space
    fild    dword ptr [ebp+16]      ; Load n as integer
    fld     qword ptr [ebp+8]       ; Load real from stack
    fscale                          ; Compute 2 to the n
    fstp    st(1)                   ; Set new top of stack
    fst     qword ptr [ebp-8]       ; Store result
    mov     esp,ebp                 ; Deallocate temporary space
    pop     ebp
    ret
_ldexp endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_TEXT ENDS
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
]]>
</file>
<file name="common.h">
<![CDATA[
#ifndef __COMMON_H
#define __COMMON_H

#include "init.h"
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#include "types.h"
#include "string.h"
#include "ctype.h"

#define _DEBUG_

#define LOG printf

#define PD(p) LOG("%s = %d\n",#p,p)
#define PX(p) LOG("%s = %x\n",#p,p)
#define PS(p) LOG("%s = %s\n",#p,p)
#define PF(p) LOG("%s = %f\n",#p,p)
#define PQ(p) {QWORD *_v_ = (QWORD*)&(p);LOG("%s = ",#p);LOG("%08x%08x\n",*((int*)_v_ + 1),(int)(*_v_));}

#ifdef _DEBUG_
 #define ASSERT(f) if(!(f)){LOG("assertion fail \"%s\" at file=%s line=%d\n",#f,__FILE__,__LINE__);exit(0);}
#else
 #define ASSERT(f) 
#endif

#define NEW(p,obj)  {p = new obj;ASSERT(p);}
#define NEW_ARRAY(p,obj,items) {p = new obj[items];ASSERT(p);}
#define DEL(p) if(p){delete p;p = NULL;}
#define DEL_ARRAY(p) if(p){delete [] p;p = NULL;}
#define MALLOC(p,obj,items) {p = (obj*)malloc(sizeof(obj)*items);ASSERT(p);}
#define FREE(p) if(p){free(p);p = NULL;}
#define REALLOC(p,obj,old_items,items) if(p){p = (obj*)realloc(p,sizeof(obj)*old_items,sizeof(obj)*items);ASSERT(p);}

#define LBUF_SIZE 2048
#define float double

#endif
]]>
</file>
<file name="stdio.h">
<![CDATA[
#ifndef __STDIO_2007_12_11_14_5_49_H
#define __STDIO_2007_12_11_14_5_49_H

#include "stdarg.h"
#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

int putchar(int ch);
int puts(const char *str);
int sprintf(char *buf, const char *fmt, ...);
int printf(const char *fmt, ...);
int vsprintf(char *buf, const char *fmt, va_list args);

#ifdef __cplusplus
} //extern "C"
#endif

#endif
]]>
</file>
<file name="stdio.c">
<![CDATA[
#include "stdio.h"
#include "types.h"
#include "stdarg.h"
#include "string.h"
#include "math.h"

#define ZEROPAD	1		// Pad with zero
#define SIGN	2		// Unsigned/signed long
#define PLUS	4		// Show plus
#define SPACE	8		// Space if plus
#define LEFT	16		// Left justified
#define SPECIAL	32		// 0x
#define LARGE	64		// Use 'ABCDEF' instead of 'abcdef'

#define is_digit(c) ((c) >= '0' && (c) <= '9')

static char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
static char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);

static size_t strnlen(const char *s, size_t count)
{
  const char *sc;
  for (sc = s; *sc != '\0' && count--; ++sc);
  return sc - s;
}

static int skip_atoi(const char **s)
{
  int i = 0;
  while (is_digit(**s)) i = i*10 + *((*s)++) - '0';
  return i;
}

static char *number(char *str, long num, int base, int size, int precision, int type)
{
  char c, sign, tmp[66];
  char *dig = digits;
  int i;

  if (type & LARGE)  dig = upper_digits;
  if (type & LEFT) type &= ~ZEROPAD;
  if (base < 2 || base > 36) return 0;
  
  c = (type & ZEROPAD) ? '0' : ' ';
  sign = 0;
  if (type & SIGN)
  {
    if (num < 0)
    {
      sign = '-';
      num = -num;
      size--;
    }
    else if (type & PLUS)
    {
      sign = '+';
      size--;
    }
    else if (type & SPACE)
    {
      sign = ' ';
      size--;
    }
  }

  if (type & SPECIAL)
  {
    if (base == 16)
      size -= 2;
    else if (base == 8)
      size--;
  }

  i = 0;

  if (num == 0)
    tmp[i++] = '0';
  else
  {
    while (num != 0)
    {
      tmp[i++] = dig[((unsigned long) num) % (unsigned) base];
      num = ((unsigned long) num) / (unsigned) base;
    }
  }

  if (i > precision) precision = i;
  size -= precision;
  if (!(type & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' ';
  if (sign) *str++ = sign;
  
  if (type & SPECIAL)
  {
    if (base == 8)
      *str++ = '0';
    else if (base == 16)
    {
      *str++ = '0';
      *str++ = digits[33];
    }
  }

  if (!(type & LEFT)) while (size-- > 0) *str++ = c;
  while (i < precision--) *str++ = '0';
  while (i-- > 0) *str++ = tmp[i];
  while (size-- > 0) *str++ = ' ';

  return str;
}

static char *eaddr(char *str, unsigned char *addr, int size, int precision, int type)
{
  char tmp[24];
  char *dig = digits;
  int i, len;

  if (type & LARGE)  dig = upper_digits;
  len = 0;
  for (i = 0; i < 6; i++)
  {
    if (i != 0) tmp[len++] = ':';
    tmp[len++] = dig[addr[i] >> 4];
    tmp[len++] = dig[addr[i] & 0x0F];
  }

  if (!(type & LEFT)) while (len < size--) *str++ = ' ';
  for (i = 0; i < len; ++i) *str++ = tmp[i];
  while (len < size--) *str++ = ' ';

  return str;
}

static char *iaddr(char *str, unsigned char *addr, int size, int precision, int type)
{
  char tmp[24];
  int i, n, len;

  len = 0;
  for (i = 0; i < 4; i++)
  {
    if (i != 0) tmp[len++] = '.';
    n = addr[i];
    
    if (n == 0)
      tmp[len++] = digits[0];
    else
    {
      if (n >= 100) 
      {
	tmp[len++] = digits[n / 100];
        n = n % 100;
	tmp[len++] = digits[n / 10];
	n = n % 10;
      }
      else if (n >= 10) 
      {
	tmp[len++] = digits[n / 10];
	n = n % 10;
      }

      tmp[len++] = digits[n];
    }
  }

  if (!(type & LEFT)) while (len < size--) *str++ = ' ';
  for (i = 0; i < len; ++i) *str++ = tmp[i];
  while (len < size--) *str++ = ' ';

  return str;
}
static void cfltcvt(double value, char *buffer, char fmt, int precision)
{
  int decpt, sign, exp, pos;
  char *digits = NULL,*_t;
  char cvtbuf[80];
  int capexp = 0;
  int magnitude;

  if (fmt == 'G' || fmt == 'E')
  {
    capexp = 1;
    fmt += 'a' - 'A';
  }

  if (fmt == 'g')
  {
    digits = ecvtbuf(value, precision, &decpt, &sign, cvtbuf);
    magnitude = decpt - 1;
    if (magnitude < -4  ||  magnitude > precision - 1)
    {
      fmt = 'e';
      precision -= 1;
    }
    else
    {
      fmt = 'f';
      precision -= decpt;
    }
  }

  if (fmt == 'e')
  {
    digits = ecvtbuf(value, precision + 1, &decpt, &sign, cvtbuf);

    if (sign) *buffer++ = '-';
    *buffer++ = *digits;
    if (precision > 0) *buffer++ = '.';
    memcpy(buffer, digits + 1, precision);
    buffer += precision;
    *buffer++ = capexp ? 'E' : 'e';

    if (decpt == 0)
    {
      if (value == 0.0)
	exp = 0;
      else
	exp = -1;
    }
    else
      exp = decpt - 1;

    if (exp < 0)
    {
      *buffer++ = '-';
      exp = -exp;
    }
    else
      *buffer++ = '+';

    buffer[2] = (exp % 10) + '0';
    exp = exp / 10;
    buffer[1] = (exp % 10) + '0';
    exp = exp / 10;
    buffer[0] = (exp % 10) + '0';
    buffer += 3;
  }
  else if (fmt == 'f')
  {
    digits = fcvtbuf(value, precision, &decpt, &sign, cvtbuf);

    if (sign) *buffer++ = '-';
    
    if (*digits)
    {
      if (decpt <= 0)
      {
			*buffer++ = '0';
			*buffer++ = '.';
			for (pos = 0; pos < -decpt; pos++) *buffer++ = '0';
			while (*digits) *buffer++ = *digits++;
      }
      else
      {
			pos = 0;
			while (*digits)
			{
			  if (pos++ == decpt) *buffer++ = '.';
			  *buffer++ = *digits++;
			}
      }
    }
    else
    {
      *buffer++ = '0';
      if (precision > 0)
      {
			*buffer++ = '.';
			for (pos = 0; pos < precision; pos++) *buffer++ = '0';
      }
    }
  }

  *buffer = '\0';
}

static void forcdecpt(char *buffer)
{
  while (*buffer)
  {
    if (*buffer == '.') return;
    if (*buffer == 'e' || *buffer == 'E') break;
    buffer++;
  }

  if (*buffer)
  {
    int n = strlen(buffer);
    while (n > 0) 
    {
      buffer[n + 1] = buffer[n];
      n--;
    }

    *buffer = '.';
  }
  else
  {
    *buffer++ = '.';
    *buffer = '\0';
  }
}

static void cropzeros(char *buffer)
{
  char *stop;

  while (*buffer && *buffer != '.') buffer++;
  if (*buffer++)
  {
    while (*buffer && *buffer != 'e' && *buffer != 'E') buffer++;
    stop = buffer--;
    while (*buffer == '0') buffer--;
    if (*buffer == '.') buffer--;
    while (*++buffer = *stop++);
  }
}

static char *flt(char *str, double num, int size, int precision, char fmt, int flags)
{
  char tmp[80];
  char c, sign;
  int n, i;

  // Left align means no zero padding
  if (flags & LEFT) flags &= ~ZEROPAD;

  // Determine padding and sign char
  c = (flags & ZEROPAD) ? '0' : ' ';
  sign = 0;
  if (flags & SIGN)
  {
    if (num < 0.0)
    {
      sign = '-';
      num = -num;
      size--;
    }
    else if (flags & PLUS)
    {
      sign = '+';
      size--;
    }
    else if (flags & SPACE)
    {
      sign = ' ';
      size--;
    }
  }

  // Compute the precision value
  if (precision < 0)
    precision = 6; // Default precision: 6
  else if (precision == 0 && fmt == 'g')
    precision = 1; // ANSI specified

  // Convert floating point number to text
  cfltcvt(num, tmp, fmt, precision);

  // '#' and precision == 0 means force a decimal point
  if ((flags & SPECIAL) && precision == 0) forcdecpt(tmp);

  // 'g' format means crop zero unless '#' given
  if (fmt == 'g' && !(flags & SPECIAL)) cropzeros(tmp);

  n = strlen(tmp);
  // Output number with alignment and padding
  size -= n;
  if (!(flags & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' ';
  if (sign) *str++ = sign;
  if (!(flags & LEFT)) while (size-- > 0) *str++ = c;

  for (i = 0; i < n; i++)
   	*str++ = tmp[i];

  while (size-- > 0) *str++ = ' ';

  return str;
}

int vsprintf(char *buf, const char *fmt, va_list args)
{
  int len;
  unsigned long num;
  int i, base;
  char *str;
  char *s;

  int flags;            // Flags to number()

  int field_width;	// Width of output field
  int precision;	// Min. # of digits for integers; max number of chars for from string
  int qualifier;	// 'h', 'l', or 'L' for integer fields

  for (str = buf; *fmt; fmt++)
  {
    if (*fmt != '%')
    {
      *str++ = *fmt;
      continue;
    }
		  
    // Process flags
    flags = 0;
repeat:
    fmt++; // This also skips first '%'
    switch (*fmt)
    {
      case '-': flags |= LEFT; goto repeat;
      case '+': flags |= PLUS; goto repeat;
      case ' ': flags |= SPACE; goto repeat;
      case '#': flags |= SPECIAL; goto repeat;
      case '0': flags |= ZEROPAD; goto repeat;
    }
	  
    // Get field width
    field_width = -1;
    if (is_digit(*fmt))
      field_width = skip_atoi(&fmt);
    else if (*fmt == '*')
    {
      fmt++;
      field_width = va_arg(args, int);
      if (field_width < 0)
      {
	field_width = -field_width;
	flags |= LEFT;
      }
    }

    // Get the precision
    precision = -1;
    if (*fmt == '.')
    {
      ++fmt;	
      if (is_digit(*fmt))
        precision = skip_atoi(&fmt);
      else if (*fmt == '*')
      {
        ++fmt;
        precision = va_arg(args, int);
      }
      if (precision < 0) precision = 0;
    }

    // Get the conversion qualifier
    qualifier = -1;
    if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
    {
      qualifier = *fmt;
      fmt++;
    }

    // Default base
    base = 10;

    switch (*fmt)
    {
      case 'c':
	if (!(flags & LEFT)) while (--field_width > 0) *str++ = ' ';
	*str++ = (unsigned char) va_arg(args, int);
	while (--field_width > 0) *str++ = ' ';
	continue;

      case 's':
	s = va_arg(args, char *);
	if (!s)	s = "<NULL>";
	len = strnlen(s, precision);
	if (!(flags & LEFT)) while (len < field_width--) *str++ = ' ';
	for (i = 0; i < len; ++i) *str++ = *s++;
	while (len < field_width--) *str++ = ' ';
	continue;

      case 'p':
	if (field_width == -1)
	{
	  field_width = 2 * sizeof(void *);
	  flags |= ZEROPAD;
	}
	str = number(str, (unsigned long) va_arg(args, void *), 16, field_width, precision, flags);
	continue;

      case 'n':
	if (qualifier == 'l')
	{
	  long *ip = va_arg(args, long *);
	  *ip = (str - buf);
	}
	else
	{
	  int *ip = va_arg(args, int *);
	  *ip = (str - buf);
	}
	continue;

      case 'A':
	flags |= LARGE;

      case 'a':
	if (qualifier == 'l')
	  str = eaddr(str, va_arg(args, unsigned char *), field_width, precision, flags);
	else
	  str = iaddr(str, va_arg(args, unsigned char *), field_width, precision, flags);
	continue;

      // Integer number formats - set up the flags and "break"
      case 'o':
	base = 8;
	break;

      case 'X':
	flags |= LARGE;

      case 'x':
	base = 16;
	break;

      case 'd':
      case 'i':
	flags |= SIGN;

      case 'u':
	break;

      case 'E':
      case 'G':
      case 'e':
      case 'f':
      case 'g':
        str = flt(str, va_arg(args, double), field_width, precision, *fmt, flags | SIGN);
	continue;

      default:
	if (*fmt != '%') *str++ = '%';
	if (*fmt)
	  *str++ = *fmt;
	else
	  --fmt;
	continue;
    }

    if (qualifier == 'l')
      num = va_arg(args, unsigned long);
    else if (qualifier == 'h')
    {
      if (flags & SIGN)
	num = va_arg(args, short);
      else
	num = va_arg(args, unsigned short);
    }
    else if (flags & SIGN)
      num = va_arg(args, int);
    else
      num = va_arg(args, unsigned int);

    str = number(str, num, base, field_width, precision, flags);
  }

  *str = '\0';
  return str - buf;
}

int puts(const char *str)
{
	char ch = *str++;

	while(ch)
	{
		putchar(ch);
		ch = *str++;
	}

	return 1;
}

int sprintf(char *buf, const char *fmt, ...)
{
  va_list args;
  int n;

  va_start(args, fmt);
  n = vsprintf(buf, fmt, args);
  va_end(args);

  return n;
}

int printf(const char *fmt, ...)
{
  char buf[4096];
  va_list args;
  int n;

  va_start(args, fmt);
  n = vsprintf(buf, fmt, args);
  va_end(args);
  
  puts(buf);

  return n;
}
]]>
</file>
<file name="ctype.h">
<![CDATA[
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef CTYPE_H
#define CTYPE_H

#define _UPPER          0x1     // Upper case letter
#define _LOWER          0x2     // Lower case letter
#define _DIGIT          0x4     // Digit[0-9]
#define _SPACE          0x8     // Tab, carriage return, newline, vertical tab or form feed
#define _PUNCT          0x10    // Punctuation character
#define _CONTROL        0x20    // Control character
#define _BLANK          0x40    // Space char
#define _HEX            0x80    // Hexadecimal digit

#define _LEADBYTE       0x8000                      // Multibyte leadbyte
#define _ALPHA          (0x0100 | _UPPER| _LOWER)   // Alphabetic character

#ifdef __cplusplus
extern "C" {
#endif

extern unsigned short *_pctype; // pointer to table for char's

#ifdef __cplusplus
} //extern "C"
#endif

#define isalpha(c)     (_pctype[(unsigned char)(c)] & (_UPPER | _LOWER))
#define isupper(c)     (_pctype[(unsigned char)(c)] & _UPPER)
#define islower(c)     (_pctype[(unsigned char)(c)] & _LOWER)
#define isdigit(c)     (_pctype[(unsigned char)(c)] & _DIGIT)
#define isxdigit(c)    (_pctype[(unsigned char)(c)] & _HEX)
#define isspace(c)     (_pctype[(unsigned char)(c)] & _SPACE)
#define ispunct(c)     (_pctype[(unsigned char)(c)] & _PUNCT)
#define isalnum(c)     (_pctype[(unsigned char)(c)] & (_UPPER | _LOWER | _DIGIT))
#define isprint(c)     (_pctype[(unsigned char)(c)] & (_BLANK | _PUNCT | _UPPER | _LOWER | _DIGIT))
#define isgraph(c)     (_pctype[(unsigned char)(c)] & (_PUNCT | _UPPER | _LOWER | _DIGIT))
#define iscntrl(c)     (_pctype[(unsigned char)(c)] & _CONTROL)
#define isleadbyte(c)  (_pctype[(unsigned char)(c)] & _LEADBYTE)

#define tolower(c)     (isupper((unsigned char)c) ? ((unsigned char)(c) - 'A' + 'a') : (unsigned char)(c))
#define toupper(c)     (islower((unsigned char)c) ? ((unsigned char)(c) - 'a' + 'A') : (unsigned char)(c))

#endif
]]>
</file>
<file name="ctype.c">
<![CDATA[
#include "ctype.h"

unsigned short _ctype[257] = 
{
  0,                      // -1 EOF
  _CONTROL,               // 00 (NUL)
  _CONTROL,               // 01 (SOH)
  _CONTROL,               // 02 (STX)
  _CONTROL,               // 03 (ETX)
  _CONTROL,               // 04 (EOT)
  _CONTROL,               // 05 (ENQ)
  _CONTROL,               // 06 (ACK)
  _CONTROL,               // 07 (BEL)
  _CONTROL,               // 08 (BS)
  _SPACE+_CONTROL,        // 09 (HT)
  _SPACE+_CONTROL,        // 0A (LF)
  _SPACE+_CONTROL,        // 0B (VT)
  _SPACE+_CONTROL,        // 0C (FF)
  _SPACE+_CONTROL,        // 0D (CR)
  _CONTROL,               // 0E (SI)
  _CONTROL,               // 0F (SO)
  _CONTROL,               // 10 (DLE)
  _CONTROL,               // 11 (DC1)
  _CONTROL,               // 12 (DC2)
  _CONTROL,               // 13 (DC3)
  _CONTROL,               // 14 (DC4)
  _CONTROL,               // 15 (NAK)
  _CONTROL,               // 16 (SYN)
  _CONTROL,               // 17 (ETB)
  _CONTROL,               // 18 (CAN)
  _CONTROL,               // 19 (EM)
  _CONTROL,               // 1A (SUB)
  _CONTROL,               // 1B (ESC)
  _CONTROL,               // 1C (FS)
  _CONTROL,               // 1D (GS)
  _CONTROL,               // 1E (RS)
  _CONTROL,               // 1F (US)
  _SPACE+_BLANK,          // 20 SPACE
  _PUNCT,                 // 21 !
  _PUNCT,                 // 22 "
  _PUNCT,                 // 23 #
  _PUNCT,                 // 24 $
  _PUNCT,                 // 25 %
  _PUNCT,                 // 26 &
  _PUNCT,                 // 27 '
  _PUNCT,                 // 28 (
  _PUNCT,                 // 29 )
  _PUNCT,                 // 2A *
  _PUNCT,                 // 2B +
  _PUNCT,                 // 2C ,
  _PUNCT,                 // 2D -
  _PUNCT,                 // 2E .
  _PUNCT,                 // 2F /
  _DIGIT+_HEX,            // 30 0
  _DIGIT+_HEX,            // 31 1
  _DIGIT+_HEX,            // 32 2
  _DIGIT+_HEX,            // 33 3
  _DIGIT+_HEX,            // 34 4
  _DIGIT+_HEX,            // 35 5
  _DIGIT+_HEX,            // 36 6
  _DIGIT+_HEX,            // 37 7
  _DIGIT+_HEX,            // 38 8
  _DIGIT+_HEX,            // 39 9
  _PUNCT,                 // 3A :
  _PUNCT,                 // 3B ;
  _PUNCT,                 // 3C <
  _PUNCT,                 // 3D =
  _PUNCT,                 // 3E >
  _PUNCT,                 // 3F ?
  _PUNCT,                 // 40 @
  _UPPER+_HEX,            // 41 A
  _UPPER+_HEX,            // 42 B
  _UPPER+_HEX,            // 43 C
  _UPPER+_HEX,            // 44 D
  _UPPER+_HEX,            // 45 E
  _UPPER+_HEX,            // 46 F
  _UPPER,                 // 47 G
  _UPPER,                 // 48 H
  _UPPER,                 // 49 I
  _UPPER,                 // 4A J
  _UPPER,                 // 4B K
  _UPPER,                 // 4C L
  _UPPER,                 // 4D M
  _UPPER,                 // 4E N
  _UPPER,                 // 4F O
  _UPPER,                 // 50 P
  _UPPER,                 // 51 Q
  _UPPER,                 // 52 R
  _UPPER,                 // 53 S
  _UPPER,                 // 54 T
  _UPPER,                 // 55 U
  _UPPER,                 // 56 V
  _UPPER,                 // 57 W
  _UPPER,                 // 58 X
  _UPPER,                 // 59 Y
  _UPPER,                 // 5A Z
  _PUNCT,                 // 5B [
  _PUNCT,                 // 5C \ 
  _PUNCT,                 // 5D ]
  _PUNCT,                 // 5E ^
  _PUNCT,                 // 5F _
  _PUNCT,                 // 60 `
  _LOWER+_HEX,            // 61 a
  _LOWER+_HEX,            // 62 b
  _LOWER+_HEX,            // 63 c
  _LOWER+_HEX,            // 64 d
  _LOWER+_HEX,            // 65 e
  _LOWER+_HEX,            // 66 f
  _LOWER,                 // 67 g
  _LOWER,                 // 68 h
  _LOWER,                 // 69 i
  _LOWER,                 // 6A j
  _LOWER,                 // 6B k
  _LOWER,                 // 6C l
  _LOWER,                 // 6D m
  _LOWER,                 // 6E n
  _LOWER,                 // 6F o
  _LOWER,                 // 70 p
  _LOWER,                 // 71 q
  _LOWER,                 // 72 r
  _LOWER,                 // 73 s
  _LOWER,                 // 74 t
  _LOWER,                 // 75 u
  _LOWER,                 // 76 v
  _LOWER,                 // 77 w
  _LOWER,                 // 78 x
  _LOWER,                 // 79 y
  _LOWER,                 // 7A z
  _PUNCT,                 // 7B {
  _PUNCT,                 // 7C |
  _PUNCT,                 // 7D }
  _PUNCT,                 // 7E ~
  _CONTROL,               // 7F (DEL)
  // and the rest are 0...
};

unsigned short *_pctype = _ctype + 1; // pointer to table for char's

]]>
</file>
<file name="init.h">
<![CDATA[
#ifndef __INIT_H
#define __INIT_H

void *operator new(unsigned int size);
void operator delete(void *p);


#ifdef __cplusplus
extern "C" {
#endif

void _init();

#ifdef __cplusplus
} //extern "C"
#endif

#endif
]]>
</file>
<file name="init.cpp">
<![CDATA[
#include "malloc.h"

void *operator new(unsigned int size)
{
	return malloc(size);
}
void operator delete(void *p)
{
	free(p);
}

#ifdef __cplusplus
extern "C" {
#endif

typedef  void (*__FUNC)(void);

extern int main();

void _init()
{
	int i,xcu_size,*p = (int*)0x30000000;
	__FUNC func;	
	
	init_heap((void*)(*(p+2)),(void*)(*(p+3)));

	xcu_size = *(p+4) / 4;
	p = (int *)0x28000000;
	for(i = 0; i < xcu_size; i++)
	{
		func  = (__FUNC)p[i];
		func();
	}
	
	main();
}

#ifdef __cplusplus
} //extern "C"
#endif
]]>
</file>
<file name="limits.h">
<![CDATA[
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef LIMITS_H
#define LIMITS_H

#define PATH_MAX      255
#define ARG_MAX       131072

#define CHAR_BIT      8			// Number of bits in a char
#define SCHAR_MIN   (-128)		// Minimum signed char value
#define SCHAR_MAX     127		// Maximum signed char value
#define UCHAR_MAX     0xff		// Maximum unsigned char value

#ifndef _CHAR_UNSIGNED
#define CHAR_MIN    SCHAR_MIN		// Mimimum char value
#define CHAR_MAX    SCHAR_MAX		// Maximum char value
#else
#define CHAR_MIN      0
#define CHAR_MAX    UCHAR_MAX
#endif

#define MB_LEN_MAX    2			 // Max. # bytes in multibyte char
#define SHRT_MIN    (-32768)		 // Minimum (signed) short value
#define SHRT_MAX      32767		 // Maximum (signed) short value
#define USHRT_MAX     0xffff		 // Maximum unsigned short value
#define INT_MIN     (-2147483647 - 1)	 // Minimum (signed) int value
#define INT_MAX       2147483647	 // Maximum (signed) int value
#define UINT_MAX      0xffffffff	 // Maximum unsigned int value
#define LONG_MIN    (-2147483647L - 1)	 // Minimum (signed) long value
#define LONG_MAX      2147483647L	 // Maximum (signed) long value
#define ULONG_MAX     0xffffffffUL	 // Maximum unsigned long value

#if _INTEGRAL_MAX_BITS >= 8
#define _I8_MIN     (-127i8 - 1)	 // Minimum signed 8 bit value
#define _I8_MAX       127i8		 // Maximum signed 8 bit value
#define _UI8_MAX      0xffui8		 // Maximum unsigned 8 bit value
#endif

#if _INTEGRAL_MAX_BITS >= 16
#define _I16_MIN    (-32767i16 - 1)	 // Minimum signed 16 bit value
#define _I16_MAX      32767i16		 // Maximum signed 16 bit value
#define _UI16_MAX     0xffffui16	 // Maximum unsigned 16 bit value
#endif

#if _INTEGRAL_MAX_BITS >= 32
#define _I32_MIN    (-2147483647i32 - 1) // Minimum signed 32 bit value
#define _I32_MAX      2147483647i32	 // Maximum signed 32 bit value
#define _UI32_MAX     0xffffffffui32	 // Maximum unsigned 32 bit value
#endif

#if _INTEGRAL_MAX_BITS >= 64
#define _I64_MIN    (-9223372036854775807i64 - 1)
#define _I64_MAX      9223372036854775807i64
#define _UI64_MAX     0xffffffffffffffffui64
#endif

#endif
]]>
</file>
<file name="malloc.h">
<![CDATA[
#ifndef __MALLOC_H
#define __MALLOC_H

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

void *malloc(DWORD nbytes);
void free(void *ap);
DWORD get_free_size(void);
int init_heap(void *heap_start,void *heap_end);
void *realloc(void *p,DWORD old_size,DWORD new_size);

#ifdef __cplusplus
} //extern "C"
#endif

#endif

]]>
</file>
<file name="malloc.c">
<![CDATA[
#include "malloc.h"
#include "types.h"

typedef DWORD Align;

union header
{
	struct
	{
		union header *ptr;
		DWORD size;
	}s;
	Align x; 
};

typedef union header Header;

static char * __heap_start = NULL;
static char * __heap_end = NULL;

static Header base;  //���������ʼ
static Header *freep=NULL;

static Header *morecore(DWORD nu);

void *malloc(DWORD nbytes)
{
	Header *p, *prevp;
	DWORD nunits;

	nunits = (nbytes+sizeof(Header)-1)/sizeof(Header) + 1;
	
	prevp = freep;
	if(prevp == NULL)
	{
		base.s.ptr = freep = prevp = &base;
		base.s.size=0;
	}
	for(p=prevp->s.ptr ; ;prevp = p,p=p->s.ptr)
	{
		if( p->s.size >= nunits)
		{
			if(p->s.size == nunits)
			{
				prevp->s.ptr = p->s.ptr;
			}
			else
			{
				p->s.size -= nunits;
				p += p->s.size;
				p->s.size = nunits; 
			}
			freep = prevp;
			return (void *)(p+1);
		}
		if(p == freep)
		{
			
			p = morecore(nunits);
			if(p==NULL)
				return NULL;
		}
	}
}

void free(void *ap)
{
	Header *bp, *p;
	
	
	bp = (Header *)ap-1;
	for(p=freep;!(bp > p && bp < p->s.ptr); p=p->s.ptr)
	{
		if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
			break;
	}
	if(bp + bp->s.size == p->s.ptr)
	{
		bp->s.size += p->s.ptr->s.size;
		bp->s.ptr = p->s.ptr->s.ptr;
	}
	else
	{
		bp->s.ptr = p->s.ptr;
	}
	
	if(p + p->s.size == bp)
	{
		p->s.size += bp->s.size;
		p->s.ptr = bp->s.ptr;	
	}
	else
	{
		p->s.ptr = bp;
	}
	freep = p;
}

Header *morecore(DWORD nu)
{
	char *cp;
	Header *up;
	static int is_run = 0;
	
	if(is_run)return NULL;
	is_run = 1;
		
	nu = (__heap_end - __heap_start)/sizeof(Header) - 1;
	
	cp = (char *)__heap_start;
	up = (Header *)cp;
	up->s.size = nu;
	
	free((void *)(up+1));
	
	return freep;
}


DWORD get_free_size()
{
	Header *p, *prevp;
	DWORD size=0;	
	prevp = freep;

	if(prevp == NULL)
	{
		return (__heap_end - __heap_start);
	}

	for(p=prevp->s.ptr ; ;prevp = p,p=p->s.ptr)
	{
		size += p->s.size;
		if(p == freep)
			break;
	}
	return size*sizeof(Header);
}

int init_heap(void *heap_start,void *heap_end)
{
	__heap_start = heap_start;
	__heap_end = heap_end;

	return OK;
}

void *realloc(void *p,DWORD old_size,DWORD new_size)
{
	void *newp;
	DWORD min;
	
	min = old_size<new_size?old_size:new_size;
	
	newp = malloc(new_size);
	
	if(newp == NULL)
		return NULL;
	
	memcpy(newp,p,min);
	
	free(p);
	
	return newp;
}

]]>
</file>
<file name="math.h">
<![CDATA[
#ifndef __MATH_H
#define __MATH_H

#include "float.h"

#define M_E        2.71828182845904523536     // e
#define M_LOG2E    1.44269504088896340736     // log2(e)
#define M_LOG10E   0.434294481903251827651    // log10(e)
#define M_LN2      0.693147180559945309417    // ln(2)
#define M_LN10     2.30258509299404568402     // ln(10)
#define M_PI       3.14159265358979323846     // pi
#define M_PI_2     1.57079632679489661923     // pi/2
#define M_PI_4     0.785398163397448309616    // pi/4
#define M_1_PI     0.318309886183790671538    // 1/pi
#define M_2_PI     0.636619772367581343076    // 2/pi
#define M_2_SQRTPI 1.12837916709551257390     // 2/sqrt(pi)
#define M_SQRT2    1.41421356237309504880     // sqrt(2)
#define M_SQRT1_2  0.707106781186547524401    // 1/sqrt(2)

#define HUGE_VAL _infinity

//
// Floating point classes for fpclassify()
//

#define FP_NAN       0
#define FP_INFINITE  1
#define FP_ZERO      2
#define FP_SUBNORMAL 3
#define FP_NORMAL    4

#ifdef __cplusplus
extern "C" {
#endif

extern const double _infinity;

double acos(double x);  //test ok
double asin(double x);  //test ok
double atan(double x);	//test ok
double atan2(double x, double y); //test ok
double ceil(double x); //test ok
double cos(double x);	//test ok
double cosh(double x);	//test ok
double exp(double x);	//test ok
double fabs(double x);	//test ok
double floor(double x); //test ok
double fmod(double x, double y);//test ok
double frexp(double x, int *n);	//test ok
double ldexp(double x, int n);	//test ok
double log(double x);	//test ok
double log10(double x);	//test ok
double modf(double x, double *y);	//test ok
double pow(double x, double y);	//test ok
double sin(double x);	//test ok
double sinh(double x);	//test ok
double sqrt(double x);	//test ok
double tan(double x);	//test ok
double tanh(double x);	//test ok

#ifdef __cplusplus
} //extern "C"
#endif

#endif
]]>
</file>
<file name="math.c">
<![CDATA[
#include "math.h"

struct dblval
{
  unsigned int manl:32;
  unsigned int manh:20;
  unsigned int exp:11;
  unsigned int sign:1;
};

int isinf(double x) 
{
  unsigned __int64 *val = (unsigned __int64 *) &x;

  return *val == 0x7ff0000000000000 ? 1 : *val == 0xfff0000000000000 ? -1 : 0;
}

int isnan(double x)
{
  return x != x;
}

int isfinite(double x)
{
  unsigned short *val = (unsigned short *) &x;

  return (val[3] & 0x7ff0) != 0x7ff0;
}

int _fpclass(double x)
{
  struct dblval *d = (struct dblval *) &x;
  
  if (d->exp == 0)
  {
    if (d->manh == 0 && d->manl == 0)
    {
      if (d->sign == 0)
        return _FPCLASS_NZ;
      else
        return _FPCLASS_PZ;
    } 
    else 
    {
      if (d->sign == 0)
        return _FPCLASS_ND;
      else
        return _FPCLASS_PD;
    }
  }

  if (d->exp == 0x7ff)
  {
    if (d->manh == 0 && d->manl == 0)
    {
      if (d->sign == 0)
        return _FPCLASS_NINF;
      else
        return _FPCLASS_PINF;
    }
    else if (d->manh == 0 && d->manl != 0) 
      return _FPCLASS_QNAN;
    else
      return _FPCLASS_SNAN;
  }

  return 0;
}

int fpclassify(double x)
{
  struct dblval *d = (struct dblval *) &x;

  if (d->exp == 0) 
  {
    if ((d->manl | d->manh) == 0) return FP_ZERO;
    return (FP_SUBNORMAL);
  }
  
  if (d->exp == 0x7ff) 
  {
    if ((d->manl | d->manh) == 0) return FP_INFINITE;
    return FP_NAN;
  
  }
  
  return FP_NORMAL;
}

int isless(double x, double y)
{
  return isfinite(x) && isfinite(y) ? x < y : 0;
}

int isgreater(double x, double y)
{
  return isfinite(x) && isfinite(y) ? x > y : 0;
}

double round(double x)
{
  double t;

  if (!isfinite(x)) return x;

  if (x >= 0.0) 
  {
    t = ceil(x);
    if (t - x > 0.5) t -= 1.0;
    return t;
  } 
  else 
  {
    t = ceil(-x);
    if (t + x > 0.5) t -= 1.0;
    return -t;
  }
}
]]>
</file>
<file name="float.h">
<![CDATA[
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _FLOAT_H
#define _FLOAT_H

//
// Limits for float
//

#define FLT_RADIX      2
#define FLT_ROUNDS     1
#define FLT_DIG        6
#define FLT_EPSILON    1.192092896e-07F
#define FLT_MANT_DIG   24
#define FLT_MAX        3.402823466e+38F
#define FLT_MAX_10_EXP 38
#define FLT_MAX_EXP    128
#define FLT_MIN        1.175494351e-38F
#define FLT_MIN_10_EXP (-37)
#define FLT_MIN_EXP    (-125)

//
// Limits for double
//

#define DBL_DIG        15
#define DBL_EPSILON    2.2204460492503131e-016
#define DBL_MANT_DIG   53
#define DBL_MAX        1.7976931348623158e+308
#define DBL_MAX_10_EXP 308
#define DBL_MAX_EXP    1024
#define DBL_MIN        2.2250738585072014e-308
#define DBL_MIN_10_EXP (-307)
#define DBL_MIN_EXP    (-1021)

//
// Floating point classes for _fpclass()
//

#define _FPCLASS_SNAN   0x0001  // Signaling NaN
#define _FPCLASS_QNAN   0x0002  // Quiet NaN
#define _FPCLASS_NINF   0x0004  // Negative infinity
#define _FPCLASS_NN     0x0008  // Negative normal
#define _FPCLASS_ND     0x0010  // Negative denormal
#define _FPCLASS_NZ     0x0020  // -0
#define _FPCLASS_PZ     0x0040  // +0
#define _FPCLASS_PD     0x0080  // Positive denormal
#define _FPCLASS_PN     0x0100  // Positive normal
#define _FPCLASS_PINF   0x0200  // Positive infinity

#endif
]]>
</file>
<file name="stdarg.h">
<![CDATA[
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef STDARG_H
#define STDARG_H

#ifndef _VA_LIST_DEFINED
#define _VA_LIST_DEFINED
typedef char *va_list;
#endif

#define _INTSIZEOF(n)    ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))

#define va_start(ap, v)  (ap = (va_list) &v + _INTSIZEOF(v))
#define va_arg(ap, t)    (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
#define va_end(ap)       (ap = (va_list) 0)

#endif

]]>
</file>
<file name="stdlib.h">
<![CDATA[
#ifndef __STDLIB_H
#define __STDLIB_H

#ifdef  __cplusplus
extern "C" {
#endif

int atoi(const char *string);
long atol(const char *string);
double strtod(const char *str, char **endptr);
double atof(const char *str);

/****system call******/
int clrscr();
int exit(int exit_code);
int get_text_size();
int load_data(char *buf,int size);
int get_time();
int get_name(int i,char *buf,int max);
int get_self_num();
int get_name(int i,char *buf,int max);
int get_self_num();
int get_cookie_size(int i);
int set_cookie_size(int i,int size);
int get_cookie_offset(int i);
int set_cookie_offset(int i,int off);
int read_cookie(int i,void *buf,int rsize);
int write_cookie(int i,void *buf,int wsize);
/*********************/

#ifdef  __cplusplus
}
#endif

#endif
]]>
</file>
<file name="stdlib.c">
<![CDATA[
#include "stdlib.h"
#include "math.h"
#include "ctype.h"
#include "limits.h"
#include "types.h"

#define FL_UNSIGNED   1
#define FL_NEG        2
#define FL_OVERFLOW   4
#define FL_READDIGIT  8

#define CVTBUFSIZE        (309 + 43)

static char *cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag)
{
  int r2;
  double fi, fj;
  char *p, *p1;

  if (ndigits < 0) ndigits = 0;
  if (ndigits >= CVTBUFSIZE - 1) ndigits = CVTBUFSIZE - 2;
  r2 = 0;
  *sign = 0;
  p = &buf[0];
  if (arg < 0)
  {
    *sign = 1;
    arg = -arg;
  }
  arg = modf(arg, &fi);
  p1 = &buf[CVTBUFSIZE];

  if (fi != 0) 
  {
    p1 = &buf[CVTBUFSIZE];
    while (fi != 0) 
    {
      fj = modf(fi / 10, &fi);
      *--p1 = (int)((fj + .03) * 10) + '0';
      r2++;
    }
    while (p1 < &buf[CVTBUFSIZE]) *p++ = *p1++;
  } 
  else if (arg > 0)
  {
    while ((fj = arg * 10) < 1) 
    {
      arg = fj;
      r2--;
    }
  }
  p1 = &buf[ndigits];
  if (eflag == 0) p1 += r2;
  *decpt = r2;
  if (p1 < &buf[0]) 
  {
    buf[0] = '\0';
    return buf;
  }
  while (p <= p1 && p < &buf[CVTBUFSIZE])
  {
    arg *= 10;
    arg = modf(arg, &fj);
    *p++ = (int) fj + '0';
  }
  if (p1 >= &buf[CVTBUFSIZE]) 
  {
    buf[CVTBUFSIZE - 1] = '\0';
    return buf;
  }
  p = p1;
  *p1 += 5;
  while (*p1 > '9') 
  {
    *p1 = '0';
    if (p1 > buf)
      ++*--p1;
    else 
    {
      *p1 = '1';
      (*decpt)++;
      if (eflag == 0) 
      {
	if (p > buf) *p = '0';
	p++;
      }
    }
  }
  *p = '\0';
  return buf;
}

char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf)
{
  return cvt(arg, ndigits, decpt, sign, buf, 1);
}

char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf)
{
  return cvt(arg, ndigits, decpt, sign, buf, 0);
}

static unsigned long strtoxl(const char *nptr, char **endptr, int ibase, int flags)
{
  const char *p;
  char c;
  unsigned long number;
  unsigned digval;
  unsigned long maxval;

  p = nptr;
  number = 0;

  c = *p++;
  while (isspace((int)(unsigned char) c)) c = *p++;

  if (c == '-') 
  {
    flags |= FL_NEG;
    c = *p++;
  }
  else if (c == '+')
    c = *p++;

  if (ibase < 0 || ibase == 1 || ibase > 36) 
  {
    if (endptr) *endptr = (char *) nptr;
    return 0L;
  }
  else if (ibase == 0)
  {
    if (c != '0')
      ibase = 10;
    else if (*p == 'x' || *p == 'X')
      ibase = 16;
    else
      ibase = 8;
  }

  if (ibase == 16)
  {
    if (c == '0' && (*p == 'x' || *p == 'X')) 
    {
      ++p;
      c = *p++;
    }
  }

  maxval = ULONG_MAX / ibase;

  for (;;) 
  {
    if (isdigit((int) (unsigned char) c))
      digval = c - '0';
    else if (isalpha((int) (unsigned char) c))
      digval = toupper(c) - 'A' + 10;
    else
      break;

    if (digval >= (unsigned) ibase) break;

    flags |= FL_READDIGIT;

    if (number < maxval || (number == maxval && (unsigned long) digval <= ULONG_MAX % ibase)) 
      number = number * ibase + digval;
    else 
      flags |= FL_OVERFLOW;

    c = *p++;
  }

  --p;

  if (!(flags & FL_READDIGIT)) 
  {
    if (endptr) p = nptr;
    number = 0L;
  }
  else if ((flags & FL_OVERFLOW) || (!(flags & FL_UNSIGNED) && (((flags & FL_NEG) && (number < LONG_MIN)) || (!(flags & FL_NEG) && (number > LONG_MAX)))))
  {
    if (flags & FL_UNSIGNED)
      number = ULONG_MAX;
    else if (flags & FL_NEG)
      number = LONG_MIN;
    else
      number = LONG_MAX;
  }

  if (endptr != NULL) *endptr = (char *) p;

  if (flags & FL_NEG) number = (unsigned long) (-(long) number);

  return number;
}

long strtol(const char *nptr, char **endptr, int ibase)
{
  return (long) strtoxl(nptr, endptr, ibase, 0);
}

unsigned long strtoul(const char *nptr, char **endptr, int ibase)
{
  return strtoxl(nptr, endptr, ibase, FL_UNSIGNED);
}

long atol(const char *nptr)
{
  int c;
  long total;
  int sign;

  while (isspace((int)(unsigned char) *nptr)) ++nptr;

  c = (int)(unsigned char) *nptr++;
  sign = c;
  if (c == '-' || c == '+') c = (int)(unsigned char) *nptr++;

  total = 0;
  while (isdigit(c)) 
  {
    total = 10 * total + (c - '0');
    c = (int)(unsigned char) *nptr++;
  }

  if (sign == '-')
    return -total;
  else
    return total;
}

int atoi(const char *nptr)
{
  return (int) atol(nptr);
}

double strtod(const char *str, char **endptr)
{
  double number;
  int exponent;
  int negative;
  char *p = (char *) str;
  double p10;
  int n;
  int num_digits;
  int num_decimals;

  // Skip leading whitespace
  while (isspace(*p)) p++;

  // Handle optional sign
  negative = 0;
  switch (*p) 
  {		
    case '-': negative = 1; // Fall through to increment position
    case '+': p++;
  }

  number = 0.;
  exponent = 0;
  num_digits = 0;
  num_decimals = 0;

  // Process string of digits
  while (isdigit(*p))
  {
    number = number * 10. + (*p - '0');
    p++;
    num_digits++;
  }

  // Process decimal part
  if (*p == '.') 
  {
    p++;

    while (isdigit(*p))
    {
      number = number * 10. + (*p - '0');
      p++;
      num_digits++;
      num_decimals++;
    }

    exponent -= num_decimals;
  }

  if (num_digits == 0)
  {
    return 0.0;
  }

  // Correct for sign
  if (negative) number = -number;

  // Process an exponent string
  if (*p == 'e' || *p == 'E') 
  {
    // Handle optional sign
    negative = 0;
    switch (*++p) 
    {	
      case '-': negative = 1;	// Fall through to increment pos
      case '+': p++;
    }

    // Process string of digits
    n = 0;
    while (isdigit(*p)) 
    {	
      n = n * 10 + (*p - '0');
      p++;
    }

    if (negative) 
      exponent -= n;
    else
      exponent += n;
  }

  if (exponent < DBL_MIN_EXP  || exponent > DBL_MAX_EXP)
  {
    return HUGE_VAL;
  }

  // Scale the result
  p10 = 10.;
  n = exponent;
  if (n < 0) n = -n;
  while (n) 
  {
    if (n & 1) 
    {
      if (exponent < 0)
        number /= p10;
      else
	number *= p10;
    }
    n >>= 1;
    p10 *= p10;
  }
  
  if (endptr) *endptr = p;

  return number;
}

double atof(const char *str)
{
  return strtod(str, NULL);
}

]]>
</file>
<file name="string.h">
<![CDATA[
#ifndef __STRING_2007_12_6_14_52_56_H
#define __STRING_2007_12_6_14_52_56_H

#include "types.h"
	
#ifdef __cplusplus
extern "C" {
#endif

int stricmp(const char *s1, const char *s2);
char *strchr(const char *s, int ch);
char *strstr(const char *str1, const char *str2);
void *memcpy(void *dst, const void *src, size_t n);
char *strcpy(char *dst, const char *src);
size_t strlen(const char *s);
int strcmp(const char *s1, const char *s2);
char *strcat(char *dst, const char *src);
void *memset(void *p, int c, size_t n);

#ifdef __cplusplus
} //extern "C"
#endif
	
#endif
]]>
</file>
<file name="string.c">
<![CDATA[
#include "string.h"

int stricmp(const char *s1, const char *s2)
{
	char f, l;
	
	do 
	{
		f = ((*s1 <= 'Z') && (*s1 >= 'A')) ? *s1 + 'a' - 'A' : *s1;
		l = ((*s2 <= 'Z') && (*s2 >= 'A')) ? *s2 + 'a' - 'A' : *s2;
		s1++;
		s2++;
	} while ((f) && (f == l));
	
	return (int) (f - l);
}

char *strchr(const char *s, int ch)
{
	while (*s && *s != (char) ch) s++;
	if (*s == (char) ch) return (char *) s;
	return NULL;
}

char *strstr(const char *str1, const char *str2)
{
	char *cp = (char *) str1;
	char *s1, *s2;
	
	if (!*str2) return (char *) str1;
	
	while (*cp)
	{
		s1 = cp;
		s2 = (char *) str2;
		
		while (*s1 && *s2 && !(*s1 - *s2)) s1++, s2++;
		if (!*s2) return cp;
		cp++;
	}
	
	return NULL;
}
]]>
</file>
<file name="types.h">
<![CDATA[
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef SYS_TYPES_H
#define SYS_TYPES_H

typedef unsigned int size_t;
typedef int ssize_t;
typedef long time_t;
typedef long clock_t;
typedef unsigned int ino_t;
typedef unsigned int dev_t;
typedef unsigned short mode_t;
typedef unsigned short nlink_t;
typedef unsigned short uid_t;
typedef unsigned short gid_t;
typedef unsigned int blkno_t;
typedef long loff_t;
typedef __int64 off64_t;
typedef off64_t off_t;
typedef int handle_t;
typedef unsigned long tid_t;
typedef unsigned long pid_t;
typedef void *hmodule_t;
typedef unsigned long tls_t;
typedef unsigned short wchar_t;
typedef char *va_list;
typedef int port_t;
typedef int err_t;

typedef __int64 systime_t;

#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif

#define FALSE 0
#define TRUE  1
#define OK    1
#define ERROR 0

#define NOHANDLE ((handle_t) -1)

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned __int64 QWORD;

typedef BYTE BOOL;
typedef int LONG;
typedef char CHAR;

#endif
]]>
</file>
</AllFiles>
</RunTimeLib>
<User>

<AllFiles>
<file name="main.cpp">
<![CDATA[
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "common.h"
#include "malloc.h"
#include "graphics.h"
#include "rect.h"

int _init_attrib();
int before_draw();
int draw();
int code(int code_num);

#include "process.h"

int main()
{
	int *p = (int *)0x30000000 + 9;
	int code_num = *(p+1);

	_init_attrib();
	
	switch(*p)
	{
		case 1: draw(); break;
		case 2: code(code_num); break;
		case 3: before_draw(); break;
	}
	
	return OK;
}
]]>
</file>
<file name="graphics.h">
<![CDATA[
#ifndef __GRAPHICS_H
#define __GRAPHICS_H

#include "common.h"
#include "rect.h"

/* Brush Styles */
#define BS_SOLID            0
#define BS_NULL             1
#define BS_HOLLOW           BS_NULL
#define BS_HATCHED          2
#define BS_PATTERN          3
#define BS_INDEXED          4
#define BS_DIBPATTERN       5
#define BS_DIBPATTERNPT     6
#define BS_PATTERN8X8       7
#define BS_DIBPATTERN8X8    8
#define BS_MONOPATTERN      9

/* Hatch Styles */
#define HS_HORIZONTAL       0       /* ----- */
#define HS_VERTICAL         1       /* ||||| */
#define HS_FDIAGONAL        2       /* \\\\\ */
#define HS_BDIAGONAL        3       /* ///// */
#define HS_CROSS            4       /* +++++ */
#define HS_DIAGCROSS        5       /* xxxxx */

/* Pen Styles */
#define PS_SOLID            0
#define PS_DASH             1       /* -------  */
#define PS_DOT              2       /* .......  */
#define PS_DASHDOT          3       /* _._._._  */
#define PS_DASHDOTDOT       4       /* _.._.._  */
#define PS_NULL             5
#define PS_INSIDEFRAME      6
#define PS_USERSTYLE        7
#define PS_ALTERNATE        8

/*
*DrawText() Format Flags 
*/
#define DT_TOP              0x00000000
#define DT_LEFT             0x00000000
#define DT_CENTER           0x00000001
#define DT_RIGHT            0x00000002
#define DT_VCENTER          0x00000004
#define DT_BOTTOM           0x00000008
#define DT_WORDBREAK        0x00000010
#define DT_SINGLELINE       0x00000020
#define DT_EXPANDTABS       0x00000040
#define DT_TABSTOP          0x00000080
#define DT_NOCLIP           0x00000100
#define DT_EXTERNALLEADING  0x00000200
#define DT_CALCRECT         0x00000400
#define DT_NOPREFIX         0x00000800
#define DT_INTERNAL         0x00001000

#define DIB_RGB_COLORS      0 /* color table in RGBs */
#define DIB_PAL_COLORS      1 /* color table in palette indices */

#define OEM_FIXED_FONT      10
#define ANSI_FIXED_FONT     11
#define ANSI_VAR_FONT       12
#define SYSTEM_FONT         13
#define DEVICE_DEFAULT_FONT 14
#define DEFAULT_PALETTE     15
#define SYSTEM_FIXED_FONT   16
#define DEFAULT_GUI_FONT    17

#define TRANSPARENT         1
#define OPAQUE              2

#define RGB(r,g,b)          ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))

#define FRAME3D_UP          1
#define FRAME3D_DOWN        2

#define TRI_UP              1
#define TRI_DOWN            2
#define TRI_LEFT            3
#define TRI_RIGHT           4

typedef DWORD   COLORREF;

#define LF_FACESIZE         32

typedef struct tagLOGFONTA
{
    LONG      lfHeight;
    LONG      lfWidth;
    LONG      lfEscapement;
    LONG      lfOrientation;
    LONG      lfWeight;
    BYTE      lfItalic;
    BYTE      lfUnderline;
    BYTE      lfStrikeOut;
    BYTE      lfCharSet;
    BYTE      lfOutPrecision;
    BYTE      lfClipPrecision;
    BYTE      lfQuality;
    BYTE      lfPitchAndFamily;
    CHAR      lfFaceName[LF_FACESIZE];
}LOGFONT;

#ifdef __cplusplus
extern "C" {
#endif

int line(int left,int top,int right,int bottom);
int get_rect(int i,int *l,int *t,int *r,int *b);
int set_pen(int style,int width,COLORREF color);
int set_rect(int i,int l,int t,int r,int b);
int set_brush(int style,COLORREF color,int hatch);
int fill_rect(int l,int t,int w,int h);
int draw_text(char *str,int size,RECT *rect,DWORD format);
int ellipse(int l,int t,int w,int h);
int set_stock_font(int stock_font);
int set_text_color(COLORREF color);
int set_bk_mode(int mode);
int set_pixel(int x,int y,COLORREF c);
int set_bk_color(COLORREF c);
int arc(int nLeftRect,int nTopRect,int nRightRect,int nBottomRect,
				int nXRadial1,int nYRadial1,int nXRadial2,int nYRadial2);
int set_font(LOGFONT *lf);

#ifdef __cplusplus
} //extern "C"
#endif

#define SetPixel set_pixel
#define DrawLine line
#define SetPen set_pen
#define SetBrush set_brush
#define SetStockFont set_stock_font
#define SetBkMode set_bk_mode
#define SetBkColor set_bk_color
#define SetTextColor set_text_color
#define Arc arc
#define SetFont set_font

int FillRect(CRect *r);
int SetRect(CRect *r);
int GetRect(CRect *r);
int DrawRect(CRect *r);
int DrawText(char *str,CRect *rect,DWORD format);
int Ellipse(CRect *r);
int SetSolidBrush(COLORREF color);
int SetHatchBrush(int style,COLORREF color);
int Draw3DFrame(int up_or_down,CRect *rect);
int Draw3DHLine(int x1,int x2,int y);
int Draw3DVLine(int x,int y1,int y2);
int DrawSmallTriangle(int x,int y,int dir,int triw,COLORREF color);
int Draw3DBorder(CRect *r);

#endif

]]>
</file>
<file name="graphics.cpp">
<![CDATA[
#include "graphics.h"

int GetRect(CRect *r)
{
  int i = get_self_num();
	return get_rect(i,&r->left,&r->top,&r->right,&r->bottom);	
}

int SetRect(CRect *r)
{
  int i = get_self_num();
	return set_rect(i,r->left,r->top,r->right,r->bottom);	
}

int FillRect(CRect *r)
{
    return fill_rect(r->left,r->top,r->GetWidth(),r->GetHeight());
}

int DrawRect(CRect *r)
{
	line(r->left,r->top,r->right,r->top);
	line(r->left,r->top,r->left,r->bottom);
	line(r->right,r->top,r->right,r->bottom);
	line(r->left,r->bottom,r->right+1,r->bottom);

	return OK;
}
int DrawText(char *str,CRect *rect,DWORD format)
{
	RECT r;
	
	r.left = rect->left;
	r.top = rect->top;
	r.right = rect->right;
	r.bottom = rect->bottom;
	
	draw_text(str,strlen(str),&r,format);
	
	return OK;
}

int Ellipse(CRect *r)
{
	CRect rt;
	
	rt.Copy(r);
	
	rt.Normalize();

	ellipse(rt.left,rt.top,rt.right,rt.bottom);
	
	return OK;
}
int SetSolidBrush(COLORREF color)
{
  return SetBrush(BS_SOLID,color,0);
}
int SetHatchBrush(int style,COLORREF color)
{
	return SetBrush(BS_HATCHED,color,style);
}

int Draw3DFrame(int up_or_down,CRect *rect)
{
	
	CRect r;
	
	r.Copy(rect);
	r.Normalize();
	SetSolidBrush(RGB(192,192,192));
	FillRect(&r);
	
	SetPen(PS_SOLID,0,RGB(128,128,128));
	DrawLine(r.left,r.top,r.left,r.bottom+1);
	DrawLine(r.left,r.top,r.right,r.top);
	
	if(up_or_down == FRAME3D_UP)
		SetPen(PS_SOLID,0,RGB(255,255,255));
	else
		SetPen(PS_SOLID,0,RGB(0,0,0));
		
	DrawLine(r.left+1,r.top+1,r.left+1,r.bottom);
	DrawLine(r.left+1,r.top+1,r.right,r.top+1);
	
	SetPen(PS_SOLID,0,RGB(128,128,128));
	DrawLine(r.right-1,r.top,r.right-1,r.bottom);
  DrawLine(r.right,r.bottom-1,r.left,r.bottom-1);
  if(up_or_down == FRAME3D_UP)
		SetPen(PS_SOLID,0,RGB(0,0,0));
	else
		SetPen(PS_SOLID,0,RGB(255,255,255));
	DrawLine(r.right,r.top,r.right,r.bottom);
  DrawLine(r.right,r.bottom,r.left,r.bottom);
	  
  return OK;
}  

int Draw3DHLine(int x1,int x2,int y)
{
	SetPen(PS_SOLID,0,RGB(255,255,255));	
	DrawLine(x1,y+1,x2,y+1);
	SetPen(PS_SOLID,0,RGB(128,128,128));	
	DrawLine(x1,y,x2,y);
	return OK;
}
int Draw3DVLine(int x,int y1,int y2)
{
	SetPen(PS_SOLID,0,RGB(255,255,255));	
	DrawLine(x+1,y1,x+1,y2);
	SetPen(PS_SOLID,0,RGB(128,128,128));	
	DrawLine(x,y1,x,y2);
	return OK;
}
int DrawSmallTriangle(int x,int y,int dir,int triw,COLORREF color)
{
	SetPen(PS_SOLID,0,color);	
	
	int hs = (triw + 1)/2;
	for(int i = 0; i < hs; i++)
	{
		if(dir == TRI_LEFT)DrawLine(x+triw-hs-i,y+i,triw-hs+x-i,y+triw - i); 
		else if(dir == TRI_RIGHT)DrawLine(x+i,i + y,x+i,y+triw - i);
		else if(dir == TRI_UP)DrawLine(x + triw - hs - i,y+i,x +hs + i,y+i);
		else if(dir == TRI_DOWN)DrawLine(x + i,y+i,x + triw - i,y+i);
	}
	
	return OK;
}
int Draw3DBorder(CRect *r)
{
	int x1,x2,y;
	int x,y1,y2;
		
	x1 = r->left;
	x2 = r->right;
	y = r->top;
	
	SetPen(PS_SOLID,0,RGB(128,128,128));	
	DrawLine(x1,y,x2,y);
	SetPen(PS_SOLID,0,RGB(255,255,255));	
	DrawLine(x1+1,y+1,x2-1,y+1);
	
	y = r->bottom;
	SetPen(PS_SOLID,0,RGB(128,128,128));	
	DrawLine(x1+1,y-1,x2-1,y-1);
	SetPen(PS_SOLID,0,RGB(255,255,255));	
	DrawLine(x1,y,x2,y);

	y1 = r->top;
	y2 = r->bottom;
	x = r->left;
	SetPen(PS_SOLID,0,RGB(255,255,255));	
	DrawLine(x+1,y1+1,x+1,y2-1);
	SetPen(PS_SOLID,0,RGB(128,128,128));	
	DrawLine(x,y1,x,y2);
	
	x = r->right;
	SetPen(PS_SOLID,0,RGB(255,255,255));	
	DrawLine(x,y1,x,y2+1);
	SetPen(PS_SOLID,0,RGB(128,128,128));	
	DrawLine(x-1,y1+1,x-1,y2);
	
	return OK;
}
]]>
</file>
<file name="rect.h">
<![CDATA[
#ifndef __RECT_H
#define __RECT_H

#include "common.h"

typedef struct tagRECT
{
    int    left;
    int    top;
    int    right;
    int    bottom;
} RECT, *PRECT;

class CRect{
public:
	int left,top;
	int right,bottom;
public:
	int Copy(RECT *r);
	int SetPos(int x,int y);
	int Offset(int cx,int cy);
	int SetRect(int l,int t,int r,int b);
	int IsIntersect(CRect *pr);
	int Empty();
	int PtInRect(int x,int y);
	int Normalize();
	int SetHeight(int h);
	int SetWidth(int w);
	int GetHeight();
	int GetWidth();
    CRect();
    virtual ~CRect();
    int Init();
    int Destroy();
    int Copy(CRect *p);
    int Comp(CRect *p);
    int Print();
    int InitBasic();
};
#endif 
]]>
</file>
<file name="rect.cpp">
<![CDATA[
#include "Rect.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CRect::CRect()
{
    this->InitBasic();
}
CRect::~CRect()
{
    this->Destroy();
}
int CRect::InitBasic()
{
	this->left = 0;
	this->top = 0;
	this->right = 0;
	this->bottom = 0;

    return OK;
}
int CRect::Init()
{
    this->InitBasic();
    //add your code
    return OK;
}
int  CRect::Destroy()
{
    //add your code
    this->InitBasic();
    return OK;
}
int  CRect::Copy(CRect *p)
{
	this->left = p->left;
	this->top = p->top;
	this->right = p->right;
	this->bottom = p->bottom;

    return OK;
}
int CRect::Comp(CRect *p)
{
    return 0;
}
int  CRect::Print()
{
	LOG("[%d,%d,%d,%d]",left,top,right,bottom);

    return TRUE;
}

int CRect::GetWidth()
{
	if(right >= left)
		return (right - left + 1);

	return (right - left - 1);
}

int CRect::GetHeight()
{
	if(bottom > top)
		return (bottom - top + 1);

	return (bottom - top - 1);
}

int CRect::SetWidth(int w)
{
	if(w == 0)	return OK;

	if(w > 0)
		this->right = this->left + w - 1;
	else
		this->right = this->left + w + 1;

	return OK;
}

int CRect::SetHeight(int h)
{
	if(h == 0)
		return OK;

	if(h > 0)
		this->bottom = this->top + h - 1;
	else
		this->bottom = this->top + h + 1;

	return OK;
}

int CRect::Normalize()
{
	int t;

	if(this->left > this->right)
	{
		t = this->left;
		this->left = this->right;
		this->right = t;
	}

	if(this->top > this->bottom)
	{
		t = this->bottom;
		this->bottom = this->top;
		this->top = t;
	}

	return OK;
}

int CRect::PtInRect(int x, int y)
{
	CRect r;

	r.Copy(this);
	r.Normalize();

	return ( x >= r.left && x <= r.right && y >= r.top && y <= r.bottom);
}

int CRect::Empty()
{
	return this->InitBasic();
}

int CRect::IsIntersect(CRect *pr)
{
	if(pr == NULL)
		return FALSE;
	
	CRect r1,r2;
    int left, top, right, bottom;

	r1.Copy(this);
	r2.Copy(pr);

	r1.Normalize();
	r2.Normalize();
 
    left = (r1.left > r2.left) ? r1.left : r2.left;
    top  = (r1.top > r2.top) ? r1.top : r2.top;
    right = (r1.right < r2.right) ? r1.right : r2.right;
    bottom = (r1.bottom < r2.bottom ) ? r1.bottom : r2.bottom;
    
	if(left > right || top > bottom)
        return FALSE;

    return TRUE;
}

int CRect::SetRect(int l, int t, int r, int b)
{
	this->left = l;
	this->top = t;
	this->right = r;
	this->bottom = b;

	return OK;
}

int CRect::Offset(int cx, int cy)
{
	this->left += cx;
	this->top += cy;
	this->right += cx;
	this->bottom += cy;

	return OK;
}

int CRect::SetPos(int x, int y)
{
	int w = this->GetWidth();
	int h = this->GetHeight();

	this->left = x;
	this->top = y;

	this->SetWidth(w);
	this->SetHeight(h);

	return OK;
}

int CRect::Copy(RECT *r)
{
	this->left = r->left;
	this->top = r->top;
	this->right = r->right;
	this->bottom = r->bottom;

	return OK;
}

]]>
</file>
</AllFiles>
</User>
</CommonFiles>
<AllNode isnode="true" icon="1">
<Graphics isnode="true" icon="9">
<Line isnode="true">
<code>
<![CDATA[

COLORREF color;
int width,style;

int code_0()
{
	CRect r;
	
	GetRect(&r);
	
	printf("Line %d,%d,%d,%d,%d,%d,%d\n",r.left,r.top,r.right,r.bottom,width,style,color);
	
	return OK;
}
int code(int code_num)
{
	switch(code_num)
	{
		case 0:code_0();break;
	}
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r;

	GetRect(&r);
	
	SetPen(style,width,color);
	DrawLine(r.left,r.top,r.right,r.bottom);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
color = RGB(0,0,0);
width = 1;
style = 0;
/*****
style
0 = SOLID
1 = DASH
2 = DOT
3 = DASHDOT
4 = PS_DASHDOTDOT
*****/
]]>
</default>
</Line>
<Rect isnode="true">
<code>
<![CDATA[

COLORREF border_color;
COLORREF fill_color;
int pen_style,pen_width;
int fill_obj;
int has_border;

int code_0()
{
	CRect r;
	
	GetRect(&r);
	
	printf("Rect %d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
					r.left,r.top,r.right,r.bottom,
					pen_style,pen_width,
					has_border,fill_obj,
					border_color,fill_color);
					
	return OK;
}
int code(int code_num)
{
	switch(code_num)
	{
		case 0:code_0();break;
	}
  return OK;
}

int before_draw()
{
	return OK;
}

int draw()
{
	CRect r;
	
	GetRect(&r);

	if(fill_obj)
	{
		SetSolidBrush(fill_color);
		FillRect(&r);
	}
	
	if(has_border)
	{
		SetPen(pen_style,pen_width,border_color);
		DrawRect(&r);
	}
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
has_border = 1;
pen_width = 0;
border_color = RGB(0,0,0);
pen_style = 0;
/*****
pen_style
0 = SOLID
1 = DASH
2 = DOT
3 = DASHDOT
4 = PS_DASHDOTDOT
*****/

fill_obj = 1;
fill_color = RGB(250,210,210);
]]>
</default>
</Rect>
<HorzLine isnode="true">
<code>
<![CDATA[

COLORREF color;
int style,width;

int code_0()
{
	CRect r;
	
	GetRect(&r);
	
	printf("HLine %d,%d,%d,%d,%d,%d\n",r.left,r.top,r.right,style,width,color);
	
	return OK;
}
int code(int code_num)
{
	switch(code_num)
	{
		case 0: code_0();break;
	}
  return OK;
}

int before_draw()
{
	return OK;
}

int draw()
{
	CRect r,rt;
	
	GetRect(&r);
  r.Normalize();
  rt.Copy(&r);
  
  rt.bottom = rt.top + 6;
 	SetRect(&rt);

	SetPen(style,width,color);
	
	DrawLine(r.left,r.top,r.right,r.top);
		
	return OK;
}
]]>
</code>
<default>
<![CDATA[
color = RGB(0,0,0);
width = 1;
style = 0;
/*****
style
0 = SOLID
1 = DASH
2 = DOT
3 = DASHDOT
4 = PS_DASHDOTDOT
*****/

]]>
</default>
</HorzLine>
<VertLine isnode="true">
<code>
<![CDATA[

COLORREF color;
int style,width;

int code_0()
{
	CRect r;
	
	GetRect(&r);
	
	printf("VLine %d,%d,%d,%d,%d,%d\n",r.left,r.top,r.bottom,style,width,color);
	
	return OK;
}
int code(int code_num)
{
	switch(code_num)
	{
		case 0:code_0();break;
	}
  return OK;
}

int before_draw()
{
	return OK;
}

int draw()
{
	CRect r,rt;
	
	GetRect(&r);
  r.Normalize();
  rt.Copy(&r);
  
  rt.right = rt.left + 6;
 	SetRect(&rt);
	SetPen(style,width,color);
	DrawLine(r.left,r.top,r.left,r.bottom);
		
	return OK;
}
]]>
</code>
<default>
<![CDATA[
color = RGB(0,0,0);
width = 1;
style = 0;
/*****
style
0 = SOLID
1 = DASH
2 = DOT
3 = DASHDOT
4 = PS_DASHDOTDOT
*****/
]]>
</default>
</VertLine>
<Label isnode="true">
<code>
<![CDATA[
char *text;
LOGFONT log_font;
int has_border;
COLORREF border_color,text_color;

int code(int code_num)
{
  return OK;
}

int before_draw()
{
	return OK;
}

int draw()
{
	CRect r;
	
	GetRect(&r);
	
	r.Normalize();
	
	SetBkMode(TRANSPARENT);
	SetTextColor(text_color);
	SetFont(&log_font);
	DrawText(text,&r,DT_WORDBREAK);
	
	if(has_border)
	{
		SetPen(PS_SOLID,0,border_color);
		DrawRect(&r);
	}
	return OK;
}
]]>
</code>
<default>
<![CDATA[
text = "Label";
text_color = RGB(0,0,0);
has_border = 0;
border_color = RGB(0,0,0);
/***log font***/
log_font.lfHeight = -16;
log_font.lfWidth = 0;
log_font.lfEscapement = 0;
log_font.lfWeight = 400;
log_font.lfItalic = 0;
log_font.lfUnderline = 0;
log_font.lfStrikeOut = 0;
strcpy(log_font.lfFaceName,"Arial");
/**************/

]]>
</default>
</Label>
<Ellipse isnode="true">
<code>
<![CDATA[

COLORREF border_color;
COLORREF fill_color;
int pen_style,pen_width;
int fill_obj;
int has_border;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r;
	
	GetRect(&r);

	r.Normalize();
	
	if(fill_obj)
	{
		SetSolidBrush(fill_color);
		Ellipse(&r);
	}
	
	if(has_border)
	{
		SetPen(pen_style,pen_width,border_color);
		Arc(r.left,r.top,r.right,r.bottom,r.left,r.top,r.left,r.top);
	}
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
has_border = 1;
pen_width = 0;
border_color = RGB(0,0,0);
pen_style = 0;
/*****
pen_style
0 = SOLID
1 = DASH
2 = DOT
3 = DASHDOT
4 = PS_DASHDOTDOT
*****/

fill_obj = 1;
fill_color = RGB(250,210,210);
]]>
</default>
</Ellipse>
</Graphics>
<Controls isnode="true" icon="6">
<HLine_3D isnode="true">
<code>
<![CDATA[

char *var;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r,rt;
		
	GetRect(&r);
  r.Normalize();
  rt.Copy(&r);
  
  rt.bottom = rt.top + 6;
 	SetRect(&rt);
 	
	Draw3DHLine(r.left,r.right,r.top);
		
	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="st_";
]]>
</default>
</HLine_3D>
<VLine_3D isnode="true">
<code>
<![CDATA[

char *var;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r,rt;
		
	GetRect(&r);
  r.Normalize();
  rt.Copy(&r);
  
  rt.right= rt.left + 6;
 	SetRect(&rt);
 	
	Draw3DVLine(r.left,r.top,r.bottom);
		
	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="st_";
]]>
</default>
</VLine_3D>
<Static isnode="true">
<code>
<![CDATA[
char *hparent;
char *var,*caption;
int align;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
	SetPen(PS_DOT,0,RGB(212,212,212));
	DrawRect(&r);
	
	SetTextColor(RGB(0,0,0));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	if(align == 1)DrawText(caption,&r,DT_SINGLELINE);
	if(align == 2)DrawText(caption,&r,DT_RIGHT|DT_SINGLELINE);
	if(align == 3)DrawText(caption,&r,DT_CENTER|DT_SINGLELINE);

	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="st_";
caption = "static";
hparent="hwnd";
align = 1;

/******
align
1 = Left
2 = Right
3 = Center
******/

]]>
</default>
</Static>
<EditBox isnode="true">
<code>
<![CDATA[
char *hparent;
char *var;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
		
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
	Draw3DFrame(FRAME3D_DOWN,&r);
	
	r.left += 2;r.top +=2;
	r.right -= 2; r.bottom -=2;
	
	SetSolidBrush(RGB(255,255,255));	
	FillRect(&r);

	SetTextColor(RGB(212,212,212));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText("Text Box",&r,NULL);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="pb_";
hparent="hwnd";

]]>
</default>
</EditBox>
<Button isnode="true" icon="21">
<code>
<![CDATA[
char *caption,*hparent;
char *var;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
	Draw3DFrame(FRAME3D_UP,&r);
		
	SetTextColor(RGB(0,0,0));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText(caption,&r,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="pb_";
caption="button";
hparent="hwnd";

]]>
</default>
</Button>
<HScrollBar isnode="true">
<code>
<![CDATA[
int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r,rt;
	int ml,mr,hw,triw;
	
	GetRect(&r);
	r.Normalize();
	
	rt.Copy(&r);
	rt.right = rt.left + 16;
	hw = r.GetWidth()/2;
	if(rt.right > r.left + hw)
		rt.right = r.left + hw;
	ml = rt.right + 1;	
	
	Draw3DFrame(FRAME3D_UP,&rt);
	triw = 5;
	if(triw > rt.GetWidth())triw =  rt.GetWidth();
	if(triw > rt.GetHeight())triw =  rt.GetHeight();
		
	DrawSmallTriangle(rt.left+(rt.GetWidth()-triw/2)/2,rt.top+(rt.GetHeight()-triw)/2,
	                  TRI_LEFT,triw,RGB(0,0,0));	
	
	rt.Copy(&r);
	rt.left = rt.right - 16;
	if(rt.left < r.left + hw)
		rt.left = r.left + hw;		
	mr = rt.left - 1;	
	Draw3DFrame(FRAME3D_UP,&rt);

	DrawSmallTriangle(rt.left+(rt.GetWidth()-triw/2)/2,rt.top+(rt.GetHeight()-triw)/2,
	                  TRI_RIGHT,triw,RGB(0,0,0));	
		
	rt.Copy(&r);
	rt.left = ml;
	rt.right = mr;
	
	SetSolidBrush(RGB(128,128,128));
	FillRect(&rt);
	
	rt.right = ml + 30;
	if(rt.right > mr)
		rt.right = mr;	
	Draw3DFrame(FRAME3D_UP,&rt);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
//test
]]>
</default>
</HScrollBar>
<VScrollBar isnode="true">
<code>
<![CDATA[
int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r,rt;
	int mt,mb,hw,triw;
	
	GetRect(&r);
	r.Normalize();
	
	rt.Copy(&r);
	rt.bottom = rt.top + 16;
	hw = r.GetHeight()/2;
	if(rt.bottom > r.top + hw)
		rt.bottom = r.top + hw;
	mt = rt.bottom + 1;	
	
	Draw3DFrame(FRAME3D_UP,&rt);
	triw = 5;
	if(triw > rt.GetWidth())triw =  rt.GetWidth();
	if(triw > rt.GetHeight())triw =  rt.GetHeight();
		
	DrawSmallTriangle(rt.left+(rt.GetWidth()-triw)/2,rt.top+(rt.GetHeight()-triw/2)/2,
	                  TRI_UP,triw,RGB(0,0,0));	
	
	rt.Copy(&r);
	rt.top = rt.bottom -16;
	if(rt.top < r.top + hw)
		rt.top = r.top + hw;		
	mb = rt.top - 1;	
	Draw3DFrame(FRAME3D_UP,&rt);

	DrawSmallTriangle(rt.left+(rt.GetWidth()-triw)/2,rt.top+(rt.GetHeight()-triw/2)/2,
	                  TRI_DOWN,triw,RGB(0,0,0));	
		
	rt.Copy(&r);
	rt.top = mt;
	rt.bottom = mb;
	
	SetSolidBrush(RGB(128,128,128));
	FillRect(&rt);
	
	rt.bottom = mt + 30;
	if(rt.bottom > mb)
		rt.bottom = mb;	
	Draw3DFrame(FRAME3D_UP,&rt);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
//test
]]>
</default>
</VScrollBar>
<CheckBox isnode="true">
<code>
<![CDATA[
char *hparent;
char *var;
char *caption;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
		
	CRect r,rt;
	int bs = 10;
	
	GetRect(&r);
	r.Normalize();
	
	rt.left = r.left;
	rt.right = r.left + bs;
	rt.top = r.top + (r.GetHeight() - bs)/2;
	rt.bottom = rt.top + bs;
	
	SetPen(PS_DOT,0,RGB(212,212,212));
	DrawRect(&r);

	Draw3DFrame(FRAME3D_DOWN,&rt);
	SetSolidBrush(RGB(255,255,255));
	
	rt.left += 2;
	rt.right -= 2;
	rt.top += 2;
	rt.bottom -= 2;
			
	FillRect(&rt);
	
	rt.Copy(&r);
	r.left += (bs + 3);
	
	SetTextColor(RGB(0,0,0));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText(caption,&r,DT_VCENTER|DT_SINGLELINE);

	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="pb_";
hparent="hwnd";
caption = "CheckBox";
]]>
</default>
</CheckBox>
<RadioBox isnode="true">
<code>
<![CDATA[
char *hparent;
char *var;
char *caption;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
		
	CRect r,rt;
	int bs = 11;
	
	GetRect(&r);
	r.Normalize();
	
	SetPen(PS_DOT,0,RGB(212,212,212));
	DrawRect(&r);
	
	rt.left = r.left;
	rt.right = r.left + bs;
	rt.top = r.top + (r.GetHeight() - bs)/2;
	rt.bottom = rt.top + bs;	
		
	SetPen(PS_SOLID,0,RGB(255,255,255));
	SetSolidBrush(RGB(255,255,255));
	Ellipse(&rt);
	SetPen(PS_SOLID,0,RGB(128,128,128));
	Arc(rt.left,rt.top,rt.right,rt.bottom,
			rt.right,rt.top,rt.left,rt.bottom);
	rt.left += 1;rt.top += 1;
	rt.right -= 1;rt.bottom -=1;
	SetPen(PS_SOLID,0,RGB(0,0,0));
	Arc(rt.left,rt.top,rt.right,rt.bottom,
			rt.right,rt.top,rt.left,rt.bottom);			
	SetPen(PS_SOLID,0,RGB(128,128,128));
	Arc(rt.left,rt.top,rt.right,rt.bottom,
			rt.left,rt.bottom,rt.right,rt.top);			
	
	rt.Copy(&r);
	r.left += (bs + 3);
	
	SetTextColor(RGB(0,0,0));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText(caption,&r,DT_VCENTER|DT_SINGLELINE);

	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="rb_";
hparent="hwnd";
caption = "Radio";
]]>
</default>
</RadioBox>
<GroupBox isnode="true">
<code>
<![CDATA[
char *caption;
int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r,rt;
	GetRect(&r);
	r.Normalize();
	
	rt.Copy(&r);
	rt.top += 6;
	Draw3DBorder(&rt);
	rt.Copy(&r);
	rt.left += 8;
	SetTextColor(RGB(0,0,0));
	SetBkColor(RGB(192,192,192));
	SetBkMode(OPAQUE);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText(caption,&rt,DT_SINGLELINE);

	return OK;
}
]]>
</code>
<default>
<![CDATA[
caption = "GroupBox";
]]>
</default>
</GroupBox>
<ListBox isnode="true">
<code>
<![CDATA[
char *hparent;
char *var;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
		
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
	Draw3DFrame(FRAME3D_DOWN,&r);
	
	r.left += 2;r.top +=2;
	r.right -= 2; r.bottom -=2;
	
	SetSolidBrush(RGB(255,255,255));	
	FillRect(&r);
	int item_height = 15;
	
	int max_line = r.GetHeight() / item_height;
	
	SetPen(PS_SOLID,0,RGB(212,212,212,212));
	for(int i = 1; i<=max_line; i++)
	{
		DrawLine(r.left, r.top + i * item_height,r.right,r.top + i * item_height);
	}
	SetTextColor(RGB(212,212,212));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText("List Box",&r,NULL);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="pb_";
hparent="hwnd";

]]>
</default>
</ListBox>
<ComboBox isnode="true" icon="3">
<code>
<![CDATA[
char *hparent;
char *var;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r,rt;
	
	GetRect(&r);
	r.Normalize();
	
	SetPen(PS_DOT,0,RGB(212,212,212));
	DrawRect(&r);
	
	rt.Copy(&r);
	rt.bottom = r.top + 20;
	if(rt.bottom > r.bottom)
		rt.bottom = r.bottom;
		
	Draw3DFrame(FRAME3D_DOWN,&rt);
	
	rt.left += 2;rt.top +=2;
	rt.right -= 2; rt.bottom -= 2;
	
	SetSolidBrush(RGB(255,255,255));	
	FillRect(&rt);
	
	rt.left = rt.right - 16;
	if(rt.left < r.left)
		rt.left = r.left;
	Draw3DFrame(FRAME3D_UP,&rt);
	
	int triw = 5;
	DrawSmallTriangle(rt.left+(rt.GetWidth()-triw)/2,rt.top+(rt.GetHeight()-triw/2)/2,
	                  TRI_DOWN,triw,RGB(0,0,0));	
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
var="pb_";
hparent="hwnd";

]]>
</default>
</ComboBox>
</Controls>
<Windows isnode="true" icon="2">
<Dialog isnode="true">
<code>
<![CDATA[
char *var,*caption,*parent;
char *class_name;
int on_msg[100];

void on_msg_code_header()
{
	if(on_msg[0])printf("    int OnCreate(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[1])printf("    int OnClose(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[2])printf("    int OnPaint(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[3])printf("    int OnSize(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[4])printf("    int OnCommand(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[5])printf("    int OnNotify(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[6])printf("    int OnLButtonDown(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[7])printf("    int OnLButtonUp(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[8])printf("    int OnRButtonDown(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[9])printf("    int OnRButtonUp(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[10])printf("    int OnScroll(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[11])printf("    int OnMouseMove(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[12])printf("    int OnChar(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[13])printf("    int OnKeyDown(WPARAM wparam, LPARAM lparam);\n");
	if(on_msg[14])printf("    int OnPosChanged(WPARAM wparam, LPARAM lparam);\n");	
}

void on_msg_code_body()
{
	if(on_msg[0])printf("int %s::OnCreate(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[1])printf("int %s::OnClose(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[2])printf("int %s::OnPaint(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[3])printf("int %s::OnSize(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[4])printf("int %s::OnCommand(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);				
	if(on_msg[5])printf("int %s::OnNotify(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[6])printf("int %s::OnLButtonDown(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[7])printf("int %s::OnLButtonUp(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[8])printf("int %s::OnRButtonDown(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[9])printf("int %s::OnRButtonUp(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);				
	if(on_msg[10])printf("int %s::OnScroll(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[11])printf("int %s::OnMouseMove(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[12])printf("int %s::OnChar(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[13])printf("int %s::OnKeyDown(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);
	if(on_msg[14])printf("int %s::OnPosChanged(WPARAM wparam, LPARAM lparam)\n{\n    return OK;\n}\n",class_name);				
}
void code_0()
{
	printf("#include \"wnd.h\"\n\n");
	printf("class %s:public CWnd{\n",class_name);
	printf("public:\n");
	printf("public:\n");
	printf("    %s();\n",class_name);
	printf("    virtual ~%s();\n",class_name);
	printf("    int Init();\n");
	printf("    int Destroy();\n");
	printf("    int InitBasic();\n");
	on_msg_code_header();
	printf("};\n");
}
void code_1()
{
	printf("%s::%s()\n",class_name,class_name);
	printf("{\n");
	printf("    this->InitBasic();\n");
	printf("}\n");
	printf("%s::~%s()\n",class_name,class_name);
	printf("{\n");
	printf("    this->Destroy();\n");
	printf("}\n");
	printf("int %s::InitBasic()\n",class_name);
	printf("{\n");
	printf("    CWnd::InitBasic();\n");
	printf("    return OK;\n");
	printf("}\n");
	printf("int %s::Init()\n",class_name);
	printf("{\n");
	printf("    this->InitBasic();\n");
	printf("    CWnd::Init();\n");
	printf("    //add your code\n");
	printf("    return OK;\n");
	printf("}\n");
	printf("int  %s::Destroy()\n",class_name);
	printf("{\n");
	printf("    //add your code\n");
	printf("    CWnd::Destroy();\n");
	printf("    this->InitBasic();\n");
	printf("    return OK;\n");
	printf("}\n");

	on_msg_code_body();
}

void code_2()
{
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
  printf("\n%s *%s;\n",class_name,var);
  printf("NEW(%s,%s);\n",var,class_name);
  printf("%s->Init();\n",var);
  printf("%s->MoveWindow(0,0,%d,%d);\n",var,r.GetWidth(),r.GetHeight());
  printf("%s->SetText(\"%s\");\n",var,caption);
  printf("%s->SetParent(%s);\n",var,parent);
  
  printf("%s->Create();\n",var);
}
int code(int code_num)
{
	switch(code_num)
	{
		case 0: code_0();break;
		case 1: code_1();break;
		case 2: code_2();break;
	}
  return OK;
}
int before_draw()
{
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
	r.right -= r.left;
	r.bottom -= r.top;
	r.left = 0;
	r.top = 0;
	
	SetRect(&r);
	
	return OK;
}
int draw()
{
		
	CRect r;
	
	GetRect(&r);
	r.Normalize();
	
	Draw3DFrame(FRAME3D_UP,&r);

	CRect rt;
	rt.Copy(&r);
	rt.left += 2;rt.top+=2;
	rt.right -= 2; 

	if(rt.bottom > 20)
		rt.bottom = rt.top + 18;
		
	SetSolidBrush(RGB(75,80,253));
	FillRect(&rt);
	
	SetTextColor(RGB(255,255,255));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText(caption,&rt,DT_VCENTER|DT_SINGLELINE);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
class_name="CWnd";
var = "wnd_";
caption = "Hello";
parent="hwnd";

/***messages need to response***/
on_msg[0]=1;    //WM_CREATE
on_msg[1]=1;    //WM_CLOSE
on_msg[2]=0;    //WM_PAINT
on_msg[3]=1;    //WM_SIZE
on_msg[4]=1;    //WM_COMMAND
on_msg[5]=0;    //WM_NOTIFY
on_msg[6]=0;    //WM_LBUTTONDOWN
on_msg[7]=0;    //WM_LBUTTONUP
on_msg[8]=0;    //WM_RBUTTONDOWN
on_msg[9]=0;    //WM_RBUTTONUP
on_msg[10]=0;   //WM_HSCROLL & WM_VSCROLL
on_msg[11]=0;   //WM_MOUSEMOVE
on_msg[12]=0;   //WM_CHAR
on_msg[13]=0;   //WM_KEYDOWN
on_msg[14]=0;   //WM_WINDOWPOSCHANGED

]]>
</default>
</Dialog>
<Test isnode="true">
<code>
<![CDATA[
int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	return OK;
}

]]>
</code>
<default>
<![CDATA[
//test
]]>
</default>
</Test>
</Windows>
<Math isnode="true" icon="15">
<FunctionCurve isnode="true">
<code>
<![CDATA[
float x,y;
int zoom_in_x;
int zoom_in_y;
float step,start_x,end_x;

#define FUNC(a,b) {x=a;_init_attrib();b=y;}

int code(int code_num)
{
  return OK;
}

int SetPixel(CRect *r,float x,float y)
{
	int x0 = r->left + r->GetWidth()/2;
	int y0 = r->top + r->GetHeight()/2;
	
	SetPixel(x0 + (int)(x * (float)zoom_in_x),y0 - (int)(y * (float)zoom_in_y),RGB(255,0,0));
	
	return OK;
}
int DrawAxis(CRect *r)
{
	SetPen(PS_SOLID,0,RGB(0,0,255));
	DrawLine(r->left,r->top + r->GetHeight()/2,r->right,r->top + r->GetHeight()/2);
	DrawLine(r->left + r->GetWidth()/2,r->top,r->left + r->GetWidth()/2,r->bottom);
	return OK;
}
int DrawCurve(CRect *r)
{
	float yy;
	
	int x0 = r->left + r->GetWidth()/2;
	int y0 = r->top + r->GetHeight()/2;
	
	float m_start = (float)(r->left - x0) / zoom_in_x;
	float m_end = (float)(r->right - x0) / zoom_in_x;
	
	float x1,x2;
	
	x1 = start_x;
	x2 = end_x;
	
	if(start_x < m_start)
		x1 = m_start;
	if(end_x > m_end)
		x2 = m_end;

	for(float i = x1; i<= x2; i+= step)
	{
		FUNC(i,yy);
		SetPixel(r,i,yy);
	}
	return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r;
	GetRect(&r);
	r.Normalize();
	
	DrawAxis(&r);
	DrawCurve(&r);
	
	return OK;
}
]]>
</code>
<default>
<![CDATA[
//this is the function you will draw
y = sin(x); 

zoom_in_x = 20;
zoom_in_y = 20;
step = 0.05;
start_x = -9999.0;
end_x = 9999.0;

]]>
</default>
</FunctionCurve>
<Calculator isnode="true">
<code>
<![CDATA[
double x;

int code(int code_num)
{
  return OK;
}
int before_draw()
{
	return OK;
}
int draw()
{
	CRect r;
	GetRect(&r);
	r.Normalize();
	
	_init_attrib(); //calculate;
	
	char buf[1024];
	sprintf(buf,"x = %f",x);
	
	SetTextColor(RGB(255,0,0));
	SetBkMode(TRANSPARENT);
	SetStockFont(DEFAULT_GUI_FONT);
	DrawText(buf,&r,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	
	return OK;
}

]]>
</code>
<default>
<![CDATA[
//write your expression
x = sin(1.2);
]]>
</default>
</Calculator>
</Math>
</AllNode>
</WorkShop>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
China China
26 years old, 2 years work experience.

Comments and Discussions