1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-23 03:29:39 +00:00
8bitworkshop/presets/sms-sms-libcv/mode4test.c

122 lines
3.1 KiB
C
Raw Normal View History

#include <cv.h>
#include <cvu.h>
2019-12-14 15:50:57 +00:00
// SMS doesn't have a BIOS
// so we have to link in a pattern table
2019-08-06 22:52:52 +00:00
#ifdef CV_SMS
//#link "fonts.s"
extern uintptr_t font_bitmap_a[];
extern uintptr_t font_bitmap_0[];
#endif
2019-12-14 15:50:57 +00:00
// HALT waits for a 60 Hz interrupt
2019-08-06 22:52:52 +00:00
#define wait_vsync() __asm__("halt")
2019-12-14 15:50:57 +00:00
// VRAM table addresses
#define PATTERN 0x0000 // 256*8 = 2048 bytes
2019-08-06 22:52:52 +00:00
#define IMAGE 0x2000 // 32*24 = 768 bytes
#define COLOR 0x0b00 // 32 bytes
#define SPRITE_PATTERNS 0x3800 // 32*32 = 1024 bytes
#define SPRITES 0x3c00 // 4*32 = 128 bytes
2022-08-29 03:16:17 +00:00
#ifdef __PLATFORM_SMS_GG_LIBCV__
/*{pal:444,n:32}*/
const short PALETTE[32] = {
0x2221, 0x4441, 0x6661, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0x2222, 0x4444, 0x6666, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0x2222, 0x4444, 0x6666, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
0x2222, 0x4444, 0x6666, 0x8888, 0xaaaa, 0xcccc, 0xeeee, 0xffff,
};
#else
/*{pal:222,n:32}*/
const char PALETTE[32] = {
2019-12-14 15:50:57 +00:00
0x10, 0x03, 0x0B, 0x0F, 0x13, 0x17, 0x1B, 0x1F,
0x22, 0x28, 0x2A, 0x2E, 0x30, 0x37, 0x3B, 0x3F,
0x10, 0x03, 0x0B, 0x0F, 0x13, 0x17, 0x1B, 0x1F,
0x22, 0x28, 0x2A, 0x2E, 0x30, 0x37, 0x3B, 0x3F,
};
2022-08-29 03:16:17 +00:00
#endif
2019-08-06 22:52:52 +00:00
/*{w:8,h:8,bpp:1,count:2,brev:1,np:4,pofs:1,sl:4}*/
const char PATTERNS[64] = {
2019-12-14 15:50:57 +00:00
0x7C, 0x1C, 0x64, 0x64,
0xFE, 0x7E, 0xFE, 0xFE,
0xD6, 0x7E, 0xD6, 0xD6,
0xFE, 0x7E, 0xFE, 0xFE,
0x66, 0xE6, 0xE6, 0xE6,
0xBC, 0xBC, 0xBC, 0x3C,
0x18, 0x18, 0x3E, 0x18,
0x7F, 0x18, 0x67, 0x18,
2019-08-06 22:52:52 +00:00
2019-12-14 15:50:57 +00:00
0x7D, 0x3C, 0x02, 0x3C,
0x7D, 0x3C, 0x9A, 0x3C,
0x7C, 0x3C, 0x83, 0x3C,
0x7E, 0x3C, 0x81, 0x3C,
0x3E, 0x3E, 0x00, 0x00,
0x36, 0x36, 0x00, 0x00,
0x36, 0x36, 0x00, 0x00,
0x00, 0x77, 0x77, 0x77,
2019-08-06 22:52:52 +00:00
};
2019-12-14 15:50:57 +00:00
// convert a mono bitmap to 4-plane
// just copy each byte 4 times
2019-08-06 22:52:52 +00:00
void expand_monobitmap(const char* src, int count) {
while (count--) {
char b = *src++;
cv_voutb(b);
cv_voutb(b);
cv_voutb(b);
cv_voutb(b);
}
}
2019-12-14 15:50:57 +00:00
// set up mode 4 graphics
void setup_graphics() {
cv_set_screen_mode(CV_SCREENMODE_4);
2019-12-14 15:50:57 +00:00
// set up tables
cv_set_character_pattern_t(PATTERN | 0x3000); // mask for mode 4
cv_set_image_table(IMAGE | 0x400); // mask for mode 4
2019-08-06 22:52:52 +00:00
cv_set_sprite_attribute_table(SPRITES);
cv_set_write_vram_address(PATTERN + '0'*32);
2019-12-14 15:50:57 +00:00
// convert mono bitmap font to 4-plane in VRAM
2019-08-06 22:52:52 +00:00
expand_monobitmap(font_bitmap_0, (128-48)*8);
2019-12-14 15:50:57 +00:00
// copy sprites to pattern table VRAM
cvu_memtovmemcpy(PATTERN+32, PATTERNS, sizeof(PATTERNS));
// copy palettes to VRAM
2022-08-29 03:16:17 +00:00
cvu_memtocmemcpy(0xc000, PALETTE, sizeof(PALETTE));
}
2019-12-14 15:50:57 +00:00
// image table has two bytes per cell (name + attribute)
void show_text() {
2019-08-06 22:52:52 +00:00
cvu_vmemset(IMAGE, 0, 32*28);
2019-12-14 15:50:57 +00:00
cvu_memtovmemcpy(IMAGE, "H e l l o W o r l d \1 ", 12*2);
}
void main() {
char i=0;
2019-08-06 22:52:52 +00:00
struct cvu_sprite4 sprite;
2019-12-14 15:50:57 +00:00
// set up mode 4 and draw initial text
setup_graphics();
show_text();
2019-12-14 15:50:57 +00:00
// turn on screen
cv_set_screen_active(true);
2019-12-14 15:50:57 +00:00
// loop (once per frame)
while (1) {
2019-08-06 22:52:52 +00:00
wait_vsync();
i++;
2019-12-14 15:50:57 +00:00
// scroll background in two directions
2019-08-06 22:52:52 +00:00
cv_set_hscroll(i);
cv_set_vscroll(i);
2019-12-14 15:50:57 +00:00
// move sprite across screen
2019-08-06 22:52:52 +00:00
sprite.y = i;
sprite.x = i;
sprite.name = 1;
cvu_set_sprite4(SPRITES, 0, &sprite);
2019-12-14 15:50:57 +00:00
sprite.y += 8;
sprite.name++;
cvu_set_sprite4(SPRITES, 1, &sprite);
}
}