mirror of
https://github.com/KarolS/millfork.git
synced 2025-07-04 18:24:44 +00:00
@ -84,11 +84,21 @@ 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
|
* [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
|
* [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)
|
||||||
|
|
||||||
|
* [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
|
## Game Boy examples
|
||||||
|
|
||||||
|
98
examples/a8/countdown_for_benchmark.mfk
Normal file
98
examples/a8/countdown_for_benchmark.mfk
Normal file
@ -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 {}
|
||||||
|
}
|
119
examples/a8/countdown_while_benchmark.mfk
Normal file
119
examples/a8/countdown_while_benchmark.mfk
Normal file
@ -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 {}
|
||||||
|
}
|
65
examples/a8/montecarlo_pi_benchmark.mfk
Normal file
65
examples/a8/montecarlo_pi_benchmark.mfk
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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, p@$e8, t@$ea
|
||||||
|
byte n@$82
|
||||||
|
|
||||||
|
screen = os_SAVMSC
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
y = 0
|
||||||
|
bingo = 0
|
||||||
|
|
||||||
|
pause()
|
||||||
|
os_RTCLOK = 0
|
||||||
|
|
||||||
|
for i,0,to,probe {
|
||||||
|
n = pokey_random & 127
|
||||||
|
x = n * word(n)
|
||||||
|
n = pokey_random & 127
|
||||||
|
y = n * word(n)
|
||||||
|
if ((x + y) <= radius) {
|
||||||
|
bingo += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p = 4 * bingo
|
||||||
|
|
||||||
|
t = os_RTCLOK.b2 + (os_RTCLOK.b1 * 256)
|
||||||
|
|
||||||
|
printScore(t)
|
||||||
|
printScore(p)
|
||||||
|
|
||||||
|
while true {}
|
||||||
|
}
|
68
examples/a8/sieve1899.mfk
Normal file
68
examples/a8/sieve1899.mfk
Normal file
@ -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 {}
|
||||||
|
}
|
37
examples/a8/vertical_scroll.mfk
Normal file
37
examples/a8/vertical_scroll.mfk
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user