I thought it would be easy to load some data to the VDP but it's not working for me....

VDP register initialization works but I think the problem is the vwrite() function.
If i use printf's instead of the actual writes to v98 it seems that the values written are ok.
Can anybody see the problem?
/*
* Project Hunter for MSX1 32kb ROM
*/
#include <stdlib.h>
//#include <stdio.h>
/*
* DEFINITIONS
*/
#define u_int unsigned int
#define u_char unsigned char
#define u_short unsigned short
#define bool char
#define true 1
#define false 0
/*
* SCREEN 2 DEFINITIONS HARDCODED
*/
u_int SCREEN2_MAX = 768; // # Patterns in one screen
u_short PNT = 14336; // Pattern Name Table
u_short PGT = 0; // Pattern Generator Table
u_short PCT = 6144; // Pattern Color Table
u_short SAT = 15360; // Sprite Attribute Table
u_short SPT = 12288; // Sprite Pattern Table
/*
* PORT mappings
*/
static port u_char v99 @ 0x99; // VDP: Command and status register
static port u_char v98 @ 0x98; // VDP: Video RAM data
static port u_char va2 @ 0xa2; // PSG: Data read
static port u_char va1 @ 0xa1; // PSG: Data write
static port u_char va0 @ 0xa0; // PSG: Address latch
extern u_char back1[8];
extern u_char back1_color[8];
extern u_char vdpregs[8];
/*
* VPD functions
*/
void init_vpd(u_char *source) {
u_int x;
for (x=0; x < 8; x++) {
v99 = source[x];
v99 = x+128;
// printf("Reg %d : %d \n",x,source[x]);
}
}
void vwrite(u_short addr, u_char *source, u_int count) {
div_t x;
x = div(addr,256);
// printf("Set vdp write byte 1 : %d \n",x.rem);
// printf("Set vdp write byte 2 : %d \n",x.quot+64);
asm("di" );
v98 = x.quot+64;
v98 = x.rem;
for (;count > 0;count--){
v98 = source[count]; //write byte to port 98
// printf("Writing %d : %d\n",count,source[count]);
}
asm("ei" );
}
main()
{
u_int t;
u_char room[768];
init_vpd(vdpregs);
for (t=0;t < 768; t++) {
room[t]= t&255;
}
vwrite(PGT, back1, 8);
vwrite(PCT, back1_color, 8);
vwrite(PNT, room, SCREEN2_MAX);
while(true) {
}
}
// Data segement
#asm
psect data
global _vdpregs
_vdpregs:
defb 00000010B // Reg# 0 000000[M3][EV]
defb 11100010B // Reg# 1 [4/16k][BLANK][IE][M1][M2]0[SIZE][MAG]
defb 00001110B // Reg# 2 0000[NAME TABLE BASE ADDRESS] = 3C00h
defb 01100000B // Reg# 3 [COLOR BASE ADDRESS] 3000h
defb 00000000B // Reg# 4 00000[PATTERN GENERATOR BASE ADDRESS] 1800h
defb 01111000B // Reg# 5 0[SPRITE ATTRIBUTE TABLE BASE ADDRESS] 3C80h
defb 00000110B // Reg# 6 00000[SPRITE PTRN GNRTR BASE ADDRESS] 3800h
defb 11100000B // Reg# 7 [TEXT COLOR 4bts][BACKDROP COLOR 4bts]
global _back1
_back1:
defb 00011100B
defb 00110110B
defb 11000011B
defb 11010011B
defb 11001011B
defb 11000011B
defb 01100110B
defb 00111100B
global _back1_color
_back1_color:
defb 00001111B
defb 00001111B
defb 00001111B
defb 00001111B
defb 00001111B
defb 00001111B
defb 00001111B
defb 00001111B
#endasm