Difference between revisions of "Programming:Unlocking ASIC"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
m (Urusergi version)
(Patent)
 
(24 intermediate revisions by 3 users not shown)
Line 8: Line 8:
  
 
Once the ASIC is unlocked, we get access to a new [[Gate Array]] register called RMR2. It is accessible in the same way as other Gate Array registers.
 
Once the ASIC is unlocked, we get access to a new [[Gate Array]] register called RMR2. It is accessible in the same way as other Gate Array registers.
 +
 +
Locking the ASIC again doesn't disable any of its functionality, it just prevents you changing it. [https://www.cpcwiki.eu/forum/programming/asm-source-code/msg249856/#msg249856 Source]
  
 
<br>
 
<br>
Line 65: Line 67:
 
== [[Madram]] version ==
 
== [[Madram]] version ==
  
In Z80 Assembler:
+
It still uses some magic numbers.
 +
 
 
<pre>
 
<pre>
UnlockAsic
 
 
di
 
di
 
ld bc,#BCFF
 
ld bc,#BCFF
Line 74: Line 76:
 
ld hl,%1001000011101010
 
ld hl,%1001000011101010
  
.loop
+
loop:
 
out (c),c
 
out (c),c
 
ld a,h:rlca:ld h,l:ld l,a
 
ld a,h:rlca:ld h,l:ld l,a
Line 81: Line 83:
 
ld c,a
 
ld c,a
 
cp #4D
 
cp #4D
jr nz,.loop
+
jr nz,loop
  
ld a,#CD     ; a=#CD for unlock, another value for lock
+
ld a,#CD ; a = #CD for unlock, another value for lock
 
out (c),a:out (c),a
 
out (c),a:out (c),a
 
ei
 
ei
Line 89: Line 91:
 
</pre>
 
</pre>
  
In Python:
+
== [[Urusergi]] version ==
<pre>
+
def unlock_asic():
+
    b, c, h, l = 0xBC, 0xFF, 0x90, 0xEA  # Initialize registers
+
    port_out(b, c)
+
    port_out(b, 0)
+
  
    while c != 0x4D:
+
No magic numbers here.
        port_out(b, c)
+
        h, l = l, ((h << 1) | (h >> 7)) & 0xFF  # Rotate h and swap h,l
+
        c = ((c >> 1) & ~(1 << 3)) | (l & 0x88)  # Modify c
+
  
    port_out(b, 0xCD)
 
    port_out(b, 0xCD)
 
 
def port_out(port, value):
 
    print(f"Port: {hex(port)}xx Out: {hex(value)}")
 
 
unlock_asic()
 
</pre>
 
 
== [[Urusergi]] version ==
 
In Z80 Assembler:
 
 
<pre>
 
<pre>
di ; v2.0 -> 31 bytes!
+
di ; v3.1 -> 30 bytes!
 
ld bc,#BCFF
 
ld bc,#BCFF
 
out (c),c
 
out (c),c
out (c),0
+
out (c),0 ; db #ED,#71
 
ld a,c
 
ld a,c
  
.loop
+
loop:
 
out (c),a
 
out (c),a
ld h,a ; H = 7654 3210
+
ld h,a ; h = 7654 3210
add hl,hl ; H = 6543 210-
+
add hl,hl ; h = 6543 210*
push af ; Carry flag (bit 7) preserved
+
rra ; a = 7765 4321
add hl,hl ; H = 5432 10--
+
add hl,hl ; h = 5432 10**
add hl,hl ; H = 4321 0---
+
xor h:and #F7:xor h ; a = 7765 1321
rra ; A = 5765 4321
+
ld l,a ; l = 7765 1321
ld l,a ; L = 5765 4321
+
ld a,h ; a = 5432 10**
pop af ; Carry flag (bit 7) recovered
+
rla ; a = 4321 0***
ld a,h ; A = 4321 0---
+
and #88:xor l ; a = (7 xor 4)765 (1 xor 0)321
rra ; A = 7432 10--
+
xor h ; A = (7 xor 4)*** (1 xor 0)***
+
xor l:and #88:xor l ; A = (7 xor 4)765 (1 xor 0)321
+
 
cp c
 
cp c
jr nz,.loop
+
jr nz,loop
  
 
ei
 
ei
Line 140: Line 120:
 
</pre>
 
</pre>
  
In Python:
+
== Algorithm ==
 +
 
 
<pre>
 
<pre>
 
def unlock_asic():
 
def unlock_asic():
 
     b, c = 0xBC, 0xFF
 
     b, c = 0xBC, 0xFF
     port_out(b, c)
+
     out(b, c)
     port_out(b, 0)
+
     out(b, 0)
 
     a = c
 
     a = c
 
      
 
      
 
     while True:
 
     while True:
         port_out(b, a)
+
         out(b, a)
         d = a
+
         # a = (7 xor 4)765 (1 xor 0)321
         a = (((a << 2 | a >> 6) ^ d) & 0x7F) ^ d
+
         a = ((a >> 1) & 0x77) | ((a ^ (a << 3)) & 0x80) | (((a << 2) ^ (a << 3)) & 0x08)
        d = (d >> 1 | d << 7) & 0xFF
+
        a = ((((a << 1 | a >> 7) ^ a) ^ d) & 0x88) ^ d
+
 
         if a == c: break
 
         if a == c: break
  
def port_out(port, value):
+
def out(port, value):
     print(f"Port: {hex(port)}xx Out: {hex(value)}")
+
     print(f"Port: {hex(port)}xx Out: {hex(value)}")
  
 
unlock_asic()
 
unlock_asic()
Line 175: Line 154:
  
 
= Patent =
 
= Patent =
For one reason or another, Amstrad has patented the verification mechanism ([[Media:Patent GB2243701A.pdf|GB2243701A]]).
+
For one reason or another, Amstrad has patented the verification mechanism ([[Media:Patent GB2243701A.pdf|GB2243701A]]). The patent seems to focus on ''verifying'' (rather than on ''sending'') the sequence, so its legal use is a bit unclear.
 
+
The patent seems to focus on ''verifying'' (rather than on ''sending'') the sequence, so its legal use is a bit unclear.
+
  
 
On the [[Original Arnold V Specs]] - Issue 1.5 - 10th April 1990, it is precised at §2.11 "Locking of enhanced features":
 
On the [[Original Arnold V Specs]] - Issue 1.5 - 10th April 1990, it is precised at §2.11 "Locking of enhanced features":
Line 184: Line 161:
 
</code>
 
</code>
  
 +
According to [https://patents.google.com/patent/GB2243701A/en Google patents for GB2243701A] the patent was withdrawn on 1994-12-21. This means that this particular patent cannot be enforced.
 
<br>
 
<br>
  
 
[[Category:Programming]]
 
[[Category:Programming]]
 
[[Category:CPC Plus]]
 
[[Category:CPC Plus]]

Latest revision as of 04:59, 9 April 2025

To unlock the ASIC, a 17-byte "unlock" sequence must be sent to the CRTC's selection port (&BC00) : RQ00, 0, 255, 119, 179, 81, 168, 212, 98, 57, 156, 70, 43, 21, 138, STATE, <ACQ>

  • RQ00 must be different from the value 0.
  • STATE=205 for UNLOCK otherwise another value for LOCK.
  • ACQ represents sending any value if STATE=205 (not needed otherwise).

Note: the ASIC is already unlocked after the STATE phase, before ACQ. So ACQ is actually never needed.

Once the ASIC is unlocked, we get access to a new Gate Array register called RMR2. It is accessible in the same way as other Gate Array registers.

Locking the ASIC again doesn't disable any of its functionality, it just prevents you changing it. Source


BASIC version

10 RESTORE 
20 FOR x=0 TO 16:READ a:OUT &BC00,a:NEXT 
30 DATA 255,0,255,119,179,81,168,212,98,57,156,70,43,21,138,205,238 
40 PRINT"ASIC unlocked!"


Z80 Assembler version

;; This example shows how to unlock the ASIC
;;
;; This example is designed for CPC+ only and will
;; not work on CPC or KC Compact.
;;
;; This example will compile with the MAXAM assembler
;; or the built-in assembler of WinAPE32.

org &8000

;;--------------------------------------------------
;; Unlock CPC+ additional features

di
ld b,&bc
ld hl,sequence
ld e,17

.seq 
ld a,(hl)
out (c),a
inc hl
dec e
jr nz,seq

ei
ret

;;----------------------------------------------------------
;; this is the sequence to unlock the ASIC extra features
.sequence
defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee


Optimized versions

The unlocking sequence can be reconstituted from simple bit operations instead of being stored in memory.

Madram version

It still uses some magic numbers.

di
ld bc,#BCFF
out (c),c
out (c),0
ld hl,%1001000011101010

loop:
out (c),c
ld a,h:rlca:ld h,l:ld l,a
srl c
xor c:and #88:xor c
ld c,a
cp #4D
jr nz,loop

ld a,#CD		; a = #CD for unlock, another value for lock
out (c),a:out (c),a
ei
ret

Urusergi version

No magic numbers here.

di			; v3.1 -> 30 bytes!
ld bc,#BCFF
out (c),c
out (c),0		; db #ED,#71
ld a,c

loop:
out (c),a
ld h,a			; h = 7654 3210
add hl,hl		; h = 6543 210*
rra			; a = 7765 4321
add hl,hl		; h = 5432 10**
xor h:and #F7:xor h	; a = 7765 1321
ld l,a			; l = 7765 1321
ld a,h			; a = 5432 10**
rla			; a = 4321 0***
and #88:xor l		; a = (7 xor 4)765 (1 xor 0)321
cp c
jr nz,loop

ei
ret

Algorithm

def unlock_asic():
    b, c = 0xBC, 0xFF
    out(b, c)
    out(b, 0)
    a = c
    
    while True:
        out(b, a)
        # a = (7 xor 4)765 (1 xor 0)321
        a = ((a >> 1) & 0x77) | ((a ^ (a << 3)) & 0x80) | (((a << 2) ^ (a << 3)) & 0x08)
        if a == c: break

def out(port, value):
    print(f"Port: {hex(port)}xx  Out: {hex(value)}")

unlock_asic()


Visual representation

As one may see, the nybbles in the sequence are based on two 4bit shift registers.

AsicUnlockSequence.png

Visual by Hwikaa


Patent

For one reason or another, Amstrad has patented the verification mechanism (GB2243701A). The patent seems to focus on verifying (rather than on sending) the sequence, so its legal use is a bit unclear.

On the Original Arnold V Specs - Issue 1.5 - 10th April 1990, it is precised at §2.11 "Locking of enhanced features": it should be noted that unauthorised use of this mechanism may infringe Amstrad's patent.

According to Google patents for GB2243701A the patent was withdrawn on 1994-12-21. This means that this particular patent cannot be enforced.