Skip to content

Commit d2640ba

Browse files
committed
COMMON: fix hash, code cleanup
1 parent 22c8844 commit d2640ba

File tree

7 files changed

+92
-82
lines changed

7 files changed

+92
-82
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
DIM r(256)
2+
DIM g(256)
3+
DIM b(256)
4+
LET f=0
5+
CLS
6+
7+
FOR x=0 TO 255
8+
LET r(x)=255-CEIL((SIN(PI*2*x/255)+1)*127)
9+
LET g(x)=CEIL((SIN(PI*2*x/127)+1)*64)
10+
LET b(x)=255-r(x)
11+
NEXT x
12+
13+
bw=xmax/3
14+
bh=ymax/3
15+
t1=timer
16+
17+
while 1
18+
t=TICKS
19+
FOR y=0 TO bh
20+
FOR x=0 TO bw
21+
LET c1=SIN(x/50+f+y/200)
22+
LET c2=SQR((SIN(0.8*f)*400-x+400)*(SIN(0.8*f)*400-x+400)+(COS(1.2*f)*240-y+240)*(COS(1.2*f)*240-y+240))
23+
LET c2=SIN(c2/50)
24+
LET c3=(c1+c2)/2
25+
LET res=(c3+1)*127
26+
27+
color RGB(r(res),g(res),b(res))
28+
pset x,y
29+
NEXT x
30+
NEXT y
31+
32+
fps=TICKSPERSEC/(TICKS-t)
33+
iter++
34+
at bw+10,0
35+
print format("Fps: ###.##", fps)
36+
at bw+10,20
37+
print format("Cnt: ###", iter)
38+
at bw+10,40
39+
print format("Elap: ###", timer-t1)
40+
41+
SHOWPAGE
42+
f += 0.1
43+
wend
44+

src/common/brun.c

Lines changed: 23 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ void code_pop_until(int type);
3434
void code_pop_and_free(stknode_t *node);
3535
stknode_t *code_stackpeek();
3636
void sys_before_comp();
37-
void sys_after_comp();
38-
void sys_before_run();
39-
void sys_after_run();
4037
int sbasic_exec_task(int tid);
4138
int sbasic_recursive_exec(int tid);
4239
void sbasic_exec_prepare(const char *filename);
@@ -45,7 +42,7 @@ int sbasic_main(const char *file);
4542
int exec_close(int tid);
4643
int sbasic_exec(const char *file);
4744
void cmd_options(void);
48-
var_t *code_resolve_varptr(var_t* var_p, int until_parens);
45+
var_t *code_resolve_varptr(var_t *var_p, int until_parens);
4946

5047
static dword evt_check_every;
5148
static char fileName[OS_FILENAME_SIZE + 1];
@@ -62,7 +59,7 @@ void code_jump_label(word label_id) {
6259
/**
6360
* Put the node 'node' in stack (PUSH)
6461
*/
65-
void code_push(stknode_t * node) {
62+
void code_push(stknode_t *node) {
6663
#if defined(_UnixOS) && defined(_CHECK_STACK)
6764
int i;
6865
#endif
@@ -88,7 +85,7 @@ void code_push(stknode_t * node) {
8885
/**
8986
* Returns and deletes the topmost node from stack (POP)
9087
*/
91-
void code_pop(stknode_t * node) {
88+
void code_pop(stknode_t *node) {
9289
#if defined(_UnixOS) && defined(_CHECK_STACK)
9390
int i;
9491
#endif
@@ -116,7 +113,7 @@ void code_pop(stknode_t * node) {
116113
/**
117114
* Returns and deletes the topmost node from stack (POP)
118115
*/
119-
void code_pop_and_free(stknode_t * node) {
116+
void code_pop_and_free(stknode_t *node) {
120117
#if defined(_UnixOS) && defined(_CHECK_STACK)
121118
int i;
122119
#endif
@@ -212,11 +209,14 @@ stknode_t *code_stackpeek() {
212209
/**
213210
* Convertion multi-dim index to one-dim index
214211
*/
215-
addr_t getarrayidx(var_t* array, var_t** var_hash_val) {
212+
addr_t getarrayidx(var_t *array, var_t **var_hash_val) {
213+
addr_t idx = 0;
214+
addr_t lev = 0;
215+
addr_t m = 0;
216216
byte code;
217217
var_t var;
218-
addr_t idx = 0, lev = 0, m = 0;
219-
addr_t idim, i;
218+
addr_t idim;
219+
addr_t i;
220220

221221
do {
222222
v_init(&var);
@@ -271,7 +271,7 @@ addr_t getarrayidx(var_t* array, var_t** var_hash_val) {
271271
/**
272272
* Used by code_getvarptr() to retrieve an element ptr of an array
273273
*/
274-
var_t *code_getvarptr_arridx(var_t* basevar_p) {
274+
var_t *code_getvarptr_arridx(var_t *basevar_p) {
275275
addr_t array_index;
276276
var_t *var_p = NULL;
277277

@@ -315,7 +315,7 @@ var_t *code_getvarptr_arridx(var_t* basevar_p) {
315315
/**
316316
* resolve a composite variable reference, eg: ar.ch(0).foo
317317
*/
318-
var_t* code_resolve_varptr(var_t* var_p, int until_parens) {
318+
var_t *code_resolve_varptr(var_t *var_p, int until_parens) {
319319
if (var_p) {
320320
switch (code_peek()) {
321321
case kwTYPE_LEVEL_BEGIN:
@@ -334,7 +334,7 @@ var_t* code_resolve_varptr(var_t* var_p, int until_parens) {
334334
/**
335335
* Used by code_isvar() to retrieve an element ptr of an array
336336
*/
337-
var_t *code_isvar_arridx(var_t * basevar_p) {
337+
var_t *code_isvar_arridx(var_t *basevar_p) {
338338
addr_t array_index;
339339
var_t *var_p = NULL;
340340

@@ -381,7 +381,8 @@ var_t *code_isvar_arridx(var_t * basevar_p) {
381381
* returns false
382382
*/
383383
int code_isvar() {
384-
var_t *basevar_p, *var_p = NULL;
384+
var_t *basevar_p;
385+
var_t *var_p = NULL;
385386
addr_t cur_ip;
386387

387388
cur_ip = prog_ip; // store IP
@@ -658,7 +659,6 @@ void cmd_chain(void) {
658659
// compile the buffer
659660
sys_before_comp();
660661
success = comp_compile_buffer(code);
661-
sys_after_comp();
662662

663663
v_free(&var);
664664
if (code_alloc) {
@@ -672,15 +672,13 @@ void cmd_chain(void) {
672672
}
673673

674674
tid_main = brun_create_task("CH_MAIN", bytecode_h, 0);
675-
sys_before_run();
676675

677676
dev_init(opt_graphics, 0);
678677
exec_sync_variables(0);
679678

680679
bc_loop(0);
681680
success = prog_error; // save tid_main status
682681

683-
sys_after_run();
684682
exec_close_task(); // cleanup task data - tid_main
685683
close_task(tid_main); // cleanup task container
686684
close_task(tid_base); // cleanup task container
@@ -977,15 +975,11 @@ void bc_loop(int isf) {
977975
pcode = code_getaddr();
978976
switch (pcode) {
979977
case kwCLS:
980-
// cdw-s 19/11/2004
981-
// dev_cls(); called in graph_reset()
982978
graph_reset();
983979
break;
984980
case kwRTE:
985981
cmd_RTE();
986982
break;
987-
// case kwSHELL:
988-
// break;
989983
case kwENVIRON:
990984
cmd_environ();
991985
break;
@@ -1230,20 +1224,12 @@ void bc_loop(int isf) {
12301224
IF_ERR_BREAK;
12311225
continue;
12321226

1233-
// //////////////
12341227
case kwLINE:
12351228
cmd_line();
12361229
break;
1237-
1238-
// third class
12391230
case kwCOLOR:
12401231
cmd_color();
12411232
break;
1242-
// case kwINTEGRAL:
1243-
// cmd_integral();
1244-
// break;
1245-
1246-
// --- at end ---
12471233
case kwOPEN:
12481234
cmd_fopen();
12491235
break;
@@ -1283,7 +1269,6 @@ void bc_loop(int isf) {
12831269
case kwTROFF:
12841270
trace_flag = 0;
12851271
continue;
1286-
12871272
case kwSTOP:
12881273
case kwEND:
12891274
if ((prog_length - 1) > prog_ip) {
@@ -1369,8 +1354,9 @@ void dump_stack() {
13691354
break;
13701355
}
13711356
}
1372-
} else
1357+
} else {
13731358
break;
1359+
}
13741360
} while (1);
13751361
}
13761362

@@ -1449,7 +1435,6 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) {
14491435
}
14501436

14511437
// create task
1452-
14531438
tid = create_task(fname); // create a task
14541439
activate_task(tid); // make it active
14551440
bytecode_h = bc_h;
@@ -1541,7 +1526,6 @@ int brun_create_task(const char *filename, mem_t preloaded_bc, int libf) {
15411526
prog_source = cp;
15421527
prog_ip = 0;
15431528

1544-
//
15451529
exec_setup_predefined_variables();
15461530

15471531
// init the keyboard map
@@ -1652,7 +1636,8 @@ int exec_close_task() {
16521636
// clean up - prog stack
16531637
while (prog_stack_count > 0) {
16541638
code_pop_and_free(&node);
1655-
}tmp_free(prog_stack);
1639+
}
1640+
tmp_free(prog_stack);
16561641
// clean up - variables
16571642
for (i = 0; i < (int) prog_varcount; i++) {
16581643
int j, shared;
@@ -1773,30 +1758,13 @@ void exec_sync_variables(int dir) {
17731758
void sys_before_comp() {
17741759
// setup prefered screen mode variables
17751760
if (dev_getenv("SBGRAF")) {
1776-
if (dev_getenv("SBGRAF"))
1761+
if (dev_getenv("SBGRAF")) {
17771762
comp_preproc_grmode(dev_getenv("SBGRAF"));
1763+
}
17781764
opt_graphics = 2;
17791765
}
17801766
}
17811767

1782-
/**
1783-
* system specific things - after compilation
1784-
*/
1785-
void sys_after_comp() {
1786-
}
1787-
1788-
/**
1789-
* system specific things - before execution
1790-
*/
1791-
void sys_before_run() {
1792-
}
1793-
1794-
/**
1795-
* system specific things - after execution
1796-
*/
1797-
void sys_after_run() {
1798-
}
1799-
18001768
/**
18011769
* execute the code on this task
18021770
*/
@@ -1868,7 +1836,7 @@ void sbasic_dump_taskinfo(FILE * output) {
18681836
/**
18691837
* dump-bytecode
18701838
*/
1871-
void sbasic_dump_bytecode(int tid, FILE * output) {
1839+
void sbasic_dump_bytecode(int tid, FILE *output) {
18721840
int i;
18731841
int prev_tid;
18741842

@@ -1941,7 +1909,6 @@ int sbasic_compile(const char *file) {
19411909
if (comp_rq) {
19421910
sys_before_comp(); // system specific preparations for compilation
19431911
success = comp_compile(file);
1944-
sys_after_comp(); // system specific things; after compilation
19451912
}
19461913
return success;
19471914
}
@@ -2005,7 +1972,6 @@ int sbasic_exec(const char *file) {
20051972
// load everything
20061973
sbasic_exec_prepare(file);
20071974

2008-
sys_before_run(); // system specific things; before run
20091975
dev_init(opt_graphics, 0); // initialize output device for graphics
20101976
evt_check_every = (50 * CLOCKS_PER_SEC) / 1000; // setup event checker time = 50ms
20111977
srand(clock()); // randomize
@@ -2020,8 +1986,6 @@ int sbasic_exec(const char *file) {
20201986

20211987
exec_close(exec_tid); // clean up executor's garbages
20221988
dev_restore(); // restore device
2023-
2024-
sys_after_run(); // system specific things; after run
20251989
}
20261990
// update IDE when it used as external
20271991
if (opt_ide == IDE_EXTERNAL) {
@@ -2040,7 +2004,7 @@ int sbasic_exec(const char *file) {
20402004
}
20412005
}
20422006

2043-
// cdw-s 22/11/2004 return as failure for compilation errors
2007+
// return compilation errors as failure
20442008
return !success ? 0 : !gsb_last_error;
20452009
}
20462010

src/common/fs_stream.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/*
3030
* open a file
3131
*/
32-
int stream_open(dev_file_t * f) {
32+
int stream_open(dev_file_t *f) {
3333
int osflags, osshare;
3434

3535
if (f->open_flags == DEV_FILE_OUTPUT) {
@@ -82,7 +82,7 @@ int stream_open(dev_file_t * f) {
8282
/*
8383
* close the stream
8484
*/
85-
int stream_close(dev_file_t * f) {
85+
int stream_close(dev_file_t *f) {
8686
int r;
8787

8888
r = close(f->handle);
@@ -95,7 +95,7 @@ int stream_close(dev_file_t * f) {
9595

9696
/*
9797
*/
98-
int stream_write(dev_file_t * f, byte * data, dword size) {
98+
int stream_write(dev_file_t *f, byte *data, dword size) {
9999
int r;
100100

101101
r = write(f->handle, data, size);
@@ -108,7 +108,7 @@ int stream_write(dev_file_t * f, byte * data, dword size) {
108108

109109
/*
110110
*/
111-
int stream_read(dev_file_t * f, byte * data, dword size) {
111+
int stream_read(dev_file_t *f, byte *data, dword size) {
112112
int r;
113113

114114
r = read(f->handle, data, size);
@@ -121,14 +121,14 @@ int stream_read(dev_file_t * f, byte * data, dword size) {
121121
/*
122122
* returns the current position
123123
*/
124-
dword stream_tell(dev_file_t * f) {
124+
dword stream_tell(dev_file_t *f) {
125125
return lseek(f->handle, 0, SEEK_CUR);
126126
}
127127

128128
/*
129129
* returns the file-length
130130
*/
131-
dword stream_length(dev_file_t * f) {
131+
dword stream_length(dev_file_t *f) {
132132
long pos, endpos;
133133

134134
pos = lseek(f->handle, 0, SEEK_CUR);
@@ -144,13 +144,13 @@ dword stream_length(dev_file_t * f) {
144144

145145
/*
146146
*/
147-
dword stream_seek(dev_file_t * f, dword offset) {
147+
dword stream_seek(dev_file_t *f, dword offset) {
148148
return lseek(f->handle, offset, SEEK_SET);
149149
}
150150

151151
/*
152152
*/
153-
int stream_eof(dev_file_t * f) {
153+
int stream_eof(dev_file_t *f) {
154154
long pos, endpos;
155155

156156
pos = lseek(f->handle, 0, SEEK_CUR);

0 commit comments

Comments
 (0)