EMU 8086 Takes much longer time to print

Viewed 95

I want to create a pong game in EMU-8086 COMPILER ,in this program I have just created a ball and applies a function with increasing time (1/100 millisecond) ,ball moves from left to right but when I emulate the program it takes bit long time to create a ball and then going very slowly from left to right kindly tell me how to speed up the program

     ;IMP LINKS
 
 ;=======FOR INT 10H FUNCTIONS==========     
 
   ;https://en.wikipedia.org/wiki/INT_10H#:~:text=List%20of%20supported%20functions%20%20%20%20Function,End%20s%20...%20%2017%20more%20rows%20
    ;https://stanislavs.org/helppc/int_10.html 
    
  ;======INT 21H FUNCTIONS==============

     ; http://spike.scu.edu.au/~barry/interrupts.html#ah2c

org 100h

 .MODEL SMALL
 .STACK 100H
 
 .DATA 
 
  BALL_X DW 0AH ;FOR X-AXIS
  BALL_Y DW 0AH ;FOR Y-AXIS   
  BALL_SIZE DW 04h ;size of the ball (width and height)  
  TIME_AUX DB 0   ;VARIABLE USED FOR CHECKING IF THE TIME HAS CHANGED OR NOT
  
 
 .CODE
 
 main proc         
    
       MOV AX,@DATA     
       MOV DS,AX   
       
  
    ;INT 10h commands
      MOV AH,00h ; for configuration to video mode
      MOV AL,13h ; for 320x200 256 color graphics (MCGA,VGA)
      INT 10h ;FOR EXECUTING PROGRAM
      
      ;for background color
      
    ;  MOV AH,0Bh ; SET CONFIGURATION
    ;  MOV BH,00h ; to bg color 
    ;  MOV BL,0Dh  ; dh=pink color
    ;  INT 10h ; executing function
     
     ;========================= 
        ;FOR TIME     
        
        CHECKTIME:         
        
        MOV AH,2CH ;CONFIGURING TIME
        INT 21H    ; CH = hour CL = minute DH = second DL = 1/100 seconds
        CMP DL,TIME_AUX ;IS THE CURRENT TIME EQUAL TO THE PREVIOUS ONE
        
        JE CHECKTIME ;IF IT'S SAME THEN CHECK AGAIN
            
            ;IF ITS DIFFERENT THEN DRAW,MOVE ETC
           
            MOV TIME_AUX,DL
            INC BALL_X
         
          
       CALL DRAWBALL
       
       JMP CHECKTIME ;AFTER EVERYTIHING CHECK TIME AGAIN
    
        
        
  MOV AH,4CH
  INT 21H
 
 
    
    DRAWBALL PROC 
        
        ;BALL LOCATION 
        
      MOV CX,BALL_X ;set X-AXIS LOCATION (X)
      MOV DX,BALL_Y ; set Y-AXIS LOCATION (Y) 
    
      
      DRAWBALL_HORIZONTAL:
      
        
       ;for pixel INFORMATION
      MOV AH,0CH ; for configuring graphic pixel
      MOV AL,0Fh ; for white color pixel
      MOV BH,00h  ; for page number
      INT 10H       
      
      INC CX ;PRINTING PIXEL/DOT UNTIL 4COL IN 1ST ROW 
      MOV AX,CX  ;CX-BALL_X>BALL_SIZE (THEN WO GO TO THE NEXT LINE)
      SUB AX,BALL_X
      CMP AX,BALL_SIZE
      JNG DRAWBALL_HORIZONTAL   
      
        MOV CX,BALL_X ; CX REGISTER GOES BAX TO INITIAL COLUM 
        INC DX ; FOR GOING TO   NEXT LINE
        MOV AX,DX
        SUB AX,BALL_Y 
        CMP AX,BALL_SIZE
        JNG DRAWBALL_HORIZONTAL
        
        
       RET 
       DRAWBALL ENDP
 
 END PROC            
ret
1 Answers

...applies a function with increasing time (1/100 millisecond)

Although the DOS.GetSystemTime function 2Ch delivers you in the DL register a value for HundredthsOfSecond, that does not mean that this function ticks at a pace of 1/100 of a second (and certainly not at 1/100 millisecond like you mentioned). The DOS time changes at a rate of 18.2 Hz. In other words you can expect a different value in the DL register some 18 times per second.
And these will be those values (approximately):

0, 5, 11, 16, 22, 27, 33, 38, 44, 50, 56, 61, 67, 72, 78, 83, 89, 94

A quick solution would be to move the ball multiple times each time your present code decides to move it once.

  ; IF IT'S DIFFERENT THEN DRAW, MOVE ETC
  mov  TIME_AUX, dl
  mov  di, 5
More:
  inc  BALL_X
  call DRAWBALL
  dec  di
  jnz  More
  jmp  CHECKTIME ;AFTER EVERYTHING CHECK TIME AGAIN

With a 5-time repeat (mov di, 5), the ball will cover the distance across the screen in about 3 seconds, which would be reasonable for a pong game.


Also, don't forget that emu8086 has a setting for program execution speed and that this emulator even in its "best speed mode" is still known to be slow...
If you want high-speed game performance, you could run your code on DOSBox or on true real address mode hardware.

Related