From fc7917a39d1bd930fa11f0d9c4de68dfcc16d141 Mon Sep 17 00:00:00 2001 From: Andy Grind Date: Wed, 21 Mar 2018 22:14:11 -0400 Subject: [PATCH] Oh hey Curly was causing an address error in MazeM and Almond --- Makefile | 1 - inc/common.h | 24 ++- inc/psg.h | 130 --------------- inc/smp_null.h | 1 - inc/stdint.h | 21 --- inc/tab_vol.h | 1 - inc/xgm.h | 202 +---------------------- inc/ym2612.h | 80 --------- inc/z80_ctrl.h | 239 --------------------------- src/ai/maze.c | 3 +- src/audio.c | 11 +- src/config.c | 1 - src/game.c | 4 +- src/main.c | 15 +- src/sheet.c | 4 +- src/stage.c | 2 - src/system.c | 61 +++---- src/tsc.c | 2 +- src/vdp_pal.c | 2 +- src/xgm.c | 394 ++++++++++++++++++++++++++++++++++++++++++++ src/xgm/psg.c | 73 --------- src/xgm/smp_null.s | 22 --- src/xgm/tab_vol.c | 276 ------------------------------- src/xgm/xgm.c | 400 --------------------------------------------- src/xgm/ym2612.c | 101 ------------ src/xgm/z80_ctrl.c | 201 ----------------------- 26 files changed, 459 insertions(+), 1812 deletions(-) delete mode 100644 inc/psg.h delete mode 100644 inc/smp_null.h delete mode 100644 inc/stdint.h delete mode 100644 inc/tab_vol.h delete mode 100644 inc/ym2612.h delete mode 100644 inc/z80_ctrl.h create mode 100644 src/xgm.c delete mode 100644 src/xgm/psg.c delete mode 100644 src/xgm/smp_null.s delete mode 100644 src/xgm/tab_vol.c delete mode 100644 src/xgm/xgm.c delete mode 100644 src/xgm/ym2612.c delete mode 100644 src/xgm/z80_ctrl.c diff --git a/Makefile b/Makefile index ac90cc61..d1dd2ed7 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,6 @@ Z80S = $(wildcard src/xgm/*.s80) CS = $(wildcard src/*.c) CS += $(wildcard src/ai/*.c) CS += $(wildcard src/db/*.c) -CS += $(wildcard src/xgm/*.c) SS = $(wildcard src/*.s) SS += $(wildcard src/xgm/*.s) OBJS = $(RESS:.res=.o) diff --git a/inc/common.h b/inc/common.h index 5cd9dc63..31cedec1 100644 --- a/inc/common.h +++ b/inc/common.h @@ -1,4 +1,24 @@ -#include +#define FALSE 0 +#define TRUE 1 +#define NULL 0 + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed long int32_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; + +// SGDK Compatibility + +typedef int8_t s8; +typedef int16_t s16; +typedef int32_t s32; + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; //#define PROFILE_BG #ifdef PROFILE_BG @@ -12,7 +32,7 @@ #define MUSIC_TICK() ({ \ if(vblank) { \ - XGM_doVBlankProcess(); \ + xgm_vblank(); \ vblank = 0; \ } \ }) diff --git a/inc/psg.h b/inc/psg.h deleted file mode 100644 index cec8eba8..00000000 --- a/inc/psg.h +++ /dev/null @@ -1,130 +0,0 @@ -/** - * \file psg.h - * \brief PSG support - * \author Stephane Dallongeville - * \date 08/2011 - * - * This unit provides access to the PSG through the 68000 CPU - */ - -/** - * \brief - * PSG port address. - */ -#define PSG_PORT 0xC00011 - -/** - * \brief - * Minimum PSG envelope value. - */ -#define PSG_ENVELOPE_MIN 15 -/** - * \brief - * Maximum PSG envelope value. - */ -#define PSG_ENVELOPE_MAX 0 - -/** - * \brief - * Periodic noise type (like low-frequency tone). - */ -#define PSG_NOISE_TYPE_PERIODIC 0 -/** - * \brief - * White noise type (hiss). - */ -#define PSG_NOISE_TYPE_WHITE 1 - -/** - * \brief - * Noise frequency = PSG clock / 2 (less coarse). - */ -#define PSG_NOISE_FREQ_CLOCK2 0 -/** - * \brief - * Noise frequency = PSG clock / 4. - */ -#define PSG_NOISE_FREQ_CLOCK4 1 -/** - * \brief - * Noise frequency = PSG clock / 8 (more coarse). - */ -#define PSG_NOISE_FREQ_CLOCK8 2 -/** - * \brief - * Noise frequency = Tone generator #3. - */ -#define PSG_NOISE_FREQ_TONE3 3 - - -/** - * \brief - * Initialize PSG chip - */ -void PSG_init(); - -/** - * \brief - * Write to PSG port. - * - * \param data - * value to write to the port. - * - * Write the specified value to PSG data port. - * - */ -void PSG_write(uint8_t data); - -/** - * \brief - * Set envelope level. - * - * \param channel - * Channel we want to set envelope (0-3). - * \param value - * Envelope level to set (#PSG_ENVELOPE_MIN - #PSG_ENVELOPE_MAX). - * - * Set envelope level for the specified PSG channel. - */ -void PSG_setEnvelope(uint8_t channel, uint8_t value); -/** - * \brief - * Set tone. - * - * \param channel - * Channel we want to set tone (0-3). - * \param value - * Tone value to set (0-1023). - * - * Set direct tone value for the specified PSG channel. - */ -void PSG_setTone(uint8_t channel, uint16_t value); -/** - * \brief - * Set frequency. - * - * \param channel - * Channel we want to set frequency (0-3). - * \param value - * Frequency value to set in Hz (0-4095). - * - * Set frequency for the specified PSG channel.
- * This method actually converts the specified frequency value in PSG tone value. - */ -void PSG_setFrequency(uint8_t channel, uint16_t value); -/** - * \brief - * Set noise type and frequency. - * - * \param type - * Noise type, accepted values are:
- * #PSG_NOISE_TYPE_PERIODIC
- * #PSG_NOISE_TYPE_WHITE - * \param frequency - * Noise frequency, accepted values are:
- * #PSG_NOISE_FREQ_CLOCK2
- * #PSG_NOISE_FREQ_CLOCK4
- * #PSG_NOISE_FREQ_CLOCK8
- * #PSG_NOISE_FREQ_TONE3 - */ -void PSG_setNoise(uint8_t type, uint8_t frequency); diff --git a/inc/smp_null.h b/inc/smp_null.h deleted file mode 100644 index 7beccce6..00000000 --- a/inc/smp_null.h +++ /dev/null @@ -1 +0,0 @@ -extern const uint8_t smp_null[0x100]; diff --git a/inc/stdint.h b/inc/stdint.h deleted file mode 100644 index 2f1adf08..00000000 --- a/inc/stdint.h +++ /dev/null @@ -1,21 +0,0 @@ -#define FALSE 0 -#define TRUE 1 -#define NULL 0 - -typedef signed char int8_t; -typedef signed short int16_t; -typedef signed long int32_t; - -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned long uint32_t; - -// SGDK Compatibility - -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; diff --git a/inc/tab_vol.h b/inc/tab_vol.h deleted file mode 100644 index ffdb86ea..00000000 --- a/inc/tab_vol.h +++ /dev/null @@ -1 +0,0 @@ -extern const uint8_t tab_vol[0x1000]; diff --git a/inc/xgm.h b/inc/xgm.h index 68ca32cc..ae8872e0 100644 --- a/inc/xgm.h +++ b/inc/xgm.h @@ -1,198 +1,12 @@ -/** - * \file xgm.h - * \brief XGM sound driver - * \author Stephane Dallongeville - * \date 08/2015 - * - * This unit provides methods to use the XGM (eXtended Genesis Music) sound driver.
- * This driver takes VGM (or XGM) file as input to play music.
- * It supports 4 PCM channels at a fixed 14 Khz and allows to play SFX through PCM with 16 level of priority.
- * The driver is designed to avoid DMA contention when possible (depending CPU load). - */ +void z80_request(); +void z80_release(); -/** - * \brief - * Returns play music state (XGM music player driver). - */ -uint8_t XGM_isPlaying(); -/** - * \brief - * Start playing the specified XGM track (XGM music player driver). - * - * \param song - * XGM track address. - * - * \see XGM_stopPlay - * \see XGM_pausePlay - * \see XGM_nextFrame - */ -void XGM_startPlay(const uint8_t *song); -/** - * \brief - * Stop playing music (XGM music player driver). - * - * \see XGM_pausePlay - */ -void XGM_stopPlay(); -/** - * \brief - * Pause playing music, music can be resumed by calling #XGM_resumePlay (XGM music player driver). - * - * \see XGM_resumePlay - * \see XGM_stopPlay - */ -void XGM_pausePlay(); -/** - * \brief - * Resume playing music after pausing with XGM_pausePlay (XGM music player driver). - * - * \see XGM_pausePlay - * \see XGM_nextFrame - */ -void XGM_resumePlay(); +void xgm_init(); -/** - * \brief - * Return play status of specified PCM channel (XGM music player driver). - * - * \param channel_mask - * Channel(s) we want to retrieve play state.
- * #SOUND_PCM_CH1_MSK = channel 1
- * #SOUND_PCM_CH2_MSK = channel 2
- * #SOUND_PCM_CH3_MSK = channel 3
- * #SOUND_PCM_CH4_MSK = channel 4
- *
- * You can combine mask to retrieve state of severals channels at once:
- * isPlayingPCM(SOUND_PCM_CH1_MSK | SOUND_PCM_CH2_MSK)
- * will actually return play state for channel 1 and channel 2. - * - * \return - * Return non zero if specified channel(s) is(are) playing. - */ -uint8_t XGM_isPlayingPCM(const uint16_t channel_mask); -/** - * \brief - * Declare a new PCM sample (maximum = 255) for the XGM music player driver.
- * Sample id < 64 are reserved for music while others are used for SFX - * so if you want to declare a new SFX PCM sample use an id >= 64 - * - * \param id - * Sample id:
- * value 0 is not allowed
- * values from 1 to 63 are used for music - * values from 64 to 255 are used for SFX - * \param sample - * Sample address, should be 256 bytes boundary aligned
- * SGDK automatically align sample resource as needed - * \param len - * Size of sample in bytes, should be a multiple of 256
- * SGDK automatically adjust resource size as needed - */ -void XGM_setPCM(const uint8_t id, const uint8_t *sample, const uint32_t len); -/** - * \brief - * Same as #XGM_setPCM but fast version.
- * This method assume that XGM driver is loaded and that 68000 has access to Z80 bus - * - * \param id - * Sample id:
- * value 0 is not allowed
- * values from 1 to 63 are used for music - * values from 64 to 255 are used for SFX - * \param sample - * Sample address, should be 256 bytes boundary aligned
- * SGDK automatically align sample resource as needed - * \param len - * Size of sample in bytes, should be a multiple of 256
- * SGDK automatically adjust resource size as needed - */ -void XGM_setPCMFast(const uint8_t id, const uint8_t *sample, const uint32_t len); -/** - * \brief - * Play a PCM sample on specified channel (XGM music player driver).
- * If a sample was currently playing on this channel then priority of the newer sample should be are compared then it's stopped and the new sample is played instead.
- * Note that music may use the first PCM channel so it's better to use channel 2 to 4 for SFX. - * - * \param id - * Sample id (set #XGM_setPCM method) - * \param priority - * Value should go from 0 to 15 where 0 is lowest priority and 15 the highest one.
- * If the channel was already playing the priority is used to determine if the new SFX should replace the current one (new priority >= old priority). - * \param channel - * Channel where we want to play sample.
- * #SOUND_PCM_CH1 = channel 1 (usually used by music)
- * #SOUND_PCM_CH2 = channel 2
- * #SOUND_PCM_CH3 = channel 3
- * #SOUND_PCM_CH4 = channel 4
- */ -void XGM_startPlayPCM(const uint8_t id, const uint8_t priority, const uint16_t channel); -/** - * \brief - * Stop play PCM on specified channel (XGM music player driver).
- * No effect if no sample was currently playing on this channel. - * - * \param channel - * Channel we want to stop.
- * #SOUND_PCM_CH1 = channel 1
- * #SOUND_PCM_CH2 = channel 2
- * #SOUND_PCM_CH3 = channel 3
- * #SOUND_PCM_CH4 = channel 4
- */ -void XGM_stopPlayPCM(const uint16_t channel); +void xgm_music_play(const uint8_t *song); +void xgm_music_stop(); -/** - * \brief - * Return the elapsed play time since the last #XGM_startPlay(..) call.
- * The returned value is in music frame which can be 50/60 per second depending the base music play rate (NTSC/PAL). - * - * \see XGM_startPlay(..) - * \see XGM_setMusicTempo() - */ -uint32_t XGM_getElapsed(); +void xgm_pcm_set(const uint8_t id, const uint8_t *sample, const uint32_t len); +void xgm_pcm_play(const uint8_t id, const uint8_t priority, const uint16_t channel); -/** - * \brief - * Set the music tempo (in tick per second).
- * Default value is 60 or 50 depending the system is NTSC or PAL. - * This method is meaningful only if you use the automatic music sync mode (see XGM_setManualSync() method) - * which is the default mode.
- * Note that using specific tempo (not 60 or 50) can completely distord FM instruments sound and affect - * performance of DMA contention and external command parsing so it's recommended to stand with default one. - * - * \see XGM_setManualSync() - * \see XGM_getMusicTempo() - */ -void XGM_setMusicTempo(uint16_t value); - -/** - * \brief - * Notify the Z80 a new frame just happened (XGM music player driver). - * - * Sound synchronization was initially 100% done by Z80 itself using the V-Interrupt but - * if the Z80 is stopped right at V-Int time (bus request from 68000 or DMA stall) then - * the V-Int can be missed by the Z80 and music timing affected.
- * To fix that issue and also to offer more flexibility the music timing should now be handled by the 68k.
- * By default this method is called automatically by SGDK at V-Int time but you can decide to handle sync - * manually (see XGM_setManualSync(..) method).
- * When you are in manual sync you normally should call this method once per frame (in the V-Int callback for instance) - * but you are free to play with it to increase or decrease music tempo.
- * Note that it's better to call this method a bit before (3/4 scanlines should be fine) doing DMA operation for best - * main bus contention protection (see #XGM_set68KBUSProtection() and #XGM_setForceDelayDMA() methods). - * - * \see XGM_setManualSync(..) - * \see XGM_nextXFrame(..) - * \see XGM_set68KBUSProtection(..) - * \see XGM_setForceDelayDMA(..) - */ -#define XGM_nextFrame() XGM_nextXFrame(1) -/** - * \brief - * Same as XGM_nextFrame() except you can specify the numer of frame. - * - * \see XGM_nextFrame(..) - */ -void XGM_nextXFrame(uint16_t num); - -void XGM_set68KBUSProtection(uint8_t value); - -void XGM_doVBlankProcess(); +void xgm_vblank(); diff --git a/inc/ym2612.h b/inc/ym2612.h deleted file mode 100644 index 0d2e88ea..00000000 --- a/inc/ym2612.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * \file ym2612.h - * \brief YM2612 support - * \author Stephane Dallongeville - * \date 08/2011 - * - * This unit provides access to the YM2612 through the 68000 CPU. - */ - -/** - * \brief - * YM2612 base port address. - */ -#define YM2612_BASEPORT 0xA04000 - - -/** - * \brief - * Reset YM2612 chip - */ -void YM2612_reset(); - -/** - * \brief - * Read YM2612 port. - * - * \param port - * Port number (0-3) - * \return YM2612 port value. - * - * Reading YM2612 always return YM2612 status (busy and timer flag) whatever is the port read. - */ -uint8_t YM2612_read(const uint16_t port); -/** - * \brief - * Write YM2612 port. - * - * \param port - * Port number (0-3) - * \param data - * Data to write - * - * This function does not perform busy check before writing to YM port.
- * See also YM2612_writeSafe(). - */ -void YM2612_write(const uint16_t port, const uint8_t data); -/** - * \deprecated Use YM2612_write(..) method instead. - */ -void YM2612_writeSafe(const uint16_t port, const uint8_t data); -/** - * \brief - * Set YM2612 register value. - * - * \param part - * part number (0-1) - * \param reg - * register number - * \param data - * register value - * - * This function does not perform busy check before writing to YM port.
- * See also YM2612_writeRegSafe(). - */ -void YM2612_writeReg(const uint16_t part, const uint8_t reg, const uint8_t data); -/** - * \deprecated Use YM2612_writeReg(..) method instead. - */ -void YM2612_writeRegSafe(const uint16_t part, const uint8_t reg, const uint8_t data); - -/** - * \brief - * Enable YM2612 DAC. - */ -void YM2612_enableDAC(); -/** - * \brief - * Disable YM2612 DAC. - */ -void YM2612_disableDAC(); diff --git a/inc/z80_ctrl.h b/inc/z80_ctrl.h deleted file mode 100644 index 7329d068..00000000 --- a/inc/z80_ctrl.h +++ /dev/null @@ -1,239 +0,0 @@ -/** - * \file z80_ctrl.h - * \brief Z80 control - * \author Stephane Dallongeville - * \date 08/2011 - * - * This unit provides Z80 access from the YM2612 :
- * - enable / disable Z80
- * - request / release Z80 BUS
- * - upload / download data to / from Z80 memory
- * - set Z80 external Bank
- * - Z80 driver handling
- */ - -#define Z80_HALT_PORT 0xA11100 -#define Z80_RESET_PORT 0xA11200 - -/** - * \brief - * - * Z80 RAM start address. - */ -#define Z80_RAM_START 0xA00000 -/** - * \brief - * - * Z80 RAM end address. - */ -#define Z80_RAM_END 0xA01FFF -/** - * \brief - * - * Z80 RAM address. - */ -#define Z80_RAM Z80_RAM_START -/** - * \brief - * - * Z80 RAM length in byte. - */ -#define Z80_RAM_LEN ((Z80_RAM_END - Z80_RAM_START) + 1) -/** - * \brief - * - * Z80 YM2612 port address. - */ -#define Z80_YM2612 0xA04000 -/** - * \brief - * - * Z80 Bank register address. - */ -#define Z80_BANK_REGISTER 0xA06000 - -/** - * \brief - * - * Z80 default driver command address. - */ -#define Z80_DRV_COMMAND 0xA00100 -/** - * \brief - * - * Z80 default driver status address. - */ -#define Z80_DRV_STATUS 0xA00102 -/** - * \brief - * - * Z80 default driver parameters address. - */ -#define Z80_DRV_PARAMS 0xA00104 - -// default command and status value -#define Z80_DRV_COM_PLAY_SFT 0 -#define Z80_DRV_COM_STOP_SFT 4 -#define Z80_DRV_STAT_PLAYING_SFT 0 -#define Z80_DRV_STAT_READY_SFT 7 - -/** - * \brief - * Z80 default driver play command. - */ -#define Z80_DRV_COM_PLAY (1 << Z80_DRV_COM_PLAY_SFT) -/** - * \brief - * Z80 default driver stop command. - */ -#define Z80_DRV_COM_STOP (1 << Z80_DRV_COM_STOP_SFT) -/** - * \brief - * Z80 default driver play status. - */ -#define Z80_DRV_STAT_PLAYING (1 << Z80_DRV_STAT_PLAYING_SFT) -/** - * \brief - * Z80 default driver ready status. - */ -#define Z80_DRV_STAT_READY (1 << Z80_DRV_STAT_READY_SFT) - -// channel definition -#define Z80_DRV_CH0_SFT 0 -#define Z80_DRV_CH1_SFT 1 -#define Z80_DRV_CH2_SFT 2 -#define Z80_DRV_CH3_SFT 3 - -/** - * \brief - * Z80 default driver channel 0 id. - */ -#define Z80_DRV_CH0 (1 << Z80_DRV_CH0_SFT) -/** - * \brief - * Z80 default driver channel 1 id. - */ -#define Z80_DRV_CH1 (1 << Z80_DRV_CH1_SFT) -/** - * \brief - * Z80 default driver channel 2 id. - */ -#define Z80_DRV_CH2 (1 << Z80_DRV_CH2_SFT) -/** - * \brief - * Z80 default driver channel 3 id. - */ -#define Z80_DRV_CH3 (1 << Z80_DRV_CH3_SFT) - -/** - * \brief - * Initialize Z80 sub system. - * - * Request Z80 BUS and reset bank number. - */ -void Z80_init(); - -/** - * \brief - * Return Z80 BUS taken state. - */ -uint16_t Z80_isBusTaken(); -/** - * \brief - * Request Z80 BUS. - * \param wait - * Wait for BUS request operation to complete. - */ -void Z80_requestBus(uint16_t wait); -/** - * \brief - * Release Z80 BUS. - */ -void Z80_releaseBus(); - -/** - * \brief - * Start Z80 reset. - */ -void Z80_startReset(); -/** - * \brief - * End Z80 reset. - */ -void Z80_endReset(); - -/** - * \brief - * Set Z80 memory bank. - * \param bank - * Bank number to set (0x000-0x1FF) - */ -void Z80_setBank(const uint16_t bank); - -/** - * \brief - * Read Z80 memory (Z80_RAM). - * \param addr - * Address to read (relative to start of Z80_RAM). - * - * You need to request Z80 BUS to access Z80 memory. - * - * \see Z80_requestBus(uint16_t) - */ -uint8_t Z80_read(const uint16_t addr); -/** - * \brief - * Write to Z80 memory (Z80_RAM). - * \param addr - * Address to write (relative to start of Z80_RAM). - * \param value - * Value to write. - * - * You need to request Z80 BUS to access Z80 memory. - * - * \see Z80_requestBus(uint16_t) - */ -void Z80_write(const uint16_t addr, const uint8_t value); - -/** - * \brief - * Clear Z80 memory. - * \param dest - * Destination address (Z80 memory). - * \param size - * Size in byte of region to clear. - * \param resetz80 - * Reset Z80 if set to TRUE. - */ -void Z80_clear(const uint16_t dest, const uint16_t size, const uint16_t resetz80); -/** - * \brief - * Upload data in Z80 memory. - * \param dest - * Destination address (Z80 memory). - * \param data - * Data to upload. - * \param size - * Size in byte of data to upload. - * \param resetz80 - * Reset Z80 if set to TRUE. - */ -void Z80_upload(const uint16_t dest, const uint8_t *data, const uint16_t size, const uint16_t resetz80); -/** - * \brief - * Read data from Z80 memory. - * - * \param from - * Source address (Z80 memory). - * \param dest - * Destination where to write data. - * \param size - * Size in byte of data to read. - */ -void Z80_download(const uint16_t from, uint8_t *dest, const uint16_t size); - -/** - * \brief - * Return driver ready state (only for non custom driver). - */ -uint16_t Z80_isDriverReady(); diff --git a/src/ai/maze.c b/src/ai/maze.c index e91d65b2..e9cd9173 100644 --- a/src/ai/maze.c +++ b/src/ai/maze.c @@ -768,7 +768,6 @@ void ai_poohblk_dying(Entity *e) { // MazeM enemies void ai_firewhirr(Entity *e) { - Entity *shot; FACE_PLAYER(e); switch(e->state) { @@ -802,7 +801,7 @@ void ai_firewhirr(Entity *e) { // if time to fire, spawn a shot if (e->timer2 > TIME(120)) { - shot = entity_create(e->x, e->y, OBJ_FIREWHIRR_SHOT, 0); + Entity *shot = entity_create(e->x, e->y, OBJ_FIREWHIRR_SHOT, 0); shot->dir = e->dir; shot->alwaysActive = TRUE; shot->x = e->x; diff --git a/src/audio.c b/src/audio.c index bc2a19be..02af58f2 100644 --- a/src/audio.c +++ b/src/audio.c @@ -2,7 +2,6 @@ #include "tables.h" #include "xgm.h" -#include "z80_ctrl.h" #include "audio.h" @@ -17,7 +16,7 @@ void sound_init() { // Here we are pointing the XGM driver to each sound effect in the game // and their length (in frames) indexed in sound_info for(uint8_t i = 1; i < SOUND_COUNT; i++) { - XGM_setPCM(0x80 + i, sound_info[i].sound, sound_info[i].length); + xgm_pcm_set(0x80 + i, sound_info[i].sound, sound_info[i].length); } soundChannel = 1; } @@ -25,7 +24,7 @@ void sound_init() { void sound_play(uint8_t id, uint8_t priority) { if(id >= 0x90 && id < 0xA0) id -= 0x40; if(id >= SOUND_COUNT || sound_info[id].length == 0) return; - XGM_startPlayPCM(0x80 + id, priority, soundChannel++); + xgm_pcm_play(0x80 + id, priority, soundChannel++); if(soundChannel > 3) soundChannel = 1; } @@ -35,11 +34,9 @@ void song_play(uint8_t id) { // Track 0 in song_info is NULL, but others could be potentially if(song_info[id].song == NULL) { id = 0; - XGM_stopPlay(); - //Z80_init(); + xgm_music_stop(); } else { - XGM_startPlay(song_info[id].song); - //XGM_setMusicTempo(60); + xgm_music_play(song_info[id].song); } songPlaying = id; } diff --git a/src/config.c b/src/config.c index ea97fa81..a8cf19ff 100644 --- a/src/config.c +++ b/src/config.c @@ -27,7 +27,6 @@ #include "vdp_ext.h" #include "weapon.h" #include "window.h" -#include "z80_ctrl.h" #include "gamemode.h" diff --git a/src/game.c b/src/game.c index 4b77c5df..17e8da70 100644 --- a/src/game.c +++ b/src/game.c @@ -110,7 +110,6 @@ void game_main(uint8_t load) { hud_show(); sprites_send(); VDP_setWindowPos(0, 0); - XGM_set68KBUSProtection(FALSE); VDP_setEnable(TRUE); } else { // HUD on top @@ -364,7 +363,6 @@ void draw_itemmenu(uint8_t resetCursor) { spr_num = 0; sprite_add(((VDPSprite) { .x = 128, .y = 128, .size = SPRITE_SIZE(1, 1) })); } - XGM_set68KBUSProtection(FALSE); VDP_setEnable(TRUE); } @@ -552,7 +550,7 @@ void do_map() { TILE_ATTR_FULL(PAL0,1,0,0,TILE_SHEETINDEX+(result-1)), mapx+x, mapy+y); } if(vblank) { - XGM_doVBlankProcess(); + xgm_vblank(); vblank = 0; } } diff --git a/src/main.c b/src/main.c index 48430f15..ba447568 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,6 @@ #include "vdp_pal.h" #include "vdp_tile.h" #include "xgm.h" -#include "z80_ctrl.h" extern const uint16_t time_tab_ntsc[0x100]; extern const uint16_t speed_tab_ntsc[0x100]; @@ -30,14 +29,9 @@ void vsync() { } void aftervsync() { - XGM_doVBlankProcess(); - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); - + xgm_vblank(); DMA_flushQueue(); - if(fading_cnt > 0) VDP_doStepFading(FALSE); - dqueued = FALSE; if(ready) { if(inFade) { spr_num = 0; } @@ -45,9 +39,6 @@ void aftervsync() { ready = FALSE; } if(gamemode == GM_GAME) stage_update(); // Scrolling - - XGM_set68KBUSProtection(FALSE); - JOY_update(); } @@ -60,10 +51,8 @@ int main() { MEM_init(); VDP_init(); DMA_init(0, 0); - //PSG_init(); JOY_init(); - // reseting z80 also reset the ym2612 - Z80_init(); + xgm_init(); // Initialize time and speed tables (framerate adjusted) SCREEN_HEIGHT = pal_mode ? 240 : 224; SCREEN_HALF_H = SCREEN_HEIGHT >> 1; diff --git a/src/sheet.c b/src/sheet.c index bbcb54d7..c1bf84c0 100644 --- a/src/sheet.c +++ b/src/sheet.c @@ -323,7 +323,7 @@ void sheets_load_stage(uint16_t sid, uint8_t init_base, uint8_t init_tiloc) { SHEET_ADD(SHEET_MGUN, &SPR_MGunB3, 5,2,2, 0,0, 0,1, 0,2, 0,3, 0,4); } else { SHEET_ADD(SHEET_CGUN, &SPR_Polar, 1,3,1, 0,0); - SHEET_ADD(SHEET_PSTAR, &SPR_PolarB3, 2,2,2, 0,0, 1,0); + SHEET_ADD(SHEET_PSTAR, &SPR_PolarB3, 2,2,2, 0,0, 0,1); } } break; case 0x2E: // Dark Place @@ -340,7 +340,7 @@ void sheets_load_stage(uint16_t sid, uint8_t init_base, uint8_t init_tiloc) { SHEET_ADD(SHEET_MGUN, &SPR_MGunB3, 5,2,2, 0,0, 0,1, 0,2, 0,3, 0,4); } else { SHEET_ADD(SHEET_CGUN, &SPR_Polar, 1,3,1, 0,0); - SHEET_ADD(SHEET_PSTAR, &SPR_PolarB3, 2,2,2, 0,0, 1,0); + SHEET_ADD(SHEET_PSTAR, &SPR_PolarB3, 2,2,2, 0,0, 0,1); } } break; case 0x30: // Waterway diff --git a/src/stage.c b/src/stage.c index debb9f27..82a227f2 100644 --- a/src/stage.c +++ b/src/stage.c @@ -174,7 +174,6 @@ void stage_load(uint16_t id) { if((playerEquipment & EQUIP_CLOCK) || stageID == STAGE_HELL_B1) system_draw_counter(); tsc_load_stage(id); MUSIC_TICK(); - XGM_set68KBUSProtection(FALSE); VDP_setEnable(TRUE); } @@ -215,7 +214,6 @@ void stage_load_credits(uint8_t id) { MUSIC_TICK(); tsc_load_stage(id); MUSIC_TICK(); - XGM_set68KBUSProtection(FALSE); VDP_setEnable(TRUE); } diff --git a/src/system.c b/src/system.c index 0c74a911..b296525a 100644 --- a/src/system.c +++ b/src/system.c @@ -7,7 +7,6 @@ #include "joy.h" #include "memory.h" #include "player.h" -#include "psg.h" #include "resources.h" #include "sprite.h" #include "sram.h" @@ -22,7 +21,6 @@ #include "weapon.h" #include "window.h" #include "xgm.h" -#include "z80_ctrl.h" #include "system.h" @@ -263,14 +261,12 @@ void system_save() { if(sram_file >= SRAM_FILE_MAX) return; if(sram_state == SRAM_INVALID) return; - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); - // Start of save data in SRAM uint16_t loc_start = SRAM_FILE_START + SRAM_FILE_LEN * sram_file; // Counters to increment while reading/writing uint16_t loc = loc_start; + z80_request(); SRAM_enable(); SRAM_writeLong(loc, STR_CSMD); loc += 4; @@ -319,15 +315,13 @@ void system_save() { checksum_write(sram_file, TRUE); SRAM_disable(); - - XGM_set68KBUSProtection(FALSE); + z80_release(); } void system_peekdata(uint8_t index, SaveEntry *file) { uint16_t loc = SRAM_FILE_START + SRAM_FILE_LEN * index; - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); + z80_request(); SRAM_enableRO(); // Save exists @@ -335,7 +329,7 @@ void system_peekdata(uint8_t index, SaveEntry *file) { if(magic != STR_CSMD) { file->used = FALSE; SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); return; } // Checksum failed? @@ -344,7 +338,7 @@ void system_peekdata(uint8_t index, SaveEntry *file) { if(!checksum_verify(index, TRUE)) { file->used = FALSE; SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); return; } // Load backup @@ -365,7 +359,7 @@ void system_peekdata(uint8_t index, SaveEntry *file) { file->weapon[4] = SRAM_readByte(loc); loc += 8; SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); } void system_load(uint8_t index) { @@ -376,8 +370,8 @@ void system_load(uint8_t index) { player_init(); sram_file = index; - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); + z80_request(); + SRAM_enableRO(); // Start of save data in SRAM uint16_t loc_start = SRAM_FILE_START + SRAM_FILE_LEN * sram_file; @@ -389,13 +383,12 @@ void system_load(uint8_t index) { // Counters to increment while reading/writing uint16_t loc = loc_start; - SRAM_enableRO(); // Test magic uint32_t magic = SRAM_readLong(loc); loc += 4; if(magic != STR_CSMD) { // Empty SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); system_new(); return; } @@ -434,8 +427,7 @@ void system_load(uint8_t index) { flags[i] = SRAM_readLong(loc); loc += 4; } SRAM_disable(); - - XGM_set68KBUSProtection(FALSE); + z80_release(); stage_load(rid); song_play(song); @@ -446,8 +438,7 @@ void system_copy(uint8_t from, uint8_t to) { uint16_t loc_from_end = loc_from + SRAM_FILE_LEN; uint16_t loc_to = SRAM_FILE_START + SRAM_FILE_LEN * to; - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); + z80_request(); SRAM_enable(); // Copy data @@ -465,36 +456,33 @@ void system_copy(uint8_t from, uint8_t to) { SRAM_writeLong(loc_to + 4, checksum); SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); } void system_delete(uint8_t index) { uint16_t loc = SRAM_FILE_START + SRAM_FILE_LEN * index; - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); + z80_request(); SRAM_enable(); SRAM_writeLong(loc, 0); // Erase the "CSMD" magic to invalidate file SRAM_writeLong(loc + SRAM_BACKUP_OFFSET, 0); // the backup too SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); } void system_load_config() { - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); - uint16_t loc = SRAM_CONFIG_POS; - + + z80_request(); SRAM_enableRO(); uint32_t magic = SRAM_readLong(loc); loc += 4; if(magic != CFG_MAGIC) { // No settings saved, keep defaults SRAM_disable(); - XGM_set68KBUSProtection(FALSE); + z80_release(); return; } @@ -516,19 +504,16 @@ void system_load_config() { if(cfg_force_btn > 2) cfg_force_btn = 0; SRAM_disable(); - - XGM_set68KBUSProtection(FALSE); + z80_release(); } void system_save_config() { - XGM_set68KBUSProtection(TRUE); - waitSubTick(10); - uint16_t loc = SRAM_CONFIG_POS; - + + z80_request(); SRAM_enable(); + SRAM_writeLong(loc, CFG_MAGIC); loc += 4; - SRAM_writeByte(loc++, cfg_btn_jump); SRAM_writeByte(loc++, cfg_btn_shoot); SRAM_writeByte(loc++, cfg_btn_ffwd); @@ -543,9 +528,9 @@ void system_save_config() { SRAM_writeByte(loc++, cfg_iframebug); SRAM_writeByte(loc++, cfg_force_btn); SRAM_writeByte(loc++, cfg_msg_blip); + SRAM_disable(); - - XGM_set68KBUSProtection(FALSE); + z80_release(); } // Level select is still the old style format... don't care enough to fix it diff --git a/src/tsc.c b/src/tsc.c index 21de45d2..c28f30f3 100644 --- a/src/tsc.c +++ b/src/tsc.c @@ -1231,7 +1231,7 @@ uint8_t execute_command() { VDP_setEnable(TRUE); song_stop(); - XGM_doVBlankProcess(); + xgm_vblank(); uint16_t t = TIME_10(350); while(--t) { diff --git a/src/vdp_pal.c b/src/vdp_pal.c index 5112cd61..5b87c25d 100644 --- a/src/vdp_pal.c +++ b/src/vdp_pal.c @@ -224,7 +224,7 @@ void VDP_fade(uint16_t fromcol, uint16_t tocol, const uint16_t *palsrc, const ui // process fading immediatly while (VDP_doStepFading(TRUE)) { vsync(); - XGM_doVBlankProcess(); + xgm_vblank(); } } } diff --git a/src/xgm.c b/src/xgm.c new file mode 100644 index 00000000..82128510 --- /dev/null +++ b/src/xgm.c @@ -0,0 +1,394 @@ +#include "common.h" +#include "vdp.h" +#include "xgm.h" +#include "xgm/z80_xgm.h" /* z80 program blob */ +#include "resources.h" + +const uint8_t smp_null[0x100] __attribute__((aligned(256))) = {}; + +// Variables +static uint16_t xgmTempo; +static uint16_t xgmTempoDef; +static int16_t xgmTempoCnt; + +// Constants +#define Z80_HALT_PORT 0xA11100 +#define Z80_RESET_PORT 0xA11200 +#define Z80_RAM_START 0xA00000 +#define Z80_RAM_END 0xA01FFF +#define Z80_RAM Z80_RAM_START +#define Z80_RAM_LEN ((Z80_RAM_END - Z80_RAM_START) + 1) +#define Z80_BANK_REGISTER 0xA06000 +#define Z80_DRV_COMMAND 0xA00100 +#define Z80_DRV_STATUS 0xA00102 +#define Z80_DRV_PARAMS 0xA00104 +// default command and status value +#define Z80_DRV_COM_PLAY 1 +#define Z80_DRV_COM_STOP 16 +#define Z80_DRV_STAT_PLAYING 1 +#define Z80_DRV_STAT_READY 128 +// channel definition +#define Z80_DRV_CH0 1 +#define Z80_DRV_CH1 2 +#define Z80_DRV_CH2 4 +#define Z80_DRV_CH3 8 + +static uint16_t z80_bus_taken() { + volatile uint16_t *pw = (uint16_t*) Z80_HALT_PORT; + if(*pw & 0x0100) return 0; + else return 1; +} + +void z80_request() { + volatile uint16_t *pw_bus = (uint16_t*) Z80_HALT_PORT; + volatile uint16_t *pw_reset = (uint16_t*) Z80_RESET_PORT; + // take bus and end reset + *pw_bus = 0x0100; + *pw_reset = 0x0100; + while(*pw_bus & 0x0100); +} + +void z80_release() { + volatile uint16_t *pw = (uint16_t*) Z80_HALT_PORT; + *pw = 0x0000; +} + +static void z80_reset_start() { + volatile uint16_t *pw = (uint16_t*) Z80_RESET_PORT; + *pw = 0x0000; +} + +static void z80_reset_end() { + volatile uint16_t *pw = (uint16_t*) Z80_RESET_PORT; + *pw = 0x0100; +} + +static void z80_set_bank(const uint16_t bank) { + volatile uint8_t *pb = (uint8_t*) Z80_BANK_REGISTER; + uint16_t i = 9; + uint16_t value = bank; + while(i--) { + *pb = value; + value >>= 1; + } +} + +static void z80_clear(const uint16_t to, const uint16_t size, const uint16_t resetz80) { + z80_request(TRUE); + const uint8_t zero = 0; + uint8_t* dst = (uint8_t*) (Z80_RAM + to); + uint16_t len = size; + while(len--) *dst++ = zero; + if(resetz80) z80_reset_start(); + z80_release(); + // wait bus released + while(z80_bus_taken()); + if(resetz80) z80_reset_end(); +} + +static void z80_upload(const uint16_t to, const uint8_t *from, const uint16_t size, const uint16_t resetz80) { + z80_request(TRUE); + // copy data to Z80 RAM (need to use byte copy here) + uint8_t* src = (uint8_t*) from; + uint8_t* dst = (uint8_t*) (Z80_RAM + to); + uint16_t len = size; + while(len--) *dst++ = *src++; + if(resetz80) z80_reset_start(); + z80_release(); + // wait bus released + while(z80_bus_taken()); + if(resetz80) z80_reset_end(); +} + +static void ym2612_write(const uint16_t port, const uint8_t data) { + volatile int8_t *pb = (int8_t*) 0xA04000; + // wait while YM2612 busy + while(*pb < 0); + // write data + pb[port & 3] = data; +} + +static void ym2612_reset() { + uint16_t bus_taken = z80_bus_taken(); + if(!bus_taken) z80_request(TRUE); + // enable left and right output for all channel + for(uint16_t i = 0; i < 3; i++) { + ym2612_write(0, 0xB4 | i); + ym2612_write(1, 0xC0); + ym2612_write(2, 0xB4 | i); + ym2612_write(3, 0xC0); + } + // disable LFO + ym2612_write(0, 0x22); + ym2612_write(1, 0x00); + // disable timer & set channel 6 to normal mode + ym2612_write(0, 0x27); + ym2612_write(1, 0x00); + // ALL KEY OFF + ym2612_write(0, 0x28); + for(uint16_t i = 0; i < 3; i++) { + ym2612_write(1, 0x00 | i); + ym2612_write(1, 0x04 | i); + } + // disable DAC + ym2612_write(0, 0x2B); + ym2612_write(1, 0x00); + if(!bus_taken) z80_release(); +} + +static void psg_init() { + volatile uint8_t *pb = (uint8_t*) 0xC00011; + for (uint16_t i = 0; i < 4; i++) { + // set tone to 0 + *pb = 0x80 | (i << 5) | 0x00; + *pb = 0x00; + // set envelope to silent + *pb = 0x90 | (i << 5) | 0x0F; + } +} + +static uint16_t xgm_get_ready() { + uint8_t ret; + volatile uint8_t *pb = (uint8_t*) Z80_DRV_STATUS; + // bus already taken ? just check status + if (z80_bus_taken()) { + ret = *pb & Z80_DRV_STAT_READY; + } else { + // take the bus, check status and release bus + z80_request(TRUE); + ret = *pb & Z80_DRV_STAT_READY; + z80_release(); + } + return ret; +} + +void xgm_init() { + z80_request(TRUE); + z80_set_bank(0); + z80_clear(0, Z80_RAM_LEN, FALSE); + // upload Z80 driver and reset Z80 + z80_upload(0, z80_xgm, sizeof(z80_xgm), 1); + // reset sound chips + ym2612_reset(); + psg_init(); + // misc parameters initialisation + z80_request(TRUE); + // point to Z80 sample id table (first entry = silent sample) + volatile uint8_t *pb = (uint8_t*) (0xA01C00); + uint32_t addr = (uint32_t) smp_null; + // null sample address (256 bytes aligned) + pb[0] = addr >> 8; + pb[1] = addr >> 16; + // null sample length (256 bytes aligned) + pb[2] = sizeof(smp_null) >> 8; + pb[3] = sizeof(smp_null) >> 16; + z80_release(); + // wait bus released + while(z80_bus_taken()); + // just wait for it + while(!xgm_get_ready()) while(z80_bus_taken()); + // Tempo + xgmTempo = 60; + xgmTempoDef = pal_mode ? 50 : 60; +} + + +void xgm_music_play(const uint8_t *song) { + uint8_t ids[0x100-4]; + uint32_t addr; + // prepare sample id table + for(uint16_t i = 0; i < 0x3F; i++) { + // sample address in sample bank data + addr = song[(i * 4) + 0] << 8; + addr |= song[(i * 4) + 1] << 16; + // silent sample ? use null sample address + if (addr == 0xFFFF00) addr = (uint32_t) smp_null; + // adjust sample address (make it absolute) + else addr += ((uint32_t) song) + 0x100; + // write adjusted addr + ids[(i * 4) + 0] = addr >> 8; + ids[(i * 4) + 1] = addr >> 16; + // and recopy len + ids[(i * 4) + 2] = song[(i * 4) + 2]; + ids[(i * 4) + 3] = song[(i * 4) + 3]; + } + // upload sample id table (first entry is silent sample, we don't transfer it) + z80_upload(0x1C00 + 4, ids, 0x100 - 4, FALSE); + // get song address and bypass sample id table + addr = ((uint32_t) song) + 0x100; + // bypass sample data (use the sample data size) + addr += song[0xFC] << 8; + addr += song[0xFD] << 16; + // and bypass the music data size field + addr += 4; + // request Z80 BUS + z80_request(TRUE); + // point to Z80 XGM address parameter + volatile uint8_t *pb = (uint8_t*) (Z80_DRV_PARAMS + 0x00); + // set XGM music data address + pb[0x00] = addr >> 0; + pb[0x01] = addr >> 8; + pb[0x02] = addr >> 16; + pb[0x03] = addr >> 24; + // point to Z80 command + pb = (uint8_t*) Z80_DRV_COMMAND; + // set play XGM command + *pb |= (1 << 6); + // point to PENDING_FRM parameter + pb = (uint8_t*) (Z80_DRV_PARAMS + 0x0F); + // clear pending frame + *pb = 0; + z80_release(); +} + +void xgm_music_stop() { + z80_request(TRUE); + // special xgm sequence to stop any sound + uint32_t addr = ((uint32_t) stop_xgm); + // point to Z80 XGM address parameter + volatile uint8_t *pb = (uint8_t*) (Z80_DRV_PARAMS + 0x00); + // set XGM music data address + pb[0x00] = addr >> 0; + pb[0x01] = addr >> 8; + pb[0x02] = addr >> 16; + pb[0x03] = addr >> 24; + // point to Z80 command + pb = (uint8_t*) Z80_DRV_COMMAND; + // set play XGM command + *pb |= (1 << 6); + // point to PENDING_FRM parameter + pb = (uint8_t*) (Z80_DRV_PARAMS + 0x0F); + // clear pending frame + *pb = 0; + z80_release(); +} + +void xgm_music_pause() { + z80_request(TRUE); + volatile uint8_t *pb = (uint8_t*) Z80_DRV_COMMAND; + // set pause XGM command + *pb |= (1 << 4); + z80_release(); +} + +void xgm_music_resume() { + z80_request(TRUE); + volatile uint8_t *pb = (uint8_t*) Z80_DRV_COMMAND; + // set resume XGM command + *pb |= (1 << 5); + // point to PENDING_FRM parameter + pb = (uint8_t*) (Z80_DRV_PARAMS + 0x0F); + // clear pending frame + *pb = 0; + z80_release(); +} + +void xgm_pcm_set(const uint8_t id, const uint8_t *sample, const uint32_t len) { + z80_request(TRUE); + // point to sample id table + volatile uint8_t *pb = (uint8_t*) (0xA01C00 + (id * 4)); + // write sample addr + pb[0x00] = ((uint32_t) sample) >> 8; + pb[0x01] = ((uint32_t) sample) >> 16; + pb[0x02] = len >> 8; + pb[0x03] = len >> 16; + z80_release(); +} + +void xgm_pcm_play(const uint8_t id, const uint8_t priority, const uint16_t channel) { + z80_request(TRUE); + // point to Z80 PCM parameters + volatile uint8_t *pb = (uint8_t*) (Z80_DRV_PARAMS + 0x04 + (channel * 2)); + // set PCM priority and id + pb[0x00] = priority & 0xF; + pb[0x01] = id; + // point to Z80 command + pb = (uint8_t*) Z80_DRV_COMMAND; + // set play PCM channel command + *pb |= (Z80_DRV_COM_PLAY << channel); + z80_release(); +} + +void xgm_protect(uint8_t enable) { + // point on bus req and reset ports + volatile uint16_t *pw_bus = (uint16_t*) Z80_HALT_PORT; + volatile uint16_t *pw_reset = (uint16_t*) Z80_RESET_PORT; + // take bus and end reset (fast method) + *pw_bus = 0x0100; + *pw_reset = 0x0100; + // wait for bus taken + while (*pw_bus & 0x0100); + // point to Z80 PROTECT parameter + volatile uint8_t *pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0D); + *pb = enable; + // release bus + *pw_bus = 0x0000; +} + +uint32_t xgm_get_elapsed() { + volatile uint8_t *pb; + uint8_t *dst; + uint8_t values[3]; + uint32_t result; + + // point to ELAPSED value + pb = (uint8_t *) (Z80_DRV_PARAMS + 0x90); + dst = values; + + z80_request(TRUE); + + // copy quickly elapsed time + *dst++ = *pb++; + *dst++ = *pb++; + *dst = *pb; + + z80_release(); + + result = (values[0] << 0) | (values[1] << 8) | (values[2] << 16); + + // fix possible 24 bit negative value (parsing first extra frame) + if (result >= 0xFFFFF0) return 0; + + return result; +} + +// VInt processing for XGM driver +void xgm_vblank() { + int16_t cnt = xgmTempoCnt; + uint16_t step = xgmTempoDef; + uint16_t num = 0; + while(cnt <= 0) { + num++; + cnt += step; + } + xgmTempoCnt = cnt - xgmTempo; + // directly do the frame here as we want this code to be as fast as possible + // (to not waste vint time) driver should be loaded here + // point on bus req and reset ports + volatile uint16_t *pw_bus = (uint16_t *) Z80_HALT_PORT; + volatile uint16_t *pw_reset = (uint16_t *) Z80_RESET_PORT; + // point to MODIFYING_F parameter + volatile uint8_t *pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0E); + while(TRUE) { + // take bus and end reset (fast method) + *pw_bus = 0x0100; + *pw_reset = 0x0100; + // wait for bus taken + while (*pw_bus & 0x100); + // Z80 not accessing ? + if (!*pb) break; + // release bus + *pw_bus = 0x0000; + // wait a bit (about 80 cycles) + __asm__("\t\tmovm.l %d0-%d3,-(%sp)\n"); + __asm__("\t\tmovm.l (%sp)+,%d0-%d3\n"); + // wait for bus released before requesting it again + while (!(*pw_bus & 0x0100)); + } + // point to PENDING_FRM parameter + pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0F); + // increment frame to process + *pb += num; + // release bus + *pw_bus = 0x0000; +} diff --git a/src/xgm/psg.c b/src/xgm/psg.c deleted file mode 100644 index dd0bdd01..00000000 --- a/src/xgm/psg.c +++ /dev/null @@ -1,73 +0,0 @@ -#include "common.h" - -#include "vdp.h" - -#include "psg.h" - -void PSG_init() -{ - volatile uint8_t *pb; - uint16_t i; - - pb = (uint8_t*) PSG_PORT; - - for (i = 0; i < 4; i++) - { - // set tone to 0 - *pb = 0x80 | (i << 5) | 0x00; - *pb = 0x00; - - // set envelope to silent - *pb = 0x90 | (i << 5) | 0x0F; - } -} - - -void PSG_write(uint8_t data) -{ - volatile uint8_t *pb; - - pb = (uint8_t*) PSG_PORT; - *pb = data; -} - - -void PSG_setEnvelope(uint8_t channel, uint8_t value) -{ - volatile uint8_t *pb; - - pb = (uint8_t*) PSG_PORT; - *pb = 0x90 | ((channel & 3) << 5) | (value & 0xF); -} - -void PSG_setTone(uint8_t channel, uint16_t value) -{ - volatile uint8_t *pb; - - pb = (uint8_t*) PSG_PORT; - *pb = 0x80 | ((channel & 3) << 5) | (value & 0xF); - *pb = (value >> 4) & 0x3F; -} - -void PSG_setFrequency(uint8_t channel, uint16_t value) -{ - uint16_t data; - - if (value) - { - // frequency to tone conversion - if (pal_mode) data = 3546893 / (value * 32); - else data = 3579545 / (value * 32); - } - else data = 0; - - PSG_setTone(channel, data); -} - -void PSG_setNoise(uint8_t type, uint8_t frequency) -{ - volatile uint8_t *pb; - - pb = (uint8_t *) PSG_PORT; - *pb = 0xE0 | ((type & 1) << 2) | (frequency & 0x3); -} diff --git a/src/xgm/smp_null.s b/src/xgm/smp_null.s deleted file mode 100644 index fa553840..00000000 --- a/src/xgm/smp_null.s +++ /dev/null @@ -1,22 +0,0 @@ -.text - - align 256 - - .globl smp_null -smp_null: - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - dc.b 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 diff --git a/src/xgm/tab_vol.c b/src/xgm/tab_vol.c deleted file mode 100644 index 3a943dea..00000000 --- a/src/xgm/tab_vol.c +++ /dev/null @@ -1,276 +0,0 @@ -#include - -const uint8_t tab_vol[0x1000] = -{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, - 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, - 0xF8, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, 0xF9, - 0xF9, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, 0xFA, - 0xFA, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, 0xFB, - 0xFB, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, - 0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, - 0xFD, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, - 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, - 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, - 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, - 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, - 0xF0, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF1, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, - 0xF2, 0xF3, 0xF3, 0xF3, 0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, 0xDF, 0xE0, 0xE1, 0xE2, - 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, - 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x00, - - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, - 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF -}; diff --git a/src/xgm/xgm.c b/src/xgm/xgm.c deleted file mode 100644 index 49451b00..00000000 --- a/src/xgm/xgm.c +++ /dev/null @@ -1,400 +0,0 @@ -#include "common.h" - -#include "resources.h" -#include "smp_null.h" -#include "system.h" -#include "vdp.h" -#include "z80_ctrl.h" - -#include "xgm.h" - -// specific for the XGM driver -static uint16_t xgmTempo; -static uint16_t xgmTempoDef; -static int16_t xgmTempoCnt = 0; - -// Z80_DRIVER_XGM -// XGM driver -/////////////////////////////////////////////////////////////// - -uint8_t XGM_isPlaying() -{ - volatile uint8_t *pb; - uint8_t ret; - - // point to Z80 status - pb = (uint8_t *) Z80_DRV_STATUS; - - Z80_requestBus(TRUE); - // play status - ret = *pb & (1 << 6); - Z80_releaseBus(); - - return ret; -} - -void XGM_startPlay(const uint8_t *song) -{ - uint8_t ids[0x100-4]; - uint32_t addr; - uint16_t i; - volatile uint8_t *pb; - - // prepare sample id table - for(i = 0; i < 0x3F; i++) - { - // sample address in sample bank data - addr = song[(i * 4) + 0] << 8; - addr |= (uint32_t)(song[(i * 4) + 1]) << 16; - - // silent sample ? use null sample address - if (addr == 0xFFFF00) addr = (uint32_t) smp_null; - // adjust sample address (make it absolute) - else addr += ((uint32_t) song) + 0x100; - - // write adjusted addr - ids[(i * 4) + 0] = addr >> 8; - ids[(i * 4) + 1] = addr >> 16; - // and recopy len - ids[(i * 4) + 2] = song[(i * 4) + 2]; - ids[(i * 4) + 3] = song[(i * 4) + 3]; - } - - // upload sample id table (first entry is silent sample, we don't transfer it) - Z80_upload(0x1C00 + 4, ids, 0x100 - 4, FALSE); - - // get song address and bypass sample id table - addr = ((uint32_t) song) + 0x100; - // bypass sample data (use the sample data size) - addr += song[0xFC] << 8; - addr += ((uint32_t)song[0xFD]) << 16; - // and bypass the music data size field - addr += 4; - - // request Z80 BUS - Z80_requestBus(TRUE); - - // point to Z80 XGM address parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x00); - // set XGM music data address - pb[0x00] = addr >> 0; - pb[0x01] = addr >> 8; - pb[0x02] = addr >> 16; - pb[0x03] = addr >> 24; - - // point to Z80 command - pb = (uint8_t *) Z80_DRV_COMMAND; - // set play XGM command - *pb |= (1 << 6); - - // point to PENDING_FRM parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0F); - // clear pending frame - *pb = 0; - - Z80_releaseBus(); -} - -void XGM_stopPlay() -{ - volatile uint8_t *pb; - uint32_t addr; - - Z80_requestBus(TRUE); - - // special xgm sequence to stop any sound - addr = ((uint32_t) stop_xgm); - - // point to Z80 XGM address parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x00); - - // set XGM music data address - pb[0x00] = addr >> 0; - pb[0x01] = addr >> 8; - pb[0x02] = addr >> 16; - pb[0x03] = addr >> 24; - - // point to Z80 command - pb = (uint8_t *) Z80_DRV_COMMAND; - // set play XGM command - *pb |= (1 << 6); - - // point to PENDING_FRM parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0F); - // clear pending frame - *pb = 0; - - Z80_releaseBus(); -} - -void XGM_pausePlay() -{ - volatile uint8_t *pb; - - Z80_requestBus(TRUE); - - // point to Z80 command - pb = (uint8_t *) Z80_DRV_COMMAND; - // set pause XGM command - *pb |= (1 << 4); - - Z80_releaseBus(); -} - -void XGM_resumePlay() -{ - volatile uint8_t *pb; - - Z80_requestBus(TRUE); - - // point to Z80 command - pb = (uint8_t *) Z80_DRV_COMMAND; - // set resume XGM command - *pb |= (1 << 5); - - // point to PENDING_FRM parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0F); - // clear pending frame - *pb = 0; - - Z80_releaseBus(); -} - -uint8_t XGM_isPlayingPCM(const uint16_t channel_mask) -{ - volatile uint8_t *pb; - uint8_t ret; - - Z80_requestBus(TRUE); - - // point to Z80 status - pb = (uint8_t *) Z80_DRV_STATUS; - // play status - ret = *pb & (channel_mask << Z80_DRV_STAT_PLAYING_SFT); - - Z80_releaseBus(); - - return ret; -} - -void XGM_setPCM(const uint8_t id, const uint8_t *sample, const uint32_t len) -{ - Z80_requestBus(TRUE); - XGM_setPCMFast(id, sample, len); - Z80_releaseBus(); -} - -void XGM_setPCMFast(const uint8_t id, const uint8_t *sample, const uint32_t len) -{ - volatile uint8_t *pb; - // point to sample id table - pb = (uint8_t *) (0xA01C00 + (id * 4)); - // write sample addr - pb[0x00] = ((uint32_t) sample) >> 8; - pb[0x01] = ((uint32_t) sample) >> 16; - pb[0x02] = len >> 8; - pb[0x03] = len >> 16; -} - -void XGM_startPlayPCM(const uint8_t id, const uint8_t priority, const uint16_t channel) -{ - volatile uint8_t *pb; - - Z80_requestBus(TRUE); - - // point to Z80 PCM parameters - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x04 + (channel * 2)); - - // set PCM priority and id - pb[0x00] = priority & 0xF; - pb[0x01] = id; - - // point to Z80 command - pb = (uint8_t *) Z80_DRV_COMMAND; - // set play PCM channel command - *pb |= (Z80_DRV_COM_PLAY << channel); - - Z80_releaseBus(); -} - -void XGM_stopPlayPCM(const uint16_t channel) -{ - volatile uint8_t *pb; - - Z80_requestBus(TRUE); - - // point to Z80 PCM parameters - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x04 + (channel * 2)); - - // use silent PCM (id = 0) with maximum priority - pb[0x00] = 0xF; - pb[0x01] = 0; - - // point to Z80 command - pb = (uint8_t *) Z80_DRV_COMMAND; - // set play PCM channel command - *pb |= (Z80_DRV_COM_PLAY << channel); - - Z80_releaseBus(); -} - -void XGM_set68KBUSProtection(uint8_t value) -{ - volatile uint16_t *pw_bus; - volatile uint16_t *pw_reset; - volatile uint8_t *pb; - - // point on bus req and reset ports - pw_bus = (uint16_t *) Z80_HALT_PORT; - pw_reset = (uint16_t *) Z80_RESET_PORT; - - // take bus and end reset (fast method) - *pw_bus = 0x0100; - *pw_reset = 0x0100; - // wait for bus taken - while (*pw_bus & 0x0100); - - // point to Z80 PROTECT parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0D); - - *pb = value; - - // release bus - *pw_bus = 0x0000; -} - -void XGM_nextXFrame(uint16_t num) -{ - volatile uint16_t *pw_bus; - volatile uint16_t *pw_reset; - volatile uint8_t *pb; - - // point on bus req and reset ports - pw_bus = (uint16_t *) Z80_HALT_PORT; - pw_reset = (uint16_t *) Z80_RESET_PORT; - // point to MODIFYING_F parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0E); - - while(TRUE) - { - // take bus and end reset (fast method) - *pw_bus = 0x0100; - *pw_reset = 0x0100; - // wait for bus taken - while (*pw_bus & 0x0100); - - // Z80 not accessing ? - if (!*pb) break; - - // release bus - *pw_bus = 0x0000; - - // wait a bit (about 80 cycles) - __asm__ volatile ("\t\tmovm.l %d0-%d3,-(%sp)\n"); - __asm__ volatile ("\t\tmovm.l (%sp)+,%d0-%d3\n"); - - // wait for bus released before requesting it again - while (!(*pw_bus & 0x0100)); - } - - // point to PENDING_FRM parameter - pb++; - // increment frame to process - *pb += num; - - // release bus - *pw_bus = 0x0000; -} - -void XGM_setMusicTempo(uint16_t value) -{ - xgmTempo = value; - if (pal_mode) xgmTempoDef = 50; - else xgmTempoDef = 60; -} - -uint32_t XGM_getElapsed() -{ - volatile uint8_t *pb; - uint8_t *dst; - uint8_t values[3]; - uint32_t result; - - // point to ELAPSED value - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x90); - dst = values; - - Z80_requestBus(TRUE); - - // copy quickly elapsed time - *dst++ = *pb++; - *dst++ = *pb++; - *dst = *pb; - - Z80_releaseBus(); - - result = (values[0] << 0) | (values[1] << 8) | ((uint32_t)(values[2]) << 16); - - // fix possible 24 bit negative value (parsing first extra frame) - if (result >= 0xFFFFF0) return 0; - - return result; -} - -// VInt processing for XGM driver -void XGM_doVBlankProcess() -{ - volatile uint16_t *pw_bus; - volatile uint16_t *pw_reset; - volatile uint8_t *pb; - int16_t cnt = xgmTempoCnt; - uint16_t step = xgmTempoDef; - uint16_t num = 0; - - while(cnt <= 0) - { - num++; - cnt += step; - } - - xgmTempoCnt = cnt - xgmTempo; - - // directly do the frame here as we want this code to be as fast as possible (to not waste vint time) - // driver should be loaded here - - // point on bus req and reset ports - pw_bus = (uint16_t *) Z80_HALT_PORT; - pw_reset = (uint16_t *) Z80_RESET_PORT; - // point to MODIFYING_F parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0E); - - while(TRUE) - { - // take bus and end reset (fast method) - *pw_bus = 0x0100; - *pw_reset = 0x0100; - // wait for bus taken - while (*pw_bus & 0x100); - - // Z80 not accessing ? - if (!*pb) break; - - // release bus - *pw_bus = 0x0000; - - // wait a bit (about 80 cycles) - __asm__ volatile ("\t\tmovm.l %d0-%d3,-(%sp)\n"); - __asm__ volatile ("\t\tmovm.l (%sp)+,%d0-%d3\n"); - - // wait for bus released before requesting it again - while (!(*pw_bus & 0x0100)); - } - - // point to PENDING_FRM parameter - pb = (uint8_t *) (Z80_DRV_PARAMS + 0x0F); - // increment frame to process - *pb += num; - - // release bus - *pw_bus = 0x0000; -} diff --git a/src/xgm/ym2612.c b/src/xgm/ym2612.c deleted file mode 100644 index 0fc78371..00000000 --- a/src/xgm/ym2612.c +++ /dev/null @@ -1,101 +0,0 @@ -#include "common.h" - -#include "vdp.h" -#include "z80_ctrl.h" - -#include "ym2612.h" - -void YM2612_reset() { - uint16_t i; - uint16_t bus_taken; - - bus_taken = Z80_isBusTaken(); - if (!bus_taken) - Z80_requestBus(TRUE); - - // enable left and right output for all channel - for(i = 0; i < 3; i++) { - YM2612_write(0, 0xB4 | i); - YM2612_write(1, 0xC0); - YM2612_write(2, 0xB4 | i); - YM2612_write(3, 0xC0); - } - - // disable LFO - YM2612_write(0, 0x22); - YM2612_write(1, 0x00); - - // disable timer & set channel 6 to normal mode - YM2612_write(0, 0x27); - YM2612_write(1, 0x00); - - // ALL KEY OFF - YM2612_write(0, 0x28); - for (i = 0; i < 3; i++) { - YM2612_write(1, 0x00 | i); - YM2612_write(1, 0x04 | i); - } - - // disable DAC - YM2612_write(0, 0x2B); - YM2612_write(1, 0x00); - - if (!bus_taken) - Z80_releaseBus(); -} - -uint8_t YM2612_read(const uint16_t port) { - volatile uint8_t *pb; - - pb = (uint8_t*) YM2612_BASEPORT; - - return pb[port & 3]; -} - -void YM2612_write(const uint16_t port, const uint8_t data) { - volatile int8_t *pb; - - pb = (int8_t*) YM2612_BASEPORT; - - // wait while YM2612 busy - while (*pb < 0); - // write data - pb[port & 3] = data; -} - -void YM2612_writeReg(const uint16_t part, const uint8_t reg, const uint8_t data) { - volatile int8_t *pb; - uint16_t port; - - pb = (int8_t*) YM2612_BASEPORT; - port = (part << 1) & 2; - - // wait while YM2612 busy - while (*pb < 0); - // set reg - pb[port + 0] = reg; - - // busy flag is not updated immediatly, force wait (needed on MD2) - __asm__ volatile ("nop"); - __asm__ volatile ("nop"); - __asm__ volatile ("nop"); - __asm__ volatile ("nop"); - __asm__ volatile ("nop"); - - // wait while YM2612 busy - while (*pb < 0); - // set data - pb[port + 1] = data; -} - -void YM2612_enableDAC() { - // enable DAC - YM2612_write(0, 0x2B); - YM2612_write(1, 0x80); -} - -void YM2612_disableDAC() { - // disable DAC - YM2612_write(0, 0x2B); - YM2612_write(1, 0x00); -} diff --git a/src/xgm/z80_ctrl.c b/src/xgm/z80_ctrl.c deleted file mode 100644 index 97cbce25..00000000 --- a/src/xgm/z80_ctrl.c +++ /dev/null @@ -1,201 +0,0 @@ -#include "common.h" - -#include "memory.h" -#include "psg.h" -#include "smp_null.h" -#include "system.h" -#include "tab_vol.h" -#include "tools.h" -#include "vdp.h" -#include "xgm.h" -#include "ym2612.h" -#include "z80_xgm.h" - -#include "z80_ctrl.h" - -void Z80_init() { - uint8_t *pb; - uint32_t addr; - // request Z80 bus - Z80_requestBus(TRUE); - // set bank to 0 - Z80_setBank(0); - // clear z80 memory - Z80_clear(0, Z80_RAM_LEN, FALSE); - // upload Z80 driver and reset Z80 - Z80_upload(0, z80_xgm, sizeof(z80_xgm), 1); - // reset sound chips - YM2612_reset(); - PSG_init(); - // misc parameters initialisation - Z80_requestBus(TRUE); - // point to Z80 sample id table (first entry = silent sample) - pb = (uint8_t *) (0xA01C00); - - addr = (uint32_t) smp_null; - // null sample address (256 bytes aligned) - pb[0] = addr >> 8; - pb[1] = addr >> 16; - // null sample length (256 bytes aligned) - pb[2] = sizeof(smp_null) >> 8; - pb[3] = sizeof(smp_null) >> 16; - Z80_releaseBus(); - // wait bus released - while(Z80_isBusTaken()); - // just wait for it - while(!Z80_isDriverReady()) - while(Z80_isBusTaken()); - XGM_setMusicTempo(60); -} - -uint16_t Z80_isBusTaken() -{ - volatile uint16_t *pw; - - pw = (uint16_t *) Z80_HALT_PORT; - if (*pw & 0x0100) return 0; - else return 1; -} - -void Z80_requestBus(uint16_t wait) -{ - volatile uint16_t *pw_bus; - volatile uint16_t *pw_reset; - - // request bus (need to end reset) - pw_bus = (uint16_t *) Z80_HALT_PORT; - pw_reset = (uint16_t *) Z80_RESET_PORT; - - // take bus and end reset - *pw_bus = 0x0100; - *pw_reset = 0x0100; - - if (wait) - { - // wait for bus taken - while (*pw_bus & 0x0100); - } -} - -void Z80_releaseBus() -{ - volatile uint16_t *pw; - - pw = (uint16_t *) Z80_HALT_PORT; - *pw = 0x0000; -} - - -void Z80_startReset() -{ - volatile uint16_t *pw; - - pw = (uint16_t *) Z80_RESET_PORT; - *pw = 0x0000; -} - -void Z80_endReset() -{ - volatile uint16_t *pw; - - pw = (uint16_t *) Z80_RESET_PORT; - *pw = 0x0100; -} - - -void Z80_setBank(const uint16_t bank) -{ - volatile uint8_t *pb; - uint16_t i, value; - - pb = (uint8_t *) Z80_BANK_REGISTER; - - i = 9; - value = bank; - while (i--) - { - *pb = value; - value >>= 1; - } -} - -uint8_t Z80_read(const uint16_t addr) -{ - return ((uint8_t*) Z80_RAM)[addr]; -} - -void Z80_write(const uint16_t addr, const uint8_t value) -{ - ((uint8_t*) Z80_RAM)[addr] = value; -} - -void Z80_clear(const uint16_t to, const uint16_t size, const uint16_t resetz80) -{ - Z80_requestBus(TRUE); - - const uint8_t zero = 0; - uint8_t* dst = (uint8_t*) (Z80_RAM + to); - uint16_t len = size; - - while(len--) *dst++ = zero; - - if (resetz80) Z80_startReset(); - Z80_releaseBus(); - // wait bus released - while(Z80_isBusTaken()); - if (resetz80) Z80_endReset(); -} - -void Z80_upload(const uint16_t to, const uint8_t *from, const uint16_t size, const uint16_t resetz80) -{ - Z80_requestBus(TRUE); - - // copy data to Z80 RAM (need to use byte copy here) - uint8_t* src = (uint8_t*) from; - uint8_t* dst = (uint8_t*) (Z80_RAM + to); - uint16_t len = size; - - while(len--) *dst++ = *src++; - - if (resetz80) Z80_startReset(); - Z80_releaseBus(); - // wait bus released - while(Z80_isBusTaken()); - if (resetz80) Z80_endReset(); -} - -void Z80_download(const uint16_t from, uint8_t *to, const uint16_t size) -{ - Z80_requestBus(TRUE); - - // copy data from Z80 RAM (need to use byte copy here) - uint8_t* src = (uint8_t*) (Z80_RAM + from); - uint8_t* dst = (uint8_t*) to; - uint16_t len = size; - - while(len--) *dst++ = *src++; - - Z80_releaseBus(); -} - -uint16_t Z80_isDriverReady() -{ - uint8_t *pb; - uint8_t ret; - - // point to Z80 status - pb = (uint8_t *) Z80_DRV_STATUS; - - // bus already taken ? just check status - if (Z80_isBusTaken()) - ret = *pb & Z80_DRV_STAT_READY; - else - { - // take the bus, check status and release bus - Z80_requestBus(TRUE); - ret = *pb & Z80_DRV_STAT_READY; - Z80_releaseBus(); - } - - return ret; -}