1
0
mirror of https://github.com/KarolS/millfork.git synced 2026-04-22 00:17:03 +00:00

Support sizeof on arrays. Preliminary Commander X16 support.

This commit is contained in:
Karol Stasiak
2019-09-14 03:34:32 +02:00
parent 6c4dc81c1b
commit 1d445ecdd1
9 changed files with 276 additions and 4 deletions
+7 -1
View File
@@ -4,7 +4,7 @@
* [Hello world](crossplatform/hello_world.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC/MSX) simple text output
* [Fizzbuzz](crossplatform/fizzbuzz.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC/MSX) everyone's favourite programming task
* [Fizzbuzz](crossplatform/fizzbuzz.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC/MSX/X16) everyone's favourite programming task
* [Fizzbuzz 2](crossplatform/fizzbuzz2.mfk) (C64/C16/PET/VIC-20/PET/Atari/Apple II/BBC Micro/ZX Spectrum/PC-88/Armstrad CPC/MSX) an alternative, more extensible implemententation of fizzbuzz
@@ -61,3 +61,9 @@ how to create a program made of multiple files loaded on demand
* [Encoding test](msx/encoding_test.mfk) text encoding test; displays three lines of text in three different languages,
no more one of which will display correctly depending on the default font of your computer.
# Commander X16 examples
* [Palette](x16/palette.mfk) displays the default 256-colour palette.
* [Balls](x16/palette.mfk) 16 sprites using 240 colours.
+92
View File
@@ -0,0 +1,92 @@
// the emulator supports only 16 sprites:
const byte SPRITE_COUNT = 16
array(vera_sprite_data) sprites[SPRITE_COUNT]
array(sbyte) vx[SPRITE_COUNT]
array(sbyte) vy[SPRITE_COUNT]
import random
void main () {
pointer.vera_sprite_data p
byte i,j
word x,y
init_rand_seed()
// make balls striped
for i,0,parallelto,$1f {
for j,1,parallelto,$f {
sprite_bitmap[nonet(j<<5) + i] *= j
}
}
for i,0,paralleluntil,SPRITE_COUNT {
p = sprites[i].pointer
// bitmap is at $10000:
p->address = $800
p->x.lo = rand()
p->x.hi = rand() & 1
p->y = rand()
// no collision, above all layers, no flipping
p->ctrl0 = $c
// 32×32 pixels, different palette offsets
p->ctrl1 = $a0 | (i & $f)
vx[i] = 1 - (rand() & 2)
vy[i] = 1 - (rand() & 2)
}
vera_upload_large($10000, sprite_bitmap.addr, sizeof(sprite_bitmap))
vera_upload_large($40800, sprites.addr, sizeof(sprites))
// enable sprites:
vera_poke($40020, 1)
while true {
for i,0,paralleluntil,SPRITE_COUNT {
p = sprites[i].pointer
x = p->x
y = p->y
x += vx[i]
y += vy[i]
p->x = x
p->y = y
if x == 0 { vx[i] = 1 }
if x >= 640-32 { vx[i] = 0-1 }
if y == 0 { vy[i] = 1 }
if y >= 480-32 { vy[i] = 0-1 }
}
vera_upload_large($40800, sprites.addr, sizeof(sprites))
}
}
array sprite_bitmap = [
$00,$00,$00,$00,$00,$00,$11,$11,$11,$11,$00,$00,$00,$00,$00,$00,
$00,$00,$00,$00,$01,$11,$11,$11,$11,$11,$11,$10,$00,$00,$00,$00,
$00,$00,$00,$01,$11,$11,$11,$11,$11,$11,$11,$11,$10,$00,$00,$00,
$00,$00,$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,$00,$00,
$00,$00,$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,$00,$00,
$00,$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,$00,
$00,$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,$00,
$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,
$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,
$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,
$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,
$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,
$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,
$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,
$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,
$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,
$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,
$00,$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,$00,
$00,$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,$00,
$00,$00,$01,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$10,$00,$00,
$00,$00,$00,$11,$11,$11,$11,$11,$11,$11,$11,$11,$11,$00,$00,$00,
$00,$00,$00,$01,$11,$11,$11,$11,$11,$11,$11,$11,$10,$00,$00,$00,
$00,$00,$00,$00,$01,$11,$11,$11,$11,$11,$11,$10,$00,$00,$00,$00,
$00,$00,$00,$00,$00,$00,$11,$11,$11,$11,$00,$00,$00,$00,$00,$00
]
+24
View File
@@ -0,0 +1,24 @@
void main() {
word i
byte hn, ln
// 256-colour text mode for layer 0
vera_poke($40000, $21)
// 8×8 tiles, 64×64 tile map
vera_poke($40001, $35)
// 2× zoom in
vera_poke($40041, $40)
vera_poke($40042, $40)
i = 0
while i < $2000 {
vera_poke(i, $A0)
if i.lo & $7f < 64 {
ln = lo(i>>1) & $1f
hn = lo(i>>2) & $e0
vera_poke(i+1, hn | ln)
} else {
vera_poke(i+1, 0)
}
i += 2
}
while true {}
}