added license, author
[bootboot] / bb.asm
diff --git a/bb.asm b/bb.asm
index 4eb536e..5f901bf 100644 (file)
--- a/bb.asm
+++ b/bb.asm
@@ -1,3 +1,6 @@
+; author Eleni Maria Stea <elene.mst@gmail.com>
+; my x86 assembly helloworld :)
+
 ; org: all instructions from now on start in 7c00h
 ; 7c00h is where the bios loads the 1st sector
 ; assembler formatting:
        out dx, al
 %endmacro
 
+bios_param_block:
+       jmp start       ; 2 bytes
+       nop             ; 1 byte
+       ; start of BPB at offset 3
+       db "BSPL 0.1"   ; 03h: OEM ident, 8 bytes
+       dw 512          ; 0bh: bytes per sector
+       db 1            ; 0dh: sectors per cluster
+       dw 1            ; 0eh: reserved sectors (including boot record)
+       db 2            ; 10h: number of FATs
+       dw 224          ; 11h: number of dir entries
+       dw 2880         ; 13h: number of sectors in volume
+       db 0fh          ; 15h: media descriptor type (f = 3.5" HD floppy)
+       dw 9            ; 16h: number of sectors per FAT
+       dw 18           ; 18h: number of sectors per track
+       dw 2            ; 1ah: number of heads
+       dd 0            ; 1ch: number of hidden sectors
+       dd 0            ; 20h: high bits of sector count
+       db 0            ; 24h: drive number
+       db 0            ; 25h: winnt flags
+       db 28h          ; 26h: signature(?)
+       dd 0            ; 27h: volume serial number
+       db "BOOTBOOT   "; 2bh: volume label, 11 bytes
+       db "FAT12   "   ; 36h: filesystem id, 8 bytes
+
 start:
        mov sp, 7c00h
 
@@ -175,16 +202,33 @@ main_loop:
        jnz .static_loop
 
        ; draw lovebug
-       mov di, 32000
+       mov di, (200 - 32) * 320 + 160 - 16
+       mov ax, [num_frames]
+       shr ax, 2               ; /4
+       cmp ax, 200 - 32
+       jz .end
+       mov bx, ax
+       shl ax, 8
+       shl bx, 6
+       add ax, bx
+       sub di, ax
+       call rand
+       and ax, 3               ; random value in 0, 2
+       sub ax, 1               ; random value in -1, 1
+       add di, ax
        mov si, lovebug
        call blit32
 
 ; wait for vblank
-.vsync:
+.vsync_blank:
        mov dx, 3dah
        in al, dx
+       and al, 8
+       jnz     .vsync_blank
+.vsync_visible:
+       in al, dx
        and al, 8               ; the 4th bit is 1 when we are in the vertical blanking period
-       jnz     .vsync
+       jz .vsync_visible
 
 ; copy backbuffer to video memory
        push es
@@ -201,12 +245,16 @@ main_loop:
        pop es
 
        inc word [num_frames]
+;   moved above:
+;      cmp word [num_frames], 200 - 32
+;      jz .end
 
        in al, 64h              ; 60h = keyb data port, 64h = keyb status port
        and al, 1               ; 1 = OUTBUF_FULL = the keyb controller out buf is full
        jz main_loop    ; no key pressed, loop back
        in al, 60h              ; reads the keyb that was pressed to reset the flag
 
+.end:
 ; re-enable all interrupts
        sti
 
@@ -221,6 +269,23 @@ main_loop:
        call print_num
        mov si, str_newline
        call print_str
+
+       mov dx, 80h             ; default to load from drive 80h
+       cmp byte [saved_drive_num], 80h
+       jnz .not_hd
+       inc dl                  ; next hd
+.not_hd:
+; load hard disk boot sector
+       xor ax, ax
+       mov es, ax
+       mov bx, 7c00h
+       mov ah, 02h
+       mov al, 1
+       mov ch, 0
+       mov cl, 1
+       mov dh, 0
+       int 13h
+       jnc 7c00h
 .inf_loop:
        jmp .inf_loop