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