2021-01-02 19:54:17 +01:00
|
|
|
; VIDEO COMPOSITE PAL IO DEVICE
|
|
|
|
; Implemented following timings in http://blog.retroleum.co.uk/electronics-articles/pal-tv-timing-and-voltages/
|
2021-01-08 17:32:08 +01:00
|
|
|
; Every line, for 52 times, it loads a byte from memory into PORTA register and then shifts the byte to the left to show another bit (do it 7 times)
|
|
|
|
; This also displays byte's MSB pixel "for free", as the video pin is PD7 (last bit of PORTA).
|
2021-01-08 16:12:46 +01:00
|
|
|
;
|
2021-01-10 07:22:55 +01:00
|
|
|
; INTERFACING WITH PAT80:
|
|
|
|
; Use PortB as data port. Before writing anything, issue a read (pin RW HIGH) and check the busy pin on the data port.
|
2021-01-10 10:50:34 +01:00
|
|
|
; If the busy pin is high, retry reading until goes low. When the busy pin goes low, we have... TODO
|
2021-01-10 07:22:55 +01:00
|
|
|
;
|
|
|
|
; ELECTRONICALLY:
|
|
|
|
; The data port D0 (= PB0) is tied to ground with a 1KOhm resistance. When the MC is busy drawing the screen, the data port is in
|
|
|
|
; high impedance state, so that avoids causing bus contention, but when read returns a 0bXXXXXXX0 byte. When the MC starts vsync,
|
|
|
|
; begins checking the port for data... TODO
|
|
|
|
;
|
2021-01-08 16:12:46 +01:00
|
|
|
; PINS:
|
2021-01-08 17:32:08 +01:00
|
|
|
; Video pin: PA0 (pin 1)
|
2021-01-08 16:12:46 +01:00
|
|
|
; Sync pin: PC0 (pin 22)
|
|
|
|
; Debug hsync pin: PC1 (pin 23)
|
2021-01-09 21:24:27 +01:00
|
|
|
;
|
2021-01-02 19:54:17 +01:00
|
|
|
|
2021-01-19 08:36:01 +01:00
|
|
|
.include "m1284def.inc" ; Atmega 1280 device definition
|
2021-01-02 16:33:51 +01:00
|
|
|
|
2021-01-19 08:36:01 +01:00
|
|
|
; reserved registers
|
2021-01-17 10:58:04 +01:00
|
|
|
.def A = r0 ; accumulator
|
|
|
|
.def STATUS = r25 ; signal status (see STATUS TABLE)
|
2021-01-22 08:58:11 +01:00
|
|
|
.def POS_COARSE = Z ; coarse position (aligned to character column)
|
|
|
|
.def POS_COARSE_H = r31
|
|
|
|
.def POS_COARSE_L = r30
|
|
|
|
.def POS_FINE = r24 ; fine position (bit inside coarse-position-pointed byte)
|
2021-01-02 16:33:51 +01:00
|
|
|
; define constant
|
2021-01-10 10:50:34 +01:00
|
|
|
.equ SYNC_PIN = PC0 ; Sync pin (pin 22)
|
|
|
|
.equ DEBUG_PIN = PC1 ; DEBUG: Single vertical sync pulse to trigger oscilloscope (pin 23)
|
2021-01-19 20:55:11 +01:00
|
|
|
.equ CLK_PIN = PD7
|
2021-01-06 00:19:15 +01:00
|
|
|
|
|
|
|
; memory
|
|
|
|
.equ FRAMEBUFFER = 0x100
|
2021-01-02 16:33:51 +01:00
|
|
|
|
|
|
|
; start vector
|
|
|
|
.org 0x0000
|
2021-01-16 19:54:32 +01:00
|
|
|
rjmp main ; reset vector: jump to main label
|
|
|
|
.org 0x001E
|
2021-01-19 08:36:01 +01:00
|
|
|
rjmp on_tim1_ovf ; interrupt for timer 1 overflow (used by video generation)
|
2021-01-02 16:33:51 +01:00
|
|
|
|
2021-01-16 19:54:32 +01:00
|
|
|
.org 0x40
|
2021-01-02 16:33:51 +01:00
|
|
|
; main program
|
|
|
|
main:
|
2021-01-10 10:50:34 +01:00
|
|
|
; pins setup
|
2021-01-06 00:19:15 +01:00
|
|
|
sbi DDRC, SYNC_PIN ; set pin as output
|
|
|
|
sbi DDRC, DEBUG_PIN ; set pin as output
|
2021-01-19 20:55:11 +01:00
|
|
|
cbi DDRD, CLK_PIN ; set pin as input
|
2021-01-06 00:19:15 +01:00
|
|
|
ldi r16, 0xFF
|
2021-01-08 17:32:08 +01:00
|
|
|
out DDRA, r16 ; set port as output (contains video pin)
|
2021-01-19 20:55:11 +01:00
|
|
|
ldi r16, 0x00
|
|
|
|
out DDRB, r16 ; set port as input (used as data bus)
|
|
|
|
|
|
|
|
|
2021-01-07 13:32:01 +01:00
|
|
|
|
2021-01-16 19:54:32 +01:00
|
|
|
; *** timer setup (use 16-bit counter TC1) ***
|
2021-01-10 10:50:34 +01:00
|
|
|
; The Power Reduction TC1 and TC3 bits in the Power Reduction Registers (PRR0.PRTIM1 and
|
|
|
|
; PRR1.PRTIM3) must be written to zero to enable the TC1 and TC3 module.
|
2021-01-16 19:54:32 +01:00
|
|
|
ldi r16, 0b00000000
|
2021-01-10 10:50:34 +01:00
|
|
|
sts PRR0, r16
|
2021-01-16 19:54:32 +01:00
|
|
|
; Set timer prescaler to 1:1
|
|
|
|
LDI r16,0b00000001
|
|
|
|
sts TCCR1B,r16
|
|
|
|
; Enambe timer1 overflow interrupt
|
|
|
|
LDI r16,0b00000001
|
|
|
|
STS TIMSK1,r16
|
|
|
|
; Enable interrupts globally
|
|
|
|
SEI
|
|
|
|
; Timer setup completed.
|
2021-01-10 10:50:34 +01:00
|
|
|
|
2021-01-19 20:55:11 +01:00
|
|
|
; Wait for data (it never exits)
|
|
|
|
jmp comm_init
|
|
|
|
|
2021-01-09 21:24:27 +01:00
|
|
|
forever:
|
|
|
|
jmp forever
|
2021-01-19 20:55:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.include "video_generator.asm" ; Asyncronous timer-interrupt-based video generation
|
|
|
|
.include "character_generator.asm" ; Character generator
|
|
|
|
.include "communication.asm" ; Communication with Pat80
|