Another JWASM 32bit gtk example

Started by jcfuller, December 17, 2009, 02:46:59 PM

Previous topic - Next topic

jcfuller

Another jwasm 32bit linux gtk example using HUG (High-level Universal GUI).
HUG is a BaCon project I ported to Jwasm and is still in it's infancy. That is why just the library is included in the zip. The original (BaCon & Jwasm) is changing daily and when it is finalized I will release the source.

I want to thank Raymond Filiatreault for giving permission to include his jwasm 32bit linux compiled floating point library with this demo.

I know the coding is not very good but it does get the job done :)

I am a high-level programmer who dislikes c nomenclature but does like the masm/jwasm high level style. You will not find me tweaking routines to reduce cycle counts!!

The include files in the zip were produced by a little utility I wrote and have not been tested very extensively so use at your own risk.

You will need libgtk2.0-dev installed.


James


;=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
;Jwasm Linux 32bit HUG Test
;see HUG.TXT
;
;James C. Fuller 12-17-2009
;------------------------------------------------------------------------------
;compile: ~/jwasm/JWASM -elf -zcw -Fo ht05_2.o ht05_2.asm
;;link: gcc -o ht05_2 ht05_2.o -I/lib/ld-linux.so.2 -L./ -lhuglib -ldl -ljfpulib `pkg-config --cflags --libs gtk+-2.0`
;=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
   
    .486
    .model flat,c
option casemap:none

include ./jwasm.inc
include ./fpu.inc
include ./huglib.inc


MaxIters equ 100
xSize equ     480
ySize equ    330

.data
dtLeft dt -2.0
dtRight dt 1.0
dtTop dt 1.0
dtBot dt -1.0
g_start_but dd 0
g_clear_but dd 0
PixelCol db "#800000",0, "#800080",0, "#8000FF",0, "#808000",0, "#808080",0, "#8080FF",0, "#80FF00",0, "#80FF80",0, \
    "#80FFFF",0, "#FF0000",0, "#FF0080",0, "#FF00FF",0, "#FF8000",0, "#FF8080",0, "#FF80FF",0, "#FFFF00",0
.code
;==============================================================================
quit_prog proc
invoke QUIT
ret
quit_prog endp
;==============================================================================
Draw_Fractal proc
    local x:SDWORD, y:SDWORD, count:SWORD
    local zr:REAL10, zi:REAL10, cr:REAL10, ci:REAL10
    local rsquared:REAL10, isquared:REAL10
    local t1:REAL10
    local dw1:DWORD
    local buf[32]:PTR BYTE
   
   
    invoke DISABLE,g_start_but
    invoke DISABLE,g_clear_but
   
    invoke LOUT,CStr("Please wait..."),CStr("#0000FF"),CStr("#FFFFFF"), 10, 300
    mov y,0
    mov x,0

.while(y < 331)
.while(x < 481)
invoke FpuAtoFL,CStr("0.0"),addr zr,DEST_MEM
invoke FpuAtoFL,CStr("0.0"),addr zi,DEST_MEM
invoke FpuAtoFL,CStr("0.0"),addr rsquared,DEST_MEM
invoke FpuAtoFL,CStr("0.0"),addr isquared,DEST_MEM
;****************************************
;cr = Left + x * (Right - Left) / xSize
;****************************************
invoke FpuSub,offset dtRight,offset dtLeft,0,SRC1_REAL OR SRC2_REAL OR DEST_FPU
invoke FpuMul,0,x,0,SRC1_FPU OR SRC2_DIMM OR DEST_FPU
invoke FpuDiv,0,xSize,0,SRC1_FPU OR SRC2_DIMM OR DEST_FPU
invoke FpuAdd,0,addr dtLeft,addr cr,SRC1_FPU OR SRC2_REAL
;***************************************
;ci = Top + y * (Bottom - Top) / ySize
;***************************************
invoke FpuSub,offset dtBot,offset dtTop,0,SRC1_REAL OR SRC2_REAL OR DEST_FPU
invoke FpuMul,0,y,0, SRC1_FPU OR SRC2_DIMM OR DEST_FPU
invoke FpuDiv,0,ySize,0,SRC1_FPU OR SRC2_DIMM OR DEST_FPU
invoke FpuAdd,0,offset dtTop,addr ci, SRC1_FPU OR SRC2_REAL
;******************
;rsquared = zr * zr
;******************
invoke FpuMul,addr zr,addr zr,addr rsquared,SRC1_REAL OR SRC2_REAL
;******************
;isquared = zi * zi
;******************
invoke FpuMul,addr zi,addr zi,addr isquared,SRC1_REAL OR SRC2_REAL

.while(count < 101)
;****************
;zi = zr * zi * 2
;****************
invoke FpuMul,addr zr,addr zi,0,SRC1_REAL OR SRC2_REAL OR DEST_FPU
invoke FpuMul,0,2,addr zi,SRC1_FPU OR SRC2_DIMM
;**************
;zi = zi + ci
;**************
invoke FpuAdd,addr zi,addr ci,addr zi,SRC1_REAL OR SRC2_REAL
;************************
;zr = rsquared - isquared
;************************
invoke FpuSub,addr rsquared,addr isquared,addr zr,SRC1_REAL OR SRC2_REAL
;**************
;zr = zr + cr
;**************
invoke FpuAdd,addr zr,addr cr,addr zr,SRC1_REAL OR SRC2_REAL
;******************
;rsquared = zr * zr
;******************
invoke FpuMul,addr zr,addr zr,addr rsquared,SRC1_REAL OR SRC2_REAL
;******************
;isquared = zi * zi
;******************
invoke FpuMul,addr zi,addr zi,addr isquared,SRC1_REAL OR SRC2_REAL
    add count,1
.endw
invoke FpuAdd,addr rsquared,addr isquared,addr t1,SRC1_REAL OR SRC2_REAL
invoke FpuComp,addr t1,4,SRC1_REAL OR SRC2_DIMM
or eax,eax
.if eax == CMP_LOWER
invoke FpuMul,addr t1,4,0,SRC1_REAL OR SRC2_DIMM OR DEST_FPU
invoke FpuRound,0,addr dw1,SRC1_FPU OR DEST_IMEM

mov eax,dw1
imul eax,8
mov ebx,offset PixelCol
add ebx,eax
invoke PIXEL,ebx,x,y
.endif

    add x,1
    mov count,0
.endw
add y,1
mov x,0
.endw
invoke SQUARE,CStr("#FFFFFF"), 10, 300, 100, 30, 1
invoke LOUT,CStr("Drawing ready."),CStr("#0000FF"),CStr("#FFFFFF"), 10, 300

    invoke ENABLE,g_start_but
    invoke ENABLE,g_clear_but


ret
Draw_Fractal endp
;==============================================================================
Clear_Fractal proc
invoke SQUARE,CStr("#FFFFFF"), 0, 0, 480, 330, 1
ret
Clear_Fractal endp
;==============================================================================
main proc
local mainwin,quit_but,frame,start_but,clear_but,labl
local canvas

;Must be called first
invoke hug_init
;Create a Window
invoke WINDOW,CStr("Drawing a fractal"),500,400
mov mainwin,eax
;Create and attach a frame
invoke FRAME,490, 340
mov frame,eax
invoke ATTACH,mainwin, frame, 5, 5
;Create and Attach a Canvas drwaing area
invoke CANVAS,480, 330
mov canvas,eax
invoke ATTACH,mainwin, canvas, 10, 10
;Create a Stock Button
invoke STOCK,CStr("gtk-execute"), 100, 40
mov start_but,eax
mov g_start_but,eax
invoke ATTACH,mainwin, start_but, 5, 355
invoke CALLBACK,start_but, offset Draw_Fractal
;Create another
invoke STOCK,CStr("gtk-clear"), 100, 40
mov clear_but,eax
mov g_clear_but,eax
invoke ATTACH,mainwin, clear_but, 120, 355
invoke CALLBACK,clear_but, offset Clear_Fractal
;Create quit button
invoke STOCK,CStr("gtk-quit"), 100, 40
mov quit_but,eax
invoke ATTACH,mainwin,quit_but,395, 355
invoke CALLBACK,quit_but, offset quit_prog

;Create a label
invoke TEXT,CStr("H.U.G. for JWasm!"), 120, 40
mov labl,eax
invoke ATTACH,mainwin, labl, 240, 355

;Show the Window

invoke DISPLAY

ret
main endp
end







dedndave

QuoteYou will not find me tweaking routines to reduce cycle counts!!

blasphemer !!!   :eek