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);
99 //SA1.S9xOpcodes = S9xSA1OpcodesM1X1; // unused
101 S9xSA1UnpackStatus();
102 //S9xSA1FixCycles (); // unused
103 SA1.Executing = TRUE;
104 SA1.BWRAM = Memory.SRAM;
105 Memory.FillRAM [0x2225] = 0;
108 void S9xSA1SetBWRAMMemMap (uint8 val)
114 for (c = 0; c < 0x400; c += 16)
116 SA1.Map [c + 6] = SA1.Map [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
117 SA1.Map [c + 7] = SA1.Map [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
118 SA1.WriteMap [c + 6] = SA1.WriteMap [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
119 SA1.WriteMap [c + 7] = SA1.WriteMap [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
121 SA1.BWRAM = Memory.SRAM + (val & 0x7f) * 0x2000 / 4;
125 for (c = 0; c < 0x400; c += 16)
127 SA1.Map [c + 6] = SA1.Map [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM;
128 SA1.Map [c + 7] = SA1.Map [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM;
129 SA1.WriteMap [c + 6] = SA1.WriteMap [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM;
130 SA1.WriteMap [c + 7] = SA1.WriteMap [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM;
132 SA1.BWRAM = Memory.SRAM + (val & 7) * 0x2000;
136 void S9xFixSA1AfterSnapshotLoad ()
138 SA1.ShiftedPB = (uint32) SA1Registers.PB << 16;
139 SA1.ShiftedDB = (uint32) SA1Registers.DB << 16;
141 S9xSA1SetPCBase (SA1.ShiftedPB + SA1Registers.PC);
142 S9xSA1UnpackStatus ();
143 //S9xSA1FixCycles (); // unused
144 SA1.VirtualBitmapFormat = (Memory.FillRAM [0x223f] & 0x80) ? 2 : 4;
145 Memory.BWRAM = Memory.SRAM + (Memory.FillRAM [0x2224] & 7) * 0x2000;
146 S9xSA1SetBWRAMMemMap (Memory.FillRAM [0x2225]);
148 SA1.Waiting = (Memory.FillRAM [0x2200] & 0x60) != 0;
149 SA1.Executing = !SA1.Waiting;
152 uint8 S9xSA1GetByte (uint32 address)
154 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
155 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
156 return (*(GetAddress + (address & 0xffff)));
158 switch ((int) GetAddress)
160 case CMemory::MAP_PPU:
161 return (S9xGetSA1 (address & 0xffff));
162 case CMemory::MAP_LOROM_SRAM:
163 case CMemory::MAP_SA1RAM:
164 return (*(Memory.SRAM + (address & 0xffff)));
165 case CMemory::MAP_BWRAM:
166 return (*(SA1.BWRAM + ((address & 0x7fff) - 0x6000)));
167 case CMemory::MAP_BWRAM_BITMAP:
169 if (SA1.VirtualBitmapFormat == 2)
170 return ((Memory.SRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
172 return ((Memory.SRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
173 case CMemory::MAP_BWRAM_BITMAP2:
174 address = (address & 0xffff) - 0x6000;
175 if (SA1.VirtualBitmapFormat == 2)
176 return ((SA1.BWRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
178 return ((SA1.BWRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
180 case CMemory::MAP_DEBUG:
183 // printf ("R(B) %06x\n", address);
190 uint16 S9xSA1GetWord (uint32 address)
192 return (S9xSA1GetByte (address) | (S9xSA1GetByte (address + 1) << 8));
195 void S9xSA1SetByte (uint8 byte, uint32 address)
197 uint8 *Setaddress = SA1.WriteMap [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
199 if (Setaddress >= (uint8 *) CMemory::MAP_LAST)
201 *(Setaddress + (address & 0xffff)) = byte;
205 switch ((int) Setaddress)
207 case CMemory::MAP_PPU:
208 S9xSetSA1 (byte, address & 0xffff);
210 case CMemory::MAP_SA1RAM:
211 case CMemory::MAP_LOROM_SRAM:
212 *(Memory.SRAM + (address & 0xffff)) = byte;
214 case CMemory::MAP_BWRAM:
215 *(SA1.BWRAM + ((address & 0x7fff) - 0x6000)) = byte;
217 case CMemory::MAP_BWRAM_BITMAP:
219 if (SA1.VirtualBitmapFormat == 2)
221 uint8 *ptr = &Memory.SRAM [(address >> 2) & 0xffff];
222 *ptr &= ~(3 << ((address & 3) << 1));
223 *ptr |= (byte & 3) << ((address & 3) << 1);
227 uint8 *ptr = &Memory.SRAM [(address >> 1) & 0xffff];
228 *ptr &= ~(15 << ((address & 1) << 2));
229 *ptr |= (byte & 15) << ((address & 1) << 2);
232 case CMemory::MAP_BWRAM_BITMAP2:
233 address = (address & 0xffff) - 0x6000;
234 if (SA1.VirtualBitmapFormat == 2)
236 uint8 *ptr = &SA1.BWRAM [(address >> 2) & 0xffff];
237 *ptr &= ~(3 << ((address & 3) << 1));
238 *ptr |= (byte & 3) << ((address & 3) << 1);
242 uint8 *ptr = &SA1.BWRAM [(address >> 1) & 0xffff];
243 *ptr &= ~(15 << ((address & 1) << 2));
244 *ptr |= (byte & 15) << ((address & 1) << 2);
251 void S9xSA1SetWord (uint16 Word, uint32 address)
253 S9xSA1SetByte ((uint8) Word, address);
254 S9xSA1SetByte ((uint8) (Word >> 8), address + 1);
257 void S9xSA1SetPCBase (uint32 address)
259 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
260 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
262 SA1.PCBase = GetAddress;
263 SA1.PC = GetAddress + (address & 0xffff);
267 switch ((int) GetAddress)
269 case CMemory::MAP_PPU:
270 SA1.PCBase = Memory.FillRAM - 0x2000;
271 SA1.PC = SA1.PCBase + (address & 0xffff);
274 case CMemory::MAP_CPU:
275 SA1.PCBase = Memory.FillRAM - 0x4000;
276 SA1.PC = SA1.PCBase + (address & 0xffff);
279 case CMemory::MAP_DSP:
280 SA1.PCBase = Memory.FillRAM - 0x6000;
281 SA1.PC = SA1.PCBase + (address & 0xffff);
284 case CMemory::MAP_SA1RAM:
285 case CMemory::MAP_LOROM_SRAM:
286 SA1.PCBase = Memory.SRAM;
287 SA1.PC = SA1.PCBase + (address & 0xffff);
290 case CMemory::MAP_BWRAM:
291 SA1.PCBase = SA1.BWRAM - 0x6000;
292 SA1.PC = SA1.PCBase + (address & 0xffff);
294 case CMemory::MAP_HIROM_SRAM:
295 SA1.PCBase = Memory.SRAM - 0x6000;
296 SA1.PC = SA1.PCBase + (address & 0xffff);
299 case CMemory::MAP_DEBUG:
301 printf ("SBP %06x\n", address);
305 case CMemory::MAP_NONE:
306 SA1.PCBase = Memory.RAM;
307 SA1.PC = Memory.RAM + (address & 0xffff);
312 void S9xSA1ExecuteDuringSleep ()
317 while (CPU.Cycles < CPU.NextEvent)
320 CPU.Cycles += TWO_CYCLES * 2;
326 void S9xSetSA1MemMap (uint32 which1, uint8 map)
329 int start = which1 * 0x100 + 0xc00;
330 int start2 = which1 * 0x200;
335 for (c = 0; c < 0x100; c += 16)
337 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 12)];
340 for (i = c; i < c + 16; i++)
341 Memory.Map [start + i] = SA1.Map [start + i] = block;
344 for (c = 0; c < 0x200; c += 16)
346 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 11) - 0x8000];
349 for (i = c + 8; i < c + 16; i++)
350 Memory.Map [start2 + i] = SA1.Map [start2 + i] = block;
354 uint8 S9xGetSA1 (uint32 address)
356 // printf ("R: %04x\n", address);
360 return ((uint8) ((Memory.FillRAM [0x2209] & 0x5f) |
361 (CPU.IRQActive & (SA1_IRQ_SOURCE | SA1_DMA_IRQ_SOURCE))));
363 return ((Memory.FillRAM [0x2200] & 0xf) |
364 (Memory.FillRAM [0x2301] & 0xf0));
366 return ((uint8) SA1.sum);
368 return ((uint8) (SA1.sum >> 8));
370 return ((uint8) (SA1.sum >> 16));
372 return ((uint8) (SA1.sum >> 24));
374 return ((uint8) (SA1.sum >> 32));
376 return (Memory.FillRAM [0x230c]);
379 uint8 byte = Memory.FillRAM [0x230d];
381 if (Memory.FillRAM [0x2258] & 0x80)
383 S9xSA1ReadVariableLengthData (TRUE, FALSE);
389 printf ("R: %04x\n", address);
393 return (Memory.FillRAM [address]);
396 void S9xSetSA1 (uint8 byte, uint32 address)
398 //printf ("W: %02x -> %04x\n", byte, address);
402 SA1.Waiting = (byte & 0x60) != 0;
403 // SA1.Executing = !SA1.Waiting && SA1.S9xOpcodes;
405 if (!(byte & 0x20) && (Memory.FillRAM [0x2200] & 0x20))
411 Memory.FillRAM [0x2301] |= 0x80;
412 if (Memory.FillRAM [0x220a] & 0x80)
414 SA1.Flags |= IRQ_PENDING_FLAG;
415 SA1.IRQActive |= SNES_IRQ_SOURCE;
416 SA1.Executing = !SA1.Waiting;// && SA1.S9xOpcodes; // unused
421 Memory.FillRAM [0x2301] |= 0x10;
423 printf ("###SA1 NMI\n");
425 if (Memory.FillRAM [0x220a] & 0x10)
432 if (((byte ^ Memory.FillRAM [0x2201]) & 0x80) &&
433 (Memory.FillRAM [0x2300] & byte & 0x80))
435 S9xSetIRQ (SA1_IRQ_SOURCE);
437 if (((byte ^ Memory.FillRAM [0x2201]) & 0x20) &&
438 (Memory.FillRAM [0x2300] & byte & 0x20))
440 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
446 Memory.FillRAM [0x2300] &= ~0x80;
447 S9xClearIRQ (SA1_IRQ_SOURCE);
451 Memory.FillRAM [0x2300] &= ~0x20;
452 S9xClearIRQ (SA1_DMA_IRQ_SOURCE);
456 // printf ("SA1 reset vector: %04x\n", byte | (Memory.FillRAM [0x2204] << 8));
459 // printf ("SA1 reset vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2203]);
463 // printf ("SA1 NMI vector: %04x\n", byte | (Memory.FillRAM [0x2206] << 8));
466 // printf ("SA1 NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2205]);
470 // printf ("SA1 IRQ vector: %04x\n", byte | (Memory.FillRAM [0x2208] << 8));
473 // printf ("SA1 IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2207]);
477 Memory.FillRAM [0x2209] = byte;
479 Memory.FillRAM [0x2300] |= 0x80;
481 if (byte & Memory.FillRAM [0x2201] & 0x80)
483 S9xSetIRQ (SA1_IRQ_SOURCE);
487 if (((byte ^ Memory.FillRAM [0x220a]) & 0x80) &&
488 (Memory.FillRAM [0x2301] & byte & 0x80))
490 SA1.Flags |= IRQ_PENDING_FLAG;
491 SA1.IRQActive |= SNES_IRQ_SOURCE;
492 // SA1.Executing = !SA1.Waiting;
494 if (((byte ^ Memory.FillRAM [0x220a]) & 0x40) &&
495 (Memory.FillRAM [0x2301] & byte & 0x40))
497 SA1.Flags |= IRQ_PENDING_FLAG;
498 SA1.IRQActive |= TIMER_IRQ_SOURCE;
499 // SA1.Executing = !SA1.Waiting;
501 if (((byte ^ Memory.FillRAM [0x220a]) & 0x20) &&
502 (Memory.FillRAM [0x2301] & byte & 0x20))
504 SA1.Flags |= IRQ_PENDING_FLAG;
505 SA1.IRQActive |= DMA_IRQ_SOURCE;
506 // SA1.Executing = !SA1.Waiting;
508 if (((byte ^ Memory.FillRAM [0x220a]) & 0x10) &&
509 (Memory.FillRAM [0x2301] & byte & 0x10))
512 printf ("###SA1 NMI\n");
519 SA1.IRQActive &= ~SNES_IRQ_SOURCE;
520 Memory.FillRAM [0x2301] &= ~0x80;
524 SA1.IRQActive &= ~TIMER_IRQ_SOURCE;
525 Memory.FillRAM [0x2301] &= ~0x40;
529 SA1.IRQActive &= ~DMA_IRQ_SOURCE;
530 Memory.FillRAM [0x2301] &= ~0x20;
535 Memory.FillRAM [0x2301] &= ~0x10;
538 SA1.Flags &= ~IRQ_PENDING_FLAG;
541 // printf ("SNES NMI vector: %04x\n", byte | (Memory.FillRAM [0x220d] << 8));
544 // printf ("SNES NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220c]);
548 // printf ("SNES IRQ vector: %04x\n", byte | (Memory.FillRAM [0x220f] << 8));
551 // printf ("SNES IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220e]);
556 printf ("Timer %s\n", (byte & 0x80) ? "linear" : "HV");
557 printf ("Timer H-IRQ %s\n", (byte & 1) ? "enabled" : "disabled");
558 printf ("Timer V-IRQ %s\n", (byte & 2) ? "enabled" : "disabled");
562 printf ("Timer reset\n");
566 printf ("H-Timer %04x\n", byte | (Memory.FillRAM [0x2213] << 8));
571 printf ("H-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2212]);
576 printf ("V-Timer %04x\n", byte | (Memory.FillRAM [0x2215] << 8));
581 printf ("V-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2214]);
588 S9xSetSA1MemMap (address - 0x2220, byte);
589 // printf ("MMC: %02x\n", byte);
592 // printf ("BWRAM image SNES %02x -> 0x6000\n", byte);
593 Memory.BWRAM = Memory.SRAM + (byte & 7) * 0x2000;
596 // printf ("BWRAM image SA1 %02x -> 0x6000 (%02x)\n", byte, Memory.FillRAM [address]);
597 if (byte != Memory.FillRAM [address])
598 S9xSA1SetBWRAMMemMap (byte);
601 // printf ("BW-RAM SNES write %s\n", (byte & 0x80) ? "enabled" : "disabled");
604 // printf ("BW-RAM SA1 write %s\n", (byte & 0x80) ? "enabled" : "disabled");
608 // printf ("BW-RAM write protect area %02x\n", byte);
611 // printf ("I-RAM SNES write protect area %02x\n", byte);
614 // printf ("I-RAM SA1 write protect area %02x\n", byte);
618 printf ("SA1 DMA %s\n", (byte & 0x80) ? "enabled" : "disabled");
619 printf ("DMA priority %s\n", (byte & 0x40) ? "DMA" : "SA1");
620 printf ("DMA %s\n", (byte & 0x20) ? "char conv" : "normal");
621 printf ("DMA type %s\n", (byte & 0x10) ? "BW-RAM -> I-RAM" : "SA1 -> I-RAM");
622 printf ("DMA distination %s\n", (byte & 4) ? "BW-RAM" : "I-RAM");
623 printf ("DMA source %s\n", DMAsource [byte & 3]);
628 SA1.in_char_dma = FALSE;
630 printf ("CHDEND %s\n", (byte & 0x80) ? "complete" : "incomplete");
631 printf ("DMA colour mode %d\n", byte & 3);
632 printf ("virtual VRAM width %d\n", (byte >> 2) & 7);
638 Memory.FillRAM [address] = byte;
640 printf ("DMA source start %06x\n",
641 Memory.FillRAM [0x2232] | (Memory.FillRAM [0x2233] << 8) |
642 (Memory.FillRAM [0x2234] << 16));
646 Memory.FillRAM [address] = byte;
649 Memory.FillRAM [address] = byte;
650 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x80)
652 // Normal DMA to I-RAM
656 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xb0)
658 Memory.FillRAM [0x2300] |= 0x20;
659 if (Memory.FillRAM [0x2201] & 0x20)
660 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
661 SA1.in_char_dma = TRUE;
665 Memory.FillRAM [address] = byte;
666 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x84)
668 // Normal DMA to BW-RAM
672 printf ("DMA dest address %06x\n",
673 Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8) |
674 (Memory.FillRAM [0x2237] << 16));
679 Memory.FillRAM [address] = byte;
681 printf ("DMA length %04x\n",
682 Memory.FillRAM [0x2238] | (Memory.FillRAM [0x2239] << 8));
686 SA1.VirtualBitmapFormat = (byte & 0x80) ? 2 : 4;
687 //printf ("virtual VRAM depth %d\n", (byte & 0x80) ? 2 : 4);
690 case 0x2240: case 0x2241: case 0x2242: case 0x2243:
691 case 0x2244: case 0x2245: case 0x2246: case 0x2247:
692 case 0x2248: case 0x2249: case 0x224a: case 0x224b:
693 case 0x224c: case 0x224d: case 0x224e:
695 if (!(SA1.Flags & TRACE_FLAG))
701 Memory.FillRAM [address] = byte;
705 Memory.FillRAM [address] = byte;
706 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xa0)
708 // Char conversion 2 DMA enabled
709 memmove (&Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + SA1.in_char_dma * 16,
710 &Memory.FillRAM [0x2240], 16);
711 SA1.in_char_dma = (SA1.in_char_dma + 1) & 7;
712 if ((SA1.in_char_dma & 3) == 0)
721 SA1.arithmetic_op = byte & 3;
725 SA1.op1 = (SA1.op1 & 0xff00) | byte;
728 SA1.op1 = (SA1.op1 & 0xff) | (byte << 8);
731 SA1.op2 = (SA1.op2 & 0xff00) | byte;
734 SA1.op2 = (SA1.op2 & 0xff) | (byte << 8);
735 switch (SA1.arithmetic_op)
738 SA1.sum = SA1.op1 * SA1.op2;
742 SA1.sum = SA1.op1 << 16;
745 SA1.sum = (SA1.op1 / (int) ((uint16) SA1.op2)) |
746 ((SA1.op1 % (int) ((uint16) SA1.op2)) << 16);
750 default: // cumulative sum
751 SA1.sum += SA1.op1 * SA1.op2;
752 if (SA1.sum & ((int64) 0xffffff << 32))
757 case 0x2258: // Variable bit-field length/auto inc/start.
758 Memory.FillRAM [0x2258] = byte;
759 S9xSA1ReadVariableLengthData (TRUE, FALSE);
763 case 0x225b: // Variable bit-field start address
764 Memory.FillRAM [address] = byte;
766 SA1.variable_bit_pos = 0;
767 S9xSA1ReadVariableLengthData (FALSE, TRUE);
770 // printf ("W: %02x->%04x\n", byte, address);
773 if (address >= 0x2200 && address <= 0x22ff)
774 Memory.FillRAM [address] = byte;
777 static void S9xSA1CharConv2 ()
779 uint32 dest = Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8);
780 uint32 offset = (SA1.in_char_dma & 7) ? 0 : 1;
781 int depth = (Memory.FillRAM [0x2231] & 3) == 0 ? 8 :
782 (Memory.FillRAM [0x2231] & 3) == 1 ? 4 : 2;
783 int bytes_per_char = 8 * depth;
784 uint8 *p = &Memory.FillRAM [0x3000] + dest + offset * bytes_per_char;
785 uint8 *q = &Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + offset * 64;
794 for (int l = 0; l < 8; l++, q += 8)
796 for (int b = 0; b < 8; b++)
799 *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1);
800 *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1);
801 *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1);
802 *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1);
803 *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1);
804 *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1);
805 *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1);
806 *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1);
814 static void S9xSA1DMA ()
816 uint32 src = Memory.FillRAM [0x2232] |
817 (Memory.FillRAM [0x2233] << 8) |
818 (Memory.FillRAM [0x2234] << 16);
819 uint32 dst = Memory.FillRAM [0x2235] |
820 (Memory.FillRAM [0x2236] << 8) |
821 (Memory.FillRAM [0x2237] << 16);
822 uint32 len = Memory.FillRAM [0x2238] |
823 (Memory.FillRAM [0x2239] << 8);
828 switch (Memory.FillRAM [0x2230] & 3)
831 s = SA1.Map [(src >> MEMMAP_SHIFT) & MEMMAP_MASK];
832 if (s >= (uint8 *) CMemory::MAP_LAST)
835 s = Memory.ROM + (src & 0xffff);
838 src &= CPU.Memory_SRAMMask;
839 len &= CPU.Memory_SRAMMask;
840 s = Memory.SRAM + src;
846 s = &Memory.FillRAM [0x3000] + src;
850 if (Memory.FillRAM [0x2230] & 4)
852 dst &= CPU.Memory_SRAMMask;
853 len &= CPU.Memory_SRAMMask;
854 d = Memory.SRAM + dst;
860 d = &Memory.FillRAM [0x3000] + dst;
863 Memory.FillRAM [0x2301] |= 0x20;
865 if (Memory.FillRAM [0x220a] & 0x20)
867 SA1.Flags |= IRQ_PENDING_FLAG;
868 SA1.IRQActive |= DMA_IRQ_SOURCE;
869 // SA1.Executing = !SA1.Waiting;
873 void S9xSA1ReadVariableLengthData (bool8 inc, bool8 no_shift)
875 uint32 addr = Memory.FillRAM [0x2259] |
876 (Memory.FillRAM [0x225a] << 8) |
877 (Memory.FillRAM [0x225b] << 16);
878 uint8 shift = Memory.FillRAM [0x2258] & 15;
886 uint8 s = shift + SA1.variable_bit_pos;
890 addr += (s >> 4) << 1;
893 uint32 data = S9xSA1GetWord (addr) |
894 (S9xSA1GetWord (addr + 2) << 16);
897 Memory.FillRAM [0x230c] = (uint8) data;
898 Memory.FillRAM [0x230d] = (uint8) (data >> 8);
901 SA1.variable_bit_pos = (SA1.variable_bit_pos + shift) & 15;
902 Memory.FillRAM [0x2259] = (uint8) addr;
903 Memory.FillRAM [0x225a] = (uint8) (addr >> 8);
904 Memory.FillRAM [0x225b] = (uint8) (addr >> 16);