src/mess/drivers/cdi.c
| r6097 | r6098 | |
| 447 | 447 | return scc68070_regs.timers.timer0; |
| 448 | 448 | case 0x2026/2: |
| 449 | 449 | verboselog(space->machine, 2, "scc68070_periphs_r: Timer 1: %04x & %04x\n", scc68070_regs.timers.timer1, mem_mask); |
| 450 | printf( "Timer 1 read\n" ); |
| 450 | 451 | return scc68070_regs.timers.timer1; |
| 451 | 452 | case 0x2028/2: |
| 452 | 453 | verboselog(space->machine, 2, "scc68070_periphs_r: Timer 2: %04x & %04x\n", scc68070_regs.timers.timer2, mem_mask); |
| 454 | printf( "Timer 2 read\n" ); |
| 453 | 455 | return scc68070_regs.timers.timer2; |
| 454 | 456 | |
| 455 | 457 | // PICR1: 80002045 |
| r6097 | r6098 | |
| 717 | 719 | case 0x2026/2: |
| 718 | 720 | verboselog(space->machine, 2, "scc68070_periphs_w: Timer 1: %04x & %04x\n", data, mem_mask); |
| 719 | 721 | COMBINE_DATA(&scc68070_regs.timers.timer1); |
| 722 | printf( "Timer 1 write: %04x\n", data ); |
| 720 | 723 | break; |
| 721 | 724 | case 0x2028/2: |
| 722 | 725 | verboselog(space->machine, 2, "scc68070_periphs_w: Timer 2: %04x & %04x\n", data, mem_mask); |
| 723 | 726 | COMBINE_DATA(&scc68070_regs.timers.timer2); |
| 727 | printf( "Timer 2 write: %04x\n", data ); |
| 724 | 728 | break; |
| 725 | 729 | |
| 726 | 730 | // PICR1: 80002045 |
| r6097 | r6098 | |
| 942 | 946 | |
| 943 | 947 | static cdic_regs_t cdic_regs; |
| 944 | 948 | |
| 949 | const INT32 cdic_adpcm_filter_coef[5][2] = |
| 950 | { |
| 951 | { 0,0 }, |
| 952 | { 60,0 }, |
| 953 | { 115,-52 }, |
| 954 | { 98,-55 }, |
| 955 | { 122,-60 }, |
| 956 | }; |
| 957 | |
| 958 | int cdic_xa_last[4] = { 0, 0, 0, 0 }; |
| 959 | |
| 960 | INLINE INT16 clamp(INT16 in) |
| 961 | { |
| 962 | return in; |
| 963 | } |
| 964 | |
| 965 | static void cdic_decode_xa_mono(const unsigned char *xa, unsigned char *ptr) |
| 966 | { |
| 967 | signed short *dp=(signed short *)ptr; |
| 968 | |
| 969 | int l0=cdic_xa_last[0], |
| 970 | l1=cdic_xa_last[1]; |
| 971 | int b=0; |
| 972 | int s=0; |
| 973 | |
| 974 | for (b=0; b<18; b++) |
| 975 | { |
| 976 | for (s=0; s<4; s++) |
| 977 | { |
| 978 | unsigned char flags=xa[(4+(s<<1))^1], |
| 979 | shift=flags&0xf, |
| 980 | filter=flags>>4; |
| 981 | int f0=cdic_adpcm_filter_coef[filter][0], |
| 982 | f1=cdic_adpcm_filter_coef[filter][1]; |
| 983 | int i=0; |
| 984 | |
| 985 | for (i=0; i<28; i++) |
| 986 | { |
| 987 | short d=(xa[(16+(i<<2)+s)^1]&0xf)<<12; |
| 988 | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 989 | *dp++=d; |
| 990 | l1=l0; |
| 991 | l0=d; |
| 992 | } |
| 993 | |
| 994 | flags=xa[(5+(s<<1))^1]; |
| 995 | shift=flags&0xf; |
| 996 | filter=flags>>4; |
| 997 | f0=cdic_adpcm_filter_coef[filter][0]; |
| 998 | f1=cdic_adpcm_filter_coef[filter][1]; |
| 999 | |
| 1000 | for (i=0; i<28; i++) |
| 1001 | { |
| 1002 | short d=(xa[(16+(i<<2)+s)^1]>>4)<<12; |
| 1003 | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1004 | *dp++=d; |
| 1005 | l1=l0; |
| 1006 | l0=d; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | xa+=128; |
| 1011 | } |
| 1012 | |
| 1013 | cdic_xa_last[0]=l0; |
| 1014 | cdic_xa_last[1]=l1; |
| 1015 | } |
| 1016 | |
| 1017 | // |
| 1018 | // |
| 1019 | // |
| 1020 | |
| 1021 | static void cdic_decode_xa_stereo(const unsigned char *xa, unsigned char *ptr) |
| 1022 | { |
| 1023 | signed short *dp=(signed short *)ptr; |
| 1024 | |
| 1025 | int l0=cdic_xa_last[0], |
| 1026 | l1=cdic_xa_last[1], |
| 1027 | l2=cdic_xa_last[2], |
| 1028 | l3=cdic_xa_last[3]; |
| 1029 | int b=0; |
| 1030 | int s=0; |
| 1031 | |
| 1032 | for (b=0; b<18; b++) |
| 1033 | { |
| 1034 | for (s=0; s<4; s++) |
| 1035 | { |
| 1036 | unsigned char flags0=xa[(4+(s<<1))^1], |
| 1037 | shift0=flags0&0xf, |
| 1038 | filter0=flags0>>4, |
| 1039 | flags1=xa[(5+(s<<1))^1], |
| 1040 | shift1=flags1&0xf, |
| 1041 | filter1=flags1>>4; |
| 1042 | |
| 1043 | int f0=cdic_adpcm_filter_coef[filter0][0], |
| 1044 | f1=cdic_adpcm_filter_coef[filter0][1], |
| 1045 | f2=cdic_adpcm_filter_coef[filter1][0], |
| 1046 | f3=cdic_adpcm_filter_coef[filter1][1]; |
| 1047 | int i=0; |
| 1048 | |
| 1049 | for (i=0; i<28; i++) |
| 1050 | { |
| 1051 | short d=xa[(16+(i<<2)+s)^1], |
| 1052 | d0=(d&0xf)<<12, |
| 1053 | d1=(d>>4)<<12; |
| 1054 | d0=clamp((int)(d0>>shift0)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1055 | *dp++=d0; |
| 1056 | l1=l0; |
| 1057 | l0=d0; |
| 1058 | |
| 1059 | d1=clamp((int)(d1>>shift1)+(((l2*f2)+(l3*f3)+32)>>6)); |
| 1060 | *dp++=d1; |
| 1061 | l3=l2; |
| 1062 | l2=d1; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | xa+=128; |
| 1067 | } |
| 1068 | |
| 1069 | cdic_xa_last[0]=l0; |
| 1070 | cdic_xa_last[1]=l1; |
| 1071 | cdic_xa_last[2]=l2; |
| 1072 | cdic_xa_last[3]=l3; |
| 1073 | } |
| 1074 | |
| 1075 | static void cdic_decode_audio_sector(const unsigned char *xa) |
| 1076 | { |
| 1077 | // Get XA format from sector header |
| 1078 | |
| 1079 | const unsigned char *hdr = xa + 4; |
| 1080 | float freq; |
| 1081 | int channels; |
| 1082 | UINT8 samples[18*28*8*2]; |
| 1083 | //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 1084 | |
| 1085 | //fseek(temp_adpcm, 0, SEEK_END); |
| 1086 | switch(hdr[2] & 0x3f) // ignore emphasis and reserved bits |
| 1087 | { |
| 1088 | case 0: |
| 1089 | channels=1; |
| 1090 | freq=37800.0f; //18900.0f; |
| 1091 | break; |
| 1092 | |
| 1093 | case 1: |
| 1094 | channels=2; |
| 1095 | freq=37800.0f; |
| 1096 | break; |
| 1097 | |
| 1098 | case 4: |
| 1099 | channels=1; |
| 1100 | freq=18900.0f; ///2.0f; |
| 1101 | break; |
| 1102 | |
| 1103 | case 5: |
| 1104 | channels=2; |
| 1105 | freq=18900.0f; //37800.0f/2.0f; |
| 1106 | break; |
| 1107 | |
| 1108 | default: |
| 1109 | printf("play_xa: unhandled xa mode %08x\n",hdr[2]); |
| 1110 | return; |
| 1111 | } |
| 1112 | |
| 1113 | switch(channels) |
| 1114 | { |
| 1115 | case 1: |
| 1116 | cdic_decode_xa_mono(xa, samples); |
| 1117 | break; |
| 1118 | case 2: |
| 1119 | cdic_decode_xa_stereo(xa, samples); |
| 1120 | break; |
| 1121 | } |
| 1122 | |
| 1123 | //fwrite(samples, 18*28*8*2, 1, temp_adpcm); |
| 1124 | //fclose(temp_adpcm); |
| 1125 | } |
| 1126 | |
| 945 | 1127 | static TIMER_CALLBACK( cdic_trigger_readback_int ) |
| 946 | 1128 | { |
| 947 | 1129 | switch(cdic_regs.command) |
| r6097 | r6098 | |
| 1033 | 1215 | { |
| 1034 | 1216 | //if(!(buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_TRIG)) |
| 1035 | 1217 | //{ |
| 1036 | | // verboselog(machine, 0, "Audio sector, ignored\n" ); |
| 1218 | verboselog(machine, 0, "Audio sector\n" ); |
| 1037 | 1219 | //} |
| 1038 | 1220 | //else |
| 1039 | 1221 | //{ |
| 1222 | cdic_decode_audio_sector((UINT8*)cdram + ((cdic_regs.data_buffer & 5) * 0xa00 + 4)); |
| 1040 | 1223 | // Ignore the audio sector for now. |
| 1041 | 1224 | cdic_regs.x_buffer |= 0x8000; |
| 1042 | 1225 | |
| r6097 | r6098 | |
| 1225 | 1408 | break; |
| 1226 | 1409 | case 0x29: // Read Mode 1 |
| 1227 | 1410 | case 0x2a: // Read Mode 2 |
| 1411 | cdic_xa_last[0] = cdic_xa_last[1] = cdic_xa_last[2] = cdic_xa_last[3] = 0; |
| 1228 | 1412 | timer_adjust_oneshot(cdic_regs.interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 1229 | 1413 | cdic_regs.data_buffer &= 0xfffe; |
| 1230 | 1414 | break; |