src/mess/machine/avr8.h
| r7566 | r7567 | |
| 3 | 3 | |
| 4 | 4 | // Helpful enums and defines for the Atmel 8-bit AVR series of microcontrollers |
| 5 | 5 | |
| 6 | namespace Avr8 |
| 7 | { |
| 8 | |
| 6 | 9 | enum |
| 7 | 10 | { |
| 8 | | AVR8_REG_R0 = 0, |
| 9 | | AVR8_REG_R1, |
| 10 | | AVR8_REG_R2, |
| 11 | | AVR8_REG_R3, |
| 12 | | AVR8_REG_R4, |
| 13 | | AVR8_REG_R5, |
| 14 | | AVR8_REG_R6, |
| 15 | | AVR8_REG_R7, |
| 16 | | AVR8_REG_R8, |
| 17 | | AVR8_REG_R9, |
| 18 | | AVR8_REG_R10, |
| 19 | | AVR8_REG_R11, |
| 20 | | AVR8_REG_R12, |
| 21 | | AVR8_REG_R13, |
| 22 | | AVR8_REG_R14, |
| 23 | | AVR8_REG_R15, |
| 24 | | AVR8_REG_R16, |
| 25 | | AVR8_REG_R17, |
| 26 | | AVR8_REG_R18, |
| 27 | | AVR8_REG_R19, |
| 28 | | AVR8_REG_R20, |
| 29 | | AVR8_REG_R21, |
| 30 | | AVR8_REG_R22, |
| 31 | | AVR8_REG_R23, |
| 32 | | AVR8_REG_R24, |
| 33 | | AVR8_REG_R25, |
| 34 | | AVR8_REG_R26, |
| 35 | | AVR8_REG_R27, |
| 36 | | AVR8_REG_R28, |
| 37 | | AVR8_REG_R29, |
| 38 | | AVR8_REG_R30, |
| 39 | | AVR8_REG_R31, |
| 11 | REGIDX_R0 = 0, |
| 12 | REGIDX_R1, |
| 13 | REGIDX_R2, |
| 14 | REGIDX_R3, |
| 15 | REGIDX_R4, |
| 16 | REGIDX_R5, |
| 17 | REGIDX_R6, |
| 18 | REGIDX_R7, |
| 19 | REGIDX_R8, |
| 20 | REGIDX_R9, |
| 21 | REGIDX_R10, |
| 22 | REGIDX_R11, |
| 23 | REGIDX_R12, |
| 24 | REGIDX_R13, |
| 25 | REGIDX_R14, |
| 26 | REGIDX_R15, |
| 27 | REGIDX_R16, |
| 28 | REGIDX_R17, |
| 29 | REGIDX_R18, |
| 30 | REGIDX_R19, |
| 31 | REGIDX_R20, |
| 32 | REGIDX_R21, |
| 33 | REGIDX_R22, |
| 34 | REGIDX_R23, |
| 35 | REGIDX_R24, |
| 36 | REGIDX_R25, |
| 37 | REGIDX_R26, |
| 38 | REGIDX_R27, |
| 39 | REGIDX_R28, |
| 40 | REGIDX_R29, |
| 41 | REGIDX_R30, |
| 42 | REGIDX_R31, |
| 40 | 43 | |
| 41 | | AVR8_REG_PINB = 0x23, |
| 42 | | AVR8_REG_DDRB, |
| 43 | | AVR8_REG_PORTB, |
| 44 | | AVR8_REG_PINC, |
| 45 | | AVR8_REG_DDRC, |
| 46 | | AVR8_REG_PORTC, |
| 47 | | AVR8_REG_PIND, |
| 48 | | AVR8_REG_DDRD, |
| 49 | | AVR8_REG_PORTD, |
| 44 | REGIDX_PINB = 0x23, |
| 45 | REGIDX_DDRB, |
| 46 | REGIDX_PORTB, |
| 47 | REGIDX_PINC, |
| 48 | REGIDX_DDRC, |
| 49 | REGIDX_PORTC, |
| 50 | REGIDX_PIND, |
| 51 | REGIDX_DDRD, |
| 52 | REGIDX_PORTD, |
| 50 | 53 | |
| 51 | | AVR8_REG_TIFR0 = 0x35, |
| 52 | | AVR8_REG_TIFR1, |
| 53 | | AVR8_REG_TIFR2, |
| 54 | REGIDX_TIFR0 = 0x35, |
| 55 | REGIDX_TIFR1, |
| 56 | REGIDX_TIFR2, |
| 54 | 57 | |
| 55 | | AVR8_REG_PCIFR = 0x3b, |
| 56 | | AVR8_REG_EIFR, |
| 57 | | AVR8_REG_EIMSK, |
| 58 | | AVR8_REG_GPIOR0, |
| 59 | | AVR8_REG_EECR, |
| 60 | | AVR8_REG_EEDR, |
| 61 | | AVR8_REG_EEARL, |
| 62 | | AVR8_REG_EEARH, |
| 63 | | AVR8_REG_GTCCR, |
| 64 | | AVR8_REG_TCCR0A, |
| 65 | | AVR8_REG_TCCR0B, |
| 66 | | AVR8_REG_TCNT0, |
| 67 | | AVR8_REG_OCR0A, |
| 68 | | AVR8_REG_OCR0B, |
| 58 | REGIDX_PCIFR = 0x3b, |
| 59 | REGIDX_EIFR, |
| 60 | REGIDX_EIMSK, |
| 61 | REGIDX_GPIOR0, |
| 62 | REGIDX_EECR, |
| 63 | REGIDX_EEDR, |
| 64 | REGIDX_EEARL, |
| 65 | REGIDX_EEARH, |
| 66 | REGIDX_GTCCR, |
| 67 | REGIDX_TCCR0A, |
| 68 | REGIDX_TCCR0B, |
| 69 | REGIDX_TCNT0, |
| 70 | REGIDX_OCR0A, |
| 71 | REGIDX_OCR0B, |
| 69 | 72 | |
| 70 | | AVR8_REG_GPIOR1 = 0x4a, |
| 71 | | AVR8_REG_GPIOR2, |
| 72 | | AVR8_REG_SPCR, |
| 73 | | AVR8_REG_SPSR, |
| 74 | | AVR8_REG_SPDR, |
| 73 | REGIDX_GPIOR1 = 0x4a, |
| 74 | REGIDX_GPIOR2, |
| 75 | REGIDX_SPCR, |
| 76 | REGIDX_SPSR, |
| 77 | REGIDX_SPDR, |
| 75 | 78 | |
| 76 | | AVR8_REG_ACSR = 0x50, |
| 79 | REGIDX_ACSR = 0x50, |
| 77 | 80 | |
| 78 | | AVR8_REG_SMCR = 0x53, |
| 79 | | AVR8_REG_MCUSR, |
| 80 | | AVR8_REG_MCUCR, |
| 81 | REGIDX_SMCR = 0x53, |
| 82 | REGIDX_MCUSR, |
| 83 | REGIDX_MCUCR, |
| 81 | 84 | |
| 82 | | AVR8_REG_SPMCSR = 0x57, |
| 85 | REGIDX_SPMCSR = 0x57, |
| 83 | 86 | |
| 84 | | AVR8_REG_SPL = 0x5d, |
| 85 | | AVR8_REG_SPH, |
| 86 | | AVR8_REG_SREG, |
| 87 | | AVR8_REG_WDTCSR, |
| 88 | | AVR8_REG_CLKPR, |
| 87 | REGIDX_SPL = 0x5d, |
| 88 | REGIDX_SPH, |
| 89 | REGIDX_SREG, |
| 90 | REGIDX_WDTCSR, |
| 91 | REGIDX_CLKPR, |
| 89 | 92 | |
| 90 | | AVR8_REG_PRR = 0X64, |
| 93 | REGIDX_PRR = 0x64, |
| 91 | 94 | |
| 92 | | AVR8_REG_OSCCAL = 0X66, |
| 95 | REGIDX_OSCCAL = 0x66, |
| 93 | 96 | |
| 94 | | AVR8_REG_PCICR = 0X68, |
| 95 | | AVR8_REG_EICRA, |
| 97 | REGIDX_PCICR = 0x68, |
| 98 | REGIDX_EICRA, |
| 96 | 99 | |
| 97 | | AVR8_REG_PCMSK0 = 0X6B, |
| 98 | | AVR8_REG_PCMSK1, |
| 99 | | AVR8_REG_PCMSK2, |
| 100 | | AVR8_REG_TIMSK0, |
| 101 | | AVR8_REG_TIMSK1, |
| 102 | | AVR8_REG_TIMSK2, |
| 100 | REGIDX_PCMSK0 = 0x6B, |
| 101 | REGIDX_PCMSK1, |
| 102 | REGIDX_PCMSK2, |
| 103 | REGIDX_TIMSK0, |
| 104 | REGIDX_TIMSK1, |
| 105 | REGIDX_TIMSK2, |
| 103 | 106 | |
| 104 | | AVR8_REG_ADCL = 0X78, |
| 105 | | AVR8_REG_ADCH, |
| 106 | | AVR8_REG_ADCSRA, |
| 107 | | AVR8_REG_ADCSRB, |
| 108 | | AVR8_REG_ADMUX, |
| 107 | REGIDX_ADCL = 0x78, |
| 108 | REGIDX_ADCH, |
| 109 | REGIDX_ADCSRA, |
| 110 | REGIDX_ADCSRB, |
| 111 | REGIDX_ADMUX, |
| 109 | 112 | |
| 110 | | AVR8_REG_DIDR0 = 0x7e, |
| 111 | | AVR8_REG_DIDR1, |
| 112 | | AVR8_REG_TCCR1A, |
| 113 | | AVR8_REG_TCCR1B, |
| 114 | | AVR8_REG_TCCR1C, |
| 113 | REGIDX_DIDR0 = 0x7e, |
| 114 | REGIDX_DIDR1, |
| 115 | REGIDX_TCCR1A, |
| 116 | REGIDX_TCCR1B, |
| 117 | REGIDX_TCCR1C, |
| 115 | 118 | |
| 116 | | AVR8_REG_TCNT1L = 0x84, |
| 117 | | AVR8_REG_TCNT1H, |
| 118 | | AVR8_REG_ICR1L, |
| 119 | | AVR8_REG_ICR1H, |
| 120 | | AVR8_REG_OCR1AL, |
| 121 | | AVR8_REG_OCR1AH, |
| 122 | | AVR8_REG_OCR1BL, |
| 123 | | AVR8_REG_OCR1BH, |
| 119 | REGIDX_TCNT1L = 0x84, |
| 120 | REGIDX_TCNT1H, |
| 121 | REGIDX_ICR1L, |
| 122 | REGIDX_ICR1H, |
| 123 | REGIDX_OCR1AL, |
| 124 | REGIDX_OCR1AH, |
| 125 | REGIDX_OCR1BL, |
| 126 | REGIDX_OCR1BH, |
| 124 | 127 | |
| 125 | | AVR8_REG_TCCR2A = 0xb0, |
| 126 | | AVR8_REG_TCCR2B, |
| 127 | | AVR8_REG_TCNT2, |
| 128 | | AVR8_REG_OCR2A, |
| 129 | | AVR8_REG_OCR2B, |
| 128 | REGIDX_TCCR2A = 0xb0, |
| 129 | REGIDX_TCCR2B, |
| 130 | REGIDX_TCNT2, |
| 131 | REGIDX_OCR2A, |
| 132 | REGIDX_OCR2B, |
| 130 | 133 | |
| 131 | | AVR8_REG_ASSR = 0xb6, |
| 134 | REGIDX_ASSR = 0xb6, |
| 132 | 135 | |
| 133 | | AVR8_REG_TWBR = 0xb8, |
| 134 | | AVR8_REG_TWSR, |
| 135 | | AVR8_REG_TWAR, |
| 136 | | AVR8_REG_TWDR, |
| 137 | | AVR8_REG_TWCR, |
| 138 | | AVR8_REG_TWAMR, |
| 136 | REGIDX_TWBR = 0xb8, |
| 137 | REGIDX_TWSR, |
| 138 | REGIDX_TWAR, |
| 139 | REGIDX_TWDR, |
| 140 | REGIDX_TWCR, |
| 141 | REGIDX_TWAMR, |
| 139 | 142 | |
| 140 | | AVR8_REG_UCSR0A = 0xc0, |
| 141 | | AVR8_REG_UCSR0B, |
| 142 | | AVR8_REG_UCSR0C, |
| 143 | REGIDX_UCSR0A = 0xc0, |
| 144 | REGIDX_UCSR0B, |
| 145 | REGIDX_UCSR0C, |
| 143 | 146 | |
| 144 | | AVR8_REG_UBRR0L = 0xc4, |
| 145 | | AVR8_REG_UBRR0H, |
| 146 | | AVR8_REG_UDR0 |
| 147 | REGIDX_UBRR0L = 0xc4, |
| 148 | REGIDX_UBRR0H, |
| 149 | REGIDX_UDR0 |
| 147 | 150 | }; |
| 148 | 151 | |
| 149 | | #define AVR8_OCR1BH (state->regs[AVR8_REG_OCR1BH]) |
| 150 | | #define AVR8_OCR1BL (state->regs[AVR8_REG_OCR1BL]) |
| 151 | | #define AVR8_OCR1AH (state->regs[AVR8_REG_OCR1AH]) |
| 152 | | #define AVR8_OCR1AL (state->regs[AVR8_REG_OCR1AL]) |
| 153 | | #define AVR8_ICR1H (state->regs[AVR8_REG_ICR1H]) |
| 154 | | #define AVR8_ICR1L (state->regs[AVR8_REG_ICR1L]) |
| 155 | | #define AVR8_TCNT1H (state->regs[AVR8_REG_TCNT1H]) |
| 156 | | #define AVR8_TCNT1L (state->regs[AVR8_REG_TCNT1L]) |
| 157 | | #define AVR8_TCCR1B (state->regs[AVR8_REG_TCCR1B]) |
| 158 | | #define AVR8_TCCR1A (state->regs[AVR8_REG_TCCR1A]) |
| 159 | | #define AVR8_TIMSK1 (state->regs[AVR8_REG_TIMSK1]) |
| 160 | | #define AVR8_TIMSK1_OCIE1A 0x02 |
| 161 | | #define AVR8_TIMSK1_OCIE1B 0x04 |
| 152 | enum |
| 153 | { |
| 154 | WGM1_NORMAL = 0, |
| 155 | WGM1_PWM_8_PC, |
| 156 | WGM1_PWM_9_PC, |
| 157 | WGM1_PWM_10_PC, |
| 158 | WGM1_CTC_OCR, |
| 159 | WGM1_FAST_PWM_8, |
| 160 | WGM1_FAST_PWM_9, |
| 161 | WGM1_FAST_PWM_10, |
| 162 | WGM1_PWM_PFC_ICR, |
| 163 | WGM1_PWM_PFC_OCR, |
| 164 | WGM1_PWM_PC_ICR, |
| 165 | WGM1_PWM_PC_OCR, |
| 166 | WGM1_CTC_ICR, |
| 167 | WGM1_RESERVED, |
| 168 | WGM1_FAST_PWM_ICR, |
| 169 | WGM1_FAST_PWM_OCR |
| 170 | }; |
| 171 | |
| 172 | } // namespace AVR8 |
| 173 | |
| 174 | #define AVR8_OCR1BH (state->regs[Avr8::REGIDX_OCR1BH]) |
| 175 | #define AVR8_OCR1BL (state->regs[Avr8::REGIDX_OCR1BL]) |
| 176 | #define AVR8_OCR1AH (state->regs[Avr8::REGIDX_OCR1AH]) |
| 177 | #define AVR8_OCR1AL (state->regs[Avr8::REGIDX_OCR1AL]) |
| 178 | #define AVR8_ICR1H (state->regs[Avr8::REGIDX_ICR1H]) |
| 179 | #define AVR8_ICR1L (state->regs[Avr8::REGIDX_ICR1L]) |
| 180 | #define AVR8_TCNT1H (state->regs[Avr8::REGIDX_TCNT1H]) |
| 181 | #define AVR8_TCNT1L (state->regs[Avr8::REGIDX_TCNT1L]) |
| 182 | |
| 183 | #define AVR8_TCCR1B (state->regs[Avr8::REGIDX_TCCR1B]) |
| 184 | #define AVR8_TCCR1B_ICNC1_MASK 0x80 |
| 185 | #define AVR8_TCCR1B_ICNC1_SHIFT 7 |
| 186 | #define AVR8_TCCR1B_ICES1_MASK 0x40 |
| 187 | #define AVR8_TCCR1B_ICES1_SHIFT 6 |
| 188 | #define AVR8_TCCR1B_WGM1_32_MASK 0x18 |
| 189 | #define AVR8_TCCR1B_WGM1_32_SHIFT 3 |
| 190 | #define AVR8_TCCR1B_CS_MASK 0x03 |
| 191 | #define AVR8_TCCR1B_CS_SHIFT 0 |
| 192 | |
| 193 | #define AVR8_TCCR1A (state->regs[Avr8::REGIDX_TCCR1A]) |
| 194 | #define AVR8_TCCR1A_COM1A_MASK 0xc0 |
| 195 | #define AVR8_TCCR1A_COM1A_SHIFT 6 |
| 196 | #define AVR8_TCCR1A_COM1B_MASK 0x30 |
| 197 | #define AVR8_TCCR1A_COM1B_SHIFT 4 |
| 198 | #define AVR8_TCCR1A_WGM1_10_MASK 0x03 |
| 199 | #define AVR8_TCCR1A_WGM1_10_SHIFT 0 |
| 200 | #define AVR8_TCCR1A_COM1A ((AVR8_TCCR1A & AVR8_TCCR1A_COM1A_MASK) >> AVR8_TCCR1A_COM1A_SHIFT) |
| 201 | #define AVR8_TCCR1A_COM1B ((AVR8_TCCR1A & AVR8_TCCR1A_COM1A_MASK) >> AVR8_TCCR1A_COM1A_SHIFT) |
| 202 | #define AVR8_TCCR1A_WGM1_10 (AVR8_TCCR1A & AVR8_TCCR1A_WGM1_10_MASK) |
| 203 | |
| 204 | #define AVR8_TIMSK1 (state->regs[Avr8::REGIDX_TIMSK1]) |
| 205 | #define AVR8_TIMSK1_ICIE1_MASK 0x20 |
| 206 | #define AVR8_TIMSK1_OCIE1B_MASK 0x04 |
| 207 | #define AVR8_TIMSK1_OCIE1A_MASK 0x02 |
| 208 | #define AVR8_TIMSK1_TOIE1_MASK 0x01 |
| 209 | #define AVR8_TIMSK1_ICIE1 ((AVR8_TIMSK1 & AVR8_TIMSK1_ICIE1_MASK) >> 5) |
| 210 | #define AVR8_TIMSK1_OCIE1B ((AVR8_TIMSK1 & AVR8_TIMSK1_OCIE1B_MASK) >> 2) |
| 211 | #define AVR8_TIMSK1_OCIE1A ((AVR8_TIMSK1 & AVR8_TIMSK1_OCIE1A_MASK) >> 1) |
| 212 | #define AVR8_TIMSK1_TOIE1 (AVR8_TIMSK1 & AVR8_TIMSK1_TOIE1_MASK) |
| 213 | |
| 214 | #define AVR8_SPSR (state->regs[Avr8::REGIDX_SPSR]) |
| 215 | #define AVR8_SPSR_SPIF_MASK 0x80 |
| 216 | #define AVR8_SPSR_SPIF_SHIFT 7 |
| 217 | #define AVR8_SPSR_SPR2X_MASK 0x01 |
| 218 | #define AVR8_SPSR_SPR2X (AVR8_SPSR & AVR8_SPSR_SPR2X_MASK) |
| 219 | |
| 220 | #define AVR8_SPCR (state->regs[Avr8::REGIDX_SPCR]) |
| 221 | #define AVR8_SPCR_SPIE_MASK 0x80 |
| 222 | #define AVR8_SPCR_SPE_MASK 0x40 |
| 223 | #define AVR8_SPCR_DORD_MASK 0x20 |
| 224 | #define AVR8_SPCR_MSTR_MASK 0x10 |
| 225 | #define AVR8_SPCR_CPOL_MASK 0x08 |
| 226 | #define AVR8_SPCR_CPHA_MASK 0x04 |
| 227 | #define AVR8_SPCR_SPR_MASK 0x03 |
| 228 | #define AVR8_SPCR_SPIE ((AVR8_SPCR & AVR8_SPCR_SPIE_MASK) >> 7) |
| 229 | #define AVR8_SPCR_SPE ((AVR8_SPCR & AVR8_SPCR_SPE_MASK) >> 6) |
| 230 | #define AVR8_SPCR_DORD ((AVR8_SPCR & AVR8_SPCR_DORD_MASK) >> 5) |
| 231 | #define AVR8_SPCR_MSTR ((AVR8_SPCR & AVR8_SPCR_MSTR_MASK) >> 4) |
| 232 | #define AVR8_SPCR_CPOL ((AVR8_SPCR & AVR8_SPCR_CPOL_MASK) >> 3) |
| 233 | #define AVR8_SPCR_CPHA ((AVR8_SPCR & AVR8_SPCR_CPHA_MASK) >> 2) |
| 234 | #define AVR8_SPCR_SPR (AVR8_SPCR & AVR8_SPCR_SPR_MASK) |
| 235 | |
| 236 | #define AVR8_TIFR1 (state->regs[Avr8::REGIDX_TIFR1]) |
| 237 | #define AVR8_TIFR1_ICF1_MASK 0x20 |
| 238 | #define AVR8_TIFR1_ICF1_SHIFT 5 |
| 239 | #define AVR8_TIFR1_OCF1B_MASK 0x04 |
| 240 | #define AVR8_TIFR1_OCF1B_SHIFT 2 |
| 241 | #define AVR8_TIFR1_OCF1A_MASK 0x02 |
| 242 | #define AVR8_TIFR1_OCF1A_SHIFT 1 |
| 243 | #define AVR8_TIFR1_TOV1_MASK 0x01 |
| 244 | #define AVR8_TIFR1_TOV1_SHIFT 0 |
| 245 | |
| 246 | #define AVR8_DDRD (state->regs[Avr8::REGIDX_DDRD]) |
| 247 | #define AVR8_DDRC (state->regs[Avr8::REGIDX_DDRC]) |
| 248 | #define AVR8_PORTB (state->regs[Avr8::REGIDX_PORTB]) |
| 249 | #define AVR8_DDRB (state->regs[Avr8::REGIDX_DDRB]) |
| 250 | |
| 162 | 251 | #define AVR8_OCR1A ((AVR8_OCR1AH << 8) | AVR8_OCR1AL) |
| 163 | 252 | #define AVR8_OCR1B ((AVR8_OCR1BH << 8) | AVR8_OCR1BL) |
| 164 | 253 | #define AVR8_ICR1 ((AVR8_ICR1H << 8) | AVR8_ICR1L) |
| 165 | 254 | #define AVR8_TCNT1 ((AVR8_TCNT1H << 8) | AVR8_TCNT1L) |
| 166 | 255 | #define AVR8_WGM1 (((AVR8_TCCR1B & 0x18) >> 1) | (AVR8_TCCR1A & 0x03)) |
| 256 | |
| 167 | 257 | #define AVR8_TCNT1_DIR (state->tcnt1_direction) |
| 168 | 258 | |
| 169 | | enum |
| 170 | | { |
| 171 | | AVR8_WGM1_NORMAL = 0, |
| 172 | | AVR8_WGM1_PWM_8_PC, |
| 173 | | AVR8_WGM1_PWM_9_PC, |
| 174 | | AVR8_WGM1_PWM_10_PC, |
| 175 | | AVR8_WGM1_CTC_OCR, |
| 176 | | AVR8_WGM1_FAST_PWM_8, |
| 177 | | AVR8_WGM1_FAST_PWM_9, |
| 178 | | AVR8_WGM1_FAST_PWM_10, |
| 179 | | AVR8_WGM1_PWM_PFC_ICR, |
| 180 | | AVR8_WGM1_PWM_PFC_OCR, |
| 181 | | AVR8_WGM1_PWM_PC_ICR, |
| 182 | | AVR8_WGM1_PWM_PC_OCR, |
| 183 | | AVR8_WGM1_CTC_ICR, |
| 184 | | AVR8_WGM1_RESERVED, |
| 185 | | AVR8_WGM1_FAST_PWM_ICR, |
| 186 | | AVR8_WGM1_FAST_PWM_OCR |
| 187 | | }; |
| 188 | | |
| 189 | 259 | #endif // __EMU_MACHINE_AVR8_H__ |
src/mess/drivers/craft.c
| r7566 | r7567 | |
| 1 | | /*\ |
| 1 | br/*\ |
| 2 | 2 | * * Linus Akesson's "Craft" |
| 3 | 3 | * * |
| 4 | 4 | * * Skeleton driver by MooglyGuy |
| r7566 | r7567 | |
| 12 | 12 | |
| 13 | 13 | #define VERBOSE_LEVEL (0) |
| 14 | 14 | |
| 15 | | #define ENABLE_VERBOSE_LOG (0) |
| 15 | #define ENABLE_VERBOSE_LOG (1) |
| 16 | 16 | |
| 17 | 17 | #if ENABLE_VERBOSE_LOG |
| 18 | 18 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| r7566 | r7567 | |
| 51 | 51 | emu_timer* ocr1b_timer; |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | enum |
| 55 | { |
| 56 | AVR8_REG_A = 0, |
| 57 | AVR8_REG_B, |
| 58 | AVR8_REG_C, |
| 59 | AVR8_REG_D, |
| 60 | }; |
| 61 | |
| 62 | static char avr8_reg_name[4] = { 'A', 'B', 'C', 'D' }; |
| 63 | |
| 54 | 64 | #if 0 |
| 55 | 65 | static UINT64 avr8_get_timer_1_frequency(craft_state *state) |
| 56 | 66 | { |
| r7566 | r7567 | |
| 130 | 140 | return 0xffff; |
| 131 | 141 | } |
| 132 | 142 | |
| 133 | | enum |
| 134 | | { |
| 135 | | AVR8_REG_A = 0, |
| 136 | | AVR8_REG_B, |
| 137 | | }; |
| 138 | | |
| 139 | 143 | static UINT16 avr8_get_tc1_distance(craft_state *state, INT32 reg) |
| 140 | 144 | { |
| 141 | 145 | UINT16 top = avr8_get_tc1_top(state); |
| 142 | | UINT16 ocr = (reg == AVR8_REG_A) ? AVR8_OCR1A : AVR8_OCR1B; |
| 146 | UINT16 ocr = (reg == Avr8::REGIDX_A) ? AVR8_OCR1A : AVR8_OCR1B; |
| 143 | 147 | if(AVR8_TCNT1_DIR > 0) |
| 144 | 148 | { |
| 145 | 149 | if(AVR8_TCNT1 < ocr) |
| r7566 | r7567 | |
| 175 | 179 | } |
| 176 | 180 | else |
| 177 | 181 | { |
| 178 | | attotime period_a = attotime_mul(ATTOTIME_IN_HZ(frequency), avr8_get_tc1_distance(state, AVR8_REG_A)); |
| 179 | | attotime period_b = attotime_mul(ATTOTIME_IN_HZ(frequency), avr8_get_tc1_distance(state, AVR8_REG_B)); |
| 182 | attotime period_a = attotime_mul(ATTOTIME_IN_HZ(frequency), avr8_get_tc1_distance(state, Avr8::REGIDX_A)); |
| 183 | attotime period_b = attotime_mul(ATTOTIME_IN_HZ(frequency), avr8_get_tc1_distance(state, Avr8::REGIDX_B)); |
| 180 | 184 | timer_adjust_oneshot(state->ocr1a_timer, period_a, 0); |
| 181 | 185 | timer_adjust_oneshot(state->ocr1b_timer, period_b, 0); |
| 182 | 186 | } |
| r7566 | r7567 | |
| 209 | 213 | { |
| 210 | 214 | craft_state *state = (craft_state *)space->machine->driver_data; |
| 211 | 215 | |
| 212 | | if(offset <= AVR8_REG_R31) |
| 216 | if(offset <= Avr8::REGIDX_R31) |
| 213 | 217 | { |
| 214 | 218 | return state->regs[offset]; |
| 215 | 219 | } |
| 216 | 220 | |
| 217 | 221 | switch( offset ) |
| 218 | 222 | { |
| 223 | case Avr8::REGIDX_SPL: |
| 224 | case Avr8::REGIDX_SPH: |
| 225 | case Avr8::REGIDX_SREG: |
| 226 | return state->regs[offset]; |
| 227 | |
| 219 | 228 | default: |
| 220 | 229 | verboselog(space->machine, 0, "AVR8: Unrecognized register read: %02x\n", offset ); |
| 221 | 230 | } |
| r7566 | r7567 | |
| 223 | 232 | return 0; |
| 224 | 233 | } |
| 225 | 234 | |
| 235 | static UINT8 avr8_get_ddr(running_machine *machine, int reg) |
| 236 | { |
| 237 | craft_state *state = (craft_state *)machine->driver_data; |
| 238 | |
| 239 | switch(reg) |
| 240 | { |
| 241 | case AVR8_REG_B: |
| 242 | return AVR8_DDRB; |
| 243 | |
| 244 | case AVR8_REG_C: |
| 245 | return AVR8_DDRC; |
| 246 | |
| 247 | case AVR8_REG_D: |
| 248 | return AVR8_DDRD; |
| 249 | |
| 250 | default: |
| 251 | verboselog(machine, 0, "avr8_get_ddr: Unsupported register retrieval: %c\n", avr8_reg_name[reg]); |
| 252 | break; |
| 253 | } |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static void avr8_change_ddr(running_machine *machine, int reg, UINT8 data) |
| 259 | { |
| 260 | //craft_state *state = (craft_state *)machine->driver_data; |
| 261 | |
| 262 | UINT8 oldddr = avr8_get_ddr(machine, reg); |
| 263 | UINT8 newddr = data; |
| 264 | UINT8 changed = newddr ^ oldddr; |
| 265 | // TODO: When AVR8 is converted to emu/machine, this should be factored out to 8 single-bit callbacks per port |
| 266 | if(changed) |
| 267 | { |
| 268 | // TODO |
| 269 | verboselog(machine, 0, "avr8_change_port: DDR%c lines %02x changed\n", avr8_reg_name[reg], changed); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | static void avr8_change_port(running_machine *machine, int reg, UINT8 data) |
| 274 | { |
| 275 | //craft_state *state = (craft_state *)machine->driver_data; |
| 276 | |
| 277 | UINT8 oldport = avr8_get_ddr(machine, reg); |
| 278 | UINT8 newport = data; |
| 279 | UINT8 changed = newport ^ oldport; |
| 280 | // TODO: When AVR8 is converted to emu/machine, this should be factored out to 8 single-bit callbacks per port |
| 281 | if(changed) |
| 282 | { |
| 283 | // TODO |
| 284 | verboselog(machine, 0, "avr8_change_port: PORT%c lines %02x changed\n", avr8_reg_name[reg], changed); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | namespace Avr8 |
| 289 | { |
| 290 | |
| 291 | enum |
| 292 | { |
| 293 | INTIDX_SPI, |
| 294 | INTIDX_ICF1, |
| 295 | INTIDX_OCF1B, |
| 296 | INTIDX_OCF1A, |
| 297 | INTIDX_TOV1, |
| 298 | |
| 299 | INTIDX_COUNT, |
| 300 | }; |
| 301 | |
| 302 | class CInterruptCondition |
| 303 | { |
| 304 | public: |
| 305 | UINT8 m_intindex; |
| 306 | UINT8 m_regindex; |
| 307 | UINT8 m_regmask; |
| 308 | UINT8 m_regshift; |
| 309 | UINT8* mp_reg; |
| 310 | }; |
| 311 | |
| 312 | static const CInterruptCondition s_int_conditions[INTIDX_COUNT] = |
| 313 | { |
| 314 | { INTIDX_SPI, REGIDX_SPSR, AVR8_SPSR_SPIF_MASK, AVR8_SPSR_SPIF_SHIFT, NULL }, |
| 315 | { INTIDX_ICF1, REGIDX_TIFR1, AVR8_TIFR1_ICF1_MASK, AVR8_TIFR1_ICF1_SHIFT, NULL }, |
| 316 | { INTIDX_OCF1B, REGIDX_TIFR1, AVR8_TIFR1_OCF1B_MASK, AVR8_TIFR1_OCF1B_SHIFT, NULL }, |
| 317 | { INTIDX_OCF1A, REGIDX_TIFR1, AVR8_TIFR1_OCF1A_MASK, AVR8_TIFR1_OCF1A_SHIFT, NULL }, |
| 318 | { INTIDX_TOV1, REGIDX_TIFR1, AVR8_TIFR1_TOV1_MASK, AVR8_TIFR1_TOV1_SHIFT, NULL } |
| 319 | }; |
| 320 | |
| 321 | } |
| 322 | |
| 323 | static void avr8_interrupt_update(running_machine *machine, int source) |
| 324 | { |
| 325 | // TODO |
| 326 | verboselog(machine, 0, "avr8_interrupt_update: TODO; source interrupt is %d\n", source); |
| 327 | } |
| 328 | |
| 329 | /****************/ |
| 330 | /* SPI Handling */ |
| 331 | /****************/ |
| 332 | |
| 333 | static void avr8_enable_spi(running_machine *machine) |
| 334 | { |
| 335 | // TODO |
| 336 | verboselog(machine, 0, "avr8_enable_spi: TODO\n"); |
| 337 | } |
| 338 | |
| 339 | static void avr8_disable_spi(running_machine *machine) |
| 340 | { |
| 341 | // TODO |
| 342 | verboselog(machine, 0, "avr8_disable_spi: TODO\n"); |
| 343 | } |
| 344 | |
| 345 | static void avr8_spi_update_masterslave_select(running_machine *machine) |
| 346 | { |
| 347 | // TODO |
| 348 | craft_state *state = (craft_state *)machine->driver_data; |
| 349 | verboselog(machine, 0, "avr8_spi_update_masterslave_select: TODO; AVR is %s\n", AVR8_SPCR_MSTR ? "Master" : "Slave"); |
| 350 | } |
| 351 | |
| 352 | static void avr8_spi_update_clock_polarity(running_machine *machine) |
| 353 | { |
| 354 | // TODO |
| 355 | craft_state *state = (craft_state *)machine->driver_data; |
| 356 | verboselog(machine, 0, "avr8_spi_update_clock_polarity: TODO; SCK is Active-%s\n", AVR8_SPCR_CPOL ? "Low" : "High"); |
| 357 | } |
| 358 | |
| 359 | static void avr8_spi_update_clock_phase(running_machine *machine) |
| 360 | { |
| 361 | // TODO |
| 362 | craft_state *state = (craft_state *)machine->driver_data; |
| 363 | verboselog(machine, 0, "avr8_spi_update_clock_phase: TODO; Sampling edge is %s\n", AVR8_SPCR_CPHA ? "Trailing" : "Leading"); |
| 364 | } |
| 365 | |
| 366 | static UINT8 avr8_spi_clock_divisor[8] = { 4, 16, 64, 128, 2, 8, 32, 64 }; |
| 367 | |
| 368 | static void avr8_spi_update_clock_rate(running_machine *machine) |
| 369 | { |
| 370 | // TODO |
| 371 | craft_state *state = (craft_state *)machine->driver_data; |
| 372 | verboselog(machine, 0, "avr8_spi_update_clock_rate: TODO; New clock rate should be f/%d\n", avr8_spi_clock_divisor[AVR8_SPCR_SPR] / (AVR8_SPSR_SPR2X ? 2 : 1)); |
| 373 | } |
| 374 | |
| 375 | static void avr8_change_spcr(running_machine *machine, UINT8 data) |
| 376 | { |
| 377 | craft_state *state = (craft_state *)machine->driver_data; |
| 378 | |
| 379 | UINT8 oldspcr = AVR8_SPCR; |
| 380 | UINT8 newspcr = data; |
| 381 | UINT8 changed = newspcr ^ oldspcr; |
| 382 | UINT8 high_to_low = ~newspcr & oldspcr; |
| 383 | UINT8 low_to_high = newspcr & ~oldspcr; |
| 384 | |
| 385 | AVR8_SPCR = data; |
| 386 | |
| 387 | if(changed & AVR8_SPCR_SPIE_MASK) |
| 388 | { |
| 389 | // Check for SPI interrupt condition |
| 390 | avr8_interrupt_update(machine, Avr8::INTIDX_SPI); |
| 391 | } |
| 392 | |
| 393 | if(low_to_high & AVR8_SPCR_SPE_MASK) |
| 394 | { |
| 395 | avr8_enable_spi(machine); |
| 396 | } |
| 397 | else if(high_to_low & AVR8_SPCR_SPE_MASK) |
| 398 | { |
| 399 | avr8_disable_spi(machine); |
| 400 | } |
| 401 | |
| 402 | if(changed & AVR8_SPCR_MSTR_MASK) |
| 403 | { |
| 404 | avr8_spi_update_masterslave_select(machine); |
| 405 | } |
| 406 | |
| 407 | if(changed & AVR8_SPCR_CPOL_MASK) |
| 408 | { |
| 409 | avr8_spi_update_clock_polarity(machine); |
| 410 | } |
| 411 | |
| 412 | if(changed & AVR8_SPCR_CPHA_MASK) |
| 413 | { |
| 414 | avr8_spi_update_clock_phase(machine); |
| 415 | } |
| 416 | |
| 417 | if(changed & AVR8_SPCR_SPR_MASK) |
| 418 | { |
| 419 | avr8_spi_update_clock_rate(machine); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | static void avr8_change_spsr(running_machine *machine, UINT8 data) |
| 424 | { |
| 425 | craft_state *state = (craft_state *)machine->driver_data; |
| 426 | |
| 427 | UINT8 oldspsr = AVR8_SPSR; |
| 428 | UINT8 newspsr = data; |
| 429 | UINT8 changed = newspsr ^ oldspsr; |
| 430 | //UINT8 high_to_low = ~newspsr & oldspsr; |
| 431 | //UINT8 low_to_high = newspsr & ~oldspsr; |
| 432 | |
| 433 | AVR8_SPSR &= ~1; |
| 434 | AVR8_SPSR |= data & 1; |
| 435 | |
| 436 | if(changed & AVR8_SPSR_SPR2X_MASK) |
| 437 | { |
| 438 | avr8_spi_update_clock_rate(machine); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /********************/ |
| 443 | /* Timer 1 Handling */ |
| 444 | /********************/ |
| 445 | |
| 446 | static void avr8_change_timsk1(running_machine *machine, UINT8 data) |
| 447 | { |
| 448 | craft_state *state = (craft_state *)machine->driver_data; |
| 449 | |
| 450 | UINT8 oldtimsk = AVR8_TIMSK1; |
| 451 | UINT8 newtimsk = data; |
| 452 | UINT8 changed = newtimsk ^ oldtimsk; |
| 453 | |
| 454 | if(changed & AVR8_TIMSK1_ICIE1_MASK) |
| 455 | { |
| 456 | // Check for Input Capture Interrupt interrupt condition |
| 457 | avr8_interrupt_update(machine, Avr8::INTIDX_ICF1); |
| 458 | } |
| 459 | |
| 460 | if(changed & AVR8_TIMSK1_OCIE1B_MASK) |
| 461 | { |
| 462 | // Check for Output Compare B Interrupt interrupt condition |
| 463 | avr8_interrupt_update(machine, Avr8::INTIDX_OCF1B); |
| 464 | } |
| 465 | |
| 466 | if(changed & AVR8_TIMSK1_OCIE1A_MASK) |
| 467 | { |
| 468 | // Check for Output Compare A Interrupt interrupt condition |
| 469 | avr8_interrupt_update(machine, Avr8::INTIDX_OCF1A); |
| 470 | } |
| 471 | |
| 472 | if(changed & AVR8_TIMSK1_TOIE1_MASK) |
| 473 | { |
| 474 | // Check for Output Compare A Interrupt interrupt condition |
| 475 | avr8_interrupt_update(machine, Avr8::INTIDX_TOV1); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | static void avr8_update_timer1_compare_mode(running_machine *machine, int reg) |
| 480 | { |
| 481 | // TODO |
| 482 | craft_state *state = (craft_state *)machine->driver_data; |
| 483 | UINT8 mode = (reg == AVR8_REG_A) ? AVR8_TCCR1A_COM1A : AVR8_TCCR1A_COM1B; |
| 484 | switch(mode) |
| 485 | { |
| 486 | case 0: |
| 487 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; OCR1%c disconnected, normal port operation\n", avr8_reg_name[reg]); |
| 488 | break; |
| 489 | |
| 490 | case 1: |
| 491 | switch(AVR8_WGM1) |
| 492 | { |
| 493 | case Avr8::WGM1_NORMAL: |
| 494 | case Avr8::WGM1_CTC_OCR: |
| 495 | case Avr8::WGM1_CTC_ICR: |
| 496 | case Avr8::WGM1_FAST_PWM_8: |
| 497 | case Avr8::WGM1_FAST_PWM_9: |
| 498 | case Avr8::WGM1_FAST_PWM_10: |
| 499 | case Avr8::WGM1_PWM_8_PC: |
| 500 | case Avr8::WGM1_PWM_9_PC: |
| 501 | case Avr8::WGM1_PWM_10_PC: |
| 502 | case Avr8::WGM1_PWM_PFC_ICR: |
| 503 | case Avr8::WGM1_PWM_PC_ICR: |
| 504 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Toggle OC1%c on compare match\n", avr8_reg_name[reg]); |
| 505 | break; |
| 506 | |
| 507 | case Avr8::WGM1_FAST_PWM_ICR: |
| 508 | case Avr8::WGM1_FAST_PWM_OCR: |
| 509 | case Avr8::WGM1_PWM_PFC_OCR: |
| 510 | case Avr8::WGM1_PWM_PC_OCR: |
| 511 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Toggle OC1A on compare match, OC1B disconnected\n"); |
| 512 | break; |
| 513 | } |
| 514 | break; |
| 515 | |
| 516 | case 2: |
| 517 | switch(AVR8_WGM1) |
| 518 | { |
| 519 | case Avr8::WGM1_NORMAL: |
| 520 | case Avr8::WGM1_CTC_OCR: |
| 521 | case Avr8::WGM1_CTC_ICR: |
| 522 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Clear OC1%c on compare match\n", avr8_reg_name[reg]); |
| 523 | break; |
| 524 | |
| 525 | case Avr8::WGM1_PWM_8_PC: |
| 526 | case Avr8::WGM1_PWM_9_PC: |
| 527 | case Avr8::WGM1_PWM_10_PC: |
| 528 | case Avr8::WGM1_PWM_PFC_ICR: |
| 529 | case Avr8::WGM1_PWM_PC_ICR: |
| 530 | case Avr8::WGM1_PWM_PFC_OCR: |
| 531 | case Avr8::WGM1_PWM_PC_OCR: |
| 532 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Clear OC1%c on match when up-counting, set OC1%c on match when down-counting\n", avr8_reg_name[reg]); |
| 533 | break; |
| 534 | |
| 535 | case Avr8::WGM1_FAST_PWM_8: |
| 536 | case Avr8::WGM1_FAST_PWM_9: |
| 537 | case Avr8::WGM1_FAST_PWM_10: |
| 538 | case Avr8::WGM1_FAST_PWM_ICR: |
| 539 | case Avr8::WGM1_FAST_PWM_OCR: |
| 540 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Clear OC1%c on compare match, set OC1%c at BOTTOM\n", avr8_reg_name[reg]); |
| 541 | break; |
| 542 | } |
| 543 | break; |
| 544 | |
| 545 | case 3: |
| 546 | switch(AVR8_WGM1) |
| 547 | { |
| 548 | case Avr8::WGM1_NORMAL: |
| 549 | case Avr8::WGM1_CTC_OCR: |
| 550 | case Avr8::WGM1_CTC_ICR: |
| 551 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Set OC1%c on compare match\n", avr8_reg_name[reg]); |
| 552 | break; |
| 553 | |
| 554 | case Avr8::WGM1_PWM_8_PC: |
| 555 | case Avr8::WGM1_PWM_9_PC: |
| 556 | case Avr8::WGM1_PWM_10_PC: |
| 557 | case Avr8::WGM1_PWM_PFC_ICR: |
| 558 | case Avr8::WGM1_PWM_PC_ICR: |
| 559 | case Avr8::WGM1_PWM_PFC_OCR: |
| 560 | case Avr8::WGM1_PWM_PC_OCR: |
| 561 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Set OC1%c on match when up-counting, clear OC1%c on match when down-counting\n", avr8_reg_name[reg]); |
| 562 | break; |
| 563 | |
| 564 | case Avr8::WGM1_FAST_PWM_8: |
| 565 | case Avr8::WGM1_FAST_PWM_9: |
| 566 | case Avr8::WGM1_FAST_PWM_10: |
| 567 | case Avr8::WGM1_FAST_PWM_ICR: |
| 568 | case Avr8::WGM1_FAST_PWM_OCR: |
| 569 | verboselog(machine, 0, "avr8_update_timer1_compare_mode: TODO; Set OC1%c on compare match, clear OC1%c at BOTTOM\n", avr8_reg_name[reg]); |
| 570 | break; |
| 571 | } |
| 572 | break; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | static void avr8_update_timer1_waveform_gen_mode(running_machine *machine) |
| 577 | { |
| 578 | // TODO |
| 579 | UINT16 top = 0; |
| 580 | craft_state *state = (craft_state *)machine->driver_data; |
| 581 | verboselog(machine, 0, "avr8_update_timer1_waveform_gen_mode: TODO; WGM1 is %d\n", AVR8_WGM1 ); |
| 582 | switch(AVR8_WGM1) |
| 583 | { |
| 584 | case Avr8::WGM1_NORMAL: |
| 585 | top = 0xffff; |
| 586 | break; |
| 587 | |
| 588 | case Avr8::WGM1_PWM_8_PC: |
| 589 | case Avr8::WGM1_FAST_PWM_8: |
| 590 | top = 0x00ff; |
| 591 | break; |
| 592 | |
| 593 | case Avr8::WGM1_PWM_9_PC: |
| 594 | case Avr8::WGM1_FAST_PWM_9: |
| 595 | top = 0x01ff; |
| 596 | break; |
| 597 | |
| 598 | case Avr8::WGM1_PWM_10_PC: |
| 599 | case Avr8::WGM1_FAST_PWM_10: |
| 600 | top = 0x03ff; |
| 601 | break; |
| 602 | |
| 603 | case Avr8::WGM1_PWM_PFC_ICR: |
| 604 | case Avr8::WGM1_PWM_PC_ICR: |
| 605 | case Avr8::WGM1_CTC_ICR: |
| 606 | case Avr8::WGM1_FAST_PWM_ICR: |
| 607 | top = AVR8_ICR1; |
| 608 | break; |
| 609 | |
| 610 | case Avr8::WGM1_PWM_PFC_OCR: |
| 611 | case Avr8::WGM1_PWM_PC_OCR: |
| 612 | case Avr8::WGM1_CTC_OCR: |
| 613 | case Avr8::WGM1_FAST_PWM_OCR: |
| 614 | top = AVR8_OCR1A; |
| 615 | break; |
| 616 | |
| 617 | default: |
| 618 | verboselog(machine, 0, "avr8_update_timer1_waveform_gen_mode: Unsupported waveform generation type: %d\n", AVR8_WGM1); |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | static void avr8_changed_tccr1a(running_machine *machine, UINT8 data) |
| 624 | { |
| 625 | craft_state *state = (craft_state *)machine->driver_data; |
| 626 | |
| 627 | UINT8 oldtccr = AVR8_TCCR1A; |
| 628 | UINT8 newtccr = data; |
| 629 | UINT8 changed = newtccr ^ oldtccr; |
| 630 | |
| 631 | if(changed & AVR8_TCCR1A_COM1A_MASK) |
| 632 | { |
| 633 | // TODO |
| 634 | avr8_update_timer1_compare_mode(machine, AVR8_REG_A); |
| 635 | } |
| 636 | |
| 637 | if(changed & AVR8_TCCR1A_COM1B_MASK) |
| 638 | { |
| 639 | // TODO |
| 640 | avr8_update_timer1_compare_mode(machine, AVR8_REG_B); |
| 641 | } |
| 642 | |
| 643 | if(changed & AVR8_TCCR1A_WGM1_10) |
| 644 | { |
| 645 | // TODO |
| 646 | avr8_update_timer1_waveform_gen_mode(machine); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | static void avr8_update_timer1_input_noise_canceler(running_machine *machine) |
| 651 | { |
| 652 | } |
| 653 | |
| 654 | static void avr8_update_timer1_input_edge_select(running_machine *machine) |
| 655 | { |
| 656 | // TODO |
| 657 | //craft_state *state = (craft_state *)machine->driver_data; |
| 658 | verboselog(machine, 0, "avr8_update_timer1_input_edge_select: TODO; Clocking edge is %s\n", "test"); |
| 659 | } |
| 660 | |
| 661 | static void avr8_update_timer1_clock_source(running_machine *machine) |
| 662 | { |
| 663 | } |
| 664 | |
| 665 | static void avr8_changed_tccr1b(running_machine *machine, UINT8 data) |
| 666 | { |
| 667 | craft_state *state = (craft_state *)machine->driver_data; |
| 668 | |
| 669 | UINT8 oldtccr = AVR8_TCCR1B; |
| 670 | UINT8 newtccr = data; |
| 671 | UINT8 changed = newtccr ^ oldtccr; |
| 672 | |
| 673 | if(changed & AVR8_TCCR1B_ICNC1_MASK) |
| 674 | { |
| 675 | // TODO |
| 676 | avr8_update_timer1_input_noise_canceler(machine); |
| 677 | } |
| 678 | |
| 679 | if(changed & AVR8_TCCR1B_ICES1_MASK) |
| 680 | { |
| 681 | // TODO |
| 682 | avr8_update_timer1_input_edge_select(machine); |
| 683 | } |
| 684 | |
| 685 | if(changed & AVR8_TCCR1B_WGM1_32_MASK) |
| 686 | { |
| 687 | // TODO |
| 688 | avr8_update_timer1_waveform_gen_mode(machine); |
| 689 | } |
| 690 | |
| 691 | if(changed & AVR8_TCCR1B_CS_MASK) |
| 692 | { |
| 693 | // TODO |
| 694 | avr8_update_timer1_clock_source(machine); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | static void avr8_update_ocr1(running_machine *machine, UINT16 newval, UINT8 reg) |
| 699 | { |
| 700 | craft_state *state = (craft_state *)machine->driver_data; |
| 701 | UINT8 *p_reg_h = (reg == AVR8_REG_A) ? &AVR8_OCR1AH : &AVR8_OCR1BH; |
| 702 | UINT8 *p_reg_l = (reg == AVR8_REG_A) ? &AVR8_OCR1AL : &AVR8_OCR1BL; |
| 703 | *p_reg_h = (UINT8)(newval >> 8); |
| 704 | *p_reg_l = (UINT8)newval; |
| 705 | // TODO |
| 706 | verboselog(machine, 0, "avr8_update_ocr1: TODO: new OCR1%c = %04x\n", avr8_reg_name[reg], newval); |
| 707 | } |
| 708 | |
| 226 | 709 | static WRITE8_HANDLER( avr8_write ) |
| 227 | 710 | { |
| 228 | 711 | craft_state *state = (craft_state *)space->machine->driver_data; |
| 229 | 712 | |
| 230 | | if(offset <= AVR8_REG_R31) |
| 713 | if(offset <= Avr8::REGIDX_R31) |
| 231 | 714 | { |
| 232 | 715 | state->regs[offset] = data; |
| 716 | return; |
| 233 | 717 | } |
| 234 | 718 | |
| 235 | 719 | switch( offset ) |
| 236 | 720 | { |
| 721 | case Avr8::REGIDX_OCR1BH: |
| 722 | avr8_update_ocr1(space->machine, (AVR8_OCR1B & 0x00ff) | (data << 8), AVR8_REG_B); |
| 723 | break; |
| 724 | |
| 725 | case Avr8::REGIDX_OCR1BL: |
| 726 | avr8_update_ocr1(space->machine, (AVR8_OCR1B & 0xff00) | data, AVR8_REG_B); |
| 727 | break; |
| 728 | |
| 729 | case Avr8::REGIDX_OCR1AH: |
| 730 | avr8_update_ocr1(space->machine, (AVR8_OCR1A & 0x00ff) | (data << 8), AVR8_REG_A); |
| 731 | break; |
| 732 | |
| 733 | case Avr8::REGIDX_OCR1AL: |
| 734 | avr8_update_ocr1(space->machine, (AVR8_OCR1A & 0xff00) | data, AVR8_REG_A); |
| 735 | break; |
| 736 | |
| 737 | case Avr8::REGIDX_TCCR1B: |
| 738 | avr8_changed_tccr1b(space->machine, data); |
| 739 | break; |
| 740 | |
| 741 | case Avr8::REGIDX_TCCR1A: |
| 742 | avr8_changed_tccr1a(space->machine, data); |
| 743 | break; |
| 744 | |
| 745 | case Avr8::REGIDX_TIMSK1: |
| 746 | avr8_change_timsk1(space->machine, data); |
| 747 | break; |
| 748 | |
| 749 | case Avr8::REGIDX_SPL: |
| 750 | case Avr8::REGIDX_SPH: |
| 751 | case Avr8::REGIDX_SREG: |
| 752 | state->regs[offset] = data; |
| 753 | break; |
| 754 | |
| 755 | case Avr8::REGIDX_SPSR: |
| 756 | avr8_change_spsr(space->machine, data); |
| 757 | break; |
| 758 | |
| 759 | case Avr8::REGIDX_SPCR: |
| 760 | avr8_change_spcr(space->machine, data); |
| 761 | break; |
| 762 | |
| 763 | case Avr8::REGIDX_DDRD: |
| 764 | avr8_change_ddr(space->machine, AVR8_REG_D, data); |
| 765 | break; |
| 766 | |
| 767 | case Avr8::REGIDX_DDRC: |
| 768 | avr8_change_ddr(space->machine, AVR8_REG_C, data); |
| 769 | break; |
| 770 | |
| 771 | case Avr8::REGIDX_PORTB: |
| 772 | avr8_change_port(space->machine, AVR8_REG_B, data); |
| 773 | break; |
| 774 | |
| 775 | case Avr8::REGIDX_DDRB: |
| 776 | avr8_change_ddr(space->machine, AVR8_REG_B, data); |
| 777 | break; |
| 778 | |
| 237 | 779 | default: |
| 238 | 780 | verboselog(space->machine, 0, "AVR8: Unrecognized register write: %02x = %02x\n", offset, data ); |
| 239 | 781 | } |