00:08:32 re ihope 00:12:59 ? 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:53:47 hello 17:54:18 hmmm, anyone familiar with reading binary files in c in windows/dos? 17:54:48 what about it? 17:54:54 could you help a bit? 17:56:53 ? 17:57:36 help in what? ;) 17:58:22 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 and show how to read a word and a double word? 17:59:39 (2-bytes and 4-bytes) 18:03:02 come on, i can get never started unlike someone shows me this simple thing :) 18:03:09 *unless 18:14:25 perhaps i should use python instead.. but can it compile? 18:15:20 although i have no idea how to do these things in python either 18:16:52 mh, no, c'd suit better 18:21:07 Keymaker: a sec 18:21:22 ok:) 18:22:55 Keymaker: int byte; FILE *fp; fp = open("somefile", "rb"); assert(fp); byte = fgetch(fp); assert(byte != EOF); // reads one byte 18:23:27 Keymaker: what endianess do you want to use with the words? 18:23:48 hmm, not sure which one is it.. it's the one used in windows/dos 18:37:11 oh this is so frustrating.. hopefully the last time ever i use c 18:37:58 you better check the byteorder somewhere :) 18:39:40 int byte1, byte2, word; byte1 = fgetch(fp); byte2=fgetch(fp); word = byte1+(byte2<<8) // reads one little-endian word 18:39:59 Keymaker: just make that a function and it's less painless 18:40:06 ok 18:40:30 and remember checks for EOF 18:40:45 how? 18:40:55 depends on how you want to fail of course 18:41:03 :) 18:41:06 assert(byte1 != EOF) will kill the whole program 18:42:30 thanks. i don't understand this stuff, so, do i need to close the file somehow? 18:42:40 and what assert does? 18:42:42 fclose(fp) 18:42:48 ok 18:43:02 Keymaker: it's just a debugging aid which i tend to overuse :) 18:43:10 ah. 18:43:33 and the last question, is there any way to read from exact hex address? 18:43:44 Keymaker: from the file? 18:43:46 yeah 18:43:51 just seek() 18:43:59 or fseek() actually 18:44:14 how do i do that? 18:44:14 -!- nooga has joined. 18:44:18 http://www.99-bottles-of-beer.net/language-sadol-941.html 18:44:20 LOOK! 18:44:27 someone codes in sadol ! 18:44:37 Keymaker: check the manual ;) 18:44:40 yeah, i've seen that :) nice 18:44:43 and i dont know him (probably) 18:44:45 lindi-: ok 18:44:52 thanks for all the fish, 18:44:54 Keymaker: and ask if it's unclear 18:44:59 ok 18:45:18 bbl.. 18:48:17 yay 18:48:21 success!!! 18:48:40 someone has written a program in my language 18:48:45 yay yay yay! 19:12:55 hm 19:13:00 that's funny 19:15:03 :) 19:15:06 (back) 19:23:26 hm 19:23:34 * nooga is writing SADOL2 interpreter 19:43:49 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 int main(int argc, char ** argv) { FILE * fp; if(argc != 2) die(); fp = fopen(argv[1], "rb"); ... 19:46:49 thanks 19:48:28 And fseek(fp, offset, SEEK_SET); makes future fread()s (or fgetch()s) start at 'offset' bytes from the start of the file. 19:48:58 cool! :) 19:54:09 wo 19:54:11 f... ten errors in few lines already.. 19:54:15 Keymaker learns C ? 19:54:38 well, my purpose isn't try to learn it, just code one program :) 19:55:02 in what did you code until now? 19:55:11 brainfuck :) 19:55:17 and will code in the future as well.. 19:55:29 i've used c sometimes, but never these file things 19:55:48 but well, the programs i've written in c this far have been minimal. 19:56:32 ah, solved the probelm 19:56:43 *bl 19:57:40 fizzie: those things require more than stdio.h? 19:57:57 They shouldn't. 19:58:01 hmm 19:58:20 then i guess i'm having some problem in my c compiler.. or in dev-c++ 19:58:28 probably the latte 19:58:30 *r 19:59:58 it doesn't complain errors but it complains "undefined reference to `die'" and doesn't create anything 20:02:10 Keymaker: by "die()" fizzie meant that you need to handle the error somehow 20:02:40 it isn't c function? 20:02:45 i guess no 20:02:58 its in perl en php though 20:03:17 hmm, i thought i've seen it in c before 20:03:41 but nevertheless, now it complains about "undefined reference to `fgetch'" 20:03:42 Keymaker: you can create the function yourself 20:03:57 Keymaker: sorry, it's fgetc() 20:04:13 Heh, thought it was fgetc() but since lindi used fgetch... :p 20:04:25 void die(char* s) {printf("error: %s",s); exit(1);} 20:04:26 :> 20:04:32 ok 20:04:38 thanks, now it works 20:04:39 getch must be some ncurses stuff 20:05:20 argh, the functions.. i wouldn't like to use own functions but i guess it's rather necessary 20:05:48 or well, not necessary, but might ease the work 20:06:08 indeed 20:07:03 what this "argc != 2" means? 20:07:09 file doesn't exist or what? 20:07:29 Tests that there are two arguments provided to the program. 20:07:34 (The first one is always the program name.) 20:07:56 ok 20:08:03 then, how do i check the file is there? 20:08:13 If it isn't, fopen() fails. 20:08:19 (And returns NULL.) 20:09:15 ok 20:09:27 this language has no logic :) 20:10:34 hmh, i can't use it 20:10:54 there's "fp = fopen(argv[1], "rb");" 20:11:03 how do i check if fopen returns null? 20:11:10 and what is that 'fp' 20:11:54 Keymaker: if (fp == NULL) { fprintf(stderr, "Failed to open file\n"); exit(1); } 20:12:06 Keymaker: how many languages did you invent? 20:12:10 or assert(fp); ;) 20:12:28 *have you invented? 20:13:01 nooga: unnecessary and trigger (partly) 20:13:12 and some unreleased, unfinished 20:13:25 and you have problems with C 20:13:30 yes 20:13:33 omigosh 20:13:39 :p 20:13:45 brainfuck makes sense, this does not 20:13:53 what about SADOL 20:13:54 ? 20:14:06 i'm coding my emulator in c 20:14:08 nice, warm, lovely, functional paradigm 20:14:13 :) 20:14:16 but i'm a c beginner... 20:14:16 yeah 20:14:26 (bbl) 20:14:39 you, a beginner?! and managed to write a kipple interpreter? 20:14:54 * Keymaker dies 20:14:57 jix: check out http://regedit.risp.pl/nosense/ 20:16:07 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 nooga: i did something like this before.. but i didn't took it to that level... 20:16:25 only simple terminal IO 20:16:33 simple instruction set 20:16:38 but now i'm writing a z80 emulator 20:16:41 i plan to use xanalogtv as a display 20:16:45 for a coleco vision emulator 20:16:59 like in the "apple][" screensaver for linux 20:18:56 http://images.opentopia.com/enc/3/2116/Apple2_BSOD.jpg 20:19:25 http://images.opentopia.com/enc/3/2116/Apple2_Screensaver.jpg 20:19:55 oh http://hactar.net/kzed/images/ircpower.jpg 20:20:00 it looks like this 20:20:20 xanalogtv emulates old, damaged tv display :D 20:20:23 where do i get xanalogtv? 20:20:30 (i know the apple][ screen saver) 20:20:41 would be cool for coleco vision emulator too 20:21:17 check out the sources of xscreensaver 20:21:45 I've started to write two z80 emulators already. :p 20:22:07 http://www.die.net/doc/linux/man/man1/xanalogtv.1.html 20:22:10 (Neither one got very far - although I think both times I had the z80 cpu part semi-done.) 20:22:59 hah 20:23:05 i just hate kdevelop 20:23:09 it's horrible 20:23:23 all that mess with automake and autoconf 20:23:28 werid errors 20:23:36 blah 20:23:38 fizzie: i implemented LD PUSH POP and EX .... 20:23:54 i'm implementing the decoding atm (i use code generation because i want to finish it...) 20:24:43 i see that z80 is quite popular 20:27:29 it is 20:27:56 simple 20:27:58 huh 20:31:05 i thought about a script for generating some opcodes' code 20:31:26 because there are many of almost equal 20:33:53 i do that... 20:34:01 it's like a specialized macro system 20:34:05 yea 20:39:20 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 i use z80-documentated.pdf 20:40:09 it's very complete... 20:41:47 mh, this program doesn't work correctly 20:42:15 int main(int argc, char ** argv){ 20:42:15 FILE * fp; 20:42:15 if (argc != 2){ die("An argument is missing (input file)."); }; 20:42:15 if (fp == NULL){ die("Failed to open file."); } 20:42:15 fp = fopen(argv[1], "rb"); 20:42:33 Should you perhaps fopen first and check fp == NULL after? 20:42:57 i don't know :) 20:43:04 I think it might make sense. 20:43:22 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:43:25 lool 20:44:08 yeah, it makes sense, but the behaviours stays as strange as before 20:44:52 it doesn't print the stuff in die() and quits strangely 20:45:41 hahm 20:46:43 mmh, now it works. 20:47:59 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 a line in decode.table looks like: ON 0xDD 0b01110aaa bDO LD_de1(`Rix`, a:r, b)T 19 # LD (IX+d),r 20:48:50 lol :D 20:49:01 and LD_de1 is defined in instructions.in.c 20:49:47 backticks can contain any c code... it's inserted into the template at instructions.in.c 20:50:06 a:r says look up the c code for every possible a in the enum table r 20:50:53 someone; how do i read a double word? 20:51:11 (lindi-: the code for reading word works perfectly) 20:51:54 Just extrapolate on it. byte1, byte2, byte3, byte4 - fgetc four times - dword = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4. 20:52:19 or use read.. (check byte order!) 20:52:21 fread 20:52:36 fizzie: that would read big-endian dword though 20:52:51 Well, big-endian is what makes sense. :p 20:53:04 but this is needed in windows 20:53:07 ;) 20:53:21 if you use fread on big-endian it reads big-endian if runs on little it reads little endian 20:53:35 jix: yeah, and that's very bad 20:53:48 You could use "unsigned int foo; fread(&foo, 4, 1, fp);" if you didn't care about portability. 20:54:06 thanks 20:54:13 things like int being 16-bits and so on... 20:54:17 well, i don't care about portability since it's a level editor for old dos game 20:54:28 please care about portability :) 20:54:37 as it's so easy in this case 20:54:44 then, what do i use?! 20:54:53 fizzie's first code or second? 20:55:02 Keymaker: fizzies code but reverse the order of bytes 20:55:48 like "dword = (byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1"? 20:55:55 yep 20:55:58 ok 20:56:02 then i'll use that 20:56:45 well, i can't make functions of those 20:57:59 Keymaker: why not? 20:58:29 i don't have the skills 20:58:34 ;) 20:59:11 would the fgetc work if i call it from some function? 20:59:21 Uh. int read_word(FILE * fp) { int byte1, byte2; byte1 = fgetc(fp); byte2 = fgetc(fp); return byte1 | (byte2 << 16); } 20:59:28 (Without error-checking.) 20:59:34 thanks 20:59:46 Why wouldn't it work when called from a function? 21:00:14 i don't know 21:00:21 i don't understand how it works 21:00:36 when i call it, do i need to have something inside ( ) ? 21:00:47 the read_word 21:00:57 The file pointer. 21:01:04 how do i write it there? 21:01:17 How would you write it when calling fgetc? 21:01:28 i have no idea :p 21:01:39 Well, "fp". If that's what you call it. 21:01:50 ah 21:01:54 thanks 21:01:59 fp = fopen(..); foo = read_word(fp); ... 21:03:32 and error checking for every other line ;) 21:04:09 i think i'll leave the error checking out, it's too annoying 21:04:42 you'll hit nasty bugs if you do that 21:10:25 is int two bytes or does that need to be defined somehow to keep portability? 21:10:56 int is somewhere between 8 and 64 bytes.. (most of the time.. there may be exceptions...) 21:11:18 it could be something different than a multiple of 8 bits... 21:11:23 ok 21:11:24 if a byte != 8bits... 21:11:25 at least here it's 4 bytes 21:11:37 #include 21:11:52 jix; what does it do? 21:12:04 you get things like int32_t for a 32bit signed int 21:12:05 and in real mode dos system it's 2 bytes 21:12:13 or uint16_t 21:12:25 you can typedef to u16 and s16 and u32.... 21:12:36 typedef uint8_t u8; 21:12:36 typedef int8_t s8; 21:12:40 well, i don't understand any of those lines, but ok 21:12:51 then u8 is a 8bit unsigned 21:13:03 replace 8bit with the bit count you want.. 21:14:31 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 ok, thanks 21:15:12 i don't use uint16_t because i always type things liek int_16t or uint16t or t_uint16... 21:16:18 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 if you need exactly that amount of bits that won't work... making it even worse because it compiles without errors... 21:17:18 I don't think he needs exactly that amount of bits. 21:17:29 no 21:17:34 (i do) 21:17:53 You just think you do. :p 21:18:29 no 21:18:31 One can always add "&0xffff"s there. 21:18:31 i don't dare even think what kind of problems there will be with file saving.. 21:18:51 fizzie: but i don't want to do that 21:21:47 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. 23:38:46 can't there be global arrays?