]> git.sur5r.net Git - cc65/blob - libsrc/c128/acc_c128_speed.s
Optimized the code a bit as suggested by Greg.
[cc65] / libsrc / c128 / acc_c128_speed.s
1 ;
2 ; Marco van den Heuvel, 2018-04-23
3 ;
4
5 ; extern unsigned char __fastcall__ set_c128_speed (unsigned char speed);
6 ;
7 ;/* Set the speed of the C128 8502 CPU, using SPEED_SLOW will switch to
8 ; * 1 Mhz (slow) mode, SPEED_2X or SPEED_FAST will switch to 2Mhz (fast) mode.
9 ; *
10 ; * Note that any value higher or equal to SPEED_2X 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 ; * For C64 programs a check for a C128 in C64 mode is needed, make sure you
16 ; * use 'detect_c128();' before using.
17 ; *
18 ; * For C128 programs no detect function call is needed.
19 ; */
20
21 ; extern unsigned char get_c128_speed (void);
22 ;
23 ;/* Get the speed of the C128 8502 CPU.
24 ; *
25 ; * Possible return values:
26 ; * SPEED_SLOW  : Slow mode
27 ; * SPEED_2X    : Fast mode
28 ; *
29 ; * For C64 programs a check for a C128 in C64 mode is needed, make sure you
30 ; * use 'detect_c128();' before using.
31 ; *
32 ; * For C128 programs no detect function call is needed.
33 ; */
34
35         .export         _set_c128_speed
36         .export         _get_c128_speed
37
38         .include        "accelerator.inc"
39
40 _set_c128_speed:
41         cmp     #SPEED_2X
42         bcs     high_speed
43 store_speed:
44         sta     C128_VICIIE_CLK
45
46         .byte   $2C              ; skip over the lda #$01
47 high_speed:
48         lda     #$01
49         bne     store_speed
50
51 _get_c128_speed:
52         lda     C128_VICIIE_CLK
53         and     #$01
54         ldx     #$00
55         rts
56