flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > How to determine amount of free conventional memory?

Author
Thread Post new topic Reply to topic
slave17



Joined: 14 Mar 2004
Posts: 6
Location: Warsaw,Poland
I want to write a prog equivalent to dos´s mem,but i can´t make out how much total conventional memoty is available.i know that it is about 640kb but i´m going to write a program extending this later and in order to check my results i need to know the real and exact value.Can so help me?
Post 14 Mar 2004, 12:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
interrupt 12h (? maybe 12d) returns you total amount of conventional memory. Check some interrupt list.

(btw, if it's less than 640kb you probably have some MBR virus (or very old computer))
Post 14 Mar 2004, 13:20
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
slave17



Joined: 14 Mar 2004
Posts: 6
Location: Warsaw,Poland
As far as i know int 12h returns the value calculated by BIOS during startup and stored in 40h:13h.the cause for the limit not being 1mb is for example the VGA standard which says that the video memory for 256 color modes (and other modes too) should be mapped begging at 0a0000h which is exactly 640kb.the may also be other devices mapping their registers or memory between 640kb and 1mb.the memory manager himem(or emm386 - frankly i dont remember) somehow decides on its own which part of this memory is not mapped and can safely be used for UMB.UMBs are addressed the same way as base mem so i dont see any good reason for not offering all free mem under 1mb as conventional mem - even if it would be divided into blocks of diffent size(ex. 0 to 09ffffh and 0c0000h to 1mb)
Post 16 Mar 2004, 12:31
View user's profile Send private message Reply with quote
slave17



Joined: 14 Mar 2004
Posts: 6
Location: Warsaw,Poland
i didnt finish my thought: i dont want to read this val from anywhere,i would like to check this value somehow,and also the umb.i want to make almost 1mb base mem available to progs,because this makes things easier(join base and umb).in such situation i cant just read out values,because they are relevant only for dos standard solution.
Post 16 Mar 2004, 12:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
i remember there was somthing about this (not exactly, but may help) in OS construction part.
Post 16 Mar 2004, 19:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
slave17



Joined: 14 Mar 2004
Posts: 6
Location: Warsaw,Poland
thanx a lot
Post 19 Mar 2004, 13:53
View user's profile Send private message Reply with quote
slave17



Joined: 14 Mar 2004
Posts: 6
Location: Warsaw,Poland
now i have naother problem: my prog checks for XMS too.the only values i can check by calls are total free XMS and lergest free EMB so i try to add the sizes of the blocks corresponding to all handles (usually 32 but may vary) in order to get used and total XMS.but this way sometimes i get zero used mem while dos' mem shows that some amount is in use.does ao know where my mistake is?checking all 64k possible handles is slow and even hangs the machine so i wrote i function checking the amount of handles by reserving all free handles to zero length blocks then i check with a function call whether handles with higher numbers exist than those that i reserved.in either case i search the highest numbered handle by comparison and assume its number to be the total amount of XMS handles in the system then i walk through all the handles using once more the same call and sum the sizes(i make here the assumption that the handles are subsequent numbers from 0 upwards).if so knows please tell me another method,dos' mem checks direct free mem by call and total mem(sometimes falsely) in an unknown way.My method finds up to 40k handles on my win98.
Post 05 Apr 2004, 18:14
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
http://freedos.sourceforge.net/mem/

(1.7 beta, GPL, compiles with Watcom C or Turbo C)
Post 16 Aug 2005, 01:57
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
yo slave17
getting free conventional memory i remember, you check value of ds at program start and sub it from $a000, the video memory framebuffer starts at the end of free memory, btw, com file allocates all free memory for your use unless you free unwanted memory after start.

getting total amount of conventional memory should be done via bios for compatibility reasons, but everything can be done via ports - and even more - but note that every motherboard can be different, so your program whould run only on one of them.

you cant get 1 MB conventional memory, because:
-there is aprox : 384KB reserved for bios - in most cases,
-64KB at $a000
-?64KB at $b000 - text mode framebuffer
-interrrupt vector table at the beginning
-some os code must be in the conventional memory

apart from these, you can be able to emulate some conventional memory, if you write or find a driver ( i saw one long time ago named : to736KB.com http://sac-ftp.externet.hu/utilmisc27.html - but it used video memory for conventional memory so it messed the screen. ) , but since there are limits in use of conventional memory, many programs simply assume you cannot have more than 640KB base memory.
Post 16 Aug 2005, 04:44
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
you are using bad terms. As far as i know "convetnional memory" is memory below 640kb boundary (00000 to 9FFFF).
Then there is are "reserved for BIOS" from which usually big part isn't used.
On some computers there was some memory located so DOS use this one. It wa called UMB - upper memory blocks. Some software (like Soft-Ice) was able to map RAM from above 1Mb to this region thus allowing things like 700kb of memory for DOS etc.
It was also used by EMM386 (usually regions E0000-EFFFF) to map above1Mb ram below 1Mb.
Then from F0000 to FFFFF is always located BIOS code (usually it's more than just these 64kb but posiiton isn't always the same). Then there was so-called HMA (high memoy area) which was from 10000 to 1FFEF, which was also accesible by DOS, because segment register can hold values above F000, which allows you to acces a little further above 1Mb. But originally on 286 address was only 20bit, so it was truncated and it wraped from 1000000 to 0. And some software was relying on this behavior, so there was created thing called A20 (21st address line, 20 because indexing from 0) which turned this wrapping on/off on newer processors. So if you disable (or enable, i don't remember Smile ) this A20 you can access also regions 1000000 to 1FFFFEF (FFFF:FFFF).
Post 16 Aug 2005, 19:01
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
ATV



Joined: 31 Aug 2004
Posts: 109
Location: Finland
Code:
use16
org 0x0100

        int     0x12                    ;BIOS - Get memory size in k bytes
        mov     dx,0x0400
        mul     dx
        call    ShowLongint
        mov     dx,txtTotal
        mov     ah,0x09                 ;DOS - Display string in dsdx
        int     0x21
        mov     ax,0x0002             ;get top of memory block
        mov     bx,cs
        sub     ax,bx
        mov     dx,0x0010
        mul     dx
        call    ShowLongint
        mov     dx,txtFree
        mov     ah,0x09                 ;DOS - Display string in dsdx
        int     0x21
        int     0x20                    ;Exit to Dos

ShowLongint                            ;dx high word, ax low word
        mov     cx,7                    ;least 7 digits
ShLo0  mov     si,dx
        mov     bx,10                   ;divisor
ShLo1  xchg    ax,si                   ;make ax high word, si low word
        xor     dx,dx                   ;extend high word
        div     bx                      ;dx = remainder, ax high quotient
        xchg    ax,si                   ;save high quotient, get low word
        div     bx                      ;dx = digit 0-9, ax low quotient
        or      dl,"0"                  ;convert to ASCII digit
ShLo2  push    dx                      ;save digit remainder on stack
        inc     ch
        mov     dx,si                   ;copy so not destroyed below
        or      dx,ax                   ;is full quotient zero?
        jnz     ShLo1                   ;no, continue
        mov     dl," "
        cmp     ch,cl                   ;If not 7 digits, fill with space
        jb      ShLo2
ShLo3  pop     dx                      ;get most significant digit
        mov     ah,0x02                 ;DOS - Display character in dl
        int     0x21
        dec     ch                      ;is more digits in stack
        jnz     ShLo3                   ;yes, loop back
        ret

txtTotal        db " bytes total memory",0x0D,0x0A,"$"
txtFree         db " bytes free",0x0D,0x0A,"$"    
Post 17 Aug 2005, 04:55
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
Try this (although it's MASM/TASM syntax, sorry). EDIT: FREERAM.ASM from TSRW31.ZIP
Post 27 Sep 2005, 22:45
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.