Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;%define BOCHS_HD_IMAGE
- BITS 16
- [org 0x7C00]
- boot:
- cli
- xor ax, ax
- mov ds, ax
- mov gs, ax
- mov ax, 0B800h
- mov es, ax ;VGA color text data segment
- mov ax, 07E0h
- mov ss, ax
- mov bp, ax
- mov sp, 9C00h
- mov ax, word int70h_handler ;setup 70h interrupt for RTC timer
- mov [gs:70h*4], ax
- mov [gs:70h*4+2], ds
- ; mov ax, 64
- ; mov fs, ax
- ; mov [fs:160], byte 1 ;Trick BIOS into thinking RTC is in use, disable int 15h functions 83/86
- sti
- ; jmp _debug
- xor ax, ax
- xor di, di
- mov cx, 80 * 25
- rep stosw ;clear screen, mov [es:di], ax
- fizzbuzz: ;(!(i%5)^!!(i%3)*3)*6
- xor ax, ax
- xor bx, bx
- mov al, byte [i] ;i%5
- mov dl, 05h
- div byte dl
- test ah, 07h ;!
- pushf
- pop cx
- and cx, 40h
- shr cx, 06h
- xor ah, ah
- mov al, byte [i] ;i%3
- mov dl, 03h
- div byte dl
- test byte ah, 03h ;!!
- push cx
- pushf
- pop cx
- and cx, 40h
- shr cx, 06h
- xor cx, 01h
- mov al, cl
- pop cx
- mov dx, 03h ;*3
- mul dx
- xor al, cl ;^
- cmp al, 0
- jz dofizz
- cmp al, 1
- jz dofizzbuzz
- cmp al, 2
- jz dobuzz
- xor ah, ah
- mov al, byte [i] ;int to ascii
- mov dl, 0Ah
- div byte dl
- add al, 30h
- add ah, 30h
- mov [istr], al
- mov [istr+2], ah
- lea si, [istr]
- jmp do_print
- dofizz:
- lea si, [fizz]
- jmp do_print
- dobuzz:
- lea si, [buzz]
- jmp do_print
- dofizzbuzz:
- lea si, [fb]
- jmp do_print
- do_print:
- call print_line
- inc byte [i]
- cmp byte [i], 65h
- jnz fizzbuzz
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- _debug:
- xor ax, ax
- cli
- ;;;; RTC init
- mov al, 8Bh ;select reg B, disable NMI
- out 70h, al
- in al, 71h ;read B
- or al, 40h
- push ax
- mov ax, 8Bh ;select B
- out 70h, al
- pop ax
- out 71h, al
- mov al, 8Ah ;select reg A and disable NMI
- out 70h, al
- in al, 71h ;read reg A value
- and al, 11110000b ;keep top nibble
- or al, 0Fh ;OR in divider in low nibble
- push ax
- mov al, 8Ah
- out 70h, al ;write value to A
- pop ax
- out 71h, al
- mov al, 0Ch
- in al, 71h
- in al, 0A1h ;clear PIC 2 mask to ensure that IRQ 8 fires
- xor al, al
- out 0A1h, al
- sti
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- mov byte [tmp], 0
- jmp $
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;si - string
- print_line:
- .iter:
- lodsw
- cmp al, 0
- je .newline
- mov cx, 1
- call print_char
- call vga_update_cursor
- cmp byte [cursorx], 80
- jl .iter
- .newline:
- mov byte [cursorx], 0
- inc byte [cursory]
- call vga_update_cursor
- call vga_scroll_screen
- .quit:
- ret
- ;al - char, ah - attr, cl - rep
- ;clobbers dx
- print_char:
- mov word [tmp], ax
- xor ax, ax
- xor dx, dx
- mov al, byte [consolew]
- sub al, byte [cursorx]
- cmp al, cl
- jge .outc
- sub cl, al
- .outc:
- mov al, byte [cursory]
- mul byte [consolew]
- mov dl, byte [cursorx]
- add ax, dx
- mov di, ax
- mov word [coffset], di ;store off the unshifted offset for cursor positioning
- push di
- shl di, 1 ;shift to word offset
- push cx
- mov ax, word [tmp]
- rep stosw
- pop cx
- pop di
- push cx
- add di, word [csize4]
- shl di, 1
- rep stosw ; copy 4 console screens down for loop
- pop cx
- add byte [cursorx], cl
- ret
- vga_update_cursor:
- push ax
- push bx
- push dx
- mov bx, word [coffset]
- mov dx, 3D4h ;set VGA register index
- mov al, 0Fh
- out dx, al
- mov dx, 3D5h ;low cursor position
- mov ax, bx
- out dx, al
- mov dx, 3D4h ;set register index again
- mov al, 0Eh
- out dx, al
- mov dx, 3D5h ;high cursor position
- mov al, bh
- out dx, al
- pop dx
- pop bx
- pop ax
- ret
- vga_scroll_screen:
- push ax
- push bx
- push dx
- mov al, byte [cursory]
- mov bl, byte [consolew]
- mul bl
- xor dx, dx
- div word [csize4]
- xchg bx, dx
- mov dx, 3D4h
- mov al, 0Ch
- out dx, al
- mov dx, 3D5h
- mov al, bh
- out dx, al
- mov dx, 3D4h
- mov al, 0Dh
- out dx, al
- mov dx, 3D5h
- mov al, bl
- out dx, al
- pop dx
- pop bx
- pop ax
- ret
- align 16
- int70h_handler: ;RTC timer interrupt
- inc byte [tmp]
- cmp byte [tmp], 5
- jnz .noscroll
- mov byte [tmp], 0
- inc byte [cursory]
- call vga_scroll_screen
- .noscroll:
- mov al, 0Ch
- out 70h, al ;read RTC reg C. We have to do this to keep receiving interrupts
- in al, 71h
- ; mov [fs:09Bh], dword 0400h
- mov al, 0x20 ; non-specific EOI
- out 0xa0, al ; PIC 2 (slave)
- out 0x20, al ; PIC 1 (master)
- iret
- i db 01h
- fizz db 'F',0Ah,'i',0Dh,'z',0Ah,'z',0Dh,0,0
- buzz db 'B',0Eh,'u',0Ch,'z',0Eh,'z',0Ch,0,0
- fb db 'F',0Dh,'i',0Ah,'z',0Dh,'z',0Ah,'B',0Eh,'u',0Ch,'z',0Eh,'z',0Ch,0,0
- istr db 0,012h,0,012h,0,0
- consolew db 80
- consoleh db 25
- cursorx db 0
- cursory db 0
- coffset dw 0
- csize4 dw 8000
- tmp dw 00
- times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
- dw 0xAA55 ; The standard PC boot signature
- %ifdef BOCHS_HD_IMAGE
- times 1024*1024 db 0 ; for Bochs disk boot, Cylinders/Heads/Sectors all set to 3
- %endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement