d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Assembly 68k Motorola Question > Reading Data From A .txt Into A 2d Array
Add Reply New Topic New Poll
Member
Posts: 3,686
Joined: Apr 29 2010
Gold: 0.00
Dec 7 2013 03:34pm
Just looking for some advice on how to tackle this problem. I'm currently writing a program to simulate Conway's Game of Life using Atari 68k ASM

A brief summary of the Game of Life:
- Given starting points pixels on the screen are set to become "alive" ( in my case, characters in my 2D array are changed from a '-' to a '@'
- Based on how many "living" neighbors are located in the 8 spaces around each spot in the array will determine if that pixel becomes alive or dead in the next generation

Basically what I need help with is that I start out with an empty 2D array initialized as '-'
To start the first generation the points to be switched as alive('@'') are located in a .txt file
Just needing some help on how to read this .txt and swap according spaces from '-' to '@'

**************************************************************************************************************************
The user is to be prompted for the path to the data file; the maximum length of this path, including
the filename itself, is to be 50 characters. Atari filenames are at maximum 12 characters, which
includes the dot and 3-character extension. Remember that this string MUST be null-terminated.

would like to use GEMDOS commands if possible


data in the .txt file comes in as
row<space>column<CR><LF>
Working C++ Code Here:

void load_array (char startboard[MAX_ROWS][MAX_COLS], char filename[])
{
bool success = true;
char row;
int col;
int row_num;
ifstream infile;

cout << "Please enter the filename to open: <<endl;
cin >> filename;
infile.open(filename);

if(infile.fail.())
{
success = false;
cout << "File Not Opened." << endl;
}
else
{
while(!infile.eof())
{
infile >> row;
row_num = row - 'a'; // converts the character used as a coordinate for the "row number" into an actual number by subtracting from ASCII 'a'
infile.ignore();
infile >> col;
infile.ignore();
infile.ignore();
startboard[row_num][col] = ALIVE // ALIVE is a constant set to equal '@'
}
}
}



TY MUCH <3

This post was edited by SoF_Legacy2 on Dec 7 2013 03:50pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 7 2013 04:28pm
Quote
I'm currently writing a program to simulate Conway's Game of Life using Atari 68k ASM

I think you're on a bad start. looks like you accidentally wrote it in c++ instead of ASM
Member
Posts: 3,686
Joined: Apr 29 2010
Gold: 0.00
Dec 7 2013 04:47pm
Quote (carteblanche @ Dec 7 2013 04:28pm)
I think you're on a bad start. looks like you accidentally wrote it in c++ instead of ASM


no shit! Trying to translate that function into ASM

Actually a common strategy for creating programs as ASM is a lot tougher to think about(in my opinion)

High Level Language-> Low-Level Language

But thanks for stating the obvious -.-

Member
Posts: 16,144
Joined: Mar 27 2008
Gold: 14,618.00
Dec 7 2013 08:21pm
why not just use a compiler? :huh:
then you instantly have the solution... ^_^
Member
Posts: 8,370
Joined: Jan 4 2011
Gold: 100.00
Dec 8 2013 04:05am
Quote (SoF_Legacy2 @ Dec 8 2013 09:47am)
no shit! Trying to translate that function into ASM

Actually a common strategy for creating programs as ASM is a lot tougher to think about(in my opinion)

-.-


:rofl:
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll