Subversion Repositories Kolibri OS

Rev

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