├── README.md ├── Sample.c ├── Screens.c ├── Screens.h ├── Views.c ├── Views.h ├── dualplayfield.c ├── dualplayfield.h ├── entities.c ├── entities.h ├── extras.c ├── extras.h ├── fontGfx.c ├── fontGfx.h ├── gels.c ├── gels.h ├── gpInput.c ├── gpInput.h ├── iffLoad.c ├── iffLoad.h ├── keyInput.c └── keyInput.h /README.md: -------------------------------------------------------------------------------- 1 | # MyAmigaLibrary 2 | My base .h/.c Files for setting up a Graphic application. Create Views, load IFF(ILBM) files, grab images from IFF(ILBM) Files, Set up GELS and creating BOBS and VSprites 3 | 4 | Note - the format of getting images from .iff files is not compatible with VSprites and SimpleSprites 5 | It only works with bobs and other bitplane images 6 | -------------------------------------------------------------------------------- /Sample.c: -------------------------------------------------------------------------------- 1 | 2 | /*#include 3 | #include */ 4 | 5 | /*for amiga defined types -UWORD, UBYTE etc*/ 6 | #include "exec/types.h" 7 | #include "exec/memory.h" 8 | 9 | /*Graphics library stuff*/ 10 | #include "graphics/gfx.h" 11 | #include "graphics/gfxbase.h" 12 | #include "graphics/gfxmacros.h" 13 | #include "graphics/view.h" 14 | #include "graphics/gels.h" 15 | #include "graphics/sprite.h" 16 | 17 | #include "hardware/custom.h" 18 | 19 | /*my custom stuff*/ 20 | #include "iffload.h" 21 | #include "views.h" 22 | #include "gels.h" 23 | #include "extras.h" 24 | #include "Screens.h" 25 | 26 | #include "intuition/intuition.h" 27 | 28 | /*set screen width/height and depth*/ 29 | #define WIDTH 320 30 | #define HEIGHT 256 31 | #define DEPTH 5 32 | 33 | /*set whether in debug mode or not. 1 = yes/true 34 | used to display any debugging windows showing values or whatever*/ 35 | #define DEBUG 1 36 | 37 | #define PORT1 1 38 | #define PORT2 2 39 | 40 | struct Bob bob, burnsbob; 41 | struct VSprite vsbob, burnsVS, LifeMeterSprite, StatusSprite; 42 | extern struct Custom far custom; 43 | extern struct Screen *IntScreen; 44 | struct SimpleSprite simpleSprite; 45 | 46 | UWORD colours[3] = 47 | { 48 | 0xf00, 0x0f0, 0x00f 49 | }; 50 | 51 | UWORD chip life[] = 52 | { 53 | 0xffff, 0x0000, 54 | 0xffff, 0x0000, 55 | 56 | }; 57 | UWORD chip status[]= 58 | { 59 | 0x0180, 0x0000, 60 | 0x0180, 0x0000, 61 | 62 | 0x0000, 0x0000, 63 | 0x0000, 0x0000, 64 | 65 | 0x0000, 0x0180, 66 | 0x0000, 0x0180, 67 | 68 | 0x0000, 0x0000, 69 | 0x0000, 0x0000, 70 | 71 | 0x0180, 0x0180, 72 | 0x0180, 0x0180, 73 | }; 74 | 75 | VOID TestDraw(IMAGE image); 76 | VOID Wait(); 77 | 78 | int main() 79 | { 80 | UBYTE toggle; 81 | struct BitMap BitMap; 82 | IMAGE Cookie[14]; 83 | IMAGE Burns; 84 | char buf[255]; 85 | UWORD x; 86 | UWORD Frame = 0; 87 | BYTE line = 0; 88 | UWORD TargetX; 89 | UWORD TargetY; 90 | BYTE clicks = 0; 91 | UBYTE Facing = 0; 92 | 93 | char *LeftMouse = (char*)0xBFE001; 94 | 95 | IMAGE statusImg; 96 | IMAGE vsprImg; 97 | 98 | vsprImg.Depth = 2; 99 | vsprImg.Height = 2; 100 | vsprImg.Width = 16; 101 | vsprImg.ImageData = life; 102 | 103 | statusImg.Depth = 2; 104 | statusImg.Height = 10; 105 | statusImg.Width = 16; 106 | statusImg.ImageData = status; 107 | 108 | CreateScreen(WIDTH, HEIGHT, 5); 109 | 110 | CreateView(WIDTH, HEIGHT, DEPTH); 111 | SetupDBCopperLists(); 112 | LoadView(&Screen.view); 113 | 114 | /*Load bitmap with cookie sprites/bobs*/ 115 | LoadBitMap("shared:cookie2002", &BitMap); 116 | Cookie[6] = GetImage(&BitMap, 0, 4, 32, 52); 117 | Cookie[13] = GetImage(&BitMap, 32, 4, 64, 52); 118 | 119 | for(x = 0; x < 6; x++) 120 | { 121 | Cookie[x] = GetImage(&BitMap, (UWORD)(x*32), 52, (UWORD)((x*32) + 32), 100); 122 | } 123 | for(x = 7; x < 13; x++) 124 | { 125 | Cookie[x] = GetImage(&BitMap, (UWORD)((x-7)*32), 99, (UWORD)((x-7)*32+32), 147); 126 | } 127 | 128 | 129 | /*load bitmap with cookie's face*/ 130 | LoadBitMap("shared:cookieface", &BitMap); 131 | /*CookieFace = GetImage(&BitMap, 0, 64, 64, 128);*/ 132 | Burns = GetImage(&BitMap, 66, 129, 98, 177); 133 | /*BurnsFace = GetImage(&BitMap, 56, 64, 120, 128);*/ 134 | 135 | Move(&Screen.rastPort, 130, 123); 136 | Text(&Screen.rastPort, "LOADING...", strlen("LOADING...")); 137 | 138 | /*load screen.bitmap from IFF file direct to screen.bitmap*/ 139 | LoadBitMap("shared:template", &Screen.bitMap[0]); 140 | LoadBitMap("shared:template", &Screen.bitMap[1]); 141 | 142 | /*perhaps should load view here*/ 143 | /*LoadView(&Screen.view);*/ 144 | 145 | /*blit cookie's face to the rastport*/ 146 | BltBitMapRastPort(&BitMap, 0, 64, &Screen.rastPort, 0, 195, 64, 64, 0x60); 147 | 148 | 149 | /*remove cookie face bitmap*/ 150 | DeleteBitMap(&BitMap); 151 | 152 | /*Create GELS structure and initialise*/ 153 | CreateGELS(&Screen.rastPort, WIDTH, HEIGHT); 154 | 155 | /*create cookie character*/ 156 | CreateBob(&vsbob, &bob, 10, 10, &Cookie[6]); 157 | SetCollisionBob(&vsbob, &bob, &Cookie[6]); 158 | SetDoubleBufferBob(&vsbob, &bob, &Cookie[6]); 159 | 160 | CreateBob(&burnsVS, &burnsbob, 226, 48, &Burns); 161 | SetCollisionBob(&burnsVS, &burnsbob, &Burns); 162 | SetDoubleBufferBob(&burnsVS, &burnsbob, &Burns); 163 | 164 | /*add bobs to rast*/ 165 | AddBob(&bob, &Screen.rastPort); 166 | AddBob(&burnsbob, &Screen.rastPort); 167 | 168 | SetAPen(&Screen.rastPort, 1); 169 | 170 | CreateVSprite(&LifeMeterSprite, 180, 220, &vsprImg, colours); 171 | /*SetCollisionVSprite(&LifeMeterSprite, &vsprImg);*/ 172 | AddVSprite(&LifeMeterSprite, &Screen.rastPort); 173 | 174 | CreateVSprite(&StatusSprite, 0, 0, &statusImg, colours); 175 | AddVSprite(&StatusSprite, &Screen.rastPort); 176 | 177 | /*current bitmap is 0, set toggle to 1, so after we draw the GList, we switch the bitmap 1;*/ 178 | toggle = 1; 179 | 180 | TargetX = vsbob.X; 181 | TargetY = vsbob.Y; 182 | 183 | while(clicks < 20) 184 | { 185 | if((*LeftMouse & 0x40) != 0x40) 186 | { 187 | clicks++; 188 | TargetX = IntScreen->MouseX - 16; 189 | TargetY = IntScreen->MouseY - vsbob.Height+2; 190 | 191 | if(TargetX % 2 != 0) 192 | TargetX++; 193 | if(TargetY % 2 != 0) 194 | TargetY++; 195 | 196 | if(TargetX > vsbob.X) 197 | Facing = 0; 198 | else 199 | Facing = 7; 200 | } 201 | 202 | /*move bob*/ 203 | if(vsbob.X < TargetX) 204 | vsbob.X += 2; 205 | else if(vsbob.X > TargetX) 206 | vsbob.X -=2; 207 | 208 | if(vsbob.Y < TargetY) 209 | vsbob.Y += 2; 210 | else if(vsbob.Y > TargetY) 211 | vsbob.Y -=2; 212 | 213 | LifeMeterSprite.X = vsbob.X; 214 | LifeMeterSprite.Y = vsbob.Y; 215 | StatusSprite.X = vsbob.X + 20; 216 | StatusSprite.Y = vsbob.Y + 6; 217 | 218 | /*draw to RastPort*/ 219 | 220 | SortGList(&Screen.rastPort); 221 | DoCollision(&Screen.rastPort); 222 | DrawGList(&Screen.rastPort, &Screen.viewPort); 223 | 224 | WaitTOF(); 225 | /*load new view*/ 226 | MakeDisplay(toggle); 227 | 228 | Screen.viewPort.RasInfo->BitMap = &Screen.bitMap[toggle]; 229 | Screen.rastPort.BitMap = &Screen.bitMap[toggle]; 230 | 231 | if(Frame > 23) 232 | { 233 | Frame = 0; 234 | } 235 | 236 | if(vsbob.X == TargetX && vsbob.Y == TargetY) 237 | { 238 | vsbob.ImageData = Cookie[6+Facing].ImageData ; 239 | } 240 | else 241 | vsbob.ImageData = Cookie[(Frame/4) + Facing].ImageData; 242 | 243 | InitMasks(&vsbob); 244 | 245 | /*flip 0 to 1, or 1 to 0*/ 246 | toggle ^= 1; 247 | Frame++; 248 | } 249 | 250 | for(x = 0; x < 14; x++) 251 | { 252 | FreeMem(Cookie[x].ImageData, RASSIZE(Cookie[x].Width, Cookie[x].Height)*Cookie[x].Depth); 253 | } 254 | 255 | ClearMemory(); 256 | /*relaod the oldview (workbench)*/ 257 | LoadView(Screen.oldView); 258 | 259 | /*Freeup all memory saved for the created bobs - but not image data*/ 260 | DeleteBob(&vsbob, &bob); 261 | 262 | /*Freeup memory in my View - bitmaps, copperlists*/ 263 | FreeCopperMemory(); 264 | 265 | /*close the GFX library*/ 266 | CloseGfxLibrary(); 267 | 268 | 269 | return 0; 270 | } 271 | 272 | VOID TestDraw(IMAGE image) 273 | { 274 | WORD d =0; 275 | WORD plane = 0; 276 | WORD x, y; 277 | 278 | for(plane = 0; plane < image.Depth; plane++) 279 | { 280 | for(y = 0; y < image.Height; y++) 281 | { 282 | for(x = 0; x < image.Width/8; x+=2) 283 | { 284 | Screen.rastPort.BitMap[0].Planes[plane][x + (y*(WIDTH/8))] |= (image.ImageData[d] >> 8); 285 | Screen.rastPort.BitMap[0].Planes[plane][x + (y*(WIDTH/8)) + 1] |= image.ImageData[d]; 286 | d++; 287 | } 288 | } 289 | } 290 | } 291 | 292 | VOID Wait() 293 | { 294 | int i, j; 295 | for(i = 0; i < 2000000; i++) 296 | { 297 | for(j = 0; j < 8; j++) 298 | { 299 | } 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /Screens.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Screens.h" 9 | 10 | struct IntuitionBase *IntuitionBase; 11 | struct Screen *IntScreen; 12 | struct NewScreen NewScreen = 13 | { 14 | 0,0, 15 | 0, 0, 0, 16 | 1, 0, 17 | 0, 18 | SCREENQUIET, 19 | NULL, 20 | "", 21 | NULL, NULL 22 | }; 23 | 24 | VOID CreateScreen(UWORD width, UWORD height, UBYTE depth) 25 | { 26 | if((IntuitionBase = (struct IntuitionBase *) 27 | OpenLibrary("intuition.library", 0)) == NULL) 28 | { 29 | printf("Failed to Open Intuition Library\n"); 30 | exit(0); 31 | } 32 | 33 | NewScreen.Width = width; 34 | NewScreen.Height = height; 35 | NewScreen.Depth = depth; 36 | 37 | 38 | IntScreen = (struct Screen *) OpenScreen(&NewScreen); 39 | if(IntScreen == 0) 40 | { 41 | printf("No Screen!\n"); 42 | CleanExit(); 43 | } 44 | 45 | OffGadget(IntScreen->FirstGadget->NextGadget, IntScreen, NULL); 46 | RemoveGadget(IntScreen, IntScreen->FirstGadget->NextGadget); 47 | OffGadget(IntScreen->FirstGadget, IntScreen, NULL); 48 | RemoveGadget(IntScreen, IntScreen->FirstGadget); 49 | 50 | 51 | } 52 | 53 | VOID CleanExit() 54 | { 55 | ClearMemory(); 56 | exit(0); 57 | } 58 | VOID ClearMemory() 59 | { 60 | if(IntScreen != NULL) 61 | CloseScreen(IntScreen); 62 | 63 | /*close intuition if open*/ 64 | if(IntuitionBase != NULL) 65 | CloseLibrary(IntuitionBase); 66 | 67 | } 68 | struct RastPort *RastPort() 69 | { 70 | return &IntScreen->RastPort; 71 | } 72 | -------------------------------------------------------------------------------- /Screens.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | VOID CreateScreen(UWORD width, UWORD height, UBYTE depth); 6 | VOID CleanExit(); 7 | VOID ClearMemory(); 8 | struct RastPort *RastPort(); -------------------------------------------------------------------------------- /Views.c: -------------------------------------------------------------------------------- 1 | #include "exec/types.h" 2 | #include "exec/exec.h" 3 | 4 | #include "graphics/view.h" 5 | #ifndef _GfxBase 6 | #include 7 | struct GfxBase *GfxBase; 8 | #endif 9 | #include "graphics/gfxmacros.h" /*includes rastport.h*/ 10 | 11 | #include "Views.h" 12 | 13 | 14 | SCREENVIEW Screen; 15 | 16 | UWORD ColorTable16[16] = 17 | { 18 | 0x000, 0xeca, 0xc00, 0xf60, 19 | 0x090, 0x3f1, 0x00f, 0x2cd, 20 | 0xf0c, 0xa0f, 0x950, 0xfca, 21 | 0xfe0, 0xccc, 0x888, 0x444 22 | }; 23 | 24 | UWORD ColorTable32[32] = 25 | { 26 | 0x000, 0xfff, 0xf00, 0xc00, 27 | 0x800, 0x0f0, 0x0c0, 0x080, 28 | 0xf0f, 0xc0c, 0x808, 0x04f, 29 | 0x04c, 0x028, 0xff0, 0xca0, 30 | 0x620, 0xe52, 0xc86, 0xfb9, 31 | 0x222, 0x444, 0x555, 0x666, 32 | 0x777, 0x888, 0x999, 0xaaa, 33 | 0xccc, 0xddd, 0xeee, 0x0ff 34 | }; 35 | 36 | void CreateView(UWORD Width, UWORD Height, UBYTE Depth) 37 | { 38 | Screen.Width = Width; 39 | Screen.Height = Height; 40 | Screen.Depth = Depth; 41 | 42 | 43 | if ((GfxBase = (struct GfxBase*) 44 | OpenLibrary("graphics.library", 0)) == NULL) 45 | { 46 | printf("Graphics failed to open\n"); 47 | Exit(1000); 48 | } 49 | 50 | Screen.oldView = GfxBase->ActiView; 51 | 52 | InitView(&Screen.view); 53 | InitVPort(&Screen.viewPort); 54 | Screen.view.ViewPort = &Screen.viewPort; 55 | InitBitMap(&Screen.bitMap[0], Depth, Width, Height); 56 | InitBitMap(&Screen.bitMap[1], Depth, Width, Height); 57 | InitRastPort(&Screen.rastPort); 58 | /*InitRastPort(&Screen.rastPort[1]);*/ 59 | Screen.rastPort.BitMap = &Screen.bitMap[0]; 60 | /*Screen.rastPort[1].BitMap = &Screen.bitMap[1];*/ 61 | 62 | 63 | CreateRasInfo(); 64 | CreateViewPort(); 65 | AllocateBitMapMemory(); 66 | 67 | } 68 | 69 | VOID SetupDBCopperLists() 70 | { 71 | Screen.view.LOFCprList = NULL; 72 | Screen.view.SHFCprList = NULL; 73 | 74 | MakeVPort(&Screen.view, &Screen.viewPort); 75 | MrgCop(&Screen.view); 76 | 77 | /*store lists for double buffering*/ 78 | Screen.LOF[0] = Screen.view.LOFCprList; 79 | Screen.SHF[0] = Screen.view.SHFCprList; 80 | 81 | /*prepare rasinfo for double buffer*/ 82 | /*Screen.viewPort.RasInfo = &Screen.rasInfo; 83 | /*Screen.rasInfo[1].Next = &Screen.rasInfo[0];*/ 84 | 85 | 86 | /*important, otherwise no 2nd copper list*/ 87 | Screen.view.LOFCprList = NULL; 88 | Screen.view.SHFCprList = NULL; 89 | 90 | /*same as above for double buffering*/ 91 | MakeVPort(&Screen.view, &Screen.viewPort); 92 | MrgCop(&Screen.view); 93 | 94 | /*store 2nd copper list*/ 95 | Screen.LOF[1] = Screen.view.LOFCprList; 96 | Screen.SHF[1] = Screen.view.SHFCprList; 97 | 98 | } 99 | 100 | void CreateRasInfo() 101 | { 102 | /*BYTE i; 103 | for(i = 0; i < 2; i++) 104 | { 105 | Screen.rasInfo[i].BitMap = &Screen.bitMap[i]; 106 | Screen.rasInfo[i].RxOffset = 0; 107 | Screen.rasInfo[i].RyOffset = 0; 108 | Screen.rasInfo[i].Next = NULL; 109 | }*/ 110 | Screen.rasInfo.BitMap = &Screen.bitMap[0]; 111 | Screen.rasInfo.RxOffset = 0; 112 | Screen.rasInfo.RyOffset = 0; 113 | Screen.rasInfo.Next = NULL; 114 | } 115 | void CreateViewPort() 116 | { 117 | UBYTE colours = 2; 118 | UBYTE i; 119 | 120 | Screen.viewPort.RasInfo = &Screen.rasInfo; 121 | 122 | Screen.viewPort.DWidth = Screen.Width; 123 | Screen.viewPort.DHeight = Screen.Height; 124 | Screen.viewPort.DxOffset = 0; 125 | Screen.viewPort.DyOffset = 0; 126 | Screen.viewPort.Modes = 0; 127 | if(Screen.Width > 320) 128 | Screen.viewPort.Modes |= HIRES; 129 | if(Screen.Height > 256) 130 | Screen.viewPort.Modes |= LACE; 131 | 132 | Screen.viewPort.Modes |= SPRITES; 133 | 134 | for(i = 0; i < Screen.Depth-1; i++) 135 | { 136 | colours *= 2; 137 | } 138 | 139 | Screen.viewPort.ColorMap = (struct ColorMap *)GetColorMap(colours); 140 | 141 | if(Screen.Depth == 4) 142 | LoadRGB4(&Screen.viewPort, &ColorTable16[0], colours); 143 | else if(Screen.Depth == 5) 144 | LoadRGB4(&Screen.viewPort, &ColorTable32[0], colours); 145 | } 146 | void AllocateBitMapMemory() 147 | { 148 | UBYTE i, j; 149 | for(j = 0; j < 2; j++) 150 | { 151 | for(i = 0; i < Screen.Depth; i++) 152 | { 153 | if((Screen.bitMap[j].Planes[i] = (PLANEPTR)AllocRaster(Screen.Width, Screen.Height)) == NULL) 154 | { 155 | printf("Cannot allocate memory for bitmap.\n"); 156 | exit(1000); 157 | } 158 | BltClear((UBYTE*)Screen.bitMap[j].Planes[i], RASSIZE(Screen.Width, Screen.Height), 0); 159 | } 160 | } 161 | } 162 | 163 | void FreeCopperMemory() 164 | { 165 | UBYTE i, j; 166 | FreeColorMap(Screen.viewPort.ColorMap); 167 | 168 | FreeCprList(Screen.LOF[0]); 169 | FreeCprList(Screen.SHF[0]); 170 | FreeCprList(Screen.LOF[1]); 171 | FreeCprList(Screen.SHF[1]); 172 | 173 | FreeVPortCopLists(&Screen.viewPort); 174 | 175 | /*if(Screen.view.LOFCprList !=0) 176 | FreeCprList(Screen.view.LOFCprList); 177 | if(Screen.view.SHFCprList != 0) 178 | FreeCprList(Screen.view.SHFCprList);*/ 179 | 180 | for(j = 0; j < 2; j++) 181 | { 182 | for(i = 0; i < Screen.Depth; i++) 183 | { 184 | FreeRaster(Screen.bitMap[j].Planes[i], Screen.Width, Screen.Height); 185 | } 186 | } 187 | } 188 | 189 | void MakeDisplay(UBYTE toggle) 190 | { 191 | MrgCop(&Screen.view); 192 | 193 | Screen.view.LOFCprList = Screen.LOF[toggle]; 194 | Screen.view.SHFCprList = Screen.SHF[toggle]; 195 | LoadView(&Screen.view); 196 | } 197 | void CloseGfxLibrary() 198 | { 199 | CloseLibrary(GfxBase); 200 | } 201 | -------------------------------------------------------------------------------- /Views.h: -------------------------------------------------------------------------------- 1 | #define VIEWS 2 | 3 | 4 | /*Double Buffered Screen*/ 5 | typedef struct ScreenView 6 | { 7 | int Width; 8 | int Height; 9 | int Depth; 10 | struct View view; 11 | struct ViewPort viewPort; 12 | struct RasInfo rasInfo; 13 | struct BitMap bitMap[2]; 14 | struct RastPort rastPort; 15 | struct View *oldView; 16 | 17 | struct cprlist *LOF[2]; 18 | struct cprlist *SHF[2]; 19 | }SCREENVIEW; 20 | 21 | extern SCREENVIEW Screen; 22 | 23 | void CreateView(UWORD Width, UWORD Height, UBYTE Depth); 24 | 25 | void CreateRasInfo(); 26 | void CreateViewPort(); 27 | void AllocateBitMapMemory(); 28 | void FreeCopperMemory(); 29 | void MakeDisplay(UBYTE toggle); 30 | void CloseGfxLibrary(); 31 | void SetupDBCopperLists(); 32 | 33 | -------------------------------------------------------------------------------- /dualplayfield.c: -------------------------------------------------------------------------------- 1 | #include "dualplayfield.h" 2 | 3 | struct View View; 4 | struct ViewPort ViewPort; 5 | struct RasInfo RasInfos[2]; 6 | struct BitMap BitMaps[2]; 7 | struct RastPort RastPorts[2]; 8 | 9 | 10 | short CreateDualPlayField() 11 | { 12 | int i, j; 13 | InitView(&View); 14 | InitVPort(&ViewPort); 15 | View.ViewPort = &ViewPort; 16 | 17 | InitBitMap(&BitMaps[0],DEPTH, WIDTH, HEIGHT); 18 | InitBitMap(&BitMaps[1],DEPTH, WIDTH, HEIGHT); 19 | 20 | for(i = 0; i < 2; i++) 21 | { 22 | RasInfos[i].BitMap = &BitMaps[i]; 23 | RasInfos[i].RxOffset = 0; 24 | RasInfos[i].RyOffset = 0; 25 | RasInfos[i].Next = NULL; 26 | } 27 | 28 | ViewPort.DxOffset = 0; 29 | ViewPort.DyOffset = 0; 30 | ViewPort.DWidth = WIDTH; 31 | ViewPort.DHeight = HEIGHT; 32 | ViewPort.RasInfo = &RasInfos[BACK]; 33 | ViewPort.Modes = DUALPF|PFBA|SPRITES; 34 | RasInfos[BACK].Next = &RasInfos[FRONT]; 35 | ViewPort.ColorMap = (struct ColorMap*)GetColorMap(16); 36 | 37 | for(i = 0; i < 2; i++) 38 | { 39 | for(j = 0; j < DEPTH; j++) 40 | { 41 | if((BitMaps[i].Planes[j] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT)) == NULL) 42 | { 43 | FreeDPFBitMaps(); 44 | return FALSE; 45 | } 46 | BltClear((UBYTE *)BitMaps[i].Planes[j], RASSIZE(WIDTH, HEIGHT), 0); 47 | } 48 | } 49 | 50 | InitRastPort(&RastPorts[0]); 51 | RastPorts[0].BitMap = &BitMaps[0]; 52 | InitRastPort(&RastPorts[1]); 53 | RastPorts[1].BitMap = &BitMaps[1]; 54 | 55 | MakeVPort(&View, &ViewPort); 56 | MrgCop(&View); 57 | 58 | ViewPort.RasInfo = &RasInfos[BACK]; 59 | RasInfos[BACK].Next = &RasInfos[FRONT]; 60 | 61 | LoadView(&View); 62 | return TRUE; 63 | } 64 | void FreeDPFBitMaps() 65 | { 66 | int i; 67 | for(i = 0; i < DEPTH; i++) 68 | { 69 | if(BitMaps[0].Planes[i]) 70 | FreeRaster(BitMaps[0].Planes[i], WIDTH, HEIGHT); 71 | if(BitMaps[1].Planes[i]) 72 | FreeRaster(BitMaps[1].Planes[i], WIDTH, HEIGHT); 73 | } 74 | } 75 | void FreeCopper() 76 | { 77 | FreeVPortCopLists(&ViewPort); 78 | FreeCprList(View.LOFCprList); 79 | FreeCprList(View.SHFCprList); 80 | } 81 | void FreeDualPlayField() 82 | { 83 | FreeDPFBitMaps(); 84 | FreeCopper(); 85 | FreeColorMap(ViewPort.ColorMap); 86 | } 87 | -------------------------------------------------------------------------------- /dualplayfield.h: -------------------------------------------------------------------------------- 1 | #ifndef DUALPLAYFIELD_H 2 | #define DUALPLAYFIELD_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define BACK 0 9 | #define FRONT 1 10 | #define WIDTH 320 11 | #define HEIGHT 256 12 | #define DEPTH 3 13 | 14 | 15 | 16 | short CreateDualPlayField(); 17 | void FreeDPFBitMaps(); 18 | void FreeCopper(); 19 | void FreeDualPlayField(); 20 | 21 | #endif -------------------------------------------------------------------------------- /entities.c: -------------------------------------------------------------------------------- 1 | #include "entities.h" 2 | 3 | 4 | void AddEntity(struct Entities *entities, struct EntityData *data) 5 | { 6 | struct Entity *newEntity = (struct Entity*)AllocMem(sizeof(struct Entity), MEMF_CLEAR);; 7 | if(entities->count == 0) 8 | { 9 | newEntity->data = data; 10 | newEntity->next = newEntity; 11 | newEntity->prev = newEntity; 12 | entities->top = newEntity; 13 | entities->bottom = newEntity; 14 | 15 | } 16 | else 17 | { 18 | newEntity->data = data; 19 | newEntity->next = entities->bottom; 20 | newEntity->prev = entities->top; 21 | entities->top->next = newEntity; 22 | entities->bottom->prev = newEntity; 23 | 24 | entities->top = newEntity; 25 | } 26 | entities->count++; 27 | } 28 | int RemoveEntity(struct Entities *entities, struct Entity *entity) 29 | { 30 | if(entity == entities->bottom) 31 | { 32 | entities->bottom = entities->bottom->next; 33 | entities->bottom->prev = entities->top; 34 | entities->top->next = entities->bottom; 35 | FreeMem(entity, sizeof(struct Entity)); 36 | entities->count--; 37 | } 38 | else if(entity == entities->top) 39 | { 40 | entities->top = entities->top->prev; 41 | entities->bottom->prev = entities->top; 42 | entities->top->next = entities->bottom; 43 | 44 | FreeMem(entity, sizeof(struct Entity)); 45 | entities->count--; 46 | } 47 | else 48 | { 49 | struct Entity tempEntity = *entities->bottom; 50 | 51 | while(tempEntity.data->name != entity->data->name) 52 | { 53 | tempEntity = *tempEntity.next; 54 | } 55 | 56 | entity->prev->next = entity->next; 57 | entity->next->prev = entity->prev; 58 | FreeMem(entity, sizeof(struct Entity)); 59 | entities->count--; 60 | } 61 | 62 | return entities->count; 63 | } 64 | 65 | void FreeEntities(struct Entities *entities) 66 | { 67 | while(entities->count != 0) 68 | { 69 | RemoveEntity(entities, entities->bottom); 70 | } 71 | } 72 | 73 | void DrawEntities(struct RastPort *rastPort, struct Entities *entities) 74 | { 75 | struct Entity *entity; 76 | SetRast(rastPort, 0); 77 | 78 | /*only attempt to draw entities if any exist*/ 79 | if(entities->count != 0) 80 | { 81 | entity = entities->bottom; 82 | do 83 | { 84 | SetAPen(rastPort, entity->data->colour); 85 | Move(rastPort, entity->data->x + 9, entity->data->y+13); 86 | Text(rastPort, entity->data->symbol, 1); 87 | entity = entity->next; 88 | 89 | }while(entity != entities->bottom); 90 | } 91 | 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /entities.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifndef ENTITIES_H 6 | #define ENTITIES_H 7 | 8 | struct Entity 9 | { 10 | struct Entity *next; 11 | struct Entity *prev; 12 | struct EntityData *data; 13 | }; 14 | struct Entities 15 | { 16 | int count; 17 | struct Entity *top; 18 | struct Entity *bottom; 19 | }; 20 | struct EntityData 21 | { 22 | int x; 23 | int y; 24 | char *symbol; 25 | char *name; 26 | short colour; 27 | /*other stuff*/ 28 | }; 29 | 30 | 31 | 32 | void AddEntity(struct Entities *entities, struct EntityData *data); 33 | int RemoveEntity(struct Entities *entities, struct Entity *entity); 34 | void FreeEntities(struct Entities *entities); 35 | void DrawEntities(struct RastPort *rastPort, struct Entities *entities); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /extras.c: -------------------------------------------------------------------------------- 1 | #include "extras.h" 2 | 3 | VOID IntToString(int n, char *s, int length) 4 | { 5 | } 6 | 7 | VOID itoas(int n, char *s) 8 | { 9 | int i = 0, j; 10 | int sign = FALSE; 11 | 12 | if(n < 0) 13 | { 14 | sign = TRUE; 15 | n = -n; 16 | } 17 | 18 | do 19 | { 20 | s[i++] = (n % 10) + '0'; 21 | }while(n /=10); 22 | 23 | if(sign) 24 | { 25 | s[i++] = '-'; 26 | } 27 | 28 | for(j = 0; j < i; j++) 29 | { 30 | if(s[j] < '0' || s[j] > '9') 31 | s[j] = '0'; 32 | } 33 | s[i] = EOS; 34 | reverse(s); 35 | 36 | } 37 | 38 | VOID reverse(char *s) 39 | { 40 | int c, i, j; 41 | 42 | for(i = 0, j = strlen(s) - 1; i < j; i++, j--) 43 | { 44 | c = s[i]; 45 | s[i] = s[j]; 46 | s[j] = c; 47 | } 48 | } -------------------------------------------------------------------------------- /extras.h: -------------------------------------------------------------------------------- 1 | #include "exec/types.h" 2 | 3 | #define EOS '\0' 4 | #define FALSE 0 5 | #define TRUE 1 6 | 7 | VOID IntToString(int n, char *s, int length); 8 | VOID itoas(int n, char *s); 9 | 10 | VOID reverse(char *s); -------------------------------------------------------------------------------- /fontGfx.c: -------------------------------------------------------------------------------- 1 | #include "fontGfx.h" 2 | #define MAX_CHARS 96 3 | #define WIDTHHEIGHT 8 4 | UBYTE characters[MAX_CHARS][WIDTHHEIGHT]; 5 | 6 | void SetFontGraphicData(struct RastPort *rastport) 7 | { 8 | ULONG value; 9 | int i, j; 10 | struct TextFont *font; 11 | font = rastport->Font; 12 | 13 | /*get font characters*/ 14 | for(j = 0; j < MAX_CHARS/sizeof(ULONG); j++) 15 | { 16 | for(i = 0; i < WIDTHHEIGHT; i++) 17 | { 18 | value = (ULONG)((font->tf_CharData[ j + (font->tf_Modulo/sizeof(ULONG))*i ])); 19 | characters[j*sizeof(ULONG)][i] = (value & 0xff000000)>>24; 20 | characters[j*sizeof(ULONG)+1][i] = (value & 0x00ff0000)>>16; 21 | characters[j*sizeof(ULONG)+2][i] = (value & 0x0000ff00)>>8; 22 | characters[j*sizeof(ULONG)+3][i] = (value & 0x000000ff); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /fontGfx.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | void SetFontGraphicData(struct RastPort *); 7 | -------------------------------------------------------------------------------- /gels.c: -------------------------------------------------------------------------------- 1 | #include "exec/types.h" 2 | #include "exec/exec.h" 3 | #include "graphics/gfx.h" 4 | #include "graphics/gfxmacros.h" 5 | #include "graphics/gfxbase.h" 6 | 7 | #include "graphics/view.h" 8 | #include "graphics/rastport.h" 9 | #include "graphics/gels.h" 10 | #include "graphics/collide.h" 11 | 12 | #include "gels.h" 13 | 14 | struct GelsInfo GelsInfo; 15 | struct VSprite Start, End; 16 | WORD *LastColors[8] = {0,0,0,0,0,0,0,0}; 17 | WORD NextLines[8] = {0,0,0,0,0,0,0,0}; 18 | struct collTable collTable; 19 | 20 | VOID CreateGELS(struct RastPort * rastPort, int width, int height) 21 | { 22 | BltClear(&Start, sizeof(struct VSprite), 0); 23 | BltClear(&End, sizeof(struct VSprite), 0); 24 | BltClear(&GelsInfo, sizeof(struct GelsInfo), 0); 25 | BltClear(&collTable, sizeof(struct collTable), 0); 26 | 27 | GelsInfo.sprRsrvd = 0x80; 28 | GelsInfo.nextLine = NextLines; 29 | GelsInfo.lastColor = LastColors; 30 | GelsInfo.collHandler = &collTable; 31 | GelsInfo.leftmost = 0; 32 | GelsInfo.rightmost = width-1; 33 | GelsInfo.topmost = 0; 34 | GelsInfo.bottommost = height-1; 35 | 36 | InitGels(&Start, &End, &GelsInfo); 37 | rastPort->GelsInfo = &GelsInfo; 38 | 39 | SetCollision(0, BorderController, &GelsInfo); 40 | } 41 | 42 | VOID SetGelsInfo(struct RastPort * RastPort) 43 | { 44 | RastPort->GelsInfo = &GelsInfo; 45 | } 46 | 47 | VOID CreateBob(struct VSprite *vsbob, struct Bob *bob, int x , int y, IMAGE *image) 48 | { 49 | BltClear(vsbob, sizeof(struct VSprite), 0); 50 | BltClear(bob, sizeof(struct Bob), 0); 51 | bob->SaveBuffer = 0; 52 | bob->DBuffer = 0; 53 | vsbob->CollMask = 0; 54 | vsbob->BorderLine = 0; 55 | 56 | vsbob->Width = image->Width / 16; 57 | vsbob->Height = image->Height; 58 | vsbob->Depth = image->Depth; 59 | vsbob->ImageData = image->ImageData; 60 | vsbob->X = x; 61 | vsbob->Y = y; 62 | vsbob->PlaneOnOff = 0x0; 63 | vsbob->PlanePick = 0xff; 64 | vsbob->Flags = OVERLAY; 65 | vsbob->MeMask = 0x0; 66 | vsbob->HitMask = 0x0; 67 | 68 | bob->Flags = 0; 69 | bob->BobVSprite = vsbob; 70 | vsbob->VSBob = bob; 71 | } 72 | 73 | VOID SetCollisionBob(struct VSprite *vsbob, struct Bob *bob, IMAGE *image) 74 | { 75 | WORD *Borderline = (WORD*)AllocMem(sizeof(WORD) * (image->Width/16), MEMF_CLEAR|MEMF_CHIP); 76 | WORD *CollisionMask = (WORD*)AllocMem(RASSIZE(image->Width, image->Height), MEMF_CLEAR|MEMF_CHIP); 77 | 78 | vsbob->CollMask = CollisionMask; 79 | vsbob->BorderLine = Borderline; 80 | 81 | bob->ImageShadow = CollisionMask; 82 | 83 | InitMasks(vsbob); 84 | } 85 | VOID SetDoubleBufferBob(struct VSprite *vsbob, struct Bob *bob, IMAGE *image) 86 | { 87 | WORD *SaveBuffer = (WORD *)AllocMem(RASSIZE(image->Width, image->Height)*(image->Depth), MEMF_CLEAR|MEMF_CHIP); 88 | WORD *DBufBuffer = (WORD *)AllocMem(RASSIZE(image->Width, image->Height)*(image->Depth), MEMF_CLEAR|MEMF_CHIP); 89 | struct DBufPacket *DBufPackets = (struct DBufPacket *)AllocMem(sizeof(struct DBufPacket), MEMF_CLEAR|MEMF_CHIP); 90 | 91 | vsbob->Flags |= SAVEBACK; 92 | 93 | bob->SaveBuffer = SaveBuffer; 94 | bob->DBuffer = DBufPackets; 95 | DBufPackets->BufBuffer = DBufBuffer; 96 | } 97 | VOID DeleteBob(struct VSprite *vsbob, struct Bob *bob) 98 | { 99 | /*if(vsbob->ImageData !=0) 100 | { 101 | FreeMem(vsbob->ImageData, RASSIZE(vsbob->Width*16, vsbob->Height)*vsbob->Depth); 102 | }*/ 103 | 104 | if(vsbob->CollMask !=0) 105 | { 106 | FreeMem(vsbob->CollMask, RASSIZE(vsbob->Width *16, vsbob->Height)); 107 | } 108 | 109 | if(vsbob->BorderLine != 0) 110 | { 111 | FreeMem(vsbob->BorderLine, vsbob->Width * sizeof(UWORD)); 112 | } 113 | 114 | 115 | if(bob->SaveBuffer !=0) 116 | { 117 | FreeMem(bob->SaveBuffer, RASSIZE(vsbob->Width *16, vsbob->Height)*(vsbob->Depth)); 118 | } 119 | 120 | if(bob->DBuffer != 0) 121 | { 122 | if(bob->DBuffer->BufBuffer != 0) 123 | { 124 | FreeMem(bob->DBuffer->BufBuffer, RASSIZE(vsbob->Width *16, vsbob->Height)*(vsbob->Depth)); 125 | } 126 | FreeMem(bob->DBuffer, sizeof(struct DBufPacket)); 127 | } 128 | 129 | } 130 | 131 | VOID CreateVSprite(struct VSprite *vspr, int x, int y, IMAGE *image, UWORD *colours) 132 | { 133 | BltClear(vspr, sizeof(struct VSprite), 0); 134 | vspr->CollMask = 0; 135 | vspr->BorderLine = 0; 136 | 137 | vspr->Width = 1; 138 | vspr->Height = image->Height; 139 | vspr->Flags = VSPRITE; 140 | vspr->Depth = 2; 141 | vspr->ImageData = image->ImageData; 142 | vspr->SprColors = colours; 143 | vspr->X = x; 144 | vspr->Y = y; 145 | 146 | vspr->MeMask = 0x0; 147 | vspr->HitMask = 0x0; 148 | } 149 | VOID SetCollisionVSprite(struct VSprite *vspr, IMAGE *image) 150 | { 151 | WORD *Borderline = (WORD*)AllocMem(sizeof(WORD) * (image->Width/16), MEMF_CLEAR|MEMF_CHIP); 152 | WORD *CollisionMask = (WORD*)AllocMem(RASSIZE(image->Width, image->Height), MEMF_CLEAR|MEMF_CHIP); 153 | 154 | vspr->CollMask = CollisionMask; 155 | vspr->BorderLine = Borderline; 156 | 157 | InitMasks(vspr); 158 | } 159 | VOID DeleteVSprite(struct VSprite *vspr) 160 | { 161 | if(vspr->ImageData !=0) 162 | { 163 | FreeMem(vspr->ImageData, RASSIZE(vspr->Width*16, vspr->Height)*vspr->Depth); 164 | } 165 | 166 | if(vspr->CollMask !=0) 167 | { 168 | FreeMem(vspr->CollMask, RASSIZE(vspr->Width *16, vspr->Height)); 169 | } 170 | 171 | if(vspr->BorderLine != 0) 172 | { 173 | FreeMem(vspr->BorderLine, vspr->Width * sizeof(UWORD)); 174 | } 175 | } 176 | VOID BorderController(struct VSprite vsprite, BYTE Border) 177 | { 178 | /*do nothing at the moment*/ 179 | } -------------------------------------------------------------------------------- /gels.h: -------------------------------------------------------------------------------- 1 | #define GELS_H 2 | 3 | #ifndef MY_IMAGE 4 | #define MY_IMAGE 5 | typedef struct MyImage 6 | { 7 | UWORD Width; 8 | UWORD Height; 9 | UWORD Depth; 10 | UWORD * ImageData; 11 | }IMAGE; 12 | 13 | 14 | 15 | #endif 16 | 17 | VOID CreateGELS(struct RastPort *RastPort, int width, int height); 18 | VOID CreateBob(struct VSprite *vsbob, struct Bob * bob, int x, int y, IMAGE *image); 19 | VOID SetCollisionBob(struct VSprite *vsbob, struct Bob *bob, IMAGE *image); 20 | VOID SetDoubleBufferBob(struct VSprite *vsbob, struct Bob *bob, IMAGE *image); 21 | VOID DeleteBob(struct VSprite *vsbob, struct Bob *bob); 22 | VOID SetGelsInfo(struct RastPort *RastPort); 23 | 24 | VOID CreateVSprite(struct VSprite *vspr, int x, int y, IMAGE *image, UWORD *colours); 25 | VOID SetCollisionVSprite(struct VSprite *vspr, IMAGE *image); 26 | VOID DeleteVSprite(struct VSprite *vspr); 27 | VOID BorderController(struct VSprite, BYTE Border); -------------------------------------------------------------------------------- /gpInput.c: -------------------------------------------------------------------------------- 1 | #include "gpInput.h" 2 | 3 | struct InputEvent *game_event; 4 | struct IOStdReq *game_io_msg = NULL; 5 | struct MsgPort *game_msg_port = NULL; 6 | 7 | struct GamePortTrigger joyTrigger = 8 | { 9 | GPTF_UPKEYS + GPTF_DOWNKEYS, 10 | 0, 11 | XMOVE, 12 | YMOVE 13 | }; 14 | 15 | UBYTE hertz = 50; 16 | SHORT codeval,error; 17 | BOOL UnitOpened, DeviceOpened = FALSE; 18 | 19 | /*need to set hertz prior to calling*/ 20 | void BeginGameDevice() 21 | { 22 | if(!(game_msg_port = CreatePort("RKM_game_port", 0))) 23 | cleanexit("Can't create Port\n", RETURN_FAIL); 24 | 25 | if(!(game_io_msg = CreateStdIO(game_msg_port))) 26 | cleanexit("cant create IO request\n", RETURN_FAIL); 27 | 28 | if(error=OpenDevice("gameport.device", 1, game_io_msg, 0)) 29 | cleanexit("can't open gameport.device\n", RETURN_FAIL); 30 | else DeviceOpened = TRUE; 31 | 32 | game_event = (struct InputEvent *)AllocMem(sizeof(struct InputEvent), MEMF_PUBLIC); 33 | 34 | if(!(set_controller_type(GPCT_RELJOYSTICK))) 35 | cleanexit("gameport unit in use?\n", RETURN_FAIL); 36 | 37 | /*set trigger conditions*/ 38 | set_trigger_conditions(&joyTrigger); 39 | flush_buffer(); 40 | 41 | send_read_request(); 42 | } 43 | 44 | 45 | BOOL set_controller_type(BYTE type) 46 | { 47 | BOOL success = FALSE; 48 | BYTE controller_type = 0; 49 | Forbid(); 50 | game_io_msg->io_Command = GPD_ASKCTYPE; 51 | game_io_msg->io_Length = 1; 52 | game_io_msg->io_Flags = IOF_QUICK; 53 | game_io_msg->io_Data = (APTR)&controller_type; 54 | DoIO(game_io_msg); 55 | 56 | /*get the controller if not in use*/ 57 | if(controller_type == GPCT_NOCONTROLLER) 58 | { 59 | game_io_msg->io_Command = GPD_SETCTYPE; 60 | game_io_msg->io_Flags = IOF_QUICK; 61 | game_io_msg->io_Length = 1; 62 | game_io_msg->io_Data = (APTR)&type; 63 | DoIO(game_io_msg); 64 | success = TRUE; 65 | UnitOpened = TRUE; 66 | } 67 | Permit(); 68 | return success; 69 | } 70 | 71 | void set_trigger_conditions(struct GamePortTrigger *gpt) 72 | { 73 | joyTrigger.gpt_Timeout = (UWORD)hertz * 20; 74 | 75 | game_io_msg->io_Command = GPD_SETTRIGGER; 76 | game_io_msg->io_Length = (LONG)sizeof(struct GamePortTrigger); 77 | game_io_msg->io_Data = (APTR)gpt; 78 | DoIO(game_io_msg); 79 | } 80 | 81 | void check_move(int *x , int *y) 82 | { 83 | WORD xmove, ymove; 84 | xmove = game_event->ie_X; 85 | ymove = game_event->ie_Y; 86 | 87 | if(xmove != 0 || ymove !=0) 88 | { 89 | if(xmove == 1 && ymove == 0) 90 | { 91 | *x = *x + 1; 92 | } 93 | if(xmove == -1 && ymove == 0) 94 | { 95 | *x = *x - 1; 96 | } 97 | if(xmove == 0 && ymove == 1) 98 | { 99 | *y = *y + 1; 100 | } 101 | if(xmove == 0 && ymove == -1) 102 | { 103 | *y = *y - 1; 104 | } 105 | 106 | if(xmove == 1 && ymove == 1) 107 | { 108 | *x = *x + 1; 109 | *y = *y + 1; 110 | } 111 | if(xmove == -1 && ymove == 1) 112 | { 113 | *x = *x - 1; 114 | *y = *y + 1; 115 | } 116 | if(xmove == 1 && ymove == -1) 117 | { 118 | *x = *x + 1; 119 | *y = *y - 1; 120 | } 121 | if(xmove == -1 && ymove == -1) 122 | { 123 | *x = *x - 1; 124 | *y = *y - 1; 125 | } 126 | } 127 | game_event->ie_X = 0; 128 | game_event->ie_Y = 0; 129 | } 130 | 131 | void flush_buffer() 132 | { 133 | game_io_msg->io_Command = CMD_CLEAR; 134 | game_io_msg->io_Flags = IOF_QUICK; 135 | DoIO(game_io_msg); 136 | } 137 | 138 | void send_read_request() 139 | { 140 | game_io_msg->io_Command = GPD_READEVENT; 141 | game_io_msg->io_Length = sizeof(struct InputEvent); 142 | game_io_msg->io_Data = (APTR)game_event; 143 | SendIO(game_io_msg); /*async*/ 144 | } 145 | 146 | void free_gp_unit() 147 | { 148 | BYTE type = GPCT_NOCONTROLLER; 149 | game_io_msg->io_Command = GPD_SETCTYPE; 150 | game_io_msg->io_Flags = IOF_QUICK; 151 | game_io_msg->io_Length = 1; 152 | game_io_msg->io_Data = (APTR)&type; 153 | DoIO(game_io_msg); 154 | } 155 | void cleanup(void) 156 | { 157 | if(DeviceOpened) CloseDevice(game_io_msg); 158 | if(game_io_msg) DeleteStdIO(game_io_msg); 159 | if(game_msg_port) DeletePort(game_msg_port); 160 | if(game_event) FreeMem(game_event, sizeof(struct InputEvent)); 161 | } 162 | 163 | void cleanexit(UBYTE *msg, LONG er) 164 | { 165 | if(*msg) printf(msg); 166 | if(UnitOpened) free_gp_unit(); 167 | cleanup(); 168 | exit(er); 169 | } -------------------------------------------------------------------------------- /gpInput.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define XMOVE 1 10 | #define YMOVE 1 11 | 12 | BOOL set_controller_type(BYTE); 13 | void set_trigger_conditions(struct GamePortTrigger *); 14 | void send_read_request(void); 15 | void check_move(int *x, int *y); 16 | void flush_buffer(void); 17 | void free_gp_unit(void); 18 | void cleanup(void); 19 | void cleanexit(UBYTE *, LONG); 20 | void GetJoyStick(); 21 | 22 | void BeginGameDevice(); -------------------------------------------------------------------------------- /iffLoad.c: -------------------------------------------------------------------------------- 1 | #include "exec/types.h" 2 | #include "exec/exec.h" 3 | #include "proto/dos.h" 4 | #include "graphics/gfx.h" 5 | #include "iffLoad.h" 6 | 7 | 8 | VOID LoadBitMap(UBYTE *file, struct BitMap *mybm) 9 | { 10 | int i, bytes, x, y, counter, byte, plane; 11 | unsigned char code, temp; 12 | BPTR filePtr; 13 | CHUNK chunk; 14 | BODY Body; 15 | char id[2]; 16 | 17 | unsigned char * buffer; 18 | 19 | filePtr = Open(file, (LONG)MODE_OLDFILE); 20 | if(filePtr == 0) 21 | { 22 | printf("Could not open file\n"); 23 | Close(filePtr); 24 | exit(1); 25 | } 26 | 27 | Seek(filePtr, 0, OFFSET_BEGINNING); 28 | Read(filePtr, (VOID *)&chunk, sizeof(CHUNK)); 29 | 30 | while(id[0] != 'B' && id[1] != 'O') 31 | { 32 | Read(filePtr, (VOID *)&id, 2); 33 | } 34 | Body.ChunkId[0] = 'B'; 35 | Body.ChunkId[1] = 'O'; 36 | Read(filePtr, (VOID *)&Body.ChunkId[2], 2); 37 | Read(filePtr, (VOID *)&Body.Size, 4); 38 | 39 | 40 | 41 | bytes = chunk.BitMapHeader.Width / 8; 42 | counter = 0; 43 | byte = 0; 44 | 45 | /*if bitmap has been initialise already, i dont want to do it again 46 | I 'll check this by checking the depth. Anything above 6 should me..not initialised*/ 47 | if(mybm->Depth > 6) 48 | { 49 | InitBitMap(mybm, chunk.BitMapHeader.BitPlanes, chunk.BitMapHeader.Width, chunk.BitMapHeader.Height); 50 | 51 | for(plane = 0; plane < mybm->Depth; plane++) 52 | { 53 | if((mybm->Planes[plane] = (PLANEPTR)AllocRaster(mybm->BytesPerRow * 8, mybm->Rows)) == NULL) 54 | { 55 | printf("Cannot allocate memory for bitmap.\n"); 56 | exit(1000); 57 | } 58 | BltClear((UBYTE*)mybm->Planes[plane], RASSIZE(mybm->BytesPerRow * 8, mybm->Rows), 0); 59 | } 60 | } 61 | 62 | for(y = 0; y < mybm->Rows; y++) 63 | { 64 | for(x = 0; x < mybm->Depth; x++) 65 | { 66 | buffer = &mybm->Planes[x][y * mybm->BytesPerRow]; 67 | counter = 0; 68 | while(counter < mybm->BytesPerRow) 69 | { 70 | Read(filePtr, (unsigned char *)&code, 1); 71 | 72 | if(code < 128) 73 | { 74 | Read(filePtr, (unsigned char *)&buffer[counter], (code + 1)); 75 | counter = (counter + code + 1); 76 | } 77 | else if(code > 128) 78 | { 79 | Read(filePtr, (unsigned char *)&temp, 1); 80 | for(i = counter; i < (counter + 257 - code); i++) 81 | { 82 | buffer[i] = temp; 83 | } 84 | counter = counter + 257-code; 85 | } 86 | else 87 | { 88 | } 89 | } 90 | } 91 | } 92 | 93 | Close(filePtr); 94 | } 95 | 96 | IMAGE GetImage(struct BitMap *BitMap, UWORD x1, UWORD y1, UWORD x2, UWORD y2) 97 | { 98 | IMAGE image; 99 | UWORD *ImageData, *myHelper; 100 | WORD plane, x, y, width, xOffset; 101 | width = (x2 - x1) / 16; /*width of image in WORDS*/ 102 | xOffset = x1/8; /*offset from left of image in bytes*/ 103 | 104 | /*setup IMAGE struct*/ 105 | image.Height = y2 - y1; 106 | image.Width = x2 - x1; 107 | image.Depth = BitMap->Depth; 108 | 109 | /*allocate CHIP memory for ImageData*/ 110 | ImageData = (UWORD *)AllocMem(RASSIZE(image.Width, image.Height) * image.Depth, MEMF_CHIP|MEMF_CLEAR); 111 | 112 | myHelper = ImageData; 113 | 114 | for(plane = 0; plane < BitMap->Depth; plane++) 115 | { 116 | for(y = y1; y < y2; y++) 117 | { 118 | for(x = 0; x < width; x++) 119 | { 120 | *myHelper |= BitMap->Planes[plane][y * BitMap->BytesPerRow + xOffset + (x*2)]; 121 | *myHelper = *myHelper << 8; 122 | *myHelper |= BitMap->Planes[plane][y * BitMap->BytesPerRow + xOffset + 1 + (x*2)]; 123 | myHelper++; 124 | } 125 | } 126 | } 127 | 128 | image.ImageData = ImageData; 129 | 130 | return image; 131 | } 132 | 133 | VOID DeleteBitMap(struct BitMap *bm) 134 | { 135 | WORD plane = 0; 136 | for(plane = 0; plane < bm->Depth; plane++) 137 | { 138 | FreeRaster(bm->Planes[plane], bm->BytesPerRow * 8, bm->Rows); 139 | } 140 | } 141 | 142 | 143 | -------------------------------------------------------------------------------- /iffLoad.h: -------------------------------------------------------------------------------- 1 | #define IFFLOAD_H 2 | 3 | #ifndef TYPES 4 | #define TYPES 5 | typedef struct _ColorMapEntry 6 | { 7 | BYTE Red; 8 | BYTE Green; 9 | BYTE Blue; 10 | }CMAPENTRY; 11 | 12 | typedef struct _ColorMapChunk 13 | { 14 | char ChunkId[4]; 15 | LONG Size; 16 | /*CMAPENTRY Map[16];*/ 17 | APTR Map; 18 | }CMAP; 19 | 20 | typedef struct _BitMapHeader 21 | { 22 | char ChunkId[4]; 23 | LONG Size; 24 | UWORD Width; 25 | UWORD Height; 26 | UWORD Left; 27 | UWORD Top; 28 | BYTE BitPlanes; 29 | BYTE Masking; 30 | BYTE Compression; 31 | BYTE Padding; 32 | UWORD Transparency; 33 | BYTE XAspectRatio; 34 | BYTE YAspectRatio; 35 | UWORD PageWidth; 36 | UWORD PageHeight; 37 | }BMHD; 38 | 39 | typedef struct _BodyChunk 40 | { 41 | char ChunkId[4]; 42 | LONG Size; 43 | /*BYTE ImageData[];*/ 44 | /*unsigned char *ImageData;*/ 45 | }BODY; 46 | 47 | typedef struct _Chunk 48 | { 49 | char ChunkId[4]; 50 | LONG Size; 51 | char TypeID[4]; 52 | BMHD BitMapHeader; 53 | /*CMAP CMap;*/ 54 | /*BODY Body;*/ 55 | }CHUNK; 56 | 57 | #define MY_IMAGE 58 | typedef struct MyImage 59 | { 60 | UWORD Width; 61 | UWORD Height; 62 | UWORD Depth; 63 | UWORD * ImageData; 64 | }IMAGE; 65 | 66 | #endif 67 | 68 | VOID LoadBitMap(UBYTE *file, struct BitMap *BitMap); 69 | VOID DeleteBitMap(struct BitMap *bitmap); 70 | IMAGE GetImage(struct BitMap *bitmap, UWORD x1, UWORD y1, UWORD x2, UWORD y2); -------------------------------------------------------------------------------- /keyInput.c: -------------------------------------------------------------------------------- 1 | #include "keyInput.h" 2 | 3 | int GetKey(int *pressed) 4 | { 5 | int i,v; 6 | struct IOStdReq *keyRequest; 7 | struct MsgPort *keyPort; 8 | UBYTE *keyMatrix; 9 | 10 | if(keyPort=CreatePort(NULL,NULL)) 11 | { 12 | if(keyRequest = (struct IOStdReq *)CreateExtIO(keyPort, sizeof(struct IOStdReq))) 13 | { 14 | if(!OpenDevice("keyboard.device", NULL, (struct IORequest *)keyRequest, NULL)) 15 | { 16 | if (keyMatrix =AllocMem(16, MEMF_PUBLIC|MEMF_CLEAR)) 17 | { 18 | keyRequest->io_Command = KBD_READMATRIX; 19 | keyRequest->io_Data = (APTR)keyMatrix; 20 | keyRequest->io_Length = 13; 21 | DoIO((struct IORequest*)keyRequest); 22 | } 23 | 24 | } 25 | CloseDevice((struct IORequest *)keyRequest); 26 | } 27 | DeleteExtIO((struct IORequest *)keyRequest); 28 | } 29 | DeletePort(keyPort); 30 | #ifdef ONEPRESS 31 | if(keyMatrix[*pressed/8] == 0) 32 | *pressed = 0; 33 | #endif 34 | for(i = 0; i < 13; i++) 35 | { 36 | if(keyMatrix[i] > 0) 37 | { 38 | v = i * 8; 39 | while(keyMatrix[i] != 0) 40 | { 41 | keyMatrix[i] >>= 1; 42 | v++; 43 | } 44 | FreeMem(keyMatrix, 16); 45 | #ifdef ONEPRESS 46 | if(v-1 == *pressed) 47 | { 48 | return 0; 49 | } 50 | #endif 51 | *pressed = v-1; 52 | return v-1; 53 | } 54 | } 55 | FreeMem(keyMatrix, 16); 56 | return 0; 57 | } -------------------------------------------------------------------------------- /keyInput.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define ONEPRESS 1 9 | 10 | /*keyboard defines*/ 11 | #define ESC 0x45 12 | #define L_SHIFT 0x60 13 | #define R_SHIFT 0x61 14 | #define CTL 0x63 15 | #define ALT 0x64 16 | #define BACKSPACE 0x41 17 | #define KB_RTN 0x44 18 | #define TAB 0x42 19 | 20 | #define KB_1 0x01 21 | #define KB_2 0x02 22 | #define KB_3 0x03 23 | #define KB_4 0x04 24 | #define KB_5 0x05 25 | #define KB_6 0x06 26 | #define KB_7 0x07 27 | #define KB_8 0x08 28 | #define KB_9 0x09 29 | #define KB_0 0x0A 30 | 31 | /*keypad defines*/ 32 | #define KP_RTN 0x44 33 | 34 | #define KP_1 0x1D 35 | #define KP_2 0x1E 36 | #define KP_3 0x1F 37 | #define KP_4 0x2D 38 | #define KP_5 0x2E 39 | #define KP_6 0x2F 40 | #define KP_7 0x3D 41 | #define KP_8 0x3E 42 | #define KP_9 0x3F 43 | #define KP_0 0x0F 44 | 45 | #define UP 0x4C 46 | #define DOWN 0x4D 47 | #define LEFT 0x4F 48 | #define RIGHT 0x4E 49 | 50 | int GetKey(int *pressed); --------------------------------------------------------------------------------