Skip to content

Commit

Permalink
Move RTC to same ports as IO expander
Browse files Browse the repository at this point in the history
  • Loading branch information
jblang committed Dec 16, 2018
1 parent 6cfb3b1 commit 4cd4fc4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 89 deletions.
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# Hardware revision (Important: must be set to correct value)
#BOARD_REV=3
# BOARD_REV=3

# Base address for RomWBW-style paging; comment out to disable support
#PAGE_BASE=0x78
# PAGE_BASE=0x78

# Uncomment to enable support for SST39F0x0 flash chips on RomWBW boards
#SST_FLASH=1
# SST_FLASH=1

# Uncomment to enable DS1306 RTC support
#DS1306_RTC=1

# Base address on which to expose RTC to Z80
#RTC_BASE=0x04
# DS1306_RTC=1

# Uncomment to enable Colecovision controller emulation
#COLECO_CONTROL=1

# Base address TMS9918A chip; comment out to disable support
#TMS_BASE=0xBE
# TMS_BASE=0xBE

# Port assigned to SN76489 sound chip
#SN76489_PORT=0xFF
# SN76489_PORT=0xFF

# Base port on which to expose I/O Expanders to Z80
#IOX_BASE=0x00
# Base port on which to expose I/O expander card to Z80
# IOX_BASE=0x00

# Current git hash
GITVERSION:= $(shell git log -1 --pretty='%h')
Expand Down
45 changes: 24 additions & 21 deletions iorq.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ void (*dma_function)(void) = NULL;
#define SIMH_DEV 0xFE
#define SENSE_SW 0xFF

#ifdef IOX_BASE
#define IOX_DEVPORT IOX_BASE
#define IOX_REGPORT IOX_BASE+1
#define IOX_VALPORT IOX_BASE+2
#define IOX_RTC 0
#define IOX_GPIO_MIN 1
#define IOX_GPIO_MAX 7

static uint8_t iox_dev = 0;
static uint8_t iox_reg = 0;
#endif

/**
* Handle Z80 IO request
*/
Expand All @@ -56,36 +68,27 @@ void iorq_dispatch(uint8_t logged)
cli();
switch (GET_ADDRLO) {
#ifdef IOX_BASE
case IOX_ADDRPORT:
case IOX_DEVPORT:
if (!GET_WR) {
iox_defaddr(GET_DATA);
iox_dev = GET_DATA;
}
break;
case IOX_REGPORT:
if (!GET_WR) {
iox_defreg(GET_DATA);
}
break;
case IOX_DATAPORT:
if (!GET_WR) {
iox_writedef(GET_DATA);
} else if (!GET_RD) {
SET_DATA(iox_readdef());
DATA_OUTPUT;
}
break;
#endif
#ifdef RTC_BASE
case RTC_REGPORT:
if (!GET_WR) {
rtc_defreg(GET_DATA);
iox_reg = GET_DATA;
}
break;
case RTC_DATAPORT:
case IOX_VALPORT:
if (!GET_WR) {
rtc_writedef(GET_DATA);
if (iox_dev == IOX_RTC)
rtc_write1(iox_reg, GET_DATA);
else if (iox_dev >= IOX_GPIO_MIN && iox_dev <= IOX_GPIO_MAX)
iox_write(iox_dev, iox_reg, GET_DATA);
} else if (!GET_RD) {
SET_DATA(rtc_readdef());
if (iox_dev == IOX_RTC)
SET_DATA(rtc_read1(iox_reg));
else if (iox_dev >= IOX_GPIO_MIN && iox_dev <= IOX_GPIO_MAX)
SET_DATA(iox_read(iox_dev, iox_reg));
DATA_OUTPUT;
}
break;
Expand Down
24 changes: 0 additions & 24 deletions iox.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include "iox.h"
#include "spi.h"

static uint8_t iox_def_chipaddr = 1;
static uint8_t iox_def_regaddr = 0;

void iox_init(void)
{
spi_init();
Expand Down Expand Up @@ -83,25 +80,4 @@ void iox_extcs_hi(uint8_t c)
uint8_t addr = (c / 4) * 2 + 1;
uint8_t pin = (c % 4) + 4;
iox_write(addr, GPIOB0, iox_read(addr, GPIOA0) | (1 << pin));
}

void iox_defaddr(uint8_t chipaddr)
{
if (chipaddr > 0 && chipaddr < 8)
iox_def_chipaddr = chipaddr;
}

void iox_defreg(uint8_t regaddr)
{
iox_def_regaddr = regaddr;
}

void iox_writedef(uint8_t data)
{
iox_write(iox_def_chipaddr, iox_def_regaddr, data);
}

uint8_t iox_readdef()
{
return iox_read(iox_def_chipaddr, iox_def_regaddr);
}
11 changes: 0 additions & 11 deletions iox.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,12 @@
#define WRITE 0
#define READ 1

#ifdef IOX_BASE
#define IOX_ADDRPORT IOX_BASE
#define IOX_REGPORT IOX_BASE+1
#define IOX_DATAPORT IOX_BASE+2
#endif

void iox_init(void);
void iox_begin(uint8_t mode, uint8_t addr);
void iox_end(void);
uint8_t iox_read(uint8_t chipaddr, uint8_t regaddr);
void iox_write(uint8_t chipaddr, uint8_t regaddr, uint8_t data);

void iox_defaddr(uint8_t chipaddr);
void iox_defreg(uint8_t regaddr);
void iox_writedef(uint8_t data);
uint8_t iox_readdef();

void iox_extcs_init(uint8_t addr);
void iox_extcs_lo(uint8_t c);
void iox_extcs_hi(uint8_t c);
Expand Down
17 changes: 0 additions & 17 deletions rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "rtc.h"
#include "spi.h"

static uint8_t rtc_def_regaddr = 0;

void rtc_begin()
{
SPI_SLOW;
Expand Down Expand Up @@ -109,19 +107,4 @@ void rtc_set_date(rtc_date_t date)
data[RTC_MIN] = ((date.min / 10) << 4) | (date.min % 10);
data[RTC_SEC] = ((date.sec / 10) << 4) | (date.sec % 10);
rtc_write(RTC_SEC, RTC_YEAR, data);
}

void rtc_defreg(uint8_t regaddr)
{
rtc_def_regaddr = regaddr;
}

void rtc_writedef(uint8_t data)
{
rtc_write1(rtc_def_regaddr, data);
}

uint8_t rtc_readdef()
{
return rtc_read1(rtc_def_regaddr);
}
5 changes: 0 additions & 5 deletions rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
#define RTC_SEL AUX1_SEL
#define RTC_DESEL AUX2_SEL

#ifdef RTC_BASE
#define RTC_REGPORT RTC_BASE
#define RTC_DATAPORT RTC_BASE+1
#endif

typedef struct {
uint8_t year;
uint8_t month;
Expand Down

0 comments on commit 4cd4fc4

Please sign in to comment.