Teletext paint program

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 9:07 pm

Hi
I've been having great fun today trying to write my own teletext paint program in BBC Basic for windows. I wanted something I could paint with the mouse and draw pixel art on and plot colours.

The aim of it is to get an app done in Android that will let me paint in teletext since there are none out there ( from what I can see).

Fills and circles are a bit adventurous at the moment. I am suprised I got this far!
So far I managed to work out how to get a palette up, how to select colours, how to plot. I found a routine that would plot a point in mode 7 so I have been working on from there. It is all new to me.

I've managed to work out how to not nuke the menu and clear a screen with a paper colour which is cool. I am so pleased so far!

Some things that are not yet implemented....I have no idea how to go about these yet:

1) How to save the Mode 7 Screen in BBC Basic for Windows
2) Using Filenames and loading and saving pictures. Not sure how I will approach this yet.
3) How to implement an undo
4) How to remove a pixel. This is challenging. The only way I can think of is put a whole character space in over the mouse. Not ideal but the best I can do for now. The plot routine plots a point but it seems there is nothing there to remove one!

I've designed it so if you hit these letters on the menu bar with the mouse it does this:

P - Single pixel drawing
DP - dithered pixels (that took a bit of headscratching to say the least Fourthstone!)
C - Clear Screen ( left click clears black right click clears to paper of current colour)

As I say this is difficult for someone like me. The code is cobbled together. I need to get in the habit of documenting it but i am just mucking around.
Last edited by pixelblip on Sat Jul 25, 2020 9:27 pm, edited 4 times in total.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 9:15 pm

Screenshot - PS the dithered pixels thing is working but not in the version below so will post again soon
Attachments
PIXELBLIP.PNG
Last edited by pixelblip on Sat Jul 25, 2020 9:27 pm, edited 1 time in total.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 9:15 pm

I do love the way BBC Basic is able to list all the variables as you go. It makes it so much easier.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 9:16 pm

Rectangles and Circles would be good as well. The trouble is it starts getting complex then...as you really need to be able to see the things before you plot them.
I think for now I will stick to pixels and maybe try a line routine if I can muster that up.

I would love an Undo in this more than anything.
Last edited by pixelblip on Sat Jul 25, 2020 9:28 pm, edited 3 times in total.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 9:17 pm

Another consideration I will have to think about is what to do about right mouse click. When you move to Android there is no right mouse click....so I need to have a think what to do there.

It would also be so cool to be able to have frames of animation. That is going to be tricky. I need to find a way of storing mode 7 screens easily and being able to recall them. I want to use BASIC for everything if that is possible.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 9:25 pm

10 MODE 7
20
30 DIM S% 7
40 VDU 28,1,24,39,1
50
60 !S%=&08040201
70
80 S%!4=&4010
90
100 REM 70 Next a row of teletext control codes must be written down the left hand side of the screen to turn every line into a graphics display
110 backcol%=0
120 PROCGR
130
140
150 REM and the associated procedure is
160
170
180
190
200 REM The main program follows - in this case to plot a "sin curve":
210 X=10:Y=73
220
230 step%=2
240 tool$="p"
250 MOUSE ON 0
260 dontpaint%=0
270 toolsel%=0
271
280 REPEAT
290
300
310
320
330 MOUSE X,Y,Z
340 X%=(X/17.29)
350
360 Y%=Y/13.83
370 CX%= X/32
380 CY%= 24-Y/40.96
390 IF CX%>3 AND CX%<6 AND CY%<2 AND INKEY-10 tool$="colred":dontpaint%=1:toolsel%=1 : backcol%=1
400 IF CX%>7 AND CX%<10 AND CY%<2 AND INKEY-10 tool$="colgreen":dontpaint%=1 :toolsel%=1: backcol%=2
410 IF CX%>11 AND CX%<14 AND CY%<2 AND INKEY-10 tool$="colyel":dontpaint%=1:toolsel%=1 : backcol%=3
420 IF CX%>15 AND CX%<18 AND CY%<2 AND INKEY-10 tool$="colblue":dontpaint%=1 :toolsel%=1 : backcol%=4
430 IF CX%>19 AND CX%<22 AND CY%<2 AND INKEY-10 tool$="colmag":dontpaint%=1 :toolsel%=1 : backcol%=5
440 IF CX%>23 AND CX%<26 AND CY%<2 AND INKEY-10 tool$="colcya":dontpaint%=1 :toolsel%=1 : backcol%=6
450 IF CX%>27 AND CX%<30 AND CY%<2 AND INKEY-10 tool$="colwhite":dontpaint%=1 :toolsel%=1 : backcol%=7
460
470 IF CX%=31 AND CY%<2 AND INKEY-10 tool$="p":dontpaint%=0
480 IF CX%=32 AND CY%<2 AND INKEY-10 tool$="dp":dontpaint%=0
481 IF CX%=33 AND CY%<2 AND INKEY-10 tool$="c":dontpaint%=0:PROCGR:backcol%=0: tool$="p":dontpaint%=0
490 IF CY%>1 AND toolsel%=1 toolsel%=0:dontpaint%=0
500
510
520
530
540
550
560 REM IF X MOD 2>1 X=X+2
570
580 REM PRINTTAB(1,22) tool$,
590 REM IF INKEY-10 PROCPLOT(X,Y)
600 REM TOP VALUES 73 by 74
610
620 REM IF X MOD 2 >2 X=X+8
630 REM IF INKEY-12 AND Y>8 AND Y<73 AND tool$="P" PRINTTAB(X,Y) "A";
640 REM IF INKEY-10 AND Y>8 AND Y<73 AND tool$="P" PROCPLOT(X-2,Y+2)
650 REM IF INKEY-12 AND Y>8 AND Y<73 AND tool$="d" AND X MOD 2=0 AND Y MOD 2=0 PROCPLOT(X-2,Y+2):PROCPLOT(X-2+2,Y+2):PROCPLOT(X-1,Y+3):PROCPLOT(X-1+2,Y+3):
660 IF INKEY-12 AND Y>8 AND Y<73 AND tool$="d" MOUSE X,Y,Z: xtemp%=X: ytemp%=Y:PRINTTAB(X/17,Y/14) CHR$160;: x=x-4: y=ytemp% :WAIT 20
670 IF INKEY-10 AND tool$="colred" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$145; :WAIT 20
680 IF INKEY-10 AND tool$="colgreen" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$146; :WAIT 20
690 IF INKEY-10 AND tool$="colyel" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$147; :WAIT 20
700 IF INKEY-10 AND tool$="colblue" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$148; :WAIT 20
710 IF INKEY-10 AND tool$="colmag" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$149; :WAIT 20
720 IF INKEY-10 AND tool$="colcya" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$150; :WAIT 20
730 IF INKEY-10 AND tool$="colwhite" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$151; :WAIT 20
REM
740 IF INKEY-12 AND tool$="colred" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$129;CHR$157; :WAIT 20
770 IF INKEY-12 AND tool$="colgreen" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$130;CHR$157; :WAIT 20
780 IF INKEY-12 AND tool$="colyel" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$131;CHR$157; :WAIT 20
790 IF INKEY-12 AND tool$="colblue" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$132;CHR$157; :WAIT 20
800 IF INKEY-12 AND tool$="colmag" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$133;CHR$157;; :WAIT 20
810 IF INKEY-12 AND tool$="colcya" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$134;CHR$157; :WAIT 20
820 IF INKEY-12 AND tool$="colwhite" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$135;CHR$157; :WAIT 20
830
840
850
860
870
880 REM IF INKEY-10 AND Y>8 AND Y<73 AND tool$="d" AND X MOD 2=0 AND Y MOD 2=0 PROCERASE(X-2,Y+2):PROCERASE(X-2+4,Y+2)
890 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="p" AND dontpaint%=0 AND CY%>2 PROCPLOT(X%-2,Y%+4)
900 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="dp" AND dontpaint%=0 AND CY%>2 PROCPLOT(X%-2,Y%+4):PROCPLOT(X%,Y%+4):
910
920 REM PRINTTAB(0,23) X%,Y%
930 IF CY%<0 CY%=0
940 IF CY%>24 CY%=24
950 IF X<0 X=0
960 IF X>1280 X=1280
970 IF Y<0 Y=0
980 IF Y>1024 Y=1024
990 REM IF CY%<2 dontpaint%=1 :trig%=1
1000
1010
1020
1030
1040
1050
1060
1070 UNTIL FALSE
1080
1090 END
1100
1110 REM and lastly here is the procedure to plot the point
1120
1130 DEF PROCPLOT(X%,Y%)
1140
1150 LOCAL C%,A%
1160
1170 VDU 31,X% DIV2+1, 24-Y% DIV3
1180
1190 C%=S%?((X% AND 1)+(2-Y%MOD3) *2)
1200
1210 A%=135
1220
1230 VDU (USR &FFF4 AND &FF00) DIV256 OR C% OR 128
1240
1250
1260 ENDPROC
1270
1280 DEF PROCERASE(X%,Y%)
1290
1300 LOCAL C%,A%
1310
1320 VDU 31,X% DIV2+1, 24-Y% DIV3
1330
1340 C%=S%?((X% AND 1)+(2-Y%MOD3) *2)
1350
1360 A%=133
1370
1380 VDU (USR &FFF4 AND &FF00) DIV256 OR C% OR 128
1390
1400 ENDPROC
1410
1420
1430 DEF PROCGR
1440
1450
1460
1470 VDU 12
1480
1490 FOR Y%=2 TO 23
1500 IF backcol%>0 PRINTTAB(0,Y%) CHR$(128+backcol%);CHR$(157);CHR$(151)
1510 IF backcol%=0 VDU 10,13,&97
1520
1530 NEXT
1540 REM PRINT PALETTE
1550 FOR count%=0 TO 8
1560 PRINTTAB(0+count%*4-3,0) CHR$(127+count%);CHR$(144+count%);CHR$(255);CHR$(255);
1570 PRINTTAB(30,0) "PDCLS"
1580 NEXT count%
1590 ENDPROC

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sat Jul 25, 2020 11:08 pm

Hey Fourthstone....you have taught me well Obi Wan

Look I got the dithering working :D ..you can see it when I painted the planet. The dithering tesselates properly like checkerboard fashion. The secret is MOD and DIV to work that out. I had a go and wrote if the position of the cursor at value X is even in value plot a point and if not then don't. It was a bodge but it works! Now to work out line drawing. I remember there is a well known routine from long ago that everyone uses to draw lines...I will have to look it up (how to plot a line with points)
Attachments
DITHERING.PNG

User avatar
FourthStone
Posts: 1030
Joined: Thu Nov 17, 2016 2:29 am
Location: Brisbane, Australia
Contact:

Re: Teletext paint program

Post by FourthStone » Sun Jul 26, 2020 2:15 am

Looking good pixel =D>

I've had a quick look at the code and can see a few areas we can reduce the amount of IF statements etc. hopefully will get some time in the next few days [-o<

To make it easier for readability and to copy / paste you can use the code block format from the tool bar </>

Code: Select all

10 MODE 7
20
30 DIM S% 7
40 VDU 28,1,24,39,1
50
60 !S%=&08040201
70
80 S%!4=&4010
If you make any changes, edit the post with the source listing in so others can keep up with the latest version and offer assistance where possible.

Excellent progress =D>

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 4:33 am

Thanks a lot those tips are very useful. I will post the code back in the same place...that is a really good idea.It is. Bit messy I know, If one doesn’t start on the right foot with commenting and easy to read variables it’s easy to get confused later down the line isn’t it,

I will tidy the code up a bit and comment it so it’s easy to understand.

I really like programming when it works....it’s so satisfying. Thanks for your help and encouragement.

User avatar
flaxcottage
Posts: 4252
Joined: Thu Dec 13, 2012 8:46 pm
Location: Derbyshire
Contact:

Re: Teletext paint program

Post by flaxcottage » Sun Jul 26, 2020 9:13 am

Brilliant! Can't wait for a working 'alpha' version.

This would save hours of pixel editing when making CommunITel viewdata screens! I wrote a simple BBCB4W program to set/unset pixels on a 'virtual MODE7' screen in a hi-res graphics mode and then convert that to a monochrome viewdata graphics screen for further editing on a Beeb. This is much better! =D>

To save the MODE7 screen you could use nested FOR...NEXT loops containing a routine using OSWORD &0A OSBYTE 135 to read the character at the cursor position and write that byte to a file. This would make a 1K file, which, when *LOADed to &7C00 on a Beeb, would display correctly.
Last edited by flaxcottage on Sun Jul 26, 2020 1:08 pm, edited 1 time in total.
- John

Image

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 10:41 am

pixelblip wrote:
Sat Jul 25, 2020 9:07 pm
The aim of it is to get an app done in Android
This is likely to be easier if you develop it using BBC BASIC for SDL 2.0 rather than BBC BASIC for Windows, although the differences in MODE 7 are minimal (BBCSDL's default MODE 7 character set is very much closer to the original; in BB4W you need to install the Bedstead font to match it).
1) How to save the Mode 7 Screen in BBC Basic for Windows
There's really no better way than to iterate through all the characters using GET(x,y) or OSBYTE 135. With only 1000 characters this will be fast.
The plot routine plots a point but it seems there is nothing there to remove one!
If you are setting a sixel using OR mask% you can reset it using AND NOT mask%. Teletext editors, including mine, usually have a way of setting or resetting the sixel under the mouse pointer.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 10:51 am

pixelblip wrote:
Sat Jul 25, 2020 9:17 pm
When you move to Android there is no right mouse click....
The only common touchscreen equivalent of 'right click' that I am aware of is a 'long press' (touch and hold), but that's usually to call up a context menu or something where the delay isn't important. There must be other touchscreen graphics editors that have set a precedent for this.

On Android you will at least be able to take advantage of the stretch-to-zoom gesture to expand the MODE 7 screen to make it easier to touch individual sixels accurately. That works in Windows too (using BBCSDL) if you're lucky enough to have a touchscreen, as I do.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 11:53 am

Thanks Richard and Flaxcottage about the saving.....
It's also really interesting to hear about undoing a pixel. That was bugging me a lot.

I was thinking about this in bed last night.....
I think the best thing would be to have one menu option for each command. So no right click.
I have customised my menu now. I'm keeping my menu all on one line to make sure the most of the screen can be seen at all times. It's almost inline with teletext anyway as you need a top line to display headers.

I managed to get circles working today. So pleased. You can't see what your plotting but that's ok.
The Undo is the thing I might need some help with from someone. What is the best way of saving the screen and loading it back if something goes wrong?

I have come up with this for the menus as you can see in the screenshot below.

P - Single Pixel
D - Dithered 1st shade
2 - Dithered 2nd shade x2 larger

C - Clear screen to black with white graphics
K - Clear screen to background colour with white graphics

O - Circle
R - Rectangle
L - Line
F - Fill

E - Eraser (at the moment it just plots a whole character)

L - Load
S - Save

U - Undo.

I think that will be enough tools to use for me.
It's so so satisfying writing a program for yourself that does what you want when there isn't really anything out there that will. (i.e teletext editor in android ). We shall see when I finally port it over to Android if the resolutions e.t.c will be ok. It works ok in SDL so far :D
Last edited by pixelblip on Sun Jul 26, 2020 11:57 am, edited 2 times in total.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 11:54 am

Circles ( basic) added
Attachments
Circles Added.PNG

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 11:57 am

10 MODE 7
20
30 DIM S% 7
40 VDU 28,1,24,39,1
50
60 !S%=&08040201
70
80 S%!4=&4010
90
100 REM 70 Next a row of teletext control codes must be written down the left hand side of the screen to turn every line into a graphics display
110 backcol%=0
120 PROCGR
130
140
150
160
170
180
190
200 REM The main program follows
210 X=10:Y=73
220
230 step%=2
240 tool$="P"
250 MOUSE ON 0
260 dontpaint%=0
270 toolsel%=0
280 circenx%=10
290 circeny%=10

300
310 REPEAT
320
330
340
350
360 MOUSE X,Y,Z
370 X%=(X/17.29)
380
390 Y%=Y/13.83
400 CX%= X/32
410 CY%= 24-Y/40.96
420 IF CX%>1 AND CX%<3 AND CY%<2 AND INKEY-10 tool$="colred":dontpaint%=1:toolsel%=1 : backcol%=1
430 IF CX%>3 AND CX%<5 AND CY%<2 AND INKEY-10 tool$="colgreen":dontpaint%=1 :toolsel%=1: backcol%=2
440 IF CX%>5 AND CX%<7 AND CY%<2 AND INKEY-10 tool$="colyel":dontpaint%=1:toolsel%=1 : backcol%=3
450 IF CX%>7 AND CX%<9 AND CY%<2 AND INKEY-10 tool$="colblue":dontpaint%=1 :toolsel%=1 : backcol%=4
460 IF CX%>9 AND CX%<11 AND CY%<2 AND INKEY-10 tool$="colmag":dontpaint%=1 :toolsel%=1 : backcol%=5
470 IF CX%>11 AND CX%<13 AND CY%<2 AND INKEY-10 tool$="colcya":dontpaint%=1 :toolsel%=1 : backcol%=6
480 IF CX%>13 AND CX%<15 AND CY%<2 AND INKEY-10 tool$="colwhite":dontpaint%=1 :toolsel%=1 : backcol%=7
490
500 IF CX%=16 AND CY%<2 AND INKEY-10 tool$="p":dontpaint%=0
510 IF CX%=17 AND CY%<2 AND INKEY-10 tool$="dp":dontpaint%=0
IF CX%=18 AND CY%<2 AND INKEY-10 tool$="dp2":dontpaint%=0
IF CX%=19 AND CY%<2 AND INKEY-10 tool$="dp2":dontpaint%=0
IF CX%=20 AND CY%<2 AND INKEY-10 tool$="dp2":dontpaint%=0
IF CX%=21 AND CY%<2 AND INKEY-10 tool$="dp2":dontpaint%=0
IF CX%=23 AND CY%<2 AND INKEY-10 tool$="o":dontpaint%=0
530 IF CX%=20 AND CY%<2 AND INKEY-10 tool$="clear":dontpaint%=0:backcol%=0:PROCGR:backcol%=0: tool$="p":dontpaint%=0
IF CX%=21 AND CY%<2 AND INKEY-10 tool$="clearpapercol":dontpaint%=0::PROCGR:backcol%=0: tool$="p":dontpaint%=0
540 IF CX%=34 AND CY%<2 AND INKEY-10 tool$="l":dontpaint%=1:
550 IF CY%>1 AND toolsel%=1 toolsel%=0:dontpaint%=0
560
570
580
590
600
610
620 REM IF X MOD 2>1 X=X+2
630
640 REM PRINTTAB(1,22) tool$,
650 REM IF INKEY-10 PROCPLOT(X,Y)
660 REM TOP VALUES 73 by 74
670
680 REM IF X MOD 2 >2 X=X+8
690 REM IF INKEY-12 AND Y>8 AND Y<73 AND tool$="P" PRINTTAB(X,Y) "A";
700 REM IF INKEY-10 AND Y>8 AND Y<73 AND tool$="P" PROCPLOT(X-2,Y+2)
710 REM IF INKEY-12 AND Y>8 AND Y<73 AND tool$="d" AND X MOD 2=0 AND Y MOD 2=0 PROCPLOT(X-2,Y+2):PROCPLOT(X-2+2,Y+2):PROCPLOT(X-1,Y+3):PROCPLOT(X-1+2,Y+3):
720 IF INKEY-12 AND Y>8 AND Y<73 AND tool$="d" MOUSE X,Y,Z: xtemp%=X: ytemp%=Y:PRINTTAB(X/17,Y/14) CHR$160;: x=x-4: y=ytemp% :WAIT 20
730 IF INKEY-10 AND tool$="colred" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$145; :WAIT 20
740 IF INKEY-10 AND tool$="colgreen" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$146; :WAIT 20
750 IF INKEY-10 AND tool$="colyel" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$147; :WAIT 20
760 IF INKEY-10 AND tool$="colblue" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$148; :WAIT 20
770 IF INKEY-10 AND tool$="colmag" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$149; :WAIT 20
780 IF INKEY-10 AND tool$="colcya" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$150; :WAIT 20
790 IF INKEY-10 AND tool$="colwhite" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$151; :WAIT 20
800 REM
810 IF INKEY-12 AND tool$="colred" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$129;CHR$157; :WAIT 20
820 IF INKEY-12 AND tool$="colgreen" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$130;CHR$157; :WAIT 20
830 IF INKEY-12 AND tool$="colyel" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$131;CHR$157; :WAIT 20
840 IF INKEY-12 AND tool$="colblue" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$132;CHR$157; :WAIT 20
850 IF INKEY-12 AND tool$="colmag" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$133;CHR$157;; :WAIT 20
860 IF INKEY-12 AND tool$="colcya" AND CY%>1 PRINTTAB(X/32,24-(Y/40.96)) CHR$134;CHR$157; :WAIT 20
870 IF INKEY-12 AND tool$="colwhite" AND CY%>1PRINTTAB(X/32,24-(Y/40.96)) CHR$135;CHR$157; :WAIT 20
880
890
900
910
920
930 REM IF INKEY-10 AND Y>8 AND Y<73 AND tool$="d" AND X MOD 2=0 AND Y MOD 2=0 PROCERASE(X-2,Y+2):PROCERASE(X-2+4,Y+2)
940 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="p" AND dontpaint%=0 AND CY%>2 PROCPLOT(X%-2,Y%+4)
950 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="e" AND dontpaint%=0 AND CY%>2 PRINTTAB(X/32,24-(Y/40.96)) " "; :WAIT 20
960 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="dp" AND X% MOD 2=0 AND Y% MOD 2=0 PROCPLOT(X%-2,Y%+4):PROCPLOT(X%-2+1,Y%+4-1)
970 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="dp2" AND X% MOD 2=0 AND Y% MOD 2=0 PROCPLOT(X%-2,Y%+4):PROCPLOT(X%-2+4,Y%+4)
980 IF INKEY-10 AND Y%>2 AND CY%>1 AND tool$="o" AND dontpaint%=0 AND CY%>2 circenx%=X%: circeny%=Y%
990 IF INKEY-12 AND Y%>2 AND CY%>1 AND tool$="o" AND dontpaint%=0 AND CY%>2 AND X-circenx%>10 AND Y-circeny%>20 circrad%=X%-circenx%: PROCc(circenx%,circeny%,circrad%)
1000
1010
1020 REM PRINTTAB(0,23) X%,Y%
1030 IF CY%<0 CY%=0
1040 IF CY%>24 CY%=24
1050 IF X<0 X=0
1060 IF X>1280 X=1280
1070 IF Y<0 Y=0
1080 IF Y>1024 Y=1024
1090 REM IF CY%<2 dontpaint%=1 :trig%=1
1100
1110
1120
1130
1140
1150
1160
1170 UNTIL FALSE
1180
1190 END
1200
1210 REM and lastly here is the procedure to plot the point
1220
1230 DEF PROCPLOT(X%,Y%)
1240
1250 LOCAL C%,A%
1260
1270 VDU 31,X% DIV2+1, 24-Y% DIV3
1280
1290 C%=S%?((X% AND 1)+(2-Y%MOD3) *2)
1300
1310 A%=135
1320
1330 VDU (USR &FFF4 AND &FF00) DIV256 OR C% OR 128
1340
1350
1360 ENDPROC
1370
1380 DEF PROCERASE(X%,Y%)
1390
1400 LOCAL C%,A%
1410
1420 VDU 31,X% DIV2+1, 24-Y% DIV3
1430
1440 C%=S%?((X% AND 1)+(2-Y%MOD3) *2)
1450
1460 A%=133
1470
1480 VDU (USR &FFF4 AND &FF00) DIV256 OR C% OR 128
1490
1500 ENDPROC
1510
1520
1530 DEF PROCGR
1540
1550
1560
1570 VDU 12
1580
1590 FOR Y%=2 TO 23
1600 IF backcol%>0 PRINTTAB(0,Y%) CHR$(128+backcol%);CHR$(157);CHR$(151)
1610 IF backcol%=0 VDU 10,13,&97
1620
1630 NEXT
1640 REM PRINT PALETTE
1650 palcol%=1
1660 FOR step%=1 TO 15 STEP 2
1670
1680 PRINTTAB(step%,0) CHR$(127);CHR$(144+palcol%);CHR$(255);
1690 palcol%=palcol%+1
1700 NEXT step%
1710
1720 PRINTTAB(14,0);CHR$(135); "PD2 CK ORLF E LS U"
1730
1740 ENDPROC
1750
1760 DEFPROCc(x%,y%,r%):LOCALA,s,c,x,y,B,s%:A=2*PI/32:s=SINA:c=COSA:x=r%:y=0:MOVEx%+r%,y%:FORs%=1TO128:B=x*c-y*s:y=x*s+y*c:x=B:PROCPLOT(x%+x,y%+y):NEXT:PROCPLOT(x%+r%,y%):ENDPROC
Last edited by pixelblip on Sun Jul 26, 2020 12:00 pm, edited 1 time in total.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 11:58 am

Please excuse the messy messy code - there's a lot of crap in it I didn't want to delete straight away incase I needed something ( from the REM statements). Once it's kinda working I will document it and replace the variable names so they make more sense.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 12:30 pm

pixelblip wrote:
Sun Jul 26, 2020 11:58 am
Please excuse the messy messy code
It would look neater, at least, if you posted it in [code] [/code] tags; that's what they're for! It also makes it much easier for somebody to copy-and-paste the program.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 12:32 pm

Ok I will do that when I have a readup thank you.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 12:37 pm

pixelblip wrote:
Sun Jul 26, 2020 11:53 am
I have come up with this for the menus as you can see in the screenshot below.
So does that mean the Android on-screen-keyboard will have to be displayed all the time? That could significantly reduce the screen real-estate available for editing. I'd prefer a more touch-friendly menu system to something needing a keyboard.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 12:39 pm

No Richard the Android on screen keyboard is not needed at all. Only for the filenames. I might even skip typing filenames in so you don't have to touch the Android keyboard at all.
That is why I put those letters at the top of the menu - they are all selected by mouse/finger rather than rely on a hotkey e.t.c.

I wanted a paint app that will let you just get on and paint with no 'interference'. I might change my mind of course!
Attachments
Rectangles.PNG

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 12:43 pm

I am now going to attempt to understand fill with points if I can find that on the net and the Bresenham line algorithm which just about every graphics programmer has been through ( but not me yet! )

If anyone can point me in the direction of this I would be grateful as I am scouring the internet for 'How to draw lines in BBC basic using PLOT 69 ' and 'how to fill shapes in BBC basic using PLOT 69). It must have been done many times before! :) Thanks.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 12:52 pm

pixelblip wrote:
Sun Jul 26, 2020 12:39 pm
That is why I put those letters at the top of the menu - they are all selected by mouse/finger rather than rely on a hotkey e.t.c.
Ah, so the letters are just mnemonics for the various commands? That's good.

I've only glanced at your code, but I can't see anything obvious that's stopping it being an 'infinite loop'. You mustn't do that in Android, you'll end up with a red-hot phone/tablet and a flat battery in no time! For that matter you shouldn't do it on any platform, but it's particularly crucial if it's battery powered. Power consumption should always be at the back of your mind when coding for mobile (I realise it's not going to be a priority if you're writing a shoot-'em-up video game, but a teletext editor is different).

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 12:59 pm

Ah ok......infinite loops.....that is interesting as the program itself is on an infinite loop but I guess you mean avoid it doing loads of calculations as well inside that....

It's still a bit rough around the edges. I need to stop shapes being plotted and the side of the screen and ruining the teletext control codes so need to work that out...that shouldn't be too bad. It's checking size of shapes/widths vs the start plot point.

The thought of being able to animate the pages is very exciting to me!. Musn't run before you can walk .......

One of the other things that bugs me is trying to get a grip on where the cursor is and where the shapes are plotted / centre of the shape. The centre of the cursor is a bit off when plotting circles to where I expect it to be. I will have to fiddle around there. As far as I can tell the max X /edge of the screen in teletext graphics using this plot routine is 73 and Y is 65 ( before you hit the menus ). Those are the variables X% and Y% in this program.
CX% and CY% are the text character position of the mouse and X,Y,Z is the actual mouse position which has a maximum resolution/value of 1280x1024.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 1:05 pm

I handily ( very handily) found this for the lines and the code is there. Phew! I didn't want to work that out.

https://rosettacode.org/wiki/Bitmap/Bre ... #BBC_BASIC

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 1:14 pm

Well that code didn't work as there is LINE command in there so back to trying to find another line drawing routine that plots points

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 1:17 pm

I got the line drawing working! Hoorah!
Sometimes you just change a variable and see what happens. In my case the plot in the bresenham had a *2 next to x% and y% - I removed it and it worked. !

User avatar
jgharston
Posts: 4119
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Teletext paint program

Post by jgharston » Sun Jul 26, 2020 1:50 pm

flaxcottage wrote:
Sun Jul 26, 2020 9:13 am
To save the MODE7 screen you could use nested FOR...NEXT loops containing a routine using OSWORD &0A OSBYTE 135 to read the character at the cursor position and write that byte to a file. This would make a 1K file, which, when *LOADed to &7C00 on a Beeb, would display correctly.
It's easier to keep the contents of the display in memory rather than using the screen as your "contents", then you just save the contents of your memory block, eg:
FOR A%=0 TO 1023:BPUT#out%,mem%?A%:NEXT A%

When you are editing your screen, store the character in your memory block, and then reflect it to the screen.
REPEAT
K%=GET
blah blah
mem%?here%=K%:VDU K%:here%=here%+1
check for wrap-around
etc.

This also makes it a lot easier to manipulate display contents where you are modifying the existing contents, and you've got the contents in your memory block instead of having to read it back from the display. For instance, if you want to insert a character into a line and "push" characters out of the way, just do it with the data in memory then redisplay the line. Similarly with manipulating pixels where you have to modify the existing character in the character cell.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 1:54 pm

pixelblip wrote:
Sun Jul 26, 2020 12:59 pm
the program itself is on an infinite loop but I guess you mean avoid it doing loads of calculations as well inside that....
It doesn't matter what it's doing in the loop: whether it's calculations or anything else it's going to be using 100% CPU time on at least one core, which is a lot of wasted energy. Put another way, these two loops run at different speeds but both use up 100% CPU uselessly, which must be avoided on a battery-powered device at least:

Code: Select all

      REPEAT UNTIL FALSE : REM Loops very quickly, using 100% CPU
      REPEAT x = ATN(1) : UNTIL FALSE : REM Loops more slowly, but still uses 100% CPU!
I need to stop shapes being plotted and the side of the screen and ruining the teletext control codes so need to work that out
Won't setting a text viewport do that for free? I would refer you to your recent question about side-scrolling in MODE 7 in which the control codes were 'protected' that way.

User avatar
Richard Russell
Posts: 1668
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Teletext paint program

Post by Richard Russell » Sun Jul 26, 2020 2:08 pm

jgharston wrote:
Sun Jul 26, 2020 1:50 pm
It's easier to keep the contents of the display in memory rather than using the screen as your "contents"
Why is it "easier"? Keeping the screen and the memory block 'in step' at all times sounds like a significant overhead to me, and if they ever did lose synchronisation it could result in hard-to-debug symptoms. If on the other hand you use the screen itself as your 'contents' it can't go wrong (and at all times you can 'see' what is there). Yes it may be that certain specific operations (like 'pushing' characters out of the way) are slightly slower as a result, but they are not going to be common in a paint program that's editing graphics rather than text.

User avatar
pixelblip
Posts: 2212
Joined: Wed Feb 04, 2015 7:19 pm
Location: London
Contact:

Re: Teletext paint program

Post by pixelblip » Sun Jul 26, 2020 2:25 pm

In the case of a paint program though wouldn't you have a 'repeat until false' anyway?
You start the program and then keep repeating it waiting for mouse movements. It never ends. How can you stop that from happening to avoid your phone getting hot?

Post Reply

Return to “programming”