T
T
Type Programmer2018-04-30 21:42:12
assembler
Type Programmer, 2018-04-30 21:42:12

How to optimize code when working with graphics?

Wrote code. The bottom line is that then I want to implement it in my mini OS. Therefore, only bios interrupts.
For graphics output I use the 13th mode, from int 10h. and for the output itself, I made a procedure that puts the color of the pixel directly into the video buffer. I also made it possible to create a sprite (well, you can call it a sprite). I made it so that the X coordinate could be changed using the "a" and "b" keys, and to erase the old sprite, I redraw the entire screen. And at the same time, there is a noticeable blinking in the virtual machine, and not very noticeable, but still on real hardware. How can I get rid of this HELP.
Source:

#make_boot#

org 7c00h 
use16
jmp start   

e: 
ret 


put_pix:       
    push ax   
    push dx
    mov ax, 0a000h
    mov es, ax
    mov ax,320
    mul cx 
    pop dx
    add ax,dx
    mov di,ax 
    pop ax
    stosb  
    ret 
    
fill_disp: 
mov di,0000h
mov cx,0000h
mov dx,0 
p0:     
cmp dx,320
jz p1 
call put_pix  
inc dx   
jmp p0
p1:   
cmp cx,200
jz e
inc cx
mov dx,0
jmp p0   

e_draw:
pop dx
pop bx 
mov [x],dx
mov [y],bx
ret

draw_sprite_nexline: 
inc si
mov al,00h
cmp al,[bx+si]
jz e_draw
dec si
add [y],01h
mov ax,[x_ret]      
mov [x],ax     
inc si
jmp draw_sprite_1

draw_sprite:    
    mov ax,bx  
    mov dx,[x]
    mov bx,[y]  
    push bx
    push dx  
    mov bx,ax
    mov ax,[x]
    mov [x_ret],ax     
    mov si,0000h  
    draw_sprite_1:
    mov ax, 0a000h
    mov es, ax
    mov ax,320  
    mov cx,[y]
    mul cx 
    mov dx,[x]
    add ax,dx
    mov di,ax
    mov al,[bx+si]   
    cmp al,255
    jz draw_sprite_2
    stosb 
    draw_sprite_2:         
    inc si 
    mov al,00h
    cmp al,[bx+si]
    jz draw_sprite_nexline
    add [x],1     
    jmp draw_sprite_1
    
    
      
    
left_sprite: 
sub [x],01h
jmp p3
right_sprite:
add [x],01h
jmp p3    
  
start:  
mov ah, 0
mov al, 13h 
int 10h       
mov al,50
call fill_disp  
mov di,0000h
mov si,0000h 
mov bx,sprite
call draw_sprite  
p4:
mov ah,00h
int 16h   
cmp al,'a'
jz left_sprite
cmp al,'d'
jz right_sprite 
p3: 
mov di,0000h
mov si,0000h 
mov al,50  
call fill_disp  
mov di,0000h
mov si,0000h 
mov bx,sprite
call draw_sprite
jmp p4




x_ret dw 0
x dw 160
y dw 100


sprite db 15,15,15,15,15,15,15,15,15,0,15,15,15,15,15,15,15,15,15,0,15,15,255,15,15,15,40,15,15,0,15,15,15,15,15,15,15,15,15,0,15,15,15,15,15,15,15,15,15,0,15,15,40,40,40,40,40,15,15,0,15,15,15,15,15,15,15,15,15,0,0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forspamonly2, 2018-05-01
@MegaCraZy6

cleaning the screen one pixel at a time, recalculating the offset of each pixel by coordinates - this may well compensate for 25 years of technical progress.
it is better to clean the screen as a thread like this:

push    0A000h
pop     es
xor     di,di
xor     eax,eax
mov     cx,64000/4
rep     stosd

and specifically for sprites, it’s even better to read about double buffering and dirty rectangles

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question