Skip to content

Commit d50b59c

Browse files
committed
made emulator use less cpu
1 parent e000f5b commit d50b59c

File tree

10 files changed

+33
-3
lines changed

10 files changed

+33
-3
lines changed

emu/cmd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ cli(FILE *in, Channel **c)
828828
void*
829829
cmdthread(void *p)
830830
{
831+
threadname("cli");
831832
cli(stdin, p);
832833
quit(0);
833834
return nil;

emu/dis340.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ renderthread(void *arg)
835835
SDL_Event ev;
836836
SDL_Texture *tex;
837837

838+
threadname("dis340");
839+
838840
dis = arg;
839841

840842
crtinit();
@@ -866,12 +868,15 @@ renderthread(void *arg)
866868
SDL_RenderClear(renderer);
867869

868870
render(dis->crt);
869-
// SDL_Delay(30);
870871

871872
SDL_UpdateTexture(tex, nil, dis->crt->pixels, 1024*sizeof(u32));
872873
SDL_RenderCopy(renderer, tex, nil, nil);
873874

874875
SDL_RenderPresent(renderer);
876+
877+
// probably not the best idea to do it like this,
878+
// should perhaps add a time delta to render instead
879+
SDL_Delay(30);
875880
}
876881
return nil;
877882
}

emu/emu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ simthread(void *p)
5656
{
5757
Task *t;
5858

59+
threadname("sim");
60+
5961
printf("[simthread] start\n");
6062
for(;;)
6163
for(t = tasks; t; t = t->next){

emu/init.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ mount ptr ../code/ptp.out
4848
#mount dx1 ../test/out.dt6
4949
#mount dx1 ../test/test.dt6
5050
mount dx1 ../files/sys6.dtr
51+
##mount dx1 ../system.dtr
5152
#mount dx2 ../test/stuff.dtr
5253
#mount dx2 ../test/spcwar.dtr
53-
mount dx2 ../test/foo.dtr
54+
#mount dx2 ../test/foo.dtr
55+
mount dx2 ../test/aap.dtr
5456

5557
#load -b ../maint/pdp6.part1

emu/main_panel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ void main340(void);
13361336
// SDL_UnlockSurface(screen);
13371337

13381338
SDL_RenderPresent(renderer);
1339+
SDL_Delay(30);
13391340
}
13401341
return 0;
13411342
}

emu/rtc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ rtcthread(void *p)
109109
RtcMsg msg;
110110
int loss;
111111

112+
threadname("rtc");
113+
114+
struct timespec slp = { 0, 1*1000*1000 }; // 1ms
112115
loss = 0;
113116
for(;;){
114117
clock_gettime(CLOCK_REALTIME, &now);
@@ -133,6 +136,9 @@ rtcthread(void *p)
133136
else
134137
rtcstop(msg.c);
135138
}
139+
140+
// make this thread sleep a bit
141+
nanosleep(&slp, nil);
136142
}
137143
}
138144

emu/threading.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define _GNU_SOURCE // TODO, make portable
12
#include "threading.h"
23
#include <assert.h>
34

@@ -208,6 +209,13 @@ threadwait(int id)
208209
pthread_join(gethandle(id), nil);
209210
}
210211

212+
void
213+
threadname(char *name)
214+
{
215+
// TODO: make portable
216+
pthread_setname_np(pthread_self(), name);
217+
}
218+
211219
int
212220
main(int argc, char *argv[])
213221
{

emu/threading.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ int threadid(void);
5858
void **threaddata(void);
5959
void threadkill(int id);
6060
void threadwait(int id);
61+
void threadname(char *name);

fe6/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ fe6_emu: $(SRC) 6/emu6.c
1818
$(CC) -I6 $(CFLAGS) $(LDFLAGS) -o $@ $^
1919

2020

21+
fe6_fastemu: $(SRC) fastemu.c ../femu/fpdp6.c
22+
$(CC) -I6 $(CFLAGS) $(LDFLAGS) -o $@ $^
23+
2124
feka: $(SRC) ka/real.c
2225
$(XX)gcc -Ika $(CFLAGS) $(LDFLAGS) -o $@ $^

fe6/fe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ threadmain(int argc, char *argv[])
619619
started = 0;
620620
}
621621
fe_svc();
622-
// usleep(1000);
622+
// this was commented out, why?
623+
usleep(1000);
623624
continue;
624625
}
625626

0 commit comments

Comments
 (0)