Skip to content

Commit

Permalink
a great deal of shitposting
Browse files Browse the repository at this point in the history
  • Loading branch information
zaydlang committed Jul 15, 2024
1 parent 5363d6a commit 5957bf6
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 136 deletions.
9 changes: 6 additions & 3 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ version (unittest) {
// shoot me, but im hardcoding it for now.
nds.load_bios7(load_file_as_bytes("roms/biosnds7.rom"));
nds.load_bios9(load_file_as_bytes("roms/biosnds9.rom"));
nds.load_firmware(load_file_as_bytes("roms/firmware.rom"));

MmFile firmware_file = new MmFile("roms/firmware.rom", MmFile.Mode.readWrite, 262144, null, 0);
nds.load_firmware(firmware_file);

nds.load_rom(load_file_as_bytes(cli_args.rom_path));

auto save_path = cli_args.rom_path.stripExtension().setExtension(".bsv");
Expand All @@ -41,8 +44,8 @@ version (unittest) {
}
}

MmFile mm_file = new MmFile(save_path, MmFile.Mode.readWrite, nds.get_backup_size(), null, 0);
nds.load_save_mmfile(mm_file);
MmFile save_file = new MmFile(save_path, MmFile.Mode.readWrite, nds.get_backup_size(), null, 0);
nds.load_save_mmfile(save_file);

nds.set_sample_rate(48_000);

Expand Down
37 changes: 1 addition & 36 deletions source/emu/hw/gpu/gpu.d
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ final class GPU {
// }

void on_hblank_start() {
log_gpu3d("on_hblank_start()");

if (hblank_irq_enabled9) interrupt9.raise_interrupt(Interrupt.LCD_HBLANK);
if (hblank_irq_enabled7) interrupt7.raise_interrupt(Interrupt.LCD_HBLANK);

Expand All @@ -65,21 +63,14 @@ final class GPU {
}

void on_hblank_end() {
log_gpu3d("on_hblank_end(%d)", scanline);

hblank = false;

scanline++;

log_gpu3d("here3");
gpu_engine_a.ppu.canvas.on_hblank_end(scanline);
log_gpu3d("here5");
gpu_engine_b.ppu.canvas.on_hblank_end(scanline);
log_gpu3d("here4 %d", scanline);

if (scanline == 192) on_vblank_start();
log_gpu3d("here68");
import std.stdio;
if (scanline == 263) on_vblank_end();

if (scanline == vcount_lyc) {
Expand All @@ -91,8 +82,6 @@ final class GPU {
}

void set_hblank_flag() {
log_gpu3d("set_hblank_flag()");

hblank = true;

if (0 <= scanline && scanline < 192) {
Expand All @@ -111,21 +100,12 @@ final class GPU {
}

void on_vblank_end() {

log_gpu3d("here69");
import std.stdio;
// readln();

vblank = false;
scanline = 0;

log_gpu3d("here11");
import std.stdio;
// readln();
apply_master_brightness_to_video_buffers(&gpu_engine_a.videobuffer, &gpu_engine_b.videobuffer);

log_gpu3d("here12");
log_ppu("pointers: %x %x %x %x", gpu_engine_a.videobuffer.ptr, gpu_engine_b.videobuffer.ptr, gpu_engine_a.videobuffer.length, gpu_engine_b.videobuffer.length); if (display_swap) {
if (display_swap) {
present_videobuffers(&gpu_engine_a.videobuffer, &gpu_engine_b.videobuffer);
} else {
present_videobuffers(&gpu_engine_b.videobuffer, &gpu_engine_a.videobuffer);
Expand Down Expand Up @@ -254,30 +234,15 @@ log_ppu("pointers: %x %x %x %x", gpu_engine_a.videobuffer.ptr, gpu_engine_b.vide
int master_brightness_b;

void apply_master_brightness_to_video_buffers(Pixel[192][256]* top, Pixel[192][256]* bot) {
import std.stdio;
log_gpu3d("here");
// readln();
// log_gpu3d("here %x %x", top, bot);
apply_master_brightness_to_video_buffer(top, master_brightness_a, master_bright_mode_a);
log_gpu3d("here");
// readln();
// log_gpu3d("here %x %x", top, bot);
apply_master_brightness_to_video_buffer(bot, master_brightness_b, master_bright_mode_b);
log_gpu3d("here");
// readln();
// log_gpu3d("here %x %x", top, bot);
}

void apply_master_brightness_to_video_buffer(Pixel[192][256]* video_buffer, ref int master_brightness, ref MasterBrightMode master_bright_mode) { import std.stdio;

if (master_bright_mode == MasterBrightMode.DISABLED) return;
log_gpu3d("here2");
// readln();

for (int x = 0; x < 256; x++) {
for (int y = 0; y < 192; y++) {
log_gpu3d("here6");
// readln();
(*video_buffer)[x][y].r = ((*video_buffer)[x][y].r * master_brightness) / 64;
(*video_buffer)[x][y].g = ((*video_buffer)[x][y].g * master_brightness) / 64;
(*video_buffer)[x][y].b = ((*video_buffer)[x][y].b * master_brightness) / 64;
Expand Down
14 changes: 0 additions & 14 deletions source/emu/hw/gpu/gpu3d/geometry_engine.d
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ final class GeometryEngine {

case MatrixMode.TEXTURE:
texture_matrix = matrix;
for (int x = 0; x < 4; x++) {
log_gpu3d("TEXMATR %f %f %f %f", cast(float) texture_matrix[x][0], cast(float) texture_matrix[x][1], cast(float) texture_matrix[x][2], cast(float) texture_matrix[x][3]);
}
break;
}
}
Expand Down Expand Up @@ -401,17 +398,6 @@ final class GeometryEngine {

void handle_MTX_LOAD_4x4(Word* args) {
auto convert = (Word x) => FixedPoint!(20, 12).from_repr(x);

if (matrix_mode == MatrixMode.TEXTURE) {
for (int x = 0; x < 4; x++) {
log_gpu3d("TEXMATR input %08x %08x %08x %08x",
args[x * 4 + 0],
args[x * 4 + 1],
args[x * 4 + 2],
args[x * 4 + 3]
);
}
}

set_current_matrix(
Matrix([
Expand Down
2 changes: 1 addition & 1 deletion source/emu/hw/gpu/gpu3d/gpu3d.d
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ final class GPU3D {
void plot(int scanline, Pixel p, int x, Coord_14_18 z, Coord_14_18 w) {
Coord_14_18 depth_value = depth_buffering_mode ? w : z;

if (depth_buffering_mode ? (w < 0) : (z < 0)) return;
if (depth_buffering_mode ? (w < 0) : (w < 0)) return;

// if (depth_buffer[scanline][x] >= depth_value && p.a != 0) {
// depth_buffer[scanline][x] = depth_value;
Expand Down
3 changes: 0 additions & 3 deletions source/emu/hw/gpu/gpu3d/rendering_engine.d
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ final class RenderingEngine {
parent.start_rendering();

for (int i = 0; i < num_polygons; i++) {
// if (i == 1) continue;
if (i == 1) log_gpu3d("alpha: %x", annotated_polygons[i].orig.alpha);

// log_gpu3d("rendering funky polygon #%d", i);
auto p = annotated_polygons[i];

Expand Down
2 changes: 1 addition & 1 deletion source/emu/hw/memory/strategy/memstrategy.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import emu.hw.memory.strategy.fastmem;
import emu.hw.memory.strategy.slowmem;
import util;

alias Mem = SlowMem;
alias Mem = FastMem;

interface MemStrategy {
Word read_data_word7(Word address);
Expand Down
8 changes: 0 additions & 8 deletions source/emu/hw/misc/rtc.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,6 @@ final class RTC_S_35199A01 {
this.date_time_hh.value = to_bcd(st.hour);
this.date_time_mm.value = to_bcd(st.minute);
this.date_time_ss.value = to_bcd(st.second);

this.date_time_year.value = 0; // to_bcd(st.year - 2000);
this.date_time_month.value = 0; //to_bcd(st.month);
this.date_time_day.value = 0; //to_bcd(st.day);
this.date_time_day_of_week.value = 0; //to_bcd(st.dayOfWeek);
this.date_time_hh.value = 0; //to_bcd(st.hour);
this.date_time_mm.value = 0; //to_bcd(st.minute);
this.date_time_ss.value = 0; //to_bcd(st.second);
}

void reset() {
Expand Down
6 changes: 3 additions & 3 deletions source/emu/hw/nds.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ final class NDS {
mem.load_bios9(data);
}

void load_firmware(Byte[] data) {
firmware.load_firmware(data);
void load_firmware(MmFile mm_file) {
firmware.load_firmware(mm_file);
}

void direct_boot() {
Expand Down Expand Up @@ -191,7 +191,7 @@ final class NDS {
arm7.run_instruction();
arm9.run_instruction();
arm9.run_instruction();
scheduler.tick(1);
scheduler.tick(2);
scheduler.process_events();

while (arm7.halted && arm9.halted) {
Expand Down
2 changes: 1 addition & 1 deletion source/emu/hw/spi/device/eeprom.d
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class EEPROM(int page_size, int num_pages) : SPIDevice {
case 0x9F: state = State.READING_JEDEC_ID; break;
case 0x06: write_enable_latch = true; break;
case 0x04: write_enable_latch = false; break;
default: error_eeprom("invalid eeprom command dummy: %x", b);
default: log_eeprom("invalid eeprom command dummy: %x", b);
}
}
}
25 changes: 13 additions & 12 deletions source/emu/hw/spi/device/firmware.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module emu.hw.spi.device.firmware;

import emu.hw.memory.mem;
import emu.hw.spi.device;
import std.mmfile;
import util;

enum FirmwareLanguage {
Expand Down Expand Up @@ -74,7 +75,7 @@ final class Firmware : SPIDevice {

int access_number;

Byte[0x1000000] data;
MmFile data;
Word address;

this() {
Expand All @@ -88,17 +89,17 @@ final class Firmware : SPIDevice {
power_on = true;
}

void load_firmware(Byte[] data) {
this.data[0..FIRMWARE_SIZE] = data[0..FIRMWARE_SIZE];
void load_firmware(MmFile mm_file) {
this.data = mm_file;

user_settings.adc_x1 = data.read!Half(0x3FE58);
user_settings.adc_y1 = data.read!Half(0x3FE5A);
user_settings.scr_x1 = data.read!Byte(0x3FE5C);
user_settings.scr_y1 = data.read!Byte(0x3FE5D);
user_settings.adc_x2 = data.read!Half(0x3FE5E);
user_settings.adc_y2 = data.read!Half(0x3FE60);
user_settings.scr_x2 = data.read!Byte(0x3FE62);
user_settings.scr_y2 = data.read!Byte(0x3FE63);
user_settings.adc_x1 = (cast(Byte[]) data[]).read!Half(0x3FE58);
user_settings.adc_y1 = (cast(Byte[]) data[]).read!Half(0x3FE5A);
user_settings.scr_x1 = (cast(Byte[]) data[]).read!Byte(0x3FE5C);
user_settings.scr_y1 = (cast(Byte[]) data[]).read!Byte(0x3FE5D);
user_settings.adc_x2 = (cast(Byte[]) data[]).read!Half(0x3FE5E);
user_settings.adc_y2 = (cast(Byte[]) data[]).read!Half(0x3FE60);
user_settings.scr_x2 = (cast(Byte[]) data[]).read!Byte(0x3FE62);
user_settings.scr_y2 = (cast(Byte[]) data[]).read!Byte(0x3FE63);

touchscreen.recalibrate();
}
Expand Down Expand Up @@ -232,7 +233,7 @@ final class Firmware : SPIDevice {
case 0xDB: command = Command.PageErase; return true;
case 0xD8: command = Command.SectorErase; return true;

default: error_eeprom("invalid eeprom command dummy"); return false;
default: log_eeprom("invalid eeprom command dummy"); return false;
}
}
}
Loading

0 comments on commit 5957bf6

Please sign in to comment.