home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
datafiles
/
text
/
c_manual
/
amiga
/
appendices
/
examples
/
systemexamples.doc
< prev
next >
Wrap
Text File
|
1995-02-27
|
6KB
|
165 lines
4 SYSTEM
4.1 HARDWARE
Example 1
This fantastic useful program does what all true hackers have
dreamt of. Enjoy your Amiga's fantastic ability to flash one
LED!
Example 2
This is a very bad program that plays a tune with the first
audio channel. The reason why it is bad is because the
program does not "lock" the channel before it uses the
hardware. It simply steals the sound channel without asking
nor notifying anyone.
If you lock the channel as described in the Audio Device
chapter you may use the hardware registers. However, this
program does not lock it nor tries to reserve the channels
as we should. The program is included here only as a
demonstration how the hardware registers are working, but
should not be used in your own programs!!!
4.2 AMIGADOS
Example1
This program collects ten integer values from the user, and
saves them in a file ("HighScore.dat") on the RAM disk. The
memory is then cleared, and the file cursor is moved to the
beginning of the file. The file is then loaded into the
memory again, and printed out.
Example2
This example demonstrates how to create a directory called
"MyDirectory" on the RAM disk.
Example3
This example demonstrates how to rename files and directories.
It will rename the file Example 1 created (called
"HighScore.dat") to "Numbers.dat". It will also rename the
directory Example 2 created ("MyDirectory") to "NewDirectory".
Example4
This example demonstrates how to delete files and directories.
It will delete the file Example 1 and directory Example 2
created. (The file and directory are supposed to have been
renamed by Example 3.)
Example5
This example demonstrates how to attach a short comment to a
file. A short file called "Letter.doc" will be created, and a
short comment will be attached. To see the comment use the
CLI command "List".
Example6
This example demonstrates how to protect and unprotect files.
The file Example 5 created ("Letter.doc") will be protected,
and we will then try to delete it (unsuccessfully). We will
then unprotect the file and then try to delete it
(successfully).
Example7
This program takes a file/directory/device name as
parameter, and prints out some interesting information about
it.
Example8
This program takes a directory/device name as parameter,
and prints out all the file/directory-names inside it. This
example describes how to use Examine() and ExNext().
4.3 LISTS
Example 1
Demonstrates how to create a list with three nodes. (Not very
amazing, but useful to know.)
Example 2
Demonstrates how to scan through a list from the head to the
tail, and the other way around.
Example 3
Demonstrates how to scan through a list looking for nodes with
a special name. Uses the function FindName().
4.4 MESSAGES
Example 1
A: This program will create a message port called "NrPort".
It will then go to sleep and will first wake up when it has
received a message. It will collect the message, read and
alter it before it replies and the program terminates.
B: This program will create a message of type NrMessage. It
will then try to find a message port called "NrPort". If it
finds that port it will send a message to it, and wait for
the other task to reply.
Start program A then program B.
Example 2
This program will open the Timer Device to which we connect
a message port. When the Timer Device has done our request
(waiting for 10 seconds) it will send a message to the
message port which tells us that the time has passed.
This example demonstrates how you can give the system (like
the Timer Device) a message port through which the system can
communicate with us. Although we are using the Timer Device,
it is only as a demonstration on how to work with message
ports. For more information about the Timer Device, see
chapter Timer Device.
Example 3
This program will open two ports. The first port is used by
the Timer Device while the second port will not be used at
all (it is a dummy port). The reason why this example opens
an extra port is because I want to demonstrate how you can
handle two message ports simultaniously. With this technique
you can monitor up to 32 ports (the system usually needs some
singnals, but you have at least 16 signals for yourself).
4.5 DIRTY INPUT
Joystick
Joystick() is a handy, easy and fast but naughty function
that hits the hardware of the Amiga. It looks at either port
1 or port 2, and returns a bitfield containing the position
of the stick and the present state of the button.
Mouse
Mouse() is a handy, easy and fast but naughty function that
hits the hardware of the Amiga. It looks at either port 1 or
port 2, and returns the (x and y) delta movement of the
mouse, as well as a bitfield containing the present state of
the three buttons. (A normal Amiga mouse has only two buttons
(left and right), but it is possible to connect a mouse with
three buttons, so why shouldn't we support it?)
Keyboard
Keyboard() is a handy, easy and fast but naughty function
that hits the hardware of the Amiga. It checks the keyboard,
and returns the Raw Key Code. (See appendix "SYSTEM DEFAULT
CONSOLE KEY MAPPING" for the full list of Raw Key Codes.)
Analogue
This is an Analogue Joystick reader. It is handy, easy and
fast but a bit naughty function since it reads directly from
the hardware registers. It can read either port 1 ("the mouse
port") or port 2 ("the joystick port"). Note that an Analogue
Joystick can have two buttons.