Implement the rest of the RTC

This commit is contained in:
Ry 2022-12-25 21:45:31 -08:00
parent eae21dd08b
commit ea53fb151c
2 changed files with 31 additions and 4 deletions

View File

@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "bus.h"
#include "cpu.h"
@ -18,9 +19,9 @@
bool bus_requests_exit = false;
extern struct timeval rtc_current_time;
extern time_t rtc_time;
extern uint32_t rtc_uptime;
;
extern fox32_vm_t vm;
extern disk_controller_t disk_controller;
extern mouse_t mouse;
@ -89,7 +90,32 @@ int bus_io_read(void *user, uint32_t *value, uint32_t port) {
case 0x80000700 ... 0x80000706: { // RTC port
uint8_t setting = port & 0x000000FF;
struct tm *now = localtime(&rtc_time);
switch (setting) {
case 0x00: { // year
*value = now->tm_year;
break;
}
case 0x01: { // month
*value = now->tm_mon;
break;
}
case 0x02: { // day
*value = now->tm_mday;
break;
}
case 0x03: { // hour
*value = now->tm_hour;
break;
}
case 0x04: { // minute
*value = now->tm_min;
break;
}
case 0x05: { // second
*value = now->tm_sec;
break;
}
case 0x06: { // ms since startup
*value = rtc_uptime;
break;

View File

@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "bus.h"
#include "cpu.h"
@ -32,7 +33,7 @@ uint32_t tick_end;
int ticks = 0;
bool done = false;
struct timeval rtc_current_time;
time_t rtc_time;
uint32_t rtc_uptime;
void main_loop(void);
@ -124,7 +125,7 @@ void main_loop(void) {
for (int i = 0; i < dt; i++) {
rtc_uptime += 1;
gettimeofday(&rtc_current_time, 0);
rtc_time = time(NULL);
int cycles_left = cycles_per_tick;