#include <libBAG_types.h>
#include <ds2io.h>
#include "sdk.h"

#include "string.h"
/*
Fast flip screen function 
*/
extern struct main_buf *pmain_buf;
extern int update_buf(int bufnum);
extern void *get_buf_from_bufnum(int buffer);

inline void BAG_FlipScreen(enum SCREEN_ID screen_num){
	if(screen_num == UP_SCREEN || screen_num == DUAL_SCREEN){
		pmain_buf->buf_st_list[buf_video_up_0].isused = 0;
		update_buf(buf_video_up_0);
		up_screen_addr = (void*)get_buf_from_bufnum(buf_video_up_0);
	}
	if(screen_num == DOWN_SCREEN || screen_num == DUAL_SCREEN){
		pmain_buf->buf_st_list[buf_video_down_0].isused = 0;
		update_buf(buf_video_down_0);
		down_screen_addr = (void*)get_buf_from_bufnum(buf_video_down_0);
	}
}	

inline void BAG_ClearAllScreenMemory(void){
	up_screen_addr = (void*)get_buf_from_bufnum(buf_video_up_0);
	memset(up_screen_addr, 0, (SCREEN_WIDTH * SCREEN_HEIGHT) << 1);
	update_buf(buf_video_up_0);
	
	up_screen_addr = (void*)get_buf_from_bufnum(buf_video_up_1);
	memset(up_screen_addr, 0, (SCREEN_WIDTH * SCREEN_HEIGHT) << 1);
	update_buf(buf_video_up_1);

	down_screen_addr = (void*)get_buf_from_bufnum(buf_video_down_0);
	memset(down_screen_addr, 0, (SCREEN_WIDTH * SCREEN_HEIGHT) << 1);
	update_buf(buf_video_down_0);

	down_screen_addr = (void*)get_buf_from_bufnum(buf_video_down_1);
	memset(down_screen_addr, 0, (SCREEN_WIDTH * SCREEN_HEIGHT) << 1);
	update_buf(buf_video_down_1);
}
