File 0003-Convert-to-modern-C.patch of Package dapple
From 45804fe1acea68bbd6fe7754bb845613ce610247 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de>
Date: Thu, 28 Sep 2023 19:12:30 +0200
Subject: [PATCH 3/4] Convert to modern C
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- declare functions in header files
- declare global variables in header files
- use proper includes for all function declarations
Signed-off-by: Klaus Kämpf <kkaempf@suse.de>
---
altkey.c | 6 +++
binmanip.c | 1 +
binmanip.h | 5 +++
cpu65c02.c | 1 +
cpu65c02.h | 7 ++++
dapple.c | 21 +++++-----
dapple.h | 9 ++++-
debug.c | 3 +-
debug.h | 1 +
disk.c | 1 +
disk.h | 4 ++
gui.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++
gui.h | 116 ++++-------------------------------------------------
ini.c | 8 ++--
joystick.c | 22 +++++-----
joystick.h | 2 +
lldisk.c | 6 +--
lldisk.h | 7 ++++
massstor.c | 9 ++---
massstor.h | 4 ++
mk.sh | 2 +-
prtsc.h | 1 +
video.c | 2 +
video.h | 6 +++
24 files changed, 205 insertions(+), 150 deletions(-)
create mode 100644 binmanip.h
create mode 100644 cpu65c02.h
create mode 100644 debug.h
create mode 100644 disk.h
create mode 100644 gui.c
create mode 100644 joystick.h
create mode 100644 lldisk.h
create mode 100644 massstor.h
create mode 100644 prtsc.h
create mode 100644 video.h
diff --git a/altkey.c b/altkey.c
index 71b6270..f6ebae5 100644
--- a/altkey.c
+++ b/altkey.c
@@ -23,6 +23,12 @@
//#include <dos.h>
#include <allegro.h>
+#include "cpu65c02.h"
+#include "dapple.h"
+#include "debug.h"
+#include "disk.h"
+#include "prtsc.h"
+#include "video.h"
extern int k;
diff --git a/binmanip.c b/binmanip.c
index d30e49a..da34b4e 100644
--- a/binmanip.c
+++ b/binmanip.c
@@ -25,6 +25,7 @@
#include <string.h>
//#include "m6502.h"
#include "dapple.h"
+#include "binmanip.h"
/* dapple.c */
extern int smode;
diff --git a/binmanip.h b/binmanip.h
new file mode 100644
index 0000000..ebd5aaf
--- /dev/null
+++ b/binmanip.h
@@ -0,0 +1,5 @@
+int xbload (char *filename);
+void savebas (char *filename);
+int loadbas(char *filename);
+int immk (char *filename);
+int imrs (char *filename);
diff --git a/cpu65c02.c b/cpu65c02.c
index ac70135..4d96b91 100644
--- a/cpu65c02.c
+++ b/cpu65c02.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include "dapple.h"
+#include "cpu65c02.h"
#define readbus(addr) Rd6502(addr)
#define writebus(addr, value) Wr6502(addr, value)
diff --git a/cpu65c02.h b/cpu65c02.h
new file mode 100644
index 0000000..2018472
--- /dev/null
+++ b/cpu65c02.h
@@ -0,0 +1,7 @@
+/* cpu65c02.c */
+extern void cpuinit();
+extern void cpureset();
+extern void cpurun();
+extern void cpusetpc(unsigned short address);
+extern unsigned short cpugetpc();
+extern unsigned short rasterline;
diff --git a/dapple.c b/dapple.c
index 63b350e..379a8e4 100644
--- a/dapple.c
+++ b/dapple.c
@@ -43,13 +43,23 @@
#include <signal.h>
#include "dapple.h"
+#include "binmanip.h"
+#include "cpu65c02.h"
+#include "debug.h"
+#include "disk.h"
#include "gui.h"
+#include "joystick.h"
+#include "lldisk.h"
+#include "massstor.h"
+#include "video.h"
#include <allegro.h>
#ifdef EMUZ80
int Z80_Execute (void);
#endif
+BITMAP *bufferzor;
+
unsigned char keycapslock = 1;
unsigned char keyswitchyz = 0;
unsigned char joybutton0;
@@ -80,10 +90,6 @@ unsigned char memlcramw; /* write LC RAM or ROM?
unsigned char memlcbank2; /* read from LC bank 1 or LC bank 2 */
unsigned char memann3; /* annunciator #3 */
unsigned char memnolc = 0; /* Is there a LC card installed? */
-void memoryreset();
-void memoryclear();
-unsigned char Rd6502(unsigned short address);
-void Wr6502(register unsigned short address, register unsigned char value);
extern unsigned char reload (char *bios);
Charset charmode=USA;
@@ -135,13 +141,6 @@ extern void virtwrite4000(register unsigned int addr);
extern void virtwrite4000aux(register unsigned int addr);
// unsigned int rasterline = 0;
-/* cpu65c02.c */
-extern void cpuinit();
-extern void cpureset();
-extern void cpurun();
-extern void cpusetpc(unsigned short address);
-extern unsigned short cpugetpc();
-extern unsigned short rasterline;
/* debug.c */
extern void Debug6502();
diff --git a/dapple.h b/dapple.h
index ea2abb6..b0c78e9 100644
--- a/dapple.h
+++ b/dapple.h
@@ -131,4 +131,11 @@ struct rgb
typedef unsigned char byte;
typedef unsigned short int word;
//zD
-BITMAP *bufferzor;
+extern BITMAP *bufferzor;
+
+unsigned char Rd6502(register unsigned short address);
+void Wr6502(register unsigned short address, register unsigned char value);
+void setshiftmanip (int x);
+
+void memoryreset();
+void memoryclear();
diff --git a/debug.c b/debug.c
index 071fbe7..7954203 100644
--- a/debug.c
+++ b/debug.c
@@ -10,6 +10,7 @@
//#include <conio.h>
#include <string.h>
#include "dapple.h"
+#include "debug.h"
/* dapple.c */
extern unsigned char debugger;
@@ -1091,7 +1092,7 @@ NMI ($FFFA): $%04X\n\
goto top;
btm:
- //clrscr();
+ //clrscr();
opengraph(); virtcopy=1; debugger = 0;
return;
diff --git a/debug.h b/debug.h
new file mode 100644
index 0000000..1b5edbe
--- /dev/null
+++ b/debug.h
@@ -0,0 +1 @@
+void Debug6502 (void);
diff --git a/disk.c b/disk.c
index 80627f9..052a5dd 100644
--- a/disk.c
+++ b/disk.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <fcntl.h>
#include "dapple.h"
+#include "gui.h"
extern unsigned char virtscreen[128000];
//#define virtplot(x,y,c) virtscreen[(y*320)+x]=c
diff --git a/disk.h b/disk.h
new file mode 100644
index 0000000..59991df
--- /dev/null
+++ b/disk.h
@@ -0,0 +1,4 @@
+void DiskReset( void );
+long FileSize( int filehandle );
+void UnmountDisk( int disk );
+void MountDisk( int disk );
diff --git a/gui.c b/gui.c
new file mode 100644
index 0000000..dd03432
--- /dev/null
+++ b/gui.c
@@ -0,0 +1,111 @@
+#include "dapple.h"
+#include "gui.h"
+#define PROGTITLE "Dapple"
+
+int yesno (char *message)
+{
+ int x;
+
+ x=alert (PROGTITLE,message,0,"&Yes","&No",'y','n');
+ return x;
+}
+
+void ynexit()
+{
+ if (yesno("Really quit " PROGTITLE "?")==1) exit(0);
+}
+
+void mbox (char *message)
+{
+ alert (PROGTITLE,message,0,"O&K",0,'k',0);
+}
+
+MENU FILE_MENU[] = {
+//{ "title", function, submenu, 0, 0 }
+{ "&Load State", loadstate,0,0,0},
+{ "&Save State",savestate,0,0,0},
+{ "",0,0,0,0},
+{ "L&oad Basic...",loadbaszor,0,0,0},
+{ "S&ave Basic...",savebaszor,0,0,0},
+{ "Loa&d Program...",xbloadzor,0,0,0},
+{ "Sav&e Program...",0,0,D_DISABLED,0},
+{ "",0,0,0,0},
+{ "E&xit",(void*)ynexit,0,0,0},
+{ 0,0,0,0,0}
+};
+MENU DRIVES_MENU[] = {
+{"Disk 1...",seld1,0,0,0},
+{"Disk 2...",seld2,0,0,0},
+{0,0,0,0,0}
+};
+MENU CPU_MENU[] = {
+{"Basic 6502 Clone",0,0,D_DISABLED,0},
+{"Synertek 6502",0,0,D_DISABLED,0},
+{"WDC 65C02",0,0,D_DISABLED,0},
+{"Rockwell 65C02",0,0,D_DISABLED,0},
+{"Speed...",0,0,D_DISABLED,0},
+{0,0,0,0,0}
+};
+MENU RAM_MENU[] = {
+{"Language Card (][ and ][+ only)",0,0,D_DISABLED,0},
+{"RAM Works/RAM Factor (//e and //c only)",0,0,D_DISABLED,0},
+{0,0,0,0,0}
+};
+MENU ROM_MENU[] = {
+{"Apple ][ (Monitor)",0,0,D_DISABLED,0},
+{"Apple ][ (Revised)",0,0,D_DISABLED,0},
+{"Apple ][+",0,0,D_DISABLED,0},
+{"Apple ][+ (Dosius Plusrom)",0,0,D_DISABLED,0},
+{"Franklin Ace",0,0,D_DISABLED,0},
+{"Viking",0,0,D_DISABLED,0},
+{"Apple //e (1982 version)",0,0,D_DISABLED,0},
+{"Apple //e (1985 version)",0,0,D_DISABLED,0},
+{"Apple //c (16K ROM)",0,0,D_DISABLED,0},
+{"Apple //c (32K ROM)",0,0,D_DISABLED,0},
+{0,0,0,0,0}
+};
+MENU DISPLAY_MENU[] = {
+{"Mono",0,0,D_DISABLED,0},
+{"Color",0,0,D_DISABLED,0},
+{"Blurry",0,0,D_DISABLED,0},
+{0,0,0,0,0}
+};
+MENU OPTIONS_MENU[] = {
+{"Drives",0,DRIVES_MENU,0,0},
+{"CPU",0,CPU_MENU,D_DISABLED,0},
+{"RAM",0,RAM_MENU,D_DISABLED,0},
+{"ROM",0,ROM_MENU,D_DISABLED,0},
+{"Sound",0,0,D_DISABLED,0},
+{"Display",0,DISPLAY_MENU,D_DISABLED,0},
+{0,0,0,0,0}
+};
+MENU DEBUG_MENU[] = {
+{"Set Execution Address...",0,0,0,0},
+{0,0,0,0,0}
+};
+MENU RESET_MENU[] = {
+{"Soft Reset",softreset,0,0,0},
+{"Hard Reset",hardreset,0,0,0},
+{"Full Reset",fullreset,0,0,0},
+{0,0,0,0,0}
+};
+MENU MAIN_MENU[] = {
+{"&File",0,FILE_MENU,0,0 },
+{"&Options",0,OPTIONS_MENU,0,0},
+{"&Debug",0,DEBUG_MENU,D_DISABLED,0},
+{"&Reset",0,RESET_MENU,0,0},
+{"&About",(void*)about,0,0,0},
+{ 0,0,0,0,0}
+};
+DIALOG dialog[] = {
+{ d_menu_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, MAIN_MENU, NULL, NULL },
+{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0}
+};
+void about()
+{
+ alert (PROGTITLE " - Apple ][ Emulator",
+ "Version " DappleVersion,
+ "Copyright (C) 2002, 2007 Steve Nickolas and Retro Emulation Project",
+ "O&K",0,'k',0);
+ do_dialog(dialog,0);
+}
diff --git a/gui.h b/gui.h
index bcab8c3..25d799e 100644
--- a/gui.h
+++ b/gui.h
@@ -1,23 +1,13 @@
-#include <allegro.h>
-#define PROGTITLE "Dapple"
#define fdialog(a,b,c) file_select_ex(a,b,c,1024,0,0)
-int yesno (char *message)
-{
- int x;
-
- x=alert (PROGTITLE,message,0,"&Yes","&No",'y','n');
- return x;
-}
+int yesno (char *message);
+void ynexit();
+void mbox (char *message);
+int vga2alleg(unsigned char c);
+void virtplot(int x,int y,unsigned char c);
-void ynexit()
-{
- if (yesno("Really quit " PROGTITLE "?")==1) exit(0);
-}
+#include <allegro.h>
-void mbox (char *message)
-{
- alert (PROGTITLE,message,0,"O&K",0,'k',0);
-}
+extern DIALOG dialog[];
void about();
int softreset();
@@ -31,95 +21,3 @@ int loadbaszor();
int savebaszor();
int xbloadzor();
-int vga2alleg(unsigned char c);
-void virtplot(int x,int y,unsigned char c);
-
-MENU FILE_MENU[] = {
-//{ "title", function, submenu, 0, 0 }
-{ "&Load State", loadstate,0,0,0},
-{ "&Save State",savestate,0,0,0},
-{ "",0,0,0,0},
-{ "L&oad Basic...",loadbaszor,0,0,0},
-{ "S&ave Basic...",savebaszor,0,0,0},
-{ "Loa&d Program...",xbloadzor,0,0,0},
-{ "Sav&e Program...",0,0,D_DISABLED,0},
-{ "",0,0,0,0},
-{ "E&xit",(void*)ynexit,0,0,0},
-{ 0,0,0,0,0}
-};
-MENU DRIVES_MENU[] = {
-{"Disk 1...",seld1,0,0,0},
-{"Disk 2...",seld2,0,0,0},
-{0,0,0,0,0}
-};
-MENU CPU_MENU[] = {
-{"Basic 6502 Clone",0,0,D_DISABLED,0},
-{"Synertek 6502",0,0,D_DISABLED,0},
-{"WDC 65C02",0,0,D_DISABLED,0},
-{"Rockwell 65C02",0,0,D_DISABLED,0},
-{"Speed...",0,0,D_DISABLED,0},
-{0,0,0,0,0}
-};
-MENU RAM_MENU[] = {
-{"Language Card (][ and ][+ only)",0,0,D_DISABLED,0},
-{"RAM Works/RAM Factor (//e and //c only)",0,0,D_DISABLED,0},
-{0,0,0,0,0}
-};
-MENU ROM_MENU[] = {
-{"Apple ][ (Monitor)",0,0,D_DISABLED,0},
-{"Apple ][ (Revised)",0,0,D_DISABLED,0},
-{"Apple ][+",0,0,D_DISABLED,0},
-{"Apple ][+ (Dosius Plusrom)",0,0,D_DISABLED,0},
-{"Franklin Ace",0,0,D_DISABLED,0},
-{"Viking",0,0,D_DISABLED,0},
-{"Apple //e (1982 version)",0,0,D_DISABLED,0},
-{"Apple //e (1985 version)",0,0,D_DISABLED,0},
-{"Apple //c (16K ROM)",0,0,D_DISABLED,0},
-{"Apple //c (32K ROM)",0,0,D_DISABLED,0},
-{0,0,0,0,0}
-};
-MENU DISPLAY_MENU[] = {
-{"Mono",0,0,D_DISABLED,0},
-{"Color",0,0,D_DISABLED,0},
-{"Blurry",0,0,D_DISABLED,0},
-{0,0,0,0,0}
-};
-MENU OPTIONS_MENU[] = {
-{"Drives",0,DRIVES_MENU,0,0},
-{"CPU",0,CPU_MENU,D_DISABLED,0},
-{"RAM",0,RAM_MENU,D_DISABLED,0},
-{"ROM",0,ROM_MENU,D_DISABLED,0},
-{"Sound",0,0,D_DISABLED,0},
-{"Display",0,DISPLAY_MENU,D_DISABLED,0},
-{0,0,0,0,0}
-};
-MENU DEBUG_MENU[] = {
-{"Set Execution Address...",0,0,0,0},
-{0,0,0,0,0}
-};
-MENU RESET_MENU[] = {
-{"Soft Reset",softreset,0,0,0},
-{"Hard Reset",hardreset,0,0,0},
-{"Full Reset",fullreset,0,0,0},
-{0,0,0,0,0}
-};
-MENU MAIN_MENU[] = {
-{"&File",0,FILE_MENU,0,0 },
-{"&Options",0,OPTIONS_MENU,0,0},
-{"&Debug",0,DEBUG_MENU,D_DISABLED,0},
-{"&Reset",0,RESET_MENU,0,0},
-{"&About",(void*)about,0,0,0},
-{ 0,0,0,0,0}
-};
-DIALOG dialog[] = {
-{ d_menu_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, MAIN_MENU, NULL, NULL },
-{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0}
-};
-void about()
-{
- alert (PROGTITLE " - Apple ][ Emulator",
- "Version " DappleVersion,
- "Copyright (C) 2002, 2007 Steve Nickolas and Retro Emulation Project",
- "O&K",0,'k',0);
- do_dialog(dialog,0);
-}
diff --git a/ini.c b/ini.c
index 5d38fcb..d5a0b77 100644
--- a/ini.c
+++ b/ini.c
@@ -21,8 +21,11 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
+#include <sys/stat.h>
+#include "dapple.h"
extern void virtsetmonochrome(unsigned int mode);
extern unsigned char virtgetmonochrome();
@@ -44,11 +47,6 @@ extern unsigned char memnolc;
extern unsigned int GameMinX, GameMinY, GameMaxX, GameMaxY;
-typedef enum {USA, France, Germany, UK, Denmark1, Sweden, Italy, Spain,
- Japan, Norway, Denmark2} Charset;
-
-extern Charset charmode;
-
extern char parallel[128], rompath[128];
void wrini(void)
diff --git a/joystick.c b/joystick.c
index e36afa7..c49af7d 100644
--- a/joystick.c
+++ b/joystick.c
@@ -22,10 +22,10 @@
//#include <conio.h>
//#include <dos.h>
#include <stdio.h>
-#include <allegro.h>
+#include <allegro.h>
//#include <go32.h>
//#include <sys/farptr.h>
-
+#include "joystick.h"
#ifdef USE_M6502
#include "m6502.h"
#else
@@ -39,17 +39,17 @@ unsigned long ClockX, ClockY; /* Timeouts for 556 timer */
unsigned int LeftAltDown = 0, RightAltDown = 0;
int joya(void)
-{
-if(key[KEY_ALT]) return 255;
-if(joy[0].button[0].b) return 255;
-return 0;
+{
+if(key[KEY_ALT]) return 255;
+if(joy[0].button[0].b) return 255;
+return 0;
}
int joyb(void)
-{
-if(key[KEY_ALTGR]) return 255;
-if(joy[0].button[1].b) return 255;
-return 0;
-}
+{
+if(key[KEY_ALTGR]) return 255;
+if(joy[0].button[1].b) return 255;
+return 0;
+}
/////////////////////////////////////////////////////////////////////////////
diff --git a/joystick.h b/joystick.h
new file mode 100644
index 0000000..76fdc82
--- /dev/null
+++ b/joystick.h
@@ -0,0 +1,2 @@
+int joya(void);
+int joyb(void);
diff --git a/lldisk.c b/lldisk.c
index d5737c4..3ce0903 100644
--- a/lldisk.c
+++ b/lldisk.c
@@ -132,11 +132,7 @@ int llwrite (int sector, unsigned char *buf)
#include <fcntl.h>
//#include <io.h>
#include "dapple.h"
-
-void InitMassStor( int slot );
-void ShutdownMassStor( void );
-byte ReadMassStorIO( word Address );
-void WriteMassStorIO( word Address, byte Data );
+#include "lldisk.h"
#define MS_DMA
diff --git a/lldisk.h b/lldisk.h
new file mode 100644
index 0000000..2ae4007
--- /dev/null
+++ b/lldisk.h
@@ -0,0 +1,7 @@
+byte ReadRawDiskIO( word Address );
+void WriteRawDiskIO( word Address, byte Data );
+
+void InitMassStor( int slot );
+void ShutdownMassStor( void );
+byte ReadMassStorIO( word Address );
+void WriteMassStorIO( word Address, byte Data );
diff --git a/massstor.c b/massstor.c
index 05522f1..3b31800 100644
--- a/massstor.c
+++ b/massstor.c
@@ -30,7 +30,9 @@
//#include <io.h>
#include <unistd.h>
#include <allegro.h>
-//#include "dapple.h"
+#include "dapple.h"
+#include "disk.h"
+#include "massstor.h"
#define COL_DRV_OFF 0x24
#define COL_DRV_ON 0x25
@@ -43,11 +45,6 @@ extern unsigned char virtcopy;
char hd1[128],hd2[128];
-void InitMassStor( int slot );
-void ShutdownMassStor( void );
-unsigned char ReadMassStorIO( unsigned short Address );
-void WriteMassStorIO( unsigned short Address, unsigned char Data );
-
/* NOTE: in theory ProDOS can support 4 volumes in slots 5 & 6. However,
it never seems to perform STATUS or FORMAT calls for the 2 extra units.
Hence, the mass-storage routines supply ProDOS with incorrect block
diff --git a/massstor.h b/massstor.h
new file mode 100644
index 0000000..5ea611e
--- /dev/null
+++ b/massstor.h
@@ -0,0 +1,4 @@
+void InitMassStor( int slot );
+void ShutdownMassStor( void );
+unsigned char ReadMassStorIO( unsigned short Address );
+void WriteMassStorIO( unsigned short Address, unsigned char Data );
diff --git a/mk.sh b/mk.sh
index 8e23b0d..f1be8c4 100755
--- a/mk.sh
+++ b/mk.sh
@@ -1,4 +1,4 @@
#!/bin/sh
-gcc -o dap altbanks.c altkey.c binmanip.c clock.c cpu65c02.c dapple.c debug.c disk.c i18n.c \
+gcc -o dap altbanks.c altkey.c binmanip.c clock.c cpu65c02.c dapple.c debug.c disk.c gui.c i18n.c \
ini.c joystick.c lldisk.c massstor.c membanks.c pic.c prtsc.c video.c \
`allegro-config --cflags --libs`
diff --git a/prtsc.h b/prtsc.h
new file mode 100644
index 0000000..4b928df
--- /dev/null
+++ b/prtsc.h
@@ -0,0 +1 @@
+void prtsc (void);
diff --git a/video.c b/video.c
index 6d89697..bf480a3 100644
--- a/video.c
+++ b/video.c
@@ -27,6 +27,8 @@
#include <string.h>
#include <allegro.h>
#include "dapple.h"
+#include "gui.h"
+#include "video.h"
/* changed_this */
#include "font.h"
diff --git a/video.h b/video.h
new file mode 100644
index 0000000..a85b597
--- /dev/null
+++ b/video.h
@@ -0,0 +1,6 @@
+void virtinit();
+void virtreset();
+unsigned char virtgetmonochrome();
+void virtsetmonochrome(unsigned char mode);
+unsigned char virtgethresmode();
+void virtsethresmode(unsigned char mode);
--
2.42.0