public static ReadHandlerPtr galaga_customio_data_r = new ReadHandlerPtr() { public int handler(int offset)
	{
	//if (errorlog && customio_command != 0x71) fprintf(errorlog,"%04x: custom IO read offset %02x\n",cpu_get_pc(),offset);
	
		switch (customio_command)
		{
			case 0x71:	/* read input */
			case 0xb1:	/* only issued after 0xe1 (go into credit mode) */
				if (offset == 0)
				{
					if (mode != 0)	/* switch mode */
					{
						/* bit 7 is the service switch */
						return readinputport(4);
					}
					else	/* credits mode: return number of credits in BCD format */
					{
						int in;
						
	
	
						in = readinputport(4);
	
						/* check if the user inserted a coin */
						if (coinpercred > 0)
						{
							if ((in & 0x70) != 0x70 && credits < 99)
							{
								coininserted++;
								if (coininserted >= coinpercred)
								{
									credits += credpercoin;
									coininserted = 0;
								}
							}
						}
						else credits = 2;
	
	
						/* check for 1 player start button */
						if ((in & 0x04) == 0)
							if (credits >= 1) credits--;
	
						/* check for 2 players start button */
						if ((in & 0x08) == 0)
							if (credits >= 2) credits -= 2;
	
						return (credits / 10) * 16 + credits % 10;
					}
				}
				else if (offset == 1)
					return readinputport(2);	/* player 1 input */
				else if (offset == 2)
					return readinputport(3);	/* player 2 input */
	
				break;
		}
	
		return -1;
	} }