Sunday, 24 November 2013

EPROM images for BASIC on the Sega Master System

http://www.atkinsoft.com/sega.html

Here are the images I've used for running BASIC on the Master System.

Sega BASIC Level 2 (SC-3000) export header checksum removed.sms

Sega BASIC Level 3 V1 (SC-3000) export header checksum removed.sms

Sega BASIC Level 3 V1 (SC-3000) export header checksum removed 24K.sms

The first of these is BASIC Level 2 with the export header added and the jump for the checksum routine removed. This image runs as BASIC Level IIA with 515 bytes free on a machine with 2K (or more) internal RAM at $C000 - $FFFF, and as BASIC Level IIB with 2043 bytes free on a machine with 2K (or more) RAM at $8000 - $BFFF in addition to the RAM at $C000.

639C    C20963    JP NZ, 6309h // checksum first 32K - check bottom 8 bits of result is 0, jump to one beep error routine if not

becomes

639C    00    NOP
639D    00    NOP
639E    00    NOP

Header

7FF0    54 4D 52 20 53 45 47 41 20 20 A9 65 00 00 00 4C

The second is BASIC Level 3 with the export header added and the jump for the checksum routine removed. This image needs 16K of RAM at $8000 - $BFFF, and will run with 16K, 18K or 32K depending on how much RAM it finds at $C000 - $FFFF. It will run with 10236 bytes free if it finds no RAM at all at $C000, with 12284 bytes free if it finds 2K RAM at $C000 - $C7FF and with 26620 bytes free if it finds 16K RAM at $C000 - $FFFF. Those are the only possibilities it looks for. This image doesn't run on a Master System with 8K RAM at $C000 - $DFFF, because the RAM size detect routine only checks for a 2K SRAM at $C000 - $C7FF. Once that test passes, the routine assumes the machine has a full 16K RAM in $C000 - $FFFF and goes on to fail another memory test on the 8K mirror at $E000 - $FFFF.

689C    C20968    JP NZ, 6809h // checksum first 32K - check bottom 8 bits of result is 0, jump to one beep error routine if not

becomes

689C    00    NOP
689D    00    NOP
689E    00    NOP

Header

7FF0    54 4D 52 20 53 45 47 41 20 20 06 20 00 00 00 4C

The third is BASIC Level 3 with the export header, the checksum removed and the RAM detect routine modified for 8K of RAM at $C000 - $DFFF. This provides 24K of RAM in total for BASIC, and displays 18428 bytes free on the startup screen.

68F5    11FFC7    LD DE, C7FFh // check for RAM at C800h, de = last byte of RAM C7FFh

68FB    26C8     LD H, C8h // now try hl = C800h

becomes

68F5    11FFDF    LD DE, DFFFh // check for RAM at E000h, de = last byte of RAM DFFFh

68FB    26E0    LD H, E0h // now try hl = E000h

Header

7FF0    54 4D 52 20 53 45 47 41 20 20 36 20 00 00 00 4C

I have now also tried running a patched image of BASIC Level 3 that accesses port 3E and memory location FFFC on the Tototek flash cartridge. The idea here, assuming the Tototek cartridge emulates the 315-5235 mapper fully, is to disable the internal RAM and enable 32K of cartridge RAM, the first 16K at $C000 - $FFFF in place of the internal RAM, and the second 16K at $8000 - $BFFF. This used the following additional code:

0000    3EBB    LD A, BBh
0002    D33E    OUT (3Eh), A
0004    3E1C    LD A, 1Ch
0006    32FCFF    LD (FFFCh), A
0009    C30068    JP 6800h

instead of

0000    C30068    JP 6800h
0003    FF FF FF FF FF FF FF FF FF

Unfortunately the Tototek cartridge doesn't implement all of the 315-5235 mapper's functionality. 16K RAM appears at $8000 - $BFFF (bit 3 of FFFCh) but nothing appears at $C000 - $FFFF (bit 4 of FFFCh) once the internal RAM is disabled (using bit 4 of port 3Eh). BASIC does run but only detects 16K RAM.


It would be better to leave the internal RAM enabled and use the 24K patch to run BASIC Level 3 on the Tototek cartridge with the same 18428 bytes free as in the home built ROM and RAM cartridge.

No comments: