; ------------------------------------------------------------------------
; A Function to put a sprite to the screen
; void put_sprite(char* ps_sprite, int ps_x, int ps_y)
; char* ps_sprite - The picture to show to the screen
; int ps_x - The x pos to show the pic to
; int ps_y - The y pos to show the pic to
; ------------------------------------------------------------------------
; EQUATE SECTION
;// PARAMETERS
PS_SPRITE_POS EQU 4
PS_X_POS EQU 6
PS_Y_POS EQU 8
PS_WIDE_POS EQU -4
PS_HIGH_POS EQU -2
DATASEG
ps_x dw 0
ps_x_start dw 0
ps_y dw 0
ps_wide dw 0
ps_color db 0
ps_count dw 0
ps_total dw 0
CODESEG
proc put_sprite
;// Create a Base Pointer
push bp;
mov bp, sp;
;// Push Registers Onto Stack
PushReg <ax,bx,cx,dx,si>
;// Get the parameters
mov ax, [bp + PS_X_POS]
mov [ps_x], ax
mov [ps_x_start], ax
mov ax, [bp + PS_Y_POS]
mov [ps_y], ax
mov si, [bp + PS_SPRITE_POS]
;// The total bytes in the image
mov ax, [si + PS_WIDE_POS]
mov [ps_wide], ax
mul [WORD si + PS_HIGH_POS]
mov [ps_total], ax
;// Set the counter variable
mov [ps_count], 0
ps_loop:
mov bx, [ps_count]
cmp bx, [ps_total]
jae ps_loop_done
;// Get the current color
mov al, [si]
mov [ps_color], al
;// Put pixel
mov al, [ps_color]
mov ah, 0Ch ;// Put Pixel to mode 13 screen
mov cx, [ps_x]
mov dx, [ps_y]
int 10h
;// Increment all the variables
inc [ps_count]
inc [ps_x]
inc si
mov ax, [ps_x]
sub ax, [ps_x_start]
cmp ax, [ps_wide]
jb ps_loop
mov ax, [ps_x_start]
mov [ps_x], ax
inc [ps_y]
jmp ps_loop
ps_loop_done:
;// Pop Registers Off the Stack
PopReg <si,dx,cx,bx,ax>
pop bp;
ret
endp put_sprite