Skip to content

Commit

Permalink
Merge branch 'MEGA65:development' into fcio-file
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund authored Jul 19, 2024
2 parents faac722 + a7b334b commit 6efb787
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CMake

on:
push:
branches: [ "master" ]
branches: [ "development" ]
pull_request:
branches: [ "master" ]
branches: [ "development" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down
8 changes: 5 additions & 3 deletions Makefile_cc65
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ cleanall: clean
src/cc65/%.o: src/cc65/%.s
$(CA65) -o $@ $<

src/%.o: src/%.c
src/%.o: src/%.c | work
$(CC65) $(CFLAGS) -o work/$*.s $<
$(CA65) -o $@ work/$*.s

work:
@if [[ ! -d work ]]; then \
mkdir work; \
fi
$(CC65) $(CFLAGS) -o work/$*.s $<
$(CA65) -o $@ work/$*.s

# Unit tests using Xemu in "testing" mode
#
Expand Down
3 changes: 3 additions & 0 deletions include/mega65/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ enum
TARGET_MEGA65R1 = 1, //!< MEGA65 board revision 1
TARGET_MEGA65R2 = 2, //!< MEGA65 board revision 2
TARGET_MEGA65R3 = 3, //!< MEGA65 board revision 3
TARGET_MEGA65R4 = 4, //!< MEGA65 board revision 4
TARGET_MEGA65R5 = 5, //!< MEGA65 board revision 5
TARGET_MEGA65R6 = 6, //!< MEGA65 board revision 6
TARGET_MEGAPHONER1 = 0x21, //!< MEGAphone revision 1
TARGET_MEGAPHONER4 = 0x22, //!< MEGAphone revision 4
TARGET_NEXYS4 = 0x40, //!< Nexys4 board
Expand Down
11 changes: 8 additions & 3 deletions src/conio.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ char* petsciitoscreencode_s(char* s)
{
char* src = s;
char* dest = p2sbuf;
while (*dest++ = petsciitoscreencode(*src++))
while ((*dest++ = petsciitoscreencode(*src++)))
;
return p2sbuf;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ void togglecase(void)
POKE(0xD018U, PEEK(0xD018U) ^ 0x02);
}

void clrscr()
void clrscr(void)
{
const unsigned int cBytes
= (unsigned int)g_curScreenW * g_curScreenH * (IS_16BITCHARSET ? 2 : 1);
Expand Down Expand Up @@ -553,10 +553,15 @@ void cputhex(long n, unsigned char prec)
cputs(&buffer[8 - prec]);
}

#ifdef __clang__
void cputdec(long n, __attribute__ ((unused)) unsigned char padding, unsigned char leadingZeros)
#else
void cputdec(long n, unsigned char padding, unsigned char leadingZeros)
#endif

{
unsigned char buffer[11];
unsigned char rem = 0, i = 0;
unsigned char rem = 0;
char digit = 9;
padding = 0; // NOTE: done to suppress compiler warning
buffer[10] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void debug_msg(char* msg)
"clv\n"
: /* no output operands */
: "a"(*msg) /* input operands */
: "a" /* clobber list */);
: /* clobber list */);
#endif
msg++;
}
Expand Down
15 changes: 5 additions & 10 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,13 @@ void unit_test_report(
__asm__("CLV");
#else
asm volatile("st%0 $D643\n"
"clv" ::"a"((uint8_t)(issue & 0xff))
: "a");
"clv" ::"a"((uint8_t)(issue & 0xff)));
asm volatile("st%0 $D643\n"
"clv" ::"a"((uint8_t)(issue >> 8))
: "a");
"clv" ::"a"((uint8_t)(issue >> 8)));
asm volatile("st%0 $D643\n"
"clv" ::"a"(sub)
: "a");
"clv" ::"a"(sub));
asm volatile("st%0 $D643\n"
"clv" ::"a"(status)
: "a");
"clv" ::"a"(status));
#endif
}

Expand All @@ -92,8 +88,7 @@ void _unit_test_msg(char* msg, char cmd)
__asm__("CLV");
#else
asm volatile("st%0 $D643\n"
"clv" ::"a"(*current)
: "a");
"clv" ::"a"(*current));
#endif
current++;
}
Expand Down
38 changes: 37 additions & 1 deletion src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ uint8_t bcd_work;
*/
uint8_t tobcd(uint8_t in)
{
if (in > 99)
return 0;
bcd_work = 0;
while (in > 9) {
bcd_work += 0x10;
Expand Down Expand Up @@ -91,6 +93,19 @@ void getrtc(struct m65_tm* tm)
tm->tm_wday = unbcd(lpeek_debounced(0xffd7116));
tm->tm_isdst = lpeek_debounced(0xffd7117) & 0x20;
break;
case TARGET_MEGA65R4:
case TARGET_MEGA65R5:
case TARGET_MEGA65R6:
tm->tm_sec = unbcd(lpeek_debounced(0xffd7110));
tm->tm_min = unbcd(lpeek_debounced(0xffd7111));
tm->tm_hour = unbcd(lpeek_debounced(0xffd7112) & 0x3f);
tm->tm_mday = unbcd(lpeek_debounced(0xffd7113));
tm->tm_mon = unbcd(lpeek_debounced(0xffd7114));
// RTC is based on 2000, not 1900
tm->tm_year = unbcd(lpeek_debounced(0xffd7115)) + 100;
tm->tm_wday = unbcd(lpeek_debounced(0xffd7116));
tm->tm_isdst = 0;
break;
case TARGET_MEGAPHONER1:
break;
default:
Expand Down Expand Up @@ -136,7 +151,7 @@ void setrtc(struct m65_tm* tm)
lpoke(0xffd7113, tobcd(tm->tm_mday));
usleep(I2CDELAY);
lpoke(0xffd7114, tobcd(tm->tm_mon));
if (tm->tm_year >= 100 && tm->tm_year <= 355) {
if (tm->tm_year >= 100 && tm->tm_year <= 199) {
usleep(I2CDELAY);
lpoke(0xffd7115, tobcd((uint8_t)(tm->tm_year - 100)));
}
Expand All @@ -154,6 +169,27 @@ void setrtc(struct m65_tm* tm)
usleep(I2CDELAY);
lpoke(0xffd7118, 0x01);

break;
case TARGET_MEGA65R4:
case TARGET_MEGA65R5:
case TARGET_MEGA65R6:
usleep(I2CDELAY);
lpoke(0xffd7110, tobcd(tm->tm_sec));
usleep(I2CDELAY);
lpoke(0xffd7111, tobcd(tm->tm_min));
usleep(I2CDELAY);
lpoke(0xffd7112, tobcd(tm->tm_hour)); // no need to set 24h mode, swiss RTC does not have AM/PM
usleep(I2CDELAY);
lpoke(0xffd7113, tobcd(tm->tm_mday));
usleep(I2CDELAY);
lpoke(0xffd7114, tobcd(tm->tm_mon));
if (tm->tm_year >= 100 && tm->tm_year <= 199) {
usleep(I2CDELAY);
lpoke(0xffd7115, tobcd(tm->tm_year - 100));
}
usleep(I2CDELAY);
lpoke(0xffd7116, tobcd(tm->tm_wday < 7 ? tm->tm_wday : 0));

break;
case TARGET_MEGAPHONER1:
break;
Expand Down

0 comments on commit 6efb787

Please sign in to comment.