Merge branch 'main' of ssh://musuka.dev:2222/paoda/scratch

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-08-26 02:41:13 -05:00
commit ec57dc7231
13 changed files with 635 additions and 93 deletions

View File

@ -37,7 +37,6 @@ pub fn draw_sprite(disp: *Display, pos: *const Point, data: *const []u8) bool {
const temp = (byte >> x_bit_offset) & 0x01;
const bit = @intCast(u1, temp);
// const bit = @as(u1, temp);
const i = DISPLAY_WIDTH * y + x;

View File

@ -14,7 +14,7 @@ pub const Cpu = struct {
sp: u16,
v: [16]u8,
stack: [16]u16,
memory: [4096]u8,
memory: [0x1000]u8,
disp: Display,
};
@ -34,7 +34,6 @@ pub fn decode(cpu: *Cpu, word: u16) ?Instruction {
const nib3: u4 = @intCast(u4, (word & 0x00F0) >> 4);
const nib4: u4 = @intCast(u4, (word & 0x000F) >> 0);
if (nib1 == 0x0) {
// nib2 is 0x0, nib3 is 0xE
@ -84,20 +83,20 @@ pub fn decode(cpu: *Cpu, word: u16) ?Instruction {
pub fn execute(cpu: *Cpu, instr: Instruction) void {
switch (instr) {
.CLS => std.debug.print("CLS\n", .{}),
.CLS => std.log.debug("CLS", .{}),
.RET => {
std.debug.print("RET\n", .{});
std.log.debug("RET", .{});
cpu.pc = cpu.stack[cpu.sp];
cpu.sp -= 1;
},
.JP => |addr| {
std.debug.print("JP 0x{X:}\n", .{ addr });
std.log.debug("JP 0x{X:}", .{ addr });
cpu.pc = addr;
},
.CALL => |addr| {
std.debug.print("CALL 0x{X:}\n", .{ addr });
std.log.debug("CALL 0x{X:}", .{ addr });
cpu.sp += 1;
cpu.stack[cpu.sp] = cpu.pc;
@ -106,7 +105,7 @@ pub fn execute(cpu: *Cpu, instr: Instruction) void {
.SE_3 => |args| {
const x = args.x;
const kk = args.kk;
std.debug.print("SE V{}, 0x{X:}\n", .{ x, kk });
std.log.debug("SE V{}, 0x{X:}", .{ x, kk });
if (cpu.v[x] != kk) {
cpu.pc += 2;
@ -115,19 +114,19 @@ pub fn execute(cpu: *Cpu, instr: Instruction) void {
.LD_6 => |args| {
const x = args.x;
const kk = args.kk;
std.debug.print("LD V{} 0x{X:}\n", .{ x, kk });
std.log.debug("LD V{} 0x{X:}", .{ x, kk });
cpu.v[x] = kk;
},
.LD_I => |addr| {
std.debug.print("LD I, 0x{X:}\n", .{ addr });
std.log.debug("LD I, 0x{X:}", .{ addr });
cpu.i = addr;
},
.DRW => |args| {
const x = args.x;
const y = args.y;
const n = args.n;
std.debug.print("DRW V{}, V{}, 0x{X:}\n", .{ x, y, n });
std.log.debug("DRW V{}, V{}, 0x{X:}", .{ x, y, n });
const draw_pos: Point = .{ .x = cpu.v[x], .y = cpu.v[y] };
const sprite_data = cpu.memory[cpu.i..(cpu.i + n)];
@ -141,7 +140,7 @@ pub fn execute(cpu: *Cpu, instr: Instruction) void {
.ADD_7 => |args| {
const x = args.x;
const kk = args.kk;
std.debug.print("ADD V{}, 0x{X:}\n", .{ x, kk });
std.log.debug("ADD V{}, 0x{X:}", .{ x, kk });
cpu.v[x] = cpu.v[x] + kk;
}
@ -158,18 +157,19 @@ fn load_rom(cpu: *Cpu, buf: []u8) void {
}
pub fn load_rom_path(cpu: *Cpu, path: []const u8) !void {
var alloc = std.heap.page_allocator;
var heap = std.heap.page_allocator;
const file = try std.fs.cwd().openFile(path, .{ .read = true });
defer file.close();
const file_size = try file.getEndPos();
const rom_buf = try file.readToEndAlloc(alloc, file_size);
const rom_buf = try file.readToEndAlloc(heap, file_size);
defer heap.free(rom_buf);
load_rom(cpu, rom_buf);
}
pub fn cycle(cpu: *Cpu) void {
pub fn step(cpu: *Cpu) void {
const opcode = fetch(cpu);
const maybe_instr = decode(cpu, opcode);

View File

@ -1,107 +1,77 @@
const std = @import("std");
const cpu = @import("cpu.zig");
const emu = @import("emu.zig");
const Display = @import("display.zig").Display;
const c = @cImport({
@cInclude("SDL2/SDL.h");
});
const assert = @import("std").debug.assert;
const c = @cImport(@cInclude("SDL.h"));
// See https://github.com/zig-lang/zig/issues/565
// SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
// SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
// SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000u
const SDL_WINDOWPOS_UNDEFINED = @bitCast(c_int, c.SDL_WINDOWPOS_UNDEFINED_MASK);
const Cpu = emu.Cpu;
extern fn SDL_PollEvent(event: *c.SDL_Event) c_int;
const WIDTH = 64;
const HEIGHT = 32;
const WINDOW_WIDTH = WIDTH * 10;
const WINDOW_HEIGHT = HEIGHT * 10;
const PIXELBUF_LEN = WIDTH * HEIGHT * @sizeOf(u32);
// SDL_RWclose is fundamentally unrepresentable in Zig, because `ctx` is
// evaluated twice. One could make the case that this is a bug in SDL,
// especially since the docs list a real function prototype that would not
// have this double-evaluation of the parameter.
// If SDL would instead of a macro use a static inline function,
// it would resolve the SDL bug as well as make the function visible to Zig
// and to debuggers.
// SDL_rwops.h:#define SDL_RWclose(ctx) (ctx)->close(ctx)
inline fn SDL_RWclose(ctx: [*]c.SDL_RWops) c_int {
return ctx[0].close.?(ctx);
}
pub fn main() !void {
// Initialize SDL2
if (c.SDL_Init(c.SDL_INIT_VIDEO) != 0) {
c.SDL_Log("Unable to initialize SDL: %s", c.SDL_GetError());
return error.SDLInitializationFailed;
}
_ = c.SDL_Init(c.SDL_INIT_VIDEO);
defer c.SDL_Quit();
// Create Screen (Maybe introduce scaling somehow?)
const screen = c.SDL_CreateWindow("Zig8", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 320, c.SDL_WINDOW_OPENGL) orelse
{
c.SDL_Log("Unable to create window: %s", c.SDL_GetError());
return error.SDLInitializationFailed;
};
defer c.SDL_DestroyWindow(screen);
const window = c.SDL_CreateWindow("CHIP-8", c.SDL_WINDOWPOS_CENTERED, c.SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, c.SDL_WINDOW_OPENGL);
defer c.SDL_DestroyWindow(window);
// Create Renderer
const renderer = c.SDL_CreateRenderer(screen, -1, c.SDL_RENDERER_ACCELERATED) orelse {
c.SDL_Log("Unable to create renderer: %s", c.SDL_GetError());
return error.SDLInitializationFailed;
};
const renderer = c.SDL_CreateRenderer(window, -1, c.SDL_RENDERER_ACCELERATED);
defer c.SDL_DestroyRenderer(renderer);
// Create RGBA Texture
const texture = c.SDL_CreateTexture(renderer, c.SDL_PIXELFORMAT_RGBA8888, c.SDL_TEXTUREACCESS_STREAMING, 64, 32) orelse {
c.SDL_Log("Unable to create texture: %s", c.SDL_GetError());
return error.SDLInitializationFailed;
};
const texture = c.SDL_CreateTexture(renderer, c.SDL_PIXELFORMAT_RGBA8888, c.SDL_TEXTUREACCESS_STATIC, WIDTH, HEIGHT);
defer c.SDL_DestroyTexture(texture);
// Initialize CHIP-8 Emulator
var chip8 = cpu.Cpu {
var zig8 = emu.Cpu {
.i = 0x00,
.pc = 0x0200,
.pc = 0x200,
.sp = 0x00,
.v = [_]u8{0x0} ** 16,
.stack = [_]u16{0x0} ** 16,
.memory = [_]u8{0x0} ** 4096,
.v = [_]u8{0x00} ** 16,
.stack = [_]u16{0x00} ** 16,
.memory = [_]u8{0x0000} ** 0x1000,
.disp = Display.new(),
};
var path = "./bin/IBM Logo.ch8";
try emu.load_rom_path(&zig8, "./bin/IBM Logo.ch8");
var pixel_buf: [PIXELBUF_LEN]u8 = [_]u8 {0x00} ** PIXELBUF_LEN;
// Load Game ROM into CHIP-8 Emulator
try cpu.load_rom_path(&chip8, path);
// Create Pixel Buffer (Temporary)
const buf_size = 64 * 32 * @sizeOf(u32);
var pixels: [buf_size]u8 = [_]u8{255} ** buf_size;
// Render
var quit = false;
while (!quit) {
var buf_ptr: [*c]?*c_void = &@ptrCast(?*c_void, &pixels[0]);
_ = c.SDL_LockTexture(texture, null, buf_ptr, 64 * @sizeOf(u32));
c.SDL_UnlockTexture(texture);
emuloop: while(true) {
_ = c.SDL_UpdateTexture(texture, null, @ptrCast(*const c_void, &pixel_buf), WIDTH * @sizeOf(u32));
_ = c.SDL_RenderCopy(renderer, texture, null, null);
_ = c.SDL_RenderPresent(renderer);
var event: c.SDL_Event = undefined;
while (SDL_PollEvent(&event) != 0) {
switch (event.@"type") {
c.SDL_QUIT => {
quit = true;
},
else => {},
while(c.SDL_PollEvent(&event) != 0) {
switch(event.type) {
c.SDL_QUIT => break :emuloop,
else => {}
}
}
_ = c.SDL_RenderClear(renderer);
_ = c.SDL_RenderCopy(renderer, texture, null, null);
c.SDL_RenderPresent(renderer);
cpu.cycle(&chip8);
c.SDL_Delay(17);
emu.step(&zig8);
draw(&zig8.disp, &pixel_buf);
}
}
fn draw(display: *const Display, pixel_buf: *[8192]u8) void {
var emu_i: usize = 0;
while (emu_i < display.buf.len) : (emu_i += 1) {
var pixel_i = emu_i * 4;
if (display.buf[emu_i] == 0x01) {
pixel_buf[pixel_i] = 0xFF;
pixel_buf[pixel_i + 1] = 0xFF;
pixel_buf[pixel_i + 2] = 0xFF;
pixel_buf[pixel_i + 3] = 0xFF;
} else {
pixel_buf[pixel_i] = 0xFF;
pixel_buf[pixel_i + 1] = 0x00;
pixel_buf[pixel_i + 2] = 0x00;
pixel_buf[pixel_i + 3] = 0x00;
}
}
}

10
2021-04-19/max.py Normal file
View File

@ -0,0 +1,10 @@
dict = {}
for line in open("words.txt"):
word = line.strip()
final_letter = word[-1]
dict[final_letter] = word
print(dict)

421
2021-05-05/gamepad-test/Cargo.lock generated Normal file
View File

@ -0,0 +1,421 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "base-x"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bumpalo"
version = "3.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
[[package]]
name = "cc"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "core-foundation"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b"
[[package]]
name = "discard"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "gamepad-test"
version = "0.1.0"
dependencies = [
"gilrs",
]
[[package]]
name = "gilrs"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e986f911d937f4395dfc2a39618dcef452773d32dcdbe0828c623f76588f749"
dependencies = [
"fnv",
"gilrs-core",
"log",
"uuid",
"vec_map",
]
[[package]]
name = "gilrs-core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a5e5bb97bf9a0d9519a28cf38839cf1d6d9bb572b48e3c67202271fec2ed5e7"
dependencies = [
"core-foundation",
"io-kit-sys",
"libc",
"libudev-sys",
"log",
"nix",
"rusty-xinput",
"stdweb",
"uuid",
"vec_map",
"winapi",
]
[[package]]
name = "io-kit-sys"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f21dcc74995dd4cd090b147e79789f8d65959cbfb5f0b118002db869ea3bd0a0"
dependencies = [
"core-foundation-sys",
"mach",
]
[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
[[package]]
name = "libudev-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
dependencies = [
"libc",
"pkg-config",
]
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "mach"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1"
dependencies = [
"libc",
]
[[package]]
name = "nix"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a"
dependencies = [
"bitflags",
"cc",
"cfg-if",
"libc",
]
[[package]]
name = "pkg-config"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
name = "proc-macro2"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "rusty-xinput"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2aa654bc32eb9ca14cce1a084abc9dfe43949a4547c35269a094c39272db3bb"
dependencies = [
"lazy_static",
"log",
"winapi",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171"
[[package]]
name = "serde_derive"
version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "sha1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "stdweb"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
dependencies = [
"discard",
"rustc_version",
"serde",
"serde_json",
"stdweb-derive",
"stdweb-internal-macros",
"stdweb-internal-runtime",
"wasm-bindgen",
]
[[package]]
name = "stdweb-derive"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn",
]
[[package]]
name = "stdweb-internal-macros"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1",
"syn",
]
[[package]]
name = "stdweb-internal-runtime"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]]
name = "syn"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "wasm-bindgen"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@ -0,0 +1,10 @@
[package]
name = "gamepad-test"
version = "0.1.0"
authors = ["Rekai Musuka <rekai@musuka.dev>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gilrs = "*"

View File

@ -0,0 +1,21 @@
use gilrs::{Button, Event, Gilrs};
fn main() {
let mut gilrs = Gilrs::new().unwrap();
// Iterate over all connected gamepads
for (_id, gamepad) in gilrs.gamepads() {
println!("{} is {:?}", gamepad.name(), gamepad.power_info());
}
let mut active_gamepad = None;
loop {
if active_gamepad.is_none() {
active_gamepad = gilrs.next_event().map(|e| e.id);
}
let maybe_gamepad = active_gamepad.map(|id| gilrs.gamepad(id));
maybe_gamepad.map(|gamepad| dbg!(gamepad.is_pressed(Button::South)));
}
}

View File

@ -0,0 +1 @@
import * as AES from "https://github.com/brix/crypto-js/src/aes.js";

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How many Letters?</title>
</head>
<body>
<textarea id="input" name="input" id="" cols="30" rows="10"></textarea>
<button id="submit" type="submit">Submit</button>
<h3>Output</h3>
<table id="output"></table>
</body>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
<script>
const btn = document.querySelector("#submit");
const textarea = document.querySelector("#input");
const table = document.querySelector("#output");
btn.addEventListener("click", () => {
let frequency = getFrequency(textarea.value);
output.innerHTML = mapToTableCells(frequency);
});
function mapToTableCells(map) {
let str = "<tr><th>Character</th><th>Times Appeared</th></tr>";
for (const pair of map[Symbol.iterator]()) {
str += `<tr><td>${pair[0]}</td><td>${pair[1]}</td></tr>`
}
return str;
}
function getFrequency(str) {
const freq = new Map();
for (let i = 0; i < str.length; i++) {
const char = str.charAt(i);
if (freq.has(char)) {
let count = freq.get(char);
freq.set(char, count + 1);
} else {
freq.set(char, 1);
}
}
return freq;
}
</script>
</html>

View File

@ -0,0 +1,27 @@
# hey bro can I ask for a little help?
# I want to figure out a script or sumn that can count and separate the characters in a string of text
# like if I enter in dushdhaosbvdiebwb
# itll tell me how many of which character is in it
# key, value
# string, integer
# "a": 1
#
def main():
freq = {}
str = input("Enter Text: ")
for char in str:
if char in freq:
freq[char] += 1
else:
freq[char] = 1
print(freq)
if __name__ == "__main__":
main()

7
2021-07-06/fizz_buzz/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "fizz_buzz"
version = "0.1.0"

View File

@ -0,0 +1,8 @@
[package]
name = "fizz_buzz"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1 @@
fn main(){for n in 1..101{let mut m=String::new();if n%3==0{m+="Fizz";}if n%5==0{m+="Buzz";}println!("{}",if m.len()==0{n.to_string()}else{m});}}