0
votes

I have function for drawing pixels in ASM file. Now I have all bitmap's pixels. But how can I draw it? I tried draw pixel per pixel - but BMP file have 120 000 pixels and resolution request 160 000. How can I draw bitmap? (it is 24 bit bitmap, but I want draw all images) What is filler - is Vesa color similar to this? Thank you.

EDIT:

OK - my BMP not have fill byte - therefore I removed dword alignment and it works... How can I determine, when the BMP have dword alignment?

2
You haven't specified which OS, graphics API and/or graphics mode you're targeting.Michael
Why? My question is very general... I have only this ask: How can I determine, when the BMP have dword alignment?Matesax
Here: fileformat.info/format/bmp/corion.htm 1 byte filler Here: en.wikipedia.org/wiki/BMP_file_format Two byte alignment in 24bit BMP. And my image not have any aligment... Now I drawing without alignment and it works...Matesax
You're also asking how to draw the bitmap.Michael
But pixel per pixel - in Vesa...Matesax

2 Answers

0
votes

How can I determine, when the BMP have dword alignment?

The scanlines in a BMP file (DIB) should always be DWORD-aligned, except if the image uses RLE compression (see e.g. the last paragraph of the bitmap header types documentation).

You can calculate the number of DWORDs per scanline as:

dwords = (int)(((biBitCount * biWidth) + 31) / 32);

(Note: in the case of biBitCount == 15 you should use 16 instead).

0
votes

OK - this code working very well - only 16 bits BMP missing - it is in process...

DrawImage:

    cmp word [ID], "BM"
    je DrawBMP

    ret

DrawBMP:

    cmp word [Depth], 24
    je DrawBMP24

    cmp word [Depth], 32
    je DrawBMP32

    ret

DrawBMP24:

    pushad
    mov [.X], eax
    mov [.Y], ebx
    mov [.x], eax
    mov [.y], ebx

    xor edx, edx
    mov [.align], edx
    mov ebx, 4

    mov eax, [Width]
    div ebx
    cmp edx, 0
    je .skip

    mov dword [.align], 1
    xor edx, edx

    mov eax, [Width]
    inc eax
    div ebx
    cmp edx, 0
    je .skip

    mov dword [.align], 2
    xor edx, edx

    mov eax, [Width]
    add eax, 2
    div ebx
    cmp edx, 0
    je .skip

    mov dword [.align], 3

.skip:

    mov esi, BMP
    add esi, [Offset]
    mov [.pointer], esi
    mov ebx, [Height]
    add [.y], ebx

.drawLine:

    mov esi, [.pointer]
    mov al, [esi]
    mov [.color], al
    mov al, [esi + 1]
    mov [.color + 1], al
    mov al, [esi + 2]
    mov [.color + 2], al
    add dword [.pointer], 3

    mov esi, .params
    call DrawPixel

    inc dword [.x]
    mov ebx, [Width]
    add ebx, [.X]
    cmp [.x], ebx
    jne .drawLine

    mov ebx, [.X]
    mov [.x], ebx
    dec dword [.y]

    mov ebx, [.pointer]
    add ebx, [.align]
    mov [.pointer], ebx

    mov ebx, [.Y]
    cmp [.y], ebx
    je .done

    jmp short .drawLine

.done:

    mov dword [.y], 0
    popad
    ret

.X dd 0
.Y dd 0
.align dd 0
.pointer dd 0

.params:

    .color dd 0
    .x dd 0
    .y dd 0

DrawBMP32:

    pushad
    mov [.X], eax
    mov [.Y], ebx
    mov [.x], eax
    mov [.y], ebx
    mov esi, BMP
    add esi, [Offset]
    mov [.pointer], esi
    mov ebx, [Height]
    add [.y], ebx

.drawLine:

    mov esi, [.pointer]
    mov eax, [esi]
    mov [.color], eax
    add dword [.pointer], 4

    mov esi, .params
    call DrawPixel

    inc dword [.x]
    mov ebx, [Width]
    add ebx, [.X]
    cmp [.x], ebx
    jne .drawLine

    mov ebx, [.X]
    mov [.x], ebx
    dec dword [.y]

    mov ebx, [.Y]
    cmp [.y], ebx
    je .done

    jmp short .drawLine

.done:

    mov dword [.y], 0
    popad
    ret

.X dd 0
.Y dd 0
.pointer dd 0
.params:

    .color dd 0
    .x dd 0
    .y dd 0

VESA (VBR) is here:

bits 16
org 0x7C00

Boot:

    mov dl, 0x80            ; 80 - FF => HardDisk
    mov si, .imageStruct
    mov cx, 14

.loadPart:

    mov ah, 0x42            ; Extended Read Sectors From Drive
    int 0x13

    add dword [.imageStruct + 6], 2144
    add word [.imageStruct + 8], 67

loop .loadPart

    mov ah, 0x42
    mov si, .kernelStruct
    int 0x13

    jnc InitializeVESA

    mov si, .error
    mov ah, 0xE
    mov cx, 29

.writeChar:

    lodsb
    int 0x10
    loop .writeChar

    mov ah, 0
    int 0x16                ; Wait for keystroke
    mov ax, 0
    int 0x19                ; Reboot the system

.imageStruct:

    dw 16
    dw 67
    dd BMP              ; Offset : Segment
    dq 26

.kernelStruct:

    dw 16               ; byte of structure length + empty byte
    dw sectorsForLoad       ; sectors for load count
    dd Kernel               ; out address
    dq 1                    ; start sector

.error db "Fatal Error! Press any key..."

InitializeVESA:

    in al, 0x92
    or al, 2
    out 0x92, al

    mov bx, 0x4118
    mov ax, 0x4F01
    mov di, ModeInfo
    mov cx, bx
    int 0x10

    mov ax, 0x4F02
    int 0x10

    cli
    lgdt [.GDTR]

    mov eax, cr0
    or al, 1
    mov cr0, eax

; CR0: PG|----RESERVED----|NE|ET|TS|EM|MP|PE
; PE Bit 0. The Protected Environment flag. This flag puts the system into protected mode when set.
; MP Bit 1. The Monitor Coprocessor flag. This flag controls the operation of the "WAIT" instruction.
; EM Bit 2. The Emulate flag. When this flag is set, coprocessor instructions will generate an exception.
; TS Bit 3. The Task Switched flag. This flag is set automatically when the processor switches to a new task.
; ET Bit 4. The Extension Type flag. ET (also called "R") tells us which type of coprocessor is installed. If ET = 0, an 80287 is installed. if ET = 1, an 80387 is installed.
; NE Bit 5. New exceptions. If this flag is clear, FPU exceptions arrive as interrupts. If set, as exceptions.
; PG Bit 31. The Paging flag. When this flag is set, memory paging is enabled. We will talk more about that in a second.

    mov ax, 0x8
    mov ds, ax
    mov es, ax
    mov ss, ax

    jmp 0x10:Kernel

.GDT dq 0, 0xCF92000000FFFF, 0xCF98000000FFFF

; Selector 0x00 cannot be used | 0x10 will be our code | 0x08 will be our data

.GDTR:

    dw 0x1F
    dd .GDT

times 510-($-$$) db 0
dw 0xAA55

%include "source/kernel/SMA.asm"
%include "source/kernel/features/Drawing.asm"
%include "source/kernel/features/Console.asm"
%include "source/kernel/features/Keyboard.asm"
%include "source/kernel/features/KeyMap.inc"
%include "source/kernel/features/Int.asm"
%include "source/kernel/features/String.asm"

times 512 - (($-$$) % 512) db 0
sectorsForLoad equ ($-$$-512) / 512

section .bss

ModeInfo:

    ModeAttributes resw 1
    WinAAttributes resb 1
    WinBAttributes resb 1
    WinGranularity resw 1
    WinSize resw 1
    WinASegment resw 1
    WinBSegment resw 1
    WinFuncPtr resd 1
    BytesPerScanLine resw 1
    ScreenWidth resw 1
    ScreenHeight resw 1
    XCharSize resb 1
    YCharSize resb 1
    NumberOfPlanes resb 1
    BitsPerPixel resb 1
    NumberOfBanks resb 1
    MemoryModel resb 1
    BankSize resb 1
    NumberOfImagePages resb 1
    ReservedPage resb 1
    RedMaskSize resb 1
    RedMaskPos resb 1
    GreenMaskSize resb 1
    GreenMaskPos resb 1
    BlueMaskSize resb 1
    BlueMaskPos resb 1
    ReservedMaskSize resb 1
    ReservedMaskPos resb 1
    DirectColorModeInfo resb 1
    ; VBE 2.0 extensions
    PhysBasePtr resd 1
    OffScreenMemOffset resd 1
    OffScreenMemSize resw 1

resb 206 ; Odsazení od ModeInfo

BMP:

    ID resw 1
    FileSize resd 1
    Reserved1 resb 1
    Reserved2 resb 1
    Reserved3 resb 1
    Reserved4 resb 1
    Offset resd 1
    HeaderLength resd 1
    Width resd 1
    Height resd 1
    NumOfPlanes resw 1
    Depth resw 1
    Compression resd 1
    BytesCount resd 1
    Hresolution resd 1
    Xresolution resd 1
    NumOfUsedColors resd 1
    NumOfImportantColors resd 1