Add (soft) video abstraction library.

This commit is contained in:
giomba 2023-10-22 11:38:45 +02:00
parent b3763de255
commit 99da9e2e4f
3 changed files with 64 additions and 0 deletions

28
src/video.c Normal file
View File

@ -0,0 +1,28 @@
#include "video.h"
#include <stdint.h>
static char *const VIDEO_MEMORY = (char *)0xd000;
static uint16_t offset = 0;
void video_putchar(char c) {
if (c == '\n' || c == '\r') {
offset += 80 - (offset % 80);
} else if (c == '\t') {
offset += 8 - offset % 8;
} else {
*(VIDEO_MEMORY + offset++) = c;
}
offset = offset % 2000;
}
void video_put(uint8_t x, uint8_t y, char c) {
if (x >= 80)
return;
if (y >= 25)
return;
*(VIDEO_MEMORY + x + y * 80) = c;
}

10
src/video.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef CEDA_PRINT_H
#define CEDA_PRINT_H
#include <stdint.h>
void video_cls(void);
void video_put(uint8_t x, uint8_t y, char c);
void video_putchar(char c);
#endif // CEDA_PRINT_H

26
src/video_a.asm Normal file
View File

@ -0,0 +1,26 @@
SECTION code
PUBLIC _video_cls
_video_cls:
push af
push bc
push de
push hl
ld hl,$d000
ld de,2000
ld c,$20
_video_cls_loop:
ld (hl),c
inc hl
dec de
ld a,d
or e
jp nz,_video_cls_loop
pop hl
pop de
pop bc
pop af
ret