![]() |
Forum Index : Microcontroller and PC projects : dim var as byte
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
That's because you didn't first type "AUTOSAVE" followed by [Enter] To simplify it further, make the first line of your source code "AUTOSAVE" Visit Vegipete's *Mite Library for cool programs. |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1571 |
Yes! And don't forget to exit the AUTOSAVE mode with CTRL-Z. Another option is to copy ([Shift-Insert]) it directly in EDITOR. Pete was faster ... ![]() Edited 2022-08-09 07:36 by twofingers causality ≠ correlation ≠ coincidence |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
I know nowt about autosave, I'm a thick user who wants to use mmbasic and loaded v4 not v5 vga mmbasic. I'll try it but there maybe "bugs" it says. plenty of try maximite but may not be compatible with picomite if that's what it's called so users advice may be incompatible. It is strange that my sprite code runs so slow compared to a 16MHz 328. ok it's reading data but my original code read "tables" which are data in prog mem. the code is the same. ok it must have defaulted to floats but so slow. why is this uno 328 ili9341 faster than rpipico 2040 mmbasic same display? mega328 uno - https://www.youtube.com/watch?v=9pys3Y8_bns rpipic-2040-nnbasic - https://www.youtube.com/watch?v=_SwoluBfOAI There's I don't want to talk about it vibe. Any none positive comments and you're not welcome.. or worst :( user opinions don't matter. some guys on this forum are kind and help and I sensed some "been there" empathy. others have, search mmbasic, reputation for not being nice.. it don't say that.. worse. |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
I tried drawing boxes blue and white and erasing and it runs fast https://www.youtube.com/watch?v=Ybfl9P6H34A |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
Welcome to the joys of the difference in speed between compiled and interpreted languages. :-) Consider the following code: autosave OPTION BASE 0 ' 0 based arrays OPTION DEFAULT INTEGER cls timer = 0 for i = 1 to 100 for x = 0 to 15 for y = 0 to 15 pixel 100+x,100+y,rgb(green) next y next x next i print timer " pixels" cls timer = 0 for i = 1 to 1000 box 100,100,16,16,1,rgb(green),rgb(green) next i print timer " boxes" The first section draws a 16 pixel square region pixel by pixel. The second draws the same filled region using the BOX command. Notice the difference in number of times the loop is executed! This code lets you compare execution speed of bits of program - very helpful when speed matters. The speed difference suggests that BLITting the sprites could be _much_ faster than drawing them pixel by pixel. Visit Vegipete's *Mite Library for cool programs. |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
Using pixel to draw udgs is too slow. the way seems blit and buffers BUT WHY, if a 328p can do moving udgs then why not mmbasic but interpreting the pixel command for a matrix 16x16 ie 256 integers is slow. I think Blit is a compiled command that just needs parameters, dunno but think it's the way to go. not sure if data can be read to blit buffers. all new and interesting. I'm just using mmedit to code and like it... well is there a better alternative that works and seems normal for a win user... not mac or linux. you can be thick and still use windows... probably why I use it. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
Here are 11 aliens and one cannon, using BLIT. Requires the "glyphs.bmp" from a few posts previous. Should fit on a 320 pixel wide by 240 pixel high screen. (Mine is 480x320) They are quite speedy if you use OPTION CPUSPEED 252000. autosave ' Requires "glyphs.bmp" to be saved on SD card in active directory OPTION BASE 0 ' 0 based arrays OPTION DEFAULT INTEGER randomize dim ax(10),ay(10),adx!(10),ady!(10) cls blit load 1,"glyphs.bmp", 0,0,16,16 ' alien 1 blit load 2,"glyphs.bmp",16,0,16,16 ' alien 2 blit load 3,"glyphs.bmp",32,0,12,10 ' cannon blit load 4,"glyphs.bmp",44,0, 2, 8 ' missile cx = 100 : cy = 200 : blit write 3,cx,cy cdx = 1 ' cannon motion aa = 1 for i = 0 to 10 ' alien motion ax(i) = rnd * 240 + 40 adx!(i) = rnd * 3 - 1 : adx!(i) = adx!(i) - (adx!(i) < .5) ay(i) = rnd * 120 + 10 ady!(i) = rnd * 3 - 1 : ady!(i) = ady!(i) - (ady!(i) < .5) blit write aa,ax(i),ay(i) next i settick 500,animate,1 do box cx,cy,16,16,0,0,0 ' erase cannon at old position cx = cx + cdx ' move cannon blit write 3,cx,cy ' draw cannon at new location if cx > 200 or cx < 50 then cdx = -cdx ' change direction for i = 0 to 10 box ax(i),ay(i),16,16,0,0,0 ' erase alien at old position ax(i) = ax(i) + adx!(i) : ay(i) = ay(i) + ady!(i) ' move alien blit write aa,ax(i),ay(i) ' draw alien at new location if ax(i) > 300 or ax(i) < 10 then adx!(i) = -adx!(i) if ay(i) > 180 or ay(i) < 10 then ady!(i) = -ady!(i) next i pause 1 ' wait a bit loop ' change alien animation frame sub animate aa = 1 + (aa=1) ' toggle alien animation frame end sub end Visit Vegipete's *Mite Library for cool programs. |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
@vegipete- your post slipped in. The blit command and it's buffers seem the way to go. The syntax for the sdcard on the ili9341 is new but the card can be read. for a beginner think draw sprite and blit it to buffer then next sprite. I've not tried this yet but looks "easy". this whole exercise was I guess adapting a basic I used to mmbasic. it was spoilt by a simple selection error in mmedit but my last basic has had an upgrade to ms studio but not much to learn.. dark theme. I still don't get why my sprite demo runs much slower than gcbasic 328 16MHz??? using blit will be faster but why? it's extra effort but if the only way needs more emphasis imho. |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
Thanks @vegipete for the code example, nice one sir. |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
@vegipete settick 500,animate,1 sub animate aa = 1 + (aa=1) ' toggle alien animation frame end sub This is alien basic. I can do if a=1 then a=0:else if a=0 then a=1. or a=!a ie a=not a or in mmbasic a=inverse a. basic is not universal in syntax :( at my age I open the fridge and grab a cold beer and think why didn't I get another hobby like ??? all hobbies you got to learn stuff. one thing I learnt is other folks code is not like mine. is mine sh*t or is other peoples??? :) |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
@vegipete - you seen to have got the blit command sorted. I'll try it and will probably have errors but maybe not.. optimism.. I'll pick your brains if I get problems ... if that's ok with you. I don't want to be a forum pest. sometimes though I hit a wall and get cheesed off. |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
@vegipete - you seen to have got the blit command sorted. I'll try it and will probably have errors but maybe not.. optimism.. I'll pick your brains if I get problems ... if that's ok with you. I don't want to be a forum pest. sometimes though I hit a wall and get cheesed off. I just looked at your code again and it seems strange ie weird ie different to what I'm used to as basic for ucontrollers goes. There's syntax and there's style. any road, it's nice example blit code, ta sir. the copy image to sd card is too new but maybe I'm not daft as I think. lots to try, very interesting. |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1129 |
I agree, "aa = 1 + (aa=1)" looks exceedingly bizarre until it sinks in. I was using this sort of structure on my apple][ 40 years ago. (aa=1) evaluates to 1 if true, or 0 if false. The overall effect is that aa alternates between the values 1 and 2. Visit Vegipete's *Mite Library for cool programs. |
||||
toml_12953 Guru ![]() Joined: 13/02/2015 Location: United StatesPosts: 424 |
It's not very portable, though. Many BASICs treat a true statement as -1 instead of 1. It's best to either avoid such constructs or document them thoroughly. |
||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1638 |
' change alien animation frame sub animate aa = 1 + abs(aa=1) ' toggle alien animation frame end sub ??? Bill Keep safe. Live long and prosper. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
First attempt gave an error RUN [4] Randomize Error : Number out of bounds changed it to randomize epoch(now) Runs well on a 320 x 240 ILI9341 A more portable sub (Provided aa starts with either 1 or 2, definitely not zero!) sub animate aa = 2/aa ' toggle between 1 and 2 end sub I haven't compared speeds Jim VK7JH MMedit |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7830 |
The simplest toggle I know of: aa = NOT aa Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
But that doesn't give the required 1 and 2 values It is slightly faster than integer divide: sub animate aa = 2\aa ' toggle alien animation frame end sub Integer divide is a lot faster than normal divide. Jim VK7JH MMedit |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7830 |
Good point. I should have read the thread more closely. lol Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella![]() Guru ![]() Joined: 25/06/2022 Location: United KingdomPosts: 2527 |
aa = NOT aa is more common to toggle between 0 and 1 or aa = (NOT aa)+1 for 1 and 2 PIN(GP15) = not PIN(GP15) should toggle a pin on to off or off to on. put this or similar in the main loop and scope gp15 to see the frequency of the loop. the manual says NOT INV invert the logical value on the right (e.g. NOT a=b is a<>b) or bitwise inversion of the value on the right (e.g. a = INV b) I think that's not a clear explanation. |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |