Information Technology - Computer Programming - Source Code - Homebrew - Open Source - Software - Hardware - 8 bit - 16 bit - 32 bit - 64 bit - x86 - x64 - DOS - Windows - Linux - Arduino - Embedded - Development - Retro - Vintage - Math - Science - History - Hobby - Beginners - Professionals - Experiment - Research - Study - Fun - Games

VTech Precomputer 1000 Examples

Anything about classic BASIC dialects such as Dartmouth BASIC, Microsoft BASIC, Tiny BASIC dialects, Atari BASIC, Commodore BASIC, V Tech Pre BASIC, G BASIC or F BASIC (for famiclone keyboards), and other classic home computer BASIC dialects.
Post Reply
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

VTech Precomputer 1000 Examples

Post by Beronica »

I will be posting examples for the VTech PreComputer 1000 here.

My first example is a program to convert a binary number to its decimal counterpart.

Code: Select all

10 PRINT "BINARY TO DECIMAL"
20 INPUT "BINARY #:  "; B
30 IF B <= 0 THEN 80
40 LET R = B - (10 * INT(B  / 10))
50 LET D = D + R * 2 ^ I
60 LET B = INT(B / 10)
70 LET I = I + 1
80 IF B > 0 THEN 30
90 PRINT D
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

Re: VTech Precomputer 1000 Examples

Post by Beronica »

Palindrome Checker

A palindrome is a word, phrase, or number that reads the same forwards and backwards. Punctuation, spaces, and case are ignored. For example "kayak", "Mr.Owl ate my metal worm.", and "101".

Line 5 uses the CLEAR statement. CLEAR is used to assign more memory to string variables. The default is 50 bytes. Using CLEAR takes away from your program memory.

Lines 40 - 90 takes the user's input, E$, and adds only the letters and numbers to the string F$.

Lines 100 - 120 reverses F$ and stores it in B$.

VTech Pre-Basic was not accepting commas in the input.

Code: Select all

1 REM --- PALINDROME CHECKER
5 CLEAR 100
10 PRINT "PALINDROME CHECKER"
20 PRINT "ENTER A WORD, PHRASE, OR NUMBER"
30 INPUT E$
40 FOR I = 1 TO LEN(E$)
50 C$ = MID$(E$, I, 1): C = ASC(C$)
60 IF C >= 97 OR C <= 122 THEN C = C - 32: C$ = CHR$(C)
70 IF C >= 65 AND C <= 90 THEN 90
80 IF C < 48 OR C > 57 THEN 100
90 F$ = F$ + C$
100 NEXT I
110 FOR I = LEN(F$) TO 1 STEP - 1
120 B$ = B$ + MID$(F$, I, 1)
130 NEXT I
140 IF F$ = B$ THEN PRINT "IT IS A PALINDROME!"
150 IF F$ <> B$ THEN PRINT "NOT A PALINDROME :("
Last edited by Beronica on Thu Mar 21, 2024 1:25 am, edited 1 time in total.
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

Re: VTech Precomputer 1000 Examples

Post by Beronica »

Decimal To Hex

Hexadecimal, or hex for short, is a number system with a base of 16. The values are represented by 0 - 9 and A - F.

Hex: 0 1 2 3 4 5 7 6 8 9 A B C D E F
Value: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

The program below converts a decimal number to a hexadecimal number.

Line 30 gets the remainder of the decimal number divided by 16 (the base of the hexadecimal number system) and stores it in R. VTech Pre-Basic does not have the MOD operator, so instead we use the formula:

remainder = quotient - (divisor * INT(quotient / divisor))

Lines 40 to 50 check to see whether the remainder is between 0 - 9 or 10 - 15 and appends the appropriate hex symbol to the R$ string. If it is between 0 - 9, it adds 48 to the remainder to get the ASCII value. 0 = 48, 1 = 49, etc. And if it is between 10 - 15, it adds 55 to the remainder. For example, a remainder of 10 plus 55 equals 65, the ASCII value for 'A'.

Line 60 gets the integer quotient of the decimal number divided by 16.

Line 70 checks to see if the quotient is equal to 0. If not, it repeats the process.

Lines 80 to 100 reverses the R$ string and stores your hexadecimal value in H$.

https://www.rapidtables.com/convert/num ... o-hex.html
This site has a good visual explanation of the process.

Code: Select all

1 REM --- DECIMAL TO HEX CONVERTER
10 PRINT "DECIMAL TO HEX"
20 INPUT "ENTER DECIMAL #"; D
30 R = D - (16 * INT(D / 16))
40 IF R >= 0 AND R < 10 THEN R$ = R$ + CHR$(R + 48)
50 IF R >= 10 AND R <= 15 THEN R$ = R$ + CHR$(R + 55)
60 D = INT(D / 16)
70 IF D > 0 THEN 30
80 FOR I = LEN(R$) TO 1 STEP - 1
90 H$ = H$ + MID$(R$, I, 1)
100 NEXT I
110 PRINT H$
Last edited by Beronica on Thu Mar 21, 2024 1:23 am, edited 1 time in total.
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

Re: VTech Precomputer 1000 Examples

Post by Beronica »

Hex To Decimal

This program converts a hexadecimal number to a decimal number.

You can get a hexadecimal number from a decimal number by multiplying each digit to the power of 16 from its corresponding place and adding them together.

Line 20 asks for user to input their hexadecimal number and stores it in string H$.

Line 30 takes the length of string H$, subtracts one from it and stores it in L.

Lines 40 to 90 reads one character at a time from the H$ string. It then gets the ASCII value of the character and stores it in C. It then checks to see if C is a number between 48-57 (0-9) or 65-70(A-F). If it is a number, it subtracts 48 from the ASCII value to get its hexadecimal value. If it is a letter, it subtracts 55. It then multiplies the resulting value with 16 to the power of L (the digit's place) and adds it to D, the sum. L is subtracted by one to get the next digit's place.

For example:

Hexadecimal #: 1B8

L equals the length of H$ - 1. The length of "1B8" is 3, so L = 2.

The first character of string H$ is "1". The ASCII value of "1" is 49. Since it is a number between 48 and 57,and therefore a number, it is subtracted by 48 which gives the value 1. 1 * 16 ^ L(2) equals 256. So, D = D(0) + 256.

D = D + ((C - 48) * 16 ^ L)
D = 0 + ((49 - 48) * 16 ^ 2)
D = 0 + ((1) * 16 ^ 2)
D = 256

L = L(2) - 1 which is 1.

The second character of string H$ is "B". The ASCII value of "B" is 66. Since it is a number between 65 and 70,and therefore a letter, it is subtracted by 55 which gives the value 11. 11 * 16 ^ L(1) equals 176. D = D(256) + 176 which equals 432.

D = D + ((C - 55) * 16 ^ L)
D = 256 + ((66 - 55) * 16 ^ 1)
D = 256 + ((11) * 16 ^ 1)
D = 432

L = L(1) - 1 which is 0.

The third character of string H$ is "8". The ASCII value of "8" is 56. Since it is a number, it is subtracted by 48 which gives the value 8. 8 * 16 ^ L(0) equals 8. So D = D(432) + 8 which equals 440.

D = D + ((C - 48) * 16 ^ L)
D = 432 + ((56 - 48) * 16 ^ 0)
D = 432 + ((8) * 16 ^ 0)
D = 440

The decimal value of the hexadecimal 1B8 is 440.

Great source for conversions with explanations.
https://www.rapidtables.com/convert/num ... cimal.html

Code: Select all

1 REM --- HEX TO DECIMAL CONVERTER
10 PRINT "HEX TO DECIMAL"
20 INPUT "ENTER HEX #"; H$
30 L = LEN(H$) - 1
40 FOR I = 1 TO LEN(H$)
50 C = ASC(MID$(H$, I, 1))
60 IF C >= 48 AND C <= 57 THEN D = D + ((C - 48) * 16 ^ L)
70 IF C >= 65 AND C <= 70 THEN D = D + ((C - 55) * 16 ^ L)
80 L = L - 1
90 NEXT I
100 PRINT D
Last edited by Beronica on Thu Mar 21, 2024 1:16 am, edited 1 time in total.
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

Re: VTech Precomputer 1000 Examples

Post by Beronica »

Pangram Checker

A pangram is a sentence that contains all the letters of the alphabet at least once. For example, "The quick brown fox jumps over a lazy dog."

This program checks to see if the user's input is a pangram.

Line 40 sets an array of 26 elements, one for each letter of the alphabet.

Lines 50 - 90 uses a for loop to check the string one character at a time.

Line 60 gets the ASCII value of the character and stores it in C.

Line 70 checks if C is between 97 - 122 (lowercase letters). If it is, it subtracts 97 from C. This gets the corresponding array element and stores a 1 in it to signify that the letter appears in the sentence.

Line 80 does the same as line 70, but checks for 65 - 90 (uppercase letters). If it is, it subtracts 65 from C.

For example, if the character is "d", then the ASCII value is 100. 97 subtracted from 100 is 3. Or, if the character is "D", then the ASCII value is 68. 65 subtracted from 68 is 3. So, in array element 3, we store a 1 which means the letter d is in the sentence.

Lines 100 to 120 uses a for loop to go through the array and check if any element of the array has a value of 0. If it does, it means a letter was not present in the sentence and therefore the sentence is not a pangram. It then skips to line 140 where it tells the user the result.

If none of the elements in the array have a value of 0, then all the letters were present in the sentence, and the sentence is a pangram. It tells the user the result and ends.

If the sentence was not a pangram, Line 150 asks the user if they would like a list of the missing letters. If they answer "N", then the program ends. Otherwise, lines 180 to 200 goes through the for loop again and if the array element has a value of 0, it prints the letter with CHR$ by adding 65 to the index to get the ASCII values A-Z.

Code: Select all

1 REM --- PANGRAM CHECKER
5 CLEAR 100
10 PRINT "PANGRAM CHECKER"
20 PRINT "ENTER A SENTENCE"
30 INPUT S$
40 DIM A(26)
50 FOR I = 1 TO LEN(S$)
60 C = ASC((MID$(S$, I, 1))
70 IF C >= 97 AND C <= 122 THEN A(C - 97) = 1 
80 IF C >= 65 AND C <= 90 THEN A(C - 65) = 1 
90 NEXT I
100 FOR I = 0 TO 25
110 IF A(I) = 0 THEN 140
120 NEXT I
130 PRINT "IT IS A PANGRAM!": END
140 PRINT "NOT A PANGRAM :("
150 PRINT "LIST MISSING LETTERS?"
160 INPUT "Y OR N"; Q$
170 IF Q$ = "N" THEN END
180 FOR I = 0 TO 25
190 IF A(I) = 0 THEN PRINT CHR$(I + 65); ",";
200 NEXT I
210 PRINT: PRINT "DONE"
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

Re: VTech Precomputer 1000 Examples

Post by Beronica »

BMI Calculator

This program calculates a person's body mass index using their weight and height in either the metric or imperial system.

Line 20 asks the user which unit system they would like to use.

Line 30 makes sure the user only enters a 1 or a 2.

Line 40 jumps to line 80 if the user chose the imperial system, otherwise, it continues to line 50.

Lines 50-70 and lines 80-100 asks for the user's weight and height in their corresponding units of measurement. It then calculates the BMI index with the appropriate formula.

Line 110 gives the user their BMI and lines 120-150 checks to see in which BMI category the number falls in.

For more information on the body mass index formula:
https://www.registerednursern.com/bmi-c ... -explained

Code: Select all

10 PRINT "BMI CALCULATOR"
20 INPUT "1-METRIC 2-US"; U
30 IF U < 1 OR U > 2 THEN 20
40 IF U = 2 THEN 80
50 INPUT "WEIGHT (KG)"; W
60 INPUT "HEIGHT (M)"; H
70 BMI = W / H ^ 2: GOTO 110
80 INPUT "WEIGHT (LB)"; W
90 INPUT "HEIGHT (IN)"; H
100 BMI = 703 * W / H ^ 2
110 PRINT "YOUR BMI IS:"; BMI
120 IF BMI < 18.5 THEN PRINT "YOU'RE UNDERWEIGHT"
130 IF BMI >= 18.5 AND BMI < 25 THEN PRINT "YOU'RE HEALTHY"
140 IF BMI >= 25 AND BMI < 30 THEN PRINT "YOU'RE OVERWEIGHT"
150 IF BMI >= 30 THEN PRINT "YOU'RE OBESE"
User avatar
Beronica
Posts: 13
Joined: Wed Feb 22, 2023 8:19 am

Re: VTech Precomputer 1000 Examples

Post by Beronica »

:!: Secret Message :!:

This program uses the Caesar cipher to encode or decode a message. To encode a message you shift the letters in the alphabet by a certain number of positions, or key, and substitute the original letter with the new one. To decode, you subtract the original key from 26 to get a new key.

For example, in a key of 3, you would shift the original alphabet by 3 positions. So,

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

becomes

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

You then substitute the letters of your message with the new letters in the same position. So, A is substituted by D, B by E, and so on. "Hello World" becomes "Khoor Zruog."

To decode, you subtract the original key from 26 to get your new key. In this case 26 - 3 = 23.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

becomes

X Y Z A B C D E F G H I J K L M N O P Q R S T U V W

With this new key, "Khoor Zruog" becomes "Hello World" again.

Lines 20 - 60 asks the user to input if they are encoding or decoding a message, in what key, and the message. If the user is decoding, line 60 subtracts the key from 26 to get the new key.

Lines 70 - 140 uses a for loop to go through the message a letter at a time. It stores the ASCII value of the letter in A. The ASCII value is then checked to see if it is upper or lower case.

Lines 100 and 120 uses modular arithmetic to shift the value according to the key. First, it subtracts the ASCII value from 65 if it is uppercase or 97 if it is lowercase to get the position in the alphabet. For example, 65(A) would be position 0 in the alphabet. The key is then added to the original position.

(N - (26 * INT(N / 26))) is used to calculate N MOD 26. This gives the new position in the alphabet. 65 or 97 is added to the new position to get the corresponding ASCII value and this is now stored in A.

For example, if you were encoding the letter "B" with a key of 3, you would get:

N = A - 65 + K
N = 66 - 65 + 3 = 4

A = N MOD 26 + 65
A = 4 MOD 26 + 65
A = 4 + 65
A = 69
69 is the ASCII value of "E"

or if you were encoding the letter "j" with a key of 20:

N = A - 97 + K
N = 106 - 97 + 20 = 29

A = N MOD 26 + 97
A = 29 MOD 26 + 97
A = 3 + 97
A = 100
100 is the ASCII value of "d"

Line 130 adds the new character to N$, as well as any punctuation.

Lines 150 to 180 print the new message 18 characters at a time. Without this, the message was being printed on the VTech too fast to be read if the message was longer than 18 characters.

Code: Select all

5 CLEAR 200
10 PRINT "SECRET MESSAGE"
20 INPUT "1-ENCODE 2-DECODE"; C
30 INPUT "KEY(1-25)"; K
40 PRINT "ENTER MESSAGE"
50 INPUT M$
60 IF C = 2 THEN K = 26 - K
70 FOR I = 1 TO LEN(M$)
80 A = ASC(MID$(M$, I, 1))
90 IF A < 65 OR A > 90 THEN 110
100 N = A - 65 + K: A = (N - (26 * INT(N / 26))) + 65
110 IF A < 97 OR A > 122 THEN 130 
120 N = A - 97 + K: A = (N - (26 * INT(N / 26))) + 97
130 N$ = N$ + CHR$(A)
140 NEXT I
150 IF LEN(N$) < 19 THEN PRINT N$: END
160 FOR I = 1 TO LEN(N$) STEP 18
170 PRINT MID$(N$, I, 18)
180 NEXT I
Post Reply