Frozone212 Posted July 5, 2021 Share Posted July 5, 2021 (edited) I typed in the entirety of Hidden Maze for the Commodore PET and i get an error in 810 Out of Memory Any ideas? maze chase.d64 Configuration: 2001 8n 4k IO: 2048 bytes 40 column etc Winvice 3.5 win 10 Edited July 5, 2021 by Frozone212 added configuration Quote Link to comment Share on other sites More sharing options...
carlsson Posted July 5, 2021 Share Posted July 5, 2021 You have a lot of recursive GOSUB without RETURN. The stack can only hold a smaller amount of nested subroutine calls. I would suggest a RETURN on line 670. I don't know what 730 is supposed to do but as it stands it makes up for an infinite loop until you ran out of stack. Also I believe 4K RAM is too little for your program, since you're allocating an array M(630) which itself would take up 3162 bytes out of the 3069 available. If you change it to M%(630), it would "only" use 1269 bytes but be a little bit slower plus that you can only store numbers -32768 to +32767. Now it seems that you're only using it for numbers 0-255 anyway, so you could set up a buffer in RAM that is as large as you need and change pointers so you don't overwrite it with variables. That means assignments to M(X) would be replaced by POKE M+X and fetching values would be PEEK(M+X). With the current program, even an 8K PET would barely fit it but 16K or more would probably be fine, once you have solved the GOSUB issues that are independent on how much RAM you have. 10 goto 400 100 rem 110 gosub 730:printct:forj=0to3:d=a:c=s2120 fori=1to7:pokec,m(d) 130 pokec-e(j),m(d-d(j)):pokec+e(j),m(d+d(j)) 140 ifm(d)=wlthen160 150 d=d+a(j)/2:c=c+e(j+1):nexti 160 nextj:pokes2,240:m(a)=240:return 200 rem 210 fori=1toh:forj=2toh+1:pokes2,j 220 m((i*(h+2))+j)=wl:nextj:nexti 310 m(a)=4 320 j=int(rnd(r)*4):z=j:pokes2,j 330 b=a+a(j):ifm(b)=wlthenm(b)=j:m(a+a(j)/2)=hl:a=b:goto320 340 j=(j+1)*-(j<3):ifj<>zthen330 350 j=m(a):m(a)=hl:ifj<4thena=a-a(j):goto320 360 t1=(3*h)+5:t2=int(rnd(r)*2):ifint(t2/2)*2=t2thent1=(2*h)+6 362 q1=-1:q2=-(h+1):q3=h+3 364 ift1=(2*h)+6thenq1=-q1:q2=-q2:q3=-q3 370 m(z)=69:m(z+q2)=wl:m(z-q1)=wl:m(z+q3)=wl 380 fori=1toh 382 m(3*(h+2)+4+int(rnd(r)*(h-5))*(h+2)+int(rnd(r)*(h-5)))=hl 384 nexti:return 400 rem 410 gosub 600:gosub 730:gosub 200:gosub 100 415 geta$:ifa$=""thenct=ct+1:goto 415 420 j=-( (a$="w")+2(a$="s")+3*(a$="d") ) 425 ifa$="?" then 500 435 a2=a+a(j)/2 440 ifm(a2)=69 then800 445 ifm(a2)<>hlthen415 450 m(a)=hl:a=a2:gosub100:goto415 510 gosub 730:f=0:fori=1toh:forj=2toh+1:l=(i*(h+2))+j 520 pokes+j+f,m(l):nextj 600 rem 605 vl=40:h=23:ff=vl 610 a(0)=2:a(1)=-(h+2):a(2)=-2:a(3)=(h+2)*2 620 d(0)=h+2:d(1)=1:d(2)=-(h+2):d(3)=-1 630 e(0)=vl:e(1)=1:e(2)=-vl:e(3)=-1:e(4)=vl 640 wl=160:hl=32:s2=32768+vl*12+int(vl/2):ct=0 650 s=s2-vl*((h+1)/2)+ff-(h+3)/2 660 a=(h+2)*(h+1)/2+(h+3)/2:dimm(630) 730 rem 810 gosub 730:print "your score";ct:end 900 rem 920 print "hidden maze":print 930 print "get out as quickly as you can using control keys" 940 print "w is up, s is down and d is right" 950 print "press ? to show full maze" 960 print "this costs points" 980 r=0:print "{rvon}{wht}{del}{CTRL-U}{rvon}{swlc}" 990 return 1 Quote Link to comment Share on other sites More sharing options...
bluejay Posted July 5, 2021 Share Posted July 5, 2021 Tl;dr: if you’re out of memory, get yourself more. Why would you use a 4K system in emulation when you can have as much as you want? Quote Link to comment Share on other sites More sharing options...
carlsson Posted July 5, 2021 Share Posted July 5, 2021 If one is developing with a certain machine in mind to run the software on later, it probably is a good idea to emulate the same spec during development. But as I told, this is a two-fold problem. 10 a=0 15 a=a+1:gosub15 It crashes out when a=24 so that is the maximum number of nested levels if you have no other values on the stack. In the real world, the number probably is a bit smaller. Normally that isn't a problem if you properly return from every subroutine but if you apply spaghetti code and GOTO yourself back to the main program, eventually this will be a problem. 2 Quote Link to comment Share on other sites More sharing options...
Frozone212 Posted July 5, 2021 Author Share Posted July 5, 2021 i'll try to find a disk version. Typing it is a nightmare Quote Link to comment Share on other sites More sharing options...
carlsson Posted July 5, 2021 Share Posted July 5, 2021 Aha. I didn't trigger on "typed in". I thought it was an own creation. Well, the listing is here: https://archive.org/details/1982-12-compute-magazine/page/n153/mode/2up It explains line 730 where you changed a PRINT:RETURN into a REM statement. I didn't check which other places that differ, but in general probably most of it is fine except the article doesn't say how little RAM you can expect the program to run on. I still think 8K would be a shoehorn but you can try. Quote Link to comment Share on other sites More sharing options...
Frozone212 Posted July 7, 2021 Author Share Posted July 7, 2021 (edited) it says bad subscript in 330. any ideas? Edited July 7, 2021 by Frozone212 caught another one Quote Link to comment Share on other sites More sharing options...
bluejay Posted July 7, 2021 Share Posted July 7, 2021 3 hours ago, Frozone212 said: it says bad subscript in 330. any ideas? It says “BAD SUBSCRIPT The program was trying to reference an element of an array whose number is outside of the range specified in the DIM statement.” Perhaps a typo on where you defined whatever array it’s referring to? Quote Link to comment Share on other sites More sharing options...
carlsson Posted July 7, 2021 Share Posted July 7, 2021 Print the values of J and B when it happens so you can see whichever of those are out of range. Actually up until 5 minutes ago, I didn't know that Commodore BASIC accepts that you have both floating point variable A and the matrix A(N) at the same time. I knew that A and A% or A and A$ may coexist, but not that matrix names were separate too. I suppose that means you can have A$ and A$(N) at the same time too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.