#AllocMem quest.
20 messages in this thread
Hi folks. More dumb-o questions. I'm trying to grab some memory from the
system. The call that makes some sense is AllocMem Correct? The sample in
Abacus Amiga Machine Language has an error. It uses A6 twice (one after the
other) I "think"it means to load the Mode into D1. Now if thats true (and I
think it is) what are the choices? I have looked at Mapping the Amiga and
Amiga Programers Handbook. Neither one (to stupid me) spells it out enough for
me to understand. I'm looking for something like D1=0 for Chip or 1 for Fast
Ram etc. I also am a tad puzzeled by releasing this memory. There are a few
different routines but It's not clear which one is to be used. Thanks in
advance for any help… Oh yes it's not clear what the size of mode should be.
Word is my guess but… Again it's not clear.
Yes, AllocMem is what you want. Its in the Exec Library. Size and Mode are
both long. If you have the Amiga include files (they come with Devpac) you
can use the names as follows :
MEMF_PUBLIC 1 Public Memory
MEMF_CHIP 2 Chip Memory
MEMF_FAST 4 Fast Memory
MEMF_CLEAR $0100 Clear the Memory
If you don't specify chip or fast it will give you either, fast if
possible. You can add MEMF_PUBLIC and/or MEMF_CLEAR to your selection.
Memory which is passed to system calls or accessed by other tasks should
be made public.
To free the memory, use FreeMem giving the adress of the block in A1 and
the size in bytes in D0, both long.
There is another way of doing this using AllocRemember/FreeRemember in the
Intuition Library. This lets you do more than one block in one go but its
more complicated.
My thanks! I'm not sure I understand. Is there and equate file for example
that knows that MEMF_CLEAR is = $0100? Thats really that part that got me
veged out. The doc (that I can find) never get around to what the values are.
And I suspect that I am not understanding how to read the doc right or I'm
missing out how to use includes. Please advise. And my thanks for the help!
It appears to be a great set of routines available and will make my program
port quite easy.
The way they do it in the include files is a bit complicated. If you look
in exec/memory.i you will find a line that says :
BITDEF MEM,CLEAR,16
This is using a macro "BITDEF" which is defined in exec/types.i and if you
look at the comments it says this should produce two lines as follows :
MEMB_CLEAR EQU 16 ; Bit number
MEMF_CLEAR EQU 1<<16 ; Bit mask
The 1<<16 means 1 shifted left 16 binary places, in other words $0100.
The designers of the system don't really want people to relate to it at
the level of "$0100 means clear", they expect you to read the RKM
Libraries manual which gives you the name MEMF_CLEAR and a description of
what it does.
You probably don't want to hear this, but if you are going to do any
serious Amiga programming using system calls you really need either the
official RKM manuals or something with the same sort of information. The
books which avoid using include files are IMHO a dead end.
I found that out right away <grin>. Well I don't have a problem with having
lots of Includes. In fact I think it's great. However I also think its stupid
to "hide" things (if thats the only reason) to make things any more obscure
than they have to be. The RKM are a wonderfull experience in lack of working
examples. However I found this to be true on every other computer I've worked
with. Often times there is a book or set of books that "spell things out" that
go with the (in this case) RKM to get you over the start of your learning
curve. Any idea what that would be? Amiga Machine Language has everything
defined within the program which is good for getting you to understand whats
really happening behind the curtin but for acutal programing…. <sigh> When
will those Doc guys get the message. One routine one working example (or more)
<grin> Thanks for your time spent replying.
I don't think the designers are deliberatly hiding things. In my
opinion the Amiga design has the look of something descended from
larger systems like Unix, rather than something that has grown from
smaller systems like the C64. There is a tendency to do things in
very "structured" ways. For example, the BITDEF macro looks
convoluted, but once you have designed it, anywhere in the system you
need to allocate single bits as flags you just use BITDEF with the
name and which bit to use. It will automatically generate a bit mask
and a bit number with consistent names. This means whenever you come
across something called xxxF_yyy you know it is a bit mask and
xxxB_yyy is the corresponding bit number.
I haven't come across any really books for people who know programming
but don't know the Amiga (I think thats what you want, am I right ?).
I tend to look things up in the RKMs and try to slog my way through
the problems. This probably explains why I have a fair amount of
theory but haven't actually achieved much <grin>. I used to have a
good book called "The Kickstart Guide to the Amiga", or something
like that. It was good at describing the overall plan of things. A
long time ago there was a magazine called "Amiga Transactor". It was
full of examples and technical articles. The magazine packed up years
ago but I used to see back issues on sale in some of the Amiga shows.
I haven't seen any recently, but then most Amiga shows around here
have turned into places full of people selling cheap games.
Good luck with your Programming !
Grab an old issue of Amiga Transactor, then start looking at the names
of the columnists and feature story writers. You'll see … Don
Curtis, Larry Phillips, John Toebes, Betty Clay, Bob Rakosky, myself,
etc. … all sysops here.
I thought a there were a lot of familiar sounding names around here.
Transactor lives, and with up to date technology. No old fashioned
paper and printing presses for the Amiga Gurus 🙂
Thanks I will keep plugging away. I guess in my case my work has never been
all that brilliant but… I get it done and it works <grin> Keep on pluggin
Nice to think of assembler language as 'up front and visible', but
code CAN be obfuscated just as much as C if that's the programmer's
style. You can bury things in mounds of macros, inventories of
#includes, and lashing of linked functions (shared from obscured
libraries with no docs or scanned from massive libs).
But, yes, if you want to, assembler code can show neatly and
clearly. That's the way I like to write it: because a year later, I
can still figure out what I was doing.
I could not agree with you more. Personaly I don't use macros. Cut
and paste work fine <grin>. I once looked at a program that was (I'm
guessing) 80 to 90 percent macros. Totaly un-good to me. I like
straightforward lots of comments at the start of a module and
comments on every line. I do it to save my mind later on. Most
"other" peoples code looks like trash to me. However I also am a
firm believer in stuff thats done and works.
for LOTS of working examples, see if you can find a copy of my old book from
Compute! books – Amiga Machine Language Programming Guide. Good luck.
I make my own equate files by reading the Amiga Rom Kernel books.
Ok heres the info you should need:
AllocMem:
memoryBlock = AllocMem(byteSize, attributes)
D0 D0 D1
INPUT:
D0 = Byte size of requested memory
D1 = Attributes (see below)
OUTPUT:
Returns memoryblock address in D0
Attributes:
MEMF_CHIP: Only allocate Chipmem
MEMF_FAST: Can ya guess what it is yet ? (Rolf Harris Voice)
MEMF_PUBLIC: Memory that is always addressable (eg not Virtual)
MEMF_LOCAL: You don't really need to know this one
MEMF_CLEAR: The memory will be initialized to all zeros.
MEMF_REVERSE: Allocates from top of memory downwards
if you need to know the values for these, well you must not be using the
includes, your better off using them, include exec.i and you'll be ok.
The attributes are individual BITS so you can make up the appropriate
number in D1 by repeatedly adding attributes to D1(initialised to 0
ofcourse..) or depending on your assembler you may be able to load them
all into the register with a single move instruction (try using the |
character between attributes in your assembler, it might work <g>)
BTW What assembler are you using?
Have fun and if you need any help give me a shout….
P.S If you REALLY need the bit values i'll dig them out for ya 🙁
Rob.
D&D Famous last words: "I throw my beer at the wizard"
Uhhh.. Ok so the include files will have them. Stupid me! <grin> I just
assumed this was all C structures. Ok, I'm using the Devpac3.0 kit and used to
use A68K. I've got my Old Developer stuff from 2.0 days (I hear we are up to
3.0 now?!?) The Abacus book thru me for a small loop since they avoid
includes. Which is ok for showing whats really going on but not so hot for big
programs I guess. Thanks for the help. It's really appreciated.
Hey no problem, i like helping if i can, the more people who realise that
the amiga is apretty neat computer to code on the better – of course if
you really wanna do some nasty stuff you need the Hardware reference
manual… then you have full blown access of the blitter and copper etc..
much more fun then the OS, even though there are a lot of good routines in
the OS (never thought i'd say that <g>) The Abacus book is to be honest a
heap of s**t… sorry but it teaches REAL bad ideas to you.. if you can
get them from somewhere the official Commodore includes and autodocs for
KS3 give a LOT of info on the OS and it's functions – i'll see if i can
get the name of abetter OS book for ya….
BTW If you ONLY code in assembler you can kill ALL the #?.h files in the
include directory… just keep the #?.i files as they are used by the
assembler..
Also try to get hold of the latest release of ASM-ONE as it has a LOT of
info in it and is a VERY good intergrated assembly/debugging
environment… (can't stand Devpac myself <g> all thouse non-standard 'db'
statements etc…)
just remember….
JMP $0
will always guru you program <g>
Rob.
AD&D Famous last words: "sorry, what was that?"
One thing that Amiga MAchine Language did was clue me in to what was really
happening <grin> But I tend to agree that as it stands it's a perfect example
of how not to program a large application correctly. They sure make those
Includes cryptic! Whats the point (is my point)
As for cryptic includes, yup i have to agree – i keep meaning to write
a program that will search all the autodocs given a keyword and give
me info on a routine by offset or name or somthin – could reduce
development time soo much…. stil i'll do it tomorrow <g> or maybe
saturday <G>
Murphys (electrical) law(s)…
A fail safe circuit will destroy others
Fail Safe! Whew scary movie… And no killer aliens in it.
Sorry never seen it 🙁
Alternative uses for floppy disks, Number 10:
Road resurfacing