From ba07c2bc98fdba991b6d6444d57f0f897cf5959f Mon Sep 17 00:00:00 2001 From: schneefux Date: Sun, 12 Jun 2016 20:08:57 +0200 Subject: import full project --- src/MATRIS.G1A | Bin 0 -> 29976 bytes src/MainIcon.bmp | Bin 0 -> 138 bytes src/Matris.c | 635 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/SYSCALLS.src | 65 ++++++ src/Sprites.h | 443 +++++++++++++++++++++++++++++++++++++ src/draw.c | 655 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/draw.h | 15 ++ src/global.c | 33 +++ src/global.h | 57 +++++ src/key.c | 39 ++++ src/key.h | 4 + 11 files changed, 1946 insertions(+) create mode 100644 src/MATRIS.G1A create mode 100644 src/MainIcon.bmp create mode 100644 src/Matris.c create mode 100644 src/SYSCALLS.src create mode 100644 src/Sprites.h create mode 100644 src/draw.c create mode 100644 src/draw.h create mode 100644 src/global.c create mode 100644 src/global.h create mode 100644 src/key.c create mode 100644 src/key.h (limited to 'src') diff --git a/src/MATRIS.G1A b/src/MATRIS.G1A new file mode 100644 index 0000000..2c54587 Binary files /dev/null and b/src/MATRIS.G1A differ diff --git a/src/MainIcon.bmp b/src/MainIcon.bmp new file mode 100644 index 0000000..3e72743 Binary files /dev/null and b/src/MainIcon.bmp differ diff --git a/src/Matris.c b/src/Matris.c new file mode 100644 index 0000000..f2f6991 --- /dev/null +++ b/src/Matris.c @@ -0,0 +1,635 @@ +/*Matris by Casimo is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. +see here: http://creativecommons.org/licenses/by-nc-sa/3.0/ +*/ +#include "stdio.h" +#include "key.h" +#include "draw.h" +#include "global.h" + +short*APP_EnableRestart() +{ + unsigned int ea; + unsigned int j; + short*pEnableRestartFlag; + ea = *(unsigned int*)0x8001007C; + ea += 0x0490*4; + if ( ea < 0x8001007C ) return 0; + if ( ea > 0x81000000 ) return 0; + ea = *(unsigned int*)( ea ); + if ( ea < 0x8001007C ) return 0; + if ( ea > 0x81000000 ) return 0; + j = *(unsigned char*)( ea + 1 ); + j *= 4; + ea = ( ea + j + 4 ) & 0xFFFFFFFC; + if ( ea < 0x8001007C ) return 0; + if ( ea > 0x81000000 ) return 0; + pEnableRestartFlag = (short*)(*( unsigned int*)( ea ) + 8 ); + if ( ( (unsigned int)pEnableRestartFlag & 0xFF000000 ) != 0x88000000 ) return 0; + if ( pEnableRestartFlag ) *pEnableRestartFlag = 1; + return pEnableRestartFlag; +} + +//restart addin after return 1 + +static unsigned int seed = 123456789; +unsigned int kiss() +{ + // interner Zustand + static unsigned int y = 362436000; + static unsigned int z = 521288629; + static unsigned int c = 7654321; + + unsigned long t; + + // Linearer Kongruenzgenerator + seed = 69069 * seed + 12345; + + // Xorshift + y ^= y << 13; + y ^= y >> 17; + y ^= y << 5; + + // Multiply-with-carry + t = (unsigned long)698769069 * z + c; + c = t >> 32; + z = (unsigned int) t; + + return seed + y + z; +} + +void seedkiss() +{ + seed = RTC_GetTicks(); +} + +//kiss is a random number generator + +char *Disp_GetVRAMPtr(void); +void DrawLineVRAM(int x1, int y1, int x2, int y2); +void AllClr_DD(void); +void AllClr_VRAM(void); +void AllClr_DDVRAM(void); +void locate(int x, int y); +void Print(const unsigned char *str); +int Timer_Install(int TimerID, void (*handler)(void), int delay); +int Timer_Uninstall(int TimerID); +int Timer_Start(int TimerID); +void App_RUN_MAT(); + +//some prototypes + +char swit; + +char pause = False; +//pause the game + +char quit = False; + +char levelchanged = False; +//has the level changed during two actions? + +char exit = False; + +char ready; + +char onoff = True; +//used for timers + +char canswap; +//brick already swapped? + +char slowyposdown = 0; + +char connected; +//multiplayer activated? + +unsigned char receiveline = 0; +unsigned char sendline = 0; +//what to send or receive? + +char cantrans = False; +//allowed to transfer? + +//taken from MonochromeLib by PierrotLL + +void drawbuffer(char *buffer) +{ + char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000; + int i, j; + for(i=0 ; i<64 ; i++) + { + *LCD_register_selector = 4; + *LCD_data_register = i|192; + *LCD_register_selector = 4; + *LCD_data_register = 0; + *LCD_register_selector = 7; + for(j=0 ; j<16 ; j++) *LCD_data_register = *buffer++; + } +} + +void RestGray(void) +{ + drawbuffer(pScreen); + drawbuffer(pScreen + 1024); + drawbuffer(pScreen + 2048); +} + + +void Disconnect() +{ + Serial_Close(1); + connected = False; +} + +void TeacherMode() +{ + Timer_Uninstall(6); + Timer_Uninstall(7); + Disconnect(); + + App_RUN_MAT(); +} + +int round(float num) +{ + return (int) (num + 0.5); +} + +void clrbuffer(char *buffer) +{ + memset(buffer, 0, 3072); +} + + +void CreateBlock() +{ + block = nextblock; + canswap = True; + nextblock = (kiss() % 7) + 1; + xpos = 7; + ypos = 3; + dir = 0; + left = True; + right = True; + cantrans = True; +} + +void ResetValues() +{ + int x,y; + + char text[30]; + + memset(&changemap, 0, 210); + memset(&globalmap, 0, 210); + + ypos = 3; + xpos = 0; + block = 0; + onoff = True; + levelchanged = False; + right = True; + left = True; + hold = 0; + exit = False; + nextdir = Down; + nextblock = (kiss() % 7) + 1; + CreateBlock(); + clrbuffer(pScreen); + Timer_Uninstall(6); + Timer_Uninstall(7); + ready = True; + connected = False; + + AllClr_DDVRAM(); + + PopUpWin(2); + sprintf(&text, "Points: %d", points); + locate(3, 3); + Print(&text); + sprintf(&text, "Level: %d", level); + locate(3, 4); + Print(&text); + PutDisp_DD(); + + points = 0; + level = 0; + + while(!KeyDown(31)); +} + +void Transfer() +{ + int xcount, ycount; + char space = kiss() % 10; //where is the hole? + + if(connected == True) + { + if(receiveline > sendline) + { + //if there are lines arriving, but there can be send lines back, erase the lines, for example: receiving 3 lines, sending 1 -> 0 are send, 2 are received + receiveline -= sendline; + sendline = 0; + } + else + { + sendline -= receiveline; + receiveline = 0; + } + if(sendline > 0) + { + while(Serial_BufferedTransmitOneByte(sendline) != 0); + //send the number of lines + sendline = 0; + } + if(receiveline > 0) + { + for(ycount = 0; ycount < 20 - receiveline; ycount++) + { + for(xcount = 0; xcount < 10; xcount++) + { + globalmap[ycount][xcount] = globalmap[ycount + receiveline][xcount]; + //move all lines upwards + } + } + + for(ycount = 19; ycount > 19 - receiveline; ycount --) + { + for(xcount = 0; xcount < 10; xcount ++) + { + globalmap[ycount][xcount] = (xcount == space) ? 0 : (kiss() % 7) + 1; + //add lines at the bottom + } + } + receiveline = 0; + } + } +} + +void receive(void) +{ + unsigned char receiveadd = 0; + + if(Serial_ReadOneByte(&receiveadd) != 0) + { + receiveadd = 0; + } + + receiveline += (receiveadd > 20)?0:receiveadd; +} + +void Connect() +{ + unsigned char connstart = 111; + unsigned char answer; + char open_mode[6]; + + PopUpWin(1); + locate( 5 , 4); + Print("Connecting..."); + PutDisp_DD(); + + open_mode[ 0 ] = 0; // always 0 + open_mode[ 1 ] = 9; // 0=300, 1=600, 2=1200, 3=2400, 4=4800, 5=9600, 6=19200, 7=38400, 8=57600, 9=115200 baud + open_mode[ 2 ] = 2; // parity: 0=no; 1=odd; 2=even + open_mode[ 3 ] = 0; // datalength: 0=8 bit; 1=7 bit + open_mode[ 4 ] = 0; // stop bits: 0=one; 1=two + open_mode[ 5 ] = 0; // always 0 + + Serial_Open( &open_mode ); + + do + { + Serial_BufferedTransmitOneByte(connstart); + Serial_ReadOneByte(&answer); + }while(answer != connstart && !KeyDown(47)); + + if(!KeyDown(47))connected = True; + + if(connected != True) + { + Disconnect(); + } +} + +void SwapPieces() +{ + char save; + if(canswap == True) + { + save = block; + if(hold == 0) + { + block = nextblock; + nextblock = (kiss() % 7) + 1; + } + else + { + block = hold; + } + hold = save; + xpos = 7; + ypos = 3; + dir = 0; + } + canswap = False; +} + +void Rotate() +{ + if(++dir == 4) + { + dir = 0; + } + + if(DrawSprite() == False) + { + dir = (dir == 0)? 3 : dir - 1; + } +} + +void MoveBlock() +{ + switch (nextdir) + { + case Left : if(left == True) {xpos ++;} nextdir = Down;break; + case Right: if(right == True){xpos --;}nextdir = Down;break; + case Rot : Rotate();nextdir = Down;break; + case Swap: SwapPieces();nextdir = Down;break; + } + + if(nextdir == Fast && (int)slowyposdown == slowyposdown) + { + points += 1; + } +} + +void CheckPoints() +{ + char typecount = 0; + char oldlevel; + int xcount, ycount; + int ycount2, ycount3; + char fulllinecount = 0; + + for(xcount = 0; xcount < 10; xcount ++) + { + if(globalmap[0][xcount] != 0) + { + exit = True; + //game over + } + } + + for(ycount = 0; ycount < 20; ycount ++) + { + fulllinecount = 0; + for(xcount = 0; xcount < 10; xcount ++) + { + if(globalmap[ycount][xcount] != 0) + { + fulllinecount ++; + } + else + { + break; + } + } + + if(fulllinecount == 10) + { + typecount ++; + + //1: single, 2: double, 3: triple line, 4: tetris (maximum) + + for(ycount2 = ycount; ycount2 > 0; ycount2 --) + { + for(xcount = 0; xcount < 10; xcount ++) + { + globalmap[ycount2][xcount] = globalmap[ycount2 - 1][xcount]; + //move averything + } + } + + line(pScreen, 0 , 0 , 81 , 0, 1); + line(pScreen, 0 , 0 , 0 , 41, 1); + line(pScreen, 81 , 0 , 81 , 41, 1); + line(pScreen, 81 , 41 , 0 , 41, 1); + + for(ycount3 = 0; ycount3 < 20; ycount3 ++) + { + for(xcount = 0; xcount < 10; xcount ++) + { + if(globalmap[ycount3][xcount] != 0 || changemap[ycount3][xcount] != 0) + { + fillbox(pScreen, ycount3, xcount, (globalmap[ycount3][xcount] != 0)? globalmap[ycount3][xcount] - 1 : changemap[ycount3][xcount] - 1); + } + } + } + } + } + if(typecount > 0) + { + int blink; + + points += (typecount == 1)? 40 * (level + 1): (typecount == 2)? 100 * level : (typecount == 3)? 300 *(level + 1): (typecount == 4)? 1200 * (level + 1) : 0; + //increment points + + sendline = (typecount == 4)? 4 : typecount - 1; + //send a line, if not tetris send lines - 1 + oldlevel = level; + level += typecount; + if((int)(level / 10) != (int)(oldlevel / 10) && level < 200) + { + levelchanged = True; + //level = round cleared lines / 10 + } + } + Transfer(); +} + +void ReadKey() +{ + nextdir =Down; + + if(KeyDown(38)) nextdir = Rot; + if(KeyDown(37)) nextdir = Left ; + if(KeyDown(28)) nextdir = Right; + if(KeyDown(27)) nextdir = Fast; + if(KeyDown(47)) exit = True; + if(KeyDown(26)) nextdir = Swap; + if(KeyDown(31)) TeacherMode(); + if(KeyDown(39)) {pause = (pause == True)? False : True; while(KeyDown(39));} +} + +void Main(void) +{ + cantrans = False; + ready = False; + if(pause == False) + { + receive(); + ypos += (slowyposdown % 10 == 0 || nextdir == Fast)? 1 : 0; + if(nextdir == Left || nextdir == Right || nextdir == Fast || nextdir == Rot || slowyposdown % 10 == 0) + { + MoveBlock(); + DrawBlock(); + if(cantrans == True) + { + CheckPoints(); + DrawBlock(); + } + } + slowyposdown++; + } + ready = True; + drawNumber(pScreen, connected, 0, 62); + drawNumber(pScreen + 1024, connected, 0, 62); + drawNumber(pScreen + 2048, connected, 0, 62); +} + +void CallMain(void) +{ + ReadKey(); + if(nextdir == Fast && onoff == False) + { + while(ready == False); + onoff = True; + Timer_Uninstall(7); + Timer_Install(7, &Main, 50); + Timer_Start(7); + if(nextdir == Down) + { + nextdir = Fast; + } + } + else + { + if(nextdir != Fast && onoff == True || levelchanged == True) + { + while(ready == False); + onoff = False; + Timer_Uninstall(7); + + if(level < 20) + { + Timer_Install(7, &Main, 100 - level * 5); + } + else + { + Timer_Install(7, &Main, 0); + } + + Timer_Start(7); + levelchanged = False; + } + } +} + +//the code above is not good, CallMain handles the keys and sets the timer of Main + +void ReadMenuKeys() +{ + if(KeyDown(31)) TeacherMode(); + if(KeyDown(47)) quit = True; +} + +int AddIn_main(int isAppli, unsigned short OptionNum) +{ + char c[] = {0xE6, 0x9B, 0}; + char mode = 0; + + level = 0; + + pScreen = (char*)malloc(3072); + + nextblock = (kiss() % 7) + 1; + CreateBlock(); + + ready = True; + + APP_EnableRestart();//thx to SimonLothar + + seedkiss();//seed random numbers + + while(mode != 3) + { + quit = False; + Timer_Install(10, &ReadMenuKeys, 200); + Timer_Start(10); + while(!KeyDown(31) && mode != 3) + { + AllClr_VRAM(); + + locate( 6, 3 ); + Print(&"Singleplayer"); + locate( 6, 4 ); + Print(&"Multiplayer"); + locate( 2, 8); + Print(&"Copyright by Casimo"); + + locate( 4, 3 + mode); + PrintC(&c); + + PutDisp_DD(); + + if(KeyDown(37)) + { + mode += (mode == 1)? -1 : 1; + while(KeyDown(37)); + } + else + { + if(KeyDown(28)) + { + mode -= (mode == 0)? -1 : 1; + while(KeyDown(28)); + } + else + { + if(KeyDown(47)) + { + mode = 3; + while(KeyDown(47)); + } + } + + } + } + + Timer_Uninstall(10); + + if(mode != 3) + { + if(mode == 1) + { + Serial_ClearReceiveBuffer(); + Connect(); + } + + Timer_Install(6,&CallMain, 150); + Timer_Start(6); + + while(exit == False){RestGray();} + + ResetValues(); + + while(KeyDown(47)); + while(KeyDown(31)); + } + } + Timer_Uninstall(6); + Timer_Uninstall(7); + Disconnect(); + free(pScreen); +} + +//I'm sure there are unused variables + +#pragma section _BR_Size +unsigned long BR_Size; +#pragma section +#pragma section _TOP +int InitializeSystem(int isAppli, unsigned short OptionNum) +{return INIT_ADDIN_APPLICATION(isAppli, OptionNum);} +#pragma section diff --git a/src/SYSCALLS.src b/src/SYSCALLS.src new file mode 100644 index 0000000..d4234f6 --- /dev/null +++ b/src/SYSCALLS.src @@ -0,0 +1,65 @@ + .SECTION P,CODE,ALIGN=4 + .MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop + .export \SYSCALLNAME' +\SYSCALLNAME' + mov.l #h'\FUNO, r0 + mov.l #H'80010070, r2 + jmp @r2 + \TAIL' + .ENDM + + SYSCALL 040C, _Serial_ReadOneByte + SYSCALL 040E, _Serial_BufferedTransmitOneByte + SYSCALL 0418, _Serial_Open + SYSCALL 0419, _Serial_Close + SYSCALL 0413, _Serial_ClearReceiveBuffer + SYSCALL 003B, _RTC_GetTicks + SYSCALL 06C4, _KBD_PRGM_GetKey + SYSCALL 0135, _Disp_GetVRAMPtr + SYSCALL 0028, _PutDisp_DD + SYSCALL 0030, _DrawLineVRAM + SYSCALL 0142, _AllClr_DD + SYSCALL 0143, _AllClr_VRAM + SYSCALL 0144, _AllClr_DDVRAM + SYSCALL 0420, _Sleep + SYSCALL 090F, _GetKey + SYSCALL 0807, _locate + SYSCALL 0808, _Print + SYSCALL 0118, _Timer_Install + SYSCALL 0119, _Timer_Uninstall + SYSCALL 011A, _Timer_Start + + SYSCALL 0160, _itoa + SYSCALL 08DB, _EditExpression + SYSCALL 0236, _Reboot + + SYSCALL 023E, _RTC_SetDateTime + SYSCALL 0039, _RTC_Reset + SYSCALL 003A, _RTC_GetTime + + SYSCALL 03F4, _PowerOff ;PowerOff(int DisplayPowerOffLogo) + SYSCALL 040E, _Serial_WriteByte + SYSCALL 0910, _PutKey + SYSCALL 0032, _ShapeToDD + SYSCALL 0CC5, _InputString + + SYSCALL 0985, _App_CONICS + SYSCALL 0998, _App_DYNA + SYSCALL 09E2, _App_EQUA + SYSCALL 09F5, _App_PROG + SYSCALL 0A00, _App_FINANCE + SYSCALL 0A48, _App_GRAPH_TABLE + SYSCALL 0A4A, _App_LINK + SYSCALL 0A6B, _App_MEMORY + SYSCALL 0A75, _App_RECUR + SYSCALL 0AAE, _App_RUN_MAT + SYSCALL 0AC6, _App_RUN_STAT + SYSCALL 0AC8, _App_SYSTEM + + SYSCALL 0D64, _InputDateDialog + SYSCALL 05A6, _BCD_SetAsInt + SYSCALL 0015, _GlibGetOSVersionInfo + SYSCALL 0160, _LongToAsc + SYSCALL 02A0, _USB_CaptureDisplay + SYSCALL 0137, _GetMiniGlyph + .end diff --git a/src/Sprites.h b/src/Sprites.h new file mode 100644 index 0000000..1519e99 --- /dev/null +++ b/src/Sprites.h @@ -0,0 +1,443 @@ +#ifndef __SPRITES_H__ +#define __SPRITES_H__ + +int numbers[10][5][3] = { +{ +{ 1 , 1 , 1 }, +{ 1 , 0 , 1 }, +{ 1 , 0 , 1 }, +{ 1 , 0 , 1 }, +{ 1 , 1 , 1 }}, + +{{ 0 , 1 , 0 }, +{ 0 , 1 , 0 }, +{ 0 , 1 , 0 }, +{ 0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{ 3 , 2 , 2 , 2 , 3 }, +{ 3 , 2 , 2 , 2 , 3 }, +{ 3 , 3 , 3 , 3 , 3 }, +}, +{ +{ 3 , 3 , 3 , 3 , 3 }, +{ 3 , 1 , 2 , 2 , 3 }, +{ 3 , 2 , 2 , 1 , 3 }, +{ 3 , 2 , 1 , 2 , 3 }, +{ 3 , 3 , 3 , 3 , 3 }, +}, +{ +{ 3 , 3 , 3 , 3 , 3 }, +{ 3 , 1 , 1 , 1 , 3 }, +{ 3 , 1 , 3 , 1 , 3 }, +{ 3 , 1 , 1 , 1 , 3 }, +{ 3 , 3 , 3 , 3 , 3 }, +}, +{ +{ 3 , 3 , 3 , 3 , 3 }, +{ 3 , 2 , 2 , 2 , 3 }, +{ 3 , 2 , 0 , 2 , 3 }, +{ 3 , 2 , 2 , 2 , 3 }, +{ 3 , 3 , 3 , 3 , 3 }, +} +}; + +#endif \ No newline at end of file diff --git a/src/draw.c b/src/draw.c new file mode 100644 index 0000000..de2d6c5 --- /dev/null +++ b/src/draw.c @@ -0,0 +1,655 @@ +#include "sprites.h" +#include "global.h" + +//also from ML, a bit modified + +void pixel(char *buffer, int x, int y, int type) +{ + if(x&~127 || y&~63) return; + switch (type) + { + case 0: + (*(buffer + (y << 4) + (x >> 3))) &= ( ~ (128 >> (x & 7))); + (*(1024 + buffer + (y << 4) + (x >> 3))) &= ( ~ (128 >> (x & 7))); + (*(2048 + buffer + (y << 4) + (x >> 3))) &= ( ~ (128 >> (x & 7))); + break; + case 1: + (*(2048 + buffer + (y << 4) + (x >> 3))) |= (128 >> (x & 7)); + (*(1024 + buffer + (y << 4) + (x >> 3))) |= (128 >> (x & 7)); + (*(buffer + (y << 4) + (x >> 3))) |= (128 >> (x & 7)); + break; + } +} + +void pixelgray(char *buffer, int x,int y, int type) +{ + switch (type) + { + case 0: + (*(buffer + (y << 4) + (x >> 3))) &= ( ~ (128 >> (x & 7))); + (*(1024 + buffer + (y << 4) + (x >> 3))) &= ( ~ (128 >> (x & 7))); + (*(2048 + buffer + (y << 4) + (x >> 3))) &= ( ~ (128 >> (x & 7))); + break; + case 3: + (*(2048 + buffer + (y << 4) + (x >> 3))) |= (128 >> (x & 7)); + case 2: + (*(1024 + buffer + (y << 4) + (x >> 3))) |= (128 >> (x & 7)); + case 1: + (*(buffer + (y << 4) + (x >> 3))) |= (128 >> (x & 7)); + break; + } +} + +#define Abs(x) ((x < 0)? -x : x) +#define sgn(x) (x == 0)?0:(x > 0)?1:-1 + +void line(char *buffer, int x1, int y1, int x2, int y2, int color) +{ + int i, x, y, dx, dy, sx, sy, cumul; + + y1 = y1 + 7; + y2 = y2 + 7; + + x = x1; + y = y1; + dx = x2 - x1; + dy = y2 - y1; + sx = sgn(dx); + sy = sgn(dy); + dx = Abs(dx); + dy = Abs(dy); + pixel(buffer, x, y, color); + if(dx > dy) + { + cumul = dx / 2; + for(i=1 ; i dx) + { + cumul -= dx; + y += sy; + } + pixel(buffer, x, y, color); + } + } + else + { + cumul = dy / 2; + for(i=1 ; i dy) + { + cumul -= dy; + x += sx; + } + pixel(buffer, x, y, color); + } + } +} +//end of ML stuff + +void drawChar(char *buffer, char charact, int posx, int posy) +{ + int xcount, ycount; + + for(xcount = 0; xcount < 5; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + pixel(buffer, posx + xcount, posy - ycount, character[charact - 65][xcount][ycount]); + //this should be optimized: it is drawed pixel per pixel + } + } +} + +void drawString(char *buffer, char *string, unsigned char strlenght, int posx, int posy) +{ + int ycount, charcount; + + for(charcount = strlenght - 1 , ycount = posy; charcount >= 0; charcount --, ycount += 4) + { + drawChar(buffer, *(string + charcount), posx, ycount); + //every char seperately + } +} + +void drawNumber(char *buffer, char num, int posx, int posy) +{ + int xcount, ycount; + + for(xcount = 0; xcount < 5; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + pixel(buffer, (int)posx + xcount, (int)posy - ycount, (int)numbers[num][xcount][ycount]); + //like drawChar + } + } +} + +void fillbox(char *buffer, int posx, int posy, int type) +{ + int ycount, xcount; + + for(ycount = 0; ycount <= 4; ycount ++) + { + for(xcount = 0; xcount <= 4; xcount ++) + { + pixelgray(buffer, posx * 5 + xcount + 1, posy * 5 + ycount + 1 + 7, spritesheed[type][ycount][xcount]); + //draw a brick box pixel per pixel + } + } +} + +void normalfillbox(char *buffer, int posx, int posy, int type) +{ + int ycount, xcount; + + for(ycount = 0; ycount <= 4; ycount ++) + { + for(xcount = 0; xcount <= 4; xcount ++) + { + pixelgray(buffer, posx * 5 + xcount - 2, posy * 5 + ycount, spritesheed[type][ycount][xcount]); + //like fillbox, just a different position + } + } +} + +int DrawSprite() +{ + char fit = True; + + int xcount, ycount; + right = True; + left = True; + + memset(&changemap, 0, 210); + + //now draw a brick, the sizes are different + //structs and a drawing function would be better, it would save code + + switch(block) + { + case 1: + for(xcount = 0; xcount < 4; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockO[dir][ycount][xcount] == 1 && ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 1; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + case 2: + for(xcount = 0; xcount < 4; xcount ++) + { + for(ycount = 0; ycount < 4; ycount ++) + { + if(blockI[dir][ycount][xcount] == 1 && ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 2; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + case 3: + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockT[dir][ycount][xcount] == 1&& ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 3; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + case 4: + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockJ[dir][ycount][xcount] == 1 && ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 4; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + case 5: + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockL[dir][ycount][xcount] == 1 && ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 5; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + case 6: + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockZ[dir][ycount][xcount] == 1 && ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 6; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + case 7: + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockS[dir][ycount][xcount] == 1 && ypos - ycount - 2 >= 0) + { + if(xpos - xcount - 2 < 0 || xpos - xcount - 2 > 9 || ypos - ycount - 2 > 20) + { + fit = False; + } + else + { + changemap[ypos - ycount - 2][xpos - xcount - 2] = 7; + if(globalmap[ypos - ycount - 2][xpos - xcount - 2] != 0 || ypos - ycount - 2 >= 20) + { + fit = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount - 1 - 2] != 0 || xpos - xcount - 2 < 1) + { + right = False; + } + if(globalmap[ypos - ycount - 2][xpos - xcount + 1 - 2] != 0 || xpos - xcount - 2 > 8) + { + left = False; + } + } + } + } + } + break; + } + return fit; +} + +void DrawBlock() +{ + int xcount, ycount; + + clrbuffer(pScreen); + + drawNumber(pScreen, (int)(level / 10) % 10, 115, 39); + drawNumber(pScreen, (int)(level / 10) % 100 / 10, 115, 43); + + drawString(pScreen, &"LV", 2, 115, 59); + + drawNumber(pScreen, points % 10, 109, 39); + drawNumber(pScreen, points % 100 / 10, 109, 43); + drawNumber(pScreen, points % 1000 / 100, 109, 47); + drawNumber(pScreen, points % 10000 / 1000, 109, 51); + drawNumber(pScreen, points % 100000 / 10000, 109, 55); + drawNumber(pScreen, points % 1000000 / 100000, 109, 59); + drawNumber(pScreen, points / 1000000, 109, 63); + + drawString(pScreen, &"PTS", 3, 103, 51); + + drawString(pScreen, &"LINE", 4, 121, 51); + + drawNumber(pScreen, level % 10, 121, 39); + drawNumber(pScreen, level % 100 / 10, 121, 43); + drawNumber(pScreen, level % 1000 / 100, 121, 47); + + if(DrawSprite() == False) + { + for(ycount = 0; ycount < 20; ycount ++) + { + for(xcount = 0; xcount < 10; xcount ++) + { + if(changemap[ycount + 1][xcount] != 0) + { + globalmap[ycount][xcount] = changemap[ycount + 1][xcount]; + } + } + } + CreateBlock(); + if(nextdir == Fast) + { + nextdir = Down; + } + } + + line(pScreen, 0 , 0 , 101 , 0, 1); + line(pScreen, 0 , 0 , 0 , 51, 1); + line(pScreen, 101 , 0 , 101 , 51, 1); + line(pScreen, 101 , 51 , 0 , 51, 1); + + for(ycount = 0; ycount < 20; ycount ++) + { + for(xcount = 0; xcount < 10; xcount ++) + { + if(globalmap[ycount][xcount] != 0 || changemap[ycount][xcount] != 0) + { + fillbox(pScreen, ycount, xcount, (globalmap[ycount][xcount] != 0)? globalmap[ycount][xcount] - 1 : changemap[ycount][xcount] - 1); + } + } + } + + drawString(pScreen, &"NEXT", 4, 103, 2); + + //draw the next block + + switch(nextblock) + { + case 1 : + for(xcount = 0; xcount < 4; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockO[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 0); + } + } + } + break; + + case 2 : + for(xcount = 0; xcount < 4; xcount ++) + { + for(ycount = 0; ycount < 4; ycount ++) + { + if(blockI[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 1); + } + } + } + break; + + case 3 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockT[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 2); + } + } + } + break; + + case 4 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockJ[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 3); + } + } + } + break; + + case 5 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockL[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 4); + } + } + } + break; + + case 6 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockZ[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 5); + } + } + } + break; + + case 7 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockS[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 0 + xcount, 6); + } + } + } + break; + } + + drawString(pScreen, &"HOLD", 4, 103, 22); + + //draw the stored block + + switch(hold) + { + case 1 : + for(xcount = 0; xcount < 4; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockO[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 0); + } + } + } + break; + + case 2 : + for(xcount = 0; xcount < 4; xcount ++) + { + for(ycount = 0; ycount < 4; ycount ++) + { + if(blockI[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 1); + } + } + } + break; + + case 3 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockT[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 2); + } + } + } + break; + + case 4 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockJ[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 3); + } + } + } + break; + + case 5 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockL[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 4); + } + } + } + break; + + case 6 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockZ[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 5); + } + } + } + break; + + case 7 : + for(xcount = 0; xcount < 3; xcount ++) + { + for(ycount = 0; ycount < 3; ycount ++) + { + if(blockS[0][ycount][xcount] == 1) + { + normalfillbox(pScreen, 22 + ycount , 4 + xcount, 6); + } + } + } + break; + } +} diff --git a/src/draw.h b/src/draw.h new file mode 100644 index 0000000..2a9f9de --- /dev/null +++ b/src/draw.h @@ -0,0 +1,15 @@ +#ifndef __DRAW_H__ +#define __DRAW_H__ + +void pixel(char *buffer, int x, int y, int type); +void pixelgray(char *buffer, int x,int y, int type); +void line(char *buffer, int x1, int y1, int x2, int y2, int color); +void drawChar(char *buffer, char charact, int posx, int posy); +void drawString(char *buffer, char *string, unsigned char strlenght, int posx, int posy); +void drawNumber(char *buffer, char num, int posx, int posy); +void fillbox(char *buffer, int posx, int posy, int type); +void normalfillbox(char *buffer, int posx, int posy, int type); +int DrawSprite(); +void DrawBlock(); + +#endif \ No newline at end of file diff --git a/src/global.c b/src/global.c new file mode 100644 index 0000000..d3afdab --- /dev/null +++ b/src/global.c @@ -0,0 +1,33 @@ +#include "global.h" + +char* pScreen; +//pointer to the 3 graybuffers + +char right = True; +char left = True; +//can move? + +char changemap[21][10] = {0}; +char globalmap [20][10] = {0}; +//the two brickmaps: globalmap is the visible one + +char block; +//block type +int xpos = 7, ypos = 3; +char dir; +//position and direction of brick + +char level; +//current level + +unsigned int points = 0; +//points + +char nextdir = Down; +//the direction for the next round + +char nextblock = 1; +//the next block + +char hold = 0; +//the stored brick diff --git a/src/global.h b/src/global.h new file mode 100644 index 0000000..1634c89 --- /dev/null +++ b/src/global.h @@ -0,0 +1,57 @@ +#ifndef __GLOBAL_H__ +#define __GLOBAL_H__ + +#define Dir_0 0 +#define Dir_90 1 +#define Dir_180 2 +#define Dir_270 3 + +//direction of brick + +#define Down 0 +#define Left -1 +#define Right 1 +#define Fast 30 +#define Rot 20 +#define Swap 10 + +//type of movement + +#define False 0 +#define True 1 + +//for bools + +extern char* pScreen; +//pointer to the 3 graybuffers + +extern char right; +extern char left; +//can move? + +extern char changemap[21][10]; +extern char globalmap [20][10]; +//the two brickmaps: globalmap is the visible one + +extern char block; +//block type +extern int xpos, ypos; +extern char dir; +//position and direction of brick + +extern char level; +//current level + +extern unsigned int points; +//points + +extern char nextdir; +//the direction for the next round + +extern char nextblock; +//the next block + +extern char hold; +//the stored brick + +#endif \ No newline at end of file diff --git a/src/key.c b/src/key.c new file mode 100644 index 0000000..9083fbd --- /dev/null +++ b/src/key.c @@ -0,0 +1,39 @@ +int OSVersionAsInt(void) +{ + unsigned char mainversion; + unsigned char minorversion; + unsigned short release; + unsigned short build; + GlibGetOSVersionInfo( &mainversion, &minorversion, &release, &build ); + return ( ( mainversion << 24 ) & 0xFF000000 ) | ( ( minorversion << 16 ) & 0x00FF0000 ) | ( release & 0x0000FFFF ); +} + +#define isOS2 (OSVersionAsInt() >= 0x02020000) + +const unsigned short* keyboardregister = (unsigned short*)0xA44B0000; + +unsigned short key[8]; + +int KeyDown(int keycode) +{ + if(isOS2) + { + int row, col, word, bit; + + row = keycode%10; + col = keycode/10-1; + word = row>>1; + bit = col + 8*(row&1); + + memcpy(&key, keyboardregister, 8 * sizeof(unsigned short)); + + return (0 != (key[word] & 1<> 4 ) == keycode; + } +} + diff --git a/src/key.h b/src/key.h new file mode 100644 index 0000000..dd4a005 --- /dev/null +++ b/src/key.h @@ -0,0 +1,4 @@ +#ifndef __KEY_H__ +#define __KEY_H__ +int KeyDown(int); +#endif \ No newline at end of file -- cgit v1.3.1