pato-z80-home-computer/pat80-io-devices/composite-pal-adapter/software/avr-assembly/main.asm
2021-01-02 19:54:17 +01:00

82 lines
2.2 KiB
NASM

; VIDEO COMPOSITE PAL IO DEVICE
; Implemented following timings in http://blog.retroleum.co.uk/electronics-articles/pal-tv-timing-and-voltages/
.include "atmega1284definition.asm"
; define constant
.equ SYNC_PIN = PD7 ; Sync pin is on Port D 7 (pin 21)
.equ VIDEO_PIN = PD6 ; Video pin is on Port D 6 (pin 20)
; start vector
.org 0x0000
rjmp main ; jump to main label
; main program
main:
sbi DDRD, SYNC_PIN ; set pin as output
sbi DDRD, VIDEO_PIN ; set pin as output
v_refresh_loop:
; start 5 long sync pulses
; end 5 long sync pulses
; start 5 short sync pulses
; end 5 short sync pulses
; start 304 picture lines
ldi r16, 2
h_picture_outer_loop:
ldi r17, 152 ; line counter
h_picture_loop:
; start line sync: 4uS, 96 cycles @ 24Mhz
cbi PORTD, SYNC_PIN ; sync goes low (0v) ; 2 cycle
ldi r18, 32 ; 1 cycle
l_sync_pulse_loop: ; requires 3 cpu cycles
dec r18 ; 1 cycle
brne l_sync_pulse_loop ; 2 cycle if true, 1 if false
sbi PORTD, SYNC_PIN ; sync goes high (0.3v)
; end line sync
; start back porch: 8uS, 192 cycles @ 24Mhz
ldi r18, 64 ; 1 cycle
l_sync_back_porch_loop:
dec r18 ; 1 cycle
brne l_sync_back_porch_loop ; 2 cycle if true, 1 if false
; end back porch
; start image: 52uS, 1247 cycles @ 24Mhz
; 3 bande da 416 cicli
sbi PORTD, VIDEO_PIN ; video goes high ; 2 cycle
ldi r18, 138 ; 1 cycle
l_sync_video_loop1:
dec r18 ; 1 cycle
brne l_sync_video_loop1 ; 2 cycle if true, 1 if false
cbi PORTD, VIDEO_PIN ; video goes low
ldi r18, 137 ; 1 cycle
l_sync_video_loop2:
dec r18 ; 1 cycle
brne l_sync_video_loop2 ; 2 cycle if true, 1 if false
sbi PORTD, VIDEO_PIN ; video goes high
ldi r18, 138 ; 1 cycle
l_sync_video_loop3:
dec r18 ; 1 cycle
brne l_sync_video_loop3 ; 2 cycle if true, 1 if false
cbi PORTD, VIDEO_PIN ; video goes low
; end image
dec r17 ; decrement line counter
brne h_picture_loop ; if not 0, repeat h_picture_loop
dec r16 ; decrement outside counter
brne h_picture_outer_loop ; if not 0, repeat h_picture_loop
; end picture lines