I disagree with the term "it works perfectly". The first set, specifically:AlexKuz wrote: This code doesn't work:But this code works perfectly:Code: Select all
unsigned short* vmem = (unsigned short*)0xb8000; void lmain() { for (unsigned int i = 0; i < 80 * 24; i++) vmem[i] = 0; while (1); }
Code: Select all
unsigned short* vmem; void lmain() { vmem = (unsigned short*)0xb8000; for (unsigned int i = 0; i < 80 * 24; i++) vmem[i] = 0; while (1); }
Code: Select all
unsigned short* vmem = (unsigned short*)0xb8000;
Then when you do:
Code: Select all
vmem[i] = 0;
Code: Select all
mov DS:[vmem+i*2], 0
Now, the reason why you think
Code: Select all
vmem = (unsigned short*)0xb8000;
Without looking any further, I would almost guaranty that you do not have your segments/selectors set up correctly. i.e.: DS doesn't pointer where you think it does at the start of your C code.
Compile it as is, but place
Code: Select all
_asm xchg bx,bx // or what ever your compiler needs
If you don't use Bochs, make your emulator of choice crash or have an infinite loop, then stop the emulator. The emulator should print out the segment register values at end of emulation.
Anyway, some how find out what these values are and you will find out they are not what you think they should be.
Ben