Author Topic: Problem whith PCOPY  (Read 7483 times)

0 Members and 1 Guest are viewing this topic.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Problem whith PCOPY
« on: September 24, 2020, 03:01:18 am »
Hi.
I have a problem copying the above screen using PCOPY.
I have always worked with Screen 0 and the PCOPY command has been used regularly to copy the current screen with the data, paint a second screen over it to introduce other data, and then restore the previous screen with another PCOPY; but when I have tried it defining a new screen and loading an image, trying to restore the previous screen with PCOPY does not. It comes out in black.
What am I doing wrong?
Thank you

This is then program:
Code: QB64: [Select]
  1. LOCATE 10, 10: PRINT "This is the first screen"
  2. LOCATE 12, 20: PRINT "Press a key to load image"
  3.  
  4. x$ = INPUT$(1)
  5.  
  6. PCOPY 0, 1
  7.  
  8. SCREEN _NEWIMAGE(2100, 1900, 32)
  9. WIDTH 150, 40
  10.  
  11. i& = _LOADIMAGE("image.jpg", 32)
  12. PageScale = 10
  13. PageHeight = 190 * PageScale
  14. PageWidth = 210 * PageScale
  15.  
  16. PointSize = 10
  17. FontHeight10 = INT(PointSize * 0.3527 * PageScale)
  18. Fuente10 = _LOADFONT("c:\windows\fonts\times.ttf", FontHeight10)
  19.  
  20. LOCATE 14, 20: PRINT "press a key to go to the previous screen"
  21.  
  22. x$ = INPUT$(1)
  23.  
  24. _FREEFONT Fuente10
  25.  
  26. PCOPY 1, 0
  27.  
  28. LOCATE 20, 10: PRINT "press a key to end": x$ = INPUT$(1)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem whith PCOPY
« Reply #1 on: September 24, 2020, 03:20:50 am »
You’re making a copy of a SCREEN 0 screen, and then tossing that text screen out and swapping over to a graphic screen with: SCREEN _NEWIMAGE(2100, 1900, 32)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Problem whith PCOPY
« Reply #2 on: September 24, 2020, 03:31:06 am »
Can't go between text and graphics screens with PCOPY, but you could make a hack...

Code: QB64: [Select]
  1. LOCATE 10, 10: PRINT "This is the first screen"
  2. LOCATE 12, 20: PRINT "Press a key to load image"
  3.  
  4. x$ = INPUT$(1)
  5.  
  6. FOR i = 1 TO _HEIGHT
  7.     FOR j = 1 TO _WIDTH
  8.         pcopy_string$ = pcopy_string$ + CHR$(SCREEN(i, j))
  9. NEXT j, i
  10.  
  11. SCREEN _NEWIMAGE(2100, 1900, 32)
  12. WIDTH 150, 40
  13.  
  14. i& = _LOADIMAGE("image.jpg", 32)
  15. PageScale = 10
  16. PageHeight = 190 * PageScale
  17. PageWidth = 210 * PageScale
  18.  
  19. PointSize = 10
  20. FontHeight10 = INT(PointSize * 0.3527 * PageScale)
  21. Fuente10 = _LOADFONT("c:\windows\fonts\times.ttf", FontHeight10)
  22.  
  23. LOCATE 14, 20: PRINT "press a key to go to the previous screen"
  24.  
  25. x$ = INPUT$(1)
  26.  
  27. LOCATE 1, 1
  28. PRINT pcopy_string$;
  29. _FREEFONT Fuente10
  30.  
  31. LOCATE 20, 10: PRINT "press a key to end": x$ = INPUT$(1)
  32.  
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Problem whith PCOPY
« Reply #3 on: September 24, 2020, 03:53:35 am »
Thank you.
Although I do not understand if I make a copy of screen 0, load a new screen and then return to screen 0, why is the previous screen not copied with PCOPY, if it was saved in memory.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Problem whith PCOPY
« Reply #4 on: September 24, 2020, 03:56:19 am »
Pete's option is very good, but there are different colors of text on the screen and it would have to be rewritten entirely

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem whith PCOPY
« Reply #5 on: September 24, 2020, 04:08:58 am »
Use _COPYIMAGE to make a backup copy.

The problem with PCOPY is that there’s no set PFREE command.  QB64 allows us to make a limitless number of screen pages, but how would you ever free those pages from memory??

You can’t, manually, so QB64 does it automatically for you, if you switch SCREENs.  PCOPY is just for quick, temporary coping of one screen, while you’re staying in that screen.  Insert another SCREEN statement, and that temporary data cache is freed, reducing resource requirements.

What you want is to use _COPYIMAGE to make a backup of your screen, which you can restore later.  Only important thing to note here:  you need to manually _FREEIMAGE when finished with the copy.  QB64 won’t clean it up automatically for you.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Problem whith PCOPY
« Reply #6 on: September 24, 2020, 05:17:28 am »
_COPYIMAGE??? No dammit, do it the hard way!!!

Code: QB64: [Select]
  1. LOCATE 7, 10
  2. FOR i = 1 TO 9
  3.     COLOR i, 9 - i
  4.     PRINT i;
  5. COLOR 7, 0
  6.  
  7. FOR i = 1 TO _HEIGHT
  8.     FOR j = 1 TO _WIDTH
  9.         pcopy_string$ = pcopy_string$ + CHR$(SCREEN(i, j))
  10.         pcopy_color$ = pcopy_color$ + CHR$(SCREEN(i, j, 1))
  11. NEXT j, i
  12.  
  13. x$ = INPUT$(1)
  14.  
  15. SCREEN _NEWIMAGE(2100, 1900, 32)
  16.  
  17. x$ = INPUT$(1)
  18.  
  19.  
  20. FOR i = 1 TO _HEIGHT
  21.     FOR j = 1 TO _WIDTH
  22.         x = ASC(MID$(pcopy_color$, _WIDTH * (i - 1) + j, 1))
  23.         COLOR x MOD 16, x \ 16
  24.         PRINT MID$(pcopy_string$, _WIDTH * (i - 1) + j, 1);
  25. NEXT j, i
  26.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Problem whith PCOPY
« Reply #7 on: September 24, 2020, 05:21:51 am »
Oh, and so Steve doesn't have a barf-a-thon over the repetitive COLOR call, do this...

Code: QB64: [Select]
  1. oldx = -1
  2. LOCATE 7, 10
  3. FOR i = 1 TO 9
  4.     COLOR i, 9 - i
  5.     PRINT i;
  6. COLOR 7, 0
  7.  
  8. FOR i = 1 TO _HEIGHT
  9.     FOR j = 1 TO _WIDTH
  10.         pcopy_string$ = pcopy_string$ + CHR$(SCREEN(i, j))
  11.         pcopy_color$ = pcopy_color$ + CHR$(SCREEN(i, j, 1))
  12. NEXT j, i
  13.  
  14. x$ = INPUT$(1)
  15.  
  16. SCREEN _NEWIMAGE(2100, 1900, 32)
  17.  
  18. x$ = INPUT$(1)
  19.  
  20.  
  21. FOR i = 1 TO _HEIGHT
  22.     FOR j = 1 TO _WIDTH
  23.         x = ASC(MID$(pcopy_color$, _WIDTH * (i - 1) + j, 1))
  24.         IF x <> oldx THEN
  25.             COLOR x MOD 16, x \ 16
  26.             oldx = x
  27.         END IF
  28.         PRINT MID$(pcopy_string$, _WIDTH * (i - 1) + j, 1);
  29. NEXT j, i
  30.  

Now if you will excuse me, that deer isn't going to tear itself apart with my bare hands...

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem whith PCOPY
« Reply #8 on: September 24, 2020, 08:10:59 am »
Even simpler:

_CONTROLCHR OFF
oldx = -1
LOCATE 7, 10
FOR i = 1 TO 9
    COLOR i, 9 - i
    PRINT i;
NEXT
COLOR 7, 0
 
BackUp =  _COPYIMAGE(0)
 
x$ = INPUT$(1)
 
SCREEN _NEWIMAGE(2100, 1900, 32)
 
x$ = INPUT$(1)
 
SCREEN BackUp
 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Problem whith PCOPY
« Reply #9 on: September 24, 2020, 10:15:13 am »
When will we be getting that _justdowhatiwant keyword? Even better...

DO until _igetwhatiwant
LOOP

How's that for simple? Well, I'm torn. I miss the good ol' days of having to figure this stuff out, but I appreciate the new tools in the box, too. Somewhere on my old backups, I have a 1990's something color screen saver routine. QBasic had no _CONTROLCHR OFF, so I think I just added past the control characters and subtracted that amount when calculating the colors. +31 and -31, maybe +8 and -8, or maybe I just swapped out chr$(7) with 255, using a select case. The only downside was loss of some possible highlighted color combos, but really only important if PALLET was being used. I sure wish the QBasic developers would have made _CONTROLCHR OFF back in the day.

I haven't used _COPYIMAGE in QB64, but yes, if I was making a graphics to text screen app, I would... STILL DO IT THE HARD WAY! Brooohahaha!!!!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Problem whith PCOPY
« Reply #10 on: September 24, 2020, 02:32:40 pm »
Thank you. It has been very helpful

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Problem whith PCOPY
« Reply #11 on: September 24, 2020, 03:50:03 pm »
Can't go between text and graphics screens with PCOPY, but you could make a hack...

Thats right you old hack... :P

_COPYIMAGE??? No dammit, do it the hard way!!!

Pete

whats so hard about PCOPY?
Antiquated maybe, but 'hard'. Nay says I.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Problem whith PCOPY
« Reply #12 on: September 24, 2020, 09:12:35 pm »
Lay off the weed and learn to read!

Pete :D
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Problem whith PCOPY
« Reply #13 on: September 25, 2020, 12:47:53 pm »
Lay off the weed and learn to read!

Pete :D

Really.... REALLY?
Is that it? Oh come on where is the snappy witticism I have come to expect from you Pete?
The fun, the pun, the wit! What happened? Dont tell me you have gotten too old?!

Seriously,
Being Screen 0  you could use DEFSEG, and PEEK to save both the character data and color data to a string. But not sure how to get the colors from screen 0 to translate back in a 32 bit screen mode. Save the brute force method of predefining them ie:
Code: QB64: [Select]
  1. CONST WHITE = _RGB32(255,255,255)
  2. IF C% = 15 THEN COLOR WHITE
and doing that for each color. But then you get the blinking colors. Besides some trickery how would you copy those to a 32bit screen?

Ah screw it.. come on lets just stick with SCREEN 0! Who needs more?
« Last Edit: September 25, 2020, 01:36:49 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem whith PCOPY
« Reply #14 on: September 25, 2020, 01:22:16 pm »
Quote
Who needs more?

I do! :) and any one who likes color graphics.

Hey just look at our avatar choices! ;-))

« Last Edit: September 25, 2020, 01:28:58 pm by bplus »