T
T
Type Programmer2018-05-13 16:41:17
assembler
Type Programmer, 2018-05-13 16:41:17

Where is the error in double buffering?

I need help, I wrote a simple program, it works in 320x200 video mode, the point is that it can output sprites, then I realized that I needed to make a second buffer (well, as I understood, I asked a question on a toaster), I made it seem like everything that was previously output to the video buffer , was output to a regular buffer, and from there, by calling draw, moved what was in the buffer to the video buffer.
Everything works fine on the virtual machine, emulators.
And here on iron of a problem. Screen fill works great. But instead of a sprite, it displays a couple of pixels, not at all from the sprite, and it should have been in the wrong position.
The code:

#make_boot# 

org 7c00h 
use16 
jmp start 

e: 
mov ax,cs 
mov ds,ax 
mov es,ax 
ret 


put_pix: 
push ax 
push dx 
mov ax,9000h
mov es, ax 
mov ax,320 
mul cx 
pop dx 
add ax,dx 
mov di,ax 
pop ax 
stosb 
ret 

fill_disp: 
push ax 
mov ax,9000h
mov ds,ax 
pop ax 
mov ah,al 
mov bx,0000h 
mov [bx],ax 
p0: 
add bx,2 
mov [bx],ax 
cmp bx,0FFFEh 
jz e 
jmp p0 

e_draw: 
pop dx 
pop bx 
mov [x],dx 
mov [y],bx  
mov ax,cs 
mov ds,ax 
mov es,ax 
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,9000h  
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 

draw_display: 
mov di,0000h 
mov bx,0000h 
mov si,0000h 
mov ax,9000h
mov ds,ax 
mov ax,0A000h 
mov es,ax 
draw_display_1: 
cmp bx,0FFFFh 
jz draw_display_2 
mov al,[bx] 
stosb 
inc bx 
jmp draw_display_1 
draw_display_2: 
jz e 


left_sprite: 
sub [x],01h 
jmp p3 
right_sprite: 
add [x],01h 
jmp p3 

start: 
cld
mov ah, 0 
mov al, 13h 
int 10h 
mov al,40 
;call fill_disp 
mov di,0000h 
mov si,0000h 
mov bx,sprite 
;call draw_sprite 
p4: 
mov ah,01h 
int 16h 
jz p7 
mov ah,00h 
int 16h 
cmp al,'a' 
jz left_sprite 
cmp al,'d' 
jz right_sprite 
p7: 
p3: 
mov di,0000h 
mov si,0000h 
mov al,40 
call fill_disp 
mov di,0000h 
mov si,0000h 
mov bx,sprite 
call draw_sprite 
mov di,0000h
mov si,0000h
call draw_display 
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

PS: I can not understand what's the matter, I've been asking a couple of times how to solve this. No one can help, they say to look for an error, I’m looking for something, I’ve rummaged through everything through the debugger, well, there are no errors, ideally everything should work, I even tried to rewrite the code again, the results are different, but somehow there’s no sense

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question