4 #define COINMECH_ID 0x20
16 u8 parity_test(u8 c) {
18 for (parity = 0; c; c = c>>1) {
19 if (c&1) parity = !parity;
24 bool parity_good(u8 c) {
27 * parity_good truth table:
36 u8 R8 = (_io_ports[M6811_SCCR1] & M6811_R8)?1:0;
37 u8 p = parity_test(c)?1:0;
41 void send_byte(u8 c) {
43 while (!(_io_ports[M6811_SCSR] & M6811_TDRE)); /* wait for TD register empty */
46 bset((void*)&_io_ports[M6811_SCCR1], M6811_T8);
48 bclr((void*)&_io_ports[M6811_SCCR1], M6811_T8);
51 void ask_for_retrans() {
52 /* sends an 0xff down the line */
57 #define IS_CTRL(x) (x & 0x10) /* true if this packet is a control packet */
58 void sci_interrupt() {
60 in = _io_ports[M6811_SCDR];
62 /* test for framing errors & parity bit */
63 if (_io_ports[M6811_SCSR] & M6811_FE || !parity_good(in)) {
64 _io_ports[M6811_SCDR]; /* read of register req'd to clear FE */
69 /* all bytes must have the correct ID in the 3 MSBs */
70 if ((in & 0xe0) != COINMECH_ID) return;
72 /* we have a good packet */
74 /* retransmit was requested */
79 if (packet_pos != 0 || IS_CTRL(in&0x10)) {
83 /* just reply with ack */
84 /* original firmware does something with link master price holding */
87 /* write back how much change to give, or 0xfe to hold it. */
89 send_byte(item_cost / value_2);
94 /* hmmm, maybe we're sposed to do something here. firmware doesnt */
95 /* and just sets a random bit - something like "changer in use"? */
103 /* just ack it and move on */
108 switch (packet_pos) {
109 case 1: value_1 = in; break;
110 case 2: value_1 |= in << 4; break;
111 case 3: value_1 |= in << 8; break;
112 case 4: value_1 |= in << 12; break;
113 case 5: value_2 = in; break;
114 case 6: value_2 |= in << 4; break;
115 case 7: dec_point = in; break;
116 case 8: have_change = (in&0x01); break;
118 if (packet_pos == 9) {
120 coin_value = value_1*value_2;
125 send_byte(0x00); /* ack */
130 coin_cost(coin_value); /* eat everything */
133 void coin_cost(u16 cost) {