|Boot disk x86 programming!
||[Jun. 27th, 2009|09:50 am]
I've found some assembly for Fasm, that writes a file to the boot sector of a floppy.|
As it is written to the first sector on the floppy - it looks empty. =)
It's a command line program, if you called it "makeboot.asm", and compiled to a COM file, you'd use it like:
I don't have a floppy drive on my computer.
So here I'm using VMWare with XP Pro and a virtual floppy to write the boot sector, some may say that's overkill:
Here's the boot writer:
;write boot sector to CHS sector 0,0,1 of drive A:, preserving boot record
;scan command line for a file name
mov al,' '
mov byte [di-1],0
;open the file
;read boot sector from it
;read the original boot sector from floppy
xor dx,dx ;mov dx,cx for drive B:
original rb 512
sektor rb 512
This is a small demo program that's changes to the simple graphics mode, and writes funky colours to the screen (I found it only -ahem-, but added my own comments).
I've set the output as "Com" just so I can run it from Windows without renaming it.
If it's compiled to myLittleProgram.com, you can then write this to the boot sector of a floppy with the above program.
30 bytes big!
I'm using a really low spec-virtual x86 machine, with a blank hard disk to do the boot test. It's connected to the same virtual floppy file the XP virtual machine above is using. The graphics program work in Windows, but it's very satisfying to see it appear after the BIOS screen on the PC:
format binary as "com"
;Change the video mode to 13h
xor ah, ah ;VIDEO Function 00h: Change screen
mov al, 13h ;Put the desired graphics mode into AL
int 10h ;Call video interrupt
mov es,ax ;es is now the pointer to the start of video RAM
xor cl,cl ;Clear bx, and cl registers
; Main loop
;Spin the colour
rol cx,1 ;Increment pixel colour, rotate it left 1 bit
;Plot [Video RAM + bx], cl
inc bx ;Inceremnt pixel offset
mov [es:bx],cl ;Plot pixel to screen
; Check for Escape key
in al,60h ;Read keyboard input
dec al ;Subtract 1
jnz @main ;Loop program if Escape wasn't pressed
If you need more than 500 Bytes (whatever for!?), this is a Fat12 Bootstrap loader that you write to the disk using makeboot.com(above), near the bottom of the program BASECODE is the name of the file on the floppy to continue loading.
( It can be used for bigger programs (up to 640ishK)Collapse )
Ah, I can't write the graphics program directly to the boot sector. =(
I have to use bootmaker, and add the graphics file as a standard file named "boot", as it looks like the boot writer program puts certain values on the disk so the OS knows it's a boot disk.