]> git.sur5r.net Git - cc65/blob - libsrc/apple2/videomode.s
Added support for switching between 40/80 columns. As the Apple //e 80 column firmwar...
[cc65] / libsrc / apple2 / videomode.s
1 ;
2 ; Oliver Schmidt, 07.09.2009
3 ;
4 ; unsigned __fastcall__ videomode (unsigned mode);
5 ;
6
7         .export         _videomode
8         .import         COUT
9
10         .include        "apple2.inc"
11
12         .segment        "LOWCODE"
13
14 _videomode:
15         ; Get and save current videomode flag
16         bit     RD80VID
17         php
18         
19         ; If we are in 80 column mode then the 80 column firmware is
20         ; known to be active so we can just print the ctrl-char code
21         ; (even if this only means staying in the current videomode)
22         bpl     :+
23         jsr     COUT
24         bra     done
25
26         ; If we are in 40 column mode and want to set 40 column mode
27         ; then we explicitly do nothing as we neither know about the
28         ; current state of the 80 column firmware nor want to fix it
29 :       cmp     #$11            ; Ctrl-char code for 40 cols
30         beq     done
31         
32         ; If we are in 40 column mode and want to set 80 column mode
33         ; then we first presume the 80 column firmware being already
34         ; active and print the ctrl-char code (this causes a garbage
35         : char to be printed on the screen if isn't already active)
36         jsr     COUT
37         
38         ; If we successfully switched to 80 column mode then the 80
39         ; column firmware was in fact already active and we're done
40         bit     RD80VID
41         bmi     done
42         
43         ; The 80 column firmware isn't already active so we need to
44         ; initialize it - causing the screen to be cleared and thus
45         ; the garbage char printed above to be erased (but for some
46         ; reason the cursor horizontal position not not be zeroed)
47         stz     CH
48
49         ; Initializing the 80 column firmware needs the ROM switched
50         ; in, otherwise it would copy the F8 ROM to the LC (@ $CEF4)
51         bit     $C082
52
53         ; Initialize 80 column firmware
54         jsr     $C300           ; PR#3
55
56         ; Switch in LC bank 2 for R/O
57         bit     $C080
58                 
59         ; Return ctrl-char code for setting previous
60         ; videomode using the saved videomode flag
61 done:   lda     #$11            ; Ctrl-char code for 40 cols
62         plp
63         bpl     :+
64         lda     #$12            ; Ctrl-char code for 80 cols
65 :       rts                     ; X was preserved all the way