Skip to content

Commit 3338d87

Browse files
committed
v1.0
1 parent 0d12470 commit 3338d87

File tree

6 files changed

+435
-0
lines changed

6 files changed

+435
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
build/
2+
*.o
3+
*.deb
4+
.DS_Store
5+
.idea
6+
*.prg
7+
*.PRG
8+
box16
9+
box16-icon56-24.png
10+
icons.png
11+
prog8compiler-*.jar
12+
x16emu

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 4800Pi
2+
3+
A major goal of this program is to have a small file size, even at the cost of
4+
code readability, maintainability, and reliability. Pull requests that decrease
5+
or keep the size the same will most likely be accepted, and pull requests that
6+
increase its size will most likely be rejected. It's really that simple!
7+
8+
This repository has only been made with Linux in mind, but nothing special is
9+
required in order to get a working build on Windows. The `sed` stuff in
10+
`buildrun.sh` is only for trimming the output size.
11+
12+
For more information, see https://javacakegames.itch.io/4800pi
13+
14+
## Recommended tools
15+
16+
* [Prog8](https://github.com/irmen/prog8) and its dependencies (see its README)
17+
* [Box16](https://github.com/indigodarkwolf/box16) emulator
18+
* [x16-emulator](https://github.com/X16Community/x16-emulator/releases) ROM

buildrun.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
java -jar prog8compiler-8.11-dev-all.jar -slowwarn -target cx16 pi.p8
4+
sed -i "/jsr cx16.init_system_phase2/d" pi.asm
5+
sed -i "/jmp cx16.cleanup_at_exit/d" pi.asm
6+
sed -ie "s/.word (+), 2023/.word (+), 0/" pi.asm
7+
sed -ie "s/, \$3a, \$8f, '\ prog8'//" pi.asm
8+
9+
sed -i "/src line:/d" pi.asm
10+
# I haven't been able to automatically get rid of rts the program's rts without
11+
# breaking everything, so it needs manually removing to save a byte for now.
12+
#sed -i "/; End/,/; variables/d" pi.asm
13+
sed -i "/; program startup initialization/,/; statements/d" pi.asm
14+
15+
64tass --ascii --case-sensitive --long-branch -Wall -Wno-strict-bool -Wno-shadow --no-monitor pi.asm --output 4800PI.PRG
16+
rm *.vice-mon-list *.prg
17+
./box16 -randram -scale 1 -nosound -warp 1 -prg PI.PRG # turbo!
18+
rm *.asm *.asme

expected.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
3.141592653589793238462643383279502884197169399375105820974944592307816406286208
2+
99862803482534211706798214808651328230664709384460955058223172535940812848111745
3+
02841027019385211055596446229489549303819644288109756659334461284756482337867831
4+
65271201909145648566923460348610454326648213393607260249141273724587006606315588
5+
17488152092096282925409171536436789259036001133053054882046652138414695194151160
6+
94330572703657595919530921861173819326117931051185480744623799627495673518857527
7+
24891227938183011949129833673362440656643086021394946395224737190702179860943702
8+
77053921717629317675238467481846766940513200056812714526356082778577134275778960
9+
91736371787214684409012249534301465495853710507922796892589235420199561121290219
10+
60864034418159813629774771309960518707211349999998372978049951059731732816096318
11+
59502445945534690830264252230825334468503526193118817101000313783875288658753320
12+
83814206171776691473035982534904287554687311595628638823537875937519577818577805
13+
32171226806613001927876611195909216420198938095257201065485863278865936153381827
14+
96823030195203530185296899577362259941389124972177528347913151557485724245415069
15+
59508295331168617278558890750983817546374649393192550604009277016711390098488240
16+
12858361603563707660104710181942955596198946767837449448255379774726847104047534
17+
64620804668425906949129331367702898915210475216205696602405803815019351125338243
18+
00355876402474964732639141992726042699227967823547816360093417216412199245863150
19+
30286182974555706749838505494588586926995690927210797509302955321165344987202755
20+
96023648066549911988183479775356636980742654252786255181841757467289097777279380
21+
00816470600161452491921732172147723501414419735685481613611573525521334757418494
22+
68438523323907394143334547762416862518983569485562099219222184272550254256887671
23+
79049460165346680498862723279178608578438382796797668145410095388378636095068006
24+
42251252051173929848960841284886269456042419652850222106611863067442786220391949
25+
45047123713786960956364371917287467764657573962413890865832645995813390478027590
26+
09946576407895126946839835259570982582262052248940772671947826848260147699090264
27+
01363944374553050682034962524517493996514314298091906592509372216964615157098583
28+
87410597885959772975498930161753928468138268683868942774155991855925245953959431
29+
04997252468084598727364469584865383673622262609912460805124388439045124413654976
30+
27807977156914359977001296160894416948685558484063534220722258284886481584560285
31+
06016842739452267467678895252138522549954666727823986456596116354886230577456498
32+
03559363456817432411251507606947945109659609402522887971089314566913686722874894
33+
05601015033086179286809208747609178249385890097149096759852613655497818931297848
34+
21682998948722658804857564014270477555132379641451523746234364542858444795265867
35+
82105114135473573952311342716610213596953623144295248493718711014576540359027993
36+
44037420073105785390621983874478084784896833214457138687519435064302184531910484
37+
81005370614680674919278191197939952061419663428754440643745123718192179998391015
38+
91956181467514269123974894090718649423196156794520809514655022523160388193014209
39+
37621378559566389377870830390697920773467221825625996615014215030680384477345492
40+
02605414665925201497442850732518666002132434088190710486331734649651453905796268
41+
56100550810665879699816357473638405257145910289706414011097120628043903975951567
42+
71577004203378699360072305587631763594218731251471205329281918261861258673215791
43+
98414848829164470609575270695722091756711672291098169091528017350671274858322287
44+
18352093539657251210835791513698820914442100675103346711031412671113699086585163
45+
98315019701651511685171437657618351556508849099898599823873455283316355076479185
46+
35893226185489632132933089857064204675259070915481416549859461637180270981994309
47+
92448895757128289059232332609729971208443357326548938239119325974636673058360414
48+
28138830320382490375898524374417029132765618093773444030707469211201913020330380
49+
19762110110044929321516084244485963766983895228684783123552658213144957685726243
50+
34418930396864262434107732269780280731891544110104468232527162010526522721116603
51+
96665573092547110557853763466820653109896526918620564769312570586356620185581007
52+
29360659876486117910453348850346113657686753249441668039626579787718556084552965
53+
41266540853061434443185867697514566140680070023787765913440171274947042056223053
54+
89945613140711270004078547332699390814546646458807972708266830634328587856983052
55+
35808933065757406795457163775254202114955761581400250126228594130216471550979259
56+
23099079654737612551765675135751782966645477917450112996148903046399471329621073
57+
40437518957359614589019389713111790429782856475032031986915140287080859904801094
58+
12147221317947647772622414254854540332157185306142288137585043063321751829798662
59+
23717215916077166925474873898665494945011465406284336639379003976926567214638530
60+
67360965712091807638327166416274888800786925602902284721040317211860820419000422

pi-spigot.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Original: https://github.com/NesHacker/NesPi/blob/main/pi-spigot.js
2+
// Modified to output the highest value of each variable for 4800 digits.
3+
// This helps test how many bits need to be allocated for each.
4+
5+
function toHex (number) {
6+
return `${number.toString(16).toUpperCase()}`
7+
}
8+
9+
/**
10+
* JavaScript implementation of pi-spigot.
11+
* @see https://www.maa.org/sites/default/files/pdf/pubs/amm_supplements/Monthly_Reference_12.pdf
12+
* @param {number} n Number of digits to calculate.
13+
* @returns {string} A string containing `n` digits of pi.
14+
*/
15+
function piSpigot (n) {
16+
n += 1
17+
const len = (10*n / 3) | 0
18+
const A = []
19+
const digits = []
20+
21+
for (let k = 0; k < len+1; k++) {
22+
A.push(2)
23+
}
24+
25+
let nines = 0
26+
let predigit = 0
27+
28+
let highestLeft = 0, highestRight = 0, highestQ = 0, highestZ = 0;
29+
30+
for (let j = n; j >= 1; j--) {
31+
let q = 0
32+
let z = 0
33+
34+
for (let i = len; i >= 1; i--) {
35+
36+
let left = 10 * A[i]
37+
let right = q * i
38+
z = left + right
39+
40+
if (left > highestLeft) highestLeft = left;
41+
if (right > highestRight) highestRight = right;
42+
if (q > highestQ) highestQ = q;
43+
if (z > highestZ) highestZ = z;
44+
45+
let twoI = 2 * i
46+
let twoIMinusOne = twoI - 1
47+
48+
A[i] = z % twoIMinusOne
49+
q = (z / twoIMinusOne) | 0
50+
51+
}
52+
53+
A[1] = q % 10
54+
q = (q / 10) | 0
55+
56+
if (q == 9) {
57+
nines++
58+
} else if (q == 10) {
59+
digits.push(predigit + 1)
60+
for (let k = 1; k <= nines; k++) {
61+
digits.push(0)
62+
}
63+
predigit = 0
64+
nines = 0
65+
} else {
66+
digits.push(predigit)
67+
predigit = q
68+
//if (j == 6) console.log(predigit)
69+
if (nines != 0) {
70+
for (let k = 1; k <= nines; k++) {
71+
digits.push(9)
72+
}
73+
nines = 0
74+
}
75+
}
76+
77+
78+
}
79+
80+
console.log("Highest left: " + highestLeft);
81+
console.log("Highest right: " + highestRight);
82+
console.log("Highest q: " + highestQ);
83+
console.log("Highest z: " + highestZ);
84+
85+
//const checksum = toHex(digits.reduce((a, b) => a + b) % 0x100)
86+
//console.log('Checksum: ' + checksum)
87+
88+
return digits[1] + '.' + digits.slice(2).join('')
89+
}
90+
91+
piSpigot(4800)

0 commit comments

Comments
 (0)