Skip to content

Commit

Permalink
Применены патчи от Antipod и boo_boo.
Browse files Browse the repository at this point in the history
  • Loading branch information
aprisobal committed Nov 5, 2008
1 parent e2a752a commit 3db336c
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 43 deletions.
Binary file removed resources/bin2c/bin2c.ncb
Binary file not shown.
34 changes: 24 additions & 10 deletions sjasm/directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ void dirSAVETRD() {

aint val;
char* fnaam, * fnaamh;
int start = -1,length = -1;
int start = -1,length = -1,autostart = -1; //autostart added by boo_boo 19_0ct_2008

fnaam = GetFileName(lp);
if (comma(lp)) {
Expand All @@ -1033,31 +1033,41 @@ void dirSAVETRD() {
if (!ParseExpression(lp, val)) {
Error("[SAVETRD] Syntax error", bp, PASS3); return;
}
//if (val < 0x4000) {
// Error("[SAVETRD] Values less than 4000h are not allowed", bp, PASS3); return;
//} else
if (val > 0xFFFF) {
Error("[SAVETRD] Values more than FFFFh are not allowed", bp, PASS3); return;
Error("[SAVETRD] Values more than 0FFFFh are not allowed", bp, PASS3); return;
}
start = val;
} else {
Error("[SAVETRD] Syntax error. No parameters", bp, PASS3); return;
}
if (comma(lp)) {
if (!comma(lp)) {
if (!ParseExpression(lp, val)) {
Error("[SAVETRD] Syntax error", bp, PASS3); return;
}
if (val < 0) {
Error("[SAVETRD] Negative values are not allowed", bp, PASS3); return;
}
length = val;
} else {
Error("[SAVETRD] Syntax error. No parameters", bp, PASS3); return;
}
}
if (comma(lp)) { //added by boo_boo 19_0ct_2008
if (!ParseExpression(lp, val)) {
Error("[SAVETRD] Syntax error", bp, PASS3); return;
}
if (val < 0) {
Error("[SAVETRD] Negative values are not allowed", bp, PASS3); return;
}
length = val;
}
autostart = val;
}
} else {
Error("[SAVETRD] Syntax error. No parameters", bp, PASS3); return;
}

if (exec) {
TRD_AddFile(fnaam, fnaamh, start, length);
TRD_AddFile(fnaam, fnaamh, start, length, autostart);
}
delete[] fnaam;
delete[] fnaamh;
Expand All @@ -1074,10 +1084,14 @@ void dirENCODING() {
*opt2 = (char) tolower(*opt2);
} while (*(opt2++));
if (!strcmp(opt, "dos")) {
ConvertEncoding = ENCDOS;delete[] opt;return;
ConvertEncoding = ENCDOS;
delete[] opt;
return;
}
if (!strcmp(opt, "win")) {
ConvertEncoding = ENCWIN;delete[] opt;return;
ConvertEncoding = ENCWIN;
delete[] opt;
return;
}
Error("[ENCODING] Syntax error. Bad parameter", bp, CATCHALL); delete[] opt;return;
}
Expand Down
27 changes: 18 additions & 9 deletions sjasm/io_trd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ int TRD_SaveEmpty(char* fname) {
return 1;
}

int TRD_AddFile(char* fname, char* fhobname, int start, int length) {
int TRD_AddFile(char* fname, char* fhobname, int start, int length, int autostart) { //autostart added by boo_boo 19_0ct_2008
FILE* ff;
unsigned char hdr[16], trd[31];
unsigned char hdr[16], trd[31], abin[4];
int i,secs,pos = 0;
aint res;
int autostart_add = autostart > 0? 4 : 0; //added by boo_boo 19_0ct_2008

// for Lua
if (!DeviceID) {
Expand All @@ -94,7 +95,7 @@ int TRD_AddFile(char* fname, char* fhobname, int start, int length) {

// for Lua
if (start > 0xFFFF) {
Error("zx.trdimage_addfile: start address more than FFFFh are not allowed", bp, PASS3); return 0;
Error("zx.trdimage_addfile: start address more than 0FFFFh are not allowed", bp, PASS3); return 0;
}
// for Lua
if (length > 0x10000) {
Expand All @@ -121,7 +122,7 @@ int TRD_AddFile(char* fname, char* fhobname, int start, int length) {
_COUT "Read error: " _CMDL fname _ENDL; return 0;
}
secs = trd[4] + (trd[5] << 8);
if (secs < (length >> 8) + 1) {
if (secs < ((length + autostart_add) >> 8) + 1) {
Error("TRD image haven't free space", fname, CATCHALL); return 0;
}

Expand Down Expand Up @@ -152,6 +153,18 @@ int TRD_AddFile(char* fname, char* fhobname, int start, int length) {
}
SaveRAM(ff, start, length);

if(autostart_add)
{
abin[0] = 0x80;
abin[1] = 0xAA;
abin[2] = autostart & 0xFF;
abin[3] = (autostart >> 8) & 0xFF;

if(fwrite(abin, 1, 4, ff) != 4) {
Error("Write error", fname, CATCHALL); return 0;
}
}

//header of file
for (i = 0; i != 9; hdr[i++] = 0x20) {
;
Expand Down Expand Up @@ -185,11 +198,7 @@ int TRD_AddFile(char* fname, char* fhobname, int start, int length) {

hdr[0x0b] = (unsigned char)(length & 0xff);
hdr[0x0c] = (unsigned char)(length >> 8);
if (hdr[0x0b] == 0) {
hdr[0x0d] = hdr[0x0c];
} else {
hdr[0x0d] = hdr[0x0c] + 1;
}
hdr[0x0d] = ((length + autostart_add) >> 8) + ((length + autostart_add) & 0xFF ? 1: 0);
hdr[0x0e] = trd[0];
hdr[0x0f] = trd[1];

Expand Down
2 changes: 1 addition & 1 deletion sjasm/io_trd.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define __IO_TRD

int TRD_SaveEmpty(char* fname);
int TRD_AddFile(char* fname, char* fhobname, int start, int length);
int TRD_AddFile(char* fname, char* fhobname, int start, int length, int autostart); //autostart added by boo_boo 19_0ct_2008
struct STRDOSSectorHeader {
unsigned char c, s, n, l;
unsigned short crc;
Expand Down
11 changes: 6 additions & 5 deletions sjasm/lua_sjasm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Lua binding: sjasm
** Generated automatically by tolua++-1.0.92 on 05/13/07 22:42:31.
** Generated automatically by tolua++-1.0.92 on 11/06/08 00:50:38.
*/

#ifndef __cplusplus
Expand Down Expand Up @@ -151,7 +151,6 @@ static int tolua_sjasm_sj_insert_label00(lua_State* tolua_S)
static int tolua_get_sj_unsigned_current_address(lua_State* tolua_S)
{
tolua_pushnumber(tolua_S,(lua_Number)CurAddress);
CheckPage();
return 1;
}
#endif //#ifndef TOLUA_DISABLE
Expand Down Expand Up @@ -242,7 +241,8 @@ static int tolua_sjasm_zx_trdimage_add_file00(lua_State* tolua_S)
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
!tolua_isnumber(tolua_S,4,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,5,&tolua_err)
!tolua_isnumber(tolua_S,5,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,6,&tolua_err)
)
goto tolua_lerror;
else
Expand All @@ -252,8 +252,9 @@ static int tolua_sjasm_zx_trdimage_add_file00(lua_State* tolua_S)
char* fhobname = ((char*) tolua_tostring(tolua_S,2,0));
int start = ((int) tolua_tonumber(tolua_S,3,0));
int length = ((int) tolua_tonumber(tolua_S,4,0));
int autostart = ((int) tolua_tonumber(tolua_S,5,0));
{
int tolua_ret = (int) TRD_AddFile(fname,fhobname,start,length);
int tolua_ret = (int) TRD_AddFile(fname,fhobname,start,length,autostart);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
Expand Down Expand Up @@ -882,7 +883,7 @@ TOLUA_API int tolua_sjasm_open (lua_State* tolua_S)
tolua_beginmodule(tolua_S,"zx");
tolua_function(tolua_S,"trdimage_create",tolua_sjasm_zx_trdimage_create00);
tolua_function(tolua_S,"trdimage_add_file",tolua_sjasm_zx_trdimage_add_file00);
tolua_function(tolua_S,"save_snapshot_sna",tolua_sjasm_zx_save_snapshot_sna12800);
tolua_function(tolua_S,"save_snapshot_sna128",tolua_sjasm_zx_save_snapshot_sna12800);
tolua_endmodule(tolua_S);
tolua_module(tolua_S,"sj",1);
tolua_beginmodule(tolua_S,"sj");
Expand Down
2 changes: 1 addition & 1 deletion sjasm/lua_sjasm.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Lua binding: sjasm
** Generated automatically by tolua++-1.0.92 on 05/13/07 22:42:31.
** Generated automatically by tolua++-1.0.92 on 11/06/08 00:50:38.
*/

/* Exported function */
Expand Down
2 changes: 1 addition & 1 deletion sjasm/lua_sjasm.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module sj {

module zx {
int TRD_SaveEmpty @ trdimage_create(char* fname);
int TRD_AddFile @ trdimage_add_file(char* fname, char* fhobname, int start, int length);
int TRD_AddFile @ trdimage_add_file(char* fname, char* fhobname, int start, int length, int autostart);
int SaveSNA_ZX @ save_snapshot_sna128(char* fname, unsigned short start);
}

Expand Down
2 changes: 1 addition & 1 deletion sjasm/sjasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ int main(int argc, char **argv) {
char buf[MAX_PATH];
int base_encoding; /* added */
char* p;
const char* logo = "SjASMPlus Z80 Cross-Assembler v1.07 Stable (build 04-04-2008)";
const char* logo = "SjASMPlus Z80 Cross-Assembler v1.07 RC8 (build 06-11-2008)";
int i = 1;

if (argc == 1) {
Expand Down
136 changes: 132 additions & 4 deletions sjasm/tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ void CMacroDefineTable::Init() {

void CMacroDefineTable::AddMacro(char* naam, char* vervanger) {
defs = new CDefineTableEntry(naam, vervanger, 0, defs);
// By Antipod: http://zx.pk.ru/showpost.php?p=159487&postcount=264
if ( !strcmp( naam, "_aFunc" ) )
{
defs = defs;
}
// --
used[*naam] = 1;
}

Expand All @@ -854,17 +860,139 @@ void CMacroDefineTable::setdefs(CDefineTableEntry* ndefs) {

char* CMacroDefineTable::getverv(char* name) {
CDefineTableEntry* p = defs;
if (!used[*name]) {
if (!used[*name] && *name != KDelimiter) {
return NULL;
}
}// std check
while (p) {
if (!strcmp(name, p->name)) {
return p->value;
return p->value;// full match
}
p = p->next;
}
return NULL;
// extended check for '_'
// By Antipod: http://zx.pk.ru/showpost.php?p=159487&postcount=264
char** array = NULL;
int count = 0;
int positions[ KTotalJoinedParams + 1 ];
SplitToArray( name, array, count, positions );

int tempBufPos = 0;
bool replaced = false;
for ( int i = 0; i<count; i++ )
{
p = defs;

if ( *array[ i ] != KDelimiter )
{
bool found = false;
while( p )
{
if ( !strcmp( array[ i ], p->name ) )
{
replaced = found = true;
tempBufPos = Copy( tempBuf, tempBufPos, p->value, 0, strlen( p->value ) );
break;
}
p = p->next;
}
if ( !found )
{
tempBufPos = Copy( tempBuf, tempBufPos, array[ i ], 0, strlen( array[i] ) );
}
}
else
{
tempBuf[ tempBufPos++ ] = KDelimiter;
tempBuf[ tempBufPos ] = 0;
}
}

FreeArray( array, count );

return replaced ? tempBuf : NULL;
// --
}

void CMacroDefineTable::SplitToArray( const char* aName, char**& aArray, int& aCount, int* aPositions ) const
{
int nameLen = strlen( aName );
aCount = 0;
int itemSizes[ KTotalJoinedParams ];
int currentItemsize = 0;
bool newLex = false;
int prevLexPos = 0;
for ( int i = 0; i<nameLen; i++, currentItemsize++ )
{
if ( aName[ i ] == KDelimiter || aName[ prevLexPos ] == KDelimiter )
{
newLex = true;
}

if ( newLex && currentItemsize )
{
itemSizes[ aCount ] = currentItemsize;
currentItemsize = 0;
aPositions[ aCount ] = prevLexPos;
prevLexPos = i;
aCount++;
newLex = false;
}

if ( aCount == KTotalJoinedParams )
{
Error("Too much joined params!", 0, FATAL);
}
}

if ( currentItemsize )
{
itemSizes[ aCount ] = currentItemsize;
aPositions[ aCount ] = prevLexPos;
aCount++;
}

if ( aCount )
{
aArray = new char*[ aCount ];
for ( int i = 0; i<aCount; i++ )
{
int itemSize = itemSizes[ i ];
if ( itemSize )
{
aArray[ i ] = new char[ itemSize + 1 ];
Copy( aArray[ i ], 0, &aName[ aPositions[ i ] ], 0, itemSize );
}
else
{
Error("Internal error. SplitToArray()", 0, FATAL);
}
}
}
}

int CMacroDefineTable::Copy( char* aDest, int aDestPos, const char* aSource, int aSourcePos, int aBytes ) const
{
int i = 0;
for ( i = 0; i < aBytes; i++ )
{
aDest[ i + aDestPos ] = aSource[ i + aSourcePos ];
}
aDest[ i + aDestPos ] = 0;
return i + aDestPos;
}

void CMacroDefineTable::FreeArray( char** aArray, int aCount )
{
if ( aArray )
{
for ( int i = 0; i<aCount; i++ )
{
delete [] aArray[ i ];
}
}
delete aArray;
}
// --

int CMacroDefineTable::FindDuplicate(char* name) {
CDefineTableEntry* p = defs;
Expand Down
Loading

0 comments on commit 3db336c

Please sign in to comment.