- [CHG] Gestió de interrupcions pasada a "mem" (futur "bus")
- [CHG] Reorganitzacions i neteja de codi - [NEW] Constants del espai io en la seua pròpia capçalera - [NEW] Comentaris en algunes parts menys obvies del codi - [CHG] Alguns defines passats a constexpr - [CHG] display::init() no feia més que cridar a display::reinit(). Concretats els dos en display::init() - [ONGOING] Passant la responsabilitat de tornar el foco a la finestra principal (que estaba en el mòdul debug) al gestor de finestres.
This commit is contained in:
+1
-2
@@ -108,10 +108,9 @@ namespace debug
|
||||
con_y = win_h - con_h;
|
||||
sym_h = win_h - sym_y;
|
||||
debug::refresh();
|
||||
display::redraw();
|
||||
} else if (e->window.event == SDL_WINDOWEVENT_CLOSE) {
|
||||
hide();
|
||||
display::focus();
|
||||
//display::focus();
|
||||
}
|
||||
}
|
||||
if (e->type == SDL_MOUSEWHEEL) {
|
||||
|
||||
+3
-8
@@ -69,7 +69,7 @@ namespace display
|
||||
return true;
|
||||
}
|
||||
|
||||
void reinit()
|
||||
void init()
|
||||
{
|
||||
if (win) ui::window::unregisterWindow(SDL_GetWindowID(win));
|
||||
|
||||
@@ -106,11 +106,6 @@ namespace display
|
||||
focus();
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
reinit();
|
||||
}
|
||||
|
||||
void focus()
|
||||
{
|
||||
if (win)
|
||||
@@ -188,7 +183,7 @@ namespace display
|
||||
if (144*value > dm.h) return;
|
||||
|
||||
zoom = value;
|
||||
reinit();
|
||||
init();
|
||||
}
|
||||
|
||||
void incZoom()
|
||||
@@ -206,7 +201,7 @@ namespace display
|
||||
void toggleFullscreen()
|
||||
{
|
||||
fullscreen = !fullscreen;
|
||||
reinit();
|
||||
init();
|
||||
}
|
||||
|
||||
const bool getFullscreen()
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace display
|
||||
{
|
||||
void init();
|
||||
void reinit();
|
||||
void focus();
|
||||
void redraw(const bool present=true);
|
||||
void present();
|
||||
|
||||
+12
-5
@@ -1,7 +1,14 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#define INTERRUPT_VBLANK 0x01
|
||||
#define INTERRUPT_LCD 0x02
|
||||
#define INTERRUPT_TIMER 0x04
|
||||
#define INTERRUPT_SERIAL 0x08
|
||||
#define INTERRUPT_JOYPAD 0x10
|
||||
namespace gb
|
||||
{
|
||||
namespace interrupts
|
||||
{
|
||||
constexpr uint8_t VBLANK = 0x01;
|
||||
constexpr uint8_t LCD = 0x02;
|
||||
constexpr uint8_t TIMER = 0x04;
|
||||
constexpr uint8_t SERIAL = 0x08;
|
||||
constexpr uint8_t JOYPAD = 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define io_interrupts_address 0xff0f
|
||||
+14
-9
@@ -52,13 +52,17 @@ namespace actions
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Control de paràmetres
|
||||
if (argc < 2) { printf("ABORTING: No rom specified.\n"); exit(1); }
|
||||
|
||||
// Velocitat de rellotge
|
||||
const uint32_t clock = 4194304;
|
||||
const uint32_t update_freq = clock >> 3;
|
||||
|
||||
// Inicia SDL
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
|
||||
// Carrega la rom
|
||||
FILE *f = fopen(argv[1], "rb");
|
||||
if (!f) { printf("ABORTING: Rom not found.\n"); exit(1); }
|
||||
fseek(f, 0, SEEK_END);
|
||||
@@ -68,8 +72,10 @@ int main(int argc, char *argv[])
|
||||
fread(buffer, filesize, 1, f);
|
||||
fclose(f);
|
||||
|
||||
// i mem inicialitza el mbc
|
||||
mem::init(buffer, filesize);
|
||||
|
||||
// Iniciem tots els sistemes
|
||||
sm83dis::loadSymbols();
|
||||
sm83::reset();
|
||||
|
||||
@@ -77,6 +83,7 @@ int main(int argc, char *argv[])
|
||||
display::init();
|
||||
debug::init();
|
||||
|
||||
// Iniciem el menú princpal (ací? perqué? No es de display.h?)
|
||||
ui::menu::init();
|
||||
ui::menu::setexitcallback(actions::exitMenu);
|
||||
|
||||
@@ -96,10 +103,6 @@ int main(int argc, char *argv[])
|
||||
ui::menu::addbooloption(menu, "STOP ON INVALID OP", sm83::getOption(SM83_OPTION_STOP_ON_INVALID), actions::decZoom);
|
||||
ui::menu::addoption(menu, "SHOW ANALYZER", actions::showAnalyzer);
|
||||
|
||||
//zx_ula::sound_init();
|
||||
|
||||
//debug::stop();
|
||||
|
||||
bool should_exit = false;
|
||||
SDL_Event e;
|
||||
|
||||
@@ -174,9 +177,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!debug::debugging() && !debug::paused()) {
|
||||
bool fastload=false;
|
||||
|
||||
// En cada bucle fem 10 pasos de la CPU, sino s'ofega
|
||||
// En cada pas de bucle fem 10 pasos de la CPU, sino s'ofega
|
||||
for (int i=0;i<20;++i) {
|
||||
if (debug::isbreak(sm83::getPC(), 9)) {
|
||||
debug::stop();
|
||||
@@ -191,14 +192,18 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// Sincronització:
|
||||
// la frequència del rellotge diu quants t_states pot executar per segon.
|
||||
// update_freq es la freq del rellotge / 8. Per tant, el nombre de t_states que
|
||||
// pot executar cada 125 ms. Ací comprobem si ja havem executat eixe nombre
|
||||
// de t_states i, si ho havem fet, esperem fins que passen 125ms des de l'ultima
|
||||
// vegada que ho comprobarem.
|
||||
if (t_states>=update_freq)
|
||||
{
|
||||
while (SDL_GetTicks()<(time+125)) {}
|
||||
t_states -= update_freq;
|
||||
time = SDL_GetTicks();
|
||||
//z80analyze::refresh();
|
||||
}
|
||||
//z80analyze::refresh(true);
|
||||
|
||||
|
||||
} else if (!debug::debugging() && debug::paused()) {
|
||||
|
||||
+7
-2
@@ -4,7 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include "apu.h"
|
||||
|
||||
#include "io_constants.h"
|
||||
#include "mbc_none.h"
|
||||
#include "mbc1.h"
|
||||
#include "mbc3.h"
|
||||
@@ -183,6 +183,11 @@ namespace mem
|
||||
}
|
||||
}
|
||||
|
||||
void requestInterrupt(uint8_t type)
|
||||
{
|
||||
mem::writeMem(io_interrupts_address, mem::readMem(io_interrupts_address) | type);
|
||||
}
|
||||
|
||||
uint8_t getTag(uint16_t address)
|
||||
{
|
||||
return tags[address];
|
||||
@@ -248,7 +253,7 @@ namespace mem
|
||||
TIMA++;
|
||||
else {
|
||||
TIMA = TMA;
|
||||
sm83::interrupt(INTERRUPT_TIMER);
|
||||
mem::requestInterrupt(gb::interrupts::TIMER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -29,7 +29,8 @@ namespace mem
|
||||
|
||||
uint8_t readMem(uint16_t address);
|
||||
void writeMem(uint16_t address, uint8_t value);
|
||||
|
||||
void requestInterrupt(uint8_t type);
|
||||
|
||||
uint8_t getTag(uint16_t address);
|
||||
void setTag(uint16_t address, uint8_t value);
|
||||
|
||||
|
||||
+6
-10
@@ -45,7 +45,6 @@ namespace ppu
|
||||
#define WY (*_WY)
|
||||
#define WX (*_WX)
|
||||
|
||||
#define IF 0xff0f
|
||||
bool last_interrupt_lcd_state = false;
|
||||
|
||||
void init()
|
||||
@@ -212,7 +211,6 @@ namespace ppu
|
||||
}
|
||||
|
||||
// gestió de en quin dot i linea estem, i tot el que ha de passar
|
||||
//uint8_t interrupts = 0x00;
|
||||
bool current_interrupt_lcd_state = false;
|
||||
dots_in_scanline++;
|
||||
if ( (dots_in_scanline==80) && (LY<144) )
|
||||
@@ -222,7 +220,7 @@ namespace ppu
|
||||
else if ( (dots_in_scanline==252) && (LY<144) )
|
||||
{
|
||||
STAT = (STAT & 0xFC); // Set mode 0
|
||||
if (STAT&0x08) current_interrupt_lcd_state = true; // interrupts |= INTERRUPT_LCD;
|
||||
if (STAT&0x08) current_interrupt_lcd_state = true;
|
||||
}
|
||||
else if (dots_in_scanline==456)
|
||||
{
|
||||
@@ -232,17 +230,16 @@ namespace ppu
|
||||
if (LY==144)
|
||||
{
|
||||
// Set vblank interrupt
|
||||
mem::writeMem(IF, mem::readMem(IF) | INTERRUPT_VBLANK);
|
||||
mem::requestInterrupt(gb::interrupts::VBLANK);
|
||||
STAT = (STAT & 0xFC) | 0x01; // Set mode 1
|
||||
//interrupts |= INTERRUPT_VBLANK;
|
||||
if (STAT&0x10) current_interrupt_lcd_state = true; //interrupts |= INTERRUPT_LCD;
|
||||
if (STAT&0x10) current_interrupt_lcd_state = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LY<144)
|
||||
{
|
||||
STAT = (STAT & 0xFC) | 0x02; // Set mode 2
|
||||
if (STAT&0x20) current_interrupt_lcd_state = true; // interrupts |= INTERRUPT_LCD;
|
||||
if (STAT&0x20) current_interrupt_lcd_state = true;
|
||||
fill_line_buffer_bkg();
|
||||
fill_line_buffer_win();
|
||||
fill_line_buffer_obj();
|
||||
@@ -251,7 +248,7 @@ namespace ppu
|
||||
if (LY==LYC)
|
||||
{
|
||||
STAT = (STAT & 0xFB) | 0x04;
|
||||
if (STAT&0x40) current_interrupt_lcd_state = true; // interrupts |= INTERRUPT_LCD;
|
||||
if (STAT&0x40) current_interrupt_lcd_state = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -261,8 +258,7 @@ namespace ppu
|
||||
|
||||
if (!last_interrupt_lcd_state && current_interrupt_lcd_state)
|
||||
{
|
||||
mem::writeMem(IF, mem::readMem(IF) | INTERRUPT_LCD);
|
||||
//sm83::interrupt(interrupts);
|
||||
mem::requestInterrupt(gb::interrupts::LCD);
|
||||
}
|
||||
last_interrupt_lcd_state = current_interrupt_lcd_state;
|
||||
|
||||
|
||||
+13
-23
@@ -46,10 +46,6 @@ namespace sm83
|
||||
|
||||
uint8_t *_rIME = ®s[12];
|
||||
|
||||
bool halted = false;
|
||||
bool exit_from_halt = false;
|
||||
int pending_ei = 0;
|
||||
|
||||
#define rA (*_rA)
|
||||
#define rF (*_rF)
|
||||
#define rB (*_rB)
|
||||
@@ -71,6 +67,9 @@ namespace sm83
|
||||
|
||||
#define EX(a,b) {auto temp=a;a=b;b=temp;}
|
||||
|
||||
bool halted = false;
|
||||
bool exit_from_halt = false;
|
||||
int pending_ei = 0;
|
||||
bool reading_m1 = false;
|
||||
|
||||
uint8_t READ_MEM_8(const uint16_t addr, const bool code=false)
|
||||
@@ -534,21 +533,21 @@ namespace sm83
|
||||
DI();
|
||||
PUSH(rPC);
|
||||
//t+=20;
|
||||
if (*IF & INTERRUPT_VBLANK) {
|
||||
if (*IF & gb::interrupts::VBLANK) {
|
||||
rPC = 0x40;
|
||||
*IF = *IF & ~INTERRUPT_VBLANK;
|
||||
} else if (*IF & INTERRUPT_LCD) {
|
||||
*IF = *IF & ~gb::interrupts::VBLANK;
|
||||
} else if (*IF & gb::interrupts::LCD) {
|
||||
rPC = 0x48;
|
||||
*IF = *IF & ~INTERRUPT_LCD;
|
||||
} else if (*IF & INTERRUPT_TIMER) {
|
||||
*IF = *IF & ~gb::interrupts::LCD;
|
||||
} else if (*IF & gb::interrupts::TIMER) {
|
||||
rPC = 0x50;
|
||||
*IF = *IF & ~INTERRUPT_TIMER;
|
||||
} else if (*IF & INTERRUPT_SERIAL) {
|
||||
*IF = *IF & ~gb::interrupts::TIMER;
|
||||
} else if (*IF & gb::interrupts::SERIAL) {
|
||||
rPC = 0x58;
|
||||
*IF = *IF & ~INTERRUPT_SERIAL;
|
||||
} else if (*IF & INTERRUPT_JOYPAD) {
|
||||
*IF = *IF & ~gb::interrupts::SERIAL;
|
||||
} else if (*IF & gb::interrupts::JOYPAD) {
|
||||
rPC = 0x60;
|
||||
*IF = *IF & ~INTERRUPT_JOYPAD;
|
||||
*IF = *IF & ~gb::interrupts::JOYPAD;
|
||||
}
|
||||
/*if (options[Z80_OPTION_BREAK_ON_INTERRUPT]) {
|
||||
printf("Break on interrupt! 0x%2x, PC: 0x%2x\n", address, rPC);
|
||||
@@ -616,15 +615,6 @@ namespace sm83
|
||||
HALT();
|
||||
}
|
||||
|
||||
void interrupt(uint8_t type)
|
||||
{
|
||||
const uint8_t IE = mem::readMem(0xffff);
|
||||
//if (IE & type) exit_from_halt = true;
|
||||
const uint8_t IF = mem::readMem(0xff0f);
|
||||
mem::writeMem(0xff0f, IF | type);
|
||||
//processInterrupts();
|
||||
}
|
||||
|
||||
static inline const uint8_t RLC(const uint8_t v)
|
||||
{
|
||||
const uint8_t res = (v>>7) | (v<<1);
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace sm83
|
||||
uint32_t getClock();
|
||||
|
||||
void processInterrupts();
|
||||
void interrupt(uint8_t type);
|
||||
|
||||
uint32_t step();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user