snippets using sprites on cga - help needed

DOS specific questions.
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

snippets using sprites on cga - help needed

Postby nitrofurano » May 29, 2012 19:56

Do someone can share some small snippet (20 lines max.) can show some sprites (using get and put) around the screen, on CGA display, which can run on Dosbox? (please, CGA only - for now, my only interest is using FreeBasic from FreeDOS, not on Linux or ReactOS - and doing code i can run in really old x86 hardware, like those 8088-based ones) - i'm strugling a lot on start some code on that! :) - thanks a lot! :)
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

Re: snippets using sprites on cga - help needed

Postby nitrofurano » May 29, 2012 20:02

i tried this one, using vga mode instead - only getting errors

Code: Select all

dim as integer i,sprite
screen 13
dim sprite((32 * 32 * 2) + 4)
line (0,0)-(31,31), 1, bf
line (0,0)-(31,31), 2, b
line (8,8)-(23,23), 4, bf
line (1,1)-(30,30), 8
line (30,1)-(1,30),16
get (0,0)-(31,31), sprite
cls
for i = 0 to 63
line (0,i)-(319,i), rgb(i * 4, i * 4, i * 4)
next i
put (19, 16), sprite, pset
put (69, 16), sprite, preset
put (119, 16), sprite, and
put (169, 16), sprite, or
put (219, 16), sprite, xor
put (269, 16), sprite, trans
sleep

any help on ajust this code into a working one, and using cga instead (4 colours, 320x200), is very welcome! thanks! :)
marcov
Posts: 2486
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: snippets using sprites on cga - help needed

Postby marcov » May 29, 2012 20:35

nitrofurano wrote: and doing code i can run in really old x86 hardware, like those 8088-based ones)


That will be interesting, since FB is afaik 386+
fxm
Posts: 7737
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: snippets using sprites on cga - help needed

Postby fxm » May 29, 2012 20:45

Starting points:

Code: Select all

dim as integer i
screen 13
dim sprite as any ptr = imagecreate(32, 32)
line (0,0)-(31,31), 1, bf
line (0,0)-(31,31), 2, b
line (8,8)-(23,23), 4, bf
line (1,1)-(30,30), 8
line (30,1)-(1,30),16
get (0,0)-(31,31), sprite
cls
for i = 0 to 63
line (0,i)-(319,i), rgb(i * 4, i * 4, i * 4)
next i
put (19, 16), sprite, pset
put (69, 16), sprite, preset
put (119, 16), sprite, and
put (169, 16), sprite, or
put (219, 16), sprite, xor
put (269, 16), sprite, trans
sleep
imagedestroy sprite

Code: Select all

dim as integer i
screen 1
dim sprite as any ptr = imagecreate(32, 32)
line (0,0)-(31,31), 1, bf
line (1,1)-(30,30), 2, b
line (8,8)-(23,23), 3, bf
line (1,1)-(30,30), 1
line (30,1)-(1,30), 2
get (0,0)-(31,31), sprite
cls
for i = 0 to 63
line (0,i)-(319,i), i mod 4
next i
put (19, 16), sprite, pset
put (69, 16), sprite, preset
put (119, 16), sprite, and
put (169, 16), sprite, or
put (219, 16), sprite, xor
put (269, 16), sprite, trans
sleep
imagedestroy sprite
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

Re: snippets using sprites on cga - help needed

Postby nitrofurano » May 29, 2012 21:28

marcov wrote:
nitrofurano wrote: and doing code i can run in really old x86 hardware, like those 8088-based ones)

That will be interesting, since FB is afaik 386+


would be great if there is some kind of code forcing to 8088! :)
would be really awesome! :)
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

Re: snippets using sprites on cga - help needed

Postby nitrofurano » May 29, 2012 21:35

fxm wrote:Starting points:

Code: Select all

dim as integer i
screen 13
dim sprite as any ptr = imagecreate(32, 32)
line (0,0)-(31,31), 1, bf
line (0,0)-(31,31), 2, b
line (8,8)-(23,23), 4, bf
line (1,1)-(30,30), 8
line (30,1)-(1,30),16
get (0,0)-(31,31), sprite
cls
for i = 0 to 63
line (0,i)-(319,i), rgb(i * 4, i * 4, i * 4)
next i
put (19, 16), sprite, pset
put (69, 16), sprite, preset
put (119, 16), sprite, and
put (169, 16), sprite, or
put (219, 16), sprite, xor
put (269, 16), sprite, trans
sleep
imagedestroy sprite

Code: Select all

dim as integer i
screen 1
dim sprite as any ptr = imagecreate(32, 32)
line (0,0)-(31,31), 1, bf
line (1,1)-(30,30), 2, b
line (8,8)-(23,23), 3, bf
line (1,1)-(30,30), 1
line (30,1)-(1,30), 2
get (0,0)-(31,31), sprite
cls
for i = 0 to 63
line (0,i)-(319,i), i mod 4
next i
put (19, 16), sprite, pset
put (69, 16), sprite, preset
put (119, 16), sprite, and
put (169, 16), sprite, or
put (219, 16), sprite, xor
put (269, 16), sprite, trans
sleep
imagedestroy sprite


brilliant, worked perfectly! thanks a lot! :)
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

Re: snippets using sprites on cga - help needed

Postby nitrofurano » Jun 02, 2012 18:23

a question: instead of using "dim sprite as any ptr = imagecreate(32, 32)" for having a sprite just on one variable, can i have sprites stored into arrays instead of just one variable, like using "put (19, 16), sprite(35), pset" instead of "put (19, 16), sprite, pset" ?
fxm
Posts: 7737
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: snippets using sprites on cga - help needed

Postby fxm » Jun 02, 2012 19:12

nitrofurano wrote:a question: instead of using "dim sprite as any ptr = imagecreate(32, 32)" for having a sprite just on one variable, can i have sprites stored into arrays instead of just one variable, like using "put (19, 16), sprite(35), pset" instead of "put (19, 16), sprite, pset" ?

Yes:
dim sprite(100) as any ptr = imagecreate(32, 32)
..........
get (0,0)-(31,31), sprite(35)
..........
put (19, 16), sprite(35), pset
TJF
Posts: 3329
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: snippets using sprites on cga - help needed

Postby TJF » Jun 02, 2012 19:39

@fxm:

Be carreful!

Code: Select all

dim sprite(100) as any ptr = imagecreate(32, 32)

doesn't compile:
....bas(4) error 60: Expected '{', found 'imagecreate' in 'dim sprite(100) as any ptr = imagecreate(32, 32)'

And when you add the {} you'll get only one image. You've to initialize each element in sprite(0 TO 100) and destroy each element when done.

Code: Select all

VAR nsprite = 100
DIM AS ANY PTR sprite(nsprite)
FOR i AS INTEGER = 0 TO nsprite
  sprite(i) = IMAGECREATE(32, 32)
NEXT

GET (0,0)-(31,31), sprite(35)
PUT (19, 16), sprite(35), PSET

FOR i AS INTEGER = 0 TO nsprite
  IMAGEDESTROY (sprite(i))
NEXT
fxm
Posts: 7737
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: snippets using sprites on cga - help needed

Postby fxm » Jun 02, 2012 19:53

TJF wrote:@fxm:

Be carreful!

Yes, thank you TJF.
On this one, I was a little too fast and offhand!
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

Re: snippets using sprites on cga - help needed

Postby nitrofurano » Jun 02, 2012 23:16

thanks! :)
angros47
Posts: 1367
Joined: Jun 21, 2005 19:04

Re: snippets using sprites on cga - help needed

Postby angros47 » Jun 06, 2012 20:30

nitrofurano wrote:would be great if there is some kind of code forcing to 8088! :)
would be really awesome! :)


No way: FreeBasic emits 32 bit assembly, so a 32 bit processor is required (and an 8088 is a 16 bit processor)
nitrofurano
Posts: 57
Joined: Dec 08, 2010 14:55
Location: Portugal
Contact:

Re: snippets using sprites on cga - help needed

Postby nitrofurano » Jun 06, 2012 22:08

angros47 wrote:
nitrofurano wrote:would be great if there is some kind of code forcing to 8088! :)
would be really awesome! :)


No way: FreeBasic emits 32 bit assembly, so a 32 bit processor is required (and an 8088 is a 16 bit processor)


but i think there is a catch... - that's why i pointed this situation - someone (or some kind of converter) could be skilled to adapt this temporary 32bit .asm file during compiling, and convert it to a 16bit compatible - i think the main difference between 16bit and 32bit opcodes are related to the ram memory addressing, and the most usual ones (related to usual registers and simple calculations) are just exactly the same? - the fact is i think you really don't need 32bit for the most code you may use CGA/EGA stuff and some "light" code
angros47
Posts: 1367
Joined: Jun 21, 2005 19:04

Re: snippets using sprites on cga - help needed

Postby angros47 » Jun 07, 2012 15:02

Converting 32 bit asm to 16 bit is not an easy task, since many features are not available in 16 bit; otherwise, almost ever 32 bit program would have a port to 16 bit... and there would be no reason to upgrade processor.

If you want an open source basic compiler (like freebasic) that emits 16 bit assembly, you can try BASM:

http://www.bcxgurus.com/basm286.zip

Or you can have a look at this: http://exmortis.narod.ru/src_compilers_eng.html (note, anyway, that the creator of this site abandoned it when he found freebasic: http://www.freebasic.net/forum/viewtopic.php?p=125018#p125018)

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 1 guest