예제 #1
0
        private unsafe void DrawBitmap(int *p, bool gammaCorrection, int layer, bool bkgrnd, int bgndColor, int borderXSize, int borderYSize, int line, int width, int height)
        {
            // Bitmap Controller is located at $AF:0100 and $AF:0108
            int  regAddr = MemoryMap.BITMAP_CONTROL_REGISTER_ADDR - MemoryMap.VICKY_BASE_ADDR + layer * 8;
            byte reg     = VICKY.ReadByte(regAddr);

            if ((reg & 0x01) == 00)
            {
                return;
            }
            byte lutIndex = (byte)((reg >> 1) & 7);  // 8 possible LUTs

            int bitmapAddress = VICKY.ReadLong(regAddr + 1);
            int xOffset       = VICKY.ReadWord(regAddr + 4);
            int yOffset       = VICKY.ReadWord(regAddr + 6);

            int  colorVal      = 0;
            int  offsetAddress = bitmapAddress + line * width;
            int  pixelOffset   = line * STRIDE;
            int *ptr           = p + pixelOffset;
            int  col           = borderXSize;

            //byte pixVal = 0;

            byte[] pixVals = new byte[width];
            VRAM.CopyIntoBuffer(offsetAddress, pixVals, 0, width);
            while (col < width - borderXSize)
            {
                //pixVal = VRAM.ReadByte(offsetAddress + col);
                colorVal   = pixVals[col] == 0 ? bgndColor : GetLUTValue(lutIndex, pixVals[col], gammaCorrection);
                ptr[col++] = colorVal;
            }
        }
예제 #2
0
파일: Gpu.cs 프로젝트: dwsJason/FoenixIDE
        private int GetCharPos(int row, int col)
        {
            if (RAM == null)
            {
                return(0);
            }
            int baseAddress = RAM.ReadLong(MemoryMap.SCREENBEGIN);

            return(baseAddress + row * COLS_PER_LINE + col);
        }
예제 #3
0
파일: Gpu.cs 프로젝트: dwsJason/FoenixIDE
        private void DrawTiles(ref BitmapData bd, int layer, int bitmapWidth, bool bkgrnd)
        {
            // There are four possible tilesets to choose from
            int addrTileset = MemoryMap.TILE_CONTROL_REGISTER_ADDR + layer * 8;
            int reg         = VICKY.ReadByte(addrTileset - MemoryMap.VICKY_BASE_ADDR);

            // if the set is not enabled, we're done.
            if ((reg & 0x01) == 00)
            {
                return;
            }
            // This is hard coded for now
            int  lines    = 52;
            int  lutIndex = (reg & 14) >> 1; // 8 possible LUTs
            bool striding = (reg & 0x80) == 0x80;

            int tilesetAddress = VICKY.ReadLong(addrTileset + 1 - MemoryMap.VICKY_BASE_ADDR);
            int strideX        = striding ? 256 : VICKY.ReadWord(addrTileset + 4 - MemoryMap.VICKY_BASE_ADDR);
            int strideY        = VICKY.ReadWord(addrTileset + 6 - MemoryMap.VICKY_BASE_ADDR);

            // Now read the tilemap
            int    tilemapAddress = 0xAF5000 + 0x800 * layer;
            IntPtr p = bd.Scan0;

            int colOffset   = bkgrnd ? (80 - ColumnsVisible) / 2 * charWidth / tileSize: 0;
            int lineOffset  = bkgrnd ? (60 - lines) / 2 * charHeight / tileSize : 0;
            int borderXSize = VICKY.ReadByte(0xAF_0008 - MemoryMap.VICKY_BASE_ADDR);
            int borderYSize = VICKY.ReadByte(0xAF_0009 - MemoryMap.VICKY_BASE_ADDR);

            for (int tileRow = lineOffset; tileRow < (30 - lineOffset); tileRow++)
            {
                if (tileRow * 16 < borderYSize || tileRow * 16 > (480 - borderYSize))
                {
                    continue;
                }
                for (int tileCol = colOffset; tileCol < (40 - colOffset); tileCol++)
                {
                    if (tileCol * 16 < borderXSize || (tileCol + 1) * 16 > (640 - borderXSize))
                    {
                        continue;
                    }
                    int tile       = VICKY.ReadByte(tilemapAddress + tileCol + tileRow * 64 - MemoryMap.VICKY_BASE_ADDR);
                    int pixelIndex = 0;
                    int value      = 0;

                    // Tiles are 16 x 16
                    for (int line = 0; line < 16; line++)
                    {
                        int offset = tilesetAddress + ((tile / 16) * 256 * 16 + (tile % 16) * 16) + line * strideX;
                        for (int col = 0; col < 16; col++)
                        {
                            // Lookup the pixel in the tileset
                            pixelIndex = VRAM.ReadByte(offset + col);
                            if (pixelIndex != 0)
                            {
                                value = (int)graphicsLUT[lutIndex * 256 + pixelIndex];
                                if (gammaCorrection != null)
                                {
                                    //value = (int)((blue << 16) + (green << 8) + red + 0xFF000000);
                                    value = (int)((gammaCorrection[(value & 0x00FF0000) >> 0x10] << 0x10) +
                                                  (gammaCorrection[0x100 + ((value & 0x0000FF00) >> 0x08)] << 0x08) +
                                                  (gammaCorrection[0x200 + (value & 0x000000FF)]) + 0xFF000000);
                                }

                                System.Runtime.InteropServices.Marshal.WriteInt32(p, (line * bitmapWidth + col + tileCol * 16 + tileRow * 16 * 640) * 4, value);
                            }
                        }
                    }
                }
            }
        }