Add some attribute handling for video module.

This commit is contained in:
giomba 2023-11-20 21:16:13 +01:00
parent e70a9b9cc4
commit 41174485b8
3 changed files with 75 additions and 5 deletions

View File

@ -1,20 +1,63 @@
#include "video.h" #include "video.h"
#include "io.h"
#include <stdint.h> #include <stdint.h>
char *const VIDEO_MEMORY = (char *)0xd000; char *const VIDEO_MEMORY = (char *)0xd000;
static uint16_t offset = 0; static uint16_t offset = 0;
static bool hstretch = false;
static bool vstretch = false;
void video_putchar(char c) { void video_locate(uint8_t row, uint8_t column) {
if (c == '\n' || c == '\r') { offset = (uint16_t)row * 80 + column;
offset += 80 - (offset % 80);
} else if (c == '\t') {
offset += 8 - offset % 8;
} else {
*(VIDEO_MEMORY + offset++) = c;
} }
void video_enableHorizontalStretch(bool enable) {
hstretch = enable;
}
void video_enableVerticalStretch(bool enable) {
vstretch = enable;
}
void video_putchar(char c) {
// TODO(giomba): this function is not very consistent :sweat:
if (c == '\n' || c == '\r') {
offset += 80 - (offset % 80);
goto end;
}
if (hstretch) {
io_out(0x81, io_in(0x81) | 0x80);
*(VIDEO_MEMORY + offset) |= 0x08;
io_out(0x81, io_in(0x81) & ~0x80);
}
if (c == '\t') {
offset += 8 - offset % 8;
goto end;
}
*(VIDEO_MEMORY + offset) = c;
if (vstretch) {
*(VIDEO_MEMORY + offset + 80) = c;
io_out(0x81, io_in(0x81) | 0x80);
*(VIDEO_MEMORY + offset) |= 0x60;
*(VIDEO_MEMORY + offset + 80) |= 0x70;
if (hstretch)
*(VIDEO_MEMORY + offset + 80) |= 0x08;
io_out(0x81, io_in(0x81) & ~0x80);
}
++offset;
if (hstretch)
++offset;
end:
offset = offset % 2000; offset = offset % 2000;
} }

View File

@ -1,12 +1,16 @@
#ifndef CEDA_PRINT_H #ifndef CEDA_PRINT_H
#define CEDA_PRINT_H #define CEDA_PRINT_H
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
extern char *const VIDEO_MEMORY; extern char *const VIDEO_MEMORY;
void video_cls(void); void video_cls(void);
void video_put(uint8_t x, uint8_t y, char c); void video_put(uint8_t x, uint8_t y, char c);
void video_locate(uint8_t row, uint8_t column);
void video_enableHorizontalStretch(bool enable);
void video_enableVerticalStretch(bool enable);
void video_putchar(char c); void video_putchar(char c);
#endif // CEDA_PRINT_H #endif // CEDA_PRINT_H

View File

@ -7,6 +7,7 @@ _video_cls:
push de push de
push hl push hl
; clear chars
ld hl,$d000 ld hl,$d000
ld de,2000 ld de,2000
ld c,$20 ld c,$20
@ -18,6 +19,28 @@ _video_cls_loop:
or e or e
jp nz,_video_cls_loop jp nz,_video_cls_loop
; enable attr video bank
in a,($81)
or a,$80
out ($81),a
; clear attributes
ld hl,$d000
ld de,2000
ld c,$00
_video_attr_cls_loop:
ld (hl),c
inc hl
dec de
ld a,d
or e
jp nz,_video_attr_cls_loop
; restore char video bank
in a,($81)
and a,$7f
out ($81),a
pop hl pop hl
pop de pop de
pop bc pop bc