boot code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

boot code

Post by sancho1980 »

Hi
I've played around a little with nasm and bootstrapping. The following compiles to a binary which can be placed in the boot sector of a floppy with

Code: Select all

nasm -f bin -o boot.bin boot.asm
It asks the user to hit a key and then returns the scancode. However there are a couple of thing i would like to do, and i cannot find the info on how to do that:

1) Instead of calling interrupts, I would like to print the output by writing to the video memory
2) I would also like to get all scancodes: also the extended ones (f-keys, and so on)...also i would like to get the scan codes of the key releases, not only of the presses
3) I would also like to write the input routine myself instead of using the interrupt...just for the learning experience...is there any resource on how to do all this??

thanks

Martin

Code: Select all

boot.asm
BITS 16 
jmp 07C0h:start 
 
start: 
    mov ax, cs 
    mov ds, ax
rept:
    mov si, txt1
    call printstring
    mov ah, 0h
    int 16h
    mov si, txt2
    call printstring
    call printuns
    jmp rept 
 
;routine printstring: will print zero-terminated string from ds:si. 
printstring: 
    pusha 
    pushf 
    mov bx, 7 ;use the right page 
    mov ah, 0Eh 
nxtprintstring: 
    lodsb 
    or al, al 
    jz endprintstring 
    int 10h 
    jmp nxtprintstring 
endprintstring: 
    popf 
    popa 
    ret

;routine printuns: will print unsigned integer in al
printuns:
    pusha
    pushf
    mov bh, al
    mov dl, 10
    mov bl, 100
nxtprintuns:
    and ax, 0000000011111111b
    div bl
    or al, 00110000b ;converting to ascii
    mov ah, 0Eh
    int 10h
    and al, 00001111b ;converting back from ascii
    mul bl
    sub bh, al
    mov al, bl
    div dl
    jz endprintuns
    mov bl, al
    mov al, bh
    jmp nxtprintuns
endprintuns:
    popf
    popa
    ret
 
txt1: 
    db 0ah, 0dh, 'Press a key! ',0
txt2:
    db 'I scanned: ',0 
 
times 510-($-$$) db 0 ; Fill the file with 0's 
dw 0AA55h ; En 
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Post by davidv1992 »

i think to do such things it would be easier to go to 32 bits protected mode, set up an IDT and such, but don't know for sure if you can cram all the code you need for that into a bootsector. The writing to the screen directly can be done both in 16 bit real and 32 bit protected mode. You have a buffer with 80*25 sets of a character and it's color atribute formatted like this

15 ............. 10 ................ 7 ............... 0
bg color text color character

at adres 0xB8000
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

yeah, and how can i achieve the other stuff...is there no full reference on all the different ports and how to program them?
i know its better to do it in pm, but im starting with real mode just to keep it plain and simple :(
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

sancho1980 wrote:yeah, and how can i achieve the other stuff...is there no full reference on all the different ports and how to program them?
i know its better to do it in pm, but im starting with real mode just to keep it plain and simple :(
in the long run pm is simpler, so better to start with it early.
Author of COBOS
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

but how can i find out how to program all these devices? its not so easy to find any good tutorial on io and port programming :(
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Have you read the wiki article Keyboard Input. It is a pretty good resource for programming the keyboard controller. The best way to do it if you want to stay in real mode would be to patch the IVT for the keyboard IRQ so that it points to your own void KeyboardIsr() routine like the one in the wiki article.

However if you do that you have to remember that you will not be able to use the bios to get key presses anymore.
Post Reply