flat assembler
Message board for the users of flat assembler.

Index > DOS > 16 bit real VESA program doesnt assemble

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 24 Jan 2006, 05:22
Very Happy Hi, I've just joined the forum

Sad the attached program doesnt assemble,

Cool the program is determining the VESA version of the computer,

Shocked anyone know why it doesnt assemble?


Description:
Download
Filename: vesa_00.asm
Filesize: 1 KB
Downloaded: 415 Time(s)

Post 24 Jan 2006, 05:22
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2006, 07:39
Depending on whether you want to create .com or .exe program you need to use appropriate formatting directives. For .com you need "org 100h", since .com programs are always loaded at offset 100h (just after PSP) in their only segment, and CS=DS=ES=that segment. So adapted to be .com, your program may look like:
Code:
        org     100h

        ; call savegfx
        ; set up 80 x 25 text,
        mov ax,03h
        int 10h
start:
        ; es:di points to VbeSignature
        mov bx,VbeSignature
        mov di,bx               ; di
        
        ; VBE function 00 
        mov ax,4f00h    
        int 10h
        
        ; echo 4 chars of VbeSignature
        mov cx,4        
        mov bx,VbeSignature
        mov ah,2h

redo:   mov dl,[bx]
        add bx,1
        int 21h
        loop redo

        ; echo BCD VbeVersion
        add bx,1        ;jump to major number
        mov dl,[bx]
        add dl,'0'      
        int 21h

        sub bx,1        ;jump to minor number
        mov dl,[bx]
        add dl,'0'      
        int 21h

        ; call restoregfx
        call exitter

exitter:
        mov ax,4c00h
        int 21h
        ret     ; pointless

restoregfx:
        mov al,[startgfx]
        mov ah,0
        int 10h
        ret

savegfx:        ; get current video mode so can restore it,
        mov ah,0fh
        int 10h
        mov [startgfx],al
        ret

startgfx        db      4 dup 0 ; keep aligned
VbeSignature    db      'VBE2'  ; set by app, reset to VESA by VBE
VbeVersion      dw      0300h ;
OemStringPtr    dd      ?
Capabilities    dd      4 dup(?)
VideoModePtr    dd      ?
further         db      512 dup 0    
Note that few more corrections were needed - with fasm name of variable (label) equals to the address, so if you need to access the contents of variable, you need to put it in square brackets.

To create .exe program, you use "format MZ" directive, and you can set up the segments with your own names and then use those names to get their addresses. You program rewritten to MZ may look like:
Code:
        format MZ

segment _code

        mov ax,_data
        mov ds,ax

        ; call savegfx
        ; set up 80 x 25 text,
        mov ax,03h
        int 10h
start:
        ; es:di points to VbeSignature
        mov bx,_data
        mov es,bx               ; es
        mov bx,VbeSignature
        mov di,bx               ; di
        
        ; VBE function 00 
        mov ax,4f00h    
        int 10h
        
        ; echo 4 chars of VbeSignature
        mov cx,4        
        mov bx,VbeSignature
        mov ah,2h

redo:   mov dl,[bx]
        add bx,1
        int 21h
        loop redo

        ; echo BCD VbeVersion
        add bx,1        ;jump to major number
        mov dl,[bx]
        add dl,'0'      
        int 21h

        sub bx,1        ;jump to minor number
        mov dl,[bx]
        add dl,'0'      
        int 21h

        ; call restoregfx
        call exitter

exitter:
        mov ax,4c00h
        int 21h
        ret     ; pointless

restoregfx:
        mov al,[startgfx]
        mov ah,0
        int 10h
        ret

savegfx:        ; get current video mode so can restore it,
        mov ah,0fh
        int 10h
        mov [startgfx],al
        ret

segment _data

startgfx        db      4 dup 0 ; keep aligned
VbeSignature    db      'VBE2'  ; set by app, reset to VESA by VBE
VbeVersion      dw      0300h ;
OemStringPtr    dd      ?
Capabilities    dd      4 dup(?)
VideoModePtr    dd      ?
further         db      512 dup 0    
Post 24 Jan 2006, 07:39
View user's profile Send private message Visit poster's website Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 24 Jan 2006, 21:31
thanks for in depth reply. You anticipated some questions I was going
to ask, eg I was wondering what CS,DS were set to which you've explained

I need to study the format MZ version you created,

for .com what are SS:SP set to initially?

is it the end of the 64K that begins at 100h?

I'm confused about something else, .com has "org 100h",

but I thought 16 bit real mode has an IDT starting at 0 with
256 x 4 bytes ie I thought the IDT was from 0 to 3ff

so how does the code begin at 100h which is 1/4 of the
way through the IDT?

and the FAT12 bootloader I downloaded
appears to suggest that bootcode is loaded to 7c00h,
why at 7c00h? why not 100h or other?


one other thing: can you explain what the difference between .com and .exe is?

can both be used for bootloader code?

with .exe if I want to use a stack do I need any further things or
can I just directly do "call" and "ret" without initialising ss:sp?

I am new to x86 though am familiar with 68k and am currently relying on internet info as the bookshops here dont sell any x86 asm books at all,

I've been going in circles reading the Intel P4 documents,

I've also been wondering how you do macros in fasm,
so far none of the internet info I've looked at talks about
x86 macros. Can you give some representative examples
of macros in fasm?
Post 24 Jan 2006, 21:31
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 29 Jan 2006, 20:14
the BIOS loads code from a hard disk drive or floppy drive into address 7c00h, always.
thats why all boot code in x86 starts at virtual address 7c00h.
Post 29 Jan 2006, 20:14
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 29 Jan 2006, 22:40
UCM wrote:
the BIOS loads code from a hard disk drive or floppy drive into address 7c00h, always.
thats why all boot code in x86 starts at virtual address 7c00h.


is there any useful system data or code from 0 to 7c00?

I know the real mode IDT is from 0 to 3ff,

(256 interrupts x 4 bytes each)

what happens from 400 to 7c00?
Post 29 Jan 2006, 22:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.