图形在重复,装配引导加载程序

时间:2018-07-31 01:23:55

标签: assembly nasm x86-16 bootloader vga

此代码应仅将顶部像素着色为红色。像素不断重复着色,否则无论瓷砖多少改变了行大小和颜色(我指定只有前2000个像素才会着色) 我认为是因为DUBBLE_BUFFER_START的位置,但我不知道将双缓冲区放在哪里,除了视频存储器0xa000的空间之后。有什么建议么?我可以采取的其他更好的做法

start.asm

[bits 16]
[org 0x7c00]
%include "kernel.asm"
;%include "std.asm"
%include "graphics.asm"
xor ax, ax
mov ss, ax
mov sp, STACK_STD_START
mov bp,sp
mov ds, ax
mov es, ax
mov si, 0
; cli
; lgdt [gdtinfo]   ; load gdt register
; mov  eax, cr0   ; switch to pmode by
; or al,1         ; set pmode bit
; mov  cr0, eax
; sti
; [bits 32]

call GRAPHICS_START
jmp _start

 _start:

    mov ax,0
    mov bl,4
.repeat:    

    call GRAPHICS_BLIT
    cmp ax,2000
    jge .done
    inc ax
    jmp .repeat
    .done:
    call GRAPHICS_UPDATE
hang:
jmp hang

OS_WELCOME db 'What is giong on',0
OS_USERNAME_DESCRIPT db 'Username:',0

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

kernel.asm

__Kernel_asm:
jmp _KERNEL_ASM_END

;STD STORAGE SPACE
SEAM_STD_BUFFER equ 0x8000
SEAM_STD_LIMIT equ 0x80ff

;GRAPHICS STORAGE SPACE

GRAPHICS_DEFAULT_START equ 0xa000
GRAPHICS_DEFAULT_END equ 0x19A00
MAX_GRAPHICS_SIZE equ 0xFA00
DUBBLE_BUFFER_START equ 0x19B00
DUBBLE_BUFFER_END equ 0x29500

;ARGUMENT STORAGE

STACK_STD_START equ 0x8100
STACK_STD_LIMIT equ 0x81ff

;REGISTER STORAGE

AX_STORAGE_PRESERVATIVE equ 8200h
BX_STORAGE_PRESERVATIVE equ 8202h
CX_STORAGE_PRESERVATIVE equ 8204h
DX_STORAGE_PRESERVATIVE equ 8206h
SI_STORAGE_PRESERVATIVE equ 8208h
DI_STORAGE_PRESERVATIVE equ 8210h
BP_STORAGE_PRESERVATIVE equ 8212h
IP_STORAGE_PRESERVATIVE equ 8214h
CS_STORAGE_PRESERVATIVE equ 8216h
DS_STORAGE_PRESERVATIVE equ 8218h
SS_STORAGE_PRESERVATIVE equ 8220h
ES_STORAGE_PRESERVATIVE equ 8222h
STD_MODE:
    mov SI,STACK_STD_START
ret
dalloc_std: ; (ptr si)
    mov al,[si]
ret
alloc_std: ;(si place to allocate,al byte value)
    mov [si], al
ret
free_std: ;(si ptr at place start to free, ax at end )
    mov [si],byte 0
    cmp si,ax
    je .done
    inc si
    jmp free_std
    .done:
ret
alloc_stack_byte: ; (al byte to store)
mov [bp],al
ret
dealloc_stack_byte: ; (al byte to give)
mov al,[bp]
ret
alloc_stack_word: ; (ax word to store)
mov [bp],ax
ret
dealloc_stack_word: ; (ax word to give)
mov ax,[bp]
ret
STORE_AX:
mov [AX_STORAGE_PRESERVATIVE],AX
ret
STORE_BX:
mov [BX_STORAGE_PRESERVATIVE],BX
ret
RESTORE_AX:
mov AX,[AX_STORAGE_PRESERVATIVE]
ret
RESTORE_BX:
mov BX,[BX_STORAGE_PRESERVATIVE]
ret
STORE_CX:
mov [CX_STORAGE_PRESERVATIVE],CX
ret
RESTORE_CX:
mov CX,[CX_STORAGE_PRESERVATIVE]
ret
STORE_DX:
mov [DX_STORAGE_PRESERVATIVE],DX
ret
STORE_SI:
mov [SI_STORAGE_PRESERVATIVE],SI
ret
STORE_DI:
mov [DI_STORAGE_PRESERVATIVE],DI
ret
STORE_BP:
mov [BP_STORAGE_PRESERVATIVE],BP
ret
_KERNEL_ASM_END:

graphics.asm

**

GRAPHICS_MODE:
jmp GRAPHIC_MODE_END
_32_BITS_MODE:
    jmp contin
    ret
GRAPHICS_START:
    mov DI, GRAPHICS_DEFAULT_START
    mov ES,DI
    mov AX,DI
    mov ax,DUBBLE_BUFFER_START
    break:
    mov DS,ax
    xor ax,ax
    mov SI,AX
    mov DI,AX
    mov AH, 0
    mov AL, 13h
    int 10h
    ret
GRAPHICS_UPDATE:;()
    call STORE_CX
    mov cx,64000
    mov SI,0
    mov DI,0
    rep movsb
    call RESTORE_CX
    mov SI,0
    mov DI,0
    ret
GRAPHICS_BLIT:;(ah xposition, al y position, bl color)
    call STORE_AX
    call STORE_BX
    mov si,ax
    mov [si], bl
    call RESTORE_AX
    call RESTORE_BX
    ret
contin:
    ;[bits 32]
    ret
GRAPHIC_MODE_END:

**

0 个答案:

没有答案