src/mame/machine/megadriv.c
| r10382 | r10383 | |
| 272 | 272 | #include "imagedev/chd_cd.h" |
| 273 | 273 | #include "includes/megadriv.h" |
| 274 | 274 | |
| 275 | |
| 275 | 276 | #define MEGADRIV_VDP_VRAM(address) megadrive_vdp_vram[(address)&0x7fff] |
| 276 | 277 | |
| 277 | 278 | #define HAZE_MD 0 // to make appear / disappear the Region DipSwitch |
| r10382 | r10383 | |
| 388 | 389 | |
| 389 | 390 | /* Sega CD stuff */ |
| 390 | 391 | static int sega_cd_connected = 0x00; |
| 391 | | static UINT16 segacd_irq_mask; |
| 392 | | static UINT8 segacd_cdd_rx[10]; |
| 393 | | static UINT8 segacd_cdd_tx[10]; |
| 394 | | static struct |
| 395 | | { |
| 396 | | UINT8 buffer[5]; |
| 397 | | UINT8 ctrl; |
| 398 | | UINT8 scd_status; // SCSI status? |
| 399 | | }segacd_cdd; |
| 400 | | #ifdef MESS |
| 401 | | static struct |
| 402 | | { |
| 403 | | UINT32 current_frame; |
| 404 | | UINT32 end_frame; |
| 405 | | UINT32 last_frame; |
| 406 | | UINT8 first_track; |
| 407 | | UINT8 last_track; |
| 392 | UINT16 segacd_irq_mask; |
| 408 | 393 | |
| 409 | | cdrom_file *cd; |
| 410 | | const cdrom_toc* toc; |
| 411 | | }segacd; |
| 412 | | #endif |
| 413 | 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 414 | 399 | static void segacd_mark_tiles_dirty(running_machine* machine, int offset); |
| 415 | 400 | |
| 416 | 401 | static struct genesis_z80_vars |
| r10382 | r10383 | |
| 3807 | 3792 | Sega CD related |
| 3808 | 3793 | *************************************************************************************************/ |
| 3809 | 3794 | |
| 3810 | | static UINT16* segacd_4meg_prgram; // pointer to SubCPU PrgRAM |
| 3795 | static UINT8 segacd_ram_writeprotect_bits; |
| 3796 | int segacd_ram_mode; |
| 3797 | static int segacd_ram_mode_old; |
| 3798 | |
| 3799 | //static int segacd_maincpu_has_ram_access = 0; |
| 3800 | static int segacd_4meg_prgbank = 0; // which bank the MainCPU can see of the SubCPU PrgRAM |
| 3801 | static int segacd_memory_priority_mode = 0; |
| 3802 | static int segacd_stampsize; |
| 3803 | int segacd_dmna = 0; |
| 3804 | int segacd_ret = 0; |
| 3805 | |
| 3806 | #define READ_MAIN (0x0200) |
| 3807 | #define READ_SUB (0x0300) |
| 3808 | #define DMA_PCM (0x0400) |
| 3809 | #define DMA_PRG (0x0500) |
| 3810 | #define DMA_WRAM (0x0700) |
| 3811 | |
| 3812 | #define REG_W_SBOUT (0x0) |
| 3813 | #define REG_W_IFCTRL (0x1) |
| 3814 | #define REG_W_DBCL (0x2) |
| 3815 | #define REG_W_DBCH (0x3) |
| 3816 | #define REG_W_DACL (0x4) |
| 3817 | #define REG_W_DACH (0x5) |
| 3818 | #define REG_W_DTTRG (0x6) |
| 3819 | #define REG_W_DTACK (0x7) |
| 3820 | #define REG_W_WAL (0x8) |
| 3821 | #define REG_W_WAH (0x9) |
| 3822 | #define REG_W_CTRL0 (0xA) |
| 3823 | #define REG_W_CTRL1 (0xB) |
| 3824 | #define REG_W_PTL (0xC) |
| 3825 | #define REG_W_PTH (0xD) |
| 3826 | #define REG_W_CTRL2 (0xE) |
| 3827 | #define REG_W_RESET (0xF) |
| 3828 | |
| 3829 | #define REG_R_COMIN (0x0) |
| 3830 | #define REG_R_IFSTAT (0x1) |
| 3831 | #define REG_R_DBCL (0x2) |
| 3832 | #define REG_R_DBCH (0x3) |
| 3833 | #define REG_R_HEAD0 (0x4) |
| 3834 | #define REG_R_HEAD1 (0x5) |
| 3835 | #define REG_R_HEAD2 (0x6) |
| 3836 | #define REG_R_HEAD3 (0x7) |
| 3837 | #define REG_R_PTL (0x8) |
| 3838 | #define REG_R_PTH (0x9) |
| 3839 | #define REG_R_WAL (0xa) |
| 3840 | #define REG_R_WAH (0xb) |
| 3841 | #define REG_R_STAT0 (0xc) |
| 3842 | #define REG_R_STAT1 (0xd) |
| 3843 | #define REG_R_STAT2 (0xe) |
| 3844 | #define REG_R_STAT3 (0xf) |
| 3845 | |
| 3846 | #define CMD_STATUS (0x0) |
| 3847 | #define CMD_STOPALL (0x1) |
| 3848 | #define CMD_GETTOC (0x2) |
| 3849 | #define CMD_READ (0x3) |
| 3850 | #define CMD_SEEK (0x4) |
| 3851 | // (0x5) |
| 3852 | #define CMD_STOP (0x6) |
| 3853 | #define CMD_RESUME (0x7) |
| 3854 | #define CMD_FF (0x8) |
| 3855 | #define CMD_RW (0x9) |
| 3856 | #define CMD_INIT (0xa) |
| 3857 | // (0xb) |
| 3858 | #define CMD_CLOSE (0xc) |
| 3859 | #define CMD_OPEN (0xd) |
| 3860 | // (0xe) |
| 3861 | // (0xf) |
| 3862 | |
| 3863 | |
| 3864 | #define TOCCMD_CURPOS (0x0) |
| 3865 | #define TOCCMD_TRKPOS (0x1) |
| 3866 | #define TOCCMD_CURTRK (0x2) |
| 3867 | #define TOCCMD_LENGTH (0x3) |
| 3868 | #define TOCCMD_FIRSTLAST (0x4) |
| 3869 | #define TOCCMD_TRACKADDR (0x5) |
| 3870 | |
| 3871 | struct segacd_t |
| 3872 | { |
| 3873 | cdrom_file *cd; |
| 3874 | const cdrom_toc *toc; |
| 3875 | }; |
| 3876 | |
| 3877 | segacd_t segacd; |
| 3878 | |
| 3879 | #define SECTOR_SIZE (2352) |
| 3880 | |
| 3881 | #define SET_CDD_DATA_MODE \ |
| 3882 | CDD_CONTROL |= 0x0100; \ |
| 3883 | |
| 3884 | #define SET_CDD_AUDIO_MODE \ |
| 3885 | CDD_CONTROL &= ~0x0100; \ |
| 3886 | |
| 3887 | #define STOP_CDC_READ \ |
| 3888 | SCD_STATUS_CDC &= ~0x01; \ |
| 3889 | |
| 3890 | #define SET_CDC_READ \ |
| 3891 | SCD_STATUS_CDC |= 0x01; \ |
| 3892 | |
| 3893 | #define SET_CDC_DMA \ |
| 3894 | SCD_STATUS_CDC |= 0x08; \ |
| 3895 | |
| 3896 | #define STOP_CDC_DMA \ |
| 3897 | SCD_STATUS_CDC &= ~0x08; \ |
| 3898 | |
| 3899 | #define SCD_READ_ENABLED \ |
| 3900 | (SCD_STATUS_CDC & 1) |
| 3901 | |
| 3902 | #define SCD_DMA_ENABLED \ |
| 3903 | (SCD_STATUS_CDC & 0x08) |
| 3904 | |
| 3905 | #define CLEAR_CDD_RESULT \ |
| 3906 | CDD_MIN = CDD_SEC = CDD_FRAME = CDD_EXT = 0; \ |
| 3907 | |
| 3908 | #define CHECK_SCD_LV5_INTERRUPT \ |
| 3909 | if (segacd_irq_mask & 0x20) \ |
| 3910 | { \ |
| 3911 | cputag_set_input_line(machine, "segacd_68k", 5, HOLD_LINE); \ |
| 3912 | } \ |
| 3913 | |
| 3914 | #define CHECK_SCD_LV4_INTERRUPT \ |
| 3915 | if (segacd_irq_mask & 0x10) \ |
| 3916 | { \ |
| 3917 | cputag_set_input_line(machine, "segacd_68k", 4, HOLD_LINE); \ |
| 3918 | } \ |
| 3919 | |
| 3920 | #define CURRENT_TRACK_IS_DATA \ |
| 3921 | (segacd.toc->tracks[SCD_CURTRK - 1].trktype != CD_TRACK_AUDIO) \ |
| 3922 | |
| 3923 | |
| 3924 | |
| 3925 | INLINE int to_bcd(int val, bool byte) |
| 3926 | { |
| 3927 | if (val > 99) val = 99; |
| 3928 | |
| 3929 | if (byte) return (((val) / 10) << 4) + ((val) % 10); |
| 3930 | else return (((val) / 10) << 8) + ((val) % 10); |
| 3931 | } |
| 3932 | |
| 3933 | |
| 3934 | |
| 3935 | UINT16* segacd_4meg_prgram; // pointer to SubCPU PrgRAM |
| 3936 | UINT16* segacd_dataram; |
| 3937 | static UINT16* segacd_dataram2; |
| 3938 | |
| 3939 | UINT8 SCD_BUFFER[2560]; |
| 3940 | UINT32 SCD_STATUS; |
| 3941 | UINT32 SCD_STATUS_CDC; |
| 3942 | INT32 SCD_CURLBA; |
| 3943 | UINT8 SCD_CURTRK; |
| 3944 | |
| 3945 | UINT16 CDC_DECODE; |
| 3946 | INT16 CDC_DMACNT; // can go negative |
| 3947 | UINT16 CDC_DMA_ADDRC; |
| 3948 | UINT16 CDC_PT; |
| 3949 | UINT16 CDC_WA; |
| 3950 | UINT16 CDC_REG0; |
| 3951 | UINT16 CDC_REG1; |
| 3952 | UINT16 CDC_DMA_ADDR; |
| 3953 | UINT16 CDC_IFSTAT; |
| 3954 | UINT8 CDC_HEADB0; |
| 3955 | UINT8 CDC_HEADB1; |
| 3956 | UINT8 CDC_HEADB2; |
| 3957 | UINT8 CDC_HEADB3; |
| 3958 | UINT8 CDC_STATB0; |
| 3959 | UINT8 CDC_STATB1; |
| 3960 | UINT8 CDC_STATB2; |
| 3961 | UINT8 CDC_STATB3; |
| 3962 | UINT16 CDC_SBOUT; |
| 3963 | UINT16 CDC_IFCTRL; |
| 3964 | UINT8 CDC_CTRLB0; |
| 3965 | UINT8 CDC_CTRLB1; |
| 3966 | UINT8 CDC_CTRLB2; |
| 3967 | UINT8 CDC_BUFFER[(32 * 1024 * 2) + SECTOR_SIZE]; |
| 3968 | |
| 3969 | UINT32 CDD_STATUS; |
| 3970 | UINT32 CDD_MIN; |
| 3971 | UINT32 CDD_SEC; |
| 3972 | |
| 3973 | UINT8 CDD_RX[10]; |
| 3974 | UINT8 CDD_TX[10]; |
| 3975 | UINT32 CDD_FRAME; |
| 3976 | UINT32 CDD_EXT; |
| 3977 | UINT16 CDD_CONTROL; |
| 3978 | INT16 CDD_DONE; |
| 3979 | |
| 3980 | static void set_data_audio_mode(void) |
| 3981 | { |
| 3982 | if (CURRENT_TRACK_IS_DATA) |
| 3983 | { |
| 3984 | SET_CDD_DATA_MODE |
| 3985 | } |
| 3986 | else |
| 3987 | { |
| 3988 | SET_CDD_AUDIO_MODE |
| 3989 | fatalerror("CDDA unsupported\n"); |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | |
| 3994 | #define CDD_PLAYINGCDDA 0x0100 |
| 3995 | #define CDD_READY 0x0400 |
| 3996 | #define CDD_STOPPED 0x0900 |
| 3997 | |
| 3998 | void CDD_DoChecksum(void) |
| 3999 | { |
| 4000 | int checksum = |
| 4001 | CDD_RX[0] + |
| 4002 | CDD_RX[1] + |
| 4003 | CDD_RX[2] + |
| 4004 | CDD_RX[3] + |
| 4005 | CDD_RX[4] + |
| 4006 | CDD_RX[5] + |
| 4007 | CDD_RX[6] + |
| 4008 | CDD_RX[7] + |
| 4009 | CDD_RX[9]; |
| 4010 | |
| 4011 | checksum &= 0xf; |
| 4012 | checksum ^= 0xf; |
| 4013 | |
| 4014 | CDD_RX[8] = checksum; |
| 4015 | } |
| 4016 | |
| 4017 | void CDD_Export(void) |
| 4018 | { |
| 4019 | CDD_RX[0] = (CDD_STATUS & 0x00ff)>>0; |
| 4020 | CDD_RX[1] = (CDD_STATUS & 0xff00)>>8; |
| 4021 | CDD_RX[2] = (CDD_MIN & 0x00ff)>>0; |
| 4022 | CDD_RX[3] = (CDD_MIN & 0xff00)>>8; |
| 4023 | CDD_RX[4] = (CDD_SEC & 0x00ff)>>0; |
| 4024 | CDD_RX[5] = (CDD_SEC & 0xff00)>>8; |
| 4025 | CDD_RX[6] = (CDD_FRAME & 0x00ff)>>0; |
| 4026 | CDD_RX[7] = (CDD_FRAME & 0xff00)>>8; |
| 4027 | /* 8 = checksum */ |
| 4028 | CDD_RX[9] = (CDD_EXT & 0x00ff)>>0; |
| 4029 | |
| 4030 | CDD_DoChecksum(); |
| 4031 | |
| 4032 | CDD_CONTROL &= 0xff03; |
| 4033 | |
| 4034 | } |
| 4035 | |
| 4036 | |
| 4037 | |
| 4038 | void CDC_UpdateHEAD(void) |
| 4039 | { |
| 4040 | if (CDC_CTRLB1 & 0x01) |
| 4041 | { |
| 4042 | CDC_HEADB0 = CDC_HEADB1 = CDC_HEADB2 = CDC_HEADB3 = 0x00; |
| 4043 | } |
| 4044 | else |
| 4045 | { |
| 4046 | UINT32 msf = lba_to_msf_alt(SCD_CURLBA+150); |
| 4047 | CDC_HEADB0 = to_bcd (((msf & 0x00ff0000)>>16), true); |
| 4048 | CDC_HEADB1 = to_bcd (((msf & 0x0000ff00)>>8), true); |
| 4049 | CDC_HEADB2 = to_bcd (((msf & 0x000000ff)>>0), true); |
| 4050 | CDC_HEADB3 = 0x01; |
| 4051 | } |
| 4052 | } |
| 4053 | |
| 4054 | |
| 4055 | void scd_ctrl_checks(running_machine* machine) |
| 4056 | { |
| 4057 | CDC_STATB0 = 0x80; |
| 4058 | |
| 4059 | (CDC_CTRLB0 & 0x10) ? (CDC_STATB2 = CDC_CTRLB1 & 0x08) : (CDC_STATB2 = CDC_CTRLB1 & 0x0C); |
| 4060 | (CDC_CTRLB0 & 0x02) ? (CDC_STATB3 = 0x20) : (CDC_STATB3 = 0x00); |
| 4061 | |
| 4062 | if (CDC_IFCTRL & 0x20) |
| 4063 | { |
| 4064 | CHECK_SCD_LV5_INTERRUPT |
| 4065 | CDC_IFSTAT &= ~0x20; |
| 4066 | CDC_DECODE = 0; |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | void scd_advance_current_readpos(void) |
| 4071 | { |
| 4072 | SCD_CURLBA++; |
| 4073 | |
| 4074 | CDC_WA += SECTOR_SIZE; |
| 4075 | CDC_PT += SECTOR_SIZE; |
| 4076 | |
| 4077 | CDC_WA &= 0x7fff; |
| 4078 | CDC_PT &= 0x7fff; |
| 4079 | } |
| 4080 | |
| 4081 | int Read_LBA_To_Buffer(running_machine* machine) |
| 4082 | { |
| 4083 | bool data_track = false; |
| 4084 | if (CDD_CONTROL & 0x0100) data_track = true; |
| 4085 | |
| 4086 | if (data_track) |
| 4087 | cdrom_read_data(segacd.cd, SCD_CURLBA, SCD_BUFFER, CD_TRACK_MODE1); |
| 4088 | |
| 4089 | CDC_UpdateHEAD(); |
| 4090 | |
| 4091 | if (!data_track) |
| 4092 | { |
| 4093 | scd_advance_current_readpos(); |
| 4094 | } |
| 4095 | |
| 4096 | if (CDC_CTRLB0 & 0x80) |
| 4097 | { |
| 4098 | if (CDC_CTRLB0 & 0x04) |
| 4099 | { |
| 4100 | if (data_track) |
| 4101 | { |
| 4102 | scd_advance_current_readpos(); |
| 4103 | |
| 4104 | memcpy(&CDC_BUFFER[CDC_PT + 4], SCD_BUFFER, 2048); |
| 4105 | CDC_BUFFER[CDC_PT+0] = CDC_HEADB0; |
| 4106 | CDC_BUFFER[CDC_PT+1] = CDC_HEADB1; |
| 4107 | CDC_BUFFER[CDC_PT+2] = CDC_HEADB2; |
| 4108 | CDC_BUFFER[CDC_PT+3] = CDC_HEADB3; |
| 4109 | } |
| 4110 | else |
| 4111 | { |
| 4112 | memcpy(&CDC_BUFFER[CDC_PT], SCD_BUFFER, SECTOR_SIZE); |
| 4113 | } |
| 4114 | } |
| 4115 | |
| 4116 | scd_ctrl_checks(machine); |
| 4117 | } |
| 4118 | |
| 4119 | |
| 4120 | return 0; |
| 4121 | } |
| 4122 | |
| 4123 | static void CheckCommand(running_machine* machine) |
| 4124 | { |
| 4125 | if (CDD_DONE) |
| 4126 | { |
| 4127 | CDD_DONE = 0; |
| 4128 | CDD_Export(); |
| 4129 | CHECK_SCD_LV4_INTERRUPT |
| 4130 | } |
| 4131 | |
| 4132 | if (SCD_READ_ENABLED) |
| 4133 | { |
| 4134 | set_data_audio_mode(); |
| 4135 | Read_LBA_To_Buffer(machine); |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | |
| 4140 | void CDD_GetStatus(void) |
| 4141 | { |
| 4142 | UINT16 s = (CDD_STATUS & 0x0f00); |
| 4143 | |
| 4144 | if ((s == 0x0200) || (s == 0x0700) || (s == 0x0e00)) |
| 4145 | CDD_STATUS = (SCD_STATUS & 0xff00) | (CDD_STATUS & 0x00ff); |
| 4146 | } |
| 4147 | |
| 4148 | |
| 4149 | void CDD_Stop(void) |
| 4150 | { |
| 4151 | CLEAR_CDD_RESULT |
| 4152 | STOP_CDC_READ |
| 4153 | SCD_STATUS = CDD_STOPPED; |
| 4154 | CDD_STATUS = 0x0000; |
| 4155 | SET_CDD_DATA_MODE |
| 4156 | } |
| 4157 | |
| 4158 | |
| 4159 | void CDD_GetPos(void) |
| 4160 | { |
| 4161 | CLEAR_CDD_RESULT |
| 4162 | UINT32 msf; |
| 4163 | CDD_STATUS &= 0xFF; |
| 4164 | CDD_STATUS |= SCD_STATUS; |
| 4165 | msf = lba_to_msf_alt(SCD_CURLBA+150); |
| 4166 | CDD_MIN = to_bcd(((msf & 0x00ff0000)>>16),false); |
| 4167 | CDD_SEC = to_bcd(((msf & 0x0000ff00)>>8),false); |
| 4168 | CDD_FRAME = to_bcd(((msf & 0x000000ff)>>0),false); |
| 4169 | } |
| 4170 | |
| 4171 | void CDD_GetTrackPos(void) |
| 4172 | { |
| 4173 | CLEAR_CDD_RESULT |
| 4174 | int elapsedlba; |
| 4175 | UINT32 msf; |
| 4176 | CDD_STATUS &= 0xFF; |
| 4177 | CDD_STATUS |= SCD_STATUS; |
| 4178 | elapsedlba = SCD_CURLBA - cdrom_get_track_start(segacd.cd, SCD_CURTRK); |
| 4179 | msf = lba_to_msf_alt (elapsedlba+150); |
| 4180 | CDD_MIN = to_bcd(((msf & 0x00ff0000)>>16),false); |
| 4181 | CDD_SEC = to_bcd(((msf & 0x0000ff00)>>8),false); |
| 4182 | CDD_FRAME = to_bcd(((msf & 0x000000ff)>>0),false); |
| 4183 | } |
| 4184 | |
| 4185 | void CDD_GetTrack(void) |
| 4186 | { |
| 4187 | CLEAR_CDD_RESULT |
| 4188 | CDD_STATUS &= 0xFF; |
| 4189 | CDD_STATUS |= SCD_STATUS; |
| 4190 | SCD_CURTRK = cdrom_get_track(segacd.cd, SCD_CURLBA)+1; |
| 4191 | CDD_MIN = to_bcd(SCD_CURTRK, false); |
| 4192 | } |
| 4193 | |
| 4194 | void CDD_Length(void) |
| 4195 | { |
| 4196 | CLEAR_CDD_RESULT |
| 4197 | CDD_STATUS &= 0xFF; |
| 4198 | CDD_STATUS |= SCD_STATUS; |
| 4199 | CDD_MIN = 259; // HACK!!!! |
| 4200 | CDD_SEC = 258; // HACK!!!! |
| 4201 | CDD_FRAME = 257; // HACK!!!! |
| 4202 | } |
| 4203 | |
| 4204 | |
| 4205 | void CDD_FirstLast(void) |
| 4206 | { |
| 4207 | CLEAR_CDD_RESULT |
| 4208 | CDD_STATUS &= 0xFF; |
| 4209 | CDD_STATUS |= SCD_STATUS; |
| 4210 | CDD_MIN = 1; // first // HACK!!!! |
| 4211 | CDD_SEC = 1; // last // HACK!!!! |
| 4212 | } |
| 4213 | |
| 4214 | void CDD_GetTrackAdr(void) |
| 4215 | { |
| 4216 | CLEAR_CDD_RESULT |
| 4217 | |
| 4218 | int track = (CDD_TX[4] & 0xF) + (CDD_TX[5] & 0xF) * 10; |
| 4219 | int last_track = cdrom_get_last_track(segacd.cd)+1; |
| 4220 | |
| 4221 | CDD_STATUS &= 0xFF; |
| 4222 | CDD_STATUS |= SCD_STATUS; |
| 4223 | |
| 4224 | if (track > last_track) |
| 4225 | track = last_track; |
| 4226 | |
| 4227 | if (track < 1) |
| 4228 | track = 1; |
| 4229 | |
| 4230 | UINT32 startlba = (segacd.toc->tracks[track-1].physframeofs); |
| 4231 | UINT32 startmsf = lba_to_msf_alt( startlba+150 ); |
| 4232 | |
| 4233 | CDD_MIN = to_bcd((startmsf&0x00ff0000)>>16,false); |
| 4234 | CDD_SEC = to_bcd((startmsf&0x0000ff00)>>8,false); |
| 4235 | CDD_FRAME = to_bcd((startmsf&0x000000ff)>>0,false); |
| 4236 | CDD_EXT = track % 10; |
| 4237 | |
| 4238 | if (segacd.toc->tracks[track - 1].trktype != CD_TRACK_AUDIO) |
| 4239 | CDD_FRAME |= 0x0800; |
| 4240 | } |
| 4241 | |
| 4242 | static UINT32 getmsf_from_regs(void) |
| 4243 | { |
| 4244 | UINT32 msf = 0; |
| 4245 | |
| 4246 | msf = ((CDD_TX[2] & 0xF) + (CDD_TX[3] & 0xF) * 10) << 16; |
| 4247 | msf |= ((CDD_TX[4] & 0xF) + (CDD_TX[5] & 0xF) * 10) << 8; |
| 4248 | msf |= ((CDD_TX[6] & 0xF) + (CDD_TX[7] & 0xF) * 10) << 0; |
| 4249 | |
| 4250 | return msf; |
| 4251 | } |
| 4252 | |
| 4253 | void CDD_Play(void) |
| 4254 | { |
| 4255 | CLEAR_CDD_RESULT |
| 4256 | UINT32 msf = getmsf_from_regs(); |
| 4257 | SCD_CURLBA = msf_to_lba(msf)-150; |
| 4258 | SCD_CURTRK = cdrom_get_track(segacd.cd, SCD_CURLBA)+1; |
| 4259 | CDC_UpdateHEAD(); |
| 4260 | SCD_STATUS = CDD_PLAYINGCDDA; |
| 4261 | CDD_STATUS = 0x0102; |
| 4262 | set_data_audio_mode(); |
| 4263 | CDD_MIN = to_bcd(SCD_CURTRK, false); |
| 4264 | SET_CDC_READ |
| 4265 | } |
| 4266 | |
| 4267 | |
| 4268 | void CDD_Seek(void) |
| 4269 | { |
| 4270 | CLEAR_CDD_RESULT |
| 4271 | UINT32 msf = getmsf_from_regs(); |
| 4272 | SCD_CURLBA = msf_to_lba(msf)-150; |
| 4273 | SCD_CURTRK = cdrom_get_track(segacd.cd, SCD_CURLBA)+1; |
| 4274 | CDC_UpdateHEAD(); |
| 4275 | STOP_CDC_READ |
| 4276 | SCD_STATUS = CDD_READY; |
| 4277 | CDD_STATUS = 0x0200; |
| 4278 | set_data_audio_mode(); |
| 4279 | } |
| 4280 | |
| 4281 | |
| 4282 | void CDD_Pause(void) |
| 4283 | { |
| 4284 | CLEAR_CDD_RESULT |
| 4285 | STOP_CDC_READ |
| 4286 | SCD_STATUS = CDD_READY; |
| 4287 | CDD_STATUS = SCD_STATUS; |
| 4288 | SET_CDD_DATA_MODE |
| 4289 | } |
| 4290 | |
| 4291 | void CDD_Resume(void) |
| 4292 | { |
| 4293 | CLEAR_CDD_RESULT |
| 4294 | STOP_CDC_READ |
| 4295 | SCD_CURTRK = cdrom_get_track(segacd.cd, SCD_CURLBA)+1; |
| 4296 | SCD_STATUS = CDD_PLAYINGCDDA; |
| 4297 | CDD_STATUS = 0x0102; |
| 4298 | set_data_audio_mode(); |
| 4299 | CDD_MIN = to_bcd (SCD_CURTRK, false); |
| 4300 | SET_CDC_READ |
| 4301 | } |
| 4302 | |
| 4303 | |
| 4304 | void CDD_FF(void) |
| 4305 | { |
| 4306 | fatalerror("Fast Forward unsupported\n"); |
| 4307 | } |
| 4308 | |
| 4309 | |
| 4310 | void CDD_RW(void) |
| 4311 | { |
| 4312 | fatalerror("Fast Rewind unsupported\n"); |
| 4313 | } |
| 4314 | |
| 4315 | |
| 4316 | void CDD_Open(void) |
| 4317 | { |
| 4318 | fatalerror("Close Tray unsupported\n"); |
| 4319 | } |
| 4320 | |
| 4321 | |
| 4322 | void CDD_Close(void) |
| 4323 | { |
| 4324 | fatalerror("Open Tray unsupported\n"); |
| 4325 | } |
| 4326 | |
| 4327 | |
| 4328 | void CDD_Init(void) |
| 4329 | { |
| 4330 | CLEAR_CDD_RESULT |
| 4331 | STOP_CDC_READ |
| 4332 | SCD_STATUS = CDD_READY; |
| 4333 | CDD_STATUS = SCD_STATUS; |
| 4334 | CDD_SEC = 1; |
| 4335 | CDD_FRAME = 1; |
| 4336 | } |
| 4337 | |
| 4338 | |
| 4339 | void CDD_Default(void) |
| 4340 | { |
| 4341 | CLEAR_CDD_RESULT |
| 4342 | CDD_STATUS = SCD_STATUS; |
| 4343 | } |
| 4344 | |
| 4345 | |
| 4346 | static void CDD_Reset(void) |
| 4347 | { |
| 4348 | CLEAR_CDD_RESULT |
| 4349 | CDD_CONTROL = CDD_STATUS = 0; |
| 4350 | |
| 4351 | for (int i = 0; i < 10; i++) |
| 4352 | CDD_RX[i] = CDD_TX[i] = 0; |
| 4353 | |
| 4354 | CDD_DoChecksum(); |
| 4355 | |
| 4356 | SCD_CURTRK = SCD_CURLBA = 0; |
| 4357 | SCD_STATUS = CDD_READY; |
| 4358 | } |
| 4359 | |
| 4360 | static void CDC_Reset(void) |
| 4361 | { |
| 4362 | memset(CDC_BUFFER, 0x00, ((16 * 1024 * 2) + SECTOR_SIZE)); |
| 4363 | CDC_UpdateHEAD(); |
| 4364 | |
| 4365 | CDC_DMA_ADDRC = CDC_DMACNT = CDC_PT = CDC_SBOUT = CDC_IFCTRL = CDC_CTRLB0 = CDC_CTRLB1 = |
| 4366 | CDC_CTRLB2 = CDC_HEADB1 = CDC_HEADB2 = CDC_HEADB3 = CDC_STATB0 = CDC_STATB1 = CDC_STATB2 = CDC_DECODE = 0; |
| 4367 | |
| 4368 | CDC_IFSTAT = 0xFF; |
| 4369 | CDC_WA = SECTOR_SIZE * 2; |
| 4370 | CDC_HEADB0 = 0x01; |
| 4371 | CDC_STATB3 = 0x80; |
| 4372 | } |
| 4373 | |
| 4374 | |
| 4375 | void lc89510_Reset(void) |
| 4376 | { |
| 4377 | CDD_Reset(); |
| 4378 | CDC_Reset(); |
| 4379 | |
| 4380 | CDC_REG0 = CDC_REG1 = CDC_DMA_ADDR = SCD_STATUS_CDC = CDD_DONE = 0; |
| 4381 | } |
| 4382 | |
| 4383 | void CDC_End_Transfer(running_machine* machine) |
| 4384 | { |
| 4385 | STOP_CDC_DMA |
| 4386 | CDC_REG0 |= 0x8000; |
| 4387 | CDC_REG0 &= ~0x4000; |
| 4388 | CDC_IFSTAT |= 0x08; |
| 4389 | |
| 4390 | if (CDC_IFCTRL & 0x40) |
| 4391 | { |
| 4392 | CDC_IFSTAT &= ~0x40; |
| 4393 | CHECK_SCD_LV5_INTERRUPT |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | void CDC_Do_DMA(running_machine* machine, int rate) |
| 4398 | { |
| 4399 | UINT32 dstoffset, length; |
| 4400 | UINT8 *dest; |
| 4401 | UINT16 destination = CDC_REG0 & 0x0700; |
| 4402 | |
| 4403 | if (!(SCD_DMA_ENABLED)) |
| 4404 | return; |
| 4405 | |
| 4406 | if ((destination == READ_MAIN) || (destination==READ_SUB)) |
| 4407 | { |
| 4408 | CDC_REG0 |= 0x4000; |
| 4409 | return; |
| 4410 | } |
| 4411 | |
| 4412 | if (CDC_DMACNT <= (rate * 2)) |
| 4413 | { |
| 4414 | length = (CDC_DMACNT + 1) >> 1; |
| 4415 | CDC_End_Transfer(machine); |
| 4416 | } |
| 4417 | else |
| 4418 | length = rate; |
| 4419 | |
| 4420 | |
| 4421 | int dmacount = length; |
| 4422 | dstoffset = (CDC_DMA_ADDR & 0xFFFF) << 3; |
| 4423 | int srcoffset = 0; |
| 4424 | |
| 4425 | while (dmacount--) |
| 4426 | { |
| 4427 | UINT16 data = (CDC_BUFFER[CDC_DMA_ADDRC+srcoffset]<<8) | CDC_BUFFER[CDC_DMA_ADDRC+srcoffset+1]; |
| 4428 | |
| 4429 | if (destination==DMA_PRG) |
| 4430 | { |
| 4431 | dest = (UINT8 *) segacd_4meg_prgram; |
| 4432 | } |
| 4433 | else if (destination==DMA_WRAM) |
| 4434 | { |
| 4435 | dest = (UINT8*)segacd_dataram; |
| 4436 | |
| 4437 | if (segacd_ram_mode) |
| 4438 | { |
| 4439 | dstoffset &= 0x1ffff; |
| 4440 | if (!(segacd_ret & 1)) dest += 0x20000; |
| 4441 | } |
| 4442 | else |
| 4443 | { |
| 4444 | dstoffset &= 0x3ffff; |
| 4445 | } |
| 4446 | } |
| 4447 | else if (destination==DMA_PCM) |
| 4448 | { |
| 4449 | fatalerror("PCM RAM DMA unimplemented!\n"); |
| 4450 | } |
| 4451 | else |
| 4452 | { |
| 4453 | fatalerror("Unknown DMA Destination!!\n"); |
| 4454 | } |
| 4455 | |
| 4456 | dest[dstoffset+1] = data >>8; |
| 4457 | dest[dstoffset+0] = data&0xff; |
| 4458 | |
| 4459 | srcoffset += 2; |
| 4460 | dstoffset += 2; |
| 4461 | } |
| 4462 | |
| 4463 | CDC_DMA_ADDR += length >> 2; |
| 4464 | CDC_DMA_ADDRC += length*2; |
| 4465 | |
| 4466 | if (SCD_DMA_ENABLED) |
| 4467 | CDC_DMACNT -= length*2; |
| 4468 | else |
| 4469 | CDC_DMACNT = 0; |
| 4470 | } |
| 4471 | |
| 4472 | |
| 4473 | |
| 4474 | |
| 4475 | UINT16 CDC_Host_r(running_machine* machine, UINT16 type) |
| 4476 | { |
| 4477 | UINT16 destination = CDC_REG0 & 0x0700; |
| 4478 | |
| 4479 | if (SCD_DMA_ENABLED) |
| 4480 | { |
| 4481 | if (destination == type) |
| 4482 | { |
| 4483 | CDC_DMACNT -= 2; |
| 4484 | |
| 4485 | if (CDC_DMACNT <= 0) |
| 4486 | { |
| 4487 | if (type==READ_SUB) CDC_DMACNT = 0; |
| 4488 | |
| 4489 | CDC_End_Transfer(machine); |
| 4490 | } |
| 4491 | |
| 4492 | UINT16 data = (CDC_BUFFER[CDC_DMA_ADDRC]<<8) | CDC_BUFFER[CDC_DMA_ADDRC+1]; |
| 4493 | CDC_DMA_ADDRC += 2; |
| 4494 | |
| 4495 | return data; |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | return 0; |
| 4500 | } |
| 4501 | |
| 4502 | |
| 4503 | UINT8 CDC_Reg_r(void) |
| 4504 | { |
| 4505 | int reg = CDC_REG0 & 0xF; |
| 4506 | UINT8 ret = 0; |
| 4507 | int decode[0x10] = { 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0 }; |
| 4508 | |
| 4509 | if (decode[reg]) |
| 4510 | CDC_DECODE |= (1 << reg); |
| 4511 | |
| 4512 | if (reg!=REG_R_STAT3) |
| 4513 | CDC_REG0 = (CDC_REG0 & 0xFFF0) | (reg+1); |
| 4514 | |
| 4515 | |
| 4516 | switch (reg) |
| 4517 | { |
| 4518 | case REG_R_COMIN: ret = 0/*COMIN*/; break; |
| 4519 | case REG_R_IFSTAT: ret = CDC_IFSTAT; break; |
| 4520 | case REG_R_DBCL: ret = CDC_DMACNT & 0xff; break; |
| 4521 | case REG_R_DBCH: ret = (CDC_DMACNT >>8) & 0xff; break; |
| 4522 | case REG_R_HEAD0: ret = CDC_HEADB0; break; |
| 4523 | case REG_R_HEAD1: ret = CDC_HEADB1; break; |
| 4524 | case REG_R_HEAD2: ret = CDC_HEADB2; break; |
| 4525 | case REG_R_HEAD3: ret = CDC_HEADB3; break; |
| 4526 | case REG_R_PTL: ret = CDC_PT & 0xff; break; |
| 4527 | case REG_R_PTH: ret = (CDC_PT >>8) & 0xff; break; |
| 4528 | case REG_R_WAL: ret = CDC_WA & 0xff; break; |
| 4529 | case REG_R_WAH: ret = (CDC_WA >>8) & 0xff; break; |
| 4530 | case REG_R_STAT0: ret = CDC_STATB0; break; |
| 4531 | case REG_R_STAT1: ret = CDC_STATB1; break; |
| 4532 | case REG_R_STAT2: ret = CDC_STATB2; break; |
| 4533 | case REG_R_STAT3: ret = CDC_STATB3; |
| 4534 | |
| 4535 | CDC_IFSTAT |= 0x20; |
| 4536 | |
| 4537 | // ?? |
| 4538 | if ((CDC_CTRLB0 & 0x80) && (CDC_IFCTRL & 0x20)) |
| 4539 | { |
| 4540 | if ((CDC_DECODE & 0x73F2) == 0x73F2) |
| 4541 | CDC_STATB3 = 0x80; |
| 4542 | } |
| 4543 | break; |
| 4544 | } |
| 4545 | |
| 4546 | return ret; |
| 4547 | } |
| 4548 | |
| 4549 | void CDC_Reg_w(UINT8 data) |
| 4550 | { |
| 4551 | int reg = CDC_REG0 & 0xF; |
| 4552 | |
| 4553 | int changers0[0x10] = { 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0}; |
| 4554 | |
| 4555 | if (changers0[reg]) |
| 4556 | CDC_REG0 = (CDC_REG0 & 0xFFF0) | (reg+1); |
| 4557 | |
| 4558 | switch (reg) |
| 4559 | { |
| 4560 | case REG_W_SBOUT: |
| 4561 | CDC_SBOUT = data; |
| 4562 | break; |
| 4563 | |
| 4564 | case REG_W_IFCTRL: |
| 4565 | CDC_IFCTRL = data; |
| 4566 | |
| 4567 | if (!(CDC_IFCTRL & 0x02)) |
| 4568 | { |
| 4569 | CDC_DMACNT = 0; |
| 4570 | STOP_CDC_DMA; |
| 4571 | CDC_IFSTAT |= 0x08; |
| 4572 | } |
| 4573 | break; |
| 4574 | |
| 4575 | case REG_W_DBCL: CDC_DMACNT = (CDC_DMACNT &~ 0x00ff) | (data & 0x00ff) << 0; break; |
| 4576 | case REG_W_DBCH: CDC_DMACNT = (CDC_DMACNT &~ 0xff00) | (data & 0x00ff) << 8; break; |
| 4577 | case REG_W_DACL: CDC_DMA_ADDRC = (CDC_DMA_ADDRC &~ 0x00ff) | (data & 0x00ff) << 0; break; |
| 4578 | case REG_W_DACH: CDC_DMA_ADDRC = (CDC_DMA_ADDRC &~ 0xff00) | (data & 0x00ff) << 8; break; |
| 4579 | |
| 4580 | case REG_W_DTTRG: |
| 4581 | if (CDC_IFCTRL & 0x02) |
| 4582 | { |
| 4583 | CDC_IFSTAT &= ~0x08; |
| 4584 | SET_CDC_DMA; |
| 4585 | CDC_REG0 &= ~0x8000; |
| 4586 | } |
| 4587 | break; |
| 4588 | |
| 4589 | case REG_W_DTACK: CDC_IFSTAT |= 0x40; break; |
| 4590 | case REG_W_WAL: CDC_WA = (CDC_WA &~ 0x00ff) | (data & 0x00ff) << 0; break; |
| 4591 | case REG_W_WAH: CDC_WA = (CDC_WA &~ 0xff00) | (data & 0x00ff) << 8; break; |
| 4592 | case REG_W_CTRL0: CDC_CTRLB0 = data; break; |
| 4593 | case REG_W_CTRL1: CDC_CTRLB1 = data; break; |
| 4594 | case REG_W_PTL: CDC_PT = (CDC_PT &~ 0x00ff) | (data & 0x00ff) << 0; break; |
| 4595 | case REG_W_PTH: CDC_PT = (CDC_PT &~ 0xff00) | (data & 0x00ff) << 8; break; |
| 4596 | case REG_W_CTRL2: CDC_CTRLB2 = data; break; |
| 4597 | case REG_W_RESET: CDC_Reset(); break; |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | void CDD_Process(running_machine* machine, int reason) |
| 4602 | { |
| 4603 | CDD_Export(); |
| 4604 | CHECK_SCD_LV4_INTERRUPT |
| 4605 | } |
| 4606 | |
| 4607 | void CDD_Handle_TOC_Commands(void) |
| 4608 | { |
| 4609 | int subcmd = CDD_TX[2]; |
| 4610 | CDD_STATUS = (CDD_STATUS & 0xFF00) | subcmd; |
| 4611 | |
| 4612 | switch (subcmd) |
| 4613 | { |
| 4614 | case TOCCMD_CURPOS: CDD_GetPos(); break; |
| 4615 | case TOCCMD_TRKPOS: CDD_GetTrackPos(); break; |
| 4616 | case TOCCMD_CURTRK: CDD_GetTrack (); break; |
| 4617 | case TOCCMD_LENGTH: CDD_Length(); break; |
| 4618 | case TOCCMD_FIRSTLAST: CDD_FirstLast(); break; |
| 4619 | case TOCCMD_TRACKADDR: CDD_GetTrackAdr(); break; |
| 4620 | default: CDD_GetStatus(); break; |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | void CDD_Import(running_machine* machine) |
| 4625 | { |
| 4626 | switch (CDD_TX[1]) |
| 4627 | { |
| 4628 | case CMD_STATUS: CDD_GetStatus(); break; |
| 4629 | case CMD_STOPALL: CDD_Stop(); break; |
| 4630 | case CMD_GETTOC: CDD_Handle_TOC_Commands(); break; |
| 4631 | case CMD_READ: CDD_Play(); break; |
| 4632 | case CMD_SEEK: CDD_Seek(); break; |
| 4633 | case CMD_STOP: CDD_Pause(); break; |
| 4634 | case CMD_RESUME: CDD_Resume(); break; |
| 4635 | case CMD_FF: CDD_FF(); break; |
| 4636 | case CMD_RW: CDD_RW(); break; |
| 4637 | case CMD_INIT: CDD_Init(); break; |
| 4638 | case CMD_CLOSE: CDD_Open(); break; |
| 4639 | case CMD_OPEN: CDD_Close(); break; |
| 4640 | default: CDD_Default(); break; |
| 4641 | } |
| 4642 | |
| 4643 | CDD_DONE = 1; |
| 4644 | } |
| 4645 | |
| 4646 | |
| 4647 | |
| 4648 | |
| 4649 | |
| 3811 | 4650 | static UINT16 segacd_hint_register; |
| 3812 | 4651 | static UINT16 segacd_imagebuffer_vdot_size; |
| 3813 | 4652 | static UINT16 segacd_imagebuffer_vcell_size; |
| r10382 | r10383 | |
| 3874 | 4713 | // so probably don't change instantly... |
| 3875 | 4714 | // |
| 3876 | 4715 | |
| 3877 | | int segacd_dmna = 0; |
| 3878 | | int segacd_ret = 0; |
| 3879 | 4716 | |
| 4717 | |
| 3880 | 4718 | static TIMER_CALLBACK( segacd_dmna_ret_timer_callback ) |
| 3881 | 4719 | { |
| 3882 | 4720 | |
| r10382 | r10383 | |
| 3909 | 4747 | } |
| 3910 | 4748 | |
| 3911 | 4749 | |
| 3912 | | static UINT8 segacd_ram_writeprotect_bits; |
| 3913 | | static int segacd_ram_mode; |
| 3914 | | static int segacd_ram_mode_old; |
| 3915 | 4750 | |
| 3916 | | //static int segacd_maincpu_has_ram_access = 0; |
| 3917 | | static int segacd_4meg_prgbank = 0; // which bank the MainCPU can see of the SubCPU PrgRAM |
| 3918 | | static int segacd_memory_priority_mode = 0; |
| 3919 | | static int segacd_stampsize; |
| 3920 | 4751 | |
| 3921 | | |
| 3922 | 4752 | static READ16_HANDLER( scd_a12002_memory_mode_r ) |
| 3923 | 4753 | { |
| 3924 | 4754 | return (segacd_ram_writeprotect_bits << 8) | |
| r10382 | r10383 | |
| 3989 | 4819 | { |
| 3990 | 4820 | //printf("main dmna\n"); |
| 3991 | 4821 | segacd_dmna = 1; |
| 3992 | | segacd_dmna_ret_timer->adjust(attotime::from_usec(100)); |
| 4822 | segacd_dmna_ret_timer->adjust(attotime::from_usec(1)); |
| 3993 | 4823 | } |
| 3994 | 4824 | } |
| 3995 | 4825 | } |
| r10382 | r10383 | |
| 4058 | 4888 | // printf("sub ret\n"); |
| 4059 | 4889 | // segacd_ret = 1; |
| 4060 | 4890 | // segacd_dmna = 0; |
| 4061 | | segacd_dmna_ret_timer->adjust(attotime::from_usec(100)); |
| 4891 | segacd_dmna_ret_timer->adjust(attotime::from_usec(1)); |
| 4062 | 4892 | } |
| 4063 | 4893 | } |
| 4064 | 4894 | } |
| r10382 | r10383 | |
| 4265 | 5095 | CDC Stuff ******** |
| 4266 | 5096 | **************************************************************/ |
| 4267 | 5097 | |
| 4268 | | static int segacd_cdc_regaddress; |
| 4269 | | static int segacd_cdc_destination_device; |
| 4270 | | static UINT8 segacd_cdc_registers[0x10]; |
| 4271 | 5098 | |
| 4272 | 5099 | |
| 4273 | 5100 | static WRITE16_HANDLER( segacd_cdc_mode_address_w ) |
| 4274 | 5101 | { |
| 4275 | | if (ACCESSING_BITS_0_7) |
| 4276 | | { |
| 4277 | | segacd_cdc_regaddress = data & 0x0f; |
| 4278 | | if (data & 0xf0) printf("unknown bits set in register address write %04x\n", data); |
| 4279 | | |
| 4280 | | printf("CDC register address set to %02x\n" , segacd_cdc_regaddress); |
| 4281 | | } |
| 4282 | | |
| 4283 | | if (ACCESSING_BITS_8_15) |
| 4284 | | { |
| 4285 | | segacd_cdc_destination_device = (data & 0x0700)>>8; |
| 4286 | | if (data & 0xf800) printf("unknown bits set in destination address write %04x\n",data); |
| 4287 | | |
| 4288 | | printf("destination set to: "); |
| 4289 | | switch (segacd_cdc_destination_device&0x7) |
| 4290 | | { |
| 4291 | | case 0x00: printf("Illegal\n"); break; |
| 4292 | | case 0x01: printf("Illegal\n"); break; |
| 4293 | | case 0x02: printf("Main Cpu Read\n"); break; |
| 4294 | | case 0x03: printf("Sub Cpu Read\n"); break; |
| 4295 | | case 0x04: printf("RFC5164 PCM\n"); break; |
| 4296 | | case 0x05: printf("PRG RAM\n"); break; |
| 4297 | | case 0x06: printf("Illegal\n"); break; |
| 4298 | | case 0x07: printf("2M AM (2M Mode) / SUB CPU 1H RAM\n"); break; |
| 4299 | | } |
| 4300 | | } |
| 5102 | COMBINE_DATA(&CDC_REG0); |
| 4301 | 5103 | } |
| 4302 | 5104 | |
| 4303 | 5105 | static READ16_HANDLER( segacd_cdc_mode_address_r ) |
| 4304 | 5106 | { |
| 4305 | | UINT16 retdata = 0x0000; |
| 4306 | | |
| 4307 | | if (ACCESSING_BITS_0_7) |
| 4308 | | { |
| 4309 | | retdata |= segacd_cdc_regaddress; |
| 4310 | | } |
| 4311 | | |
| 4312 | | if (ACCESSING_BITS_8_15) |
| 4313 | | { |
| 4314 | | retdata |= segacd_cdc_destination_device << 8; |
| 4315 | | |
| 4316 | | // todo: hook them up |
| 4317 | | int data_set_ready = 0; |
| 4318 | | int end_of_data_transfer = 0; |
| 4319 | | |
| 4320 | | if (data_set_ready) retdata |= 0x4000; |
| 4321 | | if (end_of_data_transfer) retdata |= 0x8000; |
| 4322 | | |
| 4323 | | } |
| 4324 | | |
| 4325 | | return retdata; |
| 5107 | return CDC_REG0; |
| 4326 | 5108 | } |
| 4327 | 5109 | |
| 4328 | 5110 | static WRITE16_HANDLER( segacd_cdc_data_w ) |
| 4329 | 5111 | { |
| 5112 | COMBINE_DATA(&CDC_REG1); |
| 5113 | |
| 4330 | 5114 | if (ACCESSING_BITS_0_7) |
| 4331 | | { |
| 4332 | | segacd_cdc_registers[segacd_cdc_regaddress] = data; |
| 4333 | | printf("CDC Register %02x set to %02x\n", segacd_cdc_regaddress, data & 0xff); |
| 4334 | | } |
| 4335 | | |
| 4336 | | if (ACCESSING_BITS_8_15) |
| 4337 | | { |
| 4338 | | // nothing here? |
| 4339 | | } |
| 5115 | CDC_Reg_w(data); |
| 4340 | 5116 | } |
| 4341 | 5117 | |
| 4342 | 5118 | static READ16_HANDLER( segacd_cdc_data_r ) |
| 4343 | 5119 | { |
| 4344 | | UINT16 retdata = 0x0000; |
| 5120 | UINT16 retdat = 0x0000; |
| 4345 | 5121 | |
| 4346 | 5122 | if (ACCESSING_BITS_0_7) |
| 4347 | | { |
| 4348 | | retdata |= segacd_cdc_registers[segacd_cdc_regaddress]; |
| 4349 | | printf("CDC Register %02x Read\n", segacd_cdc_regaddress); |
| 4350 | | } |
| 5123 | retdat |= CDC_Reg_r(); |
| 4351 | 5124 | |
| 4352 | | if (ACCESSING_BITS_8_15) |
| 4353 | | { |
| 4354 | | // nothing here? |
| 4355 | | } |
| 4356 | | |
| 4357 | | return retdata; |
| 5125 | return retdat; |
| 4358 | 5126 | } |
| 4359 | 5127 | |
| 4360 | 5128 | |
| 4361 | | static UINT16* segacd_dataram; |
| 4362 | | static UINT16* segacd_dataram2; |
| 4363 | 5129 | |
| 4364 | 5130 | |
| 5131 | |
| 4365 | 5132 | static READ16_HANDLER( segacd_main_dataram_part1_r ) |
| 4366 | 5133 | { |
| 4367 | 5134 | if (segacd_ram_mode==0) |
| r10382 | r10383 | |
| 4951 | 5718 | return srcdata[((ypos&((1<<tilesize)-1))*(1<<tilesize))+(xpos&((1<<tilesize)-1))]; |
| 4952 | 5719 | } |
| 4953 | 5720 | |
| 5721 | static TIMER_CALLBACK( segacd_access_timer_callback ) |
| 5722 | { |
| 5723 | CheckCommand(machine); |
| 5724 | } |
| 4954 | 5725 | |
| 4955 | | static TIMER_CALLBACK( segacd_hock_callback ) |
| 5726 | READ16_HANDLER( cdc_data_sub_r ) |
| 4956 | 5727 | { |
| 4957 | | int i,cdd_crc; |
| 5728 | return CDC_Host_r(space->machine, READ_SUB); |
| 5729 | } |
| 4958 | 5730 | |
| 4959 | | if(hock_cmd) |
| 4960 | | { |
| 4961 | | // segacd_cdd.ctrl &= ~4; // clear HOCK flag |
| 4962 | | |
| 4963 | | segacd_cdd_rx[0] = (segacd_cdd.buffer[0] & 0xf0) >> 4; |
| 4964 | | segacd_cdd_rx[1] = (segacd_cdd.buffer[0] & 0x0f) >> 0; |
| 4965 | | segacd_cdd_rx[2] = (segacd_cdd.buffer[1] & 0xf0) >> 4; |
| 4966 | | segacd_cdd_rx[3] = (segacd_cdd.buffer[1] & 0x0f) >> 0; |
| 4967 | | segacd_cdd_rx[4] = (segacd_cdd.buffer[2] & 0xf0) >> 4; |
| 4968 | | segacd_cdd_rx[5] = (segacd_cdd.buffer[2] & 0x0f) >> 0; |
| 4969 | | segacd_cdd_rx[6] = (segacd_cdd.buffer[3] & 0xf0) >> 4; |
| 4970 | | segacd_cdd_rx[7] = (segacd_cdd.buffer[3] & 0x0f) >> 0; |
| 4971 | | segacd_cdd_rx[8] = (segacd_cdd.buffer[4] & 0x0f) >> 0; |
| 4972 | | |
| 4973 | | /* Do checksum calculation of the above registers */ |
| 4974 | | cdd_crc = 0; |
| 4975 | | for(i=0;i<9;i++) |
| 4976 | | cdd_crc += segacd_cdd_rx[i]; |
| 4977 | | |
| 4978 | | segacd_cdd_rx[9] = ((cdd_crc & 0xf) ^ 0xf); |
| 4979 | | |
| 4980 | | if(segacd_irq_mask & 0x10) |
| 4981 | | cputag_set_input_line(machine, "segacd_68k", 4, HOLD_LINE); |
| 4982 | | |
| 4983 | | hock_cmd = 0; |
| 4984 | | } |
| 4985 | | |
| 4986 | | segacd_hock_timer->adjust(attotime::from_hz(75)); |
| 5731 | READ16_HANDLER( cdc_data_main_r ) |
| 5732 | { |
| 5733 | return CDC_Host_r(space->machine, READ_MAIN); |
| 4987 | 5734 | } |
| 4988 | 5735 | |
| 4989 | 5736 | |
| r10382 | r10383 | |
| 5007 | 5754 | |
| 5008 | 5755 | memory_install_readwrite16_handler(cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa12000, 0xa12001, 0, 0, scd_a12000_halt_reset_r, scd_a12000_halt_reset_w); // sub-cpu control |
| 5009 | 5756 | memory_install_readwrite16_handler(cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa12002, 0xa12003, 0, 0, scd_a12002_memory_mode_r, scd_a12002_memory_mode_w); // memory mode / write protect |
| 5010 | | |
| 5757 | //memory_install_readwrite16_handler(cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa12004, 0xa12005, 0, 0, segacd_cdc_mode_address_r, segacd_cdc_mode_address_w); |
| 5011 | 5758 | memory_install_readwrite16_handler(cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa12006, 0xa12007, 0, 0, scd_a12006_hint_register_r, scd_a12006_hint_register_w); // where HINT points on main CPU |
| 5759 | //memory_install_read16_handler (cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa12008, 0xa12009, 0, 0, cdc_data_main_r); |
| 5012 | 5760 | |
| 5013 | 5761 | |
| 5762 | |
| 5014 | 5763 | memory_install_readwrite16_handler(cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa1200e, 0xa1200f, 0, 0, segacd_comms_flags_r, segacd_comms_flags_maincpu_w); // communication flags block |
| 5015 | 5764 | |
| 5016 | 5765 | memory_install_readwrite16_handler(cputag_get_address_space(space->machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa12010, 0xa1201f, 0, 0, segacd_comms_main_part1_r, segacd_comms_main_part1_w); |
| r10382 | r10383 | |
| 5027 | 5776 | segacd_dmna_ret_timer = machine->scheduler().timer_alloc(FUNC(segacd_dmna_ret_timer_callback)); |
| 5028 | 5777 | segacd_gfx_conversion_timer->adjust(attotime::never); |
| 5029 | 5778 | |
| 5030 | | segacd_hock_timer = machine->scheduler().timer_alloc(FUNC(segacd_hock_callback)); |
| 5031 | | segacd_hock_timer->adjust(attotime::never); |
| 5779 | segacd_hock_timer = machine->scheduler().timer_alloc(FUNC(segacd_access_timer_callback)); |
| 5780 | segacd_hock_timer->adjust( attotime::from_nsec(5000000), 0, attotime::from_nsec(5000000)); |
| 5032 | 5781 | |
| 5033 | 5782 | segacd_irq3_timer = machine->scheduler().timer_alloc(FUNC(segacd_irq3_timer_callback)); |
| 5034 | 5783 | segacd_irq3_timer->adjust(attotime::never); |
| r10382 | r10383 | |
| 5054 | 5803 | machine->gfx[14]= gfx_element_alloc(machine, &sega_32x32_r10_f1_layout, (UINT8 *)segacd_dataram, 0, 0); |
| 5055 | 5804 | machine->gfx[15]= gfx_element_alloc(machine, &sega_32x32_r11_f1_layout, (UINT8 *)segacd_dataram, 0, 0); |
| 5056 | 5805 | |
| 5057 | | /* as a temporary measure we use the MAME tilemaps, this is hideously inefficient as we have to mark the active one as |
| 5058 | | dirty before each operation due to the RAM based tiles. For the larger tilemaps this means we have to re-render a 4096x4096 |
| 5059 | | bitmap to the tilemap cache on each blit operation just to copy the few needed tiles out of it, needless to say, this is SLOW. |
| 5060 | | Eventually the tilemaps will be replaced with a get_pixel function which will perform all the needed lookups on a per-pixel |
| 5061 | | basis instead of re-rendering the whole thing */ |
| 5062 | 5806 | segacd_stampmap[0] = tilemap_create(machine, get_stampmap_16x16_1x1_tile_info, tilemap_scan_rows, 16, 16, 16, 16); |
| 5063 | 5807 | segacd_stampmap[1] = tilemap_create(machine, get_stampmap_32x32_1x1_tile_info, tilemap_scan_rows, 32, 32, 8, 8); |
| 5064 | 5808 | segacd_stampmap[2] = tilemap_create(machine, get_stampmap_16x16_16x16_tile_info, tilemap_scan_rows, 16, 16, 256, 256); // 128kb! |
| r10382 | r10383 | |
| 5069 | 5813 | |
| 5070 | 5814 | static MACHINE_RESET( segacd ) |
| 5071 | 5815 | { |
| 5072 | | int i; |
| 5073 | 5816 | cpu_set_input_line(_segacd_68k_cpu, INPUT_LINE_RESET, ASSERT_LINE); |
| 5074 | 5817 | cpu_set_input_line(_segacd_68k_cpu, INPUT_LINE_HALT, ASSERT_LINE); |
| 5075 | 5818 | |
| 5076 | 5819 | segacd_hint_register = 0xffff; // -1 |
| 5077 | 5820 | |
| 5078 | | for(i=0;i<10;i++) |
| 5079 | | { |
| 5080 | | segacd_cdd_rx[i] = 0; |
| 5081 | | } |
| 5821 | /* init cd-rom device */ |
| 5082 | 5822 | |
| 5083 | | segacd_cdd_rx[9] = 0xf; // default checksum |
| 5823 | lc89510_Reset(); |
| 5084 | 5824 | |
| 5085 | | /* init cd-rom device */ |
| 5086 | | |
| 5087 | | #ifdef MESS |
| 5088 | 5825 | { |
| 5089 | 5826 | device_t *device; |
| 5090 | 5827 | |
| r10382 | r10383 | |
| 5096 | 5833 | { |
| 5097 | 5834 | segacd.toc = cdrom_get_toc( segacd.cd ); |
| 5098 | 5835 | cdda_set_cdrom( machine->device("cdda"), segacd.cd ); |
| 5099 | | segacd.last_frame = cdrom_get_track_start( segacd.cd, cdrom_get_last_track( segacd.cd ) - 1 ); |
| 5100 | | segacd.last_frame += segacd.toc->tracks[ cdrom_get_last_track( segacd.cd ) - 1 ].frames; |
| 5101 | | segacd.end_frame = segacd.last_frame; |
| 5102 | 5836 | } |
| 5103 | 5837 | } |
| 5104 | | |
| 5105 | | segacd_cdd.scd_status = 0x00; // initial state |
| 5106 | 5838 | } |
| 5107 | | #endif |
| 5108 | 5839 | |
| 5840 | |
| 5841 | if (segacd.cd) |
| 5842 | printf("cd found\n"); |
| 5843 | |
| 5109 | 5844 | segacd_dmna = 0; |
| 5110 | 5845 | segacd_ret = 0; |
| 5111 | 5846 | |
| r10382 | r10383 | |
| 5113 | 5848 | segacd_ram_mode_old = 0; |
| 5114 | 5849 | |
| 5115 | 5850 | segacd_dmna_ret_timer->adjust(attotime::zero); |
| 5116 | | segacd_hock_timer->adjust(attotime::zero); |
| 5851 | |
| 5117 | 5852 | hock_cmd = 0; |
| 5118 | 5853 | } |
| 5119 | 5854 | |
| r10382 | r10383 | |
| 5253 | 5988 | } |
| 5254 | 5989 | |
| 5255 | 5990 | |
| 5256 | | #if 0 |
| 5257 | | static void cdd_hock_irq(running_machine *machine,UINT8 dir) |
| 5258 | | { |
| 5259 | | if((segacd_cdd.ctrl & 4 || dir) && segacd_irq_mask & 0x10) // export status, check if bit 2 (HOst ClocK) and irq is enabled |
| 5260 | | { |
| 5261 | | segacd_cdd.ctrl |= 4; // enable Hock bit if it isn't already active |
| 5262 | | machine->scheduler().timer_set(attotime::from_hz(75), FUNC(execute_hock_irq)); // 1 / 75th of a second |
| 5263 | | } |
| 5264 | | } |
| 5265 | | #endif |
| 5266 | 5991 | |
| 5267 | 5992 | static READ16_HANDLER( segacd_irq_mask_r ) |
| 5268 | 5993 | { |
| r10382 | r10383 | |
| 5271 | 5996 | |
| 5272 | 5997 | static WRITE16_HANDLER( segacd_irq_mask_w ) |
| 5273 | 5998 | { |
| 5999 | UINT16 control = CDD_CONTROL; |
| 6000 | |
| 6001 | // printf("segacd_irq_mask_w %04x %04x (CDD control is %04x)\n",data, mem_mask, control); |
| 6002 | |
| 6003 | if (data & 0x10) |
| 6004 | { |
| 6005 | if (control & 0x04) |
| 6006 | { |
| 6007 | if (!segacd_irq_mask & 0x10) |
| 6008 | { |
| 6009 | segacd_irq_mask = data & 0x7e; |
| 6010 | CDD_Process(space->machine, 0); |
| 6011 | return; |
| 6012 | } |
| 6013 | } |
| 6014 | } |
| 6015 | |
| 5274 | 6016 | segacd_irq_mask = data & 0x7e; |
| 5275 | | |
| 5276 | | // TODO: check here pending IRQs |
| 5277 | 6017 | } |
| 5278 | 6018 | |
| 5279 | 6019 | static READ16_HANDLER( segacd_cdd_ctrl_r ) |
| 5280 | 6020 | { |
| 5281 | | return segacd_cdd.ctrl; |
| 6021 | return CDD_CONTROL; |
| 5282 | 6022 | } |
| 5283 | 6023 | |
| 6024 | |
| 5284 | 6025 | static WRITE16_HANDLER( segacd_cdd_ctrl_w ) |
| 5285 | 6026 | { |
| 5286 | | segacd_cdd.ctrl = data; |
| 6027 | UINT16 control = CDD_CONTROL; |
| 5287 | 6028 | |
| 5288 | | hock_cmd = (data & 4) >> 2; |
| 6029 | printf("segacd_cdd_ctrl_w %04x %04x (control %04x irq %04x\n", data, mem_mask, control, segacd_irq_mask); |
| 5289 | 6030 | |
| 5290 | | if(data & 4) // enable Hock timer |
| 5291 | | segacd_hock_timer->adjust(attotime::from_hz(75)); |
| 5292 | | else |
| 5293 | | segacd_hock_timer->adjust(attotime::never); |
| 5294 | | } |
| 5295 | | |
| 5296 | | /* 68k <- CDD communication comms are 4-bit wide */ |
| 5297 | | static READ8_HANDLER( segacd_cdd_rx_r ) |
| 5298 | | { |
| 5299 | | return (segacd_cdd_rx[offset] & 0xf); |
| 5300 | | } |
| 5301 | | |
| 5302 | | static const char *const segacd_cdd_cmd[] = |
| 5303 | | { |
| 5304 | | "Status", |
| 5305 | | "Stop All", |
| 5306 | | "Get TOC Info", |
| 5307 | | "Play", |
| 5308 | | "Seek", |
| 5309 | | "Pause/Stop", |
| 5310 | | "Resume", |
| 5311 | | "Fast Forward", |
| 5312 | | "Fast Rewind", |
| 5313 | | "Recover Initial state", |
| 5314 | | "Close Tray", |
| 5315 | | "Open Tray", |
| 5316 | | "Unknown 0xE", |
| 5317 | | "Unknown 0xF" |
| 5318 | | }; |
| 5319 | | |
| 5320 | | static const char *const segacd_cdd_get_toc_cmd[] = |
| 5321 | | { |
| 5322 | | "Get Current Position", |
| 5323 | | "Get Elapsed Time of Current Track", |
| 5324 | | "Get Current Track", |
| 5325 | | "Get Total Length", |
| 5326 | | "Get First and Last Track Number", |
| 5327 | | "Get Track Addresses", |
| 5328 | | "Invalid 0x6", |
| 5329 | | "Invalid 0x7", |
| 5330 | | "Invalid 0x8", |
| 5331 | | "Invalid 0x9", |
| 5332 | | "Invalid 0xA", |
| 5333 | | "Invalid 0xB", |
| 5334 | | "Invalid 0xC", |
| 5335 | | "Invalid 0xD", |
| 5336 | | "Invalid 0xE", |
| 5337 | | "Invalid 0xF", |
| 5338 | | }; |
| 5339 | | |
| 5340 | | #ifdef MESS |
| 5341 | | |
| 5342 | | #define LOG_CDD 1 |
| 5343 | | |
| 5344 | | static void segacd_cdd_get_status(running_machine *machine) |
| 5345 | | { |
| 5346 | | //segacd_cdd.buffer[0] = 0; |
| 5347 | | //segacd_cdd.buffer[1] = 0; |
| 5348 | | //segacd_cdd.buffer[2] = 0; |
| 5349 | | //segacd_cdd.buffer[3] = 0; |
| 5350 | | //segacd_cdd.buffer[4] = 0; |
| 5351 | | |
| 5352 | | hock_cmd = 1; |
| 5353 | | } |
| 5354 | | |
| 5355 | | static void segacd_cdd_stop_all(running_machine *machine) |
| 5356 | | { |
| 5357 | | segacd_cdd.ctrl |= 0x100; |
| 5358 | | |
| 5359 | | segacd_cdd.buffer[0] = 0; |
| 5360 | | segacd_cdd.buffer[1] = 0; |
| 5361 | | segacd_cdd.buffer[2] = 0; |
| 5362 | | segacd_cdd.buffer[3] = 0; |
| 5363 | | segacd_cdd.buffer[4] = 0; |
| 5364 | | |
| 5365 | | hock_cmd = 1; |
| 5366 | | } |
| 5367 | | |
| 5368 | | |
| 5369 | | static void segacd_cdd_get_toc_info(running_machine *machine) |
| 5370 | | { |
| 5371 | | segacd_cdd.buffer[0] = (segacd_cdd_tx[3] & 0xf) | (segacd_cdd.scd_status & 0xf0); // TODO: remove me |
| 5372 | | |
| 5373 | | #if LOG_CDD |
| 5374 | | if(segacd_cdd_tx[3] >= 6) |
| 5375 | | printf("CDD: TOC command %s issued\n",segacd_cdd_get_toc_cmd[segacd_cdd_tx[3] & 0xf]); |
| 5376 | | #endif |
| 5377 | | |
| 5378 | | // TODO: check if tray is open |
| 5379 | | |
| 5380 | | if ( ! segacd.cd ) // no cd is present |
| 6031 | if (data & 0x4) |
| 5381 | 6032 | { |
| 5382 | | segacd_cdd.scd_status = 0x00; |
| 5383 | | segacd_cdd.buffer[0] = (0) | (segacd_cdd.scd_status & 0xf0); |
| 5384 | | segacd_cdd.buffer[1] = 0; |
| 5385 | | segacd_cdd.buffer[2] = 0; |
| 5386 | | segacd_cdd.buffer[3] = 0; |
| 5387 | | segacd_cdd.buffer[4] = 0; |
| 5388 | | |
| 5389 | | hock_cmd = 1; |
| 5390 | | return; |
| 5391 | | } |
| 5392 | | else |
| 5393 | | { |
| 5394 | | switch(segacd_cdd_tx[3] & 0xf) |
| 6033 | if (!(control & 0x4)) |
| 5395 | 6034 | { |
| 5396 | | case 0x0: //Get Current Position |
| 6035 | if (segacd_irq_mask&0x10) |
| 5397 | 6036 | { |
| 5398 | | UINT32 msf; |
| 5399 | | |
| 5400 | | segacd_cdd.scd_status = 0x40; //TODO: check this |
| 5401 | | |
| 5402 | | msf = lba_to_msf( segacd.current_frame ); |
| 5403 | | segacd_cdd.buffer[0] = (0x0 & 0xf) | (segacd_cdd.scd_status & 0xf0); |
| 5404 | | segacd_cdd.buffer[1] = dec_2_bcd( msf >> 16 ) & 0xff; |
| 5405 | | segacd_cdd.buffer[2] = dec_2_bcd( msf >> 8 ) & 0xff; |
| 5406 | | segacd_cdd.buffer[3] = dec_2_bcd( msf >> 0 ) & 0xff; |
| 5407 | | segacd_cdd.buffer[4] = 0; |
| 5408 | | |
| 5409 | | hock_cmd = 1; |
| 5410 | | return; |
| 6037 | CDD_Process(space->machine, 1); |
| 5411 | 6038 | } |
| 5412 | | case 0x1: //Get Elapsed Time of Current Track |
| 5413 | | { |
| 5414 | | UINT32 msf; |
| 5415 | | UINT32 end_frame_track; |
| 5416 | | |
| 5417 | | segacd_cdd.scd_status = 0x40; //TODO: check this |
| 5418 | | |
| 5419 | | end_frame_track = segacd.toc->tracks[ cdrom_get_track(segacd.cd, segacd.current_frame) + 1 ].physframeofs; // correct? |
| 5420 | | |
| 5421 | | msf = lba_to_msf( end_frame_track - segacd.current_frame ); |
| 5422 | | |
| 5423 | | segacd_cdd.buffer[0] = (0x1 & 0xf) | (segacd_cdd.scd_status & 0xf0); |
| 5424 | | segacd_cdd.buffer[1] = dec_2_bcd( msf >> 16 ) & 0xff; |
| 5425 | | segacd_cdd.buffer[2] = dec_2_bcd( msf >> 8 ) & 0xff; |
| 5426 | | segacd_cdd.buffer[3] = dec_2_bcd( msf >> 0 ) & 0xff; |
| 5427 | | segacd_cdd.buffer[4] = 0; |
| 5428 | | |
| 5429 | | hock_cmd = 1; |
| 5430 | | return; |
| 5431 | | } |
| 5432 | | case 0x2: //Get Current Track |
| 5433 | | { |
| 5434 | | segacd_cdd.buffer[0] = (0x2 & 0xf) | (segacd_cdd.buffer[0] & 0xf0); |
| 5435 | | |
| 5436 | | segacd_cdd.buffer[1] = cdrom_get_track(segacd.cd, segacd.current_frame); |
| 5437 | | segacd_cdd.buffer[2] = 0; |
| 5438 | | segacd_cdd.buffer[3] = 0; |
| 5439 | | segacd_cdd.buffer[4] = 0; |
| 5440 | | |
| 5441 | | hock_cmd = 1; |
| 5442 | | return; |
| 5443 | | } |
| 5444 | | case 0x3: //Get Total Length (in MSF) |
| 5445 | | { |
| 5446 | | UINT32 frame,msf; |
| 5447 | | |
| 5448 | | frame = segacd.toc->tracks[segacd.toc->numtrks-1].physframeofs; |
| 5449 | | frame += segacd.toc->tracks[segacd.toc->numtrks-1].frames; |
| 5450 | | frame += 150; // 2 seconds of pre-gap |
| 5451 | | msf = lba_to_msf( frame ); |
| 5452 | | |
| 5453 | | segacd_cdd.buffer[0] = (0x3 & 0xf) | (segacd_cdd.scd_status & 0xf0); |
| 5454 | | segacd_cdd.buffer[1] = ((msf >> 16) & 0xff); |
| 5455 | | segacd_cdd.buffer[2] = ((msf >> 8) & 0xff); |
| 5456 | | segacd_cdd.buffer[3] = ((msf >> 0) & 0xff); |
| 5457 | | segacd_cdd.buffer[4] = 0; |
| 5458 | | |
| 5459 | | printf("%02x %02x %02x %02x %02x\n",segacd_cdd.buffer[0],segacd_cdd.buffer[1],segacd_cdd.buffer[2],segacd_cdd.buffer[3],segacd_cdd.buffer[4]); |
| 5460 | | |
| 5461 | | hock_cmd = 1; |
| 5462 | | return; |
| 5463 | | |
| 5464 | | } |
| 5465 | | case 0x4: //Get First and Last Track Number |
| 5466 | | { |
| 5467 | | segacd_cdd.scd_status = 0x40; |
| 5468 | | segacd_cdd.buffer[0] = (0x4 & 0xf) | (segacd_cdd.scd_status & 0xf0); |
| 5469 | | segacd.first_track = dec_2_bcd(1); |
| 5470 | | segacd.last_track = dec_2_bcd(segacd.toc->numtrks - 1); |
| 5471 | | segacd_cdd.buffer[1] = segacd.first_track; |
| 5472 | | segacd_cdd.buffer[2] = segacd.last_track; |
| 5473 | | segacd_cdd.buffer[3] = 0; |
| 5474 | | segacd_cdd.buffer[4] = 0; |
| 5475 | | |
| 5476 | | printf("%02x %02x %02x %02x %02x\n",segacd_cdd.buffer[0],segacd_cdd.buffer[1],segacd_cdd.buffer[2],segacd_cdd.buffer[3],segacd_cdd.buffer[4]); |
| 5477 | | |
| 5478 | | hock_cmd = 1; |
| 5479 | | return; |
| 5480 | | } |
| 5481 | | case 0x5: //Get Track Addresses |
| 5482 | | { |
| 5483 | | UINT8 track_num; |
| 5484 | | UINT32 start_frame,frame,msf; |
| 5485 | | |
| 5486 | | track_num = ((segacd_cdd_tx[4] & 0xf) * 10) | (segacd_cdd_tx[5] & 0x0f); |
| 5487 | | |
| 5488 | | if(track_num > segacd.last_track) |
| 5489 | | track_num = segacd.last_track; |
| 5490 | | if(track_num < segacd.first_track) |
| 5491 | | track_num = segacd.first_track; |
| 5492 | | start_frame = segacd.toc->tracks[ bcd_2_dec( track_num - 1 ) ].physframeofs; |
| 5493 | | //end_frame = segacd.toc->tracks[ bcd_2_dec( track_num ) ].physframeofs; |
| 5494 | | frame = start_frame; |
| 5495 | | msf = lba_to_msf( frame ); |
| 5496 | | |
| 5497 | | segacd_cdd.buffer[0] = (0x5 & 0xf) | (segacd_cdd.scd_status & 0xf0); |
| 5498 | | segacd_cdd.buffer[1] = ((msf >> 16) & 0xff); |
| 5499 | | segacd_cdd.buffer[2] = ((msf >> 8) & 0xff); |
| 5500 | | segacd_cdd.buffer[3] = ((msf >> 0) & 0xff); |
| 5501 | | segacd_cdd.buffer[4] = ((track_num) % 10) | (( segacd.toc->tracks[track_num-1].trktype == CD_TRACK_AUDIO ) ? 0x80 : 0x00); |
| 5502 | | |
| 5503 | | printf("%02x %02x %02x %02x %02x\n",segacd_cdd.buffer[0],segacd_cdd.buffer[1],segacd_cdd.buffer[2],segacd_cdd.buffer[3],segacd_cdd.buffer[4]); |
| 5504 | | |
| 5505 | | hock_cmd = 1; |
| 5506 | | return; |
| 5507 | | } |
| 5508 | | //default: logerror("CDD: unhandled TOC command %s issued\n",segacd_cdd_get_toc_cmd[segacd_cdd_tx[3] & 0xf]); |
| 5509 | 6039 | } |
| 5510 | 6040 | } |
| 5511 | 6041 | |
| 5512 | | hock_cmd = 1; |
| 6042 | CDD_CONTROL |= data; |
| 5513 | 6043 | } |
| 5514 | 6044 | |
| 5515 | | static void segacd_cdd_seek(running_machine *machine) |
| 5516 | | { |
| 5517 | | UINT8 m,s,f; |
| 5518 | | UINT8 track_num; |
| 5519 | | UINT32 frame; |
| 5520 | 6045 | |
| 5521 | | // TODO: check if tray is open or CD isn't there and throw an error if so |
| 5522 | 6046 | |
| 5523 | | segacd_cdd.scd_status = 0x20; //READY flag |
| 5524 | | |
| 5525 | | m = ((segacd_cdd_tx[2] & 0xf) * 10) | (segacd_cdd_tx[3] & 0x0f); |
| 5526 | | s = ((segacd_cdd_tx[4] & 0xf) * 10) | (segacd_cdd_tx[5] & 0x0f); |
| 5527 | | f = ((segacd_cdd_tx[6] & 0xf) * 10) | (segacd_cdd_tx[7] & 0x0f); |
| 5528 | | |
| 5529 | | frame = (m << 16) | (s << 8) | (f); |
| 5530 | | |
| 5531 | | track_num = cdrom_get_track(segacd.cd, frame); |
| 5532 | | segacd.current_frame = frame; |
| 5533 | | // printf("%02x %02x %02x %02x\n",m,s,f,track_num); |
| 5534 | | |
| 5535 | | segacd_cdd.ctrl &= 0xfeff; |
| 5536 | | segacd_cdd.ctrl |= (( segacd.toc->tracks[track_num-1].trktype == CD_TRACK_AUDIO ) ? 0x000 : 0x100); |
| 5537 | | |
| 5538 | | segacd_cdd.buffer[0] = segacd_cdd.scd_status & 0x20; // set READY |
| 5539 | | segacd_cdd.buffer[1] = 0; |
| 5540 | | segacd_cdd.buffer[2] = 0; |
| 5541 | | segacd_cdd.buffer[3] = 0; |
| 5542 | | segacd_cdd.buffer[4] = 0; |
| 5543 | | |
| 5544 | | hock_cmd = 1; |
| 6047 | static READ8_HANDLER( segacd_cdd_rx_r ) |
| 6048 | { |
| 6049 | return CDD_RX[offset^1]; |
| 5545 | 6050 | } |
| 5546 | 6051 | |
| 5547 | | #endif |
| 5548 | | |
| 5549 | 6052 | static WRITE8_HANDLER( segacd_cdd_tx_w ) |
| 5550 | 6053 | { |
| 5551 | | //printf("CDD Communication write %02x -> [%02x]\n",data,offset); |
| 5552 | | segacd_cdd_tx[offset] = data & 0xf; |
| 6054 | CDD_TX[offset^1] = data; |
| 5553 | 6055 | |
| 5554 | | #ifdef MESS |
| 5555 | | if(offset == 9) //execute the command when crc is sent (TODO: I wonder if we need to check if crc is valid. Plus obviously this shouldn't be instant) |
| 6056 | if(offset == 9) |
| 5556 | 6057 | { |
| 5557 | | #if LOG_CDD |
| 5558 | | if(segacd_cdd_tx[0] != 0 && segacd_cdd_tx[0] != 2) |
| 5559 | | printf("CDD: command %s issued\n",segacd_cdd_cmd[segacd_cdd_tx[0] & 0xf]); |
| 5560 | | #endif |
| 5561 | | |
| 5562 | | switch(segacd_cdd_tx[0] & 0xf) |
| 5563 | | { |
| 5564 | | case 0x0: segacd_cdd_get_status(space->machine); break; |
| 5565 | | case 0x1: segacd_cdd_stop_all(space->machine); break; |
| 5566 | | case 0x2: segacd_cdd_get_toc_info(space->machine); break; |
| 5567 | | //case 0x3: segacd_cdd_play(space->machine); break; |
| 5568 | | case 0x4: segacd_cdd_seek(space->machine); break; |
| 5569 | | //default: logerror("CDD: unhandled command %s issued\n",segacd_cdd_cmd[segacd_cdd_tx[0] & 0xf]); |
| 5570 | | } |
| 6058 | CDD_Import(space->machine); |
| 5571 | 6059 | } |
| 5572 | | #endif |
| 5573 | 6060 | } |
| 5574 | 6061 | |
| 5575 | 6062 | |
| r10382 | r10383 | |
| 5588 | 6075 | |
| 5589 | 6076 | static WRITE16_HANDLER( segacd_stampsize_w ) |
| 5590 | 6077 | { |
| 5591 | | printf("segacd_stampsize_w %04x %04x\n",data, mem_mask); |
| 6078 | //printf("segacd_stampsize_w %04x %04x\n",data, mem_mask); |
| 5592 | 6079 | if (ACCESSING_BITS_0_7) |
| 5593 | 6080 | { |
| 5594 | 6081 | segacd_stampsize = data & 0x07; |
| 5595 | | if (data & 0xf8) |
| 5596 | | printf(" unused bits (LSB) set in stampsize!\n"); |
| 6082 | //if (data & 0xf8) |
| 6083 | // printf(" unused bits (LSB) set in stampsize!\n"); |
| 5597 | 6084 | |
| 5598 | | if (data&1) printf(" Repeat On\n"); |
| 5599 | | else printf(" Repeat Off\n"); |
| 6085 | //if (data&1) printf(" Repeat On\n"); |
| 6086 | //else printf(" Repeat Off\n"); |
| 5600 | 6087 | |
| 5601 | | if (data&2) printf(" 32x32 dots\n"); |
| 5602 | | else printf(" 16x16 dots\n"); |
| 6088 | //if (data&2) printf(" 32x32 dots\n"); |
| 6089 | //else printf(" 16x16 dots\n"); |
| 5603 | 6090 | |
| 5604 | | if (data&4) printf(" 16x16 screens\n"); |
| 5605 | | else printf(" 1x1 screen\n"); |
| 6091 | //if (data&4) printf(" 16x16 screens\n"); |
| 6092 | //else printf(" 1x1 screen\n"); |
| 5606 | 6093 | |
| 5607 | 6094 | |
| 5608 | 6095 | } |
| 5609 | 6096 | |
| 5610 | 6097 | if (ACCESSING_BITS_8_15) |
| 5611 | 6098 | { |
| 5612 | | if (data&0xff00) printf(" unused bits (MSB) set in stampsize!\n"); |
| 6099 | //if (data&0xff00) printf(" unused bits (MSB) set in stampsize!\n"); |
| 5613 | 6100 | } |
| 5614 | 6101 | } |
| 5615 | 6102 | |
| r10382 | r10383 | |
| 5724 | 6211 | segacd_conversion_active = 1; |
| 5725 | 6212 | |
| 5726 | 6213 | // todo: proper time calculation |
| 5727 | | segacd_gfx_conversion_timer->adjust(attotime::from_hz(500)); |
| 6214 | segacd_gfx_conversion_timer->adjust(attotime::from_nsec(5000000)); |
| 5728 | 6215 | |
| 5729 | 6216 | |
| 6217 | |
| 5730 | 6218 | int line; |
| 5731 | 6219 | //bitmap_t *srcbitmap = tilemap_get_pixmap(segacd_stampmap[segacd_get_active_stampmap_tilemap()]); |
| 5732 | 6220 | bitmap_t *srcbitmap = 0; |
| r10382 | r10383 | |
| 5831 | 6319 | static WRITE16_HANDLER( segacd_imagebuffer_offset_w ) |
| 5832 | 6320 | { |
| 5833 | 6321 | COMBINE_DATA(&segacd_imagebuffer_offset); |
| 5834 | | printf("segacd_imagebuffer_offset_w %04x\n", segacd_imagebuffer_offset); |
| 6322 | // printf("segacd_imagebuffer_offset_w %04x\n", segacd_imagebuffer_offset); |
| 5835 | 6323 | } |
| 5836 | 6324 | |
| 5837 | 6325 | static READ16_HANDLER( segacd_imagebuffer_vcell_size_r ) |
| r10382 | r10383 | |
| 5877 | 6365 | else |
| 5878 | 6366 | segacd_irq3_timer->adjust(attotime::never); |
| 5879 | 6367 | |
| 5880 | | printf("segacd_irq3timer_w %02x\n", segacd_irq3_timer_reg); |
| 6368 | //printf("segacd_irq3timer_w %02x\n", segacd_irq3_timer_reg); |
| 5881 | 6369 | } |
| 5882 | 6370 | } |
| 5883 | 6371 | |
| 6372 | |
| 6373 | |
| 5884 | 6374 | static TIMER_CALLBACK( segacd_irq3_timer_callback ) |
| 5885 | 6375 | { |
| 5886 | 6376 | if (segacd_irq_mask & 0x08) |
| r10382 | r10383 | |
| 5890 | 6380 | } |
| 5891 | 6381 | |
| 5892 | 6382 | |
| 6383 | WRITE16_HANDLER( segacd_stopwatch_timer_w ) |
| 6384 | { |
| 6385 | |
| 6386 | } |
| 6387 | |
| 6388 | READ16_HANDLER( segacd_stopwatch_timer_r ) |
| 6389 | { |
| 6390 | return space->machine->rand(); |
| 6391 | } |
| 6392 | |
| 6393 | READ16_HANDLER( cdc_dmaaddr_r ) |
| 6394 | { |
| 6395 | return CDC_DMA_ADDR; |
| 6396 | } |
| 6397 | |
| 6398 | WRITE16_HANDLER( cdc_dmaaddr_w ) |
| 6399 | { |
| 6400 | COMBINE_DATA(&CDC_DMA_ADDR); |
| 6401 | } |
| 6402 | |
| 5893 | 6403 | static ADDRESS_MAP_START( segacd_map, ADDRESS_SPACE_PROGRAM, 16 ) |
| 5894 | 6404 | AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_BASE(&segacd_4meg_prgram) |
| 5895 | 6405 | |
| r10382 | r10383 | |
| 5907 | 6417 | |
| 5908 | 6418 | AM_RANGE(0xff8004 ,0xff8005) AM_READWRITE(segacd_cdc_mode_address_r, segacd_cdc_mode_address_w) |
| 5909 | 6419 | AM_RANGE(0xff8006 ,0xff8007) AM_READWRITE(segacd_cdc_data_r, segacd_cdc_data_w) |
| 5910 | | // AM_RANGE(0xff8008, 0xff8009) // CDC Host Data |
| 5911 | | // AM_RANGE(0xff800a, 0xff800b) // CDC DMA Address |
| 5912 | | // AM_RANGE(0xff800c, 0xff800d) // Stopwatch timer |
| 6420 | AM_RANGE(0xff8008, 0xff8009) AM_READ(cdc_data_sub_r) |
| 6421 | AM_RANGE(0xff800a, 0xff800b) AM_READWRITE(cdc_dmaaddr_r,cdc_dmaaddr_w) // CDC DMA Address |
| 6422 | AM_RANGE(0xff800c, 0xff800d) AM_READWRITE(segacd_stopwatch_timer_r, segacd_stopwatch_timer_w)// Stopwatch timer |
| 5913 | 6423 | AM_RANGE(0xff800e ,0xff800f) AM_READWRITE(segacd_comms_flags_r, segacd_comms_flags_subcpu_w) |
| 5914 | 6424 | AM_RANGE(0xff8010 ,0xff801f) AM_READWRITE(segacd_comms_sub_part1_r, segacd_comms_sub_part1_w) |
| 5915 | 6425 | AM_RANGE(0xff8020 ,0xff802f) AM_READWRITE(segacd_comms_sub_part2_r, segacd_comms_sub_part2_w) |
| r10382 | r10383 | |
| 5966 | 6476 | * |
| 5967 | 6477 | * Depending on GPO bits in status register, PM0, PM1, PM2 and XST can act as |
| 5968 | 6478 | * external status registers, os as programmable memory registers. PM4 always |
| 5969 | | * acts as PM register (independend on GPO bits). |
| 6479 | * acts as PM register (independent on GPO bits). |
| 5970 | 6480 | */ |
| 5971 | 6481 | |
| 5972 | 6482 | #include "cpu/ssp1601/ssp1601.h" |
| r10382 | r10383 | |
| 8231 | 8741 | if (genesis_scanline_counter>=0 && genesis_scanline_counter<megadrive_visible_scanlines) |
| 8232 | 8742 | { |
| 8233 | 8743 | genesis_render_scanline(timer.machine, genesis_scanline_counter); |
| 8744 | |
| 8745 | // put this one a timer instead? |
| 8746 | #define RATE 256 |
| 8747 | if (sega_cd_connected) |
| 8748 | CDC_Do_DMA(timer.machine, RATE); |
| 8234 | 8749 | } |
| 8235 | 8750 | } |
| 8236 | 8751 | |
| r10382 | r10383 | |
| 8889 | 9404 | MCFG_SOUND_ROUTE( 0, "lspeaker", 0.25 ) |
| 8890 | 9405 | MCFG_SOUND_ROUTE( 1, "rspeaker", 0.25 ) |
| 8891 | 9406 | |
| 8892 | | #ifdef MESS |
| 9407 | MCFG_QUANTUM_PERFECT_CPU("maincpu") |
| 9408 | |
| 9409 | |
| 9410 | MACHINE_CONFIG_END |
| 9411 | |
| 9412 | /* Different Softlists for different regions (for now at least) */ |
| 9413 | MACHINE_CONFIG_DERIVED( genesis_scd_scd, genesis_scd ) |
| 8893 | 9414 | MCFG_CDROM_ADD( "cdrom" ) |
| 8894 | | #endif |
| 9415 | MCFG_CDROM_INTERFACE("scd_cdrom") |
| 9416 | MCFG_SOFTWARE_LIST_ADD("cd_list","segacd") |
| 8895 | 9417 | MACHINE_CONFIG_END |
| 8896 | 9418 | |
| 9419 | MACHINE_CONFIG_DERIVED( genesis_scd_mcd, genesis_scd ) |
| 9420 | MCFG_CDROM_ADD( "cdrom" ) |
| 9421 | MCFG_CDROM_INTERFACE("scd_cdrom") |
| 9422 | MCFG_SOFTWARE_LIST_ADD("cd_list","megacd") |
| 9423 | MACHINE_CONFIG_END |
| 9424 | |
| 9425 | MACHINE_CONFIG_DERIVED( genesis_scd_mcdj, genesis_scd ) |
| 9426 | MCFG_CDROM_ADD( "cdrom" ) |
| 9427 | MCFG_CDROM_INTERFACE("scd_cdrom") |
| 9428 | MCFG_SOFTWARE_LIST_ADD("cd_list","megacdj") |
| 9429 | MACHINE_CONFIG_END |
| 9430 | |
| 8897 | 9431 | MACHINE_CONFIG_DERIVED( genesis_32x_scd, genesis_32x ) |
| 8898 | 9432 | |
| 8899 | 9433 | MCFG_CPU_ADD("segacd_68k", M68000, SEGACD_CLOCK ) /* 12.5 MHz */ |
| r10382 | r10383 | |
| 8907 | 9441 | MCFG_SOUND_ROUTE( 0, "lspeaker", 0.25 ) |
| 8908 | 9442 | MCFG_SOUND_ROUTE( 1, "rspeaker", 0.25 ) |
| 8909 | 9443 | |
| 8910 | | #ifdef MESS |
| 8911 | 9444 | MCFG_CDROM_ADD( "cdrom" ) |
| 8912 | | #endif |
| 8913 | 9445 | MACHINE_CONFIG_END |
| 8914 | 9446 | |
| 8915 | 9447 | |