diff options
Diffstat (limited to 'src/stage1_functions.asm')
-rw-r--r-- | src/stage1_functions.asm | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/stage1_functions.asm b/src/stage1_functions.asm new file mode 100644 index 0000000..2ca3eb2 --- /dev/null +++ b/src/stage1_functions.asm @@ -0,0 +1,136 @@ +; IN bx: begin of memory area to dump +; IN ax: number of words to dump +dump_range: + mov dx, bx + call print_hex + mov dx, [bx] + call print_hex + call print_newline + add bx, 2 + dec ax + cmp ax, 0 + jnz dump_range + ret + +; IN bx: hex value to print +print_hex: + push bx + push si + mov si, HEX_TEMPLATE + mov bx, dx + shr bx, 12 + mov bx, [HEXABET+bx] + mov [HEX_TEMPLATE+2], bl + mov bx, dx + and bx, 0x0FFF + shr bx, 8 + mov bx, [HEXABET+bx] + mov [HEX_TEMPLATE+3], bl + mov bx, dx + and bx, 0x00FF + shr bx, 4 + mov bx, [HEXABET+bx] + mov [HEX_TEMPLATE+4], bl + mov bx, dx + and bx, 0x000F + mov bx, [HEXABET+bx] + mov [HEX_TEMPLATE+5], bl + call print_string + pop si + pop bx + ret + +HEX_TEMPLATE: + db '0x???? ', 0 + +HEXABET: + db '0123456789ABCDEF' + +print_newline: + push ax + mov al, 10 + call print_char + mov al, 13 + call print_char + pop ax + ret + +; IN si +print_string: + push ax +_loop_print_string: + lodsb + cmp al, 0 + je print_string_fini + call print_char + jmp _loop_print_string +print_string_fini: + pop ax + ret + +; IN al: character to print +; MOD ah +print_char: + mov ah, 0x0e + int 0x10 + ret + +fat_cursor: + push ax + push cx + mov ah, 0x01 + mov cx, 0x0007 + int 0x10 + pop cx + pop ax + ret + +; OUT: current row +current_row: + push ax + push bx + push cx + mov ah, 0x03 + mov bh, 0 + int 0x10 + pop cx + pop bx + pop ax + ret + +; IN dl: drive to read from +read_from_disk: + + mov ah, 0x02 ; read sectors from drive + + mov al, 2 ; read 1 sector + mov ch, 0 ; select first cylinder + mov dh, 0 ; first head + mov cl, 2 ; second sector after boot sector + + mov bx, 0 ; where to store the data + mov es, bx + mov bx, 0x7e00 ; 512 bytes after first sector + + int 0x13 + + jc read_error + + cmp al, 2 ; 1 sector read? + jne short_read ; if not, short read + + ret + +read_error: + mov si, DISK_ERROR + call print_string + mov dh, 0 + mov dl, ah + call print_hex + jmp $ + +short_read: + mov si, SHORT_READ + call print_string + jmp $ + |