Skip to content

Instantly share code, notes, and snippets.

View build-c-bios.md
cd
sudo apt install -y pasmo
git clone https://git.code.sf.net/p/cbios/cbios cbios-cbios
cd cbios-cbios
make
ls -lR derived/
@t-mat
t-mat / microbench-win32-timemeasurement-apis.cpp
Created Apr 13, 2021
[WIN32]Casual benchmark of WIN32 time measurement APIs
View microbench-win32-timemeasurement-apis.cpp
// Casual microbenchmark of WIN32 time measurement APIs
//
// This micro-benchmark compares some WIN32 time measurement APIs.
// It calls each API for 128 million times and shows actual consumed
// time in milli-seconds including overhead of loop, etc.
//
// Result:
// clock() , dt= 4863.0996 ms, N=134217728, tx=0x0000004c321019a3
// GetTickCount64() , dt= 198.9263 ms, N=134217728, tx=0x0052290d9540cbfa
// QueryPerformanceCounter() , dt= 1745.0657 ms, N=134217728, tx=0x896882087bc31bb8
@t-mat
t-mat / GetDiskFreeSpace.cpp
Created Apr 10, 2021
[WIN32] Retrieve disk information from available drives.
View GetDiskFreeSpace.cpp
// Retrieve disk information from available drives.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <locale.h>
#include <tuple>
std::tuple<uint64_t, uint64_t, uint64_t> getDiskFreeSpace(const wchar_t* path) {
wchar_t volumePath[256];
if(FALSE == GetVolumePathNameW(path, volumePath, static_cast<DWORD>(std::size(volumePath)))) {
return { 0, 0, 0 };
@t-mat
t-mat / crc32-generator.cpp
Last active Apr 10, 2021
[C++20]Compile-time and runtime CRC-32 table and code generator.
View crc32-generator.cpp
// CRC-32 table and code generator
//
// Compile:
// g++-10 -std=c++20 -DMY_CRC32_GENERATOR_TEST crc32-generator.cpp && ./a.out
// clang++ -std=c++20 -DMY_CRC32_GENERATOR_TEST crc32-generator.cpp && ./a.out
//
// Usage:
// #include <stdio.h>
// #include <array>
// #include "crc32-generator.cpp"
@t-mat
t-mat / UncompressedPngGenerator.hpp
Last active May 22, 2021
[C++]Generate uncompressed PNG file
View UncompressedPngGenerator.hpp
// Uncompressed PNG generator
//
// This is a header-only C++17 library which generates an uncompressed PNG.
// It may be useful for a program which requires low complexity but also
// needs to use PNG as a container.
//
// Usage:
// #include "UncompressedPngGenerator.hpp"
// int main() {
// int width = 256, height = 256;
@t-mat
t-mat / EnumStartMenuLinkFiles.cpp
Created Apr 7, 2021
[WIN32] Enumerate all .lnk files in the StartMenu folders.
View EnumStartMenuLinkFiles.cpp
// Enumerate all .lnk files in the StartMenu folders.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shlobj.h> // REFKNOWNFOLDERID, SHGetKnownFolderPath
#include <functional>
#include <filesystem>
using EnumStartMenuLnkFilesCallbackFunc = std::function<void(const std::filesystem::path& rootPath, const std::filesystem::path& entryPath)>;
void enumStartMenuLnkFiles(const EnumStartMenuLnkFilesCallbackFunc& callback) {
@t-mat
t-mat / my_pcg32.hpp
Created Apr 2, 2021
[C++] PCG32 just for me.
View my_pcg32.hpp
// PCG32 just for me.
// Copyright (C) 2021, Takayuki Matsuoka.
// SPDX-License-Identifier: MIT
//
// There's no "stream id". Instead of it, use advance(K).
// For example, if you want to have N streams, you can use the following code:
//
// Pcg32 my_pcg32[N];
// for(int i = 0 ; i < N; ++i) {
// const int64_t k = (INT64_MAX / N) * i;
@t-mat
t-mat / jpeg-xl-msvc-2019-x64-build.bat
Created Mar 29, 2021
Build JPEG XL with VC++2019
View jpeg-xl-msvc-2019-x64-build.bat
@rem Build JpegXL for Windows x64 Desktop, VC++2019
@setlocal enabledelayedexpansion
@echo off
pushd .
set /a errorno=1
git --version || echo "git" not found && goto :ERROR
call vcpkg version || echo "vcpkg" not found && goto :ERROR
rem Install prerequisite packages
@t-mat
t-mat / build-runcpm-vc2019.bat
Created Mar 17, 2021
Build RunCPM with VC++2019
View build-runcpm-vc2019.bat
@rem Build RunCPM for Windows x64 Desktop, VC++2019
@setlocal enabledelayedexpansion
@echo off
pushd .
set /a errorno=1
git --version || goto :ERROR
rem
rem Set Visual C++ environment for Windows, desktop, x64.
View my-sdl2-template.cpp
// My template code for SDL2. Press ESC to exit.
// Copyright (C) 2021, Takayuki Matsuoka.
// SPDX-License-Identifier: CC0-1.0
#include <vector>
#define SDL_MAIN_HANDLED
#include <SDL.h>
#if defined(_MSC_VER)
//#pragma comment(lib, "SDL2.lib")
#pragma comment(lib, "SDL2-static.lib")
#pragma comment(lib, "winmm.lib")