jmechner
100755 292 lines (241 sloc) 3.811 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
* yellow.main
 lst off

* The job of this routine is to
* set the high-bit of $7C in aux zpage.
* (It does it by rotating in a carry set)

slot = $fd
lastrack = $ff

*-------------------------------------------------
*
* HLS APPLE COPY PROTECTION
* COPYRIGHT (C) 1987 HLS DUPLICATION
*
* Modified by Roland Gustafsson 8/25/89
* for Prince of Persia copy protection.
*
*-------------------------------------------------

OBJSCT = $07 ;PHYSICAL SECTOR #

* ZERO PAGE

HDRC = $30
HDRS = HDRC+1
HDRT = HDRC+2
HDRV = HDRC+3 HEADER SECTOR
LSRETRY = HDRC+4 ;NIB READ RETRIES
PRETRY = HDRC+5 ;OBJSCT RETRIES
NPTR = HDRC+6
NPTRH = HDRC+7
MEM1 = HDRC+8
MEM2 = HDRC+9

zpage = HDRC
zpagelen = 33 ;arbitrarily long (only needs 10)

*-------------------------------------------------

* Jordan says: use $A400-ABFF
* Roland says: OK

orgCHECK = $AAAA ;must be highbyte=lowbyte

 org $2000

 da lenCHECK

 dum $A4A4
zpagebuf ds zpagelen
was27 ds 3 ;should be 1 !!!
was2A ds 5 ; ditto
was26 ds 7 ; ditto again
 dend

 org orgCHECK

*-------------------------------------------------

start sta $C008 ;switch to main zpage

 ldx slot
 lda $C089,x ;drive on

 jsr swapzpage

* First seek track zero

 lda #0
 jsr SEEK

* Now check signature

 lda #10
 sta LSRETRY
 ldx slot
 lda $C08E,X
 lda #>:NIBS
 sta NPTRH
 lda #:NIBS
 sta NPTR

:AGAIN lda #$80
 sta PRETRY
:M1 dec PRETRY
 beq :LSFAIL
 jsr RADR16
 bcs :LSFAIL
 lda HDRS
 cmp #OBJSCT
 bne :M1

 ldy #0
:M2 lda $C08C,X
 bpl :M2
 dey
 beq :LSFAIL
 cmp #$D5
 bne :M2
 ldy #0

:M3 lda $C08C,X
 bpl :M3
 dey
 beq :LSFAIL
 cmp #$E7
 bne :M3

:M4 lda $C08C,X
 bpl :M4
 cmp #$E7
 bne :LSFAIL

:M5 lda $C08C,X
 bpl :M5
 cmp #$E7
 bne :LSFAIL

 lda $C08D,X
 ldy #$10
 bit $6 ;3 US. ( FOR //C)
:M6 lda $C08C,X
 bpl :M6
 dey
 beq :LSFAIL
 cmp #$EE
 bne :M6

* NOW AT 1/2 NIBBLES

 ldy #7
:M7 lda $C08C,X * READ DISK DATA
 bpl :M7
 cmp (NPTR),Y * COMPARE AGAINST TABLE
 bne :LSFAIL
 dey
 bpl :M7
 bmi :GOOD
:LSFAIL jmp :LSFAIL1

* A O K

:GOOD jsr swapzpage
 sta $C009-zpagelen,x
 ror $7C-zpagelen,x
 clc
 rts

* FAILED

:LSFAIL1 dec LSRETRY
 beq :ERROR
 jmp :AGAIN

:NIBS db $FC,$EE,$EE,$FC
 db $E7,$EE,$FC,$E7

:ERROR jsr swapzpage
 sta $C009-zpagelen,x
 rts

*-------------------------------------------------
*
* Read address mark
*

RADR16 ldy #$FD
 sty MEM1
:RA1 iny
 bne :RA2
 inc MEM1
 beq :RAEXIT
:RA2 lda $C08C,X
 bpl :RA2
:RA3 cmp #$D5
 bne :RA1
 nop
:RA4 lda $C08C,X
 bpl :RA4
 cmp #$AA
 bne :RA3
 ldy #3
:RA5 lda $C08C,X
 bpl :RA5
 cmp #$96
 bne :RA3
 lda #0
:RA6 sta MEM2
:RA7 lda $C08C,X
 bpl :RA7
 rol
 sta MEM1
:RA8 lda $C08C,X
 bpl :RA8
 and MEM1
 sta HDRC,Y
 eor MEM2
 dey
 bpl :RA6
 tay
 nop
 clc
 rts

:RAEXIT sec
 rts

*-------------------------------------------------
*
* SEEK, a - track
*

SEEK4 lda #4
SEEK sta was2A
 cmp lastrack
 beq :RTS0
 lda #0
 sta was26
:MOVEHEAD lda lastrack
 sta was27
 sec
 sbc was2A
 beq :ISTHERE
 bcs :T0
 eor #$FF
 inc lastrack
 bcc :T1
:T0 adc #$FE
 dec lastrack
:T1 cmp was26
 bcc :T2
 lda was26
:T2 cmp #$C
 bcs :T3
 tay
:T3 sec
 jsr :CHKPOS
 lda ONTBL,Y
 jsr :MSWAIT
 lda was27
 clc
 jsr :CHKPOS2
 lda OFFTBL,Y
 jsr :MSWAIT
 inc was26
 bne :MOVEHEAD
:ISTHERE jsr :MSWAIT
 clc
:CHKPOS lda lastrack
:CHKPOS2 and #3
 rol
 ora slot
 tax
 lda $C080,X
 ldx slot
:RTS0 rts

:MSWAIT ldx #$12
:T21 dex
 bne :T21
 sec
 sbc #1
 bne :MSWAIT
 rts

*-------------------------------------------------

swapzpage ldx #0
:0 ldy zpagebuf,x
 lda zpage,x
 sty zpage,x
 sta zpagebuf,x
 inx
 cpx #zpagelen
 bne :0
 rts

*-------------------------------------------------

ONTBL db $01,$30,$28,$24,$20,$1E,$1D,$1C,$1C,$1C,$1C,$1C
OFFTBL db $70,$2C,$26,$22,$1F,$1E,$1D,$1C,$1C,$1C,$1C,$1C,$FF,$03

*-------------------------------------------------
lenCHECK = *-orgCHECK

 org

*------------------------------------------------- EOF

 sav yellow.main

Markdown Cheat Sheet

Format Text

Headers

# This is an <h1> tag
## This is an <h2> tag
###### This is an <h6> tag

Text styles

*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__

*You **can** combine them*

Lists

Unordered

* Item 1
* Item 2
  * Item 2a
  * Item 2b

Ordered

1. Item 1
2. Item 2
3. Item 3
   * Item 3a
   * Item 3b

Miscellaneous

Images

![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)

Links

http://github.com - automatic!
[GitHub](http://github.com)

Blockquotes

As Kanye West said:

> We're living the future so
> the present is our past.

Code Examples in Markdown

Syntax highlighting with GFM

```javascript
function fancyAlert(arg) {
  if(arg) {
    $.facebox({div:'#foo'})
  }
}
```

Or, indent your code 4 spaces

Here is a Python code example
without syntax highlighting:

    def foo:
      if not bar:
        return true

Inline code for comments

I think you should use an
`<addr>` element here instead.

Something went wrong with that request. Please try again. Dismiss

Looking for the GitHub logo?