Help modifying C64 PAL code for NTSC machine

Other Computers and Game Systems

Moderator: Moderators

Post Reply
rwv01
Vic 20 Enthusiast
Posts: 161
Joined: Thu Nov 01, 2007 8:14 am

Help modifying C64 PAL code for NTSC machine

Post by rwv01 »

Hi folks.
I've been playing around with an odd experiment from the '80s called Visicode.
A method for transmitting BASIC code via a flashing square on a TV screen during a broadcast of the
British computer show "Four Computer Buffs". Video: https://www.youtube.com/watch?v=xxo1Gs46ti0
Magazine article with circuit diagram: https://archive.org/details/PersonalCom ... 4/mode/1up

I've built the circuit (C64 version) and copied the programs. The system assumes all PAL equipment, but as I only have NTSC,
I wonder if there's a way to modify this code so it runs at PAL speed on an NTSC machine, or to change the sample rates on the PB7 (L) pin of the userport?

Receiver program:

Code: Select all

10 rem receiver program for commodore 64
20 a=49152
30 read n:if n<0 then 60
40 poke a,n:a=a+1
50 goto 30
60 end
70 data 165,43,133,252,165,44,133,253,169,0
80 data 141,3,221,32,228,255,201,0,240,249
90 data 32,77,192,32,117,192,133,254,32,77
100 data 192,32,117,192,201,0,208,4,165,254
110 data 240,25,32,77,192,32,117,192,32,77
120 data 192,32,117,192,32,77,192,32,117,192
130 data 201,0,208,246,76,20,192,96,160,124
140 data 136,208,253,202,208,248,96,169,9,133
150 data 251,173,1,221,41,128,208,249,162,15
160 data 32,68,192,169,0,72,173,1,221,10
170 data 104,106,162,30,32,68,192,198,251,208
180 data 240,162,30,32,68,192,96,-1
I may have a PAL option later, but I thought I'd try this first.
Last edited by Mike on Sat Jul 01, 2023 12:51 am, edited 1 time in total.
Reason: program put into bbcode [code]...[/code] tag pairs
groepaz
Vic 20 Scientist
Posts: 1187
Joined: Wed Aug 25, 2010 5:30 pm

Re: Help modifying C64 PAL code for NTSC machine

Post by groepaz »

this is the code to begin with

Code: Select all

.C:c000  A5 2B       LDA $2B
.C:c002  85 FC       STA $FC
.C:c004  A5 2C       LDA $2C
.C:c006  85 FD       STA $FD
.C:c008  A9 00       LDA #$00
.C:c00a  8D 03 DD    STA $DD03
.C:c00d  20 E4 FF    JSR $FFE4 ; check keyboard
.C:c010  C9 00       CMP #$00
.C:c012  F0 F9       BEQ $C00D
.C:c014  20 4D C0    JSR $C04D
.C:c017  20 75 C0    JSR $C075
.C:c01a  85 FE       STA $FE
.C:c01c  20 4D C0    JSR $C04D
.C:c01f  20 75 C0    JSR $C075
.C:c022  C9 00       CMP #$00
.C:c024  D0 04       BNE $C02A
.C:c026  A5 FE       LDA $FE
.C:c028  F0 19       BEQ $C043
.C:c02a  20 4D C0    JSR $C04D
.C:c02d  20 75 C0    JSR $C075
.C:c030  20 4D C0    JSR $C04D
.C:c033  20 75 C0    JSR $C075
.C:c036  20 4D C0    JSR $C04D
.C:c039  20 75 C0    JSR $C075
.C:c03c  C9 00       CMP #$00
.C:c03e  D0 F6       BNE $C036
.C:c040  4C 14 C0    JMP $C014
.C:c043  60          RTS
.C:c044  A0 7C       LDY #$7C ; tweak this, perhaps (60*$7c)/50 = $94
.C:c046  88          DEY
.C:c047  D0 FD       BNE $C046
.C:c049  CA          DEX
.C:c04a  D0 F8       BNE $C044
.C:c04c  60          RTS
.C:c04d  A9 09       LDA #$09
.C:c04f  85 FB       STA $FB
.C:c051  AD 01 DD    LDA $DD01
.C:c054  29 80       AND #$80
.C:c056  D0 F9       BNE $C051
.C:c058  A2 0F       LDX #$0F
.C:c05a  20 44 C0    JSR $C044
.C:c05d  A9 00       LDA #$00
.C:c05f  48          PHA
.C:c060  AD 01 DD    LDA $DD01
.C:c063  0A          ASL A
.C:c064  68          PLA
.C:c065  6A          ROR A
.C:c066  A2 1E       LDX #$1E
.C:c068  20 44 C0    JSR $C044
.C:c06b  C6 FB       DEC $FB
.C:c06d  D0 F0       BNE $C05F
.C:c06f  A2 1E       LDX #$1E
.C:c071  20 44 C0    JSR $C044
.C:c074  60          RTS
Since it neither disables "badlines" nor disables interrupts, its probably not that timing sensitive anyway
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
rwv01
Vic 20 Enthusiast
Posts: 161
Joined: Thu Nov 01, 2007 8:14 am

Re: Help modifying C64 PAL code for NTSC machine

Post by rwv01 »

Thanks groepaz.
groepaz wrote: Fri Jun 30, 2023 6:49 pm .C:c044 A0 7C LDY #$7C ; tweak this, perhaps (60*$7c)/50 = $94
So instead of LDY #$7C
it would be LDY #$94C ?
Sorry my programming skills are VERY limited

Also, from a related article;
"The receiving program waited for the first edge of each start bit, waited a further 10 milliseconds, and then sampled the signal at 20 millisecond intervals." Where would I tweak these values in the program?
groepaz
Vic 20 Scientist
Posts: 1187
Joined: Wed Aug 25, 2010 5:30 pm

Re: Help modifying C64 PAL code for NTSC machine

Post by groepaz »

Generally on NTSC everything needs to be 20% percent faster (50Hz PAL vs 60Hz NTSC).

So, when you you look at the code, there is one delay loop at $c044 which is called with different values in X at various places. So the first/easy attempt is to make this delay loop 20% faster (which then means all delays are 20% less).

And now i see i made a mistake there :=) $94 is 20% more, not less, args =D

First of all, $7c is 124 in decimal. In the code its at $c045, so its the 69th value in the DATAs. This one you have to modify

The correct calculation is: ((1/60)*124)/(1/50) = ~103

So change that 124 to 103, and give it a try. If it syncs once for every byte, this should be accurate enough. If it doesnt work right, try 104 or 102 instead. If that still doesn't work, we'll have to actually count cycles and recalculate all delays.

But as said, as it neither disables interrupts nor badlines, it can probably take quite some jitter.
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
rwv01
Vic 20 Enthusiast
Posts: 161
Joined: Thu Nov 01, 2007 8:14 am

Re: Help modifying C64 PAL code for NTSC machine

Post by rwv01 »

Thanks again, groepaz.
I've been trying those changes applied to line 130, data value 124.
Changed 124 to 103, 102, 104, and even 144 (going the opposite way).

So far, all I can get the receiver program to do is go from a waiting state to "basic mode"
once the square starts flashing.

The "tune" program from the same PC World magazine article seems to work as described.
The biggest problem may be the quality of my source videos for the code transmissions.
IE, old pal video tapes digitized and uploaded to YouTube in 480p :?
One thing I had to interpret from the PCW article is that pin from 13 on the chip is connected to pin L on the userport.
It only states the userport pin connection for the BBC Micro version (PB7), which would be pin L on the C64 userport, right?
The circuit described is for both computers with minor changes for the C64.

Oh, and of course I am using a CRT monitor for the "transmission" video output with the photo transistor.
It's all done as a breadboard project so at least I can re-use the parts. :)
groepaz
Vic 20 Scientist
Posts: 1187
Joined: Wed Aug 25, 2010 5:30 pm

Re: Help modifying C64 PAL code for NTSC machine

Post by groepaz »

It uses PB7 indeed, and that's L - correct

The problem might indeed be the video source - if the video was deinterlaced, ie is now 25fps, then it will probably not work
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
Post Reply