00:35:09 -!- GregorR has joined.
00:37:02 -!- Arrogant has quit (Read error: 113 (No route to host)).
01:15:55 -!- puzzlet has quit (Read error: 110 (Connection timed out)).
01:18:51 -!- ihope has quit (Read error: 110 (Connection timed out)).
02:28:08 -!- ihope has joined.
02:35:14 -!- CXII has joined.
02:47:14 -!- ihope has quit ("Chatzilla 0.9.69 [Firefox 1.0.7/20050915]").
02:57:08 -!- CXI has quit (Connection timed out).
03:09:05 * Sgep is leaving in less than 2min
03:09:40 * Sgep executed sudo shutdown -h 5
03:10:38 -!- Sgep has quit (Remote closed the connection).
03:22:31 -!- pgimeno has quit (brown.freenode.net irc.freenode.net).
03:22:58 -!- pgimeno has joined.
03:23:34 -!- pgimeno has quit (brown.freenode.net irc.freenode.net).
03:24:00 -!- pgimeno has joined.
04:04:50 -!- CXI has joined.
04:27:55 -!- CXII has quit (Connection timed out).
05:17:55 -!- puzzlet has joined.
06:12:38 -!- sekhmet_ has joined.
06:25:39 -!- sekhmet has quit (Read error: 110 (Connection timed out)).
06:35:15 -!- sekhmet_ has changed nick to sekhmet.
07:59:59 -!- clog has quit (ended).
08:00:00 -!- clog has joined.
09:20:32 -!- kipple has joined.
13:59:35 -!- jix has joined.
16:09:39 -!- puzzlet has quit (Read error: 110 (Connection timed out)).
17:52:47 -!- Keymaker has joined.
17:54:18 <Keymaker> hmmm, anyone familiar with reading binary files in c in windows/dos?
17:58:22 <Keymaker> reading the files :) could you write a simple program that'd open something file and read a byte from it to variable and then close the file?
17:59:20 <Keymaker> and show how to read a word and a double word?
18:03:02 <Keymaker> come on, i can get never started unlike someone shows me this simple thing :)
18:14:25 <Keymaker> perhaps i should use python instead.. but can it compile?
18:15:20 <Keymaker> although i have no idea how to do these things in python either
18:22:55 <lindi-> Keymaker: int byte; FILE *fp; fp = open("somefile", "rb"); assert(fp); byte = fgetch(fp); assert(byte != EOF); // reads one byte
18:23:27 <lindi-> Keymaker: what endianess do you want to use with the words?
18:23:48 <Keymaker> hmm, not sure which one is it.. it's the one used in windows/dos
18:37:11 <Keymaker> oh this is so frustrating.. hopefully the last time ever i use c
18:37:58 <lindi-> you better check the byteorder somewhere :)
18:39:40 <lindi-> int byte1, byte2, word; byte1 = fgetch(fp); byte2=fgetch(fp); word = byte1+(byte2<<8) // reads one little-endian word
18:39:59 <lindi-> Keymaker: just make that a function and it's less painless
18:40:30 <lindi-> and remember checks for EOF
18:40:55 <lindi-> depends on how you want to fail of course
18:41:06 <lindi-> assert(byte1 != EOF) will kill the whole program
18:42:30 <Keymaker> thanks. i don't understand this stuff, so, do i need to close the file somehow?
18:43:02 <lindi-> Keymaker: it's just a debugging aid which i tend to overuse :)
18:43:33 <Keymaker> and the last question, is there any way to read from exact hex address?
18:43:44 <lindi-> Keymaker: from the file?
18:44:14 -!- nooga has joined.
18:44:18 <nooga> http://www.99-bottles-of-beer.net/language-sadol-941.html
18:44:27 <nooga> someone codes in sadol !
18:44:37 <lindi-> Keymaker: check the manual ;)
18:44:43 <nooga> and i dont know him (probably)
18:44:54 <lindi-> Keymaker: and ask if it's unclear
18:48:40 <nooga> someone has written a program in my language
19:23:34 * nooga is writing SADOL2 interpreter
19:43:49 <Keymaker> lindi-: what should i do to get the file-to-be-opened given as argument for the program? like, prog1 file.txt
19:46:32 <fizzie> int main(int argc, char ** argv) { FILE * fp; if(argc != 2) die(); fp = fopen(argv[1], "rb"); ...
19:48:28 <fizzie> And fseek(fp, offset, SEEK_SET); makes future fread()s (or fgetch()s) start at 'offset' bytes from the start of the file.
19:54:11 <Keymaker> f... ten errors in few lines already..
19:54:15 <nooga> Keymaker learns C ?
19:54:38 <Keymaker> well, my purpose isn't try to learn it, just code one program :)
19:55:02 <nooga> in what did you code until now?
19:55:17 <Keymaker> and will code in the future as well..
19:55:29 <Keymaker> i've used c sometimes, but never these file things
19:55:48 <Keymaker> but well, the programs i've written in c this far have been minimal.
19:57:40 <Keymaker> fizzie: those things require more than stdio.h?
19:58:20 <Keymaker> then i guess i'm having some problem in my c compiler.. or in dev-c++
19:59:58 <Keymaker> it doesn't complain errors but it complains "undefined reference to `die'" and doesn't create anything
20:02:10 <lindi-> Keymaker: by "die()" fizzie meant that you need to handle the error somehow
20:02:58 <nooga> its in perl en php though
20:03:17 <Keymaker> hmm, i thought i've seen it in c before
20:03:41 <Keymaker> but nevertheless, now it complains about "undefined reference to `fgetch'"
20:03:42 <lindi-> Keymaker: you can create the function yourself
20:03:57 <lindi-> Keymaker: sorry, it's fgetc()
20:04:13 <fizzie> Heh, thought it was fgetc() but since lindi used fgetch... :p
20:04:25 <nooga> void die(char* s) {printf("error: %s",s); exit(1);}
20:04:39 <lindi-> getch must be some ncurses stuff
20:05:20 <Keymaker> argh, the functions.. i wouldn't like to use own functions but i guess it's rather necessary
20:05:48 <Keymaker> or well, not necessary, but might ease the work
20:07:29 <fizzie> Tests that there are two arguments provided to the program.
20:07:34 <fizzie> (The first one is always the program name.)
20:08:03 <Keymaker> then, how do i check the file is there?
20:08:13 <fizzie> If it isn't, fopen() fails.
20:10:54 <Keymaker> there's "fp = fopen(argv[1], "rb");"
20:11:03 <Keymaker> how do i check if fopen returns null?
20:11:54 <lindi-> Keymaker: if (fp == NULL) { fprintf(stderr, "Failed to open file\n"); exit(1); }
20:12:06 <nooga> Keymaker: how many languages did you invent?
20:12:28 <nooga> *have you invented?
20:13:01 <Keymaker> nooga: unnecessary and trigger (partly)
20:13:12 <Keymaker> and some unreleased, unfinished
20:13:25 <nooga> and you have problems with C
20:13:45 <Keymaker> brainfuck makes sense, this does not
20:14:06 <jix> i'm coding my emulator in c
20:14:08 <nooga> nice, warm, lovely, functional paradigm
20:14:16 <jix> but i'm a c beginner...
20:14:39 <Keymaker> you, a beginner?! and managed to write a kipple interpreter?
20:14:57 <nooga> jix: check out http://regedit.risp.pl/nosense/
20:16:07 <nooga> i'm coding next idea of that guy (a friend of mine) - sqr16, 8 bit machine emulator with only 256 bytes of memory :D
20:16:11 <jix> nooga: i did something like this before.. but i didn't took it to that level...
20:16:25 <jix> only simple terminal IO
20:16:33 <jix> simple instruction set
20:16:38 <jix> but now i'm writing a z80 emulator
20:16:41 <nooga> i plan to use xanalogtv as a display
20:16:45 <jix> for a coleco vision emulator
20:16:59 <nooga> like in the "apple][" screensaver for linux
20:18:56 <nooga> http://images.opentopia.com/enc/3/2116/Apple2_BSOD.jpg
20:19:25 <nooga> http://images.opentopia.com/enc/3/2116/Apple2_Screensaver.jpg
20:19:55 <nooga> oh http://hactar.net/kzed/images/ircpower.jpg
20:20:00 <nooga> it looks like this
20:20:20 <nooga> xanalogtv emulates old, damaged tv display :D
20:20:23 <jix> where do i get xanalogtv?
20:20:30 <jix> (i know the apple][ screen saver)
20:20:41 <jix> would be cool for coleco vision emulator too
20:21:17 <nooga> check out the sources of xscreensaver
20:21:45 <fizzie> I've started to write two z80 emulators already. :p
20:22:07 <nooga> http://www.die.net/doc/linux/man/man1/xanalogtv.1.html
20:22:10 <fizzie> (Neither one got very far - although I think both times I had the z80 cpu part semi-done.)
20:23:05 <nooga> i just hate kdevelop
20:23:23 <nooga> all that mess with automake and autoconf
20:23:38 <jix> fizzie: i implemented LD PUSH POP and EX ....
20:23:54 <jix> i'm implementing the decoding atm (i use code generation because i want to finish it...)
20:24:43 <nooga> i see that z80 is quite popular
20:31:05 <nooga> i thought about a script for generating some opcodes' code
20:31:26 <nooga> because there are many of almost equal
20:33:53 <jix> i do that...
20:34:01 <jix> it's like a specialized macro system
20:39:20 <fizzie> I used to have a Z80 datasheet/manual here, too. Although as I didn't bother emulating the timing issues, any old opcode list would've been as good.
20:40:04 <jix> i use z80-documentated.pdf
20:40:09 <jix> it's very complete...
20:41:47 <Keymaker> mh, this program doesn't work correctly
20:42:15 <Keymaker> int main(int argc, char ** argv){
20:42:15 <Keymaker> if (argc != 2){ die("An argument is missing (input file)."); };
20:42:15 <Keymaker> if (fp == NULL){ die("Failed to open file."); }
20:42:33 <fizzie> Should you perhaps fopen first and check fp == NULL after?
20:43:04 <fizzie> I think it might make sense.
20:43:22 <fizzie> Now I'd need to design a MIPS R3000 CPU and a MMU for it, and optionally a FPU too. Optionally with VHDL descriptions so it can be simulated. A bit too low-level for my tastes.
20:44:08 <Keymaker> yeah, it makes sense, but the behaviours stays as strange as before
20:44:52 <Keymaker> it doesn't print the stuff in die() and quits strangely
20:47:59 <jix> i have two files decode.table... does the opcode => instruction mapping... and instructions.in.c that contains the code for the instructions... i use ruby code to parse both and combine them into compilable c code
20:48:16 <jix> a line in decode.table looks like: ON 0xDD 0b01110aaa bDO LD_de1(`Rix`, a:r, b)T 19 # LD (IX+d),r
20:49:01 <jix> and LD_de1 is defined in instructions.in.c
20:49:47 <jix> backticks can contain any c code... it's inserted into the template at instructions.in.c
20:50:06 <jix> a:r says look up the c code for every possible a in the enum table r
20:50:53 <Keymaker> someone; how do i read a double word?
20:51:11 <Keymaker> (lindi-: the code for reading word works perfectly)
20:51:54 <fizzie> Just extrapolate on it. byte1, byte2, byte3, byte4 - fgetc four times - dword = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4.
20:52:19 <jix> or use read.. (check byte order!)
20:52:36 <lindi-> fizzie: that would read big-endian dword though
20:52:51 <fizzie> Well, big-endian is what makes sense. :p
20:53:21 <jix> if you use fread on big-endian it reads big-endian if runs on little it reads little endian
20:53:35 <lindi-> jix: yeah, and that's very bad
20:53:48 <fizzie> You could use "unsigned int foo; fread(&foo, 4, 1, fp);" if you didn't care about portability.
20:54:13 <lindi-> things like int being 16-bits and so on...
20:54:17 <Keymaker> well, i don't care about portability since it's a level editor for old dos game
20:54:28 <lindi-> please care about portability :)
20:54:37 <lindi-> as it's so easy in this case
20:54:53 <Keymaker> fizzie's first code or second?
20:55:02 <lindi-> Keymaker: fizzies code but reverse the order of bytes
20:55:48 <Keymaker> like "dword = (byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1"?
20:56:45 <Keymaker> well, i can't make functions of those
20:59:11 <Keymaker> would the fgetc work if i call it from some function?
20:59:21 <fizzie> Uh. int read_word(FILE * fp) { int byte1, byte2; byte1 = fgetc(fp); byte2 = fgetc(fp); return byte1 | (byte2 << 16); }
20:59:28 <fizzie> (Without error-checking.)
20:59:46 <fizzie> Why wouldn't it work when called from a function?
21:00:21 <Keymaker> i don't understand how it works
21:00:36 <Keymaker> when i call it, do i need to have something inside ( ) ?
21:01:17 <fizzie> How would you write it when calling fgetc?
21:01:39 <fizzie> Well, "fp". If that's what you call it.
21:01:59 <fizzie> fp = fopen(..); foo = read_word(fp); ...
21:03:32 <lindi-> and error checking for every other line ;)
21:04:09 <Keymaker> i think i'll leave the error checking out, it's too annoying
21:04:42 <lindi-> you'll hit nasty bugs if you do that
21:10:25 <Keymaker> is int two bytes or does that need to be defined somehow to keep portability?
21:10:56 <jix> int is somewhere between 8 and 64 bytes.. (most of the time.. there may be exceptions...)
21:11:18 <jix> it could be something different than a multiple of 8 bits...
21:11:24 <jix> if a byte != 8bits...
21:11:25 <lindi-> at least here it's 4 bytes
21:11:37 <jix> #include <stdint.h>
21:12:04 <jix> you get things like int32_t for a 32bit signed int
21:12:05 <lindi-> and in real mode dos system it's 2 bytes
21:12:13 <jix> or uint16_t
21:12:25 <jix> you can typedef to u16 and s16 and u32....
21:12:36 <jix> typedef uint8_t u8;
21:12:36 <jix> typedef int8_t s8;
21:12:40 <Keymaker> well, i don't understand any of those lines, but ok
21:12:51 <jix> then u8 is a 8bit unsigned
21:13:03 <jix> replace 8bit with the bit count you want..
21:14:31 <fizzie> Or just use "uint16_t foo" for a 16-bit word, and "uint32_t bar" for a 32-bit dword - they're not _that_ long that you'd need to abbreviate them to u16 or u32.
21:15:12 <jix> i don't use uint16_t because i always type things liek int_16t or uint16t or t_uint16...
21:16:18 <fizzie> And then again, that's not the most portable solution. It might not work on, say, a Cray, where 16-bit integers don't exist. A more portable choice would be to use int_least16_t and int_least32_t from stdint.h.
21:17:00 <jix> if you need exactly that amount of bits that won't work... making it even worse because it compiles without errors...
21:17:18 <fizzie> I don't think he needs exactly that amount of bits.
21:17:53 <fizzie> You just think you do. :p
21:18:31 <fizzie> One can always add "&0xffff"s there.
21:18:31 <Keymaker> i don't dare even think what kind of problems there will be with file saving..
21:18:51 <jix> fizzie: but i don't want to do that
21:21:47 <fizzie> Then you'll probably need to do something like #ifdef UINT8_MAX typedef uint8_t u8; #define SET8(a,b) ((a) = (b)) #define GET8(a) (a) #else typedef uint_fast8_t u8; #define SET8(a,b) ((a) = ((b)&0xff)) #define GET8(a) ((a)&0xff) #endif, if you want your thing to work on platforms where no 8-bit integers exist.
23:32:32 -!- clog has joined.
23:32:32 -!- clog has joined.