From dc2def7e7218e25a124e855b19fff99e3d276c41 Mon Sep 17 00:00:00 2001 From: zbyti Date: Fri, 25 Sep 2020 03:08:33 +0200 Subject: [PATCH] A8 my last examples --- examples/README.md | 4 +++ examples/a8/bubble_sort.mfk | 62 +++++++++++++++++++++++++++++++++++++ examples/a8/landscape.mfk | 49 +++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 examples/a8/bubble_sort.mfk create mode 100644 examples/a8/landscape.mfk diff --git a/examples/README.md b/examples/README.md index 584e85b2..20c66564 100644 --- a/examples/README.md +++ b/examples/README.md @@ -92,6 +92,8 @@ how to create a program made of multiple files loaded on demand * [Grand Ttheft Antic](a8/grand_theft_antic.mfk) – ANTIC impact on CPU depending on the used graphic mode +* [Quatari Landscape](a8/landscape.mfk) – part of Quatari 256B intro + * [System Off example](a8/systemoff_example.mfk) – programming with ROM off * [GR.8 Chessboard Benchmark](a8/gr8_chessboard_benchmark.mfk) – chessboard drawing benchmark in GR.8 @@ -104,6 +106,8 @@ how to create a program made of multiple files loaded on demand * [Monte Carlo PI estimation Benchmark](a8/montecarlo_pi_benchmark.mfk) – measures the efficiency of multiplication +* [Bubble Sort Benchmark](a8/bubble_sort.mfk) – sort 255 elements + ## Game Boy examples * [GB test example](gb/gbtest.mfk) – a partial port of the NES example, with a rudimentary experimental text output implementation diff --git a/examples/a8/bubble_sort.mfk b/examples/a8/bubble_sort.mfk new file mode 100644 index 00000000..9e836982 --- /dev/null +++ b/examples/a8/bubble_sort.mfk @@ -0,0 +1,62 @@ +pointer screen @ $84 +byte i @ $80, n1 @ $81, n2 @ $82, t @ $83 +array(byte) sorttable align(fast) = [for x,255,downto,1 [x]] + +asm void pause() { + lda os_RTCLOK.b2 + .rt_check: + cmp os_RTCLOK.b2 + beq .rt_check + rts +} + +// print in HEX +void printScore(byte val) { + array(byte) tmp[2] + byte iter + + tmp[0] = val >> 4 + tmp[1] = val & %00001111 + for iter:tmp { + if tmp[iter] < 10 { + screen[0] = tmp[iter] + $10 + } else { + screen[0] = tmp[iter] + $17 + } + screen += 1 + } + screen[0] = 0 + screen += 1 +} + +void main(){ + screen = os_SAVMSC + for i:sorttable { + printScore(sorttable[i]) + } + + pause() + os_RTCLOK.b2 = 0 + + for t,253,downto,0{ + for i,0,to,253{ + n1 = sorttable[i] + n2 = sorttable[i+1] + if n1>n2 { + sorttable[i] = n2 + sorttable[i+1] = n1 + } + } + } + + t = os_RTCLOK.b2 + + screen = os_SAVMSC + for i:sorttable { + printScore(sorttable[i]) + } + // print jiffies + printScore(t) + + while true {} +} \ No newline at end of file diff --git a/examples/a8/landscape.mfk b/examples/a8/landscape.mfk new file mode 100644 index 00000000..b00d0627 --- /dev/null +++ b/examples/a8/landscape.mfk @@ -0,0 +1,49 @@ +// idea @ilmenit +// https://demozoo.org/productions/280623/ + +alias prev_x = os_OLDCOL +alias cursor_x = os_COLCRS +alias prev_y = os_OLDROW +alias cursor_y = os_ROWCRS +alias color = os_ATACHR + +byte tmp, i + +array(byte) color_height = [ + 170,150,144,144,122,122,110,110,94,94,86,86,82,80 +] + +asm void openmode(byte register(a) m) @ $ef9c extern +asm void drawto() @ $f9c2 extern + +void main(){ + openmode(9) + + os_COLOR4 = $b0 + + for i,0,to,79 { + color = 13 + prev_y = 1 + cursor_x = i + prev_x = i + + while color != $ff { + cursor_y = color_height[color] + tmp = color_height[color] + + if (pokey_random & 1) != 0 { + tmp += 1 + } else { + if (pokey_random & 1) != 0 { + tmp -= 1 + } + } + + color_height[color] = tmp + drawto() + color -= 1 + } + } + + while true {} +}