Heureka: Difference between revisions

From Software Archive
Jump to navigation Jump to search
No edit summary
Rewrite: the check measures the bit rate of one sector (324 bytes of T2..7/S11 and T31/S10), not the track length; drive and BASIC code, acceptance windows, variants, verified release list, corrected G64 patch limits. Based on Stephan Scheuer's analysis (forum64.de thread 83037).
Line 1: Line 1:
Heureka protection was probably developed by [https://www.c64-wiki.de/wiki/Martin_Pfost Martin Pfost].
= Heureka =


Heureka protection has tracks with sectors with a slower write speed followed usually by two sectors with higher write speed to roughly compensate the track length.
The Heureka protection was used by Heureka-Teachware on its educational
The speeds that the sectors were written does not fit one of the four speeds of the 1541. The speed values were chosen in a way, that a 1541 reads these sectors just fine in normal operation. So no bad sectors appear on the disk.
software (Learning English, Let's Go, Etudes Françaises, ALi, GEO, OPTI-MA
and others). It was probably developed by
[https://www.c64-wiki.de/wiki/Martin_Pfost Martin Pfost].


However the track length of these tracks deviates from the default track length. The protection check measures the track length of the tracks containing the off-speed sectors
The protection doesn't use bad sectors, extra tracks or signatures. On two
and expects certain values.
tracks, three sectors were written at a '''bit rate that none of the four
1541 speed zones uses'''. A 1541 reads these sectors without errors. The
protection check measures how long the drive needs to read one of these
sectors. A copy made with a normal copier writes every sector at the zone's
nominal speed, so the measured time is wrong.


The Heureka protection has this pattern on disk on track 31 and on another second track, usually between 2 - 7.
The programs are compiled BASIC (Austrospeed). The check is hidden inside the
compiled program, and the drive code is stored as a BASIC string.


Heureka software checks the protection often and on different places in the program, e.g. after every menu selection. Some releases check only one of these tracks at a time, some check the lower and upper after each other.
== Disk layout ==
Thus, the relevant locations on the disk degrade fast and are often of bad quality when archived (smeared in scatter plot).


While the G64 format generally supports variable speed zones per sector within a track (*) there is no support in the conversion from Kryoflux Streams to G64 using the Disk Tool Console. Also as of 2020 no C64 emulator supports that feature of G64 format.
* Tracks 1–35 use the ordinary CBM DOS layout.
* Two tracks contain off-speed sectors:
** the '''first test track''' in speed zone 3: track 2, or 2 + the volume number for the numbered series (see [[#Releases|Releases]]);
** '''track 31''' in speed zone 0.
* On both tracks the pattern is the same:


The current approach is to patch the track length in the G64 by adding / removing fill bytes after sector headers/data/track.
{| class="wikitable"
! Sector !! Bit cell compared with the zone's nominal value
|-
| 10 || about 7–8% longer (written slower)
|-
| 11 || about 4% shorter (written faster)
|-
| 12 || about 4% shorter (written faster)
|-
| all others || nominal
|}


*) Needs to be verified.
* The slow and the fast sectors roughly cancel out, so the track length stays close to normal.
* All other tracks and sectors are nominal.
* Example from a KryoFlux stream of ''Learning English, Green Line 1'', normalised to 300 rpm:


==== Patching ====
<pre>
Track  3  sector 10 +7.5 %  sector 11 -3.8 %  sector 12 -3.5 %  others nominal
Track 31  sector 10 +8.0 %  sector 11 -4.0 %  sector 12 -4.0 %  others nominal
</pre>


Note that the following description allows the protection check to work in an emulator only.
Only the program disk is protected. Side 2 of the double-sided releases,
and the additional disks of ''Englische Sprachübungen'', have no off-speed
sectors.


The lower track for the length check is located in speed zone 3, typically one track between 2 - 7. (I take 2 for this example) To get the correct timing result in emulation for the lower track the track length in bytes in the G64 must be in the range of 0x1EE1 to 0x1EF6, recommended length is 0x1EEF.
== The check ==


The upper track is located in speed zone 0 and is typically track 31. To get the correct timing result in emulation the track length must be lower than 0x1753.
=== Drive side ===


When converting from Kryoflux Streams or NIBs of a real disk, track 2 length is usually smaller and track 31 length is usually longer.
The C64 opens buffer 2 (<code>$0500</code>) and reads the sector to be
measured into it with <code>U1</code>. This also sets the track and sector of
the buffer's job. It then overwrites the buffer with the drive code (sent as
a BASIC string) and starts it with <code>U5</code>. The user vector U5 jumps
to <code>$0506</code>, which queues an EXECUTE job for buffer 2.


Convert the G64 with [[G64Conv]] to text representation. The location of the start of track 2 is encoded in the G64 at 0x0014, e.g. pointing to 0x21A6.
<pre>
Check the first two bytes at this location, they are the current track length (low/high).
$0500  20 0A F5  JSR $F50A  ; ROM: find the header of the job's sector, wait for its data block
$0503  4C 10 05  JMP $0510
$0506  A9 E0    LDA #$E0    ; U5 entry: EXECUTE job ...
$0508  A2 02    LDX #$02    ;  ... for buffer 2
$050A  20 7D D5  JSR $D57D
$050D  4C 99 D5  JMP $D599
$0510  88        DEY        ; Y = $FF
$0511  8C 08 18  STY $1808  ; VIA timer 2 low latch
$0514  50 FE    BVC $0514  ; first byte of the data block
$0516  8C 09 18  STY $1809  ; start timer 2 at $FFFF (counts down, 1 MHz)
$0519  B8        CLV
$051A  A2 02    LDX #$02
$051C  A0 44    LDY #$44
$051E  20 26 FE  JSR $FE26  ; ROM: wait for 324 more bytes
$0521  AD 08 18  LDA $1808
$0524  AE 09 18  LDX $1809
$0527  C9 03    CMP #$03
$0529  B0 01    BCS $052C
$052B  E8        INX        ; correct the high byte if the low byte wrapped
$052C  8E 41 05  STX $0541  ; result high
$052F  AA        TAX
$0530  8E 40 05  STX $0540  ; result low
$0533  4C 05 F5  JMP $F505  ; job done
</pre>


Now fill up byte difference in the track trail of track 2 to reach the track length of 0x1EEF with "bytes 55 ..."
The result is the time the drive needs to read '''324 GCR bytes of the
Convert the text representation to G64 and check the track length at e.g. 0x21A6 again, if it is 0x1EEF.
data block''' of that one sector, as a timer value (65535 − µs). It is
neither the track length nor the time between two sync marks.


After track 2 has the correct length, go to track 31. Comment all the fill bytes after the sector header, sector data and in the track trail.
=== C64 side ===
Convert back to G64 and check the track length if it is lower than 0x1753. The pointer to track 31 data is located at 0x00FB in the G64, e.g. pointing to 0x03A3F8.
One might have to add a few bits 111 at the end of track 31 to reach a bit count that is dividable by 8.


Verify if the G64 works.
The check as decompiled from ''Learning English, Green Line 1'' (by Stephan
Scheuer):
 
<pre>
8281 mp=2+bd : m1=11 : m2=57646                :rem pass 1: first test track, sector 11
8294 if m6 then mp=31 : m1=10 : m2=54341      :rem pass 2: track 31, sector 10
8308 open1,8,15,"i" : open2,8,2,"#2"
8329 print#1,"u1 2 0";mp;m1                    :rem read the sector into buffer 2
8347 m6=-(m6=0)
8352 print#2,c$;                              :rem drive code into buffer 2
8356 print#1,"u5"                              :rem run it
8367 print#1,"m-r"chr$(64)chr$(5)chr$(2)      :rem read $0540/$0541
8377 get#1,a$ : get#1,b$
8386 poke 1015,-(abs(asc(a$+chr$(0))+256*asc(b$+chr$(0))-m2)>324) or peek(1015)
8425 if m6 goto 8180                          :rem second pass
</pre>
 
* <code>bd</code> is the volume number, taken from an ID string in the program ("eGL10…" → 1 → track 3).
* The measured value must be within '''±324''' of a fixed reference value:
 
{| class="wikitable"
! Sector !! Reference !! Accepted timer values !! Accepted time for 324 bytes !! Nominal 1541 value
|-
| first test track, sector 11 || 57646 (<code>$E12E</code>, 7,889 µs) || <code>$DFEA</code>–<code>$E272</code> || 7,565–8,213 µs || 8,424 µs (zone 3)
|-
| track 31, sector 10 || 54341 (<code>$D445</code>, 11,194 µs) || <code>$D301</code>–<code>$D589</code> || 10,870–11,518 µs || 10,368 µs (zone 0)
|}
 
* The result goes to <code>$03F7</code> (1015). It is ORed with the previous result, so a failure on either track sticks.
* Both tracks are always measured.
* When the result isn't 0, the program returns to the main menu instead of continuing, for example when the vocabulary test is selected.
* The check runs in several places in the program, for example after menu selections. The two test sectors are read often and therefore wear out quickly, which is why they are often of poor quality in archived dumps.
 
=== Variants ===
 
The drive code, the reference values and the tolerance are the same in all
decompiled releases. Only the BASIC around them differs:
 
* '''First test track''': <code>2+bd</code> (Green Line, Orange Line, Red Line, Let's Go, Etudes Françaises Courte) or fixed 2 (all others).
* '''Result''': ORed into <code>$03F7</code>, or stored without OR. ''ALi 1000 und eins'' stores it in a different location.
* ''Learning English, Modern Course Gym 5'' additionally contains an encrypted machine-code check (at <code>$C800</code>, protected by checksums). It only requires sector 11 to be faster than about 8,180 µs and track 31 sector 10 to be slower than about 10,830 µs.
 
== Releases ==
 
All releases below were checked: the off-speed sectors in the KryoFlux
streams, and the original drive routine run in VICE (true drive emulation)
against the P64 images. Every protected disk shows the pattern described
above. All 47 P64 images of the program disks pass the check.
 
{| class="wikitable"
! First test track !! Releases
|-
| 2 || [[Learning English, Modern Course 1]], [[Learning English, Modern Course 2]], [[Learning English, Modern Course Gym 3]], [[Learning English, Modern Course Gym 4]], [[Learning English, Modern Course Gym 5]], [[Learning English, Modern Course Gym 6]], [[Etudes Francaise Echanges Edition Longue 1]], [[Etudes Francaise Echanges Edition Longue 2]], [[Etudes Francaise Echanges Edition Longue 3]], [[Etudes Francaise Echanges Edition Longue 4]], [[Englische Sprachübungen 2 bis 3]], [[Englische Sprachübungen 4 bis 6]], [[ALi: Das intelligente Algebraprogramm V4]], [[ALi: Das intelligente Algebraprogramm 1000 und eins]], [[Bruchtrainer]], [[GEO]], [[GEO-plus]], [[OPTI-MA]], [[Der neue Rechenmax]]
|-
| 3 || [[Learning English, Green Line 1]], [[Learning English, Orange Line 1]], [[Learning English, Red Line 1]], [[Etudes Francaise Echanges Edition Courte 1]]
|-
| 4 || [[Learning English, Green Line 2]], [[Learning English, Orange Line 2]], [[Learning English, Red Line 2]], [[Let's Go 2]]
|-
| 5 || [[Learning English, Green Line 3]], [[Learning English, Red Line 3]], [[Let's Go 3]]
|-
| 6 || [[Learning English, Green Line 4]], [[Learning English, Red Line 4]]
|-
| 7 || [[Learning English, Red Line 5]], [[Let's Go 5]]
|}
 
The second test track is track 31 on all releases.
 
Notes:
 
* No streams were available for Green Line 2 and Etudes Françaises Longue 3 and 4. Their test track was taken from the G64 images.
* [[OPTI-MA]] source 1: the patch was applied to the side 2 image (<code>…_s1.g64</code>, "OPTI-MA SEITE 2") instead of the program side. The file <code>…_[patched]_s0.g64</code> still has the original track lengths and fails the check.
 
== Copying and imaging ==
 
* A copy made with a normal disk copier rewrites the sectors at the zone's nominal speed. Both measured times are then out of the window (about 8,420 µs and 10,370 µs).
* The KryoFlux streams of the originals pass with a margin of only about 65–150 µs on the fast sector. A drive running more than about 1% slow can therefore fail the check even with an original disk.
* '''P64''' keeps the timing of every sector. All P64 images of the program disks pass in VICE without changes.
* '''G64''' has one bit rate per track in VICE. The emulator spreads the bytes of a track evenly over one revolution, so the measured time depends only on the track length. A converted G64 therefore has to be patched (see below).
 
== Patching G64 images ==
 
Note: the following only makes the check work in an emulator.
 
In VICE, the time for the 324 bytes is about
<code>324 / track length × 200,000 µs + 19 µs</code>. From the
accepted window follow these track lengths:
 
{| class="wikitable"
! Track !! Accepted track length in the G64 !! Recommended !! Measured in VICE
|-
| first test track (2–7) || <code>$1EE5</code> or longer (up to the maximum track size of the G64, usually <code>$1EF8</code>) || <code>$1EEF</code> || 8,191–8,206 µs (limit 8,213 µs)
|-
| track 31 || <code>$1604</code>–<code>$1752</code> || <code>$1710</code> || 10,981–10,996 µs
|}
 
The recommended <code>$1EEF</code> for the first test track passes, but with a
margin of only about 10 µs. The G64's maximum track size doesn't allow a
much longer track unless the header is changed.
 
Procedure with [[G64Conv]]:
 
# Convert the G64 to its text representation.
# The pointer to a track's data is in the G64 header at offset <code>$0C + (track − 1) × 8</code>: <code>$0014</code> for track 2, <code>$00FC</code> for track 31. The first two bytes at the position it points to are the track length (low/high).
# First test track: append fill bytes (<code>55</code>) to the track trail until the length is <code>$1EEF</code>.
# Track 31: comment out fill bytes after the sector headers, the sector data and in the track trail until the length is <code>$1752</code> or less, e.g. <code>$1710</code>. You might have to add a few <code>1</code> bits at the end of the track so that its bit count is divisible by 8.
# Convert back to G64 and check both track lengths again, e.g. with <code>heureka_g64check.py</code> from the analysis archive.
 
When converting from KryoFlux streams or NIBs of a real disk, the first test
track usually comes out too short and track 31 too long. This is the average
of the normal and the off-speed sectors.
 
== See also ==
 
* [[G64Conv]]
* Stephan Scheuer: "Kopierschutzverfahren gelüftet", forum64.de, thread 83037 (description of the protection, decompiled programs and cracks)


==== Pages that refer to this protection ====
==== Pages that refer to this protection ====


{{Special:Whatlinkshere/Heureka}}
{{Special:Whatlinkshere/Heureka}}

Revision as of 15:57, 8 November 2026

Heureka

The Heureka protection was used by Heureka-Teachware on its educational software (Learning English, Let's Go, Etudes Françaises, ALi, GEO, OPTI-MA and others). It was probably developed by Martin Pfost.

The protection doesn't use bad sectors, extra tracks or signatures. On two tracks, three sectors were written at a bit rate that none of the four 1541 speed zones uses. A 1541 reads these sectors without errors. The protection check measures how long the drive needs to read one of these sectors. A copy made with a normal copier writes every sector at the zone's nominal speed, so the measured time is wrong.

The programs are compiled BASIC (Austrospeed). The check is hidden inside the compiled program, and the drive code is stored as a BASIC string.

Disk layout

  • Tracks 1–35 use the ordinary CBM DOS layout.
  • Two tracks contain off-speed sectors:
    • the first test track in speed zone 3: track 2, or 2 + the volume number for the numbered series (see Releases);
    • track 31 in speed zone 0.
  • On both tracks the pattern is the same:
Sector Bit cell compared with the zone's nominal value
10 about 7–8% longer (written slower)
11 about 4% shorter (written faster)
12 about 4% shorter (written faster)
all others nominal
  • The slow and the fast sectors roughly cancel out, so the track length stays close to normal.
  • All other tracks and sectors are nominal.
  • Example from a KryoFlux stream of Learning English, Green Line 1, normalised to 300 rpm:
 Track  3   sector 10 +7.5 %   sector 11 -3.8 %   sector 12 -3.5 %   others nominal
 Track 31   sector 10 +8.0 %   sector 11 -4.0 %   sector 12 -4.0 %   others nominal

Only the program disk is protected. Side 2 of the double-sided releases, and the additional disks of Englische Sprachübungen, have no off-speed sectors.

The check

Drive side

The C64 opens buffer 2 ($0500) and reads the sector to be measured into it with U1. This also sets the track and sector of the buffer's job. It then overwrites the buffer with the drive code (sent as a BASIC string) and starts it with U5. The user vector U5 jumps to $0506, which queues an EXECUTE job for buffer 2.

$0500  20 0A F5  JSR $F50A   ; ROM: find the header of the job's sector, wait for its data block
$0503  4C 10 05  JMP $0510
$0506  A9 E0     LDA #$E0    ; U5 entry: EXECUTE job ...
$0508  A2 02     LDX #$02    ;   ... for buffer 2
$050A  20 7D D5  JSR $D57D
$050D  4C 99 D5  JMP $D599
$0510  88        DEY         ; Y = $FF
$0511  8C 08 18  STY $1808   ; VIA timer 2 low latch
$0514  50 FE     BVC $0514   ; first byte of the data block
$0516  8C 09 18  STY $1809   ; start timer 2 at $FFFF (counts down, 1 MHz)
$0519  B8        CLV
$051A  A2 02     LDX #$02
$051C  A0 44     LDY #$44
$051E  20 26 FE  JSR $FE26   ; ROM: wait for 324 more bytes
$0521  AD 08 18  LDA $1808
$0524  AE 09 18  LDX $1809
$0527  C9 03     CMP #$03
$0529  B0 01     BCS $052C
$052B  E8        INX         ; correct the high byte if the low byte wrapped
$052C  8E 41 05  STX $0541   ; result high
$052F  AA        TAX
$0530  8E 40 05  STX $0540   ; result low
$0533  4C 05 F5  JMP $F505   ; job done

The result is the time the drive needs to read 324 GCR bytes of the data block of that one sector, as a timer value (65535 − µs). It is neither the track length nor the time between two sync marks.

C64 side

The check as decompiled from Learning English, Green Line 1 (by Stephan Scheuer):

8281 mp=2+bd : m1=11 : m2=57646                :rem pass 1: first test track, sector 11
8294 if m6 then mp=31 : m1=10 : m2=54341       :rem pass 2: track 31, sector 10
8308 open1,8,15,"i" : open2,8,2,"#2"
8329 print#1,"u1 2 0";mp;m1                    :rem read the sector into buffer 2
8347 m6=-(m6=0)
8352 print#2,c$;                               :rem drive code into buffer 2
8356 print#1,"u5"                              :rem run it
8367 print#1,"m-r"chr$(64)chr$(5)chr$(2)       :rem read $0540/$0541
8377 get#1,a$ : get#1,b$
8386 poke 1015,-(abs(asc(a$+chr$(0))+256*asc(b$+chr$(0))-m2)>324) or peek(1015)
8425 if m6 goto 8180                           :rem second pass
  • bd is the volume number, taken from an ID string in the program ("eGL10…" → 1 → track 3).
  • The measured value must be within ±324 of a fixed reference value:
Sector Reference Accepted timer values Accepted time for 324 bytes Nominal 1541 value
first test track, sector 11 57646 ($E12E, 7,889 µs) $DFEA–$E272 7,565–8,213 µs 8,424 µs (zone 3)
track 31, sector 10 54341 ($D445, 11,194 µs) $D301–$D589 10,870–11,518 µs 10,368 µs (zone 0)
  • The result goes to $03F7 (1015). It is ORed with the previous result, so a failure on either track sticks.
  • Both tracks are always measured.
  • When the result isn't 0, the program returns to the main menu instead of continuing, for example when the vocabulary test is selected.
  • The check runs in several places in the program, for example after menu selections. The two test sectors are read often and therefore wear out quickly, which is why they are often of poor quality in archived dumps.

Variants

The drive code, the reference values and the tolerance are the same in all decompiled releases. Only the BASIC around them differs:

  • First test track: 2+bd (Green Line, Orange Line, Red Line, Let's Go, Etudes Françaises Courte) or fixed 2 (all others).
  • Result: ORed into $03F7, or stored without OR. ALi 1000 und eins stores it in a different location.
  • Learning English, Modern Course Gym 5 additionally contains an encrypted machine-code check (at $C800, protected by checksums). It only requires sector 11 to be faster than about 8,180 µs and track 31 sector 10 to be slower than about 10,830 µs.

Releases

All releases below were checked: the off-speed sectors in the KryoFlux streams, and the original drive routine run in VICE (true drive emulation) against the P64 images. Every protected disk shows the pattern described above. All 47 P64 images of the program disks pass the check.

First test track Releases
2 Learning English, Modern Course 1, Learning English, Modern Course 2, Learning English, Modern Course Gym 3, Learning English, Modern Course Gym 4, Learning English, Modern Course Gym 5, Learning English, Modern Course Gym 6, Etudes Francaise Echanges Edition Longue 1, Etudes Francaise Echanges Edition Longue 2, Etudes Francaise Echanges Edition Longue 3, Etudes Francaise Echanges Edition Longue 4, Englische Sprachübungen 2 bis 3, Englische Sprachübungen 4 bis 6, ALi: Das intelligente Algebraprogramm V4, ALi: Das intelligente Algebraprogramm 1000 und eins, Bruchtrainer, GEO, GEO-plus, OPTI-MA, Der neue Rechenmax
3 Learning English, Green Line 1, Learning English, Orange Line 1, Learning English, Red Line 1, Etudes Francaise Echanges Edition Courte 1
4 Learning English, Green Line 2, Learning English, Orange Line 2, Learning English, Red Line 2, Let's Go 2
5 Learning English, Green Line 3, Learning English, Red Line 3, Let's Go 3
6 Learning English, Green Line 4, Learning English, Red Line 4
7 Learning English, Red Line 5, Let's Go 5

The second test track is track 31 on all releases.

Notes:

  • No streams were available for Green Line 2 and Etudes Françaises Longue 3 and 4. Their test track was taken from the G64 images.
  • OPTI-MA source 1: the patch was applied to the side 2 image (…_s1.g64, "OPTI-MA SEITE 2") instead of the program side. The file …_[patched]_s0.g64 still has the original track lengths and fails the check.

Copying and imaging

  • A copy made with a normal disk copier rewrites the sectors at the zone's nominal speed. Both measured times are then out of the window (about 8,420 µs and 10,370 µs).
  • The KryoFlux streams of the originals pass with a margin of only about 65–150 µs on the fast sector. A drive running more than about 1% slow can therefore fail the check even with an original disk.
  • P64 keeps the timing of every sector. All P64 images of the program disks pass in VICE without changes.
  • G64 has one bit rate per track in VICE. The emulator spreads the bytes of a track evenly over one revolution, so the measured time depends only on the track length. A converted G64 therefore has to be patched (see below).

Patching G64 images

Note: the following only makes the check work in an emulator.

In VICE, the time for the 324 bytes is about 324 / track length × 200,000 µs + 19 µs. From the accepted window follow these track lengths:

Track Accepted track length in the G64 Recommended Measured in VICE
first test track (2–7) $1EE5 or longer (up to the maximum track size of the G64, usually $1EF8) $1EEF 8,191–8,206 µs (limit 8,213 µs)
track 31 $1604–$1752 $1710 10,981–10,996 µs

The recommended $1EEF for the first test track passes, but with a margin of only about 10 µs. The G64's maximum track size doesn't allow a much longer track unless the header is changed.

Procedure with G64Conv:

  1. Convert the G64 to its text representation.
  2. The pointer to a track's data is in the G64 header at offset $0C + (track − 1) × 8: $0014 for track 2, $00FC for track 31. The first two bytes at the position it points to are the track length (low/high).
  3. First test track: append fill bytes (55) to the track trail until the length is $1EEF.
  4. Track 31: comment out fill bytes after the sector headers, the sector data and in the track trail until the length is $1752 or less, e.g. $1710. You might have to add a few 1 bits at the end of the track so that its bit count is divisible by 8.
  5. Convert back to G64 and check both track lengths again, e.g. with heureka_g64check.py from the analysis archive.

When converting from KryoFlux streams or NIBs of a real disk, the first test track usually comes out too short and track 31 too long. This is the average of the normal and the off-speed sectors.

See also

  • G64Conv
  • Stephan Scheuer: "Kopierschutzverfahren gelüftet", forum64.de, thread 83037 (description of the protection, decompiled programs and cracks)

Pages that refer to this protection