Something went wrong. Try again.
A cycle-accurate Apple II and Apple IIgs emulator written in Zig, usable as both a program and a library.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>//// SPDX-License-Identifier: MIT
const std = @import("std");
const json = @import("json.zig");
pub const Direction = enum { read, write,};
address: u16,value: u8,direction: Direction,
/// Parses one access on the bus, as an [address, value, direction] triple. The/// corpus stores these as arrays rather than objects, so the default object/// based parser cannot be used.////// Read straight off the token stream, for the reason given in RAM.zig.pub fn jsonParse( alloc: std.mem.Allocator, source: anytype, options: std.json.ParseOptions,) std.json.ParseError(@TypeOf(source.*))!@This() { _ = alloc; _ = options; try json.expect(source, .array_begin); const address = try json.number(source, u16); const value = try json.number(source, u8); const direction = try json.string(source, Direction); try json.expect(source, .array_end); return .{ .address = address, .value = value, .direction = direction };}
/// Parses one access from an already parsed JSON value.pub fn jsonParseFromValue(_: std.mem.Allocator, value: std.json.Value, _: std.json.ParseOptions) std.json.ParseFromValueError!@This() { const items = switch (value) { .array => |v| v.items, else => return error.UnexpectedToken, }; if (items.len != 3) return error.LengthMismatch; const direction = switch (items[2]) { .string => |s| std.meta.stringToEnum(Direction, s) orelse return error.UnexpectedToken, else => return error.UnexpectedToken, }; return .{ .address = try json.cast(u16, items[0]), .value = try json.cast(u8, items[1]), .direction = direction, };}