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