Skip to content

Commit 04dbc01

Browse files
committed
Add Arduino stubs for compilation
1 parent f18241d commit 04dbc01

File tree

7 files changed

+66
-1
lines changed

7 files changed

+66
-1
lines changed

Arduino.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef ARDUINO_H
2+
#define ARDUINO_H
3+
#include <stdint.h>
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <stdlib.h>
7+
#define PROGMEM
8+
#define pgm_read_byte(addr) (*(const uint8_t*)(addr))
9+
#define pgm_read_word(addr) (*(const uint16_t*)(addr))
10+
#define pgm_read_dword(addr) (*(const uint32_t*)(addr))
11+
#define pgm_get_far_address(addr) ((uintptr_t)(addr))
12+
#define HIGH 1
13+
#define LOW 0
14+
#define INPUT 0
15+
#define OUTPUT 1
16+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
17+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
18+
#define PORTB (*((volatile uint8_t*)0))
19+
#define PORTD (*((volatile uint8_t*)0))
20+
#define ESP32 1
21+
#define __malloc_heap_start ((char*)0)
22+
inline long random(long max) { return rand() % max; }
23+
inline long random(long min, long max) { return min + rand() % (max - min); }
24+
inline char* dtostrf(double val, signed char width, unsigned char prec, char* buf) { sprintf(buf, "%*.*f", width, prec, val); return buf; }
25+
inline void strcpy_P(char* dest, const char* src) { strcpy(dest, src); }
26+
class HardwareSerial {
27+
public:
28+
int available() { return 0; }
29+
int availableForWrite() { return 0; }
30+
int read() { return 0; }
31+
size_t write(uint8_t) { return 1; }
32+
size_t write(const char* s) { return printf("%s", s); }
33+
size_t write(const char* s, size_t) { return printf("%s", s); }
34+
void begin(long) {}
35+
operator bool() const { return true; }
36+
};
37+
static HardwareSerial Serial;
38+
inline void pinMode(int, int) {}
39+
inline void digitalWrite(int, int) {}
40+
inline void delay(int) {}
41+
inline uint32_t millis() { static uint32_t t = 0; return t += 16; }
42+
#endif // ARDUINO_H

ArduinoUnitTests.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef ARDUINO_UNIT_TESTS_H
2+
#define ARDUINO_UNIT_TESTS_H
3+
#define unittest_setup() void unittest_setup()
4+
#define unittest_teardown() void unittest_teardown()
5+
#define unittest(name) void name()
6+
#define unittest_main() int main(){unittest_setup(); test_mock(); unittest_teardown(); return 0;}
7+
#endif // ARDUINO_UNIT_TESTS_H

HardwareSerial.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef HARDWARESERIAL_H
2+
#define HARDWARESERIAL_H
3+
#include "Arduino.h"
4+
#endif // HARDWARESERIAL_H

avr/pgmspace.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef AVR_PGMSPACE_H
2+
#define AVR_PGMSPACE_H
3+
#include <stdint.h>
4+
#define PROGMEM
5+
#define pgm_read_byte(addr) (*(const uint8_t*)(addr))
6+
#define pgm_read_word(addr) (*(const uint16_t*)(addr))
7+
#define pgm_read_dword(addr) (*(const uint32_t*)(addr))
8+
#endif // AVR_PGMSPACE_H

chessutil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ Bool check_serial()
593593
// returns True if there is a move or False otherwise
594594
Bool check_book()
595595
{
596-
static index_t index = 0;
596+
uint8_t &index = game.book_index;
597597

598598
if (!game.options.openbook) { return False; }
599599

game.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void game_t::init()
126126
turn = White;
127127

128128
move_num = 0;
129+
book_index = 0;
129130

130131
ply = 0;
131132

game.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class game_t
9292
// Increasing move number
9393
uint8_t move_num;
9494

95+
// Index of the next opening book move
96+
uint8_t book_index;
97+
9598
// The alpha and beta boundaries of our search envelope
9699
long alpha;
97100
long beta;

0 commit comments

Comments
 (0)