// File: /workspace/github_c_makefile_star2_O0/calmopyrin[P]tedplay/Tedmem.cpp
// Function: TED::Read(unsigned int)
unsigned char TED::Read(unsigned int addr)
{
	switch ( addr & 0xF000 ) {
		case 0x0000:
			switch ( addr & 0xFFFF ) {
				case 0:
					return prddr;
				case 1:
					{
						unsigned char retval =
							(
							//ReadBus()&
							0xC0)
							//|(tap->ReadCSTIn(CycleCounter)&0x10)
							;
						return (prp&prddr)|(retval&~prddr);
					}
				default:
					return actram[addr&0xFFFF];
			}
			break;
		case 0x1000:
		case 0x2000:
		case 0x3000:
			return actram[addr&0xFFFF];
		case 0x4000:
		case 0x5000:
		case 0x6000:
		case 0x7000:
			return actram[addr&RAMMask];
		case 0x8000:
		case 0x9000:
		case 0xA000:
		case 0xB000:
			return mem_8000_bfff[addr&0x3FFF];
		case 0xC000:
		case 0xD000:
		case 0xE000:
			return mem_c000_ffff[addr&0x3FFF];
		case 0xF000:
			switch ( addr >> 8 ) {
				case 0xFF:
					switch (addr) {
						case 0xFF00 : return timer1&0xFF;
						case 0xFF01 : return timer1>>8;
						case 0xFF02 : return timer2&0xFF;
						case 0xFF03 : return timer2>>8;
						case 0xFF04 : return timer3&0xFF;
						case 0xFF05 : return timer3>>8;
						case 0xFF06 : return Ram[0xFF06];
						case 0xFF07 : return Ram[0xFF07];
						case 0xFF08 :
#if 0
							if (joyemu)
								  return keys->feedjoy(Ram[0xFF08])&(keys->feedkey(Ram[0xFD30]));
							  else
								  return keys->feedkey(Ram[0xFD30]);
#else
							return 0xFF;
#endif
						case 0xFF09 : return Ram[0xFF09]|(0x25);
						case 0xFF0A : return Ram[0xFF0A]|(0xA0);
						case 0xFF0B : return irqline & 0xFF;
						case 0xFF0C : return ((crsrpos>>8)&0x03)|0xFC;
						case 0xFF0D : return crsrpos&0xFF;
						case 0xFF10 : return Ram[0xFF10] | 0x7C;
						case 0xFF12 : return Ram[0xFF12] | 0xC0;
						case 0xFF0E :
						case 0xFF0F :
						case 0xFF11 :
						case 0xFF13 :
							return Ram[addr];
						case 0xFF14 : return Ram[addr]|0x07;	// lowest 3 bits are always high
						case 0xFF15 : return ecol[0]|0x80;	// The highest bit is not used and so always 1
						case 0xFF16 : return ecol[1]|0x80;	// A few games (Rockman) used it...
						case 0xFF17 : return ecol[2]|0x80;
						case 0xFF18 : return ecol[3]|0x80;
						case 0xFF19 : return (framecol&0xFF)|0x80;
						case 0xFF1A : return (CharacterPositionReload>>8)&0xFF;
						case 0xFF1B : return CharacterPositionReload&0xFF;
						case 0xFF1C : return (beamy>>8)|0xFE;
						case 0xFF1D : return beamy&0xFF; /// 1-8. bit of the rasterline counter
						case 0xFF1E : return ((98+beamx)<<1)%228; // raster column
						case 0xFF1F : return 0x80|(crsrphase<<3)|VertSubCount;
						default:
							return mem_c000_ffff[addr&0x3FFF];
					}
					break;
				case 0xFE:
					//return tcbmbus->Read(addr);
					//return 0xFE;
					return protectedPlayerMemory[addr & 0xfff];
				case 0xFD:
					switch (addr>>4) {
						case 0xFD0: // RS232
							return 0xFD;
						case 0xFD1: // User port, PIO & 256 RAM expansion
							//return (tap->IsButtonPressed()<<2)^0xFF;
							return 0xFF;
						case 0xFD2: // Speech hardware
						case 0xFD4: // SID Card
						case 0xFD5:
							if (sidCard) {
								return sidCard->read(addr & 0x1f);
							}
							return 0xFD;
						case 0xFD3:
							return Ram[0xFD30];
					}
					return 0xFD;
				case 0xFC:
					return mem_fc00_fcff[addr&0x3FFF];
				default:
					return mem_c000_ffff[addr&0x3FFF];
			}
	}
	//fprintf(stderr,"Unhandled read %04X\n", addr);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
movl %eax, -0x1c(%rbp)
je 0x16d4d
jmp 0x16c5a
movl -0x1c(%rbp), %eax
subl $0x1000, %eax           # imm = 0x1000
je 0x16dc9
jmp 0x16c6a
movl -0x1c(%rbp), %eax
subl $0x2000, %eax           # imm = 0x2000
je 0x16dc9
jmp 0x16c7a
movl -0x1c(%rbp), %eax
subl $0x3000, %eax           # imm = 0x3000
je 0x16dc9
jmp 0x16c8a
movl -0x1c(%rbp), %eax
subl $0x4000, %eax           # imm = 0x4000
je 0x16dea
jmp 0x16c9a
movl -0x1c(%rbp), %eax
subl $0x5000, %eax           # imm = 0x5000
je 0x16dea
jmp 0x16caa
movl -0x1c(%rbp), %eax
subl $0x6000, %eax           # imm = 0x6000
je 0x16dea
jmp 0x16cba
movl -0x1c(%rbp), %eax
subl $0x7000, %eax           # imm = 0x7000
je 0x16dea
jmp 0x16cca
movl -0x1c(%rbp), %eax
subl $0x8000, %eax           # imm = 0x8000
je 0x16e0b
jmp 0x16cda
movl -0x1c(%rbp), %eax
subl $0x9000, %eax           # imm = 0x9000
je 0x16e0b
jmp 0x16cea
movl -0x1c(%rbp), %eax
subl $0xa000, %eax           # imm = 0xA000
je 0x16e0b
jmp 0x16cfa
movl -0x1c(%rbp), %eax
subl $0xb000, %eax           # imm = 0xB000
je 0x16e0b
jmp 0x16d0a
movl -0x1c(%rbp), %eax
subl $0xc000, %eax           # imm = 0xC000
je 0x16e2c
jmp 0x16d1a
movl -0x1c(%rbp), %eax
subl $0xd000, %eax           # imm = 0xD000
je 0x16e2c
jmp 0x16d2a
movl -0x1c(%rbp), %eax
subl $0xe000, %eax           # imm = 0xE000
je 0x16e2c
jmp 0x16d3a
movl -0x1c(%rbp), %eax
subl $0xf000, %eax           # imm = 0xF000
je 0x16e4d
jmp 0x17242
movzwl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x16d64
jmp 0x16d5a
movl -0x2c(%rbp), %eax
subl $0x1, %eax
je 0x16d76
jmp 0x16da8
movq -0x28(%rbp), %rax
movb 0xb6019(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rdx
movb $-0x40, -0x15(%rbp)
movzbl 0xb6018(%rdx), %eax
movzbl 0xb6019(%rdx), %ecx
andl %ecx, %eax
movzbl -0x15(%rbp), %ecx
movzbl 0xb6019(%rdx), %edx
xorl $-0x1, %edx
andl %edx, %ecx
orl %ecx, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0xb6010(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0xb6010(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rdx
movq 0xb6010(%rdx), %rax
movl -0x14(%rbp), %ecx
andl 0x76008(%rdx), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0x75ff0(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0x75ff8(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movl -0x14(%rbp), %eax
shrl $0x8, %eax
addl $0xffffff04, %eax       # imm = 0xFFFFFF04
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x3, %eax
ja 0x17224
movq -0x38(%rbp), %rax
leaq 0x87f6(%rip), %rcx      # 0x1f668
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x14(%rbp), %eax
addl $0xffff0100, %eax       # imm = 0xFFFF0100
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x1f, %eax
ja 0x17146
movq -0x40(%rbp), %rax
leaq 0x87f3(%rip), %rcx      # 0x1f690
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x28(%rbp), %rax
movl 0x65fc4(%rax), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x65fc4(%rax), %eax
shrl $0x8, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x65fc8(%rax), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x65fc8(%rax), %eax
shrl $0x8, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x65fcc(%rax), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x65fcc(%rax), %eax
shrl $0x8, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movb 0x55ec6(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movb 0x55ec7(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movb $-0x1, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0x55ec9(%rax), %eax
orl $0x25, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0x55eca(%rax), %eax
orl $0xa0, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0xb6184(%rax), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x45fa8(%rax), %eax
shrl $0x8, %eax
andl $0x3, %eax
orl $0xfc, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x45fa8(%rax), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0x55ed0(%rax), %eax
orl $0x7c, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0x55ed2(%rax), %eax
orl $0xc0, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
movb 0x45fc0(%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
movzbl 0x45fc0(%rax,%rcx), %eax
orl $0x7, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0xb618e(%rax), %eax
orl $0x80, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0xb618f(%rax), %eax
orl $0x80, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0xb6190(%rax), %eax
orl $0x80, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movzbl 0xb6191(%rax), %eax
orl $0x80, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0xb6138(%rax), %eax
andl $0xff, %eax
orl $0x80, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movl 0x1e888(%rip), %eax     # 0x35938
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movl 0x1e872(%rip), %eax     # 0x35938
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x820(%rax), %eax
shrl $0x8, %eax
orl $0xfe, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x820(%rax), %eax
andl $0xff, %eax
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x81c(%rax), %eax
addl $0x62, %eax
shll %eax
movl $0xe4, %ecx
xorl %edx, %edx
divl %ecx
movb %dl, %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl 0x45fac(%rax), %eax
shll $0x3, %eax
orl $0x80, %eax
orl 0x1e7e2(%rip), %eax     # 0x35920
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0x75ff8(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
movl %ecx, %ecx
movb 0xb61b8(%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movl -0x14(%rbp), %eax
shrl $0x4, %eax
addl $0xfffff030, %eax       # imm = 0xFFFFF030
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x5, %eax
ja 0x17200
movq -0x48(%rbp), %rax
leaq 0x84d2(%rip), %rcx      # 0x1f678
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $-0x3, -0x1(%rbp)
jmp 0x17246
movb $-0x1, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
cmpq $0x0, 0xb71d0(%rax)
je 0x171eb
movq -0x28(%rbp), %rax
movq 0xb71d0(%rax), %rdi
movl -0x14(%rbp), %esi
andl $0x1f, %esi
movq (%rdi), %rax
callq *0x38(%rax)
movb %al, -0x1(%rbp)
jmp 0x17246
movb $-0x3, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movb 0x55cf0(%rax), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movb $-0x3, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0x76000(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movq -0x28(%rbp), %rax
movq 0x75ff8(%rax), %rax
movl -0x14(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1(%rbp)
jmp 0x17246
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x50, %rsp
popq %rbp
retq
nop