1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00

Added C64/C128 SuperCPU accelerator functions and started on a generic framework for accelerators.

This commit is contained in:
Marco van den Heuvel 2018-04-09 19:36:53 -07:00
parent 60b9ea3222
commit 89c3ed6d7f
9 changed files with 419 additions and 0 deletions

34
asminc/accelerator.inc Normal file
View File

@ -0,0 +1,34 @@
;
; Accelerator definitions.
;
; ---------------------------------------------------------------------------
; Speed definitions for all accelerator, to be used as input for the 'set'
; functions.
SPEED_SLOW := $00
SPEED_FAST := $FF
SPEED_1X := SPEED_SLOW
SPEED_2X := 2 - 1
SPEED_3X := 3 - 1
SPEED_4X := 4 - 1
SPEED_5X := 5 - 1
SPEED_6X := 6 - 1
SPEED_7X := 7 - 1
SPEED_8X := 8 - 1
SPEED_10X := 10 - 1
SPEED_12X := 12 - 1
SPEED_16X := 16 - 1
SPEED_20X := 20 - 1
; ---------------------------------------------------------------------------
; C64/C128 Super CPU cartridge
SuperCPU_Slow := $D07A
SuperCPU_Fast := $D07B
SuperCPU_Speed_Mode := $D0B8
SuperCPU_Detect := $D0BC

View File

@ -88,6 +88,18 @@ url="funcref.html" name="function reference"> for declaration and usage.
</itemize>
<sect1>C128-specific accelerator functions<p>
The functions listed below are accelerator functions for the C128. See the <url
url="funcref.html" name="function reference"> for declaration and usage.
<itemize>
<item>detect_scpu
<item>scpu_get_speed
<item>scpu_set_speed
</itemize>
<sect1>CBM-specific functions<p>
Some functions are available for all (or at least most) of the Commodore

View File

@ -169,6 +169,18 @@ url="funcref.html" name="function reference"> for declaration and usage.
</itemize>
<sect1>C64-specific accelerator functions<p>
The functions listed below are accelerator functions for the C64. See the <url
url="funcref.html" name="function reference"> for declaration and usage.
<itemize>
<item>detect_scpu
<item>scpu_get_speed
<item>scpu_set_speed
</itemize>
<sect1>CBM-specific functions<p>
Some functions are available for all (or at least most) of the Commodore

View File

@ -65,6 +65,15 @@ function.
</itemize>
<sect1><tt/accelerator.h/<label id="accelerator.h"><p>
<itemize>
<item><ref id="detect_scpu" name="detect_scpu">
<item><ref id="get_scpu_speed" name="get_scpu_speed">
<item><ref id="set_scpu_speed" name="set_scpu_speed">
</itemize>
<sect1><tt/apple2.h/<label id="apple2.h"><p>
<itemize>
@ -2911,6 +2920,26 @@ used in presence of a prototype.
</quote>
<sect1>detect_scpu<label id="detect_scpu"><p>
<quote>
<descrip>
<tag/Function/Check for the presence of the C64/C128 SuperCPU cartridge.
<tag/Header/<tt/<ref id="accelerator.h" name="accelerator.h">/
<tag/Declaration/<tt/unsigned char detect_scpu (void);/
<tag/Description/The function returns a 1 if a SuperCPU cartridge has been detected.
<tag/Notes/<itemize>
<item>The function is specific to the C128 and C64.
</itemize>
<tag/Availability/cc65 (not all platforms)
<tag/See also/
<ref id="get_scpu_speed" name="get_scpu_speed">,
<ref id="set_scpu_speed" name="set_scpu_speed">,
<tag/Example/None.
</descrip>
</quote>
<sect1>div<label id="div"><p>
<quote>
@ -3450,6 +3479,28 @@ header files define constants that can be used to check the return code.
</quote>
<sect1>get_scpu_speed<label id="get_scpu_speed"><p>
<quote>
<descrip>
<tag/Function/Get the current speed of the C64/C128 SuperCPU cartridge.
<tag/Header/<tt/<ref id="accelerator.h" name="accelerator.h">/
<tag/Declaration/<tt/unsigned char get_scpu_speed (void);/
<tag/Description/The function returns the current speed of the SuperCPU cartridge.
<tag/Notes/<itemize>
<item>The function is specific to the C128 and C64.
<item>The function does not check for the presence of the cartridge.
<item>See the accelerator.h header for the speed definitions.
</itemize>
<tag/Availability/cc65 (not all platforms)
<tag/See also/
<ref id="detect_scpu" name="detect_scpu">,
<ref id="set_scpu_speed" name="set_scpu_speed">,
<tag/Example/None.
</descrip>
</quote>
<sect1>getcpu<label id="getcpu"><p>
<quote>
@ -6001,6 +6052,28 @@ clean-up when exitting the program.
</quote>
<sect1>set_scpu_speed<label id="set_scpu_speed"><p>
<quote>
<descrip>
<tag/Function/Set the current speed of the C64/C128 SuperCPU cartridge.
<tag/Header/<tt/<ref id="accelerator.h" name="accelerator.h">/
<tag/Declaration/<tt/unsigned char set_scpu_speed (unsigned char speed);/
<tag/Description/The function returns the speed after trying to set the speed of the SuperCPU cartridge.
<tag/Notes/<itemize>
<item>The function is specific to the C128 and C64.
<item>The function does not check for the presence of the cartridge.
<item>See the accelerator.h header for the speed definitions.
</itemize>
<tag/Availability/cc65 (not all platforms)
<tag/See also/
<ref id="detect_scpu" name="detect_scpu">,
<ref id="get_scpu_speed" name="get_scpu_speed">,
<tag/Example/None.
</descrip>
</quote>
<sect1>setjmp<label id="setjmp"><p>
<quote>

102
include/accelerator.h Normal file
View File

@ -0,0 +1,102 @@
/*****************************************************************************/
/* */
/* accelerator.h */
/* */
/* Accelerator specific definitions */
/* */
/* */
/* */
/* (C) 2018 Marco van den Heuvel */
/* EMail: blackystardust68@yahoo.com */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */
/* */
/* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */
/* */
/* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */
/* distribution. */
/* */
/*****************************************************************************/
#ifndef _ACCELERATOR_H
#define _ACCELERATOR_H
/*****************/
/* Speed defines */
/*****************/
#define SPEED_SLOW 0x00
#define SPEED_FAST 0xFF
#define SPEED_1X SPEED_SLOW
#define SPEED_2X 2 - 1 /* C64 Chameleon, C64DTV, C128, PET 65816, Apple2 Fast Chip, Apple2 TransWarp, Apple2 Zip Chip */
#define SPEED_3X 3 - 1 /* C64 Chameleon, C65, PET 65816, Apple2 Booster, Apple 2 Fast Chip, Apple2 Titan, Apple2 TransWarp, Apple2 Zip Chip */
#define SPEED_4X 4 - 1 /* C64 Chameleon, C64 TurboMaster, C64 TurboProcess, PET 65816, Apple2 Fast Chip, Apple2 Zip Chip */
#define SPEED_5X 5 - 1 /* C64 Chameleon, PET 65816, Apple2 Fast Chip */
#define SPEED_6X 6 - 1 /* C64 Chameleon, PET 65816, Apple2 Fast Chip */
#define SPEED_7X 7 - 1 /* PET 65816, Apple2 Fast Chip */
#define SPEED_8X 8 - 1 /* C64 Flash8, PET 65816, Apple 2 Fast Chip */
#define SPEED_10X 10 - 1 /* PET 65816, Apple2 Fast Chip */
#define SPEED_12X 12 - 1 /* Apple2 Fast Chip */
#define SPEED_16X 16 - 1 /* Apple2 Fast Chip */
#define SPEED_20X 20 - 1 /* C64/C128 SuperCPU */
/***********************************/
/* Accelerator function prototypes */
/***********************************/
/* C64/C128 SuperCPU cartridge */
extern unsigned char __fastcall__ set_scpu_speed (unsigned char speed);
/* Set the speed of the SuperCPU cartridge, using SPEED_SLOW will switch to
* 1 Mhz mode, SPEED_20X or SPEED_FAST will switch to 20 Mhz mode.
*
* Note that any value lower than SPEED_20X will switch to 1 Mhz mode, and
* any value higher or equal to SPEED_20X will switch to 20 Mhz mode.
*
* This function will return the actual speed the CPU is at after trying
* to set the requested speed, if this is not the speed that was requested
* then possibly the hardware speed switch prevented any software speed
* switching.
*
* This function does not check for the presence of the SuperCPU cartridge,
* make sure you use 'detect_scpu();' before using.
*/
extern unsigned char get_scpu_speed (void);
/* Get the speed of the SuperCPU cartridge.
*
* Possible return values:
* SPEED_1X : 1 Mhz mode
* SPEED_20X : 20 Mhz mode
*
* This function does not check for the presence of the SuperCPU cartridge,
* make sure you use 'detect_scpu();' before using.
*/
extern unsigned char detect_scpu (void);
/* Check for the presence of the SuperCPU cartridge.
*
* Possible return values:
* 0x00 : SuperCPU cartridge not present
* 0x01 : SuperCPU cartridge present
*/
/* End of accelerator.h */
#endif

34
libsrc/c128/acc_detect_scpu.s Executable file
View File

@ -0,0 +1,34 @@
;
; Marco van den Heuvel, 2018-04-08
;
; unsigned char detect_scpu (void);
;
;/* Check for the presence of the SuperCPU cartridge.
; *
; * Possible return values:
; * 0x00 : SuperCPU cartridge not present
; * 0x01 : SuperCPU cartridge present
; */
.export _detect_scpu
.include "accelerator.inc"
_detect_scpu:
ldx #$00
txa
; Make sure the current CPU is a 65816
clc
.byte $E2,$01 ; NOP #$01 on 6510 and 65(S)C02, LDA $(01,S),Y on 65CE02 and 4510, SEP #$01 on 65816
bcc not_found ; carry will be set on 65816
; 65816 has been detected, make sure it's the SuperCPU cartridge
lda SuperCPU_Detect
asl
bcs not_found
found:
lda #$01
not_found:
rts

59
libsrc/c128/acc_scpu_speed.s Executable file
View File

@ -0,0 +1,59 @@
;
; Marco van den Heuvel, 2018-04-09
;
; extern unsigned char __fastcall__ set_scpu_speed (unsigned char speed);
;
;/* Set the speed of the SuperCPU cartridge, using SPEED_SLOW will switch to
; * 1 Mhz mode, SPEED_20X or SPEED_FAST will switch to 20 Mhz mode.
; *
; * Note that any value lower than SPEED_20X will switch to 1 Mhz mode, and
; * any value higher or equal to SPEED_20X will switch to 20 Mhz mode.
; *
; * This function will return the actual speed the CPU is at after trying
; * to set the requested speed, if this is not the speed that was requested
; * then possibly the hardware speed switch prevented any software speed
; * switching.
; *
; * This function does not check for the presence of the SuperCPU cartridge,
; * make sure you use 'detect_scpu();' before using.
; */
; extern unsigned char get_scpu_speed (void);
;
;/* Get the speed of the SuperCPU cartridge.
; *
; * Possible return values:
; * SPEED_1X : 1 Mhz mode
; * SPEED_20X : 20 Mhz mode
; *
; * This function does not check for the presence of the SuperCPU cartridge,
; * make sure you use 'detect_scpu();' before using.
; */
.export _set_scpu_speed
.export _get_scpu_speed
.include "accelerator.inc"
_set_scpu_speed:
cmp #SPEED_20X
bcs high_speed
low_speed:
sta SuperCPU_Slow
jmp _get_scpu_speed
high_speed:
sta SuperCPU_Fast
_get_scpu_speed:
ldx #$00
lda SuperCPU_Speed_Mode
asl
asl
bcc is_fast_speed
lda #SPEED_1X
rts
is_fast_speed:
lda #SPEED_20X
rts

View File

@ -0,0 +1,34 @@
;
; Marco van den Heuvel, 2018-04-08
;
; unsigned char detect_scpu (void);
;
;/* Check for the presence of the SuperCPU cartridge.
; *
; * Possible return values:
; * 0x00 : SuperCPU cartridge not present
; * 0x01 : SuperCPU cartridge present
; */
.export _detect_scpu
.include "accelerator.inc"
_detect_scpu:
ldx #$00
txa
; Make sure the current CPU is a 65816
clc
.byte $E2,$01 ; NOP #$01 on 6510 and 65(S)C02, LDA $(01,S),Y on 65CE02 and 4510, SEP #$01 on 65816
bcc not_found ; carry will be set on 65816
; 65816 has been detected, make sure it's the SuperCPU cartridge
lda SuperCPU_Detect
asl
bcs not_found
found:
lda #$01
not_found:
rts

View File

@ -0,0 +1,59 @@
;
; Marco van den Heuvel, 2018-04-09
;
; extern unsigned char __fastcall__ set_scpu_speed (unsigned char speed);
;
;/* Set the speed of the SuperCPU cartridge, using SPEED_SLOW will switch to
; * 1 Mhz mode, SPEED_20X or SPEED_FAST will switch to 20 Mhz mode.
; *
; * Note that any value lower than SPEED_20X will switch to 1 Mhz mode, and
; * any value higher or equal to SPEED_20X will switch to 20 Mhz mode.
; *
; * This function will return the actual speed the CPU is at after trying
; * to set the requested speed, if this is not the speed that was requested
; * then possibly the hardware speed switch prevented any software speed
; * switching.
; *
; * This function does not check for the presence of the SuperCPU cartridge,
; * make sure you use 'detect_scpu();' before using.
; */
; extern unsigned char get_scpu_speed (void);
;
;/* Get the speed of the SuperCPU cartridge.
; *
; * Possible return values:
; * SPEED_1X : 1 Mhz mode
; * SPEED_20X : 20 Mhz mode
; *
; * This function does not check for the presence of the SuperCPU cartridge,
; * make sure you use 'detect_scpu();' before using.
; */
.export _set_scpu_speed
.export _get_scpu_speed
.include "accelerator.inc"
_set_scpu_speed:
cmp #SPEED_20X
bcs high_speed
low_speed:
sta SuperCPU_Slow
jmp _get_scpu_speed
high_speed:
sta SuperCPU_Fast
_get_scpu_speed:
ldx #$00
lda SuperCPU_Speed_Mode
asl
asl
bcc is_fast_speed
lda #SPEED_1X
rts
is_fast_speed:
lda #SPEED_20X
rts