From 19d9e36fa53f9a87efe167b7962fa6fe05e490a7 Mon Sep 17 00:00:00 2001 From: zbyti Date: Sat, 19 Sep 2020 01:34:29 +0200 Subject: [PATCH 1/5] A8 more examples --- examples/README.md | 10 +- examples/a8/countdown_for_benchmark.mfk | 98 ++++++++++++++++++ examples/a8/countdown_while_benchmark.mfk | 119 ++++++++++++++++++++++ examples/a8/vertical_scroll.mfk | 37 +++++++ 4 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 examples/a8/countdown_for_benchmark.mfk create mode 100644 examples/a8/countdown_while_benchmark.mfk create mode 100644 examples/a8/vertical_scroll.mfk diff --git a/examples/README.md b/examples/README.md index 4a786f53..b7045b6b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -84,11 +84,17 @@ how to create a program made of multiple files loaded on demand * [DLI example](a8/dli_example.mfk) – simple display list and display list interrupt example -* [Scroll example](a8/endless_scroll.mfk) – simple horizontal scroll example +* [Horizontal scroll example](a8/endless_scroll.mfk) – simple horizontal scroll example + +* [Vertical scroll example](a8/vertical_scroll.mfk) – simple vertical scroll example * [System Off example](a8/systemoff_example.mfk) – Programming example with ROM off -* [GR.8 Chessboard Benchmark](a8/gr8_chessboard_benchmark.mfk) – Chessboard drawing benchmark in GR.0 +* [GR.8 Chessboard Benchmark](a8/gr8_chessboard_benchmark.mfk) – Chessboard drawing benchmark in GR.8 + +* [FOR Countdown Benchmark](a8/countdown_for_benchmark.mfk) – Countdown from 1,999,999 to 0 (FOR loop) + +* [WHILE Countdown Benchmark](a8/countdown_while_benchmark.mfk) – Countdown from 1,999,999 to 0 (WHILE loop) ## Game Boy examples diff --git a/examples/a8/countdown_for_benchmark.mfk b/examples/a8/countdown_for_benchmark.mfk new file mode 100644 index 00000000..2af77dd9 --- /dev/null +++ b/examples/a8/countdown_for_benchmark.mfk @@ -0,0 +1,98 @@ +byte RTCLOK @ 0 +byte iter0B @ 1 +word iter0W @ 2 +bool run_counter @ 4 + +byte zpr_0 @ $24, zpr_1 @ $23, zpr_2 @ $22, zpr_3 @ $21, zpr_4 @ $20 +byte zpc_0 @ $47, zpc_1 @ $46, zpc_2 @ $45, zpc_3 @ $44, zpc_4 @ $43, zpc_5 @ $42, zpc_6 @ $41 + +const array(byte) dl align(16) = [ + $70,$70,$70, + $42,$20,0, + $41,@word[dl.addr] +] + +void system_off(){ + asm { sei } + antic_nmien = 0 + pia_portb = $fe + os_NMIVEC = vbi.addr + run_counter = false + antic_nmien = $40 +} + +asm void pause() { + lda RTCLOK + .rt_check: + cmp RTCLOK + beq .rt_check + rts +} + +interrupt void vbi(){ + RTCLOK += 1 + if run_counter{ + zpr_0 += 1 + if zpr_0 == 10 { + zpr_1 += 1 + zpr_0 = 0 + } + if zpr_1 == 10 { + zpr_2 += 1 + zpr_1 = 0 + } + if zpr_2 == 10 { + zpr_3 += 1 + zpr_2 = 0 + } + if zpr_3 == 10 { + zpr_4 += 1 + zpr_3 = 0 + } + } +} + +void copy_block(pointer src, pointer dsc, word size){ + for iter0W,0,to,size-1{ + dsc[iter0W] = src[iter0W] + } +} + +void set_block(pointer from, word size, byte val){ + for iter0W,0,to,size-1{ + from[iter0W] = val + } +} + +void main(){ + copy_block($e080,$4000,80) + system_off() + set_block($20,40,255) + set_block($20,5,0) + set_block($41,7,0) + + pause() + antic_chbase = $40 + antic_dlist = dl.addr + + run_counter = true + + for zpc_6,1,downto,0{ + for zpc_5,9,downto,0{ + for zpc_4,9,downto,0{ + for zpc_3,9,downto,0{ + for zpc_2,9,downto,0{ + for zpc_1,9,downto,0{ + for zpc_0,9,downto,0{ + } + } + } + } + } + } + } + + run_counter = false + + while true {} +} diff --git a/examples/a8/countdown_while_benchmark.mfk b/examples/a8/countdown_while_benchmark.mfk new file mode 100644 index 00000000..11fbea6b --- /dev/null +++ b/examples/a8/countdown_while_benchmark.mfk @@ -0,0 +1,119 @@ +byte RTCLOK @ 0 +byte iter0B @ 1 +word iter0W @ 2 +bool run_counter @ 4 + +byte zpr_0 @ $24, zpr_1 @ $23, zpr_2 @ $22, zpr_3 @ $21, zpr_4 @ $20 +byte zpc_0 @ $47, zpc_1 @ $46, zpc_2 @ $45, zpc_3 @ $44, zpc_4 @ $43, zpc_5 @ $42, zpc_6 @ $41 + +const array(byte) dl align(16) = [ + $70,$70,$70, + $42,$20,0, + $41,@word[dl.addr] +] + +void system_off(){ + asm { sei } + antic_nmien = 0 + pia_portb = $fe + os_NMIVEC = vbi.addr + run_counter = false + antic_nmien = $40 +} + +asm void pause() { + lda RTCLOK + .rt_check: + cmp RTCLOK + beq .rt_check + rts +} + +interrupt void vbi(){ + RTCLOK += 1 + if run_counter{ + zpr_0 += 1 + if zpr_0 == 10 { + zpr_1 += 1 + zpr_0 = 0 + } + if zpr_1 == 10 { + zpr_2 += 1 + zpr_1 = 0 + } + if zpr_2 == 10 { + zpr_3 += 1 + zpr_2 = 0 + } + if zpr_3 == 10 { + zpr_4 += 1 + zpr_3 = 0 + } + } +} + +void copy_block(pointer src, pointer dsc, word size){ + for iter0W,0,to,size-1{ + dsc[iter0W] = src[iter0W] + } +} + +void set_block(pointer from, word size, byte val){ + for iter0W,0,to,size-1{ + from[iter0W] = val + } +} + +void main(){ + copy_block($e080,$4000,80) + system_off() + set_block($20,40,255) + set_block($20,5,0) + set_block($41,7,0) + + zpc_0 = 9 + zpc_1 = 9 + zpc_2 = 9 + zpc_3 = 9 + zpc_4 = 9 + zpc_5 = 9 + zpc_6 = 1 + + pause() + antic_chbase = $40 + antic_dlist = dl.addr + + run_counter = true + + while(zpc_6 != $ff){ + zpc_5 = 9 + while(zpc_5 != $ff){ + zpc_4 = 9 + while(zpc_4 != $ff){ + zpc_3 = 9 + while(zpc_3 != $ff){ + zpc_2 = 9 + while(zpc_2 != $ff){ + zpc_1 = 9 + while(zpc_1 != $ff){ + zpc_0 = 9 + while(zpc_0 != $ff){ + zpc_0 -= 1 + } + zpc_1 -= 1 + } + zpc_2 -= 1 + } + zpc_3 -= 1 + } + zpc_4 -= 1 + } + zpc_5 -= 1 + } + zpc_6 -= 1 + } + + run_counter = false + + while true {} +} diff --git a/examples/a8/vertical_scroll.mfk b/examples/a8/vertical_scroll.mfk new file mode 100644 index 00000000..b195819c --- /dev/null +++ b/examples/a8/vertical_scroll.mfk @@ -0,0 +1,37 @@ +const array text align(64) = "...MILLFORK RULEZ..." atariscr + +const array(byte) dl align(16) = [ + $70,$70,$70,$70, + $67,@word[text.addr], + $41,@word[dl.addr] +] + +noinline asm void wait(byte register(a) f) { + clc + adc os_RTCLOK.b2 + .rt_check: + cmp os_RTCLOK.b2 + bne .rt_check + rts +} + +void main(){ + byte i0B @ $80 + + i0B = $f + os_SDLST = dl.addr + + while true { + while (i0B != 0){ + i0B -= 1 + antic_vscrol = i0B + wait(3) + } + wait(50) + while (i0B < $f){ + i0B += 1 + antic_vscrol = i0B + wait(2) + } + } +} \ No newline at end of file From 3234bbd3d9ffcbd1fb9786687f5c5a27452a7f7a Mon Sep 17 00:00:00 2001 From: zbyti Date: Sat, 19 Sep 2020 12:52:41 +0200 Subject: [PATCH 2/5] two more becnhmarks --- examples/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/README.md b/examples/README.md index b7045b6b..2f8ab1f4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -96,6 +96,10 @@ how to create a program made of multiple files loaded on demand * [WHILE Countdown Benchmark](a8/countdown_while_benchmark.mfk) – Countdown from 1,999,999 to 0 (WHILE loop) +* [Sieve of Eratosthenes 1899 Benchmark](a8/sieve1899.mfk) – Sieve of Eratosthenes, 1899 primes algorithm + +* [Monte Carlo PI estimation Benchmark](a8/montecarlo_pi_benchmark.mfk) – measures the efficiency of multiplication + ## Game Boy examples * [GB test example](gb/gbtest.mfk) – a partial port of the NES example, with a rudimentary experimental text output implementation From 269519715b0ccebf5a4ba57ddf191ee1a9ab2ed6 Mon Sep 17 00:00:00 2001 From: zbyti Date: Sat, 19 Sep 2020 12:59:14 +0200 Subject: [PATCH 3/5] two more benchmarks --- examples/a8/montecarlo_pi_benchmark.mfk | 64 +++++++++++++++++++++++ examples/a8/sieve1899.mfk | 68 +++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 examples/a8/montecarlo_pi_benchmark.mfk create mode 100644 examples/a8/sieve1899.mfk diff --git a/examples/a8/montecarlo_pi_benchmark.mfk b/examples/a8/montecarlo_pi_benchmark.mfk new file mode 100644 index 00000000..9e840953 --- /dev/null +++ b/examples/a8/montecarlo_pi_benchmark.mfk @@ -0,0 +1,64 @@ +const word probe = 9999 +const word radius = 127 * 127 +pointer screen @ $80 + +asm void pause() { + lda os_RTCLOK.b2 + .rt_check: + cmp os_RTCLOK.b2 + beq .rt_check + rts +} + +// print in HEX +void printScore(word val) { + array(byte) tmp[4] + byte iter + + tmp[0] = val.hi >> 4 + tmp[1] = val.hi & %00001111 + tmp[2] = val.lo >> 4 + tmp[3] = val.lo & %00001111 + + for iter:tmp { + if tmp[iter] < 10 { + screen[iter] = tmp[iter] + $10 + } else { + screen[iter] = tmp[iter] + $17 + } + } + screen += 40 +} + +void main() { + array(bool) flags[size] align(1024) + word i@$e0, bingo@$e2 + word x@$e4, y@$e6, n@$e8, p@$ea + + screen = os_SAVMSC + + x = 0 + y = 0 + bingo = 0 + + pause() + os_RTCLOK = 0 + + for i,0,to,probe { + n = pokey_random & 127 + x = n * n + n = pokey_random & 127 + y = n * n + if ((x + y) <= radius) { + bingo += 1 + } + } + p = 4 * bingo + + n = os_RTCLOK.b2 + (os_RTCLOK.b1 * 256) + + printScore(n) + printScore(p) + + while true {} +} diff --git a/examples/a8/sieve1899.mfk b/examples/a8/sieve1899.mfk new file mode 100644 index 00000000..62bd754b --- /dev/null +++ b/examples/a8/sieve1899.mfk @@ -0,0 +1,68 @@ +const word size = 8192 + +word RTCLOK @ $13, SAVMSC @ $58 +word i@$e0, prime@$e2, k@$e4, count@$e6 +pointer screen@$e8 + +asm void pause() { + lda $14 + .rt_check: + cmp $14 + beq .rt_check + rts +} + +// print in HEX +void printScore() { + array(byte) tmp[4] + byte iter + + screen = SAVMSC + + tmp[0] = RTCLOK.lo >> 4 + tmp[1] = RTCLOK.lo & %00001111 + tmp[2] = RTCLOK.hi >> 4 + tmp[3] = RTCLOK.hi & %00001111 + + for iter:tmp { + if tmp[iter] < 10 { + screen[iter] = tmp[iter] + $10 + } else { + screen[iter] = tmp[iter] + $17 + } + } +} + +void main() { + array(bool) flags[size] align(1024) + byte iter + + pause() + RTCLOK = 0 + + for iter,9,downto,0 { + + count = 0 + + for i:flags { + flags[i] = true + } + + for i:flags { + if flags[i] { + prime = (i * 2) + 3 + k = i + prime + while k <= size { + flags[k] = false + k += prime + } + count += 1 + } + } + + } + + printScore() + + while true {} +} From 07b6adf6bccbeea0d791a1359d32fa876046fc5f Mon Sep 17 00:00:00 2001 From: zbyti Date: Sat, 19 Sep 2020 13:02:55 +0200 Subject: [PATCH 4/5] two more benchmarks --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 2f8ab1f4..e9035f2e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -96,7 +96,7 @@ how to create a program made of multiple files loaded on demand * [WHILE Countdown Benchmark](a8/countdown_while_benchmark.mfk) – Countdown from 1,999,999 to 0 (WHILE loop) -* [Sieve of Eratosthenes 1899 Benchmark](a8/sieve1899.mfk) – Sieve of Eratosthenes, 1899 primes algorithm +* [Sieve of Eratosthenes (1899) Benchmark](a8/sieve1899.mfk) – Sieve of Eratosthenes, 1899 primes algorithm * [Monte Carlo PI estimation Benchmark](a8/montecarlo_pi_benchmark.mfk) – measures the efficiency of multiplication From e9d4359bc2021d6e4a7257e34cbacd4ed83e694a Mon Sep 17 00:00:00 2001 From: zbyti Date: Sun, 20 Sep 2020 22:58:20 +0200 Subject: [PATCH 5/5] A8 Monte Carlo PI refactor (__mul_u16u8u16) --- examples/a8/montecarlo_pi_benchmark.mfk | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/a8/montecarlo_pi_benchmark.mfk b/examples/a8/montecarlo_pi_benchmark.mfk index 9e840953..846ed70e 100644 --- a/examples/a8/montecarlo_pi_benchmark.mfk +++ b/examples/a8/montecarlo_pi_benchmark.mfk @@ -33,7 +33,8 @@ void printScore(word val) { void main() { array(bool) flags[size] align(1024) word i@$e0, bingo@$e2 - word x@$e4, y@$e6, n@$e8, p@$ea + word x@$e4, y@$e6, p@$e8, t@$ea + byte n@$82 screen = os_SAVMSC @@ -46,19 +47,19 @@ void main() { for i,0,to,probe { n = pokey_random & 127 - x = n * n + x = n * word(n) n = pokey_random & 127 - y = n * n + y = n * word(n) if ((x + y) <= radius) { bingo += 1 } } p = 4 * bingo - n = os_RTCLOK.b2 + (os_RTCLOK.b1 * 256) + t = os_RTCLOK.b2 + (os_RTCLOK.b1 * 256) - printScore(n) + printScore(t) printScore(p) while true {} -} +} \ No newline at end of file