Doom plugin: In anticipation of moving to the EABI toolchain, because of its assumpti...
[kugel-rb.git] / apps / plugins / midi / midiutil.c
blobacb15582681f3f9dab3dafb118f539929912dcc1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Stepan Moskovchenko
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
22 #include "midiutil.h"
24 int chVol[16] IBSS_ATTR; /* Channel volume */
25 int chPan[16] IBSS_ATTR; /* Channel panning */
26 int chPat[16] IBSS_ATTR; /* Channel patch */
27 int chPW[16] IBSS_ATTR; /* Channel pitch wheel, MSB only */
28 int chPBDepth[16] IBSS_ATTR; /* Channel pitch bend depth */
29 int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
30 int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
31 unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
32 unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */
34 struct GPatch * gusload(char *);
35 struct GPatch * patchSet[128];
36 struct GPatch * drumSet[128];
38 struct SynthObject voices[MAX_VOICES] IBSS_ATTR;
40 void *alloc(int size)
42 static char *offset = NULL;
43 static size_t totalSize = 0;
44 char *ret;
46 int remainder = size % 4;
48 size = size + 4-remainder;
50 if (offset == NULL)
52 offset = rb->plugin_get_audio_buffer(&totalSize);
55 if (size + 4 > (int)totalSize)
57 printf("MALLOC BARF");
58 printf("MALLOC BARF");
59 printf("MALLOC BARF");
60 printf("MALLOC BARF");
61 printf("MALLOC BARF");
62 printf("MALLOC BARF");
63 printf("MALLOC BARF");
64 /* We've made our point. */
66 return NULL;
69 ret = offset + 4;
70 *((unsigned int *)offset) = size;
72 offset += size + 4;
73 totalSize -= size + 4;
74 return ret;
77 /* Rick's code */
79 void *alloc(int size)
81 static char *offset = NULL;
82 static ssize_t totalSize = 0;
83 char *ret;
86 if (offset == NULL)
88 offset = rb->plugin_get_audio_buffer((size_t *)&totalSize);
91 if (size + 4 > totalSize)
93 return NULL;
96 ret = offset + 4;
97 *((unsigned int *)offset) = size;
99 offset += size + 4;
100 totalSize -= size + 4;
101 return ret;
105 #define malloc(n) my_malloc(n)
106 void * my_malloc(int size)
108 return alloc(size);
111 unsigned char readChar(int file)
113 char buf[2];
114 rb->read(file, &buf, 1);
115 return buf[0];
118 unsigned char * readData(int file, int len)
120 unsigned char * dat = malloc(len);
121 rb->read(file, dat, len);
122 return dat;
125 int eof(int fd)
127 int curPos = rb->lseek(fd, 0, SEEK_CUR);
129 int size = rb->lseek(fd, 0, SEEK_END);
131 rb->lseek(fd, curPos, SEEK_SET);
132 return size+1 == rb->lseek(fd, 0, SEEK_CUR);
135 // Here is a hacked up printf command to get the output from the game.
136 int printf(const char *fmt, ...)
138 static int p_xtpt = 0;
139 char p_buf[50];
140 bool ok;
141 va_list ap;
143 va_start(ap, fmt);
144 ok = rb->vsnprintf(p_buf,sizeof(p_buf), fmt, ap);
145 va_end(ap);
147 int i=0;
149 /* Device LCDs display newlines funny. */
150 for(i=0; p_buf[i]!=0; i++)
151 if(p_buf[i] == '\n')
152 p_buf[i] = ' ';
154 rb->lcd_putsxy(1,p_xtpt, (unsigned char *)p_buf);
155 rb->lcd_update();
157 p_xtpt+=8;
158 if(p_xtpt>LCD_HEIGHT-8)
160 p_xtpt=0;
161 rb->lcd_clear_display();
163 return 1;