; boot04.asm -- bootstrap example with direct output ; Copyright (C) 2004 Steffen Solyga ; asmsyntax=nasm ; compile (on linux) with: nasm boot04.asm ; prepare floppy with: dd if=boot04 of=/dev/fd0 ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; $Id: boot04.asm,v 1.6 2005/06/30 22:02:47 solyga Exp $ ; Well, I could use BIOS interrupt routines to output strings. ; However, my aim is to switch to protected mode later. And then ; BIOS interrupts are not available anymore. (Actually, until now ; I think the functions could be made available even in protected mode. ; But what are they doing with my valuable descriptors?) ; So, how can I output text without BIOS help? Just writing my stuff ; right into the video ram usually mapped to the linear address ; 0xb8000 (segment 0xb800) using video mode 3 (80x25 chars color). ; (Older adaptors - f.i. Hercules Graphics Card (HGC) - map to 0xb0000. ; With these cards only mode 7 is available. _ALL_ adaptors map to ; address 0xb0000 for mode 7. However, for compatibility, new adaptors ; seem to mirror this area to 0xb8000 for mode 7, also. ; Thus it should be save to use 0xb8000 with mode 3 nowadays that ; everybody has a VGA compatible graphicscard.) ; ; The coding of the video data is as follows: ; - addressing is from left to right and from top to bottom ; - each word corresponds with one character ; - low byte takes the ASCII code ; - high byte takes the attribute BbbbIfff with meaning: ; * B=1 blinking (?) ; * b - background color ; * I=1 high intensity ; * f - foreground color ; - colors: ; * 0 - black ; * 1 - blue ; * 2 - green ; * 3 - cyan ; * 4 - red ; * 5 - violett ; * 6 - brown ; * 7 - white ; ; The video modes (for CGA and later) are as follows (taken from Schäkel 1991): ; 0 - 40x25 black/white ; 1 - 40x25 color ; 2 - 80x25 black/white ; 3 - 80x25 color ; 4 - 320x200 graphics with 4 colors ; 5 - 320x200 graphics black/white ; 6 - 640x200 graphics black/white ; 7 - 80x25 black/white (all cards) jmp 0x07c0:start ; set cs to 0x07c0, see boot00.asm start: ; set ds mov ax, cs mov ds, ax ; set video mode 0x03 (80*25 chars color) if available mov ah, 0x0f ; function: get video mode int 0x10 ; see boot03.asm mov [video_mode], al ; save mode xor ah, ah ; function: set video mode mov al, 0x03 ; 3 - 80x25 color int 0x10 mov ah, 0x0f int 0x10 cmp al, 0x03 ; mode available? je continue mov word [vid_off], 0xb000 ; HGC base address = 0xb000 continue: ; print string mov si, string0 xor di, di ; init cursor position call print_string ; convert video mode into string and print it mov al, [video_mode] mov cl, al ; save mode mov bl, 0x02 ; counter, 2 chars conv_loop: mov al, cl and al, 0x0f or al, 0x30 cmp al, 0x3a jc nibble_done add al, 0x27 nibble_done: mov [bx+string1+1], al ; store ascii code shr cl, 4 ; next nibble dec bl jnz conv_loop mov si, string1 call print_string hang: jmp hang ; ----------------------------------------------------------------------------- print_string: cld mov es, [vid_off] mov ah, 0x09 ; intense blue on black print_loop: lodsb ; al= [ds:si], si+= 1 or al, al ; al= 0 ? jz print_done stosw ; [es:di]= ax, di+= 2 jmp print_loop print_done: ret ; ----------------------------------------------------------------------------- string0 db 'video mode: ', 0 string1 db '0x--', 0 video_mode db 0x00 vid_off dw 0xb800 ; VGA segment address times 510-($-$$) db 0 ; fill the file with 0's dw 0xaa55 ; end the file with 55 aa