6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 5:17 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Jan 17, 2021 6:28 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
I am wanting to copy a screen to the Virtual Disk, but am scared might accidentally overwrite a screen with important data if wrong number entered.

What is the best way to check that the destination screen is empty before copying the source over?

Count $400 spaces? or just check line #0 which is supposed to be just an index information line? or some other?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jan 18, 2021 10:59 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
IamRob wrote:
I am wanting to copy a screen to the Virtual Disk, but am scared might accidentally overwrite a screen with important data if wrong number entered.

What is the best way to check that the destination screen is empty before copying the source over?

Count $400 spaces? or just check line #0 which is supposed to be just an index information line? or some other?


The word INDEX takes two numbers, lo and hi, and will display line zero for blocks in the range from lo to hi inclusive. The dowside is that an unused block could have random data that may not display properly (ascii control codes). On the Commodore 64 the data in an unused block is usually zero. Fleet Forth has a word, QTYPE , that mimics the C64's quote mode. All characters that normally will not print are displayed as reverse video characters. QTYPE is used in LIST and INDEX . I filled a block in the REU with the values 0 through $FF. Here is a log of LISTing the block and using the block address to DUMP the contents.
Code:
 OK
1 RAM LIST
SCR# 8001
0: @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ !"#$%&'()*+,-./0123456789:;<=>?
1: @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_................................
2: ................................ ...............................
3: ................................ ...............................
4:
5:
6:
7:
8:
9:
A:
B:
C:
D:
E:
F:
 OK
1 RAM BLOCK 100 DUMP
CC00   0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F   @ABCDEFGHIJKLMNO
CC10  10 11 12 13 14 15 16 17  18 19 1A 1B 1C 1D 1E 1F   PQRSTUVWXYZ[\]^_
CC20  20 21 22 23 24 25 26 27  28 29 2A 2B 2C 2D 2E 2F    !"#$%&'()*+,-./
CC30  30 31 32 33 34 35 36 37  38 39 3A 3B 3C 3D 3E 3F   0123456789:;<=>?
CC40  40 41 42 43 44 45 46 47  48 49 4A 4B 4C 4D 4E 4F   @ABCDEFGHIJKLMNO
CC50  50 51 52 53 54 55 56 57  58 59 5A 5B 5C 5D 5E 5F   PQRSTUVWXYZ[\]^_
CC60  60 61 62 63 64 65 66 67  68 69 6A 6B 6C 6D 6E 6F   ................
CC70  70 71 72 73 74 75 76 77  78 79 7A 7B 7C 7D 7E 7F   ................
CC80  80 81 82 83 84 85 86 87  88 89 8A 8B 8C 8D 8E 8F   ................
CC90  90 91 92 93 94 95 96 97  98 99 9A 9B 9C 9D 9E 9F   ................
CCA0  A0 A1 A2 A3 A4 A5 A6 A7  A8 A9 AA AB AC AD AE AF    ...............
CCB0  B0 B1 B2 B3 B4 B5 B6 B7  B8 B9 BA BB BC BD BE BF   ................
CCC0  C0 C1 C2 C3 C4 C5 C6 C7  C8 C9 CA CB CC CD CE CF   ................
CCD0  D0 D1 D2 D3 D4 D5 D6 D7  D8 D9 DA DB DC DD DE DF   ................
CCE0  E0 E1 E2 E3 E4 E5 E6 E7  E8 E9 EA EB EC ED EE EF    ...............
CCF0  F0 F1 F2 F3 F4 F5 F6 F7  F8 F9 FA FB FC FD FE FF   ................
 OK
CONSOLE

And here are some screen dumps.
Attachment:
1 ram list.png
1 ram list.png [ 19.15 KiB | Viewed 686 times ]
Attachment:
1 ram block 100 dump.png
1 ram block 100 dump.png [ 27.3 KiB | Viewed 686 times ]



Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 19, 2021 12:33 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
Checking the index or LISTing screens manually does not prevent me from enter a wrong screen number. I was looking more for something that can be calculated.

Right now I can do

6 LIST 101 TOSCRN
or
6 SCR ! 101 TOSCRN

I initially did have:

6 101 COPYSCRN

but didn't like the immediacy of the copy. There was no way to check that SCREEN #101 had any data on it after the copy. And I wanted to get away from:

101 LIST
6 101 COPYSCRN

It would be nice to have some data checking done automatically.


I could have created a Virtual disk with screens having all zeroes, and the Virtual disk could have been a sparse file, to save hard drive space, that grows only as needed. But thanks to emulators and plenty of hard drive space, I instead created a 256 kb Virtual disk and saved it all with the space ($20) character. I wanted the blocks to be contiguous in the Virtual disk file anyway.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 19, 2021 1:05 am 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 895
IamRob wrote:
Checking the index or LISTing screens manually does not prevent me from enter a wrong screen number. I was looking more for something that can be calculated.

Right now I can do

6 LIST 101 TOSCRN
or
6 SCR ! 101 TOSCRN

I initially did have:

6 101 COPYSCRN

but didn't like the immediacy of the copy. There was no way to check that SCREEN #101 had any data on it after the copy. And I wanted to get away from:

101 LIST
6 101 COPYSCRN

It would be nice to have some data checking done automatically.


I would have gone with:
Code:
6 101 DUP LIST

And if the destination looked good:
Code:
COPYSCRN

to avoid a typo resulting in a different block number for LIST and the destination block for COPYSCRN .

Quote:
I could have created a Virtual disk with screens having all zeroes, and the Virtual disk could have been a sparse file, to save hard drive space, that grows only as needed. But thanks to emulators and plenty of hard drive space, I instead created a 256 kb Virtual disk and saved it all with the space ($20) character. I wanted the blocks to be contiguous in the Virtual disk file anyway.


For an automatic check, you could have COPYSCRN check the first block location for a comment character ( if you use comments in a consistent way) in line #0.
However, there is the possibility of having a block with old source that you no longer need. It too would be flagged as not available for the destination.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 20, 2021 2:29 am 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 255
IamRob wrote:
I am wanting to copy a screen to the Virtual Disk, but am scared might accidentally overwrite a screen with important data if wrong number entered.
Welcome to the running with scissors part of Forth. Forth assumes you know what you are asking for and does what you ask it to do right away -- if you want oopsie protection you'll need to build that in yourself. The good news is that Forth lets you build it in yourself. Here are some options for you to consider:

1. Make a backup of your important data before you start your session. That way, you can restore your virtual disk from your "backup" version to undo your mistake.

I like to work on my Forth code on my PC and then copy/paste it over into a terminal window to my single board computer. That way I can get my Forth into a known state and then try something. If it doesn't work out, it's easy for me to restore the Forth to that known state because I saved all of the commands to do that on my PC. I just press reset and copy all of the commands over to get back to that known state. I have a backup of all of the screens in my EEPROM so I can restore them if I do something silly. Then it's *OK* to make mistakes (encouraged even - that's how you learn!).

If I've made awesome sauce in my screens that evening, I might even write a word to print out the Forth needed to recreate those screens (that's a Forth word that outputs runnable Forth to the screen), and then copy/paste that from the terminal back into my editor. I have a word ENTER-SCREEN that prompts me line by line for 16 lines to quickly enter a screen. As long as you have 16 total lines, it's very copy/paste friendly. Here is an example I used while testing blocks (the numbers in parens actually go into the screen so I could make sure the lines were going where they should - the first line is line # 0):

Code:
\ Enter screens for testing LOAD and THRU
1 enter-screen
( Test screen 1 )
( 1 ) variable testvalue
( 2 ) testvalue 5 !
( 3 ) variable blkinscreen
( 4 ) blk @ blkinscreen !
( 5 ) variable blkinstring
( 6 ) s" blk @ blkinstring !" evaluate
( 7 ) variable blkinscreenA
( 8 ) blk @ blkinscreenA !
( 9 )
( 10 )
( 11 )
( 12 )
( 13 )
( 14 )
( 15 )
2. If you want protection, build it into your word. Here's an example of how I might check to see if a block/screen is blank (based on the fact that your blank screens are space filled). Note that this assumes 1024 byte blocks, which you might not have on an older Forth
Code:
: blkblank?  ( blk# -- f ) BLOCK 1024 -TRAILING SAWP DROP 0= ;
This loads the block, puts 1024 after it (assuming DECIMAL) to make it a 1024 byte string, and then calls -TRAILING which adjusts the size (only on the stack) of a string to remove trailing spaces. If the entire block is spaces, it will change the 1024 to a 0. It then gets rid of the address (not needed anymore) and checks the resulting size for 0, leaving a flag on the stack. You can now check that flag with IF and copy only if blank (or perhaps prompt the user if it's not blank). Note that this word consumes it's block #, so you'll probably want to DUP that before calling this word. If using an older Forth that has smaller blocks, you'll need to check all the blocks in the screen.

I personally don't like being prompted with ARE YOU SURE? type prompts unless what I am doing is very dangerous. It breaks the copy/paste scriptability if that prompt only comes up sometimes and not others. I'm a big fan of working from one known state to another target state, and then saving that new state by whatever means.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: