builtin scroll

This commit is contained in:
sfja 2026-11-22 01:36:51 +01:00
parent b5d8ad7559
commit 248f59c6c3
4 changed files with 35 additions and 16 deletions

View File

@ -13,14 +13,17 @@
@const KBD_KEYDOWN_HANDLER 0xff12
@const KBD_KEYUP_HANDLER 0xff13
@const VCD_CTL 0xff30
@const VCD_BEGIN 0xfb00
@const VCD_CTL_SCROLL 1 << 1
@const DISK_STATUS 0xff20
@const DISK_CTL 0xff21
@const DISK_BLOCK_ID 0xff22
@const DISK_ADDR 0xff23
@const DISK_CTL_DIRECTION 1 << 0
@const DISK_CTL_START 1 << 1
@const DISK_CTL_DIRECTION 1 << 0
@const DISK_CTL_START 1 << 1
@end

View File

@ -36,10 +36,8 @@ putc:
ret
.scroll:
mov r1, VCD_BEGIN
mov r2, VCD_BEGIN + vcd_width
mov r3, vcd_width * (vcd_height - 1)
call memmove
mov r1, VCD_CTL_SCROLL
mov [VCD_CTL], r1
mov r1, VCD_BEGIN + vcd_width * (vcd_height - 1)
mov r2, 0

View File

@ -107,4 +107,10 @@ character buffer starts at fb00
character = fb00 + (y * 40 + x)
ff30 ctl
## ctl
0 reserved
1 scroll

View File

@ -111,10 +111,10 @@ static uint16_t vm_arith(Opcode ty, uint16_t l, uint16_t r)
}
}
static void vm_disk_control(VM *vm, VMState *s, uint16_t control)
static void vm_disk_ctl(VM *vm, VMState *s, uint16_t ctl)
{
bool is_write = control & 1;
bool start = control >> 1 & 1;
bool is_write = ctl & 1;
bool start = ctl >> 1 & 1;
if (!start)
return;
@ -130,6 +130,20 @@ static void vm_disk_control(VM *vm, VMState *s, uint16_t control)
}
}
static void vm_vcd_ctl(VM *vm, VMState *s, uint16_t ctl)
{
(void)vm;
bool scroll = ctl >> 1 & 1;
if (scroll) {
memmove(&s->memory[0xfb00],
&s->memory[0xfb00 + 40 * 1],
sizeof(uint16_t) * 40 * 24);
vm->vcd_updated = true;
}
}
static void vm_run_op(VM *vm, VMState *s, const Op *op)
{
uint16_t *fl = &s->regs[Reg_Fl];
@ -160,12 +174,11 @@ static void vm_run_op(VM *vm, VMState *s, const Op *op)
case Op_Store: {
uint16_t addr = op2_reg_or_imm(s, op);
if (addr == 0xff21) {
vm_disk_control(vm, s, s->regs[op->op1_reg]);
break;
}
if (addr >= 0xfb00 && addr <= 0xfb00 + 40 * 25)
if (addr == 0xff21)
vm_disk_ctl(vm, s, s->regs[op->op1_reg]);
else if (addr == 0xff30)
vm_vcd_ctl(vm, s, s->regs[op->op1_reg]);
else if (addr >= 0xfb00 && addr <= 0xfb00 + 40 * 25)
vm->vcd_updated = true;
s->memory[addr] = s->regs[op->op1_reg];
@ -295,7 +308,6 @@ void vm_run(VM *vm)
vm->state = s;
mtx_unlock(&vm->mtx);
thrd_sleep(&(struct timespec) { .tv_nsec = 100000 }, NULL);
}
}