This commit is contained in:
FyloZ 2024-05-10 14:03:08 -04:00
parent 8dd1fe6037
commit d5fba04314
Signed by: william
GPG Key ID: 835378AE9AF4AE97
6 changed files with 48 additions and 22 deletions

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project> </project>

View File

@ -422,17 +422,18 @@ char *get_op_code_name(byte op) {
case 0xaa: case 0xaa:
return "TAX"; return "TAX";
case 0xc6: case 0xc6:
case 0xca:
case 0xce: case 0xce:
case 0xd6: case 0xd6:
case 0xde: case 0xde:
return "DEC"; return "DEC";
case 0xca:
return "DEX";
case 0xe6: case 0xe6:
case 0xee: case 0xee:
case 0xf6: case 0xf6:
case 0xfe: case 0xfe:
return "INC"; return "INC";
case 0x02: case 0x02:
case 0x12: case 0x12:
case 0x22: case 0x22:

View File

@ -22,7 +22,7 @@ byte mem_get_byte(address addr) {
if (addr >= RAM_MAX_ADDR && addr < PPU_MAX_ADDR) { if (addr >= RAM_MAX_ADDR && addr < PPU_MAX_ADDR) {
byte reg = (addr - RAM_MAX_ADDR) % PPU_BANK_SIZE; byte reg = (addr - RAM_MAX_ADDR) % PPU_BANK_SIZE;
ppu_read_register(reg); ppu_sig_read_register(reg);
} }
return ram[addr]; return ram[addr];
@ -64,7 +64,7 @@ void mem_set_byte(address addr, byte byte) {
ram[ram_addr] = byte; ram[ram_addr] = byte;
} }
ppu_write_register(reg_addr); ppu_sig_write_register(reg_addr);
} else { } else {
ram[addr] = byte; ram[addr] = byte;

View File

@ -57,7 +57,7 @@ typedef struct ppu {
byte x; byte x;
bool w; bool w;
void (*trigger_nmi)();
} PPU; } PPU;
PPU *ppu_get_state(); PPU *ppu_get_state();
@ -93,8 +93,8 @@ bool ppu_read_flag(size_t reg, byte mask);
* @param reg The register index * @param reg The register index
* @param mask The value mask * @param mask The value mask
*/ */
void ppu_read_register(byte reg); void ppu_sig_read_register(byte reg);
void ppu_write_register(byte reg); void ppu_sig_write_register(byte reg);
#endif //NESEMULATOR_PPU_H #endif //NESEMULATOR_PPU_H

View File

@ -15,6 +15,7 @@
// //
#include "../include/ppu.h" #include "../include/ppu.h"
#include "../cpu/cpu.h"
PPU ppu_state; PPU ppu_state;
@ -44,6 +45,15 @@ void ppu_status_set(byte mask, bool enabled) {
} }
} }
void ppu_trigger_vbl_nmi() {
if (!ppu_read_flag(PPU_REGISTER_CTRL, PPU_CTRL_GEN_VBLANK_NMI)) {
// VBlank NMI generation is disabled
return;
}
cpu_trigger_nmi();
}
long frame = 0; long frame = 0;
int x, y = 0; int x, y = 0;
@ -52,6 +62,7 @@ void ppu_cycle() {
if (y == 241) { if (y == 241) {
// VBlank start // VBlank start
ppu_status_set(PPU_STATUS_VBLANK, true); ppu_status_set(PPU_STATUS_VBLANK, true);
ppu_trigger_vbl_nmi();
} }
if (y == 261) { if (y == 261) {
@ -87,17 +98,26 @@ bool ppu_read_flag(size_t reg, byte mask) {
return ppu_state.registers[reg] & mask; return ppu_state.registers[reg] & mask;
} }
//byte ppu_read_register(size_t reg, byte mask) { //byte ppu_sig_read_register(size_t reg, byte mask) {
// return ppu_state.registers[reg] & mask; // return ppu_state.registers[reg] & mask;
//} //}
void ppu_read_register(byte reg) { void ppu_sig_read_register(byte reg) {
if (reg == PPU_REGISTER_STATUS) { if (reg == PPU_REGISTER_STATUS) {
ppu_state.w = false; ppu_state.w = false;
} }
} }
void ppu_write_register(byte reg) { void ppu_sig_write_register(byte reg) {
if (reg == PPU_REGISTER_ADDR) {
byte addr_write = ppu_state.registers[PPU_REGISTER_ADDR];
if (!ppu_state.w) {
ppu_state.v &= (addr_write << 8) | 0x0f;
} else {
ppu_state.v &= 0xff & addr_write;
}
}
if (reg == PPU_REGISTER_SCROLL || reg == PPU_REGISTER_ADDR) { if (reg == PPU_REGISTER_SCROLL || reg == PPU_REGISTER_ADDR) {
ppu_state.w = !ppu_state.w; ppu_state.w = !ppu_state.w;
} }

View File

@ -51,7 +51,7 @@ void linked_list_add(LinkedList *list, void *data) {
list->size++; list->size++;
} }
LinkedListNode *linked_list_next(LinkedList* list) { LinkedListNode *linked_list_next(LinkedList *list) {
assert(list != NULL); assert(list != NULL);
if (list->head == NULL) { if (list->head == NULL) {
@ -92,18 +92,20 @@ LinkedListNode *linked_list_get_near(LinkedList *list, int(*compute_distance)(vo
LinkedListNode *near_node = list->head; LinkedListNode *near_node = list->head;
int current_distance = compute_distance(near_node->data, userdata); // int current_distance = compute_distance(near_node->data, userdata);
if (current_distance == 0) { // if (current_distance == 0) {
return near_node; // return near_node;
// }
int current_distance = 0x7fffffff;
while (near_node->next != NULL && current_distance != 0) {
int next_distance = compute_distance(near_node->next->data, userdata);
if (next_distance > current_distance) {
break;
} }
// TODO near_node = near_node->next;
int last_distance = 0x7fffffff; current_distance = next_distance;
LinkedListNode *node = near_node->next;
while (current_distance < last_distance && near_node->next != NULL) {
node = near_node->next;
last_distance = current_distance;
current_distance = compute_distance(node->data, userdata);
} }
// After the loop, we have found the nearest node in the list, assuming there is only one point of convergence // After the loop, we have found the nearest node in the list, assuming there is only one point of convergence