IPB

Bienvenue invité ( Connexion | Inscription )

[ En ligne ] · Standard · Linéaire+

> juste qqs sources en passant :

momo
post 21/08/2002 1:19
Message #1


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



CODE
from Tkinter import *
import Image,ImageDraw,ImageTk,sys

def Dwords(files):
temp1=ord(files.read(1))*256**0
temp2=ord(files.read(1))*256**1
temp3=ord(files.read(1))*256**2
temp4=ord(files.read(1))*256**3
return temp1+temp2+temp3+temp4

def Words(files):
temp3=ord(files.read(1))*256**0
temp4=ord(files.read(1))*256**1
return temp3+temp4


def Read_Header_Bmp(bmpfile):
text=bmpfile.read(2)
print
print bmpfile
print "========BMP-Header Information========"
if text=="BM":
print "first Dword 'BM' : ok"
else:
print text
bfSize=Dwords(bmpfile)
print "File size in Bytes:", bfSize
reserv1=Words(bmpfile)
print "Must be zero:",
if reserv1==0:
print "ok"
else:
print "error"
reserv2=Words(bmpfile)
print "Must be zero:",
if reserv2==0:
print "ok"
else:
print "error"

offbits=Dwords(bmpfile)
print "Image data offset:",offbits


info=Words(bmpfile)
print "Info header=",info,"bytes"
# not Dwords but Longs ... :/
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
width=temp1+temp2+temp3+temp4
print "Width=",width
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
height=temp1+temp2+temp3+temp4
print "Height=",height
temp1=ord(bmpfile.read(1))*256**2
temp2=ord(bmpfile.read(1))*256**3
temp3=ord(bmpfile.read(1))*256**0
temp4=ord(bmpfile.read(1))*256**1
planes=temp1+temp2+temp3+temp4
print "Must be '1':",
if planes==1:
print "ok"
else:
print "error"
bitcount=Words(bmpfile)
print "Bits per pixel:",bitcount
compression=Dwords(bmpfile)
print "Compression type:",compression
sizeimage=Dwords(bmpfile)
print "Image size in Bytes:",sizeimage
xpxelpermeter=Dwords(bmpfile)
print "Pixels per meter (X):",xpxelpermeter
ypxelpermeter=Dwords(bmpfile)
print "Pixels per meter (Y):",ypxelpermeter
colorused=Dwords(bmpfile)
if colorused==0:
print "All colors used"
else:
print colorused,"colors used"
colorimportant=Dwords(bmpfile)
print colorimportant,"important color(s)"
print "============End of header ============"
return [width,height,bitcount,offbits,sizeimage]

def Bmp_read_24(offbits,bmpfile,size):
data=[]
if bmpfile.tell()<>offbits:
print bmpfile.tell()
bmpfile.seek(offbits)
for count in range(size/3):
test=bmpfile.read(3)
blue=ord(test[0])
green=ord(test[1])
red=ord(test[2])
colors=[red,green,blue]
data.append(colors)
return data


#file=open("Test.dat","rb")
file=open("Sparclin.bmp","rb")
bmpinfo=Read_Header_Bmp(file)
if bmpinfo[2]==24:
print "launch 24 bits decoding routine"
bmpdata=Bmp_read_24(bmpinfo[3],file,bmpinfo[4])
else:
print "%d bit(s) not supported yet"%(bmpinfo[2])
sys.exit()

file.close()
print"file closed"
root=Tk()
root.title("momo's dumb bmp reader")
if (bmpinfo[4]/(3*bmpinfo[1]))<>bmpinfo[0]:
print "size error",
bmpinfo[0]=bmpinfo[4]/(3*bmpinfo[1])
print "Width=%d"%(bmpinfo[0])
bitmap=Image.new("RGB",[bmpinfo[0],bmpinfo[1]])
print "mode:",bitmap.mode,"taille:",bitmap.size
bit=ImageDraw.Draw(bitmap)
count,count1=0,bmpinfo[1]
if (len(bmpdata)*3)<>bmpinfo[4]:
print "data size error %d/%d" % (len(bmpdata)*3,bmpinfo[4])
else:
print "data size ok"

for counter in range(len(bmpdata)):
color=(bmpdata[counter][0],bmpdata[counter][1],bmpdata[counter][2])
bit.point([count,count1],fill=color)
count+=1
if count>=bmpinfo[0]:
count=0
count1-=1


out=ImageTk.PhotoImage(bitmap)
lab=Label(image=out)
lab.pack()
print "Done"
root.mainloop()

bon terminé avec ce truc bmp : prise de tête à la longue ...
CODE
# attempt to create a chip8 interpreter
def cpu8(instr,regs,I,PC):
opcode=instr/4096
instr=instr-4096*opcode
if opcode==0:
PC=opcode0(instr,PC)
elif opcode==1:
print "%X: jump %X"%(PC,instr)
PC=instr
elif opcode==2:
stack.append(PC)
print "%X: jsr %X"%(PC,instr)
PC=instr
elif opcode==3:
register=int(instr/256)
value=instr-256*register
print "%X: skeq V%X,%X"%(PC,register,value)
if regs[register]==value:
PC+=4
else:
PC+=2
elif opcode==4:
register=int(instr/256)
value=instr-256*register
print "%X: skne v%X,%X"%(PC,register,value)
if regs[register]==value:
PC+=2
else:
PC+=4
elif opcode==5:
register1=int(instr/256)
register2=int((instr-256*register1)/16)
print "%X: skeq V%X,V%X"%(PC,register1,register2)
if regs[register1]==regs[register2]:
PC+=4
else:
PC+=2
elif opcode==6:
register=int(instr/256)
value=instr-256*register
regs[register]=value
print "%X: mov V%X,%X"%(PC,register,value)
PC+=2
elif opcode==7:
register=int(instr/256)
value=instr-256*register
regs[register]+=value
print "%X: add V%X,%X"%(PC,register,value)
PC+=2
elif opcode==8:
register1=int(instr/256)
register2=int((instr-256*register1)/16)
value=instr-256*register1-16*register2
opcode8(register1,register2,value,PC)
PC+=2
elif opcode==9:
print "skne"
elif opcode==0xA:
print "mvi "
elif opcode==0xB:
print "jmi"
elif opcode==0xC:
print "rand v"
elif opcode==0xD:
print "sprite r"
elif opcode==0xE:
print "opcode E : translating"
elif opcode==0xF:
print "opcode F : translating"
return PC
def opcode0(value,PC):
if value==0xE0:
print "%X: cls"%(PC)
PC+=2
elif value==0xEE:
PC=stack.pop()
print "%X: rts"%(PC)
else:
print "NoOp"
PC=0
return PC

def opcode8(register1,register2,value,PC):
if value==1:
regs[register1]=regs[register2]
print "%X: mov V%X,V%X"%(PC,register1,register2)
elif value==2:
regs[register1]=regs[register1]|regs[register2]
print "%X: or V%X,V%X"%(PC,register1,register2)
elif value==3:
regs[register1]=regs[register1]&regs[register2]
print "%X: and V%X,V%X"%(PC,register1,register2)
elif value==4:
regs[register1]=regs[register1]^regs[register2]
print "%X xor V%X,V%X"%(PC,register1,register2)
elif value==5:
regs[register1]+=regs[register2]
if regs[register1]>0xFF:
regs[0xF]=1
regs[register1]=regs[register1]%0xFF
print "%X add V%X,V%X"%(PC,register1,register2)
elif value==7:
regs[register1]-=regs[register2]
if regs[register1]<0:
regs[register1]+=0xFF
regs[0xF]=1
print "%X sub V%X,V%X"%(PC,register1,register2)
elif value==6:
regs[0xF]=regs[register1]&1
regs[register1]=regs[register1]>>1
print "%X: shr V%X"%(PC,register1)
elif value==0xE:
regs[0xF]=regs[register1]&128
regs[register1]=regs[register1]<<1
print "%X: shl V%X"%(PC,register1)


regs=[0]*16
stack=[]
PC=0x200
I=0
print ""
# list containing a instruction list ... no real memory map
intr=[0]*0x200
intr.append(0x610F)
intr.append(0)
intr.append(0x7001)
intr.append(0)
intr.append(0x00E0)
intr.append(0)
intr.append(0x5010)
intr.append(0)
intr.append(0x1202)
intr.append(0)
intr.append(0x810E)
intr.append(0)
intr.append(0x8006)
intr.append(0)
intr.append(0)
while PC<>0:
PC=cpu8(intr[PC],regs,I,PC)

print "registers:", regs
print "stack:",stack
print "0x%X"%PC

loin d'être terminé .. mais faut bien commencer par qq part .. smile.gif


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
 
Reply to this topicStart new topicStart Poll
Réponse(s)
momo
post 22/08/2002 22:17
Message #2


lvl1 male rogue St=1 Dex=5 Int=17 Wi=5 Ch=0
****

Groupe : Modérateurs
Messages : 1,730
Inscrit le : 16/05/2002 23:00
Lieu : .gif
Membre no. 12



m'enfin .. le basic n'est pas un mauvais langage, il est seulement trop simple ... smile.gif
bon, du coup, pour mon chip8, il faut que je me fasse un "bios" : une fonte en 4*5 bits ... ( A-F, 1-9 )
bon: notepad et un prog ...
au fait il existe un moyen universel d'obtenir une entrée clavier plutôt que de jongler entre curses et msvcrt selon l'architecture ?


--------------------
Natural evolution insists that we are apes; artificial evolution insists that we are machines with an attitude.
Kevin Kelly - Out of control
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Posts in this topic


Reply to this topicTopic OptionsStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :
 

Version bas débit Nous sommes le : : 08/07/2025 23:33