org 0x7C00 bits 16 WIDTH equ 0x50 HEIGHT equ 0x18 VIDEO_MODE equ 0x3 ;; see http://www.ctyme.com/intr/int-10.htm for interrupts start: ;; Use color mode mov ax, VIDEO_MODE int 10h ;; Clear screen mov ah, 0x06 mov al, 0x00 mov bh, 0x0F mov cx, 0x0000 mov dh, HEIGHT mov dl, WIDTH int 0x10 ;; Set cursor to bottom of screen mov dh, HEIGHT mov dl, 0x00 mov bh, 0x00 mov ah, 0x02 int 0x10 .loop: ;; Read character mov ah, 0x00 int 0x16 cmp al, 0x0d ; newline je .newline cmp al, 0x08 ; delete character je .change_color_mode cmp al, 0x1b ; escape character je .beep jmp .nonewline .change_color_mode: ;; Read character mov ah, 0x00 int 0x16 ;; Read character is in al sub al, 'a' mov bl, al shl bl, 0x4 ;; Read character mov ah, 0x00 int 0x16 ;; Read character is in al sub al, 'a' or al, bl mov [color_mode], al jmp .loop .newline: ;; Scroll up window mov ah, 0x06 mov al, 0x01 mov bh, 0x0F mov cx, 0x0000 mov dh, HEIGHT mov dl, WIDTH int 0x10 ;; Get current cursor position mov bh, 0x00 mov ah, 0x03 int 0x10 ;; Move cursor to beginning of screen mov dl, 0x00 mov ah, 0x02 int 0x10 jmp .loop .beep: mov al, 182 ; Prepare the speaker for the out 43h, al ; note. mov ax, 4560 ; Frequency number (in decimal) ; for middle C. out 42h, al ; Output low byte. mov al, ah ; Output high byte. out 42h, al in al, 61h ; Turn on note (get value from ; port 61h). or al, 00000011b ; Set bits 1 and 0. out 61h, al ; Send new value. mov bx, 5000 ; Pause for duration of note. .pause1: mov cx, 65535 .pause2: dec cx jne .pause2 dec bx jne .pause1 in al, 61h ; Turn off note (get value from ; port 61h). and al, 11111100b ; Reset bits 1 and 0. out 61h, al ; Send new value. jmp .loop .nonewline: ;; Write character mov ah, 0x09 mov bh, 0x00 mov bl, [color_mode] mov cx, 0x01 int 0x10 ;; Get current cursor position mov ah, 0x03 int 0x10 cmp dl, WIDTH jge .eol jmp .noeol .eol: ;; Scroll up window mov ah, 0x06 mov al, 0x01 mov bh, 0x0F mov cx, 0x0000 mov dh, HEIGHT mov dl, WIDTH int 0x10 ;; Move cursor to beginning of screen mov bh, 0 mov dh, HEIGHT mov dl, 0x00 mov ah, 0x02 int 0x10 jmp .loop .noeol: ;; Move cursor forward inc dl mov ah, 0x02 int 0x10 jmp .loop halt: hlt color_mode: db 0x02 times 510 - ($ - $$) db 0 dw 0xAA55