www.xbdev.net
xbdev - software development
Saturday April 4, 2026
Home | Contact | Support | XBOX Programming More than just a hobby...
     
 

XBOX Programming

More than just a hobby...

 


Blitting an image to the screen



Screenshot - full screen - see the drawn image in the top left.
Screenshot - full screen - see the drawn image in the top left.


DownloadSourceCode


The demo source code and xbe was developed in nasm, and makes the assumption that your using a PAL xbox. Again if your not using a pal xbox, the code seems to run perfectly well...but the image is blitted offset on the screen. You should put some code to check your xbox configuration and screen settings etc...which I might put in later. A screenshot of what to expect is shown on the right... its not much...but it blitz a raw image to the screen.


How did I get a raw image....well I took a 24bit bitmap and stripped off the header information...so that the file is just a raw image of Red Green Blue values... Again you could improve the code to check the bmp file header...and read in the appropriate data.



A nice next move, would probably be to animate an image.... possibly put in a small loop, and have a ball bounce around the screen....or maybe even a rotating cube? All this asm might make some people feel a little freaked out...especially when its written by someone else...and I'm sure my asm could do with more commenting. So our next move will be to compile our code using a compiler....create a windows exe...then convert it to a raw binary using 'ExeToBin.exe'...and put the header info in.


We can do slightly more complex code then....put in structures...and write functions ....and once we get to a confortable level....we can then maybe write an exe to xbe converter...or even an xbe linker? Of course we'll have to start looking into debugging... as our code grows, debug information if vital. But we'll soon get there.


Assembly Code (NASM)


The full code can be downloaded above (see above link) - however, the key lines of code in assembly are given below.

; 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;

; Now I've put all our useful functions/assembly algorithms into a seperate file
; called xlibrary, so we can just call them when we need them :)
%include "xlibrary.asm"

; I've attached the binary file onto the end of the xbe :)


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Globals
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xpos:
dd    310                ; width/2 = 640/2 = 310
ypos:
dd    240                ; height/2 = 480/2 = 240    
colour:
dd    0xff0000         ; Red colour pixel

ii:
dd 0x0;

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;for(unsigned int y=0; y<imageHeight; y++)
;{
;    for(unsigned int x=0; x<imageWidth; x++)
;    {
;        // Get the rgb value from our bits array in pic.h
;        unsigned int pixelrgb = imageBits[y*(imageWidth-1)+x];
;        setpixel(x -100, y+50, pixelrgb);
;    }
;}

jmp gogogo

fxleft:
dd    0x64        ; 100 in decimal
fxtop:
dd    0x60

fimagewidth:
dd 0x184        ; or in decimal 388
fimageheight:
dd 0x6C            ; decimal value is 108


gogogo:

push DWORD [fimageheight]
push DWORD [fimagewidth]
push DWORD [fxtop]
push DWORD [fxleft]
push mypic

call BlitRawRGBImage
add     esp, 5*4


;                       8        12      16        20          24
; BlitRawRGBImage( pointerdata, xleft, xtop, widthimage, heightimage )


    call    FlashingLeds
    
    ; 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


%include "picture.asm"

; The file is now 200k in size :)
TIMES 0x200000-($-$$) DB 0x90    ; this will make our section finish at 0x6000
                                ; from the start of the file.

TIMES 0x201000-($-$$) 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.
                                
ENDFILE:

;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.




 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2026 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.