Загрузчик с текстом и графикой... как?(С носом)

Ниже у меня есть код, который рисует 3 круга в 3 разных цветах... это хорошо... но как мне добавить текстовую строку? Спасибо. Я провел несколько тестов на virtualbox (windows), но не повезло. Есть идеи, как это работает?

BITS 16
ORG 100h

push 0a000h           ;Video memory graphics segment
pop es

mov ax, 0013h         ;320x200@8bpp
int 10h


push 0Eh              ;Blue
push 10               ;cX
push 10               ;cY
push 10               ;Radius
call drawFilledCircle

push 02h              ;Blue
push 40               ;cX
push 40               ;cY
push 30               ;Radius
call drawFilledCircle

push 06h              ;Blue
push 140              ;cX
push 100              ;cY
push 70               ;Radius
call drawFilledCircle



;Wait for a key
xor ah, ah
int 16h
loc   db "KERNEL  IMG"

.LOOP:
          push    cx
          mov     cx, 0x000B                          ; eleven character name
          mov     si, loc
          ; image name to find
          push    di
     rep  cmpsb                                       ; test for entry match
          pop     di
          ;je      LOAD_FAT
          pop     cx
          add     di, 0x0020                          ; queue next directory entry
          loop    .LOOP
          ;jmp     FAILURE
;Restore text mode
mov ax, 0003h
int 10h

;Return
mov ax, 4c00h
int 21h


;Color
;cX
;cY
;R
drawFilledCircle:
 push bp
 mov bp, sp

 sub sp, 02h

 mov cx, WORD [bp+04h]   ;R

 mov ax, cx              
 mul ax                  ;AX = R^2
 mov WORD [bp-02h], ax   ;[bp-02h] = R^2



 mov ax, WORD [bp+06h]
 sub ax, cx              ;i = cY-R
 mov bx, WORD [bp+08h]
 sub bx, cx              ;j = cX-R

 shl cx, 1
 mov dx, cx              ;DX = Copy of 2R

.advance_v:
 push cx
 push bx

 mov cx,  dx

.advance_h:
  ;Save values
  push bx
  push ax
  push dx

  ;Compute (i-y) and (j-x)
  sub ax, WORD [bp+06h]
  sub bx, WORD [bp+08h]

  mul ax                  ;Compute (i-y)^2

  push ax
  mov ax, bx             
  mul ax
  pop bx                  ;Compute (j-x)^2 in ax, (i-y)^2 is in bx now

  add ax, bx              ;(j-x)^2 + (i-y)^2
  cmp ax, WORD [bp-02h]   ;;(j-x)^2 + (i-y)^2 <= R^2

  ;Restore values before jump
  pop dx
  pop ax
  pop bx

  ja .continue            ;Skip pixel if (j-x)^2 + (i-y)^2 > R^2

  ;Write pixel
  push WORD [bp+0ah]
  push bx
  push ax
  call writePx


.continue:

  ;Advance j
  inc bx
 loop .advance_h

 ;Advance i
 inc ax


 pop bx            ;Restore j
 pop cx            ;Restore counter

loop .advance_v

 add sp, 02h


 pop bp
 ret 08h



;Color
;X
;Y
writePx:
 push bp
 mov bp, sp

 push ax
 push bx

 mov bx, WORD [bp+04h]
 mov ax, bx
 shl bx, 6
 shl ax, 8
 add bx, ax       ;320 = 256 + 64

 add bx, WORD [bp+06h]
 mov ax, WORD [bp+08h]

 ;TODO: Clip

 mov BYTE [es:bx], al

 pop bx
 pop ax

 pop bp
 ret 06h





times 510-($-$$) db 0 ; Fill the rest with zeros
dw 0xAA55  ; Boot loader signature

2 ответа

но как я могу добавить текстовую строку?

Вы решили использовать видео режим 320x200 256 цветов 13h.
Для вывода текста вы можете использовать каждую функцию BIOS, связанную с выводом текста, так же, как вы это делаете на текстовом видеоэкране.

В этом режиме видео используется шрифт 8x8, поэтому вы можете поместить курсор в любую из 40x25=1000 символьных ячеек.

Пример написания красной буквы B в центре экрана:

mov dx, 0C14h  ;DH=12  row,               DL=20 column
mov bh, 0      ;BH=0   display page
mov ah, 02h    ;AH=02h set cursor position function
int 10h        ;video BIOS interrupt

mov bx, 000Ch  ;BH=0   display page,      BL=12 red
mov ax, 0E42h  ;AH=0Eh teletype function, AL=66 capital B
int 10h        ;video BIOS interrupt

BITS 16

[ORG 0x7C00]




;ORG 100h

 

push 0a000h           ;Video memory graphics segment
pop es

mov ax, 0013h         ;320x200@8bpp
int 10h


push 0Eh              ;Blue
push 10              ;cX
push 10               ;cY
push 10          ;Radius
call drawFilledCircle

push 02h              ;Blue
push 40              ;cX
push 40               ;cY
push 30           ;Radius
call drawFilledCircle

push 06h              ;Blue
push 140              ;cX
push 100               ;cY
push 70           ;Radius
call drawFilledCircle




;Wait for a key
;xor ah, ah
;int 16h

 


main:  ; Label for the start of the main program

 mov ax,0x0000 ; Setup the Data Segment register
  ; Location of data is DS:Offset
 mov ds,ax ; This can not be loaded directly it has to be in two steps.
  ; 'mov ds, 0x0000' will NOT work due to limitations on the CPU

 mov si, HelloWorld ; Load the string into position for the procedure.


 call PutStr ; Call/start the procedure






;jmp $  ; Never ending loop

; Procedures
PutStr:  ; Procedure label/start
 ; Set up the registers for the interrupt call
 mov ah,0x0E ; The function to display a chacter (teletype)
 mov bh,0x00 ; Page number
 mov bl,0x07 ; Normal text attribute

.nextchar ; Internal label (needed to loop round for the next character)
 lodsb  ; I think of this as LOaD String Block 
  ; (Not sure if thats the real meaning though)
  ; Loads [SI] into AL and increases SI by one
 ; Check for end of string '0' 
 or al,al ; Sets the zero flag if al = 0 
  ; (OR outputs 0's where there is a zero bit in the register)
 jz .return ; If the zero flag has been set go to the end of the procedure.
  ; Zero flag gets set when an instruction returns 0 as the answer.
 int 0x10 ; Run the BIOS video interrupt 
 jmp .nextchar ; Loop back round tothe top
.return  ; Label at the end to jump to when complete
; ret  ; Return to main program
;Wait for a key
xor ah, ah
int 16h

push 01h              ;Blue
push 100              ;cX
push 90               ;cY
push 140           ;Radius
call drawFilledCircle


;ret
; Data

HelloWorld db '   WELCOME !!   Press Enter ',10,10,0



 loc   db "KERNEL  IMG"

.LOOP:
          push    cx
          mov     cx, 0x000B                          ; eleven character name
          mov     si, loc
                       ; image name to find
          push    di
     rep  cmpsb                                       ; test for entry match
          pop     di
          ;je      LOAD_FAT
          pop     cx
          add     di, 0x0020                          ; queue next directory entry
          loop    .LOOP
          ;jmp     FAILURE





;Restore text mode
mov ax, 0003h
int 10h

;Return
mov ax, 4c00h
int 21h


;Color
;cX
;cY
;R
drawFilledCircle:
 push bp
 mov bp, sp

 sub sp, 02h

 mov cx, WORD [bp+04h]   ;R

 mov ax, cx              
 mul ax                  ;AX = R^2
 mov WORD [bp-02h], ax   ;[bp-02h] = R^2



 mov ax, WORD [bp+06h]
 sub ax, cx              ;i = cY-R
 mov bx, WORD [bp+08h]
 sub bx, cx              ;j = cX-R

 shl cx, 1
 mov dx, cx              ;DX = Copy of 2R

.advance_v:
 push cx
 push bx

 mov cx,  dx

.advance_h:
  ;Save values
  push bx
  push ax
  push dx

  ;Compute (i-y) and (j-x)
  sub ax, WORD [bp+06h]
  sub bx, WORD [bp+08h]

  mul ax                  ;Compute (i-y)^2

  push ax
  mov ax, bx             
  mul ax
  pop bx                  ;Compute (j-x)^2 in ax, (i-y)^2 is in bx now

  add ax, bx              ;(j-x)^2 + (i-y)^2
  cmp ax, WORD [bp-02h]   ;;(j-x)^2 + (i-y)^2 <= R^2

  ;Restore values before jump
  pop dx
  pop ax
  pop bx

  ja .continue            ;Skip pixel if (j-x)^2 + (i-y)^2 > R^2

  ;Write pixel
  push WORD [bp+0ah]
  push bx
  push ax
  call writePx


.continue:

  ;Advance j
  inc bx
 loop .advance_h

 ;Advance i
 inc ax


 pop bx            ;Restore j
 pop cx            ;Restore counter

loop .advance_v

 add sp, 02h


 pop bp
 ret 08h



;Color
;X
;Y
writePx:
 push bp
 mov bp, sp

 push ax
 push bx

 mov bx, WORD [bp+04h]
 mov ax, bx
 shl bx, 6
 shl ax, 8
 add bx, ax       ;320 = 256 + 64

 add bx, WORD [bp+06h]
 mov ax, WORD [bp+08h]

 ;TODO: Clip

 mov BYTE [es:bx], al

 pop bx
 pop ax

 pop bp
 ret 06h




times 510-($-$$) db 0 ; Fill the rest with zeros
dw 0xAA55  ; Boot loader signature

Другие вопросы по тегам