/* YAPE - Yet Another Plus/4 Emulator The program emulates the Commodore 264 family of 8 bit microcomputers This program is free software, you are welcome to distribute it, and/or modify it under certain conditions. For more information, read 'Copying'. (c) 2000, 2001, 2004 Attila Grósz */ #ifndef _TEDMEM_H #define _TEDMEM_H #define RAMSIZE 65536 #define ROMSIZE 16384 #define SCR_HSIZE 456 #define SCR_VSIZE 312 #define CYCSTEP 8 #define RASTEROFFSET 52 class CPU; class KEYS; class TAP; class MEM { public: MEM(); ~MEM(); KEYS *keys; TAP *tap; // read memory through memory decoder unsigned char read(unsigned int addr); // read memory directly unsigned char readDMA(unsigned int addr) { return Ram[addr]; } // same as above but with writing void wrt(unsigned int addr, unsigned char value); void wrtDMA(unsigned int addr, unsigned char value) { Ram[addr]=value; } void setRamMask(unsigned int value) { RAMMask=value;} unsigned int getRamMask(void) { return RAMMask;} // are the ROMs disabled? bool RAMenable; // indicates whether 256K RAM is on bool bigram, bramsm; // /ram/rom path/load variables void loadroms(void); void loadloromfromfile(int nr, char fname[256]); void loadhiromfromfile(int nr, char fname[256]); char romlopath[4][256]; char romhighpath[4][256]; // this is for the FRE support void dump(void *img); void memin(void *img); // screen rendering // raster co-ordinates and boundaries unsigned int beamx, beamy, scrleft, scrright, scrtop, scrbottom; unsigned int rcolconv[458]; unsigned char screen[(SCR_HSIZE+4)*(SCR_VSIZE+4)]; bool render_ok; void texttoscreen(int x,int y, char *scrtxt); void chrtoscreen(int x,int y, char scrchr); // cursor stuff unsigned int crsrpos; int crsrphase; bool crsrblinkon; // is joy emulated? bool joyemu; // CPU class pointer CPU *cpuptr; // TED process (main loop of emulation) void ted_process(); // tape stuff bool tapeload; bool tapesave; // TED sound frequencies unsigned int TEDfreq1, TEDfreq2, TEDVolume; unsigned int TEDChannel1, TEDChannel2, TEDDA, TEDNoise; void setDS( void *ds); bool soundon; unsigned char Ram[RAMSIZE]; unsigned char RomHi[4][ROMSIZE]; // timer stuff bool t1on, t2on, t3on; unsigned int timer1, timer2, timer3, t1start; private: // memory variables unsigned char RomLo[4][ROMSIZE]; unsigned char *actromlo, *actromhi; unsigned int RAMMask; unsigned char RamExt[4][RAMSIZE]; // Ram slots for 256 K RAM unsigned char *actram; // indicates if screen blank is off bool scrblank; // for vertical/horizontal smooth scroll unsigned int hshift, vshift; unsigned int nrwscr, fltscr; // char/color buffers unsigned char chrbuf[41], clrbuf[41]; int cposy; // rendering functions void (MEM::*scrmode)(); inline void hi_text(); void mc_text(); void ec_text(); void mcec(); void rv_text(); void hi_bitmap(); void mc_bitmap(); void illegalbank(); bool charrom; int rvsmode, grmode, ecmode; int scrattr, charbank; // border color unsigned int framecol; // various memory pointers unsigned char *colorbank; unsigned char *grbank, *charrambank, *charrombank; unsigned char *scrptr, *endptr, *ramptr; // ez nem itt volt const char *DMAptr; unsigned int fastmode, irqline; unsigned char hcol[2], mcol[4], ecol[4], bmmcol[4], *cset; // supplementary unsigned int htab312[SCR_VSIZE+4]; unsigned int vtab320[321]; unsigned int htab40[256]; unsigned char hccmask[SCR_HSIZE+4]; unsigned char mccmask[SCR_HSIZE+4]; unsigned char mccmask2[SCR_HSIZE+4]; int xcol[460], crclrx[1025], crclry[1025]; unsigned int xbeam[458]; }; const short HUE[16] = { 0, 0, /*RED*/ 103, /*CYAN */ 283, /*MAGENTA*/ 53,/*GREEN*/ 241, /*BLUE*/347, /*YELLOW*/ 167,/*ORANGE*/123, /*BROWN*/ 148, /*YLLW-GRN*/ 195, /*PINK*/ 83, /*BLU-GRN*/ 265, /*LT-BLU*/ 323, /*DK-BLU*/ /*23 original, but wrong...*/ 355, /*LT-GRN */ 213 }; const unsigned char p4col_digi[768] = { // 2*128*3 color RGB components twice 0x03, 0x03, 0x03, 0x2f, 0x2f, 0x2f, 0x68, 0x10, 0x10, 0x00, 0x42, 0x42, 0x58, 0x00, 0x6d, 0x00, 0x4e, 0x00, 0x19, 0x1c, 0x94, 0x38, 0x38, 0x00, 0x56, 0x20, 0x00, 0x4b, 0x28, 0x00, 0x16, 0x48, 0x00, 0x69, 0x07, 0x2f, 0x00, 0x46, 0x26, 0x06, 0x2a, 0x80, 0x2a, 0x14, 0x9b, 0x0b, 0x49, 0x00, 0x03, 0x03, 0x03, 0x3d, 0x3d, 0x3d, 0x75, 0x1e, 0x20, 0x00, 0x50, 0x4f, 0x6a, 0x10, 0x78, 0x04, 0x5c, 0x00, 0x2a, 0x2a, 0xa3, 0x4c, 0x47, 0x00, 0x69, 0x2f, 0x00, 0x59, 0x38, 0x00, 0x26, 0x56, 0x00, 0x75, 0x15, 0x41, 0x00, 0x58, 0x3d, 0x15, 0x3d, 0x8f, 0x39, 0x22, 0xae, 0x19, 0x59, 0x00, 0x03, 0x03, 0x03, 0x42, 0x42, 0x42, 0x7b, 0x28, 0x20, 0x02, 0x56, 0x59, 0x6f, 0x1a, 0x82, 0x0a, 0x65, 0x09, 0x30, 0x34, 0xa7, 0x50, 0x51, 0x00, 0x6e, 0x36, 0x00, 0x65, 0x40, 0x00, 0x2c, 0x5c, 0x00, 0x7d, 0x1e, 0x45, 0x01, 0x61, 0x45, 0x1c, 0x45, 0x99, 0x42, 0x2d, 0xad, 0x1d, 0x62, 0x00, 0x03, 0x03, 0x03, 0x56, 0x55, 0x5a, 0x90, 0x3c, 0x3b, 0x17, 0x6d, 0x72, 0x87, 0x2d, 0x99, 0x1f, 0x7b, 0x15, 0x46, 0x49, 0xc1, 0x66, 0x63, 0x00, 0x84, 0x4c, 0x0d, 0x73, 0x55, 0x00, 0x40, 0x72, 0x00, 0x91, 0x33, 0x5e, 0x19, 0x74, 0x5c, 0x32, 0x59, 0xae, 0x59, 0x3f, 0xc3, 0x32, 0x76, 0x00, 0x03, 0x03, 0x03, 0x84, 0x7e, 0x85, 0xbb, 0x67, 0x68, 0x45, 0x96, 0x96, 0xaf, 0x58, 0xc3, 0x4a, 0xa7, 0x3e, 0x73, 0x73, 0xec, 0x92, 0x8d, 0x11, 0xaf, 0x78, 0x32, 0xa1, 0x80, 0x20, 0x6c, 0x9e, 0x12, 0xba, 0x5f, 0x89, 0x46, 0x9f, 0x83, 0x61, 0x85, 0xdd, 0x84, 0x6c, 0xef, 0x5d, 0xa3, 0x29, 0x03, 0x03, 0x03, 0xb2, 0xac, 0xb3, 0xe9, 0x92, 0x92, 0x6c, 0xc3, 0xc1, 0xd9, 0x86, 0xf0, 0x79, 0xd1, 0x76, 0x9d, 0xa1, 0xff, 0xbd, 0xbe, 0x40, 0xdc, 0xa2, 0x61, 0xd1, 0xa9, 0x4c, 0x93, 0xc8, 0x3d, 0xe9, 0x8a, 0xb1, 0x6f, 0xcd, 0xab, 0x8a, 0xb4, 0xff, 0xb2, 0x9a, 0xff, 0x88, 0xcb, 0x59, 0x03, 0x03, 0x03, 0xca, 0xca, 0xca, 0xff, 0xac, 0xac, 0x85, 0xd8, 0xe0, 0xf3, 0x9c, 0xff, 0x92, 0xea, 0x8a, 0xb7, 0xba, 0xff, 0xd6, 0xd3, 0x5b, 0xf3, 0xbe, 0x79, 0xe6, 0xc5, 0x65, 0xb0, 0xe0, 0x57, 0xff, 0xa4, 0xcf, 0x89, 0xe5, 0xc8, 0xa4, 0xca, 0xff, 0xc8, 0xb8, 0xff, 0xa2, 0xe5, 0x7a, 0x03, 0x03, 0x03, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xf2, 0xd1, 0xff, 0xff, 0xff, 0xe9, 0xff, 0xdb, 0xff, 0xd3, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xa3, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xb2, 0xfc, 0xff, 0xa2, 0xff, 0xee, 0xff, 0xd1, 0xff, 0xff, 0xeb, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xed, 0xff, 0xbc, 0x03, 0x03, 0x03, 0x2f, 0x2f, 0x2f, 0x68, 0x10, 0x10, 0x00, 0x42, 0x42, 0x58, 0x00, 0x6d, 0x00, 0x4e, 0x00, 0x19, 0x1c, 0x94, 0x38, 0x38, 0x00, 0x56, 0x20, 0x00, 0x4b, 0x28, 0x00, 0x16, 0x48, 0x00, 0x69, 0x07, 0x2f, 0x00, 0x46, 0x26, 0x06, 0x2a, 0x80, 0x2a, 0x14, 0x9b, 0x0b, 0x49, 0x00, 0x03, 0x03, 0x03, 0x3d, 0x3d, 0x3d, 0x75, 0x1e, 0x20, 0x00, 0x50, 0x4f, 0x6a, 0x10, 0x78, 0x04, 0x5c, 0x00, 0x2a, 0x2a, 0xa3, 0x4c, 0x47, 0x00, 0x69, 0x2f, 0x00, 0x59, 0x38, 0x00, 0x26, 0x56, 0x00, 0x75, 0x15, 0x41, 0x00, 0x58, 0x3d, 0x15, 0x3d, 0x8f, 0x39, 0x22, 0xae, 0x19, 0x59, 0x00, 0x03, 0x03, 0x03, 0x42, 0x42, 0x42, 0x7b, 0x28, 0x20, 0x02, 0x56, 0x59, 0x6f, 0x1a, 0x82, 0x0a, 0x65, 0x09, 0x30, 0x34, 0xa7, 0x50, 0x51, 0x00, 0x6e, 0x36, 0x00, 0x65, 0x40, 0x00, 0x2c, 0x5c, 0x00, 0x7d, 0x1e, 0x45, 0x01, 0x61, 0x45, 0x1c, 0x45, 0x99, 0x42, 0x2d, 0xad, 0x1d, 0x62, 0x00, 0x03, 0x03, 0x03, 0x56, 0x55, 0x5a, 0x90, 0x3c, 0x3b, 0x17, 0x6d, 0x72, 0x87, 0x2d, 0x99, 0x1f, 0x7b, 0x15, 0x46, 0x49, 0xc1, 0x66, 0x63, 0x00, 0x84, 0x4c, 0x0d, 0x73, 0x55, 0x00, 0x40, 0x72, 0x00, 0x91, 0x33, 0x5e, 0x19, 0x74, 0x5c, 0x32, 0x59, 0xae, 0x59, 0x3f, 0xc3, 0x32, 0x76, 0x00, 0x03, 0x03, 0x03, 0x84, 0x7e, 0x85, 0xbb, 0x67, 0x68, 0x45, 0x96, 0x96, 0xaf, 0x58, 0xc3, 0x4a, 0xa7, 0x3e, 0x73, 0x73, 0xec, 0x92, 0x8d, 0x11, 0xaf, 0x78, 0x32, 0xa1, 0x80, 0x20, 0x6c, 0x9e, 0x12, 0xba, 0x5f, 0x89, 0x46, 0x9f, 0x83, 0x61, 0x85, 0xdd, 0x84, 0x6c, 0xef, 0x5d, 0xa3, 0x29, 0x03, 0x03, 0x03, 0xb2, 0xac, 0xb3, 0xe9, 0x92, 0x92, 0x6c, 0xc3, 0xc1, 0xd9, 0x86, 0xf0, 0x79, 0xd1, 0x76, 0x9d, 0xa1, 0xff, 0xbd, 0xbe, 0x40, 0xdc, 0xa2, 0x61, 0xd1, 0xa9, 0x4c, 0x93, 0xc8, 0x3d, 0xe9, 0x8a, 0xb1, 0x6f, 0xcd, 0xab, 0x8a, 0xb4, 0xff, 0xb2, 0x9a, 0xff, 0x88, 0xcb, 0x59, 0x03, 0x03, 0x03, 0xca, 0xca, 0xca, 0xff, 0xac, 0xac, 0x85, 0xd8, 0xe0, 0xf3, 0x9c, 0xff, 0x92, 0xea, 0x8a, 0xb7, 0xba, 0xff, 0xd6, 0xd3, 0x5b, 0xf3, 0xbe, 0x79, 0xe6, 0xc5, 0x65, 0xb0, 0xe0, 0x57, 0xff, 0xa4, 0xcf, 0x89, 0xe5, 0xc8, 0xa4, 0xca, 0xff, 0xc8, 0xb8, 0xff, 0xa2, 0xe5, 0x7a, 0x03, 0x03, 0x03, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xf2, 0xd1, 0xff, 0xff, 0xff, 0xe9, 0xff, 0xdb, 0xff, 0xd3, 0xe8, 0xe8, 0xff, 0xff, 0xff, 0xa3, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xb2, 0xfc, 0xff, 0xa2, 0xff, 0xee, 0xff, 0xd1, 0xff, 0xff, 0xeb, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xed, 0xff, 0xbc, }; const double luma[9] = { /* Luminancia Voltages */ 2.00, 2.4, 2.55, 2.7, 2.9, 3.3, 3.6, 4.1, 4.8 }; const double sat[9] = { //60.0, 72.0, 74.0, 68.0, 63.0, 51.0, 42.0, 27.0, 6.0 17.0, 23.0, 30.0, 38.0, 55.0, 60.0, 38.0, 8.59 }; #endif //_TEDMEM_H /* int brightness = ...; //* 0..255 int contrast = ...; //* 0..255 for (i=0; i < 128; i++) { int k = (brightness-128) + (contrast*i)/128; if (k < 0) k=0; else if (k > 255) k = 255; table[i] = k; } */