-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc95.asm
516 lines (447 loc) · 9.07 KB
/
gc95.asm
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
title Windows CD Key Generator
type 8521
NLIST
include equates.inc
include memory.inc
LIST
program
db 04h
db 40h
dw Entry
db 00000011b
dm 'TigerDMGC'
db 21h
db 85
db 44
dm 'W95KeyGen'
dw 0000h
db 00h
db 0
dw 0
Entry:
clr r0
cmp r2,#ini_game
br eq,RetStub
cmp r2,#exe_game
jmp eq,GameExe
cmp r2,#close_game
br eq,RetStub
cmp r2,#reset_game
br eq,RetStub
mov r0,#0ffh
ret
RetStub:
ret
GameExe:
; draw windows 95 screensaver
mov r8,#0
mov r9,#0
mov r10,#0
mov r11,#0
mov r12,#200
mov r13,#160
mov r14,#21h
mov r15,#0
call Fi_graph
; play sound
mov r1,#8
movw rr2,#2000h
call SND_ADDR
mov r0,#5
call CTRL_SP
; delay for 2 seconds
mov r2,#10
delay_loop:
call Delay200ms
dec r2
br nz,delay_loop
; stop speech
call Speech_Stop
; clear screen
call Cls_scn
; draw title
mov r8,#38
mov r9,#16
mov r10,#0
mov r11,#160
mov r12,#123
mov r13,#30
mov r14,#21h
mov r15,#0
call Fi_graph
; draw button
mov r8,#68
mov r9,#116
mov r10,#123
mov r11,#160
mov r12,#64
mov r13,#24
mov r14,#21h
mov r15,#0
call Fi_graph
; draw dash
mov r8,#60
mov r9,#78
mov r10,#8
mov r11,#3
mov r12,#4
clr r13
call Draw_line_h
; draw blank license
clr r9
clr r10
clr r11
call DrawLicA
clr r9
clr r10
clr r11
clr r12
clr r13
clr r14
clr r15
call DrawLicB
movw rr2,#0
main_loop:
incw rr2
call SCAN_KEY
; touched button
cmp r0,#13*7+5
br eq,generate
cmp r0,#13*7+6
br eq,generate
cmp r0,#13*7+7
br eq,generate
cmp r0,#13*7+8
br eq,generate
cmp r0,#13*7+9
br eq,generate
cmp r0,#13*8+5
br eq,generate
cmp r0,#13*8+6
br eq,generate
cmp r0,#13*8+7
br eq,generate
cmp r0,#13*8+8
br eq,generate
cmp r0,#13*8+9
br eq,generate
jmp main_loop
generate:
; draw pressed button
mov r8,#68
mov r9,#116
mov r10,#187
mov r11,#160
mov r12,#64
mov r13,#24
mov r14,#21h
mov r15,#0
call Fi_graph
; play click
call Short_Beep
; seed the rng
call SeedRng
; generate and draw license
call GenLicA
call DrawLicA
call GenLicB
call DrawLicB
; draw regular button
mov r8,#68
mov r9,#116
mov r10,#123
mov r11,#160
mov r12,#64
mov r13,#24
mov r14,#21h
mov r15,#0
call Fi_graph
jmp main_loop
ret
DrawLicA:
push r11
push r10
push r9
; 1st digit
mov r8,#4
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 2nd digit
mov r8,#22
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 3rd digit
mov r8,#40
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
ret
DrawLicB:
push r15
push r14
push r13
push r12
push r11
push r10
push r9
; 1st digit
mov r8,#72
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 2nd digit
mov r8,#90
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 3rd digit
mov r8,#108
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 4th digit
mov r8,#126
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 5th digit
mov r8,#144
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 6th digit
mov r8,#162
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
; 7th digit
mov r8,#180
mov r9,#72
mov r10,#200
pop r11
swap r11
mov r12,#16
mov r13,#16
mov r14,#21h
mov r15,#0
call Fi_graph
ret
; seeds rng with counter
SeedRng:
movw rr0,state01
addw state23,rr0
addw state01,rr2
ret
; returns 8-bit pseudorandom value in r8
RandNum:
push r9
pushw rr10
pushw rr12
pushw rr14
; retrieve state from memory
movw rr10,state01
movw rr12,state23
; r8 = state0 ^ (state0 << 4)
mov r9,r10
mov r8,r10
and r9,#0fh
swap r9
xor r8,r9
; state0 = state1, state1 = state2, state2 = state3
mov r10,r11
mov r11,r12
mov r12,r13
; r8 = r8 ^ state3 ^ (state3 >> 1) ^ (r8 << 1)
mov r14,r12
mov r15,r8
srl r14
sll r15
xor r8,r12
xor r8,r14
xor r8,r15
; state3 = r8
mov r13,r8
; store state to memory
movw state01,rr10
movw state23,rr12
popw rr14
popw rr12
popw rr10
pop r9
ret
; generates 1st part of license key
GenLicA:
; 1st digit
call RandNum
mov r9,r8
and r9,#0fh
cmp r9,#10
br lt,adig2
sub r9,#6
adig2:
; 2nd digit
call RandNum
mov r10,r8
and r10,#0fh
cmp r10,#10
br lt,adig3
sub r10,#6
adig3:
; 3rd digit
call RandNum
mov r11,r8
and r11,#0fh
cmp r11,#10
br lt,mul_check
sub r11,#6
mul_check:
; increment/decrement if all numbers equal
cmp r9,r10
br ne,gen_done
cmp r10,r11
br ne,gen_done
cmp r11,#9
br eq,decrem
inc r11
br gen_done
decrem:
dec r11
gen_done:
ret
; generates 2nd part of license key
GenLicB:
; 1st digit
call RandNum
mov r9,r8
and r9,#0fh
cmp r9,#10
br lt,bdig2
sub r9,#6
bdig2:
; 2nd digit
call RandNum
mov r10,r8
and r10,#0fh
cmp r10,#10
br lt,bdig3
sub r10,#6
bdig3:
; 3rd digit
call RandNum
mov r11,r8
and r11,#0fh
cmp r11,#10
br lt,bdig4
sub r11,#6
bdig4:
; 4th digit
call RandNum
mov r12,r8
and r12,#0fh
cmp r12,#10
br lt,bdig5
sub r12,#6
bdig5:
; 5th digit
call RandNum
mov r13,r8
and r13,#0fh
cmp r13,#10
br lt,bdig6
sub r13,#6
bdig6:
; 6th digit
call RandNum
mov r14,r8
and r14,#0fh
cmp r14,#10
br lt,bdig7
sub r14,#6
bdig7:
; 7th digit
call RandNum
mov r15,r8
and r15,#7
inc r15
cmp r15,#8
br ne,check_acc
dec r15
check_acc:
; add up license key digits
movw rr4,#0
add r4,r9
add r4,r10
add r4,r11
add r4,r12
add r4,r13
add r4,r14
add r4,r15
; check mod 7
movw rr6,#7
div rr4,rr6
cmp r6,#0
jmp ne,GenLicB
ret
Delay200ms:
movw rr0,#0f000h
d200_loop:
decw rr0
br nz,d200_loop
ret
end