2019-02-24 15:36:38 +00:00
|
|
|
|
|
|
|
#include "neslib.h"
|
|
|
|
#include "vrambuf.h"
|
2019-04-05 12:58:26 +00:00
|
|
|
#include <string.h>
|
2019-02-24 15:36:38 +00:00
|
|
|
|
|
|
|
// index to end of buffer
|
|
|
|
byte updptr = 0;
|
|
|
|
|
2019-03-06 20:54:37 +00:00
|
|
|
// add EOF marker to buffer (but don't increment pointer)
|
2019-04-07 16:33:01 +00:00
|
|
|
void vrambuf_end(void) {
|
2019-03-10 16:17:12 +00:00
|
|
|
VRAMBUF_SET(NT_UPD_EOF);
|
2019-02-24 15:36:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 20:54:37 +00:00
|
|
|
// clear vram buffer and place EOF marker
|
2019-04-07 16:33:01 +00:00
|
|
|
void vrambuf_clear(void) {
|
2019-02-24 15:36:38 +00:00
|
|
|
updptr = 0;
|
2019-04-07 16:33:01 +00:00
|
|
|
vrambuf_end();
|
2019-02-24 15:36:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 20:54:37 +00:00
|
|
|
// wait for next frame, then clear buffer
|
|
|
|
// this assumes the NMI will call flush_vram_update()
|
2019-04-07 16:33:01 +00:00
|
|
|
void vrambuf_flush(void) {
|
2019-02-24 15:36:38 +00:00
|
|
|
// make sure buffer has EOF marker
|
2019-04-07 16:33:01 +00:00
|
|
|
vrambuf_end();
|
2019-02-24 15:36:38 +00:00
|
|
|
// wait for next frame to flush update buffer
|
|
|
|
// this will also set the scroll registers properly
|
|
|
|
ppu_wait_frame();
|
|
|
|
// clear the buffer
|
2019-04-07 16:33:01 +00:00
|
|
|
vrambuf_clear();
|
2019-02-24 15:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add multiple characters to update buffer
|
|
|
|
// using horizontal increment
|
2019-04-07 16:33:01 +00:00
|
|
|
void vrambuf_put(word addr, register const char* str, byte len) {
|
2019-03-04 14:35:33 +00:00
|
|
|
// if bytes won't fit, wait for vsync and flush buffer
|
2019-04-05 12:58:26 +00:00
|
|
|
if (VBUFSIZE-4-len < updptr) {
|
2019-04-07 16:33:01 +00:00
|
|
|
vrambuf_flush();
|
2019-04-05 12:58:26 +00:00
|
|
|
}
|
2019-03-04 14:35:33 +00:00
|
|
|
// add vram address
|
2019-03-06 20:54:37 +00:00
|
|
|
VRAMBUF_ADD((addr >> 8) ^ NT_UPD_HORZ);
|
|
|
|
VRAMBUF_ADD(addr); // only lower 8 bits
|
2019-03-04 14:35:33 +00:00
|
|
|
// add length
|
2019-03-06 20:54:37 +00:00
|
|
|
VRAMBUF_ADD(len);
|
2019-04-05 12:58:26 +00:00
|
|
|
// add data to buffer
|
|
|
|
memcpy(updbuf+updptr, str, len);
|
|
|
|
updptr += len;
|
2019-03-06 20:54:37 +00:00
|
|
|
// place EOF mark
|
2019-04-07 16:33:01 +00:00
|
|
|
vrambuf_end();
|
2019-02-24 15:36:38 +00:00
|
|
|
}
|