chore: misc style improvements
This commit is contained in:
		@@ -2,7 +2,7 @@
 | 
			
		||||
An in-progress Gameboy Advance Emulator written in Zig ⚡!
 | 
			
		||||
 | 
			
		||||
## Tests 
 | 
			
		||||
- [ ] [jsmolka GBA Test Collection](https://github.com/jsmolka/gba-tests)
 | 
			
		||||
- [ ] [jsmolka's GBA Test Collection](https://github.com/jsmolka/gba-tests)
 | 
			
		||||
    - [x] `arm.gba` and `thumb.gba`
 | 
			
		||||
    - [x] `flash64.gba`, `flash128.gba`, `none.gba`, and `sram.gba`
 | 
			
		||||
    - [x] `hello.gba`, `shades.gba`, and `stripes.gba`
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										78
									
								
								src/apu.zig
									
									
									
									
									
								
							
							
						
						
									
										78
									
								
								src/apu.zig
									
									
									
									
									
								
							@@ -31,7 +31,6 @@ pub const Apu = struct {
 | 
			
		||||
 | 
			
		||||
    sampling_cycle: u2,
 | 
			
		||||
 | 
			
		||||
    // TODO: Research whether we can have Atomic Pointers
 | 
			
		||||
    stream: *SDL.SDL_AudioStream,
 | 
			
		||||
    sched: *Scheduler,
 | 
			
		||||
 | 
			
		||||
@@ -207,83 +206,6 @@ pub const Apu = struct {
 | 
			
		||||
        self.sched.push(.SampleAudio, self.sampleTicks() -| late);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // pub fn sampleAudio(self: *Self, late: u64) void {
 | 
			
		||||
    //     // zig fmt: off
 | 
			
		||||
    //     const any_ch_enabled = self.ch1.enabled
 | 
			
		||||
    //         or self.ch2.enabled
 | 
			
		||||
    //         or self.ch3.enabled
 | 
			
		||||
    //         or self.ch4.enabled;
 | 
			
		||||
    //     // zig fmt: on
 | 
			
		||||
 | 
			
		||||
    //     const ch_left: u4 = self.psg_cnt.ch_left.read();
 | 
			
		||||
    //     const ch_right: u4 = self.psg_cnt.ch_right.read();
 | 
			
		||||
 | 
			
		||||
    //     // FIXME: Obscure behaviour?
 | 
			
		||||
    //     // Apply NR50 Volume Modifications
 | 
			
		||||
    //     const left_master_vol = (@intToFloat(f32, self.psg_cnt.left_vol.read()) + 1.0) / 7.0;
 | 
			
		||||
    //     const right_master_vol = (@intToFloat(f32, self.psg_cnt.right_vol.read()) + 1.0) / 7.0;
 | 
			
		||||
 | 
			
		||||
    //     // Apply SOUNDCNT_H Volume Modifications
 | 
			
		||||
    //     const gba_vol: f32 = switch (self.dma_cnt.ch_vol.read()) {
 | 
			
		||||
    //         0b00 => 0.25,
 | 
			
		||||
    //         0b01 => 0.5,
 | 
			
		||||
    //         else => 1.0,
 | 
			
		||||
    //     };
 | 
			
		||||
 | 
			
		||||
    //     // Sample Channel 1
 | 
			
		||||
    //     const ch1_sample = self.highPass(self.ch1.amplitude(), any_ch_enabled);
 | 
			
		||||
    //     const ch1_left = if (ch_left & 1 == 1) ch1_sample else 0;
 | 
			
		||||
    //     const ch1_right = if (ch_right & 1 == 1) ch1_sample else 0;
 | 
			
		||||
 | 
			
		||||
    //     // Sample Channel 2
 | 
			
		||||
    //     const ch2_sample = self.highPass(self.ch2.amplitude(), any_ch_enabled);
 | 
			
		||||
    //     const ch2_left = if (ch_left >> 1 & 1 == 1) ch2_sample else 0;
 | 
			
		||||
    //     const ch2_right = if (ch_right >> 1 & 1 == 1) ch2_sample else 0;
 | 
			
		||||
 | 
			
		||||
    //     // Sample Channel 3
 | 
			
		||||
    //     const ch3_sample = self.highPass(self.ch3.amplitude(), any_ch_enabled);
 | 
			
		||||
    //     const ch3_left = if (ch_left >> 2 & 1 == 1) ch3_sample else 0;
 | 
			
		||||
    //     const ch3_right = if (ch_right >> 2 & 1 == 1) ch3_sample else 0;
 | 
			
		||||
 | 
			
		||||
    //     // Sample Channel 4
 | 
			
		||||
    //     const ch4_sample = self.highPass(self.ch4.amplitude(), any_ch_enabled);
 | 
			
		||||
    //     const ch4_left = if (ch_left >> 3 == 1) ch4_sample else 0;
 | 
			
		||||
    //     const ch4_right = if (ch_right >> 3 == 1) ch4_sample else 0;
 | 
			
		||||
 | 
			
		||||
    //     const psg_left = (ch1_left + ch2_left + ch3_left + ch4_left) * left_master_vol * gba_vol;
 | 
			
		||||
    //     const psg_right = (ch1_right + ch2_right + ch3_right + ch4_right) * right_master_vol * gba_vol;
 | 
			
		||||
 | 
			
		||||
    //     // Sample Dma Channels
 | 
			
		||||
    //     const chA_sample = if (self.dma_cnt.chA_vol.read()) self.chA.amplitude() * 4 else self.chA.amplitude() * 2;
 | 
			
		||||
    //     const chA_left = if (self.dma_cnt.chA_left.read()) chA_sample else 0;
 | 
			
		||||
    //     const chA_right = if (self.dma_cnt.chA_right.read()) chA_sample else 0;
 | 
			
		||||
 | 
			
		||||
    //     const chB_sample = if (self.dma_cnt.chB_vol.read()) self.chB.amplitude() * 4 else self.chB.amplitude() * 2;
 | 
			
		||||
    //     const chB_left = if (self.dma_cnt.chB_left.read()) chB_sample else 0;
 | 
			
		||||
    //     const chB_right = if (self.dma_cnt.chB_right.read()) chB_sample else 0;
 | 
			
		||||
 | 
			
		||||
    //     // Mix all Channels
 | 
			
		||||
    //     const left = (chA_left + chB_left + psg_left) / 6.0;
 | 
			
		||||
    //     const right = (chA_right + chB_right + psg_right) / 6.0;
 | 
			
		||||
 | 
			
		||||
    //     if (self.sampling_cycle != self.bias.sampling_cycle.read()) {
 | 
			
		||||
    //         log.info("Sampling Cycle changed from {} to {}", .{ self.sampling_cycle, self.bias.sampling_cycle.read() });
 | 
			
		||||
 | 
			
		||||
    //         // Sample Rate Changed, Create a new Resampler since i can't figure out how to change
 | 
			
		||||
    //         // the parameters of the old one
 | 
			
		||||
    //         const old = self.stream;
 | 
			
		||||
    //         defer SDL.SDL_FreeAudioStream(old);
 | 
			
		||||
 | 
			
		||||
    //         self.sampling_cycle = self.bias.sampling_cycle.read();
 | 
			
		||||
    //         self.stream = SDL.SDL_NewAudioStream(SDL.AUDIO_F32, 2, @intCast(c_int, self.sampleRate()), SDL.AUDIO_F32, 2, host_sample_rate) orelse unreachable;
 | 
			
		||||
    //     }
 | 
			
		||||
 | 
			
		||||
    //     while (SDL.SDL_AudioStreamAvailable(self.stream) > (@sizeOf(f32) * 2 * 0x800)) {}
 | 
			
		||||
 | 
			
		||||
    //     _ = SDL.SDL_AudioStreamPut(self.stream, &[2]f32{ left, right }, 2 * @sizeOf(f32));
 | 
			
		||||
    //     self.sched.push(.SampleAudio, self.sampleTicks() -| late);
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    fn sampleTicks(self: *const Self) u64 {
 | 
			
		||||
        return (1 << 24) / self.sampleRate();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -33,9 +33,7 @@ pub fn deinit(self: Self) void {
 | 
			
		||||
 | 
			
		||||
pub fn checkedRead(self: *Self, comptime T: type, r15: u32, addr: u32) T {
 | 
			
		||||
    if (r15 < Self.size) {
 | 
			
		||||
        // FIXME: Just give up on *const Self on bus reads, Rekai
 | 
			
		||||
        self.addr_latch = addr;
 | 
			
		||||
 | 
			
		||||
        return self.read(T, addr);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -411,10 +411,18 @@ const Eeprom = struct {
 | 
			
		||||
                    .Large => {
 | 
			
		||||
                        if (self.writer.len() == 14) {
 | 
			
		||||
                            const addr = @intCast(u10, self.writer.finish());
 | 
			
		||||
 | 
			
		||||
                            // TODO: Bit Verbose eh?
 | 
			
		||||
                            const value_buf = buf[@as(u13, addr) * 8 ..][0..8];
 | 
			
		||||
                            const value = @as(u64, value_buf[7]) << 56 | @as(u64, value_buf[6]) << 48 | @as(u64, value_buf[5]) << 40 | @as(u64, value_buf[4]) << 32 | @as(u64, value_buf[3]) << 24 | @as(u64, value_buf[2]) << 16 | @as(u64, value_buf[1]) << 8 | @as(u64, value_buf[0]) << 0;
 | 
			
		||||
 | 
			
		||||
                            // zig fmt: off
 | 
			
		||||
                            const value = @as(u64, value_buf[7]) << 56
 | 
			
		||||
                                | @as(u64, value_buf[6]) << 48
 | 
			
		||||
                                | @as(u64, value_buf[5]) << 40
 | 
			
		||||
                                | @as(u64, value_buf[4]) << 32
 | 
			
		||||
                                | @as(u64, value_buf[3]) << 24
 | 
			
		||||
                                | @as(u64, value_buf[2]) << 16
 | 
			
		||||
                                | @as(u64, value_buf[1]) << 8
 | 
			
		||||
                                | @as(u64, value_buf[0]) << 0;
 | 
			
		||||
                            // zig fmt: on
 | 
			
		||||
 | 
			
		||||
                            self.reader.configure(value);
 | 
			
		||||
                            self.state = .RequestEnd;
 | 
			
		||||
@@ -422,11 +430,20 @@ const Eeprom = struct {
 | 
			
		||||
                    },
 | 
			
		||||
                    .Small => {
 | 
			
		||||
                        if (self.writer.len() == 6) {
 | 
			
		||||
                            // FIXME: Duplicated code from above
 | 
			
		||||
                            const addr = @intCast(u6, self.writer.finish());
 | 
			
		||||
 | 
			
		||||
                            // TODO: Bit Verbose eh?, also duplicate code
 | 
			
		||||
                            const value_buf = buf[@as(u13, addr) * 8 ..][0..8];
 | 
			
		||||
                            const value = @as(u64, value_buf[7]) << 56 | @as(u64, value_buf[6]) << 48 | @as(u64, value_buf[5]) << 40 | @as(u64, value_buf[4]) << 32 | @as(u64, value_buf[3]) << 24 | @as(u64, value_buf[2]) << 16 | @as(u64, value_buf[1]) << 8 | @as(u64, value_buf[0]) << 0;
 | 
			
		||||
 | 
			
		||||
                            // zig fmt: off
 | 
			
		||||
                            const value = @as(u64, value_buf[7]) << 56
 | 
			
		||||
                                | @as(u64, value_buf[6]) << 48
 | 
			
		||||
                                | @as(u64, value_buf[5]) << 40
 | 
			
		||||
                                | @as(u64, value_buf[4]) << 32
 | 
			
		||||
                                | @as(u64, value_buf[3]) << 24
 | 
			
		||||
                                | @as(u64, value_buf[2]) << 16
 | 
			
		||||
                                | @as(u64, value_buf[1]) << 8
 | 
			
		||||
                                | @as(u64, value_buf[0]) << 0;
 | 
			
		||||
                            // zig fmt: on
 | 
			
		||||
 | 
			
		||||
                            self.reader.configure(value);
 | 
			
		||||
                            self.state = .RequestEnd;
 | 
			
		||||
 
 | 
			
		||||
@@ -451,7 +451,6 @@ inline fn thumbIdx(opcode: u16) u10 {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn checkCond(cpsr: PSR, cond: u4) bool {
 | 
			
		||||
    // TODO: Should I implement an enum?
 | 
			
		||||
    return switch (cond) {
 | 
			
		||||
        0x0 => cpsr.z.read(), // EQ - Equal
 | 
			
		||||
        0x1 => !cpsr.z.read(), // NE - Not equal
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user