>我有在ASM文件中绘制像素的功能。现在我有了所有位图的像素。但是我该怎么画呢?我尝试绘制每个像素的像素 - 但 BMP 文件有 120 000 像素和分辨率请求 160 000。如何绘制位图?(它是24位位图,但我想绘制所有图像)什么是填充物 - Vesa 颜色与此相似吗?谢谢。
编辑:
好的 - 我的 BMP 没有填充字节 - 因此我删除了 dword 对齐方式,它可以工作......如何确定 BMP 何时具有剑对齐?
如何确定 BMP 何时具有剑对齐?
BMP 文件 (DIB) 中的扫描线应始终与 DWORD 对齐,除非图像使用 RLE 压缩(例如,请参阅位图标头类型文档的最后一段)。
可以将每个扫描线的 DWORD 数计算为:
dwords = (int)(((biBitCount * biWidth) + 31) / 32);
(注意:如果是biBitCount == 15
,您应该改用 16)。
这段代码运行良好 - 只缺少 16 位 BMP - 它正在处理中......
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) 在这里:
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