/[projet1]/users/chema/TINE/text.s
Defence Force logotype

Contents of /users/chema/TINE/text.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Tue Jun 15 09:53:43 2010 UTC (9 years, 11 months ago) by Chema
File size: 12553 byte(s)
Expanded the print routine to handle strings with more than 256 characters. Also expanded it and the print_incomming_message routine to handle text with several pages (New page is code 11, as 12 is flashing attribute).

Expanded some briefings in tutorial0 and 1 and currently working on mission8 text.

Tested mission8, which is working.
1 ;;; Code for printing texts in hires screen
2
3 #define Grammar $200
4
5 ; in pixels
6 #define INITIALX_TEXT 6
7 #define INITIALY_TEXT 6
8
9 ; in pixels
10 #define FINALX_TEXT (240-6)
11
12 ; Attributes
13 #define A_FWBLACK 0
14 #define A_FWRED 1
15 #define A_FWGREEN 2
16 #define A_FWYELLOW 3
17 #define A_FWBLUE 4
18 #define A_FWMAGENTA 5
19 #define A_FWCYAN 6
20 #define A_FWWHITE 7
21
22
23 print2buffer .byt 00 ; Prints in str buffer, for formatting text
24 buffercounter .byt 00
25 print2dbuffer .byt 00 ; Prints to the double-buffer area
26
27 ; Put this as a value different from 0
28 ; and text will be printed on caps.
29
30 capson .byt 00
31
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ; printnl
34 ; prints a string in text area ADDING a newline
35 ; String pointer passed in (sp)
36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 printnl
38 .(
39 jsr print
40 jmp perform_CRLF ; This is jsr/rts
41 .)
42
43
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 ; print2
46 ; Same as print (below), but pointer passed in tmp0
47 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 print2
49 lda tmp0
50 ldx tmp0+1
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ; print
53 ; prints a string in text area
54 ; String pointer passed in a (low) and x (high)
55 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 print
57 .(
58 ; Get pointer to text string
59 sta text+1
60 stx text+2
61
62 ; Start printing char by char
63 ldx #0
64 loop
65 text
66 lda 1234,x ; Get Next letter
67 beq end ; if 0, we are finished
68
69 ; If it is a newpage, do as if 0
70 cmp #11
71 beq end
72
73 stx savx+1
74 jsr decomp
75 savx
76 ldx #0 ;SMC
77 inx
78 bne cont
79 inc text+2
80 cont
81 jmp loop
82
83 end
84 rts
85 .)
86
87 #define COMPTEXT
88 #ifdef COMPTEXT
89 #ifdef GRAMMAR2PAGE4
90 .bss
91 *=$400
92
93 Grammar .dsb 256
94
95 .text
96
97 #endif
98
99 ;;;;;;;;;; Decompression routine ;;;;;;;;;;;;;;;;;;
100 ;__comp_start
101
102
103 decomp
104 .(
105 tay
106 ; Prepare the stack for the decompression routine
107 lda #0
108 pha
109 tya
110 pha
111
112 loop
113 pla
114 ; If it is 0, we are done
115 beq end
116
117 ; If it is a token, expand it, else print and continue
118 bpl printit
119
120 and #%01111111 ; Get table entry
121 asl
122 tay
123 lda Grammar+1,y
124 pha
125 lda Grammar,y
126 pha
127 jmp loop
128 printit
129 jsr put_code
130 jmp loop
131 end
132 ldy print2buffer
133 beq nomore
134 ldy buffercounter
135 lda #0
136 sta str_buffer,y
137 nomore
138 rts
139
140
141 .)
142
143 ;__comp_end
144
145 ;#echo Size of decomp routine in bytes:
146 ;#print (__comp_end - __comp_start)
147 ;#echo
148
149 #endif
150
151
152
153 ; Prints num in reg A (00-99)
154 printnum
155 .(
156 ldx #0
157 sec
158 loop
159 inx
160 sbc #10
161 bcs loop
162 dex
163
164 adc #(10+48)
165 pha
166 txa
167 clc
168 adc #48
169 jsr put_char
170 pla
171 jsr put_char
172 rts
173
174 .)
175
176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
177 ; clr_hires
178 ; Clears text area
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
180
181 clr_hires
182 .(
183
184 lda #<($a000)
185 sta tmp1
186 lda #>($a000)
187 sta tmp1+1
188
189 looprows
190 ldy #39
191 lda #$40
192 loopcols
193 sta (tmp1),y
194 dey
195 bpl loopcols
196
197 lda tmp1
198 clc
199 adc #40
200 sta tmp1
201 bcc nocarry
202 inc tmp1+1
203 nocarry
204
205 lda tmp1+1
206 cmp #>($bf40)
207 bne next
208 lda tmp1
209 cmp #<($bf40)
210 bne next
211 jmp end
212
213 next
214 jmp looprows
215 end
216 ;jmp _init_print
217 ;rts
218 .)
219
220
221 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
222 ; Text functions
223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
224
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
226 ; Initialize X,Y
227 ; to initial positions
228 ; or set X, Y or both to a given
229 ; position passed in regs X and Y
230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231
232 _init_print
233 .(
234 ldx #INITIALX_TEXT
235 ldy #INITIALY_TEXT
236 jmp relocate_cursor
237 ;rts
238
239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
240 ; Set X to a given value
241 ; passed in reg X
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243 +gotoX
244 ldy Cursor_origin_y
245 jmp gotoXY
246
247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
248 ; Set Y to a given value
249 ; passed in reg Y
250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
251 +gotoY
252 ldx Cursor_origin_x
253 jmp gotoXY
254 .)
255
256
257
258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259 ; Twilighte's code for printing texts...
260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261
262 .zero
263 screen .word 00
264
265 .text
266 Cursor_origin_x .dsb 1
267 Cursor_origin_y .dsb 1
268
269 #define res_x tmp4
270 #define res_y tmp4+1
271
272 //res_x .dsb 1
273 //res_y .dsb 1
274
275
276 ascii2code
277 cmp #97
278 .(
279 bcs skip1
280 cmp #65
281 bcs skip2
282 sbc #32
283 stx tmp
284 tax
285 lda punctuation_ascii,x ;31 Bytes
286 ldx tmp
287 rts
288 skip1 sbc #97
289 rts
290 skip2 sbc #39
291 .)
292 rts
293 punctuation_ascii
294 .byt 64,64,64,65,64,62,73,66,67,75,64,69,74,68,79,61
295 ; ! " # $ % & ' ( ) * + , - . / 0
296 .byt 52,53,54,55,56,57,58,59,60,71,70,77,76,78,63
297 ; 1 2 3 4 5 6 7 8 9 : ; < = > ?
298
299
300 ;Perform $CRLF
301 perform_CRLF
302 stx res_x
303 sty res_y
304 lda Cursor_origin_y
305 clc
306 adc #06 ;Vertical character spacing
307 tay
308 ldx #INITIALX_TEXT ;Cursor_origin_x
309 jsr relocate_cursor
310 ldx res_x
311 ldy res_y
312 rts
313
314
315 ;Relocate Cursor
316 ;Pass:
317 ;X X position on screen (Byte alligned 0 to 39)
318 ;Y Y position on screen (Row alligned 0 to 195)
319 gotoXY
320 relocate_cursor
321 .(
322 pha
323 ;Calculate screen loc
324 stx Cursor_origin_x
325 sty Cursor_origin_y
326
327 lda print2dbuffer
328 beq normal
329 jsr pixel_address
330 jmp cont
331 normal
332 jsr pixel_address_real
333 cont
334 tya
335 clc
336 adc tmp0
337 bcc noinctmp0
338 inc tmp0+1
339 noinctmp0
340 sta screen
341 lda tmp0+1
342 sta screen+1
343
344
345 pla
346 rts
347 .)
348
349 put_colcombo
350 .(
351 pha
352 and #7
353 sta colour_0
354 pla
355 lsr
356 lsr
357 lsr
358 lsr
359 and #7
360 sta colour_1
361 jmp put_colour_combo
362 .)
363 ;Print character, colour or Carriage return at next cursor position
364 ;A Character Code
365 put_code
366 cmp #128
367 bcs put_colcombo
368 cmp #13
369 beq perform_CRLF
370 cmp #32
371 bcc put_colour
372
373
374 ;Print character at next cursor position
375 ;A Character Code
376 put_char
377 stx res_x
378 sty res_y
379 cmp #32
380 beq put_space
381 cmp #97
382 bcc nocaps ; It is not a letter
383 ldx capson
384 beq nocaps
385 and #$df ; Uppercase it
386
387 nocaps
388 .(
389 ; Check if we are printing to buffer
390 ldy print2buffer
391 beq cont
392
393 ldy buffercounter
394 sta str_buffer,y
395 inc buffercounter
396 bne skipme ; This is allways true
397 cont
398 jsr ascii2code
399 jsr put_char_direct
400 .)
401 increment_cursor
402 .(
403 lda Cursor_origin_x
404 clc
405 adc #6
406 sta Cursor_origin_x
407 /* cmp #FINALX_TEXT
408 bne cont
409 jsr perform_CRLF
410 jmp skipme
411 cont*/
412 inc screen
413 bne skipme
414 inc screen+1
415 +skipme
416 ldx res_x
417 ldy res_y
418
419 rts
420 .)
421
422
423 put_space
424 .(
425 ; Check if we are printing to buffer
426 lda print2buffer
427 beq cont1
428 ldy buffercounter
429 lda #" "
430 sta str_buffer,y
431 inc buffercounter
432 bne skipme
433 cont1
434 lda #64
435 .)
436 ;Places the colour in A at the current cursor position and increments the
437 ;cursor.
438 ;Pass:
439 ;A Colour(0-7)
440 put_colour
441 sta colour_0
442 sta colour_1
443
444 ;Places the colour combination of colour_0 and colour_1 at the current cursor
445 ;position and increments the cursor.
446 ;Pass:
447 ;colour_0 The first colour (Repeated thrice)
448 ;colour_1 The second colour (Repeated twice)
449 put_colour_combo
450 stx res_x
451 sty res_y
452 lda colour_0
453 ldx colour_1
454 ldy #00
455 sta (screen),y
456 txa
457 ldy #40
458 sta (screen),y
459 lda colour_0
460 ldy #80
461 sta (screen),y
462 txa
463 ldy #120
464 sta (screen),y
465 lda colour_0
466 ldy #160
467 sta (screen),y
468 jmp increment_cursor
469
470
471 ;Relocate cursor and Print character
472 ;Pass:
473 ;X X position on screen (Byte alligned 0 to 39)
474 ;Y Y position on screen (Row alligned 0 to 195)
475 ;A Character Code (ASCII)
476 place_char
477 jsr relocate_cursor
478 jsr ascii2code
479 put_char_direct
480 tax ;char_number
481 lda character_bitmap_row0,x
482 ldy #00
483 sta (screen),y
484 lda character_bitmap_row1,x
485 ldy #40
486 sta (screen),y
487 lda character_bitmap_row2,x
488 ldy #80
489 sta (screen),y
490 lda character_bitmap_row3,x
491 ldy #120
492 sta (screen),y
493 lda character_bitmap_row4,x
494 ldy #160
495 sta (screen),y
496 rts
497
498 /*
499 ;73 Characters + 7 for special chars (Not defined yet) [CHEMA: 73=', 74=-,
500 ;75=space (for deleting), 76==, 77=<-, 78=->, 79=/]
501 ;80 Characters == 400($190) Bytes
502 */
503
504 character_bitmap_row0 ;80 Bytes
505 .byt $40,$70,$40,$46,$40,$5c,$7e,$70,$58,$4c,$58,$58,$40,$40,$40,$40
506 .byt $40,$40,$40,$44,$40,$40,$40,$40,$40,$40,$7e,$7e,$7e,($7e & %11111100),$7e,$7e
507 .byt $7e,$72,$5c,$5c,$72,$5c,$7e,$7e,($7e & %11011111),$7e,$7e,$7e,$7e,$7e,$72,$72
508 .byt $6a,$72,$72,$7e,$7c,$7e,$7e,$7c,$7e,$7e,$7e,$7e,$7e,$7e,$58,$7e
509 .byt $5c,$7e,$5c,$5c,$40,$40,$40,$40,$5f,$4c,$40,$40,$40,%01001000,%01000100,%01000010
510 character_bitmap_row1 ;80 Bytes
511 .byt $5e,$7e,$5e,$7e,$5e,$50,$72,$7e,$40,$40,$5a,$58,$76,$7e,$5e,$7e
512 .byt $7e,$7e,$5e,$7e,$72,$72,$6a,$72,$72,$7e,$66,$72,$66,$66,$70,$70
513 .byt $60,$72,$5c,$5c,$72,$5c,$7e,$66,$72,$72,$72,$72,$70,$5c,$72,$72
514 .byt $6a,$72,$72,$74,$5c,$42,$66,$6c,$60,$60,$66,$72,$72,$72,$72,$72
515 .byt $5c,$68,$58,$4c,$40,$40,$4c,$4c,$53,$46,$40,$40,$7e,%01011111,%01111110,%01000110
516 character_bitmap_row2 ;80 Bytes
517 .byt $66,$66,$66,$66,$66,$7e,$7e,$66,$58,$4c,$5c,$58,$7e,$66,$72,$72
518 .byt $72,$70,$78,$5c,$72,$72,$6a,$5e,$72,$6c,$7e,$7e,$60,$66,$7e,$7e
519 .byt $6e,$7e,$5c,$5c,$7c,$5c,$6a,$66,$72,$72,$72,$7c,$7e,$5c,$72,$72
520 .byt $6a,$5c,$7e,$48,$5c,$7e,$5e,$6c,$7e,$7e,$4c,$7e,$7e,$72,$5e,$4e
521 .byt $48,$7e,$58,$4c,$40,$40,$40,$40,$7c,$40,$7e,$40,$40,%01111111,%01111111,%01001100
522 character_bitmap_row3 ;80 Bytes
523 .byt $66,$66,$60,$66,$78,$5c,$46,$66,$58,$4c,$56,$58,$6a,$66,$72,$7e
524 .byt $7e,$70,$4e,$5c,$72,$5c,$7e,$7c,$7e,$5a,$66,$72,$66,$66,$70,$70
525 .byt $66,$72,$5c,$5c,$66,$5c,$6a,$66,$72,$7e,$72,$66,$46,$5c,$72,$5c
526 .byt $7e,$66,$5c,$56,$5c,$70,$66,$7e,$46,$66,$4c,$66,$46,$72,$72,$40
527 .byt $40,$4a,$58,$4c,$4c,$4c,$4c,$4c,$53,$40,$40,$40,$7e,%01011111,%01111110,%01011000
528 character_bitmap_row4 ;80 Bytes
529 .byt $7f,$7e,$7e,$7e,$7e,$5c,$7e,$66,$58,$5c,$56,$58,$6a,$66,$7e,$70
530 .byt $46,$70,$7c,$5c,$7e,$48,$5c,$66,$46,$7e,$66,$7e,$7e,$7e,$7e,$70
531 .byt $7e,$72,$5c,$7c,$66,$5e,$6a,$66,$7e,$70,$7f,$66,$7e,$5c,$7e,$48
532 .byt $5c,$66,$5c,$7e,$5c,$7e,$7e,$4c,$7e,$7e,$58,$7e,$7e,$7e,$7e,$4c
533 .byt $48,$7e,$5c,$5c,$4c,$46,$46,$40,$5f,$40,$40,$40,$40,%01001000,%01000100,%01010000
534
535
536 colour_0
537 .byt 0
538 colour_1
539 .byt 0
540
541
542 ;;; SOME EXTRA FUNCTIONS.... These are kludges... BEWARE
543
544 del_char
545 .(
546 sty savy+1
547 ldy Cursor_origin_y
548 lda Cursor_origin_x
549 sec
550 sbc #6
551 tax
552 jsr relocate_cursor
553 lda #75
554 jsr put_char_direct
555 savy
556 ldy #0 ;SMC
557 rts
558 .)
559
560
561 gets
562 .(
563 lda #<str_buffer
564 sta tmp2
565 lda #>str_buffer
566 sta tmp2+1
567 ldy #0
568 getsloop
569 sty savy+1
570 readloop
571 jsr ReadKeyNoBounce
572 beq readloop
573
574 savy
575 ldy #0 ;SMC
576 cmp #$0D
577 beq endgets
578 cmp #$20
579 bcc getsloop
580 cmp #$7f
581 beq backspace
582 cpy #$a
583 beq getsloop
584 sta (tmp2),y
585 iny
586 echochar
587 jsr put_char
588 jmp getsloop
589 backspace
590 cpy #0
591 beq getsloop
592 dey
593 jsr del_char
594 jmp getsloop
595 endgets
596 lda #0
597 sta (tmp2),y
598
599 rts
600
601 .)
602
603
604
605

  ViewVC Help
Powered by ViewVC 1.1.26