pouët.net

COM demos; where to put extra data?

category: general [glöplog]
 
Friends, I'm a newbie with a question. When writing 256/512/1024/... demos for DOS, where would you usually put extra data you generate @run-time, like textures? I have seen people using 0h1000+cs as data segment, I have seen other stuff... but I can't tell which is really the "most proper" way of handling this, so can you give me some ideas? Generally my line of thinking is, everything after the code, but before 0ha000 is safe to store data at. Before the PSP probably as well, but I suppose you don't know the initial value of CS so it's risky.
you can generally use anything at CS:(end_of_your_program...0xFFFF) for temp storage, same here for segments in [CS..0x8000] range (0x9000 is not always safe because most DOS systems place Extended BIOS Data Area at top 1k of conventional memory and there is a chance to crash system by overwriting EBDA)

presonally i prefer 0x8000 for temporary framebuffer and CS for variables ;)

p.s. oh, and there is another trick to shave 1 byte per var reference: you can use [bx\bp\si\di+imm8] with reg value biased to middle of addresable 256byte range, i.e:

Code: mov bp, 0x200 ; middle of [0x180..0x27F] range mov ax, [bp-0x200+some_label] ; shorter than [some_label] if some_label in [0x180..0x27F] ; it does work with BP because SS==DS in .COMs at startup .... ; assembly address in [0x180..0x27F] range some_label: ; your variables here
added on the 2018-09-04 17:22:37 by wbc\\bz7 wbc\\bz7
like wbs\\bz7 said, 08000h as segment is fine, also 07000h which should give you enough space. 09000h works at runtime of your program but it might crash the machine after exit.
Folks, I cannot thank you enough for your answers. Could you just enlighten me technically as to why CS will always be < 0x8000?
in typical DOS environment you have at least 450-500kb of conventional memory; so your intro will load at max ~190th kbyte from bottom (so CS will less than 0x3000 in almost every case)
added on the 2018-09-04 20:13:37 by wbc\\bz7 wbc\\bz7
(what they said, and also:)

It won't ^^ It's just a strong assumption that you still have 64*2 = 128K of memory left when you start your com program, which is very very likely in competitions where you're entry is run on a fresh FreeDos (real system) or DosBox.

whether you do

"mov dh,0x80" + "mov es,dx"
or
"inc dh" + "mov es,dx"

does not matter sizewise (4 bytes), the old approach is as good as the new.

"push 0x8000" + "pop es"

is also 4 bytes, and you even have the free choice.

Things get nasty when you try to save on this. What about

"pop ax" + "pop es" ?

Two bytes, and you use "0x20CD" as segment. Might crash, might not ;)

Also, if you're really into saving bytes, you can just start you're program with constants and index them with [SI], as that points to the start of the program first so the first lookup is actually a two byte command. Just make sure, that executing the data won't harm you actual program ( see an example here )

You can exploit many things relying on starting values.

Visit our beautiful resource collection for more information : sizecoding.org
added on the 2018-09-04 20:14:21 by HellMood HellMood
Thank you all, these are great answers, now I understand. I cannot thank you enough!
Thanks for these tips, I was having problems with screen flickering when writing straight to 0a000h. It's liberating and anarchic to code a x86 system like a C64 :)
added on the 2018-09-08 11:00:13 by El Topo El Topo

login