From 89c3ed6d7f82de68fb909978529261ac2d88c09a Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Mon, 9 Apr 2018 19:36:53 -0700 Subject: [PATCH] Added C64/C128 SuperCPU accelerator functions and started on a generic framework for accelerators. --- asminc/accelerator.inc | 34 ++++++++++++ doc/c128.sgml | 12 ++++ doc/c64.sgml | 12 ++++ doc/funcref.sgml | 73 ++++++++++++++++++++++++ include/accelerator.h | 102 ++++++++++++++++++++++++++++++++++ libsrc/c128/acc_detect_scpu.s | 34 ++++++++++++ libsrc/c128/acc_scpu_speed.s | 59 ++++++++++++++++++++ libsrc/c64/acc_detect_scpu.s | 34 ++++++++++++ libsrc/c64/acc_scpu_speed.s | 59 ++++++++++++++++++++ 9 files changed, 419 insertions(+) create mode 100644 asminc/accelerator.inc create mode 100644 include/accelerator.h create mode 100755 libsrc/c128/acc_detect_scpu.s create mode 100755 libsrc/c128/acc_scpu_speed.s create mode 100644 libsrc/c64/acc_detect_scpu.s create mode 100644 libsrc/c64/acc_scpu_speed.s diff --git a/asminc/accelerator.inc b/asminc/accelerator.inc new file mode 100644 index 000000000..1bc8fb11e --- /dev/null +++ b/asminc/accelerator.inc @@ -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 + diff --git a/doc/c128.sgml b/doc/c128.sgml index 2bfb37a3d..9af66d62b 100644 --- a/doc/c128.sgml +++ b/doc/c128.sgml @@ -88,6 +88,18 @@ url="funcref.html" name="function reference"> for declaration and usage. +C128-specific accelerator functions

+ +The functions listed below are accelerator functions for the C128. See the for declaration and usage. + + +detect_scpu +scpu_get_speed +scpu_set_speed + + + CBM-specific functions

Some functions are available for all (or at least most) of the Commodore diff --git a/doc/c64.sgml b/doc/c64.sgml index 7cca1aa09..05b87a22b 100644 --- a/doc/c64.sgml +++ b/doc/c64.sgml @@ -169,6 +169,18 @@ url="funcref.html" name="function reference"> for declaration and usage. +C64-specific accelerator functions

+ +The functions listed below are accelerator functions for the C64. See the for declaration and usage. + + +detect_scpu +scpu_get_speed +scpu_set_speed + + + CBM-specific functions

Some functions are available for all (or at least most) of the Commodore diff --git a/doc/funcref.sgml b/doc/funcref.sgml index 5f90cfd3e..e47a0c0a9 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -65,6 +65,15 @@ function. +

+ + + + + + + +

@@ -2911,6 +2920,26 @@ used in presence of a prototype. +detect_scpu

+ + + +/ + +The function is specific to the C128 and C64. + +, +, + + + + div

@@ -3450,6 +3479,28 @@ header files define constants that can be used to check the return code. +get_scpu_speed

+ + + +/ + +The function is specific to the C128 and C64. +The function does not check for the presence of the cartridge. +See the accelerator.h header for the speed definitions. + +, +, + + + + getcpu

@@ -6001,6 +6052,28 @@ clean-up when exitting the program. +set_scpu_speed

+ + + +/ + +The function is specific to the C128 and C64. +The function does not check for the presence of the cartridge. +See the accelerator.h header for the speed definitions. + +, +, + + + + setjmp

diff --git a/include/accelerator.h b/include/accelerator.h new file mode 100644 index 000000000..7d1244233 --- /dev/null +++ b/include/accelerator.h @@ -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 diff --git a/libsrc/c128/acc_detect_scpu.s b/libsrc/c128/acc_detect_scpu.s new file mode 100755 index 000000000..e42d90548 --- /dev/null +++ b/libsrc/c128/acc_detect_scpu.s @@ -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 diff --git a/libsrc/c128/acc_scpu_speed.s b/libsrc/c128/acc_scpu_speed.s new file mode 100755 index 000000000..4bd142bbb --- /dev/null +++ b/libsrc/c128/acc_scpu_speed.s @@ -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 diff --git a/libsrc/c64/acc_detect_scpu.s b/libsrc/c64/acc_detect_scpu.s new file mode 100644 index 000000000..e42d90548 --- /dev/null +++ b/libsrc/c64/acc_detect_scpu.s @@ -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 diff --git a/libsrc/c64/acc_scpu_speed.s b/libsrc/c64/acc_scpu_speed.s new file mode 100644 index 000000000..4bd142bbb --- /dev/null +++ b/libsrc/c64/acc_scpu_speed.s @@ -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 -- 2.39.5