;******************************************************************************
;16f84Dan.asm 23/01/00 (Daniel)
; This code is a litle modification from the 16f84piu.asm Erik version.
; I have made some changes to make it run on Canton R3 board.
; - Lock led run on RA1 again (I connected it to gnd, not to +5V, in order to off when lock.
; - Auto invert capability (line 22/335) is enabled again (see code), however some normal ; channels appeared inverted. Manual invert (invert jumper) doesn´t work because the code
; doesn´t support it.
; ;******************************************************************************
;16f84piu.asm 22/12/99 (Erik)
; This code is a modification from the 2.5 version meant to run on 16F84A.
; I have corrected some things to get it to run and made some changes to make it ; run on piu's design.
; -The modified vcxo setup (20 MHz xtal) is used, however the original code is still there.
; If you want to use regular vcxo, then just move the semicolons (;) for those 5 lines.
; -I added the lock led again, because the 16F84(A) has ra4 available.
; I run the led to ground, this way it is on when NOT locked.
; If you want it on when locked, then run the led to +5V.
; -Auto invert capability (line 22/335) is disabled, because on my system it doesn't work,
; it can be re-enabled by resetting the invert-video mask back to what it was (see code).
; -The tri-mode capability of the piu design is not used (i simply did not make those ; connections, because the code doesn't support it).
; -On canton board the jumpers are not used also (ports are input, but not read).
; -for canton board set bit 1 of trisb in 'main'-section to '0', because it is an
; output there (clamp), for piu board this should be '1' (LBD=input).
; -Audio pivacy control is also not used.
;
;
;
;*******************************************************************************
; PAL Revision 2.5 (FIASCO SYSTEMS) *** Compile with MPASM ***
; 991116 Code changed to be able to run on 16F84A. Search for "16F84A"
; or "16C54" to see comments in the code about the changes made. Code
; THEORETICALLY should be able to run on either Piu's or Canton's board.
; 990530 Added auto invert: uses flag at line 22/335
; 990403 Invert hor. sync support. Works with ordinary crystal again
; 990212 Teletext support & improved lock
; 990202 Modified Toms changes to get it to work
; 990128 Code changed by Tom to speed up locking
; Based on Urs revision 3 PAL code
; Original version: http://www.magicboxes.com
; ************* INFO **************
; 1. Supports supressed sync / manual inversion.
; 2. IMPORTANT: Use a 20MHz VCXO for superstable picture !
; 4. Instruction cycle is 200ns
; ************* Changes **************
; 1. Added NOPs to adjust timing to fit PAL standard
; 2. Added Lock LED control at RA1
; 3. Changed timing of testing Line3 pulses slightly (Old timing works also)
; 4. Removed Split sync stuff. Now hor. lock looks like original rev. 3 NTSC
; 5. Disabled Extreme Fast locking stuff. (But it might be working if enabled)
; 6. Added initial jump from MAIN routine to the proper line (Works without)
; 7. Added temporary test pulse in MAKEHLINE to trigger DSO
; Toms changes 990128
; 8. Added code for fast lock
; 9. Removed check for quiet in MAKEVBI
; 10. Moved check for PED up two instr cycles in MAKEVBI
; 11. Added one more samlple in "a" section in MAKEHLINE
; Jens changes 990201
; 12. Removed 2 split sync instructions and added 1 nop to fit 320 instr/line
; 13. Removed 3 NOPs after GOTO L3 - Removed 2 NOPs before L4
; 14. Changed L5 from 199 to 198 loops - Removed 1 NOP after GOTO L5
; Jens changes 990212
; 15. Front porch shorted to 1.6 uS
; 16. Teletext enabled
; 17. Now locks on front of PED at end of Sync pulse
; 18. Changed SETMODE to reset VIDEOKAY when 4 bad frames has occured (Toms idea)
; 19. Removed inserting/removing instruction from MAKEHLINE line. (Not needed any more)
; Jens changes 990403
; 20. Reestablished instruction insertion/deletion code.
; 21. Added support for inverted horisontal sync.
; FIASCO SYSTEMS changes 990530
; 22. Added (back) auto inversion. Removed manual inversion. Cleaned up a bit.
; 23. Corrected some cycle numbers (CY=<n>) from beginning of the subroutines
; ************* Current problems **************
; 1. Changing horisontal brightness bars in picture (Need AGC Hack !)
; 2. Some normal channels slightly darker than normal. Others slightly brighter.
;
; DEVICE PIC16F84A,HS_OSC,WDT_ON,PROTECT_OFF
processor 16F84A ; Use these
#include "p16f84a.inc" ; for 16F84A
; DEVICE PIC16C54,HS_OSC,WDT_ON,PROTECT_OFF
; processor 16C54 ; Use these
; #include "p16c5x.inc" ; for 16C54
__config H'3FF6' ; __config (_CP_OFF & _WDT_ON & _HS_OSC)
__idlocs H'0251' ;version 2.51
radix dec
LINES equ 22 ; number of lines for makehline to make 16f84
LOOP equ 23 ; temp variable for sampling/delay adress range
LINE3 equ 24 ; holds line 3 values vanaf 12(dec)
MODE equ 25 ; holds current mode of descramber
BADVIDEOCNT equ 12 ; holder for number of bad video frames
INVFLAG equ 13 ; flag of SSAVI auto inversion
GOODVIDEOCNT equ 14 ; holder for number of good video frames
DATAHOLDER equ 15 ; holds data for pll, etc..
COARSESLOWCNT equ 16 ; holder for number of non-lockups...
COARSEFASTCNT equ 17
LINE318 equ 20 ; For MAKEVBI
QuietCount equ 21 ; for fast lock
; MODE register bits
VIDEOKAY equ 0
PASSBLACK equ 2
DOINVERT equ 3
ERR equ 5
FINDLINE3 equ 6
SYNC equ 10000000b
BLACK equ 10010000b
VIDEO equ 00010011b
BURST equ 11010000b
INVERT equ 00110010b ;enable auto inversion
;if you want to disable it put 00010011b
OSCTRLON equ 11111000b
OSCTRLOFF equ 11111001b ;RA3 = RA4 = 1 (input), changed on all "tris porta"
; Port A bits
PLL equ 0
LOCK equ 1 ;lock led = RA1
ATT6 equ 2
;ATT10 equ 1 DOES NOT USED !
;FIASCO: manual invert not used DOINVERT equ 3
POSEDGE equ 3
NEGEDGE equ 2
POSMASK equ 00001000b
NEGMASK equ 00000100b
org 0
goto main ; restart main loop
;
; sets mode like look for line3, good/bad cntrs, etc..
;
SETMODE
btfss MODE,ERR ; IF there was not an error in VBI THEN
clrf BADVIDEOCNT ; clear errors
incf BADVIDEOCNT,f ; increment error counter
btfsc BADVIDEOCNT,2 ; IF 4 bad frames THEN
bcf MODE,FINDLINE3 ; Find Line 3 again
btfsc BADVIDEOCNT,2 ;
bcf MODE,VIDEOKAY ; Do not decode
btfsc BADVIDEOCNT,2 ;
clrf BADVIDEOCNT ; clear badvideo counter
incf GOODVIDEOCNT,f ; add a good frame
btfsc MODE,ERR ; IF error THEN
clrf GOODVIDEOCNT ; reset good frames
nop
nop
btfsc GOODVIDEOCNT,2 ; IF 4 good frames THEN
bsf MODE,VIDEOKAY ; allow decoding
nop
nop
bcf MODE,ERR ; clear last error flag
nop
bsf PORTA,LOCK ; Update LOCK LED
btfsc MODE,VIDEOKAY
bcf PORTA,LOCK
movlw 42 ; waste time
movwf LOOP
LOOP1
decfsz LOOP,f
goto LOOP1 ;CY=27, 3x41+27=150
nop ;CY=151 NEW: Added this NOP to reach 32us each halfline
retlw 1 ;CY=152,153
;
; make a half line
;
HALFLINE
movlw 05 ;CY=1
movwf LOOP
LOOP2
decfsz LOOP,f ; waste time
goto LOOP2
clrwdt ; clear timer
movlw SYNC ; create a sync signal
btfss MODE,VIDEOKAY ;
movlw VIDEO ; pass video
; The next line had an instruction error in earlier versions, now corrected in Revision 3.
btfss LINE318,0 ; line 318 = no sync
movwf PORTB ;CY=22
movlw 06
movwf LOOP
LOOP3
decfsz LOOP,f ; waste some time
goto LOOP3
goto $+1 ; delay....
movlw BLACK ; BLACK
btfss MODE,VIDEOKAY ; IF nodecoding THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=47 change mode
movlw 22h
movwf LOOP
LOOP5
decfsz LOOP,f ; waste time
goto LOOP5
nop ; NEW: Added this NOP to reach 32us each halfline
retlw 1 ;CY=152 return to main
;
; make vbi , pre, serration, post equ. pulses
;
MAKEVBI
movlw 05 ;CY=1
movwf LOOP
LOOP6
decfsz LOOP,f ; waste time
goto LOOP6
goto DELAY1 ; waste time
DELAY1
movlw SYNC ; makesync
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; pass video
movwf PORTB
;CY=22,182,342,502,662 change mode
movlw 2 ; ************ CHECK ***********
movwf LOOP
LOOP7
decfsz LOOP,f ; waste time
goto LOOP7 ; waste time
goto $+1
movlw BLACK ; make BLACK
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; pass video
movwf PORTB ; CY=35,195,355,515,675 change mode
movlw 45 ;
movwf LOOP
LOOP8
decfsz LOOP,f ; waste time
goto LOOP8
nop ; NEW: Added this NOP to reach 32us each halfline
movlw 5 ; 5 serration pulses
goto $+1
DELAY3
decfsz LINES,f ; if any lines left then make them
goto DELAY1
movwf LINES
serration
movlw SYNC ; make SYNC
btfss MODE,VIDEOKAY ; IF video is bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=822,982,1142,1302,1462 change mode
movlw 27
movwf LOOP
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
goto $+1
clrw
LOOP30
iorwf PORTB,w ; save data
decfsz LOOP,f
goto LOOP30
;nop ; NEW: Added this NOP to reach 32us each halfline
; moved PED check up two cycles*** NEW ***
movwf DATAHOLDER ; save result in datasave
subwf LINES,w
;btfss STATUS,Z ; IF lines left THEN
nop ; does not check for quiet***** NEW *****
clrf DATAHOLDER ; clear the sample
btfsc DATAHOLDER,POSEDGE ; IF there was a pos transition THEN
bsf MODE,ERR ; set error flag
btfsc DATAHOLDER,NEGEDGE ; IF there was a neg transition THEN
bsf MODE,ERR ; set error flag
movlw BLACK ; make BLACK
btfss MODE,VIDEOKAY ; IF video is bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=958,1118,1278,1438,1598
;nop ; moved PED check up two cycles**** NEW ****
movf PORTB,w ; sample again
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
movwf DATAHOLDER ; save in temp holder
nop ; moved check for PED up two cycles
nop
btfss DATAHOLDER,POSEDGE ; if no pos edge detected THEN
bsf MODE,ERR ; we still have an error
movlw 5 ; preload w for post pulses
decfsz LINES,f
goto serration ; if not finished serration then continue
movwf LINES ; 5 post equalization pulses
POST
movlw SYNC ; make SYNC
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=1622,1782,1942,2102,2262 change mode
movlw 2
movwf LOOP
LOOP20
decfsz LOOP,f ; waste time
goto LOOP20
goto $+1
movlw BLACK ; make BLACK
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=1635,1795,1955,2115,2275 change mode
movlw 35
movwf LOOP
nop
nop
nop
nop
clrf QuietCount ; used for tocom invert (soon)
clrf LINE318
nop
LOOP31
decfsz LOOP,f ; waste time
goto LOOP31
nop ; NEW: Added this NOP to reach 32us each halfline
decf LINES,f
btfsc STATUS,Z
retlw 01 ;CY=2391 return to main when done vsync int.
goto $+1
movlw 07
movwf LOOP
LOOP32
decfsz LOOP,f
goto LOOP32
goto POST
;
; makes the horizontal lines (sync and controls video)
;
MAKEHLINE
incf COARSEFASTCNT,f ;CY=1
incf COARSESLOWCNT,f ; add 1 to both as one will ALWAYS be reset!
nop
nop
nop
nop
nop
nop
nop
nop
movlw BLACK ; make BLACK
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=14 change mode
nop
nop
nop
nop ; waste some time
movlw SYNC ; make SYNC
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; passvideo
movwf PORTB ;CY=22 change mode
nop ;
nop ;
nop ;
nop ;
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
movlw BURST ; pass burst
btfss MODE,VIDEOKAY ; IF video bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=45 change mode
movf PORTB,w ; take sample..NEW ***
nop
nop
movwf DATAHOLDER
btfsc DATAHOLDER,NEGEDGE ; IF neg edge was heard THEN
bsf DATAHOLDER,POSEDGE ; make it look like we heard pos edge
;-----------------------old vcxo-------------------
; bcf PORTA,PLL
; btfsc DATAHOLDER,POSEDGE ; IF pos edge THEN
; bsf PORTA,PLL ; speed oscillator
; movlw 11111000b ; On the 16F84A, T0SK1 is now also RA4,
; and can be set as an output. All of
; the boards were designed with T0SK1
; shorted to Vcc, therefore it is very
; important to set the upper four bits
; to 1's so that T0SK1 is set to be an
; input. This code change is backwards
; compatible with the 16C54, because those
; bits are undefined on the 16C54.
; tris PORTA ; enable oscillator ctrl
;----------------------new vcxo (digitalman)--------
bcf PORTA,PLL ;PLL=0
movlw OSCTRLON ;OSCTRLON=11111000b
btfsc DATAHOLDER,POSEDGE
movlw OSCTRLOFF ;OSCTRLOFF=11111001b
tris PORTA
;--------------------------------------------------
btfss DATAHOLDER,POSEDGE ; IF no pos edge THEN
clrf COARSEFASTCNT ; clear fast counter
btfsc DATAHOLDER,POSEDGE ; IF pos edge THEN
clrf COARSESLOWCNT ; clear slow counter
btfsc COARSEFASTCNT,6 ; WAS 6 ; IF fastcount is 64 THEN
goto NORMAL ; .4uS + .2uS to NORMAL
btfsc COARSESLOWCNT,6 ; WAS 6 ; IF slowcount is 64 THEN
goto NORMAL ; .8us + .2uS to NORMAL
NORMAL
nop
nop
; this is where the active line of video begins
movlw VIDEO ;CY=67 default normal video
btfsc MODE,DOINVERT
movlw INVERT
btfsc MODE,PASSBLACK ; IF we have to make black THEN
movlw BLACK ; make BLACK
btfss MODE,VIDEOKAY ; IF video is bad THEN
movlw VIDEO ; pass video
movwf PORTB ;CY=74 change mode
btfss MODE,FINDLINE3 ; skip next if locked on
goto LOCKON ; if not locked, goto lock routine
movlw 22
movwf LOOP
LOOP33
decfsz LOOP,f
goto LOOP33 ;CY=80, 3x21+80=143
nop
nop
;FIASCO: added sampling of inv. flag here
movf PORTB,w ;CY=146
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w ;CY=154
movwf INVFLAG
movlw 50
movwf LOOP
LOOP34
decfsz LOOP,f
goto LOOP34 ;CY=159, 3x49+159=306
clrwdt ;CY=307
movlw 11111001b ; 16F84A code change. Backward compatible w/16C54.
tris PORTA
decf LINES,f
btfsc STATUS,Z ;CY=311
retlw 1
goto $+1
goto $+1
goto $+1
goto MAKEHLINE ;CY=319,320
LOCKON
movlw 7
movwf QuietCount
; This section looks for an absence of PEDS. A compete absence of PEDs indicates that we
;are in one of the empty areas between pulses in the VBI. The code looks for PED and if there
;is one, goes back to start again. It looks for 90 cycles and then assumes it is in the
;VBI
L1
btfsc PORTB,POSEDGE ; look for PED
goto LOCKON ; start over if PED
btfsc PORTB,POSEDGE
goto LOCKON
btfsc PORTB,POSEDGE
goto LOCKON
btfsc PORTB,POSEDGE
goto LOCKON
btfsc PORTB,POSEDGE
goto LOCKON
decfsz QuietCount,f ; IF 5 no PED, then decr counter and
goto L1 ; keep looking for quiet
movlw 11111000b ; 16F84A code change. Backward compatible w/16C54.
; found quiet, let's set a test pulse on RA2
tris PORTA ; FIASCO: leave manual inversion as input
;bsf PORTA,TEST
nop ;nop'd out test pulse
clrwdt
nop
; At this point, we have found the area between pulses in the VBI, but we don't know which line
;or which field or where in the line we are. The next two instructions keep looping back until
;a PED is found. This is probably a PED from a pre pulse, since the previous code should have
;exited the loop at the first pulse in the VBI
L2
btfss PORTB,POSEDGE ; now look for PED(we found quiet)
goto L2 ; loop until we find PED
;bcf PORTA,TEST ; found PED, let's clear a test pulse on RA2
nop ;nop'd out test pulse
clrwdt
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
; This code samples here to make sure that we are really in the VBI, there should be no
; PEDs or NEDs here. If there are, then we start over looking for a quiet area again.
movf PORTB,w ; look for quiet
iorwf PORTB,w ; look again
iorwf PORTB,w ; look again
movwf DATAHOLDER
btfsc DATAHOLDER,NEGEDGE
goto LOCKON
btfsc DATAHOLDER,POSEDGE
goto LOCKON ;21
; This code looks for a NED about 23 instr cycles after the PED that was found. Theoretically,
; we should not find a NED here the first time we get to this point because there is no
; NED 23 cycles (4.6us) after the the first PED in the pre-pulse (lines 623,624,625).
; If we don't find a NED, then go back to the beginning to look for another quiet area in
; the VBI. This will make the code quickly scan through lines 623,624 and 625 and finally
; going on when it finds a positive pulse midway through line 1(because it will see a NED
; 23 cycles after the PED).
movf PORTB,w ;22 look for NED 22 cycles after PED
iorwf PORTB,w
iorwf PORTB,w
iorwf PORTB,w ; keep looking for NED
movwf DATAHOLDER
btfss DATAHOLDER,NEGEDGE ; Have we found NED
goto LOCKON ; if not, start over
bsf PORTB,NEGEDGE ; FIASCO: effectively nop
clrwdt
nop
nop
nop
nop
; At this point we have found a positive pulse, probably the first one in the middle
; of line 1. If this is line 3(or line 316), there should be a PED about 13 cycles from
; the NED that we just found. If not, we are in line 1 or line 2 and go back to look for
; the next quiet area.
movf PORTB,w
iorwf PORTB,w ;13 look for PED
iorwf PORTB,w
iorwf PORTB,w
movwf DATAHOLDER
btfss DATAHOLDER,POSEDGE ; was PED found?
goto LOCKON ;5 if not, start over
;bcf PORTA,TEST
nop ;nop'd out test pulse
clrwdt
nop
movlw 99
movwf LOOP
; We have found line 3( or line 316) here because if we did not see the distinctive
; PED-NED-PED that is for line 3 only, otherwise we would have gone back to keep trying.
; At this point, we don't know if we are at line 3 or line 316, since they both have
; the PED-NED-PED. At the end of line 5 there is a sync pulse to start line 6. If this was
; line 316, that sync pulse would not be there.
L3
decfsz LOOP,f
goto L3 ;9, 98x3+9=303
; nop
; nop ;added nops for PAL
; nop
; this just checks for the pulse halfway through line 4 or start of line 317 to make sure
; we are at where we think we are.
movf PORTB,w ;307, line 4.5 or 317 starting NED here
iorwf PORTB,w ;1 look for NED
iorwf PORTB,w ;
iorwf PORTB,w
movwf DATAHOLDER
btfss DATAHOLDER,NEGEDGE ; was there a NED
goto LOCKON
; nop
; nop
movlw 157
movwf LOOP
L4
decfsz LOOP,f ;
goto L4 ;12, 3x156+12=480
CLRWDT
movf PORTB,w ;636, 2x318=636
iorwf PORTB,w ; look for NED at start of line 6
iorwf PORTB,w
iorwf PORTB,w
movwf DATAHOLDER
btfss DATAHOLDER,NEGEDGE ; NED for line 6???
goto LOCKON ; no, start again(we want 6, not 318)
; At this point we found the NED for the sync pulse at the start of line 6. We need to waste
; a little time and go back to the main routine at the end of line 7 at precisely the same
; time that a normal MAKEHLINE would. That would be 2x320-7-22+4=615 from when we found the
; NED. 2x320 for lines 6 and 7. The main routine uses 7 cycles so we subtract that. The
; MAKEHLINE routine makes the next sync pulse 22 cycles after it starts, so we subtract 22.
; I estimate that the NEDs and PEDs lag the real pulses by about 4 cycles, so we add that.
; This timing is critical and may need to be adjusted for PAL along with the 23 cycles and
; 13 cycles between PEDs and NEDs
clrwdt
movlw 198 ; Was 199
movwf LOOP
L5 decfsz LOOP,f
goto L5 ;11, 3x198+11=605
; nop
nop
bsf MODE,FINDLINE3 ;608 set line 3 found flag
movlw 11111001b ; 16F84A code change. Backward compatible w/16C54.
tris PORTA ;610 turn off osc control
;bcf PORTA,TEST
nop ;nop'd out test pulse
movlw 0
movwf LINES
retlw 1 ;615 ,640-7-22+4=615 return from line 7
;
;
;
main
;bsf PORTA,TEST ; Clear LOCK LED
nop ;nop'd out test pulse
movlw VIDEO ; 1000000b
movwf PORTB ; PORTB = movlw 00001100b ; output ;RB2=RB3=input
tris PORTB ; port b
movlw VIDEO
movwf PORTB
movlw 11111001b ; 16F84A code change. Backward compatible w/16C54.
tris PORTA clrf LINES ; clr #8
clrwdt ; clrwdt
movlw 10001111b ; Set timer to WDT, prescaler to 1:128
; On the 16F84A, OPTION is now 8 bits
; wide (not 6 like on the 16C54). The top
; two bits set whether weak pullups are
; enabled on port B and whether interrupts
; trigger on rising or falling edges. Since
; these bits are undefined on a 16C54, this
; code change is backwards compatible with
; the 16C54.
option
clrwdt ; clear it again
bcf MODE,VIDEOKAY movlw 1
goto begin
MAINLOOP
bsf MODE,PASSBLACK ; make vbi
movlw 5
movwf LINES ; call MAKEVBI ; FIELD 2 - VBI ; lines ; line 318 tricky...
; we have HALF an equalization done...
; but 318 is a whole line... no probls.
bsf LINE318,0 ;CY=2393
nop
nop
nop
nop
call HALFLINE ; (line 318 version, no sync)
movwf LINES
nop
bcf LINE318,0
nop
nop
call MAKEHLINE ; make line 319
movwf LINES
bcf MODE,PASSBLACK ; out of VBI, now pass video
nop
nop
nop
call MAKEHLINE ; make line 320
movwf LINES
nop
nop
nop
nop
call MAKEHLINE ; make line 321
movlw 14
movwf LINES
nop
nop
nop
call MAKEHLINE ; make line 322-335
movlw 100
movwf LINES ; draw 100 lines
btfss INVFLAG,NEGEDGE ;FIASCO: added auto inversio
bsf MODE,DOINVERT
nop
call MAKEHLINE ; line 336-435
nop ; NEW: Author forgot this NOP, now added in Revision 3
movlw 184 ;FIASCO: added two lines to be inverted
movwf LINES
nop
nop
call MAKEHLINE ; line 436-619
movlw 3
movwf LINES
bcf MODE,DOINVERT
nop
nop
call MAKEHLINE ; 620-622
movwf LINES
bsf MODE,PASSBLACK ; make vbi interval now
nop
nop
nop
call HALFLINE ; 623.5
nop
movlw 5
movwf LINES
nop
nop
call MAKEVBI ; make field 1
movwf LINES
nop
nop
nop
nop
call HALFLINE ; first half of line 6 movwf LINES ;
nop
nop
nop
nop
call SETMODE ; last half of line 6
begin
movwf LINES ; 1 line
bcf MODE,PASSBLACK ; pass video
nop
nop
nop
call MAKEHLINE ; line 7
movlw 15
movwf LINES
nop
nop
nop
call MAKEHLINE ; line 8-22
movlw 231
movwf LINES
btfss INVFLAG,NEGEDGE ;FIASCO: added auto inversio
bsf MODE,DOINVERT
nop
call MAKEHLINE ; 23 - 253
movlw 53 ;FIASCO: added one line to be inverted
movwf LINES
nop
nop
nop
call MAKEHLINE ; 254 - 306
movlw 4
movwf LINES
bcf MODE,DOINVERT
nop
nop
call MAKEHLINE ; 307-310
goto MAINLOOP ; loop back
END