Out of memory on this line

Basic and Machine Language

Moderator: Moderators

User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Out of memory on this line

Post by Mike »

Forbidden64 wrote:The spaces don't come out on the map in the forum text, sadly, so the map looks a little screwy.
You can put source into code-tags, i.e. 'code' and '/code' enclosed in angle brackets '[' and ']', with a result like this:

Code: Select all

1 A$="{BLK,WHT,RED,CYN,PUR,GRN,BLU,YEL}"
2 N=INT(RND(1)*8)+1
3 B$=MID$(A$,N,1)
4 PRINT B$"{SHIFT-U,SHIFT-Q,SHIFT-I,SHIFT-J,SHIFT-Q,SHIFT-K}";
5 GOTO 2
:)
Last edited by Mike on Wed May 11, 2016 1:27 pm, edited 1 time in total.
Forbidden64
Vic 20 Hobbyist
Posts: 146
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: Out of memory on this line

Post by Forbidden64 »

OH neat! good to know...Im new to posting in forums :D so I need all the pointers I can get,thanks!
Forbidden64
Vic 20 Hobbyist
Posts: 146
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: Out of memory on this line

Post by Forbidden64 »

I got the skeleton of the game engine working after finding many typos, bugs, embarrassing mistakes(like the screen offset being completely missing) :oops: . I wrote over the start of basic once and my program disappeared as a result. It is now somewhat working and you can get a sense of the speed it has. Also, wait until you see how much memory is left!!

Code: Select all

100 tt=1:sm=7680
110 dimex(20),ey(20),e
h(20),mp$(20)
130 mp$(1)="aaaaaaaaaa
aaaaaaaa"
140 mp$(2)="a@ aaaaaa
 e aaaaa"
150 mp$(3)="a  aaaaaad
aaaaaaaa"
160 mp$(4)="a  d    e
  aaaaaa"
170 mp$(5)="aaaa
  aaaaaa"
180 mp$(6)="aaaaaaaaaa
aaaaaaaa"
188 print"Ss"
190 fori=1to6:forii=1t
o18
180 mp$(6)="aaaaaaaaaa
aaaaaaaa"
188 print"Ss"
190 fori=1to6:forii=1t
o18
210 ifmid$(mp$(i),ii,1
)="e"thengosub2000
220 ifmid$(mp$(i),ii,1
)="@"thenx=i:y=ii
230 next
231 printmp$(i):next
240 g=peek(203)
249 ifg<>64thengosub25
00
250 ifjs=0thengoto500
210 ifmid$(mp$(i),ii,1
)="e"thengosub2000
220 ifmid$(mp$(i),ii,1
)="@"thenx=i:y=ii
230 next
231 printmp$(i):next
240 g=peek(203)
249 ifg<>64thengosub25
00
250 ifjs=0thengoto500
500 i=i+1:ifi>=tt+1the
ni=1:gosub1000
520 gosub1500:goto240
1000 pokesm+ex(i)*22+e
y(i),32:d=0
1020 ifx>ex(i)andmid$(
mp$(ex(i)+1),ey(i),1)<
>"a"thenex(i)=ex(i)+1:
d=1:return
1030 ify>ey(i)andmid$(
mp$(ex(i)),ey(i)+1,1)<
>"a"theney(i)=ey(i)+1:
d=2:return
1040 ify<ey(i)andmid$(
mp$(ex(i)),ey(i)-1,1)<
>"a"theney(i)=ey(i)-1:
d=3:return
1050 ifmid$(mp$(ex(i)-
1),ey(i),1)<>"a"thenex
(i)=ex(i)-1:d=4:return

1060 return
1500 ifd=0thenreturn
1050 ifmid$(mp$(ex(i)-
1),ey(i),1)<>"a"thenex
(i)=ex(i)-1:d=4:return

1060 return
1500 ifd=0thenreturn
1520 ifd=1thenpokesm+e
x(i)*22+ey(i)-22,32
1530 ifd=2thenpokesm+e
x(i)*22+ey(i)+1,32
1540 ifd=3thenpokesm+e
x(i)*22+ey(i)-1,32
1550 ifd=4thenpokesm+e
x(i)*22+ey(i)+22,32
1560 pokesm+ex(i)*22+e
y(i),6:return
2000 ex(tt)=i:ey(tt)=i
i:eh(tt)=int(rnd(1)*20
)+10:tt=tt+1:return
2500 rem **keyboard
2505 pokesm+x*22+y,32
2510 ifg=18thenifmid$(
mp$(x),y+1,1)<>"a"then
y=y+1
2520 ifg=17thenifmid$(
mp$(x),y-1,1)<>"a"then
y=y-1
2530 ifg=41thenifmid$(
mp$(x+1),y,1)<>"a"then
x=x+1
2540 ifg=9thenifmid$(m
p$(x-1),y,1)<>"a"thenx
=x-1
2545 pokesm+x*22+y,1
2550 return
?fre(0)
2431 bytes freeeeee! You can copy and paste this into vice and see that using the mid$ approach not only speeds things up, but also makes map editing very very easy ( you can literally draw it on the screen and then compile it into a string array for instance). It barely works and looks like just a bunch of letters dancing around, but its going really fast for commodore basic. I ditched my clever idea of using integers after finding out the hard way that basic v2 just cant use integral values for flow control :? . So variables are going to take up more space sadly, but there is plenty left. I think I will continue working on this since Ive had so much fun so far
wimoos
Vic 20 Afficionado
Posts: 345
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Out of memory on this line

Post by wimoos »

In lines 1020-1040 you can change the "AND" into "THEN IF". This will speed up slightly when the first condition is false.

WimBasic brings you INSTR, with which you can speed up lines 190-230 dramatically.

Regards,

Wim.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Out of memory on this line

Post by Mike »

Forbidden64,

you're obviously using the copy+paste facility of VICE to read the listing off the screen one page at a time. Not only removes this control characters (or better said, substitutes those with wrong results ... see the instance of "S" instead of {CLR} to clear the screen), the resulting column width of 22 characters makes the listing very hard to read. Neither is it possible to take that listing and paste it back into VICE directly - unless the lines are concatenated in a text editor first and then pasted from there, the BASIC editor in VICE will throw a lot of ?SYNTAX ERRORs on the partial lines without line numbers.

Please accustom yourself with the file transfer capabilities of VICE. With "Options > True Drive Emulation off" and "Settings > Peripheral settings ..." you can mount a PC directory as drive. Then, you can "print" out the listing with the following two command lines (each of them followed by pressing RETURN):

Code: Select all

OPEN2,8,2,"LISTING.TXT,S,W":CMD2:LIST

PRINT#2:CLOSE2
That will result in a file "listing.txt" in PETSCII in the chosen PC directory. That in turn can be processed to readable ASCII by the utility petcat.exe contained in the VICE folder, or similar tools. The control characters will be quoted in curly braces, with a result similar to my earlier posting.

Sorry I didn't see this earlier. I just read the first version of your post from May 11th, which only went so far as to the sentence "It is now somewhat working..." and only looked again into the thread, when wimoos had replied. :(

Likewise, you can save the program into the same PC directory (make sure to tick off "write *.P00 files" under Peripheral settings) simply with SAVE"NAME.PRG",8, compress it with ZIP, and add it as attachment to your posting. Unfortunately, the forum software doesn't allow for *.prg as extension for file attachments, for whatever reason.

Code: Select all

100 TT=1:SM=7680
110 DIMEX(20),EY(20),EH(20),MP$(20)
130 MP$(1)="AAAAAAAAAAAAAAAAAA"
140 MP$(2)="A@ AAAAAA E AAAAA"
150 MP$(3)="A  AAAAAADAAAAAAAA"
160 MP$(4)="A  D    E  AAAAAA"
170 MP$(5)="AAAA  AAAAAA"
180 MP$(6)="AAAAAAAAAAAAAAAAAA"
188 PRINT"{CLR}"
190 FORI=1TO6:FORII=1TO18
210 IFMID$(MP$(I),II,1)="E"THENGOSUB2000
220 IFMID$(MP$(I),II,1)="@"THENX=I:Y=II
230 NEXT
231 PRINTMP$(I):NEXT
240 G=PEEK(203)
249 IFG<>64THENGOSUB2500
250 IFJS=0THENGOTO500
500 I=I+1:IFI>=TT+1THENI=1:GOSUB1000
520 GOSUB1500:GOTO240
1000 POKESM+EX(I)*22+EY(I),32:D=0
1020 IFX>EX(I)ANDMID$(MP$(EX(I)+1),EY(I),1)<>"A"THENEX(I)=EX(I)+1:D=1:RETURN
1030 IFY>EY(I)ANDMID$(MP$(EX(I)),EY(I)+1,1)<>"A"THENEY(I)=EY(I)+1:D=2:RETURN
1040 IFY<EY(I)ANDMID$(MP$(EX(I)),EY(I)-1,1)<>"A"THENEY(I)=EY(I)-1:D=3:RETURN
1050 IFMID$(MP$(EX(I)-1),EY(I),1)<>"A"THENEX(I)=EX(I)-1:D=4:RETURN
1060 RETURN
1500 IFD=0THENRETURN
1520 IFD=1THENPOKESM+EX(I)*22+EY(I)-22,32
1530 IFD=2THENPOKESM+EX(I)*22+EY(I)+1,32
1540 IFD=3THENPOKESM+EX(I)*22+EY(I)-1,32
1550 IFD=4THENPOKESM+EX(I)*22+EY(I)+22,32
1560 POKESM+EX(I)*22+EY(I),6:RETURN
2000 EX(TT)=I:EY(TT)=II:EH(TT)=INT(RND(1)*20)+10:TT=TT+1:RETURN
2500 REM **KEYBOARD
2505 POKESM+X*22+Y,32
2510 IFG=18THENIFMID$(MP$(X),Y+1,1)<>"A"THENY=Y+1
2520 IFG=17THENIFMID$(MP$(X),Y-1,1)<>"A"THENY=Y-1
2530 IFG=41THENIFMID$(MP$(X+1),Y,1)<>"A"THENX=X+1
2540 IFG=9THENIFMID$(MP$(X-1),Y,1)<>"A"THENX=X-1
2545 POKESM+X*22+Y,1
2550 RETURN
Here's name.zip for download.
Forbidden64
Vic 20 Hobbyist
Posts: 146
Joined: Sun Feb 28, 2016 9:59 pm
Location: CA USA

Re: Out of memory on this line

Post by Forbidden64 »

Ya, sorry about the newb factor Mike :oops: :oops: on top of that my laptop broke so I couldn't even fix/finish it :(. Fixed now, and I started again yesterday where I left off and have made great progress! Its fast, somewhat smarter, and still very small. It wouldn't be too many mods to turn this into many games...for instance adding jumping and gravity for a side view instead of a top view. I did lose the easy scrolling map when I ditched using array strings, however:

Here is a summary of the new working version. Scans map for letter E and sets enemy ex, ey locations at those "E"s..up to 20 enemies. @ marks your start location x y which is also scanned in from the screen. This is that pause at the beginning. Allows for map editor still and the ability to store many maps on tape or disk so you don't waste ram. Also has no more map string as it was eating memory like popcorn(now uses screen memory) and maps can be loaded directly onto screen in my real implementation, although for demo purposes I left print statements inside for the map. Eventually took Mike's advice there. The map editor is half done. I also added some more AI stuff for when the enemy gets stuck at a wall to at least have some ability to move around it and try to find you. Enemies will also alter course if they spot you are in a direct path from them. I added character replacement data so you aren't just a letter running around. It is still quite small even with the map data built into the program instead of going directly from files to the screen. The more enemies you add, the slower it starts to go, naturally. With one enemy, it is next to impossible to get away once it has found you.

I did replace ANDs with THENIF wimoos, thanks for that! I'll burn wimbasic on a cart after I move though. Most of my stuff is in a giant pile in a garage size rental unit until then. Only a vic 20, commodore 64, and PDP11 with minimal peripherals are available to me at the moment. I only have a tape drive, and a 1541u2. Which in most cases is pretty darned acceptable, but no eprom burner and most of my documentation books etc. I actually have a specific purpose in mind for Wimbasic when I move though. I'm going to port my really cool inventory program over to Wimbasic from QB45 to a combined ROM expansion into a custom cartridge and use that instead of a high powered desktop computer I was using(which just had a 3.5" disk attached booting DOS 5.0, and that program. It used a huge amount of current for the overpowered cpu and tons of fans) total waste of electricity for the power I needed, and Vic 20 is also much cooler to use :D/instant boot and access. Ill likely just have a vic+Wimbasic & inventory cart, and tv in the center of my inventory racks.
Attachments
item.zip
new ge
(1.05 KiB) Downloaded 48 times
Post Reply