#include #include "bangmap01.c" #include "bangtiles01.c" #include "pioport.h" #define NOTEOFF 0 #define NOTEON 1 #define NOTEOFFOVER 2 #define MUTEON 3 #define MUTEOFF 4 #define SPEEUP 5 #define SPEEDWN 6 #define RIGHTEND 7 #define RIGHTMARK 8 #define LEFTMARK 9 #define LEFTEND 10 #define EMPTY 11 #define POINTER 12 #define NOTEONOVER 13 #define MUTEONOVER 14 #define MUTEOFFOVER 15 #define LBEG 16 #define LEND 17 #define POKE(addr, b) (*(unsigned char *)(addr) = (b)) unsigned char tiles[] ={NOTEOFF,NOTEON,NOTEOFFOVER,MUTEON,MUTEOFF,SPEEUP,SPEEDWN,RIGHTEND,RIGHTMARK,LEFTMARK,LEFTEND,EMPTY,POINTER,NOTEONOVER,MUTEONOVER,LBEG,LEND}; UBYTE matrix[8][32]; // drum grid UBYTE channel[8]; // state of channels of play position UBYTE ch_mute[8]; // channel mutes on or off UBYTE addr; // value to be passed to void move(int s_x,int s_y, UINT8 s_tile) { bangmap01[s_x+s_y*20]=s_tile; set_bkg_tiles(s_x,s_y,1,1,tiles+s_tile); } void counter(int c_x,int c_y, UINT8 c_tile) { set_bkg_tiles(c_x,c_y,1,1,tiles+c_tile); } void gb_out(UBYTE B) { GBWR_REG = B; } void main(){ UBYTE ch_1,ch_2,ch_3,ch_4,ch_5,ch_6,ch_7,ch_8,key; int x,y,c,d; int p; unsigned int len; unsigned int lcnt; unsigned int speed; unsigned int scrl; SHOW_BKG; set_bkg_data(0,70,bangtiles); set_bkg_tiles(0,0,32,18,bangmap01); gb_out(0x00); x=0;y=1; c=0;d=0; ch_1=0x00;ch_2=0x00;ch_3=0x00;ch_4=0x00;ch_5=0x00;ch_6=0x00;ch_7=0x00;ch_8=0x00; // channel output values lcnt=0; speed=100; len=16; scrl=1; move(x,y,NOTEOFFOVER); move(16,10,LBEG); for( c=0; c<9; c++ ) { // empty matrix , clear grid - should be function on key combo for( d=0; d<31; d++ ) { matrix[c][d]=0; } } for( c=0; c<9; c++ ) { // set all mute vales to on - 1 ch_mute[c]=0; } while(1){ gb_out(0x00); delay(speed); // set speed key = joypad(); // mirror for joypad input if(lcnt>=len){ move(lcnt,9,EMPTY); lcnt=-1; } lcnt++; //move(lcnt+1,9,EMPTY); move(lcnt,9,POINTER); move(lcnt-1,9,EMPTY); if(matrix[1][lcnt]==1 && ch_mute[1]==0){ move(1,0,MUTEON); ch_1=0x01;}else{ch_1=0x00;} if(matrix[2][lcnt]==1 && ch_mute[2]==0){ move(5,0,MUTEON); ch_2=0x02;}else{ch_2=0x00;} if(matrix[3][lcnt]==1 && ch_mute[3]==0){ move(9,0,MUTEON); ch_3=0x04;}else{ch_3=0x00;} if(matrix[4][lcnt]==1 && ch_mute[4]==0){ move(13,0,MUTEON); ch_4=0x08;}else{ch_4=0x00;} if(matrix[5][lcnt]==1 && ch_mute[5]==0){ move(17,0,MUTEON); ch_5=0x10;}else{ch_5=0x00;} if(matrix[6][lcnt]==1 && ch_mute[6]==0){ move(21,0,MUTEON); ch_6=0x20;}else{ch_6=0x00;} if(matrix[7][lcnt]==1 && ch_mute[7]==0){ move(25,0,MUTEON); ch_7=0x40;}else{ch_7=0x00;} if(matrix[8][lcnt]==1 && ch_mute[8]==0){ move(29,0,MUTEON); ch_8=0x80;}else{ch_8=0x00;} addr = ch_1 + ch_2 + ch_3 + ch_4 + ch_5 + ch_6 + ch_7 + ch_8; // add channel hex values to make output port binary value gb_out(addr); // set pio out to addr delay(50); // min system delay for master loops, implicates speed and output - on - time p=1; while(p<30){ move(p,0,MUTEOFF); p+=4; } p=y*4-2; if(key & J_UP) { // combo moves for speed up - down, start - select if (key & J_START ){ if(speed>=10){ speed=speed-5; }; } } if(key & J_DOWN) { if (key & J_START ){ if(speed<=200){ speed=speed+10; }; } } if(key & J_UP) { // mutes on if (key & J_SELECT ){ move(p,0,SPEEUP); ch_mute[y]=1; } } if(key & J_DOWN) { // mute off if (key & J_SELECT ){ move(p,0,SPEEDWN); ch_mute[y]=0; } } if(key & J_RIGHT) { if (key & J_START ){ if (len < 31){ len++; move(len,10,LBEG); move(len-1,10,EMPTY); } } } if(key & J_LEFT) { if (key & J_START ){ if (len > 2){ len--; move(len,10,LBEG); move(len+1,10,EMPTY); } } } if(key & J_RIGHT) { if (key & J_SELECT ){ if(scrl<7){ scroll_bkg(+16,0); scrl++; } } } if(key & J_LEFT) { if (key & J_SELECT ){ if(scrl>2){ scroll_bkg(-16,0); scrl--; } } } switch (joypad(0)) // master loops actions for key inputs { case (J_RIGHT): if(x<=31){ if(matrix[y][x]==1){ move(x,y,NOTEON); x=x+1; }else{ move(x,y,NOTEOFF); x=x+1; } if(matrix[y][x]==1){ move(x,y,NOTEONOVER); }else{ move(x,y,NOTEOFFOVER); } } break; // end right case (J_LEFT): if(x>=1){ if(matrix[y][x]==1){ move(x,y,NOTEON); x=x-1; }else{ move(x,y,NOTEOFF); x=x-1; } if(matrix[y][x]==1){ move(x,y,NOTEONOVER); }else{ move(x,y,NOTEOFFOVER); } } break; // end left case (J_UP): if(y>=2){ if(matrix[y][x]==1){ move(x,y,NOTEON); y=y-1; }else{ move(x,y,NOTEOFF); y=y-1; } if(matrix[y][x]==1){ move(x,y,NOTEONOVER); }else{ move(x,y,NOTEOFFOVER); } } break; // end up case (J_DOWN): if(y<=8){ if(matrix[y][x]==1){ move(x,y,NOTEON); y=y+1; move(x,y,NOTEONOVER); }else{ move(x,y,NOTEOFF); y=y+1; move(x,y,NOTEOFFOVER); } if(matrix[y][x]==1){ move(x,y,NOTEONOVER); }else{ move(x,y,NOTEOFFOVER); } }; break; // end down case (J_A): move(x,y,NOTEOFFOVER); matrix[y][x]=0; break; // end start case (J_B): move(x,y,NOTEON); matrix[y][x]=1; break; // end select } // end button switch } // end constant loop } // end void