Exemplo n.º 1
0
void 
C64::saveToBuffer(uint8_t **buffer)
{	
	uint8_t *old = *buffer;
		
    debug(3, "Saving internal state...\n");
		
	// Save state of this component
    write8(buffer, warp);
    write8(buffer, alwaysWarp);
    write8(buffer, warpLoad);
	write64(buffer, cycles);
	write32(buffer, (uint32_t)frame);
	write16(buffer, rasterline);
	write32(buffer, (uint32_t)rasterlineCycle);
	write64(buffer, nanoTargetTime);
	
	// Save state of sub components
	cpu->saveToBuffer(buffer);
	vic->saveToBuffer(buffer);
	sid->saveToBuffer(buffer);
	cia1->saveToBuffer(buffer);
	cia2->saveToBuffer(buffer);
	mem->saveToBuffer(buffer);
	keyboard->saveToBuffer(buffer);
    joystick1->saveToBuffer(buffer);
    joystick2->saveToBuffer(buffer);
	iec->saveToBuffer(buffer);
    expansionport->saveToBuffer(buffer);
	floppy->saveToBuffer(buffer);
	
    debug(3, "  C64 state saved (%d bytes)\n", *buffer - old);
    assert(*buffer - old == stateSize());
}
Exemplo n.º 2
0
void 
CPU::loadFromBuffer(uint8_t **buffer) 
{
    uint8_t *old = *buffer;

    chipModel = (ChipModel)read8(buffer);
    
	// Registers and flags
	A = read8(buffer);
	X = read8(buffer);
	Y = read8(buffer);
	PC = read16(buffer);
	PC_at_cycle_0 = read16(buffer);
	SP = read8(buffer);
	N = read8(buffer);
	V = read8(buffer);
	B = read8(buffer);
	D = read8(buffer);
	I = read8(buffer);
	Z = read8(buffer);
	C = read8(buffer);
	
	// Internal state
	opcode = read8(buffer);
	addr_lo = read8(buffer);
	addr_hi = read8(buffer);
	ptr = read8(buffer);
	pc_lo = read8(buffer);
	pc_hi = read8(buffer);
	overflow = (bool)read8(buffer);
	data = read8(buffer);
	
	port = read8(buffer);
	port_direction = read8(buffer);
	external_port_bits = read8(buffer);
	rdyLine = (bool)read8(buffer);
	irqLine = read8(buffer);
	nmiLine = read8(buffer);
	nmiEdge = (bool)read8(buffer);
    interruptsPending = (bool)read8(buffer);
    nextPossibleIrqCycle = read64(buffer);
	nextPossibleNmiCycle = read64(buffer);
	
	errorState = (ErrorState)read8(buffer);
	next = CPU::callbacks[read16(buffer)];
	
	for (unsigned i = 0; i < 256; i++) 
		callStack[i] = read16(buffer);	
	callStackPointer = read8(buffer);
	oldI = read8(buffer);
    
    debug(2, "  CPU state loaded (%d bytes)\n", *buffer - old);
    assert(*buffer - old == stateSize());
}
Exemplo n.º 3
0
void
C64::saveToSnapshot(Snapshot *snapshot)
{
    if (snapshot == NULL)
        return;
    
    snapshot->setTimestamp(time(NULL));
    snapshot->takeScreenshot((uint32_t *)vic.screenBuffer(), isPAL());
    
    snapshot->alloc(stateSize());
    uint8_t *ptr = snapshot->getData();
    saveToBuffer(&ptr);
}
Exemplo n.º 4
0
void
Datasette::saveToBuffer(uint8_t **buffer)
{
    uint8_t *old = *buffer;
    
    VirtualComponent::saveToBuffer(buffer);
    if (size) {
        assert(data != NULL);
        writeBlock(buffer, (uint8_t *)data, size);
    }
    
    if (*buffer - old != stateSize())
        assert(0);
}
Exemplo n.º 5
0
void 
VC1541::saveToBuffer(uint8_t **buffer)
{	
    uint8_t *old = *buffer;
    
    VirtualComponent::saveToBuffer(buffer);
    disk.saveToBuffer(buffer);
    cpu->saveToBuffer(buffer);
    via1.saveToBuffer(buffer);
    via2.saveToBuffer(buffer);
	mem->saveToBuffer(buffer);
    
    assert(*buffer - old == stateSize());
}
Exemplo n.º 6
0
void
VC1541::loadFromBuffer(uint8_t **buffer)
{	
    uint8_t *old = *buffer;
    
    VirtualComponent::loadFromBuffer(buffer);
    disk.loadFromBuffer(buffer);
	cpu->loadFromBuffer(buffer);
    via1.loadFromBuffer(buffer);
    via2.loadFromBuffer(buffer);
    mem->loadFromBuffer(buffer);
    
    assert(*buffer - old == stateSize());
}
Exemplo n.º 7
0
void
Datasette::loadFromBuffer(uint8_t **buffer)
{
    uint8_t *old = *buffer;
    
    VirtualComponent::loadFromBuffer(buffer);
    if (size) {
        if (data == NULL)
            data = (uint8_t *)malloc(size);
        readBlock(buffer, (uint8_t *)data, size);
    }
    
    if (*buffer - old != stateSize())
        assert(0);
}
Exemplo n.º 8
0
void 
C64::loadFromBuffer(uint8_t **buffer)
{	
	uint8_t *old = *buffer;
		
	debug(2, "Loading internal state...\n");
	
	// Load state of this component
    warp = read8(buffer);
    alwaysWarp = read8(buffer);
    warpLoad = read8(buffer);
	cycles = read64(buffer);
	frame = (int)read32(buffer);
	rasterline = (int)read16(buffer);
	rasterlineCycle = (int)read32(buffer);
    nanoTargetTime = read64(buffer);
	
	// Load state of sub components
	cpu->loadFromBuffer(buffer);
	vic->loadFromBuffer(buffer);
	sid->loadFromBuffer(buffer);
	cia1->loadFromBuffer(buffer);
	cia2->loadFromBuffer(buffer);	
	mem->loadFromBuffer(buffer);
	keyboard->loadFromBuffer(buffer);
    joystick1->loadFromBuffer(buffer);
    joystick2->loadFromBuffer(buffer);
    iec->loadFromBuffer(buffer);
    expansionport->loadFromBuffer(buffer);
	floppy->loadFromBuffer(buffer);

    debug(2, "  C64 state loaded (%d bytes)\n", *buffer - old);
    assert(*buffer - old == stateSize());
    
    ping();
}
Exemplo n.º 9
0
void
CPU::saveToBuffer(uint8_t **buffer) 
{
    uint8_t *old = *buffer;

    write8(buffer, (uint8_t)chipModel); 

	// Registers and flags
	write8(buffer, A);
	write8(buffer, X);
	write8(buffer, Y);
	write16(buffer, PC);
	write16(buffer, PC_at_cycle_0);
	write8(buffer, SP);
	write8(buffer, N);
	write8(buffer, V);
	write8(buffer, B);
	write8(buffer, D);
	write8(buffer, I);
	write8(buffer, Z);
	write8(buffer, C);
	
	// Internal state
	write8(buffer, opcode);
	write8(buffer, addr_lo);
	write8(buffer, addr_hi);
	write8(buffer, ptr);
	write8(buffer, pc_lo);
	write8(buffer, pc_hi);
	write8(buffer, (uint8_t)overflow);
	write8(buffer, data);
	
	write8(buffer, port);
	write8(buffer, port_direction);
	write8(buffer, external_port_bits);
	write8(buffer, (uint8_t)rdyLine);
	write8(buffer, irqLine);
	write8(buffer, nmiLine);
	write8(buffer, (uint8_t)nmiEdge);
    write8(buffer, (uint8_t)interruptsPending);
	write64(buffer, nextPossibleIrqCycle);
	write64(buffer, nextPossibleNmiCycle);
	
	write8(buffer, (uint8_t)errorState);

	for (uint16_t i = 0;; i++) {
		if (callbacks[i] == NULL) {
			panic("ERROR while saving state: Callback pointer not found!\n");
		}
		if (callbacks[i] == next) {
			write16(buffer, i);
			break;
		}
	}

	for (unsigned i = 0; i < 256; i++) 
		write16(buffer, callStack[i]);
	write8(buffer, callStackPointer);
	write8(buffer, oldI);
    
    debug(4, "  CPU state saved (%d bytes)\n", *buffer - old);
    assert(*buffer - old == stateSize());
}
Exemplo n.º 10
0
void Simulable::checkStateSize(const ConsistentVector& state) const {
  if (state.size() != stateSize()) {
    throw std::runtime_error("State size must correspond. ");
  }
}