From fefbb2febbe5722da075bb71e8c9af0a4bb6f09d Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Wed, 9 Oct 2019 13:50:34 +0200 Subject: [PATCH] Cleanup/fix C tools compilation --- source/tools/C/compfsize.bat | 2 +- source/tools/C/compvsft.bat | 2 +- source/tools/C/dos.h | 7 +++ source/tools/C/emufile.c | 7 +-- source/tools/C/fsize.c | 49 ++++++------------- source/tools/C/nexboot.c | 9 +--- source/tools/C/types.h | 16 ++++-- source/tools/C/vsft.c | 95 +++++++++--------------------------- 8 files changed, 61 insertions(+), 126 deletions(-) diff --git a/source/tools/C/compfsize.bat b/source/tools/C/compfsize.bat index ad0cfdb0..965f505a 100644 --- a/source/tools/C/compfsize.bat +++ b/source/tools/C/compfsize.bat @@ -1,6 +1,6 @@ @echo off cls -sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --no-std-crt0 crt0msx_msxdos_advanced.rel msxchar.lib asm.lib fsize.c +sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --disable-warning 85 --no-std-crt0 crt0msx_msxdos_advanced.rel fsize.c if errorlevel 1 goto :end hex2bin -e com fsize.ihx copy fsize.com ..\..\..\bin\tools\ diff --git a/source/tools/C/compvsft.bat b/source/tools/C/compvsft.bat index e4e2cf58..600541a5 100644 --- a/source/tools/C/compvsft.bat +++ b/source/tools/C/compvsft.bat @@ -1,6 +1,6 @@ @echo off cls -sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --no-std-crt0 crt0msx_msxdos_advanced.rel msxchar.lib asm.lib vsft.c +sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --disable-warning 85 --no-std-crt0 crt0msx_msxdos_advanced.rel vsft.c if errorlevel 1 goto :end hex2bin -e com vsft.ihx copy vsft.com ..\..\..\bin\tools\ diff --git a/source/tools/C/dos.h b/source/tools/C/dos.h index bea99a30..3a38f57a 100644 --- a/source/tools/C/dos.h +++ b/source/tools/C/dos.h @@ -100,6 +100,10 @@ typedef struct { #define _TERM0 0 #define _DIRIO 0x06 #define _BUFIN 0x0A +#define _SETDTA 0x1A +#define _ALLOC 0x1B +#define _RDABS 0x2F +#define _WRABS 0x30 #define _DPARM 0x31 #define _FFIRST 0x40 #define _FNEXT 0x41 @@ -108,11 +112,14 @@ typedef struct { #define _CLOSE 0x45 #define _READ 0x48 #define _WRITE 0x49 +#define _SEEK 0x4A #define _PARSE 0x5B #define _WPATH 0x5E #define _TERM 0x62 #define _EXPLAIN 0x66 #define _DOSVER 0x6F +#define _RDDRV 0x73 +#define _WRDRV 0x74 #define _GDRVR 0x78 #define _GPART 0x7A #define _CDRVR 0x7B diff --git a/source/tools/C/emufile.c b/source/tools/C/emufile.c index 25e50109..d374c6fe 100644 --- a/source/tools/C/emufile.c +++ b/source/tools/C/emufile.c @@ -4,8 +4,7 @@ Compilation command line: sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 - --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel - emufile.c + --no-std-crt0 crt0_msxdos_advanced.rel emufile.c hex2bin -e com emufile.ihx */ @@ -41,10 +40,6 @@ typedef struct { /* Defines */ -#define false (0) -#define true (!(false)) -#define null ((void*)0) - #define IS_NEXTOR (1 << 7) #define IS_DEVICE_BASED (1) diff --git a/source/tools/C/fsize.c b/source/tools/C/fsize.c index 85d5029f..72e38075 100644 --- a/source/tools/C/fsize.c +++ b/source/tools/C/fsize.c @@ -4,18 +4,9 @@ Compilation command line: sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 - --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel - asm.lib fsize.c + --no-std-crt0 crt0_msxdos_advanced.rel + fsize.c hex2bin -e com fsize.ihx - - ASM.LIB, MSXCHAR.LIB and crt0msx_msxdos_advanced.rel - are available at www.konamiman.com - - (You don't need MSXCHAR.LIB if you manage to put proper PUTCHAR.REL, - GETCHAR.REL and PRINTF.REL in the standard Z80.LIB... I couldn't manage to - do it, I get a "Library not created with SDCCLIB" error) - - Comments are welcome: konamiman@konamiman.com */ @@ -26,33 +17,14 @@ #include #include #include +#include "asmcall.h" +#include "types.h" +#include "dos.h" -//These are available at www.konamiman.com -#include "asm.h" - - /* Typedefs */ - -typedef unsigned char bool; -typedef unsigned long ulong; - - /* Defines */ - -#define false (0) -#define true (!(false)) -#define null ((void*)0) +/* Defines */ #define Buffer 0x9000 -#define _TERM0 0 -#define _FFIRST 0x40 -#define _OPEN 0x43 -#define _CREATE 0x44 -#define _CLOSE 0x45 -#define _WRITE 0x49 -#define _SEEK 0x4A -#define _TERM 0x62 -#define _DOSVER 0x6F - /* Strings */ const char* strTitle= @@ -78,6 +50,8 @@ const char* strCRLF = "\r\n"; /* Global variables */ +byte ASMRUT[4]; +byte OUT_FLAGS; Z80_registers regs; char* fileName; bool isAbsoluteSize; @@ -110,6 +84,7 @@ int main(char** argv, int argc) byte fileHandle; ulong oldSize; + ASMRUT[0] = 0xC3; fileName = (char*)0x8000; print(strTitle); @@ -253,7 +228,7 @@ bool FileExists(char* fileName) { regs.Bytes.B = 0; regs.Words.DE = (int)fileName; - regs.Words.IX = Buffer; + regs.Words.IX = (int)Buffer; DosCall(_FFIRST, ®s, REGS_ALL, REGS_AF); return regs.Bytes.A == 0; } @@ -334,3 +309,7 @@ void WriteOneByte(byte fileHandle, byte value) TerminateWithDosError(regs.Bytes.A); } } + +#define COM_FILE +#include "printf.c" +#include "asmcall.c" diff --git a/source/tools/C/nexboot.c b/source/tools/C/nexboot.c index 69adf1ef..21d86963 100644 --- a/source/tools/C/nexboot.c +++ b/source/tools/C/nexboot.c @@ -4,8 +4,8 @@ Compilation command line: sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 - --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel - nexboot.c + --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel + nexboot.c hex2bin -e com emufile.ihx */ @@ -17,14 +17,9 @@ #include "system.h" #include "dos.h" #include "asmcall.h" -#include "strcmpi.h" /* Defines */ -#define false (0) -#define true (!(false)) -#define null ((void*)0) - #define RamKeysAddress ((byte*)0xA100) /* Strings */ diff --git a/source/tools/C/types.h b/source/tools/C/types.h index e9097877..093eb489 100644 --- a/source/tools/C/types.h +++ b/source/tools/C/types.h @@ -13,12 +13,20 @@ typedef unsigned char byte; typedef unsigned long ulong; #endif -#ifndef null -#define null ((void*)0) +#ifndef bool +typedef unsigned char bool; #endif -typedef unsigned char bool; +#ifndef false #define false (0) +#endif + +#ifndef true #define true (!(false)) +#endif + +#ifndef null +#define null ((void*)0) +#endif -#endif //__TYPES_H \ No newline at end of file +#endif //__TYPES_H diff --git a/source/tools/C/vsft.c b/source/tools/C/vsft.c index 40d9936b..56961245 100644 --- a/source/tools/C/vsft.c +++ b/source/tools/C/vsft.c @@ -4,20 +4,10 @@ Compilation command line: sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 - --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel - asm.lib vsft.c + --no-std-crt0 crt0_msxdos_advanced.rel + vsft.c hex2bin -e com vsft.ihx - - ASM.LIB, MSXCHAR.LIB and crt0msx_msxdos_advanced.rel - are available at www.konamiman.com - - (You don't need MSXCHAR.LIB if you manage to put proper PUTCHAR.REL, - GETCHAR.REL and PRINTF.REL in the standard Z80.LIB... I couldn't manage to - do it, I get a "Library not created with SDCCLIB" error) - - Comments are welcome: konamiman@konamiman.com */ - /* Includes */ @@ -27,15 +17,12 @@ #include #include #include "strcmpi.h" - -//These are available at www.konamiman.com -#include "asm.h" +#include "asmcall.h" +#include "types.h" +#include "dos.h" /* Typedefs */ -typedef unsigned char bool; -typedef unsigned long ulong; - typedef struct { byte jumpInstruction[3]; char oemNameString[8]; @@ -76,21 +63,6 @@ typedef struct { /* Defines */ -#define false (0) -#define true (!(false)) -#define null ((void*)0) - -#define _TERM0 0x00 -#define _SETDTA 0x1A -#define _ALLOC 0x1B -#define _RDABS 0x2F -#define _WRABS 0x30 -#define _DPARM 0x31 -#define _TERM 0x62 -#define _DOSVER 0x6F -#define _RDDRV 0x73 -#define _WRDRV 0x74 - #define MAX_FAT12_CLUSTER_COUNT 4084 #define MAX_12BIT_CLUSTER_COUNT 4095 #define MAX_FAT16_CLUSTER_COUNT 65524 @@ -123,11 +95,13 @@ const char* strCRLF = "\r\n"; /* Global variables */ +byte ASMRUT[4]; +byte OUT_FLAGS; Z80_registers regs; bool isNextor; fatBootSector* Buffer = (fatBootSector*)0x8000; bool isFat16; -byte driveNumber; //0=A:, etc +int driveNumber; //0=A:, etc bool doFix; uint totalClusters; ulong totalSectors; @@ -137,7 +111,7 @@ int sectorsToDecreaseForFix; /* Some handy code defines */ -#define PrintNewLine() print(strCRLF) +#define PrintNewLine() printf(strCRLF) #define StringIs(a, b) (strcmpi(a,b)==0) @@ -145,7 +119,6 @@ int sectorsToDecreaseForFix; void Terminate(const char* errorMessage); void TerminateWithDosError(byte errorCode); -void print(char* s); void CheckDosVersion(); void ExtractParameters(char** argv, int argc); void GetDriveInfo(); @@ -163,10 +136,11 @@ void WritebootSector(); int main(char** argv, int argc) { - print(strTitle); + ASMRUT[0] = 0xC3; + printf(strTitle); if(argc == 0) { - print(strUsage); + printf(strUsage); Terminate(null); } @@ -177,7 +151,7 @@ int main(char** argv, int argc) CalculateSectorsToDecreaseForFix(); if(sectorsToDecreaseForFix == 0) { - print("\r\nVolume size is correct. No need to fix it.\r\n"); + printf("\r\nVolume size is correct. No need to fix it.\r\n"); Terminate(null); } else if(doFix) { DoFix(); @@ -210,37 +184,11 @@ void TerminateWithDosError(byte errorCode) } -void print(char* s) __naked -{ - __asm - push ix - ld ix,#4 - add ix,sp - ld l,(ix) - ld h,1(ix) -loop: - ld a,(hl) - or a - jr z,end - ld e,a - ld c,#2 - push hl - call #5 - pop hl - inc hl - jr loop -end: - pop ix - ret - __endasm; -} - - void CheckDosVersion() { regs.Bytes.B = 0x5A; regs.Words.HL = 0x1234; - regs.Words.DE = 0xABCD; + regs.UWords.DE = 0xABCD; regs.Words.IX = 0; DosCall(_DOSVER, ®s, REGS_ALL, REGS_ALL); @@ -311,7 +259,7 @@ void PrintDriveInfo() printf("Size: "); PrintSizeInK(totalSectors/2); PrintNewLine(); printf("Cluster count: %u\r\n", totalClusters); if(sectorsPerCluster == 1) { - print("Cluster size: 512 bytes\r\n"); + printf("Cluster size: 512 bytes\r\n"); } else { printf("Cluster size: %i KBytes\r\n", sectorsPerCluster / 2); } @@ -321,7 +269,7 @@ void PrintDriveInfo() } else if(totalClusters > MAX_12BIT_CLUSTER_COUNT) { Terminate("Cluster count does not fit in 12 bits - this is not supposed to be supported by MSX-DOS!"); } else { - print("Filesystem: FAT12 assumed (MSX-DOS does not support anything else)\r\n"); + printf("Filesystem: FAT12 assumed (MSX-DOS does not support anything else)\r\n"); } } @@ -370,7 +318,7 @@ void DoFix() ReadBootSector(); FixVolumeSize(); WritebootSector(); - print("Fix applied!\r\n"); + printf("Fix applied!\r\n"); } @@ -380,13 +328,13 @@ void PrintFixInfo() (isFat16 ? MAX_FAT16_CLUSTER_COUNT : MAX_FAT12_CLUSTER_COUNT)); printf("This can be fixed by reducing the volume size by %i KBytes.\r\n", sectorsToDecreaseForFix/2); - print("Run the tool again adding the 'fix' parameter to apply the fix.\r\n"); + printf("Run the tool again adding the 'fix' parameter to apply the fix.\r\n"); } void ReadBootSector() { - print("\r\nReading boot sector...\r\n"); + printf("\r\nReading boot sector...\r\n"); regs.Words.DE = (int)Buffer; DosCall(_SETDTA, ®s, REGS_MAIN, REGS_MAIN); @@ -432,7 +380,7 @@ void FixVolumeSize() void WritebootSector() { - print("Writing updated boot sector...\r\n"); + printf("Writing updated boot sector...\r\n"); regs.Words.DE = (int)Buffer; DosCall(_SETDTA, ®s, REGS_MAIN, REGS_MAIN); @@ -455,4 +403,7 @@ void WritebootSector() } } +#define COM_FILE +#include "printf.c" +#include "asmcall.c" #include "strcmpi.c"