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.
47 static void S9xSA1CharConv2 ();
48 static void S9xSA1DMA ();
49 static void S9xSA1ReadVariableLengthData (bool8 inc, bool8 no_shift);
53 SA1.NMIActive = FALSE;
54 SA1.IRQActive = FALSE;
55 SA1.WaitingForInterrupt = FALSE;
58 SA1.Executing = FALSE;
59 memset (&Memory.FillRAM [0x2200], 0, 0x200);
60 Memory.FillRAM [0x2200] = 0x20;
61 Memory.FillRAM [0x2220] = 0x00;
62 Memory.FillRAM [0x2221] = 0x01;
63 Memory.FillRAM [0x2222] = 0x02;
64 Memory.FillRAM [0x2223] = 0x03;
65 Memory.FillRAM [0x2228] = 0xff;
68 SA1.arithmetic_op = 0;
76 SA1Registers.PC = Memory.FillRAM [0x2203] |
77 (Memory.FillRAM [0x2204] << 8);
81 SA1Registers.SL = 0xFF;
88 SA1SetFlags (MemoryFlag | IndexFlag | IRQ | Emulation);
89 SA1ClearFlags (Decimal);
91 SA1.WaitingForInterrupt = FALSE;
94 S9xSA1SetPCBase (SA1Registers.PC);
95 //SA1.S9xOpcodes = S9xSA1OpcodesM1X1; // unused
98 //S9xSA1FixCycles (); // unused
100 SA1.BWRAM = Memory.SRAM;
101 Memory.FillRAM [0x2225] = 0;
104 void S9xSA1SetBWRAMMemMap (uint8 val)
110 for (c = 0; c < 0x400; c += 16)
112 SA1.Map [c + 6] = SA1.Map [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
113 SA1.Map [c + 7] = SA1.Map [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
114 SA1.WriteMap [c + 6] = SA1.WriteMap [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
115 SA1.WriteMap [c + 7] = SA1.WriteMap [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM_BITMAP2;
117 SA1.BWRAM = Memory.SRAM + (val & 0x7f) * 0x2000 / 4;
121 for (c = 0; c < 0x400; c += 16)
123 SA1.Map [c + 6] = SA1.Map [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM;
124 SA1.Map [c + 7] = SA1.Map [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM;
125 SA1.WriteMap [c + 6] = SA1.WriteMap [c + 0x806] = (uint8 *) CMemory::MAP_BWRAM;
126 SA1.WriteMap [c + 7] = SA1.WriteMap [c + 0x807] = (uint8 *) CMemory::MAP_BWRAM;
128 SA1.BWRAM = Memory.SRAM + (val & 7) * 0x2000;
132 void S9xFixSA1AfterSnapshotLoad ()
134 SA1.ShiftedPB = (uint32) SA1Registers.PB << 16;
135 SA1.ShiftedDB = (uint32) SA1Registers.DB << 16;
137 S9xSA1SetPCBase (SA1.ShiftedPB + SA1Registers.PC);
138 S9xSA1UnpackStatus ();
139 //S9xSA1FixCycles (); // unused
140 SA1.VirtualBitmapFormat = (Memory.FillRAM [0x223f] & 0x80) ? 2 : 4;
141 Memory.BWRAM = Memory.SRAM + (Memory.FillRAM [0x2224] & 7) * 0x2000;
142 S9xSA1SetBWRAMMemMap (Memory.FillRAM [0x2225]);
144 SA1.Waiting = (Memory.FillRAM [0x2200] & 0x60) != 0;
145 SA1.Executing = !SA1.Waiting;
148 uint8 S9xSA1GetByte (uint32 address)
150 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
151 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
152 return (*(GetAddress + (address & 0xffff)));
154 switch ((int) GetAddress)
156 case CMemory::MAP_PPU:
157 return (S9xGetSA1 (address & 0xffff));
158 case CMemory::MAP_LOROM_SRAM:
159 case CMemory::MAP_SA1RAM:
160 return (*(Memory.SRAM + (address & 0xffff)));
161 case CMemory::MAP_BWRAM:
162 return (*(SA1.BWRAM + ((address & 0x7fff) - 0x6000)));
163 case CMemory::MAP_BWRAM_BITMAP:
165 if (SA1.VirtualBitmapFormat == 2)
166 return ((Memory.SRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
168 return ((Memory.SRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
169 case CMemory::MAP_BWRAM_BITMAP2:
170 address = (address & 0xffff) - 0x6000;
171 if (SA1.VirtualBitmapFormat == 2)
172 return ((SA1.BWRAM [(address >> 2) & 0xffff] >> ((address & 3) << 1)) & 3);
174 return ((SA1.BWRAM [(address >> 1) & 0xffff] >> ((address & 1) << 2)) & 15);
176 case CMemory::MAP_DEBUG:
179 // printf ("R(B) %06x\n", address);
186 uint16 S9xSA1GetWord (uint32 address)
188 return (S9xSA1GetByte (address) | (S9xSA1GetByte (address + 1) << 8));
191 void S9xSA1SetByte (uint8 byte, uint32 address)
193 uint8 *Setaddress = SA1.WriteMap [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
195 if (Setaddress >= (uint8 *) CMemory::MAP_LAST)
197 *(Setaddress + (address & 0xffff)) = byte;
201 switch ((int) Setaddress)
203 case CMemory::MAP_PPU:
204 S9xSetSA1 (byte, address & 0xffff);
206 case CMemory::MAP_SA1RAM:
207 case CMemory::MAP_LOROM_SRAM:
208 *(Memory.SRAM + (address & 0xffff)) = byte;
210 case CMemory::MAP_BWRAM:
211 *(SA1.BWRAM + ((address & 0x7fff) - 0x6000)) = byte;
213 case CMemory::MAP_BWRAM_BITMAP:
215 if (SA1.VirtualBitmapFormat == 2)
217 uint8 *ptr = &Memory.SRAM [(address >> 2) & 0xffff];
218 *ptr &= ~(3 << ((address & 3) << 1));
219 *ptr |= (byte & 3) << ((address & 3) << 1);
223 uint8 *ptr = &Memory.SRAM [(address >> 1) & 0xffff];
224 *ptr &= ~(15 << ((address & 1) << 2));
225 *ptr |= (byte & 15) << ((address & 1) << 2);
228 case CMemory::MAP_BWRAM_BITMAP2:
229 address = (address & 0xffff) - 0x6000;
230 if (SA1.VirtualBitmapFormat == 2)
232 uint8 *ptr = &SA1.BWRAM [(address >> 2) & 0xffff];
233 *ptr &= ~(3 << ((address & 3) << 1));
234 *ptr |= (byte & 3) << ((address & 3) << 1);
238 uint8 *ptr = &SA1.BWRAM [(address >> 1) & 0xffff];
239 *ptr &= ~(15 << ((address & 1) << 2));
240 *ptr |= (byte & 15) << ((address & 1) << 2);
247 void S9xSA1SetWord (uint16 Word, uint32 address)
249 S9xSA1SetByte ((uint8) Word, address);
250 S9xSA1SetByte ((uint8) (Word >> 8), address + 1);
253 void S9xSA1SetPCBase (uint32 address)
255 uint8 *GetAddress = SA1.Map [(address >> MEMMAP_SHIFT) & MEMMAP_MASK];
256 if (GetAddress >= (uint8 *) CMemory::MAP_LAST)
258 SA1.PCBase = GetAddress;
259 SA1.PC = GetAddress + (address & 0xffff);
263 switch ((int) GetAddress)
265 case CMemory::MAP_PPU:
266 SA1.PCBase = Memory.FillRAM - 0x2000;
267 SA1.PC = SA1.PCBase + (address & 0xffff);
270 case CMemory::MAP_CPU:
271 SA1.PCBase = Memory.FillRAM - 0x4000;
272 SA1.PC = SA1.PCBase + (address & 0xffff);
275 case CMemory::MAP_DSP:
276 SA1.PCBase = Memory.FillRAM - 0x6000;
277 SA1.PC = SA1.PCBase + (address & 0xffff);
280 case CMemory::MAP_SA1RAM:
281 case CMemory::MAP_LOROM_SRAM:
282 SA1.PCBase = Memory.SRAM;
283 SA1.PC = SA1.PCBase + (address & 0xffff);
286 case CMemory::MAP_BWRAM:
287 SA1.PCBase = SA1.BWRAM - 0x6000;
288 SA1.PC = SA1.PCBase + (address & 0xffff);
290 case CMemory::MAP_HIROM_SRAM:
291 SA1.PCBase = Memory.SRAM - 0x6000;
292 SA1.PC = SA1.PCBase + (address & 0xffff);
295 case CMemory::MAP_DEBUG:
297 printf ("SBP %06x\n", address);
301 case CMemory::MAP_NONE:
302 SA1.PCBase = Memory.RAM;
303 SA1.PC = Memory.RAM + (address & 0xffff);
308 void S9xSA1ExecuteDuringSleep ()
313 while (CPU.Cycles < CPU.NextEvent)
316 CPU.Cycles += TWO_CYCLES * 2;
322 void S9xSetSA1MemMap (uint32 which1, uint8 map)
325 int start = which1 * 0x100 + 0xc00;
326 int start2 = which1 * 0x200;
331 for (c = 0; c < 0x100; c += 16)
333 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 12)];
336 for (i = c; i < c + 16; i++)
337 Memory.Map [start + i] = SA1.Map [start + i] = block;
340 for (c = 0; c < 0x200; c += 16)
342 uint8 *block = &Memory.ROM [(map & 7) * 0x100000 + (c << 11) - 0x8000];
345 for (i = c + 8; i < c + 16; i++)
346 Memory.Map [start2 + i] = SA1.Map [start2 + i] = block;
350 uint8 S9xGetSA1 (uint32 address)
352 // printf ("R: %04x\n", address);
356 return ((uint8) ((Memory.FillRAM [0x2209] & 0x5f) |
357 (CPU.IRQActive & (SA1_IRQ_SOURCE | SA1_DMA_IRQ_SOURCE))));
359 return ((Memory.FillRAM [0x2200] & 0xf) |
360 (Memory.FillRAM [0x2301] & 0xf0));
362 return ((uint8) SA1.sum);
364 return ((uint8) (SA1.sum >> 8));
366 return ((uint8) (SA1.sum >> 16));
368 return ((uint8) (SA1.sum >> 24));
370 return ((uint8) (SA1.sum >> 32));
372 return (Memory.FillRAM [0x230c]);
375 uint8 byte = Memory.FillRAM [0x230d];
377 if (Memory.FillRAM [0x2258] & 0x80)
379 S9xSA1ReadVariableLengthData (TRUE, FALSE);
385 printf ("R: %04x\n", address);
389 return (Memory.FillRAM [address]);
392 void S9xSetSA1 (uint8 byte, uint32 address)
394 //printf ("W: %02x -> %04x\n", byte, address);
398 SA1.Waiting = (byte & 0x60) != 0;
399 // SA1.Executing = !SA1.Waiting && SA1.S9xOpcodes;
401 if (!(byte & 0x20) && (Memory.FillRAM [0x2200] & 0x20))
407 Memory.FillRAM [0x2301] |= 0x80;
408 if (Memory.FillRAM [0x220a] & 0x80)
410 SA1.Flags |= IRQ_PENDING_FLAG;
411 SA1.IRQActive |= SNES_IRQ_SOURCE;
412 SA1.Executing = !SA1.Waiting;// && SA1.S9xOpcodes; // unused
417 Memory.FillRAM [0x2301] |= 0x10;
419 printf ("###SA1 NMI\n");
421 if (Memory.FillRAM [0x220a] & 0x10)
428 if (((byte ^ Memory.FillRAM [0x2201]) & 0x80) &&
429 (Memory.FillRAM [0x2300] & byte & 0x80))
431 S9xSetIRQ (SA1_IRQ_SOURCE);
433 if (((byte ^ Memory.FillRAM [0x2201]) & 0x20) &&
434 (Memory.FillRAM [0x2300] & byte & 0x20))
436 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
442 Memory.FillRAM [0x2300] &= ~0x80;
443 S9xClearIRQ (SA1_IRQ_SOURCE);
447 Memory.FillRAM [0x2300] &= ~0x20;
448 S9xClearIRQ (SA1_DMA_IRQ_SOURCE);
452 // printf ("SA1 reset vector: %04x\n", byte | (Memory.FillRAM [0x2204] << 8));
455 // printf ("SA1 reset vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2203]);
459 // printf ("SA1 NMI vector: %04x\n", byte | (Memory.FillRAM [0x2206] << 8));
462 // printf ("SA1 NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2205]);
466 // printf ("SA1 IRQ vector: %04x\n", byte | (Memory.FillRAM [0x2208] << 8));
469 // printf ("SA1 IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x2207]);
473 Memory.FillRAM [0x2209] = byte;
475 Memory.FillRAM [0x2300] |= 0x80;
477 if (byte & Memory.FillRAM [0x2201] & 0x80)
479 S9xSetIRQ (SA1_IRQ_SOURCE);
483 if (((byte ^ Memory.FillRAM [0x220a]) & 0x80) &&
484 (Memory.FillRAM [0x2301] & byte & 0x80))
486 SA1.Flags |= IRQ_PENDING_FLAG;
487 SA1.IRQActive |= SNES_IRQ_SOURCE;
488 // SA1.Executing = !SA1.Waiting;
490 if (((byte ^ Memory.FillRAM [0x220a]) & 0x40) &&
491 (Memory.FillRAM [0x2301] & byte & 0x40))
493 SA1.Flags |= IRQ_PENDING_FLAG;
494 SA1.IRQActive |= TIMER_IRQ_SOURCE;
495 // SA1.Executing = !SA1.Waiting;
497 if (((byte ^ Memory.FillRAM [0x220a]) & 0x20) &&
498 (Memory.FillRAM [0x2301] & byte & 0x20))
500 SA1.Flags |= IRQ_PENDING_FLAG;
501 SA1.IRQActive |= DMA_IRQ_SOURCE;
502 // SA1.Executing = !SA1.Waiting;
504 if (((byte ^ Memory.FillRAM [0x220a]) & 0x10) &&
505 (Memory.FillRAM [0x2301] & byte & 0x10))
508 printf ("###SA1 NMI\n");
515 SA1.IRQActive &= ~SNES_IRQ_SOURCE;
516 Memory.FillRAM [0x2301] &= ~0x80;
520 SA1.IRQActive &= ~TIMER_IRQ_SOURCE;
521 Memory.FillRAM [0x2301] &= ~0x40;
525 SA1.IRQActive &= ~DMA_IRQ_SOURCE;
526 Memory.FillRAM [0x2301] &= ~0x20;
531 Memory.FillRAM [0x2301] &= ~0x10;
534 SA1.Flags &= ~IRQ_PENDING_FLAG;
537 // printf ("SNES NMI vector: %04x\n", byte | (Memory.FillRAM [0x220d] << 8));
540 // printf ("SNES NMI vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220c]);
544 // printf ("SNES IRQ vector: %04x\n", byte | (Memory.FillRAM [0x220f] << 8));
547 // printf ("SNES IRQ vector: %04x\n", (byte << 8) | Memory.FillRAM [0x220e]);
552 printf ("Timer %s\n", (byte & 0x80) ? "linear" : "HV");
553 printf ("Timer H-IRQ %s\n", (byte & 1) ? "enabled" : "disabled");
554 printf ("Timer V-IRQ %s\n", (byte & 2) ? "enabled" : "disabled");
558 printf ("Timer reset\n");
562 printf ("H-Timer %04x\n", byte | (Memory.FillRAM [0x2213] << 8));
567 printf ("H-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2212]);
572 printf ("V-Timer %04x\n", byte | (Memory.FillRAM [0x2215] << 8));
577 printf ("V-Timer %04x\n", (byte << 8) | Memory.FillRAM [0x2214]);
584 S9xSetSA1MemMap (address - 0x2220, byte);
585 // printf ("MMC: %02x\n", byte);
588 // printf ("BWRAM image SNES %02x -> 0x6000\n", byte);
589 Memory.BWRAM = Memory.SRAM + (byte & 7) * 0x2000;
592 // printf ("BWRAM image SA1 %02x -> 0x6000 (%02x)\n", byte, Memory.FillRAM [address]);
593 if (byte != Memory.FillRAM [address])
594 S9xSA1SetBWRAMMemMap (byte);
597 // printf ("BW-RAM SNES write %s\n", (byte & 0x80) ? "enabled" : "disabled");
600 // printf ("BW-RAM SA1 write %s\n", (byte & 0x80) ? "enabled" : "disabled");
604 // printf ("BW-RAM write protect area %02x\n", byte);
607 // printf ("I-RAM SNES write protect area %02x\n", byte);
610 // printf ("I-RAM SA1 write protect area %02x\n", byte);
614 printf ("SA1 DMA %s\n", (byte & 0x80) ? "enabled" : "disabled");
615 printf ("DMA priority %s\n", (byte & 0x40) ? "DMA" : "SA1");
616 printf ("DMA %s\n", (byte & 0x20) ? "char conv" : "normal");
617 printf ("DMA type %s\n", (byte & 0x10) ? "BW-RAM -> I-RAM" : "SA1 -> I-RAM");
618 printf ("DMA distination %s\n", (byte & 4) ? "BW-RAM" : "I-RAM");
619 printf ("DMA source %s\n", DMAsource [byte & 3]);
624 SA1.in_char_dma = FALSE;
626 printf ("CHDEND %s\n", (byte & 0x80) ? "complete" : "incomplete");
627 printf ("DMA colour mode %d\n", byte & 3);
628 printf ("virtual VRAM width %d\n", (byte >> 2) & 7);
634 Memory.FillRAM [address] = byte;
636 printf ("DMA source start %06x\n",
637 Memory.FillRAM [0x2232] | (Memory.FillRAM [0x2233] << 8) |
638 (Memory.FillRAM [0x2234] << 16));
642 Memory.FillRAM [address] = byte;
645 Memory.FillRAM [address] = byte;
646 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x80)
648 // Normal DMA to I-RAM
652 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xb0)
654 Memory.FillRAM [0x2300] |= 0x20;
655 if (Memory.FillRAM [0x2201] & 0x20)
656 S9xSetIRQ (SA1_DMA_IRQ_SOURCE);
657 SA1.in_char_dma = TRUE;
661 Memory.FillRAM [address] = byte;
662 if ((Memory.FillRAM [0x2230] & 0xa4) == 0x84)
664 // Normal DMA to BW-RAM
668 printf ("DMA dest address %06x\n",
669 Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8) |
670 (Memory.FillRAM [0x2237] << 16));
675 Memory.FillRAM [address] = byte;
677 printf ("DMA length %04x\n",
678 Memory.FillRAM [0x2238] | (Memory.FillRAM [0x2239] << 8));
682 SA1.VirtualBitmapFormat = (byte & 0x80) ? 2 : 4;
683 //printf ("virtual VRAM depth %d\n", (byte & 0x80) ? 2 : 4);
686 case 0x2240: case 0x2241: case 0x2242: case 0x2243:
687 case 0x2244: case 0x2245: case 0x2246: case 0x2247:
688 case 0x2248: case 0x2249: case 0x224a: case 0x224b:
689 case 0x224c: case 0x224d: case 0x224e:
691 if (!(SA1.Flags & TRACE_FLAG))
697 Memory.FillRAM [address] = byte;
701 Memory.FillRAM [address] = byte;
702 if ((Memory.FillRAM [0x2230] & 0xb0) == 0xa0)
704 // Char conversion 2 DMA enabled
705 memmove (&Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + SA1.in_char_dma * 16,
706 &Memory.FillRAM [0x2240], 16);
707 SA1.in_char_dma = (SA1.in_char_dma + 1) & 7;
708 if ((SA1.in_char_dma & 3) == 0)
717 SA1.arithmetic_op = byte & 3;
721 SA1.op1 = (SA1.op1 & 0xff00) | byte;
724 SA1.op1 = (SA1.op1 & 0xff) | (byte << 8);
727 SA1.op2 = (SA1.op2 & 0xff00) | byte;
730 SA1.op2 = (SA1.op2 & 0xff) | (byte << 8);
731 switch (SA1.arithmetic_op)
734 SA1.sum = SA1.op1 * SA1.op2;
738 SA1.sum = SA1.op1 << 16;
741 SA1.sum = (SA1.op1 / (int) ((uint16) SA1.op2)) |
742 ((SA1.op1 % (int) ((uint16) SA1.op2)) << 16);
746 default: // cumulative sum
747 SA1.sum += SA1.op1 * SA1.op2;
748 if (SA1.sum & ((int64) 0xffffff << 32))
753 case 0x2258: // Variable bit-field length/auto inc/start.
754 Memory.FillRAM [0x2258] = byte;
755 S9xSA1ReadVariableLengthData (TRUE, FALSE);
759 case 0x225b: // Variable bit-field start address
760 Memory.FillRAM [address] = byte;
762 SA1.variable_bit_pos = 0;
763 S9xSA1ReadVariableLengthData (FALSE, TRUE);
766 // printf ("W: %02x->%04x\n", byte, address);
769 if (address >= 0x2200 && address <= 0x22ff)
770 Memory.FillRAM [address] = byte;
773 static void S9xSA1CharConv2 ()
775 uint32 dest = Memory.FillRAM [0x2235] | (Memory.FillRAM [0x2236] << 8);
776 uint32 offset = (SA1.in_char_dma & 7) ? 0 : 1;
777 int depth = (Memory.FillRAM [0x2231] & 3) == 0 ? 8 :
778 (Memory.FillRAM [0x2231] & 3) == 1 ? 4 : 2;
779 int bytes_per_char = 8 * depth;
780 uint8 *p = &Memory.FillRAM [0x3000] + dest + offset * bytes_per_char;
781 uint8 *q = &Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + offset * 64;
790 for (int l = 0; l < 8; l++, q += 8)
792 for (int b = 0; b < 8; b++)
795 *(p + 0) = (*(p + 0) << 1) | ((r >> 0) & 1);
796 *(p + 1) = (*(p + 1) << 1) | ((r >> 1) & 1);
797 *(p + 16) = (*(p + 16) << 1) | ((r >> 2) & 1);
798 *(p + 17) = (*(p + 17) << 1) | ((r >> 3) & 1);
799 *(p + 32) = (*(p + 32) << 1) | ((r >> 4) & 1);
800 *(p + 33) = (*(p + 33) << 1) | ((r >> 5) & 1);
801 *(p + 48) = (*(p + 48) << 1) | ((r >> 6) & 1);
802 *(p + 49) = (*(p + 49) << 1) | ((r >> 7) & 1);
810 static void S9xSA1DMA ()
812 uint32 src = Memory.FillRAM [0x2232] |
813 (Memory.FillRAM [0x2233] << 8) |
814 (Memory.FillRAM [0x2234] << 16);
815 uint32 dst = Memory.FillRAM [0x2235] |
816 (Memory.FillRAM [0x2236] << 8) |
817 (Memory.FillRAM [0x2237] << 16);
818 uint32 len = Memory.FillRAM [0x2238] |
819 (Memory.FillRAM [0x2239] << 8);
824 switch (Memory.FillRAM [0x2230] & 3)
827 s = SA1.Map [(src >> MEMMAP_SHIFT) & MEMMAP_MASK];
828 if (s >= (uint8 *) CMemory::MAP_LAST)
831 s = Memory.ROM + (src & 0xffff);
834 src &= CPU.Memory_SRAMMask;
835 len &= CPU.Memory_SRAMMask;
836 s = Memory.SRAM + src;
842 s = &Memory.FillRAM [0x3000] + src;
846 if (Memory.FillRAM [0x2230] & 4)
848 dst &= CPU.Memory_SRAMMask;
849 len &= CPU.Memory_SRAMMask;
850 d = Memory.SRAM + dst;
856 d = &Memory.FillRAM [0x3000] + dst;
859 Memory.FillRAM [0x2301] |= 0x20;
861 if (Memory.FillRAM [0x220a] & 0x20)
863 SA1.Flags |= IRQ_PENDING_FLAG;
864 SA1.IRQActive |= DMA_IRQ_SOURCE;
865 // SA1.Executing = !SA1.Waiting;
869 void S9xSA1ReadVariableLengthData (bool8 inc, bool8 no_shift)
871 uint32 addr = Memory.FillRAM [0x2259] |
872 (Memory.FillRAM [0x225a] << 8) |
873 (Memory.FillRAM [0x225b] << 16);
874 uint8 shift = Memory.FillRAM [0x2258] & 15;
882 uint8 s = shift + SA1.variable_bit_pos;
886 addr += (s >> 4) << 1;
889 uint32 data = S9xSA1GetWord (addr) |
890 (S9xSA1GetWord (addr + 2) << 16);
893 Memory.FillRAM [0x230c] = (uint8) data;
894 Memory.FillRAM [0x230d] = (uint8) (data >> 8);
897 SA1.variable_bit_pos = (SA1.variable_bit_pos + shift) & 15;
898 Memory.FillRAM [0x2259] = (uint8) addr;
899 Memory.FillRAM [0x225a] = (uint8) (addr >> 8);
900 Memory.FillRAM [0x225b] = (uint8) (addr >> 16);