v6502cpp/v6502.cpp

72 lines
1.6 KiB
C++
Raw Normal View History

2013-12-15 06:13:44 +00:00
#include "Emu6502.h"
#include "addressbus.h"
2013-12-14 04:18:50 +00:00
#include <fstream>
2013-12-15 06:13:44 +00:00
#include <iostream>
#include <set>
2013-12-15 06:13:44 +00:00
#include <cstdlib>
2013-12-14 04:18:50 +00:00
2013-12-12 22:05:33 +00:00
int main(int argc, char *argv[]) {
2013-12-13 14:55:19 +00:00
AddressBus mem;
2013-11-26 06:21:17 +00:00
/* Load some test program into memory */
mem.write(0x0200, 0xEA); // NOP
mem.write(0x0201, 0xEA); // NOP
mem.write(0x0202, 0xA9); // LDA #$5A
mem.write(0x0203, 0x5A); //
mem.write(0x0204, 0x85); // STA $88
mem.write(0x0205, 0x88); //
mem.write(0x0206, 0xA9); // LDA #$23
mem.write(0x0207, 0x23); //
2013-11-26 06:21:17 +00:00
mem.write(0x0208, 0xD0); // BNE $0200
mem.write(0x0209, 0xF6); //
mem.write(0xFFFC, 0x02); // RESET --> $0202
mem.write(0xFFFD, 0x02);
2013-11-26 06:09:56 +00:00
2013-12-14 06:04:55 +00:00
std::ifstream if_trans("transistors");
2013-12-15 06:13:44 +00:00
2013-12-14 06:04:55 +00:00
if (!if_trans.is_open()) {
std::cerr << "error opening file: transistors" << std::endl;
exit(EXIT_FAILURE);
}
2013-12-15 06:13:44 +00:00
Emu6502 emu(if_trans, mem);
2013-12-14 06:04:55 +00:00
2013-11-26 06:21:17 +00:00
/* turn on the CPU */
std::cout << "----------------------------------------" << std::endl;
2013-11-26 06:09:56 +00:00
std::cout << "begin power-up..." << std::endl;
2013-12-15 06:13:44 +00:00
emu.powerOn();
std::cout << "end power-up..." << std::endl;
std::cout << "----------------------------------------" << std::endl;
2013-11-26 06:21:17 +00:00
/* run it a bit, before resetting */
2013-11-26 06:09:56 +00:00
std::cout << "some power-up pre-reset cycles..." << std::endl;
for (int i(0); i < 10; ++i) {
2013-12-15 06:13:44 +00:00
emu.tick();
2013-11-26 06:09:56 +00:00
}
std::cout << "----------------------------------------" << std::endl;
2013-11-26 06:09:56 +00:00
2013-11-26 06:21:17 +00:00
/* reset the CPU, and let it run for a little while, then exit */
2013-11-26 06:09:56 +00:00
std::cout << "RESET..." << std::endl;
2013-12-15 06:13:44 +00:00
emu.reset();
2013-11-26 06:21:17 +00:00
for (int i(0); i < 50; ++i) {
2013-12-15 06:13:44 +00:00
emu.tick();
2013-11-26 06:09:56 +00:00
}
2013-12-15 06:13:44 +00:00
return EXIT_SUCCESS;
}