Skip to content

Instantly share code, notes, and snippets.

@fu-sen
Last active February 12, 2021 12:03
Show Gist options
  • Save fu-sen/188630391c3a08eeebbef9eb57195552 to your computer and use it in GitHub Desktop.
Save fu-sen/188630391c3a08eeebbef9eb57195552 to your computer and use it in GitHub Desktop.
/*
Balloons Demo | MSX-BASIC / z88dk
Copyright (c) 2019 Keiichi Shiga (BALLOON | FU-SEN)
The MIT License (MIT) - https://mit.balloon.net.eu.org/#2019
zcc +msx -lndos -create-app -subtype=disk -bn balldemo balldemo.c
--> BLOAD"BALLDEMO.MSX",R
or
zcc +msx -lndos -create-app -bn balldemo balldemo.c
--> BLOAD"CAS:",R (BALLDEMO.CAS)
*/
void wrtvrm(int addr, char data)
{
#asm
ld ix,0
add ix,sp
ld a,(ix+2) ; data
ld l,(ix+4) ; addr
ld h,(ix+5)
call 004dh ; WRTVRM
#endasm
}
void ldirvm(int addr, int vaddr, int size)
{
#asm
ld ix,0
add ix,sp
ld c,(ix+2) ; size
ld b,(ix+3)
ld e,(ix+4) ; vaddr
ld d,(ix+5)
ld l,(ix+6) ; addr
ld h,(ix+7)
call 005ch ; LDIRVM
#endasm
}
void chgclr(char forclr, char bakclr, char bdrclr)
{
#asm
ld ix,0
add ix,sp
ld a,(ix+2) ; BDRCLR
ld (0f3ebh),a
ld a,(ix+4) ; BAKCLR
ld (0f3eah),a
ld a,(ix+6) ; FORCLR
ld (0f3e9h),a
call 0062h ; CHGCLR
#endasm
}
void init32()
{
#asm
call 006fh ; INIT32
#endasm
}
void cls()
{
#asm
xor a ; ld a,0
call 00c3h ; CLS
#endasm
}
int gttrig(char btn)
{
#asm
ld a,l ; btn
call 00d8h ; GTTRIG
ld l,a
ld h,0
#endasm
}
void kilbuf()
{
#asm
call 0156h ; KILBUF
#endasm
}
void sprite_mode(char mode)
{
#asm
ld a,l
and 03h
ld hl,0f3e0h ; rg1sav
add a,(hl)
ld b,a
ld c,1 ; R#1
call 0047h ; WRTVDP
#endasm
}
int peek(int addr)
{
#asm
ld a,(hl)
ld l,a
ld h,0
#endasm
}
unsigned int r;
unsigned char rnd()
{
r=(r*5)+1;
return(r);
}
char balloon[] = {
0x0e, 0x1d, 0x1f, 0x1f, 0x0e, 0x08, 0x10, 0xe0
};
char message[] = "MSX C-LANGUAGE DEMO";
int b=0,x[31],y[31],c[31],m[31];
void main() {
r=peek(0xfc9e);
chgclr(15, 1, 1);
init32();
cls();
sprite_mode(1);
ldirvm(message, 0x1800+2*32+2, sizeof(message));
ldirvm(balloon, 0x3800, 8);
for(int i=0; i<31; i++){
x[i]=rnd()%256;
y[i]=rnd()%192;
c[i]=rnd()%15;
m[i]=rnd()%8+1;
}
while(!gttrig(0)){
for(int i=0; i<31; i++){
for(int j=0; j<31; j++){
if(gttrig(0)){
break;
}
wrtvrm(0x1b00+j*4 , y[j]);
wrtvrm(0x1b00+j*4+1, x[j]);
wrtvrm(0x1b00+j*4+2, 0);
wrtvrm(0x1b00+j*4+3, c[j]);
switch(m[j]){
case 1:
case 2:
case 8:
y[j]+=188;
break;
case 4:
case 5:
case 6:
y[j]+=4;
break;
}
y[j]%=192;
switch(m[j]){
case 2:
case 3:
case 4:
x[j]+=252;
break;
case 6:
case 7:
case 8:
x[j]+=4;
break;
}
x[j]%=256;
}
if(gttrig(0)){
break;
}
m[i]=rnd()%8+1;
if (i%15 == 14){
b++;
b%=16;
chgclr(15, b, 1);
}
}
}
chgclr(15, 4, 7);
init32();
kilbuf();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment