Thank you Mattias :)
Vitor Almeida
Recent community posts
Hey guys, I also made a quick program to visualize the default doslike palette (it will be useful for future projects):

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include "dos.h"
#define SCREEN_WIDTH screenwidth()
#define SCREEN_HEIGHT screenheight()
#define SQUARE_SIZE 15 // sqrt((SCREEN_WIDTH * SCREEN_HEIGHT) / MAX_PALETTE) == 15.8 (if SCREEN_WIDTH = 320, SCREEN_HEIGHT = 200, MAX_PALETTE = 256)
#define OFFSET 2
#define COLS_PER_ROW 21 // (SCREEN_WIDTH / SQUARE_SIZE) == 21.3333 (if SCREEN_WIDTH = 320, SQUARE_SIZE = 15)
#define MAX_PALETTE 256
#define COLOR_WHITE 15
#define COLOR_RED 41
#define PADDING 1
#define MOUSE_CURSOR_SIZE 3
char textbuffer[17]; // utility buffer for textual stuff
void input(void) {
if (keystate(KEY_ESCAPE)) exit(0); // exit the game
}
void update(void) {
}
void draw(void) {
int palindex = 0;
int x, y;
// mouse position & color
int mx = mousex(), my = mousey();
int mc = COLOR_RED;
// draw each color of the palette
for (int row = 0; palindex < MAX_PALETTE; row++) {
// row by row, as long as we have colors in the palette to draw
for (int col = 0; col < COLS_PER_ROW && palindex < MAX_PALETTE; col++) {
x = OFFSET + (col * SQUARE_SIZE);
y = OFFSET + (row * SQUARE_SIZE);
setcolor(palindex);
bar(x, y, SQUARE_SIZE - PADDING, SQUARE_SIZE - PADDING);
if (mx > x && mx < (x + SQUARE_SIZE) && my > y && my < (y + SQUARE_SIZE)) {
setcolor(COLOR_WHITE);
x = (SCREEN_WIDTH * 0.5) - 50;
y = SCREEN_HEIGHT - 15;
sprintf(textbuffer, "getcolor() = %d", palindex); outtextxy(x, y, textbuffer);
// if the mouse (that has a red cursor) is inside a redish color
// give to it a white color to increase contrast
if (palindex == 4 || palindex == 12 || (palindex >= 34 && palindex <= 41) || (palindex >= 108 && palindex <= 114))
mc = COLOR_WHITE;
}
palindex++;
}
}
// mouse cursor
setcolor(mc);
bar(mx, my, MOUSE_CURSOR_SIZE, MOUSE_CURSOR_SIZE);
}
int main(int argc, char* argv[]) {
setvideomode(videomode_320x200);
setdoublebuffer(1);
uint8_t* screen = screenbuffer();
while (!shuttingdown()) {
waitvbl();
clearscreen();
input();
update();
draw();
screen = swapbuffers();
}
return 0;
}
Mattias, thank you so much: you gave me all the tools I need to study more and understand the sound generation process.
The code you provided worked. I'm also using this video series (https://www.youtube.com/watch?v=tgamhuQnOkM) by javidx9 to practically understand the formula used in oscillator generation (to create a square wave, for example), but you've already tied up all the loose ends I needed to use a buffer and generate sound with control (amplitude, frequency, type, etc.).
Thank you for your help and precious time, my friend (I am really a beginner in sound synthesis, learning as I go).
Regarding the project, you've already helped me a lot (all the questions I had have been answered; now it's just a matter of understanding and programming).
Thank you and if you need help in your projects (promotion, testing etc.) I am available.
Hi everyone, how are you?
I am trying to do sound manipulation by generating a beep (square wave) simulating a PC speaker with a certain frequency and amplitude.
Initially, I'll make the beep for a Pong game when the ball hits a surface.
I read the library's source code and looked for some YouTube videos to understand the audio concepts involved.
But the most I'm managing to do is generate noise for a short time.
Currently I have a variable where I create the sound dynamically (before playing):
struct sound_t* sound_border;
I initialize the sound system with the code:
setsoundmode(soundmode_8bit_mono_11025);
I create the sound with the code:
int channels = 1;
int samplerate = 11025l;
short samples[] = { 0 };
sound_border = createsound(channels, samplerate, 8, samples); // 8 = framecount
And then when it's necessary to play:
playsound(1, sound_score, 0, 255); // full volume, no loop, channel 1
However, I still don't understand the concept of "framecount" (is it the number of times the samples will be copied into the sound buffer for each channel?).
I don't understand how nois is being played if my sample rate is zero (and the noise changes when I change the framecount).
Any tips would be very helpful.
Thank you everyone.
Thank you Blodyavenger.
I'm trying to simulate a color decay system (visually similar to how old phosphor monitors displayed graphics (not shown in the image)).
I'll post something when it's ready :)
Hey everyone!
I'm having trouble understanding how the color and palette system works in the library.
Currently, I'm drawing a simple Pong game (using white for the elements and other simple drawing functions like line and rectangle).
However, I've created a simple palette with some shades of green that I want to use to simulate a color decay effect using the framebuffer.
My problem is that I can't change (and especially compare) the colors in the drawn framebuffer to know which color I need to "decay".
I don't understand the combined concept of being able to change the framebuffer and the color palette.
Could you please help me?
Thanks.
+1 -> A PC speaker would be a powerful addition to the library (and would be very "harmonious" with the existing features).
I myself would like to run several tests/keyboards with this potential functionality (I really like the sound of a PC speaker).
I'm developing a series of learning games using the library and I'm really enjoying it (it's easy to use; anything I draw looks very nice (even colored rectangles) thanks to the screen shader, features, etc.).
Thank you very much for developing something that makes creating games and programs with this aesthetic much easier.


