Código da máquina x86, 1729 1619 1468 1382 bytes
Como funciona: os blocos são gerados por uma combinação de compactação RLE, imagens de 2 bits e código processual. Depois que os blocos são gerados na memória, o programa cria uma matriz de índices de bloco. Isso é carregado primeiro com o plano de fundo repetido. Depois disso, os tubos, blocos flutuantes, pirâmides e o mastro da bandeira são desenhados proceduralmente. Os canos, colinas, arbustos e pirâmides podem se estender abaixo do solo, mas ficam encobertos quando os ladrilhos da rocha são escritos a seguir. Finalmente, os valores do bloco do castelo são simplesmente copiados para o local correto. Para gerar o arquivo de imagem, o cabeçalho e a paleta BMP são armazenados no arquivo como dados e são gravados primeiro. O programa é executado através da matriz, gravando a linha apropriada do bloco correspondente para cada posição.
Uso: Execute mario.com, ele gerará "m.bmp", um arquivo de imagem BMP padrão. O arquivo é criado como um arquivo oculto, pois acabou sendo menos bytes.
Faça o download de um arquivo ZIP contendo o código fonte e o binário, além da saída.
Código de montagem para gerar o arquivo executável:
org 100h
code_start:
;xor cx,cx
mov cx,12+14+256*3
mov dx,filename
mov ah,0x3c
int 21h
mov bx,ax
push ax
;mov dx,BITMAPFILEHEADER
inc dx
inc dx
mov ah,0x40
int 21h
mov di,tiles
xor ax,ax
mov ch,48
rep stosw
cwd ; load the cloud sprite
mov si,cloud
call DrawSprite
call DrawHill
mov dx,14*256+12*16
PipeTileLoop: ;Pipe
mov si,pipe0
call DrawSprite
sub dh,2
jns PipeTileLoop
mov dx,32+12*16
call DrawSprite
mov dh,13
;mov si,pipe2
call DrawSprite
cwd
xor ax,ax ; move to the tile array
mov cl,6
MoveTileLoop:
call MoveTile
loop MoveTileLoop
mov word [BITMAPFILEHEADER+5+2],0x607 ; bushes
sub dl,3*16
mov cl,13
jnc MoveTileLoop
mov dx,0x1004
mov si,ball
call DrawSprite
mov dl,0
call MoveTile
xor bx,bx ; pole
pole:
mov word[bx+tiles+22*256+7],0x707
add bl,16;
jnc pole
mov word [BITMAPFILEHEADER+5+2],0x805 ; qbrick
mov si,qbrick
call DrawSprite
call MoveTile
mov byte[BITMAPFILEHEADER+5+3],4
mov al,1 ; bricks & castle
call Clear
mov al,23
call MoveTile ; black door
mov dx,0x800+64
BrickLoop:
xor dh,8
mov si,bricks
call DrawSprite
sub dl,dh
jg BrickLoop
cwd
call MoveTile ; left window
call MoveTile ; castle brick
mov al,3
mov di,image+15*256+16
mov cl,16
rep stosb
mov al,26
mov dl,16
call MoveTile ; reg brick
;mov dl,32
;mov si,door
call DrawSprite
;mov dl,32
call MoveTile ; door top
mov dx,48 +8*256
;mov si,cren
call DrawSprite
push si
mov dh,0
call MoveTile ; crenulation 1
mov si,image+48+256 +4
mov di,image+48+256*9+4
mov bl,7
CrenLoop:
mov cl,7
rep movsb
mov dl,256-7
add si,dx
add di,dx
dec bx
jnz CrenLoop
mov dl,3*16
call MoveTile ; crenulation 2
pop si
mov cl,3
jmp skip
LastLoop:
;call MoveTile ; right window
; block
; rocks
call DrawSprite
skip:
call MoveTile
loop LastLoop
xor ax,ax ; Begin drawing world using the tiles
call Clear
mov bl,48*4
BackgroundLoop:
lea di,[bx+image+2*256]
SmallHill:
mov al,10
mov cl,5
HillRow0:
stosb
inc ax
loop HillRow0
mov dword [di+256-4],10+11*256+256*256*14
mov byte [di+512-3],15
sub di,256-10
cmp di,image +256
ja SmallHill
mov si,fluff ; draw clouds, bushes
FluffDrawLoop:
lodsw
add ax,bx
add ax,image
xchg ax,di
lodsb
aam
mov cl,ah
;call DrawFluff;
mov ah,1
FluffLayer2:
stosb
inc ax
push cx
rep stosb
inc ax
stosb
pop cx
add di,256-2
sub di,cx
inc ax
dec ah
jns FluffLayer2
cmp si,pa
jl FluffDrawLoop
sub bl,48
jnc BackgroundLoop
;mov si,pa
mov cl,6
PipePlace:
lodsw
xchg bx,ax
mov di,image
mov word [bx+di],18+19*256
PipeLoop:
dec bh
mov word[bx+di],16+17*256
jnz PipeLoop
loop PipePlace
;mov si,dba ; draw the various floating blocks
mov cl,4
DrawBlockLoop:
lodsw
xchg ax,bx
mov ah,bl
cwd
lodsb
BlockLoop:
mov bl,al
mov byte [bx+di],ah
lodsb
cmp al,dh
mov dh,al
ja BlockLoop
dec si
loop DrawBlockLoop
mov bx,198+256*12
FlagPole: ; Draw flag pole
mov byte [bx+di],22
dec bh
jg FlagPole
inc si
;mov si,pyr ; pyramid blocks
mov cl,8
PyrMainLoop:
lodsw
shr ah,1
cwd
inc dx
jnc NoNeg
neg dx
NoNeg:
mov bx,ax
PyrDrawLoop:
mov byte [bx+di],32
dec bh
jnz PyrDrawLoop
add ax,dx
dec ah
jnz NoNeg
loop PyrMainLoop
;mov si,ground ; ground blocks
;mov di,image
mov bl,4
push di
GroundLoop:
lodsb
xchg ax,cx
mov al,33
rep stosb
lodsb
add di,ax
dec bx
jnz GroundLoop
push si
inc ch
mov si,di
sub si,cx
rep movsb
pop si
pop di
;push di
;mov si,copy ; Draw Castle, flag ball
mov dl,6
CopyLoop:
lodsw
mov cx,ax
shr cx,12
and ah,15
xchg bx,ax
CopyRun:
lodsb
mov [bx+di],al
inc bx
loop CopyRun
dec dx
jnz CopyLoop;
xor ax,ax
xor bx,bx ; image y ; write the image to file
pop dx
WriteTileStep:
WriteRowStep:
mov bl,0 ; image x
WriteStep:
pusha
mov ah,[bx+di]
mov bx,dx
add ax,tiles
xchg ax,dx
mov cl,16
mov ah,0x40
int 21h
popa
inc bx
cmp bl,212
jb WriteStep
add al,16
jnz WriteRowStep
inc bh
cmp bh,14
jl WriteTileStep
;pop bx
;mov ah,0x3e
;int 21h
;ret
DrawSprite: ; dx=x,y, si=data
pusha
mov bp,dx
;cwd
mov di,temp
push di
lodsw ; w, h*2+flag
mov dl,al
shr ah,1
pushf
mul ah
xchg bx,ax
popf
jc BitMapped
RunLoop:
lodsb
mov cl,al
shr cx,2
sub bx,cx
rep stosb
jnz RunLoop
jmp MoveData
BitMapped:
BitMappedLoop:
lodsb
mov cl,4
BitMappedQuad:
stosb
shr ax,2
loop BitMappedQuad
sub bx,4
jg BitMappedLoop
MoveData:
mov bx,sp
mov [bx+4],si
pop si
mov bx,di
lea di,[bp+image]
mov dh,-1
MoveLoop:
mov cl,dl
rep movsb
sub di,dx
cmp si,bx
jl MoveLoop
popa
ret
MoveTile: ; dx =x,y, bx=y,ax=t-1
inc ax
pusha
mov si,dx
xchg al,ah
xchg di,ax
mov ax,16
TileLoop:
mov cl,16
TileTrans:
mov bx,[si+image]
inc si
and bx,3
mov bl,[bx+BITMAPFILEHEADER+5]
mov [di+tiles],bl
inc di
loop TileTrans
add si,256-16
dec ax
jnz TileLoop
popa
add dl,16
ret
Clear: ; al = value
mov di,image
mov ch,48
rep stosb
ret;
DrawHill:
pusha
xor bx,bx
mov al,3
HillLoop:
lea di,[bx+image+6*16]
inc byte [di]
inc di
mov cl,16*5-2
sub cl,bl
sub cl,bl
rep stosb
inc byte [di]
inc bx
inc bh
cmp bl,16
jl HillLoop
mov si,spot
push si
mov dx,32-7+256*8 + 6*16
call DrawSprite
mov dl,32+17 + 6*16
pop si
call DrawSprite
mov dx,5*16 + 6*16
call DrawSprite
popa
ret
filename: db 'm','.'
BITMAPFILEHEADER: db 66,77,'P',0,12,0,1,2,3,0,26,3,0,0
BITMAPCOREHEADER: db 12,0,0,0,64,13,224,0,1,0,8,0
colors: db 252,148,92,0,0,0,252,252,252,252,188,60,176,188,252,12,76,200,0,168,0,16,208,128,56,152,252
;pal: db 0,1,2,3
cloud: db 88,32,224,5,114,5,228,5,122,5,224,5,122,5,228,9,106,5,6,5,240,102,5,4,5,240,5,86,5,10,5,252,5,78,5,4,5,6,5,252,4,13,66,5,8,5,92,13,16,17,136,5,14,7,42,5,100,9,14,5,4,9,18,9,4,9,120,5,14,11,14,7,18,5,96,5,26,5,34,5,10,9,116,5,26,7,22,5,84,13,18,11,18,15,34,9,108,5,38,5,6,5,84,5,22,27,6,23,38,108,5,34,5,4,5,88,5,10,19,14,19,18,7,34,5,108,9,26,5,92,5,10,7,10,7,26,7,54,5,120,5,18,5,92,5,10,7,46,7,46,5,128,17,56
spot: db 6,17,245,95,255,245,93,87,127,245,87,127,245,223
hilltop: db 16,3*2,0x9, 0x33, 0x9, 0x8, 0xD, 0x1B, 0xD, 0x1C, 0x19, 0x14
ball: db 8,17,80,5,244,31,253,127,253,127,249,127,249,127,228,31,80,5
pipe0: db 64,5,0x90,0xFA,0xAA,0xAE,0xFF,0xFF,0xBB,0x06,0xA9,0xAF,0xAA,0xEB,0xFF,0xFF,0xBB,0x6B,0x90,0xFA,0xAA,0xAE,0xFF,0xFF,0xAE,0x06,0xA9,0xAF,0xAA,0xEB,0xFF,0xFF,0xEF,0x6A
pipe1:db 32,4,8,113,8,129
pipe2:db 32,12,5,23,26,79,9,122,133
qbrick: db 16,33,85,85,85,85,254,255,255,127,222,255,245,119,254,191,246,127,254,191,254,127,254,255,245,127,254,191,246,127,254,191,86,127,254,215,106,127,254,218,107,127,254,218,107,127,254,90,233,127,254,171,250,127,222,255,255,119,254,255,255,127,168,170,170,42
bricks: db 8,16,33,14,5,30,5,30,5,18,33,30,5,30,5,30,5
door: db 16,32,0xFD, 0xFD, 0x89, 0x6, 0x39, 0xA, 0x39, 0x6, 0x41, 0xA, 0x31, 0x6, 0x5, 0xE, 0x29, 0xA, 0x5, 0x16, 0x19, 0x12, 0x5
cren: db 16,17,213,255,255,85,234,0,192,170,234,0,192,170,234,0,192,170,234,0,192,170,234,0,192,170,234,0,192,170,255,0,192,255
block: db 16,32,61,6,7,53,6,5,11,45,6,9,15,37,6,13,19,34,17,19,34,17,19,34,17,19,34,17,19,34,17,19,34,17,19,34,17,19,34,17,15,6,35,17,11,6,43,13,7,6,51,9,6,59,5
rocks: db 16,33,86,149,87,149,171,106,171,90,171,127,171,106,251,85,171,106,95,170,173,106,165,170,173,106,171,170,182,106,171,170,182,106,171,170,182,106,171,170,246,127,171,170,102,149,171,170,118,106,171,170,182,106,171,170,182,106,171,170,182,106,254,255,231,191
fluff: db 8,10,11, 19,11,11, 27,10,31, 36,11,21, 11,1,34, 23,1,14, 41,1,24
pa: db 28,3,38,4,46,5,57,5,163,3,179,3
dba:db 21,5
qb: db 16,21,23,78,106,109,112,170, 21,9
qb2: db 22,94,109,129,130, 27,5
ba: db 20,22,24,77,79,94,100,101,118,129,130,168,169,171 , 27,9
ba2: db 80,81,82,83,84,85,86,87,91,92,93,121,122,123,128,131,0
pyr: db 137,5*2+1,140,5*2,151,5*2+1,152,5*2+1,155,5*2,188,9*2+1,189,9*2+1,198,4
ground: db 69,2,86-69-2,3,153-86-3,2,256-153-2,0
copy: db 202,2+5*16,26,26,24,26,26, 202,3+5*16,26,26,28,26,26, 202,4+5*16,29,30,30,30,29, 203,5+3*16,31,26,25, 203,6+3*16,29,29,29, 198,12+16,20
temp: rb 256*48
tiles: rb 34*16*16
image: