![]() |
Forum Index : Microcontroller and PC projects : CMM2: initialising large arrays without DATA or files
![]() ![]() |
|||||
Author | Message | ||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Perhaps. In the case I'm working on, providing the constants for computing an MD5 hash, I think I'm just going to brute force it and assign each array element individually. Function crypt.md5$(s$) Static r%(64), K%(64) If r%(1) = 0 Then crypt.md5_init(r%, K%) ' Actual implementation of MD5 goes here. ' ... End Function Sub crypt.md5_init(r%(), K%()) r%(1) = 7 : r%(2) = 12 : r%(3) = 17 ... K%(1) = &hd76aa478 : k%(2) = &he8c7b756 : k%(3) = &h242070db ... End Sub Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Not DIM crypt.r%(4)=(7,12,17,21) DIM crypt.k%(3)=(&hd76aa478,&he8c7b756,&h242070db) ? Of course, it may not work for the size of your arrays vs the line length. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Both arrays have 64 values and k definitely would not fit on a single line. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
You're only trying to make it difficult for me, Tom. ![]() Looks like Peter's CSUB suggestion might be the most compact then. I can't help with that - 'tis one of the Great Mysteries as far as I'm concerned at the moment. ![]() Edited 2021-05-14 01:20 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I think it's me I'm making it difficult for. CSUBs are just blocks of binary, it's when they are called that the magic happens. If I understand it correctly Peter's suggestion is to not call this CSUB though, but instead to use the structure to store arbitary binary data and then use PEEK and MEMORY COPY to copy that data into my arrays. If I can get it working then I'll post my code. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
I did this on a '470. Earlier MMBasic than the CMM2 (August 2015). I had a logo run-length-encoded and that was the data in the cfunction. DIM integer rleaddress = PEEK(CFunAddr logo) DIM integer rlecolor = 0 DIM integer rleoffset = 0 DIM integer rlecount = 0 ' splash screen SUB Splash (logoen AS INTEGER) LOCAL integer oloop LOCAL integer iloop PrintLCD 0, 130, "Initializing", white IF logoen = 1 THEN FOR oloop = 0 TO 119 FOR iloop = 160 TO 319 STEP 1 RLEGetNext8 IF rlecolor <> 0 THEN PIXEL iloop, oloop, rlecolor) NEXT iloop NEXT oloop ENDIF END SUB ' get rle data SUB RLEGetNext8 LOCAL integer color LOCAL integer addoffset IF rlecount > 0 THEN rlecount = rlecount - 1 ELSE rlecount = PEEK(BYTE rleaddress + rleoffset) color = PEEK(BYTE rleaddress + rleoffset+1) IF color = 0 THEN rlecolor = black ELSE rlecolor = &HFEA0 ENDIF rleoffset = rleoffset + 2 ENDIF END SUB CFunction logo 00000000 00FF00FF 00FF00FF 00FF00FF FF030052 FF09002F FF080022 FF050034 FF08002E FF090022 FF010033 FF000000 FF020000 FF02002E FF010000 FF010000 FF020022 FF000000 FF020000 FF080032 FF07002D FF080023 FF090033 FF08002D FF090022 FF090031 FF07002C FF080023 FF0A0033 FF08002C FF090022 FF090031 FF08002C ... snip ... FF040099 FF000000 FF040098 FF03009A FF000000 FF020099 FF01009C FF000001 FF00009D FF01009B 00FF00FF 00FF00FF 00FF00FF 00DA0000 END CFunction Edited 2021-05-14 03:08 by CircuitGizmos Micromites and Maximites! - Beginning Maximite |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
That's a nice demo. Even I can understand it. I think. ![]() Is there a specific reason for beginning the CFunction with four 00 bytes? Edited 2021-05-14 03:29 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Thanks CG. MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
Carry over from a real cfunction. Micromites and Maximites! - Beginning Maximite |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Ah! Thanks, CG. Having not used these things I was wondering if it was something special. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Either I'm having a senior moment or it seems to be more than that, e.g. > list "csub_data.bas" Option Explicit Option Default None Option Base 0 Dim addr% = Peek(CFunAddr csub_data) Print Peek(Byte addr%), Peek(Byte addr% + 1), Peek(Byte addr% + 2), Peek(Byte addr% + 3) Print Peek(Byte addr%+4), Peek(Byte addr% + 5), Peek(Byte addr% + 6), Peek(Byte addr% + 7) Print Peek(Byte addr%+8), Peek(Byte addr% + 9), Peek(Byte addr% + 10), Peek(Byte addr% + 11) CSub csub_data 00000000 00000009 00000008 00000007 00000006 00000005 00000004 00000003 00000002 End CSub > run "csub_data.bas" 9 0 0 0 8 0 0 0 7 0 0 0 So it looks like the address returned from Peek(CFunAddr csub_data) points at the second word of data in the CSUB ? Peter if you're reading this also note that CSUB doesn't appear to be highlighted as a keyword in the EDITor. Best wishes, Tom Edited 2021-05-14 06:19 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
What happens if you don't put the initial 00000000 in, Tom? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
The code for a CSUB starts at the second word. The first word is the offset into the CSUB to use as the entry point. Hence CFUNADDR always returns the address of the second word. Edited 2021-05-14 07:53 by matherp |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Maybe. Bytes are 8 bits... ![]() > list Option Explicit Option Default None Option Base 0 Dim addr% = Peek(CFunAddr csub_data) Print Peek(Byte addr%), Peek(Byte addr% + 1), Peek(Byte addr% + 2), Peek(Byte addr% + 3) Print Peek(Byte addr%+4), Peek(Byte addr% + 5), Peek(Byte addr% + 6), Peek(Byte addr% + 7) Print Peek(Byte addr%+8), Peek(Byte addr% + 9), Peek(Byte addr% + 10), Peek(Byte addr% + 11) CSub csub_data 00000000 06070809 02030405 CCBBAA01 00000006 00000005 00000004 00000003 00000002 End CSub > run 9 8 7 6 5 4 3 2 1 170 187 204 Visit Vegipete's *Mite Library for cool programs. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Thanks Peter, that makes a lot of sense now. ![]() This is a neat way to do in-prog data storage. Handy for things like game maps as well as graphics. Pete: I have a feeling that they used to be... ![]() Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
MustardMan![]() Senior Member ![]() Joined: 30/08/2019 Location: AustraliaPosts: 175 |
In regards to the DATA and RESTORE commands, is there something that can save & restore the current data pointer? For example, I have a library with some DATA statements in it that contain some constants. I've given the DATA block a name, so inside my library I can "RESTORE Name_of_my_data" Elsewhere there are other things that use other DATA and leave the pointer hanging so it can read at its' convenience. However, if I call my library routine I trash it. What if I could, inside my library.... SUB Interesting RESTORE SAVE 'Save the current DATA pointer RESTORE My_data_block READ etc RESTORE RESTORE ' Put the DATA pointer back to what it was before we messed with it END SUB My_data_block DATA 1,2,3 |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Because of the possibility of recursion or simply one library function calling another you would need the ability to set/receive the data pointer from a variable (or a stack based approach for the data pointer.) Peter may set me straight but neither seems particularly likely to be implemented and the faux CSUB approach at least allows you to avoid the problem albeit with some hoop jumping involved and less agreeable syntax. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
MustardMan![]() Senior Member ![]() Joined: 30/08/2019 Location: AustraliaPosts: 175 |
Yes, it would require care, and the CSUB method would be better, although I was actually thinking more generic cases where DATA is stored inside a library (or not). Mind you, I tend to stick away from DATA statements unless nothing else will work (or I want a quick fix). Useful back in the 80's when you had nothing else, but with flash storage as easy as it is now, use cases for DATA are certainly diminished. Cheers, |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
DATA / RESTORE has never been a brilliant system really. It was always really just a way of having the data there on systems that didn't support external storage so that arrays could be filled. It's terribly inefficient in terms of memory so on the early computers it was a pain. It was also the only way to save data. I have an ancient (well, 1981) book from my TRS-80 days - "BASIC Faster and Better" - which shows the techniques for using strings for data storage, and even for using them to store machine code routines (the TRS-80 was too old for inline assembler). Those routines are scary when you look at them now as every bit of code compression in BASIC was used. Long multi-statement lines (don't waste space on line numbers!) every bit as convoluted as the programming challenge. lol Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I'll be interested if anyone corrects me but I am under the impression that only BBC Basic had that facility (and still does in its modern incarnations). Seems to have been a more common feature of FORTH implementations. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |