-4

this is a question i really need help on, i am currently writing an OS in FASM assembly and have a decent output with icons being from the ASCII table. I want to know if you can have images show up on your assembly program. I couldn't find a website so a link to a website that can help would be perfect, or no if its not possible.

  • Really? I previously recommended that you look at http://osdev.org. It very clearly explains this. You need to learn how to create and manage a frame buffer. – David Hoelzer May 31 '17 at 11:03
  • osdev.org does not show how to upload bitmaps to a assembly files in FASM i looked but thank you for responding. – Reese Houseknecht May 31 '17 at 17:35

1 Answers1

1

First of all, You need to know the file structure You are implementing.
You can check it for example on wikipedia, for bmp here: https://en.wikipedia.org/wiki/BMP_file_format
or here: http://www.dragonwins.com/domains/getteched/bmp/bmpfileformat.htm - I prefer using this one
As you see, we have to implement a bit of a header and then we can just create the file.
Lets write some sample code:

File_begin:
file_header:
        .bfType: db "BM"
        .bfSize: dd File_end - File_begin
        .bfReserved1: dw 0
        .bfReserved2: dw 0
        .bfOffBits: dd PIXEL_DATA_START  
image_header:
        .biSize: dd image_header_end-image_header
        .biWidth: dd 3
        .biHeight: dd 3
        .biPlanes: dw 1
        .biBitCount: dw 32
        .biCompression: dd 0
        .biSizeImage: dd 0
        .biXPelsPerMeter: dd 0
        .biYPelsPerMeter: dd 0
        .biClrUsed: dd 0
        .biClrImportant: dd 16
image_header_end:


PIXEL_DATA_START:
dd 0x00000000, 0x00000000, 0x00000000
dd 0x00ffffff, 0x00ffffff, 0x00000000
dd 0x00ffffff, 0x00000000, 0x00ffffff

File_end:

This is a really simple BMP file that displays a 3x3 glider symbol.
As you see the BMP file format is really simple to implement- just refer to the documentation I linked to if you need explanation of any of the fields.
One thing to keep in mind is that you should define bytes in the reversed order as things are little endian in PC architecture.

My code compiles with FASM and runs on every platform as it is just an image- no processor jobs at all.
So, to answer your question- look up the file header format and then just implement it. The same technique works with everything you do in assembly, so the file would look exactly the same way in a normal OS source.
After you create or parse such file, you should write every single pixel to the framebuffer using the following formula:
Pixel address = framebuffer address + pixelX * colordepth + pixelY * screenWidth*ColorDepth
for example:

mov eax, [framebuffer_addr]
add eax, pixelX * cDepth ; simplified code, in normal circumstances you will have to muliply it first
add eax, pixelY * cDepth * scrWidth
mov [eax], 0x00ff0000 ;; this will paint your desired pixel red

Process every pixel of the image and write it to the framebuffer and you are done.