]> git.sur5r.net Git - cc65/blob - libsrc/nes/cputc.s
Clean wherey.s
[cc65] / libsrc / nes / cputc.s
1 ;
2 ; Written by Groepaz/Hitmen <groepaz@gmx.net>
3 ; Cleanup by Ullrich von Bassewitz <uz@cc65.org>
4 ;
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
6 ; void cputc (char c);
7 ;
8
9         .export         _cputcxy, _cputc, cputdirect, putchar
10         .export         newline
11         .constructor    initconio
12         .import         gotoxy
13         .import         ppuinit, paletteinit, ppubuf_put
14         .import         setcursor
15
16         .importzp       tmp3,tmp4
17
18         .include        "nes.inc"
19
20 ;-----------------------------------------------------------------------------
21
22 .code
23
24 _cputcxy:
25         pha                     ; Save C
26         jsr     gotoxy          ; Set cursor, drop x and y
27         pla                     ; Restore C
28
29 ; Plot a character - also used as internal function
30
31 _cputc: cmp     #$0d            ; CR?
32         bne     L1
33         lda     #0
34         sta     CURS_X
35         beq     plot            ; Recalculate pointers
36
37 L1:     cmp     #$0a            ; LF?
38         beq     newline         ; Recalculate pointers
39
40 ; Printable char of some sort
41
42 cputdirect:
43         jsr     putchar         ; Write the character to the screen
44
45 ; Advance cursor position
46
47 advance:
48         ldy     CURS_X
49         iny
50         cpy     #xsize
51         bne     L3
52         inc     CURS_Y          ; new line
53         ldy     #0              ; + cr
54 L3:     sty     CURS_X
55         jmp     plot
56
57 newline:
58         inc     CURS_Y
59
60 ; Set cursor position, calculate RAM pointers
61
62 plot:   ldy     CURS_X
63         ldx     CURS_Y
64         jmp     setcursor       ; Set the new cursor
65
66
67 ; Write one character to the screen without doing anything else, return X
68 ; position in Y
69
70 putchar:
71         ora     RVS             ; Set revers bit
72         ldy     SCREEN_PTR+1
73         ldx     SCREEN_PTR
74         jmp     ppubuf_put
75
76 ;-----------------------------------------------------------------------------
77 ; Initialize the conio subsystem. Code goes into the ONCE segment, which may
78 ; be reused after startup.
79
80 .segment        "ONCE"
81
82 initconio:
83         jsr     ppuinit
84         jsr     paletteinit
85
86         lda     #0
87         sta     RVS
88         sta     CURS_X
89         sta     CURS_Y
90
91         jmp     plot            ; Set the cursor
92
93