I'm using the -Cl -Osir cc65 command line options for the Synertek Sym-1.
Does anyone have some pointers/ideas?
This sounds like "OS Pragmatics" CSC159 at CSUS.
Greg
Code: Select all
// ------------------
// Roguelike for Sym-1
// Patrick Jackson
// ------------------
#include "symRogue.h"
#define ROW_LEN 16
#define COL_HGHT 10
#define MAP_SIZE ROW_LEN * COL_HGHT
#define MONS_NUM 3
uint8_t m_delta;
uint8_t newmpos;
char int_str[4];
char status_str[20];
uint8_t monster_xy[MONS_NUM];
uint8_t monster_ch[MONS_NUM];
uint8_t monster_hp[MONS_NUM];
uint8_t gold = 0;
uint8_t pos = 25;
uint8_t hp = 50;
uint8_t key_input = 0x00;
uint8_t map[MAP_SIZE + 1];
// Function to create an X by Y box
void printMap()
{
uint8_t i;
uint8_t posInLine;
for (i = 0, posInLine = 0; i < MAP_SIZE; i++)
{
putchar( map[ i ] );
posInLine++;
if ( posInLine == ROW_LEN )
{
posInLine = 0;
newline();
}
}
}
void printStat()
{
itoa(hp, int_str, 10);
strcpy(status_str, "HP: ");
strcpy(status_str + 4, int_str);
strcpy(status_str + 4 + 2, " \t");
puts(status_str);
strcpy(status_str, "Gold: ");
itoa(gold, int_str, 10);
strcpy(status_str + 4 + 2, int_str);
puts(status_str);
}
void combat(i)
uint8_t i;
{
//
}
void m_combat()
{
//
}
void gameLoop()
{
uint8_t _pos;
uint8_t m_dir;
uint8_t i;
clrscr();
map[pos] = '.';
_pos = pos;
for (i = 0; i < MONS_NUM; i++)
map[monster_xy[i]] = '.';
switch (key_input)
{
case 'w':
pos -= ROW_LEN;
break;
case 'a':
pos--;
break;
case 's':
pos += ROW_LEN;
break;
case 'd':
pos++;
break;
default:
break;
}
// check for wall tile
if ( map[pos] == '#' )
pos = _pos;
// check for player combat
for (i = 0; i < MONS_NUM; i++)
{
if ( pos == monster_xy[i] )
{
combat(i);
pos = _pos;
}
// move monster
m_dir = ( rand() & 3 ); // really large, perhaps there's a smaller way?
switch ( m_dir )
{
case 0:
m_delta = 1;
break;
case 1:
m_delta = -1;
break;
case 2:
m_delta = ROW_LEN;
break;
case 3:
m_delta = -ROW_LEN;
break;
default:
break;
}
newmpos = (monster_xy[i] + m_delta);
if ( map[newmpos] != '#' )
{
monster_xy[i] = newmpos;
}
// check for player combat
if ( pos == monster_xy[i] )
{
m_combat();
monster_xy[i] -= m_delta;
}
// print monster
map[monster_xy[i]] = monster_ch[i];
//printf("Monster: %d\tXY: %d\n", i, monster_xy[i]);
}
// print player
map[pos] = '@';
printMap();
printStat();
}
int main(void)
{
uint8_t iMulLen;
uint8_t i;
for (i = 0; i < MONS_NUM; i++)
{
monster_xy[i] = 75;
monster_ch[i] = 'M';
monster_hp[i] = 20;
}
// Start set up of status line
strcpy(status_str, "HP: ");
// truly clears screen
puts("\033[2J");
// --------- Create map --------------
// Fill entire grid with wall tiles '#'
memset(map, '#', MAP_SIZE);
// Fill interior with floor tiles '.'
for ( iMulLen = 0; iMulLen < MAP_SIZE - ( 2 * ROW_LEN );)
{
memset( map + (iMulLen + ROW_LEN + 1), '.', ROW_LEN - 2 );
iMulLen += ROW_LEN;
}
do
{
gameLoop();
key_input = input();
}
while ( key_input != 'q' );
return 0;
}
Code: Select all
void printStat()
{
itoa(hp, int_str, 10);
strcpy(status_str, "HP: ");
strcpy(status_str + 4, int_str);
strcpy(status_str + 4 + 2, " \t");
puts(status_str);
strcpy(status_str, "Gold: ");
itoa(gold, int_str, 10);
strcpy(status_str + 4 + 2, int_str);
puts(status_str);
}
Code: Select all
void printStat()
{
itoa(hp, int_str, 10);
puts("HP: ");
puts(int_str);
puts(" \tGold: ");
itoa(gold, int_str, 10);
puts(int_str);
}
Code: Select all
void combat(i)
uint8_t i;
{
//
}
Code: Select all
void combat(uint8_t i)
{
//
}
Code: Select all
// Send a word (16-bits, 5 digits with leading 0s)
void SendWord(uint16_t w) {
uint16_t mask = 10000;
while (mask) {
SendChar('0'+(w/mask));
w %= mask;
mask/=10;
}
return;
}
Code: Select all
void SendByte(unsigned char b) {
unsigned char mask = 100;
unsigned char digit;
// 100s digit.
digit = '0';
while(b >= mask)
{
digit++;
b = b - mask;
}
SendChar(digit);
// 10s digit.
mask = 10;
digit = '0';
while(b >= mask)
{
digit++;
b = b - mask;
}
SendChar(digit);
// 1s digit.
mask = 1;
digit = '0';
while(b >= mask)
{
digit++;
b = b - mask;
}
SendChar(digit);
return;
}
Code: Select all
// ------------------
// Roguelike for Sym-1
// Patrick Jackson
// ------------------
#include "symRogue.h"
#define ROW_LEN 16
#define COL_HGHT 10
#define MAP_SIZE ROW_LEN * COL_HGHT
#define ROW_MASK ( ROW_LEN - 1 )
#define MONS_NUM 3
//char* target_hp;
uint8_t pos;
uint8_t map[ MAP_SIZE ];
uint8_t key_input = 0x00;
void printMap()
{
uint8_t i;
uint8_t posInLine;
clrscr();
for (i = 0, posInLine = 0; i < MAP_SIZE; i++)
{
putchar( map[ i ] );
posInLine++;
if ( posInLine == ROW_LEN )
{
posInLine = 0;
newline();
}
}
}
/*
void printMap()
{
uint8_t i, row;
clrscr();
for ( i = 0, row = 0; i < MAP_SIZE; ++i )
{
putchar( map[ i ] );
if ( ! ( i & ( ROW_MASK ) ) )
{
row |= 1;
newline();
}
}
}
*/
void parseInput()
{
uint8_t _pos;
map[pos] = '.';
/* Back up current player position */
_pos = pos;
switch ( key_input )
{
case 'w':
pos -= ROW_LEN;
break;
case 'a':
pos--;
break;
case 's':
pos += ROW_LEN;
break;
case 'd':
pos++;
break;
default:
break;
}
/* check for wall tile */
if ( map[ pos ] == '#' )
{
/* if wall tile, restore pos */
pos = _pos;
}
map[ pos ] = '@';
}
void parseMonster()
{
}
int main(void)
{
uint8_t i;
// Set up player pos
pos = 25;
clrdraw();
// --------- Create map ---------
// Fill entire grid with wall tiles '#'
memset( map, '#', MAP_SIZE );
// Fill interior with floor tiles '.'
for ( i = ROW_LEN; i < MAP_SIZE - ROW_LEN; i+= ROW_LEN )
memset( map + i + 1 , '.', ROW_LEN - 2 );
// --------- Main loop -----------
do
{
parseInput();
parseMonster();
printMap();
key_input = input();
}
while ( key_input != 'q' );
return 0;
}
Code: Select all
void printMap()
{
uint8_t i;
clrscr();
for ( i = 0; i < MAP_SIZE; ++i )
{
putchar( map[ i ] );
if ( ! ( ( i + 1 ) & ( ROW_MASK ) ) )
{
newline();
}
}
}Code: Select all
uint8_t move(pos, direction, glyph)
{
uint8_t _pos;
_pos = pos;
map[ _pos ] = '.';
switch( direction )
(
case 'w': case 0:
_pos -= ROW_LEN;
break;
case 'a': case 1:
_pos--;
break;
case 's': case 2:
_pos += ROW_LEN;
break;
case 'd': case 3:
_pos++;
default:
break;
}
if ( map[_pos] == '#' )
_pos = pos;
map[ _pos ] = glyph;
return _pos;
}
/* then the main loop looks like: */
do {
playerpos = move( playerpos, key_input, '@' );
monsterpos = move( monsterpos, random() & 0x03, '&' );
printMap();
key_input = input();
}
while ( key_input != 'q' )
Code: Select all
/* ------------------
Roguelike for Sym-1
Patrick Jackson
------------------
*/
#include "symRogue.h"
#define ROW_LEN 16
#define COL_HGHT 10
#define MAP_SIZE ROW_LEN * COL_HGHT
#define ROW_MASK ( ROW_LEN - 1 )
#define MONS_NUM 3
unsigned char map[ MAP_SIZE ];
unsigned char lpos, direction, glyph;
unsigned char pos;
unsigned char hp;
unsigned char mons_xy[MONS_NUM];
unsigned char mons_ch[MONS_NUM];
unsigned char mons_hp[MONS_NUM];
unsigned char key_input = 0x00;
void printMap()
{
unsigned char i;
clrscr();
for ( i = 0; i < MAP_SIZE; ++i )
{
putchar( map[ i ] );
if ( ! ( ( i + 1 ) & ( ROW_MASK ) ) )
{
newline();
}
}
}
unsigned char move()
{
unsigned char _lpos;
_lpos = lpos;
map[ _lpos ] = '.';
switch ( direction )
{
case 'w': case 0:
_lpos -= ROW_LEN;
break;
case 'a': case 1:
_lpos--;
break;
case 's': case 2:
_lpos += ROW_LEN;
break;
case 'd': case 3:
_lpos++;
default:
break;
}
if ( map[ _lpos ] == '#' )
_lpos = lpos;
map[ _lpos ] = glyph;
return _lpos;
}
int main()
{
unsigned char i;
/* Set up player pos */
pos = 25;
for ( i = 0; i < MONS_NUM; ++i )
mons_xy[ i ] = 50;
clrdraw();
/* --------- Create map ---------
Fill entire grid with wall tiles '#' */
memset( map, '#', MAP_SIZE );
/* Fill interior with floor tiles '.' */
for ( i = ROW_LEN; i < MAP_SIZE - ROW_LEN; i+= ROW_LEN )
memset( map + i + 1 , '.', ROW_LEN - 2 );
/* --------- Main loop ----------- */
do
{
lpos = pos;
direction = key_input;
glyph = '@';
pos = move();
for ( i = 0; i < MONS_NUM; i++ )
{
lpos = mons_xy[ i ];
direction = rand() & 0x03;
glyph = 'M';
mons_xy[ i ] = move();
}
printMap();
key_input = input();
}
while ( key_input != 'q' );
return 0;
}
Code: Select all
/* ------------------
Roguelike for Sym-1
Patrick Jackson
------------------
*/
#include "symRogue.h"
#define ROW_LEN 16
#define COL_HGHT 10
#define MAP_SIZE ROW_LEN * COL_HGHT
#define ROW_MASK ( ROW_LEN - 1 )
#define MONS_NUM 3
unsigned char map[ MAP_SIZE ];
unsigned char lpos, direction, glyph;
unsigned char pos;
unsigned char hp;
unsigned char mons_xy[MONS_NUM];
unsigned char mons_ch[MONS_NUM];
unsigned char mons_hp[MONS_NUM];
unsigned char m_i;
unsigned char key_input = 0x00;
void printMap()
{
unsigned char i;
clrscr();
for ( i = 0; i < MAP_SIZE; ++i )
{
putchar( map[ i ] );
if ( ! ( ( i + 1 ) & ( ROW_MASK ) ) )
{
newline();
}
}
}
void chkMCmbt()
{
//
}
void chkPCmbt()
{
//
}
unsigned char move()
{
unsigned char _lpos;
/* Move character around */
_lpos = lpos;
map[ _lpos ] = '.';
switch ( direction )
{
case 'w': case 0:
_lpos -= ROW_LEN;
break;
case 'a': case 1:
_lpos--;
break;
case 's': case 2:
_lpos += ROW_LEN;
break;
case 'd': case 3:
_lpos++;
default:
break;
}
/* Check for wall, player, or monster collision */
if (map[_lpos] == '#')
_lpos = lpos;
else if (map[_lpos] == 'M')
{
chkPCmbt();
_lpos = lpos;
}
else if (map[_lpos] == '@')
{
chkMCmbt();
_lpos = lpos;
}
map[_lpos] = glyph;
return _lpos;
}
int main()
{
unsigned char i;
/* Set up player pos */
pos = 25;
for ( i = 0; i < MONS_NUM; ++i )
mons_xy[ i ] = 50;
clrdraw();
/* --------- Create map ---------
Fill entire grid with wall tiles '#' */
memset( map, '#', MAP_SIZE );
/* Fill interior with floor tiles '.' */
for ( i = ROW_LEN; i < MAP_SIZE - ROW_LEN; i+= ROW_LEN )
memset( map + i + 1 , '.', ROW_LEN - 2 );
/* --------- Main loop ----------- */
do
{
lpos = pos;
direction = key_input;
glyph = '@';
pos = move();
for ( m_i = 0; m_i < MONS_NUM; m_i++ )
{
lpos = mons_xy[ m_i ];
direction = rand() & 0x03;
glyph = 'M';
mons_xy[ m_i ] = move();
}
printMap();
key_input = input();
}
while ( key_input != 'q' );
return 0;
}
Code: Select all
/* Fill interior with floor tiles '.' */
for ( i = ROW_LEN + 1; i < MAP_SIZE - ROW_LEN; i+= ROW_LEN )
memset( map + i, '.', ROW_LEN - 2 );
Code: Select all
// bss-name -> uninitialized variables, data-name -> initialized variables
#pragma bss-name (push,"ZEROPAGE")
uint8_t player_pos, player_hp; // Both of these are now in zeropage
#pragma bss-name (pop)