]> git.sur5r.net Git - cc65/blob - libsrc/c64/acc_chameleon_speed.s
Added C64 Chameleon accelerator code and documentation.
[cc65] / libsrc / c64 / acc_chameleon_speed.s
1 ;
2 ; Marco van den Heuvel, 2018-04-25
3 ;
4
5 ; extern unsigned char __fastcall__ set_chameleon_speed (unsigned char speed);
6 ;
7 ;/* Set the speed of the Chameleon cartridge, the following inputs
8 ; * are accepted: 
9 ; * SPEED_SLOW : 1 Mhz mode
10 ; * SPEED_1X   : 1 Mhz mode
11 ; * SPEED_2X   : 2 Mhz mode
12 ; * SPEED_3X   : 3 Mhz mode
13 ; * SPEED_4X   : 4 Mhz mode
14 ; * SPEED_5X   : 5 Mhz mode
15 ; * SPEED_6X   : 6 Mhz mode
16 ; * SPEED_FAST : Maximum speed mode
17 ; *
18 ; * Note that any value higher or equal to SPEED_7X will switch to maximum
19 ; * speed mode.
20 ; *
21 ; * This function will return the actual speed the CPU is at after trying
22 ; * to set the requested speed, to my knowledge the switching should not fail.
23 ; *
24 ; * This function does not check for the presence of the Chameleon cartridge,
25 ; * make sure you use 'detect_chameleon();' before using.
26 ; */
27
28 ; extern unsigned char get_chameleon_speed (void);
29 ;
30 ;/* Get the speed of the Chameleon cartridge.
31 ; *
32 ; * Possible return values:
33 ; * SPEED_SLOW  : Slow mode
34 ; * SPEED_2X    : 2Mhz mode
35 ; * SPEED_3X    : 3Mhz mode
36 ; * SPEED_4X    : 4Mhz mode
37 ; * SPEED_5X    : 5Mhz mode
38 ; * SPEED_6X    : 6Mhz mode
39 ; * SPEED_FAST  : Maximum speed mode
40 ; *
41 ; * This function does not check for the presence of the Chameleon cartridge,
42 ; * make sure you use 'detect_chameleon();' before using.
43 ; */
44
45         .export         _set_chameleon_speed
46         .export         _get_chameleon_speed
47
48         .include        "accelerator.inc"
49
50 _set_chameleon_speed:
51         cmp     #SPEED_7X
52         bcs     maximum_speed
53         cmp     #SPEED_1X
54         beq     low_speed
55         ora     #$80
56 set_speed:
57         jsr     activate_regs
58         sta     CHAMELEON_CFGTUR
59         jmp     return_speed
60
61 low_speed:
62         lda     #CHAMELEON_CFGTUR_LIMIT_1MHZ
63         bne     set_speed
64
65 maximum_speed:
66         lda     #CHAMELEON_CFGTUR_LIMIT_NONE
67         bne     set_speed
68
69 _get_chameleon_speed:
70         jsr     activate_regs
71 return_speed:
72         ldx     #$00
73         lda     CHAMELEON_CFGTUR
74         tay
75         and     #%10000000
76         beq     return_value
77         tya
78         and     #%00001000
79         bne     is_slow_mode
80         tya
81         and     #%00000111
82         beq     is_max_mode
83 return_value:
84         ldy     #CHAMELEON_DISABLE_REGS
85         sty     CHAMELEON_CFGENA
86         rts
87
88 is_slow_mode:
89         txa
90         bne     return_value
91
92 is_max_mode:
93         lda     #SPEED_FAST
94         bne     return_value
95
96 activate_regs:
97         ldy     #CHAMELEON_ENABLE_REGS
98         sty     CHAMELEON_CFGENA
99         rts
100