├── 32x-autohz.asm ├── 32x-autohz_12f629.hex ├── 32x-autohz_12f675.hex └── README.md /32x-autohz.asm: -------------------------------------------------------------------------------- 1 | ; --------------------------------------------------------------------- 2 | ; 32X 50/60Hz automatic slave switch 3 | ; 4 | ; Copyright (C) 2012-2021 by Maximilian Rehkopf (ikari_01) 5 | ; Idea by n00b 6 | ; 7 | ; This program is designed to run on a PIC12F629 or compatible micro 8 | ; controller. It determines the frequency of the VSync signal on pin 5 9 | ; and switches the output level of pin 6 accordingly (50Hz = 0V; 60Hz = 5V). 10 | ; 11 | ; This program is released to the public domain; it is the wish of the 12 | ; author that the original attributions stated above remain unchanged. 13 | ; 14 | ; --------------------------------------------------------------------- 15 | ; 16 | ; pin configuration: (cartridge pin) [key CIC pin] 17 | ; 18 | ; ,---_---. 19 | ; +5V |1 8| GND 20 | ; nc |2 7| nc 21 | ; nc |3 6| 50/60Hz switch out 22 | ; nc |4 5| Vsync in (TTL) 23 | ; `-------' 24 | ; Vsync can be taken from cartridge slot pin B13 or CN4 pin 15. 25 | ; No sync separator required. 26 | 27 | ; ----------------------------------------------------------------------- 28 | ; processor support. gputils's ELIFDEF is broken so using nested IFDEFs. 29 | IFDEF __12F629 30 | INCLUDE p12f629.inc 31 | ELSE 32 | IFDEF __12F675 33 | INCLUDE p12f675.inc 34 | ELSE 35 | ERROR "No supported processor selected (p12f629, p12f675)!" 36 | ENDIF 37 | ENDIF 38 | ; ----------------------------------------------------------------------- 39 | 40 | ; ----------------------------------------------------------------------- 41 | __CONFIG _INTRC_OSC_CLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _CPD_OFF 42 | 43 | ; ----------------------------------------------------------------------- 44 | ; code memory 45 | org h'0000' 46 | goto init 47 | isr 48 | org h'0004' ; ISR always located at 0x0004 49 | btfss INTCON, INTF ; only react on external interrupts 50 | goto skip 51 | bcf INTCON, INTF ; clear interrupt cause 52 | movf TMR0, w 53 | sublw h'47' ; timer threshold (71 steps ~= 55Hz) 54 | btfss STATUS, C ; if borrow: TMR0 was larger -> 50Hz 55 | goto set50 56 | bsf GPIO, 1 ; ELSE set output to HIGH = 60Hz 57 | goto cont 58 | set50 59 | bcf GPIO, 1 ; -> set output to LOW = 50Hz 60 | goto cont 61 | cont 62 | clrf TMR0 ; clear timer counter 63 | bcf INTCON, T0IF 64 | skip 65 | retfie 66 | 67 | init 68 | banksel OSCCAL ; set OSCCAL from dedicated location 69 | call h'3ff' 70 | movwf OSCCAL 71 | IFDEF __12F675 72 | clrf ANSEL ; for 12F675: disable analog function 73 | ENDIF 74 | banksel GPIO 75 | clrf GPIO ; set all pins low 76 | movlw b'00000111' ; GPIO2..0 are digital I/O (not connected to comparator) 77 | movwf CMCON 78 | banksel TRISIO 79 | movlw b'00111101' ; GP5=in GP4=in GP3=in GP2=in GP1=out GP0=in 80 | movwf TRISIO 81 | movlw b'10000111' ; no pullups; int on falling edge; TMR0 src=CLK; 82 | ; TMR0 edge=rising, Prescaler=>TIMER0, PS rate=1:256 83 | movwf OPTION_REG 84 | banksel GPIO 85 | clrf TMR0 ; reset timer 86 | movlw b'10010000' ; global interrupt enable + external interrupt enable 87 | movwf INTCON 88 | idle 89 | goto idle ; wait loop; ISR takes care of the rest 90 | 91 | end 92 | -------------------------------------------------------------------------------- /32x-autohz_12f629.hex: -------------------------------------------------------------------------------- 1 | :020000040000FA 2 | :020000001228C4 3 | :080008008B1C11288B1001086C 4 | :10001000473C031C0D2885140F2885100F288101EB 5 | :100020000B1109008316FF2390008312850107300E 6 | :10003000990083163D30850087308100831281014D 7 | :0600400090308B00222825 8 | :02400E00953FDC 9 | :00000001FF 10 | -------------------------------------------------------------------------------- /32x-autohz_12f675.hex: -------------------------------------------------------------------------------- 1 | :020000040000FA 2 | :020000001228C4 3 | :080008008B1C11288B1001086C 4 | :10001000473C031C0D2885140F2885100F288101EB 5 | :100020000B1109008316FF2390009F0183128501A5 6 | :100030000730990083163D30850087308100831298 7 | :08004000810190308B002328A0 8 | :02400E00953FDC 9 | :00000001FF 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 32x-autohz 2 | ========== 3 | 4 | 32X 50/60Hz automatic slave switch 5 | 6 | Copyright (C) 2012 by Maximilian Rehkopf (ikari_01) 7 | Idea by n00b 8 | 9 | This program is designed to run on a PIC12F629 or compatible micro 10 | controller. It determines the frequency of the VSync signal on pin 5 11 | and switches the output level of pin 6 accordingly (50Hz = 0V; 60Hz = 5V). 12 | 13 | This program is released to the public domain; it is the wish of the 14 | author that the original attributions stated above remain unchanged. 15 | 16 | --------------------------------------------------------------------- 17 | 18 | pin configuration: 19 | 20 | ,---_---. 21 | +5V |1 8| GND 22 | nc |2 7| nc 23 | nc |3 6| 50/60Hz switch out 24 | nc |4 5| Vsync in (TTL) 25 | `-------' 26 | 27 | Vsync can be taken from cartridge slot pin B13 or CN4 pin 15. 28 | No sync separator required. 29 | --------------------------------------------------------------------------------