]> git.sur5r.net Git - cc65/blob - libsrc/nes/cputc.s
Two fixes from Stefan Haubenthal
[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    conioinit
12         .import         popa, _gotoxy
13         .import         ppuinit, paletteinit, ppubuf_put
14         .import         setcursor
15
16         .importzp       tmp3,tmp4
17
18         .include        "nes.inc"
19
20 ;-----------------------------------------------------------------------------
21
22 _cputcxy:
23         pha                     ; Save C
24         jsr     popa            ; Get Y
25         jsr     _gotoxy         ; Set cursor, drop x
26         pla                     ; Restore C
27
28 ; Plot a character - also used as internal function
29
30 _cputc: cmp     #$0d            ; CR?
31         bne     L1
32         lda     #0
33         sta     CURS_X
34         beq     plot            ; Recalculate pointers
35
36 L1:     cmp     #$0a            ; LF?
37         beq     newline         ; Recalculate pointers
38
39 ; Printable char of some sort
40
41 cputdirect:
42         jsr     putchar         ; Write the character to the screen
43
44 ; Advance cursor position
45
46 advance:
47         ldy     CURS_X
48         iny
49         cpy     #xsize
50         bne     L3
51         inc     CURS_Y          ; new line
52         ldy     #0              ; + cr
53 L3:     sty     CURS_X
54         jmp     plot
55
56 newline:
57         inc     CURS_Y
58
59 ; Set cursor position, calculate RAM pointers
60
61 plot:   ldy     CURS_X
62         ldx     CURS_Y
63         jmp     setcursor       ; Set the new cursor
64
65
66 ; Write one character to the screen without doing anything else, return X
67 ; position in Y
68
69 putchar:
70         ora     RVS             ; Set revers bit
71         ldy     SCREEN_PTR+1
72         ldx     SCREEN_PTR
73         jmp     ppubuf_put
74
75 ;-----------------------------------------------------------------------------
76 ; Initialize the conio subsystem
77
78 conioinit:
79         jsr     ppuinit
80         jsr     paletteinit
81
82         lda     #0
83         sta     RVS
84         sta     CURS_X
85         sta     CURS_Y
86
87         jmp     plot            ; Set the cursor
88
89