Beispiel #1
0
            public byte this[ushort addr]
            {
                get
                {
                    if (addr < ram3k_addr)
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= ram3k_addr && addr < ram4k_addr && ((ram_banks & 0x01) != 0))
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= ram4k_addr && addr < ram8k1_addr)
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= ram8k1_addr && addr < ram8k2_addr && ((ram_banks & 0x02) != 0))
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= ram8k2_addr && addr < ram8k3_addr && ((ram_banks & 0x04) != 0))
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= ram8k3_addr && addr < char_addr && ((ram_banks & 0x08) != 0))
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= char_addr && addr < char_addr + char_rom.Length)
                    {
                        return(char_rom[addr - char_addr]);
                    }
                    else if (addr >= io_addr && addr < io_addr + io_size)
                    {
                        return(0); // io[addr - io_addr];
                    }
                    else if (addr >= cart_addr && addr < basic_addr && ((ram_banks & 0x10) != 0))
                    {
                        return(ram[addr]);
                    }
                    else if (addr >= basic_addr && addr < basic_addr + basic_rom.Length)
                    {
                        return(basic_rom[addr - basic_addr]);
                    }
                    else if (addr >= kernal_addr && addr < kernal_addr + kernal_rom.Length)
                    {
                        return(kernal_rom[addr - kernal_addr]);
                    }
                    else
                    {
                        return(0xFF);
                    }
                }

                set
                {
                    if (addr < ram3k_addr)
                    {
                        ram[addr] = value;
                    }
                    else if (addr >= ram3k_addr && addr < ram4k_addr && ((ram_banks & 0x01) != 0))
                    {
                        ram[addr] = value;
                    }
                    else if (addr >= ram4k_addr && addr < ram8k1_addr)
                    {
                        ram[addr] = value;
                    }
                    else if (addr >= ram8k1_addr && addr < ram8k2_addr && ((ram_banks & 0x02) != 0))
                    {
                        ram[addr] = value;
                    }
                    else if (addr >= ram8k2_addr && addr < ram8k3_addr && ((ram_banks & 0x04) != 0))
                    {
                        ram[addr] = value;
                    }
                    else if (addr >= ram8k3_addr && addr < char_addr && ((ram_banks & 0x08) != 0))
                    {
                        ram[addr] = value;
                    }
                    else if (addr >= io_addr && addr < io_addr + io_size)
                    {
                        //io[addr - io_addr] = value;
                        if (addr == 0x900F) // background/border/inverse
                        {
#if CBM_COLOR
                            bool reverse = (ram[199] != 0);

                            if (reverse)
                            {
                                Console.ForegroundColor = EmuVIC20.ToConsoleColor(value);
                            }
                            else
                            {
                                Console.BackgroundColor = EmuVIC20.ToConsoleColor(value);
                            }
#endif
                        }
                    }
                    else if (addr >= cart_addr && addr < basic_addr && ((ram_banks & 0x10) != 0))
                    {
                        ram[addr] = value;
                    }
                }
            }
        static void Main(string[] args)
        {
            // recommend get basic, kernal, etc. ROM files from a emulator such as https://vice-emu.sourceforge.io/index.html#download
            Emu6502 cbm      = null;
            bool    error    = false;
            int     ram_size = 0;

            Console.Error.WriteLine("6502 Emulator for Windows Console");
            Console.Error.WriteLine("C64, VIC-20, PET, TED, ...");
            Console.Error.WriteLine("");
            Console.Error.WriteLine("simple-emu-c64 version 1.7");
            Console.Error.WriteLine("Copyright (c) 2020 David R. Van Wagner");
            Console.Error.WriteLine("davevw.com");
            Console.Error.WriteLine("Open Source, MIT License");
            Console.Error.WriteLine("github.com/davervw/simple-emu-c64");
            Console.Error.WriteLine("");

            try
            {
                if (args.Length > 2 && args[1].ToLower() == "ram")
                {
                    ram_size = int.Parse(args[2]) * 1024;
                }

                if (args.Length == 0 || args[0].ToLower() == "c64")
                {
                    if (ram_size == 0)
                    {
                        ram_size = 64 * 1024;
                    }
                    if (File.Exists("basic") && File.Exists("kernal") && (!File.Exists("c64\\basic") || !File.Exists("c64\\kernal")))
                    {
                        cbm = new EmuC64(ram_size: ram_size, basic_file: "basic", chargen_file: "c64\\chargen", kernal_file: "kernal");
                    }
                    else
                    {
                        cbm = new EmuC64(ram_size: ram_size, basic_file: "c64\\basic", chargen_file: "c64\\chargen", kernal_file: "c64\\kernal");
                    }

                    if ((args.Length == 2 || args.Length == 4) && (File.Exists(args[args.Length - 1]) || File.Exists(args[args.Length - 1] + ".prg")))
                    {
                        ((EmuC64)cbm).StartupPRG = args[args.Length - 1];
                    }
                }
                else if (args.Length > 0 && args[0].ToLower() == "vic20")
                {
                    cbm = new EmuVIC20(ram_size: ram_size, char_file: "vic20\\chargen", basic_file: "vic20\\basic", kernal_file: "vic20\\kernal");
                }
                else if (args.Length > 0 && args[0].ToLower() == "c16")
                {
                    if (ram_size == 0)
                    {
                        ram_size = 16 * 1024;
                    }
                    cbm = new EmuTED(ram_size: ram_size, basic_file: "ted\\basic", kernal_file: "ted\\kernal");
                }
                else if (args.Length > 0 && args[0].ToLower() == "plus4" || args[0].ToLower() == "ted")
                {
                    if (ram_size == 0)
                    {
                        ram_size = 64 * 1024;
                    }
                    cbm = new EmuTED(ram_size: ram_size, basic_file: "ted\\basic", kernal_file: "ted\\kernal");
                }
                else if (args.Length > 0 && args[0].ToLower() == "pet")
                {
                    if (ram_size == 0)
                    {
                        ram_size = 8 * 1024;
                    }
                    cbm = new EmuPET(ram_size: ram_size, basic_file: "pet\\basic1", edit_file: "pet\\edit1g", kernal_file: "pet\\kernal1");
                }
                else
                {
                    error = true;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                error = true;
            }

            if (error)
            {
                return;
            }
            else if (args.Length == 0) // if no arguments present, then show usage as well
            {
                Console.Error.WriteLine("");
                Console.Error.WriteLine("Usage:");
                Console.Error.WriteLine("  simple-emu-c64                     (no arguments pauses, then starts c64)");
                Console.Error.WriteLine("  simple-emu-c64 help                (shows usage)");
                Console.Error.WriteLine("  simple-emu-c64 [system] {ram #}    (system=[c64|vic20|pet|c16|plus4|ted])");
                Console.Error.WriteLine("  simple-emu-c64 [system] walk [addr 1 ...]");
                Console.Error.WriteLine("");
                Console.WriteLine();
            }

            if (args.Length >= 2 && args[1].ToLower() == "walk")
            {
                if (args.Length == 2)
                {
                    cbm.Walk();
                }
                else
                {
                    Walk6502.Reset();
                    for (int i = 2; i < args.Length; ++i)
                    {
                        Walk6502.Walk(cbm, ParseAddr(args[i]));
                    }
                }
            }
            else
            {
                cbm.ResetRun();
            }
        }