Subversion Repositories Kolibri OS

Rev

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