Skip to content

Commit 5101d04

Browse files
author
Mikolaj Feliks
committed
Make code more portable
1 parent 930cc09 commit 5101d04

File tree

10 files changed

+43
-89
lines changed

10 files changed

+43
-89
lines changed

bonus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void b_nadaj0(STATEK* bon)
1919
void bonus_inicjuj(STATEK* bon)
2020
{
2121
int i, j = 36;
22-
bon->x = random(299);
22+
bon->x = rand() % 299;
2323
bon->y = 0;
2424
bon->licznik = 0;
2525
for (i = 0; i < 6; i++)

bullets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void p_nadaj0(void)
113113
void p_kontrola_kaps(POCISK* poc, KAPSULA* kaps, POLE* ple)
114114
{
115115
if (poc->x > kaps->x && poc->x < kaps->x + 19 && poc->y > kaps->y && poc->y < kaps->y + 19 && !kaps->trafiona && !ple->aktywne) {
116-
play_sound(&soundtab[random(SND_EXPLOSION)]);
116+
play_sound(&soundtab[rand() % SND_EXPLOSION]);
117117

118118
kaps->giwera--;
119119
kaps->trafiona = 1;
@@ -136,7 +136,7 @@ void p_kontrola_stat(POCISK* poc, STATEK* sta, KAPSULA* kaps)
136136
kaps->licznik++;
137137
ile_aktywnych--;
138138

139-
play_sound(&soundtab[random(SND_EXPLOSION)]);
139+
play_sound(&soundtab[rand() % SND_EXPLOSION]);
140140
}
141141
}
142142

control.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*****************************************/
88

99
#include <dos.h>
10+
#include <string.h>
1011

1112
#include "globals.h"
1213

enemies.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,44 @@
1313
void stat_inicjuj(STATEK* sta, KAPSULA* kaps)
1414
{
1515
int i, j;
16-
if (!random(2))
17-
sta->x = random(30);
18-
else
19-
sta->x = random(30) + 269;
20-
sta->y = random(79);
16+
17+
if ((rand() % 2) == 0) {
18+
sta->x = rand() % 30;
19+
}
20+
else {
21+
sta->x = (rand() % 30) + 269;
22+
}
23+
sta->y = rand() % 79;
24+
2125
sta->zm_x = 0;
2226
sta->zm_y = 0;
2327
sta->aktywny = 1;
24-
sta->xs_min = random(319);
25-
sta->xs_max = sta->xs_min + random(319 - sta->xs_min);
26-
for (i = 0; i < 3; i++)
27-
sta->poc_x[i] = random(319);
28+
29+
sta->xs_min = rand() % 319;
30+
sta->xs_max = sta->xs_min + rand() % (319 - sta->xs_min);
31+
32+
for (i = 0; i < 3; i++) {
33+
sta->poc_x[i] = rand() % 319;
34+
}
35+
2836
sta->licznik = 0;
2937
sta->k = 0;
3038
sta->laser_pom = 0;
3139
if (kaps->punkty < 20)
3240
sta->giwera = 0;
3341
else if (kaps->punkty >= 20 && kaps->punkty < 40)
34-
sta->giwera = random(2);
42+
sta->giwera = rand() % 2;
3543
else if (kaps->punkty >= 40 && kaps->punkty < 60)
36-
sta->giwera = random(3);
44+
sta->giwera = rand() % 3;
3745
else if (kaps->punkty >= 60 && kaps->punkty < 80)
38-
sta->giwera = random(4);
46+
sta->giwera = rand() % 4;
3947
else if (kaps->punkty >= 80 && kaps->punkty < 100)
40-
sta->giwera = random(5);
48+
sta->giwera = rand() % 5;
4149
else
42-
sta->giwera = random(6);
50+
sta->giwera = rand() % 6;
4351
if (sta->giwera != 5) {
44-
sta->ruch = random(2);
45-
sta->v = random(2);
52+
sta->ruch = rand() % 2;
53+
sta->v = rand() % 2;
4654
} else {
4755
sta->ruch = 2;
4856
sta->v = 1;
@@ -209,8 +217,8 @@ void stat_ruch2(STATEK* statek)
209217
}
210218
}
211219
if (!statek->zm_x && !statek->zm_y) {
212-
statek->kx = random(299);
213-
statek->ky = random(100);
220+
statek->kx = rand() % 299;
221+
statek->ky = rand() % 100;
214222
statek->zm_x = 1;
215223
statek->zm_y = 1;
216224
}

font.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
(C) 2001, 2023 M. Feliks
77
*****************************************/
88

9+
#include <string.h>
10+
911
#include "globals.h"
1012

1113
unsigned char chardata[];
1214

15+
1316
void init_font(void)
1417
{
1518
}

intro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void intro(void)
9393
timer_wait();
9494
}
9595

96-
play_sound(&soundtab[random(SND_EXPLOSION)]);
96+
play_sound(&soundtab[rand() % SND_EXPLOSION]);
9797
flash();
9898

9999
while (1) {

main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <conio.h>
1010
#include <stdio.h>
1111
#include <stdlib.h>
12+
#include <time.h>
1213
#include <string.h>
1314

1415
#include "globals.h"
@@ -55,7 +56,8 @@ void main(void)
5556
paleta_inicjuj();
5657
save_pal();
5758
w_inicjuj_sincos();
58-
randomize();
59+
60+
srand(time(NULL));
5961

6062
sb_dsp_out(ON_SPEAKER);
6163
enable_dma_int();

results.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdio.h>
1010
#include <stdlib.h>
1111
#include <string.h>
12+
#include <conio.h>
1213

1314
#include "globals.h"
1415

@@ -147,7 +148,7 @@ void analiza_wynikow(int punkty)
147148
zmien_rekordy(punkty);
148149
drukuj_liste();
149150

150-
play_sound(&soundtab[random(SND_EXPLOSION)]);
151+
play_sound(&soundtab[rand() % SND_EXPLOSION]);
151152
flash();
152153

153154
while (1) {

sound.c

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,8 @@
66
(C) 2001, 2023 M. Feliks
77
*****************************************/
88

9-
#include <dos.h>
10-
#include <stdio.h>
11-
#include <stdlib.h>
12-
139
#include "globals.h"
1410

15-
#define SB_BASE_ADDRESS 0x220
16-
#define DSP_OUT 0x10
17-
18-
#define DMA_CHANNEL 0x01
19-
#define DMA_PAGE_PORT 0x83
20-
#define DMA_OFFSET_PORT 0x02
21-
#define DMA_LENGHT_PORT 0x03
22-
#define DMA_MODE 0x48
23-
#define DMA_INT 0x0d
24-
25-
#define WAV_HEADER_SIZE 44
26-
#define SOUND_FREQUENCY 11025
27-
28-
void interrupt (*old_dma_int)(void);
29-
unsigned char end_of_sound = 1;
30-
31-
int num_of_loaded_sounds = 0;
32-
33-
3411
int sb_init(void)
3512
{
3613
return 1;
@@ -71,56 +48,18 @@ void play_sound(SOUND* s)
7148

7249
unsigned get_file_size(char* filename)
7350
{
74-
FILE* p;
75-
unsigned size = 0;
76-
77-
if ((p = fopen(filename, "r+b")) == NULL)
78-
return NULL;
79-
80-
while (!feof(p)) {
81-
fgetc(p);
82-
size++;
83-
}
84-
85-
fclose(p);
86-
return size;
51+
return 0;
8752
}
8853

8954
int load_sound(SOUND* s, char* filename)
9055
{
91-
FILE* p;
92-
unsigned i;
93-
94-
if ((s->lenght = get_file_size(filename)) == NULL) {
95-
strcpy(missed_file, filename);
96-
return NULL;
97-
}
98-
99-
//s->lenght-=WAV_HEADER_SIZE;
100-
101-
if ((s->buffer = (unsigned char*)malloc(s->lenght)) == NULL)
102-
return NULL;
103-
104-
p = fopen(filename, "r+b");
105-
106-
//fseek(p,WAV_HEADER_SIZE,SEEK_SET);
107-
fgets(s->buffer, s->lenght, p);
108-
109-
fclose(p);
110-
111-
num_of_loaded_sounds++;
11256
return 1;
11357
}
11458

11559
void unload_sound(SOUND* s)
11660
{
117-
free(s->buffer);
11861
}
11962

12063
void unload_sounds(void)
12164
{
122-
int i;
123-
124-
for (i = 0; i < num_of_loaded_sounds; i++)
125-
unload_sound(&soundtab[i]);
12665
}

stars.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void g_inicjuj(void)
3030
for (i = 0; i < 50; i++) {
3131
g = &gwiazda[i];
3232

33-
g->x = random(320);
34-
g->y = random(200);
33+
g->x = rand() % 320;
34+
g->y = rand() % 200;
3535

3636
if (i < 10) {
3737
g->v = 0;
@@ -73,7 +73,7 @@ void gwiazdy(void)
7373
g->y++;
7474
}
7575
if (g->y > 199) {
76-
g->x = random(320);
76+
g->x = rand() % 320;
7777
g->y = 0;
7878
}
7979
}

0 commit comments

Comments
 (0)