I just ran through the disassembled source, picked out the interesting parts and commented them. Unfortunatelly I'm still quite clueless what actually causes the bug, especially as the assembler code looks fine to me:
Code: Select all
this[0] = col
this[4] = pos
this[8] = off
this[C] = vidmem
Video::Video()
24: 55 push %ebp
125: 89 e5 mov %esp,%ebp
127: 8b 45 08 mov 0x8(%ebp),%eax ; eax = this
12a: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) ; pos = 0
131: 8b 45 08 mov 0x8(%ebp),%eax
134: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) ; off = 0
13b: 8b 45 08 mov 0x8(%ebp),%eax
13e: c7 00 00 07 00 00 movl $0x700,(%eax) ; col = 0x700
144: 8b 45 08 mov 0x8(%ebp),%eax
147: c7 40 0c 00 80 0b 00 movl $0xb8000,0xc(%eax) ; vidmem = 0xB8000
14e: 5d pop %ebp
14f: c3 ret
Video::accapo()
150: 55 push %ebp
151: 89 e5 mov %esp,%ebp
153: 8b 45 08 mov 0x8(%ebp),%eax ; eax = this
156: 8b 40 08 mov 0x8(%eax),%eax ; eax = off
159: 8d 50 50 lea 0x50(%eax),%edx ; edx = off[0x50]
15c: 8b 45 08 mov 0x8(%ebp),%eax ; eax = this
15f: 89 50 08 mov %edx,0x8(%eax) ; off += 80
162: 8b 45 08 mov 0x8(%ebp),%eax ; eax = this
165: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) ; pos = 0
16c: 5d pop %ebp
16d: c3 ret
void Video::put(const char c)
16e: 55 push %ebp
16f: 89 e5 mov %esp,%ebp
171: 83 ec 1c sub $0x1c,%esp ; reserve 7 locals
174: 8b 45 0c mov 0xc(%ebp),%eax ; eax = param0
177: 88 45 ec mov %al,0xffffffec(%ebp) ; local[ec] = eax
17a: 8b 45 08 mov 0x8(%ebp),%eax ; eax = this
17d: c7 40 0c 00 80 0b 00 movl $0xb8000,0xc(%eax) ; vidmem = 0xB8000
184: 80 7d ec 0a cmpb $0xa,0xffffffec(%ebp) ; if(c == '\n')
188: 75 10 jne 0x19a ; {
18a: 8b 45 08 mov 0x8(%ebp),%eax
18d: 89 04 24 mov %eax,(%esp)
190: e8 bb ff ff ff call 0x150 ; accapo()
195: e9 80 00 00 00 jmp 0x21a ; return
; }
19a: 80 7d ec 09 cmpb $0x9,0xffffffec(%ebp) ; if(c == '\t')
19e: 75 2a jne 0x1ca ; {
1a0: c7 45 fc 00 00 00 00 movl $0x0,0xfffffffc(%ebp) ; local[fc] = 0
1a7: eb 19 jmp 0x1c2 ; while(local[fc] < 8)
1a9: c7 44 24 04 20 00 00 movl $0x20,0x4(%esp) ; {
1b0: 00 ; push char(' ')
1b1: 8b 45 08 mov 0x8(%ebp),%eax ; push this
1b4: 89 04 24 mov %eax,(%esp)
1b7: e8 b2 ff ff ff call 0x16e ; call put
1bc: 8d 45 fc lea 0xfffffffc(%ebp),%eax
1bf: 83 00 01 addl $0x1,(%eax) ; local[fc] ++
1c2: 83 7d fc 07 cmpl $0x7,0xfffffffc(%ebp) ; }
1c6: 7e e1 jle 0x1a9
1c8: eb 50 jmp 0x21a ; return
; }
1ca: 8b 45 08 mov 0x8(%ebp),%eax
1cd: 8b 40 04 mov 0x4(%eax),%eax
1d0: 83 f8 50 cmp $0x50,%eax ; if(pos == 80)
1d3: 75 0b jne 0x1e0 ; {
1d5: 8b 45 08 mov 0x8(%ebp),%eax
1d8: 89 04 24 mov %eax,(%esp)
1db: e8 70 ff ff ff call 0x150 ; accapo()
; }
1e0: 8b 45 08 mov 0x8(%ebp),%eax
1e3: 8b 48 0c mov 0xc(%eax),%ecx ; ecx = vidmem
1e6: 8b 45 08 mov 0x8(%ebp),%eax
1e9: 8b 50 04 mov 0x4(%eax),%edx ; edx = pos
1ec: 8b 45 08 mov 0x8(%ebp),%eax
1ef: 8b 40 08 mov 0x8(%eax),%eax ; eax = off
1f2: 8d 04 02 lea (%edx,%eax,1),%eax ; eax = pos + off
1f5: 01 c0 add %eax,%eax ; multiply with 2 (short)
1f7: 01 c1 add %eax,%ecx ; ecx (vidmem) += (pos + off)*2
1f9: 0f b6 45 ec movzbl 0xffffffec(%ebp),%eax
1fd: 66 0f b6 d0 movzbw %al,%dx ; dx = param0
201: 8b 45 08 mov 0x8(%ebp),%eax
204: 8b 00 mov (%eax),%eax ; eax = col
206: 09 d0 or %edx,%eax ; eax |= param0
208: 66 89 01 mov %ax,(%ecx) ; *vidmem = col | param0
20b: 8b 45 08 mov 0x8(%ebp),%eax
20e: 8b 40 04 mov 0x4(%eax),%eax
211: 8d 50 01 lea 0x1(%eax),%edx
214: 8b 45 08 mov 0x8(%ebp),%eax
217: 89 50 04 mov %edx,0x4(%eax) ; pos ++
21a: c9 leave ; leave stackframe
21b: c3 ret ; return
Video::Clear()
21c: 55 push %ebp
21d: 89 e5 mov %esp,%ebp
21f: 83 ec 18 sub $0x18,%esp ; reserve 6 locals
222: 8b 45 08 mov 0x8(%ebp),%eax
225: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) ; pos = 0
22c: 8b 45 08 mov 0x8(%ebp),%eax
22f: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) ; off = 0
236: c7 45 fc 00 00 00 00 movl $0x0,0xfffffffc(%ebp) ; local[fc] = 0
23d: eb 19 jmp 0x258 ; while(local[fc] < 0x7cf)
; {
23f: c7 44 24 04 20 00 00 movl $0x20,0x4(%esp) ; push char ' '
246: 00
247: 8b 45 08 mov 0x8(%ebp),%eax
24a: 89 04 24 mov %eax,(%esp) ; push this
24d: e8 1c ff ff ff call 0x16e ; call put
252: 8d 45 fc lea 0xfffffffc(%ebp),%eax
255: 83 00 01 addl $0x1,(%eax) ; local[fc]++
258: 81 7d fc cf 07 00 00 cmpl $0x7cf,0xfffffffc(%ebp)
25f: 7e de jle 0x23f ; }
261: 8b 45 08 mov 0x8(%ebp),%eax
264: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) ; pos = 0
26b: 8b 45 08 mov 0x8(%ebp),%eax
26e: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) ; off = 0
275: c9 leave
276: c3 ret ; return
277: 90 nop
void Video::put(const char* c)
278: 55 push %ebp
279: 89 e5 mov %esp,%ebp
27b: 83 ec 18 sub $0x18,%esp ; reserve 6 locals
27e: 8b 45 0c mov 0xc(%ebp),%eax ; eax = param0
281: 89 45 f8 mov %eax,0xfffffff8(%ebp) ; local[f8] = param0
284: 8b 45 f8 mov 0xfffffff8(%ebp),%eax
287: 89 45 fc mov %eax,0xfffffffc(%ebp) ; local[fc] = param0
28a: eb 1e jmp 0x2aa ; if(*param0 != 0)
28c: 8b 45 fc mov 0xfffffffc(%ebp),%eax ; {
28f: 0f b6 00 movzbl (%eax),%eax
292: 0f be d0 movsbl %al,%edx ; edx = *param0
295: 8d 45 fc lea 0xfffffffc(%ebp),%eax
298: 83 00 01 addl $0x1,(%eax) ; param0 ++
29b: 89 54 24 04 mov %edx,0x4(%esp) ; push edx
29f: 8b 45 08 mov 0x8(%ebp),%eax
2a2: 89 04 24 mov %eax,(%esp) ; push this
2a5: e8 c4 fe ff ff call 0x16e ; call put
2aa: 8b 45 fc mov 0xfffffffc(%ebp),%eax
2ad: 0f b6 00 movzbl (%eax),%eax
2b0: 84 c0 test %al,%al
2b2: 75 d8 jne 0x28c ; }
2b4: c9 leave
2b5: c3 ret ; return
void Video::set(unsigned int kol)
2b6: 55 push %ebp ; setup stack-frame
2b7: 89 e5 mov %esp,%ebp
2b9: 8b 55 08 mov 0x8(%ebp),%edx ; edx = this = &this[0]
2bc: 8b 45 0c mov 0xc(%ebp),%eax ; eax = param0
2bf: 89 02 mov %eax,(%edx) ; col = param0
2c1: 5d pop %ebp
2c2: c3 ret ; return
That's only true for the first string. The second line actually doesn't even make it past the 76th charater, and I'm quite sure that this trend would continue for a 3rd or 4th string. Apart from that the newline character at the end of the string should get "printed" regardless of the screen position.Your video writing code is not making past 78 characters, do some internal tests on the value of your pointers (i.e. hard write "pos + off" on screen somewhere for each character written).
That actually means hidding a bug..I would also suggest changing "if(pos == 80)" to "if(pos > 79)"... never assume things will work perfectly... that is when really nasty and annoying bugs start to pop up.
regards,
gaf