home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / asm / 3dvect25 / irq.asm < prev    next >
Encoding:
Assembly Source File  |  1993-09-06  |  5.6 KB  |  242 lines

  1. ; irq handler for updating vector locations/angles
  2. ;
  3. ; this uses irq 8 set to the same speed as the vertical retrace so that
  4. ; an animation will remain at a smooth/constant speed regardless of the
  5. ; machine speed: eg, a 386SX33 will run an animation at the same  speed
  6. ; as a 486DX66, only the 386 will skip frames to compensate.all the irq
  7. ; really does is "inc traces_past" and this information is used to skip
  8. ; frames. if traces_past =1 is 486DX66, =4 is 386 or whatever.  you get
  9. ; the idea right?
  10. ;
  11. ; the irq can operate in real mode or pmode.  just call the appropiate
  12. ; routine.  i did this in case you want to add to  the  irq  your  own
  13. ; functions for sound or music or whatever.
  14.  
  15.         .386p
  16.  
  17.         public set_pmirq
  18.         public reset_pmirq
  19.  
  20.         public set_rmirq
  21.         public reset_rmirq
  22.  
  23.         public reset_raster_count
  24.         public time_raster
  25.  
  26.         public frametime
  27.  
  28.         include 3d.inc
  29.         include equ.inc
  30.  
  31.         pmodeirq equ 0  ; you could also use irq 8 for either of these.
  32.         rmodeirq equ 0  ; both can run at the same time even if both=0.
  33.  
  34. code16  segment para public use16
  35.         assume cs:code16, ds:code16
  36.  
  37. ;─────────────────────────────────────────────────────────────────────────────
  38. rmirq0:                                 ; real mode IRQ0 handler
  39.         push ax ds
  40.  
  41. ; put your real mode irq code here!!!!!
  42. ;--------------------------------------
  43.  
  44.  
  45.  
  46. ;--------------------------------------
  47.  
  48. ; now my code, this is where i inc that variable
  49. ; real mode irq increments protected mode memory location
  50.  
  51.         mov ax,cs:rfs
  52.         mov ds,ax
  53.         mov si,cs:rfo
  54.  
  55.         inc word ptr [si]               ; inc traces_past
  56.         inc dword ptr [si+2]            ; inc frame_number
  57.  
  58.         pop ds
  59.         mov al,20h
  60.         out 20h,al
  61.         pop ax
  62.  
  63.         iret
  64.  
  65. rfs     dw ?
  66. rfo     dw ?
  67.  
  68. transfer_location:
  69.         mov cs:rfs,cx                   ; set protected mode location of
  70.         mov cs:rfo,dx                   ; traces_past in terms of real mode
  71.         ret
  72.  
  73. code16  ends
  74.  
  75. code32  segment para public use32
  76.         assume cs:code32, ds:code32
  77.  
  78.         include pmode.inc
  79.  
  80. ormirq0 dd ?                            ; old real mode IRQ handler seg:off
  81. opmirq0 dd ?                            ; old protected mode IRQ handler off
  82.  
  83. pmirq0:                                 ; protected mode IRQ0 handler
  84.         push ds
  85.  
  86. ; put your protected mode irq code here!!!!!
  87. ;-------------------------------------------
  88.  
  89.  
  90.  
  91. ;-------------------------------------------
  92.  
  93. ; now my code, this is where i inc that variable
  94. ; protected mode version is easy!
  95.  
  96.         inc traces_past
  97.         inc frame_number
  98.  
  99.         pop ds
  100.         jmp cs:opmirq0                  ; chain to old IRQ0 redirector
  101.  
  102. set_rmirq:
  103.         mov eax,gs:[rmodeirq*4]         ; save real mode IRQ0 vector
  104.         mov ormirq0,eax
  105.  
  106.         cli                             ; set IRQ0 to inc variable
  107.  
  108.         mov word ptr gs:[rmodeirq*4],offset rmirq0  ; set real mode irq
  109.         mov word ptr gs:[(rmodeirq*4)+2],code16
  110.  
  111.         mov edx,offset traces_past      ; tell real mode irq where traces_past
  112.         add edx,_code32a                ; is in memory (pmode location)
  113.         mov al,dl
  114.         and ax,0fh
  115.         shr edx,4
  116.         mov v86r_cx,dx
  117.         mov v86r_dx,ax
  118.  
  119.         mov cx,seg transfer_location
  120.         mov dx,offset transfer_location
  121.         int 32h
  122.  
  123.         sti
  124.  
  125.         jmp new_timer
  126.  
  127. reset_rmirq:
  128.         cli
  129.  
  130.         mov eax,ormirq0                 ; restore old real mode IRQ0 vector
  131.         mov gs:[rmodeirq*4],eax
  132.  
  133.         sti
  134.  
  135.         jmp old_timer
  136.  
  137. set_pmirq:
  138.         xor bl,bl                       ; get protected mode IRQ0 redirector
  139.         call _getirqvect
  140.         mov opmirq0,edx
  141.  
  142.         cli                             ; set IRQ0 to inc variable
  143.  
  144.         mov bl,pmodeirq
  145.         mov edx,offset pmirq0
  146.         call _setirqvect                ; set protected mode irq
  147.  
  148.         sti
  149.  
  150.         jmp new_timer
  151.  
  152. reset_pmirq:
  153.         cli
  154.  
  155.         mov bl,pmodeirq
  156.         mov edx,opmirq0
  157.         call _setirqvect
  158.  
  159.         sti
  160.  
  161.         jmp old_timer
  162.  
  163. new_timer:
  164.         call time_raster
  165.  
  166.         cli
  167.         mov al,36h
  168.         out 43h,al
  169.         mov ax,frametime               ; set irq 8 time to match raster time
  170.         out 40h,al
  171.         mov al,ah
  172.         out 40h,al
  173.         sti
  174.  
  175.         ret
  176.  
  177. old_timer:                             ; reset timer for exit
  178.         cli
  179.         mov al,36h
  180.         out 43h,al
  181.  
  182.         mov ax,0
  183.         out 40h,al
  184.         out 40h,al
  185.  
  186.         sti
  187.  
  188.         ret
  189.  
  190. reset_raster_count:                    ; reset count before any animation loop
  191.         cli
  192.         mov traces_past,1
  193.         mov frame_number,0
  194.         sti
  195.         ret
  196.  
  197. frametime dw 0
  198.  
  199. time_raster:
  200.         cli
  201.         mov dx, input_1        ; input# 1 reg
  202. loop1:
  203.         in al,dx               ; wait for vsync
  204.         test al,8
  205.         jnz loop1
  206. loop2:
  207.         in al,dx
  208.         test al,8
  209.         jz loop2
  210.  
  211.         mov al,36h             ; reset timer
  212.         out 43h,al
  213.         mov al,0
  214.         out 40h,al
  215.         mov al,0
  216.         out 40h,al
  217. loop3:
  218.         in al,dx               ; wait for vsync
  219.         test al,8
  220.         jnz loop3
  221. loop4:
  222.         in al,dx
  223.         test al,8
  224.         jz loop4
  225.  
  226.         xor al,al              ; this calculation code courtesy future_crew
  227.         out 43h,al             ; from mental.exe
  228.         in al,40h
  229.         mov ah,al
  230.         in al,40h
  231.         xchg al,ah
  232.         neg ax
  233.         shr ax,1
  234.         mov frametime,ax
  235.  
  236.         sti
  237.         ret
  238.  
  239. code32  ends
  240.         end
  241.  
  242.