Author Topic: Silly Programming Ideas - Turning Text into Graphics  (Read 25332 times)

0 Members and 1 Guest are viewing this topic.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.356
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1201
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #50 on: 03:00, 25 October 12 »
Yes, DRAW is very slow, but I think SIN and COS are slower.
Pre-calculating the calls to SIN and COS makes it quite a bit faster (at the expense of a short wait when the program first starts).
 
Code: [Select]
10 print "Pre-calculating..."
20 DEG
21 dim s0(88):dim s90(88):dim s180(88):dim s270(88)
22 dim c0(88):dim c90(88):dim c180(88):dim c270(88)
23 for p%=0 to 88 step 2
24 s0(p%)=320+sin(p%)*100:s90(p%)=320+sin(p%+90)*100:s180(p%)=320+sin(p%+180)*100:s270(p%)=320+sin(p%+270)*100
25 c0(p%)=200+cos(p%)*50:c90(p%)=200+cos(p%+90)*50:c180(p%)=200+cos(p%+180)*50:c270(p%)=200+cos(p%+270)*50
26 next p%
27 mode 1
40 WINDOW #1,14,27,7,16:PAPER #1,0:INK 0,0:BORDER 0:INK 1,13
60 FOR p%=0 TO 88 STEP 2
61 cls #1
70 MOVE s0(p%),c0(p%),1:DRAW 320,300
80 MOVE s90(p%),c90(p%):DRAW 320,300
90 MOVE s180(p%),c180(p%):DRAW 320,300
100 MOVE s270(p%),c270(p%):DRAW 320,300
110 MOVE s0(p%),c0(p%):DRAW s90(p%),c90(p%)
120 DRAW s180(p%),c180(p%):DRAW s270(p%),c270(p%)
130 DRAW s0(p%),c0(p%)
150 CALL &BD19
160 NEXT
170 GOTO 60
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline HAL 6128

  • 6128 Plus
  • ******
  • Posts: 515
  • Country: de
    • index.php?action=treasury
  • Liked: 254
  • Likes Given: 1336
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #51 on: 10:49, 25 October 12 »
I've measured with the help of the TIME command both examples and precalulating increases speed of this example at a factor of 2,5. Impressive!
Clearing screen (of the reduced window size) took 0,02 seconds.
Drawing frame of the first example took ~0,5 second and the second example took ~0,2 second.
So, clearing screen is faster than redrawing the lines (deleting) with XOR mode.
I've measured that if the size of the object becomes smaller than drawing speed grows (of course). In the second example it varies from 0,23 to 0,17 seconds.
So,drawing command is indeed slower the bigger the object is. The reason for the low speed of the drawing command is it's all-purpose functionality (checking clipping, algorithm, mask, check mode etc.)?? Am I right? I don't know the firmware code behind.
 
By the way, the CALL &BD19 (wait for the frame flyback). What is the best position in a program for that command. Before printing, deleting?
 
 
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #52 on: 14:25, 25 October 12 »
By the way, the CALL &BD19 (wait for the frame flyback). What is the best position in a program for that command. Before printing, deleting?

After you painted something and before you clean something
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #53 on: 19:05, 25 October 12 »
With buffer:
Code: [Select]
10 ON BREAK GOSUB 280
20 PRINT "Pre-calculating..."
30 FOR t=0 TO 11:READ a:POKE &8000+t,a:NEXT
40 DEG
50 DIM s0(88):DIM s90(88):DIM s180(88):DIM s270(88)
60 DIM c0(88):DIM c90(88):DIM c180(88):DIM c270(88)
70 FOR p%=0 TO 88 STEP 2
80 s0(p%)=320+SIN(p%)*100:s90(p%)=320+SIN(p%+90)*100:s180(p%)=320+SIN(p%+180)*100:s270(p%)=320+SIN(p%+270)*100
90 c0(p%)=200+COS(p%)*50:c90(p%)=200+COS(p%+90)*50:c180(p%)=200+COS(p%+180)*50:c270(p%)=200+COS(p%+270)*50
100 NEXT p%
110 MODE 1
120 CALL &8000
130 OUT &BC00,12:OUT &BD00,&D0
140 WINDOW #1,14,27,7,16:PAPER #1,0:INK 0,0:BORDER 0:INK 1,13
150 FOR p%=0 TO 86 STEP 4
160 CLS #1
170 MOVE s0(p%),c0(p%),1:DRAW 320,300
180 MOVE s90(p%),c90(p%):DRAW 320,300
190 MOVE s180(p%),c180(p%):DRAW 320,300
200 MOVE s270(p%),c270(p%):DRAW 320,300
210 MOVE s0(p%),c0(p%):DRAW s90(p%),c90(p%)
220 DRAW s180(p%),c180(p%):DRAW s270(p%),c270(p%)
230 DRAW s0(p%),c0(p%)
240 CALL &8000
250 NEXT
260 GOTO 150
270 DATA &11,&00,&40,&21,&00,&C0,&01,&00,&40,&ED,&B0,&C9
280 MODE 1:END

The ASM code:
Code: [Select]
org &8000
LD DE,&4000
LD HL,&C000
LD BC,&4000
LDIR
ret

Any idea how to speed up the LDIR function? :D
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1981
  • Likes Given: 4650
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #54 on: 21:22, 25 October 12 »
Any idea how to speed up the LDIR function? :D

Yepp! You can do it like FutureOS does it. Like LDI:LDI:LDI:LDI:LDI:LDI:LDI:LDI:LDI: and so on....
 
Nothing is faster in copying data.
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.356
  • Country: au
    • index.php?action=treasury
  • Liked: 1016
  • Likes Given: 1201
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #55 on: 03:58, 26 October 12 »
One way to speed up LDIR is to do less of it!  :D
I've broken down the single big LDIR into 8 smaller ones, to only copy data for the character rows that the pyramid is actually drawn to.

Since the pyramid is now spinning faster (i.e. STEP 4), we can also speed up (by a factor of 2) the pre-calc by using STEP 4.
Also, the pre-calc arrays can each be shrunk by 2 bytes, as the last 2 bytes will never be referenced.

The next step for someone to implement is replacing CLS #1 with stack abuse to clear the screen...  ;)
Then WINDOW #1 will no longer be required.

Code: [Select]
10 ON BREAK GOSUB 280
20 PRINT "Pre-calculating..."
30 FOR t=0 TO 88:READ a:POKE &8000+t,a:NEXT
40 DEG
50 DIM s0(86):DIM s90(86):DIM s180(86):DIM s270(86)
60 DIM c0(86):DIM c90(86):DIM c180(86):DIM c270(86)
70 FOR p%=0 TO 86 STEP 4
80 s0(p%)=320+SIN(p%)*100:s90(p%)=320+SIN(p%+90)*100:s180(p%)=320+SIN(p%+180)*100:s270(p%)=320+SIN(p%+270)*100
90 c0(p%)=200+COS(p%)*50:c90(p%)=200+COS(p%+90)*50:c180(p%)=200+COS(p%+180)*50:c270(p%)=200+COS(p%+270)*50
100 NEXT p%
110 MODE 1
120 CALL &8000
130 OUT &BC00,12:OUT &BD00,&D0
140 WINDOW #1,14,27,7,16:PAPER #1,0:INK 0,0:BORDER 0:INK 1,13
150 FOR p%=0 TO 86 STEP 4
160 CLS #1
170 MOVE s0(p%),c0(p%),1:DRAW 320,300
180 MOVE s90(p%),c90(p%):DRAW 320,300
190 MOVE s180(p%),c180(p%):DRAW 320,300
200 MOVE s270(p%),c270(p%):DRAW 320,300
210 MOVE s0(p%),c0(p%):DRAW s90(p%),c90(p%)
220 DRAW s180(p%),c180(p%):DRAW s270(p%),c270(p%)
230 DRAW s0(p%),c0(p%)
240 CALL &8000
250 NEXT
260 GOTO 150
270 DATA &11,&e0,&41,&21,&e0,&C1,&01,&20,&03,&ED,&B0
271 DATA &11,&e0,&49,&21,&e0,&C9,&01,&20,&03,&ED,&B0
272 DATA &11,&e0,&51,&21,&e0,&D1,&01,&20,&03,&ED,&B0
273 DATA &11,&e0,&59,&21,&e0,&D9,&01,&20,&03,&ED,&B0
274 DATA &11,&e0,&61,&21,&e0,&E1,&01,&20,&03,&ED,&B0
275 DATA &11,&e0,&69,&21,&e0,&E9,&01,&20,&03,&ED,&B0
276 DATA &11,&e0,&71,&21,&e0,&F1,&01,&20,&03,&ED,&B0
277 DATA &11,&e0,&79,&21,&e0,&F9,&01,&20,&03,&ED,&B0
279 DATA &C9
280 MODE 2:END
« Last Edit: 04:17, 26 October 12 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #56 on: 13:38, 26 October 12 »
Nice programs folks.  :D


What does:


Code: [Select]
130 OUT &BC00,12:OUT &BD00,&D0


do?


is it just a fancy:


Code: [Select]
call &bd19?


I was taking a different approach when it came to "drawing" something onscreen and then wiping it, applying a short burst delay with a "FOR..NEXT" loop after the object has been drawn, and then applying no delay for deleting the object, making it seem like the object is more visually onscreen rather than offscreen. The consequence in that is the rotation of the image is slowed down, but then I figured it all boils down to how slow is too slow.  :D


If COS & SIN are considered Slow in BASIC, then Turbo Pascal equivalents is a nightmare, no lookup tables, it makes Locomotive BASIC look fast. Using Arrays in BASIC and TP of course is the secret, which will enhance performance.  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #57 on: 13:59, 26 October 12 »
130 OUT &BC00,12:OUT &BD00,&D0

= Screen ram (visible) is @ &4000, while CPC still sends screen data to &C000 (Thats why I LDIRed the ram from C000 to 4000)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #58 on: 01:02, 27 October 12 »
130 OUT &BC00,12:OUT &BD00,&D0

= Screen ram (visible) is @ &4000, while CPC still sends screen data to &C000 (Thats why I LDIRed the ram from C000 to 4000)


Sorry I misread your Assembly program.  :o  Makes sense to move the data from the screen to 2nd screen if it's there, the OUTs threw me cause I would of been doing a SCR SET BASE (&BC08) instead.  :D 


Would of made a nice type-in in it's day.  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #59 on: 10:00, 28 October 12 »
Just had a couple of bits of information totally unrelated, though linked to this thread:  ;D


* What I didn't realise was GRA PLOT ABSOLUTE (&BBEA) or simply PLOT in BASIC (I was doing this in BASIC 1.0, but it should work in BASIC 1.1) will work in conjunction with SCR ACCESS (&BC59), so using XOR mode from SCR ACCESS will work for those as well. Personally I like having the 0s around the graphic and move it in that fashion, though XOR Sprites is possible. It might even be possible to take the Plot Image Routines I made earlier and stick a XOR in it for effect.


* Adjusting the 'theta' variable from "HAL 6128's" program can produce some interesting effects, having it as low as 1 could produce an extremely animated square and returning to where it was, I'd adjusted it to 15 which gives a nice animation effect - about 6 squares before returning to where it was.  ;D  My adjustments to it and adding information has help me to understand the rotation cycles a little better instead of blowing up my image.  :)
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #60 on: 11:53, 01 November 12 »
I think I've got this right now, I've just got no means of testing it at the moment. :(


Code: [Select]

10 MODE 1
20 ' WHILE 1
30 GOSUB 100
40 GOSUB 200
50 GOSUB 300
60 GOSUB 400
70 GOSUB 500
80 GOSUB 600
90 ' WEND
100 MOVE 50,150
110 DRAW 50,50,1
120 DRAW 150,50
130 DRAW 150,150
140 DRAW 50,150
150 RETURN
200 MOVE 39,135
210 DRAW 65,39,2
220 DRAW 161,65
230 DRAW 135,161
240 DRAW 39,135
250 RETURN
300 MOVE 32,118
310 DRAW 82,32,3
320 DRAW 168,82
330 DRAW 118,168
340 DRAW 32,118
350 RETURN
400 MOVE 30,100
410 DRAW 100,30,1
420 DRAW 170,100
430 DRAW 100,170
440 DRAW 30,100
450 RETURN
500 MOVE 32,82
510 DRAW 118,32,2
520 DRAW 168,118
530 DRAW 82,168
540 DRAW 32,82
550 RETURN
600 MOVE 39,65
610 DRAW 135,39,3
620 DRAW 161,135
630 DRAW 65,161
640 DRAW 39,65
650 RETURN
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Online Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 16.012
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3452
  • Likes Given: 6198
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #61 on: 13:58, 01 November 12 »
Quote from: CP/M User
I think I've got this right now, I've just got no means of testing it at the moment.


Code: [Select]
10 MODE 1
20 ' WHILE 1
30 GOSUB 100
40 GOSUB 200
50 GOSUB 300
60 GOSUB 400
70 GOSUB 500
80 GOSUB 600
90 ' WEND
100 MOVE 50,150
110 DRAW 50,50,1
120 DRAW 150,50
130 DRAW 150,150
140 DRAW 50,150
150 RETURN
200 MOVE 39,135
210 DRAW 65,39,2
220 DRAW 161,65
230 DRAW 135,161
240 DRAW 39,135
250 RETURN
300 MOVE 32,118
310 DRAW 82,32,3
320 DRAW 168,82
330 DRAW 118,168
340 DRAW 32,118
350 RETURN
400 MOVE 30,100
410 DRAW 100,30,1
420 DRAW 170,100
430 DRAW 100,170
440 DRAW 30,100
450 RETURN
500 MOVE 32,82
510 DRAW 118,32,2
520 DRAW 168,118
530 DRAW 82,168
540 DRAW 32,82
550 RETURN
600 MOVE 39,65
610 DRAW 135,39,3
620 DRAW 161,135
630 DRAW 65,161
640 DRAW 39,65
650 RETURN
 
Unexpected Return in 150 :D

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #62 on: 14:54, 01 November 12 »
Code: [Select]

10 MODE 1
20 ' WHILE 1
30 GOSUB 100
40 GOSUB 200
50 GOSUB 300
60 GOSUB 400
70 GOSUB 500
80 GOSUB 600
90 GOTO 30 ' WEND
100 MOVE 50,150
110 DRAW 50,50,1
120 DRAW 150,50
130 DRAW 150,150
140 DRAW 50,150
150 RETURN
200 MOVE 39,135
210 DRAW 65,39,2
220 DRAW 161,65
230 DRAW 135,161
240 DRAW 39,135
250 RETURN
300 MOVE 32,118
310 DRAW 82,32,3
320 DRAW 168,82
330 DRAW 118,168
340 DRAW 32,118
350 RETURN
400 MOVE 30,100
410 DRAW 100,30,1
420 DRAW 170,100
430 DRAW 100,170
440 DRAW 30,100
450 RETURN
500 MOVE 32,82
510 DRAW 118,32,2
520 DRAW 168,118
530 DRAW 82,168
540 DRAW 32,82
550 RETURN
600 MOVE 39,65
610 DRAW 135,39,3
620 DRAW 161,135
630 DRAW 65,161
640 DRAW 39,65
650 RETURN
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Online Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 16.012
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3452
  • Likes Given: 6198
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #63 on: 21:03, 01 November 12 »
Nice, thanks! Missed that!

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #64 on: 21:10, 01 November 12 »
Oops, Line 90 should of had a END in it.  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #65 on: 09:43, 03 November 12 »
This is what I came up with in BASIC/Assembly which is based on the last example, unfortunately I forgot to include the Assembly source (the data is in that). It's using GRA LINE ABSOLUTE, though I've been trying to get it to work in conjunction with GRA LINE RELATIVE. The issue I'm having, is having it appear to rotate around like this example is showing. The benefit of GRA LINE RELATIVE is having the image(s) draw onscreen anywhere, though the trick is working out the next position to move to & draw the relevant box.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #66 on: 14:26, 03 November 12 »
Nice thing!
Now check this mod:
Code: [Select]
31 PRINT CHR$(23);CHR$(1)
Also swap the pen in line 70 (second |DRAWIMAGE)  to 1 ;)

So your rectangle will not destroy any background (if exists)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #67 on: 01:59, 01 December 12 »
There was this funny little Type-in in AA58 which twisted and turned with a series of lines which allowed you to either scroll up or scroll down the screen called Twister. The program itself was using Text Based Cursor Up/Down commands LF & VT to either scroll up or down the screen. I thought would be interesting to see how the LDIR Scroll (which only scrolls up) would go on it. I made some modifications to the original program and it produces this interesting spiral scrolling effect. I made two programs (SPIRAL1.BAS & SPIRAL2.BAS), the first one just draws the lines in the same colours up the screen and the second one I've made it to produce it in a series of random colours which looks interesting too. :) In the Disk Image I've attached the Binary as well as the Source Code for the Scrolling Routine.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #68 on: 12:08, 02 December 12 »

Regarding the Rotating Square I was trying to do earlier, this is what I came up with which is all done using Draw Relative (DRAWR) which has some advantages when it comes to placement onscreen (cause everything is being done Relative), the following example is the second program I've attached, I've only modified it in terms of where it starts on screen (using the PLOT statements), though if you look at the first example you will see all the dimensions of the Square are the same (only the positioning has changed), though I did have to work out all the correct positions in order to getting the image to appear to rotate in the correct positions.  :D

Code: [Select]
5 MODE 1
10 PLOT 150,200
20 DRAWR 0,-100,2
30 DRAWR 100,0
40 DRAWR 0,100
50 DRAWR -100,0
60 PLOT 139,185
70 DRAWR 26,-96
80 DRAWR 96,26
90 DRAWR -26,96
100 DRAWR -96,-26
110 PLOT 132,168
120 DRAWR 50,-86
130 DRAWR 86,50
140 DRAWR -50,86
150 DRAWR -86,-50
160 PLOT 130,150
170 DRAWR 70,-70
180 DRAWR 70,70
190 DRAWR -70,70
200 DRAWR -70,-70
210 PLOT 132,132
220 DRAWR 86,-50
230 DRAWR 50,86
240 DRAWR -86,50
250 DRAWR -50,-86
260 PLOT 139,115
270 DRAWR 96,-26
280 DRAWR 26,96
290 DRAWR -96,26
300 DRAWR -26,-96
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #69 on: 06:42, 26 May 13 »
Time to give this ol' Thread a dust down, yesterday I came across an earlier Bouncing Ball Demo I made in BASIC, which is Text Based in nature (using standard LOCATE, PRINT to display & remove the Ball which is a standard "O"), so it moves around the screen really fast, the general idea being I could setup a Window (which I have) and bounce it around that.


Today I thought that would be a good example to stick a background pattern into the Window and have the Ball Bouncing over the top of that, which I thought this would be a good example to use the Transparency Command Code in something simple, which could help me with more complicated programs which use it.


Code: [Select]
10 DIM board$(11,25):GOSUB 1000
20 GOSUB 160:WINDOW wx1%,wx2%,wt%,wb%:PAPER 1: PEN 0: CLS
30 FOR y%=1 TO 25:FOR x%=1 TO 11:BORDER 3:INK 0,3:INK 2,9:PEN 2:LOCATE x%,y%:PRINT board$(x%,y%);:NEXT x%:NEXT y%
40 x%=0:y%=0:xd%=1:yd%=1
50 WHILE INKEY(47)=-1
60 x%=x%+xd%:y%=y%+yd%:oldx%=x%:oldy%=y%
70 PRINT CHR$(22);CHR$(1);:LOCATE x%,y%:PEN 0:PRINT "O"
80 PRINT CHR$(22);CHR$(0);
90 CALL &BD19:CALL &BD19
100 LOCATE oldx%,oldy%:PEN 2:PRINT board$(oldx%,oldy%)
110 IF x%=sx2% THEN xd%=-1
120 IF x%=sx1% THEN xd%=1
130 IF y%=wb% THEN yd%=-1
140 IF y%=wt% THEN yd%=1
150 WEND:MODE 2:PAPER 0:PEN 1:CALL &BC02:END
160 MODE 0:wx1%=5:wx2%=15:wt%=1:wb%=25:sx1%=1:sx2%=11:RETURN
1000 FOR y%=1 TO 25
1010 FOR x%=1 TO 11
1020 board$(x%,y%)=CHR$(207)
1030 NEXT x%:NEXT y%:RETURN


So what I did in this case is setup an 2 Dimensional String based Array, used a subroutine (Line 1000-1030) to place the Background pattern into the Array, Line 20 is one of the original lines which leads to another subroutine (Line 160 - which is also original), which changes the screen mode & sets up the Co-ordinates for the Window before returning. Line 30 is an absolute joke, which more or less does what the subroutine at 1000-1030 does minus printing the result, plus it's constantly changing the INKs, BORDERs & PENs in that Nested Loop, lagging the program even more, sadly it's come to this cause the original program is also weird - a "MODE 0" in a subroutine at the end of the program for example. I couldn't stand the original program just having a GOTO 60 where line 150 now resides, so I changed it to a WHILE loop which exits when Space is pressed & plus I'm resetting the screen INKs and PAPER & PEN colours back to the default colours because I seem to get a little irritated these days by ESCaping from the program and changing everything back to the way it was. Line 40 sets up the positions for the "O" and the Direction it's heading. Initially I had X% & Y% set to 1, but because I'm adding 1 (Line 60) before display the ball, I've changed them to 0 so that when it comes to display it, it will show up in 1,1 and not 2,2 which is what the original did. Line 50 is the Loop - Space Bar will exit the program and restore all the screen colours. Line 60 relates to line 40, does all the work of working out where the Ball will be position next, I've also setup oldx% & oldy% which is used for the 2D Array. The opening Command Code in Line 70 activates the Transparency, so by this stage I've got my Window setup, the background pattern is there, so to make it appear as if the Ball is positioned over the Background pattern, I can use this command to activate the Transparency, LOCATE the position for the Ball & then place the Ball there. Line 80 is the reverse, so it switches it off, I'm unsure if this is needed, I've seen other examples have it there, though in my case in Line 90 I'm doing a Frame Flyback the 464 way, and then in line 100 I'm restoring the position from where the Ball was, so it restores the background pattern. Initially I thought I'd need line 80 because I'm moving the ball, in this case it's a simple process of alternating between Ball & Background, so it looks like the Ball is moving across the Background. Lines 110-140 are merely there as part of the original program to check where the ball is and if it's hitting a marker, so then it can bounce back the other way. Line 150 is where the Loop finishes and where the program Exits back to BASIC with all the colours restored.


Updated: Before anyone downloads that old spaghetti version of my program, I've updated it, I'll keep the old one on show here in case anyone wants to see how Bad it is.  ;D  Another thing I updated in it too is in the old version, once you exited the program and typed in CAT there would be a long pause before displaying the Directory and then another pause before coming up with Ready. Apparently this is because I'm using a 464, a 6128 doesn't seem to have this problem, so what was happening was my 2D array was doing something which was holding up the Disc Drive, so once the program exits and I have no need for the Array, it gets erased, which resolves the Disk Drive hold up. This new program is a bit more polished, though a bit tricky to sort things out, which is why the original has things scattered around in it.
« Last Edit: 11:56, 26 May 13 by AMSDOS »
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #70 on: 11:31, 11 July 13 »

Yepp! You can do it like FutureOS does it. Like LDI:LDI:LDI:LDI:LDI:LDI:LDI:LDI:LDI: and so on....
 
Nothing is faster in copying data.

I've written a scroller using LDI, and to be honest I'm having trouble understanding why a continuous stream of LDIs is better than having one LDI looping around so many times. In my case it's the Horizon, so I'm looping it 80 times to get that effect. It works, though it's slower than LDIR with BC set to a length of 80, though it might have something to do with me using a DJNZ loop since LDI increments and decrements anyway.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.751
  • Country: gb
    • redbox
  • Liked: 326
  • Likes Given: 267
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #71 on: 12:24, 11 July 13 »
I've written a scroller using LDI, and to be honest I'm having trouble understanding why a continuous stream of LDIs is better than having one LDI looping around so many times. In my case it's the Horizon, so I'm looping it 80 times to get that effect. It works, though it's slower than LDIR with BC set to a length of 80, though it might have something to do with me using a DJNZ loop since LDI increments and decrements anyway.

Each instruction takes a set amount of time to execute in the processor.  The LDI instruction is faster than LDIR.

So:
LDI (16 clock cycles) = 80 * 16 = 1280 clock cycles
LDIR (21 clock cycles) = 80 * 21 = 1680 clock cycles
LD r,value (7 clock cycles) : LDI (16 clock cycles) : DJNZ (13 clock cycles) = (7+16+13) * 80 = 2880 clock cycles.

I've used clock cycles instead of the exact CPC speed (it has an overhead if I remember), but hopefully you get the idea.


Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #72 on: 12:50, 11 July 13 »
Each instruction takes a set amount of time to execute in the processor.  The LDI instruction is faster than LDIR.

So:
LDI (16 clock cycles) = 80 * 16 = 1280 clock cycles
LDIR (21 clock cycles) = 80 * 21 = 1680 clock cycles
LD r,value (7 clock cycles) : LDI (16 clock cycles) : DJNZ (13 clock cycles) = (7+16+13) * 80 = 2880 clock cycles.

I've used clock cycles instead of the exact CPC speed (it has an overhead if I remember), but hopefully you get the idea.

Hmmm, I see what you mean.   :-[

So the next thing I was wondering about is on this website they have examples of assembler code to tell the assembler how many times to repeat for things like "ldi" instead of typing it out, I think the Winape Assembler supports this, though the instructions maybe different depending on what statements it's using.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.751
  • Country: gb
    • redbox
  • Liked: 326
  • Likes Given: 267
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #73 on: 13:40, 11 July 13 »
So the next thing I was wondering about is on this website they have examples of assembler code to tell the assembler how many times to repeat for things like "ldi" instead of typing it out, I think the Winape Assembler supports this, though the instructions maybe different depending on what statements it's using.

Yes, Winape does have a 'repeat' macro.

Code: [Select]
repeat 80
   ldi
rend

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.898
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1110
  • Likes Given: 1877
Re: Silly Programming Ideas - Turning Text into Graphics
« Reply #74 on: 11:54, 13 July 13 »
Yes, Winape does have a 'repeat' macro.

Code: [Select]
repeat 80
   ldi
rend

Thanks for that, this is what I came up with

Code: [Select]
;; LDI Scroll - This shifts the screen down in rows at a time.
;; Top Row needs to be blank so contents don't push it all the way down the screen

org &4000

xor a ;; Position for Loop equals 0.
.loop
ld hl,(adr_hl) ;; This holds the address pointer and is place into HL
ld e,(hl) ;; Though the Contents from that address goes into DE
inc hl ;; Cause it's 16bit data this is the only way I know
ld d,(hl) ;; How to do it, there maybe other ways. I dunno.

ex de,hl ;; The data above needs to go into HL and not DE

push hl ;; I need to protect my data in HL

ld hl,(adr_de) ;; This holds the address pointer and is place into HL
ld e,(hl) ;; Though the Contents from that address goes into DE
inc hl ;; Cause it's 16bit data this is the only way I know
ld d,(hl) ;; How to do it, there maybe other ways. I dunno.

pop hl ;; But restore it again for this routine

repeat 80
ldi ;; Moves things along.
rend

ld hl,(adr_hl) ;; Increment Start Position to the next spot
inc hl
inc hl
ld (adr_hl),hl ;; And store it in that pointer variable.

ld hl,(adr_de) ;; Increment Destination to the next position
inc hl
inc hl
ld (adr_de),hl ;; And store it in that pointer variable

inc a ;; Increment Loop

cp 192 ;; Check if this equals 192.

jp nz,loop ;; returns if not equal to 192, otherwise exit

ld hl,begin ;; Restores pointer to the beginning
ld (adr_hl),hl ;; should the user want to continue calling routine

ld hl,dest ;; Restores pointer to the Destination
ld (adr_de),hl ;; should the user want to continue calling routine

ret ;; exit routine

.adr_hl defw begin ;; pointer position to where the start position is for HL register
.adr_de defw dest ;; pointer position to where the start position is for DE register

;; Below these are Screen co-ordinate positions for DE, move from bottom to top of the screen

.dest defw &C780,&CF80,&D780,&DF80,&E780,&EF80,&F780,&FF80
.begin defw &C730,&CF30,&D730,&DF30,&E730,&EF30,&F730,&FF30
defw &C6E0,&CEE0,&D6E0,&DEE0,&E6E0,&EEE0,&F6E0,&FEE0
defw &C690,&CE90,&D690,&DE90,&E690,&EE90,&F690,&FE90
defw &C640,&CE40,&D640,&DE40,&E640,&EE40,&F640,&FE40
defw &C5F0,&CDF0,&D5F0,&DDF0,&E5F0,&EDF0,&F5F0,&FDF0
defw &C5A0,&CDA0,&D5A0,&DDA0,&E5A0,&EDA0,&F5A0,&FDA0
defw &C550,&CD50,&D550,&DD50,&E550,&ED50,&F550,&FD50
defw &C500,&CD00,&D500,&DD00,&E500,&ED00,&F500,&FD00
defw &C4B0,&CCB0,&D4B0,&DCB0,&E4B0,&ECB0,&F4B0,&FCB0
defw &C460,&CC60,&D460,&DC60,&E460,&EC60,&F460,&FC60
defw &C410,&CC10,&D410,&DC10,&E410,&EC10,&F410,&FC10
defw &C3C0,&CBC0,&D3C0,&DBC0,&E3C0,&EBC0,&F3C0,&FBC0
defw &C370,&CB70,&D370,&DB70,&E370,&EB70,&F370,&FB70
defw &C320,&CB20,&D320,&DB20,&E320,&EB20,&F320,&FB20
defw &C2D0,&CAD0,&D2D0,&DAD0,&E2D0,&EAD0,&F2D0,&FAD0
defw &C280,&CA80,&D280,&DA80,&E280,&EA80,&F280,&FA80
defw &C230,&CA30,&D230,&DA30,&E230,&EA30,&F230,&FA30
defw &C1E0,&C9E0,&D1E0,&D9E0,&E1E0,&E9E0,&F1E0,&F9E0
defw &C190,&C990,&D190,&D990,&E190,&E990,&F190,&F990
defw &C140,&C940,&D140,&D940,&E140,&E940,&F140,&F940
defw &C0F0,&C8F0,&D0F0,&D8F0,&E0F0,&E8F0,&F0F0,&F8F0
defw &C0A0,&C8A0,&D0A0,&D8A0,&E0A0,&E8A0,&F0A0,&F8A0
defw &C050,&C850,&D050,&D850,&E050,&E850,&F050,&F850
defw &C000,&C800,&D000,&D800,&E000,&E800,&F000,&F800

I tested it with my existing Assembly Starscrl code and it's faster than the Firmware SCR HW ROLL (&BC4D) because my Starship at the bottom was struggling to stay on screen, it needed 3 Frame Flybacks and even then it was still blinking away, however in order to make the screen look like it's rolling, the first row needs to stay blank to prevent things from being pushed down the screen, something SCR HW ROLL doesn't have a problem with.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3