==================================================
SEGA Mega Drive / Genesis LIVE RAM Development Kit
==================================================

(C) 2012 Oerg866

Receive Routine and cable diagram by Mask of Destiny

;;;;;;;;;;;;;;;;;;;;;
;; 
;; MEMORY LAYOUT
;;
\|

RAM layout is as follows:

$FF0000    61440 Bytes  Your program starts here
           
$FFF000    1280 Bytes   Usable RAM area. Anything before this too, provided your program is small enough

$FFF500    512 Bytes    Vertical Interrupt Routines can go here          

$FFF700    256 Bytes    Horizontal Interupt Routines can go here.

! NOTE ! If you don't use the space for the interrupts, you must put RTE ($4753) at the start of both!

$FFF800 until $FFFFFF is reserved for the stack and should never be touched. 


;;;;;;;;;;;;;;;;;;;;;
;;
;; HARDWARE SETUP
;; 

Uh. Not much to say here. TMSS is obviously already set up, and uh.. Other than that, usual shenanigans apply.

Interrupts are enabled when your program starts. 

;;
;; VDP

The VDP is already setup as follows:

$80: 0x14 | Horizontal Interrupt Enabled
$81: 0x74 | Display Enabled, Vertical Interrupt Enabled, DMA Enabled, 28 visible tile-rows
$82: 0x30 | Background A tilemap at VRAM address 0xC000 
$83: 0x00 | Window plane tilemap at VRAM address 0x0000 (unused, set this up if you really want to)
$84: 0x07 | Background B tilemap at VRAM address 0xE000
$85: 0x78 | Sprite data tables   at VRAM address 0xF000
$86: <<unused>>
$87: 0x00 | Background Color: Palette 0, Color 0
$88: <<unused>>
$89: <<unused>>
$8A: 0xFF | Horizontal Interrupt Value: 255
$8B: 0x08 | External Interrupt enabled, Full Vertical Scroll, Full Horizontal Scroll
$8C: 0x81 | H40
$8D: 0x3E | Horizontal Scroll table at VRAM address 0xF800
$8E: <<unused>>
$8F: 0x02 | Auto Increment set to 2
$90: 0x01 | V32 H64 (Tilemap consists of 32 rows and 64 columns)
$91: 0x00 | Window is 0 cells from left
$92: 0x00 | Window is 0 cells from bottom (again, set these up if you really want to use the window)

DMA regs are all nulled and need to be set up for DMA operations:

$93: 0x0000   | DMA length is 0
$95; 0x000000 | DMA source is 0x00000000

;;
;; VRAM

I don't really have much loaded there for your convenience except a font. Use it! 
It uses the 2nd color of the first palette (pal 0 col 1) 

$0000 :: Font

Speaking of which, the palette is already up so that color is set to white.

;;
;; FILES

In this folder you find several small files that belong to the program you're making that ultimately will be transferred to the Mega Drive and run from memory.

** BUILD.ASM **

This is the main file with all the program code in it. You do not have to do any addr(pc) shenanigans or anything because the first line

	ORG $FF0000

makes sure that this is the base adress. Meaning all calls will be adjusted properly. 

It includes two files, called macros.asm and subs.asm

** MACROS.ASM ** 

Contains macros and equates that could potentially aid you in development. Not much is in there though...

** SUBS.ASM ** 

This file contains several routines, so that you don't have to! They're all written by me, and should work fine. It has several operations like loading tiles, loading palettes, printing strings, that do not use any memory, so your program can still use as much space as possible. As soon as I find out how to lock these functions in the original host-ROM (what grabs stuff off parallel port) so that you dont have to give up RAM space for it, it will be easy to use even more RAM space because all these routines have a fixed position in ROM. 

FUNCTION NAMES:

Names         | What it does                | Parameters
------------------------------------------------------------------------------
Load_Palette  | Loads a 16-entry palette    | a0.l: source
              |                             | d0.w: Palette number (0-3)
------------------------------------------------------------------------------
Load_Tiles    | Loads tiles into VRAM       | a0.l: source
              |                             | d0.w: destination in VRAM
              |                             | d1.w: amount of tiles
------------------------------------------------------------------------------
Display_Tiles | Puts tiles from VRAM on the | d0.w: address in VRAM 
              | screen (rectangular)        | d1.b: 0 = ScrollA / 1 = ScrollB
              |                             | d2.l: $yyyyxxxx 
              |                             | yyyy: y position in cells/tiles
              |                             | xxxx: x position in cells/tiles
              |                             | 
              |                             | d3.l: lower word: width in cells
              |                             |       high word: height in cells
              |                             | d6.w: VRAM flags applied to
              |                             |       tilemap (CMD'S CMDVDP.TXT
              |                             |       gives you good info on
              |                             |       how to set these)
------------------------------------------------------------------------------
Print_String  | Prints some text on screen! | a0.l: source
              |                             | d0.w: X position in cells/tiles
              |                             | d1.w: Y position in cells/tiles
              |                             | d2.w: VRAM flags (see above)
------------------------------------------------------------------------------
CalcOffset    | Set VDP control reg for     | d0.l: VRAM address
              | writing data to a specific  | 
              | address                     | 
------------------------------------------------------------------------------
RunLength     | Not really useful here but  | a6.l: source (stuff to decode)
Decoding      | it decompresses a RLE file  | a5.l: destination (in RAM)
              | into memory. RLECOMP.EXE is | 
              | available on my website ;)  | 
------------------------------------------------------------------------------
Print_HEXByte | Prints a byte on screen in  | d0.w: X position in cells/tiles 
              | hexadecimal notation.       | d1.w: Y position in cells/tiles
              |                             | d2.b: the byte to print
              |                             | d4.w: VRAM flags(see above)


