; ****************************************************************************************
; **** LUCIDSCIENCE.COM - VGA DUAL BUFFER FRAMEWORK (C) 2010 BY RADBRAD
; ****************************************************************************************

; COMPILER SETTINGS
.INCLUDE "M644pDEF.INC"

; INTERRUPT VECTORS
.org 0
rjmp RESET
.org oc1aaddr
rjmp VIDEO ;2
RESET:

 

; ****************************************************************************************
; **** IO PORT A SETUP
; ****************************************************************************************

sbi ddra,0 ; ADDRESS BIT 00
sbi ddra,1 ; ADDRESS BIT 01
sbi ddra,2 ; ADDRESS BIT 02
sbi ddra,3 ; ADDRESS BIT 03
sbi ddra,4 ; ADDRESS BIT 04
sbi ddra,5 ; ADDRESS BIT 05
sbi ddra,6 ; ADDRESS BIT 06
sbi ddra,7 ; ADDRESS BIT 07

 

; ****************************************************************************************
; **** IO PORT C SETUP
; ****************************************************************************************

sbi ddrc,0 ; ADDRESS BIT 08
sbi ddrc,1 ; ADDRESS BIT 09
sbi ddrc,2 ; ADDRESS BIT 12
sbi ddrc,3 ; ADDRESS BIT 11
sbi ddrc,4 ; ADDRESS BIT 12
sbi ddrc,5 ; ADDRESS BIT 13
sbi ddrc,6 ; ADDRESS BIT 14
sbi ddrc,7 ; ADDRESS BIT 15

 

; ****************************************************************************************
; **** IO PORT D SETUP
; ****************************************************************************************

sbi ddrd,0 ; RED BIT 0
sbi ddrd,1 ; RED BIT 1
sbi ddrd,2 ; GRN BIT 0
sbi ddrd,3 ; GRN BIT 1
sbi ddrd,4 ; BLU BIT 0
sbi ddrd,5 ; BLU BIT 1
sbi ddrd,6 ; INT BIT 0
sbi ddrd,7 ; INT BIT 1

 

; ****************************************************************************************
; **** IO PORT B SETUP
; ****************************************************************************************

sbi ddrb,0 ; HORIZONTAL SYNC PULSE
sbi ddrb,1 ; VERTICAL SYNC PULSE
sbi ddrb,2 ; VIDEO DAC ENABLE
sbi ddrb,3 ; SRAM WRITE ENABLE
sbi ddrb,4 ; SRAM OUTPUT ENABLE
sbi ddrb,5 ; SRAM PAGE CONTROL
sbi ddrb,6 ; JOYSTICK READ ENABLE
cbi ddrb,7 ; SOUND OUTPUT PIN


; ****************************************************************************************
; **** DEFINE MAIN LOOP REGISTERS
; ****************************************************************************************

.def sn = r2 ; SOUND FREQUENCY
.def sx = r16 ; SCREEN LOCATION X
.def sy = r17 ; SCREEN LOCATION Y
.def px = r18 ; SCREEN PIXEL COLOR
.def t1 = r19 ; TEMP REGISTER 1
.def t2 = r20 ; TEMP REGISTER 2
.def t3 = r21 ; TEMP REGISTER 3
.def t4 = r22 ; TEMP REGISTER 4
.def t5 = r23 ; TEMP REGISTER 5
.def t6 = r24 ; TEMP REGISTER 6
.def mr = r25 ; MEMREADY FLAG (READ ONLY)

; CLEAR ALL REGISTERS
clr r0
clr r1
clr sn
clr sx
clr sy
clr px
clr t1
clr t2
clr t3
clr t4
clr t5
clr t6
clr xl
clr xh
clr yl
clr yh
clr zl
clr zh

 

; ****************************************************************************************
; **** STARTUP SEQUENCE
; ****************************************************************************************

; STACK POINTER
ldi r24,low(ramend)
out spl,r24
ldi r24,high(ramend)
out sph,r24

; SET TIMER1 TO SCLK WITH RESET
ldi r24,(1<<CS10 | 1<<WGM12)
sts tccr1b,r24

; SET TIMER1 MATCH INTERRUPT
ldi r24,(1<<OCIE1A)
sts timsk1,r24

; SET TIMER1 INTERRUPT TIME
ldi r24,high(636)
sts ocr1ah,r24
ldi r24,low(636)
sts ocr1al,r24

; SET SRAM TO IDLE
sbi portb,3
sbi portb,4

; CLEAR VIDEO VARIABLES
clr r24
sts 256,r24
sts 257,r24
sts 258,r24

; CLEAR VIDEO PAGE 0
cbi portb,5
ldi px,0
call CLEARSCREEN

; CLEAR VIDEO PAGE 1
sbi portb,5
ldi px,0
call CLEARSCREEN

; TURN ON GLOBAL INTERRUPTS
sei

 

; ****************************************************************************************
; **** MAIN PROGRAM LOOP
; ****************************************************************************************

main:

; CLEAR VIDEO PAGE
ldi px,0
call CLEARSCREEN

; YOUR CODE GOES HERE

; FLIP PAGES ON VERTICAL SYNC
call PAGEFLIP

; END OF MAIN LOOP
rjmp main

 

; ****************************************************************************************
; **** FLIP VIDEO PAGES
; ****************************************************************************************

PAGEFLIP:

; STACK OPERATION
push t1

; WAIT FOR VSYNC
PFVS:
sbic portb,1
rjmp PFVS

; SWAP BUFFERS
in t1,portb
sbrc t1,5
cbi portb,5
sbrs t1,5
sbi portb,5

; STACK OPERATION
pop t1
ret

 

; ****************************************************************************************
; **** READ SCREEN PIXEL / SX=XLOC / SY=YLOC / RETURNS PX=COLOR
; ****************************************************************************************

READPIXEL:

; STACK OPERATION
push t1

; WAIT FOR MEMREADY
RPMR:
sbrc mr,0
rjmp RPMR

; SET SCREEN ADDRESS
out porta,sx
out portc,sy

; SET DATA PORT INPUT
clr t1
out ddrd,t1

; SRAM OUTPUT ENABLE
cbi portb,4

; TURNAROUND DELAY
nop

; READ DATA BYTE
in px,pind

; SRAM OUTPUT DISABLE
sbi portb,4

; SET DATA PORT OUTPUT
ser t1
out ddrd,t1

; STACK OPERATION
pop t1
ret

 

; ****************************************************************************************
; **** COPY SPRITE TO SCREEN / SX=XLOC / SY=YLOC
; ****************************************************************************************

DRAWSPRITE:

; STACK OPERATION
push xh
push xl
push yh
push yl
push zh
push zl
push t1

; READ SPRITE SIZE DATA
lpm xl,z+
lpm xh,z+

; SET SCREEN LOCATION
add xl,sx
add xh,sy
mov yh,sy

; COUNT Y BYTES
DSYL:
mov yl,sx

; WAIT FOR MEMREADY
DSMR:
sbrc mr,0
rjmp DSMR

; COUNT X BYTES
DSXL:
lpm t1,z+
cpi t1,0

; SKIP BLANK PIXELS
breq DSBL

; SEND SPRITE DATA
out portd,t1
out porta,yl
out portc,yh
cbi portb,3
sbi portb,3

; COMPLETE LOOP
DSBL:
inc yl
cp yl,xl
brne DSXL
inc yh
cp yh,xh
brne DSYL

; STACK OPERATION
pop t1
pop zl
pop zh
pop yl
pop yh
pop xl
pop xh
ret

 

; ****************************************************************************************
; **** COPY IMAGE TO SCREEN / SX=XLOC / SY=YLOC
; ****************************************************************************************

DRAWIMAGE:

; STACK OPERATION
push t1
push xl
push xh
push yl
push yh
push zl
push zh

; READ SPRITE SIZE DATA
lpm xl,z+
lpm xh,z+

; SET SCREEN LOCATION
add xl,sx
add xh,sy
mov yh,sy

; COUNT Y BYTES
DIYL:
mov yl,sx

; WAIT FOR MEMREADY
DIMR:
sbrc mr,0
rjmp DIMR

; COUNT X BYTES
DIXL:
lpm t1,z+

; SEND SPRITE DATA
out portd,t1
out porta,yl
out portc,yh
cbi portb,3
sbi portb,3

; COMPLETE LOOP
DIBL:
inc yl
cp yl,xl
brne DIXL
inc yh
cp yh,xh
brne DIYL

; STACK OPERATION
pop zh
pop zl
pop yh
pop yl
pop xh
pop xl
pop t1
ret

 

; ****************************************************************************************
; **** CLEAR ENTIRE VIDEO SCREEN / PX=COLOR
; ****************************************************************************************

CLEARSCREEN:

; STACK OPERATION
push xh
push xl

; RESET SCREEN ADDRESS
clr xh
clr xl

; WAIT FOR MEMREADY
CLEAR:
CSMR:
sbrc mr,0
rjmp CSMR

; SEND SCREEN DATA
out portd,px
out portc,xh
cbi portb,3
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
out porta,xl
inc xl
sbi portb,3

; COMPLETE LOOP
cpi xl,240
brne clear
inc xh
cpi xh,240
brne clear

; STACK OPERATION
pop xl
pop xh
ret

 

; **********************************************************************************************
; **** PRINT TEXT CHARACTER / T1=CHARACTER / SX=XLOC / SY=YLOC / PX=FORECOLOR / T2=BACKCOLOR
; **********************************************************************************************

PRINTCHAR:

; STACK OPERATION
push t3
push t4
push zl
push zh
push yl
push yh

; SET POINTER TO CHARACTER DATA
ldi zl,low(2*chars)
ldi zh,high(2*chars)
ldi t3,8
mul t1,t3
add zl,r0
adc zh,r1

; WAIT FOR MEMREADY
PCMR:
sbrc mr,0
rjmp PCMR

; LOOP
mov yh,sy
ldi t4,8
PRLY:

; READ CHARACTER BYTE
lpm t1,z+

; SET SCREEN ADDRESS
mov yl,sx
out portc,yh
ldi t3,8
PRLX:
out porta,yl

; SHIFT OUT CHARACTER BITS
out portd,px
sbrc t1,0
rjmp DOSHIFT

; SKIP PIXELS IF FCOLOR = BCOLOR
cp t2,px
breq NOSHIFT
sbrs t1,0
out portd,t2

DOSHIFT:
cbi portb,3
sbi portb,3
NOSHIFT:

; COMPLETE SHIFT LOOP
lsr t1
inc yl
dec t3
brne PRLX
inc yh
dec t4
brne PRLY

; STACK OPERATION
pop yh
pop yl
pop zh
pop zl
pop t4
pop t3
ret

 

; ****************************************************************************************
; **** VIDEO RENDERING INTERRUPT / R2=SOUND FREQUENCY / RETURNS R25=MEMREADY
; ****************************************************************************************

VIDEO:

; HORIZONTAL CLOCK TIMING
;HFP:12 (0-11)
;HSP:76 (12-87)
;HBP:36 (88-123)
;HPX:512 (124-635)
;TOT:636

; VERTICAL LINE TIMING
;VLN:480 (0-479)
;VFP:11 (480-490)
;VSP:2 (491-492)
;VBP:32 (493-524)
;TOT:525 LINES

; ****************************************************************************************
; **** HORIZONTAL AND VERTICAL SYNC = 76 CYCLES
; ****************************************************************************************

; SAVE STATUS REGISTER
push r24 ;2
in r24,sreg ;1
push r24 ;2

; EQUALIZE INTERRUPT LATENCY
lds r24,tcnt1l ;2
cpi r24,10 ;1
brlo LATFIX1 ;1/2
LATFIX1:
cpi r24,11 ;1
brlo LATFIX2 ;1/2
LATFIX2:
cpi r24,12 ;1
brlo LATFIX3 ;1/2
LATFIX3:
cpi r24,13 ;1
brlo LATFIX4 ;1/2
LATFIX4:

; HORIZONTAL SYNC LOW
cbi portb,0 ;2

; PUSH REGISTERS TO STACK
push r0 ;2
push r1 ;2
push r17 ;2
push r18 ;2
push yl ;2
push yh ;2
push zl ;2
push zh ;2

; SET POINTER TO VLINE TABLE
ldi zl,low(2*VLINE) ;1
ldi zh,high(2*VLINE) ;1

; LOAD VLINE COUNTER
lds yl,256 ;2
lds yh,257 ;2
lds r17,258 ;2

; SET VLINE TABLE POSITION
add zl,yl ;1
adc zh,yh ;1

; READ VLINE TABLE BYTE
lpm r24,z ;3

; INCREMENT VERTICAL ADDRESS
sbrs r24,3 ;1/2
inc r17 ;1

; RESET VERTICAL ADDRESS
sbrc r24,0 ;1/2
ser r17 ;1

; INCREMENT VLINE COUNTER
adiw yh:yl,1 ;1

; RESET VLINE COUNTER
sbrc r24,0 ;1/2
clr yl ;1
sbrc r24,0 ;1/2
clr yh ;1

; SAVE VLINE COUNTER
sts 256,yl ;2
sts 257,yh ;2
sts 258,r17 ;2

; VERTICAL SYNC CONTROL
sbrc r24,1 ;1/2
cbi portb,1 ;2
sbrs r24,1 ;1/2
sbi portb,1 ;2

; SET MEMREADY FLAG (R25)
sbrc r24,4 ;1/2
clr r25 ;1
sbrs r24,4 ;1/2
ser r25 ;1

; HORIZONTAL SYNC HIGH
sbi portb,0 ;2

 

; ****************************************************************************************
; **** HORIZONTAL BACK PORCH = 36 CYCLES
; ****************************************************************************************

; SET VERTICAL ADDRESS
sbrc r24,2 ;1/2
out portc,r17 ;1

; LOAD SOUND COUNTER
push r3 ;2
lds r3,259 ;2

; SEND SOUND DATA
dec r3 ;1
cp r2,r3 ;1
brne ns ;1/2
clr r3 ;1
ns:
brne n1 ;1/2
sbi portb,7 ;2
n1:
breq n2 ;1/2
cbi portb,7 ;2
n2:

; SAVE SOUND COUNTER
sts 259,r3 ;2
pop r3 ;2

; POP REGISTERS FROM STACK
pop zh ;2
pop zl ;2
pop yh ;2
pop yl ;2
pop r18 ;2
pop r17 ;2
pop r1 ;2
pop r0 ;2

; CONTROL ACTIVE LINES
sbrs r24,2 ;1/2
rjmp NOVID ;2

; SET SRAM TO IDLE
sbi portb,3 ;2
sbi portb,4 ;2

; RELEASE DATA BUS
clr r24 ;1
out ddrd,r24 ;1

; SET SRAM TO READ
cbi portb,4 ;2

 

; ****************************************************************************************
; **** HORIZONTAL ACTIVE LINE = 512 CYCLES - 32 / 2 = 240 PIXELS
; ****************************************************************************************

; SET TO FRONT BUFFER
in r24,portb ;1
sbrc r24,5 ;1/2
cbi portb,5 ;2
sbrs r24,5 ;1/2
sbi portb,5 ;2

; RESET HORIZONTAL ADDRESS
clr r24 ;1
out porta,r24 ;1

; TURN ON VIDEO DAC
cbi portb,2 ;2

inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1
inc r24 ;1
out porta,r24 ;1

; TURN OFF VIDEO DAC
sbi portb,2 ;2

; SET TO BACK BUFFER
in r24,portb ;1
sbrc r24,5 ;1/2
cbi portb,5 ;2
sbrs r24,5 ;1/2
sbi portb,5 ;2

; SET SRAM TO IDLE
sbi portb,4 ;2

; ENABLE DATA BUS
ser r24 ;1
out ddrd,r24 ;1

 

; ****************************************************************************************
; **** HORIZONTAL FRONT PORCH = 12 CYCLES
; ****************************************************************************************

; BLANKING LINES EXIT POINT
NOVID:

; RESTORE STATUS REGISTER
pop r24 ;2
out sreg,r24 ;1
pop r24 ;2

; RETURN FROM INTERRUPT
reti ;4

 

; ****************************************************************************************
; **** VERTICAL LINE LOOKUP TABLE
; ****************************************************************************************

VLINE:
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12,4,12
.db 16,16,16,16,16,16,16,16,16,16,16,18,18,16,16,16,16,16,16,16,16,16,16,16
.db 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,0,1,0

 

; **********************************************************************************************
; **** ALPHANUMERIC CHARACTER SET
; **********************************************************************************************
CHARS:
.db 0,0,0,0,0,0,0,0 ; 00 SPACE
.db 28,54,99,99,127,99,99,0 ; 01 A
.db 63,102,102,62,102,102,63,0 ; 02 B
.db 60,102,3,3,3,102,60,0 ; 03 C
.db 31,54,102,102,102,54,31,0 ; 04 D
.db 127,67,3,31,3,67,127,0 ; 05 E
.db 127,70,6,62,6,6,15,0 ; 06 F
.db 62,99,3,3,123,99,62,0 ; 07 G
.db 99,99,99,127,99,99,99,0 ; 08 H
.db 60,24,24,24,24,24,60,0 ; 09 I
.db 60,24,24,24,27,27,14,0 ; 10 J
.db 99,51,27,15,27,51,99,0 ; 11 K
.db 15,6,6,6,6,70,127,0 ; 12 L
.db 99,119,127,107,107,99,99,0 ; 13 M
.db 99,103,103,111,123,115,99,0 ; 14 N
.db 62,99,99,99,99,99,62,0 ; 15 O
.db 63,102,102,62,6,6,15,0 ; 16 P
.db 62,99,99,99,99,107,62,96 ; 17 Q
.db 63,99,99,63,27,51,99,0 ; 18 R
.db 62,99,3,62,96,99,62,0 ; 19 S
.db 126,90,24,24,24,24,60,0 ; 20 T
.db 99,99,99,99,99,99,62,0 ; 21 U
.db 99,99,99,99,54,28,8,0 ; 22 V
.db 99,99,107,107,127,119,99,0 ; 23 W
.db 99,54,28,28,28,54,99,0 ; 24 X
.db 102,102,102,60,24,24,60,0 ; 25 Y
.db 127,97,48,24,12,70,127,0 ; 26 Z
.db 0,0,30,48,62,51,126,0 ; 27 a
.db 7,6,62,102,102,102,63,0 ; 28 b
.db 0,0,62,99,3,99,62,0 ; 29 c
.db 56,48,62,51,51,51,126,0 ; 30 d
.db 0,0,62,99,127,3,62,0 ; 31 e
.db 56,108,12,63,12,12,30,0 ; 32 f
.db 0,0,110,115,99,126,96,62 ; 33 g
.db 7,6,62,102,102,102,103,0 ; 34 h
.db 24,0,28,24,24,24,60,0 ; 35 i
.db 48,0,56,48,48,48,51,30 ; 36 j
.db 7,6,102,54,30,54,103,0 ; 37 k
.db 24,24,24,24,24,24,56,0 ; 38 l
.db 0,0,54,127,107,107,99,0 ; 39 m
.db 0,0,59,102,102,102,102,0 ; 40 n
.db 0,0,62,99,99,99,62,0 ; 41 o
.db 0,0,59,102,102,62,6,15 ; 42 p
.db 0,0,110,51,51,62,48,120 ; 43 q
.db 0,0,59,102,6,6,15,0 ; 44 r
.db 0,0,62,3,62,96,62,0 ; 45 s
.db 12,12,63,12,12,108,56,0 ; 46 t
.db 0,0,51,51,51,51,110,0 ; 47 u
.db 0,0,99,99,54,28,8,0 ; 48 v
.db 0,0,99,99,107,127,54,0 ; 49 w
.db 0,0,99,54,28,54,99,0 ; 50 x
.db 0,0,99,99,115,110,96,62 ; 51 y
.db 0,0,63,25,12,38,63,0 ; 52 z
.db 62,99,115,123,111,103,62,0 ; 53 0
.db 24,30,24,24,24,24,126,0 ; 54 1
.db 62,99,48,24,12,102,127,0 ; 55 2
.db 62,99,96,60,96,99,62,0 ; 56 3
.db 48,56,60,54,127,48,48,0 ; 57 4
.db 127,3,63,96,96,99,62,0 ; 58 5
.db 62,99,3,63,99,99,62,0 ; 59 6
.db 127,99,96,48,24,24,24,0 ; 60 7
.db 62,99,99,62,99,99,62,0 ; 61 8
.db 62,99,99,126,96,99,62,0 ; 62 9
.db 24,60,60,24,24,0,24,0 ; 63 !
.db 54,54,54,0,0,0,0,0 ; 64 "
.db 54,54,127,54,127,54,54,0 ; 65 #
.db 24,126,3,62,96,63,24,0 ; 66 $
.db 0,99,48,24,12,6,99,0 ; 67 %
.db 28,54,28,110,51,51,110,0 ; 68 &
.db 24,24,12,0,0,0,0,0 ; 69 '
.db 24,12,6,6,6,12,24,0 ; 70 (
.db 6,12,24,24,24,12,6,0 ; 71 )
.db 0,119,62,127,62,119,0,0 ; 72 *
.db 0,24,24,126,24,24,0,0 ; 73 +
.db 0,0,0,0,24,24,12,0 ; 74 ,
.db 0,0,0,127,0,0,0,0 ; 75 -
.db 0,0,0,0,0,28,28,0 ; 76 .
.db 96,48,24,12,6,3,1,0 ; 77 /
.db 0,56,56,0,0,56,56,0 ; 78 :
.db 0,24,24,0,0,24,24,12 ; 79 ;
.db 48,24,12,6,12,24,48,0 ; 80 <
.db 0,0,127,0,0,127,0,0 ; 81 =
.db 6,12,24,48,24,12,6,0 ; 82 >
.db 62,99,96,48,24,0,24,0 ; 83 ?
.db 62,99,99,123,59,3,126,0 ; 84 @
.db 62,6,6,6,6,6,62,0 ; 85 [
.db 3,6,12,24,48,96,64,0 ; 86 \
.db 62,48,48,48,48,48,62,0 ; 87 ]
.db 8,28,54,99,0,0,0,0 ; 88 ^
.db 0,0,0,0,0,0,0,255 ; 89 _
.db 12,12,24,0,0,0,0,0 ; 90 `
.db 24,126,102,195,195,102,126,24 ; 91 HOLLOW BALL
.db 24,126,126,255,255,126,126,24 ; 92 SOLID BALL
.db 255,129,129,129,129,129,129,255 ; 93 HOLLOW SQUARE
.db 255,255,255,255,255,255,255,255 ; 94 SOLID SQUARE

 

; ****************************************************************************************
; **** SINE WAVE TABLE DATA
; ****************************************************************************************

SINE:
.db 0,0,0,0,1,1,1,2,2,3,4,5,5,6,7,9
.db 10,11,12,14,15,17,18,20,21,23,25,27,29,31,33,35
.db 37,40,42,44,47,49,52,54,57,59,62,65,67,70,73,76
.db 79,82,85,88,90,93,97,100,103,106,109,112,115,118,121,124
.db 127,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173
.db 176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215
.db 218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244
.db 245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255
.db 255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246
.db 245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220
.db 218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179
.db 176,173,170,168,165,162,158,155,152,149,146,143,140,137,134,131
.db 128,124,121,118,115,112,109,106,103,100,97,94,90,88,85,82
.db 79,76,73,70,67,65,62,59,57,54,52,49,47,44,42,40
.db 37,35,33,31,29,27,25,23,21,20,18,17,15,14,12,11
.db 10,9,7,6,5,5,4,3,2,2,1,1,1,0,0,0