/* atm.c */ /* uses dirty functions calling functions calling functions because no one taught me how to program properly */ /* CPU ports documentation: Port0: Card reader, player ID Port1: Card reader, card ID Ports2-4: Number buttons 1-3 Ports5,6: Up/Down arrow keys Port7: Enter/Accept key Port8: Cancel/Abort key */ /* Screen is 0x0 - 30x18 */ #define NO_CMATH /* don't need any math */ #define FUNDSINCAMOUNT 5 /* the amount to inc/dec fund selection by - I recommend 5 */ #define BACKGROUNDCOLOR 049 /* The background color to use - 049 is a soothing blue */ #include clib.c /* for stdc functions */ #include lolilib.c /* for LOLIFUNCTIONS */ int playerID; int cardID; int currentFunds; main() { /* The following code before the while loop executes only once. */ int menuChoice; char cardIDString[7]; char currentCardIDString[24]; extern int playerID; extern int cardID; extern int currentFunds; welcomeMessage(); while (true) { /* This is the primary wait loop */ /* we're checking to see if the card reader is reporting a non-zero card ID */ if ( inport(1) != 0 ) { /* a card has appeared (I hope), so open access to the ATM */ playerID = inport(0); cardID = inport(1); clrscr(); setbg(BACKGROUNDCOLOR); loli_print("------------------------------",0,0); loli_print("WELCOME!",0,1); loli_print("User ID confirmed - Hello!",2,2); //"Current card ID: 123456" itoa(cardID, cardIDString); strcpy(currentCardIDString, "Current card ID: "); strcat(currentCardIDString, &cardIDString); loli_print(¤tCardIDString,3,3) /* The user is now authenticated. */ /* Get the user's current funds and present the menu. */ currentFunds = getCurrentFunds(); menuChoice = transactionMenu(); /* here's the fork in the road. */ if (menuChoice == 1) { currentFunds -= withdrawScreen(); endgameScreen(); else if (menuChoice == 2) currentFunds += depositScreen(); endgameScreen(); else if (menuChoice == 3) fundsScreen(); } } } } welcomeMessage() { /* welcome the user */ clrscr(); loli_print("K E Y C A R D",8,6); loli_print("E N A B L E D",8,7); loli_print("_ _____ __ __",8,8); loli_print("/_\\_ _| \\/ |",7,9); loli_print("/ _ \\| | | |\\/| |",6,10); loli_print("/_/ \\_\\\\_| |_| |_|",5,11); loli_print("Insert keycard now.",5,13); } transactionMenu() { int menuChoice; /* present the main transaction menu. */ loli_print("Transaction menu:",0,9); loli_print("1. Withdraw",0,11); loli_print("2. Deposit",0,12); loli_print("3. View Funds",0,13); loli_print("Use the buttons on the right",0,15); loli_print("to choose.",0,17); loli_print("WELCOME!",22,17); loli_print("------------------------------",0,18); while (true) { if (inport(2) != 1) { return 1; else if (inport(3) != 1) return 2; else if (inport(3) != 1) return 3; } } } withdrawScreen() { char fundsString[25]; char fundsAmountString[6]; int fundsAmount; extern int currentFunds; fundsAmount = 0; clrscr(); loli_print("------------------------------",0,6); loli_print("Withdraw Funds",8,7); loli_print("------------------------------",0,8); loli_print("Please choose the amount of",0,10); loli_print("funds to withdraw by using the",0,11); loli_print("arrow keys on the right, then",0,12); loli_print("press enter to accept.",0,13); loli_print ("Funds to withdraw:",0,15); while (true) { if (inport(5) != 0) { if (fundsAmount == 0) { loli_print("Can't withdraw negative funds!",0,16); else fundsAmount += FUNDSINCAMOUNT; //loli_print(strcat("Funds to withdraw: ", itoa(fundsAmount))); itoa(fundsAmount, fundsAmountString); strcpy(fundsString, "Funds to withdraw: ",0,15); strcat(fundsString, &fundsAmountString); loli_print(&fundsString); } else if (inport(6) != 0) if (currentFunds - fundsAmount > currentFunds) { loli_print("Can't withdraw any more funds!",0,16); else fundsAmount -= FUNDSINCAMOUNT; itoa(fundsAmount, fundsAmountString); strcpy(fundsString, "Funds to withdraw: ",0,15); strcat(fundsString, &fundsAmountString); loli_print(&fundsString) } else if (inport(7) != 0) return fundsAmount; else if (inport(8) != 0) return 0; } } } depositScreen() { char fundsString[24]; char fundsAmountString[6]; int fundsAmount; extern int currentFunds; fundsAmount = 0; clrscr(); loli_print("------------------------------",0,6); loli_print("Deposit Funds",8,7); loli_print("------------------------------",0,8); loli_print("Please choose the amount of",0,10); loli_print("funds to deposit by using the",0,11); loli_print("arrow keys on the right, then",0,12); loli_print("press Enter to accept.",0,13); loli_print ("Funds to deposit:",0,15); while (true) { if (inport(5) != 0) { if (fundsAmount == 0) { loli_print("Can't deposit negative funds!",0,16); else fundsAmount += FUNDSINCAMOUNT; //loli_print(strcat("Funds to withdraw: ", itoa(fundsAmount))); itoa(fundsAmount, fundsAmountString); strcpy(fundsString, "Funds to deposit: ",0,15); strcat(fundsString, &fundsAmountString); loli_print(&fundsString); } else if (inport(6) != 0) if (65535 - currentFunds > fundsAmount) { loli_print("Can't deposit any more funds!",0,16); else fundsAmount -= FUNDSINCAMOUNT; itoa(fundsAmount, fundsAmountString); strcpy(fundsString, "Funds to deposit: ",0,17); strcat(fundsString, &fundsAmountString); loli_print(&fundsString) } else if (inport(7) != 0) return fundsAmount; else if (inport(8) != 0) return 0; } } } getCurrentFunds() { } setCurrentFunds() { } fundsScreen() { char fundsString[26]; char currentFundsString[6]; extern int currentFunds; clrscr(); loli_print("------------------------------",0,6); loli_print("Current Funds",8,7); loli_print("------------------------------",0,8); itoa(currentFunds, currentFundsString); strcpy(fundsString, "You currently have: ",2,10); strcat(fundsString, ¤tFundsString); loli_print(&fundsString); loli_print("Press Enter to continue.",3,12); while (true) { if (inport7 != 0) return; } } endgameScreen() { char fundsString[32]; char currentFundsString[6]; extern int currentFunds clrscr(); loli_print("------------------------------",0,0); loli_print("THANK YOU!",0,1); loli_print("Thank you for using the ATM!",1,5); itoa(currentFunds, currentFundsString); strcpy(fundsString, "Your funds amount is now: ",0,7); strcat(fundsString, ¤tFundsString); loli_print(&fundsString); loli_print("Please remove your keycard. ",1,9); loli_print("THANK YOU!",20,17); loli_print("------------------------------",0,18); while (true) { if inport(0) == 0) welcomeMessage(); return; } }