Some changes.

This commit is contained in:
bʰedoh₂ swé 2025-05-25 17:49:39 +05:00
parent e1e670abdf
commit 60516831b9

42
boot.c
View File

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