Skip to content

Instantly share code, notes, and snippets.

@fu-sen
Last active April 19, 2025 02:21
Show Gist options
  • Select an option

  • Save fu-sen/188630391c3a08eeebbef9eb57195552 to your computer and use it in GitHub Desktop.

Select an option

Save fu-sen/188630391c3a08eeebbef9eb57195552 to your computer and use it in GitHub Desktop.
/*
Balloons Demo | MSX / z88dk
Copyright (c) 2019-2025 BALLOON | FU-SEN
The MIT License (MIT) - https://mit.balloon.net.eu.org/#2019-2025
zcc +msx -lndos -create-app -subtype=disk -bn balldemo balldemo.c
--> BLOAD"BALLDEMO.MSX",R
zcc +msx -lndos -create-app -bn balldemo balldemo.c
--> BLOAD"CAS:",R (BALLDEMO.CAS)
zcc +msx -lndos -create-app -subtype=wav -bn balldemo balldemo.c
--> BLOAD"CAS:",R (BALLDEMO.WAV)
*/
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 ; Clear Z flag
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 redclk(char addr)
{
#asm
ld c,l
ld ix,01F5h ; REDCLK
call 015fh ; EXTROM
and 0fh
ld l,a
ld h,0
#endasm
}
int peek(int addr)
{
#asm
ld a,(hl) ; addr
ld l,a
ld h,0
#endasm
}
unsigned int r;
unsigned char rnd()
{
r++;
r ^= r >> 3;
r ^= r << 5;
r ^= r >> 7;
return(r);
}
char balloon[] = {
0x0e, 0x1d, 0x1f, 0x1f, 0x0e, 0x08, 0x10, 0xe0
};
char message[] = "MSX C-LANGUAGE DEMO";
int b=0,x[32],y[32],c[32],m[32];
char buf[128] = { 0 };
void main() {
if(peek(0x2d)<1){
r=peek(0xfc9e);
}else{
r=redclk(2)*60+redclk(1)*10+redclk(0);
}
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<32; i++){
x[i]=rnd()%272;
y[i]=rnd()%208;
c[i]=rnd()%15+1;
m[i]=rnd()%8+1;
}
while(!gttrig(0)){
for(int i=0; i<32; i++){
for(int j=0; j<32; j++){
if(gttrig(0)){
break;
}
if(y[j]>15) {
buf[j*4] =y[j]-16;
} else {
buf[j*4] =y[j]+240;
}
if(x[j]>15) {
buf[j*4+1]=x[j]-16;
buf[j*4+3]=c[j];
} else {
buf[j*4+1]=x[j]+16;
buf[j*4+3]=128+c[j];
}
/* buf[i*4+2]=0; */
switch(m[j]){
case 1:
case 2:
case 8:
y[j]+=204;
break;
case 4:
case 5:
case 6:
y[j]+=4;
break;
}
y[j]%=208;
switch(m[j]){
case 2:
case 3:
case 4:
x[j]+=268;
break;
case 6:
case 7:
case 8:
x[j]+=4;
break;
}
x[j]%=272;
}
if(gttrig(0)){
break;
}
ldirvm(buf, 0x1b00, 128);
m[i]=rnd()%8+1;
}
b=(b+1)%45;
chgclr(15, b/3+1, 1);
}
chgclr(15, 4, 7);
init32();
kilbuf();
}
@fu-sen

fu-sen commented Dec 29, 2024

Copy link
Copy Markdown
Author

balldemo_0000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment