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"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

View File

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

View File

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

View File

@ -57,7 +57,7 @@ typedef struct ppu {
byte x;
bool w;
void (*trigger_nmi)();
} PPU;
PPU *ppu_get_state();
@ -93,8 +93,8 @@ bool ppu_read_flag(size_t reg, byte mask);
* @param reg The register index
* @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

View File

@ -15,6 +15,7 @@
//
#include "../include/ppu.h"
#include "../cpu/cpu.h"
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;
int x, y = 0;
@ -52,6 +62,7 @@ void ppu_cycle() {
if (y == 241) {
// VBlank start
ppu_status_set(PPU_STATUS_VBLANK, true);
ppu_trigger_vbl_nmi();
}
if (y == 261) {
@ -87,17 +98,26 @@ bool ppu_read_flag(size_t reg, byte 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;
//}
void ppu_read_register(byte reg) {
void ppu_sig_read_register(byte reg) {
if (reg == PPU_REGISTER_STATUS) {
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) {
ppu_state.w = !ppu_state.w;
}

View File

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