0100  *=$2000
0110 ;GET INCH AND OUTCH READY
0120  LDA $E406
0130  STA OUTCH+1
0140  INC OUTCH+1
0150  LDA $E407
0160  STA OUTCH+2
0170  LDA $E424
0180  STA INCH+1
0190  INC INCH+1
0200  LDA $E425
0210  STA INCH+2
0220 ;GET INBUFF READY FOR FLOAT
0230  LDA #BUFFER&255
0240  STA INBUFF
0250  LDA #BUFFER/256
0260  STA INBUFF+1
0270  JMP START
0280 ;CIO
0290 ICCMD=$342 ;COMMAND NUMBER
0300 ICSTA=$343 ;STATUS
0310 ICBAL=$344 ;BUFFER ADDRESS
0320 ICBAH=$345
0330 ICBLL=$348 ;BUFFER LENGTH
0340 ICBLH=$349
0350 ICAX1=$34A ;AUX
0360 ICAX2=$34B
0370 CIOV=$E456
0380 ;
0390 EOL=$9B
0400 LOW=$CB
0410 HIGH=$CC
0420 SAVEY=$CD
0430 SAVEX=$CE
0440 SAVEA=$CF
0450 ;
0460 ;2 BYTE POINTER TO ASCII
0470 INBUFF=$00F3 
0480 CIX=$00F2 ;OFFSET
0490 ;ASCII TO FLOATING POINT
0500 AFP=$D800
0510 ;FLOATING POINT TO INTEGER
0520 FPI=$D9D2
0530 ;6 BYTE FP NUMBER
0540 FRO=$00D4
0550 ;INTEGER TO FLOATING POINT
0560 IFP=$D9AA
0570 ;FLOATING POINT TO ASCII
0580 FASC=$D8E6
0590 RANDOM=$D20A
0600 BUFLEN=80
0610 BUFFER
0620  *=*+BUFLEN
0630 ;
0640 OUTCH
0650  JMP $FFFF
0660 ;
0670 INCH
0680  JMP $FFFF
0690 ;
0700 READLINE
0710  LDX #$0
0720  LDA #$5 ;GET RECORD
0730  STA ICCMD,X
0740  LDA #BUFLEN
0750  STA ICBLL,X
0760  LDA #$0
0770  STA ICBLH,X
0780  LDA #BUFFER&255
0790  STA ICBAL,X
0800  LDA #BUFFER/256
0810  STA ICBAH,X
0820  JMP CIOV
0830 ;
0840 ;A LOW
0850 ;Y HIGH
0860 ;WRITE MESSAGE ENDING IN EOL
0870 WRITE
0880  LDX #$0
0890  STA ICBAL,X
0900  STY ICBAH ;CAN'T ,X
0910  LDA #$9 ;PUT RECORD
0920  STA ICCMD,X
0930  LDA #$FF
0940  STA ICBLL,X
0950  STA ICBLH,X
0960  JMP CIOV
0970 ;
0980 ;A LOW
0990 ;Y HIGH
1000 ;WRITE MESSAGE ENDING IN ZERO
1010 WRITE0
1020  STA LOW
1030  STY HIGH
1040  LDY #0
1050 W0 LDA (LOW),Y
1060  BEQ W1
1070  INY
1080  JSR CHROUT
1090  JMP W0
1100 W1 RTS
1110 ;
1120 ;SOURCE A - NUMBER TO CONVERT
1130 ;OUTPUT X HIGH BYTE
1140 ; Y LOW BYTE
1150 ; A ENDS UP SAME AS X
1160 BIN2HEX
1170  TAX
1180  AND #$0F
1190  CMP #10
1200  CLC
1210  BMI B1
1220  ADC #39 ;LOWER
1230 B1
1240  ADC #48 ;'0' CONVERT TO ASCII
1250  TAY
1260 ;
1270  TXA
1280  AND #$F0
1290  LSR A
1300  LSR A
1310  LSR A
1320  LSR A
1330  CMP #10
1340  CLC
1350  BMI B2
1360  ADC #39 ;LOWER
1370 B2
1380  ADC #48 ;'0' CONVERT TO ASCII
1390  TAX
1400  RTS
1410 ;
1420 ;GET HEX AND PRINT IT OUT
1430 ;USES A X AND Y
1440 BIN2HEXOUT
1450  JSR BIN2HEX
1460  JSR CHROUT
1470  TYA
1480  JSR CHROUT
1490  RTS
1500 ;
1510 ;A IS CHARACTER TO OUTPUT
1520 ;USES SAVEX AND SAVEY
1530 CHROUT
1540  STX SAVEX
1550  STY SAVEY
1560  JSR OUTCH
1570  LDX SAVEX
1580  LDY SAVEY
1590  RTS
1600 ;
1610 EOLOUT
1620  LDA #EOL
1630  JMP CHROUT
1640 ;
1650 ;CONVERTS ASCII TO INT
1660 ;SAVES TWO BYTE INTEGER TO FRO
1670 TOINT
1680  LDA #0
1690  STA CIX
1700  JSR AFP
1710  BCS TOINTBAD
1720  JSR FPI
1730 TOINTBAD
1740  RTS
1750 ;
1760 ;FROM FRO AND FRO+1
1770 ;USES INBUFF
1780 INTOUT
1790  JSR IFP
1800  JSR FASC
1810  LDY #0
1820 L1 
1830  LDA (INBUFF),Y
1840  BMI L2 ;LAST DIGIT IS NEGATIVE
1850  JSR CHROUT 
1860  INY
1870  JMP L1
1880 L2
1890  AND #$7F ;%01111111
1900  JSR CHROUT
1910  LDA #BUFFER&255
1920  STA INBUFF
1930  LDA #BUFFER/256
1940  STA INBUFF+1
1950  RTS
1960 ;
1970 MSG1 .BYTE "I'M THINKING OF A NUMBER BETWEEN 1 AND100.",EOL
1980 MSG2 .BYTE "WHAT IS YOUR GUESS?",EOL
1990 MSG3 .BYTE "PLEASE ENTER A NUMBER.",EOL
2000 MSG4 .BYTE "TOO LARGE.",EOL
2010 MSG5 .BYTE "TOO SMALL.",EOL
2020 MSG6 .BYTE "YOU GOT IT! IT TOOK ",0
2030 MSG7 .BYTE " TRIES.",EOL
2040 MSG8 .BYTE "PLAY AGAIN? Y/N.",EOL
2050 NUMBER .BYTE $00
2060 TRIES .BYTE $00
2070 ;
2080 START
2090  LDA RANDOM
2100  BEQ START
2110  STA NUMBER
2120  CMP #100
2130  BCS START
2140  LDA #0
2150  STA TRIES
2160  LDA #MSG1&255
2170  LDY #MSG1/256
2180  JSR WRITE
2190 LOOP
2200  LDA #MSG2&255
2210  LDY #MSG2/256
2220  JSR WRITE
2230  JSR READLINE
2240  JSR TOINT
2250  BCC OKAY
2260  LDA #MSG3&255
2270  LDY #MSG3/256
2280  JSR WRITE
2290  JMP LOOP
2300 OKAY
2310  INC TRIES
2320  LDA FRO+1
2330  BNE GREATER
2340  LDA FRO
2350  CMP NUMBER
2360  BEQ YOUGOTIT
2370  BCS GREATER
2380 LESSER
2390  LDA #MSG5&255
2400  LDY #MSG5/256
2410  JSR WRITE
2420  JMP LOOP
2430 GREATER
2440  LDA #MSG4&255
2450  LDY #MSG4/256
2460  JSR WRITE
2470  JMP LOOP
2480 YOUGOTIT
2490  LDA #MSG6&255
2500  LDY #MSG6/256
2510  JSR WRITE0
2520  LDA TRIES
2530  STA FRO
2540  JSR INTOUT
2550  LDA #MSG7&255
2560  LDY #MSG7/256
2570  JSR WRITE
2580  LDA #MSG8&255
2590  LDY #MSG8/256
2600  JSR WRITE
2610 AGAIN
2620  JSR INCH
2630  CMP #'Y
2640  BEQ START
2650  CMP #'N
2660  BNE AGAIN
2670  BRK
