• ### Some 3D

I try to do some 3D wireframe graphics with Terminal-BASIC matrix operations:

The source is in the Terminal-BASIC team repository:

```10 REM 3D rotations using matrix operations
20 REM FILL TABLES OF SIN AND COS
30 DIM SC(1,255)
40 LET D = 2.*PI()/256.
50 LET A = 0
60 FOR I%=0 TO 255
65   A = A + D
70   SC(0,I%) = SIN(A)
80   SC(1,I%) = COS(A)
90 NEXT I%
100 REM Octahedron
110 DIM V1(2,0), V1W(2,0)
120 V1(0,0) = 0 : V1(1,0) = 0 : V1(2,0) = 40
125 MAT V1W = V1
130 DIM V2(2,0), V2W(2,0)
140 V2(0,0) = -25 : V2(1,0) = 25 : V2(2,0) = 0
145 MAT V2W = V2
150 DIM V3(2,0), V3W(2,0)
160 V3(0,0) = -25 : V3(1,0) = -25 : V3(2,0) = 0
165 MAT V3W = V3
170 DIM V4(2,0), V4W(2,0)
180 V4(0,0) = 25 : V4(1,0) = -25 : V4(2,0) = 0
185 MAT V4W = V4
190 DIM V5(2,0), V5W(2,0)
200 V5(0,0) = 25 : V5(1,0) = 25 : V5(2,0) = 0
205 MAT V5W = V5
210 DIM V6(2,0), V6W(2,0)
220 V6(0,0) = 0 : V6(1,0) = 0 : V6(2,0) = -40
230 MAT V6W = V6
300 REM screen coordinates
320 DIM VS1(1), VS2(1), VS3(1), VS4(1), VS5(2), VS6(2)
330 LET A% = 0 : LET B%=0 : LET C%=0
340 DIM RMX(2,2) : MAT RMX = IDN
350 DIM RMY(2,2) : MAT RMY = IDN
360 DIM RMZ(2,2) : MAT RMZ = IDN
370 DIM RM(2,2)
380 GOSUB 1100 : GOSUB 1200 : GOSUB 1300
1000 REM main loop
1010 K\$ = INKEY\$()
1020 IF K\$ = "d" THEN A% = A% + 1 : GOSUB 1100
1030 IF K\$ = "a" THEN A% = A% - 1 : GOSUB 1100
1040 IF K\$ = "w" THEN B% = B% + 1 : GOSUB 1200
1050 IF K\$ = "s" THEN B% = B% - 1 : GOSUB 1200
1060 IF K\$ = "e" THEN C% = C% + 1 : GOSUB 1300
1070 IF K\$ = "q" THEN C% = C% - 1 : GOSUB 1300
1080 GOTO 1000
1100 REM Update rot matrix z
1110 IF A%<0 THEN A%=255
1120 IF A%>255 THEN A%=0
1130 RMZ(0,0) = SC(1,A%) : RMZ(0,1) = -SC(0,A%)
1140 RMZ(1,0) = SC(0,A%) : RMZ(1,1) = SC(1,A%)
1150 GOSUB 1400
1160 GOSUB 9000 : GOSUB 10000
1170 RETURN
1200 REM Update rot matrix x
1210 IF B%<0 THEN B%=255
1220 IF B%>255 THEN B%=0
1230 RMX(1,1) = SC(1,B%) : RMX(1,2) = -SC(0,B%)
1240 RMX(2,1) = SC(0,B%) : RMX(2,2) = SC(1,B%)
1250 GOSUB 1400
1260 GOSUB 9000 : GOSUB 10000
1270 RETURN
1300 REM Update rot matrix y
1310 IF C%<0 THEN C%=255
1320 IF C%>255 THEN C%=0
1330 RMY(0,0) = SC(1,C%) : RMY(0,2) = SC(0,C%)
1340 RMY(2,0) = -SC(0,C%) : RMY(2,2) = SC(1,C%)
1350 GOSUB 1400
1360 GOSUB 9000 : GOSUB 10000
1370 RETURN
1400 REM Rotate points
1410 MAT RM = RMX * RMY
1420 MAT RM = RM * RMZ
1440 MAT V1W = RM*V1 : MAT V2W = RM*V2
1450 MAT V3W = RM*V3 : MAT V4W = RM*V4
1460 MAT V5W = RM*V5 : MAT V6W = RM*V6
1470 RETURN
1990 END
9000 REM procedure to project
9010 VS1(0) = V1W(0,0)+100 : VS1(1) = -V1W(2,0)+90
9020 VS2(0) = V2W(0,0)+100 : VS2(1) = -V2W(2,0)+90
9030 VS3(0) = V3W(0,0)+100 : VS3(1) = -V3W(2,0)+90
9040 VS4(0) = V4W(0,0)+100 : VS4(1) = -V4W(2,0)+90
9050 VS5(0) = V5W(0,0)+100 : VS5(1) = -V5W(2,0)+90
9060 VS6(0) = V6W(0,0)+100 : VS6(1) = -V6W(2,0)+90
10000 REM procedure to draw figure
10005 CLS
10010 LINE VS1(0),VS1(1),VS2(0),VS2(1)
10020 LINE VS1(0),VS1(1),VS3(0),VS3(1)
10030 LINE VS1(0),VS1(1),VS4(0),VS4(1)
10040 LINE VS1(0),VS1(1),VS5(0),VS5(1)
10050 LINE VS2(0),VS2(1),VS3(0),VS3(1)
10060 LINE VS3(0),VS3(1),VS4(0),VS4(1)
10070 LINE VS4(0),VS4(1),VS5(0),VS5(1)
10080 LINE VS5(0),VS5(1),VS2(0),VS2(1)
10090 LINE VS6(0),VS6(1),VS2(0),VS2(1)
10100 LINE VS6(0),VS6(1),VS3(0),VS3(1)
10110 LINE VS6(0),VS6(1),VS4(0),VS4(1)
10120 LINE VS6(0),VS6(1),VS5(0),VS5(1)
10190 RETURN
```
• ### Software update

New software, I'v just built, based on Terminal-BASIC 2.1-b1. It uses russian lexems, because the computer is used by my 5 years old daughter, who don't understand English and still can't read latin alphabet. Also I use my new ps/2 keyboard Arduino library, from https://bitbucket.org/starling13/libps2 . This library supports locales switching and controls the keyboard LEDs, as can be seen on the photo.

• ### Load BMP file from SD-card

03/31/2019 at 20:52 1 comment

Terminal-BASIC 2.0-rc introduced UNIX-style file operations. This video shows the process of loading 1-bpp BMP file from SD-card. Yes, it's damn slow. Image was loaded by the following BASIC program:

```   1 DEF FN BN% (BYT%, BIT%) = (BYT% \ (2 ^ BIT%)) AND 1
10 INPUT F\$
20 GOSUB  1000
100 END
1010 BMP% = FOPEN ( F\$ )
1020 IF BMP% = -  1 THEN PRINT "FOPEN" : GOTO  1995
1030 B% = FREAD ( BMP% ) : M% = FREAD ( BMP% )
1040 S\$ = CHR\$ ( B% ) + CHR\$ ( M% )
1050 IF S\$ <> "BM" THEN PRINT "HEADER" : GOTO  1990
1060 FOR I% =  1 TO  8 : B% = FREAD ( BMP% ) : NEXT I%
1070 DP% = FREAD ( BMP% )
1080 DP% = DP% + FREAD ( BMP% ) *  256
1085 DP%=DP%-12
1090 IF DP% < 0 GOTO 1110
1100 FOR I%=0 TO DP%-1 : B%=FREAD(BMP%) : NEXT I%
1110 FOR Y%=191 TO 0 STEP -1
1120   FOR X%=0 TO 24
1140     FOR XX%=0 TO 7
1150       POINTC X%*8+XX%, Y%, FN BN%(B%,7-XX%)
1600     NEXT XX%
1700   NEXT X%
1800 NEXT Y%
1990 FCLOSE BMP%
1991 S\$=GET\$()
1992 IF S\$="" GOTO 1991
1995 RETURN```
• ### Alternative firmware

This computers firmware is a variant of my Terminal-BASIC. It suffers from heavy weight, due to my limited abilities and C++ it's written in, but it is important for me as the window in the world of language translators and learning desk.

But I start to think about the alternative firmware, which is a compromise between the simplicity and flexibility. It will be based on Z80 CPU emulator.

On the host side there will be a piece of C++ code. First component is an  interactive monitor, allowing to view/modify the Z80 emulator ram, load and store ram portions to or from SD card, may be some assemble/disassemble in the future. The second component is a Z80 emulator calls library, allowing to call the native C++ functions from the z80 code.

The main purpose of this firmware is the ability to write programs in C, using sdcc for z80, store multiple programs to SD card and run it without reprogramming the Arduino flash.

Unlike great projects, running CP/M emulator on Arduino DUE, this approach gives the ability to use the boards with a cople kilobytes of RAM to run simple programs, as long as CP/M will not run with less then 64k RAM, and more need to an emulator itself.

Compared to the Terminal-BASIC, which allows to run programs from SD card too, I expect, compiled C code, running in Z80 emulator to be much faster.