VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 12345678[9]10 ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 20:51:05 01/11/02 Fri
Author: Ronald
Subject: Re: Canton Rev 5 Line 22 PAL Source Code
In reply to: John 's message, "Re: Canton Rev 5 Line 22 PAL Source Code" on 12:56:24 01/11/02 Fri

>Sorry I haven't replied, I just saw the mail.
>
>My system crashed a while back and I lost the code.
>Actually, since I have no way to test PALB, I'm not
>100%
>sure the code worked at all.
>
>John
>
>
>
>>Any one has the above source code? I cannot find in
>>canton page. I tried to send to John Crawford but he
>>did not reply.
Hi John,
Can you modify the source code to run on Canton's Rev 3 board? I have the Daniels code working previously but it is always inverted when it is set to auto invert. I wonder if the source code can be modify to run the way it get the data like you did on GILine18 to GILine22 instead. I need you to do the proper subroutine then I can play around to make it work in PAL-B. Below is the working code for PAL-B



; PAL Revision 2.5 (FIASCO SYSTEMS) *** Compile with MPASM ***
; 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=) 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 PIC16C54,XT_OSC,WDT_ON,PROTECT_OFF
processor 16F84
#include "p16c84.inc"
__config (_CP_OFF & _WDT_ON & _HS_OSC)
__idlocs H'0205'

radix dec

LINES equ 22 ; number of lines for makehline to make
LOOP equ 23 ; temp variable for sampling/delay
LINE3 equ 24 ; holds line 3 values
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 00010011b

; Port A bits
PLL equ 0
LOCK equ 1
TEST equ 2
;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

bcf PORTA,PLL
movlw 11111000b
btfsc DATAHOLDER,POSEDGE ; IF pos edge THEN
;bsf PORTA,PLL ; speed oscillator
movlw 11111001b
tris PORTA ; enable oscillator ctrl

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 1001b
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 1000b ; found quiet, let's set a test pulse on RA2
; FIASCO: leave manual inversion as input
tris PORTA
bsf PORTA,TEST
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
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
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 1001b
tris PORTA ;610 turn off osc control
bcf PORTA,TEST
movlw 0
movwf LINES
retlw 1 ;615 ,640-7-22+4=615 return from line 7


;
;
;

main
bsf PORTA,TEST ; Clear LOCK LED
movlw VIDEO ; 1000000b
movwf PORTB ; PORTB =
movlw 00001100b ; output
tris PORTB ; port b
movlw VIDEO
movwf PORTB
movlw 1001b
tris PORTA
clrf LINES ; clr #8
clrwdt ; clrwdt
movlw 00001111b ; set wdt timer
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

Can you add your this subroutine into the above code to work on line22?

[ Next Thread | Previous Thread | Next Message | Previous Message ]

[ Contact Forum Admin ]


Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.