mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
uvm32 initial version
This commit is contained in:
commit
c9d30b6d28
34 changed files with 2088 additions and 0 deletions
40
apps/zig-mandel/src/main.zig
Normal file
40
apps/zig-mandel/src/main.zig
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
const uvm = @import("uvm.zig");
|
||||
|
||||
fn mandel() void {
|
||||
const xmin: i32 = -8601;
|
||||
const xmax: i32 = 2867;
|
||||
const ymin: i32 = -4915;
|
||||
const ymax: i32 = 4915;
|
||||
const maxiter: usize = 32;
|
||||
const dx: i32 = @divTrunc((xmax - xmin), 79);
|
||||
const dy: i32 = @divTrunc((ymax - ymin), 24);
|
||||
var cy = ymin;
|
||||
|
||||
while (cy <= ymax) {
|
||||
var cx = xmin;
|
||||
while (cx <= xmax) {
|
||||
var x: i32 = 0;
|
||||
var y: i32 = 0;
|
||||
var x2: i32 = 0;
|
||||
var y2: i32 = 0;
|
||||
var iter: usize = 0;
|
||||
while (iter < maxiter) : (iter += 1) {
|
||||
if (x2 + y2 > 16384) break;
|
||||
y = ((x * y) >> 11) + cy;
|
||||
x = x2 - y2 + cx;
|
||||
x2 = (x * x) >> 12;
|
||||
y2 = (y * y) >> 12;
|
||||
uvm.yield();
|
||||
}
|
||||
uvm.printc(' ' + @as(u8, @intCast(iter)));
|
||||
cx += dx;
|
||||
}
|
||||
uvm.printc('\n');
|
||||
cy += dy;
|
||||
}
|
||||
}
|
||||
|
||||
export fn main() void {
|
||||
mandel();
|
||||
uvm.println("Hello world");
|
||||
}
|
||||
38
apps/zig-mandel/src/uvm.zig
Normal file
38
apps/zig-mandel/src/uvm.zig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const uvm32 = @cImport({
|
||||
@cDefine("USE_MAIN", "1");
|
||||
@cInclude("uvm32_target.h");
|
||||
});
|
||||
const std = @import("std");
|
||||
|
||||
pub inline fn println(val: [:0]const u8) void {
|
||||
asm volatile ("csrw " ++ std.fmt.comptimePrint("0x{x}", .{uvm32.IOREQ_PRINTLN}) ++ ", %[arg1]"
|
||||
:
|
||||
: [arg1] "r" (val.ptr),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn printd(val: u32) void {
|
||||
asm volatile ("csrw " ++ std.fmt.comptimePrint("0x{x}", .{uvm32.IOREQ_PRINTD}) ++ ", %[arg1]"
|
||||
:
|
||||
: [arg1] "r" (val),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn printx(val: u32) void {
|
||||
asm volatile ("csrw " ++ std.fmt.comptimePrint("0x{x}", .{uvm32.IOREQ_PRINTX}) ++ ", %[arg1]"
|
||||
:
|
||||
: [arg1] "r" (val),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn printc(val: u32) void {
|
||||
asm volatile ("csrw " ++ std.fmt.comptimePrint("0x{x}", .{uvm32.IOREQ_PRINTC}) ++ ", %[arg1]"
|
||||
:
|
||||
: [arg1] "r" (val),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn yield() void {
|
||||
asm volatile (std.fmt.comptimePrint("csrwi 0x{x}, 0", .{uvm32.IOREQ_YIELD}));
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue