1864
|
1
|
|
2 NAM Score
|
|
3 TTL Routines to handle high score recording
|
|
4
|
|
5 * Program segment to be compiled using Level II RMA
|
|
6 * This is not a mainline program segment
|
|
7 * Written by Larry Olson
|
|
8
|
|
9 IFP1
|
|
10 * use /dd/defs/os9defs.a
|
|
11 ENDc
|
|
12
|
|
13 STACK EQU 100
|
|
14
|
|
15 PSECT SCORE,0,0,2,STACK,SBEGIN
|
|
16
|
|
17 VSECT
|
|
18
|
|
19 * Local Variables
|
|
20
|
|
21 FPATH: rmb 1 File path number
|
|
22 FSCORE: rmb 126 Names & scores put here
|
|
23 PNAME: rmb 15 Players name
|
|
24 NAMLGH rmb 2 Number of characters in name
|
|
25 ENTCNT rmb 1 Entry counter
|
|
26 ENTPNT rmb 2 Pointer to start of entry
|
|
27 COUNT rmb 1
|
|
28 SAVEX rmb 2
|
|
29 CURPOS rmb 3
|
|
30
|
|
31 rmb STACK
|
|
32
|
|
33 ENDSECT
|
|
34
|
|
35 FILLST: fcc '/dd/sys/pac_scores'
|
|
36
|
|
37 WRTNBY fcb 2,37,33,87,114,105,116,116
|
|
38 fcb 101,110,32,66,121,$1b,$32,1,2
|
|
39 fcb 35,36,76,97,114,114,121,32
|
|
40 fcb 69,46,32,79,108,115,111,110
|
|
41
|
|
42 LDGSCR fcb 2,33,34,76,111,97,100,105,110
|
|
43 fcb 103,32,72,105,103,104,32,83
|
|
44 fcb 99,111,114,101,115
|
|
45
|
|
46 ENTNAM fcb $1b,$32,1,$1b,$33,0,$0c,2,33,33
|
|
47 fcb 80,76,69,65,83,69,32
|
|
48 fcb 69,78,84,69,82,32,89,79
|
|
49 fcb 85,82,32,78,65,77,69,32
|
|
50
|
|
51 ARROW fcb $1b,$32,2,2,34,35,45,45,62
|
|
52 fcb 32,$1b,$32,3,95,2,38,35
|
|
53
|
|
54 QUESTN fcb $1b,$32,9,2,32,35,32,73,115,32
|
|
55 fcb 78,97,109,101,32,67,111,114,114
|
|
56 fcb 101,99,116,32,40,89,47,78,41,32,63
|
|
57 fcb 2,55,35
|
|
58
|
|
59 CONGRT fcb 2,37,33,$1b,$32,2,67,79,78
|
|
60 fcb 71,82,65,84,85,76,65,84,73
|
|
61 fcb 79,78,83,$1b,$32,4,2,38,35
|
|
62
|
|
63 NOTFND fcb $0c,$1b,$32,4,2,37,32,83,99,111
|
|
64 fcb 114,101,32,70,105,108,101,$1b,$32
|
|
65 fcb 2,2,34,34,47,100,100,47,115,121
|
|
66 fcb 115,47,112,97,99,95,115,99,111
|
|
67 fcb 114,101,115,$1b,$32,4,2,38,36
|
|
68 fcb 78,79,84,32,70,79,85,78,68
|
|
69
|
|
70 CREATE fcb 2,38,36,32,32,32,32,32,32,32,32
|
|
71 fcb 32,2,37,36,67,114,101,97,116
|
|
72 fcb 105,110,103,32,73,116
|
|
73
|
|
74 CHGWK1 fcb $1b,$25,0,0,40,24
|
|
75 fcb $1b,$33,7
|
|
76
|
|
77 CHGWK2 fcb $1b,$25,8,9,22,7,2,32,32
|
|
78
|
|
79 CRLF fcb $0d,$0a
|
|
80
|
|
81 CLRSCN fcb $0c
|
|
82
|
|
83 CURXY1 fcb 2,32,32
|
|
84
|
|
85 CURXY2 fcb $0c,2,38,33,$1b,$32,4
|
|
86
|
|
87 CLNORM fcb $1b,$32,2,$1b,$33,0
|
|
88
|
|
89 CLINVT fcb $1b,$32,4,$1b,$33,0
|
|
90
|
|
91 CLNRM2 fcb $1b,$32,2,$1b,$33,0
|
|
92
|
|
93
|
|
94 SBEGIN: leax SCRBOX,pcr
|
|
95 ldy #39
|
|
96 lbsr OUTST2
|
|
97 leax WRTNBY,pcr
|
|
98 ldy #33
|
|
99 lbsr OUTST2
|
|
100 ldx #200
|
|
101 lbsr WAIT
|
|
102 leax CLRSCN,pcr
|
|
103 ldy #1
|
|
104 lbsr OUTST2
|
|
105 leax LDGSCR,pcr
|
|
106 ldy #22
|
|
107 lbsr OUTST2
|
|
108 ldx #75
|
|
109 lbsr WAIT
|
|
110
|
|
111 OPENFL lda #1 Set for read
|
|
112 leax FILLST,pcr Point to pathlist
|
|
113 os9 I$Open Open file
|
|
114 lbcs OPNERR Go handle any errors
|
|
115 sta FPATH,U
|
|
116 READFL leax FSCORE,U Point to data storage area
|
|
117 ldy #126 Read entire file (126 bytes)
|
|
118 os9 I$Read Go do read
|
|
119 lbcs REDERR Go handle any errors
|
|
120 * Close file
|
|
121 lda FPATH,U
|
|
122 os9 I$Close
|
|
123 lbcs ERR1
|
|
124
|
|
125 leax CLRSCN,pcr
|
|
126 ldy #1
|
|
127 lbsr OUTST2
|
|
128
|
|
129 lbsr PRFIL2 Print score data
|
|
130 leax CHGWK1,pcr Reset screen 0,0,40,24
|
|
131 ldy #9
|
|
132 lbsr OUTST2
|
|
133 rts
|
|
134
|
|
135 SCEND: lda #0
|
|
136 sta ENTCNT,U
|
|
137 lda #2
|
|
138 sta CURPOS,U
|
|
139 lda #32
|
|
140 sta CURPOS+1,U
|
|
141
|
|
142 lbsr SCRCMP Compare players score
|
|
143 lda ENTCNT,U
|
|
144 cmpa #-1
|
|
145 beq SCRTN
|
|
146
|
|
147 OPNFL2 lda #2 Set to write
|
|
148 leax FILLST,pcr
|
|
149 os9 I$Open
|
|
150 lbcs ERR1
|
|
151 sta FPATH,U
|
|
152 WRITFL leax FSCORE,U
|
|
153 ldy #126
|
|
154 os9 I$Write
|
|
155 lbcs ERR1
|
|
156 lda FPATH,U
|
|
157 os9 I$Close
|
|
158 lbcs ERR1
|
|
159
|
|
160 ldx #100
|
|
161 lbsr WAIT
|
|
162 SCRTN rts
|
|
163
|
|
164 * File data has been put in memory
|
|
165 * now print it on screen
|
|
166 * This is used for path2
|
|
167 PRFIL2 leax CLNRM2,pcr
|
|
168 ldy #6
|
|
169 lbsr OUTST2
|
|
170 leax CURXY1,pcr
|
|
171 ldy #3
|
|
172 lbsr OUTST2
|
|
173 leax FSCORE,U
|
|
174 leax -21,X
|
|
175 ldb #7
|
|
176 pshs B,X
|
|
177 PLOOP2 puls B,X
|
|
178 decb
|
|
179 beq PDONE2
|
|
180 leax 21,X
|
|
181 pshs B,X
|
|
182 ldy #21
|
|
183 lbsr OUTST2
|
|
184 leax CRLF,pcr
|
|
185 ldy #2
|
|
186 lbsr OUTST2
|
|
187 bra PLOOP2
|
|
188
|
|
189 PDONE2 rts
|
|
190
|
|
191 SCRCMP lda #0 Set entry count to zero
|
|
192 ldb #0
|
|
193 sta ENTCNT,U Save it
|
|
194 std ENTPNT,U Set entry pointer
|
|
195 leay FSCORE,U Point to start of data
|
|
196 SCLOOP leay 15,Y Move to first score
|
|
197 leax SCRASC-1,U Point to players score -1
|
|
198 ldb #7 Set byte counter
|
|
199 SCLOP2 decb Decrement counter
|
|
200 beq NEXTCK If =, go get next score
|
|
201 lda ,Y+ Get hi-score byte
|
|
202 leax 1,X Bump player score pointer
|
|
203 cmpa ,X Compare them
|
|
204 beq SCLOP2 If =, go check next byte
|
|
205 blo MOVE If <, insert players name
|
|
206
|
|
207 NEXTCK lda ENTCNT,U Get entry counter
|
|
208 inca Bump it
|
|
209 cmpa #6 Done 6 yet ?
|
|
210 bne NEXT Score not higher, Print old data
|
|
211 lda #-1
|
|
212 sta ENTCNT,U
|
|
213 bra PRFILE
|
|
214
|
|
215 NEXT sta ENTCNT,U Save count
|
|
216 leay FSCORE,U
|
|
217 ldb #21
|
|
218 mul
|
|
219 leay D,Y
|
|
220 std ENTPNT,U
|
|
221 bra SCLOOP
|
|
222
|
|
223 * This routine is used to insert the
|
|
224 * player's score into the hi-scores
|
|
225 * Move name & score data down to allow player's
|
|
226 * name & score to be inserted. This will remove
|
|
227 * the last item from the list
|
|
228
|
|
229 MOVE lda #5 Set constant
|
|
230 suba ENTCNT,U Subtract entry counter
|
|
231 ldb #21 Set multiplier
|
|
232 mul B reg. holds loop counter
|
|
233 leax FSCORE,U Point to start of data
|
|
234 leax 126,X Move to last byte entry 6 +1
|
|
235 leay FSCORE,U
|
|
236 leay 105,Y Move to last byte entry 5 +1
|
|
237 cmpd #0 If on bottom, then don't
|
|
238 beq PUTIT move any down
|
|
239 INLOOP lda ,-Y Get a byte
|
|
240 sta ,-X Move it
|
|
241 decb Decrement counter
|
|
242 bne INLOOP
|
|
243
|
|
244 * Now zero(underline) out previous entry at this location
|
|
245
|
|
246 PUTIT ldb #15 Set byte counter
|
|
247 lda #95 ASCII underline chacarter
|
|
248 PUTLOP decb Decrement counter
|
|
249 beq PUTSCR
|
|
250 sta ,Y+ Store a '_' character
|
|
251 bra PUTLOP Loop till 15 are done
|
|
252 * Now transfer players score
|
|
253 PUTSCR lda #32 Space character
|
|
254 sta ,Y+
|
|
255 ldb #7 Set transfer byte counter
|
|
256 leax SCRASC,U Point to players ascii score
|
|
257 PLOOP decb Decrement counter
|
|
258 beq PRFILE If 0, then exit
|
|
259 lda ,X+ Get byte & increment X
|
|
260 sta ,Y+ Put byte & increment Y
|
|
261 bra PLOOP
|
|
262 * File data has been put in memory
|
|
263 * now print it on screen
|
|
264 * This is used for path
|
|
265 PRFILE leax CLNORM,pcr
|
|
266 ldy #6
|
|
267 lbsr OUTST2
|
|
268 leax CHGWK2,pcr
|
|
269 ldy #9
|
|
270 lbsr OUTST2
|
|
271 leax FSCORE,U
|
|
272 leax -21,X
|
|
273 lda #-1
|
|
274 ldb #7
|
|
275 pshs D,X
|
|
276 PRLOOP puls D,X
|
|
277 decb
|
|
278 beq PRDONE
|
|
279 leax 21,X Point to line to print
|
|
280 inca Increment compare count
|
|
281 pshs D,X
|
|
282 cmpa ENTCNT,U Are we on the new line ?
|
|
283 bne NORMPR
|
|
284 stx SAVEX,U Save X register
|
|
285 leax CLINVT,pcr Invert screen colors
|
|
286 ldy #6
|
|
287 lbsr OUTST2
|
|
288 ldx SAVEX,U Get X register value
|
|
289 ldy #21 Output 21 bytes
|
|
290 lbsr OUTST2
|
|
291 leax CRLF,pcr Do a carriage return
|
|
292 ldy #2 and a line feed
|
|
293 lbsr OUTST2
|
|
294 leax CLNORM,pcr Reset screen colors
|
|
295 ldy #6
|
|
296 lbsr OUTST2
|
|
297 bra PRLOOP
|
|
298
|
|
299 NORMPR ldy #21
|
|
300 lbsr OUTST2
|
|
301 leax CRLF,pcr
|
|
302 ldy #2
|
|
303 lbsr OUTST2
|
|
304 bra PRLOOP
|
|
305
|
|
306 PRDONE lda ENTCNT,U
|
|
307 cmpa #-1
|
|
308 lbeq RDDONE
|
|
309
|
|
310 OPNBOT ldx #100
|
|
311 lbsr WAIT
|
|
312 leax BOTWIN,pcr
|
|
313 ldy #47
|
|
314 lbsr OUTST2
|
|
315
|
|
316 PNAMLP leax ENTNAM,pcr Print 'Please enter your name'
|
|
317 ldy #33 Output 34 bytes
|
|
318 lbsr OUTST2
|
|
319
|
|
320 leax ARROW,pcr Print '-->_'
|
|
321 ldy #17
|
|
322 lbsr OUTST2
|
|
323
|
|
324 * Now get players name
|
|
325
|
|
326 GETNAM leax PNAME,U Fill name storage
|
|
327 lda #32 with spaces
|
|
328 ldb #15
|
|
329 PNLOOP sta ,X+
|
|
330 decb
|
|
331 bne PNLOOP
|
|
332
|
|
333 RDNAME leax PNAME,U Get name from player
|
|
334 ldy #15 14 + CR
|
|
335 lda PATH2,U
|
|
336 os9 I$ReadLn
|
|
337 lbcs ERR1
|
|
338 tfr Y,D
|
|
339
|
|
340 leax PNAME,U
|
|
341 subd #1
|
|
342 leax D,X
|
|
343 std NAMLGH,U
|
|
344 lda #32
|
|
345 sta ,X Remove CR
|
|
346
|
|
347 NAMEOK ldd NAMLGH,U
|
|
348 cmpd #0
|
|
349 beq NAMASK
|
|
350
|
|
351 leax CURXY2,pcr Clear screen, Move to XY
|
|
352 ldy #7 location 6,0
|
|
353 lbsr OUTST2 and set color
|
|
354
|
|
355 leax PNAME,U
|
|
356 ldy NAMLGH,U
|
|
357 lbsr OUTST2
|
|
358
|
|
359 NAMASK leax QUESTN,pcr
|
|
360 ldy #33
|
|
361 lbsr OUTST2
|
|
362
|
|
363 lbsr READ2
|
|
364 lda RESPON,U
|
|
365 cmpa #89
|
|
366 beq PUTNAM
|
|
367 cmpa #121
|
|
368 beq PUTNAM
|
|
369 leax CLRSCN,pcr
|
|
370 ldy #1
|
|
371 lbsr OUTST2
|
|
372
|
|
373 lbra PNAMLP
|
|
374
|
|
375 PUTNAM leax BOTEND,pcr
|
|
376 ldy #15
|
|
377 lbsr OUTST2
|
|
378
|
|
379 leax PNAME,U
|
|
380 leay FSCORE,U
|
|
381 ldd ENTPNT,U
|
|
382 leay D,Y
|
|
383 ldb #14
|
|
384 PUTNML lda ,X+
|
|
385 sta ,Y+
|
|
386 decb
|
|
387 bne PUTNML
|
|
388
|
|
389 lda ENTCNT,U
|
|
390 adda #32
|
|
391 sta CURPOS+2,U
|
|
392
|
|
393 leax CURPOS,U
|
|
394 ldy #3
|
|
395 lbsr OUTST2
|
|
396
|
|
397 leax FSCORE,U
|
|
398 ldd ENTPNT,U
|
|
399 leax D,X
|
|
400 ldy #21
|
|
401 lbsr OUTST2
|
|
402
|
|
403 leax BOTWIN,pcr
|
|
404 ldy #47
|
|
405 lbsr OUTST2
|
|
406
|
|
407 leax CONGRT,pcr
|
|
408 ldy #27
|
|
409 lbsr OUTST2
|
|
410
|
|
411 leax PNAME,U
|
|
412 ldy NAMLGH,U
|
|
413 lbsr OUTST2
|
|
414
|
|
415 RDDONE ldx #200
|
|
416 lda ENTCNT,U
|
|
417 cmpa #-1
|
|
418 beq RDWAIT
|
|
419 ldx #150
|
|
420 RDWAIT lbsr WAIT Sleep for 150 or 200 ticks
|
|
421 lda ENTCNT,U
|
|
422 cmpa #-1
|
|
423 beq RDEXIT
|
|
424
|
|
425 leax BOTEND,pcr
|
|
426 ldy #15
|
|
427 lbsr OUTST2
|
|
428 RDEXIT rts
|
|
429
|
|
430 * Handle file errors here
|
|
431 * 214- no permission
|
|
432 * 216- path name not found
|
|
433 *
|
|
434
|
|
435 OPNERR cmpb #216 Is it PATH NAME NOT FOUND ?
|
|
436 lbne ERR1
|
|
437 * Print Creating score file
|
|
438 leax NOTFND,pcr
|
|
439 ldy #56
|
|
440 lbsr OUTST2
|
|
441 ldx #75
|
|
442 lbsr WAIT
|
|
443 FILLSC leax FSCORE,U Point to data area
|
|
444 ldb #7 Set counter
|
|
445 stb COUNT,U
|
|
446 DMLOOP lda COUNT,U
|
|
447 deca
|
|
448 beq CRFILE
|
|
449 sta COUNT,U Save new count
|
|
450 ldb #15
|
|
451 lda #46 '.'
|
|
452 DLOOP2 decb
|
|
453 beq SPACE
|
|
454 sta ,X+ Put 14 '.' in data area
|
|
455 bra DLOOP2
|
|
456 SPACE lda #32 ' '
|
|
457 sta ,X+ Put a space in data area
|
|
458 lda #32 Space
|
|
459 ldb #6
|
|
460 DLOOP3 decb
|
|
461 beq DZERO
|
|
462 sta ,X+ Put 5 spaces in data area
|
|
463 bra DLOOP3
|
|
464 DZERO lda #48 '0'
|
|
465 sta ,X+
|
|
466 bra DMLOOP
|
|
467
|
|
468 * File doesn't exist, so create it
|
|
469
|
|
470 CRFILE leax CREATE,pcr
|
|
471 ldy #26
|
|
472 lbsr OUTST2
|
|
473 leax FILLST,pcr Point to path list
|
|
474 lda #2 Access mode (2=write)
|
|
475 ldb #47 Attributes (00101111)
|
|
476 os9 I$Create Go create file
|
|
477 lbcs ERR1
|
|
478 sta FPATH,U Save path #
|
|
479 * Write data to file
|
|
480 WRTFIL leax FSCORE,U Point to data
|
|
481 ldy #126 Write 126 bytes
|
|
482 lda FPATH,U Set path #
|
|
483 os9 I$Write Do write
|
|
484 lbcs ERR1
|
|
485 * Now close file
|
|
486 CLSFIL lda FPATH,U
|
|
487 os9 I$Close
|
|
488 lbcs ERR1
|
|
489 ldx #75
|
|
490 lbsr WAIT
|
|
491
|
|
492 rts
|
|
493
|
|
494 REDERR lbra ERR1
|
|
495
|
|
496
|
|
497 ENDSECT
|
|
498
|
|
499
|