RetroCoding_GfxEngine.pdf

(1072 KB) Pobierz
Retro Coding:
Amiga, C, and graphics.library timer.device
Objectives
I only wanted to know how the vbcc works as cross compiler from Linux, but soon I find out
that I have no usable my own pure C code.
So I planed a little C-finger exercise, a simple little graphic FrameWork, "Graphic Engine" is
here really exaggerated, but for simplicity and from the lack of better word, we call it a graphic
tool :-)
Then I got the idea to turn it into a small programming workshop for the Amiga where I
describe the function and development of this graphic engine and a few details about some
AmigaOS components.
The engine itself uses the double-buffering technique for the graphics display: drawing
operations are made on a hidden bitmap that is only copied into the visible area of the window
once at a time when the drawing operations are complete. Later, in this workshop, I plan to
apply this technique to a full-screen display, in which, not only the content of the bitmap is
copied, but the bitmap itself may be used for display.
The frame rate could be set at will and will be controlled by the timer.device. We could also
control any animation based on the elapsed time, so that animations will be played at the
correct speed when we have limited frame rate in a limited power computer.
Our engine is designed for a system-friendly operation in a multitasking environment and can
be run from AOS1.2. Features of AOS3.0 are used, they will improve graphics
performance. However, in current version our renderers are limited to 8bit graphics thus there
is no support available for RTG systems. Also, there is no support available for specific features
of the Amiga chipsets: so no Hardware scrolling, no sprites or Copper lists.
There is a nice “playground” on which we can play and experiment with the functions
of graphics.library and bitplanes and results could be achieved as like the so "genuine" demos,
games or applications without too much changes.
I will perform some basic graphics.library functions to develope a simple 2D vector render that
achieved a quite fast performance in pure 68000 systems.
In order to follow the workshop you need a working C compiler. I will start with a brief
explanation on the installation and use of vbcc and NDK3.9. However, it will be possible test
the source also with SAS/C 6.5, StormC 3 and Maxon C++ 4. Since I will not use any compiler-
specific instructions in the the workshop, other compilers should not be a serious problem.
Have fun!
Kai Scherrer ( kai@kaiiv.de )
The fastest C compiler
There are a whole range of C compilers for the Amiga platform. Unfortunately, almost all are
not active maintained. One notable exception is vbcc, it is steadily growing by Frank Willes
hands.
I present here a few important compilers:
AZTEC C
A permanent element, which already in the earliest
Amiga years had an excellent reputation and was
practically the unofficial standard compiler on the
Amiga in the early nineties. The development was
then adjusted, however, the latest version 5.2
quickly became older software. Only recommended
if you like to devlop in authentic as possible 1.3.x system.
SAS/C 6.5
The official standard compiler on the Amiga. This is a
veteran too, which was available from the beginning of the
Amiga under the name "Lattice C". The last version was
6.58. In addition to the Compiler, Assembler and Linker,
there is a Debugger, a rudimentary Profiler and a useful
Make also. It is of complex operation: the compiler knows
574765744 different options, many of which make the
impression that even the developers themselves were not
sure whether they are good or bad in detail. This compiler
also runs on a pure 68000 system under Workbench 1.3, I only use it if I have old existing
source to maintain.
StormC 3
A C++ compiler from Haage & Partner. Also a complete
development kit with a real IDE operating badly together,
however, and can be operated in places only very
hemdsärmelig. Although not officially, the compiler seems to have
emerged from the last version of Maxon C ++: it is partly of the
same developer, both compilers have identical bugs and large
passages from the manual are taken like a mirror.
There is a version 4 in which the compiler was swapped by gcc.
Maxon C++ 4
My personal favorite, primarily due to the
successful integrated development environment:
Edit, Compile and Debug are going here like water
in a river. Unfortunately, it wasn´t particularly
widespread and the latest version was not too long
in the market, because shortly after its publication
in 1996 Maxon retired from the Amiga market.
Therefore, it is only suitable if you want to port
existing software projects though writing with it is
very pleasant.
vbcc
And the best for last: the only compiler that is still currently
maintained. A solid C compiler with Linker and Assembler.
It can also be used as a cross-compiler, which allows to build his
Amiga binaries, for example, under Linux.
This will be the compiler that I will use here for the workshop, so I
will touch briefly on the installation.
vbcc installation under AmigaOS
At least three packages are needed to use the compiler for Amiga projects:
The compiler itself from http://sun.hasenbraten.de/vbcc/: vbcc_bin_amigaos68k.lha
The AmigaOS target archive, also from http://sun.hasenbraten.de/vbcc/:
vbcc_target_m68k-amigaos.lha
The NDK for AmigaOS3.9 that kindly still offered at Haage & Partner
To create the vbcc binaries that are compatible with the Workbench 1.2 a config file still is
necessary, which unfortunately is missing in the current vbcc version 0.9d.
Begin with NDK39.lha, that unpacks itself to a suitable location on your hard disk, eg. Work:
Code. Then unpack vbcc_bin_amigaos68k.lha to RAM: and after start the included installer and
reboot in the end. Now unzip vbcc_target_m68k-amigaOS.lha to RAM: and start the
installer. On the question of the system headers add the path to the unzipped
NDK39, include/include_h, eg. Work: Code/NDK_3.9/include/include_h.
Reboot again in the end.
Now copy kick13 to vbcc: config/and test your setup as follows:
Creates the file test.c with:
#include <dos/dos.h>
#include <clib/dos_protos.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv [])
{
static char hello[] = "Hello Amiga! \n\n" ;
Write(Output (), hello, sizeof(hello) - 1);
printf("Hello C! \n");
exit(RETURN_OK);
}
Compile it with vbcc with:
vc + kick13 test.c -o test -lamiga
For SAS/C:
sc test.c link ansi strict
If the code copile without errors,
run test . This should be easy and
generate two lines:
Hello Amiga!
Hello C!
If it is successful, we can use the compiler to do our workshop.
C and how it works with AmigaOS
Because it fits so nicely, I would like to discuss here how C interacts with the AmigaOS.
In our test.c above we are dealing simultaneously with three different levels:
First there is the C core language itself, in our example are the basic data types int, char,
and the operator sizeof().
Then we have functions from the standard C library, in our example these are the
functions printf() and exit() , which are declared in the includes stdio.h or stdlib.h.
These features are available on every system and, usually, integrate the Compiler
package itself.
And finally, we find the system calls for AmigaOS. These are available only on Amiga
systems and are here incorporated in the NDK 3.9. From C programming view, AmigaOS
looks like a large collection of functions and data types. In our example, these are the
two functions write() and output() from the dos.library, and the constant
RETURN_OK which are declared in Includes clib/dos_protos.h and dos/dos.h.
This Includes are found in NDK folder in include/include_h. In addition, for these
functions we still need amiga.lib which we will call with the option -lamiga for the
Compiler integrate the librarie with the code. It should be noted that all declarations for
the system functions are in the files #?_Protos.h located in clib/folder.
We should also know why test.c is the way it is: our Compiler installation is so complete that
we can use both the C standard library and the Amiga system calls.
Here we go
We want to open a simple, resizable, window on workbench in which we will draw with the
help of graphics.library functions to do an accurate timing animation. All should be system
friendly, (it should respond immediately to user actions and consume only as much computer
time and resources as it is necessary). This sounds easier than it really is, so we go through the
path step by step.
Starting with main() function, we will not do too much inside main(), however, is a good place
to open the necessary libraries: intuition.library for the window and graphics.library for the
drawing commands.
First we must define the global variables, here are two base addresses initialized with 0:
Zgłoś jeśli naruszono regulamin