Subversion Repositories Kolibri OS

Rev

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