Skip to content

Instantly share code, notes, and snippets.

@egelmex
Created November 21, 2012 10:58
Show Gist options
  • Save egelmex/4124295 to your computer and use it in GitHub Desktop.
Save egelmex/4124295 to your computer and use it in GitHub Desktop.
From cb6fd3ed76d6c128af19987998dccb7b2eed0ff4 Mon Sep 17 00:00:00 2001
From: egelmex <[email protected]>
Date: Wed, 21 Nov 2012 10:56:06 +0000
Subject: [PATCH] Comments and type clarification.
Added doxygen comments. Some XXXs where I would like more details.
Converted types to use stdint types to make it precice what sizes we are
workign with.
---
vdp.cpp | 142 +++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 112 insertions(+), 30 deletions(-)
diff --git a/vdp.cpp b/vdp.cpp
index dd133b8..6bcd5a6 100644
--- a/vdp.cpp
+++ b/vdp.cpp
@@ -1,15 +1,19 @@
-// DGen v1.13+
-// Megadrive's VDP C++ module
-//
-// A useful resource for the Genesis VDP:
-// http://cgfm2.emuviews.com/txt/genvdp.txt
-// Thanks to Charles MacDonald for writing these docs.
-
+/**
+ * DGen v1.13+
+ * Megadrive's VDP C++ module
+ *
+ * A useful resource for the Genesis VDP:
+ * http://cgfm2.emuviews.com/txt/genvdp.txt
+ * Thanks to Charles MacDonald for writing these docs.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "md.h"
+/**
+ * Reset the VDP.
+ */
void md_vdp::reset()
{
command_pending = false;
@@ -26,6 +30,10 @@ void md_vdp::reset()
dest = NULL;
}
+/**
+ * Constructor.
+ * @param refrence to md that this VDP belongs to.
+ */
md_vdp::md_vdp(md& md): belongs(md)
{
vram = (mem + 0x00000);
@@ -37,14 +45,26 @@ md_vdp::md_vdp(md& md): belongs(md)
reset();
}
+/**
+ * Distructor.
+ * unsets vram, cram and vsram.
+ */
md_vdp::~md_vdp()
{
vram = cram = vsram = NULL;
}
+/**
+ * return the length of dma XXX
+ * @return XXX
+ */
int md_vdp::dma_len()
{ return (reg[0x14]<<8)+reg[0x13]; }
+/**
+ * XXX
+ * @return XXX
+ */
int md_vdp::dma_addr()
{
int addr=0;
@@ -55,17 +75,27 @@ int md_vdp::dma_addr()
}
-// DMA can read from anywhere
-unsigned char md_vdp::dma_mem_read(int addr)
+/**
+ * DMA ready byte
+ * DMA can read from anywhere.
+ * @param address to read
+ * @return the byte of memory at addr
+ */
+uint8_t md_vdp::dma_mem_read(int addr)
{
return belongs.misc_readbyte(addr);
}
-// Must go through these calls to update the dirty flags
-int md_vdp::poke_vram(int addr,unsigned char d)
+/**
+ * Set a byte of vram.
+ * Must go through these calls to update the dirty flags.
+ * Dirty bits are set if d changes the value at addr.
+ * @param addr address to store into.
+ * @param d byte to write.
+ * @return 0 on success (always 0).
+ */
+int md_vdp::poke_vram(int addr,uint8_t d)
{
-// Keeping GCC happy over unused vars. [PKH]
-// int diff=0;
addr&=0xffff;
if (vram[addr]!=d)
{
@@ -77,33 +107,54 @@ int md_vdp::poke_vram(int addr,unsigned char d)
}
return 0;
}
-int md_vdp::poke_cram(int addr,unsigned char d)
+
+/**
+ * Set a byte of cram.
+ * Must go through these calls to update the dirty flags.
+ * Dirty bits are set if d changes the value at addr.
+ * @param addr address to store into.
+ * @param d byte to write.
+ * @return 0 on success (always 0).
+ */
+int md_vdp::poke_cram(int addr,uint8_t d)
{
-// int diff=0;
addr&=0x007f;
if (cram[addr]!=d)
{
// Store dirty information down to 1byte level in bits
int byt,bit;
byt=addr; bit=byt&7; byt>>=3; byt&=0x0f;
- dirt[0x20+byt]|=(1<<bit); dirt[0x34]|=2;
+ dirt[0x20+byt]|=(1<<bit); dirt[0x34]|=2;
cram[addr]=d;
}
return 0;
}
-int md_vdp::poke_vsram(int addr,unsigned char d)
+
+/**
+ * Set a byte of cram.
+ * Must go through these calls to update the dirty flags.
+ * Dirty bits are set if d changes the value at addr.
+ * @param addr address to store into.
+ * @param d byte to write.
+ * @return 0 on success (always 0).
+ */
+int md_vdp::poke_vsram(int addr, uint8_t d)
{
-// int diff=0;
addr&=0x007f;
if (vsram[addr]!=d)
{ dirt[0x34]|=4; vsram[addr]=d; }
return 0;
}
-int md_vdp::putword(unsigned short d)
+/**
+ * put a 16bit word#
+ * Called by dma or a straight write
+ * @param d word to put
+ * @ret 0 on success (Always 0)
+ */
+int md_vdp::putword(uint16_t d)
{
- // Called by dma or a straight write
switch(rw_mode)
{
case 0x04:
@@ -129,10 +180,14 @@ int md_vdp::putword(unsigned short d)
return 0;
}
-int md_vdp::putbyte(unsigned char d)
+/**
+ * Put a 8bit byte.
+ * Called by dma or a straight write
+ * @param d byte two write
+ * @return 0 on success. (Always 0).
+ */
+int md_vdp::putbyte(uint8_t d)
{
-// int diff=0;
- // Called by dma or a straight write
switch(rw_mode)
{
case 0x04: poke_vram (rw_addr,d); break;
@@ -145,9 +200,13 @@ int md_vdp::putbyte(unsigned char d)
#undef MAYCHANGE
-unsigned short md_vdp::readword()
+/**
+ * Read a 16bit word.
+ * Called by strait read only.
+ * @return XXX
+ */
+uint16_t md_vdp::readword()
{
- // Called by a straight read only
unsigned short result=0x0000;
switch(rw_mode)
{
@@ -162,9 +221,13 @@ unsigned short md_vdp::readword()
return result;
}
+/**
+ * Read an 8 bit byte.
+ * Called by a straight read only
+ * @return XXX
+ */
unsigned char md_vdp::readbyte()
{
- // Called by a straight read only
unsigned char result=0x00;
switch(rw_mode)
{
@@ -176,7 +239,7 @@ unsigned char md_vdp::readbyte()
return result;
}
-/*
+/**
* VDP commands
*
* A VDP command is 32-bits in length written into the control port
@@ -201,6 +264,9 @@ unsigned char md_vdp::readbyte()
*
* In these cases the pending flag is cleared, and the first half of
* the command remains comitted.
+ *
+ * @param cmd cmd to run.
+ * @return 0 on success. (always 0).
*/
int md_vdp::command(uint16_t cmd)
{
@@ -275,7 +341,13 @@ int md_vdp::command(uint16_t cmd)
return 0;
}
-int md_vdp::writeword(unsigned short d)
+/**
+ * Write 16bit word.
+ * XXX
+ * @param d
+ * @return 0 on success. (Always 0).
+ */
+int md_vdp::writeword(uint16_t d)
{
if (rw_dma)
{
@@ -298,7 +370,13 @@ int md_vdp::writeword(unsigned short d)
return 0;
}
-int md_vdp::writebyte(unsigned char d)
+/**
+ * Write a 8 bit word.
+ * XXX
+ * @param d 8bits of data to write
+ * @ret 0 on success (Always 0).
+ */
+int md_vdp::writebyte(uint8_t d)
{
if (rw_dma)
{
@@ -332,7 +410,11 @@ bool md_vdp::get_command_pending()
return (command_pending);
}
-// write away a vdp register
+/**
+ * Write away a vdp register.
+ * @param addr address of register to write to.
+ * @param data Data to write.
+ */
void md_vdp::write_reg(uint8_t addr, uint8_t data)
{
uint8_t byt, bit;
--
1.7.5.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
OSZAR »