示例#1
0
        public void ReadByte_FileWithData_ReturnFirstByte()
        {
            // Arrange
            const int    expectedResult  = 0x31;
            IInputStream fileInputStream = new FileInputStream($"{TestFilesPath}/FileWithData.txt");

            // Act
            int result = fileInputStream.ReadByte();

            fileInputStream.Dispose();

            // Assert
            Assert.Equal(expectedResult, result);
        }
示例#2
0
        public void ReadByte_FileIsEmpty_ReturnEndOfStreamIntCode()
        {
            // Arrange
            const int    endOfFileCode   = -1;
            IInputStream fileInputStream = new FileInputStream($"{TestFilesPath}/EmptyFile.txt");

            // Act
            int result = fileInputStream.ReadByte();

            fileInputStream.Dispose();

            // Assert
            Assert.Equal(endOfFileCode, result);
        }
示例#3
0
        // Processor wants to read data or status:
        public override byte Read()
        {
            byte  b;
            Int32 Byte;

            if ((Address & 0x0001) == 0x0001)
            {
                // Read received data:
                switch (mode)
                {
                case IO_MODE_6820_TAPE:
                    timer.Start();
                    ResetFlag(ACIA_STATUS_RDRF);
                    if (line < Lines.Length)
                    {
                        if (pos > Lines[line].Length - 1)
                        {
                            if (Lines[line] == "RUN")
                            {
                                // Special treatment.
                                // People use to put "RUN" at end of listing in order to run the app,
                                // folloed by on last line containing only one space.
                                // The manual states procedure to use if "RUN" and pace is not inlcuded
                                // in listing only, and the user is told to get back to normal (not load)
                                // mode by pressing space and then enter.
                                // However, this does not work here, so if a "RUN" line is encountered
                                // we must tell keyboard input routine to reset the load:
                                mainPage.CSignetic6502.MemoryBus.Keyboard.loadResetIsNeeded = true;
                            }
                            line++;
                            pos = 0;
                            GC.Collect();
                            return(0x0d);
                        }
                        else
                        {
                            b = (byte)Lines[line][pos++];
                            return(b);
                        }
                    }
                    return(0x00);

                case IO_MODE_6820_MIDI:
                    // If this is the last byte received for now, set flag to indicate 'no data available':
                    if ((byte)(outpointer + 1) == inpointer)
                    {
                        ResetFlag(ACIA_STATUS_RDRF);
                    }
                    return(midiBuffer[outpointer++]);

                case IO_MODE_6820_SERIAL:
                    if (inStream != null)
                    {
                        Byte = inStream.ReadByte();
                        if (Byte > -1)
                        {
                            return((byte)Byte);
                        }
                        else
                        {
                            inStream.Close();
                            inStream = null;
                        }
                    }
                    return(0x00);

                case IO_MODE_6820_FILE:
                    //while (CharNumber >= CurrentFile[LineNumber].Length)
                    //{
                    //    CharNumber = 0;
                    //    LineNumber++;
                    //}
                    //if (LineNumber < CurrentFile.Length)
                    //{
                    //    if (CurrentFile[LineNumber][CharNumber++] != 0x0a)
                    //    {
                    //        return (byte)CurrentFile[LineNumber][CharNumber];
                    //    }
                    //}
                    if (FileInputStream != null)
                    {
                        Byte = FileInputStream.ReadByte();
                        // BASIC uses only 0d for line feeds, remove 0a:
                        if (Byte == 10)
                        {
                            Byte = FileInputStream.ReadByte();
                        }
                        if (Byte > -1)
                        {
                            return((byte)Byte);
                        }
                        else
                        {
                            FileInputStream.Close();
                            FileInputStream = null;
                        }
                    }
                    return(0xff);

                default:
                    return(0xff);
                }
            }
            else
            {
                // Read status:
                switch (mode)
                {
                case IO_MODE_6820_TAPE:
                    if (line < Lines.Length)
                    {
                        return(ACIAStatus);
                    }
                    else
                    {
                        return(0);
                    }

                case IO_MODE_6820_MIDI:
                    if ((ACIAStatus & ACIA_STATUS_TDRE) == ACIA_STATUS_TDRE)
                    {
                        SetFlag(ACIA_STATUS_TDRE);
                        return(ACIAStatus);
                    }
                    else
                    {
                        return(ACIAStatus);
                    }

                case IO_MODE_6820_FILE:
                    return(ACIAStatus);

                case IO_MODE_6820_SERIAL:
                    SetFlag(ACIA_STATUS_TDRE);
                    SetFlag(ACIA_STATUS_RDRF);
                    return(ACIAStatus);

                default:
                    return(0);
                }
            }
        }