Re: Standard way of graphics in Linux
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Wed, 13 Sep 2006 12:20:19 +0200
Bjoern Schliessmann wrote:
Herbert Kleebauer wrote:
Depends -- does it have to run in the console or should it run on
top of X? For console, there also exists SDL (http://www.libsdl.org
-- it's kind of portable). For X see below.
It should run on any Linux installed on a x86 with a VGA card (like
a simple DOS graphics program run on any MS OS from DOS 1.0 - XP.
In DOS you can use int 10 to switch to 320*200 graphics and the
program can be executed on any MS OS up to XP.
Are you sure? But yes, with dosbox that may work. (But dosbox runs
in Linux too ;) )
I have a PC with a pre installed Linspire Linux. Because Dosbox was
not installed, I downloaded it (and FreeDOS) from Linspires website,
but it crashes. When there are even problems with Linspires "one-click-
installation", I think you can't assume that Dosbox is available in
a standard Linux installation.
Or can I somehow switch to 320*200 pixel VGA mode in a full screen
mode?
Mh. I run linux consoles in 1280x1024 all the time -- resolution is
not the problem.
I mean, if I'm are running KDE and start my demo, then all graphic output
should be stopped, the mode switched to standard VGA and the demo has
full control over the screen. When the demo exits, the old graphic
mode is restored and KDE gets control back. This is what happens if
you start a 16 bit graphic program in Windows. But is should also work
if it is only a Linux console installation (as it works in DOS 6.2).
Consider using high level toolkits like wxWidgets, GTK (installed
almost everywhere) or Qt (at least installed on every computer that
has KDE). You can then also use OpenGL if needed.
No, I don't consider high level toolkits. I want to play around
at the lowest level using assembly code. I managed to reduce the
ELF header to three source code lines in the assembler program
(see example below) to get small executables where I explicitly
control any byte in the binary. All I need, is a simple way to get
native keyboard (not stdin) and mouse input and a way to do graphics
output. And I don't want to use external libraries (any code in
a library which is executed in the context of the user program
can also be written as part of the application itself). I'm
interested in the low level "int" or "syscall" interface (which
switches the CPU to ring 0 mode) for graphic output. Only if there
is a simple way to do this, I would consider Linux an alternative
for learning assembly programming.
;===========================================================================
seg32
@=$08048000
code_offset=@@
code_addr:
;--------------------------- ELF header -----------------------------------
dc.l $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dc.l 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dc.l 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096
;--------------------------- code ------------------------------------------
main:
_10: bsr.l getc
cmp.l #-1,r0
beq.b _20
cmp.b #13,r0
beq.b _10
bsr.l putc
br.b _10
_20: move.l #0,r3 ; return code
move.l #1,r0 ; exit
trap #$80
getc: movem.l r0-r7,-(sp)
move.l #0,r3 ; stdin
move.l #buf,r2
move.l #1,r1 ; 1 byte
move.l #3,r0 ; read
trap #$80
tst.l r0,r0
bmi.b _10
movem.l (sp)+,r0-r7
beq.b _20
movu.bl buf,r0
rts.l
_20: orq.l #-1,r0
rts.l
_10: orq.l #-1,r3 ; return code
move.l #1,r0 ; exit
trap #$80
putc: movem.l r0-r7,-(sp)
move.l #1,r3 ; stdout
move.l #buf,r2
move.b r0,(r2)
move.l #1,r1 ; 1 byte
move.l #4,r0 ; write
trap #$80
cmpq.l #1,r0
bne.b _10
movem.l (sp)+,r0-r7
rts.l
_10: orq.l #-1,r3 ; return code
move.l #1,r0 ; exit
trap #$80
;--------------------------- constant data ---------------------------------
;---------------------------------------------------------------------------
code_filez=@@-code_offset
code_memsz= @-code_addr
even 4
@=(@+4095)/4096*4096+(@@\4096)
data_offset=@@
data_addr:
;--------------------------- initialized data ------------------------------
;var1: dc.l 1
;var2: dc.l 11
;--------------------------- uninitialized data ----------------------------
buf: blk.b 4
;---------------------------------------------------------------------------
data_filez=@@-data_offset
data_memsz= @-data_addr
;===========================================================================
The binary:
#!/bin/bash
name=dos2unix
rm -f $name
(for ((;;)); do
read line
if [[ "$line" == "" ]]; then break; fi
for ((j=0;;j+=2)); do
m=${line:$j:1}
n=${line:$j+1:1}
if [[ "$n" == "" ]]; then break; fi
echo -n -e \\$(( 0x$m/4*100 + (0x$m&3)*20 + 0x$n/8*10 + (0x$n&7) ))>>$name
done
done)<<"end"
7f454c4601010100000000000000000002000300010000007480040834000000
0000000000000000340020000200000000000000010000000000000000800408
00800408f7000000f7000000050000000010000001000000f8000000f8900408
f890040800000000040000000600000000100000e81e0000003dffffffff740b
3c0d74f0e843000000ebe9bb00000000b801000000cd8060bb00000000b9f890
0408ba01000000b803000000cd8085c07810619074080fb605f8900408c383c8
ffc383cbffb801000000cd8060bb01000000b9f89004088801ba01000000b804
000000cd8083f80175036190c383cbffb801000000cd8000
end
chmod +x $name
#############################################################################
.
- Follow-Ups:
- Re: Standard way of graphics in Linux
- From: Wolfgang Draxinger
- Re: Standard way of graphics in Linux
- From: "Nils O. Selåsdal"
- Re: Standard way of graphics in Linux
- References:
- Standard way of graphics in Linux
- From: Herbert Kleebauer
- Re: Standard way of graphics in Linux
- From: Bjoern Schliessmann
- Standard way of graphics in Linux
- Prev by Date: Re: Standard way of graphics in Linux
- Next by Date: Re: Standard way of graphics in Linux
- Previous by thread: Re: Standard way of graphics in Linux
- Next by thread: Re: Standard way of graphics in Linux
- Index(es):
Relevant Pages
|