; code.asm
; C:>nasm code.asm -o code.xbe
; This includeds the header information for the xbe
file.
%include "header.asm"
; CODE ** CODE ** CODE ** CODE ** CODE ** CODE **
CODE ** CODE ** CODE ** CODE ** CODE
; CODE ** CODE ** CODE ** CODE ** CODE ** CODE **
CODE ** CODE ** CODE ** CODE ** CODE
; Lets jump to the entry point in our code e.g. like
we do with main() in C...
jmp start
framebuffer:
dd 0xf0010000 + 640*320 + 80;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DrawPixel:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Setup Function
push ebp ; Setup
our function
mov ebp, esp
; ecx = y;
; ebx = x
; ecx*=640
; ecx = x+y*640
mov ecx, DWORD [ebp+12] ;
put y pos in ecx
imul ecx, 640
mov ebx, DWORD [ebp+8] ;
put x pos int edx
add ecx, ebx ; hence
ecx = x+y*640
mov ebx, DWORD [framebuffer] ;
Get the location in memory
; where we
will put this pixel
; e.g.
framebuffer
; Put blue pixel into memory
mov eax, DWORD [ebp+16] ;
put pixel colour in eax
and eax, 255
mov BYTE [ebx+ecx*4], al
; Put green pixel into memory
mov eax, DWORD [ebp+16] ;
put pixel colour in edx
and eax, 65280
shr eax, 8
mov BYTE [ebx+ecx*4+1], al
; Put red pixel into memory
mov eax, DWORD [ebp+16]
and eax, 16711680
shr eax, 16
mov BYTE [ebx+ecx*4+2], al
; tidy up and return from function call
pop ebp
ret 0
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; End of DrawPixel
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Globals
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xpos:
dd 310 ; width/2 = 640/2 =
310
ypos:
dd 240 ; height/2 = 480/2 =
240
colour:
dd 0xff0000 ; Red colour pixel
xloop: ; We do a simple
loop and draw a small line
dd 0x50
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a_loop:
; This is the same as DrawPixel(x, y, colour)
push DWORD [colour]
push DWORD [ypos]
push DWORD [xpos]
call DrawPixel
add esp, 12
; Increment the ypos.
mov eax, [ypos]
add eax, 1
mov [ypos], eax
; Loop around 100 times back to loopx - as
sometimes people say...I can't see
; the red pixel...so using this simple asm
loop... we've managed to draw a
; simple line :)
mov eax, [xloop]
dec eax
mov [xloop],eax
jne a_loop
; Program has now finished, so we simply just
stay here and loop :)
bbb:
jmp bbb;
; END OF CODE ** END OF CODE ** END OF CODE ** END
OF CODE ** END OF CODE ** END OF CODE
; END OF CODE ** END OF CODE ** END OF CODE ** END
OF CODE ** END OF CODE ** END OF CODE
TIMES 0x6000-($-$$) DB 0x90 ; this will make our
section finish at 0x6000
; from the start of
the file.
TIMES 0x7000-($-$$) DB 0x0 ; And of course, this
will make our file size
; equal to 0x7000 a
nice round number -
; 0x7000 is
28672bytes... so if you assemble the file
; you should find
its that size exactly. |