Skip to content

Instantly share code, notes, and snippets.

@Dhole
Last active August 29, 2015 14:12
Show Gist options
  • Save Dhole/ed6cde3ec6b6574e080f to your computer and use it in GitHub Desktop.
Save Dhole/ed6cde3ec6b6574e080f to your computer and use it in GitHub Desktop.
void EXTI0_IRQHandler(void)
#define BUS_RD (GPIOC->IDR & 0x0002)
#define BUS_WR (GPIOC->IDR & 0x0004)
#define ADDR_IN GPIOD->IDR
#define DATA_IN GPIOE->IDR
#define DATA_OUT GPIOE->ODR
#define SET_DATA_MODE_IN GPIOE->MODER = 0x00000000;
#define SET_DATA_MODE_OUT GPIOE->MODER = 0x55550000;
/* Handle PC0 interrupt (rising edge of the gameboy CLK) */
void EXTI0_IRQHandler(void) {
uint16_t addr;
uint8_t data;
uint32_t enablestatus;
enablestatus = EXTI->IMR & EXTI_Line0;
if (((EXTI->PR & EXTI_Line0) != (uint32_t)RESET) &&
(enablestatus != (uint32_t)RESET)) {
/* Do stuff on trigger */
/* Wait 10 NOPs, until the ADDR is ready in the bus */
REP(1,0,asm("NOP"););
/* Read ADDR from the bus */
addr = ADDR_IN;
if (BUS_RD || !BUS_WR) {
/* Write operation */
/* Wait 30 NOPs, until the DATA is ready in the bus */
REP(3,0,asm("NOP"););
/* Read DATA from the bus */
data = DATA_IN >> 8;
/* Write data to cartridge at addr */
mbc1_write(addr, data);
} else {
/* Read operation */
/* Set the GPIOE in output mode */
SET_DATA_MODE_OUT;
/* Output the data read at addr through GPIOE */
DATA_OUT = ((uint16_t)mbc1_read(addr)) << 8;
/* Wait 14 NOPs, until the gameboy has read the DATA
* in the bus */
REP(1,4,asm("NOP"););
/* Set the GPIOE back to input mode */
SET_DATA_MODE_IN;
}
}
/* Clear interrupt flag */
EXTI->PR = EXTI_Line0;
//EXTI_ClearITPendingBit(EXTI_Line0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment