]> git.sur5r.net Git - cc65/blob - libsrc/c64/acc_c65_speed.s
Minor math optimizations
[cc65] / libsrc / c64 / acc_c65_speed.s
1 ;
2 ; Marco van den Heuvel, 2018-04-27
3 ;
4
5 ; unsigned char __fastcall__ set_c65_speed (unsigned char speed);
6 ;
7 ;/* Set the speed of the C65 CPU, using SPEED_SLOW will switch to
8 ; * 1 Mhz mode, SPEED_3X or SPEED_FAST will switch to 3.5 Mhz (fast) mode.
9 ; *
10 ; * Note that any value higher or equal to SPEED_3X will switch to fast mode.
11 ; *
12 ; * This function will return the actual speed the CPU is at after trying
13 ; * to set the requested speed, to my knowledge the switching should not fail.
14 ; *
15 ; * This function does not check for the presence of a C65/C64DX in C64 mode,
16 ; * make sure you use 'detect_c65();' before using.
17 ; */
18
19 ; unsigned char get_c65_speed (void);
20 ;
21 ;/* Get the speed of the C65 CPU.
22 ; *
23 ; * Possible return values:
24 ; * SPEED_SLOW  : 1 Mhz mode
25 ; * SPEED_3X    : 3.5 Mhz mode
26 ; *
27 ; * This function does not check for the presence of a C65/C64DX in C64 mode,
28 ; * make sure you use 'detect_c65();' before using.
29 ; */
30
31         .export         _set_c65_speed
32         .export         _get_c65_speed
33
34         .include        "accelerator.inc"
35
36 _set_c65_speed:
37         tay
38         jsr     activate_new_vic_mode
39         cpy     #SPEED_3X
40         bcs     high_speed
41 low_speed:
42         and     #$BF
43 store_speed:
44         sta     C65_VICIII_CTRL_B
45         lda     C65_VICIII_CTRL_B
46         jmp     return_c65_speed
47
48 high_speed:
49         ora     #$40
50         bne     store_speed
51
52 _get_c65_speed:
53         jsr     activate_new_vic_mode
54 return_c65_speed:
55         sta     C65_VICIII_KEY
56         and     #$40
57         beq     speed_is_slow              ; when this branch is taken then register A is already set to SPEED_SLOW
58         lda     #SPEED_3X
59 speed_is_slow:
60         ldx     #$00
61         rts
62
63 activate_new_vic_mode:
64         lda     #C65_VICIII_UNLOCK_1
65         sta     C65_VICIII_KEY
66         lda     #C65_VICIII_UNLOCK_2
67         sta     C65_VICIII_KEY
68         lda     C65_VICIII_CTRL_B
69         rts