Removed more unrelated stuff that I don't want to touch anymore

This commit is contained in:
Андреев Григорий 2025-12-23 23:02:09 +03:00
parent 1328d194be
commit 6a0681b42e
5 changed files with 0 additions and 552 deletions

View File

@ -1 +0,0 @@
#version 450

View File

@ -1 +0,0 @@
#version 450

View File

@ -1,8 +0,0 @@
#ifndef PROTOTYPE1_SRC_L3_FUN_MACHINE_BUBINA_H
#define PROTOTYPE1_SRC_L3_FUN_MACHINE_BUBINA_H
typedef struct {
} BubinaState;
#endif

View File

@ -1,185 +0,0 @@
#ifndef PROTOTYPE1_SRC_L3_FUN_MACHINE_STATE_H
#define PROTOTYPE1_SRC_L3_FUN_MACHINE_STATE_H
#include "../../../gen/l1/VecAndSpan_U8.h"
#include "../../../gen/l1/VecAndSpan_U16.h"
// todo: recheck this structure
const U8 FunMachine_LRU_states[24][4] ={
/* x = 0 1 2 3 */
{ 3, 0, 8, 16}, /* state 0 : (1 2 3 0) LRU=0 */
{ 1, 11, 9, 17}, /* state 1 : (0 2 3 1) LRU=1 */
{ 2, 10, 19, 18}, /* state 2 : (0 1 3 2) LRU=2 */
{ 3, 11, 19, 18}, /* state 3 : (0 1 2 3) LRU=3 */
{ 2, 4, 8, 16},
{ 5, 10, 9, 17},
{ 6, 10, 9, 18},
{ 7, 11, 19, 17},
{ 7, 0, 8, 20},
{ 1, 15, 9, 21},
{ 2, 10, 23, 22},
{ 3, 11, 23, 22},
{ 1, 0, 12, 20},
{ 1, 0, 13, 21},
{ 2, 14, 8, 22},
{ 3, 15, 23, 16},
{ 6, 4, 12, 16},
{ 5, 14, 13, 17},
{ 6, 14, 13, 18},
{ 7, 15, 19, 21},
{ 5, 4, 12, 20},
{ 5, 4, 13, 21},
{ 6, 14, 12, 22},
{ 7, 15, 23, 20}
};
#define FunMachine_levers_count 16
#define FunMachine_keys_count 50
#define FunMachine_cache_banks_count 4
#define FunMachine_cache_sets_count 32
#define FunMachine_cache_sets_pow 5
#define FunMachine_cache_line_size 16
#define FunMachine_cache_line_pow 4
#define FunMachine_disk_drives 2
#define FunMachine_disk_io_block_pow 7
#define FunMachine_disk_io_block_size 128
typedef struct {
U64 timeout_remaining;
bool powered;
U16 levers;
bool keys[FunMachine_keys_count];
// History of cache bank usage (from 0 to 23)
U8 lru;
// Our simulation acknowledges complete cache consistency and does not separate cache storage from
// memory storage
// We have 4 banks and memory blocks of size 2^4 (we have 2^12) of them are separated into
// 2^5 interleaved sets (at each time each set can point to 4 of 2^7 possible indexes)
U8 cache_indexes[FunMachine_cache_banks_count][FunMachine_cache_sets_count];
// We store the last cache line that was used for instruction decoding right inside JSM3C
U16 last_command_line_mask; // Last 4 bits in IP are zeroed out
// We store the history of 3
// 0 - Z (all bits of last op result were 0)
// 1 - S (msb of last op result was 1)
// 2 - O (last operation resulted in overflow)
U16 flags;
U16 AX;
U16 BX;
U16 CX;
U16 DX;
U16 EX;
U16 FX;
U16 IP;
VecU16 memory;
} FunMachineState;
FunMachineState FunMachineState_from_image(SpanU16 image) {
assert(image.len <= UINT16_MAX);
FunMachineState res = (FunMachineState){
.timeout_remaining = UINT64_MAX,
.memory = VecU16_new_zeroinit(UINT16_MAX)};
return res;
}
void FunMachine_drop(FunMachineState self) {
VecU16_drop(self.memory);
}
typedef enum {
FunMachineIM_power_on,
FunMachineIM_power_off,
FunMachineIM_auto_wake,
FunMachineIM_button_press,
FunMachineIM_button_release,
FunMachineIM_lever_changed,
FunMachineIM_disk_drive_connected,
FunMachineIM_disk_drive_disconnected,
FunMachineIM_disk_drive_not_busy,
FunMachineIM_disk_drive_synchronized,
} FunMachineIM_variant;
typedef struct {
U8 drive_id; // From
} FunMachine_DriveConnectionInfo;
typedef struct {
FunMachineIM_variant variant;
union {
U8 id; // For button and for lever event
FunMachine_DriveConnectionInfo drive; // For all the disk drive events
};
} FunMachineIM;
// (U64, funMachineIM)
typedef struct{
U64 tp;
FunMachineIM im;
} FunMachineIM_TP;
typedef enum {
FunMachineIMR_None,
FunMachineIMR_LampUpdate,
FunMachineIMR_ShutAllDown,
} FunMachineIMR_variant;
typedef struct {
FunMachineIMR_variant variant;
// For FunMachineIMR_LampUpdate
U8 changed_row;
U16 nav; // new value set for that row
} FunMachineIMR;
// (FunMachineIMR, int, U64)
typedef struct {
FunMachineIMR r;
/* Right now there is only one inner hardware error:
* if small physical interrupt queue overflows and some events get chewed up */
int inner_hardware_error;
U64 awt;
} FunMachineIMR_AWT;
// 80K TPS
const U64 tick_time = 12500;
void FunMachine_boot(FunMachineState* self, SpanU16 image) {
assert(image.len <= UINT16_MAX);
self->powered = true;
self->AX = self->BX = self->CX = self->DX = self->EX = self->FX = self->IP = self->flags = 0;
self->lru = 0;
self->last_command_line_mask = 0;
memcpy(self->memory.buf, image.data, image.len * sizeof(U16));
memset(self->memory.buf + image.len, 0, (UINT16_MAX - image.len) * sizeof(U16));
for (int i = 0; i < FunMachine_cache_banks_count; i++)
for (int j = 0; j < FunMachine_cache_sets_count; j++)
self->cache_indexes[i][j] = i;
}
void FunMachine_sync_time_progress(FunMachineState* self, U64 tp) {
assert(self->timeout_remaining >= tp);
if (self->timeout_remaining < UINT64_MAX)
self->timeout_remaining -= tp;
}
FunMachineIMR_AWT FunMachine_execute_instruction(FunMachineState* self) {
// todo: actaully write this function
return (FunMachineIMR_AWT){ .r.variant = FunMachineIMR_None, .awt = self->timeout_remaining };
}
FunMachineIMR_AWT FunMachine_runtime_reaction(FunMachineState* self) {
if (self->timeout_remaining)
return (FunMachineIMR_AWT){ .r.variant = FunMachineIMR_None, .awt = self->timeout_remaining };
return FunMachine_execute_instruction(self);
}
FunMachineIMR_AWT FunMachine_act(FunMachineState* self, FunMachineIM_TP imtp) {
FunMachineIM im = imtp.im;
FunMachine_sync_time_progress(self, imtp.tp);
if (im.variant == FunMachineIM_power_off && !self->powered)
return (FunMachineIMR_AWT){ .r.variant = FunMachineIMR_None, .awt = self->timeout_remaining };
// todo: actaully write this function
return (FunMachineIMR_AWT){ .r.variant = FunMachineIMR_None, .awt = self->timeout_remaining };
}
#endif

View File

@ -1,357 +0,0 @@
/* This shit was written by chatgpt */
// todo: remove this crap. Rewrite it in wayland. Get rid of ncurses client
#include "../fun_machine/fun_machine.h"
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdbool.h>
#include <term.h>
static void enter_altscreen(void)
{
const char *smcup = tigetstr("smcup");
if (smcup)
putp(smcup);
}
static void leave_altscreen(void)
{
const char *rmcup = tigetstr("rmcup");
if (rmcup)
putp(rmcup);
}
#define BOARD_SIZE 32
#define BOARD_OUTER_SIZE (BOARD_SIZE + 2)
#define TIMEOUT_USEC 100000 // Won't be used
#define LEVER_COUNT 16
#define KEYBOARD_ROW_SIZE 10
#define KEYBOARD_ROWS 5
const short keyboard_style[KEYBOARD_ROWS] = {2, 1, 0, 2, 1};
typedef struct {
int lamps[BOARD_SIZE][BOARD_SIZE];
U16 levers; // MSB is the left one, LSB is thr right one. false is down, true is up
/* Numeration of key statuses in this array:
* 0 1 ... 9
* 10 11 ... 19
* 20 ... 29
* 30 ... 39
* 40 ... 49
*/
U8 keys[KEYBOARD_ROW_SIZE * KEYBOARD_ROWS]; // 0 - released, 1 - pressed
bool on; // false - machine is off, on - machine is on
} VisibleState;
VisibleState VisibleState_new() {
return (VisibleState){0};
}
/* Pos on screen is opposite to bit pos (we represent lever word in big endian) */
void VisibleState_set_lever(VisibleState* self, int pos, bool v) {
U16 mask = (1u << (LEVER_COUNT - 1 - pos));
self->levers = (self->levers & (~mask)) | ((short)v << LEVER_COUNT - 1 - pos);
}
bool VisibleState_get_lever(VisibleState* self, int pos) {
return self->levers & (1u << (LEVER_COUNT - 1 - pos));
}
const char key_marks[KEYBOARD_ROW_SIZE * KEYBOARD_ROWS] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'?', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'p', '"',
'$', 'f', 'g', 'h', 'j', 'k', 'l', 'i', 'o', '\'',
'%', 'a', 's', 'd', 'z', 'x', 'c', 'v', 'n', 'm',
'*', 'b', '!', '/', ' ', '(', ')', '=', '-', '+',
};
#define LOGO_WIDTH 5
#define LOGO_HEIGHT (7 + 2 + 7)
U8 logo_bitmap[LOGO_HEIGHT][LOGO_WIDTH] = {
{1, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 1, 1, 1, 1},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{1, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{1, 1, 0, 1, 1},
{1, 0, 1, 0, 1},
{1, 0, 1, 0, 1},
{1, 0, 1, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
{1, 0, 0, 0, 1},
};
char engraving_char = '#';
// char engraving_char = 176; // can be 177 or 178s
typedef enum {
pair_lampboard_border = 1,
pair_unlit_lamp,
pair_lit_lamp,
pair_lever,
pair_released_key_border,
pair_released_key_symbol,
pair_pressed_key_border,
pair_pressed_key_symbol,
pair_power_button_outer,
pair_power_button_inner,
pair_unlit_led,
pair_lit_led,
pair_engraving
} ncurses_color_pairs;
static void init_colors(void)
{
start_color();
use_default_colors();
init_pair(pair_lampboard_border, -1, 245);
init_pair(pair_unlit_lamp, 236, -1);
init_pair(pair_lit_lamp, COLOR_WHITE, COLOR_YELLOW);
init_pair(pair_lever, COLOR_WHITE, -1);
init_pair(pair_released_key_border, 233, 239);
init_pair(pair_released_key_symbol, 7, 0);
init_pair(pair_pressed_key_border, 237, 245);
init_pair(pair_pressed_key_symbol, 203, 88);
init_pair(pair_power_button_outer, 124, 9);
init_pair(pair_power_button_inner, COLOR_BLACK, 160);
init_pair(pair_unlit_led, 52, -1);
init_pair(pair_lit_led, COLOR_WHITE, 9);
init_pair(pair_engraving, 136, -1);
}
/*--------------------------------------------------------------*/
// Won't be used
static void seed_dots(VisibleState* state)
{
for (int y = 0; y < BOARD_SIZE; ++y)
for (int x = 0; x < BOARD_SIZE; ++x)
state->lamps[y][x] = rand() & 1;
}
static void toggle_dot(VisibleState* state, int y, int x)
{
if (y >= 0 && y < BOARD_SIZE && x >= 0 && x < BOARD_SIZE)
state->lamps[y][x] ^= 1;
}
/*--------------------------------------------------------------*
* Drawing
*--------------------------------------------------------------*/
static void draw_board(VisibleState* state, int X, int Y)
{
attron(COLOR_PAIR(pair_lampboard_border));
for (int i = 0; i < BOARD_OUTER_SIZE; i++) {
mvaddch(Y, X + i, ' ');
mvaddch(Y + BOARD_OUTER_SIZE - 1, X + i, ' ');
mvaddch(Y + i, X, ' ');
mvaddch(Y + i, X + BOARD_OUTER_SIZE - 1, ' ');
}
for (int y = 0; y < BOARD_SIZE; ++y)
for (int x = 0; x < BOARD_SIZE; ++x) {
int pair = state->lamps[y][x] ? pair_lit_lamp : pair_unlit_lamp;
attron(COLOR_PAIR(pair));
mvaddch(Y + y + 1, X + x + 1, '.');
attroff(COLOR_PAIR(pair));
}
refresh();
}
static void draw_power_button(int X, int Y) {
attron(COLOR_PAIR(pair_power_button_outer));
mvaddch(Y + 0, X + 1, '-');
mvaddch(Y + 0, X + 2, '-');
mvaddch(Y + 0, X + 3, '-');
mvaddch(Y + 1, X + 3, ' ');
mvaddch(Y + 1, X + 4, '|');
mvaddch(Y + 2, X + 4, '|');
mvaddch(Y + 3, X + 4, '|');
mvaddch(Y + 3, X + 3, ' ');
mvaddch(Y + 4, X + 3, '-');
mvaddch(Y + 4, X + 2, '-');
mvaddch(Y + 4, X + 1, '-');
mvaddch(Y + 4, X + 1, '-');
mvaddch(Y + 3, X + 1, ' ');
mvaddch(Y + 3, X + 0, '|');
mvaddch(Y + 2, X + 0, '|');
mvaddch(Y + 1, X + 0, '|');
mvaddch(Y + 1, X + 1, ' ');
attron(COLOR_PAIR(pair_power_button_inner));
mvaddch(Y + 1, X + 2, ' ');
mvaddch(Y + 2, X + 1, ' ');
mvaddch(Y + 3, X + 2, ' ');
mvaddch(Y + 2, X + 3, ' ');
mvaddch(Y + 2, X + 2, 'P');
}
void draw_power_led(VisibleState* state, int X, int Y) {
attron(COLOR_PAIR(state->on ? pair_lit_led : pair_unlit_led));
mvaddch(Y, X, state->on ? '.' : 'O');
}
void draw_levers(VisibleState* state, int X, int Y) {
attron(COLOR_PAIR(pair_lever));
for (int i = 0; i < LEVER_COUNT; i++) {
mvaddch(Y + 1, X + 2 * i, 'O');
mvaddch(Y + (VisibleState_get_lever(state, i) ? 0 : 2), X + 2 * i, '|');
}
}
void draw_keyboard(VisibleState* state, int X, int Y) {
for (int row = 0; row < KEYBOARD_ROWS; row++) {
for (int s = 0; s < KEYBOARD_ROW_SIZE; s++) {
int x = X + keyboard_style[row] + 4 * s;
int y = Y + row * 2;
bool pressed = state->keys[KEYBOARD_ROW_SIZE * row + s];
attron(COLOR_PAIR(pressed ? pair_pressed_key_border : pair_released_key_border));
mvaddch(y, x, '[');
mvaddch(y, x + 2, ']');
attron(COLOR_PAIR(pressed ? pair_pressed_key_symbol : pair_released_key_symbol));
mvaddch(y, x + 1, key_marks[KEYBOARD_ROW_SIZE * row + s]);
}
}
}
void draw_logo_engraving(int X, int Y) {
attron(COLOR_PAIR(pair_engraving));
for (int y = 0; y < LOGO_HEIGHT; y++) {
for (int x = 0; x < LOGO_WIDTH; x++) {
if (logo_bitmap[y][x])
mvaddch(Y + y, X + x, engraving_char);
}
}
}
#define LAMPBOARD_X 16
#define LAMPBOARD_Y 0
#define POWER_BUTTON_X 0
#define POWER_BUTTON_Y (BOARD_OUTER_SIZE + 1)
#define POWER_LED_X (5 + 2)
#define POWER_LED_Y 32
#define LEVER_ROW_X (5 + 12)
#define LEVER_ROW_Y (BOARD_OUTER_SIZE + 1)
#define KEYBOARD_X 10
#define KEYBOARD_Y 40
#define LOGO_X 3
#define LOGO_Y 2
static void draw_fun_machine(VisibleState* state) {
erase();
draw_board(state, LAMPBOARD_X, LAMPBOARD_Y);
draw_power_button(POWER_BUTTON_X, POWER_BUTTON_Y);
draw_power_led(state, POWER_LED_X, POWER_LED_Y);
draw_levers(state, LEVER_ROW_X, LEVER_ROW_Y);
draw_keyboard(state, KEYBOARD_X, KEYBOARD_Y);
draw_logo_engraving(LOGO_X, LOGO_Y);
}
int lever_intersection(int evx, int evy) {
for (int i = 0; i < LEVER_COUNT; i++) {
int lcx = LEVER_ROW_X + 2 * i;
int lcy = LEVER_ROW_Y + 1;
if (evx == lcx && abs(lcy - evy) <= 1)
return i;
}
return -1;
}
int key_intersection(int evx, int evy) {
for (int row = 0; row < KEYBOARD_ROWS; row++) {
for (int s = 0; s < KEYBOARD_ROW_SIZE; s++) {
int kcx = KEYBOARD_X + keyboard_style[row] + 4 * s + 1;
int kcy = KEYBOARD_Y + 2 * row;
if (abs(kcx - evx) <= 1 && kcy == evy)
return row * KEYBOARD_ROW_SIZE + s;
}
}
return -1;
}
/*--------------------------------------------------------------*
* Main
*--------------------------------------------------------------*/
static volatile sig_atomic_t keep_running = 1;
static void sigint_handler(int sig) { (void)sig; keep_running = 0; }
int main(void)
{
srand((unsigned)time(NULL));
VisibleState mach_disp = VisibleState_new();
seed_dots(&mach_disp);
setupterm(NULL, fileno(stdout), NULL);
enter_altscreen();
atexit(leave_altscreen);
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
mousemask(ALL_MOUSE_EVENTS, NULL);
curs_set(0);
init_colors();
signal(SIGINT, sigint_handler);
timeout(TIMEOUT_USEC / 1000);
while (keep_running) {
draw_fun_machine(&mach_disp);
int ch = getch();
if (ch == ERR)
continue; /* timeout */
if (ch == 'q' || ch == 'Q')
break; /* quit */
if (ch == KEY_MOUSE) {
MEVENT ev;
if (getmouse(&ev) == OK) {
if (ev.bstate & BUTTON1_CLICKED) {
toggle_dot(&mach_disp, ev.y - LAMPBOARD_Y - 1, ev.x - LAMPBOARD_X - 1);
int li = lever_intersection(ev.x, ev.y);
if (li >= 0)
VisibleState_set_lever(&mach_disp, li, !VisibleState_get_lever(&mach_disp, li));
int ki = key_intersection(ev.x, ev.y);
if (ki >= 0) {
// do something
}
} else if (ev.bstate & BUTTON3_CLICKED) {
int ki = key_intersection(ev.x, ev.y);
if (ki >= 0) {
if (mach_disp.keys[ki]) {
// Releasing
mach_disp.keys[ki] = 0;
} else {
// Pressing
mach_disp.keys[ki] = 1;
}
}
}
}
} else {
seed_dots(&mach_disp); /* any other key scramble */
}
}
endwin();
return 0;
}