From 3a4ecad384920e1034ade7296ab41a1fd6631249 Mon Sep 17 00:00:00 2001 From: IgorA Date: Tue, 4 Nov 2014 23:31:24 +0000 Subject: [PATCH] add list operations git-svn-id: svn://kolibrios.org@5171 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../TinyGL/asm_fork/examples/test2.asm | 183 +++++++++ .../libraries/TinyGL/asm_fork/init.asm | 8 +- .../libraries/TinyGL/asm_fork/list.asm | 367 ++++++++++++------ .../libraries/TinyGL/asm_fork/tinygl.asm | 10 +- .../develop/libraries/TinyGL/asm_fork/zgl.inc | 5 +- 5 files changed, 438 insertions(+), 135 deletions(-) create mode 100644 programs/develop/libraries/TinyGL/asm_fork/examples/test2.asm diff --git a/programs/develop/libraries/TinyGL/asm_fork/examples/test2.asm b/programs/develop/libraries/TinyGL/asm_fork/examples/test2.asm new file mode 100644 index 0000000000..105eef20bb --- /dev/null +++ b/programs/develop/libraries/TinyGL/asm_fork/examples/test2.asm @@ -0,0 +1,183 @@ +use32 + org 0x0 + db 'MENUET01' + dd 0x1 + dd start + dd i_end + dd mem,stacktop + dd 0,cur_dir_path + +include '../../../../../../programs/proc32.inc' +include '../../../../../../programs/macros.inc' +include '../../../../../../programs/develop/libraries/box_lib/load_lib.mac' +include '../../../../../../programs/dll.inc' +include '../opengl_const.inc' + +@use_library + +align 4 +start: + load_library name_tgl, cur_dir_path, library_path, system_path, \ + err_message_found_lib, head_f_l, import_lib_tinygl, err_message_import, head_f_i + cmp eax,-1 + jz button.exit + + mcall 40,0x27 + +stdcall [kosglMakeCurrent], 10,10,300,225,ctx1 +stdcall [glEnable], GL_DEPTH_TEST + +stdcall [glGenLists],1 +mov [obj1],eax +stdcall [glNewList],eax,GL_COMPILE +;--- + stdcall [glColor3f],1.0, 0.0, 0.0 + stdcall [glBegin],GL_LINE_LOOP + stdcall [glVertex3f], 0, 0.9, 0.1 + stdcall [glVertex3f], 0.636, 0.636, 0.1 + stdcall [glVertex3f], 0.9, 0.0, 0.1 + stdcall [glVertex3f], 0.636, -0.636, 0.1 + stdcall [glVertex3f], 0.0, -0.9, 0.1 + stdcall [glVertex3f], -0.636,-0.636, 0.1 + stdcall [glVertex3f], -0.9, 0.0, 0.1 + stdcall [glVertex3f], -0.636, 0.636, 0.1 + call [glEnd] + + stdcall [glColor3f],0.0, 0.0, 1.0 + stdcall [glBegin],GL_LINE_LOOP + stdcall [glVertex3f], 0.0, 1.1, 0.1 + stdcall [glVertex3f], 0.778, 0.778, 0.1 + stdcall [glVertex3f], 2.1, 0.0, 0.1 + stdcall [glVertex3f], 0.778, -0.778, 0.1 + stdcall [glVertex3f], 0.0, -1.1, 0.1 + stdcall [glVertex3f], -0.778, -0.778, 0.1 + stdcall [glVertex3f], -2.1, 0.0, 0.1 + stdcall [glVertex3f], -0.778, 0.778, 0.1 + call [glEnd] +;--- +call [glEndList] + +call draw_3d + +align 4 +red_win: + call draw_window + +align 4 +still: + mcall 10 + cmp al,1 + jz red_win + cmp al,2 + jz key + cmp al,3 + jz button + jmp still + +align 4 +draw_window: + pushad + mcall 12,1 + + mov edx,0x33ffffff ;0x73ffffff + mcall 0,(50 shl 16)+330,(30 shl 16)+275,,,caption + stdcall [kosglSwapBuffers] + + mcall 12,2 + popad + ret + +align 4 +key: + mcall 2 + + cmp ah,27 ;Esc + je button.exit + + ;178 ;Up + ;177 ;Down + cmp ah,176 ;Left + jne @f + fld dword[angle_z] + fadd dword[delt_size] + fstp dword[angle_z] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + cmp ah,179 ;Right + jne @f + fld dword[angle_z] + fsub dword[delt_size] + fstp dword[angle_z] + call draw_3d + stdcall [kosglSwapBuffers] + @@: + + jmp still + +align 4 +button: + mcall 17 + cmp ah,1 + jne still +.exit: + mcall -1 + + +align 4 +caption db 'Test tinygl library, [Esc] - exit, [<-] and [->] - rotate',0 +align 4 +ctx1 db 28 dup (0) ;TinyGLContext or KOSGLContext +;sizeof.TinyGLContext = 28 + +align 4 +draw_3d: +stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT ;очистим буфер цвета и глубины + +stdcall [glPushMatrix] + stdcall [glRotatef], [angle_z],0.0,0.0,1.0 + stdcall [glScalef], 0.3,0.3,0.3 + + stdcall [glCallList],[obj1] + +stdcall [glPopMatrix] +ret + +align 4 +angle_z dd 0.0 +delt_size dd 3.0 +obj1 dd ? + +;-------------------------------------------------- +align 4 +import_lib_tinygl: + +macro E_LIB n +{ + n dd sz_#n +} +include '../export.inc' + dd 0,0 +macro E_LIB n +{ + sz_#n db `n,0 +} +include '../export.inc' + +;-------------------------------------------------- +system_path db '/sys/lib/' +name_tgl db 'tinygl.obj',0 +err_message_found_lib db 'Sorry I cannot load library tinygl.obj',0 +head_f_i: +head_f_l db 'System error',0 +err_message_import db 'Error on load import library tinygl.obj',0 +;-------------------------------------------------- + +i_end: + rb 1024 +stacktop: +cur_dir_path: + rb 4096 +library_path: + rb 4096 +mem: diff --git a/programs/develop/libraries/TinyGL/asm_fork/init.asm b/programs/develop/libraries/TinyGL/asm_fork/init.asm index 47a1b9034c..f661f8e5da 100644 --- a/programs/develop/libraries/TinyGL/asm_fork/init.asm +++ b/programs/develop/libraries/TinyGL/asm_fork/init.asm @@ -15,21 +15,17 @@ endp align 4 proc endSharedState uses eax ebx, context:dword mov ebx,[context] - mov ebx,[ebx+offs_cont_shared_state] - ; int i; ; for(i=0;ifirst_op_buffer; -; while (pb!=NULL) { -; pb1=pb->next; -; gl_free(pb); -; pb=pb1; -; } + ; free param buffer + mov eax,[edx] ;eax = GLList.first_op_buffer + @@: + cmp eax,0 + je .end_w + mov ecx,[eax+offs_gpbu_next] + stdcall gl_free,eax + mov eax,ecx + jmp @b + .end_w: -; gl_free(l); -; c->shared_state.lists[list]=NULL; -;} + stdcall gl_free,edx + mov ecx,[list] + shl ecx,2 + mov ebx,[ebx+offs_cont_shared_state] ;ebx = &context.shared_state.lists + add ebx,ecx + mov dword[ebx],0 ;=NULL + ret +endp -;static GLList *alloc_list(GLContext *c,int list) -;{ -; GLList *l; -; GLParamBuffer *ob; +align 4 +proc alloc_list uses ebx ecx, context:dword, list:dword + stdcall gl_zalloc,sizeof.GLParamBuffer + mov ecx,eax + stdcall gl_zalloc,sizeof.GLList -; l=gl_zalloc(sizeof(GLList)); -; ob=gl_zalloc(sizeof(GLParamBuffer)); + mov dword[ecx+offs_gpbu_next],0 ;ob.next=NULL + mov dword[eax],ecx ;l.first_op_buffer=ob -; ob->next=NULL; -; l->first_op_buffer=ob; + mov dword[ecx+offs_gpbu_ops],OP_EndList ;ob.ops[0].op=OP_EndList -; ob->ops[0].op=OP_EndList; + mov ebx,[context] + mov ebx,[ebx+offs_cont_shared_state] + mov ecx,[list] + shl ecx,2 + add ebx,ecx + mov [ebx],eax ;context.shared_state.lists[list]=l +if DEBUG ;alloc_list +push edi + mov ecx,80 + lea edi,[buf_param] + stdcall convert_int_to_str,ecx -; c->shared_state.lists[list]=l; -; return l; -;} + stdcall str_n_cat,edi,txt_nl,2 + stdcall dbg_print,f_alloc_l,buf_param +pop edi +end if + ret +endp ;void gl_print_op(FILE *f,GLParam *p) ;{ @@ -102,43 +132,55 @@ endp ;} align 4 -proc gl_compile_op uses eax ebx, context:dword, p:dword - mov eax,[context] -; int op,op_size; -; GLParamBuffer *ob,*ob1; -; int index,i; +proc gl_compile_op, context:dword, p:dword +pushad + mov edx,[context] -; op=p[0].op; -; op_size=op_table_size[op]; -; index=c->current_op_buffer_index; -; ob=c->current_op_buffer; + lea ebx,[op_table_size] + mov ecx,[p] + mov ecx,[ecx] + shl ecx,2 + add ecx,ebx + mov ecx,[ecx] ;ecx = кол-во параметров в компилируемой функции + mov ebx,[edx+offs_cont_current_op_buffer_index] + mov eax,[edx+offs_cont_current_op_buffer] -; /* we should be able to add a NextBuffer opcode */ -; if ((index + op_size) > (OP_BUFFER_MAX_SIZE-2)) { + ; we should be able to add a NextBuffer opcode + mov esi,ebx + add esi,ecx + cmp esi,(OP_BUFFER_MAX_SIZE-2) + jle @f + mov edi,eax + stdcall gl_zalloc,sizeof.GLParamBuffer + mov dword[eax+offs_gpbu_next],0 ;=NULL -; ob1=gl_zalloc(sizeof(GLParamBuffer)); -; ob1->next=NULL; + mov dword[edi+offs_gpbu_next],eax + mov esi,ebx + shl esi,2 + add esi,edi + mov dword[esi+offs_gpbu_ops],OP_NextBuffer + mov dword[esi+offs_gpbu_ops+4],eax -; ob->next=ob1; -; ob->ops[index].op=OP_NextBuffer; -; ob->ops[index+1].p=(void *)ob1; + mov dword[edx+offs_cont_current_op_buffer],eax + xor ebx,ebx + @@: -; c->current_op_buffer=ob1; -; ob=ob1; -; index=0; -; } - -; for(i=0;iops[index]=p[i]; -; index++; -; } -; c->current_op_buffer_index=index; + mov esi,[p] + @@: + mov edi,ebx + shl edi,2 + add edi,eax + movsd + inc ebx + loop @b + mov dword[edx+offs_cont_current_op_buffer_index],ebx +popad ret endp align 4 proc gl_add_op uses eax ebx ecx, p:dword ;GLParam* -if DEBUG +if DEBUG ;gl_add_op push edi esi mov ebx,[p] mov ebx,[ebx] @@ -209,6 +251,7 @@ end if add ecx,ebx call dword[ecx] ;op_table_func[op](c,p) @@: + call gl_get_context cmp dword[eax+offs_cont_compile_flag],0 je @f stdcall gl_compile_op,eax,[p] @@ -234,61 +277,107 @@ proc glopNextBuffer, context:dword, p:dword ret endp -;void glopCallList(GLContext *c,GLParam *p) -;{ -; GLList *l; -; int list,op; +align 4 +proc glopCallList uses eax ebx ecx edx edi, context:dword, p:dword + mov edx,[context] + mov ebx,[p] -; list=p[1].ui; -; l=find_list(c,list); -; if (l == NULL) gl_fatal_error("list %d not defined",list); -; p=l->first_op_buffer->ops; + stdcall find_list,edx,[ebx+4] + cmp eax,0 + jne @f + ;if (eax == NULL) gl_fatal_error("list %d not defined",[ebx+4]) + @@: + mov edi,[eax] ;edi = &GLList.first_op_buffer.ops -; while (1) { -; op=p[0].op; -; if (op == OP_EndList) break; -; if (op == OP_NextBuffer) { -; p=(GLParam *)p[1].p; -; } else { -; op_table_func[op](c,p); -; p+=op_table_size[op]; -; } -; } -;} +align 4 + .cycle_0: ;while (1) +if DEBUG ;glopCallList +push ecx edi + mov eax,[edi] + mov ecx,80 + lea edi,[buf_param] + stdcall convert_int_to_str,ecx + + stdcall str_n_cat,edi,txt_nl,2 + stdcall dbg_print,txt_op,buf_param +pop edi ecx +end if + cmp dword[edi],OP_EndList + je .end_f ;if (op == OP_EndList) break + cmp dword[edi],OP_NextBuffer + jne .els_0 ;if (op == OP_NextBuffer) + mov edi,[edi+4] ;p=p[1].p + jmp .cycle_0 + .els_0: + mov ecx,dword[edi] ;ecx = OP_... + shl ecx,2 + lea ebx,[op_table_func] + add ecx,ebx + stdcall dword[ecx],edx,edi ;op_table_func[op](context,p) + + mov ecx,dword[edi] ;ecx = OP_... + shl ecx,2 + lea ebx,[op_table_size] + add ecx,ebx + mov ecx,[ecx] + shl ecx,2 + add edi,ecx ;edi += op_table_size[op] + jmp .cycle_0 + .end_f: + ret +endp + +align 4 +proc glNewList uses eax ebx, list:dword, mode:dword + call gl_get_context + mov ebx,eax -;void glNewList(unsigned int list,int mode) -;{ -; GLList *l; -; GLContext *c=gl_get_context(); -; ; assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE); -; assert(c->compile_flag == 0); -; -; l=find_list(c,list); -; if (l!=NULL) delete_list(c,list); -; l=alloc_list(c,list); -; -; c->current_op_buffer=l->first_op_buffer; -; c->current_op_buffer_index=0; -; -; c->compile_flag=1; -; c->exec_flag=(mode == GL_COMPILE_AND_EXECUTE); -;} +; assert(ebx->compile_flag == 0); -;void glEndList(void) -;{ -; GLContext *c=gl_get_context(); -; GLParam p[1]; + stdcall find_list,ebx,[list] + cmp eax,0 + je @f + stdcall delete_list,ebx,[list] + @@: + stdcall alloc_list,ebx,[list] + + mov eax,[eax] ;eax = GLList.first_op_buffer + mov [ebx+offs_cont_current_op_buffer],eax + mov dword[ebx+offs_cont_current_op_buffer_index],0 + + mov dword[ebx+offs_cont_compile_flag],1 + xor eax,eax + cmp dword[mode],GL_COMPILE_AND_EXECUTE + jne @f + inc eax ;eax = (mode == GL_COMPILE_AND_EXECUTE) + @@: + mov [ebx+offs_cont_exec_flag],eax + ret +endp + +align 4 +proc glEndList uses eax ebx +locals + p dd ? +endl + call gl_get_context ; assert(c->compile_flag == 1); -; /* end of list */ -; p[0].op=OP_EndList; -; gl_compile_op(c,p); + ; end of list + mov dword[p],OP_EndList + mov ebx,ebp + sub ebx,4 ;=sizeof(dd) + stdcall gl_compile_op,eax,ebx -; c->compile_flag=0; -; c->exec_flag=1; -;} + mov dword[eax+offs_cont_compile_flag],0 + mov dword[eax+offs_cont_exec_flag],1 +if DEBUG ;glEndList + stdcall dbg_print,f_end_l,txt_nl +end if + ret +endp ;output: ; eax = (find_list(gl_get_context,list) != NULL) @@ -300,30 +389,60 @@ proc glIsList, list:dword je @f mov eax,1 @@: +if DEBUG ;glIsList +push edi + mov ecx,80 + lea edi,[buf_param] + stdcall convert_int_to_str,ecx + + stdcall str_n_cat,edi,txt_nl,2 + stdcall dbg_print,f_is_l,buf_param +pop edi +end if ret endp -;unsigned int glGenLists(int range) -;{ -; GLContext *c=gl_get_context(); -; int count,i,list; -; GLList **lists; +align 4 +proc glGenLists uses ebx ecx edx edi esi, range:dword + call gl_get_context + mov edi,eax -; lists=c->shared_state.lists; -; count=0; -; for(i=0;i