6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Sep 29, 2024 3:27 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Aug 20, 2018 7:39 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
Hello all,

In C you might use initialize an array such as:
Code:
int myArrray = [1, 17, 6, 42]



In assembly you would basically 'set aside' a chunk of memory and use the syntax of your compiler to tell it what values should fill that chunk like:

Code:
*=$0801 ; 10 SYS (2064)

        byte $0E, $08, $0A, $00, $9E, $20, $28, $32
        byte $30, $36, $34, $29, $00, $00, $00


How is this accomplished in Forth? I can use:

Code:
 create inbuffer 20 allot


so set aside some memory for an 'array' but what is the Forthy way to initialize the values therein?

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 20, 2018 7:58 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
DOH! I swear I searched for an answer before posting. I glanced through ''Starting Forth' again and found the section cryptically labeled 'Initializing an array' :)

Code:
create myData 200 , 123 , 543 , 111 ,


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 22, 2018 8:11 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
There is one detail about that to remember (bit me at one point): The comma saves a whole cell, but if you want to save a byte (say, characters), you need "c-comma".
Code:
create mycells  10 ,  20 ,  30 ,     \ uses three cells
create mybytes  10 c,  20 c,  30 c,  \ uses three bytes
For the most 6502 machines, a cell is two bytes, though I think on my Ubuntu computer with Gforth it's 8 bytes (64 bit CPU), so this can save serious space.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 22, 2018 1:32 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
Thanks! I had not realized there was a c, but it makes sense as it is analogous to c@ and c!. For what I was thinking about I did need a double so I had not considered there might be a byte version of the same command.

I was doing a simple plot to the screen memory and when you use the standard x+n*y to calculate the memory address you pay a dear price for the multiplication on a small system like the C64. In the past if I was only moving one line in Y I would just add the appropriate offset for a line (40 in this case) which is much faster. I dawned on my that if one could spare 50 bytes (two bytes for 25 screen lines) to save the offset of the start of each line in an array [0, 40, 80, 120...] then the Y position could be used to index into the array to retrieve the correct offset (using a lshft since we have to index two bytes at a time. So typing form the top of my head:

Code:
y lshift yOffArray + @ x +


I'm not sure if this would actually be any faster but I guess there is nothing to do but try it and see.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 22, 2018 2:59 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Charlie H. has been doing some awesome work in PETTIL. You should check it out, because a lot of his meticulous optimizations can be easily ported to the C=64.

https://github.com/chitselb/pettil

https://pettil.tumblr.com/

(it looks like his tiddlywiki is no longer working, but maybe that's just a temporary or treatable condition ... it happens to the best of us as we get older ...).

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 22, 2018 3:04 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
barrym95838 wrote:
Charlie H. has been doing some awesome work in PETTIL. You should check it out, because a lot of his meticulous optimizations can be easily ported to the C=64.

https://github.com/chitselb/pettil

https://pettil.tumblr.com/

(it looks like his tiddlywiki is no longer working, but maybe that's just a temporary or treatable condition ... it happens to the best of us as we get older ...).


Forth on the PET. That would be pretty cool. Might give me a good excuse to dig out my PET and see if I can fix whatever it was that popped and stunk up my house last time I used it. lol

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 22, 2018 3:17 pm 
Offline

Joined: Wed Jul 18, 2018 12:12 pm
Posts: 96
barrym95838 wrote:
Charlie H. has been doing some awesome work in PETTIL. You should check it out, because a lot of his meticulous optimizations can be easily ported to the C=64.

https://github.com/chitselb/pettil

https://pettil.tumblr.com/

(it looks like his tiddlywiki is no longer working, but maybe that's just a temporary or treatable condition ... it happens to the best of us as we get older ...).


Thanks, I'll give that a read tonight. I have been using: https://github.com/jkotlinski/durexforth for the C64


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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: