Import bootloader (and don't mess with hscroll)

This commit is contained in:
Gyorgy Szombathelyi
2019-01-03 16:45:47 +01:00
parent c7e0123982
commit 0843354a8c
9 changed files with 1929 additions and 3 deletions

48
SMSBootLoader/palette.inc Normal file
View File

@@ -0,0 +1,48 @@
;----------------------------------------------------------------------------
pal_table_bg_fade_0:
.db %00000000 ; 0: Black
.db %00000000 ; 1: Gray 1
.db %00000000 ; 2: Gray 2
.db %00000000 ; 3: White
.db %00000000 ; 4: Light Blue
;----------------------------------------------------------------------------
pal_table_bg_fade_1:
.db %00000000 ; 0: Black
.db %00000000 ; 1: Gray 1
.db %00000000 ; 2: Gray 2
.db %00010101 ; 3: White
.db %00010000 ; 4: Light Blue
;----------------------------------------------------------------------------
pal_table_bg_fade_2:
.db %00000000 ; 0: Black
.db %00000000 ; 1: Gray 1
.db %00010101 ; 2: Gray 2
.db %00101010 ; 3: White
.db %00100000 ; 4: Light Blue
;----------------------------------------------------------------------------
pal_table_bg:
.db %00000000 ; 0: Black
.db %00010101 ; 1: Gray 1
.db %00101010 ; 2: Gray 2
.db %00111111 ; 3: White
.db %00110000 ; 4: Light Blue
;----------------------------------------------------------------------------
pal_table_fg:
.db %00000000 ; 0: <UNUSED>
.db %00000000 ; 1: Black
.db %00000110 ; 2: Marron
.db %00000111 ; 3: Light Orange
.db %00011011 ; 4: Peach
.db %00001111 ; 5: Yellow
.db %00011001 ; 6: Green (background)
.db %00111111 ; 7: White
.db %00000000 ; 8: <UNUSED>
.db %00000000 ; 9: <UNUSED>
.db %00000000 ; 10: <UNUSED>
.db %00000000 ; 11: <UNUSED>
.db %00000000 ; 12: <UNUSED>
.db %00000000 ; 13: <UNUSED>
.db %00000000 ; 14: <UNUSED>
.db %00000000 ; 15: <UNUSED>
;----------------------------------------------------------------------------

99
SMSBootLoader/sms.inc Normal file
View File

@@ -0,0 +1,99 @@
;----------------------------------------------------------------------------
; Sega Master System & Game Gear basic definitions
; by Omar Cornut (Bock)
; Started on February 2001
; Last update: 10 November 2001
;----------------------------------------------------------------------------
; MEMORY --------------------------------------------------------------------
.DEFINE PAGE_SIZE $4000
.DEFINE PAGE_0 $0000
.DEFINE PAGE_1 (PAGE_0 + PAGE_SIZE)
.DEFINE PAGE_2 (PAGE_1 + PAGE_SIZE)
.DEFINE RAM $C000
.DEFINE RAM_LEN $1FF8
.DEFINE RAM_MIRROR $E000
.DEFINE REG_MAP_SRAM $FFFC
.DEFINE REG_MAP_0 $FFFD
.DEFINE REG_MAP_1 $FFFE
.DEFINE REG_MAP_2 $FFFF
;----------------------------------------------------------------------------
; VIDEO ---------------------------------------------------------------------
.DEFINE VDP_DATA $BE
.DEFINE VDP_ADDR $BF
.DEFINE VDP_STATUS $BF
.DEFINE VRAM_TILES $0000
.DEFINE VRAM_BG_MAP $3800
.DEFINE VRAM_SPR_MAP $3F00
.DEFINE VRAM_SPR_LAST 208
;----------------------------------------------------------------------------
.DEFINE VRAM_SIZE $4000
.DEFINE VRAM_TILE_SIZE 32 ; (8 * 8) * 4 bits = 32 bytes
;----------------------------------------------------------------------------
.DEFINE VREG_CONFIG0 $80
.DEFINE VREG_CONFIG1 $81
; ..
.DEFINE VREG_BORDER_COL $87
.DEFINE VREG_HSCROLL $88
.DEFINE VREG_VSCROLL $89
.DEFINE VREG_LINES_CNT $8A
;----------------------------------------------------------------------------
; INPUTS --------------------------------------------------------------------
.DEFINE PORT_INPUT1 $DC
.DEFINE P1_UP $01
.DEFINE P1_DOWN $02
.DEFINE P1_LEFT $04
.DEFINE P1_RIGHT $08
.DEFINE P1_BUTTON1 $10
.DEFINE P1_BUTTON2 $20
.DEFINE P2_UP $40
.DEFINE P2_DOWN $80
;----------------------------------------------------------------------------
.DEFINE P1_UP_BIT 0
.DEFINE P1_DOWN_BIT 1
.DEFINE P1_LEFT_BIT 2
.DEFINE P1_RIGHT_BIT 3
.DEFINE P1_BUTTON1_BIT 4
.DEFINE P1_BUTTON2_BIT 5
.DEFINE P2_UP_BIT 6
.DEFINE P2_DOWN_BIT 7
;----------------------------------------------------------------------------
.DEFINE PORT_INPUT2 $DD
.DEFINE P2_LEFT $01
.DEFINE P2_RIGHT $02
.DEFINE P2_BUTTON1 $04
.DEFINE P2_BUTTON2 $08
.DEFINE RESET_BUTTON $10
; Unused $20
.DEFINE LIGHTGUN1 $40
.DEFINE LIGHTGUN2 $80
;----------------------------------------------------------------------------
.DEFINE PORT_INPUTGG $00
.DEFINE START_BUTTON $80
;----------------------------------------------------------------------------
; SOUND ---------------------------------------------------------------------
.DEFINE PORT_PSG $7F
.DEFINE PORT_FM_ADDR $F0
.DEFINE PORT_FM_DATA $F1
.DEFINE PORT_FM_LATCH $F2
;----------------------------------------------------------------------------
; MISCELLANEOUS -------------------------------------------------------------
.DEFINE PORT_HARDWARE $3E
.DEFINE PORT_NATION $3F
.DEFINE PORT_VLINE $7E
.DEFINE PORT_HLINE $7F
;----------------------------------------------------------------------------
; HEADER --------------------------------------------------------------------
.DEFINE HEADER $7FF0
.DEFINE HEADER_ID $7FF0 ; TMR SEGA
; ..
.DEFINE HEADER_CHECKSUM $7FFA
; ..
.DEFINE HEADER_SYS_SIZE $7FFF
;----------------------------------------------------------------------------

222
SMSBootLoader/smsboot.asm Normal file
View File

@@ -0,0 +1,222 @@
;------------------------------------------------------------------------------
; SMS Boot 0.91
; by Omar Cornut (Bock)
; Last updated 28 December 2003
;------------------------------------------------------------------------------
.INCLUDE "sms.inc"
; WlaDX stuffs ----------------------------------------------------------------
.EMPTYFILL $00
.SMSTAG
.COMPUTESMSCHECKSUM
.MEMORYMAP
DEFAULTSLOT 0
SLOTSIZE PAGE_SIZE
SLOT 0 PAGE_0
SLOT 1 PAGE_1
.ENDME
.ROMBANKMAP
BANKSTOTAL 2
BANKSIZE PAGE_SIZE
BANKS 2
.ENDRO
.BANK 0 SLOT 0
;------------------------------------------------------------------------------
; Variables -------------------------------------------------------------------
.DEFINE VAR_frame_cnt (RAM + $1000) ; 1 byte
.DEFINE VAR_menu_slot (RAM + $1001) ; 1 byte
.DEFINE VAR_menu_sprite_y (RAM + $1002) ; 1 byte
;------------------------------------------------------------------------------
; Start -----------------------------------------------------------------------
.ORGA $0000
di
im 1
ld sp, $DFF0
jp start
;------------------------------------------------------------------------------
; Tools ---------------------------------------------------------------------
.ORGA $0010
vdp_write_de:
ld a, e
out (VDP_ADDR), a
ld a, d
out (VDP_ADDR), a
ret
.ORGA $0018
vdp_write_addr_de:
ld a, e
out (VDP_ADDR), a
ld a, d
or $40
out (VDP_ADDR), a
ret
.ORGA $0028
vdp_write_addr_hl:
ld a, l
out (VDP_ADDR), a
ld a, h
or $40
out (VDP_ADDR), a
ret
; Interrupt -------------------------------------------------------------------
.ORGA $0038
interrupt:
di
push af
in a, (VDP_STATUS)
and $80
jr z, interrupt_end
ld a, (VAR_frame_cnt)
inc a
ld (VAR_frame_cnt), a
interrupt_end:
pop af
ei
ret
;------------------------------------------------------------------------------
; NMI -------------------------------------------------------------------------
.ORGA $0066
reti
;------------------------------------------------------------------------------
; SDSC HEADER DATA ------------------------------------------------------------
sdsc_author: .db "wsoltys", 0
sdsc_program_name: .db "MiST Boot Loader", 0
sdsc_unused_but_stored: .db "v0.91", 0
;------------------------------------------------------------------------------
; VDP Library -----------------------------------------------------------------
.INCLUDE "vdp.asm"
; DATA ------------------------------------------------------------------------
tiles_data:
.INCLUDE "tiles.inc"
palette_data:
.INCLUDE "palette.inc"
;------------------------------------------------------------------------------
start:
call vdp_init
; Setup palette for fade start
ld a, 0
ld b, 5
ld hl, pal_table_bg_fade_0
call vdp_set_pal
; Load tiles
ld bc, VRAM_TILE_SIZE * GFX_LAST_TILE
ld hl, tiles_data
ld de, $0000 + (1 * VRAM_TILE_SIZE)
call vdp_load_data
; Draw SEGA logo to map
ld b, GFX_SEGA_SIZE_X
ld c, GFX_SEGA_SIZE_Y
ld d, GFX_SEGA_TILE
ld e, 0
ld hl, VRAM_BG_MAP + (10*2+(2)*32)
call vdp_bg_putimage
; Draw Master System logo to map
ld b, GFX_MASTERSYSTEM_SIZE_X
ld c, GFX_MASTERSYSTEM_SIZE_Y
ld d, GFX_MASTERSYSTEM_TILE
ld e, 0
ld hl, VRAM_BG_MAP + (4*2+(12)*32)
call vdp_bg_putimage
; Draw Boot Loader logo to map
ld b, GFX_BOOTLOADER_SIZE_X
ld c, GFX_BOOTLOADER_SIZE_Y
ld d, GFX_BOOTLOADER_TILE
ld e, 0
ld hl, VRAM_BG_MAP + (1*2+(22)*32)
call vdp_bg_putimage
; Draw SMS Power copyright to map
; ld b, GFX_SMSPOWER_SIZE_X
; ld c, GFX_SMSPOWER_SIZE_Y
; ld d, GFX_SMSPOWER_TILE - 256
; ld e, 1
; ld hl, VRAM_BG_MAP + (9*2+(42)*32)
call vdp_bg_putimage
; Reset horizontal scrolling
ld de, $8800
rst $10
; Enable display, 16x8 sprites & vblank
ld de, $81E2
rst $10
; Fade-in
xor a
ld b, 5
ld c, 4
ld d, 10
ld hl, pal_table_bg_fade_0
ei
call vdp_fade
di
; Enable display & 16x8 sprites, disable vblank
ld de, $81C2
rst $10
; Setup final palette
ld a, 16
ld b, 16
ld hl, pal_table_fg
call vdp_set_pal
wait_for_rom:
ld a, $3e
ld ($c700),a
ld a, $b8
ld ($c701),a ; ld a,$b8
ld a, $d3
ld ($c702),a
ld a, $3e ; out 3e,(a)
ld ($c703),a
ld a, $c3
ld ($c704),a
ld a, 00
ld ($c705),a
ld ($c706),a; jp 0
jp $c700
;------------------------------------------------------------------------------
boot_end:
.BANK 1 SLOT 1
; SDSC HEADER -----------------------------------------------------------------
.ORGA $7FE0
.DB "SDSC" ; Magic
.DB $00, $91 ; Version 0.91
.DB $12 ; 17
.DB $11 ; November
.DW $2001 ; 2001
.DW sdsc_author
.DW sdsc_program_name
.DW $FFFF
; CHECKSUM --------------------------------------------------------------------
.ORGA $7FF0
.DB "TMR SEGA" ; Trademark
.DW $0120 ; Year
.DW $0000 ; Checksum not correct
.DW $0000 ; Part Num not correct
.DB $01 ; Version
.DB $4C ; Master System, 32k

View File

@@ -0,0 +1,2 @@
[objects]
smsboot.o

54
SMSBootLoader/smsboot.txt Normal file
View File

@@ -0,0 +1,54 @@
-------------------------------------------
SMS Boot Loader 0.91
by Omar Cornut (Bock), for SMS Power 2001
E-mail: omar AT miracleworld DOT net
Web: http://www.smspower.org
-------------------------------------------
17 November 2001
v0.90: This is a beta release version of my SMS Boot Loader.
v0.91: Minor changes I can't remember!
This simple program, once run on an original Sega Master System, let
you choose and execute a program from one of the three available slots:
+-------------------------------------------------------------+
| System SMS1 SMS2+ MD-PBC |
+-------------------------------------------------------------+
| Cartridge slot yes yes yes |
| Card slot yes no yes |
| Expansion slot yes no no |
+-------------------------------------------------------------+
It has the advantage of not checking any country code or header, so
basically it is possible to boot up an original Japanese mycard game
(for SG-1000 or Mark III) on your US or European Master System 1.
You can also use it to boot Brasilian 8 megabits games which are
not supported by all models of Master System 1.
Last but not least, using a homemade pinout converter, it would be
possible the same way to boot up any SG-1000/SC-3000 or Mark III/SMS
cartridge.
The problem of course is to be able to run the actual SMS Boot Loader
on a real system. Easiest solution is to use a development cartridge,
but the most interesting one is to replace the machine BIOS by this
Boot Loader.
Things done:
Code run from RAM is copied at 0xC700 as with the real BIOS,
although this is not the same code, no known software rely on
values at that location.
Slot number is written to 0xC000 before booting.
Things to do:
Fix the bug when pressing button 1 on the title run cartridge
directly (it happens sometimes).
Detect data present on the three slots (and suggest one).
Leave VDP Registers in the same state as the original BIOS does.
Clear three byte variables (currently stored at 0xD00?).
Clean and release source code.
Enjoy!

1327
SMSBootLoader/tiles.inc Normal file

File diff suppressed because it is too large Load Diff

BIN
SMSBootLoader/tiles.pcx Normal file

Binary file not shown.

174
SMSBootLoader/vdp.asm Normal file
View File

@@ -0,0 +1,174 @@
;----------------------------------------------------------------------------
; Sega Master System & Game Gear - VDP functions
; by Omar Cornut (Bock)
; Started on February 2001
; Last update: 10 November 2001
;----------------------------------------------------------------------------
; VDP_INIT() ----------------------------------------------------------------
; Initialize default VDP registers, clear VRAM, clear sprites
;----------------------------------------------------------------------------
; no parameters
;----------------------------------------------------------------------------
vdp_init:
in a, (VDP_STATUS) ; Read VDP status once
ld hl, vdp_init_table ; before using VDP
ld b, 11*2 ;
ld c, VDP_ADDR ; Then upload default
otir ; registers.
; VDP_CLEAR() ---------------------------------------------------------------
; Clear VRAM, clear sprites
;----------------------------------------------------------------------------
; no parameters
;----------------------------------------------------------------------------
vdp_clear: ;
ld de, $0000 ; Clear VRAM
rst $18 ; Set VDP address to DE
ld bc, VRAM_SIZE ;
vdp_clear_loop: ;
xor a
out (VDP_DATA), a ;
dec bc ;
ld a, b ;
or c ;
jr nz, vdp_clear_loop ;
; VDP_DISABLE_SPRITES() -----------------------------------------------------
; Clear sprites (by setting the first sprite position to 208)
;----------------------------------------------------------------------------
; no parameters
;----------------------------------------------------------------------------
vdp_disable_sprites:
ld de, VRAM_SPR_MAP ; Disable sprites
rst $18 ;
ld a, VRAM_SPR_LAST ;
out (VDP_DATA), a ;
ret
;----------------------------------------------------------------------------
vdp_init_table:
.db $16, $80, $80, $81, $FF, $82, $FF, $83, $FF, $84
.db $FF, $85, $FF, $86, $00, $87, $00, $88, $00, $89
.db $00, $8A
;----------------------------------------------------------------------------
; VDP_FRAME() / VDP_FRAME_ONE() ---------------------------------------------
; Wait for one or more frame to pass
;----------------------------------------------------------------------------
; b = number of frames to wait for
;----------------------------------------------------------------------------
vdp_frame_one:
ld b, 1
vdp_frame:
xor a
ld (VAR_frame_cnt), a
vdp_frame_loop:
ld a, (VAR_frame_cnt)
and $FF
jr z, vdp_frame_loop
djnz vdp_frame
ret
;----------------------------------------------------------------------------
; VDP_LOAD_DATA() -----------------------------------------------------------
; Load data from given source to video memory
;----------------------------------------------------------------------------
; bc = number of bytes
; hl = source in ROM/RAM
; de = destination in VRAM
;----------------------------------------------------------------------------
vdp_load_data:
push hl
rst $18 ; Set VDP address to DE
vdp_load_data_loop:
ld a, (hl)
inc hl
out (VDP_DATA), a
dec bc
ld a, b
or c
jr nz, vdp_load_data_loop
pop hl
ret
;----------------------------------------------------------------------------
; VDP_BG_PUTIMAGE() ---------------------------------------------------------
; Put image to background tile map
;----------------------------------------------------------------------------
; b = image width (in tile)
; c = image height (in tile)
; d = starting tile number
; e = attribute (automatically set bit 0 when d overflow)
; hl = VRAM address
;----------------------------------------------------------------------------
vdp_bg_putimage:
push bc
push de
push hl
vdp_bg_putimage_y:
rst $28 ; Set VDP address to HL
push bc
vdp_bg_putimage_x:
ld a, d
out (VDP_DATA), a
push ix
pop ix
ld a, e
out (VDP_DATA), a
inc d
jr nz, vdp_bg_putimage_attr_end
set 0, e
vdp_bg_putimage_attr_end:
djnz vdp_bg_putimage_x
ld bc, 32*2
add hl, bc
pop bc
dec c
jr nz, vdp_bg_putimage_y
pop hl
pop de
pop bc
ret
;----------------------------------------------------------------------------
; VDP_SET_PAL() -------------------------------------------------------------
; Set palette
;----------------------------------------------------------------------------
; a = starting color
; b = number of colors
; hl = data source
;----------------------------------------------------------------------------
vdp_set_pal:
out (VDP_ADDR), a ;
ld a, %11000000 ;
out (VDP_ADDR), a ;
vdp_set_pal_loop: ;
ld a, (hl) ;
out (VDP_DATA), a ;
inc hl ;
djnz vdp_set_pal_loop ;
ret ;
;----------------------------------------------------------------------------
; VDP_FADE() ----------------------------------------------------------------
; Fade palette
;----------------------------------------------------------------------------
; hl = address of fade data
; a = starting affected color
; b = number of colors per step
; c = number of steps
; d = tempo between steps
;----------------------------------------------------------------------------
vdp_fade:
push af
push bc
call vdp_set_pal
ld b, d
call vdp_frame
pop bc
pop af
dec c
jr nz, vdp_fade
ret
;----------------------------------------------------------------------------

View File

@@ -14,7 +14,7 @@ CONTENT BEGIN
0060: 00 00 00 00 00 00 ED 4D 77 73 6F 6C 74 79 73 00 4D 69 53 54 20 42 6F 6F;
0078: 74 20 4C 6F 61 64 65 72 00 76 30 2E 39 31 00 DB BF 21 AA 00 06 16 0E BF;
0090: ED B3 11 00 00 DF 01 00 40 AF D3 BE 0B 78 B1 20 F8 11 00 3F DF 3E D0 D3;
00A8: BE C9 16 80 80 81 FF 82 FF 83 FF 84 FF 85 FF 86 00 87 00 88 00 89 FF 8A;
00A8: BE C9 16 80 80 81 FF 82 FF 83 FF 84 FF 85 FF 86 00 87 00 88 00 89 00 8A;
00C0: 06 01 AF 32 00 D0 3A 00 D0 E6 FF 28 F9 10 F3 C9 E5 DF 7E 23 D3 BE 0B 78;
00D8: B1 20 F7 E1 C9 C5 D5 E5 EF C5 7A D3 BE DD E5 DD E1 7B D3 BE 14 20 02 CB;
00F0: C3 10 EF 01 40 00 09 C1 0D 20 E5 E1 D1 C1 C9 D3 BF 3E C0 D3 BF 7E D3 BE;
@@ -597,10 +597,10 @@ CONTENT BEGIN
36D0: 00 06 07 1B 0F 19 3F 00 00 00 00 00 00 00 00 CD 87 00 3E 00 06 05 21 BB;
36E8: 36 CD FF 00 01 C0 35 21 1B 01 11 20 00 CD D0 00 06 0A 0E 04 16 01 1E 00;
3700: 21 54 38 CD DD 00 06 17 0E 03 16 29 1E 00 21 88 39 CD DD 00 06 1D 0E 07;
3718: 16 6E 1E 00 21 C2 3A CD DD 00 CD DD 00 11 04 88 D7 11 E2 81 D7 AF 06 05;
3718: 16 6E 1E 00 21 C2 3A CD DD 00 CD DD 00 11 00 88 D7 11 E2 81 D7 AF 06 05;
3730: 0E 04 16 0A 21 BB 36 FB CD 0C 01 F3 11 C2 81 D7 3E 10 06 10 21 CF 36 CD;
3748: FF 00 3E 3E 32 00 C7 3E B8 32 01 C7 3E D3 32 02 C7 3E 3E 32 03 C7 3E C3;
3760: 32 04 C7 3E 00 32 05 C7 3E 00 32 06 C7 C3 00 C7 00 00 00 00 00 00 00 00;
3760: 32 04 C7 3E 00 32 05 C7 32 06 C7 C3 00 C7 00 00 00 00 00 00 00 00 00 00;
3778: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00;
3790: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00;
37A8: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00;