;*************************************************************************** ;* vidgen.ASM ;* ;*************************************************************************** .DEVICE AT90S1200 ;*************************************************************************** ;* a few, very useful macros ;*************************************************************************** .LISTMAC .MACRO ADDI subi @0, -@1 .ENDMACRO ;skip next instruction if not equal to zero .MACRO skipne ;.SET _skipne = PC+2 brne PC+2 ;_skipne .ENDMACRO ;skip next instruction if carry set .MACRO skipcs ;.SET _skipcs = PC+2 brcs PC+2 ;_skipcs .ENDMACRO ;skip next instruction if carry clear .MACRO skipcc ;.SET _skipcc = PC+2 brcc PC+2 ;_skipcc .ENDMACRO ;skip next instruction if equal to zero .MACRO skipeq ;.SET _skipeq = PC+2 breq PC+2 ;_skipeq .ENDMACRO ;skip next instruction if lower .MACRO skiplo ;.SET _skiplo = PC+2 brlo PC+2 ;_skiplo .ENDMACRO ;skip next instruction if half carry set .MACRO skiphs ;.SET _skiphs = PC+2 brhs PC+2 ;_skiphs .ENDMACRO ;skip next instruction if half carry clear .MACRO skiphc ;.SET _skiphc= PC+2 brhc PC+2 ;_skiphc .ENDMACRO ;skip next instruction if T set .MACRO skipts ;.SET _skipts = PC+2 brts PC+2 ;_skipts .ENDMACRO ;skip next instruction if T clear .MACRO skiptc ;.SET _skiptc = PC+2 brtc PC+2 ;_skiptc .ENDMACRO ;wait two cycles but waste only one instruction .MACRO doublenop ;.SET _doublenop = PC+1 rjmp PC+1 ;_doublenop .ENDMACRO ;include AT90S1200 registers definitions .include "1200def.inc" ;include font definitions ;fonts are stored in a EEPROM table, edit fonts.inc to modify it as you wish .include "vis_byte.inc" .include "charsrc.inc" ;*************************************************************************** ;* VARIABLE ASSIGNEMENTS ;*************************************************************************** .CSEG .def SaveStatus = r0 ;status buffer during interrupts .def XX= r1 .def ct50hz = r14 ; .def PixelMask = r16 .def RowsModFour = r17 ;raster rows counter, split in two for .def RowsDivFour = r18 ;convenience of use. Counts up to 312 .def Arg1 = r19 ;Temp variable used by interrupt .def Arg2 = r20 ; " " " " .def Arg3 = r21 ; " " " " .def Arg4 = r22 ; .def Arg5 = r23 ; .def Arg6 = r24 ; .def Sleep = r25 ; .def MiscFlags = r26 ;Assorted flags ;bit 0,1: position (0-3) of interrupt ;identifies wich of the four line position ;we are on (3=end of line, 0=sync pulse) when ;an interrupt occurs ;used by timer interrupt routine ;flags bit definition .equ Position1Bit = 0 .equ Position2Bit = 1 .equ POSITIONMASK = 1 ;3 .def CurrHeight = r30 ;character height (running counter) ;*************************************************************************** ;* Constants ;*************************************************************************** .equ DisplayRow = 150/4 ;counter value for display start .equ StartRetrace = (312/4)-1;counter value at wich retrace starts .equ StopRetrace = (312/4) ;maximum counter value ;*************************************************************************** ;* Port Pin Assignements ;*************************************************************************** ;port D bit definitions (OUTPUTS) .equ CSyncBit = 0 ;set video output to composite sync level when low .equ VideoBit = 1 ;set video level to white when high, black when low ;port B bit definitions (INPUTS) ;*************************************************************************** ;* VECTORS ;*************************************************************************** rjmp RESET ;Reset Handle rjmp RESET ;Ext. interrupt request 0 rjmp RESET ;Timer rjmp ANCOMP ;analog comparator ;*************************************************************************** ;* ;* MAIN PROGRAM ;* ;*************************************************************************** ;* INITAILIZATION ;*************************************************************************** RESET: clt ;clear T bit flag ;VERY important: ;clear T flag, here used to ;verify if we were sleeping ldi Arg1, 0b01111111 ;set port D bits to outputs out DDRD, Arg1 ldi Arg1, 0b00000001 ;preset output state out PortD, Arg1 ldi Arg1, 0b00000000 ;set port B to inputs out DDRB, Arg1 ldi Arg1, 0b11111111 ;turn on pullups on inputs out PortB, Arg1 ldi Arg1, 1 out TCCR0, Arg1 ;dont'use timer prescaler ldi Arg1, 32 out MCUCR, Arg1 ;enable sleep idle mode ldi Arg1,0b00001011 ;enable comparator ir out ACSR,Arg1 ldi CurrHeight, 8 ldi MiscFlags, 1 clr PixelMask clr Arg1 ;and clear interrupt variables clr Arg2 clr Arg3 clr Sleep sei ;at last, allow interrupts ;*************************************************************************** ;* MAIN LOOP ;*************************************************************************** FOREVER: sleep rcall tennop rcall tennop rcall tennop rcall tennop in Arg1,ACSR sbrs Arg1,ACO rjmp linesync framesync: ldi RowsModFour,0 ldi RowsDivFour,0 rjmp voidline linesync: inc RowsModFour ;increment row counters cpi RowsModFour, 4 ;if RowsModFour == 4 skipne inc RowsDivFour ;then increment RowsDivFour andi RowsModFour, 0b00000011 ;clear anyway bit 2 rcall tennop rcall tennop rcall tennop rcall tennop rcall tennop _A1: cpi RowsDivFour, 188/4 ;4 lines brlo _A2 rjmp VOIDLINE _A2: cpi RowsDivFour, 184/4 ;4 lines brne _A3 ldi Arg1,6 rjmp DISPLAYDIGITS _A3: cpi RowsDivFour, 180/4 ;4 lines brne _A4 ldi Arg1,5 rjmp DISPLAYDIGITS _A4: cpi RowsDivFour, 176/4 ;4 lines brne _A5 ldi Arg1,4 rjmp DISPLAYDIGITS _A5: cpi RowsDivFour, 172/4 ;4 lines brne _A6 ldi Arg1,3 rjmp DISPLAYDIGITS _A6: cpi RowsDivFour, 168/4 ;4 lines brne _A7 ldi Arg1,2 rjmp DISPLAYDIGITS _A7: cpi RowsDivFour, 164/4 ;4 lines brne _A8 ldi Arg1,1 rjmp DISPLAYDIGITS _A8: cpi RowsDivFour, 160/4 ;4 lines brne _A9 ldi Arg1,0 rjmp DISPLAYDIGITS _A9: VOIDLINE: clr PixelMask ;reset pixel mask rjmp FOREVER tennop: doublenop nop ret ;**************************************************************************** ;* ON SCREEN DISPLAY ROUTINES ;**************************************************************************** DISPLAYDIGITS: cpi Arg1,0 brne n1 ldi Arg3,C11 rcall DISPLAYCHAR ldi Arg3,C21 rcall DISPLAYCHAR ldi Arg3,C31 rcall DISPLAYCHAR ldi Arg3,C41 rcall DISPLAYCHAR ldi Arg3,C51 rcall DISPLAYCHAR ldi Arg3,C61 rcall DISPLAYCHAR rjmp DISPLAYLINERESTART ;end line n1: cpi Arg1,1 brne n2 ldi Arg3,C12 rcall DISPLAYCHAR ldi Arg3,C22 rcall DISPLAYCHAR ldi Arg3,C32 rcall DISPLAYCHAR ldi Arg3,C42 rcall DISPLAYCHAR ldi Arg3,C52 rcall DISPLAYCHAR ldi Arg3,C62 rcall DISPLAYCHAR rjmp DISPLAYLINERESTART ;end line n2: cpi Arg1,2 brne n3 ldi Arg3,C13 rcall DISPLAYCHAR ldi Arg3,C23 rcall DISPLAYCHAR ldi Arg3,C33 rcall DISPLAYCHAR ldi Arg3,C43 rcall DISPLAYCHAR ldi Arg3,C53 rcall DISPLAYCHAR ldi Arg3,C63 rcall DISPLAYCHAR rjmp DISPLAYLINERESTART ;end line n3: cpi Arg1,3 brne n4 ldi Arg3,C14 rcall DISPLAYCHAR ldi Arg3,C24 rcall DISPLAYCHAR ldi Arg3,C34 rcall DISPLAYCHAR ldi Arg3,C44 rcall DISPLAYCHAR ldi Arg3,C54 rcall DISPLAYCHAR ldi Arg3,C64 rcall DISPLAYCHAR rjmp DISPLAYLINERESTART ;end line n4: cpi Arg1,4 brne n5 ldi Arg3,C15 rcall DISPLAYCHAR ldi Arg3,C25 rcall DISPLAYCHAR ldi Arg3,C35 rcall DISPLAYCHAR ldi Arg3,C45 rcall DISPLAYCHAR ldi Arg3,C55 rcall DISPLAYCHAR ldi Arg3,C65 rcall DISPLAYCHAR rjmp DISPLAYLINERESTART ;end line n5: cpi Arg1,5 brne n6 ldi Arg3,C16 rcall DISPLAYCHAR ldi Arg3,C26 rcall DISPLAYCHAR ldi Arg3,C36 rcall DISPLAYCHAR ldi Arg3,C46 rcall DISPLAYCHAR ldi Arg3,C56 rcall DISPLAYCHAR ldi Arg3,C66 rcall DISPLAYCHAR rjmp DISPLAYLINERESTART ;end line n6: cpi Arg1,6 brne n7 ldi Arg3,C17 rcall DISPLAYCHAR ldi Arg3,C27 rcall DISPLAYCHAR ldi Arg3,C37 rcall DISPLAYCHAR ldi Arg3,C47 rcall DISPLAYCHAR ldi Arg3,C57 rcall DISPLAYCHAR ldi Arg3,C67 rcall DISPLAYCHAR n7: rjmp DISPLAYLINERESTART ;end line DISPLAYCHAR: mov Arg5,Arg3 andi Arg5,0b10000000 ;mask unwanted pixels skipeq sbi PortD, VideoBit ;...turn pixel off skipne ;according to table cbi PortD, VideoBit ;turn pixel on or... mov Arg5,Arg3 andi Arg5,0b01000000 ;mask unwanted pixels skipeq sbi PortD, VideoBit ;...turn pixel off skipne ;according to table cbi PortD, VideoBit ;turn pixel on or... mov Arg5,Arg3 andi Arg5,0b00100000 ;mask unwanted pixels skipeq sbi PortD, VideoBit ;...turn pixel off skipne ;according to table cbi PortD, VideoBit ;turn pixel on or... mov Arg5,Arg3 andi Arg5,0b00010000 ;mask unwanted pixels skipeq sbi PortD, VideoBit ;...turn pixel off skipne ;according to table cbi PortD, VideoBit ;turn pixel on or... mov Arg5,Arg3 andi Arg5,0b00001000 ;mask unwanted pixels skipeq sbi PortD, VideoBit ;...turn pixel off skipne ;according to table cbi PortD, VideoBit ;turn pixel on or... doublenop ;last pixel, waste time... doublenop cbi PortD, VideoBit ;turn pixel off ret DISPLAYLINERESTART: rjmp FOREVER ;*************************************************************************** ;* IR ;*************************************************************************** ANCOMP: reti