Skip to content

Commit db41a16

Browse files
committed
apple2video: fix low-memory -ramsize crash by protecting HGR reads
1 parent 24db213 commit db41a16

6 files changed

Lines changed: 34 additions & 18 deletions

File tree

src/mame/apple/apple2.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ void apple2_state::machine_start()
315315
save_item(NAME(m_reset_latch));
316316

317317
// setup video pointers
318-
m_video->set_ram_pointers(m_ram_ptr, m_ram_ptr);
318+
m_video->set_ram_pointers(m_ram_ptr, nullptr);
319+
m_video->set_ram_masks(m_ram_size-1, 0);
319320
m_video->set_char_pointer(memregion("gfx1")->base(), memregion("gfx1")->bytes());
320321
}
321322

src/mame/apple/apple2e.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ void apple2e_state::machine_start()
990990

991991
// setup video pointers
992992
m_video->set_ram_pointers(m_ram_ptr, m_aux_ptr);
993-
m_video->set_aux_mask(m_aux_mask);
993+
m_video->set_ram_masks(0xffff, m_aux_mask);
994994
m_video->set_char_pointer(memregion("gfx1")->base(), memregion("gfx1")->bytes());
995995

996996
// IOU events occur at the rightmost edge of active video

src/mame/apple/apple2video.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -833,19 +833,34 @@ void a2_video_device::hgr_update(screen_device &screen, bitmap_ind16 &bitmap, co
833833
for (int row = beginrow; row <= endrow; row++)
834834
{
835835
unsigned const address = start_address + (((row/8) & 0x07) << 7) + (((row/8) & 0x18) * 5) + ((row & 7) << 10);
836-
uint8_t const *const vram_row = &m_ram_ptr[address];
837-
838-
uint16_t words[40];
839-
840-
unsigned last_output_bit = 0;
841-
842-
for (int col = std::max(0, startcol-1); col < std::min(stopcol+1, 40); col++)
836+
static const uint16_t empty_words[40] =
843837
{
844-
unsigned word = double_7_bits[vram_row[col] & 0x7f];
845-
if (vram_row[col] & bit7_mask)
846-
word = (word * 2 + last_output_bit) & 0x3fff;
847-
words[col] = word;
848-
last_output_bit = word >> 13;
838+
// empty RAM socket causes TTL input to float high
839+
0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff,
840+
0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff,
841+
0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff,
842+
0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff,
843+
0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff, 0x3fff
844+
};
845+
uint16_t ram_words[40];
846+
uint16_t *words;
847+
848+
if (address > m_ram_mask)
849+
words = (uint16_t *)empty_words;
850+
else
851+
{
852+
uint8_t const *const vram_row = &m_ram_ptr[address];
853+
unsigned last_output_bit = 0;
854+
words = ram_words;
855+
856+
for (int col = std::max(0, startcol-1); col < std::min(stopcol+1, 40); col++)
857+
{
858+
unsigned word = double_7_bits[vram_row[col] & 0x7f];
859+
if (vram_row[col] & bit7_mask)
860+
word = (word * 2 + last_output_bit) & 0x3fff;
861+
words[col] = word;
862+
last_output_bit = word >> 13;
863+
}
849864
}
850865

851866
if (rgb_monitor())

src/mame/apple/apple2video.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class a2_video_device : public device_t, public device_palette_interface, public
6767

6868
void set_base_model(model base_model) { m_base_model = base_model; }
6969
void set_ram_pointers(u8 *main, u8 *aux) { m_ram_ptr = main; m_aux_ptr = aux; }
70-
void set_aux_mask(u16 aux_mask) { m_aux_mask = aux_mask; }
70+
void set_ram_masks(u16 ram_mask, u16 aux_mask) { m_ram_mask = ram_mask; m_aux_mask = aux_mask; }
7171
void set_hgr2(u16 hgr2) { m_hgr2 = hgr2; }
7272
void set_char_pointer(u8 *charptr, int size) { m_char_ptr = charptr; m_char_size = size; }
7373
void setup_GS_graphics() { m_8bit_graphics = std::make_unique<bitmap_ind16>(560, 192); }
@@ -120,7 +120,7 @@ class a2_video_device : public device_t, public device_palette_interface, public
120120
int monochrome_hue();
121121

122122
u8 *m_ram_ptr = nullptr, *m_aux_ptr = nullptr, *m_char_ptr = nullptr;
123-
u16 m_aux_mask = 0xffff;
123+
u16 m_ram_mask = 0xffff, m_aux_mask = 0xffff;
124124
u16 m_hgr2 = 0x4000;
125125
int m_char_size = 0;
126126
bool m_page2 = false;

src/mame/apple/superga2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void superga2_state::machine_start()
100100
save_item(NAME(m_speaker_state));
101101

102102
// setup video pointers
103-
m_video->set_ram_pointers(m_ram_ptr, m_ram_ptr);
103+
m_video->set_ram_pointers(m_ram_ptr, nullptr);
104104
m_video->set_char_pointer(nullptr, 0); // no text modes on this machine
105105
}
106106

src/mame/apple/tk2000.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void tk2000_state::machine_start()
150150
save_item(NAME(m_ctrl_key));
151151

152152
// setup video pointers
153-
m_video->set_ram_pointers(m_ram_ptr, m_ram_ptr);
153+
m_video->set_ram_pointers(m_ram_ptr, nullptr);
154154
m_video->set_char_pointer(nullptr, 0); // no text modes on this machine
155155
m_video->set_hgr2(0xa000);
156156
}

0 commit comments

Comments
 (0)