]> git.sur5r.net Git - cc65/blob - libsrc/c64/soft80_conio.s
Merge pull request #628 from ops/VIAFIX_PET
[cc65] / libsrc / c64 / soft80_conio.s
1 ;
2 ; Groepaz/Hitmen, 11.10.2015
3 ;
4 ; Low level init code for soft80 screen output/console input
5 ;
6
7         .constructor    soft80_init, 8
8         .destructor     soft80_shutdown
9
10         .import         soft80_kclrscr, soft80_charset
11         .export         soft80_internal_bgcolor, soft80_internal_cellcolor
12         .export         soft80_internal_cursorxlsb
13
14         .importzp       ptr1, ptr2, ptr3
15
16         .include        "c64.inc"
17         .include        "soft80.inc"
18
19 soft80_init:
20         lda     soft80_first_init
21         bne     @skp
22         jsr     firstinit
23 @skp:
24         ; the "color voodoo" in other parts of the code relies on the vram and
25         ; colorram being set up as expected, which is why we cant use the
26         ; _bgcolor and _textcolor functions here.
27
28         lda     CHARCOLOR       ; use current textcolor
29         and     #$0F            ; make sure the upper nibble is 0s
30         sta     CHARCOLOR
31
32         lda     VIC_BG_COLOR0   ; use current bgcolor
33         and     #$0F
34         sta     soft80_internal_bgcolor
35         asl     a
36         asl     a
37         asl     a
38         asl     a
39         ora     CHARCOLOR
40         sta     soft80_internal_cellcolor
41
42         lda     #$3B
43         sta     VIC_CTRL1
44         lda     #$00
45         sta     CIA2_PRA
46         lda     #$68
47         sta     VIC_VIDEO_ADR
48         lda     #$C8
49         sta     VIC_CTRL2
50
51         jmp     soft80_kclrscr
52
53 soft80_shutdown:
54
55         lda     #$07
56         sta     CIA2_PRA
57         jmp     $FF5B           ; Initialize video I/O
58
59         .segment "ONCE"
60 firstinit:
61         ; copy charset to RAM under I/O
62         sei
63         lda     $01
64         pha
65         lda     #$34
66         sta     $01
67
68         inc     soft80_first_init
69
70         lda     #<soft80_charset
71         ldx     #>soft80_charset
72         sta     ptr1
73         stx     ptr1+1
74         lda     #<soft80_lo_charset
75         ldx     #>soft80_lo_charset
76         sta     ptr2
77         stx     ptr2+1
78         lda     #<soft80_hi_charset
79         ldx     #>soft80_hi_charset
80         sta     ptr3
81         stx     ptr3+1
82
83         ldx     #4
84 @l2:
85         ldy     #0
86 @l1:
87         lda     (ptr1),y
88         sta     (ptr2),y
89         asl     a
90         asl     a
91         asl     a
92         asl     a
93         sta     (ptr3),y
94         iny
95         bne     @l1
96         inc     ptr1+1
97         inc     ptr2+1
98         inc     ptr3+1
99         dex
100         bne     @l2
101
102         ; copy the kplot tables to ram under I/O
103         ;ldx     #0             ; is 0
104 @l3:
105         lda     soft80_tables_data_start,x
106         sta     soft80_bitmapxlo,x
107         lda     soft80_tables_data_start + (soft80_tables_data_end - soft80_tables_data_start - $0100),x
108         sta     soft80_bitmapxlo + (soft80_tables_data_end - soft80_tables_data_start - $0100),x
109         inx
110         bne     @l3
111
112         pla
113         sta     $01
114         cli
115         rts
116
117 ; the following tables take up 267 bytes, used by kplot
118 soft80_tables_data_start:
119
120 soft80_bitmapxlo_data:
121         .repeat 80,col
122         .byte <((col/2)*8)
123         .endrepeat
124 soft80_bitmapxhi_data:
125         .repeat 80,col
126         .byte >((col/2)*8)
127         .endrepeat
128 soft80_vramlo_data:
129         .repeat 25,row
130         .byte <(soft80_vram+(row*40))
131         .endrepeat
132         .byte 0,0,0,0,0,0,0     ; padding to next page
133 soft80_vramhi_data:
134         .repeat 25,row
135         .byte >(soft80_vram+(row*40))
136         .endrepeat
137 soft80_bitmapylo_data:
138         .repeat 25,row
139         .byte <(soft80_bitmap+(row*40*8))
140         .endrepeat
141 soft80_bitmapyhi_data:
142         .repeat 25,row
143         .byte >(soft80_bitmap+(row*40*8))
144         .endrepeat
145
146 soft80_tables_data_end:
147
148 ;-------------------------------------------------------------------------------
149         .segment "INIT"
150 soft80_internal_cellcolor:
151         .res 1
152 soft80_internal_bgcolor:
153         .res 1
154 soft80_internal_cursorxlsb:
155         .res 1
156
157         .data
158 soft80_first_init:
159         .byte 0                 ; flag to check first init, this really must be in .data