Skip to content

Commit 6bb5c74

Browse files
committed
Refactor
1 parent e6d7d84 commit 6bb5c74

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPOS\Service\BIOS\IO\PrintConstantString;
6+
7+
use PHPOS\Architecture\Register\DataRegisterWithHighAndLowInterface;
8+
use PHPOS\Architecture\Register\RegisterType;
9+
use PHPOS\Operation\Int_;
10+
use PHPOS\Operation\Mov;
11+
use PHPOS\OS\Instruction;
12+
use PHPOS\OS\InstructionInterface;
13+
use PHPOS\Service\BaseService;
14+
use PHPOS\Service\BIOS\BIOS;
15+
use PHPOS\Service\ServiceInterface;
16+
use PHPOS\Service\ServiceManagerInterface;
17+
18+
class PrintNewLine implements ServiceInterface
19+
{
20+
use BaseService;
21+
22+
public function process(ServiceManagerInterface $serviceManager): InstructionInterface
23+
{
24+
$registers = $this->code->architecture()->runtime()->registers();
25+
$ax = $registers->get(RegisterType::ACCUMULATOR_BITS_16);
26+
assert($ax instanceof DataRegisterWithHighAndLowInterface);
27+
28+
return (new Instruction($this->code, $serviceManager))
29+
->label(
30+
$this->label(),
31+
fn (InstructionInterface $instruction) => $instruction
32+
->append(Mov::class, $ax->high(), 0x0E)
33+
->append(Mov::class, $ax->low(), 0x0D)
34+
->append(Int_::class, BIOS::VIDEO_INTERRUPT->value)
35+
36+
->append(Mov::class, $ax->high(), 0x0E)
37+
->append(Mov::class, $ax->low(), 0x0A)
38+
->append(Int_::class, BIOS::VIDEO_INTERRUPT->value)
39+
);
40+
}
41+
}

src/Service/BIOS/IO/ReadString/ReadString.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPOS\Architecture\Register\DataRegisterWithHighAndLowInterface;
88
use PHPOS\Architecture\Register\IndexRegisterInterface;
99
use PHPOS\Architecture\Register\RegisterType;
10+
use PHPOS\Operation\Call;
1011
use PHPOS\Operation\Cmp;
1112
use PHPOS\Operation\Inc;
1213
use PHPOS\Operation\Int_;
@@ -64,6 +65,8 @@ public function process(ServiceManagerInterface $serviceManager): InstructionInt
6465
$this->label(),
6566
fn (InstructionInterface $instruction) => $instruction
6667
->append(Mov::class, $di->index(), $buffer->name())
68+
->append(Call::class, $this->label() . '_char_read')
69+
->append(Jmp::class, $this->label() . '_done')
6770
->label(
6871
$this->label() . '_char_read',
6972
fn (InstructionInterface $instruction) => $instruction
@@ -87,6 +90,7 @@ public function process(ServiceManagerInterface $serviceManager): InstructionInt
8790
->append(Ret::class),
8891
)
8992
),
90-
);
93+
)
94+
->label($this->label() . '_done');
9195
}
9296
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PHPOS\Service\BIOS\VESABIOSExtension;
6+
7+
use PHPOS\Architecture\Register\DataRegisterWithHighAndLowInterface;
8+
use PHPOS\Architecture\Register\RegisterType;
9+
use PHPOS\Operation\Int_;
10+
use PHPOS\Operation\Mov;
11+
use PHPOS\OS\Instruction;
12+
use PHPOS\OS\InstructionInterface;
13+
use PHPOS\Service\BaseService;
14+
use PHPOS\Service\BIOS\BIOS;
15+
use PHPOS\Service\ServiceInterface;
16+
use PHPOS\Service\ServiceManagerInterface;
17+
18+
class TextMode implements ServiceInterface
19+
{
20+
use BaseService;
21+
22+
public function process(ServiceManagerInterface $serviceManager): InstructionInterface
23+
{
24+
$registers = $this->code->architecture()->runtime()->registers();
25+
$ax = $registers->get(RegisterType::ACCUMULATOR_BITS_16);
26+
assert($ax instanceof DataRegisterWithHighAndLowInterface);
27+
28+
return (new Instruction($this->code, $serviceManager))
29+
->label(
30+
$this->label(),
31+
fn (InstructionInterface $instruction) => $instruction
32+
->append(Mov::class, $ax->value(), 0x03)
33+
->append(Int_::class, BIOS::VIDEO_INTERRUPT->value)
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)