Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperAuguste committed May 20, 2024
1 parent 9d67213 commit 754b9d9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
2 changes: 0 additions & 2 deletions simulator/src/apu-worklet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class APUProcessor extends AudioWorkletProcessor {
outputRight[index] = pcmRight[index] / 32767;
}

console.log(pcmLeft.length);

return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions simulator/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const ADDR_LIGHT_LEVEL = 0x06;
export const ADDR_NEOPIXELS = 0x08;
export const ADDR_RED_LED = 0x1c;
export const ADDR_BATTERY_LEVEL = 0x1e;
export const ADDR_FRAMEBUFFER = 0x20;
export const ADDR_AUDIO_BUFFER = 0xb01e;
export const ADDR_FRAMEBUFFER = 0x1e;
export const ADDR_AUDIO_BUFFER = 0xa020;

export const CONTROLS_START = 1;
export const CONTROLS_SELECT = 2;
Expand Down
18 changes: 9 additions & 9 deletions src/badge/cart.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub fn svcall_handler() callconv(.Naked) void {
\\ cmp r3, #0xDF
\\ bne 12f
\\ ldrb r3, [r2, #0 * 1]
\\ cmp r3, #12
\\ bhi 13f
\\ cmp r3, #11
\\ bhi 12f
\\ tbb [pc, r3]
\\0:
\\ .byte (0f - 0b) / 2
Expand All @@ -49,12 +49,12 @@ pub fn svcall_handler() callconv(.Naked) void {
\\ .byte (4f - 0b) / 2
\\ .byte (5f - 0b) / 2
\\ .byte (6f - 0b) / 2
\\ .byte (7f - 0b) / 2
\\ .byte (8f - 0b) / 2
\\ .byte (9f - 0b) / 2
\\ .byte (10f - 0b) / 2
\\12:
\\ .byte (11f - 0b) / 2
\\13:
\\ .byte (12f - 0b) / 2
\\ .byte 0xDE
\\ .align 1
\\0:
Expand All @@ -78,18 +78,18 @@ pub fn svcall_handler() callconv(.Naked) void {
\\6:
\\ ldm r1, {r0-r3}
\\ b %[vline:P]
\\8:
\\7:
\\ ldm r1, {r0-r2}
\\ b %[read_flash:P]
\\9:
\\8:
\\ ldm r1, {r0-r1}
\\ b %[write_flash_page:P]
\\10:
\\9:
\\ b %[rand:P]
\\11:
\\10:
\\ ldm r1, {r0-r1}
\\ b %[trace:P]
\\12:
\\11:
\\ lsrs r0, #31
\\ msr control, r0
\\ it eq
Expand Down
12 changes: 6 additions & 6 deletions src/badge/feature_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ export fn update() void {
var wave_t: f32 = 0;

export fn audio() void {
for (&cart.audio_buffer[0], &cart.audio_buffer[1]) |*l, *r| {
const val: i16 = @intFromFloat(@sin(wave_t) * std.math.maxInt(i16));
// for (&cart.audio_buffer[0], &cart.audio_buffer[1]) |*l, *r| {
// const val: i16 = @intFromFloat(@sin(wave_t) * std.math.maxInt(i16));

l.* = val;
r.* = val;
// l.* = val;
// r.* = val;

wave_t += 0.1;
}
// wave_t += 0.1;
// }
}
17 changes: 9 additions & 8 deletions src/board/audio.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const sample_buffer: *volatile [2][512]i16 = @ptrFromInt(0x20000000 + 0xa020);
var call_audio: *const fn () void = undefined;
var call_audio: ?*const fn () void = null;

pub fn init(call_audio_fn: *const fn () void) void {
@setCold(true);
Expand Down Expand Up @@ -185,15 +185,16 @@ pub fn init(call_audio_fn: *const fn () void) void {
}

pub fn mix() callconv(.C) void {
var speaker_enable: port.Level = .low;
// var speaker_enable: port.Level = .low;
const speaker_enable: port.Level = .low;

call_audio();
// if (call_audio) |ca| ca();

for (&sample_buffer[
(dma.get_audio_part() + sample_buffer.len - 1) % sample_buffer.len
]) |sample| {
if (sample != 0) speaker_enable = .high;
}
// for (&sample_buffer[
// (dma.get_audio_part() + sample_buffer.len - 1) % sample_buffer.len
// ]) |sample| {
// if (sample != 0) speaker_enable = .high;
// }

board.SPKR_EN.write(speaker_enable);
dma.ack_audio();
Expand Down
4 changes: 2 additions & 2 deletions src/cart.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ MEMORY
bootloader (rx!w) : ORIGIN = 0x00000000, LENGTH = 0x00004000
runtime_flash (rx!w) : ORIGIN = 0x00004000, LENGTH = 0x0002C000
cart_flash (rx!w) : ORIGIN = 0x00030000, LENGTH = 0x00080000
cart_fixed (rw!x) : ORIGIN = 0x20000000, LENGTH = 0x0000A020
cart_ram (rw!x) : ORIGIN = 0x2000A020, LENGTH = 0x00015FE0
cart_fixed (rw!x) : ORIGIN = 0x20000000, LENGTH = 0x0000A820
cart_ram (rw!x) : ORIGIN = 0x2000A820, LENGTH = 0x000157E0
runtime_ram (rw!x) : ORIGIN = 0x20020000, LENGTH = 0x00008000
cart_stack (rw!x) : ORIGIN = 0x20028000, LENGTH = 0x00004000
runtime_stack (rw!x) : ORIGIN = 0x2002C000, LENGTH = 0x00004000
Expand Down
10 changes: 5 additions & 5 deletions src/cart/api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub const neopixels: *[5]NeopixelColor = @ptrFromInt(base + 0x08);
pub const red_led: *bool = @ptrFromInt(base + 0x1c);
pub const battery_level: *u12 = @ptrFromInt(base + 0x1e);
pub const framebuffer: *volatile [screen_width][screen_height]Pixel = @ptrFromInt(base + 0x20);
pub const audio_buffer: *volatile [2][512]i16 = @ptrFromInt(base + 0xa020);
// pub const audio_buffer: *volatile [2][512]i16 = @ptrFromInt(base + 0xa020);

pub const BlitOptions = struct {
pub const Flags = packed struct(u32) {
Expand Down Expand Up @@ -428,7 +428,7 @@ pub inline fn read_flash(offset: u32, dst: []u8) u32 {
} else {
var clobber_r1: usize = undefined;
var clobber_r2: usize = undefined;
return asm volatile (" svc #8"
return asm volatile (" svc #7"
: [result] "={r0}" (-> u32),
[clobber_r1] "={r1}" (clobber_r1),
[clobber_r2] "={r2}" (clobber_r2),
Expand All @@ -448,7 +448,7 @@ pub inline fn write_flash_page(page: u16, src: [flash_page_size]u8) void {
} else {
var clobber_r0: usize = undefined;
var clobber_r1: usize = undefined;
asm volatile (" svc #9"
asm volatile (" svc #8"
: [clobber_r0] "={r0}" (clobber_r0),
[clobber_r1] "={r1}" (clobber_r1),
: [page] "{r0}" (page),
Expand All @@ -465,7 +465,7 @@ pub inline fn rand() u32 {
extern fn rand() u32;
}.rand();
} else {
return asm volatile (" svc #10"
return asm volatile (" svc #9"
: [result] "={r0}" (-> u32),
:
: "r1", "r2", "r3"
Expand All @@ -482,7 +482,7 @@ pub inline fn trace(x: []const u8) void {
} else {
var clobber_r0: usize = undefined;
var clobber_r1: usize = undefined;
asm volatile (" svc #11"
asm volatile (" svc #10"
: [clobber_r0] "={r0}" (clobber_r0),
[clobber_r1] "={r1}" (clobber_r1),
: [x_ptr] "{r0}" (x.ptr),
Expand Down

0 comments on commit 754b9d9

Please sign in to comment.