2 * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
4 * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5 * Jerremy Koot (jkoot@snes9x.com)
7 * Super FX C emulator code
8 * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
10 * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
12 * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13 * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14 * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
16 * DOS port code contains the works of other authors. See headers in
19 * Snes9x homepage: http://www.snes9x.com
21 * Permission to use, copy, modify and distribute Snes9x in both binary and
22 * source form, for non-commercial purposes, is hereby granted without fee,
23 * providing that this license information and copyright notice appear with
24 * all copies and any derived work.
26 * This software is provided 'as-is', without any express or implied
27 * warranty. In no event shall the authors be held liable for any damages
28 * arising from the use of this software.
30 * Snes9x is freeware for PERSONAL USE only. Commercial users should
31 * seek permission of the copyright holders first. Commercial use includes
32 * charging money for Snes9x or software derived from Snes9x.
34 * The copyright holders request that bug fixes and improvements to the code
35 * should be forwarded to them so everyone can benefit from the modifications
38 * Super NES and Super Nintendo Entertainment System are trademarks of
39 * Nintendo Co., Limited and its subsidiary companies.
51 static void S9xSA1CharConv2 ();
52 static void S9xSA1DMA ();
53 static void S9xSA1ReadVariableLengthData (bool8 inc, bool8 no_shift);
57 SA1.NMIActive = FALSE;
58 SA1.IRQActive = FALSE;
59 SA1.WaitingForInterrupt = FALSE;
62 SA1.Executing = FALSE;
63 memset (&Memory.FillRAM [0x2200], 0, 0x200);
64 Memory.FillRAM [0x2200] = 0x20;
65 Memory.FillRAM [0x2220] = 0x00;
66 Memory.FillRAM [0x2221] = 0x01;
67 Memory.FillRAM [0x2222] = 0x02;
68 Memory.FillRAM [0x2223] = 0x03;
69 Memory.FillRAM [0x2228] = 0xff;
72 SA1.arithmetic_op = 0;
80 SA1Registers.PC = Memory.FillRAM [0x2203] |
81 (Memory.FillRAM [0x2204] << 8);
85 SA1Registers.SL = 0xFF;
92 SA1SetFlags (MemoryFlag | IndexFlag | IRQ | Emulation);
93 SA1ClearFlags (Decimal);
95 SA1.WaitingForInterrupt = FALSE;
98 S9xSA1SetPCBase (SA1Registers.PC);
100 #if !CONF_BUILD_ASM_SA1
101 SA1.S9xOpcodes = S9xSA1OpcodesM1X1;
102 S9xSA1UnpackStatus();
106 SA1.Executing = TRUE;
107 SA1.BWRAM = Memory.SRAM;
108 Memory.FillRAM [0x2225] = 0;
111 void S9xSA1SetBWRAMMemMap (uint8 val)
117 for (c = 0; c < 0x400; c += 16)
119 SA1.Map [c + 6] = SA1.Map [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
120 SA1.Map [c + 7] = SA1.Map [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
121 SA1.WriteMap [c + 6] = SA1.WriteMap [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
122 SA1.WriteMap [c + 7] = SA1.WriteMap [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
124 SA1.BWRAM = Memory.SRAM + (val & 0x7f) * 0x2000 / 4;
128 for (c = 0; c < 0x400; c += 16)
130 SA1.Map [c + 6] = SA1.Map [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM;
131 SA1.Map [c + 7] = SA1.Map [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM;
132 SA1.WriteMap [c + 6] = SA1.WriteMap [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM;
133 SA1.WriteMap [c + 7] = SA1.WriteMap [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM;
135 SA1.BWRAM = Memory.SRAM + (val & 7) * 0x2000;
139 void S9xFixSA1AfterSnapshotLoad ()
141 SA1.ShiftedPB = (uint32) SA1Registers.PB << 16;
142 SA1.ShiftedDB = (uint32) SA1Registers.DB << 16;
144 S9xSA1SetPCBase (SA1.ShiftedPB + SA1Registers.PC);
145 #if !CONF_BUILD_ASM_SA1
146 S9xSA1UnpackStatus ();
149 SA1.VirtualBitmapFormat = (Memory.FillRAM [0x223f] & 0x80) ? 2 : 4;
150 Memory.BWRAM = Memory.SRAM + (Memory.FillRAM [0x2224] & 7) * 0x2000;
151 S9xSA1SetBWRAMMemMap (Memory.FillRAM [0x2225]);
153 SA1.Waiting = (Memory.FillRAM [0x2200] & 0x60) != 0;
154 SA1.Executing = !SA1.Waiting;
157 uint8 S9xSA1GetByte (uint32 address)
159 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
160 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
161 return (*(GetAddress + (address & 0xffff)));
163 switch ((CMemory::Types)(intptr_t) GetAddress)
165 case CMemory::MAP_PPU:
166 return (S9xGetSA1 (address & 0xffff));
167 case CMemory::MAP_LOROM_SRAM:
168 case CMemory::MAP_SA1RAM:
169 return (*(Memory.SRAM + (address & 0xffff)));
170 case CMemory::MAP_BWRAM:
171 return (*(SA1.BWRAM + ((address & 0x7fff) - 0x6000)));
172 case CMemory::MAP_BWRAM_BITMAP:
174 if (SA1.VirtualBitmapFormat == 2)
175 return ((Memory.SRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
177 return ((Memory.SRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
178 case CMemory::MAP_BWRAM_BITMAP2:
179 address = (address & 0xffff) - 0x6000;
180 if (SA1.VirtualBitmapFormat == 2)
181 return ((SA1.BWRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
183 return ((SA1.BWRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
185 case CMemory::MAP_DEBUG:
188 // printf ("R(B) %06x\n", address);
195 uint16 S9xSA1GetWord (uint32 address)
197 return (S9xSA1GetByte (address) | (S9xSA1GetByte (address + 1) << 8));
200 void S9xSA1SetByte (uint8 byte, uint32 address)
202 uint8 *SetAddress = SA1.WriteMap [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
204 if (SetAddress >= (uint8 *) CMemory::MAP_LAST)
206 *(SetAddress + (address & 0xffff)) = byte;
210 switch ((CMemory::Types)(intptr_t) SetAddress)
212 case CMemory::MAP_PPU:
213 S9xSetSA1 (byte, address & 0xffff);
215 case CMemory::MAP_SA1RAM:
216 case CMemory::MAP_LOROM_SRAM:
217 *(Memory.SRAM + (address & 0xffff)) = byte;
219 case CMemory::MAP_BWRAM:
220 *(SA1.BWRAM + ((address & 0x7fff) - 0x6000)) = byte;
222 case CMemory::MAP_BWRAM_BITMAP:
224 if (SA1.VirtualBitmapFormat == 2)
226 uint8 *ptr = &Memory.SRAM [(address >> 2) & 0xffff];
227 *ptr &= ~(3 << ((address & 3) << 1));
228 *ptr |= (byte & 3) << ((address & 3) << 1);
232 uint8 *ptr = &Memory.SRAM [(address >> 1) & 0xffff];
233 *ptr &= ~(15 << ((address & 1) << 2));
234 *ptr |= (byte & 15) << ((address & 1) << 2);
237 case CMemory::MAP_BWRAM_BITMAP2:
238 address = (address & 0xffff) - 0x6000;
239 if (SA1.VirtualBitmapFormat == 2)
241 uint8 *ptr = &SA1.BWRAM [(address >> 2) & 0xffff];
242 *ptr &= ~(3 << ((address & 3) << 1));
243 *ptr |= (byte & 3) << ((address & 3) << 1);
247 uint8 *ptr = &SA1.BWRAM [(address >> 1) & 0xffff];
248 *ptr &= ~(15 << ((address & 1) << 2));
249 *ptr |= (byte & 15) << ((address & 1) << 2);
256 void S9xSA1SetWord (uint16 Word, uint32 address)
258 S9xSA1SetByte ((uint8) Word, address);
259 S9xSA1SetByte ((uint8) (Word >> 8), address + 1);
262 void S9xSA1SetPCBase (uint32 address)
264 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
265 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
267 SA1.PCBase = GetAddress;
268 SA1.PC = GetAddress + (address & 0xffff);
272 switch ((CMemory::Types)(intptr_t) GetAddress)
274 case CMemory::MAP_PPU:
275 SA1.PCBase = Memory.FillRAM - 0x2000;
276 SA1.PC = SA1.PCBase + (address & 0xffff);
279 case CMemory::MAP_CPU:
280 SA1.PCBase = Memory.FillRAM - 0x4000;
281 SA1.PC = SA1.PCBase + (address & 0xffff);
284 case CMemory::MAP_DSP:
285 SA1.PCBase = Memory.FillRAM - 0x6000;
286 SA1.PC = SA1.PCBase + (address & 0xffff);
289 case CMemory::MAP_SA1RAM:
290 case CMemory::MAP_LOROM_SRAM:
291 SA1.PCBase = Memory.SRAM;
292 SA1.PC = SA1.PCBase + (address & 0xffff);
295 case CMemory::MAP_BWRAM:
296 SA1.PCBase = SA1.BWRAM - 0x6000;
297 SA1.PC = SA1.PCBase + (address & 0xffff);
299 case CMemory::MAP_HIROM_SRAM:
300 SA1.PCBase = Memory.SRAM - 0x6000;
301 SA1.PC = SA1.PCBase + (address & 0xffff);
304 case CMemory::MAP_DEBUG:
306 printf ("SBP %06x\n", address);
310 case CMemory::MAP_NONE:
311 SA1.PCBase = Memory.RAM;
312 SA1.PC = Memory.RAM + (address & 0xffff);
317 void S9xSA1ExecuteDuringSleep ()
322 while (CPU.Cycles < CPU.NextEvent)
325 CPU.Cycles += TWO_CYCLES * 2;
331 void S9xSetSA1MemMap (uint32 which1, uint8 map)
334 int start = which1 * 0x100 + 0xc00;
335 int start2 = which1 * 0x200;
340 for (c = 0; c < 0x100; c += 16)
342 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 12)];
345 for (i = c; i < c + 16; i++)
346 Memory.Map [start + i] = SA1.Map [start + i] = block;
349 for (c = 0; c < 0x200; c += 16)
351 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 11) - 0x8000];
354 for (i = c + 8; i < c + 16; i++)
355 Memory.Map [start2 + i] = SA1.Map [start2 + i] = block;
359 uint8 S9xGetSA1 (uint32 address)
361 // printf ("R: %04x\n", address);
365 return ((uint8) ((Memory.FillRAM [0x2209] & 0x5f) |
366 (CPU.IRQActive & (SA1_IRQ_SOURCE | SA1_DMA_IRQ_SOURCE))));
368 return ((Memory.FillRAM [0x2200] & 0xf) |
369 (Memory.FillRAM [0x2301] & 0xf0));
371 return ((uint8) SA1.sum);
373 return ((uint8) (SA1.sum >> 8));
375 return ((uint8) (SA1.sum >> 16));
377 return ((uint8) (SA1.sum >> 24));
379 return ((uint8) (SA1.sum >> 32));
381 return (Memory.FillRAM [0x230c]);
384 uint8 byte = Memory.FillRAM [0x230d];
386 if (Memory.FillRAM [0x2258] & 0x80)
388 S9xSA1ReadVariableLengthData (TRUE, FALSE);
394 printf ("R: %04x\n", address);
398 return (Memory.FillRAM [address]);
401 void S9xSetSA1 (uint8 byte, uint32 address)
403 //printf ("W: %02x -> %04x\n", byte, address);
407 SA1.Waiting = (byte & 0x60) != 0;
408 // SA1.Executing = !SA1.Waiting && SA1.S9xOpcodes;
410 if (!(byte & 0x20) && (Memory.FillRAM [0x2200] & 0x20))
416 Memory.FillRAM [0x2301] |= 0x80;
417 if (Memory.FillRAM [0x220a] & 0x80)
419 SA1.Flags |= IRQ_PENDING_FLAG;
420 SA1.IRQActive |= SNES_IRQ_SOURCE;
421 SA1.Executing = !SA1.Waiting;// && SA1.S9xOpcodes; // unused
426 Memory.FillRAM [0x2301] |= 0x10;
428 printf ("###SA1 NMI\n");
430 if (Memory.FillRAM [0x220a] & 0x10)
437 if (((byte ^ Memory.FillRAM [0x2201]) & 0x80) &&
438 (Memory.FillRAM [0x2300] & byte & 0x80))
440 S9xSetIRQ (SA1_IRQ_SOURCE);
442 if (((byte ^ Memory.FillRAM [0x2201]) & 0x20) &&
443 (Memory.FillRAM [0x2300] & byte & 0x20))
445 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
451 Memory.FillRAM [0x2300] &= ~0x80;
452 S9xClearIRQ (SA1_IRQ_SOURCE);
456 Memory.FillRAM [0x2300] &= ~0x20;
457 S9xClearIRQ (SA1_DMA_IRQ_SOURCE);
461 // printf ("SA1 reset vector: %04x\n", byte | (Memory.FillRAM [0x2204] << 8));
464 // printf ("SA1 reset vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2203]);
468 // printf ("SA1 NMI vector: %04x\n", byte | (Memory.FillRAM [0x2206] << 8));
471 // printf ("SA1 NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2205]);
475 // printf ("SA1 IRQ vector: %04x\n", byte | (Memory.FillRAM [0x2208] << 8));
478 // printf ("SA1 IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2207]);
482 Memory.FillRAM [0x2209] = byte;
484 Memory.FillRAM [0x2300] |= 0x80;
486 if (byte & Memory.FillRAM [0x2201] & 0x80)
488 S9xSetIRQ (SA1_IRQ_SOURCE);
492 if (((byte ^ Memory.FillRAM [0x220a]) & 0x80) &&
493 (Memory.FillRAM [0x2301] & byte & 0x80))
495 SA1.Flags |= IRQ_PENDING_FLAG;
496 SA1.IRQActive |= SNES_IRQ_SOURCE;
497 // SA1.Executing = !SA1.Waiting;
499 if (((byte ^ Memory.FillRAM [0x220a]) & 0x40) &&
500 (Memory.FillRAM [0x2301] & byte & 0x40))
502 SA1.Flags |= IRQ_PENDING_FLAG;
503 SA1.IRQActive |= TIMER_IRQ_SOURCE;
504 // SA1.Executing = !SA1.Waiting;
506 if (((byte ^ Memory.FillRAM [0x220a]) & 0x20) &&
507 (Memory.FillRAM [0x2301] & byte & 0x20))
509 SA1.Flags |= IRQ_PENDING_FLAG;
510 SA1.IRQActive |= DMA_IRQ_SOURCE;
511 // SA1.Executing = !SA1.Waiting;
513 if (((byte ^ Memory.FillRAM [0x220a]) & 0x10) &&
514 (Memory.FillRAM [0x2301] & byte & 0x10))
517 printf ("###SA1 NMI\n");
524 SA1.IRQActive &= ~SNES_IRQ_SOURCE;
525 Memory.FillRAM [0x2301] &= ~0x80;
529 SA1.IRQActive &= ~TIMER_IRQ_SOURCE;
530 Memory.FillRAM [0x2301] &= ~0x40;
534 SA1.IRQActive &= ~DMA_IRQ_SOURCE;
535 Memory.FillRAM [0x2301] &= ~0x20;
540 Memory.FillRAM [0x2301] &= ~0x10;
543 SA1.Flags &= ~IRQ_PENDING_FLAG;
546 // printf ("SNES NMI vector: %04x\n", byte | (Memory.FillRAM [0x220d] << 8));
549 // printf ("SNES NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220c]);
553 // printf ("SNES IRQ vector: %04x\n", byte | (Memory.FillRAM [0x220f] << 8));
556 // printf ("SNES IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220e]);
561 printf ("Timer %s\n", (byte & 0x80) ? "linear" : "HV");
562 printf ("Timer H-IRQ %s\n", (byte & 1) ? "enabled" : "disabled");
563 printf ("Timer V-IRQ %s\n", (byte & 2) ? "enabled" : "disabled");
567 printf ("Timer reset\n");
571 printf ("H-Timer %04x\n", byte | (Memory.FillRAM [0x2213] << 8));
576 printf ("H-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2212]);
581 printf ("V-Timer %04x\n", byte | (Memory.FillRAM [0x2215] << 8));
586 printf ("V-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2214]);
593 S9xSetSA1MemMap (address - 0x2220, byte);
594 // printf ("MMC: %02x\n", byte);
597 // printf ("BWRAM image SNES %02x -> 0x6000\n", byte);
598 Memory.BWRAM = Memory.SRAM + (byte & 7) * 0x2000;
601 // printf ("BWRAM image SA1 %02x -> 0x6000 (%02x)\n", byte, Memory.FillRAM [address]);
602 if (byte != Memory.FillRAM [address])
603 S9xSA1SetBWRAMMemMap (byte);
606 // printf ("BW-RAM SNES write %s\n", (byte & 0x80) ? "enabled" : "disabled");
609 // printf ("BW-RAM SA1 write %s\n", (byte & 0x80) ? "enabled" : "disabled");
613 // printf ("BW-RAM write protect area %02x\n", byte);
616 // printf ("I-RAM SNES write protect area %02x\n", byte);
619 // printf ("I-RAM SA1 write protect area %02x\n", byte);
623 printf ("SA1 DMA %s\n", (byte & 0x80) ? "enabled" : "disabled");
624 printf ("DMA priority %s\n", (byte & 0x40) ? "DMA" : "SA1");
625 printf ("DMA %s\n", (byte & 0x20) ? "char conv" : "normal");
626 printf ("DMA type %s\n", (byte & 0x10) ? "BW-RAM -> I-RAM" : "SA1 -> I-RAM");
627 printf ("DMA distination %s\n", (byte & 4) ? "BW-RAM" : "I-RAM");
628 printf ("DMA source %s\n", DMAsource [byte & 3]);
633 SA1.in_char_dma = FALSE;
635 printf ("CHDEND %s\n", (byte & 0x80) ? "complete" : "incomplete");
636 printf ("DMA colour mode %d\n", byte & 3);
637 printf ("virtual VRAM width %d\n", (byte >> 2) & 7);
643 Memory.FillRAM [address] = byte;
645 printf ("DMA source start %06x\n",
646 Memory.FillRAM [0x2232] | (Memory.FillRAM [0x2233] << 8) |
647 (Memory.FillRAM [0x2234] << 16));
651 Memory.FillRAM [address] = byte;
654 Memory.FillRAM [address] = byte;
655 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x80)
657 // Normal DMA to I-RAM
661 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xb0)
663 Memory.FillRAM [0x2300] |= 0x20;
664 if (Memory.FillRAM [0x2201] & 0x20)
665 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
666 SA1.in_char_dma = TRUE;
670 Memory.FillRAM [address] = byte;
671 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x84)
673 // Normal DMA to BW-RAM
677 printf ("DMA dest address %06x\n",
678 Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8) |
679 (Memory.FillRAM [0x2237] << 16));
684 Memory.FillRAM [address] = byte;
686 printf ("DMA length %04x\n",
687 Memory.FillRAM [0x2238] | (Memory.FillRAM [0x2239] << 8));
691 SA1.VirtualBitmapFormat = (byte & 0x80) ? 2 : 4;
692 //printf ("virtual VRAM depth %d\n", (byte & 0x80) ? 2 : 4);
695 case 0x2240: case 0x2241: case 0x2242: case 0x2243:
696 case 0x2244: case 0x2245: case 0x2246: case 0x2247:
697 case 0x2248: case 0x2249: case 0x224a: case 0x224b:
698 case 0x224c: case 0x224d: case 0x224e:
700 if (!(SA1.Flags & TRACE_FLAG))
706 Memory.FillRAM [address] = byte;
710 Memory.FillRAM [address] = byte;
711 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xa0)
713 // Char conversion 2 DMA enabled
714 memmove (&Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + SA1.in_char_dma * 16,
715 &Memory.FillRAM [0x2240], 16);
716 SA1.in_char_dma = (SA1.in_char_dma + 1) & 7;
717 if ((SA1.in_char_dma & 3) == 0)
726 SA1.arithmetic_op = byte & 3;
730 SA1.op1 = (SA1.op1 & 0xff00) | byte;
733 SA1.op1 = (SA1.op1 & 0xff) | (byte << 8);
736 SA1.op2 = (SA1.op2 & 0xff00) | byte;
739 SA1.op2 = (SA1.op2 & 0xff) | (byte << 8);
740 switch (SA1.arithmetic_op)
743 SA1.sum = SA1.op1 * SA1.op2;
747 SA1.sum = SA1.op1 << 16;
750 SA1.sum = (SA1.op1 / (int) ((uint16) SA1.op2)) |
751 ((SA1.op1 % (int) ((uint16) SA1.op2)) << 16);
755 default: // cumulative sum
756 SA1.sum += SA1.op1 * SA1.op2;
757 if (SA1.sum & ((int64) 0xffffff << 32))
762 case 0x2258: // Variable bit-field length/auto inc/start.
763 Memory.FillRAM [0x2258] = byte;
764 S9xSA1ReadVariableLengthData (TRUE, FALSE);
768 case 0x225b: // Variable bit-field start address
769 Memory.FillRAM [address] = byte;
771 SA1.variable_bit_pos = 0;
772 S9xSA1ReadVariableLengthData (FALSE, TRUE);
775 // printf ("W: %02x->%04x\n", byte, address);
778 if (address >= 0x2200 && address <= 0x22ff)
779 Memory.FillRAM [address] = byte;
782 static void S9xSA1CharConv2 ()
784 uint32 dest = Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8);
785 uint32 offset = (SA1.in_char_dma & 7) ? 0 : 1;
786 int depth = (Memory.FillRAM [0x2231] & 3) == 0 ? 8 :
787 (Memory.FillRAM [0x2231] & 3) == 1 ? 4 : 2;
788 int bytes_per_char = 8 * depth;
789 uint8 *p = &Memory.FillRAM [0x3000] + dest + offset * bytes_per_char;
790 uint8 *q = &Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + offset * 64;
799 for (int l = 0; l < 8; l++, q += 8)
801 for (int b = 0; b < 8; b++)
804 *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1);
805 *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1);
806 *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1);
807 *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1);
808 *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1);
809 *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1);
810 *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1);
811 *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1);
819 static void S9xSA1DMA ()
821 uint32 src = Memory.FillRAM [0x2232] |
822 (Memory.FillRAM [0x2233] << 8) |
823 (Memory.FillRAM [0x2234] << 16);
824 uint32 dst = Memory.FillRAM [0x2235] |
825 (Memory.FillRAM [0x2236] << 8) |
826 (Memory.FillRAM [0x2237] << 16);
827 uint32 len = Memory.FillRAM [0x2238] |
828 (Memory.FillRAM [0x2239] << 8);
833 switch (Memory.FillRAM [0x2230] & 3)
836 s = SA1.Map [(src >> MEMMAP_SHIFT) & MEMMAP_MASK];
837 if (s >= (uint8 *) CMemory::MAP_LAST)
840 s = Memory.ROM + (src & 0xffff);
843 src &= CPU.Memory_SRAMMask;
844 len &= CPU.Memory_SRAMMask;
845 s = Memory.SRAM + src;
851 s = &Memory.FillRAM [0x3000] + src;
855 if (Memory.FillRAM [0x2230] & 4)
857 dst &= CPU.Memory_SRAMMask;
858 len &= CPU.Memory_SRAMMask;
859 d = Memory.SRAM + dst;
865 d = &Memory.FillRAM [0x3000] + dst;
868 Memory.FillRAM [0x2301] |= 0x20;
870 if (Memory.FillRAM [0x220a] & 0x20)
872 SA1.Flags |= IRQ_PENDING_FLAG;
873 SA1.IRQActive |= DMA_IRQ_SOURCE;
874 // SA1.Executing = !SA1.Waiting;
878 void S9xSA1ReadVariableLengthData (bool8 inc, bool8 no_shift)
880 uint32 addr = Memory.FillRAM [0x2259] |
881 (Memory.FillRAM [0x225a] << 8) |
882 (Memory.FillRAM [0x225b] << 16);
883 uint8 shift = Memory.FillRAM [0x2258] & 15;
891 uint8 s = shift + SA1.variable_bit_pos;
895 addr += (s >> 4) << 1;
898 uint32 data = S9xSA1GetWord (addr) |
899 (S9xSA1GetWord (addr + 2) << 16);
902 Memory.FillRAM [0x230c] = (uint8) data;
903 Memory.FillRAM [0x230d] = (uint8) (data >> 8);
906 SA1.variable_bit_pos = (SA1.variable_bit_pos + shift) & 15;
907 Memory.FillRAM [0x2259] = (uint8) addr;
908 Memory.FillRAM [0x225a] = (uint8) (addr >> 8);
909 Memory.FillRAM [0x225b] = (uint8) (addr >> 16);