View Single Post
  #3  
Old February 6th 20, 02:33 AM posted to alt.comp.periphs.videocards.nvidia
[email protected]
external usenet poster
 
Posts: 533
Default Skybuck's Open Source Project: Mario for TP7 and Delphi (10.2)

Would be nice if somebody could convert this ASM into some C or Pascal source code, or some pseudo code to explain/describe it's functionality/behaviour:

(This code may be x-mode related and somehow decodes the ASM bitmap below):

Here is a somewhat reduced example and also an example of the ASM bitmap:

Here is the code I need help with understanding:

const
VGA_SEGMENT = $A000;

VIR_SCREEN_WIDTH = SCREEN_WIDTH + 2 * 20;
VIR_SCREEN_HEIGHT = 182;

BYTES_PER_LINE = VIR_SCREEN_WIDTH div 4;

MAP_MASK = 2;

SC_INDEX = $03C4;

var
PageOffset: Word = 0;

procedure DrawImage (XPos, YPos, Width, Height: Integer; var BitMap);
{ Draw an image on the screen (NULL-bytes are ignored) }
begin
asm
push ds

mov ax, VGA_SEGMENT
mov es, ax

mov ax, YPos
cmp ax, VIR_SCREEN_HEIGHT
jb @NotNeg
jg @End
mov bx, ax
add bx, Height
jnc @End
@NotNeg:
mov bx, BYTES_PER_LINE
mul bx
mov di, XPos
mov bx, di
shr di, 1
shr di, 1
add di, ax { DI = (YPos * 80) + XPos / 4 }
add di, PageOffset

lds si, BitMap { Point to bitmap }

and bl, 3
mov cl, bl
mov ah, 1
shl ah, cl
sub bl, 4
mov cx, 4 { 4 planes }

@Plane:
push bx
push cx { Planes to go }
push ax { Mask in AH }

mov al, MAP_MASK
mov dx, SC_INDEX
out dx, ax

cld
push di
mov bx, Width
shr bx, 1
shr bx, 1
mov ax, BYTES_PER_LINE
sub ax, bx { Space before next line }
mov dx, Height
@Line:
mov cx, bx
shr cx, 1

push ax
pushf

@Pixel:
lodsw
or al, al
jz @Skip1
seges
mov [di], al
@Skip1:
inc di
or ah, ah
jz @Skip2
seges
mov [di], ah
@Skip2:
inc di
loop @Pixel

popf
rcl cx, 1
jcxz @Skip3

lodsb
or al, al
jz @Odd
stosb
jmp @Skip3
@Odd: inc di
@Skip3:
pop ax
add di, ax
dec dx
jnz @Line

pop di

pop ax
mov al, ah
mov cl, 4
shl al, cl
or ah, al { Mask for next byte }
rol ah, 1 { Bit mask for next plane }
pop cx { Planes }
pop bx
inc bl { Still in the same byte? }
adc di, 0
loop @Plane

@End:
pop ds
end;
end;

{ Example of ASM bitmap enemy }

procedure GRKOOPA000; assembler;
asm
db 0, 0, 0, 0, 0, 0, 23, 0, 0, 0, 0, 31, 0, 0, 0
db 0, 31, 16, 0, 0, 0, 31, 81, 0, 0, 0, 31, 77, 0, 0
db 0, 31, 78, 0, 0, 0, 31, 78, 0, 0, 16,127, 53, 0, 0
db 16, 78, 83, 17, 17, 16, 53, 74,113,112, 16, 73,104,116,115
db 16, 16,104,115,114, 0, 16, 28,129,129, 0, 83, 30,115,114
db 0, 76, 30,128,112, 0, 16, 30,114,113, 0, 16,111,114,113
db 0, 0,135, 18, 96, 0, 0,130, 26, 26, 0, 0, 16,134,134
db 0, 16, 76,120,120, 0, 29, 83, 0, 76, 0, 16, 16, 0, 16
db 0, 0, 0, 0, 0, 0, 23, 0, 0, 0, 0, 31, 0, 0, 0
db 0, 31, 0, 0, 0, 16, 31, 16, 0, 0, 16, 31, 76, 0, 0
db 16, 31, 77, 0, 0, 18,127, 77, 0, 0, 84, 78, 75, 0, 0
db 84, 78, 16,128, 0, 83, 74, 25,114,112, 76, 16, 31,116,113
db 76, 81, 31,129,115, 18, 83, 20,118,112, 0, 77, 16,117,113
db 0, 77, 16,115,112, 0, 83, 16,112,114, 0, 74, 23,114,114
db 0, 0, 31, 16, 18, 0, 0,134, 26, 26, 0, 16,128,134,134
db 0, 76, 76,120,120, 0, 77, 83, 17,132, 0, 16, 16, 0, 16
db 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 16, 20, 0, 0, 0
db 23, 20, 0, 0, 0, 18, 20, 0, 0, 0, 17, 20, 17, 0, 0
db 17,125, 17, 0, 0, 25,133, 17, 0, 0, 78, 78, 17, 0, 0
db 77, 78, 0,128, 0, 78, 76,104,118, 0, 78, 81,104,129, 16
db 78, 76,104,117,113, 74, 74,113,119,114, 0, 73, 96,119, 96
db 0, 73,114,116,114, 0, 73,114,113,114, 0, 18,113,112,112
db 0, 16,104,112, 16, 0, 16, 27, 26, 26, 0, 74,134,134, 55
db 0, 77,120,120, 19, 0, 77, 17, 76, 28, 0, 16, 0, 16, 16
db 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 22, 19, 0, 0, 0
db 28, 16, 0, 0, 0, 25,120, 0, 0, 0, 22, 73, 0, 0, 0
db 23, 77, 0, 0, 0,135, 53, 0, 0, 0, 76, 78, 0, 0, 0
db 74, 53, 0,112, 0, 78, 76,128,113, 0, 77, 81,114,130, 0
db 83, 81,114,129, 16, 83, 23,112,118, 16, 17, 23,113,117, 16
db 17, 23,128,114, 16, 0, 23,115,112, 16, 0, 23,113,112, 16
db 0,122, 96, 16, 0, 0, 18, 26, 26, 16, 0, 74,134,134, 16
db 0, 77,120,120, 0,104, 83, 0, 76, 16, 16, 16, 0, 16, 16
end;

Bye,
Skybuck.