|
|
1.1 ! root 1: /* ! 2: Hatari ! 3: ! 4: ST Memory functions - takes care of endian swaps ! 5: */ ! 6: ! 7: #include "main.h" ! 8: #include "decode.h" ! 9: #include "m68000.h" ! 10: #include "memAlloc.h" ! 11: ! 12: //----------------------------------------------------------------------- ! 13: /* ! 14: Clear section of ST's memory space ! 15: */ ! 16: void STMemory_Clear(unsigned long StartAddress, unsigned long EndAddress) ! 17: { ! 18: Memory_Clear((void *)((unsigned long)STRam+StartAddress),EndAddress-StartAddress); ! 19: } ! 20: ! 21: //----------------------------------------------------------------------- ! 22: /* ! 23: Swap 16-bit integer to/from 68000/PC format ! 24: */ ! 25: /* Thanks to Stefan Berndtsson for the htons/l patch! - Thothy */ ! 26: unsigned short int STMemory_Swap68000Int(unsigned short int var) ! 27: { ! 28: return htons(var); ! 29: } ! 30: ! 31: //----------------------------------------------------------------------- ! 32: /* ! 33: Swap 32-bit integer to/from 68000/PC format ! 34: */ ! 35: unsigned long STMemory_Swap68000Long(unsigned long var) ! 36: { ! 37: return htonl(var); ! 38: } ! 39: ! 40: //----------------------------------------------------------------------- ! 41: /* ! 42: Write 32-bit word into ST memory space, NOTE - value will be convert to 68000 endian ! 43: */ ! 44: void STMemory_WriteLong(unsigned long Address,unsigned long Var) ! 45: { ! 46: unsigned long *pLongWord; ! 47: ! 48: Address &= 0xffffff; ! 49: pLongWord = (unsigned long *)((unsigned long)STRam+Address); ! 50: *pLongWord = STMemory_Swap68000Long(Var); ! 51: } ! 52: ! 53: //----------------------------------------------------------------------- ! 54: /* ! 55: Write 16-bit word into ST memory space, NOTE - value will be convert to 68000 endian ! 56: */ ! 57: void STMemory_WriteWord(unsigned long Address,unsigned short int Var) ! 58: { ! 59: unsigned short int *pShortWord; ! 60: ! 61: Address &= 0xffffff; ! 62: pShortWord = (unsigned short int *)((unsigned long)STRam+Address); ! 63: *pShortWord = STMemory_Swap68000Int(Var); ! 64: } ! 65: ! 66: //----------------------------------------------------------------------- ! 67: /* ! 68: Write 8-bit byte into ST memory space ! 69: */ ! 70: void STMemory_WriteByte(unsigned long Address,unsigned char Var) ! 71: { ! 72: unsigned char *pChar; ! 73: ! 74: Address &= 0xffffff; ! 75: pChar = (unsigned char *)((unsigned long)STRam+Address); ! 76: *pChar = Var; ! 77: } ! 78: ! 79: //----------------------------------------------------------------------- ! 80: /* ! 81: Read 32-bit word from ST memory space, NOTE - value will be converted to PC endian ! 82: */ ! 83: unsigned long STMemory_ReadLong(unsigned long Address) ! 84: { ! 85: unsigned long *pLongWord; ! 86: ! 87: Address &= 0xffffff; ! 88: pLongWord = (unsigned long *)((unsigned long)STRam+Address); ! 89: return( STMemory_Swap68000Long(*pLongWord) ); ! 90: } ! 91: ! 92: //----------------------------------------------------------------------- ! 93: /* ! 94: Read 16-bit word from ST memory space, NOTE - value will be converted to PC endian ! 95: */ ! 96: unsigned short int STMemory_ReadWord(unsigned long Address) ! 97: { ! 98: unsigned short int *pShortWord; ! 99: ! 100: Address &= 0xffffff; ! 101: pShortWord = (unsigned short int *)((unsigned long)STRam+Address); ! 102: return( STMemory_Swap68000Int(*pShortWord) ); ! 103: } ! 104: ! 105: //----------------------------------------------------------------------- ! 106: /* ! 107: Read 8-bit byte from ST memory space ! 108: */ ! 109: unsigned char STMemory_ReadByte(unsigned long Address) ! 110: { ! 111: unsigned char *pChar; ! 112: ! 113: Address &= 0xffffff; ! 114: pChar = (unsigned char *)((unsigned long)STRam+Address); ! 115: return( *pChar ); ! 116: } ! 117: ! 118: //----------------------------------------------------------------------- ! 119: /* ! 120: Write 32-bit word into PC memory space, NOTE - value will be convert to 68000 endian ! 121: */ ! 122: void STMemory_WriteLong_PCSpace(void *pAddress,unsigned long Var) ! 123: { ! 124: unsigned long *pLongWord=(unsigned long *)pAddress; ! 125: ! 126: *pLongWord = STMemory_Swap68000Long(Var); ! 127: } ! 128: ! 129: //----------------------------------------------------------------------- ! 130: /* ! 131: Write 16-bit word into PC memory space, NOTE - value will be convert to 68000 endian ! 132: */ ! 133: void STMemory_WriteWord_PCSpace(void *pAddress,unsigned short int Var) ! 134: { ! 135: unsigned short int *pShortWord=(unsigned short int *)pAddress; ! 136: ! 137: *pShortWord = STMemory_Swap68000Int(Var); ! 138: } ! 139: ! 140: //----------------------------------------------------------------------- ! 141: /* ! 142: Read 32-bit word from PC memory space, NOTE - value will be convert to 68000 endian ! 143: */ ! 144: unsigned long STMemory_ReadLong_PCSpace(void *pAddress) ! 145: { ! 146: unsigned long *pLongWord=(unsigned long *)pAddress; ! 147: ! 148: return( STMemory_Swap68000Long(*pLongWord) ); ! 149: } ! 150: ! 151: //----------------------------------------------------------------------- ! 152: /* ! 153: Read 16-bit word from PC memory space, NOTE - value will be convert to 68000 endian ! 154: */ ! 155: unsigned short int STMemory_ReadWord_PCSpace(void *pAddress) ! 156: { ! 157: unsigned short int *pShortWord=(unsigned short int *)pAddress; ! 158: ! 159: return( STMemory_Swap68000Int(*pShortWord) ); ! 160: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.