Add code and binary
This commit is contained in:
parent
ae62ec4aaa
commit
7024260425
30
README.md
30
README.md
@ -1,2 +1,28 @@
|
||||
# amiga-allocmem-example-code
|
||||
The C program used in "What the Heck is NoFastMem?" to show how AllocMem works
|
||||
# Amiga AllocMem Example Code
|
||||
|
||||
The C program used in "What the Heck is NoFastMem?" to show how AllocMem works.
|
||||
View the video here: https://www.youtube.com/watch?v=CDUtoaqKkkk
|
||||
|
||||
## Compiling
|
||||
|
||||
You'll need [vbcc](http://sun.hasenbraten.de/vbcc/) with the m68k target and the appropriate Native
|
||||
Development Kit headers installed:
|
||||
|
||||
```
|
||||
vc -lauto -lamiga -c99 +kick13 -o mem mem.c
|
||||
```
|
||||
|
||||
`mem` included in this repo is built with the above command and
|
||||
should run on AmigaOS 1.3 and higher.
|
||||
|
||||
## Running
|
||||
|
||||
Open a Shell on an Amiga with Fast RAM and run:
|
||||
|
||||
```
|
||||
mem
|
||||
run nofastmem
|
||||
mem
|
||||
run nofastmem
|
||||
run
|
||||
```
|
||||
|
57
mem.c
Normal file
57
mem.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <exec/exec.h>
|
||||
#include <clib/exec_protos.h>
|
||||
#include <clib/graphics_protos.h>
|
||||
|
||||
#include <hardware/dmabits.h>
|
||||
#include <hardware/custom.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MEMORY_SIZE (100)
|
||||
|
||||
extern struct Custom custom;
|
||||
|
||||
UBYTE *buffer;
|
||||
UBYTE *target;
|
||||
|
||||
void cleanUp() {
|
||||
if (buffer) FreeMem(buffer, MEMORY_SIZE);
|
||||
if (target) FreeMem(target, MEMORY_SIZE);
|
||||
}
|
||||
|
||||
int main() {
|
||||
atexit(cleanUp);
|
||||
|
||||
buffer = AllocMem(MEMORY_SIZE, MEMF_CLEAR);
|
||||
target = AllocMem(MEMORY_SIZE, MEMF_CLEAR);
|
||||
|
||||
strcpy((char*)buffer, "Agnus copied me since I am in Chip RAM. Thanks, Agnus!");
|
||||
strcpy((char*)target, "Oh no, the blitter can't work with me since I'm in Fast RAM (or Slow RAM).");
|
||||
|
||||
// Agnus blitter stuff
|
||||
OwnBlitter(); WaitBlit(); // Wait for the blitter to finish up its current operation.
|
||||
custom.bltcon0 = 0x09f0;
|
||||
custom.bltcon1 = 0;
|
||||
custom.bltapt = buffer;
|
||||
custom.bltdpt = target;
|
||||
custom.bltamod = 0;
|
||||
custom.bltdmod = 0;
|
||||
custom.bltafwm = 0xffff;
|
||||
custom.bltalwm = 0xffff;
|
||||
// Setting bltsize starts the blitter operation
|
||||
custom.bltsize = (1 * 64) + (MEMORY_SIZE / 2); // 1 "row", convert byte width to words
|
||||
DisownBlitter(); WaitBlit(); // Wait before we do anything else with the Chip RAM we (might) have.
|
||||
|
||||
printf("\n%s\n\n", target);
|
||||
|
||||
if (buffer) FreeMem(buffer, MEMORY_SIZE);
|
||||
if (target) FreeMem(target, MEMORY_SIZE);
|
||||
|
||||
buffer = 0;
|
||||
target = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user