summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2021-01-16 14:52:56 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit2ad167622077b875a3d4157d27690a575c9248af (patch)
tree37beb7087d2d8cb4f5a70e8eba02bed68370a288
parent50b9955b040005e489127a11cf9c1648438a6266 (diff)
Starting work on MCU port
-rw-r--r--.gitignore2
-rw-r--r--Makefile47
-rw-r--r--include/ct1986.c20
-rw-r--r--src/mcu.c8
4 files changed, 64 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index dc61327..d0a201f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
data/
ctaklm
pptdb
+mcu.hex
+*.s
diff --git a/Makefile b/Makefile
index 1dfb930..bc31852 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,7 @@
IDIR=include
+
+# -------------------------------------------------------------------
+# Computer stuff
TPDIR=3rd-party
DEFINES=-DDETERMINISTIC
CFLAGS=-O3 -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE $(DEFINES) -I$(IDIR) -I$(TPDIR)
@@ -11,6 +14,27 @@ PROG=ctaklm
STAT=pptdb
SIZE=size
+# -------------------------------------------------------------------
+# MCU stuff
+MCU=atmega32
+F_CPU=20000000UL
+ACC=avr-gcc
+ACFLAGS=-Os -Wall -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -I$(IDIR)
+AOBJCOPY=avr-objcopy
+AOBJSIZE=avr-size
+
+AVRDUDE=avrdude
+ADFLAGS=-c usbasp -p t24
+
+TARGET=mcu
+AHEX=$(TARGET).hex
+ASRC=src/$(TARGET).c $(wildcard include/*.c)
+AOBJ=$(patsubst %.c, %.o, $(ASRC))
+AASM=$(patsubst %.c, %.s, $(ASRC))
+
+# -------------------------------------------------------------------
+# Targets
+
%.o: %.c
cc -c $< -o $@ $(CFLAGS)
@@ -21,8 +45,25 @@ $(PROG): src/$(PROG).o $(OBJS)
$(STAT): src/$(STAT).o $(OBJS)
$(CC) $(CFLAGS) src/$(STAT).o $(OBJS) -o $(STAT)
+avr: $(AHEX) $(AASM) ASUMMARY upload
+
+$(AHEX): $(AOBJ)
+ $(AOBJCOPY) -S -j .text -j .data -O ihex $< $@
+
+$(AOBJ): $(ASRC)
+ $(ACC) $(ACFLAGS) -DF_CPU=$(F_CPU) -mmcu=$(MCU) $(ASRC) -o $@
+
+%.s: %.c
+ $(ACC) -S $(ACFLAGS) -DF_CPU=$(F_CPU) -mmcu=$(MCU) $< -o $@
+
+ASUMMARY: $(AOBJ)
+ @echo ----------------------------------------------------------------------
+ @$(AOBJSIZE) $(AOBJ) $(AHEX)
+
+upload: $(TARGET).hex
+ $(AVRDUDE) $(ADFLAGS) -U flash:w:$<
+
clean:
- rm -f $(PROG)
- rm -f $(STAT)
+ rm -f $(PROG) $(STAT) $(OBJS)
+ rm -f $(AOBJ) $(AHEX) $(AASM)
rm -f src/*.o
- rm -f $(OBJS)
diff --git a/include/ct1986.c b/include/ct1986.c
index a3b089e..4537fa5 100644
--- a/include/ct1986.c
+++ b/include/ct1986.c
@@ -186,8 +186,8 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
float optimal = (min) ? infty : -infty;
// Step across the board
- for (uint8_t row = 0; row < board_size; row++) {
- for (uint8_t col = 0; col < board_size; col++) {
+ for (uint8_t row = 0; row < 5; row++) {
+ for (uint8_t col = 0; col < 5; col++) {
// Try all valid actions for this square. Is it empty?
const uint8_t loc = THE_COORDS(col, row);
const uint8_t count = COUNT_AT(loc);
@@ -198,17 +198,17 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
// better than manually unrolling this. Sufficiently smart
// compilers?
- uint16_t colours_backup[board_size];
- uint8_t celldat_backup[board_size], drops[board_size-1];
+ uint16_t colours_backup[5];
+ uint8_t celldat_backup[5], drops[5-1];
// Back up the row of the board
- for (uint8_t y = 0; y < board_size; y++) {
+ for (uint8_t y = 0; y < 5; y++) {
colours_backup[y] = colours[THE_COORDS(col, y)];
celldat_backup[y] = celldat[THE_COORDS(col, y)];
}
for (enum MOVE_DIRECTION dir = M_UP; dir <= M_RIGHT; dir++) {
// Back-up the column once we start looking horizontally
if (dir == M_LEFT) {
- for (uint8_t x = 0; x < board_size; x++) {
+ for (uint8_t x = 0; x < 5; x++) {
colours_backup[x] = colours[THE_COORDS(x, row)];
celldat_backup[x] = celldat[THE_COORDS(x, row)];
}
@@ -217,7 +217,7 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
// just try everything...
// For every number of steps
- for (uint8_t steps = 1; steps < board_size && steps <= count; steps++) {
+ for (uint8_t steps = 1; steps < 5 && steps <= count; steps++) {
uint8_t idx, carry;
for (idx = 0; idx < steps; idx++) drops[idx]=0;
idx = 0;
@@ -227,7 +227,7 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
drops[idx]++;
do {
if (carry) { drops[++idx]++; carry = 0;}
- if (drops[idx] > count || drops[idx] > board_size) {
+ if (drops[idx] > count || drops[idx] > 5) {
drops[idx] = 1; carry = 1;
}
} while (carry && idx < steps);
@@ -247,12 +247,12 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
});
// Reset the board data
if (dir <= M_DOWN) {
- for (uint8_t y = 0; y < board_size; y++) {
+ for (uint8_t y = 0; y < 5; y++) {
colours[THE_COORDS(col, y)] = colours_backup[y];
celldat[THE_COORDS(col, y)] = celldat_backup[y];
}
} else {
- for (uint8_t x = 0; x < board_size; x++) {
+ for (uint8_t x = 0; x < 5; x++) {
colours[THE_COORDS(x, row)] = colours_backup[x];
celldat[THE_COORDS(x, row)] = celldat_backup[x];
}
diff --git a/src/mcu.c b/src/mcu.c
new file mode 100644
index 0000000..4083165
--- /dev/null
+++ b/src/mcu.c
@@ -0,0 +1,8 @@
+#include <avr/io.h>
+#include <tak.h>
+#include <ct1986.h>
+
+int main(void) {
+ while(1);
+ return 0;
+}