Skip to content

Commit

Permalink
Implement lcd dma
Browse files Browse the repository at this point in the history
 * fix fp context
 * fix light sensor reading
 * fix svc handler debug return value hack that was not properly reverted
  • Loading branch information
jacobly0 committed May 18, 2024
1 parent c21982d commit b9fd04a
Show file tree
Hide file tree
Showing 27 changed files with 1,181 additions and 1,487 deletions.
11 changes: 4 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ const Build = std.Build;
const MicroZig = @import("microzig/build");
const atsam = @import("microzig/bsp/microchip/atsam");

pub const py_badge: MicroZig.Target = .{
.preferred_format = .elf,
.chip = atsam.chips.atsamd51j19,
.hal = null,
};

fn sycl_badge_microzig_target(d: *Build.Dependency) MicroZig.Target {
var atsamd51j19_chip_with_fpu = atsam.chips.atsamd51j19.chip;
atsamd51j19_chip_with_fpu.cpu.target.cpu_features_add = std.Target.arm.featureSet(&.{.vfp4d16sp});
atsamd51j19_chip_with_fpu.cpu.target.abi = .eabihf;
return .{
.preferred_format = .elf,
.chip = atsam.chips.atsamd51j19.chip,
.chip = atsamd51j19_chip_with_fpu,
.hal = .{
.root_source_file = d.builder.path("src/hal.zig"),
},
Expand Down
4 changes: 2 additions & 2 deletions samples/feature_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export fn update() void {

for (0..cart.screen_height) |y| {
for (0..cart.screen_width) |x| {
cart.framebuffer[y * cart.screen_width + x] = .{
cart.framebuffer[x][y].setColor(.{
.r = @intFromFloat(@as(f32, @floatFromInt(x)) / cart.screen_width * 31),
.g = green_565,
.b = @intFromFloat(@as(f32, @floatFromInt(y)) / cart.screen_height * 31),
};
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion showcase/carts/metalgear-timer/src/metalgear-timer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn r(x: usize, y: usize, w: usize, h: usize) void {
const y1 = y0 + sy * h;
for (y0..y1) |yi| {
for (x0..x1) |xi| {
cart.framebuffer[yi * cart.screen_width + xi] = color;
cart.framebuffer[xi][yi].setColor(color);
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions showcase/carts/plasma/src/plasma.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const hue_colors = init_hue_colors: {

var plasma_buffer = init_plasma_buffer: {
@setEvalBranchQuota(100000);
var initial_plasma_buffer: [cart.framebuffer.len]u8 = undefined;
var initial_plasma_buffer: [cart.screen_width][cart.screen_height]u8 = undefined;
var y: usize = 0;
while (y < cart.screen_height) : (y += 1) {
var x: usize = 0;
Expand All @@ -37,16 +37,18 @@ var plasma_buffer = init_plasma_buffer: {
value += @sin(@sqrt(fx * fx + fy * fy) / 8.0);
// shift range from -4 .. 4 to 0 .. 255
value = std.math.clamp((value + 4) * 32, 0, 255);
initial_plasma_buffer[y * cart.screen_width + x] = @intFromFloat(value);
initial_plasma_buffer[x][y] = @intFromFloat(value);
}
}
break :init_plasma_buffer initial_plasma_buffer;
};

fn updatePlasma() void {
for (0..cart.framebuffer.len) |i| {
plasma_buffer[i] +%= 2;
cart.framebuffer[i] = hue_colors[plasma_buffer[i]];
for (cart.framebuffer, &plasma_buffer) |*fb_col, *plasma_col| {
for (fb_col, plasma_col) |*fb_pix, *plasma_pix| {
plasma_pix.* +%= 2;
fb_pix.setColor(hue_colors[plasma_pix.*]);
}
}
}

Expand Down
10 changes: 3 additions & 7 deletions showcase/carts/raytracer/src/camera.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ w: Vec3,
defocus_disk_u: Vec3,
defocus_disk_v: Vec3,

pub fn init(position: Vec3) Camera {
var self: Camera = undefined;
pub fn init(self: *Camera, position: Vec3) void {
self.lookfrom = position;
self.camera_center = self.lookfrom;

Expand All @@ -68,8 +67,6 @@ pub fn init(position: Vec3) Camera {

self.defocus_disk_u = self.u.mul_scalar(defocus_radius);
self.defocus_disk_v = self.v.mul_scalar(defocus_radius);

return self;
}

fn pixel_sample_square(self: *Camera) Vec3 {
Expand Down Expand Up @@ -111,13 +108,12 @@ pub fn render(self: *Camera, world: *HittableList) !void {
const samples: f32 = @floatFromInt(self.samples);
col = col.div_scalar(samples);

const index: usize = i + j * image_width;
const color = vec.color3_to_color(col);
cart.framebuffer[index] = .{
cart.framebuffer[i][j].setColor(.{
.r = @truncate(color.rgb.r >> 3),
.g = @truncate(color.rgb.g >> 2),
.b = @truncate(color.rgb.b >> 3),
};
});
}
}
//std.debug.print("Done!\n", .{});
Expand Down
3 changes: 2 additions & 1 deletion showcase/carts/raytracer/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub fn main_program() !void {
const x = radius * std.math.sin(angle_rad);
const y = radius * std.math.cos(angle_rad);

var camera = Camera.init(Vec3.init(x, 2, y));
var camera: Camera = undefined;
camera.init(Vec3.init(x, 2, y));

var a: i32 = -5;
while (a < 5) : (a += 1) {
Expand Down
12 changes: 9 additions & 3 deletions showcase/carts/zeroman/src/Renderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const Sprite = struct {
const index = (y + src_y0) * sprite.width + (if (flip_x) @abs(src_rect.w) - 1 - x else x) + src_x0;
const color = sprite.colors[sprite.indices.get(index)];
if (color.r == 31 and color.g == 0 and color.b == 31) continue;
cart.framebuffer[@as(usize, @intCast(dst_y * cart.screen_width + dst_x))] = color;
cart.framebuffer[@intCast(dst_x)][@intCast(dst_y)].setColor(color);
}
}
}
Expand All @@ -95,7 +95,7 @@ pub const Tilemap = struct {
const src_y = (tile_index / 16) * tile_size + (y % tile_size);
const color = tiles.colors[tiles.indices.get(src_y * tiles.width + src_x)];
if (color.r == 31 and color.g == 0 and color.b == 31) continue;
cart.framebuffer[@as(usize, @intCast((dst_y) * cart.screen_width + dst_x))] = color;
cart.framebuffer[@intCast(dst_x)][@intCast(dst_y)].setColor(color);
}
}
}
Expand All @@ -104,5 +104,11 @@ pub const Tilemap = struct {
pub fn init() void {}

pub fn clear() void {
@memset(cart.framebuffer, .{ .r = 0, .g = 0, .b = 0 });
cart.rect(.{
.x = 0,
.y = 0,
.width = cart.screen_width,
.height = cart.screen_height,
.fill_color = .{ .r = 0, .g = 0, .b = 0 },
});
}
6 changes: 6 additions & 0 deletions simulator/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export class Runtime {
read_flash: this.read_flash.bind(this),
write_flash_page: this.write_flash_page.bind(this),

rand: this.rand.bind(this),

trace: this.trace.bind(this),
};

Expand Down Expand Up @@ -207,6 +209,10 @@ export class Runtime {
console.log(str);
}

rand (): number {
return ~~(Math.random() * 4294967296.0);
}

trace (strUtf8Ptr: number, byteLength: number) {
const strUtf8 = new Uint8Array(this.memory.buffer, strUtf8Ptr, byteLength);
const str = new TextDecoder().decode(strUtf8);
Expand Down
Loading

0 comments on commit b9fd04a

Please sign in to comment.