add documentation
This commit is contained in:
parent
a8a7a3d3d1
commit
3ca4ce76f0
1 changed files with 150 additions and 131 deletions
281
messages.asm
281
messages.asm
|
@ -1,9 +1,11 @@
|
||||||
org 0x7C00
|
org 0x7C00 ; The boot code on a drive always gets loaded at address 0x7C00
|
||||||
bits 16
|
bits 16 ; .bin defaults to 16 bits
|
||||||
|
|
||||||
WIDTH equ 0x50
|
;; FIXME: possible problem with HEIGHT being defined
|
||||||
HEIGHT equ 0x18
|
;; as one less than what VIDEO_MODE implies?
|
||||||
VIDEO_MODE equ 0x3
|
WIDTH equ 0x50 ; 60
|
||||||
|
HEIGHT equ 0x18 ; 24 (?)
|
||||||
|
VIDEO_MODE equ 0x3 ; 80x25 screen, text mode
|
||||||
|
|
||||||
;; see http://www.ctyme.com/intr/int-10.htm for interrupts
|
;; see http://www.ctyme.com/intr/int-10.htm for interrupts
|
||||||
|
|
||||||
|
@ -13,173 +15,190 @@ mov ax, VIDEO_MODE
|
||||||
int 10h
|
int 10h
|
||||||
|
|
||||||
;; Clear screen
|
;; Clear screen
|
||||||
mov ah, 0x06
|
mov ah, 0x06 ; scroll screen up
|
||||||
mov al, 0x00
|
mov al, 0x00 ; lines to scroll (0 = clear)
|
||||||
mov bh, 0x0F
|
mov bh, 0x0F ; bg/fg colour
|
||||||
mov cx, 0x0000
|
mov cx, 0x0000 ; upper row number, left col number (both 0)
|
||||||
mov dh, HEIGHT
|
mov dh, HEIGHT ; lower row number (24)
|
||||||
mov dl, WIDTH
|
mov dl, WIDTH ; right col number (80)
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
;; Set cursor to bottom of screen
|
;; Set cursor to bottom of screen
|
||||||
mov dh, HEIGHT
|
mov ah, 0x02 ; set cursor position
|
||||||
mov dl, 0x00
|
mov bh, 0x00 ; page number
|
||||||
mov bh, 0x00
|
mov dh, HEIGHT ; row (bottommost row)
|
||||||
mov ah, 0x02
|
mov dl, 0x00 ; col (leftmost col)
|
||||||
int 0x10
|
int 0x10
|
||||||
mov sp, 0x2000
|
|
||||||
|
mov sp, 0x2000 ; initialise stack pointer
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
;; Read character
|
mov ah, 0x00 ; Read character
|
||||||
mov ah, 0x00
|
int 0x16
|
||||||
int 0x16
|
|
||||||
|
|
||||||
cmp al, 0x0d ; newline
|
cmp al, 0x0d ; newline
|
||||||
je .newline
|
je .newline
|
||||||
cmp al, 0x08 ; delete character
|
|
||||||
je .change_color_mode
|
cmp al, 0x08 ; delete character
|
||||||
cmp al, 0x1b ; escape character
|
je .change_color_mode
|
||||||
je .beep
|
|
||||||
jmp .nonewline
|
cmp al, 0x1b ; escape character
|
||||||
|
je .beep
|
||||||
|
|
||||||
|
jmp .nonewline
|
||||||
|
|
||||||
.change_color_mode:
|
.change_color_mode:
|
||||||
call .readbyte
|
call .readbyte
|
||||||
mov [color_mode], al
|
mov [color_mode], al
|
||||||
jmp .loop
|
jmp .loop
|
||||||
|
|
||||||
.newline:
|
.newline:
|
||||||
;; Scroll up window
|
;; Scroll up window
|
||||||
mov ah, 0x06
|
mov ah, 0x06
|
||||||
mov al, 0x01
|
mov al, 0x01
|
||||||
mov bh, 0x0F
|
mov bh, 0x0F
|
||||||
mov cx, 0x0000
|
mov cx, 0x0000
|
||||||
mov dh, HEIGHT
|
mov dh, HEIGHT
|
||||||
mov dl, WIDTH
|
mov dl, WIDTH
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
;; Get current cursor position
|
;; Get current cursor position
|
||||||
mov bh, 0x00
|
mov bh, 0x00
|
||||||
mov ah, 0x03
|
mov ah, 0x03
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
;; Move cursor to beginning of screen
|
;; Move cursor to beginning of screen
|
||||||
mov dl, 0x00
|
mov dl, 0x00
|
||||||
mov ah, 0x02
|
mov ah, 0x02
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
jmp .loop
|
jmp .loop
|
||||||
|
|
||||||
.beep:
|
.beep:
|
||||||
call .readduration
|
call .readduration
|
||||||
mov ah, 0
|
mov ah, 0
|
||||||
push ax
|
push ax
|
||||||
mov al, 182 ; Prepare the speaker for the
|
mov al, 182 ; Prepare the speaker for the
|
||||||
out 43h, al ; note.
|
out 43h, al ; note.
|
||||||
call .readbyte
|
call .readbyte
|
||||||
mov ah, 0
|
mov ah, 0
|
||||||
sal ax, 5 ; multiply by 32
|
sal ax, 5 ; multiply by 32
|
||||||
add ax, 1140
|
add ax, 1140
|
||||||
out 42h, al ; Output low byte.
|
out 42h, al ; Output low byte.
|
||||||
mov al, ah ; Output high byte.
|
mov al, ah ; Output high byte.
|
||||||
out 42h, al
|
out 42h, al
|
||||||
in al, 61h ; Turn on note (get value from
|
in al, 61h ; Turn on note (get value from
|
||||||
; port 61h).
|
; port 61h).
|
||||||
or al, 00000011b ; Set bits 1 and 0.
|
or al, 00000011b ; Set bits 1 and 0.
|
||||||
out 61h, al ; Send new value.
|
out 61h, al ; Send new value.
|
||||||
;; mov bx, 50000 ; Pause for duration of note.
|
;; mov bx, 50000 ; Pause for duration of note.
|
||||||
pop bx
|
pop bx
|
||||||
push ax
|
push ax
|
||||||
mov ax, 3125
|
mov ax, 3125
|
||||||
mul bx
|
mul bx
|
||||||
mov bx, ax
|
mov bx, ax
|
||||||
pop ax
|
pop ax
|
||||||
|
|
||||||
.pause1:
|
.pause1:
|
||||||
mov cx, 65535
|
mov cx, 65535
|
||||||
.pause2:
|
.pause2:
|
||||||
dec cx
|
dec cx
|
||||||
jne .pause2
|
jne .pause2
|
||||||
dec bx
|
dec bx
|
||||||
jne .pause1
|
jne .pause1
|
||||||
in al, 61h ; Turn off note (get value from
|
in al, 61h ; Turn off note (get value from
|
||||||
; port 61h).
|
; port 61h).
|
||||||
and al, 11111100b ; Reset bits 1 and 0.
|
and al, 11111100b ; Reset bits 1 and 0.
|
||||||
out 61h, al ; Send new value.
|
out 61h, al ; Send new value.
|
||||||
jmp .loop
|
jmp .loop
|
||||||
|
|
||||||
|
|
||||||
.nonewline:
|
.nonewline:
|
||||||
|
|
||||||
;; Write character
|
;; Write character
|
||||||
mov ah, 0x09
|
mov ah, 0x09
|
||||||
mov bh, 0x00
|
mov bh, 0x00
|
||||||
mov bl, [color_mode]
|
mov bl, [color_mode]
|
||||||
mov cx, 0x01
|
mov cx, 0x01
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
;; Get current cursor position
|
;; Get current cursor position
|
||||||
mov ah, 0x03
|
mov ah, 0x03
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
cmp dl, WIDTH
|
cmp dl, WIDTH
|
||||||
jge .eol
|
jge .eol
|
||||||
jmp .noeol
|
jmp .noeol
|
||||||
|
|
||||||
.eol:
|
.eol:
|
||||||
;; Scroll up window
|
;; Scroll up window
|
||||||
mov ah, 0x06
|
mov ah, 0x06
|
||||||
mov al, 0x01
|
mov al, 0x01
|
||||||
mov bh, 0x0F
|
mov bh, 0x0F
|
||||||
mov cx, 0x0000
|
mov cx, 0x0000
|
||||||
mov dh, HEIGHT
|
mov dh, HEIGHT
|
||||||
mov dl, WIDTH
|
mov dl, WIDTH
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
;; Move cursor to beginning of screen
|
;; Move cursor to beginning of screen
|
||||||
mov bh, 0
|
mov bh, 0
|
||||||
mov dh, HEIGHT
|
mov dh, HEIGHT
|
||||||
mov dl, 0x00
|
mov dl, 0x00
|
||||||
mov ah, 0x02
|
mov ah, 0x02
|
||||||
int 0x10
|
int 0x10
|
||||||
jmp .loop
|
jmp .loop
|
||||||
|
|
||||||
.noeol:
|
.noeol:
|
||||||
|
|
||||||
;; Move cursor forward
|
;; Move cursor forward
|
||||||
inc dl
|
inc dl
|
||||||
mov ah, 0x02
|
mov ah, 0x02
|
||||||
int 0x10
|
int 0x10
|
||||||
jmp .loop
|
jmp .loop
|
||||||
|
|
||||||
|
|
||||||
|
;; Reads two characters from the keyboard buffer and converts them into a single byte
|
||||||
|
;;
|
||||||
|
;; The conversion happens as follows:
|
||||||
|
;; ASCII 'a' is subtracted from each character (so 'a' = 0, 'b' = 1, ...)
|
||||||
|
;; the first character is shifted left by 4
|
||||||
|
;; the shifted and non-shifted values are then or'ed together to form a byte
|
||||||
|
;;
|
||||||
|
;; CLOBBERS
|
||||||
|
;; - ax
|
||||||
|
;; - bl
|
||||||
.readbyte:
|
.readbyte:
|
||||||
;; Read character
|
mov ah, 0x00 ; Read character
|
||||||
mov ah, 0x00
|
int 0x16
|
||||||
int 0x16
|
|
||||||
;; Read character is in al
|
|
||||||
sub al, 'a'
|
|
||||||
mov bl, al
|
|
||||||
shl bl, 0x4
|
|
||||||
|
|
||||||
;; Read character
|
;; Read character is in al
|
||||||
mov ah, 0x00
|
sub al, 'a' ; Normalise
|
||||||
int 0x16
|
mov bl, al
|
||||||
;; Read character is in al
|
shl bl, 0x4 ; First character is upper 4 bits
|
||||||
sub al, 'a'
|
|
||||||
or al, bl
|
mov ah, 0x00 ; Read character
|
||||||
ret
|
int 0x16
|
||||||
|
|
||||||
|
;; Read character is in al
|
||||||
|
sub al, 'a' ; Normalise
|
||||||
|
|
||||||
|
or al, bl ; Combine both characters
|
||||||
|
|
||||||
|
ret
|
||||||
|
|
||||||
.readduration:
|
.readduration:
|
||||||
;; Read duration (0-16 supported)
|
;; Read duration (0-16 supported)
|
||||||
mov ah, 0x00
|
mov ah, 0x00
|
||||||
int 0x16
|
int 0x16
|
||||||
;; Read character is in al
|
;; Read character is in al
|
||||||
sub al, 'a'
|
sub al, 'a'
|
||||||
ret
|
ret
|
||||||
|
|
||||||
halt: hlt
|
halt: hlt
|
||||||
|
|
||||||
color_mode: db 0x02
|
color_mode: db 0x02
|
||||||
|
|
||||||
|
;; Magic number must be in the last 2 bytes of the sector so
|
||||||
|
;; fill the binary with zeroes until it is 510 bytes in size
|
||||||
|
;; (magic number will use up the remaining 2)
|
||||||
times 510 - ($ - $$) db 0
|
times 510 - ($ - $$) db 0
|
||||||
dw 0xAA55
|
dw 0xAA55 ;; Magic number to mark sector as bootable
|
||||||
|
|
Loading…
Reference in a new issue