COMAL-SPRITE-LOCATION-SHAPE-AND-POSIBILITIES -------------------------------------------------------------------------------------------------- TOOL: COMAL-80-C64 {Version 2.01} Language: COMAL - Structured BASIC Extra: - Author: Misel Zivanovic Note: (C) 11th March 2026 - www.lived.ch, mzretro.ch --------------------------------------------------------------------------------------------------- ******** * NOTE * ********************************************************************* * .d64 floppy disk is containing listings below! * * you can load it with load"*" and then type RUN or run it directly * * with the run"*" command. * * * * In both cases don't forget to hit the ENTER key * ********************************************************************* This {LISTING 1} is the way to normally define a sprite in COMAL-80 which are then visible only on the high resolution graphics screen! There is a room for 32 sprites {0-31}! Now imagine doing all of them like this! 1 sprite definition {lines 0100 to 0300} is wasting 341 bytes! That is 10912 bytes or roughly 10KB or 1/3 of the available memory for all 32 sprites! Can be OK depending on the project! But is it necessary? Not really! What can you do? You can save/load/link the sprite definition as a string There are following commands available for that: saveshape(),) loadshape(),) linkshape() That means, the definitions don't need to be part of the program! Just load them! But wait, 32!!! Yes, you would need to load each one of them individually... What can you do? You know already the most important thing! And that is the location, $d000, dec 53248. Now all you need to do is bring the sprite data to that location in one go. That also means how you can store there 32 sprites and use them on the text screen too and not just the graphics screen. All you need to do is copy a sprite or sprites you need to a location where they are accessible with the BASIC pointers 2040 - 2047 {sprites 0 to 7} What are available options, how can this be done? 1. Using DATA lines and make a routine which will load the sprites, export to $d000 and then load and run the main program! That would save you 10KB memory! 2. Do the same with loading SHAPES! It will take a while, but will also save you 10KB BASIC RAM! 3. Using COMAL-80-SUPERCHIP-II Version which is offering BLOAD and BSAVE commands! 4. Write your own routine to save sprites and load them in one go! 5. 32 SPRITES are 2KB memory! You could do some magic like load sprite data as a high resolution picture, then transfer the data to $d000 and later use the high resolution screen and text screen for your project like nothing ever happend! OK, plenty of options, however... - WE WILL GET BUSY JUST WITH THE OPTION ONE FOR STARTERS - CHECK FURTHER BELOW THE LISTINGS 2A & 2B --------------------------------------------------------------------------------------------------- LISTING 1 : SPRITE SHAPE DEFINITION, DEFAULT WAY The classic way to make sprite shapes in COMAL-80! In fact, it isn't so bad at all and it can also be used to create and transfer 32 sprites into the memory and afterwards just load the main program which will use those sprites. --------------------------------------------------------------------------------------------------- 0100 DATA %11111111,%11111111,%11111111 0110 DATA %10000000,%00000000,%00000001 0120 DATA %10000000,%00000000,%00000001 0130 DATA %10000000,%00000000,%00000001 0140 DATA %10000000,%00000000,%00000001 0150 DATA %10000000,%00000000,%00000001 0160 DATA %10000000,%00000000,%00000001 0170 DATA %10000000,%00000000,%00000001 0180 DATA %10000000,%00000000,%00000001 0190 DATA %10000000,%00000000,%00000001 0200 DATA %10000000,%00000000,%00000001 0210 DATA %10000000,%00000000,%00000001 0220 DATA %10000000,%00000000,%00000001 0230 DATA %10000000,%00000000,%00000001 0240 DATA %10000000,%00000000,%00000001 0250 DATA %10000000,%00000000,%00000001 0260 DATA %10000000,%00000000,%00000001 0270 DATA %10000000,%00000000,%00000001 0280 DATA %10000000,%00000000,%00000001 0290 DATA %10000000,%00000000,%00000001 0300 DATA %11111111,%11111111,%11111111 0310 0320 USE graphics 0330 graphicscreen(0) 0340 USE sprites 0350 DIM drawing$ OF 64 0360 FOR i:=1 TO 63 DO 0370 READ byte 0380 drawing$:+CHR$(byte) 0390 ENDFOR i 0400 color:=1 0410 drawingno:=1 0420 spriteno:=1 0430 define(drawingno,drawing$+""0"") 0440 identify(spriteno,drawingno) 0450 spritecolor(spriteno,color) 0460 spritepos(spriteno,50,100) 0470 showsprite(spriteno) 0480 0490 PAGE 0500 plottext(0,192,"press any key!") 0510 WHILE KEY$=CHR$(0) DO NULL 0520 0530 movesprite(spriteno,250,150,200,0) 0540 0550 n$:="press any key to quit!" 0560 plottext(0,192,n$) 0570 WHILE KEY$=CHR$(0) DO NULL --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- OPTION 1 - HOW TO DO IT HOW CAN WE LOAD SPRITES and load the MAIN program which will make use of it! 1. Using DATA lines and make a routine which will load the sprite data, export to $d000 and then load and run the main program! That would save you 10KB memory because you don't need that routine in memory once the sprites are loaded! We won't be doing all 32 sprites here, just one, but the process is the same even for 1000 sprites! --------------------------------------------------------------------------------------------------- LISTING 2A: LOAD SPRITE{S}, EXECUTE AND THEN LOAD OUR MAIN PROGRAM TO SAVE RAM SPACE IMPORTANT: Even if we are generating sprite definition for the graphic screen and pointers used by COMAL-80, {Sprite Pointer is called IDENTIFY (sprite#[0-7], sprite-shape#[0-31]) You can always access those shapes and use also on the text screen. All you need to do is copy the sprite data from there to available lower memory area where the sprites can be accessed with 2040-2047 pointers. 1st free area is @ location 13 {13x64} = dec 832, hex $340 there are actually 192 bytes free! = 3 {different} sprites poke 2040,13 poke 2041,14 poke 2042,15 In our example we will use just one sprite definition and point that shape to all other sprites. Which resulted in 8 balls in different color! It's all done in the 2 listings below! --------------------------------------------------------------------------------------------------- 0010 // by mzretro.ch - lived.ch 0020 // misel zivanovic 0030 // load sprites and start 0040 // of the main program 0050 // 0060 FOR a:=832 TO 832+63 DO POKE a,0 0070 USE system 0080 USE sprites 0090 USE graphics 0100 textbackground(0); textborder(0) 0110 textcolor(15) 0120 setpage(0) 0130 RESTORE mysprites 0140 FOR a:=0 TO 63 DO 0150 READ spritedata 0160 POKE 53248+a,spritedata 0170 ENDFOR a 0180 setpage($81) 0190 POKE 53269,255 // all sprites on 0200 POKE 53248,255 // x 0210 POKE 53249,100 // y 0220 POKE 2040,13 // pointer to 832 0230 // 13x64 bytes 0240 // info 0250 PAGE 0260 PRINT "** text screen **" 0270 PRINT "*********************" 0280 PRINT "* no sprite visible *" 0290 PRINT "* because we copied *" 0300 PRINT "* the definition to *" 0310 PRINT "* graphics sprite *" 0320 PRINT "* area! *" 0330 PRINT "*********************" 0340 PRINT 0350 PRINT "press any key" 0360 WHILE KEY$=CHR$(0) DO NULL 0370 setpage(1) 0380 0390 graphicscreen(0) 0400 identify(0,0) 0410 spritepos(0,255,100) 0420 showsprite(0) 0430 plottext(0,192," gfx screen ") 0440 plottext(0,182,"****************") 0450 plottext(0,172,"* our sprite 0 *") 0460 plottext(0,162,"* definition *") 0470 plottext(0,152,"* from $d000 - *") 0480 plottext(0,142,"* $d040 *") 0490 plottext(0,132,"****************") 0500 plottext(0,112,"press any key") 0510 WHILE KEY$=CHR$(0) DO NULL 0520 PAGE 0530 textscreen 0540 PRINT "now we will copy graphics" 0550 PRINT "sprite to have the access" 0560 PRINT "to it on the text screen!" 0570 PRINT 0580 PRINT "-------------------------" 0590 PRINT "copy process is slightly" 0600 PRINT "delayed on purpose!" 0610 PRINT 0620 PRINT "-------------------------" 0630 PRINT "press any key" 0640 WHILE KEY$=CHR$(0) DO NULL 0650 setpage($81) 0660 POKE 2040,13 0670 POKE 53269,1 0680 setpage(0) 0690 FOR a:=0 TO 63 DO 0700 FOR b:=0 TO 50 DO // delay 0710 ENDFOR b 0720 spr:=PEEK(53248+a) 0730 POKE 832+a,spr 0740 ENDFOR a 0750 PRINT AT 10,0: " " 0760 0770 setpage($81) 0780 FOR a:=0 TO 3 DO PRINT 0790 h$:=CHR$(19); e$:=CHR$(34) 0800 m$:="press enter to continue" 0810 r$:="run"+e$+"main"+e$ 0820 0830 textcolor(7) // show what to do 0840 PRINT AT 16,0: m$ 0850 textcolor(0) // mask run command 0860 PRINT AT 17,0: r$ 0870 PRINT AT 13,0: 0880 END 0890 0900 // sprite data 0910 mysprites: 0920 DATA 1,255,128,6,255,224,31,255 0930 DATA 248,62,255,252,52,95,252 0940 DATA 126,255,254,127,255,254 0950 DATA 126,255,254,255,255,255 0960 DATA 255,255,255,255,255,255 0970 DATA 255,255,255,255,255,255 0980 DATA 255,255,255,127,255,254 0990 DATA 127,255,254,63,255,252 1000 DATA 63,255,252,31,255,248,7 1010 DATA 255,224,1,255,128,0 --------------------------------------------------------------------------------------------------- LISTING 2B: MAIN PROGRAM WHICH NEEDS LISTING 2A TO WORK PROPERLY --------------------------------------------------------------------------------------------------- 0010 // by mzretro.ch - lived.ch 0020 // misel zivanovic 0030 // main program 0035 // 0040 USE sprites 0050 USE graphics 0060 textbackground(0); textborder(0) 0070 textcolor(15) 0080 // 0085 POKE 53269,255 0090 FOR a:=0 TO 7 DO 0095 POKE 2040+a,13 0100 spritecolor(a,a+1) 0110 spritesize(a,0,0) // all small 0120 spritepos(a,295,21+(a*24)) 0130 ENDFOR a 0140 // 0143 PAGE // clear screen 0145 PRINT AT 0,0: "balls of steel..."; 0146 PRINT AT 0,20: "ready to roll!" 0150 FOR a:=0 TO 39 DO 0151 POKE 1064+a,99 0152 POKE 55296+40+a,10 0153 ENDFOR a