Subversion Repositories Kolibri OS

Rev

Rev 6523 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;строки с именами функций
  2. op_table_str:
  3. macro ADD_OP a,b,c
  4. {
  5.         db 'gl',`a,' ',c,0
  6. }
  7. include 'opinfo.inc'
  8. purge ADD_OP
  9.  
  10. ;указатели на функции ;static void (*op_table_func[])(GLContext *,GLParam *)=
  11. align 4
  12. op_table_func:
  13. macro ADD_OP a,b,c
  14. {
  15.         dd glop#a
  16. }
  17. include 'opinfo.inc'
  18. purge ADD_OP
  19.  
  20. ;число параметров в функциях
  21. align 4
  22. op_table_size:
  23. macro ADD_OP a,b,c
  24. {
  25.         dd b+1
  26. }
  27. include 'opinfo.inc'
  28. purge ADD_OP
  29.  
  30. ;коды функций у которых нет входных параметров
  31. align 4
  32. macro ADD_OP a,b,c
  33. {
  34. if b eq 0
  35.         op_#a dd OP_#a
  36. end if
  37. }
  38. include 'opinfo.inc'
  39. purge ADD_OP
  40.  
  41.  
  42. ;output:
  43. ; eax = context.shared_state.lists[list]
  44. align 4
  45. proc find_list uses ebx, context:dword, list:dword
  46.         mov eax,[context]
  47.         mov eax,[eax+GLContext.shared_state]
  48.         mov ebx,[list]
  49.         lea eax,[eax+4*ebx]
  50.         mov eax,[eax]
  51.         ret
  52. endp
  53.  
  54. align 4
  55. proc delete_list uses eax ebx ecx edx, context:dword, list:dword
  56.         mov ebx,[context]
  57.         stdcall find_list,ebx,[list]
  58.         mov edx,eax
  59. ;  assert(l != NULL);
  60.  
  61.         ; free param buffer
  62.         mov eax,[edx] ;eax = GLList.first_op_buffer
  63.         @@:
  64.         cmp eax,0
  65.         je .end_w
  66.                 mov ecx,[eax+offs_gpbu_next]
  67.                 stdcall gl_free,eax
  68.                 mov eax,ecx
  69.                 jmp @b
  70.         .end_w:
  71.  
  72.         stdcall gl_free,edx
  73.         mov ebx,[ebx+GLContext.shared_state] ;ebx = &context.shared_state.lists
  74.         mov ecx,[list]
  75.         lea ebx,[ebx+4*ecx]
  76.         mov dword[ebx],0 ;=NULL
  77.         ret
  78. endp
  79.  
  80. align 4
  81. proc alloc_list uses ebx ecx, context:dword, list:dword
  82.         stdcall gl_zalloc,sizeof.GLParamBuffer
  83.         mov ecx,eax
  84.         stdcall gl_zalloc,sizeof.GLList
  85.  
  86.         mov dword[ecx+offs_gpbu_next],0 ;ob.next=NULL
  87.         mov dword[eax],ecx ;l.first_op_buffer=ob
  88.  
  89.         mov dword[ecx+offs_gpbu_ops],OP_EndList ;ob.ops[0].op=OP_EndList
  90.  
  91.         mov ebx,[context]
  92.         mov ebx,[ebx+GLContext.shared_state]
  93.         mov ecx,[list]
  94.         lea ebx,[ebx+4*ecx]
  95.         mov [ebx],eax ;context.shared_state.lists[list]=l
  96.         ret
  97. endp
  98.  
  99. ;void gl_print_op(FILE *f,GLParam *p)
  100. ;{
  101. ;  int op;
  102. ;  char *s;
  103.  
  104. ;  op=p[0].op;
  105. ;  p++;
  106. ;  s=op_table_str[op];
  107. ;  while (*s != 0) {
  108. ;    if (*s == '%') {
  109. ;      s++;
  110. ;      switch (*s++) {
  111. ;      case 'f':
  112. ;       fprintf(f,"%g",p[0].f);
  113. ;       break;
  114. ;      default:
  115. ;       fprintf(f,"%d",p[0].i);
  116. ;       break;
  117. ;      }
  118. ;      p++;
  119. ;    } else {
  120. ;      fputc(*s,f);
  121. ;      s++;
  122. ;    }
  123. ;  }
  124. ;  fprintf(f,"\n");
  125. ;}
  126.  
  127. align 4
  128. proc gl_compile_op, context:dword, p:dword
  129. pushad
  130.         mov edx,[context]
  131.  
  132.         mov ecx,[p]
  133.         mov ecx,[ecx] ;код операции
  134.         lea ecx,[op_table_size+4*ecx]
  135.         mov ecx,[ecx] ;ecx = кол-во параметров в компилируемой функции
  136.         mov ebx,[edx+GLContext.current_op_buffer_index]
  137.         mov eax,[edx+GLContext.current_op_buffer]
  138.  
  139.         ; we should be able to add a NextBuffer opcode
  140.         lea esi,[ebx+ecx]
  141.         cmp esi,(OP_BUFFER_MAX_SIZE-2)
  142.         jle @f
  143.                 mov edi,eax
  144.                 stdcall gl_zalloc,sizeof.GLParamBuffer
  145.                 mov dword[eax+offs_gpbu_next],0 ;=NULL
  146.  
  147.                 mov dword[edi+offs_gpbu_next],eax
  148.                 lea esi,[edi+4*ebx]
  149.                 mov dword[esi+offs_gpbu_ops],OP_NextBuffer
  150.                 mov dword[esi+offs_gpbu_ops+4],eax
  151.  
  152.                 mov dword[edx+GLContext.current_op_buffer],eax
  153.                 xor ebx,ebx
  154.         @@:
  155.  
  156.         mov esi,[p]
  157.         @@:
  158.                 lea edi,[eax+4*ebx]
  159.                 movsd
  160.                 inc ebx
  161.         loop @b
  162.         mov dword[edx+GLContext.current_op_buffer_index],ebx
  163. popad
  164.         ret
  165. endp
  166.  
  167. align 4
  168. proc gl_add_op uses eax ebx ecx, p:dword ;GLParam*
  169. if DEBUG ;gl_add_op
  170. push edi esi
  171.         mov ebx,[p]
  172.         mov ebx,[ebx]
  173.         lea eax,[op_table_str]
  174.         @@:
  175.                 cmp ebx,0
  176.                 je @f
  177.                 cmp byte[eax],0
  178.                 jne .no_dec
  179.                         dec ebx
  180.                 .no_dec:
  181.                 inc eax
  182.                 jmp @b
  183.         @@:
  184.         stdcall dbg_print,eax,txt_nl
  185.  
  186.         mov esi,eax
  187.         mov word[NumberSymbolsAD],3
  188.         mov ebx,[p]
  189.         lea edi,[buf_param]
  190.         mov byte[edi],0
  191.         mov ecx,80
  192.         .cycle_0:
  193.                 cmp byte[esi],'%'
  194.                 jne .no_param
  195.                         cmp ebx,[p]
  196.                         je @f
  197.                                 stdcall str_n_cat,edi,txt_zp_sp,2
  198.                                 stdcall str_len,edi
  199.                                 add edi,eax
  200.                         @@:
  201.                         add ebx,4
  202.                         inc esi
  203.  
  204.                         cmp byte[esi],'f'
  205.                         jne @f
  206.                                 fld dword[ebx]
  207.                                 fstp qword[Data_Double]
  208.                                 call DoubleFloat_to_String
  209.                                 stdcall str_cat, edi,Data_String
  210.                         @@:
  211.                         cmp byte[esi],'d'
  212.                         jne @f
  213.                                 stdcall str_len,edi
  214.                                 add edi,eax
  215.                                 sub ecx,eax
  216.                                 mov eax,dword[ebx]
  217.                                 stdcall convert_int_to_str,ecx
  218.                         @@:
  219.                 .no_param:
  220.                 inc esi
  221.                 cmp byte[esi],0
  222.                 jne .cycle_0
  223.         stdcall str_cat, edi,txt_nl
  224.         stdcall dbg_print,txt_sp,buf_param
  225. pop esi edi
  226. end if
  227.         call gl_get_context
  228.         mov ebx,[p]
  229.  
  230.         cmp dword[eax+GLContext.exec_flag],0
  231.         je @f
  232.                 push ebx
  233.                 push eax
  234.                 mov ecx,dword[ebx] ;ecx = OP_...
  235.                 shl ecx,2
  236.                 lea ebx,[op_table_func]
  237.                 add ecx,ebx
  238.                 call dword[ecx] ;op_table_func[op](c,p)
  239.         @@:
  240.         call gl_get_context
  241.         cmp dword[eax+GLContext.compile_flag],0
  242.         je @f
  243.                 stdcall gl_compile_op,eax,[p]
  244.         @@:
  245.         cmp dword[eax+GLContext.print_flag],0
  246.         je @f
  247.                 ;gl_print_op(stderr,p);
  248.         @@:
  249.         ret
  250. endp
  251.  
  252. ; this opcode is never called directly
  253. align 4
  254. proc glopEndList, context:dword, p:dword
  255. ;  assert(0);
  256.         ret
  257. endp
  258.  
  259. ; this opcode is never called directly
  260. align 4
  261. proc glopNextBuffer, context:dword, p:dword
  262. ;  assert(0);
  263.         ret
  264. endp
  265.  
  266. align 4
  267. proc glopCallList uses eax ebx ecx edx edi, context:dword, p:dword
  268.         mov edx,[context]
  269.         mov ebx,[p]
  270.  
  271.         stdcall find_list,edx,[ebx+4]
  272.         or eax,eax
  273.         jnz @f
  274.                 ;gl_fatal_error("list %d not defined",[ebx+4])
  275.         @@:
  276.         mov edi,[eax] ;edi = &GLList.first_op_buffer.ops
  277.  
  278. align 4
  279.         .cycle_0: ;while (1)
  280.         cmp dword[edi],OP_EndList
  281.         je .end_f ;if (op == OP_EndList) break
  282.         cmp dword[edi],OP_NextBuffer
  283.         jne .els_0 ;if (op == OP_NextBuffer)
  284.                 mov edi,[edi+4] ;p=p[1].p
  285.                 jmp .cycle_0
  286.         .els_0:
  287.                 mov ecx,dword[edi] ;ecx = OP_...
  288.                 shl ecx,2
  289.                 lea ebx,[op_table_func]
  290.                 add ecx,ebx
  291.                 stdcall dword[ecx],edx,edi ;op_table_func[op](context,p)
  292.  
  293.                 mov ecx,dword[edi] ;ecx = OP_...
  294.                 shl ecx,2
  295.                 lea ebx,[op_table_size]
  296.                 add ecx,ebx
  297.                 mov ecx,[ecx]
  298.                 shl ecx,2
  299.                 add edi,ecx ;edi += op_table_size[op]
  300.         jmp .cycle_0
  301.         .end_f:
  302.         ret
  303. endp
  304.  
  305. align 4
  306. proc glNewList uses eax ebx, list:dword, mode:dword
  307.         call gl_get_context
  308.         mov ebx,eax
  309.  
  310. ;  assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE);
  311. ;  assert(ebx->compile_flag == 0);
  312.  
  313.         stdcall find_list,ebx,[list]
  314.         cmp eax,0
  315.         je @f
  316.                 stdcall delete_list,ebx,[list]
  317.         @@:
  318.         stdcall alloc_list,ebx,[list]
  319.  
  320.         mov eax,[eax] ;eax = GLList.first_op_buffer
  321.         mov [ebx+GLContext.current_op_buffer],eax
  322.         mov dword[ebx+GLContext.current_op_buffer_index],0
  323.  
  324.         mov dword[ebx+GLContext.compile_flag],1
  325.         xor eax,eax
  326.         cmp dword[mode],GL_COMPILE_AND_EXECUTE
  327.         jne @f
  328.                 inc eax ;eax = (mode == GL_COMPILE_AND_EXECUTE)
  329.         @@:
  330.         mov [ebx+GLContext.exec_flag],eax
  331.         ret
  332. endp
  333.  
  334. align 4
  335. proc glEndList uses eax ebx
  336. locals
  337.         p dd ?
  338. endl
  339.         call gl_get_context
  340.  
  341. ;  assert(c->compile_flag == 1);
  342.  
  343.         ; end of list
  344.         mov dword[p],OP_EndList
  345.         mov ebx,ebp
  346.         sub ebx,4 ;=sizeof(dd)
  347.         stdcall gl_compile_op,eax,ebx
  348.  
  349.         mov dword[eax+GLContext.compile_flag],0
  350.         mov dword[eax+GLContext.exec_flag],1
  351.         ret
  352. endp
  353.  
  354. ;output:
  355. ; eax = (find_list(gl_get_context,list) != NULL)
  356. align 4
  357. proc glIsList, list:dword
  358.         call gl_get_context
  359.         stdcall find_list, eax,[list]
  360.         cmp eax,0 ;NULL
  361.         je @f
  362.                 mov eax,1
  363.         @@:
  364.         ret
  365. endp
  366.  
  367. align 4
  368. proc glGenLists uses ebx ecx edx edi esi, range:dword
  369.         call gl_get_context
  370.         mov edi,eax
  371.  
  372.         mov ebx,[eax+GLContext.shared_state] ;ebx=context.shared_state.lists
  373.         xor edx,edx ;count=0
  374.         mov ecx,MAX_DISPLAY_LISTS
  375.         xor esi,esi
  376.         .cycle_0: ;for(esi=0;esi<MAX_DISPLAY_LISTS;esi++)
  377.                 cmp dword[ebx],0 ;if (ebx[i]==NULL)
  378.                 jne .els_0
  379.                         inc edx
  380.                         cmp edx,[range] ;if (count == range)
  381.                         jne .els_1
  382.                         mov ecx,[range]
  383.                         inc esi
  384.                         sub esi,ecx ;esi = (esi-range+1)
  385.                         .cycle_1: ;for(i=0;i<range;i++)
  386.                                 stdcall alloc_list,edi,esi
  387.                                 inc esi
  388.                         loop .cycle_1
  389.                         mov eax,esi
  390.                         jmp .end_f
  391.                 .els_0:
  392.                         xor edx,edx ;count=0
  393.                 .els_1:
  394.                 add ebx,4
  395.                 inc esi
  396.         loop .cycle_0
  397.         xor eax,eax
  398.         .end_f:
  399.         ret
  400. endp
  401.