mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-23 14:33:13 -04:00
rtc: implement RTC
Untested in-game since Animal Forest does not yet run.
This commit is contained in:
parent
cfd2336443
commit
b2721e7d37
|
@ -357,6 +357,7 @@ set(SI_SOURCES
|
|||
${PROJECT_SOURCE_DIR}/si/pak.c
|
||||
${PROJECT_SOURCE_DIR}/si/pak_transfer.c
|
||||
${PROJECT_SOURCE_DIR}/si/gb.c
|
||||
${PROJECT_SOURCE_DIR}/si/rtc.c
|
||||
)
|
||||
|
||||
set(VI_SOURCES
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "ri/controller.h"
|
||||
#include "si/cic.h"
|
||||
#include "si/controller.h"
|
||||
#include "si/rtc.h"
|
||||
#include "thread.h"
|
||||
#include "vi/controller.h"
|
||||
#include "vr4300/interface.h"
|
||||
|
@ -190,22 +191,19 @@ int pif_perform_command(struct si_controller *si,
|
|||
case 0x06:
|
||||
if (channel != 4)
|
||||
assert(0 && "Invalid channel for RTC status");
|
||||
// TODO
|
||||
return 1;
|
||||
return rtc_status(send_buf, send_bytes, recv_buf, recv_bytes);
|
||||
|
||||
// RTC read
|
||||
case 0x07:
|
||||
if (channel != 4)
|
||||
assert(0 && "Invalid channel for RTC read");
|
||||
// TODO
|
||||
return 1;
|
||||
return rtc_read(send_buf, send_bytes, recv_buf, recv_bytes);
|
||||
|
||||
// RTC write
|
||||
case 0x08:
|
||||
if (channel != 4)
|
||||
assert(0 && "Invalid channel for RTC write");
|
||||
// TODO
|
||||
return 1;
|
||||
return rtc_write(send_buf, send_bytes, recv_buf, recv_bytes);
|
||||
|
||||
// Unimplemented command:
|
||||
default:
|
||||
|
|
65
si/rtc.c
Normal file
65
si/rtc.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// si/rtc.c: RTC routines
|
||||
//
|
||||
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
|
||||
// Copyright (C) 2016, Mike Ryan.
|
||||
//
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// 'LICENSE', which is part of this source code package.
|
||||
//
|
||||
|
||||
#include "common.h"
|
||||
#include "local_time.h"
|
||||
|
||||
int rtc_status(uint8_t *send_buf, uint8_t send_bytes,
|
||||
uint8_t *recv_buf, uint8_t recv_bytes) {
|
||||
recv_buf[0] = 0x00;
|
||||
recv_buf[1] = 0x10;
|
||||
recv_buf[2] = 0x00;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc_read(uint8_t *send_buf, uint8_t send_bytes,
|
||||
uint8_t *recv_buf, uint8_t recv_bytes) {
|
||||
struct time_stamp now;
|
||||
|
||||
// FIXME is this needed?
|
||||
memset(recv_buf, 0, recv_bytes);
|
||||
|
||||
// read RTC block
|
||||
switch (send_buf[1]) {
|
||||
case 0:
|
||||
recv_buf[0] = 0x02;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
debug("RTC cannot read block 1\n");
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
get_local_time(&now);
|
||||
recv_buf[0] = byte2bcd(now.sec);
|
||||
recv_buf[1] = byte2bcd(now.min);
|
||||
recv_buf[2] = 0x80 + byte2bcd(now.hour);
|
||||
recv_buf[3] = byte2bcd(now.day);
|
||||
recv_buf[4] = byte2bcd(now.week_day);
|
||||
recv_buf[5] = byte2bcd(now.month);
|
||||
recv_buf[6] = byte2bcd(now.year);
|
||||
recv_buf[7] = byte2bcd(now.year / 100);
|
||||
recv_buf[8] = 0x00; // status
|
||||
break;
|
||||
|
||||
default:
|
||||
debug("RTC unknown block\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc_write(uint8_t *send_buf, uint8_t send_bytes,
|
||||
uint8_t *recv_buf, uint8_t recv_bytes) {
|
||||
debug("RTC write not implemented\n");
|
||||
return 1;
|
||||
}
|
22
si/rtc.h
Normal file
22
si/rtc.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// si/rtc.h: RTC routines
|
||||
//
|
||||
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
|
||||
// Copyright (C) 2016, Mike Ryan.
|
||||
//
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// 'LICENSE', which is part of this source code package.
|
||||
//
|
||||
|
||||
#ifndef __si_rtc_h__
|
||||
#define __si_rtc_h__
|
||||
#include "common.h"
|
||||
|
||||
int rtc_status(uint8_t *send_buf, uint8_t send_bytes,
|
||||
uint8_t *recv_buf, uint8_t recv_bytes);
|
||||
int rtc_read(uint8_t *send_buf, uint8_t send_bytes,
|
||||
uint8_t *recv_buf, uint8_t recv_bytes);
|
||||
int rtc_write(uint8_t *send_buf, uint8_t send_bytes,
|
||||
uint8_t *recv_buf, uint8_t recv_bytes);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue