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 S9xSA1UnpackStatus ();
146 //S9xSA1FixCycles (); // unused
147 SA1.VirtualBitmapFormat = (Memory.FillRAM [0x223f] & 0x80) ? 2 : 4;
148 Memory.BWRAM = Memory.SRAM + (Memory.FillRAM [0x2224] & 7) * 0x2000;
149 S9xSA1SetBWRAMMemMap (Memory.FillRAM [0x2225]);
151 SA1.Waiting = (Memory.FillRAM [0x2200] & 0x60) != 0;
152 SA1.Executing = !SA1.Waiting;
155 uint8 S9xSA1GetByte (uint32 address)
157 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
158 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
159 return (*(GetAddress + (address & 0xffff)));
161 switch ((int) GetAddress)
163 case CMemory::MAP_PPU:
164 return (S9xGetSA1 (address & 0xffff));
165 case CMemory::MAP_LOROM_SRAM:
166 case CMemory::MAP_SA1RAM:
167 return (*(Memory.SRAM + (address & 0xffff)));
168 case CMemory::MAP_BWRAM:
169 return (*(SA1.BWRAM + ((address & 0x7fff) - 0x6000)));
170 case CMemory::MAP_BWRAM_BITMAP:
172 if (SA1.VirtualBitmapFormat == 2)
173 return ((Memory.SRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
175 return ((Memory.SRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
176 case CMemory::MAP_BWRAM_BITMAP2:
177 address = (address & 0xffff) - 0x6000;
178 if (SA1.VirtualBitmapFormat == 2)
179 return ((SA1.BWRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
181 return ((SA1.BWRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
183 case CMemory::MAP_DEBUG:
186 // printf ("R(B) %06x\n", address);
193 uint16 S9xSA1GetWord (uint32 address)
195 return (S9xSA1GetByte (address) | (S9xSA1GetByte (address + 1) << 8));
198 void S9xSA1SetByte (uint8 byte, uint32 address)
200 uint8 *Setaddress = SA1.WriteMap [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
202 if (Setaddress >= (uint8 *) CMemory::MAP_LAST)
204 *(Setaddress + (address & 0xffff)) = byte;
208 switch ((int) Setaddress)
210 case CMemory::MAP_PPU:
211 S9xSetSA1 (byte, address & 0xffff);
213 case CMemory::MAP_SA1RAM:
214 case CMemory::MAP_LOROM_SRAM:
215 *(Memory.SRAM + (address & 0xffff)) = byte;
217 case CMemory::MAP_BWRAM:
218 *(SA1.BWRAM + ((address & 0x7fff) - 0x6000)) = byte;
220 case CMemory::MAP_BWRAM_BITMAP:
222 if (SA1.VirtualBitmapFormat == 2)
224 uint8 *ptr = &Memory.SRAM [(address >> 2) & 0xffff];
225 *ptr &= ~(3 << ((address & 3) << 1));
226 *ptr |= (byte & 3) << ((address & 3) << 1);
230 uint8 *ptr = &Memory.SRAM [(address >> 1) & 0xffff];
231 *ptr &= ~(15 << ((address & 1) << 2));
232 *ptr |= (byte & 15) << ((address & 1) << 2);
235 case CMemory::MAP_BWRAM_BITMAP2:
236 address = (address & 0xffff) - 0x6000;
237 if (SA1.VirtualBitmapFormat == 2)
239 uint8 *ptr = &SA1.BWRAM [(address >> 2) & 0xffff];
240 *ptr &= ~(3 << ((address & 3) << 1));
241 *ptr |= (byte & 3) << ((address & 3) << 1);
245 uint8 *ptr = &SA1.BWRAM [(address >> 1) & 0xffff];
246 *ptr &= ~(15 << ((address & 1) << 2));
247 *ptr |= (byte & 15) << ((address & 1) << 2);
254 void S9xSA1SetWord (uint16 Word, uint32 address)
256 S9xSA1SetByte ((uint8) Word, address);
257 S9xSA1SetByte ((uint8) (Word >> 8), address + 1);
260 void S9xSA1SetPCBase (uint32 address)
262 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
263 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
265 SA1.PCBase = GetAddress;
266 SA1.PC = GetAddress + (address & 0xffff);
270 switch ((int) GetAddress)
272 case CMemory::MAP_PPU:
273 SA1.PCBase = Memory.FillRAM - 0x2000;
274 SA1.PC = SA1.PCBase + (address & 0xffff);
277 case CMemory::MAP_CPU:
278 SA1.PCBase = Memory.FillRAM - 0x4000;
279 SA1.PC = SA1.PCBase + (address & 0xffff);
282 case CMemory::MAP_DSP:
283 SA1.PCBase = Memory.FillRAM - 0x6000;
284 SA1.PC = SA1.PCBase + (address & 0xffff);
287 case CMemory::MAP_SA1RAM:
288 case CMemory::MAP_LOROM_SRAM:
289 SA1.PCBase = Memory.SRAM;
290 SA1.PC = SA1.PCBase + (address & 0xffff);
293 case CMemory::MAP_BWRAM:
294 SA1.PCBase = SA1.BWRAM - 0x6000;
295 SA1.PC = SA1.PCBase + (address & 0xffff);
297 case CMemory::MAP_HIROM_SRAM:
298 SA1.PCBase = Memory.SRAM - 0x6000;
299 SA1.PC = SA1.PCBase + (address & 0xffff);
302 case CMemory::MAP_DEBUG:
304 printf ("SBP %06x\n", address);
308 case CMemory::MAP_NONE:
309 SA1.PCBase = Memory.RAM;
310 SA1.PC = Memory.RAM + (address & 0xffff);
315 void S9xSA1ExecuteDuringSleep ()
320 while (CPU.Cycles < CPU.NextEvent)
323 CPU.Cycles += TWO_CYCLES * 2;
329 void S9xSetSA1MemMap (uint32 which1, uint8 map)
332 int start = which1 * 0x100 + 0xc00;
333 int start2 = which1 * 0x200;
338 for (c = 0; c < 0x100; c += 16)
340 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 12)];
343 for (i = c; i < c + 16; i++)
344 Memory.Map [start + i] = SA1.Map [start + i] = block;
347 for (c = 0; c < 0x200; c += 16)
349 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 11) - 0x8000];
352 for (i = c + 8; i < c + 16; i++)
353 Memory.Map [start2 + i] = SA1.Map [start2 + i] = block;
357 uint8 S9xGetSA1 (uint32 address)
359 // printf ("R: %04x\n", address);
363 return ((uint8) ((Memory.FillRAM [0x2209] & 0x5f) |
364 (CPU.IRQActive & (SA1_IRQ_SOURCE | SA1_DMA_IRQ_SOURCE))));
366 return ((Memory.FillRAM [0x2200] & 0xf) |
367 (Memory.FillRAM [0x2301] & 0xf0));
369 return ((uint8) SA1.sum);
371 return ((uint8) (SA1.sum >> 8));
373 return ((uint8) (SA1.sum >> 16));
375 return ((uint8) (SA1.sum >> 24));
377 return ((uint8) (SA1.sum >> 32));
379 return (Memory.FillRAM [0x230c]);
382 uint8 byte = Memory.FillRAM [0x230d];
384 if (Memory.FillRAM [0x2258] & 0x80)
386 S9xSA1ReadVariableLengthData (TRUE, FALSE);
392 printf ("R: %04x\n", address);
396 return (Memory.FillRAM [address]);
399 void S9xSetSA1 (uint8 byte, uint32 address)
401 //printf ("W: %02x -> %04x\n", byte, address);
405 SA1.Waiting = (byte & 0x60) != 0;
406 // SA1.Executing = !SA1.Waiting && SA1.S9xOpcodes;
408 if (!(byte & 0x20) && (Memory.FillRAM [0x2200] & 0x20))
414 Memory.FillRAM [0x2301] |= 0x80;
415 if (Memory.FillRAM [0x220a] & 0x80)
417 SA1.Flags |= IRQ_PENDING_FLAG;
418 SA1.IRQActive |= SNES_IRQ_SOURCE;
419 SA1.Executing = !SA1.Waiting;// && SA1.S9xOpcodes; // unused
424 Memory.FillRAM [0x2301] |= 0x10;
426 printf ("###SA1 NMI\n");
428 if (Memory.FillRAM [0x220a] & 0x10)
435 if (((byte ^ Memory.FillRAM [0x2201]) & 0x80) &&
436 (Memory.FillRAM [0x2300] & byte & 0x80))
438 S9xSetIRQ (SA1_IRQ_SOURCE);
440 if (((byte ^ Memory.FillRAM [0x2201]) & 0x20) &&
441 (Memory.FillRAM [0x2300] & byte & 0x20))
443 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
449 Memory.FillRAM [0x2300] &= ~0x80;
450 S9xClearIRQ (SA1_IRQ_SOURCE);
454 Memory.FillRAM [0x2300] &= ~0x20;
455 S9xClearIRQ (SA1_DMA_IRQ_SOURCE);
459 // printf ("SA1 reset vector: %04x\n", byte | (Memory.FillRAM [0x2204] << 8));
462 // printf ("SA1 reset vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2203]);
466 // printf ("SA1 NMI vector: %04x\n", byte | (Memory.FillRAM [0x2206] << 8));
469 // printf ("SA1 NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2205]);
473 // printf ("SA1 IRQ vector: %04x\n", byte | (Memory.FillRAM [0x2208] << 8));
476 // printf ("SA1 IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2207]);
480 Memory.FillRAM [0x2209] = byte;
482 Memory.FillRAM [0x2300] |= 0x80;
484 if (byte & Memory.FillRAM [0x2201] & 0x80)
486 S9xSetIRQ (SA1_IRQ_SOURCE);
490 if (((byte ^ Memory.FillRAM [0x220a]) & 0x80) &&
491 (Memory.FillRAM [0x2301] & byte & 0x80))
493 SA1.Flags |= IRQ_PENDING_FLAG;
494 SA1.IRQActive |= SNES_IRQ_SOURCE;
495 // SA1.Executing = !SA1.Waiting;
497 if (((byte ^ Memory.FillRAM [0x220a]) & 0x40) &&
498 (Memory.FillRAM [0x2301] & byte & 0x40))
500 SA1.Flags |= IRQ_PENDING_FLAG;
501 SA1.IRQActive |= TIMER_IRQ_SOURCE;
502 // SA1.Executing = !SA1.Waiting;
504 if (((byte ^ Memory.FillRAM [0x220a]) & 0x20) &&
505 (Memory.FillRAM [0x2301] & byte & 0x20))
507 SA1.Flags |= IRQ_PENDING_FLAG;
508 SA1.IRQActive |= DMA_IRQ_SOURCE;
509 // SA1.Executing = !SA1.Waiting;
511 if (((byte ^ Memory.FillRAM [0x220a]) & 0x10) &&
512 (Memory.FillRAM [0x2301] & byte & 0x10))
515 printf ("###SA1 NMI\n");
522 SA1.IRQActive &= ~SNES_IRQ_SOURCE;
523 Memory.FillRAM [0x2301] &= ~0x80;
527 SA1.IRQActive &= ~TIMER_IRQ_SOURCE;
528 Memory.FillRAM [0x2301] &= ~0x40;
532 SA1.IRQActive &= ~DMA_IRQ_SOURCE;
533 Memory.FillRAM [0x2301] &= ~0x20;
538 Memory.FillRAM [0x2301] &= ~0x10;
541 SA1.Flags &= ~IRQ_PENDING_FLAG;
544 // printf ("SNES NMI vector: %04x\n", byte | (Memory.FillRAM [0x220d] << 8));
547 // printf ("SNES NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220c]);
551 // printf ("SNES IRQ vector: %04x\n", byte | (Memory.FillRAM [0x220f] << 8));
554 // printf ("SNES IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220e]);
559 printf ("Timer %s\n", (byte & 0x80) ? "linear" : "HV");
560 printf ("Timer H-IRQ %s\n", (byte & 1) ? "enabled" : "disabled");
561 printf ("Timer V-IRQ %s\n", (byte & 2) ? "enabled" : "disabled");
565 printf ("Timer reset\n");
569 printf ("H-Timer %04x\n", byte | (Memory.FillRAM [0x2213] << 8));
574 printf ("H-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2212]);
579 printf ("V-Timer %04x\n", byte | (Memory.FillRAM [0x2215] << 8));
584 printf ("V-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2214]);
591 S9xSetSA1MemMap (address - 0x2220, byte);
592 // printf ("MMC: %02x\n", byte);
595 // printf ("BWRAM image SNES %02x -> 0x6000\n", byte);
596 Memory.BWRAM = Memory.SRAM + (byte & 7) * 0x2000;
599 // printf ("BWRAM image SA1 %02x -> 0x6000 (%02x)\n", byte, Memory.FillRAM [address]);
600 if (byte != Memory.FillRAM [address])
601 S9xSA1SetBWRAMMemMap (byte);
604 // printf ("BW-RAM SNES write %s\n", (byte & 0x80) ? "enabled" : "disabled");
607 // printf ("BW-RAM SA1 write %s\n", (byte & 0x80) ? "enabled" : "disabled");
611 // printf ("BW-RAM write protect area %02x\n", byte);
614 // printf ("I-RAM SNES write protect area %02x\n", byte);
617 // printf ("I-RAM SA1 write protect area %02x\n", byte);
621 printf ("SA1 DMA %s\n", (byte & 0x80) ? "enabled" : "disabled");
622 printf ("DMA priority %s\n", (byte & 0x40) ? "DMA" : "SA1");
623 printf ("DMA %s\n", (byte & 0x20) ? "char conv" : "normal");
624 printf ("DMA type %s\n", (byte & 0x10) ? "BW-RAM -> I-RAM" : "SA1 -> I-RAM");
625 printf ("DMA distination %s\n", (byte & 4) ? "BW-RAM" : "I-RAM");
626 printf ("DMA source %s\n", DMAsource [byte & 3]);
631 SA1.in_char_dma = FALSE;
633 printf ("CHDEND %s\n", (byte & 0x80) ? "complete" : "incomplete");
634 printf ("DMA colour mode %d\n", byte & 3);
635 printf ("virtual VRAM width %d\n", (byte >> 2) & 7);
641 Memory.FillRAM [address] = byte;
643 printf ("DMA source start %06x\n",
644 Memory.FillRAM [0x2232] | (Memory.FillRAM [0x2233] << 8) |
645 (Memory.FillRAM [0x2234] << 16));
649 Memory.FillRAM [address] = byte;
652 Memory.FillRAM [address] = byte;
653 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x80)
655 // Normal DMA to I-RAM
659 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xb0)
661 Memory.FillRAM [0x2300] |= 0x20;
662 if (Memory.FillRAM [0x2201] & 0x20)
663 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
664 SA1.in_char_dma = TRUE;
668 Memory.FillRAM [address] = byte;
669 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x84)
671 // Normal DMA to BW-RAM
675 printf ("DMA dest address %06x\n",
676 Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8) |
677 (Memory.FillRAM [0x2237] << 16));
682 Memory.FillRAM [address] = byte;
684 printf ("DMA length %04x\n",
685 Memory.FillRAM [0x2238] | (Memory.FillRAM [0x2239] << 8));
689 SA1.VirtualBitmapFormat = (byte & 0x80) ? 2 : 4;
690 //printf ("virtual VRAM depth %d\n", (byte & 0x80) ? 2 : 4);
693 case 0x2240: case 0x2241: case 0x2242: case 0x2243:
694 case 0x2244: case 0x2245: case 0x2246: case 0x2247:
695 case 0x2248: case 0x2249: case 0x224a: case 0x224b:
696 case 0x224c: case 0x224d: case 0x224e:
698 if (!(SA1.Flags & TRACE_FLAG))
704 Memory.FillRAM [address] = byte;
708 Memory.FillRAM [address] = byte;
709 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xa0)
711 // Char conversion 2 DMA enabled
712 memmove (&Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + SA1.in_char_dma * 16,
713 &Memory.FillRAM [0x2240], 16);
714 SA1.in_char_dma = (SA1.in_char_dma + 1) & 7;
715 if ((SA1.in_char_dma & 3) == 0)
724 SA1.arithmetic_op = byte & 3;
728 SA1.op1 = (SA1.op1 & 0xff00) | byte;
731 SA1.op1 = (SA1.op1 & 0xff) | (byte << 8);
734 SA1.op2 = (SA1.op2 & 0xff00) | byte;
737 SA1.op2 = (SA1.op2 & 0xff) | (byte << 8);
738 switch (SA1.arithmetic_op)
741 SA1.sum = SA1.op1 * SA1.op2;
745 SA1.sum = SA1.op1 << 16;
748 SA1.sum = (SA1.op1 / (int) ((uint16) SA1.op2)) |
749 ((SA1.op1 % (int) ((uint16) SA1.op2)) << 16);
753 default: // cumulative sum
754 SA1.sum += SA1.op1 * SA1.op2;
755 if (SA1.sum & ((int64) 0xffffff << 32))
760 case 0x2258: // Variable bit-field length/auto inc/start.
761 Memory.FillRAM [0x2258] = byte;
762 S9xSA1ReadVariableLengthData (TRUE, FALSE);
766 case 0x225b: // Variable bit-field start address
767 Memory.FillRAM [address] = byte;
769 SA1.variable_bit_pos = 0;
770 S9xSA1ReadVariableLengthData (FALSE, TRUE);
773 // printf ("W: %02x->%04x\n", byte, address);
776 if (address >= 0x2200 && address <= 0x22ff)
777 Memory.FillRAM [address] = byte;
780 static void S9xSA1CharConv2 ()
782 uint32 dest = Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8);
783 uint32 offset = (SA1.in_char_dma & 7) ? 0 : 1;
784 int depth = (Memory.FillRAM [0x2231] & 3) == 0 ? 8 :
785 (Memory.FillRAM [0x2231] & 3) == 1 ? 4 : 2;
786 int bytes_per_char = 8 * depth;
787 uint8 *p = &Memory.FillRAM [0x3000] + dest + offset * bytes_per_char;
788 uint8 *q = &Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + offset * 64;
797 for (int l = 0; l < 8; l++, q += 8)
799 for (int b = 0; b < 8; b++)
802 *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1);
803 *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1);
804 *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1);
805 *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1);
806 *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1);
807 *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1);
808 *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1);
809 *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1);
817 static void S9xSA1DMA ()
819 uint32 src = Memory.FillRAM [0x2232] |
820 (Memory.FillRAM [0x2233] << 8) |
821 (Memory.FillRAM [0x2234] << 16);
822 uint32 dst = Memory.FillRAM [0x2235] |
823 (Memory.FillRAM [0x2236] << 8) |
824 (Memory.FillRAM [0x2237] << 16);
825 uint32 len = Memory.FillRAM [0x2238] |
826 (Memory.FillRAM [0x2239] << 8);
831 switch (Memory.FillRAM [0x2230] & 3)
834 s = SA1.Map [(src >> MEMMAP_SHIFT) & MEMMAP_MASK];
835 if (s >= (uint8 *) CMemory::MAP_LAST)
838 s = Memory.ROM + (src & 0xffff);
841 src &= CPU.Memory_SRAMMask;
842 len &= CPU.Memory_SRAMMask;
843 s = Memory.SRAM + src;
849 s = &Memory.FillRAM [0x3000] + src;
853 if (Memory.FillRAM [0x2230] & 4)
855 dst &= CPU.Memory_SRAMMask;
856 len &= CPU.Memory_SRAMMask;
857 d = Memory.SRAM + dst;
863 d = &Memory.FillRAM [0x3000] + dst;
866 Memory.FillRAM [0x2301] |= 0x20;
868 if (Memory.FillRAM [0x220a] & 0x20)
870 SA1.Flags |= IRQ_PENDING_FLAG;
871 SA1.IRQActive |= DMA_IRQ_SOURCE;
872 // SA1.Executing = !SA1.Waiting;
876 void S9xSA1ReadVariableLengthData (bool8 inc, bool8 no_shift)
878 uint32 addr = Memory.FillRAM [0x2259] |
879 (Memory.FillRAM [0x225a] << 8) |
880 (Memory.FillRAM [0x225b] << 16);
881 uint8 shift = Memory.FillRAM [0x2258] & 15;
889 uint8 s = shift + SA1.variable_bit_pos;
893 addr += (s >> 4) << 1;
896 uint32 data = S9xSA1GetWord (addr) |
897 (S9xSA1GetWord (addr + 2) << 16);
900 Memory.FillRAM [0x230c] = (uint8) data;
901 Memory.FillRAM [0x230d] = (uint8) (data >> 8);
904 SA1.variable_bit_pos = (SA1.variable_bit_pos + shift) & 15;
905 Memory.FillRAM [0x2259] = (uint8) addr;
906 Memory.FillRAM [0x225a] = (uint8) (addr >> 8);
907 Memory.FillRAM [0x225b] = (uint8) (addr >> 16);