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

Express BASIC - an interpreter in C

Anything C/C++ related.
admin
Site Admin
Posts: 127
Joined: Wed Feb 22, 2023 6:51 am

Re: Express BASIC - an interpreter in C

Post by admin »

Bleeding edge update!

Before I get into the update, let me talk a bit about the conditions..

The past weeks have been rough here in the Arizona desert. We're powered by solar and generator. A few 100 watt panels, 2k watt generator, and three Jackery power stations. I put in a window AC for the first time after living off grid for almost 8 years. It barely keeps up. Not even worth running when over 100 degrees, so we just run swamp coolers during the day and the AC for a few hours at night.

Managing the homestead and showing up to work on time while trying to keep the mind sharp with coding takes a toll when you're sitting in well.. it is 109 in my trailer as I type this and my poor 2001 Dell Inspiron 1150 with Windows XP is nearly ablaze with fire.

Doesn't help that we're struggling in general. My job barely gets us by. Hand washing clothes or going to a laundry place. Hauling our own water. Pumping said water to tower and various tanks. Taking care of our plants and animals. Time is precious and goes too fast.

That's enough about that. Here's what we have to present with the update! Be warned. This is a bleeding edge update, although they really all have been.

The update includes:

1. SPACE$() function as an alias for TAB() to help with portability of BASIC code
2. Bitwise operators BAND, BOR, and BNOT(). XOR was already bitwise
3. HEX$() and OCT$() functions
4. Error #13 Unable to open file stream
5. Major issue with the string array not having headers fixed
6. Relational operators < > <= >= now work with strings along with = and <>
7. Whitespacing with tabs using space and colon after line number

We were planning on adding INKEY, but ran into trouble with Linux and haven't found a solution yet. Rather than waiting, we're pushing out the update without INKEY. It is working fine for DOS, DPMI, and Windows. The implementation is based on TSR BASIC (not TRS).

INKEY will look like this when we implement it on a future update.

10 PRINT "Enter key, or q to stop";
20 key = INKEY(1)
30 scancode = key SHR 8
40 charcode = key BAND &HFF
50 PRINT
60 PRINT "scan code = "; scancode
70 PRINT "char code = "; charcode;
80 PRINT " ("; CHR$(charcode); ")"
90 IF UCASE$(CHR$(charcode)) <> "Q" THEN 20

Again, this update will not include the INKEY function.

New examples:

Code: Select all

1 REM BUBBLE SORT 
2 REM BEGINNER'S BASIC BY PETER LEAR
3 REM MODIFIED TO RUN ON EXPRESS BASIC
5 CLS
10 INPUT "NUMBER OF WORDS TO SORT"; N
20 PRINT "ENTER WORDS:"
30 FOR I = 1 TO N
40 INPUT $(I)
50 NEXT I
60 PRINT "NOW SORTING...PLEASE WAIT"
70 PRINT
80 FOR I = 1 TO N - 1
90 FOR J = I + 1 TO N
100 IF $(I) < $(J) THEN 150
110 DU$ = $(J)
120 $(J) = $(I)
130 $(I) = DU$
150 NEXT J
160 NEXT I
170 FOR I = 1 TO N
180 PRINT $(I)
190 NEXT I

Code: Select all

1 REM https://rosettacode.org/wiki/Floyd's_triangle
100 INPUT "Number of rows (1-20): "; rows
110 FOR col = 1 TO rows
120 :	@(col) = LEN(STR$(col + rows * (rows - 1) / 2))
130 NEXT col
140 thisnum = 1
150 FOR r = 1 TO rows
160 :	FOR col = 1 TO r
170 :		PRINT RIGHT$("  " + STR$(thisnum), @(col)); " ";
180 :		thisnum = thisnum + 1
190 :	NEXT col
200 :	PRINT
210 NEXT r

Code: Select all

1 REM https://rosettacode.org/wiki/Bioinformatics/base_count
100 INPUT "DNA file (*.txt): ", file$: OPEN "I", #1, file$
110 PRINT : PRINT "SEQUENCE: "
120 IF EOF(1) THEN PRINT "no data in file": END
130 INPUT #1, b$: GOSUB 1000: IF EOF(1) = 0 THEN 130
140 PRINT: PRINT
150 PRINT "Count: A = "; acnt; " C = "; ccnt; " G = "; gcnt; " T = "; tcnt
160 END
1000 IF b$ = "" THEN RETURN
1010 FOR i = 1 TO LEN(b$)
1020 :	IF n MOD 30 = 0 THEN PRINT: PRINT RIGHT$("     " + STR$(n + 1), 5) + ": ";
1030 :	IF n MOD 5 = 0 THEN PRINT " ";
1040 :	m$ = MID$(b$, i, 1)
1050 :	PRINT m$;
1060 :  IF m$ = "A" THEN acnt = acnt + 1: GOTO 1110
1070 :  IF m$ = "C" THEN ccnt = ccnt + 1: GOTO 1110
1080 :  IF m$ = "G" THEN gcnt = gcnt + 1: GOTO 1110
1090 :  IF m$ = "T" THEN tcnt = tcnt + 1: GOTO 1110
1100 :  PRINT "error at "; n, m$
1110 :  n = n + 1
1120 NEXT i
1130 RETURN
admin
Site Admin
Posts: 127
Joined: Wed Feb 22, 2023 6:51 am

Re: Express BASIC - an interpreter in C

Post by admin »

Found a few more bugs and glitches. Will be working on fixing them these next few days.

One problem was the LOCATE is displaying 1 off in Windows. Another was a few missing symbol values for the new functions SHR and SHL in the expression evaluator. We really just need more time for testing. There could always be more mistakes.

I have added RND() as an alias for RND. It will accept 0 to return the same as RND (decimal > 0 and < 1). With 1, it returns 1. With any number greater than 1, it returns between 1 and that number as an int. This alias for RND will help with portability to other BASIC dialects.

Also, I made a new game called Math Quiz. It demonstrates the RND syntax described above and will be included with the next update.

Code: Select all

1 REM Math Quiz by Gemino Smothers 2024
2 REM Run with Express BASIC
10 COLOR 0, 7: CLS: PRINT "Math Quiz by Gemino Smothers 2024": PRINT
20 PRINT "Solve 100 addition, subtraction, multiplication, and division problems."
30 PRINT "For division operations, calculate the largest whole quotient.": PRINT
35 INPUT "Start game (y/n)"; cont$: CLS
40 IF UCASE$(cont$) = "N" THEN GOTO 200
50 operators$ = "+-*/"
60 difficulty = difficulty + 2
70 operand1 = RND(difficulty): operand2 = RND(difficulty)
80 operation = RND(4)
90 IF operation = 1 THEN answer = operand1 + operand2
100 IF operation = 2 THEN answer = operand1 - operand2
110 IF operation = 3 THEN answer = operand1 * operand2
120 IF operation = 4 THEN answer = INT(operand1 / operand2)
130 PRINT
140 PRINT "Problem "; answered + 1; ":", operand1, MID$(operators$, operation, 1), operand2, "=",
150 INPUT attempt: PRINT: COLOR 4
160 IF attempt < answer THEN PRINT "Too low.": PRINT: COLOR 0: incorrect = incorrect + 1: GOTO 140
170 IF attempt > answer THEN PRINT "Too high.": PRINT: COLOR 0: incorrect = incorrect + 1: GOTO 140
180 answered = answered + 1: COLOR 1: PRINT "Correct!": PRINT
190 IF answered < 100 AND incorrect < 100 THEN COLOR 0: INPUT "Continue (y/n)", cont$: CLS: GOTO 40
200 PRINT "Questions answered: "; answered; " / 100"
210 PRINT "Incorrect attempts: "; incorrect
220 PRINT
230 IF incorrect >= 25 THEN COLOR 4: PRINT "That's a lot of wrong answers. You need to practice more!"
240 IF answered = 100 THEN COLOR 1: PRINT "You answered all of the math problems. Good work!"
250 IF answered < 100 THEN PRINT "You're going to leave all these problems unsolved? Try again later!"
260 PRINT: INPUT "Press ENTER/RETURN to exit program...", cont$
admin
Site Admin
Posts: 127
Joined: Wed Feb 22, 2023 6:51 am

Update!

Post by admin »

Update time!

This one is later than expected. A server migration set us back.

Fixes and new features:

- Added RND() to supplement RND

- LOCATE command was one position off in x and y in Windows edition

- EB was crashing when there were two commas at the end of a print statement
Ex. PRINT "hi", ,

- Missing SHL and SHR in one of the editions

- Added TIME$ and DATE$ functions

- COLOR command was malfunctioning in Linux edition

New examples:

MathQuiz.bas
Rock-paper-scissors.bas
BubbleSort.bas
PRINCIPAL_ON_A_LOAN.BAS
REGULAR_PAYMENT_ON_A_LOAN.BAS
LAST_PAYMENT_ON_A_LOAN.BAS
TERM_OF_A_LOAN.BAS
REGULAR_WITHDRAWALS.BAS
REMAINING_BALANCE_ON_A_LOAN.BAS
SALVAGE_VALUE.BAS
DEPRECIATION_AMOUNT.BAS
DEPRECIATION_RATE.BAS
NOMINAL_INTEREST_RATE_ON_INVESTMENTS.BAS
MINIMUM_INVESTMENTS_FOR_WITHDRAWALS.BAS
FUTURE_VALUE_OF_AN_INVESTMENT.BAS
REGULAR_DEPOSITS.BAS
ANNUITY.BAS
INITIAL_INVESTMENT.BAS
EFFECTIVE_INTEREST_RATE.BAS
RECIPE_COST.BAS
FOKUL.BAS
CHICKEN.BAS
DETECTIVE'S_DILEMMA.BAS
admin
Site Admin
Posts: 127
Joined: Wed Feb 22, 2023 6:51 am

Quick update

Post by admin »

Quick update...

We've been busy with side projects this month. Needed a break from this. I have beeen using EB as a a macro tool on the side and noticed a bug earlier this week. The fix was quick and easy, but uploading the update was challenging as there was an update to CPanel. The CPanel update broke my browser compatibility, but there was a backup/second links that works for me. I'm using Seamonkey on Windows XP, so options are limited these days. Also tried Supermium. Good so far..

Update overview:

1. Fixed issue with the $() string array. It was missing part of the header causing evaluation issues. I discovered this while trying ti compare the contents to a blank string
2. Added an example program with sime code being used in a game we're developing. The example demonstrates an RPG level system for games.

The new example:

Code: Select all

10 REM Experience until next level algorithm for RPGs
20 FOR l = 1 TO 99
30 :	tnl = INT(2 + ((l - 1) / 7))
40 :	tnl = INT(.25 * (l - 1 + 300 * tnl))
50 :	tnl = tnl * l * 2
60 :	IF l <= 15 THEN tnl = INT(tnl / 3.2)
70 :	IF l >= 85 THEN tnl = INT(tnl * 5.4)
80 :	PRINT l; ":"; tnl,
90 NEXT l

This is a small, but important update. It fixes a big issue/mistake with string manipulation and strings are important.
We're going to be working on this project full time again soon.. just need to finish uo these wild side projects...
Post Reply