Skip to content

Commit

Permalink
Make code more portable
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Feliks committed Nov 4, 2023
1 parent 930cc09 commit 5101d04
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 89 deletions.
2 changes: 1 addition & 1 deletion bonus.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void b_nadaj0(STATEK* bon)
void bonus_inicjuj(STATEK* bon)
{
int i, j = 36;
bon->x = random(299);
bon->x = rand() % 299;
bon->y = 0;
bon->licznik = 0;
for (i = 0; i < 6; i++)
Expand Down
4 changes: 2 additions & 2 deletions bullets.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void p_nadaj0(void)
void p_kontrola_kaps(POCISK* poc, KAPSULA* kaps, POLE* ple)
{
if (poc->x > kaps->x && poc->x < kaps->x + 19 && poc->y > kaps->y && poc->y < kaps->y + 19 && !kaps->trafiona && !ple->aktywne) {
play_sound(&soundtab[random(SND_EXPLOSION)]);
play_sound(&soundtab[rand() % SND_EXPLOSION]);

kaps->giwera--;
kaps->trafiona = 1;
Expand All @@ -136,7 +136,7 @@ void p_kontrola_stat(POCISK* poc, STATEK* sta, KAPSULA* kaps)
kaps->licznik++;
ile_aktywnych--;

play_sound(&soundtab[random(SND_EXPLOSION)]);
play_sound(&soundtab[rand() % SND_EXPLOSION]);
}
}

Expand Down
1 change: 1 addition & 0 deletions control.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*****************************************/

#include <dos.h>
#include <string.h>

#include "globals.h"

Expand Down
44 changes: 26 additions & 18 deletions enemies.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,44 @@
void stat_inicjuj(STATEK* sta, KAPSULA* kaps)
{
int i, j;
if (!random(2))
sta->x = random(30);
else
sta->x = random(30) + 269;
sta->y = random(79);

if ((rand() % 2) == 0) {
sta->x = rand() % 30;
}
else {
sta->x = (rand() % 30) + 269;
}
sta->y = rand() % 79;

sta->zm_x = 0;
sta->zm_y = 0;
sta->aktywny = 1;
sta->xs_min = random(319);
sta->xs_max = sta->xs_min + random(319 - sta->xs_min);
for (i = 0; i < 3; i++)
sta->poc_x[i] = random(319);

sta->xs_min = rand() % 319;
sta->xs_max = sta->xs_min + rand() % (319 - sta->xs_min);

for (i = 0; i < 3; i++) {
sta->poc_x[i] = rand() % 319;
}

sta->licznik = 0;
sta->k = 0;
sta->laser_pom = 0;
if (kaps->punkty < 20)
sta->giwera = 0;
else if (kaps->punkty >= 20 && kaps->punkty < 40)
sta->giwera = random(2);
sta->giwera = rand() % 2;
else if (kaps->punkty >= 40 && kaps->punkty < 60)
sta->giwera = random(3);
sta->giwera = rand() % 3;
else if (kaps->punkty >= 60 && kaps->punkty < 80)
sta->giwera = random(4);
sta->giwera = rand() % 4;
else if (kaps->punkty >= 80 && kaps->punkty < 100)
sta->giwera = random(5);
sta->giwera = rand() % 5;
else
sta->giwera = random(6);
sta->giwera = rand() % 6;
if (sta->giwera != 5) {
sta->ruch = random(2);
sta->v = random(2);
sta->ruch = rand() % 2;
sta->v = rand() % 2;
} else {
sta->ruch = 2;
sta->v = 1;
Expand Down Expand Up @@ -209,8 +217,8 @@ void stat_ruch2(STATEK* statek)
}
}
if (!statek->zm_x && !statek->zm_y) {
statek->kx = random(299);
statek->ky = random(100);
statek->kx = rand() % 299;
statek->ky = rand() % 100;
statek->zm_x = 1;
statek->zm_y = 1;
}
Expand Down
3 changes: 3 additions & 0 deletions font.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
(C) 2001, 2023 M. Feliks
*****************************************/

#include <string.h>

#include "globals.h"

unsigned char chardata[];


void init_font(void)
{
}
Expand Down
2 changes: 1 addition & 1 deletion intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void intro(void)
timer_wait();
}

play_sound(&soundtab[random(SND_EXPLOSION)]);
play_sound(&soundtab[rand() % SND_EXPLOSION]);
flash();

while (1) {
Expand Down
4 changes: 3 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#include "globals.h"
Expand Down Expand Up @@ -55,7 +56,8 @@ void main(void)
paleta_inicjuj();
save_pal();
w_inicjuj_sincos();
randomize();

srand(time(NULL));

sb_dsp_out(ON_SPEAKER);
enable_dma_int();
Expand Down
3 changes: 2 additions & 1 deletion results.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

#include "globals.h"

Expand Down Expand Up @@ -147,7 +148,7 @@ void analiza_wynikow(int punkty)
zmien_rekordy(punkty);
drukuj_liste();

play_sound(&soundtab[random(SND_EXPLOSION)]);
play_sound(&soundtab[rand() % SND_EXPLOSION]);
flash();

while (1) {
Expand Down
63 changes: 1 addition & 62 deletions sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,8 @@
(C) 2001, 2023 M. Feliks
*****************************************/

#include <dos.h>
#include <stdio.h>
#include <stdlib.h>

#include "globals.h"

#define SB_BASE_ADDRESS 0x220
#define DSP_OUT 0x10

#define DMA_CHANNEL 0x01
#define DMA_PAGE_PORT 0x83
#define DMA_OFFSET_PORT 0x02
#define DMA_LENGHT_PORT 0x03
#define DMA_MODE 0x48
#define DMA_INT 0x0d

#define WAV_HEADER_SIZE 44
#define SOUND_FREQUENCY 11025

void interrupt (*old_dma_int)(void);
unsigned char end_of_sound = 1;

int num_of_loaded_sounds = 0;


int sb_init(void)
{
return 1;
Expand Down Expand Up @@ -71,56 +48,18 @@ void play_sound(SOUND* s)

unsigned get_file_size(char* filename)
{
FILE* p;
unsigned size = 0;

if ((p = fopen(filename, "r+b")) == NULL)
return NULL;

while (!feof(p)) {
fgetc(p);
size++;
}

fclose(p);
return size;
return 0;
}

int load_sound(SOUND* s, char* filename)
{
FILE* p;
unsigned i;

if ((s->lenght = get_file_size(filename)) == NULL) {
strcpy(missed_file, filename);
return NULL;
}

//s->lenght-=WAV_HEADER_SIZE;

if ((s->buffer = (unsigned char*)malloc(s->lenght)) == NULL)
return NULL;

p = fopen(filename, "r+b");

//fseek(p,WAV_HEADER_SIZE,SEEK_SET);
fgets(s->buffer, s->lenght, p);

fclose(p);

num_of_loaded_sounds++;
return 1;
}

void unload_sound(SOUND* s)
{
free(s->buffer);
}

void unload_sounds(void)
{
int i;

for (i = 0; i < num_of_loaded_sounds; i++)
unload_sound(&soundtab[i]);
}
6 changes: 3 additions & 3 deletions stars.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void g_inicjuj(void)
for (i = 0; i < 50; i++) {
g = &gwiazda[i];

g->x = random(320);
g->y = random(200);
g->x = rand() % 320;
g->y = rand() % 200;

if (i < 10) {
g->v = 0;
Expand Down Expand Up @@ -73,7 +73,7 @@ void gwiazdy(void)
g->y++;
}
if (g->y > 199) {
g->x = random(320);
g->x = rand() % 320;
g->y = 0;
}
}
Expand Down

0 comments on commit 5101d04

Please sign in to comment.