;=============================================================== ; BOOT SECTOR ; [http://www.karig.net/0011.html] ;=============================================================== [ORG 0x7C00] [BITS 16] main: ; ------ Straighten out segment registers. ; ------ [http://www.karig.net/0002.html] jmp word 0:segzero segzero: mov ax, cs mov ds, ax mov es, ax mov fs, ax mov gs, ax ; ------ Set up call stack. cli mov ax, 0x1000 mov ss, ax mov sp, 0xFFFE sti ; ------ Clear text screen. ; ------ [http://www.karig.net/0011.html] ; set 80x25 text mode and clear screen mov ax, 3 int 0x10 ; ------ Change current screen attribute. .4: mov ax, (9 * 0x100) + ' ' mov bx, [attrib] mov cx, 2 int 0x10 ; ------ Get key. .1: xor ah, ah int 0x16 ; ------ If key is F1..F4, change current attribute. sub ah, 0x3B cmp ah, 4 jnb .2 xor bh, bh mov bl, ah mov ah, [attribs+bx] mov [attrib], ah jmp short .4 ; ------ If key is not printable, go get another key. .2: cmp al, 33 jb .1 ; ------ Echo printable character to the screen. xor bh, bh mov ah, 0xE int 0x10 ; ------ If character is first in word, get next key. inc byte [c] ; 4 bytes mov al, [c] ; 3 bytes test al, 1 ; 2 bytes jnz .1 ; 2 bytes ; ------ If character is second, type two spaces. mov ax, (0xE * 0x100) + ' ' xor bh, bh int 0x10 mov ax, (0xE * 0x100) + ' ' xor bh, bh int 0x10 jmp short .4 ; ------ Variables. c: db 0 attrib: db 0x04, 0 ; the 0 is so we can mov bx, attrib (save a byte) attribs: db 0x04 ; red on black (define) db 0x02 ; green on black (compile) db 0x0E ; yellow on black (execute) db 0x05 ; magenta on black (hex) ; ------ (Required to make this a boot sector.) times 510 - ($-$$) db 0x90 ; nop db 0x55, 0xAA