Skip to content

Commit

Permalink
kc85 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Jul 22, 2024
1 parent 53a7ea4 commit d9d085b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/common/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub const memory = @import("memory.zig");
pub const glue = @import("glue.zig");
pub const clock = @import("clock.zig");
pub const filter = @import("filter.zig");
pub const utils = @import("utils.zig");
29 changes: 29 additions & 0 deletions src/common/utils.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const std = @import("std");
const assert = std.debug.assert;

// shorthand for std.mem.copyForwards
pub fn cp(src: []const u8, dst: []u8) void {
std.mem.copyForwards(u8, dst, src);
}

// 32-bit xorshifter
pub fn xorshift32(in_x: u32) u32 {
var x = in_x;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return x;
}

pub fn fillNoise(slice: []u8, seed: u32) u32 {
assert((slice.len & 3) == 0);
var x = seed;
for (0..(slice.len >> 2)) |i| {
x = xorshift32(x);
slice[i * 4] = @truncate(x);
slice[i * 4 + 1] = @truncate(x >> 8);
slice[i * 4 + 2] = @truncate(x >> 16);
slice[i * 4 + 3] = @truncate(x >> 24);
}
return x;
}
5 changes: 1 addition & 4 deletions src/systems/bombjack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const common = @import("common");
const memory = common.memory;
const clock = common.clock;
const pin = common.bitutils.pin;
const cp = common.utils.cp;
const AudioCallback = common.glue.AudioCallback;
const AudioOptions = common.glue.AudioOptions;
const DisplayInfo = common.glue.DisplayInfo;
Expand Down Expand Up @@ -842,10 +843,6 @@ pub const Bombjack = struct {
self.main_board.palette[pal_index] = c;
}

fn cp(src: []const u8, dst: []u8) void {
std.mem.copyForwards(u8, dst, src);
}

fn initMainRom(opts: Options) [5][0x2000]u8 {
var rom: [5][0x2000]u8 = undefined;
cp(opts.roms.main_0000_1FFF, &rom[0]);
Expand Down
24 changes: 17 additions & 7 deletions src/systems/kc85.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const common = @import("common");
const memory = common.memory;
const clock = common.clock;
const pin = common.bitutils.pin;
const cp = common.utils.cp;
const fillNoise = common.utils.fillNoise;
const AudioCallback = common.glue.AudioCallback;
const AudioOptions = common.glue.AudioOptions;
const DisplayInfo = common.glue.DisplayInfo;
Expand Down Expand Up @@ -287,7 +289,7 @@ pub fn Type(comptime model: Model) type {
mem: Memory,

// memory buffers
ram: [8][0x4000]u8, // up to 8 16-KByte RAM banks
ram: [8][0x4000]u8,
rom: Rom,
ext_buf: [EXP.BUF_SIZE]u8,
fb: [DISPLAY.FB_SIZE]u8 align(128),
Expand All @@ -303,8 +305,20 @@ pub fn Type(comptime model: Model) type {
.junk_page = &self.junk_page,
.unmapped_page = &self.unmapped_page,
}),
// FIXME: on KC85/2, /3 fill with noise
.ram = std.mem.zeroes(@TypeOf(self.ram)),
.ram = init: {
var arr: [8][0x4000]u8 = undefined;
if (model == .KC854) {
// on KC85/4, RAM is filled with zeroes
arr = std.mem.zeroes(@TypeOf(self.ram));
} else {
// on KC85/2, /3 RAM is filled with noise
var x: u32 = 0x6D98302B; // seed for xorshift32
inline for (0..8) |i| {
x = fillNoise(&arr[i], x);
}
}
break :init arr;
},
.rom = initRoms(opts),
.ext_buf = std.mem.zeroes(@TypeOf(self.ext_buf)),
.fb = std.mem.zeroes(@TypeOf(self.fb)),
Expand Down Expand Up @@ -349,10 +363,6 @@ pub fn Type(comptime model: Model) type {
};
}

fn cp(src: []const u8, dst: []u8) void {
std.mem.copyForwards(u8, dst, src);
}

fn initRoms(opts: Options) Rom {
var rom: Rom = undefined;
switch (model) {
Expand Down
5 changes: 1 addition & 4 deletions src/systems/namco.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const memory = common.memory;
const clock = common.clock;
const filter = common.filter;
const pin = common.bitutils.pin;
const cp = common.utils.cp;
const AudioCallback = common.glue.AudioCallback;
const AudioOptions = common.glue.AudioOptions;
const DisplayInfo = common.glue.DisplayInfo;
Expand Down Expand Up @@ -765,10 +766,6 @@ pub fn Type(comptime sys: System) type {
}
}

fn cp(src: []const u8, dst: []u8) void {
std.mem.copyForwards(u8, dst, src);
}

fn initSysRom(opts: Options) [MEMMAP.CPU_ROM_SIZE]u8 {
var rom: [MEMMAP.CPU_ROM_SIZE]u8 = undefined;
if (sys == .Pacman) {
Expand Down

0 comments on commit d9d085b

Please sign in to comment.