Compare commits

..

No commits in common. "60516831b95b8dc7434895e1effa807ba0d7120a" and "60d8f9bc318688c8d177aa0500743c8356830e78" have entirely different histories.

2 changed files with 33 additions and 25 deletions

View File

@ -1,4 +1,4 @@
Copyright (C) 2024-2025 by bedohswe bedohswe@firemail.cc
Copyright (C) 2024 by bedohswe bedohswe@firemail.cc
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.

56
boot.c
View File

@ -2,22 +2,20 @@
#include <stdbool.h>
#include "hedley.h"
typedef unsigned char uchar;
typedef enum : uchar {
typedef enum : char {
NONE = ' ',
CROSS = 'X',
NOT = 'O'
} Cell;
static Cell* const board = (Cell*)0x7F00;
Cell* board = ((Cell*)0x7F00);
static uchar readchar(void);
static bool checkwin(Cell c);
static void putchar(uchar);
static void printboard(void);
HEDLEY_ALWAYS_INLINE char readchar(void);
HEDLEY_ALWAYS_INLINE bool checkwin(Cell c);
HEDLEY_NEVER_INLINE void putchar(char);
HEDLEY_NEVER_INLINE void printboard(void);
static uchar numpadkeys[11];
char numpadkeys[];
void _start(void) {
__asm__ volatile (
@ -26,12 +24,13 @@ void _start(void) {
"start:\n"
);
Cell cur = CROSS;
for (uchar i = 0; i < 9; i++)
board[i] = NONE;
for (char i = 0; i < 3; i++)
for (char j = 0; j < 3; j++)
board[i * 3 + j] = NONE;
while (1) {
printboard();
uchar k = readchar();
uchar o;
char k = readchar();
char o;
if (k > 0x46)
o = 0x47;
else if (k < 0x13)
@ -40,13 +39,16 @@ void _start(void) {
o = (0x1E - 4);
else
o = (0x2C - 8);
uchar c = numpadkeys[k - o];
size_t c = numpadkeys[k - o];
if (board[c] != NONE)
continue;
board[c] = cur;
if (checkwin(cur))
break;
cur ^= (CROSS ^ NOT);
if (cur == CROSS)
cur = NOT;
else
cur = CROSS;
}
putchar(cur);
printboard();
@ -55,10 +57,11 @@ void _start(void) {
HEDLEY_UNREACHABLE();
}
// numpadkeys[x - 0x47]
static uchar numpadkeys[11] = {0, 1, 2, false, 3, 4, 5, false, 6, 7, 8};
char numpadkeys[] = {0, 1, 2, false, 3, 4, 5, false, 6, 7, 8};
static void printboard(void) {
HEDLEY_NEVER_INLINE
void printboard(void) {
__asm__ volatile (
"movb $0x02, %%ah;"
"movb $0x00, %%bh;"
@ -68,8 +71,8 @@ static void printboard(void) {
:
:"%ah","%bh","%dx"
);
for (uchar i = 0; i < 3; i++) {
for (uchar j = 0; j < 3; j++) {
for (char i = 0; i < 3; i++) {
for (char j = 0; j < 3; j++) {
putchar(board[i * 3 + j]);
}
putchar('\n');
@ -77,10 +80,13 @@ static void printboard(void) {
}
}
static bool checkwin(Cell c) {
HEDLEY_ALWAYS_INLINE
bool checkwin(Cell c) {
for (size_t i = 0; i <= 2; i++)
if (((board[i] == c) && (board[i + 3] == c) && (board[i + 6] == c)) &&
((board[3*i] == c) && (board[3*i + 1] == c) && (board[3*i + 2] == c)))
if ((board[i] == c) && (board[i + 3] == c) && (board[i + 6] == c))
return true;
for (size_t i = 0; i <= 2; i++)
if ((board[3*i] == c) && (board[3*i + 1] == c) && (board[3*i + 2] == c))
return true;
if (board[0] == c && board[4] == c && board[8] == c)
return true;
@ -94,7 +100,8 @@ static bool checkwin(Cell c) {
* 678
*/
static uchar readchar(void) {
HEDLEY_ALWAYS_INLINE
char readchar(void) {
char out;
__asm__ volatile (
"movb $0x00, %%ah;"
@ -107,7 +114,8 @@ __asm__ volatile (
return out;
}
static void putchar(uchar out) {
HEDLEY_NEVER_INLINE
void putchar(char out) {
__asm__ volatile (
"movb $0x0e, %%ah;"
"movb %0, %%al;"