Jeśli chcesz wziąć udział w dyskusjach na forum - zaloguj się. Jeżeli nie masz loginu - poproś o członkostwo.
Vanilla 1.1.4 jest produktem Lussumo. Więcej informacji: Dokumentacja, Forum.
procedure Pause; assembler; overload;
(*
@description:
Delay program execution (1/50 second).
*)
asm
{ lda:cmp:req :rtclok+2
};
end;
lda:cmp:req 20 -> lda 20
-> wait cmp 20
-> beq wait
program Pause;
uses crt;
var rtClock : byte absolute 20;
var frame : byte absolute $e0;
var counter : word absolute $e2;
begin
counter := 0;
frame := rtClock;
while frame = rtClock do Inc(counter);
rtClock := 0;
WriteLn('Counter: ', counter);
ReadKey;
end.
program YoshBenchPlus;
uses crt;
{$define FAST}
{$ifdef FAST}
var i : word absolute $e0;
var a : word absolute $e2;
var b : word absolute $e4;
{$else}
var i : word;
var a : word;
var b : word;
{$endif}
var rtClock : byte absolute 20;
begin
i:=0;a:=0;b:=0;
Pause;
rtClock := 0;
while rtClock < 100 do begin
Inc(a); b := a;
Inc(b); a := b;
Inc(i);
end;
WriteLn('YoshPlus - iterations in 100 frames.');
{$ifdef FAST}
Writeln('Mad Pascal 1.6.4 opt');
{$else}
Writeln('Mad Pascal 1.6.4');
{$endif}
Writeln('Counter = ', i);
ReadKey;
end.
10 A=0:B=0:I=0:F=PEEK(20)
20 IF F=PEEK(20) THEN 20
30 POKE 20,0
40 IF PEEK(20)=100 THEN 100
50 A=A+1:B=A:B=B+1:A=B:I=I+1
60 GOTO 40
100 ? "YOSHPLUS - INTERATIONS IN 100 FRAMES."
110 ? "ATARI BASIC. STANDARD OS."
120 ? "COUNTER = ";I
program MonteCarloPi;
uses crt;
var
rtClock1 : byte absolute 19;
rtClock2 : byte absolute 20;
rndNumber : byte absolute $D20A;
stop, x, y, i, r : word;
bingo, probe : word;
foundPi : real;
begin
bingo := 0;
r := 255 * 255;
probe := 65535;
repeat until rndNumber <> 0;
Pause;
rtClock1 := 0; rtClock2 := 0;
for i := 0 to probe do begin
x := rndNumber; x := x * x;
y := rndNumber; y := y * y;
if (x + y) <= r then Inc(bingo);
end;
foundPi := 4 * (bingo / probe);
stop := (rtClock1 * 256) + rtClock2;
WriteLn('Probe size ', probe);
WriteLn('Points in circle ', bingo);
WriteLn('Found pi approximation ', foundPi);
WriteLn('Frames counter = ', stop);
ReadKey;
end.
RandG Return gaussian distributed random number
RandomRange
RandomRangeF
program MonteCarloPi;
var
i, bingo, probe : cardinal;
r, x, y : word;
foundPi : real;
begin
Randomize;
bingo := 0;
r := 255 * 255;
probe := 1000000;
for i := 0 to probe do begin
x := Random(256); x := x * x;
y := Random(256); y := y * y;
if (x + y) <= r then Inc(bingo);
end;
foundPi := 4 * (bingo / probe);
WriteLn('Probe size ', probe);
WriteLn('Points in circle ', bingo);
WriteLn('Found pi approximation ', foundPi);
end.
Probe size 1000000
Points in circle 783651
Found pi approximation 3.1346039999999999E+000
------------------
(program exited with code: 0)
Press return to continue
Probe size 400000000
Points in circle 313248037
Found pi approximation 3.1324803700000001E+000
------------------
(program exited with code: 0)
Press return to continue
program real_vs_integer;
uses crt, sysutils;
const DNI = 30;
MIES = 6;
ILOSC = DNI * MIES;
var miesiac, dzien: byte;
czas1, czas2: cardinal;
function INT_LiczDzienJulianski(rok: word; miesiac, dzien: byte): cardinal;
var a: word;
begin
a := 4716 + rok + ((miesiac + 9) div 12);
result := 367 * rok + 1729317 + dzien -
((a * 7) div 4) - (3 * (((a + 83) div 100) + 1) div 4) + ((275 * miesiac) div 9);
end;
function REAL_LiczDzienJulianski(rok: word; miesiac, dzien: byte): real;
var a, b: real;
begin
a := 4716.0 + real(rok) + Int((real(miesiac) + 9.0) / 12.0);
b := 1729279.5 + 367.0 * real(rok) + Int(275.0 * real(miesiac) / 9.0) - Int(7.0 * a / 4.0) + real(dzien);
result := b + 38.0 - Int(3.0 * (Int((a + 83.0) / 100.0) + 1.0) / 4.0);
end;
begin
Writeln(ILOSC, ' wywolan dla typu REAL');
czas1 := GetTickCount;
for miesiac := 1 to MIES do begin
for dzien := 1 to DNI do begin
REAL_LiczDzienJulianski(2017, miesiac, dzien);
Write('.');
end;
Writeln;
end;
czas1 := GetTickCount - czas1;
Writeln('czas wykonania: ', czas1, ' ramek');
Writeln;
Writeln(ILOSC, ' wywolan dla typu INTEGER');
czas2 := GetTickCount;
for miesiac := 1 to MIES do begin
for dzien := 1 to DNI do begin
INT_LiczDzienJulianski(2017, miesiac, dzien);
Write('.');
end;
Writeln;
end;
czas2 := GetTickCount - czas2;
Writeln('czas wykonania: ', czas2, ' ramek');
Writeln;
Writeln('okolo ', real(czas1) / real(czas2) ,' razy szybciej');
ReadKey;
end.
program MonteCarloPi;
uses crt;
var
rtClock1 : byte absolute 19;
rtClock2 : byte absolute 20;
rndNumber : byte absolute $D20A;
stop, i, r, x, y : word;
bingo, probe, foundPi : word;
begin
bingo := 0;
r := 255 * 255;
probe := 10000;
Pause;
rtClock1 := 0; rtClock2 := 0;
for i := 0 to probe do begin
x := rndNumber; x := x * x;
y := rndNumber; y := y * y;
if (x + y) <= r then Inc(bingo);
end;
foundPi := 4 * bingo;
stop := (rtClock1 * 256) + rtClock2;
WriteLn('Probe size ', probe);
WriteLn('Points in circle ', bingo);
WriteLn('Found pi approximation ', foundPi / probe);
WriteLn('Frames counter = ', stop);
ReadKey;
end.
jhusak:
bo będzie zależał od prędkości algorytmu mnożeniazbyti:
Przeprowadzę też test obliczania silni, bo wygląda na to, że procedury odpowiedzialne za mnożenie nie są jednolite i różnią się wydajnością w różnych językach.10 BINGO=0:PROBE=10000:R=255*255:RP=53770:F=PEEK(20)
20 IF F=PEEK(20) THEN 20
30 POKE 20,0:POKE 19,0
40 FOR I=0 TO PROBE
50 X=PEEK(RP):X=X*X:Y=PEEK(RP):Y=Y*Y
60 IF (X+Y)<=R THEN BINGO=BINGO+1
70 NEXT I
80 P=4*BINGO
90 T=PEEK(20)+256*PEEK(19)
100 ? P/PROBE;" COUNTED IN ";T;" FRAMES"
(* source: CLSN PASCAL *)
(* This program uses a mutually *)
(* recursive routine to calculate *)
(* the number PI *)
uses crt;
function a(t: byte): single; forward;
function b(n: byte): single;
begin
if (n=0) then
b:=1/sqrt(2)
else
b:=sqrt(a(n-1)*b(n-1));
end;
function a(t:byte): single;
begin
if (t=0) then
a:=1
else
a:=(a(t-1)+b(t-1))*0.5;
end;
function d(n: byte): single;
var
j: byte;
s: single;
begin
s:=0;
for j:=1 to n do
s:=s+(1 shl (j+1))*(sqr(a(j))-sqr(b(j)));
d:=1-s;
end;
function x_pi: single;
const
level=2;
begin
x_pi:=4*a(level)*b(level)/d(level);
end;
begin
writeln('PI=',x_pi);
repeat until keypressed;
end.
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;
{$else}
stop, i, r, x, y : word;
bingo, probe, foundPi : word;
{$endif}
begin
bingo := 0;
r := 255 * 255;
probe := 10000;
Pause;
rtClock1 := 0; rtClock2 := 0;
for i := 0 to probe do begin
x := rndNumber; x := x * x;
y := rndNumber; y := y * y;
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);
WriteLn('Found pi approximation ', foundPi / probe);
WriteLn('Frames counter = ', stop);
ReadKey;
end.
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.
10 PROBE=10000:BINGO=0:R=127*127:RP=53770:F=PEEK(20)
20 IF F=PEEK(20) THEN 20
30 POKE 20,0:POKE 19,0
40 FOR I=0 TO PROBE
50 N=PEEK(RP):N=N!128:N=N EXOR 128:X=N*N
55 N=PEEK(RP):N=N!128:N=N EXOR 128:Y=N*N
60 IF (X+Y)<=R THEN BINGO=BINGO+1
70 NEXT I
80 P=4*BINGO
90 T=PEEK(20)+256*PEEK(19)
100 ? P;CHR$(30);CHR$(30);CHR$(30);CHR$(30);CHR$(255);CHR$(46)
110 ? T;" FRAMES"
BYTE RTCLOCK2=20
BYTE RTCLOCK1=19
BYTE RNDPOKEY=$D20A
BYTE N
CARD BINGO,I,X,Y,P,T
CARD PROBE=[10000]
CARD RADIUS=[16129]
PROC main()
X=0 Y=0 BINGO=0
N=RTCLOCK2
WHILE N=RTCLOCK2 DO OD
RTCLOCK1=0 RTCLOCK2=0
FOR I=0 TO PROBE
DO
N=(RNDPOKEY % 128) ! 128
X=N*N
N=(RNDPOKEY % 128) ! 128
Y=N*N
IF (X+Y)<=RADIUS THEN BINGO==+1 FI
OD
P=4*BINGO
T=RTCLOCK2+(RTCLOCK1*256)
PRINTE("Mone-Carlo Pi in Action! 3.7P")
PRINT("Pi approximation = ") PRINTC(P)
PUT(30) PUT(30) PUT(30) PUT(30) PUT(255) PUT(46) PUTE()
PRINTF("Frames = %U%E",T)
RETURN
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"
Quick-Sourcetext
D2:PI.QIK
----------------
Length: $0233
Free : $7538
----------------
BYTE
[
RTC1=19
RTC2=20
RNDP=$D20A
N
]
WORD
[
B,I,X,Y,P,T,PR,RA,XY
]
ARRAY
[
FIELD(8)
]
MAIN
PR=10000
RA=16129
X=0
Y=0
B=0
I=0
N=RTC2
WHILE N=RTC2
WEND
RTC2=0
RTC1=0
WHILE I<PR
OR(RNDP,128,N)
EOR(N,128,N)
MULT(N,N,X)
OR(RNDP,128,N)
EOR(N,128,N)
MULT(N,N,Y)
ADD(X,Y,XY)
IF XY<=RA
ADD(B,1,B)
ENDIF
ADD(I,1,I)
WEND
MULT(4,B,P)
MULT(RTC1,256,T)
ADD(RTC2,T,T)
FIELD(0)=30
FIELD(1)=30
FIELD(2)=30
FIELD(3)=30
FIELD(4)=30
FIELD(5)=255
FIELD(6)=46
FIELD(7)=0
?("PI = ",P,FIELD)
?("FRAMES = ",T)
ENDMAIN
cl65 -t atari -o mcpi.xex mcpi.c 602 ticks
cl65 -t atari -Osir -Cl -o mcpi.xex mcpi.c 303 ticks
#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;
}
#include <stdio.h>
#include <peekpoke.h>
#define tick 0x14
#define tack 0x13
#define rndp 0xd20a
void main(void)
{
register unsigned int stop, i, x, y;
register unsigned int b, p, r;
register unsigned char n;
b = 0;
r = 127 * 127;
p = 10000;
n = PEEK(tick);
while (PEEK(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 = (PEEK(rndp) | 128) ^ 128;
x = n * n;
n = (PEEK(rndp) | 128) ^ 128;
y = n * n;
if ((x + y) <= r)
++b;
}
b = 4 * b;
stop = PEEK(tick) + (PEEK(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;
}