Extrn GetDec:Far, PutDec:Far, PutDec:Far, Putstrng:Far, NewLine:Far ; #include "iostream.h" Data Segment ;######Game variables########### CASH dw -5551 ;cash in cents DAY dw 1 GlassesSold dw ? PriceperGlass dw -56 Income dw ? Expenses dw ? GlassesMade dw ? AdvertisingMade dw ? AdvertisingCost dw 15 Profit dw ? Assets dw ? CurrentAssets dw ? DaystoPlay dw ? ;######inputforday function prompts###### OnDay db "On day " ; length 7 LemonadeCost db ", The Cost of Lemonade is " ; length 26 ;######Random number function vars###### RAND_k dw 369 RAND_seed dw ? ;######prompts######### intro db "Welcome to lemonade stand" ;basic intro prompt 25 weather db 'Todays weather is' ;weather report 17 dailystatement db 'Lemonade stand Daily Statement:' ;daily statement 31 date db 'On day: ' ;day output sales db 'Glasses sold: ' ; glasses sold 14 priceprompt db 'Price per glass: ' ; price per glass 17 production db 'Glasses made: ' ; glasses made 14 advertsprompt db 'Signs made: ' ; signs made 12 profitprompt db 'Profit: ' ;profit prompt 8 AssetsPrompt db 'Assets: ' ;asset prompt 8 glassesprompt db 'How many glasses of lemonade to you wish to make? ';length 50 advertisingprompt db 'How many advertising signs do you wish to make (15 cents each)? ' ;64 lemonadepriceprompt db 'What price (in cents) do you wish to charge for lemonade? '; 56 Data Ends Code Segment Assume Cs:Code, Ds:Data, Ss:Sseg ;#####Convert to Dollar####### ;takes 1 value converts it front cents ;to dollars ;Returns Whole # in Ax ;Cents # in DX @CentstoDollars Proc Near C, @CASH:WORD push Bx xor dx,dx mov Ax, @Cash cwd mov Bx, 100 iDiv Bx pop Bx @ctdif: cmp Dx, 0 jl @ctdthen jmp @ctdendif @ctdthen: neg Dx jmp @ctdendif @ctdendif: ret @CentstoDollars Endp ;#####random number generator####### ;gets a large number, a seed, and an upper limit ;seed is wiped out initially ;system time is used for seed ;answer is returned in Ax @RANDOMNUMBER Proc Near C, K:WORD, seed:WORD, @high:word push Bx push Cx push Dx xor Ax, Ax ;clear AX mov ah, 2Ch ;load 2Ch into ah int 21h ;load system time into registers mov seed, Dx ;dh holds seconds, dl holds ms, move to seed mov ax, seed ;move seed to Ax mul k ;multiply by large k inc ax ;add 1 mov seed, ax ;put Ax into the seed shr ax,1 ;shift logical right 1 place mov bx, @high ;put high value into Bx add bx, 5 ;add 5 to it @loopit: and ax, bx ;mask to 5+ax mov bx, @high ;put high into bx cmp al, bl ;is it high#? ja @loopit ;loop till a number is chosen < high pop Dx pop cx pop Bx ret @RANDOMNUMBER ENDp ;####ClearScreen###### ;clears the screen with a loop ;puts @line # of new lines on the screen @cLEARSCREEN Proc Near C, @lines:word push Ax push Bx push Cx push Dx mov Bx, @lines @CSfor: cmp bx, 0 ja @CSdo jmp @CSendfor @CSdo: call newline dec Bx jmp @CSfor @CSendfor: pop Dx pop Cx pop Bx pop Ax ret @CLEARSCREEN ENDp ;######outputs cents formated nicely##### ;outputs -3453 or 300 as $34.53 or $3.00 ;input is money in cents @outputdollars Proc Near C, @money:word push ax push bx push cx push dx invoke @CentstoDollars, @money ;break money apart into ;dollars and cents push Ax push dx xor ax, ax xor dx, dx mov ah, 02h mov Dl, 36 int 21h pop Dx pop Ax @optif2: cmp @money, 0 jl @optand2 jmp @optendif2 @optand2: cmp @money, -100 jg @optthen2 jmp @optendif2 @optthen2: push Ax push dx xor ax, ax xor dx, dx mov ah, 02h mov Dl, 45 int 21h pop Dx pop Ax jmp @optendif2 @optendif2: call putdec push Ax push dx xor ax, ax xor dx, dx mov ah, 02h mov Dl, 46 int 21h pop Dx pop Ax mov Ax, Dx @optif: cmp Ax, 10 Jb @optthen jmp @optendif @optthen: push Ax mov Ax, 0 call putdec pop Ax jmp @optendif @optendif: call putdec pop dx pop cx pop bx pop ax ret @outputdollars ENDp @InputForDay Proc Near C push ax push bx push cx push dx Mov Cx, 7 Lea Di, onday Call Putstrng mov Ax, DAY call putdec Mov Cx, 26 Lea Di, lemonadecost Call Putstrng invoke @outputdollars, PricePerglass call newline Mov Cx, 7 Lea Di, assetsprompt Call Putstrng invoke @outputdollars, CASH call newline Mov Cx, 50 Lea Di, glassesprompt Call Putstrng call getdec mov GlassesMade, Ax call newline Mov Cx, 64 Lea Di, advertisingprompt Call Putstrng call getdec mov advertisingmade, Ax call newline Mov Cx, 58 Lea Di, lemonadepriceprompt Call Putstrng call getdec mov priceperglass, Ax pop dx pop cx pop bx pop ax ret @InputForDay endp ;#######Asset Statement############ @AssetStatement Proc Near C push cx push ax invoke @clearscreen, 25 mov cx,31 lea di,dailystatement call putstrng call newline mov cx,8 lea di,date call putstrng mov ax,day call putdec call newline mov cx,14 lea di,sales call putstrng mov ax,GlassesSold call putdec call newline mov cx,17 lea di,priceprompt call putstrng invoke @outputdollars,PriceperGlass call newline mov cx,14 lea di,production call putstrng mov ax,GlassesMade call putdec call newline mov cx,12 lea di,advertsprompt call putstrng mov ax,AdvertisingMade call putdec call newline mov cx,8 lea di,profitprompt call putstrng invoke @outputdollars,Profit call newline lea di,assetsprompt call putstrng invoke @outputdollars,assets call newline pop cx pop ax ret @AssetStatement ENDp @PromptforDays proc near C ret @promptforDays endp @GenerateWeather Proc near C ret @generateweather endp main Proc Far MOV AX,SEG DATA MOV DS,AX MOV ES,AX invoke @clearscreen, 20 Mov Cx, 25 Lea Di, intro Call Putstrng Call Newline invoke @Centstodollars, CASH call Putdec call newline mov ax,dx call putdec call newline invoke @RANDOMNUMBER, RAND_k, RAND_seed, 50 call Putdec call newline invoke @RANDOMNUMBER, RAND_k, RAND_seed, 70 call Putdec call newline invoke @InputForDay Mov Ah, 4Ch Int 21h main Endp Code Ends SSeg Segment STACK DB 254 dup(?) SSeg Ends End main