trunk/src/mame/drivers/multigam.c
| r26012 | r26013 | |
| 116 | 116 | public: |
| 117 | 117 | multigam_state(const machine_config &mconfig, device_type type, const char *tag) |
| 118 | 118 | : driver_device(mconfig, type, tag), |
| 119 | | m_maincpu(*this, "maincpu") { } |
| 120 | | |
| 119 | m_maincpu(*this, "maincpu"), |
| 120 | m_nesapu(*this, "nesapu"), |
| 121 | m_ppu(*this, "ppu") { } |
| 122 | |
| 123 | required_device<cpu_device> m_maincpu; |
| 124 | required_device<nesapu_device> m_nesapu; |
| 125 | required_device<ppu2c0x_device> m_ppu; |
| 126 | |
| 121 | 127 | UINT8* m_nt_ram; |
| 122 | 128 | UINT8* m_vram; |
| 123 | 129 | UINT8* m_nt_page[4]; |
| r26012 | r26013 | |
| 195 | 201 | void multigm3_decrypt(UINT8* mem, int memsize, const UINT8* decode_nibble); |
| 196 | 202 | void multigam3_mmc3_scanline_cb(int scanline, int vblank, int blanked); |
| 197 | 203 | void ppu_irq(int *ppu_regs); |
| 198 | | required_device<cpu_device> m_maincpu; |
| 199 | 204 | }; |
| 200 | 205 | |
| 201 | 206 | |
| r26012 | r26013 | |
| 286 | 291 | WRITE8_MEMBER(multigam_state::sprite_dma_w) |
| 287 | 292 | { |
| 288 | 293 | int source = (data & 7); |
| 289 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 290 | | ppu->spriteram_dma(space, source); |
| 294 | m_ppu->spriteram_dma(space, source); |
| 291 | 295 | } |
| 292 | 296 | |
| 293 | 297 | READ8_MEMBER(multigam_state::psg_4015_r) |
| 294 | 298 | { |
| 295 | | device_t *device = machine().device("nes"); |
| 296 | | return nes_psg_r(device, space, 0x15); |
| 299 | return m_nesapu->read(space, 0x15); |
| 297 | 300 | } |
| 298 | 301 | |
| 299 | 302 | WRITE8_MEMBER(multigam_state::psg_4015_w) |
| 300 | 303 | { |
| 301 | | device_t *device = machine().device("nes"); |
| 302 | | nes_psg_w(device, space, 0x15, data); |
| 304 | m_nesapu->write(space, 0x15, data); |
| 303 | 305 | } |
| 304 | 306 | |
| 305 | 307 | WRITE8_MEMBER(multigam_state::psg_4017_w) |
| 306 | 308 | { |
| 307 | | device_t *device = machine().device("nes"); |
| 308 | | nes_psg_w(device, space, 0x17, data); |
| 309 | m_nesapu->write(space, 0x17, data); |
| 309 | 310 | } |
| 310 | 311 | |
| 311 | 312 | /****************************************************** |
| r26012 | r26013 | |
| 408 | 409 | AM_RANGE(0x0000, 0x07ff) AM_RAM /* NES RAM */ |
| 409 | 410 | AM_RANGE(0x0800, 0x0fff) AM_RAM /* additional RAM */ |
| 410 | 411 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_device, read, write) |
| 411 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 412 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu", nesapu_device, read, write) /* PSG primary registers */ |
| 412 | 413 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_w) |
| 413 | 414 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| 414 | 415 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(multigam_IN0_r, multigam_IN0_w) /* IN0 - input port 1 */ |
| r26012 | r26013 | |
| 428 | 429 | AM_RANGE(0x3000, 0x3000) AM_WRITE(multigam_switch_prg_rom) |
| 429 | 430 | AM_RANGE(0x3fff, 0x3fff) AM_WRITE(multigam_switch_gfx_rom) |
| 430 | 431 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_device, read, write) |
| 431 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 432 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu", nesapu_device, read, write) /* PSG primary registers */ |
| 432 | 433 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_w) |
| 433 | 434 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| 434 | 435 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(multigam_IN0_r, multigam_IN0_w) /* IN0 - input port 1 */ |
| r26012 | r26013 | |
| 461 | 462 | |
| 462 | 463 | WRITE8_MEMBER(multigam_state::multigam3_mmc3_rom_switch_w) |
| 463 | 464 | { |
| 464 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 465 | | |
| 466 | 465 | /* basically, a MMC3 mapper from the nes */ |
| 467 | 466 | int bankmask = m_multigam3_mmc3_prg_size == 0x40000 ? 0x1f : 0x0f; |
| 468 | 467 | |
| r26012 | r26013 | |
| 599 | 598 | |
| 600 | 599 | case 0x6000: /* disable irqs */ |
| 601 | 600 | machine().device("maincpu")->execute().set_input_line(M6502_IRQ_LINE, CLEAR_LINE); |
| 602 | | ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 601 | m_ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 603 | 602 | break; |
| 604 | 603 | |
| 605 | 604 | case 0x6001: /* enable irqs */ |
| 606 | | ppu->set_scanline_callback(ppu2c0x_scanline_delegate(FUNC(multigam_state::multigam3_mmc3_scanline_cb),this)); |
| 605 | m_ppu->set_scanline_callback(ppu2c0x_scanline_delegate(FUNC(multigam_state::multigam3_mmc3_scanline_cb),this)); |
| 607 | 606 | break; |
| 608 | 607 | } |
| 609 | 608 | } |
| r26012 | r26013 | |
| 693 | 692 | AM_RANGE(0x0000, 0x07ff) AM_RAM /* NES RAM */ |
| 694 | 693 | AM_RANGE(0x0800, 0x0fff) AM_RAM /* additional RAM */ |
| 695 | 694 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_device, read, write) |
| 696 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 695 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu", nesapu_device, read, write) /* PSG primary registers */ |
| 697 | 696 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_w) |
| 698 | 697 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| 699 | 698 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(multigam_IN0_r, multigam_IN0_w) /* IN0 - input port 1 */ |
| r26012 | r26013 | |
| 724 | 723 | |
| 725 | 724 | void multigam_state::multigam_init_mapper02(UINT8* prg_base, int prg_size) |
| 726 | 725 | { |
| 727 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 728 | 726 | UINT8* mem = memregion("maincpu")->base(); |
| 729 | 727 | memcpy(mem + 0x8000, prg_base + prg_size - 0x8000, 0x8000); |
| 730 | 728 | m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8_delegate(FUNC(multigam_state::multigam3_mapper02_rom_switch_w),this)); |
| 731 | 729 | |
| 732 | 730 | m_mapper02_prg_base = prg_base; |
| 733 | 731 | m_mapper02_prg_size = prg_size; |
| 734 | | ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 732 | m_ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 735 | 733 | } |
| 736 | 734 | |
| 737 | 735 | /****************************************************** |
| r26012 | r26013 | |
| 877 | 875 | void multigam_state::multigam_init_mmc1(UINT8 *prg_base, int prg_size, int chr_bank_base) |
| 878 | 876 | { |
| 879 | 877 | UINT8* dst = memregion("maincpu")->base(); |
| 880 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 881 | | |
| 878 | |
| 882 | 879 | memcpy(&dst[0x8000], prg_base + (prg_size - 0x8000), 0x8000); |
| 883 | 880 | |
| 884 | 881 | m_maincpu->space(AS_PROGRAM).install_write_handler(0x8000, 0xffff, write8_delegate(FUNC(multigam_state::mmc1_rom_switch_w),this)); |
| r26012 | r26013 | |
| 889 | 886 | m_mmc1_prg_size = prg_size; |
| 890 | 887 | m_mmc1_chr_bank_base = chr_bank_base; |
| 891 | 888 | |
| 892 | | ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 889 | m_ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 893 | 890 | }; |
| 894 | 891 | |
| 895 | 892 | |
| r26012 | r26013 | |
| 917 | 914 | |
| 918 | 915 | void multigam_state::supergm3_set_bank() |
| 919 | 916 | { |
| 920 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 921 | 917 | UINT8* mem = memregion("maincpu")->base(); |
| 922 | 918 | |
| 923 | 919 | // video bank |
| r26012 | r26013 | |
| 925 | 921 | m_supergm3_chr_bank == 0x40 ) |
| 926 | 922 | { |
| 927 | 923 | // VRAM |
| 928 | | ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "bank1"); |
| 929 | | ppu->space(AS_PROGRAM).install_write_bank(0x0000, 0x1fff, "bank1"); |
| 924 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "bank1"); |
| 925 | m_ppu->space(AS_PROGRAM).install_write_bank(0x0000, 0x1fff, "bank1"); |
| 930 | 926 | membank("bank1")->set_base(m_vram); |
| 931 | 927 | |
| 932 | 928 | if (m_supergm3_chr_bank == 0x40) |
| r26012 | r26013 | |
| 934 | 930 | } |
| 935 | 931 | else |
| 936 | 932 | { |
| 937 | | ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x03ff, "bank2"); |
| 938 | | ppu->space(AS_PROGRAM).install_read_bank(0x0400, 0x07ff, "bank3"); |
| 939 | | ppu->space(AS_PROGRAM).install_read_bank(0x0800, 0x0bff, "bank4"); |
| 940 | | ppu->space(AS_PROGRAM).install_read_bank(0x0c00, 0x0fff, "bank5"); |
| 941 | | ppu->space(AS_PROGRAM).install_read_bank(0x1000, 0x13ff, "bank6"); |
| 942 | | ppu->space(AS_PROGRAM).install_read_bank(0x1400, 0x17ff, "bank7"); |
| 943 | | ppu->space(AS_PROGRAM).install_read_bank(0x1800, 0x1bff, "bank8"); |
| 944 | | ppu->space(AS_PROGRAM).install_read_bank(0x1c00, 0x1fff, "bank9"); |
| 945 | | ppu->space(AS_PROGRAM).unmap_write(0x0000, 0x1fff); |
| 933 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x03ff, "bank2"); |
| 934 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0400, 0x07ff, "bank3"); |
| 935 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0800, 0x0bff, "bank4"); |
| 936 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0c00, 0x0fff, "bank5"); |
| 937 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1000, 0x13ff, "bank6"); |
| 938 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1400, 0x17ff, "bank7"); |
| 939 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1800, 0x1bff, "bank8"); |
| 940 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1c00, 0x1fff, "bank9"); |
| 941 | m_ppu->space(AS_PROGRAM).unmap_write(0x0000, 0x1fff); |
| 946 | 942 | |
| 947 | 943 | set_videorom_bank(0, 8, 0, 8); |
| 948 | 944 | } |
| r26012 | r26013 | |
| 953 | 949 | // title screen |
| 954 | 950 | memcpy(mem + 0x8000, mem + 0x18000, 0x8000); |
| 955 | 951 | membank("bank10")->set_base(mem + 0x6000); |
| 956 | | ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 952 | m_ppu->set_scanline_callback(ppu2c0x_scanline_delegate()); |
| 957 | 953 | } |
| 958 | 954 | else if ((m_supergm3_prg_bank & 0x40) == 0) |
| 959 | 955 | { |
| r26012 | r26013 | |
| 998 | 994 | AM_RANGE(0x0000, 0x07ff) AM_RAM /* NES RAM */ |
| 999 | 995 | AM_RANGE(0x0800, 0x0fff) AM_RAM /* additional RAM */ |
| 1000 | 996 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_device, read, write) |
| 1001 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 997 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu", nesapu_device, read, write) /* PSG primary registers */ |
| 1002 | 998 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_w) |
| 1003 | 999 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| 1004 | 1000 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(multigam_IN0_r, multigam_IN0_w) /* IN0 - input port 1 */ |
| r26012 | r26013 | |
| 1144 | 1140 | |
| 1145 | 1141 | *******************************************************/ |
| 1146 | 1142 | |
| 1147 | | static const nes_interface multigam_interface_1 = |
| 1143 | static const nesapu_interface multigam_interface_1 = |
| 1148 | 1144 | { |
| 1149 | 1145 | "maincpu" |
| 1150 | 1146 | }; |
| 1151 | 1147 | |
| 1152 | 1148 | void multigam_state::palette_init() |
| 1153 | 1149 | { |
| 1154 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 1155 | | ppu->init_palette(machine(), 0); |
| 1150 | m_ppu->init_palette(machine(), 0); |
| 1156 | 1151 | } |
| 1157 | 1152 | |
| 1158 | 1153 | void multigam_state::ppu_irq(int *ppu_regs) |
| r26012 | r26013 | |
| 1176 | 1171 | UINT32 multigam_state::screen_update_multigam(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 1177 | 1172 | { |
| 1178 | 1173 | /* render the ppu */ |
| 1179 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 1180 | | ppu->render(bitmap, 0, 0, 0, 0); |
| 1174 | m_ppu->render(bitmap, 0, 0, 0, 0); |
| 1181 | 1175 | return 0; |
| 1182 | 1176 | } |
| 1183 | 1177 | |
| r26012 | r26013 | |
| 1210 | 1204 | m_nt_page[2] = m_nt_ram + 0x800; |
| 1211 | 1205 | m_nt_page[3] = m_nt_ram + 0xc00; |
| 1212 | 1206 | |
| 1213 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(multigam_state::multigam_nt_r),this), write8_delegate(FUNC(multigam_state::multigam_nt_w),this)); |
| 1214 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "bank1"); |
| 1207 | m_ppu->space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(multigam_state::multigam_nt_r),this), write8_delegate(FUNC(multigam_state::multigam_nt_w),this)); |
| 1208 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "bank1"); |
| 1215 | 1209 | membank("bank1")->set_base(memregion("gfx1")->base()); |
| 1216 | 1210 | } |
| 1217 | 1211 | |
| r26012 | r26013 | |
| 1223 | 1217 | m_nt_page[2] = m_nt_ram + 0x800; |
| 1224 | 1218 | m_nt_page[3] = m_nt_ram + 0xc00; |
| 1225 | 1219 | |
| 1226 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(multigam_state::multigam_nt_r),this), write8_delegate(FUNC(multigam_state::multigam_nt_w),this)); |
| 1220 | m_ppu->space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(multigam_state::multigam_nt_r),this), write8_delegate(FUNC(multigam_state::multigam_nt_w),this)); |
| 1227 | 1221 | |
| 1228 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x03ff, "bank2"); |
| 1229 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0400, 0x07ff, "bank3"); |
| 1230 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0800, 0x0bff, "bank4"); |
| 1231 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0c00, 0x0fff, "bank5"); |
| 1232 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x1000, 0x13ff, "bank6"); |
| 1233 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x1400, 0x17ff, "bank7"); |
| 1234 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x1800, 0x1bff, "bank8"); |
| 1235 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x1c00, 0x1fff, "bank9"); |
| 1222 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x03ff, "bank2"); |
| 1223 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0400, 0x07ff, "bank3"); |
| 1224 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0800, 0x0bff, "bank4"); |
| 1225 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0c00, 0x0fff, "bank5"); |
| 1226 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1000, 0x13ff, "bank6"); |
| 1227 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1400, 0x17ff, "bank7"); |
| 1228 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1800, 0x1bff, "bank8"); |
| 1229 | m_ppu->space(AS_PROGRAM).install_read_bank(0x1c00, 0x1fff, "bank9"); |
| 1236 | 1230 | |
| 1237 | 1231 | set_videorom_bank(0, 8, 0, 8); |
| 1238 | 1232 | }; |
| r26012 | r26013 | |
| 1245 | 1239 | m_nt_page[2] = m_nt_ram + 0x800; |
| 1246 | 1240 | m_nt_page[3] = m_nt_ram + 0xc00; |
| 1247 | 1241 | |
| 1248 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(multigam_state::multigam_nt_r),this), write8_delegate(FUNC(multigam_state::multigam_nt_w),this)); |
| 1242 | m_ppu->space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(multigam_state::multigam_nt_r),this), write8_delegate(FUNC(multigam_state::multigam_nt_w),this)); |
| 1249 | 1243 | |
| 1250 | 1244 | m_vram = auto_alloc_array(machine(), UINT8, 0x2000); |
| 1251 | 1245 | m_multigmc_mmc3_6000_ram = auto_alloc_array(machine(), UINT8, 0x2000); |
| r26012 | r26013 | |
| 1274 | 1268 | /* sound hardware */ |
| 1275 | 1269 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 1276 | 1270 | |
| 1277 | | MCFG_SOUND_ADD("nes", NES, N2A03_DEFAULTCLOCK) |
| 1271 | MCFG_SOUND_ADD("nesapu", NES_APU, N2A03_DEFAULTCLOCK) |
| 1278 | 1272 | MCFG_SOUND_CONFIG(multigam_interface_1) |
| 1279 | 1273 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 1280 | 1274 | |
trunk/src/mame/drivers/famibox.c
| r26012 | r26013 | |
| 71 | 71 | public: |
| 72 | 72 | famibox_state(const machine_config &mconfig, device_type type, const char *tag) |
| 73 | 73 | : driver_device(mconfig, type, tag), |
| 74 | | m_maincpu(*this, "maincpu") { } |
| 74 | m_maincpu(*this, "maincpu"), |
| 75 | m_nesapu(*this, "nesapu"), |
| 76 | m_ppu(*this, "ppu") { } |
| 75 | 77 | |
| 78 | |
| 79 | required_device<cpu_device> m_maincpu; |
| 80 | required_device<nesapu_device> m_nesapu; |
| 81 | required_device<ppu2c0x_device> m_ppu; |
| 82 | |
| 76 | 83 | UINT8* m_nt_ram; |
| 77 | 84 | UINT8* m_nt_page[4]; |
| 78 | 85 | |
| r26012 | r26013 | |
| 117 | 124 | void famicombox_bankswitch(UINT8 bank); |
| 118 | 125 | void famicombox_reset(); |
| 119 | 126 | void ppu_irq(int *ppu_regs); |
| 120 | | required_device<cpu_device> m_maincpu; |
| 121 | 127 | }; |
| 122 | 128 | |
| 123 | 129 | /****************************************************** |
| r26012 | r26013 | |
| 181 | 187 | |
| 182 | 188 | WRITE8_MEMBER(famibox_state::sprite_dma_w) |
| 183 | 189 | { |
| 184 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 185 | 190 | int source = (data & 7); |
| 186 | | ppu->spriteram_dma(space, source); |
| 191 | m_ppu->spriteram_dma(space, source); |
| 187 | 192 | } |
| 188 | 193 | |
| 189 | 194 | READ8_MEMBER(famibox_state::psg_4015_r) |
| 190 | 195 | { |
| 191 | | device_t *device = machine().device("nes"); |
| 192 | | return nes_psg_r(device, space, 0x15); |
| 196 | return m_nesapu->read(space, 0x15); |
| 193 | 197 | } |
| 194 | 198 | |
| 195 | 199 | WRITE8_MEMBER(famibox_state::psg_4015_w) |
| 196 | 200 | { |
| 197 | | device_t *device = machine().device("nes"); |
| 198 | | nes_psg_w(device, space, 0x15, data); |
| 201 | m_nesapu->write(space, 0x15, data); |
| 199 | 202 | } |
| 200 | 203 | |
| 201 | 204 | WRITE8_MEMBER(famibox_state::psg_4017_w) |
| 202 | 205 | { |
| 203 | | device_t *device = machine().device("nes"); |
| 204 | | nes_psg_w(device, space, 0x17, data); |
| 206 | m_nesapu->write(space, 0x17, data); |
| 205 | 207 | } |
| 206 | 208 | |
| 207 | 209 | /****************************************************** |
| r26012 | r26013 | |
| 393 | 395 | static ADDRESS_MAP_START( famibox_map, AS_PROGRAM, 8, famibox_state ) |
| 394 | 396 | AM_RANGE(0x0000, 0x1fff) AM_RAM |
| 395 | 397 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_device, read, write) |
| 396 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 398 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu", nesapu_device, read, write) /* PSG primary registers */ |
| 397 | 399 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_w) |
| 398 | 400 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| 399 | 401 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(famibox_IN0_r, famibox_IN0_w) /* IN0 - input port 1 */ |
| r26012 | r26013 | |
| 509 | 511 | |
| 510 | 512 | *******************************************************/ |
| 511 | 513 | |
| 512 | | static const nes_interface famibox_interface_1 = |
| 514 | static const nesapu_interface famibox_interface_1 = |
| 513 | 515 | { |
| 514 | 516 | "maincpu" |
| 515 | 517 | }; |
| 516 | 518 | |
| 517 | 519 | void famibox_state::palette_init() |
| 518 | 520 | { |
| 519 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 520 | | ppu->init_palette(machine(), 0); |
| 521 | m_ppu->init_palette(machine(), 0); |
| 521 | 522 | } |
| 522 | 523 | |
| 523 | 524 | void famibox_state::ppu_irq(int *ppu_regs) |
| r26012 | r26013 | |
| 541 | 542 | UINT32 famibox_state::screen_update_famibox(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 542 | 543 | { |
| 543 | 544 | /* render the ppu */ |
| 544 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 545 | | ppu->render(bitmap, 0, 0, 0, 0); |
| 545 | m_ppu->render(bitmap, 0, 0, 0, 0); |
| 546 | 546 | return 0; |
| 547 | 547 | } |
| 548 | 548 | |
| r26012 | r26013 | |
| 563 | 563 | m_nt_page[2] = m_nt_ram + 0x800; |
| 564 | 564 | m_nt_page[3] = m_nt_ram + 0xc00; |
| 565 | 565 | |
| 566 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(famibox_state::famibox_nt_r), this), write8_delegate(FUNC(famibox_state::famibox_nt_w), this)); |
| 567 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "ppubank1"); |
| 566 | m_ppu->space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff, read8_delegate(FUNC(famibox_state::famibox_nt_r), this), write8_delegate(FUNC(famibox_state::famibox_nt_w), this)); |
| 567 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "ppubank1"); |
| 568 | 568 | |
| 569 | 569 | famicombox_bankswitch(0); |
| 570 | 570 | |
| r26012 | r26013 | |
| 601 | 601 | /* sound hardware */ |
| 602 | 602 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 603 | 603 | |
| 604 | | MCFG_SOUND_ADD("nes", NES, N2A03_DEFAULTCLOCK) |
| 604 | MCFG_SOUND_ADD("nesapu", NES_APU, N2A03_DEFAULTCLOCK) |
| 605 | 605 | MCFG_SOUND_CONFIG(famibox_interface_1) |
| 606 | 606 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 607 | 607 | |
trunk/src/mame/drivers/vsnes.c
| r26012 | r26013 | |
| 142 | 142 | #include "cpu/z80/z80.h" |
| 143 | 143 | #include "sound/sn76496.h" |
| 144 | 144 | #include "rendlay.h" |
| 145 | | #include "video/ppu2c0x.h" |
| 146 | 145 | #include "sound/dac.h" |
| 147 | | #include "sound/nes_apu.h" |
| 148 | 146 | #include "includes/vsnes.h" |
| 149 | 147 | |
| 150 | 148 | /******************************************************************************/ |
| r26012 | r26013 | |
| 153 | 151 | WRITE8_MEMBER(vsnes_state::sprite_dma_0_w) |
| 154 | 152 | { |
| 155 | 153 | int source = ( data & 7 ); |
| 156 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu1"); |
| 157 | | ppu->spriteram_dma( space, source ); |
| 154 | m_ppu1->spriteram_dma( space, source ); |
| 158 | 155 | } |
| 159 | 156 | |
| 160 | 157 | WRITE8_MEMBER(vsnes_state::sprite_dma_1_w) |
| 161 | 158 | { |
| 162 | 159 | int source = ( data & 7 ); |
| 163 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu2"); |
| 164 | | ppu->spriteram_dma( space, source ); |
| 160 | m_ppu2->spriteram_dma( space, source ); |
| 165 | 161 | } |
| 166 | 162 | |
| 167 | 163 | WRITE8_MEMBER(vsnes_state::vsnes_coin_counter_w) |
| r26012 | r26013 | |
| 196 | 192 | |
| 197 | 193 | READ8_MEMBER(vsnes_state::psg1_4015_r) |
| 198 | 194 | { |
| 199 | | device_t *device = machine().device("nes1"); |
| 200 | | return nes_psg_r(device, space, 0x15); |
| 195 | return m_nesapu1->read(space, 0x15); |
| 201 | 196 | } |
| 202 | 197 | |
| 203 | 198 | WRITE8_MEMBER(vsnes_state::psg1_4015_w) |
| 204 | 199 | { |
| 205 | | device_t *device = machine().device("nes1"); |
| 206 | | nes_psg_w(device, space, 0x15, data); |
| 200 | m_nesapu1->write(space, 0x15, data); |
| 207 | 201 | } |
| 208 | 202 | |
| 209 | 203 | WRITE8_MEMBER(vsnes_state::psg1_4017_w) |
| 210 | 204 | { |
| 211 | | device_t *device = machine().device("nes1"); |
| 212 | | nes_psg_w(device, space, 0x17, data); |
| 205 | m_nesapu1->write(space, 0x17, data); |
| 213 | 206 | } |
| 214 | 207 | |
| 215 | 208 | READ8_MEMBER(vsnes_state::psg2_4015_r) |
| 216 | 209 | { |
| 217 | | device_t *device = machine().device("nes2"); |
| 218 | | return nes_psg_r(device, space, 0x15); |
| 210 | return m_nesapu2->read(space, 0x15); |
| 219 | 211 | } |
| 220 | 212 | |
| 221 | 213 | WRITE8_MEMBER(vsnes_state::psg2_4015_w) |
| 222 | 214 | { |
| 223 | | device_t *device = machine().device("nes2"); |
| 224 | | nes_psg_w(device, space, 0x15, data); |
| 215 | m_nesapu2->write(space, 0x15, data); |
| 225 | 216 | } |
| 226 | 217 | |
| 227 | 218 | WRITE8_MEMBER(vsnes_state::psg2_4017_w) |
| 228 | 219 | { |
| 229 | | device_t *device = machine().device("nes2"); |
| 230 | | nes_psg_w(device, space, 0x17, data); |
| 220 | m_nesapu2->write(space, 0x17, data); |
| 231 | 221 | } |
| 232 | 222 | static ADDRESS_MAP_START( vsnes_cpu1_map, AS_PROGRAM, 8, vsnes_state ) |
| 233 | 223 | AM_RANGE(0x0000, 0x07ff) AM_MIRROR(0x1800) AM_RAM AM_SHARE("work_ram") |
| 234 | 224 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu1", ppu2c0x_device, read, write) |
| 235 | 225 | AM_RANGE(0x4011, 0x4011) AM_DEVWRITE("dac1", dac_device, write_unsigned8) |
| 236 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes1", nes_psg_r, nes_psg_w) |
| 226 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu1", nesapu_device, read, write) |
| 237 | 227 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_0_w) |
| 238 | 228 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg1_4015_r, psg1_4015_w) /* PSG status / first control register */ |
| 239 | 229 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(vsnes_in0_r, vsnes_in0_w) |
| r26012 | r26013 | |
| 247 | 237 | AM_RANGE(0x0000, 0x07ff) AM_MIRROR(0x1800) AM_RAM AM_SHARE("work_ram_1") |
| 248 | 238 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu2", ppu2c0x_device, read, write) |
| 249 | 239 | AM_RANGE(0x4011, 0x4011) AM_DEVWRITE("dac2", dac_device, write_unsigned8) |
| 250 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes2", nes_psg_r, nes_psg_w) |
| 240 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu2", nesapu_device, read, write) |
| 251 | 241 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_1_w) |
| 252 | 242 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg2_4015_r, psg2_4015_w) /* PSG status / first control register */ |
| 253 | 243 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(vsnes_in0_1_r, vsnes_in0_1_w) |
| r26012 | r26013 | |
| 264 | 254 | AM_RANGE(0x0000, 0x07ff) AM_MIRROR(0x1800) AM_RAM AM_SHARE("work_ram") |
| 265 | 255 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu1", ppu2c0x_device, read, write) |
| 266 | 256 | AM_RANGE(0x4011, 0x4011) AM_DEVWRITE("dac1", dac_device, write_unsigned8) |
| 267 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes1", nes_psg_r, nes_psg_w) |
| 257 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu1", nesapu_device, read, write) |
| 268 | 258 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_0_w) |
| 269 | 259 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg1_4015_r, psg1_4015_w) /* PSG status / first control register */ |
| 270 | 260 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(vsnes_in0_r, vsnes_in0_w) |
| r26012 | r26013 | |
| 1706 | 1696 | PORT_DIPSETTING( 0xc0, "RP2C04-0004" ) |
| 1707 | 1697 | INPUT_PORTS_END |
| 1708 | 1698 | |
| 1709 | | static const nes_interface nes_interface_1 = |
| 1699 | static const nesapu_interface nes_interface_1 = |
| 1710 | 1700 | { |
| 1711 | 1701 | "maincpu" |
| 1712 | 1702 | }; |
| 1713 | 1703 | |
| 1714 | | static const nes_interface nes_interface_2 = |
| 1704 | static const nesapu_interface nes_interface_2 = |
| 1715 | 1705 | { |
| 1716 | 1706 | "sub" |
| 1717 | 1707 | }; |
| r26012 | r26013 | |
| 1744 | 1734 | /* sound hardware */ |
| 1745 | 1735 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 1746 | 1736 | |
| 1747 | | MCFG_SOUND_ADD("nes1", NES, N2A03_DEFAULTCLOCK) |
| 1737 | MCFG_SOUND_ADD("nesapu1", NES_APU, N2A03_DEFAULTCLOCK) |
| 1748 | 1738 | MCFG_SOUND_CONFIG(nes_interface_1) |
| 1749 | 1739 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 1750 | 1740 | |
| r26012 | r26013 | |
| 1825 | 1815 | /* sound hardware */ |
| 1826 | 1816 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 1827 | 1817 | |
| 1828 | | MCFG_SOUND_ADD("nes1", NES, N2A03_DEFAULTCLOCK) |
| 1818 | MCFG_SOUND_ADD("nesapu1", NES_APU, N2A03_DEFAULTCLOCK) |
| 1829 | 1819 | MCFG_SOUND_CONFIG(nes_interface_1) |
| 1830 | 1820 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 1831 | 1821 | |
| 1832 | | MCFG_SOUND_ADD("nes2", NES, N2A03_DEFAULTCLOCK) |
| 1822 | MCFG_SOUND_ADD("nesapu2", NES_APU, N2A03_DEFAULTCLOCK) |
| 1833 | 1823 | MCFG_SOUND_CONFIG(nes_interface_2) |
| 1834 | 1824 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 1835 | 1825 | |
| r26012 | r26013 | |
| 1881 | 1871 | /* sound hardware */ |
| 1882 | 1872 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 1883 | 1873 | |
| 1884 | | MCFG_SOUND_ADD("nes1", NES, N2A03_DEFAULTCLOCK) |
| 1874 | MCFG_SOUND_ADD("nesapu1", NES_APU, N2A03_DEFAULTCLOCK) |
| 1885 | 1875 | MCFG_SOUND_CONFIG(nes_interface_1) |
| 1886 | 1876 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 1887 | 1877 | |
trunk/src/mame/drivers/cham24.c
| r26012 | r26013 | |
| 66 | 66 | public: |
| 67 | 67 | cham24_state(const machine_config &mconfig, device_type type, const char *tag) |
| 68 | 68 | : driver_device(mconfig, type, tag), |
| 69 | | m_maincpu(*this, "maincpu") { } |
| 69 | m_maincpu(*this, "maincpu"), |
| 70 | m_nesapu(*this, "nesapu"), |
| 71 | m_ppu(*this, "ppu") { } |
| 70 | 72 | |
| 73 | required_device<cpu_device> m_maincpu; |
| 74 | required_device<nesapu_device> m_nesapu; |
| 75 | required_device<ppu2c0x_device> m_ppu; |
| 76 | |
| 71 | 77 | UINT8* m_nt_ram; |
| 72 | 78 | UINT8* m_nt_page[4]; |
| 73 | 79 | UINT32 m_in_0; |
| r26012 | r26013 | |
| 92 | 98 | UINT32 screen_update_cham24(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); |
| 93 | 99 | void cham24_set_mirroring( int mirroring ); |
| 94 | 100 | void ppu_irq(int *ppu_regs); |
| 95 | | required_device<cpu_device> m_maincpu; |
| 96 | 101 | }; |
| 97 | 102 | |
| 98 | 103 | |
| r26012 | r26013 | |
| 145 | 150 | WRITE8_MEMBER(cham24_state::sprite_dma_w) |
| 146 | 151 | { |
| 147 | 152 | int source = (data & 7); |
| 148 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 149 | | ppu->spriteram_dma(space, source); |
| 153 | m_ppu->spriteram_dma(space, source); |
| 150 | 154 | } |
| 151 | 155 | |
| 152 | 156 | READ8_MEMBER(cham24_state::psg_4015_r) |
| 153 | 157 | { |
| 154 | | device_t *device = machine().device("nes"); |
| 155 | | return nes_psg_r(device,space,0x15); |
| 158 | return m_nesapu->read(space,0x15); |
| 156 | 159 | } |
| 157 | 160 | |
| 158 | 161 | WRITE8_MEMBER(cham24_state::psg_4015_w) |
| 159 | 162 | { |
| 160 | | device_t *device = machine().device("nes"); |
| 161 | | nes_psg_w(device,space,0x15, data); |
| 163 | m_nesapu->write(space,0x15, data); |
| 162 | 164 | } |
| 163 | 165 | |
| 164 | 166 | WRITE8_MEMBER(cham24_state::psg_4017_w) |
| 165 | 167 | { |
| 166 | | device_t *device = machine().device("nes"); |
| 167 | | nes_psg_w(device,space,0x17, data); |
| 168 | m_nesapu->write(space,0x17, data); |
| 168 | 169 | } |
| 169 | 170 | |
| 170 | 171 | |
| r26012 | r26013 | |
| 241 | 242 | static ADDRESS_MAP_START( cham24_map, AS_PROGRAM, 8, cham24_state ) |
| 242 | 243 | AM_RANGE(0x0000, 0x07ff) AM_RAM /* NES RAM */ |
| 243 | 244 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_device, read, write) |
| 244 | | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE_LEGACY("nes", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 245 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nesapu", nesapu_device, read, write) /* PSG primary registers */ |
| 245 | 246 | AM_RANGE(0x4014, 0x4014) AM_WRITE(sprite_dma_w) |
| 246 | 247 | AM_RANGE(0x4015, 0x4015) AM_READWRITE(psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| 247 | 248 | AM_RANGE(0x4016, 0x4016) AM_READWRITE(cham24_IN0_r, cham24_IN0_w) /* IN0 - input port 1 */ |
| r26012 | r26013 | |
| 271 | 272 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2) |
| 272 | 273 | INPUT_PORTS_END |
| 273 | 274 | |
| 274 | | static const nes_interface cham24_interface_1 = |
| 275 | static const nesapu_interface cham24_interface_1 = |
| 275 | 276 | { |
| 276 | 277 | "maincpu" |
| 277 | 278 | }; |
| r26012 | r26013 | |
| 282 | 283 | |
| 283 | 284 | void cham24_state::palette_init() |
| 284 | 285 | { |
| 285 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 286 | | ppu->init_palette(machine(), 0); |
| 286 | m_ppu->init_palette(machine(), 0); |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | void cham24_state::ppu_irq(int *ppu_regs) |
| r26012 | r26013 | |
| 307 | 307 | UINT32 cham24_state::screen_update_cham24(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 308 | 308 | { |
| 309 | 309 | /* render the ppu */ |
| 310 | | ppu2c0x_device *ppu = machine().device<ppu2c0x_device>("ppu"); |
| 311 | | ppu->render(bitmap, 0, 0, 0, 0); |
| 310 | m_ppu->render(bitmap, 0, 0, 0, 0); |
| 312 | 311 | return 0; |
| 313 | 312 | } |
| 314 | 313 | |
| r26012 | r26013 | |
| 323 | 322 | memcpy(&dst[0xc000], &src[0x0f8000], 0x4000); |
| 324 | 323 | |
| 325 | 324 | /* uses 8K swapping, all ROM!*/ |
| 326 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "bank1"); |
| 325 | m_ppu->space(AS_PROGRAM).install_read_bank(0x0000, 0x1fff, "bank1"); |
| 327 | 326 | membank("bank1")->set_base(memregion("gfx1")->base()); |
| 328 | 327 | |
| 329 | 328 | /* need nametable ram, though. I doubt this uses more than 2k, but it starts up configured for 4 */ |
| r26012 | r26013 | |
| 334 | 333 | m_nt_page[3] = m_nt_ram + 0xc00; |
| 335 | 334 | |
| 336 | 335 | /* and read/write handlers */ |
| 337 | | machine().device("ppu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff,read8_delegate(FUNC(cham24_state::nt_r), this), write8_delegate(FUNC(cham24_state::nt_w), this)); |
| 336 | m_ppu->space(AS_PROGRAM).install_readwrite_handler(0x2000, 0x3eff,read8_delegate(FUNC(cham24_state::nt_r), this), write8_delegate(FUNC(cham24_state::nt_w), this)); |
| 338 | 337 | } |
| 339 | 338 | |
| 340 | 339 | DRIVER_INIT_MEMBER(cham24_state,cham24) |
| r26012 | r26013 | |
| 368 | 367 | /* sound hardware */ |
| 369 | 368 | MCFG_SPEAKER_STANDARD_MONO("mono") |
| 370 | 369 | |
| 371 | | MCFG_SOUND_ADD("nes", NES, N2A03_DEFAULTCLOCK) |
| 370 | MCFG_SOUND_ADD("nesapu", NES_APU, N2A03_DEFAULTCLOCK) |
| 372 | 371 | MCFG_SOUND_CONFIG(cham24_interface_1) |
| 373 | 372 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 374 | 373 | |
trunk/src/emu/sound/nes_apu.c
| r26012 | r26013 | |
| 47 | 47 | #include "emu.h" |
| 48 | 48 | #include "nes_apu.h" |
| 49 | 49 | #include "cpu/m6502/n2a03.h" |
| 50 | | #include "devlegcy.h" |
| 51 | 50 | |
| 52 | | #include "nes_defs.h" |
| 53 | 51 | |
| 54 | | /* GLOBAL CONSTANTS */ |
| 55 | | #define SYNCS_MAX1 0x20 |
| 56 | | #define SYNCS_MAX2 0x80 |
| 57 | 52 | |
| 58 | | /* GLOBAL VARIABLES */ |
| 59 | | struct nesapu_state |
| 60 | | { |
| 61 | | apu_t APU; /* Actual APUs */ |
| 62 | | float apu_incsize; /* Adjustment increment */ |
| 63 | | uint32 samps_per_sync; /* Number of samples per vsync */ |
| 64 | | uint32 buffer_size; /* Actual buffer size in bytes */ |
| 65 | | uint32 real_rate; /* Actual playback rate */ |
| 66 | | uint8 noise_lut[NOISE_LONG]; /* Noise sample lookup table */ |
| 67 | | uint32 vbl_times[0x20]; /* VBL durations in samples */ |
| 68 | | uint32 sync_times1[SYNCS_MAX1]; /* Samples per sync table */ |
| 69 | | uint32 sync_times2[SYNCS_MAX2]; /* Samples per sync table */ |
| 70 | | sound_stream *stream; |
| 71 | | }; |
| 72 | | |
| 73 | | |
| 74 | | INLINE nesapu_state *get_safe_token(device_t *device) |
| 75 | | { |
| 76 | | assert(device != NULL); |
| 77 | | assert(device->type() == NES); |
| 78 | | return (nesapu_state *)downcast<nesapu_device *>(device)->token(); |
| 79 | | } |
| 80 | | |
| 81 | 53 | /* INTERNAL FUNCTIONS */ |
| 82 | 54 | |
| 83 | 55 | /* INITIALIZE WAVE TIMES RELATIVE TO SAMPLE RATE */ |
| r26012 | r26013 | |
| 90 | 62 | } |
| 91 | 63 | |
| 92 | 64 | /* INITIALIZE SAMPLE TIMES IN TERMS OF VSYNCS */ |
| 93 | | static void create_syncs(nesapu_state *info, unsigned long sps) |
| 65 | void nesapu_device::create_syncs(unsigned long sps) |
| 94 | 66 | { |
| 95 | 67 | int i; |
| 96 | 68 | unsigned long val = sps; |
| 97 | 69 | |
| 98 | 70 | for (i = 0; i < SYNCS_MAX1; i++) |
| 99 | 71 | { |
| 100 | | info->sync_times1[i] = val; |
| 72 | m_sync_times1[i] = val; |
| 101 | 73 | val += sps; |
| 102 | 74 | } |
| 103 | 75 | |
| 104 | 76 | val = 0; |
| 105 | 77 | for (i = 0; i < SYNCS_MAX2; i++) |
| 106 | 78 | { |
| 107 | | info->sync_times2[i] = val; |
| 108 | | info->sync_times2[i] >>= 2; |
| 79 | m_sync_times2[i] = val; |
| 80 | m_sync_times2[i] >>= 2; |
| 109 | 81 | val += sps; |
| 110 | 82 | } |
| 111 | 83 | } |
| r26012 | r26013 | |
| 127 | 99 | } |
| 128 | 100 | } |
| 129 | 101 | |
| 102 | const device_type NES_APU = &device_creator<nesapu_device>; |
| 103 | |
| 104 | nesapu_device::nesapu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 105 | : device_t(mconfig, NES_APU, "N2A03 APU", tag, owner, clock, "nesapu", __FILE__), |
| 106 | device_sound_interface(mconfig, *this), |
| 107 | m_apu_incsize(0.0d), |
| 108 | m_samps_per_sync(0), |
| 109 | m_buffer_size(0), |
| 110 | m_real_rate(0), |
| 111 | m_stream(NULL) |
| 112 | { |
| 113 | for (int i = 0; i < NOISE_LONG; i++) |
| 114 | { |
| 115 | m_noise_lut[i] = 0; |
| 116 | } |
| 117 | |
| 118 | for (int i = 0; i < 0X20; i++) |
| 119 | { |
| 120 | m_vbl_times[i] = 0; |
| 121 | } |
| 122 | |
| 123 | for (int i = 0; i < SYNCS_MAX1; i++) |
| 124 | { |
| 125 | m_sync_times1[i] = 0; |
| 126 | } |
| 127 | |
| 128 | for (int i = 0; i < SYNCS_MAX2; i++) |
| 129 | { |
| 130 | m_sync_times2[i] = 0; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | //------------------------------------------------- |
| 135 | // device_config_complete - perform any |
| 136 | // operations now that the configuration is |
| 137 | // complete |
| 138 | //------------------------------------------------- |
| 139 | |
| 140 | void nesapu_device::device_config_complete() |
| 141 | { |
| 142 | // inherit a copy of the static data |
| 143 | const nesapu_interface *intf = reinterpret_cast<const nesapu_interface *>(static_config()); |
| 144 | if (intf != NULL) |
| 145 | *static_cast<nesapu_interface *>(this) = *intf; |
| 146 | |
| 147 | // or initialize to defaults if none provided |
| 148 | else |
| 149 | { |
| 150 | m_cpu_tag = ""; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | //------------------------------------------------- |
| 155 | // device_start - device-specific startup |
| 156 | //------------------------------------------------- |
| 157 | |
| 158 | void nesapu_device::device_start() |
| 159 | { |
| 160 | int rate = clock() / 4; |
| 161 | int i; |
| 162 | |
| 163 | /* Initialize global variables */ |
| 164 | m_samps_per_sync = rate / ATTOSECONDS_TO_HZ(machine().primary_screen->frame_period().attoseconds); |
| 165 | m_buffer_size = m_samps_per_sync; |
| 166 | m_real_rate = m_samps_per_sync * ATTOSECONDS_TO_HZ(machine().primary_screen->frame_period().attoseconds); |
| 167 | m_apu_incsize = (float) (clock() / (float) m_real_rate); |
| 168 | |
| 169 | /* Use initializer calls */ |
| 170 | create_noise(m_noise_lut, 13, NOISE_LONG); |
| 171 | create_vbltimes(m_vbl_times,vbl_length,m_samps_per_sync); |
| 172 | create_syncs(m_samps_per_sync); |
| 173 | |
| 174 | /* Adjust buffer size if 16 bits */ |
| 175 | m_buffer_size+=m_samps_per_sync; |
| 176 | |
| 177 | /* Initialize individual chips */ |
| 178 | (m_APU.dpcm).memory = &machine().device(m_cpu_tag)->memory().space(AS_PROGRAM); |
| 179 | |
| 180 | m_stream = machine().sound().stream_alloc(*this, 0, 1, rate, this); |
| 181 | |
| 182 | /* register for save */ |
| 183 | for (i = 0; i < 2; i++) |
| 184 | { |
| 185 | save_item(NAME(m_APU.squ[i].regs), i); |
| 186 | save_item(NAME(m_APU.squ[i].vbl_length), i); |
| 187 | save_item(NAME(m_APU.squ[i].freq), i); |
| 188 | save_item(NAME(m_APU.squ[i].phaseacc), i); |
| 189 | save_item(NAME(m_APU.squ[i].output_vol), i); |
| 190 | save_item(NAME(m_APU.squ[i].env_phase), i); |
| 191 | save_item(NAME(m_APU.squ[i].sweep_phase), i); |
| 192 | save_item(NAME(m_APU.squ[i].adder), i); |
| 193 | save_item(NAME(m_APU.squ[i].env_vol), i); |
| 194 | save_item(NAME(m_APU.squ[i].enabled), i); |
| 195 | } |
| 196 | |
| 197 | save_item(NAME(m_APU.tri.regs)); |
| 198 | save_item(NAME(m_APU.tri.linear_length)); |
| 199 | save_item(NAME(m_APU.tri.vbl_length)); |
| 200 | save_item(NAME(m_APU.tri.write_latency)); |
| 201 | save_item(NAME(m_APU.tri.phaseacc)); |
| 202 | save_item(NAME(m_APU.tri.output_vol)); |
| 203 | save_item(NAME(m_APU.tri.adder)); |
| 204 | save_item(NAME(m_APU.tri.counter_started)); |
| 205 | save_item(NAME(m_APU.tri.enabled)); |
| 206 | |
| 207 | save_item(NAME(m_APU.noi.regs)); |
| 208 | save_item(NAME(m_APU.noi.cur_pos)); |
| 209 | save_item(NAME(m_APU.noi.vbl_length)); |
| 210 | save_item(NAME(m_APU.noi.phaseacc)); |
| 211 | save_item(NAME(m_APU.noi.output_vol)); |
| 212 | save_item(NAME(m_APU.noi.env_phase)); |
| 213 | save_item(NAME(m_APU.noi.env_vol)); |
| 214 | save_item(NAME(m_APU.noi.enabled)); |
| 215 | |
| 216 | save_item(NAME(m_APU.dpcm.regs)); |
| 217 | save_item(NAME(m_APU.dpcm.address)); |
| 218 | save_item(NAME(m_APU.dpcm.length)); |
| 219 | save_item(NAME(m_APU.dpcm.bits_left)); |
| 220 | save_item(NAME(m_APU.dpcm.phaseacc)); |
| 221 | save_item(NAME(m_APU.dpcm.output_vol)); |
| 222 | save_item(NAME(m_APU.dpcm.cur_byte)); |
| 223 | save_item(NAME(m_APU.dpcm.enabled)); |
| 224 | save_item(NAME(m_APU.dpcm.irq_occurred)); |
| 225 | save_item(NAME(m_APU.dpcm.vol)); |
| 226 | |
| 227 | save_item(NAME(m_APU.regs)); |
| 228 | |
| 229 | #ifdef USE_QUEUE |
| 230 | save_item(NAME(m_APU.queue)); |
| 231 | save_item(NAME(m_APU.head)); |
| 232 | save_item(NAME(m_APU.tail)); |
| 233 | #else |
| 234 | save_item(NAME(m_APU.buf_pos)); |
| 235 | save_item(NAME(m_APU.step_mode)); |
| 236 | #endif |
| 237 | } |
| 238 | |
| 130 | 239 | /* TODO: sound channels should *ALL* have DC volume decay */ |
| 131 | 240 | |
| 132 | 241 | /* OUTPUT SQUARE WAVE SAMPLE (VALUES FROM -16 to +15) */ |
| 133 | | static int8 apu_square(nesapu_state *info, square_t *chan) |
| 242 | int8 nesapu_device::apu_square(square_t *chan) |
| 134 | 243 | { |
| 135 | 244 | int env_delay; |
| 136 | 245 | int sweep_delay; |
| r26012 | r26013 | |
| 146 | 255 | return 0; |
| 147 | 256 | |
| 148 | 257 | /* enveloping */ |
| 149 | | env_delay = info->sync_times1[chan->regs[0] & 0x0F]; |
| 258 | env_delay = m_sync_times1[chan->regs[0] & 0x0F]; |
| 150 | 259 | |
| 151 | 260 | /* decay is at a rate of (env_regs + 1) / 240 secs */ |
| 152 | 261 | chan->env_phase -= 4; |
| r26012 | r26013 | |
| 169 | 278 | /* freqsweeps */ |
| 170 | 279 | if ((chan->regs[1] & 0x80) && (chan->regs[1] & 7)) |
| 171 | 280 | { |
| 172 | | sweep_delay = info->sync_times1[(chan->regs[1] >> 4) & 7]; |
| 281 | sweep_delay = m_sync_times1[(chan->regs[1] >> 4) & 7]; |
| 173 | 282 | chan->sweep_phase -= 2; |
| 174 | 283 | while (chan->sweep_phase < 0) |
| 175 | 284 | { |
| r26012 | r26013 | |
| 185 | 294 | || (chan->freq >> 16) < 4) |
| 186 | 295 | return 0; |
| 187 | 296 | |
| 188 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 297 | chan->phaseacc -= (float) m_apu_incsize; /* # of cycles per sample */ |
| 189 | 298 | |
| 190 | 299 | while (chan->phaseacc < 0) |
| 191 | 300 | { |
| r26012 | r26013 | |
| 205 | 314 | } |
| 206 | 315 | |
| 207 | 316 | /* OUTPUT TRIANGLE WAVE SAMPLE (VALUES FROM -16 to +15) */ |
| 208 | | static int8 apu_triangle(nesapu_state *info, triangle_t *chan) |
| 317 | int8 nesapu_device::apu_triangle(triangle_t *chan) |
| 209 | 318 | { |
| 210 | 319 | int freq; |
| 211 | 320 | int8 output; |
| r26012 | r26013 | |
| 244 | 353 | if (freq < 4) /* inaudible */ |
| 245 | 354 | return 0; |
| 246 | 355 | |
| 247 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 356 | chan->phaseacc -= (float) m_apu_incsize; /* # of cycles per sample */ |
| 248 | 357 | while (chan->phaseacc < 0) |
| 249 | 358 | { |
| 250 | 359 | chan->phaseacc += freq; |
| r26012 | r26013 | |
| 263 | 372 | } |
| 264 | 373 | |
| 265 | 374 | /* OUTPUT NOISE WAVE SAMPLE (VALUES FROM -16 to +15) */ |
| 266 | | static int8 apu_noise(nesapu_state *info, noise_t *chan) |
| 375 | int8 nesapu_device::apu_noise(noise_t *chan) |
| 267 | 376 | { |
| 268 | 377 | int freq, env_delay; |
| 269 | 378 | uint8 outvol; |
| r26012 | r26013 | |
| 278 | 387 | return 0; |
| 279 | 388 | |
| 280 | 389 | /* enveloping */ |
| 281 | | env_delay = info->sync_times1[chan->regs[0] & 0x0F]; |
| 390 | env_delay = m_sync_times1[chan->regs[0] & 0x0F]; |
| 282 | 391 | |
| 283 | 392 | /* decay is at a rate of (env_regs + 1) / 240 secs */ |
| 284 | 393 | chan->env_phase -= 4; |
| r26012 | r26013 | |
| 302 | 411 | return 0; |
| 303 | 412 | |
| 304 | 413 | freq = noise_freq[chan->regs[2] & 0x0F]; |
| 305 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 414 | chan->phaseacc -= (float) m_apu_incsize; /* # of cycles per sample */ |
| 306 | 415 | while (chan->phaseacc < 0) |
| 307 | 416 | { |
| 308 | 417 | chan->phaseacc += freq; |
| r26012 | r26013 | |
| 319 | 428 | else |
| 320 | 429 | outvol = 0x0F - chan->env_vol; |
| 321 | 430 | |
| 322 | | output = info->noise_lut[chan->cur_pos]; |
| 431 | output = m_noise_lut[chan->cur_pos]; |
| 323 | 432 | if (output > outvol) |
| 324 | 433 | output = outvol; |
| 325 | 434 | |
| 326 | | if (info->noise_lut[chan->cur_pos] & 0x80) /* make it negative */ |
| 435 | if (m_noise_lut[chan->cur_pos] & 0x80) /* make it negative */ |
| 327 | 436 | output = -output; |
| 328 | 437 | |
| 329 | 438 | return (int8) output; |
| r26012 | r26013 | |
| 342 | 451 | |
| 343 | 452 | /* OUTPUT DPCM WAVE SAMPLE (VALUES FROM -64 to +63) */ |
| 344 | 453 | /* TODO: centerline naughtiness */ |
| 345 | | static int8 apu_dpcm(nesapu_state *info, dpcm_t *chan) |
| 454 | int8 nesapu_device::apu_dpcm(dpcm_t *chan) |
| 346 | 455 | { |
| 347 | 456 | int freq, bit_pos; |
| 348 | 457 | |
| r26012 | r26013 | |
| 355 | 464 | if (chan->enabled) |
| 356 | 465 | { |
| 357 | 466 | freq = dpcm_clocks[chan->regs[0] & 0x0F]; |
| 358 | | chan->phaseacc -= (float) info->apu_incsize; /* # of cycles per sample */ |
| 467 | chan->phaseacc -= (float) m_apu_incsize; /* # of cycles per sample */ |
| 359 | 468 | |
| 360 | 469 | while (chan->phaseacc < 0) |
| 361 | 470 | { |
| r26012 | r26013 | |
| 372 | 481 | if (chan->regs[0] & 0x80) /* IRQ Generator */ |
| 373 | 482 | { |
| 374 | 483 | chan->irq_occurred = TRUE; |
| 375 | | downcast<n2a03_device &>(info->APU.dpcm.memory->device()).set_input_line(N2A03_APU_IRQ_LINE, ASSERT_LINE); |
| 484 | downcast<n2a03_device &>(m_APU.dpcm.memory->device()).set_input_line(N2A03_APU_IRQ_LINE, ASSERT_LINE); |
| 376 | 485 | } |
| 377 | 486 | break; |
| 378 | 487 | } |
| r26012 | r26013 | |
| 383 | 492 | bit_pos = 7 - (chan->bits_left & 7); |
| 384 | 493 | if (7 == bit_pos) |
| 385 | 494 | { |
| 386 | | chan->cur_byte = info->APU.dpcm.memory->read_byte(chan->address); |
| 495 | chan->cur_byte = m_APU.dpcm.memory->read_byte(chan->address); |
| 387 | 496 | chan->address++; |
| 388 | 497 | chan->length--; |
| 389 | 498 | } |
| r26012 | r26013 | |
| 406 | 515 | } |
| 407 | 516 | |
| 408 | 517 | /* WRITE REGISTER VALUE */ |
| 409 | | INLINE void apu_regwrite(nesapu_state *info,int address, uint8 value) |
| 518 | inline void nesapu_device::apu_regwrite(int address, uint8 value) |
| 410 | 519 | { |
| 411 | 520 | int chan = (address & 4) ? 1 : 0; |
| 412 | 521 | |
| r26012 | r26013 | |
| 415 | 524 | /* squares */ |
| 416 | 525 | case APU_WRA0: |
| 417 | 526 | case APU_WRB0: |
| 418 | | info->APU.squ[chan].regs[0] = value; |
| 527 | m_APU.squ[chan].regs[0] = value; |
| 419 | 528 | break; |
| 420 | 529 | |
| 421 | 530 | case APU_WRA1: |
| 422 | 531 | case APU_WRB1: |
| 423 | | info->APU.squ[chan].regs[1] = value; |
| 532 | m_APU.squ[chan].regs[1] = value; |
| 424 | 533 | break; |
| 425 | 534 | |
| 426 | 535 | case APU_WRA2: |
| 427 | 536 | case APU_WRB2: |
| 428 | | info->APU.squ[chan].regs[2] = value; |
| 429 | | if (info->APU.squ[chan].enabled) |
| 430 | | info->APU.squ[chan].freq = ((((info->APU.squ[chan].regs[3] & 7) << 8) + value) + 1) << 16; |
| 537 | m_APU.squ[chan].regs[2] = value; |
| 538 | if (m_APU.squ[chan].enabled) |
| 539 | m_APU.squ[chan].freq = ((((m_APU.squ[chan].regs[3] & 7) << 8) + value) + 1) << 16; |
| 431 | 540 | break; |
| 432 | 541 | |
| 433 | 542 | case APU_WRA3: |
| 434 | 543 | case APU_WRB3: |
| 435 | | info->APU.squ[chan].regs[3] = value; |
| 544 | m_APU.squ[chan].regs[3] = value; |
| 436 | 545 | |
| 437 | | if (info->APU.squ[chan].enabled) |
| 546 | if (m_APU.squ[chan].enabled) |
| 438 | 547 | { |
| 439 | | info->APU.squ[chan].vbl_length = info->vbl_times[value >> 3]; |
| 440 | | info->APU.squ[chan].env_vol = 0; |
| 441 | | info->APU.squ[chan].freq = ((((value & 7) << 8) + info->APU.squ[chan].regs[2]) + 1) << 16; |
| 548 | m_APU.squ[chan].vbl_length = m_vbl_times[value >> 3]; |
| 549 | m_APU.squ[chan].env_vol = 0; |
| 550 | m_APU.squ[chan].freq = ((((value & 7) << 8) + m_APU.squ[chan].regs[2]) + 1) << 16; |
| 442 | 551 | } |
| 443 | 552 | |
| 444 | 553 | break; |
| 445 | 554 | |
| 446 | 555 | /* triangle */ |
| 447 | 556 | case APU_WRC0: |
| 448 | | info->APU.tri.regs[0] = value; |
| 557 | m_APU.tri.regs[0] = value; |
| 449 | 558 | |
| 450 | | if (info->APU.tri.enabled) |
| 559 | if (m_APU.tri.enabled) |
| 451 | 560 | { /* ??? */ |
| 452 | | if (FALSE == info->APU.tri.counter_started) |
| 453 | | info->APU.tri.linear_length = info->sync_times2[value & 0x7F]; |
| 561 | if (FALSE == m_APU.tri.counter_started) |
| 562 | m_APU.tri.linear_length = m_sync_times2[value & 0x7F]; |
| 454 | 563 | } |
| 455 | 564 | |
| 456 | 565 | break; |
| 457 | 566 | |
| 458 | 567 | case 0x4009: |
| 459 | 568 | /* unused */ |
| 460 | | info->APU.tri.regs[1] = value; |
| 569 | m_APU.tri.regs[1] = value; |
| 461 | 570 | break; |
| 462 | 571 | |
| 463 | 572 | case APU_WRC2: |
| 464 | | info->APU.tri.regs[2] = value; |
| 573 | m_APU.tri.regs[2] = value; |
| 465 | 574 | break; |
| 466 | 575 | |
| 467 | 576 | case APU_WRC3: |
| 468 | | info->APU.tri.regs[3] = value; |
| 577 | m_APU.tri.regs[3] = value; |
| 469 | 578 | |
| 470 | 579 | /* this is somewhat of a hack. there is some latency on the Real |
| 471 | 580 | ** Thing between when trireg0 is written to and when the linear |
| r26012 | r26013 | |
| 483 | 592 | */ |
| 484 | 593 | |
| 485 | 594 | /* used to be 3, but now we run the clock faster, so base it on samples/sync */ |
| 486 | | info->APU.tri.write_latency = (info->samps_per_sync + 239) / 240; |
| 595 | m_APU.tri.write_latency = (m_samps_per_sync + 239) / 240; |
| 487 | 596 | |
| 488 | | if (info->APU.tri.enabled) |
| 597 | if (m_APU.tri.enabled) |
| 489 | 598 | { |
| 490 | | info->APU.tri.counter_started = FALSE; |
| 491 | | info->APU.tri.vbl_length = info->vbl_times[value >> 3]; |
| 492 | | info->APU.tri.linear_length = info->sync_times2[info->APU.tri.regs[0] & 0x7F]; |
| 599 | m_APU.tri.counter_started = FALSE; |
| 600 | m_APU.tri.vbl_length = m_vbl_times[value >> 3]; |
| 601 | m_APU.tri.linear_length = m_sync_times2[m_APU.tri.regs[0] & 0x7F]; |
| 493 | 602 | } |
| 494 | 603 | |
| 495 | 604 | break; |
| 496 | 605 | |
| 497 | 606 | /* noise */ |
| 498 | 607 | case APU_WRD0: |
| 499 | | info->APU.noi.regs[0] = value; |
| 608 | m_APU.noi.regs[0] = value; |
| 500 | 609 | break; |
| 501 | 610 | |
| 502 | 611 | case 0x400D: |
| 503 | 612 | /* unused */ |
| 504 | | info->APU.noi.regs[1] = value; |
| 613 | m_APU.noi.regs[1] = value; |
| 505 | 614 | break; |
| 506 | 615 | |
| 507 | 616 | case APU_WRD2: |
| 508 | | info->APU.noi.regs[2] = value; |
| 617 | m_APU.noi.regs[2] = value; |
| 509 | 618 | break; |
| 510 | 619 | |
| 511 | 620 | case APU_WRD3: |
| 512 | | info->APU.noi.regs[3] = value; |
| 621 | m_APU.noi.regs[3] = value; |
| 513 | 622 | |
| 514 | | if (info->APU.noi.enabled) |
| 623 | if (m_APU.noi.enabled) |
| 515 | 624 | { |
| 516 | | info->APU.noi.vbl_length = info->vbl_times[value >> 3]; |
| 517 | | info->APU.noi.env_vol = 0; /* reset envelope */ |
| 625 | m_APU.noi.vbl_length = m_vbl_times[value >> 3]; |
| 626 | m_APU.noi.env_vol = 0; /* reset envelope */ |
| 518 | 627 | } |
| 519 | 628 | break; |
| 520 | 629 | |
| 521 | 630 | /* DMC */ |
| 522 | 631 | case APU_WRE0: |
| 523 | | info->APU.dpcm.regs[0] = value; |
| 632 | m_APU.dpcm.regs[0] = value; |
| 524 | 633 | if (0 == (value & 0x80)) { |
| 525 | | downcast<n2a03_device &>(info->APU.dpcm.memory->device()).set_input_line(N2A03_APU_IRQ_LINE, CLEAR_LINE); |
| 526 | | info->APU.dpcm.irq_occurred = FALSE; |
| 634 | downcast<n2a03_device &>(m_APU.dpcm.memory->device()).set_input_line(N2A03_APU_IRQ_LINE, CLEAR_LINE); |
| 635 | m_APU.dpcm.irq_occurred = FALSE; |
| 527 | 636 | } |
| 528 | 637 | break; |
| 529 | 638 | |
| 530 | 639 | case APU_WRE1: /* 7-bit DAC */ |
| 531 | | //info->APU.dpcm.regs[1] = value - 0x40; |
| 532 | | info->APU.dpcm.regs[1] = value & 0x7F; |
| 533 | | info->APU.dpcm.vol = (info->APU.dpcm.regs[1]-64); |
| 640 | //m_APU.dpcm.regs[1] = value - 0x40; |
| 641 | m_APU.dpcm.regs[1] = value & 0x7F; |
| 642 | m_APU.dpcm.vol = (m_APU.dpcm.regs[1]-64); |
| 534 | 643 | break; |
| 535 | 644 | |
| 536 | 645 | case APU_WRE2: |
| 537 | | info->APU.dpcm.regs[2] = value; |
| 538 | | //apu_dpcmreset(info->APU.dpcm); |
| 646 | m_APU.dpcm.regs[2] = value; |
| 647 | //apu_dpcmreset(m_APU.dpcm); |
| 539 | 648 | break; |
| 540 | 649 | |
| 541 | 650 | case APU_WRE3: |
| 542 | | info->APU.dpcm.regs[3] = value; |
| 651 | m_APU.dpcm.regs[3] = value; |
| 543 | 652 | break; |
| 544 | 653 | |
| 545 | 654 | case APU_IRQCTRL: |
| 546 | 655 | if(value & 0x80) |
| 547 | | info->APU.step_mode = 5; |
| 656 | m_APU.step_mode = 5; |
| 548 | 657 | else |
| 549 | | info->APU.step_mode = 4; |
| 658 | m_APU.step_mode = 4; |
| 550 | 659 | break; |
| 551 | 660 | |
| 552 | 661 | case APU_SMASK: |
| 553 | 662 | if (value & 0x01) |
| 554 | | info->APU.squ[0].enabled = TRUE; |
| 663 | m_APU.squ[0].enabled = TRUE; |
| 555 | 664 | else |
| 556 | 665 | { |
| 557 | | info->APU.squ[0].enabled = FALSE; |
| 558 | | info->APU.squ[0].vbl_length = 0; |
| 666 | m_APU.squ[0].enabled = FALSE; |
| 667 | m_APU.squ[0].vbl_length = 0; |
| 559 | 668 | } |
| 560 | 669 | |
| 561 | 670 | if (value & 0x02) |
| 562 | | info->APU.squ[1].enabled = TRUE; |
| 671 | m_APU.squ[1].enabled = TRUE; |
| 563 | 672 | else |
| 564 | 673 | { |
| 565 | | info->APU.squ[1].enabled = FALSE; |
| 566 | | info->APU.squ[1].vbl_length = 0; |
| 674 | m_APU.squ[1].enabled = FALSE; |
| 675 | m_APU.squ[1].vbl_length = 0; |
| 567 | 676 | } |
| 568 | 677 | |
| 569 | 678 | if (value & 0x04) |
| 570 | | info->APU.tri.enabled = TRUE; |
| 679 | m_APU.tri.enabled = TRUE; |
| 571 | 680 | else |
| 572 | 681 | { |
| 573 | | info->APU.tri.enabled = FALSE; |
| 574 | | info->APU.tri.vbl_length = 0; |
| 575 | | info->APU.tri.linear_length = 0; |
| 576 | | info->APU.tri.counter_started = FALSE; |
| 577 | | info->APU.tri.write_latency = 0; |
| 682 | m_APU.tri.enabled = FALSE; |
| 683 | m_APU.tri.vbl_length = 0; |
| 684 | m_APU.tri.linear_length = 0; |
| 685 | m_APU.tri.counter_started = FALSE; |
| 686 | m_APU.tri.write_latency = 0; |
| 578 | 687 | } |
| 579 | 688 | |
| 580 | 689 | if (value & 0x08) |
| 581 | | info->APU.noi.enabled = TRUE; |
| 690 | m_APU.noi.enabled = TRUE; |
| 582 | 691 | else |
| 583 | 692 | { |
| 584 | | info->APU.noi.enabled = FALSE; |
| 585 | | info->APU.noi.vbl_length = 0; |
| 693 | m_APU.noi.enabled = FALSE; |
| 694 | m_APU.noi.vbl_length = 0; |
| 586 | 695 | } |
| 587 | 696 | |
| 588 | 697 | if (value & 0x10) |
| 589 | 698 | { |
| 590 | 699 | /* only reset dpcm values if DMA is finished */ |
| 591 | | if (FALSE == info->APU.dpcm.enabled) |
| 700 | if (FALSE == m_APU.dpcm.enabled) |
| 592 | 701 | { |
| 593 | | info->APU.dpcm.enabled = TRUE; |
| 594 | | apu_dpcmreset(&info->APU.dpcm); |
| 702 | m_APU.dpcm.enabled = TRUE; |
| 703 | apu_dpcmreset(&m_APU.dpcm); |
| 595 | 704 | } |
| 596 | 705 | } |
| 597 | 706 | else |
| 598 | | info->APU.dpcm.enabled = FALSE; |
| 707 | m_APU.dpcm.enabled = FALSE; |
| 599 | 708 | |
| 600 | | info->APU.dpcm.irq_occurred = FALSE; |
| 709 | m_APU.dpcm.irq_occurred = FALSE; |
| 601 | 710 | |
| 602 | 711 | break; |
| 603 | 712 | default: |
| r26012 | r26013 | |
| 608 | 717 | } |
| 609 | 718 | } |
| 610 | 719 | |
| 611 | | /* UPDATE SOUND BUFFER USING CURRENT DATA */ |
| 612 | | INLINE void apu_update(nesapu_state *info, stream_sample_t *buffer16, int samples) |
| 613 | | { |
| 614 | | int accum; |
| 615 | 720 | |
| 616 | | while (samples--) |
| 617 | | { |
| 618 | | accum = apu_square(info, &info->APU.squ[0]); |
| 619 | | accum += apu_square(info, &info->APU.squ[1]); |
| 620 | | accum += apu_triangle(info, &info->APU.tri); |
| 621 | | accum += apu_noise(info, &info->APU.noi); |
| 622 | | accum += apu_dpcm(info, &info->APU.dpcm); |
| 623 | 721 | |
| 624 | | /* 8-bit clamps */ |
| 625 | | if (accum > 127) |
| 626 | | accum = 127; |
| 627 | | else if (accum < -128) |
| 628 | | accum = -128; |
| 629 | | |
| 630 | | *(buffer16++)=accum<<8; |
| 631 | | } |
| 632 | | } |
| 633 | | |
| 634 | 722 | /* READ VALUES FROM REGISTERS */ |
| 635 | | INLINE uint8 apu_read(nesapu_state *info,int address) |
| 723 | inline uint8 nesapu_device::apu_read(int address) |
| 636 | 724 | { |
| 637 | 725 | if (address == 0x15) /*FIXED* Address $4015 has different behaviour*/ |
| 638 | 726 | { |
| 639 | 727 | int readval = 0; |
| 640 | | if (info->APU.squ[0].vbl_length > 0) |
| 728 | if (m_APU.squ[0].vbl_length > 0) |
| 641 | 729 | readval |= 0x01; |
| 642 | 730 | |
| 643 | | if (info->APU.squ[1].vbl_length > 0) |
| 731 | if (m_APU.squ[1].vbl_length > 0) |
| 644 | 732 | readval |= 0x02; |
| 645 | 733 | |
| 646 | | if (info->APU.tri.vbl_length > 0) |
| 734 | if (m_APU.tri.vbl_length > 0) |
| 647 | 735 | readval |= 0x04; |
| 648 | 736 | |
| 649 | | if (info->APU.noi.vbl_length > 0) |
| 737 | if (m_APU.noi.vbl_length > 0) |
| 650 | 738 | readval |= 0x08; |
| 651 | 739 | |
| 652 | | if (info->APU.dpcm.enabled == TRUE) |
| 740 | if (m_APU.dpcm.enabled == TRUE) |
| 653 | 741 | readval |= 0x10; |
| 654 | 742 | |
| 655 | | if (info->APU.dpcm.irq_occurred == TRUE) |
| 743 | if (m_APU.dpcm.irq_occurred == TRUE) |
| 656 | 744 | readval |= 0x80; |
| 657 | 745 | |
| 658 | 746 | return readval; |
| 659 | 747 | } |
| 660 | 748 | else |
| 661 | | return info->APU.regs[address]; |
| 749 | return m_APU.regs[address]; |
| 662 | 750 | } |
| 663 | 751 | |
| 664 | 752 | /* WRITE VALUE TO TEMP REGISTRY AND QUEUE EVENT */ |
| 665 | | INLINE void apu_write(nesapu_state *info,int address, uint8 value) |
| 753 | inline void nesapu_device::apu_write(int address, uint8 value) |
| 666 | 754 | { |
| 667 | | info->APU.regs[address]=value; |
| 668 | | info->stream->update(); |
| 669 | | apu_regwrite(info,address,value); |
| 755 | m_APU.regs[address]=value; |
| 756 | m_stream->update(); |
| 757 | apu_regwrite(address,value); |
| 670 | 758 | } |
| 671 | 759 | |
| 672 | 760 | /* EXTERNAL INTERFACE FUNCTIONS */ |
| 673 | 761 | |
| 674 | 762 | /* REGISTER READ/WRITE FUNCTIONS */ |
| 675 | | READ8_DEVICE_HANDLER( nes_psg_r ) {return apu_read(get_safe_token(device),offset);} |
| 676 | | WRITE8_DEVICE_HANDLER( nes_psg_w ) {apu_write(get_safe_token(device),offset,data);} |
| 763 | READ8_MEMBER( nesapu_device::read ) {return apu_read(offset);} |
| 764 | WRITE8_MEMBER( nesapu_device::write ) {apu_write(offset,data);} |
| 677 | 765 | |
| 678 | | /* UPDATE APU SYSTEM */ |
| 679 | | static STREAM_UPDATE( nes_psg_update_sound ) |
| 680 | | { |
| 681 | | nesapu_state *info = (nesapu_state *)param; |
| 682 | | apu_update(info, outputs[0], samples); |
| 683 | | } |
| 684 | 766 | |
| 685 | | |
| 686 | | /* INITIALIZE APU SYSTEM */ |
| 687 | | static DEVICE_START( nesapu ) |
| 688 | | { |
| 689 | | const nes_interface *intf = (const nes_interface *)device->static_config(); |
| 690 | | nesapu_state *info = get_safe_token(device); |
| 691 | | int rate = device->clock() / 4; |
| 692 | | int i; |
| 693 | | |
| 694 | | /* Initialize global variables */ |
| 695 | | info->samps_per_sync = rate / ATTOSECONDS_TO_HZ(device->machine().primary_screen->frame_period().attoseconds); |
| 696 | | info->buffer_size = info->samps_per_sync; |
| 697 | | info->real_rate = info->samps_per_sync * ATTOSECONDS_TO_HZ(device->machine().primary_screen->frame_period().attoseconds); |
| 698 | | info->apu_incsize = (float) (device->clock() / (float) info->real_rate); |
| 699 | | |
| 700 | | /* Use initializer calls */ |
| 701 | | create_noise(info->noise_lut, 13, NOISE_LONG); |
| 702 | | create_vbltimes(info->vbl_times,vbl_length,info->samps_per_sync); |
| 703 | | create_syncs(info, info->samps_per_sync); |
| 704 | | |
| 705 | | /* Adjust buffer size if 16 bits */ |
| 706 | | info->buffer_size+=info->samps_per_sync; |
| 707 | | |
| 708 | | /* Initialize individual chips */ |
| 709 | | (info->APU.dpcm).memory = &device->machine().device(intf->cpu_tag)->memory().space(AS_PROGRAM); |
| 710 | | |
| 711 | | info->stream = device->machine().sound().stream_alloc(*device, 0, 1, rate, info, nes_psg_update_sound); |
| 712 | | |
| 713 | | /* register for save */ |
| 714 | | for (i = 0; i < 2; i++) |
| 715 | | { |
| 716 | | device->save_item(NAME(info->APU.squ[i].regs), i); |
| 717 | | device->save_item(NAME(info->APU.squ[i].vbl_length), i); |
| 718 | | device->save_item(NAME(info->APU.squ[i].freq), i); |
| 719 | | device->save_item(NAME(info->APU.squ[i].phaseacc), i); |
| 720 | | device->save_item(NAME(info->APU.squ[i].output_vol), i); |
| 721 | | device->save_item(NAME(info->APU.squ[i].env_phase), i); |
| 722 | | device->save_item(NAME(info->APU.squ[i].sweep_phase), i); |
| 723 | | device->save_item(NAME(info->APU.squ[i].adder), i); |
| 724 | | device->save_item(NAME(info->APU.squ[i].env_vol), i); |
| 725 | | device->save_item(NAME(info->APU.squ[i].enabled), i); |
| 726 | | } |
| 727 | | |
| 728 | | device->save_item(NAME(info->APU.tri.regs)); |
| 729 | | device->save_item(NAME(info->APU.tri.linear_length)); |
| 730 | | device->save_item(NAME(info->APU.tri.vbl_length)); |
| 731 | | device->save_item(NAME(info->APU.tri.write_latency)); |
| 732 | | device->save_item(NAME(info->APU.tri.phaseacc)); |
| 733 | | device->save_item(NAME(info->APU.tri.output_vol)); |
| 734 | | device->save_item(NAME(info->APU.tri.adder)); |
| 735 | | device->save_item(NAME(info->APU.tri.counter_started)); |
| 736 | | device->save_item(NAME(info->APU.tri.enabled)); |
| 737 | | |
| 738 | | device->save_item(NAME(info->APU.noi.regs)); |
| 739 | | device->save_item(NAME(info->APU.noi.cur_pos)); |
| 740 | | device->save_item(NAME(info->APU.noi.vbl_length)); |
| 741 | | device->save_item(NAME(info->APU.noi.phaseacc)); |
| 742 | | device->save_item(NAME(info->APU.noi.output_vol)); |
| 743 | | device->save_item(NAME(info->APU.noi.env_phase)); |
| 744 | | device->save_item(NAME(info->APU.noi.env_vol)); |
| 745 | | device->save_item(NAME(info->APU.noi.enabled)); |
| 746 | | |
| 747 | | device->save_item(NAME(info->APU.dpcm.regs)); |
| 748 | | device->save_item(NAME(info->APU.dpcm.address)); |
| 749 | | device->save_item(NAME(info->APU.dpcm.length)); |
| 750 | | device->save_item(NAME(info->APU.dpcm.bits_left)); |
| 751 | | device->save_item(NAME(info->APU.dpcm.phaseacc)); |
| 752 | | device->save_item(NAME(info->APU.dpcm.output_vol)); |
| 753 | | device->save_item(NAME(info->APU.dpcm.cur_byte)); |
| 754 | | device->save_item(NAME(info->APU.dpcm.enabled)); |
| 755 | | device->save_item(NAME(info->APU.dpcm.irq_occurred)); |
| 756 | | device->save_item(NAME(info->APU.dpcm.vol)); |
| 757 | | |
| 758 | | device->save_item(NAME(info->APU.regs)); |
| 759 | | |
| 760 | | #ifdef USE_QUEUE |
| 761 | | device->save_item(NAME(info->APU.queue)); |
| 762 | | device->save_item(NAME(info->APU.head)); |
| 763 | | device->save_item(NAME(info->APU.tail)); |
| 764 | | #else |
| 765 | | device->save_item(NAME(info->APU.buf_pos)); |
| 766 | | device->save_item(NAME(info->APU.step_mode)); |
| 767 | | #endif |
| 768 | | } |
| 769 | | |
| 770 | | const device_type NES = &device_creator<nesapu_device>; |
| 771 | | |
| 772 | | nesapu_device::nesapu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 773 | | : device_t(mconfig, NES, "N2A03 APU", tag, owner, clock, "nesapu", __FILE__), |
| 774 | | device_sound_interface(mconfig, *this) |
| 775 | | { |
| 776 | | m_token = global_alloc_clear(nesapu_state); |
| 777 | | } |
| 778 | | |
| 779 | 767 | //------------------------------------------------- |
| 780 | | // device_config_complete - perform any |
| 781 | | // operations now that the configuration is |
| 782 | | // complete |
| 768 | // sound_stream_update - handle a stream update |
| 783 | 769 | //------------------------------------------------- |
| 784 | 770 | |
| 785 | | void nesapu_device::device_config_complete() |
| 771 | void nesapu_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 786 | 772 | { |
| 787 | | } |
| 773 | int accum; |
| 774 | memset( outputs[0], 0, samples*sizeof(*outputs[0]) ); |
| 788 | 775 | |
| 789 | | //------------------------------------------------- |
| 790 | | // device_start - device-specific startup |
| 791 | | //------------------------------------------------- |
| 776 | while (samples--) |
| 777 | { |
| 778 | accum = apu_square(&m_APU.squ[0]); |
| 779 | accum += apu_square(&m_APU.squ[1]); |
| 780 | accum += apu_triangle(&m_APU.tri); |
| 781 | accum += apu_noise(&m_APU.noi); |
| 782 | accum += apu_dpcm(&m_APU.dpcm); |
| 792 | 783 | |
| 793 | | void nesapu_device::device_start() |
| 794 | | { |
| 795 | | DEVICE_START_NAME( nesapu )(this); |
| 796 | | } |
| 784 | /* 8-bit clamps */ |
| 785 | if (accum > 127) |
| 786 | accum = 127; |
| 787 | else if (accum < -128) |
| 788 | accum = -128; |
| 797 | 789 | |
| 798 | | //------------------------------------------------- |
| 799 | | // sound_stream_update - handle a stream update |
| 800 | | //------------------------------------------------- |
| 801 | | |
| 802 | | void nesapu_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 803 | | { |
| 804 | | // should never get here |
| 805 | | fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); |
| 790 | *(outputs[0]++)=accum<<8; |
| 791 | } |
| 806 | 792 | } |