Skip to content

Commit e7938ec

Browse files
committed
more vga oop & levelization
1 parent 9290ca1 commit e7938ec

File tree

6 files changed

+83
-37
lines changed

6 files changed

+83
-37
lines changed

makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ vga_irq.obj: vga_irq.cpp vga_irq.hpp vga_reg.lib pc_pit.lib pc_cpu.lib
4848
vga_irq.lib: vga_irq.obj vga_reg.lib pc_pit.lib pc_cpu.lib
4949
$(LIB) $@ $<
5050

51-
vga_mode.obj: vga_mode.cpp vga_mode.hpp vga_reg.lib pc_bus.lib pc_cpu.lib
51+
vga_mode.obj: vga_mode.cpp vga_mode.hpp vga_reg.lib vga_bios.lib pc_bus.lib pc_cpu.lib
5252
$(CPP) $[@
53-
vga_mode.lib: vga_mode.obj vga_reg.lib pc_bus.lib pc_cpu.lib
53+
vga_mode.lib: vga_mode.obj vga_reg.lib vga_bios.lib pc_bus.lib pc_cpu.lib
5454
$(LIB) $@ $<
5555

56-
vga_reg.obj: vga_reg.cpp vga_reg.hpp pc_bus.lib
56+
vga_reg.obj: vga_reg.cpp vga_reg.hpp pc_bus.lib pc_cpu.lib
5757
$(CPP) $[@
58-
vga_reg.lib: vga_reg.obj pc_bus.lib
58+
vga_reg.lib: vga_reg.obj pc_bus.lib pc_cpu.lib
59+
$(LIB) $@ $<
60+
61+
vga_bios.obj: vga_bios.cpp vga_bios.hpp pc_bus.lib
62+
$(CPP) $[@
63+
vga_bios.lib: vga_bios.obj pc_bus.lib
5964
$(LIB) $@ $<
6065

6166
sb16.obj: sb16.cpp sb16.hpp pc_dma.lib pc_pic.lib pc_cpu.lib pc_bus.lib

vga_bios.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "vga_bios.hpp"
2+
3+
#include <cstdint>
4+
5+
#include "i86.h" // int386
6+
7+
using std::uint8_t;
8+
9+
namespace rqdq {
10+
namespace vga {
11+
12+
namespace bios {
13+
14+
void SetMode(uint8_t modeNum) {
15+
union REGS r;
16+
r.h.ah = 0; // set video mode
17+
r.h.al = modeNum;
18+
int386(0x10, &r, &r); }
19+
20+
21+
std::uint8_t GetMode() {
22+
union REGS r;
23+
r.h.ah = 0x0f; // get current video mode
24+
int386(0x10, &r, &r);
25+
return r.h.al; }
26+
27+
28+
} // namespace bios
29+
30+
31+
} // namespace vga
32+
} // namespace rqdq

vga_bios.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
#include <cstdint>
3+
4+
namespace rqdq {
5+
namespace vga {
6+
7+
namespace bios {
8+
9+
void SetMode(std::uint8_t modeNum);
10+
11+
std::uint8_t GetMode();
12+
13+
14+
} // namespace bios
15+
16+
17+
} // namespace vga
18+
} // namespace rqdq

vga_mode.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
11
#include "vga_mode.hpp"
22

3-
#include <i86.h> // int386
4-
53
#include "pc_bus.hpp"
64
#include "pc_cpu.hpp"
5+
#include "vga_bios.hpp"
76
#include "vga_reg.hpp"
87

98
namespace rqdq {
109
namespace vga {
1110

12-
13-
void SetBIOSMode(int num) {
14-
union REGS r;
15-
r.x.eax = num;
16-
int386(0x10, &r, &r); }
17-
18-
19-
class SequencerDisabledSection {
20-
public:
21-
SequencerDisabledSection(const pc::CriticalSection& cs) :cs(cs) {
22-
pc::TXdw(VP_SEQC, 0x100); } // clear bit 1, starting reset
23-
~SequencerDisabledSection() {
24-
pc::TXdw(VP_SEQC, 0x300); } // undo reset / restart sequencer)
25-
private:
26-
SequencerDisabledSection& operator=(const SequencerDisabledSection&); // non-copyable
27-
SequencerDisabledSection(const SequencerDisabledSection&); // non-copyable
28-
const pc::CriticalSection& cs; };
29-
30-
3111
/*
3212
* ModeX 320x240 initialization
3313
*
3414
* This is taken directly from M.Abrash's Mode-X .asm code
3515
*/
3616
void SetModeX() {
37-
SetBIOSMode(0x13);
17+
bios::SetMode(0x13);
3818
SpinUntilNextRetraceBegins();
3919

4020
pc::TXdw(VP_SEQC, 0x604); // disable chain4

vga_mode.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <cstdint>
33
#include <cstdlib>
44

5+
#include "vga_bios.hpp"
56
#include "vga_reg.hpp"
67

78
using std::uint8_t;
@@ -10,7 +11,7 @@ using std::uint16_t;
1011
namespace rqdq {
1112
namespace vga {
1213

13-
const int VM_TEXT = 3;
14+
const int VM_TEXT = 0x03;
1415
const int VM_MODE13 = 0x13;
1516
const int VM_MODEX = 0x100;
1617

@@ -26,27 +27,24 @@ const vga::VRAMPage modeXPages[2] = {
2627
{ 1, vga::VGAPTR + (320*240/4), 320*240/4 } };
2728

2829

29-
void SetBIOSMode(int num);
3030
void SetModeX();
3131

3232

3333
class ModeSetter {
3434
public:
35-
// XXX assume text-mode, need detection
36-
ModeSetter() :oldMode_(0x3), curMode_(oldMode_) {}
35+
ModeSetter()
36+
:oldMode_(bios::GetMode()),
37+
curMode_(oldMode_) {}
3738

3839
void Set(int req) {
39-
if (req == VM_TEXT) {
40-
vga::SetBIOSMode(0x3);
41-
curMode_ = VM_TEXT; }
42-
else if (req == VM_MODE13) {
43-
vga::SetBIOSMode(0x13);
44-
curMode_ = VM_MODE13; }
40+
if (req < 256) {
41+
bios::SetMode(req);
42+
curMode_ = req; }
4543
else if (req == VM_MODEX) {
4644
vga::SetModeX();
4745
curMode_ = VM_MODEX; }
4846
else {
49-
// XXX
47+
// xxx throw std::runtime_error("unsupported vga mode");
5048
std::exit(1); }}
5149

5250
~ModeSetter() {

vga_reg.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <cstdint>
66

77
#include "pc_bus.hpp"
8+
#include "pc_cpu.hpp"
89

910
using std::uint8_t;
1011
using std::uint16_t;
@@ -103,5 +104,17 @@ inline void SpinWhileHorizontalRetrace() {
103104
*/
104105

105106

107+
class SequencerDisabledSection {
108+
public:
109+
SequencerDisabledSection(const pc::CriticalSection& cs) :cs(cs) {
110+
pc::TXdw(VP_SEQC, 0x100); } // clear bit 1, starting reset
111+
~SequencerDisabledSection() {
112+
pc::TXdw(VP_SEQC, 0x300); } // undo reset / restart sequencer)
113+
private:
114+
SequencerDisabledSection& operator=(const SequencerDisabledSection&); // non-copyable
115+
SequencerDisabledSection(const SequencerDisabledSection&); // non-copyable
116+
const class pc::CriticalSection& cs; };
117+
118+
106119
} // namespace vga
107120
} // namespace rqdq

0 commit comments

Comments
 (0)