Skip to content

Commit

Permalink
MEGA65: CPUaddr2Linear little hack + cleanups #140
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Mar 16, 2022
1 parent 2b6b403 commit 50293c0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 107 deletions.
2 changes: 1 addition & 1 deletion targets/mega65/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
## Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
## Copyright (C)2016-2021 LGB (Gábor Lénárt) <[email protected]>
## Copyright (C)2016-2022 LGB (Gábor Lénárt) <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
101 changes: 0 additions & 101 deletions targets/mega65/TODO

This file was deleted.

4 changes: 3 additions & 1 deletion targets/mega65/cpu_custom_functions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2021 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2022 LGB (Gábor Lénárt) <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -77,6 +77,8 @@ extern Uint32 cpu65_read_linear_long_opcode_callback ( const Uint8 index );

extern void cpu65_illegal_opcode_callback ( void );

extern int memory_cpurd2linear_xlat ( Uint16 cpu_addr);

CPU_CUSTOM_FUNCTIONS_INLINE_DECORATOR Uint8 cpu65_read_callback ( Uint16 addr ) {
return CALL_MEMORY_READER(addr >> 8, addr);
}
Expand Down
6 changes: 6 additions & 0 deletions targets/mega65/memory_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,12 @@ void memory_debug_write_phys_addr ( int addr, Uint8 data )
CALL_MEMORY_WRITER(MEM_SLOT_DEBUG_RESOLVER, addr, data);
}

int memory_cpurd2linear_xlat ( Uint16 cpu_addr)
{
int slot = cpu_addr >> 8;
return mem_page_rd_o[slot] + mem_page_refp[slot]->start + (int)(cpu_addr & 0xFF);
}

/* the same as above but for CPU addresses */
Uint8 memory_debug_read_cpu_addr ( Uint16 addr )
{
Expand Down
4 changes: 2 additions & 2 deletions targets/mega65/xemu-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#define CPU_65CE02
#define MEGA65
#define CPU65_65CE02_6502NMOS_TIMING_EMULATION
#define XEMU_SNAPSHOT_SUPPORT "MEGA65"
//#define XEMU_SNAPSHOT_SUPPORT "MEGA65"
#define CPU_STEP_MULTI_OPS
#define DEBUG_CPU
//#define DEBUG_CPU
#define CPU_CUSTOM_MEMORY_FUNCTIONS_H "cpu_custom_functions.h"
#define CPU65 cpu65
//#define CPU65_DISCRETE_PF_NZ
Expand Down
7 changes: 5 additions & 2 deletions xemu/cpu65.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2021 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2022 LGB (Gábor Lénárt) <[email protected]>
THIS IS AN UGLY PIECE OF SOURCE REALLY.
Expand Down Expand Up @@ -876,9 +876,12 @@ int cpu65_step (
case 0x00: /* BRK Implied */
#ifdef DEBUG_CPU
DEBUG("CPU: WARN: BRK is about executing at PC=$%04X" NL, (CPU65.pc - 1) & 0xFFFF);
#ifdef MEGA65
DEBUG("CPU: BRK opcode linear address is $%X" NL, memory_cpurd2linear_xlat((CPU65.pc - 1) & 0xFFFF));
#endif
#endif
pushWord(CPU65.pc + 1);
push(cpu65_get_pf() | CPU65_PF_B); // BRK always pushes 'B' bit set (like PHP too, unlike hardware interrupts
push(cpu65_get_pf() | CPU65_PF_B); // BRK always pushes 'B' bit set (like PHP too, unlike hardware interrupts)
CPU65.pf_d = 0; // actually, NMOS CPU does not do this for real, only 65C02+
CPU65.pf_i = 1;
CPU65.pc = readWord(0xFFFE);
Expand Down

0 comments on commit 50293c0

Please sign in to comment.