From: Bernard Blackham Date: Sun, 10 Aug 2003 14:46:09 +0000 (+0000) Subject: More coin mech code X-Git-Tag: ROMW~80 X-Git-Url: https://git.ucc.asn.au/?p=uccvend-snackrom.git;a=commitdiff_plain;h=11baa477da66fe8b2899dd50bd71d11615ff050e More coin mech code --- diff --git a/ROM2/coinmech.c b/ROM2/coinmech.c index 4701ada..b52559d 100644 --- a/ROM2/coinmech.c +++ b/ROM2/coinmech.c @@ -1,8 +1,17 @@ +#include "coinmech.h" #include "vend.h" #define COINMECH_ID 0x20 u8 last_byte; +u8 packet_pos = 0; +u16 value_1 = 0; +u8 value_2 = 0; +u8 dec_point = 0; + +u16 coin_value = 0; +u8 item_cost = 0; +bool have_change = 0; u8 parity_test(u8 c) { u8 parity = 0; @@ -12,6 +21,8 @@ u8 parity_test(u8 c) { return parity; } +bool parity_good(u8 c) { + /* * parity_good truth table: * @@ -22,7 +33,6 @@ u8 parity_test(u8 c) { * 1 | 0 1 */ -bool parity_good(u8 c) { u8 R8 = (_io_ports[M6811_SCCR1] & M6811_R8)?1:0; u8 p = parity_test(c)?1:0; return R8 == p; @@ -44,8 +54,6 @@ void ask_for_retrans() { } -u8 packet_pos = 0; - #define IS_CTRL(x) (x & 0x10) /* true if this packet is a control packet */ void sci_interrupt() { u8 in; @@ -68,13 +76,60 @@ void sci_interrupt() { return; } - if (packet_pos != 0 && !IS_CTRL(in&0x10)) { - switch (in & 0x0f) { + if (packet_pos != 0 || IS_CTRL(in&0x10)) { + in &= 0x0f; + switch (in) { + case 0x01: + /* just reply with ack */ + /* original firmware does something with link master price holding */ + send_byte(0x00); + case 0x02: + /* write back how much change to give, or 0xfe to hold it. */ + if (item_cost) { + send_byte(item_cost / value_2); + } else + send_byte(0xfe); + break; + case 0x03: + /* hmmm, maybe we're sposed to do something here. firmware doesnt */ + /* and just sets a random bit - something like "changer in use"? */ + break; + case 0x08: + /* start of packet */ + packet_pos = 1; + send_byte(0x00); + break; + default: + /* just ack it and move on */ + send_byte(0x00); } } else { - + in &= 0x0f; + switch (packet_pos) { + case 1: value_1 = in; break; + case 2: value_1 |= in << 4; break; + case 3: value_1 |= in << 8; break; + case 4: value_1 |= in << 12; break; + case 5: value_2 = in; break; + case 6: value_2 |= in << 4; break; + case 7: dec_point = in; break; + case 8: have_change = (in&0x01); break; + default: + if (packet_pos == 9) { + packet_pos = 0; + coin_value = value_1*value_2; + } + /* hmmm, else? */ + } + packet_pos++; + send_byte(0x00); /* ack */ } } void coin_eat() { + coin_cost(coin_value); /* eat everything */ +} + +void coin_cost(u16 cost) { + item_cost = cost; } diff --git a/ROM2/coinmech.h b/ROM2/coinmech.h index 5514d0b..8e8ad24 100644 --- a/ROM2/coinmech.h +++ b/ROM2/coinmech.h @@ -1,6 +1,11 @@ #ifndef _COINMECH_H_ #define _COINMECH_H_ +#include "vend.h" + +extern u16 coin_value; + void coin_eat(); +void coin_cost(u16 cost); /* specify the cost of an item. */ #endif /* _COINMECH_H_ */ diff --git a/ROM2/main.c b/ROM2/main.c index 61de403..81919f0 100644 --- a/ROM2/main.c +++ b/ROM2/main.c @@ -10,7 +10,6 @@ u16 pin; u8 selection; u16 scroll_timer; -u16 coin_value; bool uid_enter() { u8 uidpos; diff --git a/ROM2/memory.x b/ROM2/memory.x index 3546f0a..267c073 100644 --- a/ROM2/memory.x +++ b/ROM2/memory.x @@ -13,7 +13,7 @@ MEMORY { page0 (rwx) : ORIGIN = 0x0000, LENGTH = 0x00ff /* 256 bytes internal RAM */ text (rx) : ORIGIN = 0x8000, LENGTH = 0x7fff - data (rw) : ORIGIN = 0x0800, LENGTH = 0x07ff /* 2k external SRAM */ + data (rw) : ORIGIN = 0x0800, LENGTH = 0x07ff /* 2k external SRAM FIXME - dont want to use this */ } /* Setup the stack on the top of the data internal ram (not used). */