BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
blitzexec.h
Go to the documentation of this file.
1/*
2 * blitzexec.h - exec calls from library code. There is no C startup in a
3 * library, so no SysBase variable: like the originals (MOVE.l 4,a6) the
4 * base is read from address 4 at every call.
5 */
6#ifndef BLITZEXEC_H
7#define BLITZEXEC_H
8
9#include <exec/io.h>
10#include <exec/memory.h>
11#include <exec/ports.h>
12#define __NOLIBBASE__
13#include <proto/exec.h>
14#undef __NOLIBBASE__
15#define SysBase (*(struct ExecBase **)4L)
16
17/* BL_FREESIGNAL(sig) - FreeSignal with the signal number zero extended,
18 like the originals (MOVEQ #0,d0:MOVE.b sigbit,d0:JSR _FreeSignal(a6)).
19 The NDK inline takes a BYTE and would pass a bit number $FF as -1.
20 `sig` is passed as its (unsigned) value: a UBYTE mp_SigBit, or a UWORD
21 for MOVE.w (brexxlib mybit = $FFFF). Needs blitzlib.h (BLITZ_SYSJSR1). */
22#define BL_FREESIGNAL(sig) ((void)BLITZ_SYSJSR1(SysBase, -336, (sig)))
23
24/* ------------------------------------ exec V36 calls built with V33 ones
25
26 Exec V36's CreateMsgPort/DeleteMsgPort, CreateIORequest/DeleteIORequest
27 and AllocVec/FreeVec do not exist on Kickstart 1.x; these helpers do
28 the same with exec V33 functions (AllocMem, FreeMem, AllocSignal,
29 FreeSignal, FindTask), one path on every Kickstart. They are static
30 inline and always inlined (the libraries are built without GCC's own
31 inlining of small functions, which would leave each an out-of-line copy
32 or not, by its heuristics): a library that calls one from several
33 places and wants a single copy wraps it in a static function of its
34 own (ricompactdisclib's and ritrackdisklib's newport). */
35#define BL_EXEC_INLINE static inline __attribute__((always_inline))
36
37/* bl_newport: a signal port of the calling task (as CreateMsgPort): the
38 MsgPort cleared, a signal bit, PA_SIGNAL, an empty message list; NULL
39 without memory or a free signal */
40BL_EXEC_INLINE struct MsgPort *bl_newport(void)
41{
42 struct MsgPort *mp = AllocMem(sizeof *mp, MEMF_PUBLIC | MEMF_CLEAR);
43 BYTE sig;
44
45 if (!mp)
46 return NULL;
47 sig = AllocSignal(-1);
48 if (sig < 0) {
49 FreeMem(mp, sizeof *mp);
50 return NULL;
51 }
52 mp->mp_Node.ln_Type = NT_MSGPORT;
53 mp->mp_Flags = PA_SIGNAL;
54 mp->mp_SigBit = sig;
55 mp->mp_SigTask = FindTask(NULL);
56 mp->mp_MsgList.lh_Head = (struct Node *)&mp->mp_MsgList.lh_Tail;
57 mp->mp_MsgList.lh_TailPred = (struct Node *)&mp->mp_MsgList.lh_Head;
58 return mp;
59}
60
61/* bl_freeport: frees the signal bit and the port of bl_newport() */
62BL_EXEC_INLINE void bl_freeport(struct MsgPort *mp)
63{
64 FreeSignal(mp->mp_SigBit);
65 FreeMem(mp, sizeof *mp);
66}
67
68/* bl_newreq: a cleared request of `size` bytes with mn_ReplyPort `port`
69 and mn_Length set (as CreateIORequest) and NT_REPLYMSG: CheckIO takes a
70 request that was never sent for done, as one of CreateIORequest; NULL
71 without memory */
72BL_EXEC_INLINE void *bl_newreq(struct MsgPort *port, ULONG size)
73{
74 struct IORequest *req = AllocMem(size, MEMF_PUBLIC | MEMF_CLEAR);
75
76 if (req) {
77 req->io_Message.mn_Node.ln_Type = NT_REPLYMSG;
78 req->io_Message.mn_ReplyPort = port;
79 req->io_Message.mn_Length = size;
80 }
81 return req;
82}
83
84/* bl_freereq: frees a request of bl_newreq() of `size` bytes; NULL is
85 ignored */
86BL_EXEC_INLINE void bl_freereq(void *req, ULONG size)
87{
88 if (req)
89 FreeMem(req, size);
90}
91
92/* bl_allocvec: a block of `size` bytes in AllocVec's layout: AllocMem of
93 size + 4 bytes, the whole size in the first long, the block behind it.
94 exec sees the sizes AllocVec would allocate, and a block of it may be
95 freed by exec's FreeVec on V36+ (and the other way round). NULL
96 without memory */
98{
99 ULONG *p;
100
101 size += 4;
102 p = AllocMem(size, flags);
103 if (!p)
104 return NULL;
105 *p = size;
106 return p + 1;
107}
108
109/* bl_freevec: frees a block of bl_allocvec() (or AllocVec); NULL is
110 ignored, as by FreeVec */
112{
113 ULONG *p = block;
114
115 if (p) {
116 p--;
117 FreeMem(p, *p);
118 }
119}
120
121#endif
UBYTE flags[2]
Definition 2dlib.c:297
UWORD size
Definition 2dlib.c:1170
BL_ALWAYS_INLINE void block(const struct bb_shape *shape, const struct bb_bitmap *bm, UBYTE *cb, WORD x, WORD y)
Definition blitlib.c:241
BL_EXEC_INLINE void bl_freevec(void *block)
Definition blitzexec.h:111
BL_EXEC_INLINE void * bl_newreq(struct MsgPort *port, ULONG size)
Definition blitzexec.h:72
BL_EXEC_INLINE void bl_freeport(struct MsgPort *mp)
Definition blitzexec.h:62
BL_EXEC_INLINE void * bl_allocvec(ULONG size, ULONG flags)
Definition blitzexec.h:97
#define BL_EXEC_INLINE
Definition blitzexec.h:35
BL_EXEC_INLINE void bl_freereq(void *req, ULONG size)
Definition blitzexec.h:86
BL_EXEC_INLINE struct MsgPort * bl_newport(void)
Definition blitzexec.h:40
struct MsgPort port
Definition brexxlib.c:299