zbyti Posted February 29, 2020 Share Posted February 29, 2020 (edited) program MonteCarloPi; uses crt; {$define FAST} {$f $70} var rtClock1 : byte absolute 19; rtClock2 : byte absolute 20; rndNumber : byte absolute $D20A; {$ifdef FAST} stop : word absolute $e0; i : word absolute $e0; r : word absolute $e2; x : word absolute $e4; y : word absolute $e6; bingo : word absolute $e8; probe : word absolute $ea; foundPi : word absolute $ec; n : byte absolute $ee; {$else} stop, i, r, x, y : word; bingo, probe, foundPi : word; n : byte; {$endif} begin bingo := 0; r := 127 * 127; probe := 10000; Pause; rtClock1 := 0; rtClock2 := 0; for i := 0 to probe do begin n := (rndNumber or %10000000) xor %10000000; x := n * n; n := (rndNumber or %10000000) xor %10000000; y := n * n; if (x + y) <= r then Inc(bingo); end; foundPi := 4 * bingo; stop := (rtClock1 * 256) + rtClock2; {$ifdef FAST} WriteLn('Variables on zero page'); {$endif} WriteLn('Probe size ', probe); WriteLn('Points in circle ', bingo); Write('Found pi approximation ', foundPi); WriteLn(chr(30),chr(30),chr(30),chr(30),chr(255),chr(44)); WriteLn('Frames counter = ', stop); ReadKey; end. PROBE=10000:B=0:R=127*127:F=PEEK(20) WHILE F=PEEK(20) WEND POKE 20,0:POKE 19,0 FOR I=0 TO PROBE N=PEEK($D20A):N=N!128:N=N EXOR 128 X=N*N N=PEEK($D20A):N=N!128:N=N EXOR 128 Y=N*N IF (X+Y)<=R THEN INC B NEXT I P=4*B T=TIME ? P;CHR$(30);CHR$(30);CHR$(30);CHR$(30);CHR$(255);CHR$(46) ? T;" FRAMES" YoshPlus&Pi - Benchmarks.ods monte-carlo-pi-sources.zip Edited March 1, 2020 by zbyti sources Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 2, 2020 Share Posted March 2, 2020 (edited) #include <stdio.h> void main(void) { register unsigned int stop, i, x, y; register unsigned int b, p, r; register unsigned char n; register unsigned char* rndp = 0xd20a; register unsigned char* tick = 0x14; register unsigned char* tack = 0x13; b = 0; r = 127 * 127; p = 10000; n = *tick; while (*tick == n) { ; } printf("\nMonte-Carlo PI cc65 V2.18\n"); asm(" lda #0"); asm(" sta $13"); asm(" sta $14"); for (i = 0 ; i < p; ++i) { n = (*rndp | 128) ^ 128; x = n * n; n = (*rndp | 128) ^ 128; y = n * n; if ((x + y) <= r) ++b; } b = 4 * b; stop = *tick + (*tack * 256); printf("%d%c%c%c%c%c%c\n", b, 30, 30, 30, 30, 255, 46); printf("%d ticks\n", stop); infinite: goto infinite; } cl65 -t atari -o mcpi.xex mcpi.c 602 ticks cl65 -t atari -Osir -Cl -o mcpi.xex mcpi.c 303 ticks YoshPlus&Pi - Benchmarks.ods Edited March 2, 2020 by zbyti Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 2, 2020 Share Posted March 2, 2020 (edited) Mad Pascal 1.6.4 updated to 01.03.2020 master. Edited March 2, 2020 by zbyti Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 2, 2020 Share Posted March 2, 2020 (edited) #include <stdio.h> #include <peekpoke.h> #define p 10000 #define r 16129 #define tick (PEEK(0x14)) #define tack (PEEK(0x13) * 256) #define rndp (PEEK(0xd20a)) void main(void) { register unsigned int stop, i, x, y; register unsigned int b = 0; register unsigned char n; n = tick; while (tick == n) { ; } printf("\nMonte-Carlo PI cc65 V2.18\n"); asm(" lda #0"); asm(" sta $13"); asm(" sta $14"); for (i = 0 ; i < p; ++i) { n = (rndp | 128) ^ 128; x = n * n; n = (rndp | 128) ^ 128; y = n * n; if ((x + y) <= r) ++b; } b *= 4; stop = tick + tack; printf("%d%c%c%c%c%c%c\n", b, 30, 30, 30, 30, 255, 46); printf("%d ticks\n", stop); infinite: goto infinite; } Edited March 2, 2020 by zbyti add macros Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted March 2, 2020 Share Posted March 2, 2020 n = (rndp | 128) ^ 128 This is producing: lda $D20A ora #$80 eor #$80 is that not the same as: n = rndp & 127 either of the optimizer flags doesn't detect and replace this? 1 Quote Link to comment Share on other sites More sharing options...
drac030 Posted March 2, 2020 Share Posted March 2, 2020 Also, does not CC65 support such use of pointers as: n = *(unsigned char *)0xd20a & 0x7f; or (instead of the asm snippet): *(int *)0x13 = 0; Also, this: infinite: goto infinite; would be better said as something like that: for(;;) ; (although it in no way affects performance, of course). 2 Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 2, 2020 Share Posted March 2, 2020 @Wrathchild no, it's not the same. @drac030 thx :] #include <stdio.h> #define p 10000 #define r 16129 #define RTCLOK1 (*(volatile unsigned char*)0x13) #define RTCLOK2 (*(volatile unsigned char*)0x14) #define RANDOM (*(volatile unsigned char*)0xd20a) void main(void) { register unsigned int stop, i, x, y; register unsigned int b = 0; register unsigned char n; n = RTCLOK2; while (RTCLOK2 == n) { ; } printf("\nMonte-Carlo PI cc65 V2.18\n"); RTCLOK1 = 0; RTCLOK2 = 0; for (i = 0 ; i < p; ++i) { n = (RANDOM | 128) ^ 128; x = n * n; n = (RANDOM | 128) ^ 128; y = n * n; if ((x + y) <= r) ++b; } b *= 4; stop = RTCLOK2 + 256 * RTCLOK1; printf("%u\x1e\x1e\x1e\x1e\xff.\n%u ticks\n", b, stop); for (;;); } Quote Link to comment Share on other sites More sharing options...
bocianu Posted March 3, 2020 Share Posted March 3, 2020 I'm pretty sure that: n = (rndp | 128) ^ 128 is equivalent of: n = rndp & 127 and it's quicker. Try and compare results 1 Quote Link to comment Share on other sites More sharing options...
drac030 Posted March 3, 2020 Share Posted March 3, 2020 (edited) Yes, I see no difference either: n is unsigned char, so random | 128 ^ 128 = LDA RANDOM / ORA #$80 / EOR #$80 which effectively, when bit 7 is set, sets it again, and inverts (clears) it later; and when it is clear - first sets it and inverts (clears) later. So it is AND #$7F = &0x7F (as said already above). Edited March 3, 2020 by drac030 typos, many typos Quote Link to comment Share on other sites More sharing options...
dmsc Posted March 3, 2020 Share Posted March 3, 2020 Hi! 3 hours ago, zbyti said: @Wrathchild no, it's not the same. @drac030 thx :] A little more "idiomatic" C : #include <stdio.h> #include <atari.h> #pragma static-locals(on) #define p 10000 #define r 16129 void main(void) { register unsigned int x, y; unsigned int stop, i, b = 0; register unsigned char n; n = OS.rtclok[2]; while (OS.rtclok[2] == n) { ; } printf("\nMonte-Carlo PI cc65 V2.18\n"); OS.rtclok[1] = 0; OS.rtclok[2] = 0; for (i = 0 ; i < p; ++i) { n = (POKEY_READ.random | 128) ^ 128; x = n * n; n = (POKEY_READ.random | 128) ^ 128; y = n * n; if ((x + y) <= r) ++b; } b *= 4; stop = OS.rtclok[2] + 256 * OS.rtclok[1]; printf("%u.%04u\n%u ticks\n", b/10000,b%10000, stop); for (;;); } Also, writing (n = POKEY_READ.random & 0x7F) would be a little faster. Have Fun! 1 Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 3, 2020 Share Posted March 3, 2020 (edited) @dmsc very nice! thx :] I wrote Monte-Carlo PI as benchmark this way to make it easier for me to transfer code to other programming languages. Edited March 3, 2020 by zbyti Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 3, 2020 Share Posted March 3, 2020 (edited) @Wrathchild & @bocianu & @drac030 shame on me of course you are right. Edited March 3, 2020 by zbyti rnd & 127 Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted March 3, 2020 Share Posted March 3, 2020 @zbyti no worries POKEY's random number generator should in no way be seen as a good candidate for use in a Monte Carlo simulation 1 Quote Link to comment Share on other sites More sharing options...
zbyti Posted March 3, 2020 Share Posted March 3, 2020 (edited) 47 minutes ago, Wrathchild said: @zbyti no worries POKEY's random number generator should in no way be seen as a good candidate for use in a Monte Carlo simulation It's true, but SID it's no better //cl65 -t c64 -Osir -Cl -o mcpi.prg mcpi-c64.c #include <stdio.h> #define p 10000 #define r 16129 #define RTCLOK1 (*(volatile unsigned char*)0xa1) #define RTCLOK2 (*(volatile unsigned char*)0xa2) #define RANDOM (*(volatile unsigned char*)0xd41b) void main(void) { register unsigned int stop, i, x, y; register unsigned int b = 0; register unsigned char n; //SID's Random Number Generator asm(" lda #$ff"); //maximum frequency value asm(" sta $D40E"); //voice 3 frequency low byte asm(" sta $D40F"); //voice 3 frequency high byte asm(" lda #$80"); //noise waveform, gate bit off asm(" sta $D412"); //voice 3 control register n = RTCLOK2; while (RTCLOK2 == n) { ; } printf("\nMonte-Carlo PI cc65 V2.18\n"); RTCLOK1 = 0; RTCLOK2 = 0; for (i = 0 ; i < p; ++i) { n = RANDOM & 127; x = n * n; n = RANDOM & 127; y = n * n; if ((x + y) <= r) ++b; } b *= 4; stop = RTCLOK2 + 256 * RTCLOK1; printf("%u.%04u\n%u ticks\n", b/p,b%p, stop); for (;;); } Edited March 3, 2020 by zbyti Quote Link to comment Share on other sites More sharing options...
tebe Posted March 7, 2020 Author Share Posted March 7, 2020 MP Instruction in English by Uwo Oertel, thx http://mads.atari8.info/doc/madpascal_en.html 4 3 Quote Link to comment Share on other sites More sharing options...
stepho Posted March 12, 2020 Share Posted March 12, 2020 On 3/3/2020 at 8:53 AM, bocianu said: n = (rndp | 128) ^ 128 When I want to turn bit 7 off I usually write it as: n = rndp & ~(1<<7) Turning it on is like: n = rndp | (1<<7) And testing it is like: if( rndp & (1<<7) != 0 ) the != 0 is not strictly necessary. Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted March 12, 2020 Share Posted March 12, 2020 12 hours ago, stepho said: n = rndp | (1<<7) Thankfully compilers are intelligent enough to pre-calc the constant math, even without the optimiser enabled lda $D20A ora #$80 Quote Link to comment Share on other sites More sharing options...
jvas Posted March 22, 2020 Share Posted March 22, 2020 Hi, Can somebody tell me what is missing? I'm trying to set pixels, but nothing happens on screen (just a black/blank one). Thanks in advance! Cheers, Jozsi test1.pas Quote Link to comment Share on other sites More sharing options...
tebe Posted March 27, 2020 Author Share Posted March 27, 2020 current color palette is clear SetRGBPalette(0); // set index to 0 SetRGBPalette(0,0,0); // palette[0] = rgb(0,0,0) SetRGBPalette(100,100,100); // palette[1] = rgb(100,100,100) test_vbxe.zip 2 Quote Link to comment Share on other sites More sharing options...
+Stephen Posted March 27, 2020 Share Posted March 27, 2020 42 minutes ago, tebe said: current color palette is clear SetRGBPalette(0); // set index to 0 SetRGBPalette(0,0,0); // palette[0] = rgb(0,0,0) SetRGBPalette(100,100,100); // palette[1] = rgb(100,100,100) test_vbxe.zip 2.01 kB · 0 downloads Is there a way to determine which of the 4 palettes is being used? Quote Link to comment Share on other sites More sharing options...
tebe Posted March 27, 2020 Author Share Posted March 27, 2020 default = 1 Quote Link to comment Share on other sites More sharing options...
Tickled_Pink Posted April 10, 2020 Share Posted April 10, 2020 On 2/25/2020 at 10:17 AM, zbyti said: Here are my tests on atari800 PAL :] Sources mostly included Programming languages in the latest official version for February 20, 2020. A8-Benchmarks.zip 59.57 kB · 5 downloads For me, the most interesting thing about this was just how slow PL65 was. It was my language of choice. Still have my original disk here somewhere. I suspect that the problem was that it constantly jumped to its runtime library which, IIRC, was quite large and clearly not very well optimised. Quote Link to comment Share on other sites More sharing options...
+DjayBee Posted April 10, 2020 Share Posted April 10, 2020 2 hours ago, Tickled_Pink said: Still have my original disk here somewhere. If you find it and know someone with the right equipment, then please have it dumped. PL65 is not yet available as a preservation dump. I know of only one .PRO-file here on AtariAge at all. Quote Link to comment Share on other sites More sharing options...
Tickled_Pink Posted April 10, 2020 Share Posted April 10, 2020 2 hours ago, DjayBee said: If you find it and know someone with the right equipment, then please have it dumped. PL65 is not yet available as a preservation dump. I know of only one .PRO-file here on AtariAge at all. Yeah. That was probably the one I originally dumped when I had an APE interface. I'm not sure how to dump it properly into a standard XEX file. Quote Link to comment Share on other sites More sharing options...
tebe Posted April 13, 2020 Author Share Posted April 13, 2020 https://github.com/tebe6502/Mad-Pascal chessboard 70 ticks romsum 73-79 ticks sieve 607 ticks mp_bench.7z 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.